0030480: Visualization - Clear of Select3D_SensitiveGroup does not update internal...
[occt.git] / src / Select3D / Select3D_SensitiveTriangulation.hxx
CommitLineData
f751596e 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
f751596e 17#ifndef _Select3D_SensitiveTriangulation_Header
18#define _Select3D_SensitiveTriangulation_Header
19
f751596e 20#include <TopLoc_Location.hxx>
21#include <gp_Trsf.hxx>
22#include <gp_Pnt.hxx>
23#include <TColStd_HArray1OfInteger.hxx>
f751596e 24#include <Select3D_SensitiveEntity.hxx>
f751596e 25#include <SelectMgr_SelectingVolumeManager.hxx>
f751596e 26#include <Select3D_SensitiveSet.hxx>
f751596e 27
28class Poly_Triangulation;
f751596e 29
30//! A framework to define selection of a sensitive entity made of a set of triangles.
31class Select3D_SensitiveTriangulation : public Select3D_SensitiveSet
32{
0609d8ee 33 DEFINE_STANDARD_RTTIEXT(Select3D_SensitiveTriangulation, Select3D_SensitiveSet)
f751596e 34public:
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
35c0599a 60 Standard_EXPORT Handle(Select3D_SensitiveEntity) GetConnected() Standard_OVERRIDE;
f751596e 61
0609d8ee 62 const Handle(Poly_Triangulation)& Triangulation() const { return myTriangul; }
f751596e 63
f751596e 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
3bf9a45f 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.
91d96372 92 Standard_EXPORT virtual gp_GTrsf InvInitLocation() const Standard_OVERRIDE;
3bf9a45f 93
0609d8ee 94 const TopLoc_Location& GetInitLocation() const { return myInitLocation; }
f751596e 95
96protected:
97
98 //! Inner function for transformation application to bounding
99 //! box of the triangulation
100 Select3D_BndBox3d applyTransformation();
101
f751596e 102private:
103
104 //! Checks whether the element with index theIdx overlaps the current selecting volume
25333d45 105 Standard_EXPORT virtual Standard_Boolean overlapsElement (SelectBasics_PickResult& thePickResult,
106 SelectBasics_SelectingVolumeManager& theMgr,
107 Standard_Integer theElemIdx,
108 Standard_Boolean theIsFullInside) Standard_OVERRIDE;
f751596e 109
110 //! Calculates distance from the 3d projection of used-picked screen point to center of the geometry
25333d45 111 Standard_EXPORT virtual Standard_Real distanceToCOG (SelectBasics_SelectingVolumeManager& theMgr) Standard_OVERRIDE;
f751596e 112
2157d6ac 113 //! Checks whether the entity with index theIdx is inside the current selecting volume
25333d45 114 Standard_EXPORT virtual Standard_Boolean elementIsInside (SelectBasics_SelectingVolumeManager& theMgr,
115 Standard_Integer theElemIdx,
116 Standard_Boolean theIsFullInside) Standard_OVERRIDE;
2157d6ac 117
f751596e 118private:
119
35c0599a 120 Handle(Poly_Triangulation) myTriangul;
3bf9a45f 121 TopLoc_Location myInitLocation;
122 gp_Pnt myCDG3D; //!< Center of the whole triangulation
35c0599a 123 Handle(TColStd_HArray1OfInteger) myFreeEdges;
3bf9a45f 124 Standard_Boolean mySensType; //!< Type of sensitivity: boundary or interior
3bf9a45f 125 Standard_Integer myPrimitivesNb; //!< Amount of free edges or triangles depending on sensitivity type
35c0599a 126 Handle(TColStd_HArray1OfInteger) myBVHPrimIndexes; //!< Indexes of edges or triangles for BVH build
3bf9a45f 127 mutable Select3D_BndBox3d myBndBox; //!< Bounding box of the whole triangulation
91d96372 128 gp_GTrsf myInvInitLocation;
f751596e 129};
130
131DEFINE_STANDARD_HANDLE(Select3D_SensitiveTriangulation, Select3D_SensitiveSet)
132
f751596e 133#endif // _Select3D_SensitiveTriangulation_Header