Warnings on vc14 were eliminated
[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   //! Returns the length of array of triangles or edges
82   Standard_EXPORT virtual Standard_Integer Size() const Standard_OVERRIDE;
83
84   //! Returns bounding box of triangle/edge with index theIdx
85   Standard_EXPORT virtual Select3D_BndBox3d Box (const Standard_Integer theIdx) const Standard_OVERRIDE;
86
87   //! Returns geometry center of triangle/edge with index theIdx
88   //! in array along the given axis theAxis
89   Standard_EXPORT virtual Standard_Real Center (const Standard_Integer theIdx,
90                                                 const Standard_Integer theAxis) const Standard_OVERRIDE;
91
92   //! Swaps items with indexes theIdx1 and theIdx2 in array
93   Standard_EXPORT virtual void Swap (const Standard_Integer theIdx1,
94                                      const Standard_Integer theIdx2) Standard_OVERRIDE;
95
96   //! Returns bounding box of the triangulation. If location
97   //! transformation is set, it will be applied
98   Standard_EXPORT virtual Select3D_BndBox3d BoundingBox() Standard_OVERRIDE;
99
100   //! Returns center of triangulation. If location transformation
101   //! is set, it will be applied
102   Standard_EXPORT virtual gp_Pnt CenterOfGeometry() const Standard_OVERRIDE;
103
104   //! Returns true if the shape corresponding to the entity has init location
105   Standard_EXPORT virtual Standard_Boolean HasInitLocation() const Standard_OVERRIDE;
106
107   //! Returns inversed location transformation matrix if the shape corresponding
108   //! to this entity has init location set. Otherwise, returns identity matrix.
109   Standard_EXPORT virtual gp_GTrsf InvInitLocation() const Standard_OVERRIDE;
110
111   inline const TopLoc_Location& GetInitLocation() const;
112
113 public:
114   DEFINE_STANDARD_RTTIEXT(Select3D_SensitiveTriangulation,Select3D_SensitiveSet)
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 private:
138
139   Handle(Poly_Triangulation)       myTriangul;
140   TopLoc_Location                  myInitLocation;
141   gp_Pnt                           myCDG3D;              //!< Center of the whole triangulation
142   Handle(TColStd_HArray1OfInteger) myFreeEdges;
143   Standard_Boolean                 mySensType;            //!< Type of sensitivity: boundary or interior
144   Standard_Integer                 myPrimitivesNb;       //!< Amount of free edges or triangles depending on sensitivity type
145   Handle(TColStd_HArray1OfInteger) myBVHPrimIndexes;     //!< Indexes of edges or triangles for BVH build
146   mutable Select3D_BndBox3d        myBndBox;             //!< Bounding box of the whole triangulation
147   gp_GTrsf                         myInvInitLocation;
148 };
149
150 DEFINE_STANDARD_HANDLE(Select3D_SensitiveTriangulation, Select3D_SensitiveSet)
151
152 #include <Select3D_SensitiveTriangulation.lxx>
153
154
155 #endif // _Select3D_SensitiveTriangulation_Header