File indexing completed on 2025-01-18 10:04:43
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015 #ifndef _RWMesh_CoordinateSystemConverter_HeaderFile
0016 #define _RWMesh_CoordinateSystemConverter_HeaderFile
0017
0018 #include <RWMesh_CoordinateSystem.hxx>
0019
0020 #include <gp_Ax3.hxx>
0021 #include <gp_XYZ.hxx>
0022 #include <gp_Trsf.hxx>
0023 #include <Graphic3d_Vec.hxx>
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046 class RWMesh_CoordinateSystemConverter
0047 {
0048 public:
0049
0050
0051 static gp_Ax3 StandardCoordinateSystem (RWMesh_CoordinateSystem theSys)
0052 {
0053 switch (theSys)
0054 {
0055 case RWMesh_CoordinateSystem_posYfwd_posZup: return gp_Ax3 (gp::Origin(), gp::DZ(), gp::DX());
0056 case RWMesh_CoordinateSystem_negZfwd_posYup: return gp_Ax3 (gp::Origin(), gp::DY(), gp::DX());
0057 case RWMesh_CoordinateSystem_Undefined: break;
0058 }
0059 return gp_Ax3();
0060 }
0061
0062 public:
0063
0064
0065 Standard_EXPORT RWMesh_CoordinateSystemConverter();
0066
0067
0068 Standard_Boolean IsEmpty() const { return myIsEmpty; }
0069
0070
0071
0072 Standard_Real InputLengthUnit() const { return myInputLengthUnit; }
0073
0074
0075 void SetInputLengthUnit (Standard_Real theInputScale)
0076 {
0077 Init (myInputAx3, theInputScale, myOutputAx3, myOutputLengthUnit);
0078 }
0079
0080
0081
0082 Standard_Real OutputLengthUnit() const { return myOutputLengthUnit; }
0083
0084
0085 void SetOutputLengthUnit (Standard_Real theOutputScale)
0086 {
0087 Init (myInputAx3, myInputLengthUnit, myOutputAx3, theOutputScale);
0088 }
0089
0090
0091 Standard_Boolean HasInputCoordinateSystem() const { return myHasInputAx3; }
0092
0093
0094 const gp_Ax3& InputCoordinateSystem() const { return myInputAx3; }
0095
0096
0097 void SetInputCoordinateSystem (const gp_Ax3& theSysFrom)
0098 {
0099 myHasInputAx3 = Standard_True;
0100 Init (theSysFrom, myInputLengthUnit, myOutputAx3, myOutputLengthUnit);
0101 }
0102
0103
0104 void SetInputCoordinateSystem (RWMesh_CoordinateSystem theSysFrom)
0105 {
0106 myHasInputAx3 = theSysFrom != RWMesh_CoordinateSystem_Undefined;
0107 Init (StandardCoordinateSystem (theSysFrom), myInputLengthUnit, myOutputAx3, myOutputLengthUnit);
0108 }
0109
0110
0111 Standard_Boolean HasOutputCoordinateSystem() const { return myHasOutputAx3; }
0112
0113
0114 const gp_Ax3& OutputCoordinateSystem() const { return myOutputAx3; }
0115
0116
0117 void SetOutputCoordinateSystem (const gp_Ax3& theSysTo)
0118 {
0119 myHasOutputAx3 = Standard_True;
0120 Init (myInputAx3, myInputLengthUnit, theSysTo, myOutputLengthUnit);
0121 }
0122
0123
0124 void SetOutputCoordinateSystem (RWMesh_CoordinateSystem theSysTo)
0125 {
0126 myHasOutputAx3 = theSysTo != RWMesh_CoordinateSystem_Undefined;
0127 Init (myInputAx3, myInputLengthUnit, StandardCoordinateSystem (theSysTo), myOutputLengthUnit);
0128 }
0129
0130
0131 Standard_EXPORT void Init (const gp_Ax3& theInputSystem,
0132 Standard_Real theInputLengthUnit,
0133 const gp_Ax3& theOutputSystem,
0134 Standard_Real theOutputLengthUnit);
0135
0136 public:
0137
0138
0139 void TransformTransformation (gp_Trsf& theTrsf) const
0140 {
0141 if (myHasScale)
0142 {
0143 gp_XYZ aTransPart = theTrsf.TranslationPart();
0144 aTransPart *= myUnitFactor;
0145 theTrsf.SetTranslationPart (aTransPart);
0146 }
0147 if (myTrsf.Form() != gp_Identity)
0148 {
0149 theTrsf = myTrsf * theTrsf * myTrsfInv;
0150 }
0151 }
0152
0153
0154 void TransformPosition (gp_XYZ& thePos) const
0155 {
0156 if (myHasScale)
0157 {
0158 thePos *= myUnitFactor;
0159 }
0160 if (myTrsf.Form() != gp_Identity)
0161 {
0162 myTrsf.Transforms (thePos);
0163 }
0164 }
0165
0166
0167 void TransformNormal (Graphic3d_Vec3& theNorm) const
0168 {
0169 if (myTrsf.Form() != gp_Identity)
0170 {
0171 const Graphic3d_Vec4 aNorm = myNormTrsf * Graphic3d_Vec4 (theNorm, 0.0f);
0172 theNorm = aNorm.xyz();
0173 }
0174 }
0175
0176 private:
0177
0178 gp_Ax3 myInputAx3;
0179 gp_Ax3 myOutputAx3;
0180 Standard_Real myInputLengthUnit;
0181 Standard_Real myOutputLengthUnit;
0182 Standard_Boolean myHasInputAx3;
0183 Standard_Boolean myHasOutputAx3;
0184
0185 gp_Trsf myTrsf;
0186 gp_Trsf myTrsfInv;
0187 Graphic3d_Mat4 myNormTrsf;
0188 Standard_Real myUnitFactor;
0189 Standard_Boolean myHasScale;
0190 Standard_Boolean myIsEmpty;
0191
0192 };
0193
0194 #endif