1 // Copyright (c) 2016 OPEN CASCADE SAS
3 // This file is part of Open CASCADE Technology software library.
5 // This library is free software; you can redistribute it and/or modify it under
6 // the terms of the GNU Lesser General Public License version 2.1 as published
7 // by the Free Software Foundation, with special exception defined in the file
8 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
9 // distribution for complete text of the license and disclaimer of any warranty.
11 // Alternatively, this file may be used under the terms of Open CASCADE
12 // commercial license or contractual agreement.
14 #ifndef _gp_TrsfNLerp_HeaderFile
15 #define _gp_TrsfNLerp_HeaderFile
17 #include <gp_Trsf.hxx>
18 #include <gp_QuaternionNLerp.hxx>
19 #include <NCollection_Lerp.hxx>
20 #include <Precision.hxx>
22 //! Linear interpolation tool for transformation defined by gp_Trsf.
24 //! In general case, there is a no well-defined interpolation between arbitrary transformations,
25 //! because desired transient values might vary depending on application needs.
27 //! This tool performs independent interpolation of three logical
28 //! transformation parts - rotation (using gp_QuaternionNLerp), translation and scale factor.
29 //! Result of such interpolation might be not what application expects,
30 //! thus this tool might be considered for simple cases or for interpolating between small intervals.
31 template<> class NCollection_Lerp<gp_Trsf>
39 NCollection_Lerp (const gp_Trsf& theStart, const gp_Trsf& theEnd)
41 Init (theStart, theEnd);
44 //! Initialize values.
45 void Init (const gp_Trsf& theStart, const gp_Trsf& theEnd)
47 myTrsfStart = theStart;
49 myLocLerp .Init (theStart.TranslationPart(), theEnd.TranslationPart());
50 myRotLerp .Init (theStart.GetRotation(), theEnd.GetRotation());
51 myScaleLerp.Init (theStart.ScaleFactor(), theEnd.ScaleFactor());
54 //! Compute interpolated value between two values.
55 //! @param theT normalized interpolation coefficient within [0, 1] range,
56 //! with 0 pointing to first value and 1 to the second value.
57 //! @param theResult [out] interpolated value
58 void Interpolate (double theT, gp_Trsf& theResult) const
60 if (Abs (theT - 0.0) < Precision::Confusion())
62 theResult = myTrsfStart;
65 else if (Abs (theT - 1.0) < Precision::Confusion())
67 theResult = myTrsfEnd;
73 Standard_Real aScale = 1.0;
74 myLocLerp .Interpolate (theT, aLoc);
75 myRotLerp .Interpolate (theT, aRot);
76 myScaleLerp.Interpolate (theT, aScale);
77 theResult = gp_Trsf();
78 theResult.SetRotation (aRot);
79 theResult.SetTranslationPart (aLoc);
80 theResult.SetScaleFactor (aScale);
84 NCollection_Lerp<gp_XYZ> myLocLerp;
85 NCollection_Lerp<Standard_Real> myScaleLerp;
86 gp_QuaternionNLerp myRotLerp;
91 typedef NCollection_Lerp<gp_Trsf> gp_TrsfNLerp;
93 #endif // _gp_TrsfNLerp_HeaderFile