SelectMgr_SensitiveEntitySet now stores a map of registered owners with a counter of registered entities.
SelectMgr_ViewerSelector::traverseObject() now reads the number of sensitive entities for specific owner
from SelectMgr_SensitiveEntitySet instead of re-computing it every time.
theEntity->ResetSelectionActiveStatus();
return;
}
- mySensitives.Add (theEntity);
+
+ const Standard_Integer anExtent = mySensitives.Extent();
+ if (mySensitives.Add (theEntity) > anExtent)
+ {
+ addOwner (theEntity->BaseSensitive()->OwnerId());
+ }
MarkDirty();
}
aSelEntIter.Value()->ResetSelectionActiveStatus();
continue;
}
- mySensitives.Add (aSelEntIter.Value());
+
+ const Standard_Integer anExtent = mySensitives.Extent();
+ if (mySensitives.Add (aSelEntIter.Value()) > anExtent)
+ {
+ addOwner (aSelEntIter.Value()->BaseSensitive()->OwnerId());
+ }
}
MarkDirty();
}
}
mySensitives.RemoveLast();
+ removeOwner (aSelEntIter.Value()->BaseSensitive()->OwnerId());
}
MarkDirty();
{
return mySensitives.FindKey (theIndex + 1);
}
+
+//=======================================================================
+// function : addOwner
+// purpose :
+//=======================================================================
+void SelectMgr_SensitiveEntitySet::addOwner (const Handle(SelectMgr_EntityOwner)& theOwner)
+{
+ if (!theOwner.IsNull())
+ {
+ if (Standard_Integer* aNumber = myOwnersMap.ChangeSeek (theOwner))
+ {
+ ++(*aNumber);
+ }
+ else
+ {
+ myOwnersMap.Bind (theOwner, 1);
+ }
+ }
+}
+
+//=======================================================================
+// function : removeOwner
+// purpose :
+//=======================================================================
+void SelectMgr_SensitiveEntitySet::removeOwner (const Handle(SelectMgr_EntityOwner)& theOwner)
+{
+ if (Standard_Integer* aNumber = !theOwner.IsNull() ? myOwnersMap.ChangeSeek (theOwner) : NULL)
+ {
+ if (--(*aNumber) == 0)
+ {
+ myOwnersMap.UnBind (theOwner);
+ }
+ }
+}
#define _SelectMgr_SensitiveEntitySet_HeaderFile
#include <BVH_PrimitiveSet3d.hxx>
+#include <NCollection_DataMap.hxx>
#include <NCollection_IndexedMap.hxx>
#include <Select3D_BndBox3d.hxx>
#include <Select3D_BVHBuilder3d.hxx>
+#include <SelectMgr_EntityOwner.hxx>
#include <SelectMgr_SensitiveEntity.hxx>
#include <SelectMgr_Selection.hxx>
typedef NCollection_IndexedMap<Handle(SelectMgr_SensitiveEntity)> SelectMgr_IndexedMapOfHSensitive;
+typedef NCollection_DataMap<Handle(SelectMgr_EntityOwner), Standard_Integer> SelectMgr_MapOfOwners;
//! This class is used to store all calculated sensitive entites of one selectable
//! object. It provides an interface for building BVH tree which is used to speed-up
//! Returns map of entities.
const SelectMgr_IndexedMapOfHSensitive& Sensitives() const { return mySensitives; }
+ //! Returns map of owners.
+ const SelectMgr_MapOfOwners& Owners() const { return myOwnersMap; }
+
+protected:
+
+ //! Adds entity owner to the map of owners (or increases its counter if it is already there).
+ Standard_EXPORT void addOwner (const Handle(SelectMgr_EntityOwner)& theOwner);
+
+ //! Decreases counter of owner in the map of owners (or removes it from the map if counter == 0).
+ Standard_EXPORT void removeOwner (const Handle(SelectMgr_EntityOwner)& theOwner);
+
private:
SelectMgr_IndexedMapOfHSensitive mySensitives; //!< Map of entities and its corresponding index in BVH
+ SelectMgr_MapOfOwners myOwnersMap; //!< Map of entity owners and its corresponding number of sensitives
};
#endif // _SelectMgr_SensitiveEntitySet_HeaderFile
const SelectMgr_SortCriterion& aCriterion = mystored.FindFromIndex (aStoredIter);
const Handle(SelectMgr_EntityOwner)& anOwner = aCriterion.Entity->OwnerId();
Standard_Integer aNbOwnerEntities = 0;
- for (SelectMgr_IndexedMapOfHSensitive::Iterator aSensIter (anEntitySet->Sensitives()); aSensIter.More(); aSensIter.Next())
+ anEntitySet->Owners().Find (anOwner, aNbOwnerEntities);
+ if (aNbOwnerEntities > aCriterion.NbOwnerMatches)
{
- if (aSensIter.Value()->BaseSensitive()->OwnerId() == anOwner)
- {
- if (++aNbOwnerEntities > aCriterion.NbOwnerMatches)
- {
- // Remove from index map.
- // Considering NCollection_IndexedDataMap implementation, the values for lower indexes will not be modified.
- // Hence, just keep iterating in backward direction.
- mystored.RemoveFromIndex (aStoredIter);
- break;
- }
- }
+ mystored.RemoveFromIndex (aStoredIter);
}
}
}