added a function to retrieve a list of IDs from a list of subshapes. This function is provided for better performance when searching the IDs of a great number of subshapes.

This commit is contained in:
rnc 2013-01-23 16:31:10 +00:00
parent 011f7da686
commit 3892ca7188
6 changed files with 134 additions and 3 deletions

View File

@ -1841,6 +1841,14 @@ module GEOM
*/
long GetSubShapeIndex (in GEOM_Object theMainShape, in GEOM_Object theSubShape);
/*!
* Get global indices of \a theSubShapes in \a theMainShape.
* \param theMainShape Main shape.
* \param theSubShapes List of sub-shapes of the main shape.
* \return list of global indices of \a theSubShapes in \a theMainShape.
*/
ListOfLong GetSubShapesIndices (in GEOM_Object theMainShape, in ListOfGO theSubShapes);
/*!
* \brief Get index of \a theSubShape in \a theMainShape, unique among sub-shapes of the same type.
*

View File

@ -1558,14 +1558,62 @@ Standard_Integer GEOMImpl_IShapesOperations::GetSubShapeIndex (Handle(GEOM_Objec
TopTools_IndexedMapOfShape anIndices;
TopExp::MapShapes(aMainShape, anIndices);
if (anIndices.Contains(aSubShape)) {
// if (anIndices.Contains(aSubShape)) {
// SetErrorCode(OK);
// return anIndices.FindIndex(aSubShape);
// }
int id = anIndices.FindIndex(aSubShape);
if (id > 0)
{
SetErrorCode(OK);
return anIndices.FindIndex(aSubShape);
return id;
}
return -1;
}
//=============================================================================
/*!
* GetSubShapeIndices
*/
//=============================================================================
Handle(TColStd_HSequenceOfInteger) GEOMImpl_IShapesOperations::GetSubShapesIndices (Handle(GEOM_Object) theMainShape,
std::list<Handle(GEOM_Object)> theSubShapes)
{
MESSAGE("GEOMImpl_IShapesOperations::GetSubShapesIndices")
SetErrorCode(KO);
Handle(TColStd_HSequenceOfInteger) aSeq = new TColStd_HSequenceOfInteger;
TopoDS_Shape aMainShape = theMainShape->GetValue();
if (aMainShape.IsNull())
{
MESSAGE("NULL main shape")
return NULL;
}
TopTools_IndexedMapOfShape anIndices;
TopExp::MapShapes(aMainShape, anIndices);
std::list<Handle(GEOM_Object)>::iterator it;
for (it=theSubShapes.begin(); it != theSubShapes.end(); ++it)
{
TopoDS_Shape aSubShape = (*it)->GetValue();
if (aSubShape.IsNull())
{
MESSAGE("NULL subshape")
return NULL;
}
int id = anIndices.FindIndex(aSubShape);
aSeq->Append(id);
}
SetErrorCode(OK);
return aSeq;
}
//=============================================================================
/*!
* GetTopologyIndex

View File

@ -137,6 +137,9 @@ class GEOMImpl_IShapesOperations : public GEOM_IOperations
Standard_EXPORT Standard_Integer GetSubShapeIndex (Handle(GEOM_Object) theMainShape,
Handle(GEOM_Object) theSubShape);
Standard_EXPORT Handle(TColStd_HSequenceOfInteger) GetSubShapesIndices (Handle(GEOM_Object) theMainShape,
std::list<Handle(GEOM_Object)> theSubShapes);
Standard_EXPORT Standard_Integer GetTopologyIndex (Handle(GEOM_Object) theMainShape,
Handle(GEOM_Object) theSubShape);

View File

@ -831,6 +831,49 @@ CORBA::Long GEOM_IShapesOperations_i::GetSubShapeIndex
return anID;
}
//=============================================================================
/*!
* GetSubShapesIndices
*/
//=============================================================================
GEOM::ListOfLong* GEOM_IShapesOperations_i::GetSubShapesIndices
(GEOM::GEOM_Object_ptr theMainShape, const GEOM::ListOfGO& theSubShapes)
{
GEOM::ListOfLong_var aSeq = new GEOM::ListOfLong;
//Get the reference main shape
Handle(GEOM_Object) aMainShapeRef = GetObjectImpl(theMainShape);
if (aMainShapeRef.IsNull()) return aSeq._retn();
//Get the subshapes
std::list<Handle(GEOM_Object)> aShapes;
int aLen = theSubShapes.length();
for (int ind = 0; ind < aLen; ind++) {
Handle(GEOM_Object) aSh = GetObjectImpl(theSubShapes[ind]);
if (aSh.IsNull())
{
MESSAGE("NULL shape")
return aSeq._retn();
}
aShapes.push_back(aSh);
}
//Get the IDs of <theSubShapes> inside <theMainShape>
Handle(TColStd_HSequenceOfInteger) aHSeq =
GetOperations()->GetSubShapesIndices(aMainShapeRef, aShapes);
if (!GetOperations()->IsDone() || aHSeq.IsNull()) return aSeq._retn();
Standard_Integer aLength = aHSeq->Length();
aSeq->length(aLength);
for (Standard_Integer i = 1; i <= aLength; i++)
aSeq[i-1] = aHSeq->Value(i);
return aSeq._retn();
}
//=============================================================================
/*!
* GetTopologyIndex

View File

@ -128,6 +128,9 @@ class GEOM_I_EXPORT GEOM_IShapesOperations_i :
CORBA::Long GetSubShapeIndex (GEOM::GEOM_Object_ptr theMainShape,
GEOM::GEOM_Object_ptr theSubShape);
GEOM::ListOfLong* GetSubShapesIndices (GEOM::GEOM_Object_ptr theMainShape,
const GEOM::ListOfGO& theSubShapes);
CORBA::Long GetTopologyIndex (GEOM::GEOM_Object_ptr theMainShape,
GEOM::GEOM_Object_ptr theSubShape);

View File

@ -5194,6 +5194,32 @@ class geompyDC(GEOM._objref_GEOM_Gen):
anID = self.LocalOp.GetSubShapeIndex(aShape, aSubShape)
RaiseIfFailed("GetSubShapeIndex", self.LocalOp)
return anID
## Obtain unique IDs of sub-shapes <VAR>aSubShapes</VAR> inside <VAR>aShape</VAR>
# This function is provided for performance purpose. The complexity is O(n) with n
# the number of subobjects of aShape
# @param aShape Shape to get sub-shape of.
# @param aSubShapes Sub-shapes of aShape.
# @return list of IDs of found sub-shapes.
#
# @ref swig_all_decompose "Example"
def GetSubShapesIDs(self, aShape, aSubShapes):
"""
Obtain a list of IDs of sub-shapes aSubShapes inside aShape
This function is provided for performance purpose. The complexity is O(n) with n
the number of subobjects of aShape
Parameters:
aShape Shape to get sub-shape of.
aSubShapes Sub-shapes of aShape.
Returns:
List of IDs of found sub-shape.
"""
# Example: see GEOM_TestAll.py
anIDs = self.ShapesOp.GetSubShapesIndices(aShape, aSubShapes)
RaiseIfFailed("GetSubShapesIndices", self.ShapesOp)
return anIDs
# end of l4_access
## @}