From 24d5088297c103c52c52e47df887532bc650038b Mon Sep 17 00:00:00 2001 From: eap Date: Thu, 16 May 2013 16:08:00 +0000 Subject: [PATCH] - virtual SMDS_ElemIteratorPtr nodesIteratorToUNV() const; + virtual SMDS_NodeIteratorPtr nodeIterator() const; + virtual SMDS_NodeIteratorPtr interlacedNodesIterator() const; + virtual SMDS_NodeIteratorPtr nodesIteratorToUNV() const; --- src/SMDS/SMDS_MeshElement.cxx | 71 ++++++++++++++++++++++++++--------- src/SMDS/SMDS_MeshElement.hxx | 5 ++- 2 files changed, 57 insertions(+), 19 deletions(-) diff --git a/src/SMDS/SMDS_MeshElement.cxx b/src/SMDS/SMDS_MeshElement.cxx index b3478e3f5..708f5c1a8 100644 --- a/src/SMDS/SMDS_MeshElement.cxx +++ b/src/SMDS/SMDS_MeshElement.cxx @@ -161,34 +161,69 @@ class SMDS_MeshElement_MyIterator:public SMDS_ElemIterator } }; -SMDS_ElemIteratorPtr SMDS_MeshElement:: - elementsIterator(SMDSAbs_ElementType type) const +SMDS_ElemIteratorPtr +SMDS_MeshElement::elementsIterator(SMDSAbs_ElementType type) const { - /** @todo Check that iterator in the child classes return elements - in the same order for each different implementation (i.e: SMDS_VolumeOfNodes - and SMDS_VolumeOfFaces */ - - if(type==GetType()) - return SMDS_ElemIteratorPtr(new SMDS_MeshElement_MyIterator(this)); - else - { - MESSAGE("Iterator not implemented"); - return SMDS_ElemIteratorPtr((SMDS_ElemIterator*)NULL); - } + /** @todo Check that iterator in the child classes return elements + in the same order for each different implementation (i.e: SMDS_VolumeOfNodes + and SMDS_VolumeOfFaces */ + if(type==GetType()) + return SMDS_ElemIteratorPtr(new SMDS_MeshElement_MyIterator(this)); + else + { + MESSAGE("Iterator not implemented"); + return SMDS_ElemIteratorPtr((SMDS_ElemIterator*)NULL); + } } //! virtual, redefined in vtkEdge, vtkFace and vtkVolume classes -SMDS_ElemIteratorPtr SMDS_MeshElement::nodesIteratorToUNV() const +SMDS_NodeIteratorPtr SMDS_MeshElement::nodesIteratorToUNV() const { - MESSAGE("Iterator not implemented"); - return SMDS_ElemIteratorPtr((SMDS_ElemIterator*) NULL); + return nodeIterator(); } //! virtual, redefined in vtkEdge, vtkFace and vtkVolume classes +SMDS_NodeIteratorPtr SMDS_MeshElement::interlacedNodesIterator() const +{ + return nodeIterator(); +} + +namespace +{ + //======================================================================= + //class : _MyNodeIteratorFromElemIterator + //======================================================================= + class _MyNodeIteratorFromElemIterator : public SMDS_NodeIterator + { + SMDS_ElemIteratorPtr myItr; + public: + _MyNodeIteratorFromElemIterator(SMDS_ElemIteratorPtr elemItr):myItr( elemItr ) {} + bool more() { return myItr->more(); } + const SMDS_MeshNode* next() { return static_cast< const SMDS_MeshNode*>( myItr->next() ); } + }; + //======================================================================= + //class : _MyElemIteratorFromNodeIterator + //======================================================================= + class _MyElemIteratorFromNodeIterator : public SMDS_ElemIterator + { + SMDS_NodeIteratorPtr myItr; + public: + _MyElemIteratorFromNodeIterator(SMDS_NodeIteratorPtr nodeItr): myItr( nodeItr ) {} + bool more() { return myItr->more(); } + const SMDS_MeshElement* next() { return myItr->next(); } + }; +} + SMDS_ElemIteratorPtr SMDS_MeshElement::interlacedNodesElemIterator() const { - MESSAGE("Iterator not implemented"); - return SMDS_ElemIteratorPtr((SMDS_ElemIterator*) NULL); + return SMDS_ElemIteratorPtr + ( new _MyElemIteratorFromNodeIterator( interlacedNodesIterator() )); +} + +SMDS_NodeIteratorPtr SMDS_MeshElement::nodeIterator() const +{ + return SMDS_NodeIteratorPtr + ( new _MyNodeIteratorFromElemIterator( nodesIterator() )); } bool operator<(const SMDS_MeshElement& e1, const SMDS_MeshElement& e2) diff --git a/src/SMDS/SMDS_MeshElement.hxx b/src/SMDS/SMDS_MeshElement.hxx index ccb4373a9..a8a3ad422 100644 --- a/src/SMDS/SMDS_MeshElement.hxx +++ b/src/SMDS/SMDS_MeshElement.hxx @@ -65,9 +65,12 @@ public: SMDS_ElemIteratorPtr edgesIterator() const; SMDS_ElemIteratorPtr facesIterator() const; virtual SMDS_ElemIteratorPtr elementsIterator(SMDSAbs_ElementType type) const; - virtual SMDS_ElemIteratorPtr nodesIteratorToUNV() const; virtual SMDS_ElemIteratorPtr interlacedNodesElemIterator() const; + virtual SMDS_NodeIteratorPtr nodeIterator() const; + virtual SMDS_NodeIteratorPtr interlacedNodesIterator() const; + virtual SMDS_NodeIteratorPtr nodesIteratorToUNV() const; + // std-like iteration on nodes typedef SMDS_StdIterator< const SMDS_MeshNode*, SMDS_ElemIteratorPtr > iterator; iterator begin_nodes() const { return iterator( nodesIterator() ); } -- 2.39.2