fc552d84 |
1 | // Author: Kirill Gavrilov |
2 | // Copyright (c) 2015-2019 OPEN CASCADE SAS |
3 | // |
4 | // This file is part of Open CASCADE Technology software library. |
5 | // |
6 | // This library is free software; you can redistribute it and/or modify it under |
7 | // the terms of the GNU Lesser General Public License version 2.1 as published |
8 | // by the Free Software Foundation, with special exception defined in the file |
9 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT |
10 | // distribution for complete text of the license and disclaimer of any warranty. |
11 | // |
12 | // Alternatively, this file may be used under the terms of Open CASCADE |
13 | // commercial license or contractual agreement. |
14 | |
15 | #include <RWMesh_CoordinateSystemConverter.hxx> |
16 | |
17 | #include <gp_Quaternion.hxx> |
18 | |
19 | // ================================================================ |
20 | // Function : RWMesh_CoordinateSystemConverter |
21 | // Purpose : |
22 | // ================================================================ |
23 | RWMesh_CoordinateSystemConverter::RWMesh_CoordinateSystemConverter() |
24 | : myInputLengthUnit (-1.0), |
25 | myOutputLengthUnit(-1.0), |
26 | myHasInputAx3 (Standard_False), |
27 | myHasOutputAx3(Standard_False), |
28 | // |
29 | myUnitFactor (1), |
30 | myHasScale (Standard_False), |
31 | myIsEmpty (Standard_True) |
32 | { |
33 | // |
34 | } |
35 | |
36 | // ================================================================ |
37 | // Function : Init |
38 | // Purpose : |
39 | // ================================================================ |
40 | void RWMesh_CoordinateSystemConverter::Init (const gp_Ax3& theInputSystem, |
41 | Standard_Real theInputLengthUnit, |
42 | const gp_Ax3& theOutputSystem, |
43 | Standard_Real theOutputLengthUnit) |
44 | { |
45 | myInputLengthUnit = theInputLengthUnit; |
46 | myOutputLengthUnit = theOutputLengthUnit; |
47 | myInputAx3 = theInputSystem; |
48 | myOutputAx3 = theOutputSystem; |
49 | if (theInputLengthUnit > 0.0 |
50 | && theOutputLengthUnit > 0.0) |
51 | { |
52 | myUnitFactor = theInputLengthUnit / theOutputLengthUnit; |
53 | myHasScale = Abs(myUnitFactor - 1.0) > gp::Resolution(); |
54 | } |
55 | else |
56 | { |
57 | myUnitFactor = 1.0; |
58 | myHasScale = Standard_False; |
59 | } |
60 | |
61 | gp_Trsf aTrsf; |
62 | if (myHasInputAx3 |
63 | && myHasOutputAx3) |
64 | { |
65 | aTrsf.SetTransformation (theOutputSystem, theInputSystem); |
66 | if (aTrsf.TranslationPart().IsEqual (gp_XYZ (0.0, 0.0, 0.0), gp::Resolution()) |
67 | && aTrsf.GetRotation().IsEqual (gp_Quaternion())) |
68 | { |
69 | aTrsf = gp_Trsf(); |
70 | } |
71 | } |
72 | |
73 | myTrsf = aTrsf; |
74 | myTrsfInv = aTrsf.Inverted(); |
75 | myTrsf.GetMat4 (myNormTrsf); |
76 | myIsEmpty = !myHasScale && myTrsf.Form() == gp_Identity; |
77 | } |