Loading...
Searching...
No Matches
simpleBox3.h
Go to the documentation of this file.
// -*- Mode: C++; tab-width: 2; -*-
// vi: set ts=2:
//
// $Id: simpleBox3.h,v 1.9 2004/05/27 19:49:42 oliver Exp $
//
#ifndef BALL_MATHS_SIMPLEBOX3_H
#define BALL_MATHS_SIMPLEBOX3_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 TSimpleBox3
{
public:
BALL_CREATE(TSimpleBox3<T>)
TSimpleBox3()
;
TSimpleBox3(const TSimpleBox3& box);
TSimpleBox3(const TVector3<T>& a, const TVector3<T>& b);
TSimpleBox3(const T& ax, const T& ay, const T& az, const T& bx, const T& by, const T& bz);
virtual ~TSimpleBox3()
{
}
virtual void clear();
void set(const TSimpleBox3& box);
void set(const TVector3<T>& lower, const TVector3<T>& upper);
void set(const T& ax, const T& ay, const T& az, const T& bx, const T& by, const T& bz);
const TSimpleBox3& operator = (const TSimpleBox3& box);
void get(TSimpleBox3& box) const;
void get(TVector3<T>& lower, TVector3<T>& upper) const;
void get(T& ax, T& ay, T& az, T& bx, T& by, T& bz) const;
void swap(TSimpleBox3& box);
T getSurface() const;
T getVolume() const;
T getWidth() const;
T getHeight() const;
T getDepth() const;
void join(const TSimpleBox3& box);
bool operator == (const TSimpleBox3& box) const;
bool operator != (const TSimpleBox3& box) const;
bool has(const TVector3<T>& point, bool on_surface = false) const;
bool isIntersecting(const TSimpleBox3& box) const;
bool isValid() const;
void dump(std::ostream& s = std::cout, Size depth = 0) const;
TVector3<T> a;
TVector3<T> b;
};
template <typename T>
TSimpleBox3<T>::TSimpleBox3()
: a(),
b()
{
}
template <typename T>
TSimpleBox3<T>::TSimpleBox3(const TSimpleBox3<T>& box)
: a(box.a),
b(box.b)
{
}
template <typename T>
TSimpleBox3<T>::TSimpleBox3(const TVector3<T>& lower, const TVector3<T>& upper)
: a(lower),
b(upper)
{
}
template <typename T>
TSimpleBox3<T>::TSimpleBox3(const T& ax, const T& ay, const T& az,
const T& bx, const T& by, const T& bz)
: a(ax, ay, az),
b(bx, by, bz)
{
}
template <typename T>
BALL_INLINE
void TSimpleBox3<T>::set(const TSimpleBox3<T>& box)
{
a.set(box.a);
b.set(box.b);
}
template <typename T>
BALL_INLINE
void TSimpleBox3<T>::set(const TVector3<T>& lower, const TVector3<T>& upper)
{
a.set(lower);
b.set(upper);
}
template <typename T>
BALL_INLINE
void TSimpleBox3<T>::set(const T& ax, const T& ay, const T& az,
const T& bx, const T& by, const T& bz)
{
a.set(ax, ay, az);
b.set(bx, by, bz);
}
template <typename T>
BALL_INLINE
const TSimpleBox3<T>& TSimpleBox3<T>::operator = (const TSimpleBox3<T> &box)
{
set(box);
return *this;
}
template <typename T>
BALL_INLINE
void TSimpleBox3<T>::get(TSimpleBox3<T>& box) const
{
box.set(*this);
}
template <typename T>
BALL_INLINE
void TSimpleBox3<T>::get(TVector3<T>& lower, TVector3<T>& upper) const
{
lower.set(a);
upper.set(b);
}
template <typename T>
BALL_INLINE
void TSimpleBox3<T>::get(T& ax, T& ay, T& az, T& bx, T& by, T& bz) const
{
a.get(ax, ay, az);
b.get(bx, by, bz);
}
template <typename T>
BALL_INLINE
void TSimpleBox3<T>::swap(TSimpleBox3<T>& box)
{
a.swap(box.a);
b.swap(box.b);
}
template <typename T>
BALL_INLINE
void TSimpleBox3<T>::clear()
{
a.set((T)0, (T)0, (T)0);
b.set((T)0, (T)0, (T)0);
}
template <typename T>
BALL_INLINE
T TSimpleBox3<T>::getSurface() const
{
T width = Maths::abs(b.x - a.x);
T height = Maths::abs(b.y - a.y);
T depth = Maths::abs(b.z - a.z);
return ((width * height + width * depth + height * depth) * 2);
}
template <typename T>
BALL_INLINE
T TSimpleBox3<T>::getVolume() const
{
T width = Maths::abs(b.x - a.x);
T height = Maths::abs(b.y - a.y);
T depth = Maths::abs(b.z - a.z);
return (width * height * depth);
}
template <typename T>
BALL_INLINE
T TSimpleBox3<T>::getWidth() const
{
return Maths::abs(b.x - a.x);
}
template <typename T>
BALL_INLINE
T TSimpleBox3<T>::getHeight() const
{
return Maths::abs(b.y - a.y);
}
template <typename T>
BALL_INLINE
T TSimpleBox3<T>::getDepth() const
{
return Maths::abs(b.z - a.z);
}
template <typename T>
void TSimpleBox3<T>::join(const TSimpleBox3<T>& box)
{
T minimum = a.x;
minimum = Maths::min(minimum, b.x);
minimum = Maths::min(minimum, box.a.x);
minimum = Maths::min(minimum, box.b.x);
T maximum = a.x;
maximum = Maths::max(maximum, b.x);
maximum = Maths::max(maximum, box.a.x);
maximum = Maths::max(maximum, box.b.x);
a.x = minimum;
b.x = maximum;
minimum = a.y;
minimum = Maths::min(minimum, b.y);
minimum = Maths::min(minimum, box.a.y);
minimum = Maths::min(minimum, box.b.y);
maximum = a.y;
maximum = Maths::max(maximum, b.y);
maximum = Maths::max(maximum, box.a.y);
maximum = Maths::max(maximum, box.b.y);
a.y = minimum;
b.y = maximum;
minimum = a.z;
minimum = Maths::min(minimum, b.z);
minimum = Maths::min(minimum, box.a.z);
minimum = Maths::min(minimum, box.b.z);
maximum = a.z;
maximum = Maths::max(maximum, b.z);
maximum = Maths::max(maximum, box.a.z);
maximum = Maths::max(maximum, box.b.z);
a.z = minimum;
b.z = maximum;
}
template <typename T>
BALL_INLINE
bool TSimpleBox3<T>::operator == (const TSimpleBox3<T>& box) const
{
return (a == box.a && b == box.b);
}
template <typename T>
BALL_INLINE
bool TSimpleBox3<T>::operator != (const TSimpleBox3<T> &box) const
{
return !(*this == box);
}
template <typename T>
BALL_INLINE
bool TSimpleBox3<T>::isValid() const
{
return (a.isValid() && b.isValid());
}
template <typename T>
bool TSimpleBox3<T>::has(const TVector3<T>& point, bool on_surface) const
{
if (!on_surface)
{
if (Maths::isLess(b[0],a[0]) || Maths::isLess(b[1],a[1]) || Maths::isLess(b[2],a[2]))
{
for (int i = 0; i < 3; i++)
{
if (Maths::isLess(point[i],b[i]) || Maths::isLess(a[i],point[i]))
{
return false;
}
}
}
else
{
for (int i = 0; i < 3; i++)
{
if (Maths::isLess(point[i],a[i]) || Maths::isLess(b[i],point[i]))
{
return false;
}
}
}
return true;
}
bool temp = false;
for (int i = 0; i < 3; i++)
{
if (Maths::isEqual(point[i],a[i]) || Maths::isEqual(point[i],b[i]))
{
temp = true;
break;
}
}
return (temp && has(point, false));
}
template <typename T>
bool TSimpleBox3<T>::isIntersecting(const TSimpleBox3& box) const
{
const TVector3<T>* lower;
const TVector3<T>* higher;
const TVector3<T>* box_lower;
const TVector3<T>* box_higher;
if (Maths::isLess(b[0],a[0]) ||
Maths::isLess(b[1],a[1]) ||
Maths::isLess(b[2],a[2]))
{
lower = &b;
higher = &a;
}
else
{
lower = &a;
higher = &b;
}
if (Maths::isLess(box.b[0],box.a[0]) ||
Maths::isLess(box.b[1],box.a[1]) ||
Maths::isLess(box.b[2],box.a[2]))
{
box_lower = &box.b;
box_higher = &box.a;
}
else
{
box_lower = &box.a;
box_higher = &box.b;;
}
for (int i = 0; i < 3; i++)
{
if (Maths::isLess((*box_higher)[i],(*lower)[i]) || Maths::isLess((*higher)[i],(*box_lower)[i]))
{
return false;
}
}
return true;
}
template <typename T>
void TSimpleBox3<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 << " a: " << a << std::endl;
BALL_DUMP_DEPTH(s, depth);
s << " b: " << b << std::endl;
BALL_DUMP_STREAM_SUFFIX(s);
}
template <typename T>
std::istream& operator >> (std::istream& s, TSimpleBox3<T>& box)
{
char c;
s >> c >> box.a >> box.b >> c;
return s;
}
template <typename T>
std::ostream& operator << (std::ostream& s, const TSimpleBox3<T>& box)
{
return s << "(" << box.a << ' ' << box.b << ')';
}
typedef TSimpleBox3<float> SimpleBox3;
} // namespace BALL
#endif // BALL_MATHS_SimpleBox3_H
BALL::TSimpleBox3
Definition simpleBox3.h:32
BALL::TSimpleBox3::get
void get(TVector3< T > &lower, TVector3< T > &upper) const
Definition simpleBox3.h:326
BALL::TSimpleBox3::getHeight
T getHeight() const
Definition simpleBox3.h:394
BALL::TSimpleBox3::dump
void dump(std::ostream &s=std::cout, Size depth=0) const
Definition simpleBox3.h:564
BALL::TSimpleBox3< float >::a
TVector3< float > a
Definition simpleBox3.h:239
BALL::TSimpleBox3::has
bool has(const TVector3< T > &point, bool on_surface=false) const
Definition simpleBox3.h:477
BALL::TSimpleBox3::set
void set(const T &ax, const T &ay, const T &az, const T &bx, const T &by, const T &bz)
Definition simpleBox3.h:299
BALL::TSimpleBox3::getSurface
T getSurface() const
Definition simpleBox3.h:362
BALL::TSimpleBox3::set
void set(const TVector3< T > &lower, const TVector3< T > &upper)
Definition simpleBox3.h:290
BALL::TSimpleBox3::getDepth
T getDepth() const
Definition simpleBox3.h:402
BALL::TSimpleBox3::swap
void swap(TSimpleBox3 &box)
Definition simpleBox3.h:344
BALL::TSimpleBox3::getVolume
T getVolume() const
Definition simpleBox3.h:374
BALL::TSimpleBox3::isValid
bool isValid() const
Definition simpleBox3.h:470
BALL::TSimpleBox3::isIntersecting
bool isIntersecting(const TSimpleBox3 &box) const
Definition simpleBox3.h:518
BALL::TSimpleBox3::clear
virtual void clear()
Definition simpleBox3.h:353
BALL::TSimpleBox3::operator==
bool operator==(const TSimpleBox3 &box) const
Definition simpleBox3.h:454
BALL::TSimpleBox3::operator=
const TSimpleBox3 & operator=(const TSimpleBox3 &box)
Definition simpleBox3.h:309
BALL::TSimpleBox3::get
void get(T &ax, T &ay, T &az, T &bx, T &by, T &bz) const
Definition simpleBox3.h:335
BALL::TSimpleBox3::getWidth
T getWidth() const
Definition simpleBox3.h:386
BALL::TSimpleBox3::operator!=
bool operator!=(const TSimpleBox3 &box) const
Definition simpleBox3.h:462
BALL::TSimpleBox3::set
void set(const TSimpleBox3 &box)
Definition simpleBox3.h:281
BALL::TSimpleBox3::TSimpleBox3
TSimpleBox3()
Definition simpleBox3.h:249
BALL::TSimpleBox3< float >::b
TVector3< float > b
Definition simpleBox3.h:243
BALL::TSimpleBox3::get
void get(TSimpleBox3 &box) const
Definition simpleBox3.h:318
BALL::TSimpleBox3::join
void join(const TSimpleBox3 &box)
Definition simpleBox3.h:409
BALL::TVector3
Definition vector3.h:71
BALL::TVector3::set
void set(const T *ptr)
Definition vector3.h:615
common.h
BALL_CREATE
#define BALL_CREATE(name)
Definition create.h:62
BALL_INLINE
#define BALL_INLINE
Definition debug.h:15
BALL::SimpleBox3
TSimpleBox3< float > SimpleBox3
Definition simpleBox3.h:615
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::Maths::max
T max(const T &a, const T &b)
Definition MATHS/common.h:75
BALL::Maths::isLess
bool isLess(const T1 &a, const T2 &b)
Definition MATHS/common.h:236
BALL::Maths::min
T min(const T &a, const T &b)
Definition MATHS/common.h:102
BALL::Maths::abs
T abs(const T &t)
Definition MATHS/common.h:50
BALL::Maths::isEqual
bool isEqual(const T1 &a, const T2 &b)
Definition MATHS/common.h:212
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