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