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 Standard_EXPORT virtual ~SelectMgr_SelectingVolumeManager() {};
41 //! Returns a copy of active frustum transformed according to the matrix given
42 Standard_EXPORT virtual SelectMgr_SelectingVolumeManager Transform (const gp_Trsf& theTrsf);
44 //! IMPORTANT: Makes sense only for point selection!
45 //! Returns a copy of the frustum resized according to the scale factor given
46 Standard_EXPORT virtual SelectMgr_SelectingVolumeManager Scale (const Standard_Real theScaleFactor);
48 Standard_EXPORT virtual Standard_Integer GetActiveSelectionType() const Standard_OVERRIDE;
50 Standard_EXPORT void SetActiveSelectionType (const SelectionType& theType);
52 //! Updates camera projection and orientation matrices in all selecting volumes
53 Standard_EXPORT void SetCamera (const Handle(Graphic3d_Camera) theCamera);
55 //! Updates camera projection and orientation matrices in all selecting volumes
56 Standard_EXPORT void SetCamera (const Graphic3d_Mat4d& theProjection,
57 const Graphic3d_Mat4d& theWorldView,
58 const Standard_Boolean theIsOrthographic,
59 const Graphic3d_WorldViewProjState& theWVPState = Graphic3d_WorldViewProjState());
61 //! @return current projection transformation common for all selecting volumes
62 Standard_EXPORT const Graphic3d_Mat4d& ProjectionMatrix() const;
64 //! @return current world view transformation common for all selecting volumes
65 Standard_EXPORT const Graphic3d_Mat4d& WorldViewMatrix() const;
67 //! @return current camera world view projection transformation state common for all selecting volumes
68 Standard_EXPORT const Graphic3d_WorldViewProjState& WorldViewProjState() const;
70 //! Updates viewport in all selecting volumes
71 Standard_EXPORT void SetViewport (const Standard_Real theX,
72 const Standard_Real theY,
73 const Standard_Real theWidth,
74 const Standard_Real theHeight);
76 //! Updates pixel tolerance in all selecting volumes
77 Standard_EXPORT void SetPixelTolerance (const Standard_Real theTolerance);
79 //! Updates window size in all selecting volumes
80 Standard_EXPORT void SetWindowSize (const Standard_Integer theWidth, const Standard_Integer theHeight);
83 //! Builds rectangular selecting frustum for point selection
84 Standard_EXPORT void BuildSelectingVolume (const gp_Pnt2d& thePoint);
86 //! Builds rectangular selecting frustum for box selection
87 Standard_EXPORT void BuildSelectingVolume (const gp_Pnt2d& theMinPt,
88 const gp_Pnt2d& theMaxPt);
90 //! Builds set of triangular selecting frustums for polyline selection
91 Standard_EXPORT void BuildSelectingVolume (const TColgp_Array1OfPnt2d& thePoints);
94 //! SAT intersection test between defined volume and given axis-aligned box
95 Standard_EXPORT virtual Standard_Boolean Overlaps (const BVH_Box<Standard_Real, 3>& theBndBox,
96 Standard_Real& theDepth) Standard_OVERRIDE;
98 //! Returns true if selecting volume is overlapped by axis-aligned bounding box
99 //! with minimum corner at point theMinPt and maximum at point theMaxPt
100 Standard_EXPORT virtual Standard_Boolean Overlaps (const SelectMgr_Vec3& theBoxMin,
101 const SelectMgr_Vec3& theBoxMax,
102 Standard_Boolean* theInside = NULL) Standard_OVERRIDE;
104 //! Intersection test between defined volume and given point
105 Standard_EXPORT virtual Standard_Boolean Overlaps (const gp_Pnt& thePt,
106 Standard_Real& theDepth) Standard_OVERRIDE;
108 //! SAT intersection test between defined volume and given ordered set of points,
109 //! representing line segments. The test may be considered of interior part or
110 //! boundary line defined by segments depending on given sensitivity type
111 Standard_EXPORT virtual Standard_Boolean Overlaps (const Handle(TColgp_HArray1OfPnt)& theArrayOfPts,
112 Standard_Integer theSensType,
113 Standard_Real& theDepth) Standard_OVERRIDE;
115 //! Checks if line segment overlaps selecting frustum
116 Standard_EXPORT virtual Standard_Boolean Overlaps (const gp_Pnt& thePt1,
117 const gp_Pnt& thePt2,
118 Standard_Real& theDepth) Standard_OVERRIDE;
120 //! SAT intersection test between defined volume and given triangle. The test may
121 //! be considered of interior part or boundary line defined by triangle vertices
122 //! depending on given sensitivity type
123 Standard_EXPORT virtual Standard_Boolean Overlaps (const gp_Pnt& thePt1,
124 const gp_Pnt& thePt2,
125 const gp_Pnt& thePt3,
126 Standard_Integer theSensType,
127 Standard_Real& theDepth) Standard_OVERRIDE;
130 //! Measures distance between 3d projection of user-picked
131 //! screen point and given point theCOG
132 Standard_EXPORT virtual Standard_Real DistToGeometryCenter (const gp_Pnt& theCOG) Standard_OVERRIDE;
134 //! Calculates the point on a view ray that was detected during the run of selection algo by given depth. Is valid for point
136 Standard_EXPORT virtual NCollection_Vec3<Standard_Real> DetectedPoint (const Standard_Real theDepth) const Standard_OVERRIDE;
138 //! Checks if the point of sensitive in which selection was detected belongs
139 //! to the region defined by clipping planes
140 Standard_EXPORT virtual Standard_Boolean IsClipped (const Graphic3d_SequenceOfHClipPlane& thePlanes,
141 const Standard_Real& theDepth);
143 //! Is used for rectangular selection only
144 //! If theIsToAllow is false, only fully included sensitives will be detected, otherwise the algorithm will
145 //! mark both included and overlapped entities as matched
146 Standard_EXPORT virtual void AllowOverlapDetection (const Standard_Boolean theIsToAllow);
148 Standard_EXPORT virtual Standard_Boolean IsOverlapAllowed() const Standard_OVERRIDE;
151 enum { Frustum, FrustumSet, VolumeTypesNb }; //!< Defines the amount of available selecting volumes
153 NCollection_Handle<SelectMgr_BaseFrustum> mySelectingVolumes[VolumeTypesNb]; //!< Array of selecting volumes
154 Standard_Boolean myToAllowOverlap; //!< Defines if partially overlapped entities will me detected or not