Back to index

salome-smesh  6.5.0
SMDS_FaceOfNodes.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_SetIterator.hxx"
00030 #include "SMDS_FaceOfNodes.hxx"
00031 #include "SMDS_IteratorOfElements.hxx"
00032 #include "SMDS_MeshNode.hxx"
00033 #include "SMDS_Mesh.hxx"
00034 
00035 #include "utilities.h"
00036 
00037 using namespace std;
00038 
00039 //=======================================================================
00040 //function : NbEdges
00041 //purpose  : 
00042 //=======================================================================
00043 
00044 int SMDS_FaceOfNodes::NbEdges() const
00045 {
00046         return NbNodes();
00047 }
00048 
00049 int SMDS_FaceOfNodes::NbFaces() const
00050 {
00051         return 1;
00052 }
00053 
00054 int SMDS_FaceOfNodes::NbNodes() const
00055 {
00056         return myNbNodes;
00057 }
00058 
00059 //=======================================================================
00060 //function : Print
00061 //purpose  : 
00062 //=======================================================================
00063 
00064 void SMDS_FaceOfNodes::Print(ostream & OS) const
00065 {
00066         OS << "face <" << GetID() << " > : ";
00067         int i;
00068         for (i = 0; i < NbNodes() - 1; i++) OS << myNodes[i] << ",";
00069         OS << myNodes[i] << ") " << endl;
00070 }
00071 
00072 //=======================================================================
00073 //function : elementsIterator
00074 //purpose  : 
00075 //=======================================================================
00076 
00077 class SMDS_FaceOfNodes_MyIterator:public SMDS_NodeArrayElemIterator
00078 {
00079  public:
00080   SMDS_FaceOfNodes_MyIterator(const SMDS_MeshNode* const *s, int l):
00081     SMDS_NodeArrayElemIterator( s, & s[ l ] ) {}
00082 };
00083 
00085 
00088 
00089 
00090 class _MyEdgeIterator : public SMDS_ElemIterator
00091 {
00092   vector< const SMDS_MeshElement* > myElems;
00093   int myIndex;
00094 public:
00095   _MyEdgeIterator(const SMDS_FaceOfNodes* face):myIndex(0) {
00096     myElems.reserve( face->NbNodes() );
00097     for ( int i = 0; i < face->NbNodes(); ++i ) {
00098       const SMDS_MeshElement* edge =
00099         SMDS_Mesh::FindEdge( face->GetNode( i ), face->GetNodeWrap( i + 1 ));
00100       if ( edge )
00101         myElems.push_back( edge );
00102     }
00103   }
00105   virtual bool more() { return myIndex < myElems.size(); }
00106 
00108   virtual const SMDS_MeshElement* next() { return myElems[ myIndex++ ]; }
00109 };
00110 
00111 SMDS_ElemIteratorPtr SMDS_FaceOfNodes::elementsIterator
00112                          (SMDSAbs_ElementType type) const
00113 {
00114   switch(type)
00115   {
00116   case SMDSAbs_Face:
00117     return SMDS_MeshElement::elementsIterator(SMDSAbs_Face);
00118   case SMDSAbs_Node:
00119     return SMDS_ElemIteratorPtr(new SMDS_FaceOfNodes_MyIterator(myNodes,myNbNodes));
00120   case SMDSAbs_Edge:
00121     return SMDS_ElemIteratorPtr(new _MyEdgeIterator( this ));
00122     break;
00123   default:
00124     return SMDS_ElemIteratorPtr
00125       (new SMDS_IteratorOfElements
00126        (this,type,SMDS_ElemIteratorPtr
00127         (new SMDS_FaceOfNodes_MyIterator(myNodes,myNbNodes))));
00128   }
00129   return SMDS_ElemIteratorPtr();
00130 }
00131 
00132 SMDS_FaceOfNodes::SMDS_FaceOfNodes(const SMDS_MeshNode* node1,
00133                                    const SMDS_MeshNode* node2,
00134                                    const SMDS_MeshNode* node3)
00135 {
00136   //MESSAGE("******************************************************* SMDS_FaceOfNodes");
00137         myNbNodes = 3;
00138         myNodes[0]=node1;
00139         myNodes[1]=node2;
00140         myNodes[2]=node3;
00141         myNodes[3]=0;
00142 }
00143 
00144 SMDS_FaceOfNodes::SMDS_FaceOfNodes(const SMDS_MeshNode* node1,
00145                                    const SMDS_MeshNode* node2,
00146                                    const SMDS_MeshNode* node3,
00147                                    const SMDS_MeshNode* node4)
00148 {
00149   //MESSAGE("******************************************************* SMDS_FaceOfNodes");
00150         myNbNodes = 4;
00151         myNodes[0]=node1;
00152         myNodes[1]=node2;
00153         myNodes[2]=node3;
00154         myNodes[3]=node4;       
00155 }
00156 bool SMDS_FaceOfNodes::ChangeNodes(const SMDS_MeshNode* nodes[],
00157                                    const int            nbNodes)
00158 {
00159   myNbNodes = nbNodes;
00160   myNodes[0]=nodes[0];
00161   myNodes[1]=nodes[1];
00162   myNodes[2]=nodes[2];
00163   if (nbNodes == 4)
00164     myNodes[3]=nodes[3];
00165   else if (nbNodes != 3)
00166     return false;
00167 
00168   return true;
00169 }
00170 
00176 const SMDS_MeshNode* SMDS_FaceOfNodes::GetNode(const int ind) const
00177 {
00178   return myNodes[ ind ];
00179 }
00180 
00181 SMDSAbs_EntityType SMDS_FaceOfNodes::GetEntityType() const
00182 {
00183   return myNbNodes == 3 ? SMDSEntity_Triangle : SMDSEntity_Quadrangle;
00184 }