f62cf4137340a53881e7e729e6594032473cef91
[occt.git] / src / Select3D / Select3D_Projector.lxx
1 // Created on: 1992-07-09
2 // Created by: Christophe MARION
3 // Copyright (c) 1992-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
5 //
6 // This file is part of Open CASCADE Technology software library.
7 //
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
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.
13 //
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
16
17 #include <Graphic3d_Mat4d.hxx>
18 #include <Standard_Assert.hxx>
19 #include <gp_Vec.hxx>
20 #include <gp_Pnt.hxx>
21 #include <gp_Lin.hxx>
22
23 //=======================================================================
24 //function : Perspective
25 //purpose  :
26 //=======================================================================
27 inline Standard_Boolean Select3D_Projector::Perspective() const
28 {
29   return myPersp;
30 }
31
32 //=======================================================================
33 //function : ProjectionTransformation
34 //purpose  :
35 //=======================================================================
36 inline const Graphic3d_Mat4d& Select3D_Projector::Projection() const
37 {
38   return myProjTrsf;
39 }
40
41 //=======================================================================
42 //function : Transformation
43 //purpose  :
44 //=======================================================================
45 inline const gp_GTrsf& Select3D_Projector::Transformation() const
46 {
47   return myGTrsf;
48 }
49
50 //=======================================================================
51 //function : InvertedTransformation
52 //purpose  :
53 //=======================================================================
54 inline const gp_GTrsf& Select3D_Projector::InvertedTransformation() const
55 {
56   return myInvTrsf;
57 }
58
59 //=======================================================================
60 //function : FullTransformation
61 //purpose  :
62 //=======================================================================
63 inline const gp_Trsf& Select3D_Projector::FullTransformation() const
64 {
65   return myScaledTrsf;
66 }
67
68 //=======================================================================
69 //function : Focus
70 //purpose  :
71 //=======================================================================
72 inline Standard_Real Select3D_Projector::Focus() const
73 {
74   Standard_ASSERT_RAISE (myPersp, "Not a simplified Perspective.");
75   return myFocus;
76 }
77
78 //=======================================================================
79 //function : Transform
80 //purpose  :
81 //=======================================================================
82 inline void Select3D_Projector::Transform (gp_Vec& theD) const
83 {
84   gp_XYZ aXYZ = theD.XYZ();
85
86   if (myGTrsf.Form() == gp_PntMirror)
87   {
88     aXYZ.Reverse();
89   }
90   else if (myGTrsf.Form() != gp_Identity && myGTrsf.Form() != gp_Translation)
91   {
92     aXYZ.Multiply (myGTrsf.VectorialPart());
93   }
94
95   theD.SetXYZ (aXYZ);
96 }
97
98 //=======================================================================
99 //function : Transform
100 //purpose  :
101 //=======================================================================
102 inline void Select3D_Projector::Transform (gp_Pnt& thePnt) const
103 {
104   Transform (thePnt, myGTrsf);
105 }
106
107 //=======================================================================
108 //function : Transform
109 //purpose  :
110 //=======================================================================
111 inline void Select3D_Projector::Transform (gp_Lin& theLin, const gp_GTrsf& theTrsf) const
112 {
113   gp_Ax1 anAx1 = theLin.Position();
114   gp_XYZ aXYZ = anAx1.Location().XYZ();
115   theTrsf.Transforms (aXYZ);
116   anAx1.SetLocation (gp_Pnt (aXYZ));
117   gp_Dir aDir = anAx1.Direction();
118   gp_XYZ aDirXYZ = aDir.XYZ();
119
120   if (theTrsf.Form() == gp_PntMirror) 
121   {
122     aDirXYZ.Reverse();
123   }
124   else if (theTrsf.Form() != gp_Identity && theTrsf.Form() != gp_Translation)
125   {
126     aDirXYZ.Multiply (theTrsf.VectorialPart());
127     Standard_Real aModulus = aDirXYZ.Modulus();
128     aDirXYZ.Divide (aModulus);
129   }
130
131   aDir.SetXYZ (aDirXYZ);
132   anAx1.SetDirection (aDir);
133   theLin.SetPosition (anAx1);
134 }
135
136 //=======================================================================
137 //function : Transform
138 //purpose  :
139 //=======================================================================
140 inline void Select3D_Projector::Transform (gp_Pnt& thePnt, const gp_GTrsf& theTrsf) const
141 {
142   gp_XYZ aXYZ = thePnt.XYZ();
143   theTrsf.Transforms (aXYZ);
144   thePnt = gp_Pnt (aXYZ);
145 }