0031757: Visualization - Prebuild BVH for Select3D_SensitiveEntity in separate threads
[occt.git] / src / Select3D / Select3D_SensitiveEntity.hxx
1 // Created on: 1995-03-13
2 // Created by: Robert COUBLANC
3 // Copyright (c) 1995-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_SensitiveEntity_HeaderFile
18 #define _Select3D_SensitiveEntity_HeaderFile
19
20 #include <gp_GTrsf.hxx>
21 #include <gp_Trsf.hxx>
22 #include <Standard_Assert.hxx>
23 #include <Standard_Transient.hxx>
24 #include <Select3D_BndBox3d.hxx>
25 #include <SelectBasics_SelectingVolumeManager.hxx>
26 #include <SelectBasics_PickResult.hxx>
27 #include <SelectBasics_SensitiveEntity.hxx>
28 #include <SelectMgr_SelectingVolumeManager.hxx>
29 #include <TopLoc_Location.hxx>
30
31 class SelectMgr_EntityOwner;
32
33 //! Abstract framework to define 3D sensitive entities.
34 class Select3D_SensitiveEntity : public Standard_Transient
35 {
36   DEFINE_STANDARD_RTTIEXT(Select3D_SensitiveEntity, Standard_Transient)
37 public:
38
39   //! Returns pointer to owner of the entity
40   const Handle(SelectMgr_EntityOwner)& OwnerId() const { return myOwnerId; }
41
42   //! Sets owner of the entity
43   virtual void Set (const Handle(SelectMgr_EntityOwner)& theOwnerId)
44   {
45     myOwnerId = theOwnerId;
46   }
47
48   //! allows a better sensitivity for a specific entity in selection algorithms useful for small sized entities.
49   Standard_Integer SensitivityFactor() const { return mySFactor; }
50
51   //! Allows to manage sensitivity of a particular sensitive entity
52   void SetSensitivityFactor (const Standard_Integer theNewSens)
53   {
54     Standard_ASSERT_RAISE (theNewSens > 0, "Error! Selection sensitivity have positive value.");
55     mySFactor = theNewSens;
56   }
57
58   //! Originally this method intended to return sensitive entity with new location aLocation,
59   //! but currently sensitive entities do not hold a location,
60   //! instead HasLocation() and Location() methods call corresponding entity owner's methods.
61   //! Thus all entities returned by GetConnected() share the same location propagated from corresponding selectable object.
62   //! You must redefine this function for any type of sensitive entity which can accept another connected sensitive entity.
63   virtual Handle(Select3D_SensitiveEntity) GetConnected() { return Handle(Select3D_SensitiveEntity)(); }
64
65   //! Checks whether sensitive overlaps current selecting volume.
66   //! Stores minimum depth, distance to center of geometry and closest point detected into thePickResult
67   virtual Standard_Boolean Matches (SelectBasics_SelectingVolumeManager& theMgr,
68                                     SelectBasics_PickResult& thePickResult) = 0;
69
70   //! Returns the number of sub-entities or elements in sensitive entity.
71   //! Is used to determine if entity is complex and needs to pre-build BVH at the creation of sensitive entity step
72   //! or is light-weighted so the tree can be build on demand with unnoticeable delay.
73   virtual Standard_Integer NbSubElements() const = 0;
74
75   //! Returns bounding box of a sensitive with transformation applied
76   virtual Select3D_BndBox3d BoundingBox() = 0;
77
78   //! Returns center of a sensitive with transformation applied
79   virtual gp_Pnt CenterOfGeometry() const = 0;
80
81   //! Builds BVH tree for a sensitive if needed
82   virtual void BVH() {}
83
84   //! Returns TRUE if BVH tree is in invalidated state
85   virtual Standard_Boolean ToBuildBVH() const { return Standard_True; }
86
87   //! Clears up all resources and memory
88   virtual void Clear() { Set (Handle(SelectMgr_EntityOwner)()); }
89
90   //! Returns true if the shape corresponding to the entity has init location
91   virtual Standard_Boolean HasInitLocation() const { return Standard_False; }
92
93   //! Returns inversed location transformation matrix if the shape corresponding to this entity has init location set.
94   //! Otherwise, returns identity matrix.
95   virtual gp_GTrsf InvInitLocation() const { return gp_GTrsf(); }
96
97   //! Dumps the content of me into the stream
98   Standard_EXPORT virtual void DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth = -1) const;
99
100 protected:
101
102   Standard_EXPORT Select3D_SensitiveEntity (const Handle(SelectMgr_EntityOwner)& theOwnerId);
103
104 protected:
105
106   Handle(SelectMgr_EntityOwner) myOwnerId;
107   Standard_Integer mySFactor;
108
109 };
110
111 DEFINE_STANDARD_HANDLE(Select3D_SensitiveEntity, Standard_Transient)
112
113 // for porting old code
114 typedef Select3D_SensitiveEntity SelectBasics_SensitiveEntity;
115
116 #endif // _Select3D_SensitiveEntity_HeaderFile