0026147: Visualization - restore the ability to pick only fully included objects...
[occt.git] / src / Select3D / Select3D_SensitiveTriangulation.hxx
1 // Created on: 1997-05-15
2 // Created by: Robert COUBLANC
3 // Copyright (c) 1997-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
5 //
6 // This file is part of Open CASCADE Technology software library.
7 //
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
13 //
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
16
17 //Modified      Thur Apr 09 98 by rob : No more computation of free edges.
18 //                                      fix bug on Compute Depth (don't forget
19 //                                      Location...)
20
21 #ifndef _Select3D_SensitiveTriangulation_Header
22 #define _Select3D_SensitiveTriangulation_Header
23
24 #include <Standard.hxx>
25 #include <Standard_DefineHandle.hxx>
26 #include <Standard_Type.hxx>
27
28 #include <Handle_Poly_Triangulation.hxx>
29 #include <TopLoc_Location.hxx>
30 #include <gp_Trsf.hxx>
31 #include <gp_Pnt.hxx>
32 #include <TColStd_HArray1OfInteger.hxx>
33 #include <Handle_TColStd_HArray1OfInteger.hxx>
34 #include <Standard_Boolean.hxx>
35 #include <TColgp_HArray1OfPnt.hxx>
36 #include <Select3D_SensitiveEntity.hxx>
37 #include <Handle_SelectBasics_EntityOwner.hxx>
38 #include <SelectMgr_SelectingVolumeManager.hxx>
39 #include <Standard_OStream.hxx>
40 #include <Select3D_SensitiveSet.hxx>
41 #include <NCollection_Handle.hxx>
42
43 class Poly_Triangulation;
44 class TColStd_HArray1OfInteger;
45 class SelectBasics_EntityOwner;
46 class TopLoc_Location;
47 class gp_Pnt;
48 class Select3D_SensitiveEntity;
49 class Handle(Select3D_SensitiveEntity);
50 class TColgp_Array1OfPnt2d;
51
52 //! A framework to define selection of a sensitive entity made of a set of triangles.
53 class Select3D_SensitiveTriangulation : public Select3D_SensitiveSet
54 {
55
56 public:
57
58   //! Constructs a sensitive triangulation object defined by
59   //! the owner theOwnerId, the triangulation theTrg,
60   //! the location theInitLoc, and the flag theIsInterior.
61   Standard_EXPORT Select3D_SensitiveTriangulation (const Handle(SelectBasics_EntityOwner)& theOwnerId,
62                                                    const Handle(Poly_Triangulation)& theTrg,
63                                                    const TopLoc_Location& theInitLoc,
64                                                    const Standard_Boolean theIsInterior = Standard_True);
65
66   //! Constructs a sensitive triangulation object defined by
67   //! the owner theOwnerId, the triangulation theTrg,
68   //! the location theInitLoc, the array of free edges
69   //! theFreeEdges, the center of gravity theCOG, and the flag theIsInterior.
70   //! As free edges and the center of gravity do not have
71   //! to be computed later, this syntax reduces computation time.
72   Standard_EXPORT Select3D_SensitiveTriangulation (const Handle(SelectBasics_EntityOwner)& theOwnerId,
73                                                    const Handle(Poly_Triangulation)& theTrg,
74                                                    const TopLoc_Location& theInitLoc,
75                                                    const Handle(TColStd_HArray1OfInteger)& theFreeEdges,
76                                                    const gp_Pnt& theCOG,
77                                                    const Standard_Boolean theIsInterior);
78
79   //! Returns the amount of nodes in triangulation
80   Standard_EXPORT virtual Standard_Integer NbSubElements() Standard_OVERRIDE;
81
82   Standard_EXPORT Handle_Select3D_SensitiveEntity GetConnected() Standard_OVERRIDE;
83
84   const Handle_Poly_Triangulation& Triangulation() const;
85
86   Standard_Boolean HasInitLocation() const;
87
88   const TopLoc_Location& GetInitLocation() const;
89
90   //! Returns the length of array of triangles or edges
91   Standard_EXPORT virtual Standard_Integer Size() const Standard_OVERRIDE;
92
93   //! Returns bounding box of triangle/edge with index theIdx
94   Standard_EXPORT virtual Select3D_BndBox3d Box (const Standard_Integer theIdx) const Standard_OVERRIDE;
95
96   //! Returns geometry center of triangle/edge with index theIdx
97   //! in array along the given axis theAxis
98   Standard_EXPORT virtual Standard_Real Center (const Standard_Integer theIdx,
99                                                 const Standard_Integer theAxis) const Standard_OVERRIDE;
100
101   //! Swaps items with indexes theIdx1 and theIdx2 in array
102   Standard_EXPORT virtual void Swap (const Standard_Integer theIdx1,
103                                      const Standard_Integer theIdx2) Standard_OVERRIDE;
104
105   //! Returns bounding box of the triangulation. If location
106   //! transformation is set, it will be applied
107   Standard_EXPORT virtual Select3D_BndBox3d BoundingBox() Standard_OVERRIDE;
108
109   //! Returns center of triangulation. If location transformation
110   //! is set, it will be applied
111   Standard_EXPORT virtual gp_Pnt CenterOfGeometry() const Standard_OVERRIDE;
112
113 public:
114   DEFINE_STANDARD_RTTI(Select3D_SensitiveTriangulation)
115
116 protected:
117
118   //! Inner function for transformation application to bounding
119   //! box of the triangulation
120   Select3D_BndBox3d applyTransformation();
121
122
123 private:
124
125   //! Checks whether the element with index theIdx overlaps the current selecting volume
126   virtual Standard_Boolean overlapsElement (SelectBasics_SelectingVolumeManager& theMgr,
127                                             Standard_Integer theElemIdx,
128                                             Standard_Real& theMatchDepth) Standard_OVERRIDE;
129
130   //! Calculates distance from the 3d projection of used-picked screen point to center of the geometry
131   virtual Standard_Real distanceToCOG (SelectBasics_SelectingVolumeManager& theMgr) Standard_OVERRIDE;
132
133   //! Checks whether the entity with index theIdx is inside the current selecting volume
134   virtual Standard_Boolean elementIsInside (SelectBasics_SelectingVolumeManager& theMgr,
135                                             const Standard_Integer               theElemIdx) Standard_OVERRIDE;
136
137 public:
138   Standard_Real myBVHBuildTime;
139
140 private:
141
142   Handle_Poly_Triangulation       myTriangul;
143   TopLoc_Location                 myInitLocation;
144   gp_Pnt                          myCDG3D;              //!< Center of the whole triangulation
145   Handle_TColStd_HArray1OfInteger myFreeEdges;
146   Standard_Boolean                mySensType;            //!< Type of sensitivity: boundary or interior
147   Standard_Integer                myDetectedTr;
148   Standard_Integer                myPrimitivesNb;       //!< Amount of free edges or triangles depending on sensitivity type
149   Handle_TColStd_HArray1OfInteger myBVHPrimIndexes;     //!< Indexes of edges or triangles for BVH build
150   mutable Select3D_BndBox3d       myBndBox;             //!< Bounding box of the whole triangulation
151 };
152
153 DEFINE_STANDARD_HANDLE(Select3D_SensitiveTriangulation, Select3D_SensitiveSet)
154
155 #include <Select3D_SensitiveTriangulation.lxx>
156
157
158 #endif // _Select3D_SensitiveTriangulation_Header