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
6 // This file is part of Open CASCADE Technology software library.
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.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
17 #ifndef _Select3D_SensitiveTriangulation_Header
18 #define _Select3D_SensitiveTriangulation_Header
20 #include <TopLoc_Location.hxx>
21 #include <gp_Trsf.hxx>
23 #include <TColStd_HArray1OfInteger.hxx>
24 #include <Select3D_SensitiveEntity.hxx>
25 #include <SelectMgr_SelectingVolumeManager.hxx>
26 #include <Select3D_SensitiveSet.hxx>
28 class Poly_Triangulation;
30 //! A framework to define selection of a sensitive entity made of a set of triangles.
31 class Select3D_SensitiveTriangulation : public Select3D_SensitiveSet
33 DEFINE_STANDARD_RTTIEXT(Select3D_SensitiveTriangulation, Select3D_SensitiveSet)
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);
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,
55 const Standard_Boolean theIsInterior);
57 //! Returns the amount of nodes in triangulation
58 Standard_EXPORT virtual Standard_Integer NbSubElements() Standard_OVERRIDE;
60 Standard_EXPORT Handle(Select3D_SensitiveEntity) GetConnected() Standard_OVERRIDE;
62 const Handle(Poly_Triangulation)& Triangulation() const { return myTriangul; }
64 //! Returns the length of array of triangles or edges
65 Standard_EXPORT virtual Standard_Integer Size() const Standard_OVERRIDE;
67 //! Returns bounding box of triangle/edge with index theIdx
68 Standard_EXPORT virtual Select3D_BndBox3d Box (const Standard_Integer theIdx) const Standard_OVERRIDE;
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;
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;
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;
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;
87 //! Returns true if the shape corresponding to the entity has init location
88 Standard_EXPORT virtual Standard_Boolean HasInitLocation() const Standard_OVERRIDE;
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;
94 const TopLoc_Location& GetInitLocation() const { return myInitLocation; }
98 //! Inner function for transformation application to bounding
99 //! box of the triangulation
100 Select3D_BndBox3d applyTransformation();
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;
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;
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;
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;
129 DEFINE_STANDARD_HANDLE(Select3D_SensitiveTriangulation, Select3D_SensitiveSet)
131 #endif // _Select3D_SensitiveTriangulation_Header