Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:03:45

0001 // Copyright (c) 2016 OPEN CASCADE SAS
0002 //
0003 // This file is part of Open CASCADE Technology software library.
0004 //
0005 // This library is free software; you can redistribute it and/or modify it under
0006 // the terms of the GNU Lesser General Public License version 2.1 as published
0007 // by the Free Software Foundation, with special exception defined in the file
0008 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
0009 // distribution for complete text of the license and disclaimer of any warranty.
0010 //
0011 // Alternatively, this file may be used under the terms of Open CASCADE
0012 // commercial license or contractual agreement.
0013 
0014 #ifndef _gp_TrsfNLerp_HeaderFile
0015 #define _gp_TrsfNLerp_HeaderFile
0016 
0017 #include <gp_Trsf.hxx>
0018 #include <gp_QuaternionNLerp.hxx>
0019 #include <NCollection_Lerp.hxx>
0020 #include <Precision.hxx>
0021 
0022 //! Linear interpolation tool for transformation defined by gp_Trsf.
0023 //!
0024 //! In general case, there is a no well-defined interpolation between arbitrary transformations,
0025 //! because desired transient values might vary depending on application needs.
0026 //!
0027 //! This tool performs independent interpolation of three logical
0028 //! transformation parts - rotation (using gp_QuaternionNLerp), translation and scale factor.
0029 //! Result of such interpolation might be not what application expects,
0030 //! thus this tool might be considered for simple cases or for interpolating between small intervals.
0031 template<> class NCollection_Lerp<gp_Trsf>
0032 {
0033 public:
0034 
0035   //! Empty constructor
0036   NCollection_Lerp() {}
0037 
0038   //! Main constructor.
0039   NCollection_Lerp (const gp_Trsf& theStart, const gp_Trsf& theEnd)
0040   {
0041     Init (theStart, theEnd);
0042   }
0043 
0044   //! Initialize values.
0045   void Init (const gp_Trsf& theStart, const gp_Trsf& theEnd)
0046   {
0047     myTrsfStart = theStart;
0048     myTrsfEnd   = theEnd;
0049     myLocLerp  .Init (theStart.TranslationPart(), theEnd.TranslationPart());
0050     myRotLerp  .Init (theStart.GetRotation(),     theEnd.GetRotation());
0051     myScaleLerp.Init (theStart.ScaleFactor(),     theEnd.ScaleFactor());
0052   }
0053 
0054   //! Compute interpolated value between two values.
0055   //! @param theT normalized interpolation coefficient within [0, 1] range,
0056   //!             with 0 pointing to first value and 1 to the second value.
0057   //! @param theResult [out] interpolated value
0058   void Interpolate (double theT, gp_Trsf& theResult) const
0059   {
0060     if (Abs (theT - 0.0) < Precision::Confusion())
0061     {
0062       theResult = myTrsfStart;
0063       return;
0064     }
0065     else if (Abs (theT - 1.0) < Precision::Confusion())
0066     {
0067       theResult = myTrsfEnd;
0068       return;
0069     }
0070 
0071     gp_XYZ aLoc;
0072     gp_Quaternion aRot;
0073     Standard_Real aScale = 1.0;
0074     myLocLerp  .Interpolate (theT, aLoc);
0075     myRotLerp  .Interpolate (theT, aRot);
0076     myScaleLerp.Interpolate (theT, aScale);
0077     theResult = gp_Trsf();
0078     theResult.SetRotation (aRot);
0079     theResult.SetTranslationPart (aLoc);
0080     theResult.SetScaleFactor (aScale);
0081   }
0082 
0083 private:
0084   NCollection_Lerp<gp_XYZ>        myLocLerp;
0085   NCollection_Lerp<Standard_Real> myScaleLerp;
0086   gp_QuaternionNLerp              myRotLerp;
0087   gp_Trsf                         myTrsfStart;
0088   gp_Trsf                         myTrsfEnd;
0089 };
0090 
0091 typedef NCollection_Lerp<gp_Trsf> gp_TrsfNLerp;
0092 
0093 #endif // _gp_TrsfNLerp_HeaderFile