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 <SelectBasics_SelectingVolumeManager.hxx>
21 #include <SelectMgr_BaseIntersector.hxx>
22 #include <SelectMgr_VectorTypes.hxx>
23 #include <SelectMgr_ViewClipRange.hxx>
25 //! This class is used to switch between active selecting volumes depending
26 //! on selection type chosen by the user.
27 //! The sample of correct selection volume initialization procedure:
29 //! aMgr.InitPointSelectingVolume (aMousePos);
30 //! aMgr.SetPixelTolerance (aTolerance);
31 //! aMgr.SetCamera (aCamera);
32 //! aMgr.SetWindowSize (aWidth, aHeight);
33 //! aMgr.BuildSelectingVolume();
35 class SelectMgr_SelectingVolumeManager : public SelectBasics_SelectingVolumeManager
39 //! Creates instances of all available selecting volume types
40 Standard_EXPORT SelectMgr_SelectingVolumeManager();
42 virtual ~SelectMgr_SelectingVolumeManager() {}
44 //! Creates, initializes and activates rectangular selecting frustum for point selection
45 Standard_EXPORT void InitPointSelectingVolume (const gp_Pnt2d& thePoint);
47 //! Creates, initializes and activates rectangular selecting frustum for box selection
48 Standard_EXPORT void InitBoxSelectingVolume (const gp_Pnt2d& theMinPt,
49 const gp_Pnt2d& theMaxPt);
51 //! Creates, initializes and activates set of triangular selecting frustums for polyline selection
52 Standard_EXPORT void InitPolylineSelectingVolume (const TColgp_Array1OfPnt2d& thePoints);
54 //! Creates and activates axis selector for point selection
55 Standard_EXPORT void InitAxisSelectingVolume (const gp_Ax1& theAxis);
57 //! Sets as active the custom selecting volume
58 Standard_EXPORT void InitSelectingVolume (const Handle(SelectMgr_BaseIntersector)& theVolume);
60 //! Builds previously initialized selecting volume.
61 Standard_EXPORT void BuildSelectingVolume();
63 //! Returns active selecting volume that was built during last
64 //! run of OCCT selection mechanism
65 const Handle(SelectMgr_BaseIntersector)& ActiveVolume() const { return myActiveSelectingVolume; }
67 // Returns active selection type (point, box, polyline)
68 Standard_EXPORT virtual Standard_Integer GetActiveSelectionType() const Standard_OVERRIDE;
70 //! IMPORTANT: Scaling makes sense only for frustum built on a single point!
71 //! Note that this method does not perform any checks on type of the frustum.
73 //! Returns a copy of the frustum resized according to the scale factor given
74 //! and transforms it using the matrix given.
75 //! There are no default parameters, but in case if:
76 //! - transformation only is needed: @theScaleFactor must be initialized as any negative value;
77 //! - scale only is needed: @theTrsf must be set to gp_Identity.
78 //! Builder is an optional argument that represents corresponding settings for re-constructing transformed
79 //! frustum from scratch. Can be null if reconstruction is not expected furthermore.
80 Standard_EXPORT virtual SelectMgr_SelectingVolumeManager ScaleAndTransform (const Standard_Integer theScaleFactor,
81 const gp_GTrsf& theTrsf,
82 const Handle(SelectMgr_FrustumBuilder)& theBuilder) const;
84 //! Returns a copy of the selecting volume manager and its active frustum re-constructed using the passed builder.
85 //! Builder is an argument that represents corresponding settings for re-constructing transformed
86 //! frustum from scratch.
87 Standard_EXPORT virtual SelectMgr_SelectingVolumeManager CopyWithBuilder (const Handle(SelectMgr_FrustumBuilder)& theBuilder) const;
91 //! Returns current camera definition.
92 Standard_EXPORT const Handle(Graphic3d_Camera)& Camera() const;
94 //! Updates camera projection and orientation matrices in all selecting volumes
95 //! Note: this method should be called after selection volume building
96 //! else exception will be thrown
97 Standard_EXPORT void SetCamera (const Handle(Graphic3d_Camera)& theCamera);
99 //! Updates viewport in all selecting volumes
100 //! Note: this method should be called after selection volume building
101 //! else exception will be thrown
102 Standard_EXPORT void SetViewport (const Standard_Real theX,
103 const Standard_Real theY,
104 const Standard_Real theWidth,
105 const Standard_Real theHeight);
107 //! Updates pixel tolerance in all selecting volumes
108 //! Note: this method should be called after selection volume building
109 //! else exception will be thrown
110 Standard_EXPORT void SetPixelTolerance (const Standard_Integer theTolerance);
112 //! Returns window size
113 Standard_EXPORT void WindowSize (Standard_Integer& theWidth, Standard_Integer& theHeight) const;
115 //! Updates window size in all selecting volumes
116 //! Note: this method should be called after selection volume building
117 //! else exception will be thrown
118 Standard_EXPORT void SetWindowSize (const Standard_Integer theWidth, const Standard_Integer theHeight);
121 //! SAT intersection test between defined volume and given axis-aligned box
122 Standard_EXPORT virtual Standard_Boolean OverlapsBox (const SelectMgr_Vec3& theBoxMin,
123 const SelectMgr_Vec3& theBoxMax,
124 SelectBasics_PickResult& thePickResult) const Standard_OVERRIDE;
126 //! Returns true if selecting volume is overlapped by axis-aligned bounding box
127 //! with minimum corner at point theMinPt and maximum at point theMaxPt
128 Standard_EXPORT virtual Standard_Boolean OverlapsBox (const SelectMgr_Vec3& theBoxMin,
129 const SelectMgr_Vec3& theBoxMax,
130 Standard_Boolean* theInside = NULL) const Standard_OVERRIDE;
132 //! Intersection test between defined volume and given point
133 Standard_EXPORT virtual Standard_Boolean OverlapsPoint (const gp_Pnt& thePnt,
134 SelectBasics_PickResult& thePickResult) const Standard_OVERRIDE;
136 //! Intersection test between defined volume and given point
137 Standard_EXPORT virtual Standard_Boolean OverlapsPoint (const gp_Pnt& thePnt) const Standard_OVERRIDE;
139 //! SAT intersection test between defined volume and given ordered set of points,
140 //! representing line segments. The test may be considered of interior part or
141 //! boundary line defined by segments depending on given sensitivity type
142 Standard_EXPORT virtual Standard_Boolean OverlapsPolygon (const TColgp_Array1OfPnt& theArrayOfPts,
143 Standard_Integer theSensType,
144 SelectBasics_PickResult& thePickResult) const Standard_OVERRIDE;
146 //! Checks if line segment overlaps selecting frustum
147 Standard_EXPORT virtual Standard_Boolean OverlapsSegment (const gp_Pnt& thePnt1,
148 const gp_Pnt& thePnt2,
149 SelectBasics_PickResult& thePickResult) const Standard_OVERRIDE;
151 //! SAT intersection test between defined volume and given triangle. The test may
152 //! be considered of interior part or boundary line defined by triangle vertices
153 //! depending on given sensitivity type
154 Standard_EXPORT virtual Standard_Boolean OverlapsTriangle (const gp_Pnt& thePnt1,
155 const gp_Pnt& thePnt2,
156 const gp_Pnt& thePnt3,
157 Standard_Integer theSensType,
158 SelectBasics_PickResult& thePickResult) const Standard_OVERRIDE;
160 //! Intersection test between defined volume and given sphere
161 Standard_EXPORT virtual Standard_Boolean OverlapsSphere (const gp_Pnt& theCenter,
162 const Standard_Real theRadius,
163 SelectBasics_PickResult& thePickResult) const Standard_OVERRIDE;
165 //! Intersection test between defined volume and given sphere
166 Standard_EXPORT virtual Standard_Boolean OverlapsSphere (const gp_Pnt& theCenter,
167 const Standard_Real theRadius,
168 Standard_Boolean* theInside = NULL) const Standard_OVERRIDE;
170 //! Returns true if selecting volume is overlapped by cylinder (or cone) with radiuses theBottomRad
171 //! and theTopRad, height theHeight and transformation to apply theTrsf.
172 Standard_EXPORT virtual Standard_Boolean OverlapsCylinder (const Standard_Real theBottomRad,
173 const Standard_Real theTopRad,
174 const Standard_Real theHeight,
175 const gp_Trsf& theTrsf,
176 const Standard_Boolean theIsHollow,
177 SelectBasics_PickResult& thePickResult) const Standard_OVERRIDE;
179 //! Returns true if selecting volume is overlapped by cylinder (or cone) with radiuses theBottomRad
180 //! and theTopRad, height theHeight and transformation to apply theTrsf.
181 Standard_EXPORT virtual Standard_Boolean OverlapsCylinder (const Standard_Real theBottomRad,
182 const Standard_Real theTopRad,
183 const Standard_Real theHeight,
184 const gp_Trsf& theTrsf,
185 const Standard_Boolean theIsHollow,
186 Standard_Boolean* theInside = NULL) const Standard_OVERRIDE;
188 //! Returns true if selecting volume is overlapped by circle with radius theRadius,
189 //! boolean theIsFilled and transformation to apply theTrsf.
190 //! The position and orientation of the circle are specified
191 //! via theTrsf transformation for gp::XOY() with center in gp::Origin().
192 Standard_EXPORT virtual Standard_Boolean OverlapsCircle (const Standard_Real theBottomRad,
193 const gp_Trsf& theTrsf,
194 const Standard_Boolean theIsFilled,
195 SelectBasics_PickResult& thePickResult) const Standard_OVERRIDE;
197 //! Returns true if selecting volume is overlapped by circle with radius theRadius,
198 //! boolean theIsFilled and transformation to apply theTrsf.
199 //! The position and orientation of the circle are specified
200 //! via theTrsf transformation for gp::XOY() with center in gp::Origin().
201 Standard_EXPORT virtual Standard_Boolean OverlapsCircle (const Standard_Real theBottomRad,
202 const gp_Trsf& theTrsf,
203 const Standard_Boolean theIsFilled,
204 Standard_Boolean* theInside = NULL) const Standard_OVERRIDE;
206 //! Measures distance between 3d projection of user-picked
207 //! screen point and given point theCOG
208 Standard_EXPORT virtual Standard_Real DistToGeometryCenter (const gp_Pnt& theCOG) const Standard_OVERRIDE;
210 //! Calculates the point on a view ray that was detected during the run of selection algo by given depth.
211 //! Throws exception if active selection type is not Point.
212 Standard_EXPORT virtual gp_Pnt DetectedPoint (const Standard_Real theDepth) const Standard_OVERRIDE;
214 //! If theIsToAllow is false, only fully included sensitives will be detected, otherwise the algorithm will
215 //! mark both included and overlapped entities as matched
216 Standard_EXPORT virtual void AllowOverlapDetection (const Standard_Boolean theIsToAllow);
218 Standard_EXPORT virtual Standard_Boolean IsOverlapAllowed() const Standard_OVERRIDE;
220 //! Return view clipping planes.
221 const Handle(Graphic3d_SequenceOfHClipPlane)& ViewClipping() const { return myViewClipPlanes; }
223 //! Return object clipping planes.
224 const Handle(Graphic3d_SequenceOfHClipPlane)& ObjectClipping() const { return myObjectClipPlanes; }
226 //! Valid for point selection only!
227 //! Computes depth range for clipping planes.
228 //! @param theViewPlanes [in] global view planes
229 //! @param theObjPlanes [in] object planes
230 //! @param theWorldSelMgr [in] selection volume in world space for computing clipping plane ranges
231 Standard_EXPORT void SetViewClipping (const Handle(Graphic3d_SequenceOfHClipPlane)& theViewPlanes,
232 const Handle(Graphic3d_SequenceOfHClipPlane)& theObjPlanes,
233 const SelectMgr_SelectingVolumeManager* theWorldSelMgr);
235 //! Copy clipping planes from another volume manager.
236 Standard_EXPORT void SetViewClipping (const SelectMgr_SelectingVolumeManager& theOther);
238 //! Return clipping range.
239 const SelectMgr_ViewClipRange& ViewClipRanges() const { return myViewClipRange; }
241 //! Set clipping range.
242 void SetViewClipRanges (const SelectMgr_ViewClipRange& theRange) { myViewClipRange = theRange; }
244 //! A set of helper functions that return rectangular selecting frustum data
245 Standard_EXPORT const gp_Pnt* GetVertices() const;
247 //! Valid only for point and rectangular selection.
248 //! Returns projection of 2d mouse picked point or projection
249 //! of center of 2d rectangle (for point and rectangular selection
250 //! correspondingly) onto near view frustum plane
251 Standard_EXPORT virtual gp_Pnt GetNearPickedPnt() const Standard_OVERRIDE;
253 //! Valid only for point and rectangular selection.
254 //! Returns projection of 2d mouse picked point or projection
255 //! of center of 2d rectangle (for point and rectangular selection
256 //! correspondingly) onto far view frustum plane
257 Standard_EXPORT virtual gp_Pnt GetFarPickedPnt() const Standard_OVERRIDE;
259 //! Valid only for point and rectangular selection.
260 //! Returns view ray direction
261 Standard_EXPORT virtual gp_Dir GetViewRayDirection() const Standard_OVERRIDE;
263 //! Checks if it is possible to scale current active selecting volume
264 Standard_EXPORT virtual Standard_Boolean IsScalableActiveVolume() const Standard_OVERRIDE;
266 //! Returns mouse coordinates for Point selection mode.
267 //! @return infinite point in case of unsupport of mouse position for this active selection volume.
268 Standard_EXPORT virtual gp_Pnt2d GetMousePosition() const Standard_OVERRIDE;
270 //! Stores plane equation coefficients (in the following form:
271 //! Ax + By + Cz + D = 0) to the given vector
272 Standard_EXPORT virtual void GetPlanes (NCollection_Vector<SelectMgr_Vec4>& thePlaneEquations) const Standard_OVERRIDE;
274 //! Dumps the content of me into the stream
275 Standard_EXPORT virtual void DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth = -1) const Standard_OVERRIDE;
279 Standard_DEPRECATED("Deprecated method - InitPointSelectingVolume() and Build() methods should be used instead")
280 Standard_EXPORT void BuildSelectingVolume (const gp_Pnt2d& thePoint);
282 Standard_DEPRECATED("Deprecated method - InitBoxSelectingVolume() and Build() should be used instead")
283 Standard_EXPORT void BuildSelectingVolume (const gp_Pnt2d& theMinPt,
284 const gp_Pnt2d& theMaxPt);
286 Standard_DEPRECATED("Deprecated method - InitPolylineSelectingVolume() and Build() should be used instead")
287 Standard_EXPORT void BuildSelectingVolume (const TColgp_Array1OfPnt2d& thePoints);
290 Handle(SelectMgr_BaseIntersector) myActiveSelectingVolume;
291 Handle(Graphic3d_SequenceOfHClipPlane) myViewClipPlanes; //!< view clipping planes
292 Handle(Graphic3d_SequenceOfHClipPlane) myObjectClipPlanes; //!< object clipping planes
293 SelectMgr_ViewClipRange myViewClipRange;
294 Standard_Boolean myToAllowOverlap; //!< Defines if partially overlapped entities will me detected or not