Back to index

salome-smesh  6.5.0
SMDS_FaceOfEdges.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00004 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00005 //
00006 // This library is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 2.1 of the License.
00010 //
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 // Lesser General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU Lesser General Public
00017 // License along with this library; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00019 //
00020 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00021 //
00022 
00023 //  SMESH SMDS : implementaion of Salome mesh data structure
00024 //
00025 #ifdef _MSC_VER
00026 #pragma warning(disable:4786)
00027 #endif
00028 
00029 #include "SMDS_FaceOfEdges.hxx"
00030 #include "SMDS_IteratorOfElements.hxx"
00031 #include "SMDS_MeshNode.hxx"
00032 #include "utilities.h"
00033 
00034 using namespace std;
00035 
00036 //=======================================================================
00037 //function : NbEdges
00038 //purpose  : 
00039 //=======================================================================
00040 
00041 int SMDS_FaceOfEdges::NbEdges() const
00042 {
00043         return myNbEdges;
00044 }
00045 
00046 int SMDS_FaceOfEdges::NbFaces() const
00047 {
00048         return 1;
00049 }
00050 //=======================================================================
00051 //function : Print
00052 //purpose  : 
00053 //=======================================================================
00054 
00055 void SMDS_FaceOfEdges::Print(ostream & OS) const
00056 {
00057         OS << "face <" << GetID() << " > : ";
00058         int i;
00059         for (i = 0; i < NbEdges() - 1; i++) OS << myEdges[i] << ",";
00060         OS << myEdges[i] << ") " << endl;
00061 }
00062 
00063 SMDSAbs_ElementType SMDS_FaceOfEdges::GetType() const
00064 {
00065         return SMDSAbs_Face;
00066 }
00067 
00068 //=======================================================================
00069 //function : elementsIterator
00070 //purpose  : 
00071 //=======================================================================
00072 
00073 class SMDS_FaceOfEdges_MyIterator:public SMDS_ElemIterator
00074 {
00075   const SMDS_MeshEdge* const *mySet;
00076   int myLength;
00077   int index;
00078  public:
00079   SMDS_FaceOfEdges_MyIterator(const SMDS_MeshEdge* const *s, int l):
00080     mySet(s),myLength(l),index(0) {}
00081 
00082   bool more()
00083   {
00084     return index<myLength;
00085   }
00086 
00087   const SMDS_MeshElement* next()
00088   {
00089     index++;
00090     return mySet[index-1];
00091   }     
00092 };
00093 
00094 SMDS_ElemIteratorPtr SMDS_FaceOfEdges::elementsIterator
00095                          (SMDSAbs_ElementType type) const
00096 {
00097   switch(type)
00098   {
00099   case SMDSAbs_Face:
00100     return SMDS_MeshElement::elementsIterator(SMDSAbs_Face);
00101   case SMDSAbs_Edge:
00102     return SMDS_ElemIteratorPtr(new SMDS_FaceOfEdges_MyIterator(myEdges,myNbEdges));
00103   default:
00104     return SMDS_ElemIteratorPtr
00105       (new SMDS_IteratorOfElements
00106        (this,type, SMDS_ElemIteratorPtr
00107         (new SMDS_FaceOfEdges_MyIterator(myEdges,myNbEdges))));
00108   }
00109 }
00110 
00111 SMDS_FaceOfEdges::SMDS_FaceOfEdges(const SMDS_MeshEdge* edge1,
00112                                    const SMDS_MeshEdge* edge2,
00113                                    const SMDS_MeshEdge* edge3)
00114 {
00115   //MESSAGE("****************************************************** SMDS_FaceOfEdges");
00116         myNbEdges = 3;
00117         myEdges[0]=edge1;
00118         myEdges[1]=edge2;
00119         myEdges[2]=edge3;
00120         myEdges[3]=0;
00121 }
00122 
00123 SMDS_FaceOfEdges::SMDS_FaceOfEdges(const SMDS_MeshEdge* edge1,
00124                                    const SMDS_MeshEdge* edge2,
00125                                    const SMDS_MeshEdge* edge3,
00126                                    const SMDS_MeshEdge* edge4)
00127 {
00128   //MESSAGE("****************************************************** SMDS_FaceOfEdges");
00129         myNbEdges = 4;
00130         myEdges[0]=edge1;
00131         myEdges[1]=edge2;
00132         myEdges[2]=edge3;
00133         myEdges[3]=edge4;       
00134 }
00135 
00136 /*bool operator<(const SMDS_FaceOfEdges& f1, const SMDS_FaceOfEdges& f2)
00137 {
00138         set<SMDS_MeshNode> set1,set2;
00139         SMDS_ElemIteratorPtr it;
00140         const SMDS_MeshNode * n;
00141 
00142         it=f1.nodesIterator();
00143 
00144         while(it->more())
00145         {
00146                 n=static_cast<const SMDS_MeshNode *>(it->next());
00147                 set1.insert(*n);
00148         }
00149 
00150         delete it;
00151         it=f2.nodesIterator();
00152         
00153         while(it->more())
00154         {       
00155                 n=static_cast<const SMDS_MeshNode *>(it->next());
00156                 set2.insert(*n);
00157         }
00158 
00159         delete it;
00160         return set1<set2;       
00161 
00162 }*/
00163 
00164 
00165 int SMDS_FaceOfEdges::NbNodes() const
00166 {
00167   return myEdges[0]->NbNodes() + myEdges[1]->NbNodes() + myEdges[2]->NbNodes() +
00168     ( myNbEdges == 4 ? myEdges[3]->NbNodes() : 0 ) - myNbEdges;
00169 }
00170 
00176 const SMDS_MeshNode* SMDS_FaceOfEdges::GetNode(const int ind) const
00177 {
00178   int index = ind;
00179   for ( int i = 0; i < myNbEdges; ++i ) {
00180     if ( index >= myEdges[ i ]->NbNodes() )
00181       index -= myEdges[ i ]->NbNodes();
00182     else
00183       return myEdges[ i ]->GetNode( index );
00184   }
00185   return 0;
00186 }
00187 
00188 SMDSAbs_EntityType SMDS_FaceOfEdges::GetEntityType() const
00189 {
00190   return myNbEdges == 3 ? SMDSEntity_Triangle : SMDSEntity_Quadrangle;
00191 }