Rocstar  1.0
Rocstar multiphysics simulation application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
BoundingBox.hpp
Go to the documentation of this file.
1 
8 #ifndef BOUNDING_BOX_H
9 #define BOUNDING_BOX_H
10 
11 #include <sstream>
12 #include <cstdlib>
13 #include <cassert>
14 #include <cstring>
15 #include <vector>
16 #include <algorithm>
17 
19 
20 
22 {
23  protected:
24  double max[3];
25  double min[3];
26 
27 
28  public:
29 
37  {
38  double min[3]; double max[3];
39 
40  std::vector< double > xaxis; xaxis.resize( 4 );
41  std::vector< double > yaxis; yaxis.resize( 4 );
42  std::vector< double > zaxis; zaxis.resize( 4 );
43 
44  xaxis[ 0 ] = b1.getMinX( );
45  xaxis[ 1 ] = b1.getMaxX( );
46  xaxis[ 2 ] = b2.getMinX( );
47  xaxis[ 3 ] = b2.getMaxX( );
48 
49  yaxis[ 0 ] = b1.getMinY( );
50  yaxis[ 1 ] = b1.getMaxY( );
51  yaxis[ 2 ] = b2.getMinY( );
52  yaxis[ 3 ] = b2.getMaxY( );
53 
54  zaxis[ 0 ] = b1.getMinZ( );
55  zaxis[ 1 ] = b1.getMaxZ( );
56  zaxis[ 2 ] = b2.getMinZ( );
57  zaxis[ 3 ] = b2.getMaxZ( );
58 
59  std::sort( xaxis.begin( ), xaxis.end( ) );
60  std::sort( yaxis.begin( ), yaxis.end( ) );
61  std::sort( zaxis.begin( ), zaxis.end( ) );
62 
63 
64  min[ 0 ] = xaxis[ 1 ];
65  max[ 0 ] = xaxis[ 2 ];
66 
67  min[ 1 ] = yaxis[ 1 ];
68  max[ 1 ] = yaxis[ 2 ];
69 
70  min[ 2 ] = zaxis[ 1 ];
71  max[ 2 ] = zaxis[ 2 ];
72 
73  xaxis.clear( );
74  yaxis.clear( );
75  zaxis.clear( );
76 
77  return ( BoundingBox( min[ 0 ], min[ 1 ], min[ 2 ],
78  max[ 0 ], max[ 1 ], max[ 2 ] ) );
79 
80  }
81 
87  static size_t Size( )
88  {
89  return( 6*sizeof( double ) );
90  }
91 
101  inline void setCoordinates(
102  const double x, const double y, const double z,
103  const double X, const double Y, const double Z )
104  {
105  this ->min[ 0 ] = x;
106  this ->min[ 1 ] = y;
107  this ->min[ 2 ] = z;
108  this ->max[ 0 ] = X;
109  this ->max[ 1 ] = Y;
110  this ->max[ 2 ] = Z;
111  };
112 
117  {
118  this ->min[ 0 ] = 0.0;
119  this ->min[ 1 ] = 0.0;
120  this ->min[ 2 ] = 0.0;
121  this ->max[ 0 ] = 1.0;
122  this ->max[ 1 ] = 1.0;
123  this ->max[ 2 ] = 1.0;
124  }
125 
135  BoundingBox( const double x, const double y, const double z,
136  const double X, const double Y, const double Z )
137  {
138  this ->setCoordinates( x,y,z, X,Y,Z );
139  }
140 
145  {
146 
147  }
148 
152  inline double getMinX( ){ return this ->min[ 0 ]; };
153 
157  inline double getMinY( ){ return this ->min[ 1 ]; };
158 
162  inline double getMinZ( ){ return this ->min[ 2 ]; };
163 
167  inline double getMaxX( ){ return this ->max[ 0 ]; };
168 
172  inline double getMaxY( ){ return this ->max[ 1 ]; };
173 
177  inline double getMaxZ( ){ return this ->max[ 2 ]; };
178 
187  inline bool hasPoint( const double x, const double y, const double z )
188  {
189 
190  return(
191  ( x > this ->getMinX( ) || Numerics::fpointequals( x, this ->getMinX( ) ) ) &&
192  ( x < this ->getMaxX( ) || Numerics::fpointequals( x, this ->getMaxX( ) ) ) &&
193  ( y > this ->getMinY( ) || Numerics::fpointequals( y, this ->getMinY( ) ) ) &&
194  ( y < this ->getMaxY( ) || Numerics::fpointequals( y, this ->getMaxY( ) ) ) &&
195  ( z > this ->getMinZ( ) || Numerics::fpointequals( z, this ->getMinZ( ) ) ) &&
196  ( z < this ->getMaxZ( ) || Numerics::fpointequals( z, this ->getMaxZ( ) ) )
197  );
198 
199  }
200 
201 };
202 
203 #endif
double getMinX()
A concrete object that provides the functionality for representing a bounding box geometric primitive...
Definition: BoundingBox.hpp:21
double getMinZ()
void int int REAL REAL * y
Definition: read.cpp:74
double getMaxZ()
double getMinY()
bool hasPoint(const double x, const double y, const double z)
Determines if a point is inside the bounding box.
static size_t Size()
Same as BoundingBox::getBytesize( ) but does not require a BoundingBox instance to be allocated...
Definition: BoundingBox.hpp:87
void setCoordinates(const double x, const double y, const double z, const double X, const double Y, const double Z)
Sets the coordinates of this BoundingBox instance.
static BoundingBox intersection(BoundingBox &b1, BoundingBox &b2)
Computes the bounding box intersection between bounding box b1,b2.
Definition: BoundingBox.hpp:36
BoundingBox()
Default Constructor.
void int int int REAL REAL REAL * z
Definition: write.cpp:76
void int int REAL * x
Definition: read.cpp:74
double min[3]
Definition: BoundingBox.hpp:25
BoundingBox(const double x, const double y, const double z, const double X, const double Y, const double Z)
Custom Constructor.
This library provides routines for comparing two floating numbers within a user-supplied tolerance...
double getMaxY()
double getMaxX()
~BoundingBox()
Destructor.
double max[3]
Definition: BoundingBox.hpp:24
bool fpointequals(const double a, const double b, double TOL=1e-9)
Checks if two floating numbers are &quot;nearly&quot; equal.