1 // Created on: 2014-05-22
2 // Created by: Varvara POSKONINA
3 // Copyright (c) 2005-2014 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
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.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
16 #ifndef _SelectMgr_SelectingVolumeManager_HeaderFile
17 #define _SelectMgr_SelectingVolumeManager_HeaderFile
19 #include <NCollection_Handle.hxx>
21 #include <Graphic3d_Camera.hxx>
22 #include <Graphic3d_SequenceOfHClipPlane.hxx>
23 #include <Graphic3d_WorldViewProjState.hxx>
25 #include <SelectMgr_BaseFrustum.hxx>
26 #include <SelectMgr_RectangularFrustum.hxx>
27 #include <SelectMgr_TriangularFrustumSet.hxx>
28 #include <SelectBasics_SelectingVolumeManager.hxx>
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
36 //! Creates instances of all available selecting volume types
37 Standard_EXPORT SelectMgr_SelectingVolumeManager (Standard_Boolean theToAllocateFrustums = Standard_True);
39 virtual ~SelectMgr_SelectingVolumeManager() {}
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.
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 //! Builder is an optional argument that represents corresponding settings for re-constructing transformed
50 //! frustum from scratch. Can be null if reconstruction is not expected furthermore.
51 Standard_EXPORT virtual SelectMgr_SelectingVolumeManager ScaleAndTransform (const Standard_Integer theScaleFactor,
52 const gp_GTrsf& theTrsf,
53 const Handle(SelectMgr_FrustumBuilder)& theBuilder = NULL) const;
55 Standard_EXPORT virtual Standard_Integer GetActiveSelectionType() const Standard_OVERRIDE;
57 Standard_EXPORT void SetActiveSelectionType (const SelectionType& theType);
59 //! Returns current camera definition.
60 const Handle(Graphic3d_Camera)& Camera() const { return mySelectingVolumes[Frustum]->Camera(); }
62 //! Updates camera projection and orientation matrices in all selecting volumes
63 Standard_EXPORT void SetCamera (const Handle(Graphic3d_Camera) theCamera);
65 //! Updates camera projection and orientation matrices in all selecting volumes
66 Standard_EXPORT void SetCamera (const Graphic3d_Mat4d& theProjection,
67 const Graphic3d_Mat4d& theWorldView,
68 const Standard_Boolean theIsOrthographic,
69 const Graphic3d_WorldViewProjState& theWVPState = Graphic3d_WorldViewProjState());
71 //! @return current projection transformation common for all selecting volumes
72 Standard_EXPORT const Graphic3d_Mat4d& ProjectionMatrix() const;
74 //! @return current world view transformation common for all selecting volumes
75 Standard_EXPORT const Graphic3d_Mat4d& WorldViewMatrix() const;
77 Standard_EXPORT void WindowSize (Standard_Integer& theWidth, Standard_Integer& theHeight) const;
79 //! @return current camera world view projection transformation state common for all selecting volumes
80 Standard_EXPORT const Graphic3d_WorldViewProjState& WorldViewProjState() const;
82 //! Updates viewport in all selecting volumes
83 Standard_EXPORT void SetViewport (const Standard_Real theX,
84 const Standard_Real theY,
85 const Standard_Real theWidth,
86 const Standard_Real theHeight);
88 //! Updates pixel tolerance in all selecting volumes
89 Standard_EXPORT void SetPixelTolerance (const Standard_Integer theTolerance);
91 //! Updates window size in all selecting volumes
92 Standard_EXPORT void SetWindowSize (const Standard_Integer theWidth, const Standard_Integer theHeight);
95 //! Builds rectangular selecting frustum for point selection
96 Standard_EXPORT void BuildSelectingVolume (const gp_Pnt2d& thePoint);
98 //! Builds rectangular selecting frustum for box selection
99 Standard_EXPORT void BuildSelectingVolume (const gp_Pnt2d& theMinPt,
100 const gp_Pnt2d& theMaxPt);
102 //! Builds set of triangular selecting frustums for polyline selection
103 Standard_EXPORT void BuildSelectingVolume (const TColgp_Array1OfPnt2d& thePoints);
106 //! SAT intersection test between defined volume and given axis-aligned box
107 Standard_EXPORT virtual Standard_Boolean Overlaps (const SelectMgr_Vec3& theBoxMin,
108 const SelectMgr_Vec3& theBoxMax,
109 SelectBasics_PickResult& thePickResult) const Standard_OVERRIDE;
111 //! Returns true if selecting volume is overlapped by axis-aligned bounding box
112 //! with minimum corner at point theMinPt and maximum at point theMaxPt
113 Standard_EXPORT virtual Standard_Boolean Overlaps (const SelectMgr_Vec3& theBoxMin,
114 const SelectMgr_Vec3& theBoxMax,
115 Standard_Boolean* theInside = NULL) const Standard_OVERRIDE;
117 //! Intersection test between defined volume and given point
118 Standard_EXPORT virtual Standard_Boolean Overlaps (const gp_Pnt& thePnt,
119 SelectBasics_PickResult& thePickResult) const Standard_OVERRIDE;
121 //! Intersection test between defined volume and given point
122 Standard_EXPORT virtual Standard_Boolean Overlaps (const gp_Pnt& thePnt) const Standard_OVERRIDE;
124 //! SAT intersection test between defined volume and given ordered set of points,
125 //! representing line segments. The test may be considered of interior part or
126 //! boundary line defined by segments depending on given sensitivity type
127 Standard_EXPORT virtual Standard_Boolean Overlaps (const Handle(TColgp_HArray1OfPnt)& theArrayOfPts,
128 Standard_Integer theSensType,
129 SelectBasics_PickResult& thePickResult) const Standard_OVERRIDE;
131 //! SAT intersection test between defined volume and given ordered set of points,
132 //! representing line segments. The test may be considered of interior part or
133 //! boundary line defined by segments depending on given sensitivity type
134 Standard_EXPORT virtual Standard_Boolean Overlaps (const TColgp_Array1OfPnt& theArrayOfPts,
135 Standard_Integer theSensType,
136 SelectBasics_PickResult& thePickResult) const Standard_OVERRIDE;
138 //! Checks if line segment overlaps selecting frustum
139 Standard_EXPORT virtual Standard_Boolean Overlaps (const gp_Pnt& thePnt1,
140 const gp_Pnt& thePnt2,
141 SelectBasics_PickResult& thePickResult) const Standard_OVERRIDE;
143 //! SAT intersection test between defined volume and given triangle. The test may
144 //! be considered of interior part or boundary line defined by triangle vertices
145 //! depending on given sensitivity type
146 Standard_EXPORT virtual Standard_Boolean Overlaps (const gp_Pnt& thePnt1,
147 const gp_Pnt& thePnt2,
148 const gp_Pnt& thePnt3,
149 Standard_Integer theSensType,
150 SelectBasics_PickResult& thePickResult) const Standard_OVERRIDE;
153 //! Measures distance between 3d projection of user-picked
154 //! screen point and given point theCOG
155 Standard_EXPORT virtual Standard_Real DistToGeometryCenter (const gp_Pnt& theCOG) const Standard_OVERRIDE;
157 //! Calculates the point on a view ray that was detected during the run of selection algo by given depth.
158 //! Throws exception if active selection type is not Point.
159 Standard_EXPORT virtual gp_Pnt DetectedPoint (const Standard_Real theDepth) const Standard_OVERRIDE;
161 //! Is used for rectangular selection only
162 //! If theIsToAllow is false, only fully included sensitives will be detected, otherwise the algorithm will
163 //! mark both included and overlapped entities as matched
164 Standard_EXPORT virtual void AllowOverlapDetection (const Standard_Boolean theIsToAllow);
166 Standard_EXPORT virtual Standard_Boolean IsOverlapAllowed() const Standard_OVERRIDE;
168 //! Return view clipping planes.
169 const Handle(Graphic3d_SequenceOfHClipPlane)& ViewClipping() const { return myViewClipPlanes; }
171 //! Return object clipping planes.
172 const Handle(Graphic3d_SequenceOfHClipPlane)& ObjectClipping() const { return myObjectClipPlanes; }
174 //! Valid for point selection only!
175 //! Computes depth range for clipping planes.
176 //! @param theViewPlanes global view planes
177 //! @param theObjPlanes object planes
178 Standard_EXPORT void SetViewClipping (const Handle(Graphic3d_SequenceOfHClipPlane)& theViewPlanes,
179 const Handle(Graphic3d_SequenceOfHClipPlane)& theObjPlanes);
181 //! Copy clipping planes from another volume manager.
182 Standard_EXPORT void SetViewClipping (const SelectMgr_SelectingVolumeManager& theOther);
184 //! Return clipping range.
185 const SelectMgr_ViewClipRange& ViewClipRanges() const { return myViewClipRange; }
187 //! Set clipping range.
188 void SetViewClipRanges (const SelectMgr_ViewClipRange& theRange) { myViewClipRange = theRange; }
190 //! A set of helper functions that return rectangular selecting frustum data
191 Standard_EXPORT const gp_Pnt* GetVertices() const;
193 //! Valid only for point and rectangular selection.
194 //! Returns projection of 2d mouse picked point or projection
195 //! of center of 2d rectangle (for point and rectangular selection
196 //! correspondingly) onto near view frustum plane
197 Standard_EXPORT virtual gp_Pnt GetNearPickedPnt() const Standard_OVERRIDE;
199 //! Valid only for point and rectangular selection.
200 //! Returns projection of 2d mouse picked point or projection
201 //! of center of 2d rectangle (for point and rectangular selection
202 //! correspondingly) onto far view frustum plane
203 Standard_EXPORT virtual gp_Pnt GetFarPickedPnt() const Standard_OVERRIDE;
205 //! Return mouse coordinates for Point selection mode.
206 virtual gp_Pnt2d GetMousePosition() const Standard_OVERRIDE
208 if (myActiveSelectionType != Point)
210 return gp_Pnt2d (RealLast(), RealLast());
212 const SelectMgr_RectangularFrustum* aFr = reinterpret_cast<const SelectMgr_RectangularFrustum*> (mySelectingVolumes[myActiveSelectionType / 2].get());
213 return aFr->GetMousePosition();
216 //! Returns active selecting volume that was built during last
217 //! run of OCCT selection mechanism
218 Handle(SelectMgr_BaseFrustum) ActiveVolume() const
220 if (myActiveSelectionType == Unknown)
221 return Handle(SelectMgr_BaseFrustum)();
223 return mySelectingVolumes[myActiveSelectionType / 2];
226 //! Stores plane equation coefficients (in the following form:
227 //! Ax + By + Cz + D = 0) to the given vector
228 virtual void GetPlanes (NCollection_Vector<SelectMgr_Vec4>& thePlaneEquations) const Standard_OVERRIDE
230 if (myActiveSelectionType == Unknown)
232 thePlaneEquations.Clear();
236 return mySelectingVolumes[myActiveSelectionType / 2]->GetPlanes (thePlaneEquations);
240 enum { Frustum, FrustumSet, VolumeTypesNb }; //!< Defines the amount of available selecting volumes
242 Handle(SelectMgr_BaseFrustum) mySelectingVolumes[VolumeTypesNb]; //!< Array of selecting volumes
243 Handle(Graphic3d_SequenceOfHClipPlane) myViewClipPlanes; //!< view clipping planes
244 Handle(Graphic3d_SequenceOfHClipPlane) myObjectClipPlanes; //!< object clipping planes
245 SelectMgr_ViewClipRange myViewClipRange;
246 Standard_Boolean myToAllowOverlap; //!< Defines if partially overlapped entities will me detected or not