0027536: Visualization - incorrect behavior of zoom persisted objects
[occt.git] / src / SelectMgr / SelectMgr_BaseFrustum.hxx
1 // Created on: 2014-05-22
2 // Created by: Varvara POSKONINA
3 // Copyright (c) 2005-2014 OPEN CASCADE SAS
4 //
5 // This file is part of Open CASCADE Technology software library.
6 //
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.
12 //
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
15
16 #ifndef _SelectMgr_BaseFrustum_HeaderFile
17 #define _SelectMgr_BaseFrustum_HeaderFile
18
19 #include <gp_GTrsf.hxx>
20 #include <gp_Pnt.hxx>
21 #include <gp_Pln.hxx>
22
23 #include <Graphic3d_Camera.hxx>
24 #include <Graphic3d_ClipPlane.hxx>
25 #include <Graphic3d_SequenceOfHClipPlane.hxx>
26 #include <Graphic3d_WorldViewProjState.hxx>
27
28 #include <TColgp_HArray1OfPnt.hxx>
29 #include <TColgp_Array1OfPnt2d.hxx>
30
31 #include <Select3D_BndBox3d.hxx>
32 #include <SelectMgr_FrustumBuilder.hxx>
33 #include <Select3D_TypeOfSensitivity.hxx>
34 #include <SelectMgr_VectorTypes.hxx>
35
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 : public Standard_Transient
42 {
43 public:
44
45   //! Creates new selecting volume with pixel toletance set to 2,
46   //! orthographic camera and empty frustum builder
47   Standard_EXPORT SelectMgr_BaseFrustum();
48
49   virtual ~SelectMgr_BaseFrustum() {}
50
51   //! Passes camera projection and orientation matrices to builder
52   Standard_EXPORT void SetCamera (const Handle(Graphic3d_Camera)& theCamera);
53
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_Integer theIsOrthographic,
58                                   const Graphic3d_WorldViewProjState& theWVPState = Graphic3d_WorldViewProjState());
59
60   //! @return current camera projection transformation common for all selecting volumes
61   Standard_EXPORT const Graphic3d_Mat4d& ProjectionMatrix() const;
62
63   //! @return current camera world view transformation common for all selecting volumes
64   Standard_EXPORT const Graphic3d_Mat4d& WorldViewMatrix() const;
65
66   //! @return current camera world view projection transformation state
67   Standard_EXPORT const Graphic3d_WorldViewProjState& WorldViewProjState() const;
68
69   Standard_EXPORT void SetPixelTolerance (const Standard_Integer theTol);
70
71   Standard_EXPORT void SetWindowSize (const Standard_Integer theWidth, 
72                                       const Standard_Integer theHeight);
73
74   Standard_EXPORT void WindowSize (Standard_Integer& theWidth,
75                                    Standard_Integer& theHeight);
76
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);
82
83   //! Nullifies the builder created in the constructor and copies the pointer given
84   Standard_EXPORT void SetBuilder (const Handle(SelectMgr_FrustumBuilder)& theBuilder);
85
86
87   //! Builds volume according to the point and given pixel tolerance
88   virtual void Build (const gp_Pnt2d& /*thePoint*/) {}
89
90   //! Builds volume according to the selected rectangle
91   virtual void Build (const gp_Pnt2d& /*theMinPt*/,
92                       const gp_Pnt2d& /*theMaxPt*/) {}
93
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*/) {}
98
99   //! Builds selecting volumes set according to polyline points
100   virtual void Build (const TColgp_Array1OfPnt2d& /*thePoints*/) {}
101
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   Standard_EXPORT virtual NCollection_Handle<SelectMgr_BaseFrustum> ScaleAndTransform (const Standard_Integer /*theScaleFactor*/,
110                                                                                        const gp_GTrsf& /*theTrsf*/) { return NULL; }
111
112   //! SAT intersection test between defined volume and given axis-aligned box
113   Standard_EXPORT virtual Standard_Boolean Overlaps (const SelectMgr_Vec3& theBoxMin,
114                                                      const SelectMgr_Vec3& theBoxMax,
115                                                      Standard_Real& theDepth);
116
117   //! Returns true if selecting volume is overlapped by axis-aligned bounding box
118   //! with minimum corner at point theMinPt and maximum at point theMaxPt
119   Standard_EXPORT virtual Standard_Boolean Overlaps (const SelectMgr_Vec3& theBoxMin,
120                                                      const SelectMgr_Vec3& theBoxMax,
121                                                      Standard_Boolean*     theInside = NULL);
122
123   //! Intersection test between defined volume and given point
124   Standard_EXPORT virtual Standard_Boolean Overlaps (const gp_Pnt& thePnt,
125                                                      Standard_Real& theDepth);
126
127   //! Intersection test between defined volume and given point
128   //! Does not perform depth calculation, so this method is defined as
129   //! helper function for inclusion test. Therefore, its implementation
130   //! makes sense only for rectangular frustum with box selection mode activated.
131   Standard_EXPORT virtual Standard_Boolean Overlaps (const gp_Pnt& thePnt);
132
133   //! SAT intersection test between defined volume and given ordered set of points,
134   //! representing line segments. The test may be considered of interior part or
135   //! boundary line defined by segments depending on given sensitivity type
136   Standard_EXPORT virtual Standard_Boolean Overlaps (const TColgp_Array1OfPnt& theArrayOfPnts,
137                                                      Select3D_TypeOfSensitivity theSensType,
138                                                      Standard_Real& theDepth);
139
140   //! Checks if line segment overlaps selecting frustum
141   Standard_EXPORT virtual Standard_Boolean Overlaps (const gp_Pnt& thePnt1,
142                                                      const gp_Pnt& thePnt2,
143                                                      Standard_Real& theDepth);
144
145   //! SAT intersection test between defined volume and given triangle. The test may
146   //! be considered of interior part or boundary line defined by triangle vertices
147   //! depending on given sensitivity type
148   Standard_EXPORT virtual Standard_Boolean Overlaps (const gp_Pnt& thePt1,
149                                                      const gp_Pnt& thePt2,
150                                                      const gp_Pnt& thePt3,
151                                                      Select3D_TypeOfSensitivity theSensType,
152                                                      Standard_Real& theDepth);
153
154   //! Measures distance between 3d projection of user-picked
155   //! screen point and given point theCOG
156   Standard_EXPORT virtual Standard_Real DistToGeometryCenter (const gp_Pnt& theCOG);
157
158   Standard_EXPORT virtual gp_Pnt DetectedPoint (const Standard_Real theDepth) const;
159
160   //! Checks if the point of sensitive in which selection was detected belongs
161   //! to the region defined by clipping planes
162   Standard_EXPORT virtual Standard_Boolean IsClipped (const Graphic3d_SequenceOfHClipPlane& thePlanes,
163                                                       const Standard_Real theDepth);
164
165   //! Valid for point selection only!
166   //! Computes depth range for global (defined for the whole view) clipping planes.
167   virtual void SetViewClipping (const Graphic3d_SequenceOfHClipPlane& /*thePlanes*/) {};
168
169   DEFINE_STANDARD_RTTIEXT(SelectMgr_BaseFrustum,Standard_Transient)
170
171 protected:
172   Standard_Integer    myPixelTolerance;      //!< Pixel tolerance
173   Standard_Boolean    myIsOrthographic;      //!< Defines if current camera is orthographic
174
175   Handle(SelectMgr_FrustumBuilder) myBuilder; //!< A tool implementing methods for volume build
176 };
177
178 #endif // _SelectMgr_BaseFrustum_HeaderFile