b311480e |
1 | // Created on: 1995-04-05 |
2 | // Created by: Christophe MARION |
3 | // Copyright (c) 1995-1999 Matra Datavision |
973c2be1 |
4 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
b311480e |
5 | // |
973c2be1 |
6 | // This file is part of Open CASCADE Technology software library. |
b311480e |
7 | // |
d5f74e42 |
8 | // This library is free software; you can redistribute it and/or modify it under |
9 | // the terms of the GNU Lesser General Public License version 2.1 as published |
973c2be1 |
10 | // by the Free Software Foundation, with special exception defined in the file |
11 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT |
12 | // distribution for complete text of the license and disclaimer of any warranty. |
b311480e |
13 | // |
973c2be1 |
14 | // Alternatively, this file may be used under the terms of Open CASCADE |
15 | // commercial license or contractual agreement. |
7fd59977 |
16 | |
a13df0fe |
17 | #include <HLRTest_Projector.hxx> |
42cf5bc1 |
18 | |
19 | #include <Draw_Display.hxx> |
a13df0fe |
20 | #include <gp_Ax3.hxx> |
42cf5bc1 |
21 | #include <HLRAlgo_Projector.hxx> |
7fd59977 |
22 | |
a13df0fe |
23 | IMPLEMENT_STANDARD_RTTIEXT(HLRTest_Projector, Draw_Drawable3D) |
92efcf78 |
24 | |
7fd59977 |
25 | //======================================================================= |
26 | //function : HLRTest_Projector |
a13df0fe |
27 | //purpose : |
7fd59977 |
28 | //======================================================================= |
a13df0fe |
29 | HLRTest_Projector::HLRTest_Projector (const HLRAlgo_Projector& P) |
30 | : myProjector(P) |
7fd59977 |
31 | { |
a13df0fe |
32 | // |
7fd59977 |
33 | } |
34 | |
35 | //======================================================================= |
36 | //function : DrawOn |
a13df0fe |
37 | //purpose : |
7fd59977 |
38 | //======================================================================= |
a13df0fe |
39 | void HLRTest_Projector::DrawOn (Draw_Display&) const |
7fd59977 |
40 | { |
a13df0fe |
41 | // |
7fd59977 |
42 | } |
43 | |
44 | //======================================================================= |
45 | //function : Copy |
a13df0fe |
46 | //purpose : |
7fd59977 |
47 | //======================================================================= |
a13df0fe |
48 | Handle(Draw_Drawable3D) HLRTest_Projector::Copy() const |
7fd59977 |
49 | { |
50 | return new HLRTest_Projector(myProjector); |
51 | } |
52 | |
53 | //======================================================================= |
54 | //function : Dump |
a13df0fe |
55 | //purpose : |
7fd59977 |
56 | //======================================================================= |
a13df0fe |
57 | void HLRTest_Projector::Dump (Standard_OStream& S) const |
7fd59977 |
58 | { |
59 | S << "Projector : \n"; |
60 | if (myProjector.Perspective()) |
61 | S << "perspective, focal = " << myProjector.Focus() << "\n"; |
62 | |
63 | for (Standard_Integer i = 1; i <= 3; i++) { |
64 | |
65 | for (Standard_Integer j = 1; j <= 4; j++) { |
04232180 |
66 | S << std::setw(15) << myProjector.Transformation().Value(i,j); |
7fd59977 |
67 | } |
68 | S << "\n"; |
69 | } |
04232180 |
70 | S << std::endl; |
7fd59977 |
71 | } |
72 | |
73 | //======================================================================= |
a13df0fe |
74 | //function : Save |
75 | //purpose : |
7fd59977 |
76 | //======================================================================= |
a13df0fe |
77 | void HLRTest_Projector::Save (Standard_OStream& theStream) const |
78 | { |
79 | theStream << (myProjector.Perspective() ? "1" : "0") << "\n"; |
80 | if (myProjector.Perspective()) |
81 | { |
82 | theStream << myProjector.Focus() << "\n"; |
83 | } |
84 | |
85 | const gp_Trsf aTransformation = myProjector.Transformation(); |
86 | const gp_XYZ aTranslationVector = aTransformation.TranslationPart(); |
87 | const gp_Mat aMatrix = aTransformation.VectorialPart(); |
7fd59977 |
88 | |
a13df0fe |
89 | theStream << aMatrix(1, 1) << " "; |
90 | theStream << aMatrix(1, 2) << " "; |
91 | theStream << aMatrix(1, 3) << " "; |
92 | theStream << aTranslationVector.Coord (1) << " "; |
93 | theStream << "\n"; |
94 | theStream << aMatrix(2, 1) << " "; |
95 | theStream << aMatrix(2, 2) << " "; |
96 | theStream << aMatrix(2, 3) << " "; |
97 | theStream << aTranslationVector.Coord (2) << " "; |
98 | theStream << "\n"; |
99 | theStream << aMatrix(3, 1) << " "; |
100 | theStream << aMatrix(3, 2) << " "; |
101 | theStream << aMatrix(3, 3) << " "; |
102 | theStream << aTranslationVector.Coord (3) << " "; |
103 | theStream << "\n"; |
104 | } |
105 | |
106 | //======================================================================= |
107 | //function : Restore |
108 | //purpose : |
109 | //======================================================================= |
110 | Handle(Draw_Drawable3D) HLRTest_Projector::Restore (Standard_IStream& theStream) |
7fd59977 |
111 | { |
a13df0fe |
112 | Standard_Boolean aPerspective = false; |
113 | Standard_Real aFocus = 1.0; |
114 | Standard_Real aDirVect1[3], aDirVect2[3], aDirVect3[3]; |
115 | Standard_Real aTranslationVector[3]; |
116 | theStream >> aPerspective; |
117 | if (aPerspective) |
118 | { |
119 | theStream >> aFocus; |
120 | } |
121 | theStream >> aDirVect1[0] >> aDirVect1[1] >> aDirVect1[2] >> aTranslationVector[0]; |
122 | theStream >> aDirVect2[0] >> aDirVect2[1] >> aDirVect2[2] >> aTranslationVector[1]; |
123 | theStream >> aDirVect3[0] >> aDirVect3[1] >> aDirVect3[2] >> aTranslationVector[2]; |
124 | |
125 | gp_Dir aDir1 (aDirVect1[0], aDirVect1[1], aDirVect1[2]); |
126 | gp_Dir aDir2 (aDirVect2[0], aDirVect2[1], aDirVect2[2]); |
127 | gp_Dir aDir3 (aDirVect3[0], aDirVect3[1], aDirVect3[2]); |
128 | gp_Ax3 anAxis (gp_Pnt (0, 0, 0), aDir3, aDir1); |
129 | aDir3.Cross (aDir1); |
130 | if (aDir3.Dot (aDir2) < 0.0) |
131 | { |
132 | anAxis.YReverse(); |
133 | } |
134 | gp_Trsf aTransformation; |
135 | aTransformation.SetTransformation (anAxis); |
136 | aTransformation.SetTranslationPart (gp_Vec (aTranslationVector[0], aTranslationVector[1], aTranslationVector[2])); |
137 | |
138 | HLRAlgo_Projector anAlgoProtector (aTransformation, aPerspective, aFocus); |
139 | Handle(HLRTest_Projector) aTestProjector = new HLRTest_Projector (anAlgoProtector); |
140 | return aTestProjector; |
7fd59977 |
141 | } |
142 | |
a13df0fe |
143 | //======================================================================= |
144 | //function : Whatis |
145 | //purpose : |
146 | //======================================================================= |
147 | void HLRTest_Projector::Whatis (Draw_Interpretor& I) const |
148 | { |
149 | I << "projector"; |
150 | } |