Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-10-05 09:21:44

0001 // Created on: 2013-12-20
0002 // Created by: Denis BOGOLEPOV
0003 // Copyright (c) 2013-2014 OPEN CASCADE SAS
0004 //
0005 // This file is part of Open CASCADE Technology software library.
0006 //
0007 // This library is free software; you can redistribute it and/or modify it under
0008 // the terms of the GNU Lesser General Public License version 2.1 as published
0009 // by the Free Software Foundation, with special exception defined in the file
0010 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
0011 // distribution for complete text of the license and disclaimer of any warranty.
0012 //
0013 // Alternatively, this file may be used under the terms of Open CASCADE
0014 // commercial license or contractual agreement.
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 //! Abstract properties of geometric object.
0024 class BVH_Properties : public Standard_Transient
0025 {
0026   DEFINE_STANDARD_RTTIEXT(BVH_Properties, Standard_Transient)
0027 public:
0028   //! Releases resources of object properties.
0029   Standard_EXPORT ~BVH_Properties() override = 0;
0030 };
0031 
0032 //! Stores transform properties of geometric object.
0033 template <class T, int N>
0034 class BVH_Transform : public BVH_Properties
0035 {
0036 public:
0037   //! Type of transformation matrix.
0038   typedef typename BVH::MatrixType<T, N>::Type BVH_MatNt;
0039 
0040 public:
0041   //! Creates new identity transformation.
0042   BVH_Transform() = default;
0043 
0044   //! Creates new transformation with specified matrix.
0045   BVH_Transform(const BVH_MatNt& theTransform)
0046       : myTransform(theTransform)
0047   {
0048   }
0049 
0050   //! Releases resources of transformation properties.
0051   ~BVH_Transform() override = default;
0052 
0053   //! Returns transformation matrix.
0054   const BVH_MatNt& Transform() const { return myTransform; }
0055 
0056   //! Sets new transformation matrix.
0057   void SetTransform(const BVH_MatNt& theTransform);
0058 
0059   //! Returns inversed transformation matrix.
0060   const BVH_MatNt& Inversed() const { return myTransformInversed; }
0061 
0062   //! Applies transformation matrix to bounding box.
0063   BVH_Box<T, N> Apply(const BVH_Box<T, N>& theBox) const;
0064 
0065 protected:
0066   BVH_MatNt myTransform;         //!< Transformation matrix
0067   BVH_MatNt myTransformInversed; //!< Inversed transformation matrix
0068 };
0069 
0070 namespace BVH
0071 {
0072 template <class T, int N>
0073 struct MatrixOp
0074 {
0075   // Not implemented
0076 };
0077 
0078 template <class T>
0079 struct MatrixOp<T, 4>
0080 {
0081   typedef typename BVH::MatrixType<T, 4>::Type BVH_Mat4t;
0082 
0083   static void Inverse(const BVH_Mat4t& theIn, BVH_Mat4t& theOut) { theIn.Inverted(theOut); }
0084 
0085   typedef typename BVH::VectorType<T, 4>::Type BVH_Vec4t;
0086 
0087   static BVH_Vec4t Multiply(const BVH_Mat4t& theMat, const BVH_Vec4t& theVec)
0088   {
0089     BVH_Vec4t aOut = theMat * theVec;
0090     return aOut * static_cast<T>(1.0 / aOut.w());
0091   }
0092 };
0093 
0094 template <class T, int N>
0095 struct UnitVector
0096 {
0097   // Not implemented
0098 };
0099 
0100 template <class T>
0101 struct UnitVector<T, 2>
0102 {
0103   typedef typename BVH::VectorType<T, 2>::Type BVH_Vec2t;
0104 
0105   static BVH_Vec2t DX() { return BVH_Vec2t(static_cast<T>(1.0), static_cast<T>(0.0)); }
0106 
0107   static BVH_Vec2t DY() { return BVH_Vec2t(static_cast<T>(0.0), static_cast<T>(1.0)); }
0108 
0109   static BVH_Vec2t DZ() { return BVH_Vec2t(static_cast<T>(0.0), static_cast<T>(0.0)); }
0110 };
0111 
0112 template <class T>
0113 struct UnitVector<T, 3>
0114 {
0115   typedef typename BVH::VectorType<T, 3>::Type BVH_Vec3t;
0116 
0117   static BVH_Vec3t DX()
0118   {
0119     return BVH_Vec3t(static_cast<T>(1.0), static_cast<T>(0.0), static_cast<T>(0.0));
0120   }
0121 
0122   static BVH_Vec3t DY()
0123   {
0124     return BVH_Vec3t(static_cast<T>(0.0), static_cast<T>(1.0), static_cast<T>(0.0));
0125   }
0126 
0127   static BVH_Vec3t DZ()
0128   {
0129     return BVH_Vec3t(static_cast<T>(0.0), static_cast<T>(0.0), static_cast<T>(1.0));
0130   }
0131 };
0132 
0133 template <class T>
0134 struct UnitVector<T, 4>
0135 {
0136   typedef typename BVH::VectorType<T, 4>::Type BVH_Vec4t;
0137 
0138   static BVH_Vec4t DX()
0139   {
0140     return BVH_Vec4t(static_cast<T>(1.0),
0141                      static_cast<T>(0.0),
0142                      static_cast<T>(0.0),
0143                      static_cast<T>(0.0));
0144   }
0145 
0146   static BVH_Vec4t DY()
0147   {
0148     return BVH_Vec4t(static_cast<T>(0.0),
0149                      static_cast<T>(1.0),
0150                      static_cast<T>(0.0),
0151                      static_cast<T>(0.0));
0152   }
0153 
0154   static BVH_Vec4t DZ()
0155   {
0156     return BVH_Vec4t(static_cast<T>(0.0),
0157                      static_cast<T>(0.0),
0158                      static_cast<T>(1.0),
0159                      static_cast<T>(0.0));
0160   }
0161 };
0162 } // namespace BVH
0163 
0164 //=================================================================================================
0165 
0166 template <class T, int N>
0167 void BVH_Transform<T, N>::SetTransform(const BVH_MatNt& theTransform)
0168 {
0169   myTransform = theTransform;
0170   BVH::MatrixOp<T, N>::Inverse(myTransform, myTransformInversed);
0171 }
0172 
0173 //=================================================================================================
0174 
0175 template <class T, int N>
0176 BVH_Box<T, N> BVH_Transform<T, N>::Apply(const BVH_Box<T, N>& theBox) const
0177 {
0178   typename BVH_Box<T, N>::BVH_VecNt aSize = theBox.Size();
0179 
0180   BVH_Box<T, N> aBox;
0181   for (int aX = 0; aX <= 1; ++aX)
0182   {
0183     for (int aY = 0; aY <= 1; ++aY)
0184     {
0185       for (int aZ = 0; aZ <= 1; ++aZ)
0186       {
0187         typename BVH_Box<T, N>::BVH_VecNt aCorner =
0188           theBox.CornerMin() + BVH::UnitVector<T, N>::DX() * aSize * static_cast<T>(aX)
0189           + BVH::UnitVector<T, N>::DY() * aSize * static_cast<T>(aY)
0190           + BVH::UnitVector<T, N>::DZ() * aSize * static_cast<T>(aZ);
0191 
0192         aBox.Add(BVH::MatrixOp<T, N>::Multiply(myTransform, aCorner));
0193       }
0194     }
0195   }
0196 
0197   return aBox;
0198 }
0199 
0200 #endif // _BVH_Properties_Header