|
|
|||
File indexing completed on 2026-09-20 09:18:52
0001 // Created on: 2014-05-29 0002 // Created by: Varvara POSKONINA 0003 // Copyright (c) 2005-2014 OPEN CASCADE SAS 0004 // 0005 // This file is part of Open CASCADE Technology software library. 0006 // 0007 // This library is free software; you can redistribute it and/or modify it under 0008 // the terms of the GNU Lesser General Public License version 2.1 as published 0009 // by the Free Software Foundation, with special exception defined in the file 0010 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT 0011 // distribution for complete text of the license and disclaimer of any warranty. 0012 // 0013 // Alternatively, this file may be used under the terms of Open CASCADE 0014 // commercial license or contractual agreement. 0015 0016 #ifndef _Select3D_SensitiveSet_Header 0017 #define _Select3D_SensitiveSet_Header 0018 0019 #include <BVH_PrimitiveSet3d.hxx> 0020 #include <Select3D_BVHBuilder3d.hxx> 0021 #include <Select3D_SensitiveEntity.hxx> 0022 0023 //! This class is base class for handling overlap detection of complex sensitive 0024 //! entities. It provides an interface for building BVH tree for some set of entities. 0025 //! Thereby, each iteration of overlap detection is a traverse of BVH tree in fact. 0026 //! To use speed-up hierarchical structure in a custom complex sensitive entity, it is 0027 //! necessary to make that custom entity a descendant of this class and organize sub-entities 0028 //! in some container which allows referencing to elements by index. Note that methods taking 0029 //! index as a parameter are used for BVH build and the range of given index is [0; Size() - 1]. 0030 //! For example of usage see Select3D_SensitiveTriangulation. 0031 class Select3D_SensitiveSet : public Select3D_SensitiveEntity 0032 { 0033 DEFINE_STANDARD_RTTIEXT(Select3D_SensitiveSet, Select3D_SensitiveEntity) 0034 public: 0035 //! Return global instance to default BVH builder. 0036 Standard_EXPORT static const occ::handle<Select3D_BVHBuilder3d>& DefaultBVHBuilder(); 0037 0038 //! Assign new BVH builder to be used by default for new sensitive sets (assigning is NOT 0039 //! thread-safe!). 0040 Standard_EXPORT static void SetDefaultBVHBuilder( 0041 const occ::handle<Select3D_BVHBuilder3d>& theBuilder); 0042 0043 public: 0044 //! Creates new empty sensitive set and its content 0045 Standard_EXPORT Select3D_SensitiveSet(const occ::handle<SelectMgr_EntityOwner>& theOwnerId); 0046 0047 public: 0048 //! Returns the amount of sub-entities of the complex entity 0049 virtual int Size() const = 0; 0050 0051 //! Returns bounding box of sub-entity with index theIdx in sub-entity list 0052 virtual Select3D_BndBox3d Box(const int theIdx) const = 0; 0053 0054 //! Returns geometry center of sensitive entity index theIdx along the given axis theAxis 0055 virtual double Center(const int theIdx, const int theAxis) const = 0; 0056 0057 //! Swaps items with indexes theIdx1 and theIdx2 0058 virtual void Swap(const int theIdx1, const int theIdx2) = 0; 0059 0060 //! Checks whether one or more entities of the set overlap current selecting volume. 0061 //! Implements the traverse of BVH tree built for the set 0062 bool Matches(SelectBasics_SelectingVolumeManager& theMgr, 0063 SelectBasics_PickResult& thePickResult) override 0064 { 0065 return matches(theMgr, thePickResult, false); 0066 } 0067 0068 //! Builds BVH tree for sensitive set. 0069 //! Must be called manually to build BVH tree for any sensitive set 0070 //! in case if its content was initialized not in a constructor, 0071 //! but element by element 0072 Standard_EXPORT void BVH() override; 0073 0074 //! Returns TRUE if BVH tree is in invalidated state 0075 bool ToBuildBVH() const override { return myContent.IsDirty(); } 0076 0077 //! Sets the method (builder) used to construct BVH. 0078 void SetBuilder(const occ::handle<Select3D_BVHBuilder3d>& theBuilder) 0079 { 0080 myContent.SetBuilder(theBuilder); 0081 } 0082 0083 //! Marks BVH tree of the set as outdated. It will be rebuild 0084 //! at the next call of BVH() 0085 void MarkDirty() { myContent.MarkDirty(); } 0086 0087 //! Returns bounding box of the whole set. 0088 //! This method should be redefined in Select3D_SensitiveSet descendants 0089 Standard_EXPORT Select3D_BndBox3d BoundingBox() override; 0090 0091 //! Returns center of the whole set. 0092 //! This method should be redefined in Select3D_SensitiveSet descendants 0093 Standard_EXPORT gp_Pnt CenterOfGeometry() const override; 0094 0095 //! Destroys cross-reference to avoid memory leak 0096 Standard_EXPORT void Clear() override; 0097 0098 //! Returns a number of nodes in 1 BVH leaf 0099 int GetLeafNodeSize() const { return myContent.Builder()->LeafNodeSize(); } 0100 0101 //! Dumps the content of me into the stream 0102 Standard_EXPORT void DumpJson(Standard_OStream& theOStream, int theDepth = -1) const override; 0103 0104 protected: 0105 //! Checks whether one or more entities of the set overlap current selecting volume. 0106 //! Implements the traverse of BVH tree built for the set 0107 //! @param theMgr selection manager 0108 //! @param thePickResult picking result (for picking by ray) 0109 //! @param theToCheckAllInside flag indicating that even with 0110 //! SelectMgr_SelectingVolumeManager::IsOverlapAllowed() returning FALSE 0111 //! the method will return TRUE if at least one sub-element is fully inside selection 0112 //! volume ::elementIsInside(); this is useful for entities allowing local selection of 0113 //! sub-elements using single Owner object. 0114 Standard_EXPORT bool matches(SelectBasics_SelectingVolumeManager& theMgr, 0115 SelectBasics_PickResult& thePickResult, 0116 bool theToCheckAllInside); 0117 0118 //! Checks whether the entity with index theIdx (partially) overlaps the current selecting volume. 0119 //! @param[out] thePickResult picking result, should update minimum depth 0120 //! @param[in] theMgr selection manager 0121 //! @param[in] theElemIdx element index within BVH tree to check 0122 //! @param[in] theIsFullInside when TRUE indicates that entire BVH node is already inside 0123 //! selection volume (in case of rectangle selection); 0124 //! in this case algorithm might skip checking the element and just 0125 //! register it as detected 0126 virtual bool overlapsElement(SelectBasics_PickResult& thePickResult, 0127 SelectBasics_SelectingVolumeManager& theMgr, 0128 int theElemIdx, 0129 bool theIsFullInside) = 0; 0130 0131 //! Checks whether the entity with index theIdx is (fully) inside the current selecting volume 0132 //! @param[in] theMgr selection manager 0133 //! @param[in] theElemIdx element index within BVH tree to check 0134 //! @param[in] theIsFullInside when TRUE indicates that entire BVH node is already inside 0135 //! selection volume (in case of rectangle selection); 0136 //! in this case algorithm might skip checking the element and just 0137 //! register it as detected 0138 virtual bool elementIsInside(SelectBasics_SelectingVolumeManager& theMgr, 0139 int theElemIdx, 0140 bool theIsFullInside) = 0; 0141 0142 //! Calculates distance from the 3d projection of used-picked screen point to center of the 0143 //! geometry 0144 virtual double distanceToCOG(SelectBasics_SelectingVolumeManager& theMgr) = 0; 0145 0146 //! Process elements overlapped by the selection volume 0147 //! @param theMgr selection manager 0148 //! @param theFirstElem index of the first element 0149 //! @param theLastElem index of the last element 0150 //! @param theIsFullInside when TRUE indicates that entire BVH node is already inside selection 0151 //! volume 0152 //! @param[out] thePickResult picking result (for picking by ray) 0153 //! @param[out] theMatchesNb number of processed elements 0154 //! @return FALSE if some element is outside the selection volume (if IsOverlapAllowed is FALSE); 0155 //! TRUE otherwise 0156 Standard_EXPORT bool processElements(SelectBasics_SelectingVolumeManager& theMgr, 0157 int theFirstElem, 0158 int theLastElem, 0159 bool theIsFullInside, 0160 bool theToCheckAllInside, 0161 SelectBasics_PickResult& thePickResult, 0162 int& theMatchesNb); 0163 0164 protected: 0165 //! The purpose of this class is to provide a link between BVH_PrimitiveSet 0166 //! and Select3D_SensitiveSet instance to build BVH tree for set of sensitives. 0167 class BvhPrimitiveSet : public BVH_PrimitiveSet3d 0168 { 0169 public: 0170 //! Empty constructor. 0171 BvhPrimitiveSet() 0172 : BVH_PrimitiveSet3d(occ::handle<Select3D_BVHBuilder3d>()), 0173 mySensitiveSet(nullptr) 0174 { 0175 } 0176 0177 //! Destructor. 0178 ~BvhPrimitiveSet() override = default; 0179 0180 //! Setup sensitivity set. 0181 void SetSensitiveSet(Select3D_SensitiveSet* theSensitiveSet) 0182 { 0183 mySensitiveSet = theSensitiveSet; 0184 MarkDirty(); 0185 } 0186 0187 //! Returns the length of set of sensitives 0188 int Size() const override { return mySensitiveSet->Size(); } 0189 0190 //! Returns bounding box of sensitive with index theIdx 0191 Select3D_BndBox3d Box(const int theIdx) const override { return mySensitiveSet->Box(theIdx); } 0192 0193 //! Make inherited method Box() visible to avoid CLang warning 0194 using BVH_PrimitiveSet3d::Box; 0195 0196 //! Returns center of sensitive with index theIdx in the set along the given axis theAxis 0197 double Center(const int theIdx, const int theAxis) const override 0198 { 0199 return mySensitiveSet->Center(theIdx, theAxis); 0200 } 0201 0202 //! Swaps items with indexes theIdx1 and theIdx2 in the set 0203 void Swap(const int theIdx1, const int theIdx2) override 0204 { 0205 mySensitiveSet->Swap(theIdx1, theIdx2); 0206 } 0207 0208 //! Returns the tree built for set of sensitives 0209 const opencascade::handle<BVH_Tree<double, 3>>& GetBVH() { return BVH(); } 0210 0211 //! Dumps the content of me into the stream 0212 void DumpJson(Standard_OStream& theOStream, int theDepth = -1) const 0213 { 0214 (void)theOStream; 0215 (void)theDepth; 0216 } 0217 0218 protected: 0219 Select3D_SensitiveSet* mySensitiveSet; //!< Set of sensitive entities 0220 }; 0221 0222 protected: 0223 BvhPrimitiveSet myContent; //!< A link between sensitive entity and BVH_PrimitiveSet 0224 int myDetectedIdx; //!< Index of detected primitive in BVH sorted primitive array 0225 }; 0226 0227 #endif // _Select3D_SensitiveSet_Header
| [ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
|
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
|