Loading...
Searching...
No Matches
box3.h
Go to the documentation of this file.
// -*- Mode: C++; tab-width: 2; -*-
// vi: set ts=2:
//
// $Id: box3.h,v 1.46 2005/12/23 17:01:48 amoll Exp $
//
#ifndef BALL_MATHS_BOX3_H
#define BALL_MATHS_BOX3_H
#ifndef BALL_COMMON_H
# include <BALL/common.h>
#endif
#ifndef BALL_MATHS_VECTOR3_H
# include <BALL/MATHS/vector3.h>
#endif
namespace BALL
{
template <typename T>
class TBox3
{
public:
BALL_CREATE(TBox3<T>)
TBox3();
TBox3(const TBox3& box);
TBox3(const TVector3<T>& point,
const TVector3<T>& right_vector,
const TVector3<T>& height_vector,
const T& depth = 1);
TBox3(const TVector3<T>& point,
const TVector3<T>& right_vector = TVector3<T>((T) 0, (T)1, (T)0),
const TVector3<T>& height_vector = TVector3<T>((T) 1, (T)0, (T)0),
const TVector3<T>& depth_vector = TVector3<T>((T) 0, (T)0, (T)1));
virtual ~TBox3()
{
}
virtual void clear();
void set(const TBox3& box);
const TBox3& operator = (const TBox3& box);
void swap(TBox3& box);
void setWidth(T width);
T getWidth() const { return width_;}
void setHeight(T height);
T getHeight() const { return height_;}
void setDepth(T depth);
T getDepth() const { return depth_;}
const TVector3<T>& getPoint() const { return point_;}
void setPoint(const TVector3<T>& point) { point_ = point;}
const TVector3<T>& getRightVector() const { return right_vector_;}
void setRightVector(const TVector3<T>& v);
const TVector3<T>& getHeightVector() const { return height_vector_;}
void setHeightVector(const TVector3<T>& v);
const TVector3<T>& getDepthVector() const
{ return depth_vector_;}
void setDepthVector(const TVector3<T>& v);
T getSurface() const;
T getVolume() const;
TVector3<T> getDiagonalVector() const;
bool operator == (const TBox3& box) const;
bool operator != (const TBox3& box) const;
/* Test if a given point is a member of the box.
Optional it can be testet, if the point lies on the surface.
@param point the point to be tested
@param on_surface true to test the surface (default = false)
@return bool, <b>true</b> or <b>false</b>
*/
//bool has(const TVector3<T>& point, bool on_surface = false) const;
/* Test if two boxes intersect.
@param box the box to be tested
@return bool, <b>true</b> if the two boxes are intersecting, <b>false</b> otherwise
*/
//bool isIntersecting(const TBox3& box) const;
bool isValid() const;
void dump(std::ostream& s = std::cout, Size depth = 0) const;
protected:
//_ lower left point of the box.
TVector3<T> point_;
TVector3<T> right_vector_;
TVector3<T> height_vector_;
TVector3<T> depth_vector_;
T width_;
T height_;
T depth_;
};
template <typename T>
TBox3<T>::TBox3(const TVector3<T>& point, const TVector3<T>& right_vector,const TVector3<T>& height_vector,const T& depth)
: point_(point),
right_vector_(right_vector),
height_vector_(height_vector),
depth_vector_((right_vector % height_vector).normalize() * depth),
width_(right_vector.getLength()),
height_(height_vector.getLength()),
depth_(depth)
{}
template <typename T>
TBox3<T>::TBox3(const TVector3<T>& point,
const TVector3<T>& right_vector,
const TVector3<T>& height_vector,
const TVector3<T>& depth_vector)
: point_(point),
right_vector_(right_vector),
height_vector_(height_vector),
depth_vector_(depth_vector),
width_(right_vector.getLength()),
height_(height_vector.getLength()),
depth_(depth_vector.getLength())
{}
template <typename T>
TBox3<T>::TBox3()
: point_((T)0, (T)0, (T)0),
right_vector_((T)0, (T)1, (T)0),
height_vector_((T)1, (T)0, (T)0),
depth_vector_((T)0, (T)0, (T)1),
width_((T)1),
height_((T)1),
depth_((T)1)
{
}
template <typename T>
TBox3<T>::TBox3(const TBox3<T>& box)
: point_(box.point_),
right_vector_(box.right_vector_),
height_vector_(box.height_vector_),
depth_vector_(box.depth_vector_),
width_(box.width_),
height_(box.height_),
depth_(box.depth_)
{
}
template <typename T>
void TBox3<T>::set(const TBox3<T>& box)
{
point_ = box.point_;
right_vector_ = box.right_vector_;
height_vector_ = box.height_vector_;
depth_vector_ = box.depth_vector_;
width_ = box.width_;
height_ = box.height_;
depth_ = box.depth_;
}
template <typename T>
BALL_INLINE
const TBox3<T>& TBox3<T>::operator = (const TBox3<T> &box)
{
set(box);
return *this;
}
template <typename T>
void TBox3<T>::swap(TBox3<T>& box)
{
point_.swap(box.point_);
right_vector_.swap(box.right_vector_);
height_vector_.swap(box.height_vector_);
depth_vector_.swap(box.depth_vector_);
std::swap(width_, box.width_);
std::swap(height_, box.height_);
std::swap(depth_, box.depth_);
}
template <typename T>
void TBox3<T>::clear()
{
point_.clear();
right_vector_ = TVector3<T>((T)0, (T)1, (T)0);
height_vector_ = TVector3<T>((T)-1, (T)0, (T)0);
depth_vector_ = TVector3<T>((T)0, (T)0, (T)1);
width_ = (T) 1;
height_ = (T) 1;
depth_ = (T) 1;
}
template <typename T>
BALL_INLINE
void TBox3<T>::setWidth(T width)
{
right_vector_.normalize();
right_vector_ *= width;
width_ = width;
}
template <typename T>
BALL_INLINE
void TBox3<T>::setHeight(T height)
{
height_vector_.normalize();
height_vector_ *= height;
height_ = height;
}
template <typename T>
BALL_INLINE
void TBox3<T>::setDepth(T depth)
{
depth_vector_.normalize();
depth_vector_ *= depth;
depth_ = depth;
}
template <typename T>
BALL_INLINE
void TBox3<T>::setRightVector(const TVector3<T>& v)
{
right_vector_ = v;
width_ = right_vector_.getLength();
}
template <typename T>
BALL_INLINE
void TBox3<T>::setHeightVector(const TVector3<T>& v)
{
height_vector_ = v;
height_ = height_vector_.getLength();
}
template <typename T>
BALL_INLINE
void TBox3<T>::setDepthVector(const TVector3<T>& v)
{
depth_vector_ = v;
depth_ = depth_vector_.getLength();
}
template <typename T>
BALL_INLINE
T TBox3<T>::getSurface() const
{
return ((width_ * height_ + width_ * depth_ + height_ * depth_) * 2);
}
template <typename T>
TVector3<T> TBox3<T>::getDiagonalVector() const
{
return (right_vector_ + height_vector_ + depth_vector_);
}
template <typename T>
BALL_INLINE
T TBox3<T>::getVolume() const
{
return (width_ * height_ * depth_);
}
template <typename T>
bool TBox3<T>::operator == (const TBox3<T>& box) const
{
return (point_ == box.point_ &&
right_vector_ == box.right_vector_ &&
height_vector_ == box.height_vector_ &&
depth_vector_ == box.depth_vector_ &&
width_ == box.width_ &&
height_ == box.height_ &&
depth_ == box.depth_);
}
template <typename T>
BALL_INLINE
bool TBox3<T>::operator != (const TBox3<T> &box) const
{
return !(*this == box);
}
template <typename T>
BALL_INLINE
bool TBox3<T>::isValid() const
{
return (point_.isValid() &&
right_vector_.isValid() &&
height_vector_.isValid() &&
depth_vector_.isValid() &&
!right_vector_.isZero() &&
!height_vector_.isZero() &&
!depth_vector_.isZero());
}
template <typename T>
void TBox3<T>::dump(std::ostream& s, Size depth) const
{
BALL_DUMP_STREAM_PREFIX(s);
BALL_DUMP_HEADER(s, this, this);
BALL_DUMP_DEPTH(s, depth);
s << "point: " << point_ << std::endl;
BALL_DUMP_DEPTH(s, depth);
s << "right_vector: " << right_vector_ << std::endl;
BALL_DUMP_DEPTH(s, depth);
s << "height_vector: " << height_vector_ << std::endl;
BALL_DUMP_DEPTH(s, depth);
s << "depth_vector: " << depth_vector_ << std::endl;
BALL_DUMP_DEPTH(s, depth);
s << "width: " << width_ << std::endl;
BALL_DUMP_DEPTH(s, depth);
s << "height: " << height_ << std::endl;
BALL_DUMP_DEPTH(s, depth);
s << "depth: " << depth_ << std::endl;
BALL_DUMP_STREAM_SUFFIX(s);
}
template <typename T>
std::istream& operator >> (std::istream& s, TBox3<T>& box)
{
TVector3<T> point, right, height, depth;
s >> point >> right >> height >> depth;
box.setPoint(point);
box.setRightVector(right);
box.setHeightVector(height);
box.setDepthVector(depth);
return s;
}
template <typename T>
std::ostream& operator << (std::ostream& s, const TBox3<T>& box)
{
return s << box.getPoint() << " "
<< box.getRightVector() << " "
<< box.getHeightVector() << " "
<< box.getDepthVector();
}
typedef TBox3<float> Box3;
} // namespace BALL
#endif // BALL_MATHS_BOX3_H
BALL::TBox3
Definition box3.h:33
BALL::TBox3::setDepth
void setDepth(T depth)
Set depth.
Definition box3.h:341
BALL::TBox3::getHeightVector
const TVector3< T > & getHeightVector() const
Get the height vector.
Definition box3.h:139
BALL::TBox3::clear
virtual void clear()
Definition box3.h:309
BALL::TBox3::setWidth
void setWidth(T width)
Set width.
Definition box3.h:323
BALL::TBox3::getVolume
T getVolume() const
Definition box3.h:387
BALL::TBox3::getDiagonalVector
TVector3< T > getDiagonalVector() const
Definition box3.h:380
BALL::TBox3::getRightVector
const TVector3< T > & getRightVector() const
Get the right vector.
Definition box3.h:133
BALL::TBox3::setDepthVector
void setDepthVector(const TVector3< T > &v)
Set the depth vector.
Definition box3.h:366
BALL::TBox3::set
void set(const TBox3 &box)
Definition box3.h:276
BALL::TBox3::operator!=
bool operator!=(const TBox3 &box) const
Definition box3.h:406
BALL::TBox3::getDepth
T getDepth() const
Get depth.
Definition box3.h:124
BALL::TBox3::isValid
bool isValid() const
Definition box3.h:413
BALL::TBox3::getPoint
const TVector3< T > & getPoint() const
Get the point.
Definition box3.h:127
BALL::TBox3< float >::height_vector_
TVector3< float > height_vector_
Definition box3.h:216
BALL::TBox3::swap
void swap(TBox3 &box)
Definition box3.h:296
BALL::TBox3::operator=
const TBox3 & operator=(const TBox3 &box)
Definition box3.h:289
BALL::TBox3::getSurface
T getSurface() const
Definition box3.h:374
BALL::TBox3::setPoint
void setPoint(const TVector3< T > &point)
Set the point.
Definition box3.h:130
BALL::TBox3::setHeight
void setHeight(T height)
Set height.
Definition box3.h:332
BALL::TBox3< float >::width_
float width_
Definition box3.h:219
BALL::TBox3< float >::depth_
float depth_
Definition box3.h:221
BALL::TBox3::getDepthVector
const TVector3< T > & getDepthVector() const
Get the depth vector.
Definition box3.h:145
BALL::TBox3::TBox3
TBox3()
Definition box3.h:252
BALL::TBox3< float >::point_
TVector3< float > point_
Definition box3.h:214
BALL::TBox3::getHeight
T getHeight() const
Get height.
Definition box3.h:118
BALL::TBox3::setRightVector
void setRightVector(const TVector3< T > &v)
Set the right vector.
Definition box3.h:350
BALL::TBox3::getWidth
T getWidth() const
Get width.
Definition box3.h:112
BALL::TBox3::dump
void dump(std::ostream &s=std::cout, Size depth=0) const
Definition box3.h:426
BALL::TBox3< float >::depth_vector_
TVector3< float > depth_vector_
Definition box3.h:217
BALL::TBox3< float >::height_
float height_
Definition box3.h:220
BALL::TBox3< float >::right_vector_
TVector3< float > right_vector_
Definition box3.h:215
BALL::TBox3::setHeightVector
void setHeightVector(const TVector3< T > &v)
Set the height vector.
Definition box3.h:358
BALL::TBox3::operator==
bool operator==(const TBox3 &box) const
Definition box3.h:393
BALL::TVector3
Definition vector3.h:71
common.h
BALL_CREATE
#define BALL_CREATE(name)
Definition create.h:62
BALL_INLINE
#define BALL_INLINE
Definition debug.h:15
BALL::Box3
TBox3< float > Box3
Definition box3.h:496
BALL::operator<<
BALL_EXPORT std::ostream & operator<<(std::ostream &os, const Exception::GeneralException &e)
BALL_DUMP_STREAM_PREFIX
#define BALL_DUMP_STREAM_PREFIX(os)
Definition macros.h:391
BALL_DUMP_STREAM_SUFFIX
#define BALL_DUMP_STREAM_SUFFIX(os)
Definition macros.h:395
BALL_DUMP_DEPTH
#define BALL_DUMP_DEPTH(os, depth)
Definition macros.h:390
BALL_DUMP_HEADER
#define BALL_DUMP_HEADER(os, cl, ob)
Definition macros.h:393
BALL
Definition constants.h:13
BALL::Size
BALL_SIZE_TYPE Size
Definition COMMON/global.h:114
BALL::operator>>
std::istream & operator>>(std::istream &is, TRegularData1D< ValueType > &grid)
Input operator.
Definition regularData1D.h:802
vector3.h