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
6 // This file is part of Open CASCADE Technology software library.
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.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
17 #ifndef _Bnd_Box_HeaderFile
18 #define _Bnd_Box_HeaderFile
20 #include <Standard.hxx>
21 #include <Standard_DefineAlloc.hxx>
22 #include <Standard_Handle.hxx>
24 #include <Standard_Real.hxx>
25 #include <Standard_Integer.hxx>
26 #include <Standard_Boolean.hxx>
27 class Standard_ConstructionError;
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:
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.
68 //! Creates an empty Box.
69 //! The constructed box is qualified Void. Its gap is null.
70 Standard_EXPORT Bnd_Box();
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();
76 //! Sets this bounding box so that it is empty. All points are outside a void box.
77 Standard_EXPORT void SetVoid();
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);
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);
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);
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);
101 //! Returns the gap of this bounding box.
102 Standard_EXPORT Standard_Real GetGap() const;
104 //! Set the gap of this bounding box to abs(Tol).
105 Standard_EXPORT void SetGap (const Standard_Real Tol);
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);
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.
120 Standard_EXPORT void Get (Standard_Real& theXmin, Standard_Real& theYmin, Standard_Real& theZmin, Standard_Real& theXmax, Standard_Real& theYmax, Standard_Real& theZmax) const;
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.
127 Standard_EXPORT gp_Pnt CornerMin() const;
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.
134 Standard_EXPORT gp_Pnt CornerMax() const;
136 //! The Box will be infinitely long in the Xmin
138 Standard_EXPORT void OpenXmin();
140 //! The Box will be infinitely long in the Xmax
142 Standard_EXPORT void OpenXmax();
144 //! The Box will be infinitely long in the Ymin
146 Standard_EXPORT void OpenYmin();
148 //! The Box will be infinitely long in the Ymax
150 Standard_EXPORT void OpenYmax();
152 //! The Box will be infinitely long in the Zmin
154 Standard_EXPORT void OpenZmin();
156 //! The Box will be infinitely long in the Zmax
158 Standard_EXPORT void OpenZmax();
160 //! Returns true if this bounding box is open in the Xmin direction.
161 Standard_EXPORT Standard_Boolean IsOpenXmin() const;
163 //! Returns true if this bounding box is open in the Xmax direction.
164 Standard_EXPORT Standard_Boolean IsOpenXmax() const;
166 //! Returns true if this bounding box is open in the Ymix direction.
167 Standard_EXPORT Standard_Boolean IsOpenYmin() const;
169 //! Returns true if this bounding box is open in the Ymax direction.
170 Standard_EXPORT Standard_Boolean IsOpenYmax() const;
172 //! Returns true if this bounding box is open in the Zmin direction.
173 Standard_EXPORT Standard_Boolean IsOpenZmin() const;
175 //! Returns true if this bounding box is open in the Zmax direction.
176 Standard_EXPORT Standard_Boolean IsOpenZmax() const;
178 //! Returns true if this bounding box is infinite in all 6 directions (WholeSpace flag).
179 Standard_EXPORT Standard_Boolean IsWhole() const;
181 //! Returns true if this bounding box is empty (Void flag).
182 Standard_EXPORT Standard_Boolean IsVoid() const;
184 //! true if xmax-xmin < tol.
185 Standard_EXPORT Standard_Boolean IsXThin (const Standard_Real tol) const;
187 //! true if ymax-ymin < tol.
188 Standard_EXPORT Standard_Boolean IsYThin (const Standard_Real tol) const;
190 //! true if zmax-zmin < tol.
191 Standard_EXPORT Standard_Boolean IsZThin (const Standard_Real tol) const;
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;
197 //! Returns a bounding box which is the result of applying the
198 //! transformation T to this bounding box.
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;
205 //! Adds the box <Other> to <me>.
206 Standard_EXPORT void Add (const Bnd_Box& Other);
208 //! Adds a Pnt to the box.
209 Standard_EXPORT void Add (const gp_Pnt& P);
211 //! Extends <me> from the Pnt <P> in the direction <D>.
212 Standard_EXPORT void Add (const gp_Pnt& P, const gp_Dir& D);
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);
219 //! Returns True if the Pnt is out the box.
220 Standard_EXPORT Standard_Boolean IsOut (const gp_Pnt& P) const;
222 //! Returns False if the line intersects the box.
223 Standard_EXPORT Standard_Boolean IsOut (const gp_Lin& L) const;
225 //! Returns False if the plane intersects the box.
226 Standard_EXPORT Standard_Boolean IsOut (const gp_Pln& P) const;
228 //! Returns False if the <Box> intersects or is inside <me>.
229 Standard_EXPORT Standard_Boolean IsOut (const Bnd_Box& Other) const;
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;
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;
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;
244 //! Computes the minimum distance between two boxes.
245 Standard_EXPORT Standard_Real Distance (const Bnd_Box& Other) const;
247 Standard_EXPORT void Dump() const;
249 //! Computes the squared diagonal of me.
250 Standard_Real SquareExtent() const;
272 Standard_Integer Flags;
278 #include <Bnd_Box.lxx>
284 #endif // _Bnd_Box_HeaderFile