|
||||
File indexing completed on 2025-01-18 10:04:53
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 0036 //! Return global instance to default BVH builder. 0037 Standard_EXPORT static const Handle(Select3D_BVHBuilder3d)& DefaultBVHBuilder(); 0038 0039 //! Assign new BVH builder to be used by default for new sensitive sets (assigning is NOT thread-safe!). 0040 Standard_EXPORT static void SetDefaultBVHBuilder (const Handle(Select3D_BVHBuilder3d)& theBuilder); 0041 0042 public: 0043 0044 //! Creates new empty sensitive set and its content 0045 Standard_EXPORT Select3D_SensitiveSet (const Handle(SelectMgr_EntityOwner)& theOwnerId); 0046 0047 public: 0048 0049 //! Returns the amount of sub-entities of the complex entity 0050 virtual Standard_Integer Size() const = 0; 0051 0052 //! Returns bounding box of sub-entity with index theIdx in sub-entity list 0053 virtual Select3D_BndBox3d Box (const Standard_Integer theIdx) const = 0; 0054 0055 //! Returns geometry center of sensitive entity index theIdx along the given axis theAxis 0056 virtual Standard_Real Center (const Standard_Integer theIdx, 0057 const Standard_Integer theAxis) const = 0; 0058 0059 //! Swaps items with indexes theIdx1 and theIdx2 0060 virtual void Swap (const Standard_Integer theIdx1, 0061 const Standard_Integer theIdx2) = 0; 0062 0063 //! Checks whether one or more entities of the set overlap current selecting volume. 0064 //! Implements the traverse of BVH tree built for the set 0065 virtual Standard_Boolean Matches (SelectBasics_SelectingVolumeManager& theMgr, 0066 SelectBasics_PickResult& thePickResult) Standard_OVERRIDE 0067 { 0068 return matches (theMgr, thePickResult, false); 0069 } 0070 0071 //! Builds BVH tree for sensitive set. 0072 //! Must be called manually to build BVH tree for any sensitive set 0073 //! in case if its content was initialized not in a constructor, 0074 //! but element by element 0075 Standard_EXPORT virtual void BVH() Standard_OVERRIDE; 0076 0077 //! Returns TRUE if BVH tree is in invalidated state 0078 virtual Standard_Boolean ToBuildBVH() const Standard_OVERRIDE { return myContent.IsDirty(); } 0079 0080 //! Sets the method (builder) used to construct BVH. 0081 void SetBuilder (const Handle(Select3D_BVHBuilder3d)& theBuilder) { myContent.SetBuilder (theBuilder); } 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 virtual Select3D_BndBox3d BoundingBox() Standard_OVERRIDE; 0090 0091 //! Returns center of the whole set. 0092 //! This method should be redefined in Select3D_SensitiveSet descendants 0093 Standard_EXPORT virtual gp_Pnt CenterOfGeometry() const Standard_OVERRIDE; 0094 0095 //! Destroys cross-reference to avoid memory leak 0096 Standard_EXPORT virtual void Clear() Standard_OVERRIDE; 0097 0098 //! Returns a number of nodes in 1 BVH leaf 0099 Standard_Integer GetLeafNodeSize() const { return myContent.Builder()->LeafNodeSize(); } 0100 0101 //! Dumps the content of me into the stream 0102 Standard_EXPORT virtual void DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth = -1) const Standard_OVERRIDE; 0103 0104 protected: 0105 0106 //! Checks whether one or more entities of the set overlap current selecting volume. 0107 //! Implements the traverse of BVH tree built for the set 0108 //! @param theMgr selection manager 0109 //! @param thePickResult picking result (for picking by ray) 0110 //! @param theToCheckAllInside flag indicating that even with SelectMgr_SelectingVolumeManager::IsOverlapAllowed() returning FALSE 0111 //! the method will return TRUE if at least one sub-element is fully inside selection volume ::elementIsInside(); 0112 //! this is useful for entities allowing local selection of sub-elements using single Owner object. 0113 Standard_EXPORT Standard_Boolean matches (SelectBasics_SelectingVolumeManager& theMgr, 0114 SelectBasics_PickResult& thePickResult, 0115 Standard_Boolean theToCheckAllInside); 0116 0117 //! Checks whether the entity with index theIdx (partially) overlaps the current selecting volume. 0118 //! @param thePickResult [OUT] picking result, should update minimum depth 0119 //! @param theMgr [IN] selection manager 0120 //! @param theElemIdx [IN] element index within BVH tree to check 0121 //! @param theIsFullInside [IN] when TRUE indicates that entire BVH node is already inside selection volume (in case of rectangle selection); 0122 //! in this case algorithm might skip checking the element and just register it as detected 0123 virtual Standard_Boolean overlapsElement (SelectBasics_PickResult& thePickResult, 0124 SelectBasics_SelectingVolumeManager& theMgr, 0125 Standard_Integer theElemIdx, 0126 Standard_Boolean theIsFullInside) = 0; 0127 0128 //! Checks whether the entity with index theIdx is (fully) inside the current selecting volume 0129 //! @param theMgr [IN] selection manager 0130 //! @param theElemIdx [IN] element index within BVH tree to check 0131 //! @param theIsFullInside [IN] when TRUE indicates that entire BVH node is already inside selection volume (in case of rectangle selection); 0132 //! in this case algorithm might skip checking the element and just register it as detected 0133 virtual Standard_Boolean elementIsInside (SelectBasics_SelectingVolumeManager& theMgr, 0134 Standard_Integer theElemIdx, 0135 Standard_Boolean theIsFullInside) = 0; 0136 0137 //! Calculates distance from the 3d projection of used-picked screen point to center of the geometry 0138 virtual Standard_Real distanceToCOG (SelectBasics_SelectingVolumeManager& theMgr) = 0; 0139 0140 //! Process elements overlapped by the selection volume 0141 //! @param theMgr selection manager 0142 //! @param theFirstElem index of the first element 0143 //! @param theLastElem index of the last element 0144 //! @param theIsFullInside when TRUE indicates that entire BVH node is already inside selection volume 0145 //! @param thePickResult [OUT] picking result (for picking by ray) 0146 //! @param theMatchesNb [OUT] number of processed elements 0147 //! @return FALSE if some element is outside the selection volume (if IsOverlapAllowed is FALSE); TRUE otherwise 0148 Standard_EXPORT Standard_Boolean processElements (SelectBasics_SelectingVolumeManager& theMgr, 0149 Standard_Integer theFirstElem, 0150 Standard_Integer theLastElem, 0151 Standard_Boolean theIsFullInside, 0152 Standard_Boolean theToCheckAllInside, 0153 SelectBasics_PickResult& thePickResult, 0154 Standard_Integer& theMatchesNb); 0155 0156 protected: 0157 0158 //! The purpose of this class is to provide a link between BVH_PrimitiveSet 0159 //! and Select3D_SensitiveSet instance to build BVH tree for set of sensitives. 0160 class BvhPrimitiveSet : public BVH_PrimitiveSet3d 0161 { 0162 public: 0163 0164 //! Empty constructor. 0165 BvhPrimitiveSet() 0166 : BVH_PrimitiveSet3d(Handle(Select3D_BVHBuilder3d)()), 0167 mySensitiveSet(NULL) 0168 { 0169 } 0170 0171 //! Destructor. 0172 ~BvhPrimitiveSet() {} 0173 0174 //! Setup sensitivity set. 0175 void SetSensitiveSet (Select3D_SensitiveSet* theSensitiveSet) 0176 { 0177 mySensitiveSet = theSensitiveSet; 0178 MarkDirty(); 0179 } 0180 0181 //! Returns the length of set of sensitives 0182 virtual Standard_Integer Size() const Standard_OVERRIDE { return mySensitiveSet->Size(); } 0183 0184 //! Returns bounding box of sensitive with index theIdx 0185 virtual Select3D_BndBox3d Box (const Standard_Integer theIdx) const Standard_OVERRIDE { return mySensitiveSet->Box (theIdx); } 0186 0187 //! Make inherited method Box() visible to avoid CLang warning 0188 using BVH_PrimitiveSet3d::Box; 0189 0190 //! Returns center of sensitive with index theIdx in the set along the given axis theAxis 0191 virtual Standard_Real Center (const Standard_Integer theIdx, 0192 const Standard_Integer theAxis) const Standard_OVERRIDE { return mySensitiveSet->Center (theIdx, theAxis); } 0193 0194 //! Swaps items with indexes theIdx1 and theIdx2 in the set 0195 virtual void Swap (const Standard_Integer theIdx1, 0196 const Standard_Integer theIdx2) Standard_OVERRIDE { mySensitiveSet->Swap (theIdx1, theIdx2); } 0197 0198 //! Returns the tree built for set of sensitives 0199 const opencascade::handle<BVH_Tree<Standard_Real, 3> >& GetBVH() { return BVH(); } 0200 0201 //! Dumps the content of me into the stream 0202 void DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth = -1) const 0203 { (void)theOStream; (void)theDepth; } 0204 0205 protected: 0206 Select3D_SensitiveSet* mySensitiveSet; //!< Set of sensitive entities 0207 }; 0208 0209 protected: 0210 0211 BvhPrimitiveSet myContent; //!< A link between sensitive entity and BVH_PrimitiveSet 0212 Standard_Integer myDetectedIdx; //!< Index of detected primitive in BVH sorted primitive array 0213 0214 }; 0215 0216 DEFINE_STANDARD_HANDLE(Select3D_SensitiveSet, Select3D_SensitiveEntity) 0217 0218 #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 |