Implement iteration in id increasing order

-  SMDS_NodeIteratorPtr nodesIterator(bool idInceasingOrder=false) const;
-  SMDS_0DElementIteratorPtr elements0dIterator() const;
-  SMDS_EdgeIteratorPtr edgesIterator() const;
-  SMDS_FaceIteratorPtr facesIterator() const;
-  SMDS_VolumeIteratorPtr volumesIterator() const;
+  SMDS_NodeIteratorPtr nodesIterator          (bool idInceasingOrder=false) const;
+  SMDS_0DElementIteratorPtr elements0dIterator(bool idInceasingOrder=false) const;
+  SMDS_EdgeIteratorPtr edgesIterator          (bool idInceasingOrder=false) const;
+  SMDS_FaceIteratorPtr facesIterator          (bool idInceasingOrder=false) const;
+  SMDS_VolumeIteratorPtr volumesIterator      (bool idInceasingOrder=false) const;
This commit is contained in:
eap 2010-08-19 09:17:39 +00:00
parent 2712d2bac8
commit 32e5402500
2 changed files with 51 additions and 19 deletions

View File

@ -2191,12 +2191,18 @@ namespace {
class IdSortedIterator : public SMDS_Iterator<ELEM>
{
const SMDS_MeshElementIDFactory& myIDFact;
int myID, myMaxID;
int myID, myMaxID, myNbFound, myTotalNb;
SMDSAbs_ElementType myType;
ELEM myElem;
public:
IdSortedIterator(const SMDS_MeshElementIDFactory& fact)
:myIDFact( fact ), myID(1), myMaxID( myIDFact.GetMaxID() ), myElem(0)
IdSortedIterator(const SMDS_MeshElementIDFactory& fact,
const SMDSAbs_ElementType type, // SMDSAbs_All NOT allowed!!!
const int totalNb)
:myIDFact( fact ),
myID(1), myMaxID( myIDFact.GetMaxID() ),myNbFound(0), myTotalNb( totalNb ),
myType( type ),
myElem(0)
{
next();
}
@ -2207,8 +2213,14 @@ namespace {
ELEM next()
{
ELEM current = myElem;
for ( myElem = 0; myID <= myMaxID && !myElem; ++myID )
myElem = (ELEM) myIDFact.MeshElement( myID );
for ( myElem = 0; !myElem && myNbFound < myTotalNb && myID <= myMaxID; ++myID )
if ((myElem = (ELEM) myIDFact.MeshElement( myID ))
&& myElem->GetType() != myType )
myElem = 0;
myNbFound += bool(myElem);
return current;
}
};
@ -2224,7 +2236,7 @@ SMDS_NodeIteratorPtr SMDS_Mesh::nodesIterator(bool idInceasingOrder) const
< SetOfNodes, const SMDS_MeshNode*, SMDS_NodeIterator > TIterator;
typedef IdSortedIterator< const SMDS_MeshNode* > TSortedIterator;
return ( idInceasingOrder ?
SMDS_NodeIteratorPtr( new TSortedIterator( *myNodeIDFactory )) :
SMDS_NodeIteratorPtr( new TSortedIterator( *myNodeIDFactory, SMDSAbs_Node, NbNodes())) :
SMDS_NodeIteratorPtr( new TIterator(myNodes)));
}
@ -2232,44 +2244,64 @@ SMDS_NodeIteratorPtr SMDS_Mesh::nodesIterator(bool idInceasingOrder) const
///Return an iterator on 0D elements of the current mesh.
///////////////////////////////////////////////////////////////////////////////
SMDS_0DElementIteratorPtr SMDS_Mesh::elements0dIterator() const
SMDS_0DElementIteratorPtr SMDS_Mesh::elements0dIterator(bool idInceasingOrder) const
{
typedef MYNCollection_Map_Iterator
< SetOf0DElements, const SMDS_Mesh0DElement*, SMDS_0DElementIterator > TIterator;
return SMDS_0DElementIteratorPtr(new TIterator(my0DElements));
typedef IdSortedIterator< const SMDS_Mesh0DElement* > TSortedIterator;
return ( idInceasingOrder ?
SMDS_0DElementIteratorPtr( new TSortedIterator( *myElementIDFactory,
SMDSAbs_0DElement,
Nb0DElements() )) :
SMDS_0DElementIteratorPtr( new TIterator(my0DElements)));
}
///////////////////////////////////////////////////////////////////////////////
///Return an iterator on edges of the current mesh.
///////////////////////////////////////////////////////////////////////////////
SMDS_EdgeIteratorPtr SMDS_Mesh::edgesIterator() const
SMDS_EdgeIteratorPtr SMDS_Mesh::edgesIterator(bool idInceasingOrder) const
{
typedef MYNCollection_Map_Iterator
< SetOfEdges, const SMDS_MeshEdge*, SMDS_EdgeIterator > TIterator;
return SMDS_EdgeIteratorPtr(new TIterator(myEdges));
typedef IdSortedIterator< const SMDS_MeshEdge* > TSortedIterator;
return ( idInceasingOrder ?
SMDS_EdgeIteratorPtr( new TSortedIterator( *myElementIDFactory,
SMDSAbs_Edge,
NbEdges() )) :
SMDS_EdgeIteratorPtr(new TIterator(myEdges)));
}
///////////////////////////////////////////////////////////////////////////////
///Return an iterator on faces of the current mesh.
///////////////////////////////////////////////////////////////////////////////
SMDS_FaceIteratorPtr SMDS_Mesh::facesIterator() const
SMDS_FaceIteratorPtr SMDS_Mesh::facesIterator(bool idInceasingOrder) const
{
typedef MYNCollection_Map_Iterator
< SetOfFaces, const SMDS_MeshFace*, SMDS_FaceIterator > TIterator;
return SMDS_FaceIteratorPtr(new TIterator(myFaces));
typedef IdSortedIterator< const SMDS_MeshFace* > TSortedIterator;
return ( idInceasingOrder ?
SMDS_FaceIteratorPtr( new TSortedIterator( *myElementIDFactory,
SMDSAbs_Face,
NbFaces() )) :
SMDS_FaceIteratorPtr(new TIterator(myFaces)));
}
///////////////////////////////////////////////////////////////////////////////
///Return an iterator on volumes of the current mesh.
///////////////////////////////////////////////////////////////////////////////
SMDS_VolumeIteratorPtr SMDS_Mesh::volumesIterator() const
SMDS_VolumeIteratorPtr SMDS_Mesh::volumesIterator(bool idInceasingOrder) const
{
typedef MYNCollection_Map_Iterator
< SetOfVolumes, const SMDS_MeshVolume*, SMDS_VolumeIterator > TIterator;
return SMDS_VolumeIteratorPtr(new TIterator(myVolumes));
typedef IdSortedIterator< const SMDS_MeshVolume* > TSortedIterator;
return ( idInceasingOrder ?
SMDS_VolumeIteratorPtr( new TSortedIterator( *myElementIDFactory,
SMDSAbs_Volume,
NbVolumes() )) :
SMDS_VolumeIteratorPtr(new TIterator(myVolumes)));
}
///////////////////////////////////////////////////////////////////////////////

View File

@ -48,11 +48,11 @@ public:
SMDS_Mesh();
SMDS_NodeIteratorPtr nodesIterator(bool idInceasingOrder=false) const;
SMDS_0DElementIteratorPtr elements0dIterator() const;
SMDS_EdgeIteratorPtr edgesIterator() const;
SMDS_FaceIteratorPtr facesIterator() const;
SMDS_VolumeIteratorPtr volumesIterator() const;
SMDS_NodeIteratorPtr nodesIterator (bool idInceasingOrder=false) const;
SMDS_0DElementIteratorPtr elements0dIterator(bool idInceasingOrder=false) const;
SMDS_EdgeIteratorPtr edgesIterator (bool idInceasingOrder=false) const;
SMDS_FaceIteratorPtr facesIterator (bool idInceasingOrder=false) const;
SMDS_VolumeIteratorPtr volumesIterator (bool idInceasingOrder=false) const;
SMDS_ElemIteratorPtr elementsIterator(SMDSAbs_ElementType type=SMDSAbs_All) const;
SMDSAbs_ElementType GetElementType( const int id, const bool iselem ) const;