00001 // Copyright (C) 2007-2011 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_PolygonalFaceOfNodes.hxx" 00030 00031 #include "SMDS_IteratorOfElements.hxx" 00032 #include "SMDS_SetIterator.hxx" 00033 #include "SMDS_Mesh.hxx" 00034 00035 #include "utilities.h" 00036 00037 using namespace std; 00038 00039 //======================================================================= 00040 //function : Constructor 00041 //purpose : 00042 //======================================================================= 00043 SMDS_PolygonalFaceOfNodes::SMDS_PolygonalFaceOfNodes 00044 (std::vector<const SMDS_MeshNode *> nodes) 00045 { 00046 //MESSAGE("******************************************** SMDS_PolygonalFaceOfNodes"); 00047 myNodes = nodes; 00048 } 00049 00050 //======================================================================= 00051 //function : GetType 00052 //purpose : 00053 //======================================================================= 00054 SMDSAbs_ElementType SMDS_PolygonalFaceOfNodes::GetType() const 00055 { 00056 return SMDSAbs_Face; 00057 //return SMDSAbs_PolygonalFace; 00058 } 00059 00060 //======================================================================= 00061 //function : ChangeNodes 00062 //purpose : 00063 //======================================================================= 00064 bool SMDS_PolygonalFaceOfNodes::ChangeNodes (std::vector<const SMDS_MeshNode *> nodes) 00065 { 00066 if (nodes.size() < 3) 00067 return false; 00068 00069 myNodes = nodes; 00070 00071 return true; 00072 } 00073 00074 //======================================================================= 00075 //function : ChangeNodes 00076 //purpose : to support the same interface, as SMDS_FaceOfNodes 00077 //======================================================================= 00078 bool SMDS_PolygonalFaceOfNodes::ChangeNodes (const SMDS_MeshNode* nodes[], 00079 const int nbNodes) 00080 { 00081 if (nbNodes < 3) 00082 return false; 00083 00084 myNodes.resize(nbNodes); 00085 int i = 0; 00086 for (; i < nbNodes; i++) { 00087 myNodes[i] = nodes[i]; 00088 } 00089 00090 return true; 00091 } 00092 00093 //======================================================================= 00094 //function : NbNodes 00095 //purpose : 00096 //======================================================================= 00097 int SMDS_PolygonalFaceOfNodes::NbNodes() const 00098 { 00099 return myNodes.size(); 00100 } 00101 00102 //======================================================================= 00103 //function : NbEdges 00104 //purpose : 00105 //======================================================================= 00106 int SMDS_PolygonalFaceOfNodes::NbEdges() const 00107 { 00108 return NbNodes(); 00109 } 00110 00111 //======================================================================= 00112 //function : NbFaces 00113 //purpose : 00114 //======================================================================= 00115 int SMDS_PolygonalFaceOfNodes::NbFaces() const 00116 { 00117 return 1; 00118 } 00119 00120 //======================================================================= 00121 //function : Print 00122 //purpose : 00123 //======================================================================= 00124 void SMDS_PolygonalFaceOfNodes::Print(ostream & OS) const 00125 { 00126 OS << "polygonal face <" << GetID() << " > : "; 00127 int i, nbNodes = myNodes.size(); 00128 for (i = 0; i < nbNodes - 1; i++) 00129 OS << myNodes[i] << ","; 00130 OS << myNodes[i] << ") " << endl; 00131 } 00132 00133 //======================================================================= 00134 //function : elementsIterator 00135 //purpose : 00136 //======================================================================= 00137 class SMDS_PolygonalFaceOfNodes_MyIterator:public SMDS_NodeVectorElemIterator 00138 { 00139 public: 00140 SMDS_PolygonalFaceOfNodes_MyIterator(const vector<const SMDS_MeshNode *>& s): 00141 SMDS_NodeVectorElemIterator( s.begin(), s.end() ) {} 00142 }; 00143 00145 00148 00149 00150 class _MyEdgeIterator : public SMDS_ElemIterator 00151 { 00152 vector< const SMDS_MeshElement* > myElems; 00153 int myIndex; 00154 public: 00155 _MyEdgeIterator(const SMDS_MeshFace* face):myIndex(0) { 00156 myElems.reserve( face->NbNodes() ); 00157 for ( int i = 0; i < face->NbNodes(); ++i ) { 00158 const SMDS_MeshElement* edge = 00159 SMDS_Mesh::FindEdge( face->GetNode( i ), face->GetNodeWrap( i + 1 )); 00160 if ( edge ) 00161 myElems.push_back( edge ); 00162 } 00163 } 00165 virtual bool more() { return myIndex < myElems.size(); } 00166 00168 virtual const SMDS_MeshElement* next() { return myElems[ myIndex++ ]; } 00169 }; 00170 00171 SMDS_ElemIteratorPtr SMDS_PolygonalFaceOfNodes::elementsIterator 00172 (SMDSAbs_ElementType type) const 00173 { 00174 switch(type) 00175 { 00176 case SMDSAbs_Face: 00177 return SMDS_MeshElement::elementsIterator(SMDSAbs_Face); 00178 case SMDSAbs_Node: 00179 return SMDS_ElemIteratorPtr(new SMDS_PolygonalFaceOfNodes_MyIterator(myNodes)); 00180 case SMDSAbs_Edge: 00181 return SMDS_ElemIteratorPtr(new _MyEdgeIterator( this )); 00182 break; 00183 default: 00184 return SMDS_ElemIteratorPtr 00185 (new SMDS_IteratorOfElements 00186 (this,type,SMDS_ElemIteratorPtr 00187 (new SMDS_PolygonalFaceOfNodes_MyIterator(myNodes)))); 00188 } 00189 return SMDS_ElemIteratorPtr(); 00190 } 00191 00197 const SMDS_MeshNode* SMDS_PolygonalFaceOfNodes::GetNode(const int ind) const 00198 { 00199 return myNodes[ WrappedIndex( ind )]; 00200 }