File indexing completed on 2025-01-18 10:03:19
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016 #ifndef BVH_Properties_HeaderFile
0017 #define BVH_Properties_HeaderFile
0018
0019 #include <BVH_Box.hxx>
0020
0021 #include <Standard_Macro.hxx>
0022
0023
0024 class BVH_Properties : public Standard_Transient
0025 {
0026 DEFINE_STANDARD_RTTIEXT(BVH_Properties, Standard_Transient)
0027 public:
0028
0029
0030 Standard_EXPORT virtual ~BVH_Properties() = 0;
0031
0032 };
0033
0034
0035 template<class T, int N>
0036 class BVH_Transform : public BVH_Properties
0037 {
0038 public:
0039
0040
0041 typedef typename BVH::MatrixType<T, N>::Type BVH_MatNt;
0042
0043 public:
0044
0045
0046 BVH_Transform() {}
0047
0048
0049 BVH_Transform (const BVH_MatNt& theTransform) : myTransform (theTransform) {}
0050
0051
0052 virtual ~BVH_Transform() {}
0053
0054
0055 const BVH_MatNt& Transform() const { return myTransform; }
0056
0057
0058 void SetTransform (const BVH_MatNt& theTransform);
0059
0060
0061 const BVH_MatNt& Inversed() const { return myTransformInversed; }
0062
0063
0064 BVH_Box<T, N> Apply (const BVH_Box<T, N>& theBox) const;
0065
0066 protected:
0067
0068 BVH_MatNt myTransform;
0069 BVH_MatNt myTransformInversed;
0070
0071 };
0072
0073 namespace BVH
0074 {
0075 template<class T, int N> struct MatrixOp
0076 {
0077
0078 };
0079
0080 template<class T> struct MatrixOp<T, 4>
0081 {
0082 typedef typename BVH::MatrixType<T, 4>::Type BVH_Mat4t;
0083
0084 static void Inverse (const BVH_Mat4t& theIn,
0085 BVH_Mat4t& theOut)
0086 {
0087 theIn.Inverted (theOut);
0088 }
0089
0090 typedef typename BVH::VectorType<T, 4>::Type BVH_Vec4t;
0091
0092 static BVH_Vec4t Multiply (const BVH_Mat4t& theMat,
0093 const BVH_Vec4t& theVec)
0094 {
0095 BVH_Vec4t aOut = theMat * theVec;
0096 return aOut * static_cast<T> (1.0 / aOut.w());
0097 }
0098 };
0099
0100 template<class T, int N>
0101 struct UnitVector
0102 {
0103
0104 };
0105
0106 template<class T>
0107 struct UnitVector<T, 2>
0108 {
0109 typedef typename BVH::VectorType<T, 2>::Type BVH_Vec2t;
0110 static BVH_Vec2t DX() { return BVH_Vec2t (static_cast<T> (1.0), static_cast<T> (0.0)); }
0111 static BVH_Vec2t DY() { return BVH_Vec2t (static_cast<T> (0.0), static_cast<T> (1.0)); }
0112 static BVH_Vec2t DZ() { return BVH_Vec2t (static_cast<T> (0.0), static_cast<T> (0.0)); }
0113 };
0114
0115 template<class T>
0116 struct UnitVector<T, 3>
0117 {
0118 typedef typename BVH::VectorType<T, 3>::Type BVH_Vec3t;
0119 static BVH_Vec3t DX() { return BVH_Vec3t (static_cast<T> (1.0), static_cast<T> (0.0), static_cast<T> (0.0)); }
0120 static BVH_Vec3t DY() { return BVH_Vec3t (static_cast<T> (0.0), static_cast<T> (1.0), static_cast<T> (0.0)); }
0121 static BVH_Vec3t DZ() { return BVH_Vec3t (static_cast<T> (0.0), static_cast<T> (0.0), static_cast<T> (1.0)); }
0122 };
0123
0124 template<class T>
0125 struct UnitVector<T, 4>
0126 {
0127 typedef typename BVH::VectorType<T, 4>::Type BVH_Vec4t;
0128 static BVH_Vec4t DX() { return BVH_Vec4t (static_cast<T> (1.0), static_cast<T> (0.0), static_cast<T> (0.0), static_cast<T> (0.0)); }
0129 static BVH_Vec4t DY() { return BVH_Vec4t (static_cast<T> (0.0), static_cast<T> (1.0), static_cast<T> (0.0), static_cast<T> (0.0)); }
0130 static BVH_Vec4t DZ() { return BVH_Vec4t (static_cast<T> (0.0), static_cast<T> (0.0), static_cast<T> (1.0), static_cast<T> (0.0)); }
0131 };
0132 }
0133
0134
0135
0136
0137
0138 template<class T, int N>
0139 void BVH_Transform<T, N>::SetTransform (const BVH_MatNt& theTransform)
0140 {
0141 myTransform = theTransform;
0142 BVH::MatrixOp<T, N>::Inverse (myTransform, myTransformInversed);
0143 }
0144
0145
0146
0147
0148
0149 template<class T, int N>
0150 BVH_Box<T, N> BVH_Transform<T, N>::Apply (const BVH_Box<T, N>& theBox) const
0151 {
0152 typename BVH_Box<T, N>::BVH_VecNt aSize = theBox.Size();
0153
0154 BVH_Box<T, N> aBox;
0155 for (Standard_Integer aX = 0; aX <= 1; ++aX)
0156 {
0157 for (Standard_Integer aY = 0; aY <= 1; ++aY)
0158 {
0159 for (Standard_Integer aZ = 0; aZ <= 1; ++aZ)
0160 {
0161 typename BVH_Box<T, N>::BVH_VecNt aCorner = theBox.CornerMin() +
0162 BVH::UnitVector<T, N>::DX() * aSize * static_cast<T> (aX) +
0163 BVH::UnitVector<T, N>::DY() * aSize * static_cast<T> (aY) +
0164 BVH::UnitVector<T, N>::DZ() * aSize * static_cast<T> (aZ);
0165
0166 aBox.Add (BVH::MatrixOp<T, N>::Multiply (myTransform, aCorner));
0167 }
0168 }
0169 }
0170
0171 return aBox;
0172 }
0173
0174 #endif