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