File indexing completed on 2026-09-23 09:17:38
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015 #ifndef _gp_GTrsf_HeaderFile
0016 #define _gp_GTrsf_HeaderFile
0017
0018 #include <gp_Ax1.hxx>
0019 #include <gp_Ax2.hxx>
0020 #include <gp_Mat.hxx>
0021 #include <gp_Trsf.hxx>
0022 #include <gp_TrsfForm.hxx>
0023 #include <gp_XYZ.hxx>
0024 #include <Standard_ConstructionError.hxx>
0025 #include <Standard_OutOfRange.hxx>
0026
0027
0028 #ifdef SetForm
0029 #undef SetForm
0030 #endif
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049
0050
0051
0052
0053
0054
0055
0056
0057 class gp_GTrsf
0058 {
0059 public:
0060 DEFINE_STANDARD_ALLOC
0061
0062
0063 constexpr gp_GTrsf() noexcept
0064 : loc(0.0, 0.0, 0.0),
0065 shape(gp_Identity),
0066 scale(1.0)
0067 {
0068 matrix.SetScale(1.0);
0069 }
0070
0071
0072
0073
0074 gp_GTrsf(const gp_Trsf& theT)
0075 {
0076 shape = theT.Form();
0077 matrix = theT.matrix;
0078 loc = theT.TranslationPart();
0079 scale = theT.ScaleFactor();
0080 }
0081
0082
0083
0084
0085 constexpr gp_GTrsf(const gp_Mat& theM, const gp_XYZ& theV) noexcept
0086 : matrix(theM),
0087 loc(theV),
0088 shape(gp_Other),
0089 scale(0.0)
0090 {
0091 }
0092
0093
0094
0095
0096
0097
0098
0099
0100 void SetAffinity(const gp_Ax1& theA1, const double theRatio);
0101
0102
0103
0104
0105
0106
0107
0108
0109
0110 void SetAffinity(const gp_Ax2& theA2, const double theRatio);
0111
0112
0113
0114
0115 void SetValue(const int theRow, const int theCol, const double theValue);
0116
0117
0118 constexpr void SetVectorialPart(const gp_Mat& theMatrix) noexcept
0119 {
0120 matrix = theMatrix;
0121 shape = gp_Other;
0122 scale = 0.0;
0123 }
0124
0125
0126
0127 Standard_EXPORT void SetTranslationPart(const gp_XYZ& theCoord);
0128
0129
0130 void SetTrsf(const gp_Trsf& theT)
0131 {
0132 shape = theT.shape;
0133 matrix = theT.matrix;
0134 loc = theT.loc;
0135 scale = theT.scale;
0136 }
0137
0138
0139
0140 constexpr bool IsNegative() const noexcept { return matrix.Determinant() < 0.0; }
0141
0142
0143
0144
0145
0146
0147
0148
0149
0150 constexpr bool IsSingular() const noexcept { return matrix.IsSingular(); }
0151
0152
0153
0154
0155
0156
0157 constexpr gp_TrsfForm Form() const noexcept { return shape; }
0158
0159
0160
0161
0162
0163
0164
0165
0166
0167 Standard_EXPORT void SetForm();
0168
0169
0170 constexpr const gp_XYZ& TranslationPart() const noexcept { return loc; }
0171
0172
0173
0174 constexpr const gp_Mat& VectorialPart() const noexcept { return matrix; }
0175
0176
0177
0178 constexpr double Value(const int theRow, const int theCol) const;
0179
0180 double operator()(const int theRow, const int theCol) const { return Value(theRow, theCol); }
0181
0182 Standard_EXPORT void Invert();
0183
0184
0185
0186
0187 [[nodiscard]] gp_GTrsf Inverted() const
0188 {
0189 gp_GTrsf aT = *this;
0190 aT.Invert();
0191 return aT;
0192 }
0193
0194
0195
0196
0197
0198
0199
0200
0201
0202
0203
0204
0205
0206
0207
0208
0209 [[nodiscard]] gp_GTrsf Multiplied(const gp_GTrsf& theT) const
0210 {
0211 gp_GTrsf aTres = *this;
0212 aTres.Multiply(theT);
0213 return aTres;
0214 }
0215
0216 [[nodiscard]] gp_GTrsf operator*(const gp_GTrsf& theT) const { return Multiplied(theT); }
0217
0218
0219
0220 Standard_EXPORT void Multiply(const gp_GTrsf& theT);
0221
0222 void operator*=(const gp_GTrsf& theT) { Multiply(theT); }
0223
0224
0225
0226
0227 Standard_EXPORT void PreMultiply(const gp_GTrsf& theT);
0228
0229 Standard_EXPORT void Power(const int theN);
0230
0231
0232
0233
0234
0235
0236
0237
0238
0239
0240
0241
0242
0243
0244 [[nodiscard]] gp_GTrsf Powered(const int theN) const
0245 {
0246 gp_GTrsf aT = *this;
0247 aT.Power(theN);
0248 return aT;
0249 }
0250
0251 constexpr void Transforms(gp_XYZ& theCoord) const noexcept;
0252
0253
0254 constexpr void Transforms(double& theX, double& theY, double& theZ) const noexcept;
0255
0256 gp_Trsf Trsf() const;
0257
0258
0259 template <class T>
0260 void GetMat4(NCollection_Mat4<T>& theMat) const
0261 {
0262 if (shape == gp_Identity)
0263 {
0264 theMat.InitIdentity();
0265 return;
0266 }
0267
0268 theMat.SetValue(0, 0, static_cast<T>(Value(1, 1)));
0269 theMat.SetValue(0, 1, static_cast<T>(Value(1, 2)));
0270 theMat.SetValue(0, 2, static_cast<T>(Value(1, 3)));
0271 theMat.SetValue(0, 3, static_cast<T>(Value(1, 4)));
0272 theMat.SetValue(1, 0, static_cast<T>(Value(2, 1)));
0273 theMat.SetValue(1, 1, static_cast<T>(Value(2, 2)));
0274 theMat.SetValue(1, 2, static_cast<T>(Value(2, 3)));
0275 theMat.SetValue(1, 3, static_cast<T>(Value(2, 4)));
0276 theMat.SetValue(2, 0, static_cast<T>(Value(3, 1)));
0277 theMat.SetValue(2, 1, static_cast<T>(Value(3, 2)));
0278 theMat.SetValue(2, 2, static_cast<T>(Value(3, 3)));
0279 theMat.SetValue(2, 3, static_cast<T>(Value(3, 4)));
0280 theMat.SetValue(3, 0, static_cast<T>(0));
0281 theMat.SetValue(3, 1, static_cast<T>(0));
0282 theMat.SetValue(3, 2, static_cast<T>(0));
0283 theMat.SetValue(3, 3, static_cast<T>(1));
0284 }
0285
0286
0287 template <class T>
0288 void SetMat4(const NCollection_Mat4<T>& theMat)
0289 {
0290 shape = gp_Other;
0291 scale = 0.0;
0292 matrix.SetValue(1, 1, theMat.GetValue(0, 0));
0293 matrix.SetValue(1, 2, theMat.GetValue(0, 1));
0294 matrix.SetValue(1, 3, theMat.GetValue(0, 2));
0295 matrix.SetValue(2, 1, theMat.GetValue(1, 0));
0296 matrix.SetValue(2, 2, theMat.GetValue(1, 1));
0297 matrix.SetValue(2, 3, theMat.GetValue(1, 2));
0298 matrix.SetValue(3, 1, theMat.GetValue(2, 0));
0299 matrix.SetValue(3, 2, theMat.GetValue(2, 1));
0300 matrix.SetValue(3, 3, theMat.GetValue(2, 2));
0301 loc.SetCoord(theMat.GetValue(0, 3), theMat.GetValue(1, 3), theMat.GetValue(2, 3));
0302 }
0303
0304
0305 Standard_EXPORT void DumpJson(Standard_OStream& theOStream, int theDepth = -1) const;
0306
0307 private:
0308 gp_Mat matrix;
0309 gp_XYZ loc;
0310 gp_TrsfForm shape;
0311 double scale;
0312 };
0313
0314
0315
0316 inline void gp_GTrsf::SetAffinity(const gp_Ax1& theA1, const double theRatio)
0317 {
0318 shape = gp_Other;
0319 scale = 0.0;
0320 matrix.SetDot(theA1.Direction().XYZ());
0321 matrix.Multiply(1.0 - theRatio);
0322 matrix.SetDiagonal(matrix.Value(1, 1) + theRatio,
0323 matrix.Value(2, 2) + theRatio,
0324 matrix.Value(3, 3) + theRatio);
0325 loc = theA1.Location().XYZ();
0326 loc.Reverse();
0327 loc.Multiply(matrix);
0328 loc.Add(theA1.Location().XYZ());
0329 }
0330
0331
0332
0333 inline void gp_GTrsf::SetAffinity(const gp_Ax2& theA2, const double theRatio)
0334 {
0335 shape = gp_Other;
0336 scale = 0.0;
0337 matrix.SetDot(theA2.Direction().XYZ());
0338 matrix.Multiply(theRatio - 1.);
0339 loc = theA2.Location().XYZ();
0340 loc.Reverse();
0341 loc.Multiply(matrix);
0342 matrix.SetDiagonal(matrix.Value(1, 1) + 1., matrix.Value(2, 2) + 1., matrix.Value(3, 3) + 1.);
0343 }
0344
0345
0346
0347 inline void gp_GTrsf::SetValue(const int theRow, const int theCol, const double theValue)
0348 {
0349 Standard_OutOfRange_Raise_if(theRow < 1 || theRow > 3 || theCol < 1 || theCol > 4, " ");
0350 if (theCol == 4)
0351 {
0352 loc.SetCoord(theRow, theValue);
0353 if (shape == gp_Identity)
0354 {
0355 shape = gp_Translation;
0356 }
0357 return;
0358 }
0359 else
0360 {
0361 if (!(shape == gp_Other) && !(scale == 1.0))
0362 {
0363 matrix.Multiply(scale);
0364 }
0365 matrix.SetValue(theRow, theCol, theValue);
0366 shape = gp_Other;
0367 scale = 0.0;
0368 return;
0369 }
0370 }
0371
0372
0373
0374 inline constexpr double gp_GTrsf::Value(const int theRow, const int theCol) const
0375 {
0376 Standard_OutOfRange_Raise_if(theRow < 1 || theRow > 3 || theCol < 1 || theCol > 4, " ");
0377 if (theCol == 4)
0378 {
0379 return loc.Coord(theRow);
0380 }
0381 if (shape == gp_Other)
0382 {
0383 return matrix.myMat[theRow - 1][theCol - 1];
0384 }
0385 return scale * matrix.myMat[theRow - 1][theCol - 1];
0386 }
0387
0388
0389
0390 inline constexpr void gp_GTrsf::Transforms(gp_XYZ& theCoord) const noexcept
0391 {
0392 theCoord.Multiply(matrix);
0393 if (!(shape == gp_Other) && !(scale == 1.0))
0394 {
0395 theCoord.Multiply(scale);
0396 }
0397 theCoord.Add(loc);
0398 }
0399
0400
0401
0402 inline constexpr void gp_GTrsf::Transforms(double& theX, double& theY, double& theZ) const noexcept
0403 {
0404 gp_XYZ aTriplet(theX, theY, theZ);
0405 aTriplet.Multiply(matrix);
0406 if (!(shape == gp_Other) && !(scale == 1.0))
0407 {
0408 aTriplet.Multiply(scale);
0409 }
0410 aTriplet.Add(loc);
0411 aTriplet.Coord(theX, theY, theZ);
0412 }
0413
0414
0415
0416 inline gp_Trsf gp_GTrsf::Trsf() const
0417 {
0418 if (Form() == gp_Other)
0419 {
0420 throw Standard_ConstructionError("gp_GTrsf::Trsf() - non-orthogonal GTrsf");
0421 }
0422 gp_Trsf aT;
0423 aT.shape = shape;
0424 aT.scale = scale;
0425 aT.matrix = matrix;
0426 aT.loc = loc;
0427 return aT;
0428 }
0429
0430 #endif