1 // Copyright (c) 2016 OPEN CASCADE SAS 2 // 3 // This file is part of Open CASCADE Technology software library. 4 // 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. 10 // 11 // Alternatively, this file may be used under the terms of Open CASCADE 12 // commercial license or contractual agreement. 13 14 #ifndef _gp_TrsfNLerp_HeaderFile 15 #define _gp_TrsfNLerp_HeaderFile 16 17 #include <gp_Trsf.hxx> 18 #include <gp_QuaternionNLerp.hxx> 19 #include <NCollection_Lerp.hxx> 20 #include <Precision.hxx> 21 22 //! Linear interpolation tool for transformation defined by gp_Trsf. 23 //! 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. 26 //! 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> 32 { 33 public: 34 35 //! Empty constructor NCollection_Lerp()36 NCollection_Lerp() {} 37 38 //! Main constructor. NCollection_Lerp(const gp_Trsf & theStart,const gp_Trsf & theEnd)39 NCollection_Lerp (const gp_Trsf& theStart, const gp_Trsf& theEnd) 40 { 41 Init (theStart, theEnd); 42 } 43 44 //! Initialize values. Init(const gp_Trsf & theStart,const gp_Trsf & theEnd)45 void Init (const gp_Trsf& theStart, const gp_Trsf& theEnd) 46 { 47 myTrsfStart = theStart; 48 myTrsfEnd = theEnd; 49 myLocLerp .Init (theStart.TranslationPart(), theEnd.TranslationPart()); 50 myRotLerp .Init (theStart.GetRotation(), theEnd.GetRotation()); 51 myScaleLerp.Init (theStart.ScaleFactor(), theEnd.ScaleFactor()); 52 } 53 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 Interpolate(double theT,gp_Trsf & theResult) const58 void Interpolate (double theT, gp_Trsf& theResult) const 59 { 60 if (Abs (theT - 0.0) < Precision::Confusion()) 61 { 62 theResult = myTrsfStart; 63 return; 64 } 65 else if (Abs (theT - 1.0) < Precision::Confusion()) 66 { 67 theResult = myTrsfEnd; 68 return; 69 } 70 71 gp_XYZ aLoc; 72 gp_Quaternion aRot; 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); 81 } 82 83 private: 84 NCollection_Lerp<gp_XYZ> myLocLerp; 85 NCollection_Lerp<Standard_Real> myScaleLerp; 86 gp_QuaternionNLerp myRotLerp; 87 gp_Trsf myTrsfStart; 88 gp_Trsf myTrsfEnd; 89 }; 90 91 typedef NCollection_Lerp<gp_Trsf> gp_TrsfNLerp; 92 93 #endif // _gp_TrsfNLerp_HeaderFile 94