0026344: Visualization - provide a support of zoom persistent selection
[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 //=======================================================================
19 // function : SelectMgr_SelectingVolume
20 // purpose  : Creates new selecting volume with pixel toletance set to 2,
21 //            orthographic camera and empty frustum builder
22 //=======================================================================
23 SelectMgr_BaseFrustum::SelectMgr_BaseFrustum()
24 : myPixelTolerance (2),
25   myIsOrthographic (Standard_True)
26 {
27   myBuilder = new SelectMgr_FrustumBuilder();
28 }
29
30 //=======================================================================
31 // function : SetCamera
32 // purpose  : Passes camera projection and orientation matrices to builder
33 //=======================================================================
34 void SelectMgr_BaseFrustum::SetCamera (const Handle(Graphic3d_Camera)& theCamera)
35 {
36   myBuilder->SetWorldViewMatrix (theCamera->OrientationMatrix());
37   myBuilder->SetProjectionMatrix (theCamera->ProjectionMatrix());
38   myBuilder->SetWorldViewProjState (theCamera->WorldViewProjState());
39   myIsOrthographic = theCamera->IsOrthographic();
40   myBuilder->InvalidateViewport();
41 }
42
43 //=======================================================================
44 // function : SetCamera
45 // purpose  : Passes camera projection and orientation matrices to builder
46 //=======================================================================
47 void SelectMgr_BaseFrustum::SetCamera (const Graphic3d_Mat4d& theProjection,
48                                        const Graphic3d_Mat4d& theWorldView,
49                                        const Standard_Integer theIsOrthographic,
50                                        const Graphic3d_WorldViewProjState& theWVPState)
51 {
52   myBuilder->SetWorldViewMatrix (theWorldView);
53   myBuilder->SetProjectionMatrix (theProjection);
54   myBuilder->SetWorldViewProjState (theWVPState);
55   myIsOrthographic = theIsOrthographic;
56 }
57
58 //=======================================================================
59 // function : ProjectionMatrix
60 // purpose  : Returns current camera projection transformation common for
61 //            all selecting volumes
62 //=======================================================================
63 const Graphic3d_Mat4d& SelectMgr_BaseFrustum::ProjectionMatrix() const
64 {
65   return myBuilder->ProjectionMatrix();
66 }
67
68 //=======================================================================
69 // function : WorldViewMatrix
70 // purpose  : Returns current camera world view transformation common for
71 //            all selecting volumes
72 //=======================================================================
73 const Graphic3d_Mat4d& SelectMgr_BaseFrustum::WorldViewMatrix() const
74 {
75   return myBuilder->WorldViewMatrix();
76 }
77
78 //=======================================================================
79 // function : WorldViewProjState
80 // purpose  : Returns current camera world view projection transformation
81 //            state
82 //=======================================================================
83 const Graphic3d_WorldViewProjState& SelectMgr_BaseFrustum::WorldViewProjState() const
84 {
85   return myBuilder->WorldViewProjState();
86 }
87
88 //=======================================================================
89 // function : SetViewport
90 // purpose  : Passes viewport parameters to builder
91 //=======================================================================
92 void SelectMgr_BaseFrustum::SetViewport (const Standard_Real theX,
93                                          const Standard_Real theY,
94                                          const Standard_Real theWidth,
95                                          const Standard_Real theHeight)
96 {
97   myBuilder->SetViewport (theX, theY, theWidth, theHeight);
98 }
99
100 //=======================================================================
101 // function : SetPixelTolerance
102 // purpose  :
103 //=======================================================================
104 void SelectMgr_BaseFrustum::SetPixelTolerance (const Standard_Real theTol)
105 {
106   myPixelTolerance = theTol;
107 }
108
109 //=======================================================================
110 // function : SetWindowSize
111 // purpose  :
112 //=======================================================================
113 void SelectMgr_BaseFrustum::SetWindowSize (const Standard_Integer theWidth, const Standard_Integer theHeight)
114 {
115   myBuilder->SetWindowSize (theWidth, theHeight);
116 }
117
118 //=======================================================================
119 // function : SetBuilder
120 // purpose  :
121 //=======================================================================
122 void SelectMgr_BaseFrustum::SetBuilder (const Handle(SelectMgr_FrustumBuilder)& theBuilder)
123 {
124   myBuilder.Nullify();
125   myBuilder = theBuilder;
126 }
127
128 //=======================================================================
129 // function : Overlaps
130 // purpose  : SAT intersection test between defined volume and
131 //            given axis-aligned box
132 //=======================================================================
133 Standard_Boolean SelectMgr_BaseFrustum::Overlaps (const BVH_Box<Standard_Real, 3>& /*theBndBox*/,
134                                                   Standard_Real& /*theDepth*/)
135 {
136   return Standard_False;
137 }
138
139 //=======================================================================
140 // function : Overlaps
141 // purpose  : Intersection test between defined volume and given point
142 //=======================================================================
143 Standard_Boolean SelectMgr_BaseFrustum::Overlaps (const SelectMgr_Vec3& /*theBoxMin*/,
144                                                   const SelectMgr_Vec3& /*theBoxMax*/,
145                                                   Standard_Boolean*     /*theInside*/)
146 {
147   return Standard_False;
148 }
149
150 //=======================================================================
151 // function : Overlaps
152 // purpose  : Intersection test between defined volume and given point
153 //=======================================================================
154 Standard_Boolean SelectMgr_BaseFrustum::Overlaps (const gp_Pnt& /*thePt*/,
155                                                   Standard_Real& /*theDepth*/)
156 {
157   return Standard_False;
158 }
159
160 //=======================================================================
161 // function : Overlaps
162 // purpose  : SAT intersection test between defined volume and given
163 //            ordered set of points, representing line segments. The test
164 //            may be considered of interior part or boundary line defined
165 //            by segments depending on given sensitivity type
166 //=======================================================================
167 Standard_Boolean SelectMgr_BaseFrustum::Overlaps (const Handle(TColgp_HArray1OfPnt)& /*theArrayOfPts*/,
168                                                   Select3D_TypeOfSensitivity /*theSensType*/,
169                                                   Standard_Real& /*theDepth*/)
170 {
171   return Standard_False;
172 }
173
174 //=======================================================================
175 // function : Overlaps
176 // purpose  : SAT intersection test between defined volume and given
177 //            triangle. The test may be considered of interior part or
178 //            boundary line defined by triangle vertices depending on
179 //            given sensitivity type
180 //=======================================================================
181 Standard_Boolean SelectMgr_BaseFrustum::Overlaps (const gp_Pnt& /*thePt1*/,
182                                                   const gp_Pnt& /*thePt2*/,
183                                                   const gp_Pnt& /*thePt3*/,
184                                                   Select3D_TypeOfSensitivity /*theSensType*/,
185                                                   Standard_Real& /*theDepth*/)
186 {
187   return Standard_False;
188 }
189
190 //=======================================================================
191 // function : Overlaps
192 // purpose  : Checks if line segment overlaps selecting volume
193 //=======================================================================
194 Standard_Boolean SelectMgr_BaseFrustum::Overlaps (const gp_Pnt& /*thePt1*/,
195                                                   const gp_Pnt& /*thePt2*/,
196                                                   Standard_Real& /*theDepth*/)
197 {
198   return Standard_False;
199 }
200
201 //=======================================================================
202 // function : DistToGeometryCenter
203 // purpose  : Measures distance between 3d projection of user-picked
204 //            screen point and given point theCOG
205 //=======================================================================
206 Standard_Real SelectMgr_BaseFrustum::DistToGeometryCenter (const gp_Pnt& /*theCOG*/)
207 {
208   return DBL_MAX;
209 }
210
211 SelectMgr_Vec3 SelectMgr_BaseFrustum::DetectedPoint (const Standard_Real /*theDepth*/) const
212 {
213   return SelectMgr_Vec3 (RealLast());
214 }
215
216 //=======================================================================
217 // function : IsClipped
218 // purpose  : Checks if the point of sensitive in which selection was
219 //            detected belongs to the region defined by clipping planes
220 //=======================================================================
221 Standard_Boolean SelectMgr_BaseFrustum::IsClipped (const Graphic3d_SequenceOfHClipPlane& /*thePlanes*/,
222                                                    const Standard_Real /*theDepth*/)
223 {
224   return Standard_True;
225 }