1 // Created on: 2013-12-20
2 // Created by: Denis BOGOLEPOV
3 // Copyright (c) 2013-2014 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License 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.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
16 // =======================================================================
17 // function : BVH_Transform
19 // =======================================================================
20 template<class T, int N>
21 BVH_Transform<T, N>::BVH_Transform()
26 // =======================================================================
27 // function : BVH_Transform
29 // =======================================================================
30 template<class T, int N>
31 BVH_Transform<T, N>::BVH_Transform (const BVH_MatNt& theTransform)
32 : myTransform (theTransform)
37 // =======================================================================
38 // function : ~BVH_Transform
40 // =======================================================================
41 template<class T, int N>
42 BVH_Transform<T, N>::~BVH_Transform()
47 // =======================================================================
48 // function : Transform
50 // =======================================================================
51 template<class T, int N>
52 const typename BVH_Transform<T, N>::BVH_MatNt& BVH_Transform<T, N>::Transform() const
59 template<class T, int N> struct MatrixOp
64 template<class T> struct MatrixOp<T, 4>
66 typedef typename BVH::MatrixType<T, 4>::Type BVH_Mat4t;
68 static void Inverse (const BVH_Mat4t& theIn,
71 theIn.Inverted (theOut);
74 typedef typename BVH::VectorType<T, 4>::Type BVH_Vec4t;
76 static BVH_Vec4t Multiply (const BVH_Mat4t& theMat,
77 const BVH_Vec4t& theVec)
79 BVH_Vec4t aOut = theMat * theVec;
80 return aOut * static_cast<T> (1.0 / aOut.w());
85 // =======================================================================
86 // function : SetTransform
88 // =======================================================================
89 template<class T, int N>
90 void BVH_Transform<T, N>::SetTransform (const BVH_MatNt& theTransform)
92 myTransform = theTransform;
93 BVH::MatrixOp<T, N>::Inverse (myTransform, myTransformInversed);
96 // =======================================================================
97 // function : Inversed
99 // =======================================================================
100 template<class T, int N>
101 const typename BVH_Transform<T, N>::BVH_MatNt& BVH_Transform<T, N>::Inversed() const
103 return myTransformInversed;
108 template<class T, int N>
115 struct UnitVector<T, 2>
117 typedef typename BVH::VectorType<T, 2>::Type BVH_Vec2t;
119 static BVH_Vec2t DX()
121 return BVH_Vec2t (static_cast<T> (1.0),
122 static_cast<T> (0.0));
125 static BVH_Vec2t DY()
127 return BVH_Vec2t (static_cast<T> (0.0),
128 static_cast<T> (1.0));
131 static BVH_Vec2t DZ()
133 return BVH_Vec2t (static_cast<T> (0.0),
134 static_cast<T> (0.0));
139 struct UnitVector<T, 3>
141 typedef typename BVH::VectorType<T, 3>::Type BVH_Vec3t;
143 static BVH_Vec3t DX()
145 return BVH_Vec3t (static_cast<T> (1.0),
146 static_cast<T> (0.0),
147 static_cast<T> (0.0));
150 static BVH_Vec3t DY()
152 return BVH_Vec3t (static_cast<T> (0.0),
153 static_cast<T> (1.0),
154 static_cast<T> (0.0));
157 static BVH_Vec3t DZ()
159 return BVH_Vec3t (static_cast<T> (0.0),
160 static_cast<T> (0.0),
161 static_cast<T> (1.0));
166 struct UnitVector<T, 4>
168 typedef typename BVH::VectorType<T, 4>::Type BVH_Vec4t;
170 static BVH_Vec4t DX()
172 return BVH_Vec4t (static_cast<T> (1.0),
173 static_cast<T> (0.0),
174 static_cast<T> (0.0),
175 static_cast<T> (0.0));
178 static BVH_Vec4t DY()
180 return BVH_Vec4t (static_cast<T> (0.0),
181 static_cast<T> (1.0),
182 static_cast<T> (0.0),
183 static_cast<T> (0.0));
186 static BVH_Vec4t DZ()
188 return BVH_Vec4t (static_cast<T> (0.0),
189 static_cast<T> (0.0),
190 static_cast<T> (1.0),
191 static_cast<T> (0.0));
196 // =======================================================================
199 // =======================================================================
200 template<class T, int N>
201 BVH_Box<T, N> BVH_Transform<T, N>::Apply (const BVH_Box<T, N>& theBox) const
203 typename BVH_Box<T, N>::BVH_VecNt aSize = theBox.Size();
206 for (Standard_Integer aX = 0; aX <= 1; ++aX)
208 for (Standard_Integer aY = 0; aY <= 1; ++aY)
210 for (Standard_Integer aZ = 0; aZ <= 1; ++aZ)
212 typename BVH_Box<T, N>::BVH_VecNt aCorner = theBox.CornerMin() +
213 BVH::UnitVector<T, N>::DX() * aSize * static_cast<T> (aX) +
214 BVH::UnitVector<T, N>::DY() * aSize * static_cast<T> (aY) +
215 BVH::UnitVector<T, N>::DZ() * aSize * static_cast<T> (aZ);
217 aBox.Add (BVH::MatrixOp<T, N>::Multiply (myTransform, aCorner));