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>
28 #include <NCollection_Handle.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
46 //! Creates new selecting volume with pixel toletance set to 2,
47 //! orthographic camera and empty frustum builder
48 SelectMgr_BaseFrustum();
50 virtual ~SelectMgr_BaseFrustum() {};
52 //! Passes camera projection and orientation matrices to builder
53 void SetCamera (const Handle(Graphic3d_Camera)& theCamera);
55 //! Passes camera projection and orientation matrices to builder
56 void SetCamera (const Graphic3d_Mat4d& theProjection,
57 const Graphic3d_Mat4d& theOrientation,
58 const Standard_Integer theIsOrthographic);
60 void SetPixelTolerance (const Standard_Real theTol);
62 void SetWindowSize (const Standard_Integer theWidth, const Standard_Integer theHeight);
64 //! Passes viewport parameters to builder
65 void SetViewport (const Standard_Real theX,
66 const Standard_Real theY,
67 const Standard_Real theWidth,
68 const Standard_Real theHeight);
70 //! Nullifies the builder created in the constructor and copies the pointer given
71 void SetBuilder (const NCollection_Handle<SelectMgr_FrustumBuilder>& theBuilder);
74 //! Builds volume according to the point and given pixel tolerance
75 virtual void Build (const gp_Pnt2d& /*thePoint*/) {};
77 //! Builds volume according to the selected rectangle
78 virtual void Build (const gp_Pnt2d& /*theMinPt*/,
79 const gp_Pnt2d& /*theMaxPt*/) {};
81 //! Builds volume according to the triangle given
82 virtual void Build (const gp_Pnt2d& /*theP1*/,
83 const gp_Pnt2d& /*theP2*/,
84 const gp_Pnt2d& /*theP3*/) {};
86 //! Builds selecting volumes set according to polyline points
87 virtual void Build (const TColgp_Array1OfPnt2d& /*thePoints*/) {};
89 virtual NCollection_Handle<SelectMgr_BaseFrustum> Transform (const gp_Trsf& /*theTrsf*/) { return NULL; }
91 //! IMPORTANT: Makes sense only for frustum built on a single point!
92 //! Returns a copy of the frustum resized according to the scale factor given
93 virtual NCollection_Handle<SelectMgr_BaseFrustum> Scale (const Standard_Real /*theScaleFactor*/) { return NULL; }
95 //! SAT intersection test between defined volume and given axis-aligned box
96 virtual Standard_Boolean Overlaps (const BVH_Box<Standard_Real, 3>& theBndBox,
97 Standard_Real& theDepth);
99 //! Returns true if selecting volume is overlapped by axis-aligned bounding box
100 //! with minimum corner at point theMinPt and maximum at point theMaxPt
101 virtual Standard_Boolean Overlaps (const SelectMgr_Vec3& theMinPt,
102 const SelectMgr_Vec3& theMaxPt);
104 //! Intersection test between defined volume and given point
105 virtual Standard_Boolean Overlaps (const gp_Pnt& thePt,
106 Standard_Real& theDepth);
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 virtual Standard_Boolean Overlaps (const Handle(TColgp_HArray1OfPnt)& theArrayOfPts,
112 Select3D_TypeOfSensitivity theSensType,
113 Standard_Real& theDepth);
115 //! Checks if line segment overlaps selecting frustum
116 virtual Standard_Boolean Overlaps (const gp_Pnt& thePt1,
117 const gp_Pnt& thePt2,
118 Standard_Real& theDepth);
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 virtual Standard_Boolean Overlaps (const gp_Pnt& thePt1,
124 const gp_Pnt& thePt2,
125 const gp_Pnt& thePt3,
126 Select3D_TypeOfSensitivity theSensType,
127 Standard_Real& theDepth);
129 //! Measures distance between 3d projection of user-picked
130 //! screen point and given point theCOG
131 virtual Standard_Real DistToGeometryCenter (const gp_Pnt& theCOG);
133 virtual SelectMgr_Vec3 DetectedPoint (const Standard_Real theDepth) const;
135 //! Checks if the point of sensitive in which selection was detected belongs
136 //! to the region defined by clipping planes
137 virtual Standard_Boolean IsClipped (const Graphic3d_SequenceOfHClipPlane& thePlanes,
138 const Standard_Real theDepth);
141 Standard_Real myPixelTolerance; //!< Pixel tolerance
142 Standard_Boolean myIsOrthographic; //!< Defines if current camera is orthographic
144 NCollection_Handle<SelectMgr_FrustumBuilder> myBuilder; //!< A tool implementing methods for volume build
147 #endif // _SelectMgr_BaseFrustum_HeaderFile