BALL 1.5.0
sphere3.h
Go to the documentation of this file.
1// -*- Mode: C++; tab-width: 2; -*-
2// vi: set ts=2:
3//
4
5#ifndef BALL_MATHS_SPHERE3_H
6#define BALL_MATHS_SPHERE3_H
7
8#ifdef BALL_HAS_IEEEFP_H
9# include <ieeefp.h>
10#endif
11
12#include <iostream>
13
14#ifndef BALL_MATHS_PLANE3_H
15# include <BALL/MATHS/plane3.h>
16#endif
17
18#ifndef BALL_MATHS_VECTOR3_H
19# include <BALL/MATHS/vector3.h>
20#endif
21
22namespace BALL
23{
28
31 template <typename T>
33 {
34 public:
35
37
38
41
42
47 : p(),
48 radius(0)
49 {
50 }
51
56 TSphere3(const TSphere3& sphere)
57 : p(sphere.p),
58 radius(sphere.radius)
59 {
60 }
61
67 TSphere3(const TVector3<T>& point, const T& radius)
68 : p(point),
70 {
71 }
72
76 virtual ~TSphere3()
77 {
78 }
79
82 virtual void clear()
83 {
84 p.clear();
85 radius = (T) 0;
86 }
88
92
96 void swap(TSphere3& sphere)
97 {
98 TVector3<T> temp_point(p);
99 p = sphere.p;
100 sphere.p = temp_point;
101
102 T temp = radius;
103 radius = sphere.radius;
104 sphere.radius = temp;
105 }
106
110 void set(const TSphere3& sphere)
111 {
112 p = sphere.p;
113 radius = sphere.radius;
114 }
115
121 void set(const TVector3<T>& point, const T& r)
122 {
123 p = point;
124 radius = r;
125 }
126
132 {
133 p = sphere.p;
134 radius = sphere.radius;
135 return *this;
136 }
137
142 void get(TSphere3& sphere) const
143 {
144 sphere.p = p;
145 sphere.radius = radius;
146 }
147
152 void get(TVector3<T>& point, T& r) const
153 {
154 point = p;
155 r = radius;
156 }
157
159
162
166 bool operator == (const TSphere3& sphere) const
167 {
168 return (p == sphere.p && Maths::isEqual(radius, sphere.radius));
169 }
170
174 bool operator != (const TSphere3& sphere) const
175 {
176 return (p != sphere.p || Maths::isNotEqual(radius, sphere.radius));
177 }
178
185 bool has(const TVector3<T>& point, bool on_surface = false) const
186 {
187 if (on_surface)
188 {
189 return Maths::isEqual(p.getDistance(point), radius);
190 }
191 else
192 {
193 return Maths::isLessOrEqual(p.getDistance(point), radius);
194 }
195 }
196
200 bool isEmpty() const
201
202 {
203 return Maths::isZero(radius);
204 }
205
207
210
215 bool isValid() const
216
217 {
218 return true;
219 }
220
227 void dump(std::ostream& s = std::cout, Size depth = 0) const
228
229 {
231
232 BALL_DUMP_HEADER(s, this, this);
233
234 BALL_DUMP_DEPTH(s, depth);
235 s << " position: " << p << std::endl;
236
237 BALL_DUMP_DEPTH(s, depth);
238 s << " radius: " << radius << std::endl;
239
241 }
242
244
247
251
255
257 };
259
266
270 template <typename T>
271 std::istream& operator >> (std::istream& s, TSphere3<T>& sphere)
272
273 {
274 char c;
275 s >> c >> sphere.p >> sphere.radius >> c;
276 return s;
277 }
278
285 template <typename T>
286 std::ostream& operator << (std::ostream& s, const TSphere3<T>& sphere)
287
288 {
289 s << '(' << sphere.p << ' ' << sphere.radius << ')';
290 return s;
291 }
293
300
301} // namespace BALL
302
303#endif // BALL_MATHS_SPHERE3_H
#define BALL_DUMP_STREAM_PREFIX(os)
Definition: macros.h:391
#define BALL_DUMP_STREAM_SUFFIX(os)
Definition: macros.h:395
#define BALL_DUMP_DEPTH(os, depth)
Definition: macros.h:390
#define BALL_DUMP_HEADER(os, cl, ob)
Definition: macros.h:393
#define BALL_CREATE(name)
Definition: create.h:62
BALL_EXPORT std::ostream & operator<<(std::ostream &os, const Exception::GeneralException &e)
TSphere3< float > Sphere3
Definition: sphere3.h:299
Definition: constants.h:13
std::istream & operator>>(std::istream &is, TRegularData1D< ValueType > &grid)
Input operator.
BALL_EXTERN_VARIABLE const double c
Definition: constants.h:149
bool isNotEqual(const T1 &a, const T2 &b)
Definition: MATHS/common.h:224
bool isZero(const T &t)
Definition: MATHS/common.h:189
bool isLessOrEqual(const T1 &a, const T2 &b)
Definition: MATHS/common.h:249
bool isEqual(const T1 &a, const T2 &b)
Definition: MATHS/common.h:212
TVector3< T > p
Definition: sphere3.h:250
bool isEmpty() const
Definition: sphere3.h:200
bool operator!=(const TSphere3 &sphere) const
Definition: sphere3.h:174
virtual ~TSphere3()
Definition: sphere3.h:76
bool isValid() const
Definition: sphere3.h:215
void dump(std::ostream &s=std::cout, Size depth=0) const
Definition: sphere3.h:227
void get(TVector3< T > &point, T &r) const
Definition: sphere3.h:152
void swap(TSphere3 &sphere)
Definition: sphere3.h:96
void set(const TVector3< T > &point, const T &r)
Definition: sphere3.h:121
TSphere3(const TVector3< T > &point, const T &radius)
Definition: sphere3.h:67
void set(const TSphere3 &sphere)
Definition: sphere3.h:110
bool operator==(const TSphere3 &sphere) const
Definition: sphere3.h:166
virtual void clear()
Definition: sphere3.h:82
TSphere3 & operator=(const TSphere3 &sphere)
Definition: sphere3.h:131
void get(TSphere3 &sphere) const
Definition: sphere3.h:142
bool has(const TVector3< T > &point, bool on_surface=false) const
Definition: sphere3.h:185
TSphere3(const TSphere3 &sphere)
Definition: sphere3.h:56