0024002: Overall code and build procedure refactoring -- automatic
[occt.git] / src / Bnd / Bnd_Box.hxx
1 // Created on: 1991-01-28
2 // Created by: Remi Lequette
3 // Copyright (c) 1991-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
5 //
6 // This file is part of Open CASCADE Technology software library.
7 //
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
13 //
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
16
17 #ifndef _Bnd_Box_HeaderFile
18 #define _Bnd_Box_HeaderFile
19
20 #include <Standard.hxx>
21 #include <Standard_DefineAlloc.hxx>
22 #include <Standard_Handle.hxx>
23
24 #include <Standard_Real.hxx>
25 #include <Standard_Integer.hxx>
26 #include <Standard_Boolean.hxx>
27 class Standard_ConstructionError;
28 class gp_Pnt;
29 class gp_Dir;
30 class gp_Trsf;
31 class gp_Lin;
32 class gp_Pln;
33
34
35 //! Describes a bounding box in 3D space.
36 //! A bounding box is parallel to the axes of the coordinates
37 //! system. If it is finite, it is defined by the three intervals:
38 //! -   [ Xmin,Xmax ],
39 //! -   [ Ymin,Ymax ],
40 //! -   [ Zmin,Zmax ].
41 //! A bounding box may be infinite (i.e. open) in one or more
42 //! directions. It is said to be:
43 //! -   OpenXmin if it is infinite on the negative side of the   "X Direction";
44 //! -   OpenXmax if it is infinite on the positive side of the "X Direction";
45 //! -   OpenYmin if it is infinite on the negative side of the   "Y Direction";
46 //! -   OpenYmax if it is infinite on the positive side of the "Y Direction";
47 //! -   OpenZmin if it is infinite on the negative side of the   "Z Direction";
48 //! -   OpenZmax if it is infinite on the positive side of the "Z Direction";
49 //! -   WholeSpace if it is infinite in all six directions. In this
50 //! case, any point of the space is inside the box;
51 //! -   Void if it is empty. In this case, there is no point included in the box.
52 //! A bounding box is defined by:
53 //! -   six bounds (Xmin, Xmax, Ymin, Ymax, Zmin and
54 //! Zmax) which limit the bounding box if it is finite,
55 //! -   eight flags (OpenXmin, OpenXmax, OpenYmin,
56 //! OpenYmax, OpenZmin, OpenZmax,
57 //! WholeSpace and Void) which describe the
58 //! bounding box if it is infinite or empty, and
59 //! -   a gap, which is included on both sides in any direction
60 //! when consulting the finite bounds of the box.
61 class Bnd_Box 
62 {
63 public:
64
65   DEFINE_STANDARD_ALLOC
66
67   
68   //! Creates an empty Box.
69   //! The constructed box is qualified Void. Its gap is null.
70   Standard_EXPORT Bnd_Box();
71   
72   //! Sets this bounding box so that it  covers the whole of 3D space.
73   //! It is infinitely  long in all directions.
74   Standard_EXPORT void SetWhole();
75   
76   //! Sets this bounding box so that it is empty. All points are outside a void box.
77   Standard_EXPORT void SetVoid();
78   
79   //! Sets this bounding box so that it bounds
80   //! -   the point P. This involves first setting this bounding box
81   //! to be void and then adding the point P.
82   Standard_EXPORT void Set (const gp_Pnt& P);
83   
84   //! Sets this bounding box so that it bounds
85   //! the half-line defined by point P and direction D, i.e. all
86   //! points M defined by M=P+u*D, where u is greater than
87   //! or equal to 0, are inside the bounding volume. This
88   //! involves first setting this box to be void and then adding   the half-line.
89   Standard_EXPORT void Set (const gp_Pnt& P, const gp_Dir& D);
90   
91   //! Enlarges this bounding box, if required, so that it
92   //! contains at least:
93   //! -   interval [ aXmin,aXmax ] in the "X Direction",
94   //! -   interval [ aYmin,aYmax ] in the "Y Direction",
95   //! -   interval [ aZmin,aZmax ] in the "Z Direction";
96   Standard_EXPORT void Update (const Standard_Real aXmin, const Standard_Real aYmin, const Standard_Real aZmin, const Standard_Real aXmax, const Standard_Real aYmax, const Standard_Real aZmax);
97   
98   //! Adds a point of coordinates (X,Y,Z) to this bounding box.
99   Standard_EXPORT void Update (const Standard_Real X, const Standard_Real Y, const Standard_Real Z);
100   
101   //! Returns the gap of this bounding box.
102   Standard_EXPORT Standard_Real GetGap() const;
103   
104   //! Set the gap of this bounding box to abs(Tol).
105   Standard_EXPORT void SetGap (const Standard_Real Tol);
106   
107   //! Enlarges the      box    with    a   tolerance   value.
108   //! (minvalues-Abs(<tol>) and maxvalues+Abs(<tol>))
109   //! This means that the minimum values of its X, Y and Z
110   //! intervals of definition, when they are finite, are reduced by
111   //! the absolute value of Tol, while the maximum values are
112   //! increased by the same amount.
113   Standard_EXPORT void Enlarge (const Standard_Real Tol);
114   
115   //! Returns the bounds of this bounding box. The gap is included.
116   //! If this bounding box is infinite (i.e. "open"), returned values
117   //! may be equal to +/- Precision::Infinite().
118   //! Standard_ConstructionError exception will be thrown if the box is void.
119   //! if IsVoid()
120   Standard_EXPORT void Get (Standard_Real& theXmin, Standard_Real& theYmin, Standard_Real& theZmin, Standard_Real& theXmax, Standard_Real& theYmax, Standard_Real& theZmax) const;
121   
122   //! Returns the lower corner of this bounding box. The gap is included.
123   //! If this bounding box is infinite (i.e. "open"), returned values
124   //! may be equal to +/- Precision::Infinite().
125   //! Standard_ConstructionError exception will be thrown if the box is void.
126   //! if IsVoid()
127   Standard_EXPORT gp_Pnt CornerMin() const;
128   
129   //! Returns the upper corner of this bounding box. The gap is included.
130   //! If this bounding box is infinite (i.e. "open"), returned values
131   //! may be equal to +/- Precision::Infinite().
132   //! Standard_ConstructionError exception will be thrown if the box is void.
133   //! if IsVoid()
134   Standard_EXPORT gp_Pnt CornerMax() const;
135   
136   //! The   Box will be   infinitely   long  in the Xmin
137   //! direction.
138   Standard_EXPORT void OpenXmin();
139   
140   //! The   Box will be   infinitely   long  in the Xmax
141   //! direction.
142   Standard_EXPORT void OpenXmax();
143   
144   //! The   Box will be   infinitely   long  in the Ymin
145   //! direction.
146   Standard_EXPORT void OpenYmin();
147   
148   //! The   Box will be   infinitely   long  in the Ymax
149   //! direction.
150   Standard_EXPORT void OpenYmax();
151   
152   //! The   Box will be   infinitely   long  in the Zmin
153   //! direction.
154   Standard_EXPORT void OpenZmin();
155   
156   //! The   Box will be   infinitely   long  in the Zmax
157   //! direction.
158   Standard_EXPORT void OpenZmax();
159   
160   //! Returns true if this bounding box is open in the  Xmin direction.
161   Standard_EXPORT Standard_Boolean IsOpenXmin() const;
162   
163   //! Returns true if this bounding box is open in the  Xmax direction.
164   Standard_EXPORT Standard_Boolean IsOpenXmax() const;
165   
166   //! Returns true if this bounding box is open in the  Ymix direction.
167   Standard_EXPORT Standard_Boolean IsOpenYmin() const;
168   
169   //! Returns true if this bounding box is open in the  Ymax direction.
170   Standard_EXPORT Standard_Boolean IsOpenYmax() const;
171   
172   //! Returns true if this bounding box is open in the  Zmin direction.
173   Standard_EXPORT Standard_Boolean IsOpenZmin() const;
174   
175   //! Returns true if this bounding box is open in the  Zmax  direction.
176   Standard_EXPORT Standard_Boolean IsOpenZmax() const;
177   
178   //! Returns true if this bounding box is infinite in all 6 directions (WholeSpace flag).
179   Standard_EXPORT Standard_Boolean IsWhole() const;
180   
181   //! Returns true if this bounding box is empty (Void flag).
182   Standard_EXPORT Standard_Boolean IsVoid() const;
183   
184   //! true if xmax-xmin < tol.
185   Standard_EXPORT Standard_Boolean IsXThin (const Standard_Real tol) const;
186   
187   //! true if ymax-ymin < tol.
188   Standard_EXPORT Standard_Boolean IsYThin (const Standard_Real tol) const;
189   
190   //! true if zmax-zmin < tol.
191   Standard_EXPORT Standard_Boolean IsZThin (const Standard_Real tol) const;
192   
193   //! Returns true if IsXThin, IsYThin and IsZThin are all true,
194   //! i.e. if the box is thin in all three dimensions.
195   Standard_EXPORT Standard_Boolean IsThin (const Standard_Real tol) const;
196   
197   //! Returns a bounding box which is the result of applying the
198   //! transformation T to this bounding box.
199   //! Warning
200   //! Applying a geometric transformation (for example, a
201   //! rotation) to a bounding box generally increases its
202   //! dimensions. This is not optimal for algorithms which use it.
203   Standard_EXPORT Bnd_Box Transformed (const gp_Trsf& T) const;
204   
205   //! Adds the box <Other> to <me>.
206   Standard_EXPORT void Add (const Bnd_Box& Other);
207   
208   //! Adds a Pnt to the box.
209   Standard_EXPORT void Add (const gp_Pnt& P);
210   
211   //! Extends  <me> from the Pnt <P> in the direction <D>.
212   Standard_EXPORT void Add (const gp_Pnt& P, const gp_Dir& D);
213   
214   //! Extends the Box  in the given Direction, i.e. adds
215   //! an  half-line. The   box  may become   infinite in
216   //! 1,2 or 3 directions.
217   Standard_EXPORT void Add (const gp_Dir& D);
218   
219   //! Returns True if the Pnt is out the box.
220   Standard_EXPORT Standard_Boolean IsOut (const gp_Pnt& P) const;
221   
222   //! Returns False if the line intersects the box.
223   Standard_EXPORT Standard_Boolean IsOut (const gp_Lin& L) const;
224   
225   //! Returns False if the plane intersects the box.
226   Standard_EXPORT Standard_Boolean IsOut (const gp_Pln& P) const;
227   
228   //! Returns False if the <Box> intersects or is inside <me>.
229   Standard_EXPORT Standard_Boolean IsOut (const Bnd_Box& Other) const;
230   
231   //! Returns False if  the transformed <Box> intersects
232   //! or  is inside <me>.
233   Standard_EXPORT Standard_Boolean IsOut (const Bnd_Box& Other, const gp_Trsf& T) const;
234   
235   //! Returns False  if the transformed <Box> intersects
236   //! or  is inside the transformed box <me>.
237   Standard_EXPORT Standard_Boolean IsOut (const gp_Trsf& T1, const Bnd_Box& Other, const gp_Trsf& T2) const;
238   
239   //! Returns False  if the flat band lying between two parallel
240   //! lines represented by their reference points <P1>, <P2> and
241   //! direction <D> intersects the box.
242   Standard_EXPORT Standard_Boolean IsOut (const gp_Pnt& P1, const gp_Pnt& P2, const gp_Dir& D) const;
243   
244   //! Computes the minimum distance between two boxes.
245   Standard_EXPORT Standard_Real Distance (const Bnd_Box& Other) const;
246   
247   Standard_EXPORT void Dump() const;
248   
249   //! Computes the squared diagonal of me.
250     Standard_Real SquareExtent() const;
251
252
253
254
255 protected:
256
257
258
259
260
261 private:
262
263
264
265   Standard_Real Xmin;
266   Standard_Real Xmax;
267   Standard_Real Ymin;
268   Standard_Real Ymax;
269   Standard_Real Zmin;
270   Standard_Real Zmax;
271   Standard_Real Gap;
272   Standard_Integer Flags;
273
274
275 };
276
277
278 #include <Bnd_Box.lxx>
279
280
281
282
283
284 #endif // _Bnd_Box_HeaderFile