1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-08-04 13:13:25 +03:00

0026213: Visualization - replace sequence in Select3D_SensitiveGroup

NCollection_IndexedMap is now used instead of NCollection_Sequence within Select3D_SensitiveGroup.
This commit is contained in:
kgv
2017-07-10 13:40:54 +03:00
committed by bugmaster
parent 99cfc27757
commit 7f5945d688
6 changed files with 93 additions and 60 deletions

View File

@@ -415,12 +415,16 @@ public:
//! Remove the given key. //! Remove the given key.
//! Caution! The index of the last key can be changed. //! Caution! The index of the last key can be changed.
void RemoveKey(const TheKeyType& theKey1) Standard_Boolean RemoveKey (const TheKeyType& theKey1)
{ {
Standard_Integer anIndToRemove = FindIndex(theKey1); Standard_Integer anIndToRemove = FindIndex(theKey1);
if (anIndToRemove > 0) { if (anIndToRemove < 1)
RemoveFromIndex(anIndToRemove); {
return Standard_False;
} }
RemoveFromIndex (anIndToRemove);
return Standard_True;
} }
//! FindKey //! FindKey

View File

@@ -2,6 +2,7 @@ Select3D_BndBox3d.hxx
Select3D_BVHBuilder3d.hxx Select3D_BVHBuilder3d.hxx
Select3D_BVHIndexBuffer.hxx Select3D_BVHIndexBuffer.hxx
Select3D_EntitySequence.hxx Select3D_EntitySequence.hxx
Select3D_IndexedMapOfEntity.hxx
Select3D_InteriorSensitivePointSet.cxx Select3D_InteriorSensitivePointSet.cxx
Select3D_InteriorSensitivePointSet.hxx Select3D_InteriorSensitivePointSet.hxx
Select3D_Pnt.hxx Select3D_Pnt.hxx

View File

@@ -0,0 +1,22 @@
// Copyright (c) 2017 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
// This library is free software; you can redistribute it and/or modify it under
// the terms of the GNU Lesser General Public License version 2.1 as published
// by the Free Software Foundation, with special exception defined in the file
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
// distribution for complete text of the license and disclaimer of any warranty.
//
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
#ifndef _Select3D_IndexedMapOfEntity_Header
#define _Select3D_IndexedMapOfEntity_Header
#include <NCollection_IndexedMap.hxx>
class Select3D_SensitiveEntity;
typedef NCollection_IndexedMap<Handle(Select3D_SensitiveEntity)> Select3D_IndexedMapOfEntity;
#endif // _Select3D_IndexedMapOfEntity_Header

View File

@@ -39,6 +39,7 @@ Select3D_SensitiveGroup::Select3D_SensitiveGroup (const Handle(SelectBasics_Enti
Select3D_EntitySequence& theEntities, Select3D_EntitySequence& theEntities,
const Standard_Boolean theIsMustMatchAll) const Standard_Boolean theIsMustMatchAll)
: Select3D_SensitiveSet (theOwnerId), : Select3D_SensitiveSet (theOwnerId),
myEntities (Max (1, theEntities.Size())),
myMustMatchAll (theIsMustMatchAll), myMustMatchAll (theIsMustMatchAll),
myToCheckOverlapAll (Standard_False), myToCheckOverlapAll (Standard_False),
myCenter (0.0, 0.0, 0.0) myCenter (0.0, 0.0, 0.0)
@@ -46,13 +47,18 @@ Select3D_SensitiveGroup::Select3D_SensitiveGroup (const Handle(SelectBasics_Enti
for (Select3D_EntitySequenceIter anIter (theEntities); anIter.More(); anIter.Next()) for (Select3D_EntitySequenceIter anIter (theEntities); anIter.More(); anIter.Next())
{ {
const Handle(Select3D_SensitiveEntity)& anEntity = anIter.Value(); const Handle(Select3D_SensitiveEntity)& anEntity = anIter.Value();
myEntities.Append (anEntity); const Standard_Integer aPrevExtent = myEntities.Extent();
if (myEntities.Add (anEntity) <= aPrevExtent)
{
continue;
}
myBndBox.Combine (anEntity->BoundingBox()); myBndBox.Combine (anEntity->BoundingBox());
myBVHPrimIndexes.Append (myEntities.Size()); myBVHPrimIndexes.Append (myEntities.Extent());
myCenter.ChangeCoord() += anEntity->CenterOfGeometry().XYZ(); myCenter.ChangeCoord() += anEntity->CenterOfGeometry().XYZ();
} }
myCenter.ChangeCoord().Divide (static_cast<Standard_Real> (myEntities.Size())); myCenter.ChangeCoord().Divide (static_cast<Standard_Real> (myEntities.Extent()));
MarkDirty(); MarkDirty();
} }
@@ -63,15 +69,27 @@ Select3D_SensitiveGroup::Select3D_SensitiveGroup (const Handle(SelectBasics_Enti
//======================================================================= //=======================================================================
void Select3D_SensitiveGroup::Add (Select3D_EntitySequence& theEntities) void Select3D_SensitiveGroup::Add (Select3D_EntitySequence& theEntities)
{ {
if (theEntities.IsEmpty())
{
return;
}
gp_Pnt aCent (0.0, 0.0, 0.0); gp_Pnt aCent (0.0, 0.0, 0.0);
myEntities.ReSize (myEntities.Extent() + theEntities.Size());
for (Select3D_EntitySequenceIter anIter (theEntities); anIter.More(); anIter.Next()) for (Select3D_EntitySequenceIter anIter (theEntities); anIter.More(); anIter.Next())
{ {
myEntities.Append (anIter.Value()); const Handle(Select3D_SensitiveEntity)& anEntity = anIter.Value();
myBndBox.Combine (anIter.Value()->BoundingBox()); const Standard_Integer aPrevExtent = myEntities.Extent();
myBVHPrimIndexes.Append (myEntities.Size()); if (myEntities.Add (anEntity) <= aPrevExtent)
aCent.ChangeCoord() += anIter.Value()->CenterOfGeometry().XYZ(); {
continue;
}
myBndBox.Combine (anEntity->BoundingBox());
myBVHPrimIndexes.Append (myEntities.Extent());
aCent.ChangeCoord() += anEntity->CenterOfGeometry().XYZ();
} }
aCent.ChangeCoord().Divide (myEntities.Length()); aCent.ChangeCoord().Divide (myEntities.Extent());
myCenter = (myCenter.XYZ() + aCent.XYZ()).Multiplied (0.5); myCenter = (myCenter.XYZ() + aCent.XYZ()).Multiplied (0.5);
} }
@@ -81,16 +99,16 @@ void Select3D_SensitiveGroup::Add (Select3D_EntitySequence& theEntities)
//======================================================================= //=======================================================================
void Select3D_SensitiveGroup::Add (const Handle(Select3D_SensitiveEntity)& theSensitive) void Select3D_SensitiveGroup::Add (const Handle(Select3D_SensitiveEntity)& theSensitive)
{ {
for (Select3D_EntitySequenceIter anIter (myEntities); anIter.More(); anIter.Next()) const Standard_Integer aPrevExtent = myEntities.Extent();
if (myEntities.Add (theSensitive) <= aPrevExtent)
{ {
if (anIter.Value() == theSensitive) return;
return;
} }
myEntities.Append (theSensitive);
myBVHPrimIndexes.Append (myEntities.Size()); myBVHPrimIndexes.Append (myEntities.Extent());
myBndBox.Combine (theSensitive->BoundingBox()); myBndBox.Combine (theSensitive->BoundingBox());
myCenter.ChangeCoord() += theSensitive->CenterOfGeometry().XYZ(); myCenter.ChangeCoord() += theSensitive->CenterOfGeometry().XYZ();
if (myEntities.First() != myEntities.Last()) if (myEntities.Extent() >= 2)
{ {
myCenter.ChangeCoord().Multiply (0.5); myCenter.ChangeCoord().Multiply (0.5);
} }
@@ -102,30 +120,22 @@ void Select3D_SensitiveGroup::Add (const Handle(Select3D_SensitiveEntity)& theSe
//======================================================================= //=======================================================================
void Select3D_SensitiveGroup::Remove (const Handle(Select3D_SensitiveEntity)& theSensitive) void Select3D_SensitiveGroup::Remove (const Handle(Select3D_SensitiveEntity)& theSensitive)
{ {
Standard_Boolean isSensitiveRemoved = Standard_False; if (!myEntities.RemoveKey (theSensitive))
for (Select3D_EntitySequenceIter anIter (myEntities); anIter.More(); anIter.Next())
{ {
if (anIter.Value() == theSensitive) return;
{
myEntities.Remove (anIter);
isSensitiveRemoved = Standard_True;
break;
}
} }
if (isSensitiveRemoved) myBndBox.Clear();
myCenter = gp_Pnt (0.0, 0.0, 0.0);
myBVHPrimIndexes.Clear();
for (Standard_Integer anIdx = 1; anIdx <= myEntities.Size(); ++anIdx)
{ {
myBndBox.Clear(); const Handle(Select3D_SensitiveEntity)& anEntity = myEntities.FindKey (anIdx);
myCenter = gp_Pnt (0.0, 0.0, 0.0); myBndBox.Combine (anEntity->BoundingBox());
myBVHPrimIndexes.Clear(); myCenter.ChangeCoord() += anEntity->CenterOfGeometry().XYZ();
for (Standard_Integer anIdx = 1; anIdx <= myEntities.Size(); ++anIdx) myBVHPrimIndexes.Append (anIdx);
{
myBndBox.Combine (myEntities.Value (anIdx)->BoundingBox());
myCenter.ChangeCoord() += myEntities.Value (anIdx)->CenterOfGeometry().XYZ();
myBVHPrimIndexes.Append (anIdx);
}
myCenter.ChangeCoord().Divide (static_cast<Standard_Real> (myEntities.Size()));
} }
myCenter.ChangeCoord().Divide (static_cast<Standard_Real> (myEntities.Extent()));
} }
//======================================================================= //=======================================================================
@@ -134,12 +144,7 @@ void Select3D_SensitiveGroup::Remove (const Handle(Select3D_SensitiveEntity)& th
//======================================================================= //=======================================================================
Standard_Boolean Select3D_SensitiveGroup::IsIn (const Handle(Select3D_SensitiveEntity)& theSensitive) const Standard_Boolean Select3D_SensitiveGroup::IsIn (const Handle(Select3D_SensitiveEntity)& theSensitive) const
{ {
for(Select3D_EntitySequenceIter anIter (myEntities); anIter.More(); anIter.Next()) return myEntities.Contains (theSensitive);
{
if (anIter.Value() == theSensitive)
return Standard_True;
}
return Standard_False;
} }
//======================================================================= //=======================================================================
@@ -173,9 +178,9 @@ Handle(Select3D_SensitiveEntity) Select3D_SensitiveGroup::GetConnected()
{ {
Handle(Select3D_SensitiveGroup) aNewEntity = new Select3D_SensitiveGroup (myOwnerId, myMustMatchAll); Handle(Select3D_SensitiveGroup) aNewEntity = new Select3D_SensitiveGroup (myOwnerId, myMustMatchAll);
Select3D_EntitySequence aConnectedEnt; Select3D_EntitySequence aConnectedEnt;
for (Select3D_EntitySequenceIter It (myEntities); It.More(); It.Next()) for (Select3D_IndexedMapOfEntity::Iterator anEntityIter (myEntities); anEntityIter.More(); anEntityIter.Next())
{ {
aConnectedEnt.Append (It.Value()->GetConnected()); aConnectedEnt.Append (anEntityIter.Value()->GetConnected());
} }
aNewEntity->Add (aConnectedEnt); aNewEntity->Add (aConnectedEnt);
return aNewEntity; return aNewEntity;
@@ -200,10 +205,10 @@ Standard_Boolean Select3D_SensitiveGroup::Matches (SelectBasics_SelectingVolumeM
Standard_Real aDepth = RealLast(); Standard_Real aDepth = RealLast();
Standard_Real aDistToCOG = RealLast(); Standard_Real aDistToCOG = RealLast();
Standard_Boolean isFailed = Standard_False; Standard_Boolean isFailed = Standard_False;
for (Select3D_EntitySequenceIter anIt (myEntities); anIt.More(); anIt.Next()) for (Select3D_IndexedMapOfEntity::Iterator anEntityIter (myEntities); anEntityIter.More(); anEntityIter.Next())
{ {
SelectBasics_PickResult aMatchResult; SelectBasics_PickResult aMatchResult;
Handle(Select3D_SensitiveEntity)& aChild = anIt.ChangeValue(); const Handle(Select3D_SensitiveEntity)& aChild = anEntityIter.Value();
if (!aChild->Matches (theMgr, aMatchResult)) if (!aChild->Matches (theMgr, aMatchResult))
{ {
if (toMatchAll) if (toMatchAll)
@@ -238,9 +243,10 @@ Standard_Boolean Select3D_SensitiveGroup::Matches (SelectBasics_SelectingVolumeM
void Select3D_SensitiveGroup::Set (const Handle(SelectBasics_EntityOwner)& theOwnerId) void Select3D_SensitiveGroup::Set (const Handle(SelectBasics_EntityOwner)& theOwnerId)
{ {
Select3D_SensitiveEntity::Set (theOwnerId); Select3D_SensitiveEntity::Set (theOwnerId);
// set TheOwnerId for each element of sensitive group for (Select3D_IndexedMapOfEntity::Iterator anEntityIter (myEntities); anEntityIter.More(); anEntityIter.Next())
for (Select3D_EntitySequenceIter anIter (myEntities); anIter.More(); anIter.Next()) {
anIter.Value()->Set (theOwnerId); anEntityIter.Value()->Set (theOwnerId);
}
} }
//======================================================================= //=======================================================================
@@ -255,9 +261,9 @@ Select3D_BndBox3d Select3D_SensitiveGroup::BoundingBox()
// do not apply the transformation because sensitives AABBs // do not apply the transformation because sensitives AABBs
// are already transformed // are already transformed
for (Select3D_EntitySequenceIter anIter (myEntities); anIter.More(); anIter.Next()) for (Select3D_IndexedMapOfEntity::Iterator anEntityIter (myEntities); anEntityIter.More(); anEntityIter.Next())
{ {
myBndBox.Combine (anIter.Value()->BoundingBox()); myBndBox.Combine (anEntityIter.Value()->BoundingBox());
} }
return myBndBox; return myBndBox;
@@ -280,7 +286,7 @@ gp_Pnt Select3D_SensitiveGroup::CenterOfGeometry() const
Select3D_BndBox3d Select3D_SensitiveGroup::Box (const Standard_Integer theIdx) const Select3D_BndBox3d Select3D_SensitiveGroup::Box (const Standard_Integer theIdx) const
{ {
const Standard_Integer anElemIdx = myBVHPrimIndexes.Value (theIdx); const Standard_Integer anElemIdx = myBVHPrimIndexes.Value (theIdx);
return myEntities.Value (anElemIdx)->BoundingBox(); return myEntities.FindKey (anElemIdx)->BoundingBox();
} }
//======================================================================= //=======================================================================
@@ -292,7 +298,7 @@ Standard_Real Select3D_SensitiveGroup::Center (const Standard_Integer theIdx,
const Standard_Integer theAxis) const const Standard_Integer theAxis) const
{ {
const Standard_Integer anElemIdx = myBVHPrimIndexes.Value (theIdx); const Standard_Integer anElemIdx = myBVHPrimIndexes.Value (theIdx);
const gp_Pnt aCenter = myEntities.Value (anElemIdx)->CenterOfGeometry(); const gp_Pnt aCenter = myEntities.FindKey (anElemIdx)->CenterOfGeometry();
return theAxis == 0 ? aCenter.X() : (theAxis == 1 ? aCenter.Y() : aCenter.Z()); return theAxis == 0 ? aCenter.X() : (theAxis == 1 ? aCenter.Y() : aCenter.Z());
} }
@@ -331,7 +337,7 @@ Standard_Boolean Select3D_SensitiveGroup::overlapsElement (SelectBasics_Selectin
theMatchDepth = RealLast(); theMatchDepth = RealLast();
const Standard_Integer aSensitiveIdx = myBVHPrimIndexes.Value (theElemIdx); const Standard_Integer aSensitiveIdx = myBVHPrimIndexes.Value (theElemIdx);
SelectBasics_PickResult aResult; SelectBasics_PickResult aResult;
if (myEntities.Value (aSensitiveIdx)->Matches (theMgr, aResult)) if (myEntities.FindKey (aSensitiveIdx)->Matches (theMgr, aResult))
{ {
theMatchDepth = aResult.Depth(); theMatchDepth = aResult.Depth();
return Standard_True; return Standard_True;

View File

@@ -18,6 +18,7 @@
#define _Select3D_SensitiveGroup_HeaderFile #define _Select3D_SensitiveGroup_HeaderFile
#include <Select3D_EntitySequence.hxx> #include <Select3D_EntitySequence.hxx>
#include <Select3D_IndexedMapOfEntity.hxx>
#include <Select3D_SensitiveEntity.hxx> #include <Select3D_SensitiveEntity.hxx>
#include <Select3D_SensitiveSet.hxx> #include <Select3D_SensitiveSet.hxx>
#include <SelectMgr_SelectingVolumeManager.hxx> #include <SelectMgr_SelectingVolumeManager.hxx>
@@ -48,19 +49,19 @@ public:
const Standard_Boolean theIsMustMatchAll = Standard_True); const Standard_Boolean theIsMustMatchAll = Standard_True);
//! Gets group content //! Gets group content
const Select3D_EntitySequence& GetEntities() const { return myEntities; } const Select3D_IndexedMapOfEntity& Entities() const { return myEntities; }
//! Access entity by index [1, NbSubElements()]. //! Access entity by index [1, NbSubElements()].
const Handle(Select3D_SensitiveEntity)& SubEntity (const Standard_Integer theIndex) const const Handle(Select3D_SensitiveEntity)& SubEntity (const Standard_Integer theIndex) const
{ {
return myEntities.Value (theIndex); return myEntities.FindKey (theIndex);
} }
//! Return last detected entity. //! Return last detected entity.
Handle(Select3D_SensitiveEntity) LastDetectedEntity() const Handle(Select3D_SensitiveEntity) LastDetectedEntity() const
{ {
const Standard_Integer anIndex = LastDetectedEntityIndex(); const Standard_Integer anIndex = LastDetectedEntityIndex();
return anIndex != -1 ? myEntities.Value (anIndex) : Handle(Select3D_SensitiveEntity)(); return anIndex != -1 ? myEntities.FindKey (anIndex) : Handle(Select3D_SensitiveEntity)();
} }
//! Return index of last detected entity. //! Return index of last detected entity.
@@ -158,7 +159,7 @@ private:
private: private:
Select3D_EntitySequence myEntities; //!< Grouped sensitive entities Select3D_IndexedMapOfEntity myEntities; //!< Grouped sensitive entities
Standard_Boolean myMustMatchAll; //!< Determines whether all entities in the group should be overlapped or not Standard_Boolean myMustMatchAll; //!< Determines whether all entities in the group should be overlapped or not
Standard_Boolean myToCheckOverlapAll; //!< flag to check overlapping with all entities within rectangular/polygonal selection Standard_Boolean myToCheckOverlapAll; //!< flag to check overlapping with all entities within rectangular/polygonal selection
gp_Pnt myCenter; //!< Center of geometry of the group gp_Pnt myCenter; //!< Center of geometry of the group

View File

@@ -87,8 +87,7 @@ void StdSelect_BRepSelectionTool::PreBuildBVH (const Handle(SelectMgr_Selection)
} }
Handle(Select3D_SensitiveGroup) aGroup = Handle(Select3D_SensitiveGroup)::DownCast (aSensitive); Handle(Select3D_SensitiveGroup) aGroup = Handle(Select3D_SensitiveGroup)::DownCast (aSensitive);
const Select3D_EntitySequence& aSubEntities = aGroup->GetEntities(); for (Select3D_IndexedMapOfEntity::Iterator aSubEntitiesIter (aGroup->Entities()); aSubEntitiesIter.More(); aSubEntitiesIter.Next())
for (Select3D_EntitySequenceIter aSubEntitiesIter (aSubEntities); aSubEntitiesIter.More(); aSubEntitiesIter.Next())
{ {
const Handle(Select3D_SensitiveEntity)& aSubEntity = aSubEntitiesIter.Value(); const Handle(Select3D_SensitiveEntity)& aSubEntity = aSubEntitiesIter.Value();
if (aSubEntity->NbSubElements() >= BVH_PRIMITIVE_LIMIT) if (aSubEntity->NbSubElements() >= BVH_PRIMITIVE_LIMIT)