a6b2741b6f18b2ab5828fddcbf40bd521fc5ec1e
[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_Type.hxx>
26 #include <Standard_Type.hxx>
27
28 #include <TopLoc_Location.hxx>
29 #include <gp_Trsf.hxx>
30 #include <gp_Pnt.hxx>
31 #include <TColStd_HArray1OfInteger.hxx>
32 #include <TColStd_HArray1OfInteger.hxx>
33 #include <Standard_Boolean.hxx>
34 #include <TColgp_HArray1OfPnt.hxx>
35 #include <Select3D_SensitiveEntity.hxx>
36 #include <SelectMgr_SelectingVolumeManager.hxx>
37 #include <Standard_OStream.hxx>
38 #include <Select3D_SensitiveSet.hxx>
39 #include <NCollection_Handle.hxx>
40
41 class Poly_Triangulation;
42 class SelectBasics_EntityOwner;
43 class TopLoc_Location;
44 class gp_Pnt;
45 class Select3D_SensitiveEntity;
46
47 //! A framework to define selection of a sensitive entity made of a set of triangles.
48 class Select3D_SensitiveTriangulation : public Select3D_SensitiveSet
49 {
50
51 public:
52
53   //! Constructs a sensitive triangulation object defined by
54   //! the owner theOwnerId, the triangulation theTrg,
55   //! the location theInitLoc, and the flag theIsInterior.
56   Standard_EXPORT Select3D_SensitiveTriangulation (const Handle(SelectBasics_EntityOwner)& theOwnerId,
57                                                    const Handle(Poly_Triangulation)& theTrg,
58                                                    const TopLoc_Location& theInitLoc,
59                                                    const Standard_Boolean theIsInterior = Standard_True);
60
61   //! Constructs a sensitive triangulation object defined by
62   //! the owner theOwnerId, the triangulation theTrg,
63   //! the location theInitLoc, the array of free edges
64   //! theFreeEdges, the center of gravity theCOG, and the flag theIsInterior.
65   //! As free edges and the center of gravity do not have
66   //! to be computed later, this syntax reduces computation time.
67   Standard_EXPORT Select3D_SensitiveTriangulation (const Handle(SelectBasics_EntityOwner)& theOwnerId,
68                                                    const Handle(Poly_Triangulation)& theTrg,
69                                                    const TopLoc_Location& theInitLoc,
70                                                    const Handle(TColStd_HArray1OfInteger)& theFreeEdges,
71                                                    const gp_Pnt& theCOG,
72                                                    const Standard_Boolean theIsInterior);
73
74   //! Returns the amount of nodes in triangulation
75   Standard_EXPORT virtual Standard_Integer NbSubElements() Standard_OVERRIDE;
76
77   Standard_EXPORT Handle(Select3D_SensitiveEntity) GetConnected() Standard_OVERRIDE;
78
79   const Handle(Poly_Triangulation)& Triangulation() const;
80
81   Standard_Boolean HasInitLocation() const;
82
83   const TopLoc_Location& GetInitLocation() const;
84
85   //! Returns the length of array of triangles or edges
86   Standard_EXPORT virtual Standard_Integer Size() const Standard_OVERRIDE;
87
88   //! Returns bounding box of triangle/edge with index theIdx
89   Standard_EXPORT virtual Select3D_BndBox3d Box (const Standard_Integer theIdx) const Standard_OVERRIDE;
90
91   //! Returns geometry center of triangle/edge with index theIdx
92   //! in array along the given axis theAxis
93   Standard_EXPORT virtual Standard_Real Center (const Standard_Integer theIdx,
94                                                 const Standard_Integer theAxis) const Standard_OVERRIDE;
95
96   //! Swaps items with indexes theIdx1 and theIdx2 in array
97   Standard_EXPORT virtual void Swap (const Standard_Integer theIdx1,
98                                      const Standard_Integer theIdx2) Standard_OVERRIDE;
99
100   //! Returns bounding box of the triangulation. If location
101   //! transformation is set, it will be applied
102   Standard_EXPORT virtual Select3D_BndBox3d BoundingBox() Standard_OVERRIDE;
103
104   //! Returns center of triangulation. If location transformation
105   //! is set, it will be applied
106   Standard_EXPORT virtual gp_Pnt CenterOfGeometry() const Standard_OVERRIDE;
107
108 public:
109   DEFINE_STANDARD_RTTI(Select3D_SensitiveTriangulation, Select3D_SensitiveSet)
110
111 protected:
112
113   //! Inner function for transformation application to bounding
114   //! box of the triangulation
115   Select3D_BndBox3d applyTransformation();
116
117
118 private:
119
120   //! Checks whether the element with index theIdx overlaps the current selecting volume
121   virtual Standard_Boolean overlapsElement (SelectBasics_SelectingVolumeManager& theMgr,
122                                             Standard_Integer theElemIdx,
123                                             Standard_Real& theMatchDepth) Standard_OVERRIDE;
124
125   //! Calculates distance from the 3d projection of used-picked screen point to center of the geometry
126   virtual Standard_Real distanceToCOG (SelectBasics_SelectingVolumeManager& theMgr) Standard_OVERRIDE;
127
128   //! Checks whether the entity with index theIdx is inside the current selecting volume
129   virtual Standard_Boolean elementIsInside (SelectBasics_SelectingVolumeManager& theMgr,
130                                             const Standard_Integer               theElemIdx) Standard_OVERRIDE;
131
132 public:
133   Standard_Real myBVHBuildTime;
134
135 private:
136
137   Handle(Poly_Triangulation)       myTriangul;
138   TopLoc_Location                 myInitLocation;
139   gp_Pnt                          myCDG3D;              //!< Center of the whole triangulation
140   Handle(TColStd_HArray1OfInteger) myFreeEdges;
141   Standard_Boolean                mySensType;            //!< Type of sensitivity: boundary or interior
142   Standard_Integer                myDetectedTr;
143   Standard_Integer                myPrimitivesNb;       //!< Amount of free edges or triangles depending on sensitivity type
144   Handle(TColStd_HArray1OfInteger) myBVHPrimIndexes;     //!< Indexes of edges or triangles for BVH build
145   mutable Select3D_BndBox3d       myBndBox;             //!< Bounding box of the whole triangulation
146 };
147
148 DEFINE_STANDARD_HANDLE(Select3D_SensitiveTriangulation, Select3D_SensitiveSet)
149
150 #include <Select3D_SensitiveTriangulation.lxx>
151
152
153 #endif // _Select3D_SensitiveTriangulation_Header