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>
23 #include <Graphic3d_Camera.hxx>
24 #include <Graphic3d_ClipPlane.hxx>
25 #include <Graphic3d_SequenceOfHClipPlane.hxx>
26 #include <Graphic3d_WorldViewProjState.hxx>
28 #include <TColgp_HArray1OfPnt.hxx>
29 #include <TColgp_Array1OfPnt2d.hxx>
31 #include <Select3D_BndBox3d.hxx>
32 #include <SelectMgr_FrustumBuilder.hxx>
33 #include <Select3D_TypeOfSensitivity.hxx>
34 #include <SelectMgr_VectorTypes.hxx>
36 #include <SelectBasics_PickResult.hxx>
38 //! This class is an interface for different types of selecting frustums,
39 //! defining different selection types, like point, box or polyline
40 //! selection. It contains signatures of functions for detection of
41 //! overlap by sensitive entity and initializes some data for building
42 //! the selecting frustum
43 class SelectMgr_BaseFrustum : public Standard_Transient
47 //! Creates new selecting volume with pixel toletance set to 2,
48 //! orthographic camera and empty frustum builder
49 Standard_EXPORT SelectMgr_BaseFrustum();
51 virtual ~SelectMgr_BaseFrustum() {}
53 //! Return camera definition.
54 const Handle(Graphic3d_Camera)& Camera() const { return myCamera; }
56 //! Passes camera projection and orientation matrices to builder
57 Standard_EXPORT void SetCamera (const Handle(Graphic3d_Camera)& theCamera);
59 //! Passes camera projection and orientation matrices to builder
60 Standard_EXPORT void SetCamera (const Graphic3d_Mat4d& theProjection,
61 const Graphic3d_Mat4d& theWorldView,
62 const Standard_Boolean theIsOrthographic,
63 const Graphic3d_WorldViewProjState& theWVPState = Graphic3d_WorldViewProjState());
65 //! @return current camera projection transformation common for all selecting volumes
66 Standard_EXPORT const Graphic3d_Mat4d& ProjectionMatrix() const;
68 //! @return current camera world view transformation common for all selecting volumes
69 Standard_EXPORT const Graphic3d_Mat4d& WorldViewMatrix() const;
71 //! @return current camera world view projection transformation state
72 Standard_EXPORT const Graphic3d_WorldViewProjState& WorldViewProjState() const;
74 Standard_EXPORT void SetPixelTolerance (const Standard_Integer theTol);
76 Standard_EXPORT void SetWindowSize (const Standard_Integer theWidth,
77 const Standard_Integer theHeight);
79 Standard_EXPORT void WindowSize (Standard_Integer& theWidth,
80 Standard_Integer& theHeight) const;
82 //! Passes viewport parameters to builder
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 //! Nullifies the builder created in the constructor and copies the pointer given
89 Standard_EXPORT void SetBuilder (const Handle(SelectMgr_FrustumBuilder)& theBuilder);
92 //! Builds volume according to the point and given pixel tolerance
93 virtual void Build (const gp_Pnt2d& /*thePoint*/) {}
95 //! Builds volume according to the selected rectangle
96 virtual void Build (const gp_Pnt2d& /*theMinPt*/,
97 const gp_Pnt2d& /*theMaxPt*/) {}
99 //! Builds volume according to the triangle given
100 virtual void Build (const gp_Pnt2d& /*theP1*/,
101 const gp_Pnt2d& /*theP2*/,
102 const gp_Pnt2d& /*theP3*/) {}
104 //! Builds selecting volumes set according to polyline points
105 virtual void Build (const TColgp_Array1OfPnt2d& /*thePoints*/) {}
107 //! IMPORTANT: Scaling makes sense only for frustum built on a single point!
108 //! Note that this method does not perform any checks on type of the frustum.
109 //! Returns a copy of the frustum resized according to the scale factor given
110 //! and transforms it using the matrix given.
111 //! There are no default parameters, but in case if:
112 //! - transformation only is needed: @theScaleFactor must be initialized as any negative value;
113 //! - scale only is needed: @theTrsf must be set to gp_Identity.
114 virtual Handle(SelectMgr_BaseFrustum) ScaleAndTransform (const Standard_Integer /*theScaleFactor*/,
115 const gp_GTrsf& /*theTrsf*/) const
120 //! SAT intersection test between defined volume and given axis-aligned box
121 Standard_EXPORT virtual Standard_Boolean Overlaps (const SelectMgr_Vec3& theBoxMin,
122 const SelectMgr_Vec3& theBoxMax,
123 SelectBasics_PickResult& thePickResult) const;
125 //! Returns true if selecting volume is overlapped by axis-aligned bounding box
126 //! with minimum corner at point theMinPt and maximum at point theMaxPt
127 Standard_EXPORT virtual Standard_Boolean Overlaps (const SelectMgr_Vec3& theBoxMin,
128 const SelectMgr_Vec3& theBoxMax,
129 Standard_Boolean* theInside = NULL) const;
131 //! Intersection test between defined volume and given point
132 Standard_EXPORT virtual Standard_Boolean Overlaps (const gp_Pnt& thePnt,
133 SelectBasics_PickResult& thePickResult) const;
135 //! Intersection test between defined volume and given point
136 //! Does not perform depth calculation, so this method is defined as
137 //! helper function for inclusion test. Therefore, its implementation
138 //! makes sense only for rectangular frustum with box selection mode activated.
139 Standard_EXPORT virtual Standard_Boolean Overlaps (const gp_Pnt& thePnt) const;
141 //! SAT intersection test between defined volume and given ordered set of points,
142 //! representing line segments. The test may be considered of interior part or
143 //! boundary line defined by segments depending on given sensitivity type
144 Standard_EXPORT virtual Standard_Boolean Overlaps (const TColgp_Array1OfPnt& theArrayOfPnts,
145 Select3D_TypeOfSensitivity theSensType,
146 SelectBasics_PickResult& thePickResult) const;
148 //! Checks if line segment overlaps selecting frustum
149 Standard_EXPORT virtual Standard_Boolean Overlaps (const gp_Pnt& thePnt1,
150 const gp_Pnt& thePnt2,
151 SelectBasics_PickResult& thePickResult) const;
153 //! SAT intersection test between defined volume and given triangle. The test may
154 //! be considered of interior part or boundary line defined by triangle vertices
155 //! depending on given sensitivity type
156 Standard_EXPORT virtual Standard_Boolean Overlaps (const gp_Pnt& thePt1,
157 const gp_Pnt& thePt2,
158 const gp_Pnt& thePt3,
159 Select3D_TypeOfSensitivity theSensType,
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 //! Valid for point selection only!
169 //! Computes depth range for clipping planes.
170 //! @param theViewPlanes global view planes
171 //! @param theObjPlanes object planes
172 virtual void SetViewClipping (const Handle(Graphic3d_SequenceOfHClipPlane)& theViewPlanes,
173 const Handle(Graphic3d_SequenceOfHClipPlane)& theObjPlanes)
175 (void )theViewPlanes;
179 //! Stores plane equation coefficients (in the following form:
180 //! Ax + By + Cz + D = 0) to the given vector
181 virtual void GetPlanes (NCollection_Vector<SelectMgr_Vec4>& thePlaneEquations) const
183 thePlaneEquations.Clear();
187 DEFINE_STANDARD_RTTIEXT(SelectMgr_BaseFrustum,Standard_Transient)
190 Standard_Integer myPixelTolerance; //!< Pixel tolerance
191 Standard_Boolean myIsOrthographic; //!< Defines if current camera is orthographic
193 Handle(SelectMgr_FrustumBuilder) myBuilder; //!< A tool implementing methods for volume build
194 Handle(Graphic3d_Camera) myCamera; //!< camera definition
197 #endif // _SelectMgr_BaseFrustum_HeaderFile