1 // Created on: 2013-08-27
2 // Created by: Denis BOGOLEPOV
3 // Copyright (c) 2013 OPEN CASCADE SAS
5 // The content of this file is subject to the Open CASCADE Technology Public
6 // License Version 6.5 (the "License"). You may not use the content of this file
7 // except in compliance with the License. Please obtain a copy of the License
8 // at http://www.opencascade.org and read it completely before using this file.
10 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
11 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
13 // The Original Code and all software distributed under the License is
14 // distributed on an "AS IS" basis, without warranty of any kind, and the
15 // Initial Developer hereby disclaims all such warranties, including without
16 // limitation, any warranties of merchantability, fitness for a particular
17 // purpose or non-infringement. Please see the License for the specific terms
18 // and conditions governing the rights and limitations under the License.
27 #include <Standard_ShortReal.hxx>
29 #include <OpenGl_AABB.hxx>
32 OpenGl_AABB::OpenGl_AABB() : myMinPoint(),
37 OpenGl_AABB::OpenGl_AABB (const OpenGl_RTVec4f& thePoint) : myMinPoint (thePoint),
38 myMaxPoint (thePoint),
42 OpenGl_AABB::OpenGl_AABB (const OpenGl_RTVec4f& theMinPoint,
43 const OpenGl_RTVec4f& theMaxPoint) : myMinPoint (theMinPoint),
44 myMaxPoint (theMaxPoint),
48 OpenGl_AABB::OpenGl_AABB (const OpenGl_AABB& theVolume) : myMinPoint (theVolume.myMinPoint),
49 myMaxPoint (theVolume.myMaxPoint),
50 myIsValid (theVolume.myIsValid)
53 void OpenGl_AABB::Add (const OpenGl_RTVec4f& thePoint)
57 myMinPoint = thePoint;
58 myMaxPoint = thePoint;
63 myMinPoint = OpenGl_RTVec4f (Min (myMinPoint.x(), thePoint.x()),
64 Min (myMinPoint.y(), thePoint.y()),
65 Min (myMinPoint.z(), thePoint.z()),
68 myMaxPoint = OpenGl_RTVec4f (Max (myMaxPoint.x(), thePoint.x()),
69 Max (myMaxPoint.y(), thePoint.y()),
70 Max (myMaxPoint.z(), thePoint.z()),
75 void OpenGl_AABB::Combine (const OpenGl_AABB& theVolume)
77 if (!theVolume.myIsValid)
82 myMinPoint = theVolume.myMinPoint;
83 myMaxPoint = theVolume.myMaxPoint;
88 myMinPoint = OpenGl_RTVec4f (Min (myMinPoint.x(), theVolume.myMinPoint.x()),
89 Min (myMinPoint.y(), theVolume.myMinPoint.y()),
90 Min (myMinPoint.z(), theVolume.myMinPoint.z()),
93 myMaxPoint = OpenGl_RTVec4f (Max (myMaxPoint.x(), theVolume.myMaxPoint.x()),
94 Max (myMaxPoint.y(), theVolume.myMaxPoint.y()),
95 Max (myMaxPoint.z(), theVolume.myMaxPoint.z()),
100 OpenGl_AABB OpenGl_AABB::Added (const OpenGl_RTVec4f& thePoint) const
102 OpenGl_AABB result (*this);
104 result.Add (thePoint);
109 OpenGl_AABB OpenGl_AABB::Combined (const OpenGl_AABB& theVolume) const
111 OpenGl_AABB result (*this);
113 result.Combine (theVolume);
118 void OpenGl_AABB::Clear()
123 OpenGl_RTVec4f OpenGl_AABB::Size() const
125 return myMaxPoint - myMinPoint;
128 float OpenGl_AABB::Area() const
130 const float aXLen = myMaxPoint.x() - myMinPoint.x();
131 const float aYLen = myMaxPoint.y() - myMinPoint.y();
132 const float aZLen = myMaxPoint.z() - myMinPoint.z();
134 return ( aXLen * aYLen + aXLen * aZLen + aZLen * aYLen ) * 2.f;