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