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