Salome HOME
Add SMDS_SetIterator.hxx, element->GetNode(index), fix some errors
authoreap <eap@opencascade.com>
Fri, 3 Mar 2006 13:50:03 +0000 (13:50 +0000)
committereap <eap@opencascade.com>
Fri, 3 Mar 2006 13:50:03 +0000 (13:50 +0000)
23 files changed:
src/SMDS/Makefile.in
src/SMDS/SMDS_ElemIterator.hxx
src/SMDS/SMDS_FaceOfEdges.cxx
src/SMDS/SMDS_FaceOfEdges.hxx
src/SMDS/SMDS_FaceOfNodes.cxx
src/SMDS/SMDS_FaceOfNodes.hxx
src/SMDS/SMDS_Mesh.hxx
src/SMDS/SMDS_MeshEdge.cxx
src/SMDS/SMDS_MeshEdge.hxx
src/SMDS/SMDS_MeshElement.cxx
src/SMDS/SMDS_MeshElement.hxx
src/SMDS/SMDS_MeshNode.hxx
src/SMDS/SMDS_PolygonalFaceOfNodes.cxx
src/SMDS/SMDS_PolygonalFaceOfNodes.hxx
src/SMDS/SMDS_QuadraticEdge.cxx
src/SMDS/SMDS_QuadraticEdge.hxx
src/SMDS/SMDS_QuadraticFaceOfNodes.cxx
src/SMDS/SMDS_QuadraticFaceOfNodes.hxx
src/SMDS/SMDS_QuadraticVolumeOfNodes.cxx
src/SMDS/SMDS_QuadraticVolumeOfNodes.hxx
src/SMDS/SMDS_SetIterator.hxx [new file with mode: 0644]
src/SMDS/SMDS_VolumeOfNodes.cxx
src/SMDS/SMDS_VolumeOfNodes.hxx

index 67c41b2031350a58d2f14f96d0caf54eaa12b572..7ecaf313a8b0bc98241fb65fd2e34c340504c2f8 100644 (file)
@@ -63,20 +63,6 @@ LIB_SRC = \
        SMDS_QuadraticEdge.cxx \
        SMDS_QuadraticFaceOfNodes.cxx \
        SMDS_QuadraticVolumeOfNodes.cxx
-#      SMDS_Tria3OfNodes.cxx \
-#      SMDS_HexahedronOfNodes.cxx
-
-#SMDSControl_BoundaryEdges.cxx \
-#SMDSControl_BoundaryFaces.cxx \
-#SMDSControl.cxx \
-#SMDSControl_MeshBoundary.cxx \
-#SMDSEdit_Transform.cxx \
-#SMDS_MeshNodeIDFactory.cxx \
-#SMDS_MeshPrism.cxx \
-#SMDS_MeshPyramid.cxx \
-#SMDS_MeshQuadrangle.cxx \
-#SMDS_MeshTetrahedron.cxx \
-#SMDS_MeshTriangle.cxx \
 
 
 LIB_CLIENT_IDL = 
@@ -119,21 +105,8 @@ EXPORT_HEADERS= \
        SMDS_VolumeTool.hxx \
        SMDS_QuadraticEdge.hxx \
        SMDS_QuadraticFaceOfNodes.hxx \
-       SMDS_QuadraticVolumeOfNodes.hxx
-#      SMDS_Tria3OfNodes.hxx \
-#      SMDS_HexahedronOfNodes.hxx
-
-#SMDSControl_BoundaryEdges.hxx \
-#SMDSControl_BoundaryFaces.hxx \
-#SMDSControl.hxx \
-#SMDSControl_MeshBoundary.hxx \
-#SMDSEdit_Transform.hxx \
-#SMDS_MeshPrism.hxx \
-#SMDS_MeshPyramid.hxx \
-#SMDS_MeshQuadrangle.hxx \
-#SMDS_MeshTetrahedron.hxx \
-#SMDS_MeshTriangle.hxx \
-#SMDS_MeshNodeIDFactory.hxx
+       SMDS_QuadraticVolumeOfNodes.hxx \
+       SMDS_SetIterator.hxx
 
 # additionnal information to compil and link file
 CPPFLAGS += -I${KERNEL_ROOT_DIR}/include/salome $(OCC_INCLUDES) $(BOOST_CPPFLAGS)
index c8432afddf0e0865c92f6132415fa577836628cb..6ff0986448f727bd97c074a496d0c3130af908bb 100755 (executable)
 #include <boost/shared_ptr.hpp>
 
 class SMDS_MeshElement;
+class SMDS_MeshNode;
+class SMDS_MeshEdge;
+class SMDS_MeshFace;
+class SMDS_MeshVolume;
 
 typedef SMDS_Iterator<const SMDS_MeshElement *> SMDS_ElemIterator;
 typedef boost::shared_ptr<SMDS_Iterator<const SMDS_MeshElement *> > SMDS_ElemIteratorPtr;
 
+typedef SMDS_Iterator<const SMDS_MeshNode *> SMDS_NodeIterator;
+typedef boost::shared_ptr<SMDS_Iterator<const SMDS_MeshNode *> > SMDS_NodeIteratorPtr;
+
+typedef SMDS_Iterator<const SMDS_MeshEdge *> SMDS_EdgeIterator;
+typedef boost::shared_ptr<SMDS_Iterator<const SMDS_MeshEdge *> > SMDS_EdgeIteratorPtr;
+
+typedef SMDS_Iterator<const SMDS_MeshFace *> SMDS_FaceIterator;
+typedef boost::shared_ptr<SMDS_Iterator<const SMDS_MeshFace *> > SMDS_FaceIteratorPtr;
+
+typedef SMDS_Iterator<const SMDS_MeshVolume *> SMDS_VolumeIterator;
+typedef boost::shared_ptr<SMDS_Iterator<const SMDS_MeshVolume *> > SMDS_VolumeIteratorPtr;
+
 #endif
index 640c55d30194f44cd2835f4164abfaed5bc93a3b..7a014afb8bc6f10522930b8ee5696bdcccab1325 100644 (file)
@@ -155,3 +155,29 @@ SMDS_FaceOfEdges::SMDS_FaceOfEdges(const SMDS_MeshEdge* edge1,
 
 }*/
 
+
+int SMDS_FaceOfEdges::NbNodes() const
+{
+  return myEdges[0]->NbNodes() + myEdges[1]->NbNodes() + myEdges[2]->NbNodes() +
+    ( myNbEdges == 4 ? myEdges[3]->NbNodes() : 0 ) - myNbEdges;
+}
+
+/*!
+ * \brief Return node by its index
+ * \param ind - node index
+ * \retval const SMDS_MeshNode* - the node
+ * 
+ * Index is wrapped if it is out of a valid range
+ */
+const SMDS_MeshNode* SMDS_FaceOfEdges::GetNode(const int ind) const
+{
+  int index = WrappedIndex( ind );
+  for ( int i = 0; i < myNbEdges; ++i ) {
+    if ( index >= myEdges[ i ]->NbNodes() )
+      index -= myEdges[ i ]->NbNodes();
+    else
+      return myEdges[ i ]->GetNode( index );
+  }
+  return 0;
+}
+
index cd8e5dd8f29ee2ca94343860f1ec1b3e86a9191a..54a9a688f95c919b7929064a7a58a74ba495e192 100644 (file)
@@ -42,10 +42,21 @@ class SMDS_FaceOfEdges:public SMDS_MeshFace
                          const SMDS_MeshEdge* edge4);
                
        SMDSAbs_ElementType GetType() const;
+       int NbNodes() const;
        int NbEdges() const;
        int NbFaces() const;
 //     friend bool operator<(const SMDS_FaceOfEdges& e1, const SMDS_FaceOfEdges& e2);
 
+
+  /*!
+   * \brief Return node by its index
+    * \param ind - node index
+    * \retval const SMDS_MeshNode* - the node
+   * 
+   * Index is wrapped if it is out of a valid range
+   */
+  virtual const SMDS_MeshNode* GetNode(const int ind) const;
+
   protected:
        SMDS_ElemIteratorPtr
                elementsIterator(SMDSAbs_ElementType type) const;
index aa687082475c0633983a49b859093ecbd6b5bdca..018bd88a0d927efaef2a4d57ae01567d5cb133b6 100644 (file)
@@ -23,6 +23,7 @@
 #pragma warning(disable:4786)
 #endif
 
+#include "SMDS_SetIterator.hxx"
 #include "SMDS_FaceOfNodes.hxx"
 #include "SMDS_IteratorOfElements.hxx"
 #include "SMDS_MeshNode.hxx"
@@ -68,25 +69,11 @@ void SMDS_FaceOfNodes::Print(ostream & OS) const
 //purpose  : 
 //=======================================================================
 
-class SMDS_FaceOfNodes_MyIterator:public SMDS_ElemIterator
+class SMDS_FaceOfNodes_MyIterator:public SMDS_NodeArrayElemIterator
 {
-  const SMDS_MeshNode* const *mySet;
-  int myLength;
-  int index;
  public:
   SMDS_FaceOfNodes_MyIterator(const SMDS_MeshNode* const *s, int l):
-    mySet(s),myLength(l),index(0) {}
-
-  bool more()
-  {
-    return index<myLength;
-  }
-
-  const SMDS_MeshElement* next()
-  {
-    index++;
-    return mySet[index-1];
-  }
+    SMDS_NodeArrayElemIterator( s, & s[ l ] ) {}
 };
 
 SMDS_ElemIteratorPtr SMDS_FaceOfNodes::elementsIterator
@@ -147,6 +134,18 @@ bool SMDS_FaceOfNodes::ChangeNodes(const SMDS_MeshNode* nodes[],
   return true;
 }
 
+/*!
+ * \brief Return node by its index
+ * \param ind - node index
+ * \retval const SMDS_MeshNode* - the node
+ * 
+ * Index is wrapped if it is out of a valid range
+ */
+const SMDS_MeshNode* SMDS_FaceOfNodes::GetNode(const int ind) const
+{
+  return myNodes[ WrappedIndex( ind )];
+}
+
 /*bool operator<(const SMDS_FaceOfNodes& f1, const SMDS_FaceOfNodes& f2)
 {
        set<SMDS_MeshNode> set1,set2;
index 290195107d4844fbd2be02cfd5770209232a703c..8cbdf6f33ccdc95e64d69a3bf5d1ab73dcc0c735 100644 (file)
@@ -44,6 +44,16 @@ class SMDS_FaceOfNodes:public SMDS_MeshFace
        int NbEdges() const;
        int NbFaces() const;
        int NbNodes() const;
+
+  /*!
+   * \brief Return node by its index
+    * \param ind - node index
+    * \retval const SMDS_MeshNode* - the node
+   * 
+   * Index is wrapped if it is out of a valid range
+   */
+  virtual const SMDS_MeshNode* GetNode(const int ind) const;
+
   protected:
        SMDS_ElemIteratorPtr
                elementsIterator(SMDSAbs_ElementType type) const;
index f0835eae355e8b569f394741dffa3f5b33185c87..a0d95cb56fc5f79ca5fc03c4b9a7e43be66fb6ca 100644 (file)
 #include <set>
 #include <list>
 
-typedef SMDS_Iterator<const SMDS_MeshNode *> SMDS_NodeIterator;
-typedef boost::shared_ptr<SMDS_Iterator<const SMDS_MeshNode *> > SMDS_NodeIteratorPtr;
-typedef SMDS_Iterator<const SMDS_MeshEdge *> SMDS_EdgeIterator;
-typedef boost::shared_ptr<SMDS_Iterator<const SMDS_MeshEdge *> > SMDS_EdgeIteratorPtr;
-typedef SMDS_Iterator<const SMDS_MeshFace *> SMDS_FaceIterator;
-typedef boost::shared_ptr<SMDS_Iterator<const SMDS_MeshFace *> > SMDS_FaceIteratorPtr;
-typedef SMDS_Iterator<const SMDS_MeshVolume *> SMDS_VolumeIterator;
-typedef boost::shared_ptr<SMDS_Iterator<const SMDS_MeshVolume *> > SMDS_VolumeIteratorPtr;
-
 class SMDS_WNT_EXPORT SMDS_Mesh:public SMDS_MeshObject{
 public:
   
index 66c8ae3d5cf36edf2e0ff37545f40a6e4d2e4b43..dc1dab968d5ec2f78b1440212e2af305f883a2a0 100644 (file)
@@ -135,6 +135,18 @@ bool operator<(const SMDS_MeshEdge & e1, const SMDS_MeshEdge & e2)
        else return false;
 }
 
+/*!
+ * \brief Return node by its index
+ * \param ind - node index
+ * \retval const SMDS_MeshNode* - the node
+ * 
+ * Index is wrapped if it is out of a valid range
+ */
+const SMDS_MeshNode* SMDS_MeshEdge::GetNode(const int ind) const
+{
+  return myNodes[ WrappedIndex( ind )];
+}
+
 //=======================================================================
 //function : ChangeNodes
 //purpose  : 
index 3fdf0ae1c5eb84749c4b628546da6f9206cbcf3f..c99b08198c7cadbed6a246056b101192bf155186 100644 (file)
@@ -44,6 +44,16 @@ class SMDS_MeshEdge:public SMDS_MeshElement
        int NbNodes() const;
        int NbEdges() const;
        friend bool operator<(const SMDS_MeshEdge& e1, const SMDS_MeshEdge& e2);
+
+  /*!
+   * \brief Return node by its index
+    * \param ind - node index
+    * \retval const SMDS_MeshNode* - the node
+   * 
+   * Index is wrapped if it is out of a valid range
+   */
+  virtual const SMDS_MeshNode* GetNode(const int ind) const;
+
   protected:
        SMDS_ElemIteratorPtr
                elementsIterator(SMDSAbs_ElementType type) const;
index 518feb1adc5ce2c5cec2e47fcc0ff2debdb68585..f75367e792b6a2ab3b39227cf3954194f911a5f4 100644 (file)
@@ -200,17 +200,11 @@ bool SMDS_MeshElement::IsValidIndex(const int ind) const
 
 const SMDS_MeshNode* SMDS_MeshElement::GetNode(const int ind) const
 {
-  SMDS_MeshNode* N;
-  if(IsValidIndex(ind)) {
-    int nbe = 0;
-    SMDS_ElemIteratorPtr it=edgesIterator();
-    while(nbe<ind) {
-      it->next();
-      nbe++;
-    }
-    return static_cast<const SMDS_MeshNode*> (it->next());
-  }
-  return N;
+  SMDS_ElemIteratorPtr it = nodesIterator();
+  int i = 0, index = WrappedIndex( ind );
+  while ( index != i++ )
+    it->next();
+  return static_cast<const SMDS_MeshNode*> (it->next());
 }
 
 bool SMDS_MeshElement::IsQuadratic() const
index e8672cd908ce8f7d2cee327022919bbd9292c410..126a192b958b2c274a9e81fed9d692e039c5e141 100644 (file)
@@ -68,15 +68,6 @@ public:
   virtual int NbFaces() const;
   int GetID() const;
 
-  /**
-   * Return true if index of node is valid (0...NbNodes()-1)
-   */
-  virtual bool IsValidIndex(const int ind) const;
-  /**
-   * Return node by it index (if index is valid)
-   */
-  virtual const SMDS_MeshNode* GetNode(const int ind) const;
-
   ///Return the type of the current element
   virtual SMDSAbs_ElementType GetType() const = 0;
   virtual bool IsPoly() const { return false; };
@@ -87,6 +78,36 @@ public:
   friend std::ostream & operator <<(std::ostream & OS, const SMDS_MeshElement *);
   friend bool SMDS_MeshElementIDFactory::BindID(int ID,SMDS_MeshElement*elem);
 
+  // ===========================
+  //  Access to nodes by index
+  // ===========================
+  /*!
+   * \brief Return node by its index
+    * \param ind - node index
+    * \retval const SMDS_MeshNode* - the node
+   * 
+   * Index is wrapped if it is out of a valid range
+   */
+  virtual const SMDS_MeshNode* GetNode(const int ind) const;
+
+  /*!
+   * \brief Return true if index of node is valid (0 <= ind < NbNodes())
+    * \param ind - node index
+    * \retval bool - index check result
+   */
+  virtual bool IsValidIndex(const int ind) const;
+
+  /*!
+   * \brief Make index valid
+    * \param ind - node index
+    * \retval int - valid node index
+   */
+  int WrappedIndex(const int ind) const {
+    if ( ind < 0 ) return -( ind % NbNodes());
+    if ( ind >= NbNodes() ) return ind % NbNodes();
+    return ind;
+  }
+
 protected:
   SMDS_MeshElement(int ID=-1);
   virtual void Print(std::ostream & OS) const;
index 042a1734af5bfdefef81be8e24fbb719339bfe8c..fad62253411a848c8b0675bef333b36332e43275 100644 (file)
@@ -64,6 +64,15 @@ class SMDS_WNT_EXPORT SMDS_MeshNode:public SMDS_MeshElement
        void setXYZ(double x, double y, double z);
        friend bool operator<(const SMDS_MeshNode& e1, const SMDS_MeshNode& e2);
 
+  /*!
+   * \brief Return node by its index
+    * \param ind - node index
+    * \retval const SMDS_MeshNode* - the node
+   * 
+   * Index is wrapped if it is out of a valid range
+   */
+  virtual const SMDS_MeshNode* GetNode(const int) const { return this; }
+
   protected:
        SMDS_ElemIteratorPtr
                elementsIterator(SMDSAbs_ElementType type) const;
index 38abf18c2f225e598249640cce2e308602e7f43a..568bd34d0095b128adce4c9d48c6166a518d425e 100644 (file)
@@ -26,7 +26,7 @@
 #include "SMDS_PolygonalFaceOfNodes.hxx"
 
 #include "SMDS_IteratorOfElements.hxx"
-//#include "SMDS_MeshNode.hxx"
+#include "SMDS_SetIterator.hxx"
 #include "utilities.h"
 
 using namespace std;
@@ -128,28 +128,11 @@ void SMDS_PolygonalFaceOfNodes::Print(ostream & OS) const
 //function : elementsIterator
 //purpose  : 
 //=======================================================================
-class SMDS_PolygonalFaceOfNodes_MyIterator:public SMDS_ElemIterator
+class SMDS_PolygonalFaceOfNodes_MyIterator:public SMDS_NodeVectorElemIterator
 {
-  //const SMDS_MeshNode* const *mySet;
-  const std::vector<const SMDS_MeshNode *> mySet;
-  //int myLength;
-  int index;
  public:
-  //SMDS_PolygonalFaceOfNodes_MyIterator(const SMDS_MeshNode* const *s, int l):
-  //  mySet(s),myLength(l),index(0) {}
-  SMDS_PolygonalFaceOfNodes_MyIterator(const std::vector<const SMDS_MeshNode *> s):
-    mySet(s),index(0) {}
-
-  bool more()
-  {
-    return index < mySet.size();
-  }
-
-  const SMDS_MeshElement* next()
-  {
-    index++;
-    return mySet[index-1];
-  }
+  SMDS_PolygonalFaceOfNodes_MyIterator(const vector<const SMDS_MeshNode *>& s):
+    SMDS_NodeVectorElemIterator( s.begin(), s.end() ) {}
 };
 
 SMDS_ElemIteratorPtr SMDS_PolygonalFaceOfNodes::elementsIterator
@@ -172,3 +155,16 @@ SMDS_ElemIteratorPtr SMDS_PolygonalFaceOfNodes::elementsIterator
   }
   return SMDS_ElemIteratorPtr();
 }
+
+/*!
+ * \brief Return node by its index
+ * \param ind - node index
+ * \retval const SMDS_MeshNode* - the node
+ * 
+ * Index is wrapped if it is out of a valid range
+ */
+const SMDS_MeshNode* SMDS_PolygonalFaceOfNodes::GetNode(const int ind) const
+{
+  return myNodes[ WrappedIndex( ind )];
+}
+
index 567746259105ba4b57fc28f184b7864aa15d2029..c8884b3197093327242060937c989ea973e7fea1 100644 (file)
@@ -50,6 +50,15 @@ class SMDS_PolygonalFaceOfNodes:public SMDS_MeshFace
 
   virtual void Print (std::ostream & OS) const;
 
+  /*!
+   * \brief Return node by its index
+    * \param ind - node index
+    * \retval const SMDS_MeshNode* - the node
+   * 
+   * Index is wrapped if it is out of a valid range
+   */
+  virtual const SMDS_MeshNode* GetNode(const int ind) const;
+
  protected:
   virtual SMDS_ElemIteratorPtr elementsIterator (SMDSAbs_ElementType type) const;
 
index 1c7a44115ff4bbc18ea1c45d71968fc16b0f73ed..ca12343ffa4ba96ef6bb4dc33d15c229fc37812e 100644 (file)
@@ -1,11 +1,34 @@
+//  SMESH SMDS : implementaion of Salome mesh data structure
+//
+//  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+//  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
+// 
+//  This library is free software; you can redistribute it and/or 
+//  modify it under the terms of the GNU Lesser General Public 
+//  License as published by the Free Software Foundation; either 
+//  version 2.1 of the License. 
+// 
+//  This library is distributed in the hope that it will be useful, 
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of 
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
+//  Lesser General Public License for more details. 
+// 
+//  You should have received a copy of the GNU Lesser General Public 
+//  License along with this library; if not, write to the Free Software 
+//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA 
+// 
+//  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
+//
+//
+//
 // File:      SMDS_QuadraticEdge.cxx
 // Created:   16.01.06 16:25:42
 // Author:    Sergey KUUL
-// Copyright: Open CASCADE 2006
 
 
 #include "SMDS_QuadraticEdge.hxx"
 
+#include "SMDS_SetIterator.hxx"
 #include "SMDS_IteratorOfElements.hxx"
 #include "SMDS_MeshNode.hxx"
 
@@ -47,74 +70,118 @@ int SMDS_QuadraticEdge::NbNodes() const
   return 3;
 }
 
-
 //=======================================================================
-//function : Iterator
+//function : ChangeNodes
 //purpose  : 
 //=======================================================================
 
-class SMDS_QuadraticEdge_MyNodeIterator:public SMDS_ElemIterator
+bool SMDS_QuadraticEdge::ChangeNodes(const SMDS_MeshNode * node1,
+                                     const SMDS_MeshNode * node2,
+                                     const SMDS_MeshNode * node12)
 {
-  const SMDS_MeshNode *const* myNodes;
-  int myIndex;
- public:
-  SMDS_QuadraticEdge_MyNodeIterator(const SMDS_MeshNode * const* nodes):
-    myNodes(nodes),myIndex(0) {}
+  myNodes[0]=node1;
+  myNodes[1]=node2;
+  myNodes[2]=node12;
+  return true;
+}
 
-  bool more()
-  {
-    return myIndex<3;
-  }
+//=======================================================================
+//function : IsMediumNode
+//purpose  : 
+//=======================================================================
 
-  const SMDS_MeshElement* next()
-  {
-    myIndex++;
-    return myNodes[myIndex-1];
-  }
-};
+bool SMDS_QuadraticEdge::IsMediumNode(const SMDS_MeshNode * node) const
+{
+  return (myNodes[2]==node);
+}
 
-SMDS_ElemIteratorPtr SMDS_QuadraticEdge::
-       elementsIterator(SMDSAbs_ElementType type) const
+namespace
 {
-  switch(type)
+  //=======================================================================
+  //class : _MyInterlacedNodeIterator
+  //purpose  : 
+  //=======================================================================
+
+  class _MyInterlacedNodeIterator: public SMDS_NodeArrayIterator
   {
-  case SMDSAbs_Edge:
-    return SMDS_MeshElement::elementsIterator(SMDSAbs_Edge); 
-  case SMDSAbs_Node:
-    return SMDS_ElemIteratorPtr(new SMDS_QuadraticEdge_MyNodeIterator(myNodes));
-  default:
-    return SMDS_ElemIteratorPtr
-      (new SMDS_IteratorOfElements
-       (this,type, SMDS_ElemIteratorPtr(new SMDS_QuadraticEdge_MyNodeIterator(myNodes))));
-  }
+    const SMDS_MeshNode * myNodes[3];
+  public:
+    _MyInterlacedNodeIterator(const SMDS_MeshNode * const * nodes):
+      SMDS_NodeArrayIterator( myNodes, & myNodes[3] )
+    {
+      myNodes[0] = nodes[0];
+      myNodes[1] = nodes[2];
+      myNodes[2] = nodes[1];
+    }
+  };
+
+  //=======================================================================
+  //class : _MyInterlacedNodeElemIterator
+  //purpose  : 
+  //=======================================================================
+
+  class _MyInterlacedNodeElemIterator : public SMDS_ElemIterator
+  {
+    SMDS_NodeIteratorPtr myItr;
+  public:
+    _MyInterlacedNodeElemIterator(SMDS_NodeIteratorPtr interlacedNodeItr):
+      myItr( interlacedNodeItr ) {}
+    bool more()                    { return myItr->more(); }
+    const SMDS_MeshElement* next() { return myItr->next(); }
+  };
+
+  //=======================================================================
+  //class : _MyNodeIterator
+  //purpose  : 
+  //=======================================================================
+
+  class _MyNodeIterator:public SMDS_NodeArrayElemIterator
+  {
+  public:
+    _MyNodeIterator(const SMDS_MeshNode * const * nodes):
+      SMDS_NodeArrayElemIterator( nodes, & nodes[3] ) {}
+  };
 }
 
-
 //=======================================================================
-//function : ChangeNodes
+//function : interlacedNodesIterator
 //purpose  : 
 //=======================================================================
 
-bool SMDS_QuadraticEdge::ChangeNodes(const SMDS_MeshNode * node1,
-                                     const SMDS_MeshNode * node2,
-                                     const SMDS_MeshNode * node12)
+SMDS_NodeIteratorPtr SMDS_QuadraticEdge::interlacedNodesIterator() const
 {
-  myNodes[0]=node1;
-  myNodes[1]=node2;
-  myNodes[2]=node12;
-  return true;
+  return SMDS_NodeIteratorPtr (new _MyInterlacedNodeIterator (myNodes));
 }
 
 
 //=======================================================================
-//function : IsMediumNode
+//function : interlacedNodesElemIterator
 //purpose  : 
 //=======================================================================
 
-bool SMDS_QuadraticEdge::IsMediumNode(const SMDS_MeshNode * node) const
+SMDS_ElemIteratorPtr SMDS_QuadraticEdge::interlacedNodesElemIterator() const
 {
-  return (myNodes[2]==node);
+  return SMDS_ElemIteratorPtr
+    (new _MyInterlacedNodeElemIterator ( interlacedNodesIterator() ));
 }
 
+//=======================================================================
+//function : elementsIterator
+//purpose  : 
+//=======================================================================
 
+SMDS_ElemIteratorPtr SMDS_QuadraticEdge::elementsIterator(SMDSAbs_ElementType type) const
+{
+  switch(type)
+  {
+  case SMDSAbs_Edge:
+    return SMDS_MeshElement::elementsIterator(SMDSAbs_Edge); 
+  case SMDSAbs_Node:
+    return SMDS_ElemIteratorPtr(new _MyNodeIterator(myNodes));
+  default:
+    return SMDS_ElemIteratorPtr
+      (new SMDS_IteratorOfElements
+       (this,type, SMDS_ElemIteratorPtr(new _MyNodeIterator(myNodes))));
+  }
+}
 
index 0319c1cc43e870ec8202b361ca0c59a01739e215..dacdef01cfa3d774c19916b71e54c255ffd0e9e3 100644 (file)
@@ -34,25 +34,29 @@ class SMDS_WNT_EXPORT SMDS_QuadraticEdge: public SMDS_MeshEdge
 {
 
 public:
-    SMDS_QuadraticEdge(const SMDS_MeshNode * node1,
-                       const SMDS_MeshNode * node2,
-                       const SMDS_MeshNode * node12);
-
-    bool ChangeNodes(const SMDS_MeshNode * node1,
+  SMDS_QuadraticEdge(const SMDS_MeshNode * node1,
                      const SMDS_MeshNode * node2,
                      const SMDS_MeshNode * node12);
 
-    void Print(std::ostream & OS) const;
-    
-    int NbNodes() const;
+  bool ChangeNodes(const SMDS_MeshNode * node1,
+                   const SMDS_MeshNode * node2,
+                   const SMDS_MeshNode * node12);
+
+  void Print(std::ostream & OS) const;
+
+  int NbNodes() const;
+
+  virtual bool IsQuadratic() const { return true; }
+
+  virtual bool IsMediumNode(const SMDS_MeshNode* node) const;
+
+  SMDS_NodeIteratorPtr interlacedNodesIterator() const;
 
-    virtual bool IsQuadratic() const { return true; }
-    
-    virtual bool IsMediumNode(const SMDS_MeshNode* node) const;
+  SMDS_ElemIteratorPtr interlacedNodesElemIterator() const;
 
 protected:
   SMDS_ElemIteratorPtr
-    elementsIterator(SMDSAbs_ElementType type) const;
+  elementsIterator(SMDSAbs_ElementType type) const;
 
 };
 #endif
index 6d8e55156b042a777b9fd224fc021cc48f483b16..ecd69cc70369b0b1014517865673f46c207ac1ef 100644 (file)
@@ -1,10 +1,33 @@
+//  SMESH SMDS : implementaion of Salome mesh data structure
+//
+//  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+//  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
+// 
+//  This library is free software; you can redistribute it and/or 
+//  modify it under the terms of the GNU Lesser General Public 
+//  License as published by the Free Software Foundation; either 
+//  version 2.1 of the License. 
+// 
+//  This library is distributed in the hope that it will be useful, 
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of 
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
+//  Lesser General Public License for more details. 
+// 
+//  You should have received a copy of the GNU Lesser General Public 
+//  License along with this library; if not, write to the Free Software 
+//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA 
+// 
+//  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
+//
+//
+//
 // File:      SMDS_QuadraticFaceOfNodes.cxx
 // Created:   16.01.06 17:12:58
 // Author:    Sergey KUUL
-// Copyright: Open CASCADE 2006
 
 #include "SMDS_QuadraticFaceOfNodes.hxx"
 
+#include "SMDS_SetIterator.hxx"
 #include "SMDS_IteratorOfElements.hxx"
 #include "SMDS_MeshNode.hxx"
 
@@ -25,12 +48,13 @@ SMDS_QuadraticFaceOfNodes::SMDS_QuadraticFaceOfNodes(const SMDS_MeshNode * n1,
                                                      const SMDS_MeshNode * n23,
                                                      const SMDS_MeshNode * n31)
 {
-  myNodes.push_back(n1);
-  myNodes.push_back(n2);
-  myNodes.push_back(n3);
-  myNodes.push_back(n12);
-  myNodes.push_back(n23);
-  myNodes.push_back(n31);
+  myNodes.resize( 6 );
+  myNodes[ 0 ] = n1;
+  myNodes[ 1 ] = n2;
+  myNodes[ 2 ] = n3;
+  myNodes[ 3 ] = n12;
+  myNodes[ 4 ] = n23;
+  myNodes[ 5 ] = n31;
 }
 
 
@@ -48,14 +72,15 @@ SMDS_QuadraticFaceOfNodes::SMDS_QuadraticFaceOfNodes(const SMDS_MeshNode * n1,
                                                      const SMDS_MeshNode * n34,
                                                      const SMDS_MeshNode * n41)
 {
-  myNodes.push_back(n1);
-  myNodes.push_back(n2);
-  myNodes.push_back(n3);
-  myNodes.push_back(n4);
-  myNodes.push_back(n12);
-  myNodes.push_back(n23);
-  myNodes.push_back(n34);
-  myNodes.push_back(n41);
+  myNodes.resize( 8 );
+  myNodes[ 0 ] = n1;
+  myNodes[ 1 ] = n2;
+  myNodes[ 2 ] = n3;
+  myNodes[ 3 ] = n4;
+  myNodes[ 4 ] = n12;
+  myNodes[ 5 ] = n23;
+  myNodes[ 6 ] = n34;
+  myNodes[ 7 ] = n41;
 }
 
 
@@ -123,7 +148,6 @@ int SMDS_QuadraticFaceOfNodes::NbFaces() const
   return 1;
 }
 
-
 //=======================================================================
 //function : Print
 //purpose  : 
@@ -137,79 +161,91 @@ void SMDS_QuadraticFaceOfNodes::Print(ostream & OS) const
   OS << myNodes[i] << ") " << endl;
 }
 
+namespace {
 
-//=======================================================================
-//function : interlacedNodesIterator
-//purpose  : 
-//=======================================================================
-class SMDS_QuadraticFaceOfNodes_MyInterlacedNodeIterator:public SMDS_NodeIterator
-{
-  const std::vector<const SMDS_MeshNode *> mySet;
-  int index;
- public:
-  SMDS_QuadraticFaceOfNodes_MyInterlacedNodeIterator(const std::vector<const SMDS_MeshNode *> s):
-    mySet(s),index(0) {}
-
-  bool more()
-  {
-    return index < mySet.size();
-  }
+  //=======================================================================
+  //class : _MyInterlacedNodeIterator
+  //purpose  : 
+  //=======================================================================
 
-  const SMDS_MeshNode* next()
+  class _MyInterlacedNodeIterator:public SMDS_NodeIterator
   {
-    index++;
-    int num=0;
-    if(mySet.size()==6) {
-      if(index==2) num=3;
-      else if(index==3) num=1;
-      else if(index==4) num=4;
-      else if(index==5) num=2;
-      else if(index==6) num=5;
+    const vector<const SMDS_MeshNode *>& mySet;
+    int myIndex;
+    const int * myInterlace;
+  public:
+    _MyInterlacedNodeIterator(const vector<const SMDS_MeshNode *>& s,
+                              const int * interlace):
+      mySet(s),myIndex(0),myInterlace(interlace) {}
+
+    bool more()
+    {
+      return myIndex < mySet.size();
     }
-    else {
-      if(index==2) num=4;
-      else if(index==3) num=1;
-      else if(index==4) num=5;
-      else if(index==5) num=2;
-      else if(index==6) num=6;
-      else if(index==7) num=3;
-      else if(index==8) num=7;
+
+    const SMDS_MeshNode* next()
+    {
+      return mySet[ myInterlace[ myIndex++ ]];
     }
-    return mySet[num];
-  }
-};
+  };
+
+  //=======================================================================
+  //class : _MyInterlacedNodeElemIterator
+  //purpose  : 
+  //=======================================================================
+
+  class _MyInterlacedNodeElemIterator : public SMDS_ElemIterator
+  {
+    SMDS_NodeIteratorPtr myItr;
+  public:
+    _MyInterlacedNodeElemIterator(SMDS_NodeIteratorPtr interlacedNodeItr):
+      myItr( interlacedNodeItr ) {}
+    bool more()                    { return myItr->more(); }
+    const SMDS_MeshElement* next() { return myItr->next(); }
+  };
+
+  //=======================================================================
+  //class : _MyNodeIterator
+  //purpose  : 
+  //=======================================================================
+
+  class _MyNodeIterator : public SMDS_NodeVectorElemIterator
+  {
+  public:
+    _MyNodeIterator(const vector<const SMDS_MeshNode *>& s):
+      SMDS_NodeVectorElemIterator( s.begin(), s.end() ) {}
+  };
+  
+}
+
+//=======================================================================
+//function : interlacedNodesIterator
+//purpose  : 
+//=======================================================================
 
 SMDS_NodeIteratorPtr SMDS_QuadraticFaceOfNodes::interlacedNodesIterator() const
 {
+  static int triaInterlace [] = { 0, 3, 1, 4, 2, 5 };
+  static int quadInterlace [] = { 0, 4, 1, 5, 2, 6, 3, 7 };
   return SMDS_NodeIteratorPtr
-    (new SMDS_QuadraticFaceOfNodes_MyInterlacedNodeIterator(myNodes));
+    (new _MyInterlacedNodeIterator (myNodes, myNodes.size()==6 ? triaInterlace : quadInterlace));
 }
 
+//=======================================================================
+//function : interlacedNodesElemIterator
+//purpose  : 
+//=======================================================================
 
+SMDS_ElemIteratorPtr SMDS_QuadraticFaceOfNodes::interlacedNodesElemIterator() const
+{
+  return SMDS_ElemIteratorPtr
+    (new _MyInterlacedNodeElemIterator ( interlacedNodesIterator() ));
+}
 
 //=======================================================================
 //function : elementsIterator
 //purpose  : 
 //=======================================================================
-class SMDS_QuadraticFaceOfNodes_MyIterator:public SMDS_ElemIterator
-{
-  const std::vector<const SMDS_MeshNode *> mySet;
-  int index;
- public:
-  SMDS_QuadraticFaceOfNodes_MyIterator(const std::vector<const SMDS_MeshNode *> s):
-    mySet(s),index(0) {}
-
-  bool more()
-  {
-    return index < mySet.size();
-  }
-
-  const SMDS_MeshElement* next()
-  {
-    index++;
-    return mySet[index-1];
-  }
-};
 
 SMDS_ElemIteratorPtr SMDS_QuadraticFaceOfNodes::elementsIterator
                                          (SMDSAbs_ElementType type) const
@@ -219,15 +255,27 @@ SMDS_ElemIteratorPtr SMDS_QuadraticFaceOfNodes::elementsIterator
   case SMDSAbs_Face:
     return SMDS_MeshElement::elementsIterator(SMDSAbs_Face);
   case SMDSAbs_Node:
-    return SMDS_ElemIteratorPtr(new SMDS_QuadraticFaceOfNodes_MyIterator(myNodes));
+    return SMDS_ElemIteratorPtr(new _MyNodeIterator(myNodes));
   case SMDSAbs_Edge:
     MESSAGE("Error : edge iterator for SMDS_QuadraticFaceOfNodes not implemented");
     break;
   default:
     return SMDS_ElemIteratorPtr
       (new SMDS_IteratorOfElements
-       (this,type,SMDS_ElemIteratorPtr
-        (new SMDS_QuadraticFaceOfNodes_MyIterator(myNodes))));
+       (this,type,SMDS_ElemIteratorPtr (new _MyNodeIterator(myNodes))));
   }
   return SMDS_ElemIteratorPtr();
 }
+
+/*!
+ * \brief Return node by its index
+ * \param ind - node index
+ * \retval const SMDS_MeshNode* - the node
+ * 
+ * Index is wrapped if it is out of a valid range
+ */
+const SMDS_MeshNode* SMDS_QuadraticFaceOfNodes::GetNode(const int ind) const
+{
+  return myNodes[ WrappedIndex( ind )];
+}
+
index 8ce72f3fbd1cb43bef4266af7df08c3f9d49ccf6..77cda784af0e96d7b5365245c397646c004a761d 100644 (file)
@@ -29,9 +29,6 @@
 
 #include "SMDS_MeshFace.hxx"
 
-typedef SMDS_Iterator<const SMDS_MeshNode *> SMDS_NodeIterator;
-typedef boost::shared_ptr<SMDS_Iterator<const SMDS_MeshNode *> > SMDS_NodeIteratorPtr;
-
 class SMDS_WNT_EXPORT SMDS_QuadraticFaceOfNodes:public SMDS_MeshFace
 {
 public:
@@ -66,6 +63,17 @@ public:
 
   SMDS_NodeIteratorPtr interlacedNodesIterator() const;
 
+  SMDS_ElemIteratorPtr interlacedNodesElemIterator() const;
+
+  /*!
+   * \brief Return node by its index
+    * \param ind - node index
+    * \retval const SMDS_MeshNode* - the node
+   * 
+   * Index is wrapped if it is out of a valid range
+   */
+  virtual const SMDS_MeshNode* GetNode(const int ind) const;
+
 protected:
   virtual SMDS_ElemIteratorPtr elementsIterator (SMDSAbs_ElementType type) const;
 
index 1da0c13bf3c7b9b8c595879c04f9e6dd8dc3e969..b7f7e7821169781ea86e3828e41d0c07a3d52fc9 100644 (file)
@@ -1,12 +1,35 @@
+//  SMESH SMDS : implementaion of Salome mesh data structure
+//
+//  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+//  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
+// 
+//  This library is free software; you can redistribute it and/or 
+//  modify it under the terms of the GNU Lesser General Public 
+//  License as published by the Free Software Foundation; either 
+//  version 2.1 of the License. 
+// 
+//  This library is distributed in the hope that it will be useful, 
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of 
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
+//  Lesser General Public License for more details. 
+// 
+//  You should have received a copy of the GNU Lesser General Public 
+//  License along with this library; if not, write to the Free Software 
+//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA 
+// 
+//  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
+//
+//
+//
 // File:      SMDS_QuadraticVolumeOfNodes.cxx
 // Created:   17.01.06 09:46:11
 // Author:    Sergey KUUL
-// Copyright: Open CASCADE 2006
 
 #include "SMDS_QuadraticVolumeOfNodes.hxx"
 
 #include "SMDS_IteratorOfElements.hxx"
 #include "SMDS_MeshNode.hxx"
+#include "SMDS_SetIterator.hxx"
 
 #include "utilities.h"
 
@@ -30,16 +53,17 @@ SMDS_QuadraticVolumeOfNodes::SMDS_QuadraticVolumeOfNodes
                                                 const SMDS_MeshNode * n24,
                                                 const SMDS_MeshNode * n34)
 {
-  myNodes.push_back(n1);
-  myNodes.push_back(n2);
-  myNodes.push_back(n3);
-  myNodes.push_back(n4);
-  myNodes.push_back(n12);
-  myNodes.push_back(n23);
-  myNodes.push_back(n31);
-  myNodes.push_back(n14);
-  myNodes.push_back(n24);
-  myNodes.push_back(n34);
+  myNodes.resize( 10 );
+  myNodes[ 0 ] = n1;
+  myNodes[ 1 ] = n2;
+  myNodes[ 2 ] = n3;
+  myNodes[ 3 ] = n4;
+  myNodes[ 4 ] = n12;
+  myNodes[ 5 ] = n23;
+  myNodes[ 6 ] = n31;
+  myNodes[ 7 ] = n14;
+  myNodes[ 8 ] = n24;
+  myNodes[ 9 ] = n34;
 }
 
 
@@ -63,19 +87,20 @@ SMDS_QuadraticVolumeOfNodes::SMDS_QuadraticVolumeOfNodes
                                                 const SMDS_MeshNode * n35,
                                                 const SMDS_MeshNode * n45)
 {
-  myNodes.push_back(n1);
-  myNodes.push_back(n2);
-  myNodes.push_back(n3);
-  myNodes.push_back(n4);
-  myNodes.push_back(n5);
-  myNodes.push_back(n12);
-  myNodes.push_back(n23);
-  myNodes.push_back(n34);
-  myNodes.push_back(n41);
-  myNodes.push_back(n15);
-  myNodes.push_back(n25);
-  myNodes.push_back(n35);
-  myNodes.push_back(n45);
+  myNodes.resize( 13 );
+  myNodes[ 0 ] = n1;
+  myNodes[ 1 ] = n2;
+  myNodes[ 2 ] = n3;
+  myNodes[ 3 ] = n4;
+  myNodes[ 4 ] = n5;
+  myNodes[ 5 ] = n12;
+  myNodes[ 6 ] = n23;
+  myNodes[ 7 ] = n34;
+  myNodes[ 8 ] = n41;
+  myNodes[ 9 ] = n15;
+  myNodes[ 10 ] = n25;
+  myNodes[ 11 ] = n35;
+  myNodes[ 12 ] = n45;
 }
 
 
@@ -101,21 +126,22 @@ SMDS_QuadraticVolumeOfNodes::SMDS_QuadraticVolumeOfNodes
                                                 const SMDS_MeshNode * n25,
                                                 const SMDS_MeshNode * n36)
 {
-  myNodes.push_back(n1);
-  myNodes.push_back(n2);
-  myNodes.push_back(n3);
-  myNodes.push_back(n4);
-  myNodes.push_back(n5);
-  myNodes.push_back(n6);
-  myNodes.push_back(n12);
-  myNodes.push_back(n23);
-  myNodes.push_back(n31);
-  myNodes.push_back(n45);
-  myNodes.push_back(n56);
-  myNodes.push_back(n64);
-  myNodes.push_back(n14);
-  myNodes.push_back(n25);
-  myNodes.push_back(n36);
+  myNodes.resize( 15 );
+  myNodes[ 0 ] = n1;
+  myNodes[ 1 ] = n2;
+  myNodes[ 2 ] = n3;
+  myNodes[ 3 ] = n4;
+  myNodes[ 4 ] = n5;
+  myNodes[ 5 ] = n6;
+  myNodes[ 6 ] = n12;
+  myNodes[ 7 ] = n23;
+  myNodes[ 8 ] = n31;
+  myNodes[ 9 ] = n45;
+  myNodes[ 10 ] = n56;
+  myNodes[ 11 ] = n64;
+  myNodes[ 12 ] = n14;
+  myNodes[ 13 ] = n25;
+  myNodes[ 14 ] = n36;
 }
 
 
@@ -146,26 +172,27 @@ SMDS_QuadraticVolumeOfNodes::SMDS_QuadraticVolumeOfNodes
                                                 const SMDS_MeshNode * n37,
                                                 const SMDS_MeshNode * n48)
 {
-  myNodes.push_back(n1);
-  myNodes.push_back(n2);
-  myNodes.push_back(n3);
-  myNodes.push_back(n4);
-  myNodes.push_back(n5);
-  myNodes.push_back(n6);
-  myNodes.push_back(n7);
-  myNodes.push_back(n8);
-  myNodes.push_back(n12);
-  myNodes.push_back(n23);
-  myNodes.push_back(n34);
-  myNodes.push_back(n41);
-  myNodes.push_back(n56);
-  myNodes.push_back(n67);
-  myNodes.push_back(n78);
-  myNodes.push_back(n85);
-  myNodes.push_back(n15);
-  myNodes.push_back(n26);
-  myNodes.push_back(n37);
-  myNodes.push_back(n48);
+  myNodes.resize( 20 );
+  myNodes[ 0 ] = n1;
+  myNodes[ 1 ] = n2;
+  myNodes[ 2 ] = n3;
+  myNodes[ 3 ] = n4;
+  myNodes[ 4 ] = n5;
+  myNodes[ 5 ] = n6;
+  myNodes[ 6 ] = n7;
+  myNodes[ 7 ] = n8;
+  myNodes[ 8 ] = n12;
+  myNodes[ 9 ] = n23;
+  myNodes[ 10 ] = n34;
+  myNodes[ 11 ] = n41;
+  myNodes[ 12 ] = n56;
+  myNodes[ 13 ] = n67;
+  myNodes[ 14 ] = n78;
+  myNodes[ 15 ] = n85;
+  myNodes[ 16 ] = n15;
+  myNodes[ 17 ] = n26;
+  myNodes[ 18 ] = n37;
+  myNodes[ 19 ] = n48;
 }
 
 
@@ -176,29 +203,15 @@ SMDS_QuadraticVolumeOfNodes::SMDS_QuadraticVolumeOfNodes
 
 bool SMDS_QuadraticVolumeOfNodes::IsMediumNode(const SMDS_MeshNode* node) const
 {
-  if(NbNodes()==10) {
-    int i=4;
-    for(; i<10; i++) {
-      if(myNodes[i]==node) return true;
-    }
-  }
-  else if(NbNodes()==13) {
-    int i=5;
-    for(; i<13; i++) {
-      if(myNodes[i]==node) return true;
-    }
+  int nbCorners = 0;
+  switch (myNodes.size()) {
+  case 10: nbCorners = 4; break;
+  case 13: nbCorners = 5; break;
+  case 15: nbCorners = 6; break;
+  default: nbCorners = 8;
   }
-  else if(NbNodes()==15) {
-    int i=6;
-    for(; i<15; i++) {
-      if(myNodes[i]==node) return true;
-    }
-  }
-  else {
-    int i=8;
-    for(; i<20; i++) {
-      if(myNodes[i]==node) return true;
-    }
+  for ( int i = nbCorners; i<myNodes.size(); i++) {
+    if(myNodes[i]==node) return true;
   }
   return false;
 }
@@ -240,11 +253,11 @@ int SMDS_QuadraticVolumeOfNodes::NbNodes() const
 //=======================================================================
 int SMDS_QuadraticVolumeOfNodes::NbEdges() const
 {
-  if(NbNodes()==10)
+  if(myNodes.size()==10)
     return 6;
-  else if(NbNodes()==13)
+  else if(myNodes.size()==13)
     return 8;
-  else if(NbNodes()==15)
+  else if(myNodes.size()==15)
     return 9;
   else
     return 12;
@@ -257,9 +270,9 @@ int SMDS_QuadraticVolumeOfNodes::NbEdges() const
 //=======================================================================
 int SMDS_QuadraticVolumeOfNodes::NbFaces() const
 {
-  if(NbNodes()==10)
+  if(myNodes.size()==10)
     return 4;
-  else if(NbNodes()==20)
+  else if(myNodes.size()==20)
     return 6;
   else
     return 5;
@@ -280,29 +293,22 @@ void SMDS_QuadraticVolumeOfNodes::Print(ostream & OS) const
 
 
 //=======================================================================
-//function : elementsIterator
+//private class : SMDS_QuadraticVolumeOfNodes_MyIterator
 //purpose  : 
 //=======================================================================
-class SMDS_QuadraticVolumeOfNodes_MyIterator:public SMDS_ElemIterator
-{
-  const std::vector<const SMDS_MeshNode *> mySet;
-  int index;
- public:
-  SMDS_QuadraticVolumeOfNodes_MyIterator(const std::vector<const SMDS_MeshNode *> s):
-    mySet(s),index(0) {}
-
-  bool more()
-  {
-    return index < mySet.size();
-  }
 
-  const SMDS_MeshElement* next()
-  {
-    index++;
-    return mySet[index-1];
-  }
+class SMDS_QuadraticVolumeOfNodes_MyIterator : public SMDS_NodeVectorElemIterator
+{
+public:
+  SMDS_QuadraticVolumeOfNodes_MyIterator(const vector<const SMDS_MeshNode *>& s):
+    SMDS_NodeVectorElemIterator( s.begin(), s.end() ) {}
 };
 
+//=======================================================================
+//function : elementsIterator
+//purpose  : 
+//=======================================================================
+
 SMDS_ElemIteratorPtr SMDS_QuadraticVolumeOfNodes::elementsIterator
                                          (SMDSAbs_ElementType type) const
 {
@@ -327,3 +333,15 @@ SMDS_ElemIteratorPtr SMDS_QuadraticVolumeOfNodes::elementsIterator
   return SMDS_ElemIteratorPtr();
 }
 
+/*!
+ * \brief Return node by its index
+ * \param ind - node index
+ * \retval const SMDS_MeshNode* - the node
+ * 
+ * Index is wrapped if it is out of a valid range
+ */
+const SMDS_MeshNode* SMDS_QuadraticVolumeOfNodes::GetNode(const int ind) const
+{
+  return myNodes[ WrappedIndex( ind )];
+}
+
index 7ab5c796b37049c3a0e6dd538608aeda23fc6faf..6fa60b0b6d7404bd56e1eed15fdc4cee20e0c8d4 100644 (file)
@@ -111,6 +111,15 @@ public:
 
   virtual void Print (std::ostream & OS) const;
 
+  /*!
+   * \brief Return node by its index
+    * \param ind - node index
+    * \retval const SMDS_MeshNode* - the node
+   * 
+   * Index is wrapped if it is out of a valid range
+   */
+  virtual const SMDS_MeshNode* GetNode(const int ind) const;
+
  protected:
   virtual SMDS_ElemIteratorPtr elementsIterator (SMDSAbs_ElementType type) const;
 
diff --git a/src/SMDS/SMDS_SetIterator.hxx b/src/SMDS/SMDS_SetIterator.hxx
new file mode 100644 (file)
index 0000000..8c08a73
--- /dev/null
@@ -0,0 +1,101 @@
+//  SMESH SMDS : implementaion of Salome mesh data structure
+//
+//  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+//  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
+// 
+//  This library is free software; you can redistribute it and/or 
+//  modify it under the terms of the GNU Lesser General Public 
+//  License as published by the Free Software Foundation; either 
+//  version 2.1 of the License. 
+// 
+//  This library is distributed in the hope that it will be useful, 
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of 
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
+//  Lesser General Public License for more details. 
+// 
+//  You should have received a copy of the GNU Lesser General Public 
+//  License along with this library; if not, write to the Free Software 
+//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA 
+// 
+//  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
+//
+//
+//
+// File      : SMDS_SetIterator.hxx
+// Created   : Mon Feb 27 16:57:43 2006
+// Author    : Edward AGAPOV (eap)
+
+
+#ifndef SMDS_SetIterator_HeaderFile
+#define SMDS_SetIterator_HeaderFile
+
+#include "SMDS_Iterator.hxx"
+
+///////////////////////////////////////////////////////////////////////////////
+/// specific SMDS_Iterator iterating over abstract set of values like STL containers
+///
+/// BE CAREFUL: iterator pointed value is static_cast'ed to VALUE
+///
+///////////////////////////////////////////////////////////////////////////////
+
+template<typename VALUE, typename VALUE_SET_ITERATOR>
+class SMDS_SetIterator : public SMDS_Iterator<VALUE>
+{
+protected:
+  VALUE_SET_ITERATOR _beg, _end;
+public:
+  SMDS_SetIterator(const VALUE_SET_ITERATOR & begin,
+                   const VALUE_SET_ITERATOR & end)
+  { init ( begin, end ); }
+
+  /// Initialization
+  virtual void init(const VALUE_SET_ITERATOR & begin,
+                    const VALUE_SET_ITERATOR & end)
+  { _beg = begin; _end = end; }
+
+  /// Return true if and only if there are other object in this iterator
+  virtual bool more() { return _beg != _end; }
+
+  /// Return the current object and step to the next one
+  virtual VALUE next() { return static_cast<VALUE>( *_beg++ ); }
+
+};
+
+// useful specifications
+
+#include <vector>
+
+class SMDS_MeshElement;
+class SMDS_MeshNode;
+
+typedef const SMDS_MeshElement* SMDS_pElement;
+typedef const SMDS_MeshNode*    SMDS_pNode;
+
+// element iterators
+
+typedef SMDS_SetIterator< SMDS_pElement, std::vector< SMDS_pElement >::const_iterator>
+SMDS_ElementVectorIterator;
+
+
+typedef SMDS_SetIterator< SMDS_pElement, SMDS_pElement const *>
+SMDS_ElementArrayIterator;
+
+
+typedef SMDS_SetIterator< SMDS_pElement, std::vector< SMDS_pNode >::const_iterator>
+SMDS_NodeVectorElemIterator;
+
+
+typedef SMDS_SetIterator< SMDS_pElement, SMDS_pNode const * >
+SMDS_NodeArrayElemIterator;
+
+// node iterators
+
+typedef SMDS_SetIterator< SMDS_pNode, std::vector< SMDS_pNode >::const_iterator >
+SMDS_NodeVectorIterator;
+
+
+typedef SMDS_SetIterator< SMDS_pNode, SMDS_pNode const * >
+SMDS_NodeArrayIterator;
+
+
+#endif
index cd893f484a87e45a70059e678810ce358bb25271..941f538c3e4a4eb30a712612c3e12f9fd04778e4 100644 (file)
@@ -25,6 +25,7 @@
 
 #include "SMDS_VolumeOfNodes.hxx"
 #include "SMDS_MeshNode.hxx"
+#include "SMDS_SetIterator.hxx"
 #include "utilities.h"
 
 using namespace std;
@@ -170,29 +171,14 @@ int SMDS_VolumeOfNodes::NbEdges() const
         return 0;
 }
 
-class SMDS_VolumeOfNodes_MyIterator:public SMDS_ElemIterator
+class SMDS_VolumeOfNodes_MyIterator:public SMDS_NodeArrayElemIterator
 {
-  const SMDS_MeshNode* const* mySet;
-  int myLength;
-  int index;
  public:
   SMDS_VolumeOfNodes_MyIterator(const SMDS_MeshNode* const* s, int l):
-    mySet(s),myLength(l),index(0) {}
-
-  bool more()
-  {
-    return index<myLength;
-  }
-
-  const SMDS_MeshElement* next()
-  {
-    index++;
-    return mySet[index-1];
-  }
+    SMDS_NodeArrayElemIterator( s, & s[ l ]) {}
 };
 
-SMDS_ElemIteratorPtr SMDS_VolumeOfNodes::
-       elementsIterator(SMDSAbs_ElementType type) const
+SMDS_ElemIteratorPtr SMDS_VolumeOfNodes::elementsIterator(SMDSAbs_ElementType type) const
 {
   switch(type)
   {
@@ -210,3 +196,15 @@ SMDSAbs_ElementType SMDS_VolumeOfNodes::GetType() const
 {
        return SMDSAbs_Volume;
 }
+
+/*!
+ * \brief Return node by its index
+ * \param ind - node index
+ * \retval const SMDS_MeshNode* - the node
+ * 
+ * Index is wrapped if it is out of a valid range
+ */
+const SMDS_MeshNode* SMDS_VolumeOfNodes::GetNode(const int ind) const
+{
+  return myNodes[ WrappedIndex( ind )];
+}
index bb553a03a003518bf96b42dd530591fc59f3ece9..7595174906a4879011ce5689762b4b939e9f4a0a 100644 (file)
@@ -70,6 +70,16 @@ class SMDS_VolumeOfNodes:public SMDS_MeshVolume
        int NbNodes() const;
        int NbEdges() const;
        SMDSAbs_ElementType GetType() const;    
+
+  /*!
+   * \brief Return node by its index
+    * \param ind - node index
+    * \retval const SMDS_MeshNode* - the node
+   * 
+   * Index is wrapped if it is out of a valid range
+   */
+  virtual const SMDS_MeshNode* GetNode(const int ind) const;
+
   protected:
        SMDS_ElemIteratorPtr
                elementsIterator(SMDSAbs_ElementType type) const;