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_BaseFrustum_HeaderFile
17 #define _SelectMgr_BaseFrustum_HeaderFile
19 #include <Bnd_Box.hxx>
24 #include <Graphic3d_Camera.hxx>
25 #include <Graphic3d_ClipPlane.hxx>
26 #include <Graphic3d_SequenceOfHClipPlane.hxx>
27 #include <Graphic3d_WorldViewProjState.hxx>
29 #include <TColgp_HArray1OfPnt.hxx>
30 #include <TColgp_Array1OfPnt2d.hxx>
32 #include <Select3D_BndBox3d.hxx>
33 #include <SelectMgr_FrustumBuilder.hxx>
34 #include <Select3D_TypeOfSensitivity.hxx>
35 #include <SelectMgr_VectorTypes.hxx>
37 //! This class is an interface for different types of selecting frustums,
38 //! defining different selection types, like point, box or polyline
39 //! selection. It contains signatures of functions for detection of
40 //! overlap by sensitive entity and initializes some data for building
41 //! the selecting frustum
42 class SelectMgr_BaseFrustum : public Standard_Transient
46 //! Creates new selecting volume with pixel toletance set to 2,
47 //! orthographic camera and empty frustum builder
48 Standard_EXPORT SelectMgr_BaseFrustum();
50 virtual ~SelectMgr_BaseFrustum() {}
52 //! Passes camera projection and orientation matrices to builder
53 Standard_EXPORT void SetCamera (const Handle(Graphic3d_Camera)& theCamera);
55 //! Passes camera projection and orientation matrices to builder
56 Standard_EXPORT void SetCamera (const Graphic3d_Mat4d& theProjection,
57 const Graphic3d_Mat4d& theWorldView,
58 const Standard_Integer theIsOrthographic,
59 const Graphic3d_WorldViewProjState& theWVPState = Graphic3d_WorldViewProjState());
61 //! @return current camera projection transformation common for all selecting volumes
62 Standard_EXPORT const Graphic3d_Mat4d& ProjectionMatrix() const;
64 //! @return current camera 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
68 Standard_EXPORT const Graphic3d_WorldViewProjState& WorldViewProjState() const;
70 Standard_EXPORT void SetPixelTolerance (const Standard_Real theTol);
72 Standard_EXPORT void SetWindowSize (const Standard_Integer theWidth,
73 const Standard_Integer theHeight);
75 //! Passes viewport parameters to builder
76 Standard_EXPORT void SetViewport (const Standard_Real theX,
77 const Standard_Real theY,
78 const Standard_Real theWidth,
79 const Standard_Real theHeight);
81 //! Nullifies the builder created in the constructor and copies the pointer given
82 Standard_EXPORT void SetBuilder (const Handle(SelectMgr_FrustumBuilder)& theBuilder);
85 //! Builds volume according to the point and given pixel tolerance
86 virtual void Build (const gp_Pnt2d& /*thePoint*/) {}
88 //! Builds volume according to the selected rectangle
89 virtual void Build (const gp_Pnt2d& /*theMinPt*/,
90 const gp_Pnt2d& /*theMaxPt*/) {}
92 //! Builds volume according to the triangle given
93 virtual void Build (const gp_Pnt2d& /*theP1*/,
94 const gp_Pnt2d& /*theP2*/,
95 const gp_Pnt2d& /*theP3*/) {}
97 //! Builds selecting volumes set according to polyline points
98 virtual void Build (const TColgp_Array1OfPnt2d& /*thePoints*/) {}
100 virtual NCollection_Handle<SelectMgr_BaseFrustum> Transform (const gp_Trsf& /*theTrsf*/) { return NULL; }
102 //! IMPORTANT: Makes sense only for frustum built on a single point!
103 //! Returns a copy of the frustum resized according to the scale factor given
104 virtual NCollection_Handle<SelectMgr_BaseFrustum> Scale (const Standard_Real /*theScaleFactor*/) { return NULL; }
106 //! SAT intersection test between defined volume and given axis-aligned box
107 Standard_EXPORT virtual Standard_Boolean Overlaps (const BVH_Box<Standard_Real, 3>& theBndBox,
108 Standard_Real& theDepth);
110 //! Returns true if selecting volume is overlapped by axis-aligned bounding box
111 //! with minimum corner at point theMinPt and maximum at point theMaxPt
112 Standard_EXPORT virtual Standard_Boolean Overlaps (const SelectMgr_Vec3& theBoxMin,
113 const SelectMgr_Vec3& theBoxMax,
114 Standard_Boolean* theInside = NULL);
116 //! Intersection test between defined volume and given point
117 Standard_EXPORT virtual Standard_Boolean Overlaps (const gp_Pnt& thePt,
118 Standard_Real& theDepth);
120 //! SAT intersection test between defined volume and given ordered set of points,
121 //! representing line segments. The test may be considered of interior part or
122 //! boundary line defined by segments depending on given sensitivity type
123 Standard_EXPORT virtual Standard_Boolean Overlaps (const Handle(TColgp_HArray1OfPnt)& theArrayOfPts,
124 Select3D_TypeOfSensitivity theSensType,
125 Standard_Real& theDepth);
127 //! Checks if line segment overlaps selecting frustum
128 Standard_EXPORT virtual Standard_Boolean Overlaps (const gp_Pnt& thePt1,
129 const gp_Pnt& thePt2,
130 Standard_Real& theDepth);
132 //! SAT intersection test between defined volume and given triangle. The test may
133 //! be considered of interior part or boundary line defined by triangle vertices
134 //! depending on given sensitivity type
135 Standard_EXPORT virtual Standard_Boolean Overlaps (const gp_Pnt& thePt1,
136 const gp_Pnt& thePt2,
137 const gp_Pnt& thePt3,
138 Select3D_TypeOfSensitivity theSensType,
139 Standard_Real& theDepth);
141 //! Measures distance between 3d projection of user-picked
142 //! screen point and given point theCOG
143 Standard_EXPORT virtual Standard_Real DistToGeometryCenter (const gp_Pnt& theCOG);
145 Standard_EXPORT virtual SelectMgr_Vec3 DetectedPoint (const Standard_Real theDepth) const;
147 //! Checks if the point of sensitive in which selection was detected belongs
148 //! to the region defined by clipping planes
149 Standard_EXPORT virtual Standard_Boolean IsClipped (const Graphic3d_SequenceOfHClipPlane& thePlanes,
150 const Standard_Real theDepth);
152 DEFINE_STANDARD_RTTI(SelectMgr_BaseFrustum, Standard_Transient)
155 Standard_Real myPixelTolerance; //!< Pixel tolerance
156 Standard_Boolean myIsOrthographic; //!< Defines if current camera is orthographic
158 Handle(SelectMgr_FrustumBuilder) myBuilder; //!< A tool implementing methods for volume build
161 #endif // _SelectMgr_BaseFrustum_HeaderFile