0024001: Stereographic rendering support
[occt.git] / src / OpenGl / OpenGl_AABB.cxx
CommitLineData
e276548b 1// Created on: 2013-08-27
2// Created by: Denis BOGOLEPOV
3// Copyright (c) 2013 OPEN CASCADE SAS
4//
973c2be1 5// This file is part of Open CASCADE Technology software library.
e276548b 6//
973c2be1 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.
e276548b 12//
973c2be1 13// Alternatively, this file may be used under the terms of Open CASCADE
14// commercial license or contractual agreement.
e276548b 15
16#ifdef HAVE_CONFIG_H
17 #include <config.h>
18#endif
19
20#ifdef HAVE_OPENCL
21
22#include <Standard_ShortReal.hxx>
23
24#include <OpenGl_AABB.hxx>
25
26
27OpenGl_AABB::OpenGl_AABB() : myMinPoint(),
28 myMaxPoint(),
29 myIsValid (false)
30{ }
31
32OpenGl_AABB::OpenGl_AABB (const OpenGl_RTVec4f& thePoint) : myMinPoint (thePoint),
33 myMaxPoint (thePoint),
34 myIsValid (true)
35{ }
36
37OpenGl_AABB::OpenGl_AABB (const OpenGl_RTVec4f& theMinPoint,
38 const OpenGl_RTVec4f& theMaxPoint) : myMinPoint (theMinPoint),
39 myMaxPoint (theMaxPoint),
40 myIsValid (true)
41{ }
42
43OpenGl_AABB::OpenGl_AABB (const OpenGl_AABB& theVolume) : myMinPoint (theVolume.myMinPoint),
44 myMaxPoint (theVolume.myMaxPoint),
45 myIsValid (theVolume.myIsValid)
46{ }
47
48void OpenGl_AABB::Add (const OpenGl_RTVec4f& thePoint)
49{
50 if (!myIsValid)
51 {
52 myMinPoint = thePoint;
53 myMaxPoint = thePoint;
54 myIsValid = true;
55 }
56 else
57 {
58 myMinPoint = OpenGl_RTVec4f (Min (myMinPoint.x(), thePoint.x()),
59 Min (myMinPoint.y(), thePoint.y()),
60 Min (myMinPoint.z(), thePoint.z()),
61 1.f);
62
63 myMaxPoint = OpenGl_RTVec4f (Max (myMaxPoint.x(), thePoint.x()),
64 Max (myMaxPoint.y(), thePoint.y()),
65 Max (myMaxPoint.z(), thePoint.z()),
66 1.f);
67 }
68}
69
70void OpenGl_AABB::Combine (const OpenGl_AABB& theVolume)
71{
72 if (!theVolume.myIsValid)
73 return;
74
75 if (!myIsValid)
76 {
77 myMinPoint = theVolume.myMinPoint;
78 myMaxPoint = theVolume.myMaxPoint;
79 myIsValid = true;
80 }
81 else
82 {
83 myMinPoint = OpenGl_RTVec4f (Min (myMinPoint.x(), theVolume.myMinPoint.x()),
84 Min (myMinPoint.y(), theVolume.myMinPoint.y()),
85 Min (myMinPoint.z(), theVolume.myMinPoint.z()),
86 1.f);
87
88 myMaxPoint = OpenGl_RTVec4f (Max (myMaxPoint.x(), theVolume.myMaxPoint.x()),
89 Max (myMaxPoint.y(), theVolume.myMaxPoint.y()),
90 Max (myMaxPoint.z(), theVolume.myMaxPoint.z()),
91 1.f);
92 }
93}
94
95OpenGl_AABB OpenGl_AABB::Added (const OpenGl_RTVec4f& thePoint) const
96{
97 OpenGl_AABB result (*this);
98
99 result.Add (thePoint);
100
101 return result;
102}
103
104OpenGl_AABB OpenGl_AABB::Combined (const OpenGl_AABB& theVolume) const
105{
106 OpenGl_AABB result (*this);
107
108 result.Combine (theVolume);
109
110 return result;
111}
112
113void OpenGl_AABB::Clear()
114{
115 myIsValid = false;
116}
117
118OpenGl_RTVec4f OpenGl_AABB::Size() const
119{
120 return myMaxPoint - myMinPoint;
121}
122
123float OpenGl_AABB::Area() const
124{
125 const float aXLen = myMaxPoint.x() - myMinPoint.x();
126 const float aYLen = myMaxPoint.y() - myMinPoint.y();
127 const float aZLen = myMaxPoint.z() - myMinPoint.z();
128
129 return ( aXLen * aYLen + aXLen * aZLen + aZLen * aYLen ) * 2.f;
130}
131
973c2be1 132#endif