0024473: TKMath, BVH - introduce template-based package for Bounding volume hierarchy...
[occt.git] / src / BVH / BVH_Box.hxx
1 // Created on: 2013-12-20
2 // Created by: Denis BOGOLEPOV
3 // Copyright (c) 2013 OPEN CASCADE SAS
4 //
5 // This file is part of Open CASCADE Technology software library.
6 //
7 // This library is free software; you can redistribute it and / or modify it
8 // under the terms of the GNU Lesser General Public version 2.1 as published
9 // by the Free Software Foundation, with special exception defined in the file
10 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 // distribution for complete text of the license and disclaimer of any warranty.
12 //
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
15
16 #ifndef _BVH_Box_Header
17 #define _BVH_Box_Header
18
19 #include <BVH_Types.hxx>
20
21 //! Axis aligned bounding box (AABB).
22 template<class T, int N>
23 class BVH_Box
24 {
25 public:
26
27   typedef typename BVHTools::VectorType<T, N>::Type BVH_VecNt;
28
29 public:
30
31   //! Creates uninitialized bounding box.
32   BVH_Box() : myInitialized (Standard_False) {}
33
34   //! Creates bounding box of given point.
35   BVH_Box (const BVH_VecNt& thePoint)
36   : myMinPoint    (thePoint),
37     myMaxPoint    (thePoint),
38     myInitialized (Standard_True) {}
39
40   //! Creates copy of another bounding box.
41   BVH_Box (const BVH_Box& theBox)
42   : myMinPoint    (theBox.myMinPoint),
43     myMaxPoint    (theBox.myMaxPoint),
44     myInitialized (theBox.myInitialized) {}
45
46   //! Creates bounding box from corner points.
47   BVH_Box (const BVH_VecNt& theMinPoint,
48            const BVH_VecNt& theMaxPoint)
49   : myMinPoint    (theMinPoint),
50     myMaxPoint    (theMaxPoint),
51     myInitialized (Standard_True) {}
52
53 public:
54
55   //! Clears bounding box.
56   void Clear();
57
58   //! Is bounding box valid?
59   Standard_Boolean IsValid() const;
60
61   //! Appends new point to the bounding box.
62   void Add (const BVH_VecNt& thePoint);
63
64   //! Combines bounding box with another one.
65   void Combine (const BVH_Box& theVolume);
66
67   //! Returns minimum point of bounding box.
68   const BVH_VecNt& CornerMin() const;
69
70   //! Returns maximum point of bounding box.
71   const BVH_VecNt& CornerMax() const;
72
73   //! Returns minimum point of bounding box.
74   BVH_VecNt& CornerMin();
75
76   //! Returns maximum point of bounding box.
77   BVH_VecNt& CornerMax();
78
79   //! Returns surface area of bounding box.
80   T Area() const;
81
82   //! Returns diagonal of bounding box.
83   BVH_VecNt Size() const;
84
85   //! Returns center of bounding box.
86   BVH_VecNt Center() const;
87
88 protected:
89
90   BVH_VecNt        myMinPoint;    //!< Minimum point of bounding box
91   BVH_VecNt        myMaxPoint;    //!< Maximum point of bounding box
92   Standard_Boolean myInitialized; //!< Is bounding box valid?
93
94 };
95
96 #include <BVH_Box.lxx>
97
98 #endif // _BVH_Box_Header