0027611: Visualization - provide an interface to access selection frustum center...
[occt.git] / src / SelectMgr / SelectMgr_SelectingVolumeManager.hxx
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 #ifndef _SelectMgr_SelectingVolumeManager_HeaderFile
17 #define _SelectMgr_SelectingVolumeManager_HeaderFile
18
19 #include <NCollection_Handle.hxx>
20
21 #include <Graphic3d_Camera.hxx>
22 #include <Graphic3d_SequenceOfHClipPlane.hxx>
23 #include <Graphic3d_WorldViewProjState.hxx>
24
25 #include <SelectMgr_BaseFrustum.hxx>
26 #include <SelectMgr_RectangularFrustum.hxx>
27 #include <SelectMgr_TriangularFrustumSet.hxx>
28 #include <SelectBasics_SelectingVolumeManager.hxx>
29
30 //! This class is used to switch between active selecting volumes depending
31 //! on selection type chosen by the user
32 class SelectMgr_SelectingVolumeManager : public SelectBasics_SelectingVolumeManager
33 {
34 public:
35
36   //! Creates instances of all available selecting volume types
37   Standard_EXPORT SelectMgr_SelectingVolumeManager (Standard_Boolean theToAllocateFrustums = Standard_True);
38
39   virtual ~SelectMgr_SelectingVolumeManager() {};
40
41   //! IMPORTANT: Scaling makes sense only for frustum built on a single point!
42   //!            Note that this method does not perform any checks on type of the frustum.
43   //!
44   //! Returns a copy of the frustum resized according to the scale factor given
45   //! and transforms it using the matrix given.
46   //! There are no default parameters, but in case if:
47   //!    - transformation only is needed: @theScaleFactor must be initialized as any negative value;
48   //!    - scale only is needed: @theTrsf must be set to gp_Identity.
49   Standard_EXPORT virtual SelectMgr_SelectingVolumeManager ScaleAndTransform (const Standard_Integer theScaleFactor,
50                                                                               const gp_GTrsf& theTrsf);
51
52   Standard_EXPORT virtual Standard_Integer GetActiveSelectionType() const Standard_OVERRIDE;
53
54   Standard_EXPORT void SetActiveSelectionType (const SelectionType& theType);
55
56   //! Updates camera projection and orientation matrices in all selecting volumes
57   Standard_EXPORT void SetCamera (const Handle(Graphic3d_Camera) theCamera);
58
59   //! Updates camera projection and orientation matrices in all selecting volumes
60   Standard_EXPORT void SetCamera (const Graphic3d_Mat4d& theProjection,
61                                   const Graphic3d_Mat4d& theWorldView,
62                                   const Standard_Boolean theIsOrthographic,
63                                   const Graphic3d_WorldViewProjState& theWVPState = Graphic3d_WorldViewProjState());
64
65   //! @return current projection transformation common for all selecting volumes
66   Standard_EXPORT const Graphic3d_Mat4d& ProjectionMatrix() const;
67
68   //! @return current world view transformation common for all selecting volumes
69   Standard_EXPORT const Graphic3d_Mat4d& WorldViewMatrix() const;
70
71   Standard_EXPORT void WindowSize (Standard_Integer& theWidth, Standard_Integer& theHeight);
72
73   //! @return current camera world view projection transformation state common for all selecting volumes
74   Standard_EXPORT const Graphic3d_WorldViewProjState& WorldViewProjState() const;
75
76   //! Updates viewport in all selecting volumes
77   Standard_EXPORT void SetViewport (const Standard_Real theX,
78                                     const Standard_Real theY,
79                                     const Standard_Real theWidth,
80                                     const Standard_Real theHeight);
81
82   //! Updates pixel tolerance in all selecting volumes
83   Standard_EXPORT void SetPixelTolerance (const Standard_Integer theTolerance);
84
85   //! Updates window size in all selecting volumes
86   Standard_EXPORT void SetWindowSize (const Standard_Integer theWidth, const Standard_Integer theHeight);
87
88
89   //! Builds rectangular selecting frustum for point selection
90   Standard_EXPORT void BuildSelectingVolume (const gp_Pnt2d& thePoint);
91
92   //! Builds rectangular selecting frustum for box selection
93   Standard_EXPORT void BuildSelectingVolume (const gp_Pnt2d& theMinPt,
94                                              const gp_Pnt2d& theMaxPt);
95
96   //! Builds set of triangular selecting frustums for polyline selection
97   Standard_EXPORT void BuildSelectingVolume (const TColgp_Array1OfPnt2d& thePoints);
98
99
100   //! SAT intersection test between defined volume and given axis-aligned box
101   Standard_EXPORT virtual Standard_Boolean Overlaps (const SelectMgr_Vec3& theBoxMin,
102                                                       const SelectMgr_Vec3& theBoxMax,
103                                                      Standard_Real& theDepth) Standard_OVERRIDE;
104
105   //! Returns true if selecting volume is overlapped by axis-aligned bounding box
106   //! with minimum corner at point theMinPt and maximum at point theMaxPt
107   Standard_EXPORT  virtual Standard_Boolean Overlaps (const SelectMgr_Vec3& theBoxMin,
108                                                       const SelectMgr_Vec3& theBoxMax,
109                                                       Standard_Boolean*     theInside = NULL) Standard_OVERRIDE;
110
111   //! Intersection test between defined volume and given point
112   Standard_EXPORT virtual Standard_Boolean Overlaps (const gp_Pnt& thePnt,
113                                                      Standard_Real& theDepth) Standard_OVERRIDE;
114
115   //! Intersection test between defined volume and given point
116   Standard_EXPORT virtual Standard_Boolean Overlaps (const gp_Pnt& thePnt) Standard_OVERRIDE;
117
118   //! SAT intersection test between defined volume and given ordered set of points,
119   //! representing line segments. The test may be considered of interior part or
120   //! boundary line defined by segments depending on given sensitivity type
121   Standard_EXPORT virtual Standard_Boolean Overlaps (const Handle(TColgp_HArray1OfPnt)& theArrayOfPts,
122                                                      Standard_Integer theSensType,
123                                                      Standard_Real& theDepth) Standard_OVERRIDE;
124
125   //! SAT intersection test between defined volume and given ordered set of points,
126   //! representing line segments. The test may be considered of interior part or
127   //! boundary line defined by segments depending on given sensitivity type
128   Standard_EXPORT virtual Standard_Boolean Overlaps (const TColgp_Array1OfPnt& theArrayOfPts,
129                                                      Standard_Integer theSensType,
130                                                      Standard_Real& theDepth) Standard_OVERRIDE;
131
132   //! Checks if line segment overlaps selecting frustum
133   Standard_EXPORT virtual Standard_Boolean Overlaps (const gp_Pnt& thePnt1,
134                                                      const gp_Pnt& thePnt2,
135                                                      Standard_Real& theDepth) Standard_OVERRIDE;
136
137   //! SAT intersection test between defined volume and given triangle. The test may
138   //! be considered of interior part or boundary line defined by triangle vertices
139   //! depending on given sensitivity type
140   Standard_EXPORT  virtual Standard_Boolean Overlaps (const gp_Pnt& thePnt1,
141                                                       const gp_Pnt& thePnt2,
142                                                       const gp_Pnt& thePnt3,
143                                                       Standard_Integer theSensType,
144                                                       Standard_Real& theDepth) Standard_OVERRIDE;
145
146
147   //! Measures distance between 3d projection of user-picked
148   //! screen point and given point theCOG
149   Standard_EXPORT virtual Standard_Real DistToGeometryCenter (const gp_Pnt& theCOG) Standard_OVERRIDE;
150
151   //! Calculates the point on a view ray that was detected during the run of selection algo by given depth. Is valid for point
152   //! selection only
153   Standard_EXPORT virtual gp_Pnt DetectedPoint (const Standard_Real theDepth) const Standard_OVERRIDE;
154
155   //! Checks if the point of sensitive in which selection was detected belongs
156   //! to the region defined by clipping planes
157   Standard_EXPORT virtual Standard_Boolean IsClipped (const Graphic3d_SequenceOfHClipPlane& thePlanes,
158                                                       const Standard_Real& theDepth);
159
160   //! Is used for rectangular selection only
161   //! If theIsToAllow is false, only fully included sensitives will be detected, otherwise the algorithm will
162   //! mark both included and overlapped entities as matched
163   Standard_EXPORT virtual void AllowOverlapDetection (const Standard_Boolean theIsToAllow);
164
165   Standard_EXPORT virtual Standard_Boolean IsOverlapAllowed() const Standard_OVERRIDE;
166
167   //! Valid for point selection only!
168   //! Computes depth range for global (defined for the whole view) clipping planes.
169   Standard_EXPORT void SetViewClipping (const Graphic3d_SequenceOfHClipPlane& thePlanes);
170
171   //! A set of helper functions that return rectangular selecting frustum data
172   Standard_EXPORT const gp_Pnt* GetVertices() const;
173
174   //! Valid only for point and rectangular selection.
175   //! Returns projection of 2d mouse picked point or projection
176   //! of center of 2d rectangle (for point and rectangular selection
177   //! correspondingly) onto near view frustum plane
178   Standard_EXPORT virtual gp_Pnt GetNearPickedPnt() const Standard_OVERRIDE;
179
180   //! Valid only for point and rectangular selection.
181   //! Returns projection of 2d mouse picked point or projection
182   //! of center of 2d rectangle (for point and rectangular selection
183   //! correspondingly) onto far view frustum plane
184   Standard_EXPORT virtual gp_Pnt GetFarPickedPnt() const Standard_OVERRIDE;
185
186 private:
187   enum { Frustum, FrustumSet, VolumeTypesNb };       //!< Defines the amount of available selecting volumes
188
189   NCollection_Handle<SelectMgr_BaseFrustum> mySelectingVolumes[VolumeTypesNb];      //!< Array of selecting volumes
190   Standard_Boolean                          myToAllowOverlap;      //!< Defines if partially overlapped entities will me detected or not
191 };
192
193 #endif