Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-14 09:15:47

0001 // Created on: 2014-08-15
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 _SelectMgr_SensitiveEntitySet_HeaderFile
0017 #define _SelectMgr_SensitiveEntitySet_HeaderFile
0018 
0019 #include <BVH_PrimitiveSet3d.hxx>
0020 #include <Select3D_BVHBuilder3d.hxx>
0021 #include <SelectMgr_EntityOwner.hxx>
0022 #include <SelectMgr_SensitiveEntity.hxx>
0023 #include <SelectMgr_Selection.hxx>
0024 
0025 //! This class is used to store all calculated sensitive entities of one selectable object.
0026 //! It provides an interface for building BVH tree which is used to speed-up
0027 //! the performance of searching for overlap among sensitives of one selectable object
0028 class SelectMgr_SensitiveEntitySet : public BVH_PrimitiveSet3d
0029 {
0030   DEFINE_STANDARD_RTTIEXT(SelectMgr_SensitiveEntitySet, BVH_PrimitiveSet3d)
0031 public:
0032   //! Empty constructor.
0033   Standard_EXPORT SelectMgr_SensitiveEntitySet(
0034     const occ::handle<Select3D_BVHBuilder3d>& theBuilder);
0035 
0036   ~SelectMgr_SensitiveEntitySet() override = default;
0037 
0038   //! Adds new entity to the set and marks BVH tree for rebuild
0039   Standard_EXPORT void Append(const occ::handle<SelectMgr_SensitiveEntity>& theEntity);
0040 
0041   //! Adds every entity of selection theSelection to the set and marks
0042   //! BVH tree for rebuild
0043   Standard_EXPORT void Append(const occ::handle<SelectMgr_Selection>& theSelection);
0044 
0045   //! Removes every entity of selection theSelection from the set
0046   //! and marks BVH tree for rebuild
0047   Standard_EXPORT void Remove(const occ::handle<SelectMgr_Selection>& theSelection);
0048 
0049   //! Returns bounding box of entity with index theIdx
0050   Standard_EXPORT Select3D_BndBox3d Box(const int theIndex) const override;
0051 
0052   //! Make inherited method Box() visible to avoid CLang warning
0053   using BVH_PrimitiveSet3d::Box;
0054 
0055   //! Returns geometry center of sensitive entity index theIdx
0056   //! along the given axis theAxis
0057   Standard_EXPORT double Center(const int theIndex, const int theAxis) const override;
0058 
0059   //! Swaps items with indexes theIdx1 and theIdx2
0060   Standard_EXPORT void Swap(const int theIndex1, const int theIndex2) override;
0061 
0062   //! Returns the amount of entities
0063   Standard_EXPORT int Size() const override;
0064 
0065   //! Returns the entity with index theIndex in the set
0066   Standard_EXPORT const occ::handle<SelectMgr_SensitiveEntity>& GetSensitiveById(
0067     const int theIndex) const;
0068 
0069   //! Returns map of entities.
0070   const NCollection_IndexedMap<occ::handle<SelectMgr_SensitiveEntity>>& Sensitives() const
0071   {
0072     return mySensitives;
0073   }
0074 
0075   //! Returns map of owners.
0076   const NCollection_DataMap<occ::handle<SelectMgr_EntityOwner>, int>& Owners() const
0077   {
0078     return myOwnersMap;
0079   }
0080 
0081   //! Returns map of entities.
0082   bool HasEntityWithPersistence() const { return myNbEntityWithPersistence > 0; }
0083 
0084   //! Returns true if this set contains sensitive entities with flipping options.
0085   bool HasEntityWithFlipping() const { return myNbEntityWithFlipping > 0; }
0086 
0087 protected:
0088   //! Adds entity owner to the map of owners (or increases its counter if it is already there).
0089   Standard_EXPORT void addOwner(const occ::handle<SelectMgr_EntityOwner>& theOwner);
0090 
0091   //! Decreases counter of owner in the map of owners (or removes it from the map if counter == 0).
0092   Standard_EXPORT void removeOwner(const occ::handle<SelectMgr_EntityOwner>& theOwner);
0093 
0094 private:
0095   // clang-format off
0096   NCollection_IndexedMap<occ::handle<SelectMgr_SensitiveEntity>> mySensitives;              //!< Map of entities and its corresponding index in BVH
0097   NCollection_DataMap<occ::handle<SelectMgr_EntityOwner>, int>            myOwnersMap;               //!< Map of entity owners and its corresponding number of sensitives
0098   int                 myNbEntityWithPersistence; //!< number of sensitive entities that have own transform persistence
0099   int                 myNbEntityWithFlipping;    //!< number of sensitive entities that have flipping options
0100   // clang-format on
0101 };
0102 
0103 #endif // _SelectMgr_SensitiveEntitySet_HeaderFile