0030640: Visualization, Graphic3d_Camera - add option creating Projection matrix...
[occt.git] / src / SelectMgr / SelectMgr_BaseFrustum.cxx
1 // Created on: 2014-05-22
2 // Created by: Varvara POSKONINA
3 // Copyright (c) 2005-2014 OPEN CASCADE SAS
4 //
5 // This file is part of Open CASCADE Technology software library.
6 //
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License version 2.1 as published
9 // by the Free Software Foundation, with special exception defined in the file
10 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 // distribution for complete text of the license and disclaimer of any warranty.
12 //
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
15
16 #include <SelectMgr_BaseFrustum.hxx>
17
18 #include <Message.hxx>
19
20 #include <Standard_Dump.hxx>
21
22 IMPLEMENT_STANDARD_RTTIEXT(SelectMgr_BaseFrustum,Standard_Transient)
23
24 //=======================================================================
25 // function : SelectMgr_SelectingVolume
26 // purpose  : Creates new selecting volume with pixel toletance set to 2,
27 //            orthographic camera and empty frustum builder
28 //=======================================================================
29 SelectMgr_BaseFrustum::SelectMgr_BaseFrustum()
30 : myPixelTolerance (2),
31   myIsOrthographic (Standard_True)
32 {
33   myBuilder = new SelectMgr_FrustumBuilder();
34 }
35
36 //=======================================================================
37 // function : SetCamera
38 // purpose  : Passes camera projection and orientation matrices to builder
39 //=======================================================================
40 void SelectMgr_BaseFrustum::SetCamera (const Handle(Graphic3d_Camera)& theCamera)
41 {
42   myCamera = theCamera;
43   myBuilder->SetWorldViewMatrix (theCamera->OrientationMatrix());
44   myBuilder->SetProjectionMatrix (theCamera->ProjectionMatrix(), theCamera->IsZeroToOneDepth());
45   myBuilder->SetWorldViewProjState (theCamera->WorldViewProjState());
46   myIsOrthographic = theCamera->IsOrthographic();
47   myBuilder->InvalidateViewport();
48 }
49
50 //=======================================================================
51 // function : SetCamera
52 // purpose  : Passes camera projection and orientation matrices to builder
53 //=======================================================================
54 void SelectMgr_BaseFrustum::SetCamera (const Graphic3d_Mat4d& theProjection,
55                                        const Graphic3d_Mat4d& theWorldView,
56                                        const Standard_Boolean theIsOrthographic,
57                                        const Graphic3d_WorldViewProjState& theWVPState)
58 {
59   myCamera.Nullify();
60   myBuilder->SetWorldViewMatrix (theWorldView);
61   myBuilder->SetProjectionMatrix (theProjection, false);
62   myBuilder->SetWorldViewProjState (theWVPState);
63   myIsOrthographic = theIsOrthographic;
64 }
65
66 //=======================================================================
67 // function : ProjectionMatrix
68 // purpose  : Returns current camera projection transformation common for
69 //            all selecting volumes
70 //=======================================================================
71 const Graphic3d_Mat4d& SelectMgr_BaseFrustum::ProjectionMatrix() const
72 {
73   return myBuilder->ProjectionMatrix();
74 }
75
76 //=======================================================================
77 // function : WorldViewMatrix
78 // purpose  : Returns current camera world view transformation common for
79 //            all selecting volumes
80 //=======================================================================
81 const Graphic3d_Mat4d& SelectMgr_BaseFrustum::WorldViewMatrix() const
82 {
83   return myBuilder->WorldViewMatrix();
84 }
85
86 //=======================================================================
87 // function : WorldViewProjState
88 // purpose  : Returns current camera world view projection transformation
89 //            state
90 //=======================================================================
91 const Graphic3d_WorldViewProjState& SelectMgr_BaseFrustum::WorldViewProjState() const
92 {
93   return myBuilder->WorldViewProjState();
94 }
95
96 //=======================================================================
97 // function : SetViewport
98 // purpose  : Passes viewport parameters to builder
99 //=======================================================================
100 void SelectMgr_BaseFrustum::SetViewport (const Standard_Real theX,
101                                          const Standard_Real theY,
102                                          const Standard_Real theWidth,
103                                          const Standard_Real theHeight)
104 {
105   myBuilder->SetViewport (theX, theY, theWidth, theHeight);
106 }
107
108 //=======================================================================
109 // function : SetPixelTolerance
110 // purpose  :
111 //=======================================================================
112 void SelectMgr_BaseFrustum::SetPixelTolerance (const Standard_Integer theTol)
113 {
114   myPixelTolerance = theTol;
115 }
116
117 //=======================================================================
118 // function : SetWindowSize
119 // purpose  :
120 //=======================================================================
121 void SelectMgr_BaseFrustum::SetWindowSize (const Standard_Integer theWidth, const Standard_Integer theHeight)
122 {
123   myBuilder->SetWindowSize (theWidth, theHeight);
124 }
125
126 //=======================================================================
127 // function : WindowSize
128 // purpose  :
129 //=======================================================================
130 void SelectMgr_BaseFrustum::WindowSize (Standard_Integer& theWidth,
131                                         Standard_Integer& theHeight) const
132 {
133   myBuilder->WindowSize (theWidth, theHeight);
134 }
135
136 //=======================================================================
137 // function : SetBuilder
138 // purpose  :
139 //=======================================================================
140 void SelectMgr_BaseFrustum::SetBuilder (const Handle(SelectMgr_FrustumBuilder)& theBuilder)
141 {
142   myBuilder.Nullify();
143   myBuilder = theBuilder;
144 }
145
146 //=======================================================================
147 // function : Overlaps
148 // purpose  : SAT intersection test between defined volume and
149 //            given axis-aligned box
150 //=======================================================================
151 Standard_Boolean SelectMgr_BaseFrustum::Overlaps (const SelectMgr_Vec3& /*theBoxMin*/,
152                                                   const SelectMgr_Vec3& /*theBoxMax*/,
153                                                   const SelectMgr_ViewClipRange& /*theClipRange*/,
154                                                   SelectBasics_PickResult& /*thePickResult*/) const
155 {
156   return Standard_False;
157 }
158
159 //=======================================================================
160 // function : Overlaps
161 // purpose  : Intersection test between defined volume and given point
162 //=======================================================================
163 Standard_Boolean SelectMgr_BaseFrustum::Overlaps (const SelectMgr_Vec3& /*theBoxMin*/,
164                                                   const SelectMgr_Vec3& /*theBoxMax*/,
165                                                   Standard_Boolean*     /*theInside*/) const
166 {
167   return Standard_False;
168 }
169
170 //=======================================================================
171 // function : Overlaps
172 // purpose  : Intersection test between defined volume and given point
173 //=======================================================================
174 Standard_Boolean SelectMgr_BaseFrustum::Overlaps (const gp_Pnt& /*thePnt*/,
175                                                   const SelectMgr_ViewClipRange& /*theClipRange*/,
176                                                   SelectBasics_PickResult& ) const
177 {
178   return Standard_False;
179 }
180
181 //=======================================================================
182 // function : Overlaps
183 // purpose  : Intersection test between defined volume and given point
184 //=======================================================================
185 Standard_Boolean SelectMgr_BaseFrustum::Overlaps (const gp_Pnt& /*thePnt*/) const
186 {
187   return Standard_False;
188 }
189
190 //=======================================================================
191 // function : Overlaps
192 // purpose  : SAT intersection test between defined volume and given
193 //            ordered set of points, representing line segments. The test
194 //            may be considered of interior part or boundary line defined
195 //            by segments depending on given sensitivity type
196 //=======================================================================
197 Standard_Boolean SelectMgr_BaseFrustum::Overlaps (const TColgp_Array1OfPnt& /*theArrayOfPnts*/,
198                                                   Select3D_TypeOfSensitivity /*theSensType*/,
199                                                   const SelectMgr_ViewClipRange& /*theClipRange*/,
200                                                   SelectBasics_PickResult& ) const
201 {
202   return Standard_False;
203 }
204
205 //=======================================================================
206 // function : Overlaps
207 // purpose  : SAT intersection test between defined volume and given
208 //            triangle. The test may be considered of interior part or
209 //            boundary line defined by triangle vertices depending on
210 //            given sensitivity type
211 //=======================================================================
212 Standard_Boolean SelectMgr_BaseFrustum::Overlaps (const gp_Pnt& /*thePt1*/,
213                                                   const gp_Pnt& /*thePt2*/,
214                                                   const gp_Pnt& /*thePt3*/,
215                                                   Select3D_TypeOfSensitivity /*theSensType*/,
216                                                   const SelectMgr_ViewClipRange& /*theClipRange*/,
217                                                   SelectBasics_PickResult& ) const
218 {
219   return Standard_False;
220 }
221
222 //=======================================================================
223 // function : Overlaps
224 // purpose  : Checks if line segment overlaps selecting volume
225 //=======================================================================
226 Standard_Boolean SelectMgr_BaseFrustum::Overlaps (const gp_Pnt& /*thePnt1*/,
227                                                   const gp_Pnt& /*thePnt2*/,
228                                                   const SelectMgr_ViewClipRange& /*theClipRange*/,
229                                                   SelectBasics_PickResult& ) const
230 {
231   return Standard_False;
232 }
233
234 //=======================================================================
235 // function : DistToGeometryCenter
236 // purpose  : Measures distance between 3d projection of user-picked
237 //            screen point and given point theCOG
238 //=======================================================================
239 Standard_Real SelectMgr_BaseFrustum::DistToGeometryCenter (const gp_Pnt& /*theCOG*/) const
240 {
241   return DBL_MAX;
242 }
243
244 //=======================================================================
245 // function : DetectedPoint
246 // purpose  :
247 //=======================================================================
248 gp_Pnt SelectMgr_BaseFrustum::DetectedPoint (const Standard_Real /*theDepth*/) const
249 {
250   return gp_Pnt (RealLast(), RealLast(), RealLast());
251 }
252
253 //=======================================================================
254 //function : DumpJson
255 //purpose  : 
256 //=======================================================================
257 void SelectMgr_BaseFrustum::DumpJson (Standard_OStream& theOStream, Standard_Integer) const
258 {
259   OCCT_DUMP_TRANSIENT_CLASS_BEGIN (theOStream)
260
261   OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myPixelTolerance)
262   OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myIsOrthographic)
263   OCCT_DUMP_FIELD_VALUE_POINTER (theOStream, myBuilder)
264   OCCT_DUMP_FIELD_VALUE_POINTER (theOStream, myCamera)
265 }