BALL  1.4.79
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
box3.h
Go to the documentation of this file.
1 // -*- Mode: C++; tab-width: 2; -*-
2 // vi: set ts=2:
3 //
4 // $Id: box3.h,v 1.46 2005/12/23 17:01:48 amoll Exp $
5 //
6 
7 #ifndef BALL_MATHS_BOX3_H
8 #define BALL_MATHS_BOX3_H
9 
10 #ifndef BALL_COMMON_H
11 # include <BALL/common.h>
12 #endif
13 
14 #ifndef BALL_MATHS_VECTOR3_H
15 # include <BALL/MATHS/vector3.h>
16 #endif
17 
18 namespace BALL
19 {
25 
31  template <typename T>
32  class TBox3
33  {
34  public:
35 
37 
38 
41 
44  TBox3();
45 
49  TBox3(const TBox3& box);
50 
57  TBox3(const TVector3<T>& point,
58  const TVector3<T>& right_vector,
59  const TVector3<T>& height_vector,
60  const T& depth = 1);
61 
68  TBox3(const TVector3<T>& point,
69  const TVector3<T>& right_vector = TVector3<T>((T) 0, (T)1, (T)0),
70  const TVector3<T>& height_vector = TVector3<T>((T) 1, (T)0, (T)0),
71  const TVector3<T>& depth_vector = TVector3<T>((T) 0, (T)0, (T)1));
72 
75  virtual ~TBox3()
76  {
77  }
78 
82  virtual void clear();
83 
85 
87 
91  void set(const TBox3& box);
92 
97  const TBox3& operator = (const TBox3& box);
98 
102  void swap(TBox3& box);
103 
105 
107 
109  void setWidth(T width);
110 
112  T getWidth() const { return width_;}
113 
115  void setHeight(T height);
116 
118  T getHeight() const { return height_;}
119 
121  void setDepth(T depth);
122 
124  T getDepth() const { return depth_;}
125 
127  const TVector3<T>& getPoint() const { return point_;}
128 
130  void setPoint(const TVector3<T>& point) { point_ = point;}
131 
133  const TVector3<T>& getRightVector() const { return right_vector_;}
134 
136  void setRightVector(const TVector3<T>& v);
137 
139  const TVector3<T>& getHeightVector() const { return height_vector_;}
140 
142  void setHeightVector(const TVector3<T>& v);
143 
146  { return depth_vector_;}
147 
149  void setDepthVector(const TVector3<T>& v);
150 
154  T getSurface() const;
155 
159  T getVolume() const;
160 
163 
165 
167 
171  bool operator == (const TBox3& box) const;
172 
176  bool operator != (const TBox3& box) const;
177 
178  /* Test if a given point is a member of the box.
179  Optional it can be testet, if the point lies on the surface.
180  @param point the point to be tested
181  @param on_surface true to test the surface (default = false)
182  @return bool, <b>true</b> or <b>false</b>
183  */
184  //bool has(const TVector3<T>& point, bool on_surface = false) const;
185 
186  /* Test if two boxes intersect.
187  @param box the box to be tested
188  @return bool, <b>true</b> if the two boxes are intersecting, <b>false</b> otherwise
189  */
190  //bool isIntersecting(const TBox3& box) const;
191 
193 
195 
200  bool isValid() const;
201 
208  void dump(std::ostream& s = std::cout, Size depth = 0) const;
210 
211  protected:
212 
213  //_ lower left point of the box.
218 
222  };
224 
225 
226  template <typename T>
227  TBox3<T>::TBox3(const TVector3<T>& point, const TVector3<T>& right_vector,const TVector3<T>& height_vector,const T& depth)
228  : point_(point),
229  right_vector_(right_vector),
230  height_vector_(height_vector),
231  depth_vector_((right_vector % height_vector).normalize() * depth),
232  width_(right_vector.getLength()),
233  height_(height_vector.getLength()),
234  depth_(depth)
235  {}
236 
237  template <typename T>
239  const TVector3<T>& right_vector,
240  const TVector3<T>& height_vector,
241  const TVector3<T>& depth_vector)
242  : point_(point),
243  right_vector_(right_vector),
244  height_vector_(height_vector),
245  depth_vector_(depth_vector),
246  width_(right_vector.getLength()),
247  height_(height_vector.getLength()),
248  depth_(depth_vector.getLength())
249  {}
250 
251  template <typename T>
253  : point_((T)0, (T)0, (T)0),
254  right_vector_((T)0, (T)1, (T)0),
255  height_vector_((T)1, (T)0, (T)0),
256  depth_vector_((T)0, (T)0, (T)1),
257  width_((T)1),
258  height_((T)1),
259  depth_((T)1)
260  {
261  }
262 
263  template <typename T>
265  : point_(box.point_),
266  right_vector_(box.right_vector_),
267  height_vector_(box.height_vector_),
268  depth_vector_(box.depth_vector_),
269  width_(box.width_),
270  height_(box.height_),
271  depth_(box.depth_)
272  {
273  }
274 
275  template <typename T>
276  void TBox3<T>::set(const TBox3<T>& box)
277  {
278  point_ = box.point_;
279  right_vector_ = box.right_vector_;
280  height_vector_ = box.height_vector_;
281  depth_vector_ = box.depth_vector_;
282  width_ = box.width_;
283  height_ = box.height_;
284  depth_ = box.depth_;
285  }
286 
287  template <typename T>
290  {
291  set(box);
292  return *this;
293  }
294 
295  template <typename T>
297  {
298  point_.swap(box.point_);
299  right_vector_.swap(box.right_vector_);
300  height_vector_.swap(box.height_vector_);
301  depth_vector_.swap(box.depth_vector_);
302 
303  std::swap(width_, box.width_);
304  std::swap(height_, box.height_);
305  std::swap(depth_, box.depth_);
306  }
307 
308  template <typename T>
310  {
311  point_.clear();
312  right_vector_ = TVector3<T>((T)0, (T)1, (T)0);
313  height_vector_ = TVector3<T>((T)-1, (T)0, (T)0);
314  depth_vector_ = TVector3<T>((T)0, (T)0, (T)1);
315  width_ = (T) 1;
316  height_ = (T) 1;
317  depth_ = (T) 1;
318  }
319 
320 
321  template <typename T>
323  void TBox3<T>::setWidth(T width)
324  {
325  right_vector_.normalize();
326  right_vector_ *= width;
327  width_ = width;
328  }
329 
330  template <typename T>
332  void TBox3<T>::setHeight(T height)
333  {
334  height_vector_.normalize();
335  height_vector_ *= height;
336  height_ = height;
337  }
338 
339  template <typename T>
341  void TBox3<T>::setDepth(T depth)
342  {
343  depth_vector_.normalize();
344  depth_vector_ *= depth;
345  depth_ = depth;
346  }
347 
348  template <typename T>
351  {
352  right_vector_ = v;
353  width_ = right_vector_.getLength();
354  }
355 
356  template <typename T>
359  {
360  height_vector_ = v;
361  height_ = height_vector_.getLength();
362  }
363 
364  template <typename T>
367  {
368  depth_vector_ = v;
369  depth_ = depth_vector_.getLength();
370  }
371 
372  template <typename T>
373  BALL_INLINE
375  {
376  return ((width_ * height_ + width_ * depth_ + height_ * depth_) * 2);
377  }
378 
379  template <typename T>
381  {
382  return (right_vector_ + height_vector_ + depth_vector_);
383  }
384 
385  template <typename T>
386  BALL_INLINE
388  {
389  return (width_ * height_ * depth_);
390  }
391 
392  template <typename T>
393  bool TBox3<T>::operator == (const TBox3<T>& box) const
394  {
395  return (point_ == box.point_ &&
396  right_vector_ == box.right_vector_ &&
397  height_vector_ == box.height_vector_ &&
398  depth_vector_ == box.depth_vector_ &&
399  width_ == box.width_ &&
400  height_ == box.height_ &&
401  depth_ == box.depth_);
402  }
403 
404  template <typename T>
405  BALL_INLINE
406  bool TBox3<T>::operator != (const TBox3<T> &box) const
407  {
408  return !(*this == box);
409  }
410 
411  template <typename T>
412  BALL_INLINE
413  bool TBox3<T>::isValid() const
414  {
415  return (point_.isValid() &&
416  right_vector_.isValid() &&
417  height_vector_.isValid() &&
418  depth_vector_.isValid() &&
419  !right_vector_.isZero() &&
420  !height_vector_.isZero() &&
421  !depth_vector_.isZero());
422 
423  }
424 
425  template <typename T>
426  void TBox3<T>::dump(std::ostream& s, Size depth) const
427  {
429 
430  BALL_DUMP_HEADER(s, this, this);
431 
432  BALL_DUMP_DEPTH(s, depth);
433  s << "point: " << point_ << std::endl;
434 
435  BALL_DUMP_DEPTH(s, depth);
436  s << "right_vector: " << right_vector_ << std::endl;
437 
438  BALL_DUMP_DEPTH(s, depth);
439  s << "height_vector: " << height_vector_ << std::endl;
440 
441  BALL_DUMP_DEPTH(s, depth);
442  s << "depth_vector: " << depth_vector_ << std::endl;
443 
444  BALL_DUMP_DEPTH(s, depth);
445  s << "width: " << width_ << std::endl;
446 
447  BALL_DUMP_DEPTH(s, depth);
448  s << "height: " << height_ << std::endl;
449 
450  BALL_DUMP_DEPTH(s, depth);
451  s << "depth: " << depth_ << std::endl;
452 
454  }
455 
463  template <typename T>
464  std::istream& operator >> (std::istream& s, TBox3<T>& box)
465  {
466  TVector3<T> point, right, height, depth;
467  s >> point >> right >> height >> depth;
468  box.setPoint(point);
469  box.setRightVector(right);
470  box.setHeightVector(height);
471  box.setDepthVector(depth);
472  return s;
473  }
474 
483  template <typename T>
484  std::ostream& operator << (std::ostream& s, const TBox3<T>& box)
485  {
486  return s << box.getPoint() << " "
487  << box.getRightVector() << " "
488  << box.getHeightVector() << " "
489  << box.getDepthVector();
490  }
492 
497 
498 } // namespace BALL
499 
500 #endif // BALL_MATHS_BOX3_H
bool isValid() const
Definition: box3.h:413
T getDepth() const
Get depth.
Definition: box3.h:124
TVector3< T > height_vector_
Definition: box3.h:216
#define BALL_CREATE(name)
Definition: create.h:62
const TVector3< T > & getPoint() const
Get the point.
Definition: box3.h:127
TVector3< T > depth_vector_
Definition: box3.h:217
TVector3< T > point_
Definition: box3.h:214
TBox3()
Definition: box3.h:252
const TVector3< T > & getDepthVector() const
Get the depth vector.
Definition: box3.h:145
void setRightVector(const TVector3< T > &v)
Set the right vector.
Definition: box3.h:350
std::istream & operator>>(std::istream &is, TRegularData1D< ValueType > &grid)
Input operator.
T getSurface() const
Definition: box3.h:374
TVector3< T > getDiagonalVector() const
Definition: box3.h:380
T getLength() const
Definition: vector3.h:757
TBox3< float > Box3
Definition: box3.h:496
void setHeight(T height)
Set height.
Definition: box3.h:332
T depth_
Definition: box3.h:221
void setDepth(T depth)
Set depth.
Definition: box3.h:341
T getWidth() const
Get width.
Definition: box3.h:112
T width_
Definition: box3.h:219
void dump(std::ostream &s=std::cout, Size depth=0) const
Definition: box3.h:426
#define BALL_INLINE
Definition: debug.h:15
#define BALL_DUMP_HEADER(os, cl, ob)
Definition: macros.h:86
void setWidth(T width)
Set width.
Definition: box3.h:323
virtual ~TBox3()
Definition: box3.h:75
TVector3< T > right_vector_
Definition: box3.h:215
virtual void clear()
Definition: box3.h:309
T getHeight() const
Get height.
Definition: box3.h:118
T getVolume() const
Definition: box3.h:387
void set(const TBox3 &box)
Definition: box3.h:276
void setPoint(const TVector3< T > &point)
Set the point.
Definition: box3.h:130
#define BALL_DUMP_STREAM_PREFIX(os)
Definition: macros.h:84
const TVector3< T > & getRightVector() const
Get the right vector.
Definition: box3.h:133
void swap(TBox3 &box)
Definition: box3.h:296
const TVector3< T > & getHeightVector() const
Get the height vector.
Definition: box3.h:139
#define BALL_DUMP_STREAM_SUFFIX(os)
Definition: macros.h:88
#define BALL_DUMP_DEPTH(os, depth)
Definition: macros.h:83
void setHeightVector(const TVector3< T > &v)
Set the height vector.
Definition: box3.h:358
void setDepthVector(const TVector3< T > &v)
Set the depth vector.
Definition: box3.h:366
bool operator!=(const TBox3 &box) const
Definition: box3.h:406
const TBox3 & operator=(const TBox3 &box)
Definition: box3.h:289
T height_
Definition: box3.h:220
bool operator==(const TBox3 &box) const
Definition: box3.h:393