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 <gp_GTrsf.hxx>
20 #include <Graphic3d_Camera.hxx>
21 #include <Graphic3d_WorldViewProjState.hxx>
22 #include <Select3D_BndBox3d.hxx>
23 #include <Select3D_TypeOfSensitivity.hxx>
24 #include <SelectMgr_FrustumBuilder.hxx>
25 #include <SelectMgr_VectorTypes.hxx>
26 #include <SelectMgr_ViewClipRange.hxx>
27 #include <SelectBasics_PickResult.hxx>
28 #include <TColgp_Array1OfPnt.hxx>
29 #include <TColgp_Array1OfPnt2d.hxx>
31 #include <Standard_OStream.hxx>
33 //! This class is an interface for different types of selecting frustums,
34 //! defining different selection types, like point, box or polyline
35 //! selection. It contains signatures of functions for detection of
36 //! overlap by sensitive entity and initializes some data for building
37 //! the selecting frustum
38 class SelectMgr_BaseFrustum : public Standard_Transient
42 //! Creates new selecting volume with pixel toletance set to 2,
43 //! orthographic camera and empty frustum builder
44 Standard_EXPORT SelectMgr_BaseFrustum();
46 virtual ~SelectMgr_BaseFrustum() {}
48 //! Return camera definition.
49 const Handle(Graphic3d_Camera)& Camera() const { return myCamera; }
51 //! Passes camera projection and orientation matrices to builder
52 Standard_EXPORT void SetCamera (const Handle(Graphic3d_Camera)& theCamera);
54 //! Passes camera projection and orientation matrices to builder
55 Standard_EXPORT void SetCamera (const Graphic3d_Mat4d& theProjection,
56 const Graphic3d_Mat4d& theWorldView,
57 const Standard_Boolean theIsOrthographic,
58 const Graphic3d_WorldViewProjState& theWVPState = Graphic3d_WorldViewProjState());
60 //! @return current camera projection transformation common for all selecting volumes
61 Standard_EXPORT const Graphic3d_Mat4d& ProjectionMatrix() const;
63 //! @return current camera world view transformation common for all selecting volumes
64 Standard_EXPORT const Graphic3d_Mat4d& WorldViewMatrix() const;
66 //! @return current camera world view projection transformation state
67 Standard_EXPORT const Graphic3d_WorldViewProjState& WorldViewProjState() const;
69 Standard_EXPORT void SetPixelTolerance (const Standard_Integer theTol);
71 Standard_EXPORT void SetWindowSize (const Standard_Integer theWidth,
72 const Standard_Integer theHeight);
74 Standard_EXPORT void WindowSize (Standard_Integer& theWidth,
75 Standard_Integer& theHeight) const;
77 //! Passes viewport parameters to builder
78 Standard_EXPORT void SetViewport (const Standard_Real theX,
79 const Standard_Real theY,
80 const Standard_Real theWidth,
81 const Standard_Real theHeight);
83 //! Nullifies the builder created in the constructor and copies the pointer given
84 Standard_EXPORT void SetBuilder (const Handle(SelectMgr_FrustumBuilder)& theBuilder);
87 //! Builds volume according to the point and given pixel tolerance
88 virtual void Build (const gp_Pnt2d& /*thePoint*/) {}
90 //! Builds volume according to the selected rectangle
91 virtual void Build (const gp_Pnt2d& /*theMinPt*/,
92 const gp_Pnt2d& /*theMaxPt*/) {}
94 //! Builds volume according to the triangle given
95 virtual void Build (const gp_Pnt2d& /*theP1*/,
96 const gp_Pnt2d& /*theP2*/,
97 const gp_Pnt2d& /*theP3*/) {}
99 //! Builds selecting volumes set according to polyline points
100 virtual void Build (const TColgp_Array1OfPnt2d& /*thePoints*/) {}
102 //! IMPORTANT: Scaling makes sense only for frustum built on a single point!
103 //! Note that this method does not perform any checks on type of the frustum.
104 //! Returns a copy of the frustum resized according to the scale factor given
105 //! and transforms it using the matrix given.
106 //! There are no default parameters, but in case if:
107 //! - transformation only is needed: @theScaleFactor must be initialized as any negative value;
108 //! - scale only is needed: @theTrsf must be set to gp_Identity.
109 virtual Handle(SelectMgr_BaseFrustum) ScaleAndTransform (const Standard_Integer /*theScaleFactor*/,
110 const gp_GTrsf& /*theTrsf*/) const
115 //! SAT intersection test between defined volume and given axis-aligned box
116 Standard_EXPORT virtual Standard_Boolean Overlaps (const SelectMgr_Vec3& theBoxMin,
117 const SelectMgr_Vec3& theBoxMax,
118 const SelectMgr_ViewClipRange& theClipRange,
119 SelectBasics_PickResult& thePickResult) const;
121 //! Returns true if selecting volume is overlapped by axis-aligned bounding box
122 //! with minimum corner at point theMinPt and maximum at point theMaxPt
123 Standard_EXPORT virtual Standard_Boolean Overlaps (const SelectMgr_Vec3& theBoxMin,
124 const SelectMgr_Vec3& theBoxMax,
125 Standard_Boolean* theInside = NULL) const;
127 //! Intersection test between defined volume and given point
128 Standard_EXPORT virtual Standard_Boolean Overlaps (const gp_Pnt& thePnt,
129 const SelectMgr_ViewClipRange& theClipRange,
130 SelectBasics_PickResult& thePickResult) const;
132 //! Intersection test between defined volume and given point
133 //! Does not perform depth calculation, so this method is defined as
134 //! helper function for inclusion test. Therefore, its implementation
135 //! makes sense only for rectangular frustum with box selection mode activated.
136 Standard_EXPORT virtual Standard_Boolean Overlaps (const gp_Pnt& thePnt) const;
138 //! SAT intersection test between defined volume and given ordered set of points,
139 //! representing line segments. The test may be considered of interior part or
140 //! boundary line defined by segments depending on given sensitivity type
141 Standard_EXPORT virtual Standard_Boolean Overlaps (const TColgp_Array1OfPnt& theArrayOfPnts,
142 Select3D_TypeOfSensitivity theSensType,
143 const SelectMgr_ViewClipRange& theClipRange,
144 SelectBasics_PickResult& thePickResult) const;
146 //! Checks if line segment overlaps selecting frustum
147 Standard_EXPORT virtual Standard_Boolean Overlaps (const gp_Pnt& thePnt1,
148 const gp_Pnt& thePnt2,
149 const SelectMgr_ViewClipRange& theClipRange,
150 SelectBasics_PickResult& thePickResult) const;
152 //! SAT intersection test between defined volume and given triangle. The test may
153 //! be considered of interior part or boundary line defined by triangle vertices
154 //! depending on given sensitivity type
155 Standard_EXPORT virtual Standard_Boolean Overlaps (const gp_Pnt& thePt1,
156 const gp_Pnt& thePt2,
157 const gp_Pnt& thePt3,
158 Select3D_TypeOfSensitivity theSensType,
159 const SelectMgr_ViewClipRange& theClipRange,
160 SelectBasics_PickResult& thePickResult) const;
162 //! Measures distance between 3d projection of user-picked
163 //! screen point and given point theCOG
164 Standard_EXPORT virtual Standard_Real DistToGeometryCenter (const gp_Pnt& theCOG) const;
166 Standard_EXPORT virtual gp_Pnt DetectedPoint (const Standard_Real theDepth) const;
168 //! Stores plane equation coefficients (in the following form:
169 //! Ax + By + Cz + D = 0) to the given vector
170 virtual void GetPlanes (NCollection_Vector<SelectMgr_Vec4>& thePlaneEquations) const
172 thePlaneEquations.Clear();
176 //! Dumps the content of me into the stream
177 Standard_EXPORT virtual void DumpJson (Standard_OStream& theOStream, const Standard_Integer theDepth = -1) const;
179 DEFINE_STANDARD_RTTIEXT(SelectMgr_BaseFrustum,Standard_Transient)
182 Standard_Integer myPixelTolerance; //!< Pixel tolerance
183 Standard_Boolean myIsOrthographic; //!< Defines if current camera is orthographic
185 Handle(SelectMgr_FrustumBuilder) myBuilder; //!< A tool implementing methods for volume build
186 Handle(Graphic3d_Camera) myCamera; //!< camera definition
189 #endif // _SelectMgr_BaseFrustum_HeaderFile