Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-16 09:17:18

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
0031 //! intervals.
0032 template <>
0033 class NCollection_Lerp<gp_Trsf>
0034 {
0035 public:
0036   //! Empty constructor
0037   NCollection_Lerp() = default;
0038 
0039   //! Main constructor.
0040   NCollection_Lerp(const gp_Trsf& theStart, const gp_Trsf& theEnd) { Init(theStart, theEnd); }
0041 
0042   //! Initialize values.
0043   void Init(const gp_Trsf& theStart, const gp_Trsf& theEnd)
0044   {
0045     myTrsfStart = theStart;
0046     myTrsfEnd   = theEnd;
0047     myLocLerp.Init(theStart.TranslationPart(), theEnd.TranslationPart());
0048     myRotLerp.Init(theStart.GetRotation(), theEnd.GetRotation());
0049     myScaleLerp.Init(theStart.ScaleFactor(), theEnd.ScaleFactor());
0050   }
0051 
0052   //! Compute interpolated value between two values.
0053   //! @param theT normalized interpolation coefficient within [0, 1] range,
0054   //!             with 0 pointing to first value and 1 to the second value.
0055   //! @param[out] theResult  interpolated value
0056   void Interpolate(double theT, gp_Trsf& theResult) const
0057   {
0058     if (std::abs(theT - 0.0) < Precision::Confusion())
0059     {
0060       theResult = myTrsfStart;
0061       return;
0062     }
0063     else if (std::abs(theT - 1.0) < Precision::Confusion())
0064     {
0065       theResult = myTrsfEnd;
0066       return;
0067     }
0068 
0069     gp_XYZ        aLoc;
0070     gp_Quaternion aRot;
0071     double        aScale = 1.0;
0072     myLocLerp.Interpolate(theT, aLoc);
0073     myRotLerp.Interpolate(theT, aRot);
0074     myScaleLerp.Interpolate(theT, aScale);
0075     theResult = gp_Trsf();
0076     theResult.SetRotation(aRot);
0077     theResult.SetTranslationPart(aLoc);
0078     theResult.SetScaleFactor(aScale);
0079   }
0080 
0081 private:
0082   NCollection_Lerp<gp_XYZ> myLocLerp;
0083   NCollection_Lerp<double> myScaleLerp;
0084   gp_QuaternionNLerp       myRotLerp;
0085   gp_Trsf                  myTrsfStart;
0086   gp_Trsf                  myTrsfEnd;
0087 };
0088 
0089 #endif // _gp_TrsfNLerp_HeaderFile