Rocstar  1.0
Rocstar multiphysics simulation application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
include/CGAL/Bbox_3.h
Go to the documentation of this file.
1 /* *******************************************************************
2  * Rocstar Simulation Suite *
3  * Copyright@2015, Illinois Rocstar LLC. All rights reserved. *
4  * *
5  * Illinois Rocstar LLC *
6  * Champaign, IL *
7  * www.illinoisrocstar.com *
8  * sales@illinoisrocstar.com *
9  * *
10  * License: See LICENSE file in top level of distribution package or *
11  * http://opensource.org/licenses/NCSA *
12  *********************************************************************/
13 /* *******************************************************************
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, *
15  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES *
16  * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND *
17  * NONINFRINGEMENT. IN NO EVENT SHALL THE CONTRIBUTORS OR *
18  * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
19  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, *
20  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE *
21  * USE OR OTHER DEALINGS WITH THE SOFTWARE. *
22  *********************************************************************/
23 // $Id: Bbox_3.h,v 1.8 2008/12/06 08:43:26 mtcampbe Exp $
24 
25 #ifndef CGAL_OPT_BBOX_3_H
26 #define CGAL_OPT_BBOX_3_H
27 
28 #include <CGAL/basic.h>
29 #include <cmath>
30 
32 
33 class Bbox_3
34 {
35 public:
36  Bbox_3() {
37  _min[0] = _min[1] = _min[2] = HUGE_VAL;
38  _max[0] = _max[1] = _max[2] = -HUGE_VAL;
39  }
40  // Bbox_3(const Bbox_3 &);
41  Bbox_3(double x_min, double y_min, double z_min,
42  double x_max, double y_max, double z_max) {
43  _min[0]=x_min; _min[1]=y_min; _min[2]=z_min;
44  _max[0]=x_max; _max[1]=y_max; _max[2]=z_max;
45  }
46 
47  template <class Point3>
48  explicit Bbox_3( const Point3 &p) {
49  _min[0]=p[0]; _min[1]=p[1]; _min[2]=p[2];
50  _max[0]=p[0]; _max[1]=p[1]; _max[2]=p[2];
51  }
52 
53  // Bbox_3 &operator=(const Bbox_3 &b);
54  // bool operator==(const Bbox_3 &b) const;
55  // bool operator!=(const Bbox_3 &b) const;
56 
57  double xmin() const { return _min[0]; }
58  double ymin() const { return _min[1]; }
59  double zmin() const { return _min[2]; }
60  double xmax() const { return _max[0]; }
61  double ymax() const { return _max[1]; }
62  double zmax() const { return _max[2]; }
63 
64  Bbox_3 operator+(const Bbox_3& b) const {
65  Bbox_3 box=*this; box+=b; return box;
66  }
67 
68  Bbox_3& operator+=(const Bbox_3& b) {
69  _min[0] = std::min(_min[0], b._min[0]);
70  _min[1] = std::min(_min[1], b._min[1]);
71  _min[2] = std::min(_min[2], b._min[2]);
72 
73  _max[0] = std::max(_max[0], b._max[0]);
74  _max[1] = std::max(_max[1], b._max[1]);
75  _max[2] = std::max(_max[2], b._max[2]);
76 
77  return *this;
78  }
79 
80  // Two bounding boxes are considered to match if for every bound,
81  // the difference between the two boxes is smaller than a fraction (eps)
82  // of the largest dimension of the two boxes.
83  bool do_match(const Bbox_3& bb, double tol) const {
84  return (std::abs(xmax()-bb.xmax()) <= tol &&
85  std::abs(xmin()-bb.xmin()) <= tol &&
86  std::abs(ymax()-bb.ymax()) <= tol &&
87  std::abs(ymin()-bb.ymin()) <= tol &&
88  std::abs(zmax()-bb.zmax()) <= tol &&
89  std::abs(zmin()-bb.zmin()) <= tol);
90  }
91 
92 private:
93  double _min[3],_max[3];
94 };
95 
96 inline bool do_overlap(const Bbox_3& bb1, const Bbox_3& bb2)
97 {
98  // check for emptiness ??
99  if (bb1.xmax() < bb2.xmin() || bb2.xmax() < bb1.xmin())
100  return false;
101  if (bb1.ymax() < bb2.ymin() || bb2.ymax() < bb1.ymin())
102  return false;
103  if (bb1.zmax() < bb2.zmin() || bb2.zmax() < bb1.zmin())
104  return false;
105  return true;
106 }
107 
108 #ifndef NO_OSTREAM_INSERT_BBOX_3
109 inline
110 std::ostream&
111 operator<<(std::ostream &os, const Bbox_3& b)
112 {
113  switch(os.iword(IO::mode))
114  {
115  case IO::ASCII :
116  return os << b.xmin() << ' ' << b.ymin() << ' ' << b.zmin() << ' '
117  << b.xmax() << ' ' << b.ymax() << ' ' << b.zmax();
118  case IO::BINARY :
119  write(os, b.xmin());
120  write(os, b.ymin());
121  write(os, b.zmin());
122  write(os, b.xmax());
123  write(os, b.ymax());
124  write(os, b.zmax());
125  return os;
126  default:
127  os << "Bbox_3((" << b.xmin()
128  << ", " << b.ymin()
129  << ", " << b.zmin() << "), (";
130  os << b.xmax()
131  << ", " << b.ymax()
132  << ", " << b.zmax() << "))";
133  return os;
134  }
135 }
136 #endif // NO_OSTREAM_INSERT_BBOX_3
137 
138 
139 
140 #ifndef NO_ISTREAM_EXTRACT_BBOX_3
141 inline
142 std::istream&
143 operator>>(std::istream &is, Bbox_3& b)
144 {
145  double xmin, ymin, zmin, xmax, ymax, zmax;
146 
147  switch(is.iword(IO::mode))
148  {
149  case IO::ASCII :
150  is >> xmin >> ymin >> zmin >> xmax >> ymax >> zmax ;
151  break;
152  case IO::BINARY :
153  read(is, xmin);
154  read(is, ymin);
155  read(is, zmin);
156  read(is, xmax);
157  read(is, ymax);
158  read(is, zmax);
159  break;
160  }
161  b = Bbox_3(xmin, ymin, zmin, xmax, ymax, zmax);
162  return is;
163 }
164 
165 #endif // NO_ISTREAM_EXTRACT_BBOX_3
166 
168 
169 #include <CGAL/cgalopt.h>
170 
172 using CGAL::Bbox_3;
173 
174 inline bool do_overlap_eps(const Bbox_3& bb1, const Bbox_3& bb2,
175  const double eps) {
176  // check for emptiness ??
177  if (bb1.xmax()+eps < bb2.xmin() || bb2.xmax()+eps < bb1.xmin())
178  return false;
179  if (bb1.ymax()+eps < bb2.ymin() || bb2.ymax()+eps < bb1.ymin())
180  return false;
181  if (bb1.zmax()+eps < bb2.zmin() || bb2.zmax()+eps < bb1.zmin())
182  return false;
183  return true;
184 }
185 
186 inline bool do_overlap_strict(const Bbox_3& bb1, const Bbox_3& bb2)
187 {
188  // check for emptiness ??
189  if (bb1.xmax() <= bb2.xmin() || bb2.xmax() <= bb1.xmin())
190  return false;
191  if (bb1.ymax() <= bb2.ymin() || bb2.ymax() <= bb1.ymin())
192  return false;
193  if (bb1.zmax() <= bb2.zmin() || bb2.zmax() <= bb1.zmin())
194  return false;
195  return true;
196 }
197 
198 template <class InIter>
199 Bbox_3 get_Bbox_3(InIter first, InIter last) {
200  Bbox_3 box;
201 
202  while (first != last) {
203  box += first->bbox();
204  ++first;
205  }
206  return box;
207 }
208 
210 
211 #endif // CGAL_OPT_BBOX_3_H
212 
213 
214 
215 
216 
217 
Bbox_3 get_Bbox_3(InIter first, InIter last)
double xmax() const
double _min[3]
Bbox_3 & operator+=(const Bbox_3 &b)
bool do_overlap_strict(const Bbox_2 &bb1, const Bbox_2 &bb2)
Bbox_3(double x_min, double y_min, double z_min, double x_max, double y_max, double z_max)
Vector_n max(const Array_n_const &v1, const Array_n_const &v2)
Definition: Vector_n.h:354
KD_tree::Box box
Definition: Overlay_0d.C:47
double xmin() const
double zmin() const
Definition: io.h:64
double ymax() const
void write(std::ostream &os, const T &t, const io_Read_write &)
Definition: io.h:96
double zmax() const
bool do_match(const Bbox_3 &bb, double tol) const
static int mode
Definition: io.h:63
Definition: io.h:64
double _max[3]
Vector_n min(const Array_n_const &v1, const Array_n_const &v2)
Definition: Vector_n.h:346
Bbox_3(const Point3 &p)
double ymin() const
bool do_overlap(const Bbox_2 &bb1, const Bbox_2 &bb2)
void read(std::istream &is, T &t, const io_Read_write &)
Definition: io.h:132
NT abs(const NT &x)
Definition: number_utils.h:130
#define CGAL_BEGIN_NAMESPACE
Definition: kdtree_d.h:86
std::istream & operator>>(std::istream &is, CGAL::Aff_transformation_2< R > &t)
#define CGAL_OPT_END_NAMESPACE
Definition: cgalopt.h:33
bool do_overlap_eps(const Bbox_2 &bb1, const Bbox_2 &bb2, const double eps)
std::ostream & operator<<(std::ostream &os, const COM_exception &ex)
Print out a given exception.
#define CGAL_END_NAMESPACE
Definition: kdtree_d.h:87
#define CGAL_OPT_BEGIN_NAMESPACE
Definition: cgalopt.h:32
Bbox_3 operator+(const Bbox_3 &b) const