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 <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 //! This class is an interface for different types of selecting frustums,
37 //! defining different selection types, like point, box or polyline
38 //! selection. It contains signatures of functions for detection of
39 //! overlap by sensitive entity and initializes some data for building
40 //! the selecting frustum
41 class SelectMgr_BaseFrustum
45 //! Creates new selecting volume with pixel toletance set to 2,
46 //! orthographic camera and empty frustum builder
47 SelectMgr_BaseFrustum();
49 virtual ~SelectMgr_BaseFrustum() {}
51 //! Passes camera projection and orientation matrices to builder
52 void SetCamera (const Handle(Graphic3d_Camera)& theCamera);
54 //! Passes camera projection and orientation matrices to builder
55 void SetCamera (const Graphic3d_Mat4d& theProjection,
56 const Graphic3d_Mat4d& theOrientation,
57 const Standard_Integer theIsOrthographic);
59 void SetPixelTolerance (const Standard_Real theTol);
61 void SetWindowSize (const Standard_Integer theWidth, const Standard_Integer theHeight);
63 //! Passes viewport parameters to builder
64 void SetViewport (const Standard_Real theX,
65 const Standard_Real theY,
66 const Standard_Real theWidth,
67 const Standard_Real theHeight);
69 //! Nullifies the builder created in the constructor and copies the pointer given
70 void SetBuilder (const Handle(SelectMgr_FrustumBuilder)& theBuilder);
73 //! Builds volume according to the point and given pixel tolerance
74 virtual void Build (const gp_Pnt2d& /*thePoint*/) {}
76 //! Builds volume according to the selected rectangle
77 virtual void Build (const gp_Pnt2d& /*theMinPt*/,
78 const gp_Pnt2d& /*theMaxPt*/) {}
80 //! Builds volume according to the triangle given
81 virtual void Build (const gp_Pnt2d& /*theP1*/,
82 const gp_Pnt2d& /*theP2*/,
83 const gp_Pnt2d& /*theP3*/) {}
85 //! Builds selecting volumes set according to polyline points
86 virtual void Build (const TColgp_Array1OfPnt2d& /*thePoints*/) {}
88 virtual NCollection_Handle<SelectMgr_BaseFrustum> Transform (const gp_Trsf& /*theTrsf*/) { return NULL; }
90 //! IMPORTANT: Makes sense only for frustum built on a single point!
91 //! Returns a copy of the frustum resized according to the scale factor given
92 virtual NCollection_Handle<SelectMgr_BaseFrustum> Scale (const Standard_Real /*theScaleFactor*/) { return NULL; }
94 //! SAT intersection test between defined volume and given axis-aligned box
95 virtual Standard_Boolean Overlaps (const BVH_Box<Standard_Real, 3>& theBndBox,
96 Standard_Real& theDepth);
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 virtual Standard_Boolean Overlaps (const SelectMgr_Vec3& theBoxMin,
101 const SelectMgr_Vec3& theBoxMax,
102 Standard_Boolean* theInside = NULL);
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 Handle(SelectMgr_FrustumBuilder) myBuilder; //!< A tool implementing methods for volume build
147 #endif // _SelectMgr_BaseFrustum_HeaderFile