Loading...
Searching...
No Matches
sphere3.h
Go to the documentation of this file.
// -*- Mode: C++; tab-width: 2; -*-
// vi: set ts=2:
//
#ifndef BALL_MATHS_SPHERE3_H
#define BALL_MATHS_SPHERE3_H
#ifdef BALL_HAS_IEEEFP_H
# include <ieeefp.h>
#endif
#include <iostream>
#ifndef BALL_MATHS_PLANE3_H
# include <BALL/MATHS/plane3.h>
#endif
#ifndef BALL_MATHS_VECTOR3_H
# include <BALL/MATHS/vector3.h>
#endif
namespace BALL
{
template <typename T>
class TSphere3
{
public:
BALL_CREATE(TSphere3)
TSphere3()
: p(),
radius(0)
{
}
TSphere3(const TSphere3& sphere)
: p(sphere.p),
radius(sphere.radius)
{
}
TSphere3(const TVector3<T>& point, const T& radius)
: p(point),
radius(radius)
{
}
virtual ~TSphere3()
{
}
virtual void clear()
{
p.clear();
radius = (T) 0;
}
void swap(TSphere3& sphere)
{
TVector3<T> temp_point(p);
p = sphere.p;
sphere.p = temp_point;
T temp = radius;
radius = sphere.radius;
sphere.radius = temp;
}
void set(const TSphere3& sphere)
{
p = sphere.p;
radius = sphere.radius;
}
void set(const TVector3<T>& point, const T& r)
{
p = point;
radius = r;
}
TSphere3& operator = (const TSphere3& sphere)
{
p = sphere.p;
radius = sphere.radius;
return *this;
}
void get(TSphere3& sphere) const
{
sphere.p = p;
sphere.radius = radius;
}
void get(TVector3<T>& point, T& r) const
{
point = p;
r = radius;
}
bool operator == (const TSphere3& sphere) const
{
return (p == sphere.p && Maths::isEqual(radius, sphere.radius));
}
bool operator != (const TSphere3& sphere) const
{
return (p != sphere.p || Maths::isNotEqual(radius, sphere.radius));
}
bool has(const TVector3<T>& point, bool on_surface = false) const
{
if (on_surface)
{
return Maths::isEqual(p.getDistance(point), radius);
}
else
{
return Maths::isLessOrEqual(p.getDistance(point), radius);
}
}
bool isEmpty() const
{
return Maths::isZero(radius);
}
bool isValid() const
{
return true;
}
void dump(std::ostream& s = std::cout, Size depth = 0) const
{
BALL_DUMP_STREAM_PREFIX(s);
BALL_DUMP_HEADER(s, this, this);
BALL_DUMP_DEPTH(s, depth);
s << " position: " << p << std::endl;
BALL_DUMP_DEPTH(s, depth);
s << " radius: " << radius << std::endl;
BALL_DUMP_STREAM_SUFFIX(s);
}
TVector3<T> p;
T radius;
};
template <typename T>
std::istream& operator >> (std::istream& s, TSphere3<T>& sphere)
{
char c;
s >> c >> sphere.p >> sphere.radius >> c;
return s;
}
template <typename T>
std::ostream& operator << (std::ostream& s, const TSphere3<T>& sphere)
{
s << '(' << sphere.p << ' ' << sphere.radius << ')';
return s;
}
typedef TSphere3<float> Sphere3;
} // namespace BALL
#endif // BALL_MATHS_SPHERE3_H
BALL::TSphere3
Definition sphere3.h:33
BALL::TSphere3< float >::p
TVector3< float > p
Definition sphere3.h:250
BALL::TSphere3::isEmpty
bool isEmpty() const
Definition sphere3.h:200
BALL::TSphere3< float >::radius
float radius
Definition sphere3.h:254
BALL::TSphere3::operator!=
bool operator!=(const TSphere3 &sphere) const
Definition sphere3.h:174
BALL::TSphere3::~TSphere3
virtual ~TSphere3()
Definition sphere3.h:76
BALL::TSphere3::isValid
bool isValid() const
Definition sphere3.h:215
BALL::TSphere3::dump
void dump(std::ostream &s=std::cout, Size depth=0) const
Definition sphere3.h:227
BALL::TSphere3::get
void get(TVector3< T > &point, T &r) const
Definition sphere3.h:152
BALL::TSphere3::swap
void swap(TSphere3 &sphere)
Definition sphere3.h:96
BALL::TSphere3::set
void set(const TVector3< T > &point, const T &r)
Definition sphere3.h:121
BALL::TSphere3::TSphere3
TSphere3(const TVector3< T > &point, const T &radius)
Definition sphere3.h:67
BALL::TSphere3::set
void set(const TSphere3 &sphere)
Definition sphere3.h:110
BALL::TSphere3::operator==
bool operator==(const TSphere3 &sphere) const
Definition sphere3.h:166
BALL::TSphere3::clear
virtual void clear()
Definition sphere3.h:82
BALL::TSphere3::TSphere3
TSphere3()
Definition sphere3.h:46
BALL::TSphere3::operator=
TSphere3 & operator=(const TSphere3 &sphere)
Definition sphere3.h:131
BALL::TSphere3::get
void get(TSphere3 &sphere) const
Definition sphere3.h:142
BALL::TSphere3::has
bool has(const TVector3< T > &point, bool on_surface=false) const
Definition sphere3.h:185
BALL::TSphere3::TSphere3
TSphere3(const TSphere3 &sphere)
Definition sphere3.h:56
BALL::TVector3
Definition vector3.h:71
BALL_CREATE
#define BALL_CREATE(name)
Definition create.h:62
BALL::Sphere3
TSphere3< float > Sphere3
Definition sphere3.h:299
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::isNotEqual
bool isNotEqual(const T1 &a, const T2 &b)
Definition MATHS/common.h:224
BALL::Maths::isZero
bool isZero(const T &t)
Definition MATHS/common.h:189
BALL::Maths::isLessOrEqual
bool isLessOrEqual(const T1 &a, const T2 &b)
Definition MATHS/common.h:249
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
plane3.h
vector3.h