|
||||
File indexing completed on 2025-01-18 10:03:03
0001 // Created on: 1991-01-28 0002 // Created by: Remi Lequette 0003 // Copyright (c) 1991-1999 Matra Datavision 0004 // Copyright (c) 1999-2014 OPEN CASCADE SAS 0005 // 0006 // This file is part of Open CASCADE Technology software library. 0007 // 0008 // This library is free software; you can redistribute it and/or modify it under 0009 // the terms of the GNU Lesser General Public License version 2.1 as published 0010 // by the Free Software Foundation, with special exception defined in the file 0011 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT 0012 // distribution for complete text of the license and disclaimer of any warranty. 0013 // 0014 // Alternatively, this file may be used under the terms of Open CASCADE 0015 // commercial license or contractual agreement. 0016 0017 #ifndef _Bnd_Box_HeaderFile 0018 #define _Bnd_Box_HeaderFile 0019 0020 #include <Standard.hxx> 0021 #include <Standard_DefineAlloc.hxx> 0022 #include <Standard_Handle.hxx> 0023 0024 #include <gp_Pnt.hxx> 0025 #include <Standard_Real.hxx> 0026 #include <Standard_Boolean.hxx> 0027 class gp_Pnt; 0028 class gp_Dir; 0029 class gp_Trsf; 0030 class gp_Lin; 0031 class gp_Pln; 0032 0033 0034 //! Describes a bounding box in 3D space. 0035 //! A bounding box is parallel to the axes of the coordinates 0036 //! system. If it is finite, it is defined by the three intervals: 0037 //! - [ Xmin,Xmax ], 0038 //! - [ Ymin,Ymax ], 0039 //! - [ Zmin,Zmax ]. 0040 //! A bounding box may be infinite (i.e. open) in one or more 0041 //! directions. It is said to be: 0042 //! - OpenXmin if it is infinite on the negative side of the "X Direction"; 0043 //! - OpenXmax if it is infinite on the positive side of the "X Direction"; 0044 //! - OpenYmin if it is infinite on the negative side of the "Y Direction"; 0045 //! - OpenYmax if it is infinite on the positive side of the "Y Direction"; 0046 //! - OpenZmin if it is infinite on the negative side of the "Z Direction"; 0047 //! - OpenZmax if it is infinite on the positive side of the "Z Direction"; 0048 //! - WholeSpace if it is infinite in all six directions. In this 0049 //! case, any point of the space is inside the box; 0050 //! - Void if it is empty. In this case, there is no point included in the box. 0051 //! A bounding box is defined by: 0052 //! - six bounds (Xmin, Xmax, Ymin, Ymax, Zmin and 0053 //! Zmax) which limit the bounding box if it is finite, 0054 //! - eight flags (OpenXmin, OpenXmax, OpenYmin, 0055 //! OpenYmax, OpenZmin, OpenZmax, 0056 //! WholeSpace and Void) which describe the 0057 //! bounding box if it is infinite or empty, and 0058 //! - a gap, which is included on both sides in any direction 0059 //! when consulting the finite bounds of the box. 0060 class Bnd_Box 0061 { 0062 public: 0063 0064 DEFINE_STANDARD_ALLOC 0065 0066 0067 //! Creates an empty Box. 0068 //! The constructed box is qualified Void. Its gap is null. 0069 Standard_EXPORT Bnd_Box(); 0070 0071 //! Creates a bounding box, it contains: 0072 //! - minimum/maximum point of bounding box, 0073 //! The constructed box is qualified Void. Its gap is null. 0074 Standard_EXPORT Bnd_Box (const gp_Pnt& theMin, const gp_Pnt& theMax); 0075 0076 //! Sets this bounding box so that it covers the whole of 3D space. 0077 //! It is infinitely long in all directions. 0078 void SetWhole() { Flags = WholeMask; } 0079 0080 //! Sets this bounding box so that it is empty. All points are outside a void box. 0081 void SetVoid() 0082 { 0083 Xmin = RealLast(); 0084 Xmax = -RealLast(); 0085 Ymin = RealLast(); 0086 Ymax = -RealLast(); 0087 Zmin = RealLast(); 0088 Zmax = -RealLast(); 0089 Flags = VoidMask; 0090 Gap = 0.0; 0091 } 0092 0093 //! Sets this bounding box so that it bounds 0094 //! - the point P. This involves first setting this bounding box 0095 //! to be void and then adding the point P. 0096 Standard_EXPORT void Set (const gp_Pnt& P); 0097 0098 //! Sets this bounding box so that it bounds 0099 //! the half-line defined by point P and direction D, i.e. all 0100 //! points M defined by M=P+u*D, where u is greater than 0101 //! or equal to 0, are inside the bounding volume. This 0102 //! involves first setting this box to be void and then adding the half-line. 0103 Standard_EXPORT void Set (const gp_Pnt& P, const gp_Dir& D); 0104 0105 //! Enlarges this bounding box, if required, so that it 0106 //! contains at least: 0107 //! - interval [ aXmin,aXmax ] in the "X Direction", 0108 //! - interval [ aYmin,aYmax ] in the "Y Direction", 0109 //! - interval [ aZmin,aZmax ] in the "Z Direction"; 0110 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); 0111 0112 //! Adds a point of coordinates (X,Y,Z) to this bounding box. 0113 Standard_EXPORT void Update (const Standard_Real X, const Standard_Real Y, const Standard_Real Z); 0114 0115 //! Returns the gap of this bounding box. 0116 Standard_EXPORT Standard_Real GetGap() const; 0117 0118 //! Set the gap of this bounding box to abs(Tol). 0119 Standard_EXPORT void SetGap (const Standard_Real Tol); 0120 0121 //! Enlarges the box with a tolerance value. 0122 //! (minvalues-Abs(<tol>) and maxvalues+Abs(<tol>)) 0123 //! This means that the minimum values of its X, Y and Z 0124 //! intervals of definition, when they are finite, are reduced by 0125 //! the absolute value of Tol, while the maximum values are 0126 //! increased by the same amount. 0127 Standard_EXPORT void Enlarge (const Standard_Real Tol); 0128 0129 //! Returns the bounds of this bounding box. The gap is included. 0130 //! If this bounding box is infinite (i.e. "open"), returned values 0131 //! may be equal to +/- Precision::Infinite(). 0132 //! Standard_ConstructionError exception will be thrown if the box is void. 0133 //! if IsVoid() 0134 Standard_EXPORT void Get (Standard_Real& theXmin, Standard_Real& theYmin, Standard_Real& theZmin, Standard_Real& theXmax, Standard_Real& theYmax, Standard_Real& theZmax) const; 0135 0136 //! Returns the lower corner of this bounding box. The gap is included. 0137 //! If this bounding box is infinite (i.e. "open"), returned values 0138 //! may be equal to +/- Precision::Infinite(). 0139 //! Standard_ConstructionError exception will be thrown if the box is void. 0140 //! if IsVoid() 0141 Standard_EXPORT gp_Pnt CornerMin() const; 0142 0143 //! Returns the upper corner of this bounding box. The gap is included. 0144 //! If this bounding box is infinite (i.e. "open"), returned values 0145 //! may be equal to +/- Precision::Infinite(). 0146 //! Standard_ConstructionError exception will be thrown if the box is void. 0147 //! if IsVoid() 0148 Standard_EXPORT gp_Pnt CornerMax() const; 0149 0150 //! The Box will be infinitely long in the Xmin 0151 //! direction. 0152 void OpenXmin() { Flags |= XminMask; } 0153 0154 //! The Box will be infinitely long in the Xmax 0155 //! direction. 0156 void OpenXmax() { Flags |= XmaxMask; } 0157 0158 //! The Box will be infinitely long in the Ymin 0159 //! direction. 0160 void OpenYmin() { Flags |= YminMask; } 0161 0162 //! The Box will be infinitely long in the Ymax 0163 //! direction. 0164 void OpenYmax() { Flags |= YmaxMask; } 0165 0166 //! The Box will be infinitely long in the Zmin 0167 //! direction. 0168 void OpenZmin() { Flags |= ZminMask; } 0169 0170 //! The Box will be infinitely long in the Zmax 0171 //! direction. 0172 void OpenZmax() { Flags |= ZmaxMask; } 0173 0174 //! Returns true if this bounding box has at least one open direction. 0175 Standard_Boolean IsOpen() const { return (Flags & WholeMask) != 0; } 0176 0177 //! Returns true if this bounding box is open in the Xmin direction. 0178 Standard_Boolean IsOpenXmin() const { return (Flags & XminMask) != 0; } 0179 0180 //! Returns true if this bounding box is open in the Xmax direction. 0181 Standard_Boolean IsOpenXmax() const { return (Flags & XmaxMask) != 0; } 0182 0183 //! Returns true if this bounding box is open in the Ymix direction. 0184 Standard_Boolean IsOpenYmin() const { return (Flags & YminMask) != 0; } 0185 0186 //! Returns true if this bounding box is open in the Ymax direction. 0187 Standard_Boolean IsOpenYmax() const { return (Flags & YmaxMask) != 0; } 0188 0189 //! Returns true if this bounding box is open in the Zmin direction. 0190 Standard_Boolean IsOpenZmin() const { return (Flags & ZminMask) != 0; } 0191 0192 //! Returns true if this bounding box is open in the Zmax direction. 0193 Standard_Boolean IsOpenZmax() const { return (Flags & ZmaxMask) != 0; } 0194 0195 //! Returns true if this bounding box is infinite in all 6 directions (WholeSpace flag). 0196 Standard_Boolean IsWhole() const { return (Flags & WholeMask) == WholeMask; } 0197 0198 //! Returns true if this bounding box is empty (Void flag). 0199 Standard_Boolean IsVoid() const { return (Flags & VoidMask) != 0; } 0200 0201 //! true if xmax-xmin < tol. 0202 Standard_EXPORT Standard_Boolean IsXThin (const Standard_Real tol) const; 0203 0204 //! true if ymax-ymin < tol. 0205 Standard_EXPORT Standard_Boolean IsYThin (const Standard_Real tol) const; 0206 0207 //! true if zmax-zmin < tol. 0208 Standard_EXPORT Standard_Boolean IsZThin (const Standard_Real tol) const; 0209 0210 //! Returns true if IsXThin, IsYThin and IsZThin are all true, 0211 //! i.e. if the box is thin in all three dimensions. 0212 Standard_EXPORT Standard_Boolean IsThin (const Standard_Real tol) const; 0213 0214 //! Returns a bounding box which is the result of applying the 0215 //! transformation T to this bounding box. 0216 //! Warning 0217 //! Applying a geometric transformation (for example, a 0218 //! rotation) to a bounding box generally increases its 0219 //! dimensions. This is not optimal for algorithms which use it. 0220 Standard_NODISCARD Standard_EXPORT Bnd_Box Transformed (const gp_Trsf& T) const; 0221 0222 //! Adds the box <Other> to <me>. 0223 Standard_EXPORT void Add (const Bnd_Box& Other); 0224 0225 //! Adds a Pnt to the box. 0226 Standard_EXPORT void Add (const gp_Pnt& P); 0227 0228 //! Extends <me> from the Pnt <P> in the direction <D>. 0229 Standard_EXPORT void Add (const gp_Pnt& P, const gp_Dir& D); 0230 0231 //! Extends the Box in the given Direction, i.e. adds 0232 //! an half-line. The box may become infinite in 0233 //! 1,2 or 3 directions. 0234 Standard_EXPORT void Add (const gp_Dir& D); 0235 0236 //! Returns True if the Pnt is out the box. 0237 Standard_EXPORT Standard_Boolean IsOut (const gp_Pnt& P) const; 0238 0239 //! Returns False if the line intersects the box. 0240 Standard_EXPORT Standard_Boolean IsOut (const gp_Lin& L) const; 0241 0242 //! Returns False if the plane intersects the box. 0243 Standard_EXPORT Standard_Boolean IsOut (const gp_Pln& P) const; 0244 0245 //! Returns False if the <Box> intersects or is inside <me>. 0246 Standard_EXPORT Standard_Boolean IsOut (const Bnd_Box& Other) const; 0247 0248 //! Returns False if the transformed <Box> intersects 0249 //! or is inside <me>. 0250 Standard_EXPORT Standard_Boolean IsOut (const Bnd_Box& Other, const gp_Trsf& T) const; 0251 0252 //! Returns False if the transformed <Box> intersects 0253 //! or is inside the transformed box <me>. 0254 Standard_EXPORT Standard_Boolean IsOut (const gp_Trsf& T1, const Bnd_Box& Other, const gp_Trsf& T2) const; 0255 0256 //! Returns False if the flat band lying between two parallel 0257 //! lines represented by their reference points <P1>, <P2> and 0258 //! direction <D> intersects the box. 0259 Standard_EXPORT Standard_Boolean IsOut (const gp_Pnt& P1, const gp_Pnt& P2, const gp_Dir& D) const; 0260 0261 //! Computes the minimum distance between two boxes. 0262 Standard_EXPORT Standard_Real Distance (const Bnd_Box& Other) const; 0263 0264 Standard_EXPORT void Dump() const; 0265 0266 //! Computes the squared diagonal of me. 0267 Standard_Real SquareExtent() const 0268 { 0269 if (IsVoid()) 0270 { 0271 return 0.0; 0272 } 0273 0274 const Standard_Real aDx = Xmax - Xmin + Gap + Gap; 0275 const Standard_Real aDy = Ymax - Ymin + Gap + Gap; 0276 const Standard_Real aDz = Zmax - Zmin + Gap + Gap; 0277 return aDx * aDx + aDy * aDy + aDz * aDz; 0278 } 0279 0280 //! Returns a finite part of an infinite bounding box (returns self if this is already finite box). 0281 //! This can be a Void box in case if its sides has been defined as infinite (Open) without adding any finite points. 0282 //! WARNING! This method relies on Open flags, the infinite points added using Add() method will be returned as is. 0283 Bnd_Box FinitePart() const 0284 { 0285 if (!HasFinitePart()) 0286 { 0287 return Bnd_Box(); 0288 } 0289 0290 Bnd_Box aBox; 0291 aBox.Update (Xmin, Ymin, Zmin, Xmax, Ymax, Zmax); 0292 aBox.SetGap (Gap); 0293 return aBox; 0294 } 0295 0296 //! Returns TRUE if this box has finite part. 0297 Standard_Boolean HasFinitePart() const 0298 { 0299 return !IsVoid() 0300 && Xmax >= Xmin; 0301 } 0302 0303 //! Dumps the content of me into the stream 0304 Standard_EXPORT void DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth = -1) const; 0305 0306 //! Inits the content of me from the stream 0307 Standard_EXPORT Standard_Boolean InitFromJson (const Standard_SStream& theSStream, Standard_Integer& theStreamPos); 0308 0309 protected: 0310 0311 //! Bit flags. 0312 enum MaskFlags 0313 { 0314 VoidMask = 0x01, 0315 XminMask = 0x02, 0316 XmaxMask = 0x04, 0317 YminMask = 0x08, 0318 YmaxMask = 0x10, 0319 ZminMask = 0x20, 0320 ZmaxMask = 0x40, 0321 WholeMask = 0x7e 0322 }; 0323 0324 private: 0325 0326 Standard_Real Xmin; 0327 Standard_Real Xmax; 0328 Standard_Real Ymin; 0329 Standard_Real Ymax; 0330 Standard_Real Zmin; 0331 Standard_Real Zmax; 0332 Standard_Real Gap; 0333 Standard_Integer Flags; 0334 0335 }; 0336 0337 #endif // _Bnd_Box_HeaderFile
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |