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_MeshElement.hxx" 00030 #include "SMDS_MeshNode.hxx" 00031 #include "SMDS_MeshEdge.hxx" 00032 #include "SMDS_MeshFace.hxx" 00033 #include "SMDS_MeshVolume.hxx" 00034 #include "utilities.h" 00035 00036 using namespace std; 00037 00038 SMDS_MeshElement::SMDS_MeshElement(int ID) 00039 { 00040 init(ID); 00041 } 00042 00043 SMDS_MeshElement::SMDS_MeshElement(int id, ShortType meshId, LongType shapeId) 00044 { 00045 init(id, meshId, shapeId); 00046 } 00047 00048 void SMDS_MeshElement::init(int id, ShortType meshId, LongType shapeId ) 00049 { 00050 myID = id; 00051 myMeshId = meshId; 00052 myShapeId = shapeId; 00053 myIdInShape = -1; 00054 } 00055 00056 void SMDS_MeshElement::Print(ostream & OS) const 00057 { 00058 OS << "dump of mesh element" << endl; 00059 } 00060 00061 ostream & operator <<(ostream & OS, const SMDS_MeshElement * ME) 00062 { 00063 ME->Print(OS); 00064 return OS; 00065 } 00066 00071 SMDS_ElemIteratorPtr SMDS_MeshElement::nodesIterator() const 00072 { 00073 return elementsIterator(SMDSAbs_Node); 00074 } 00075 00080 SMDS_ElemIteratorPtr SMDS_MeshElement::edgesIterator() const 00081 { 00082 return elementsIterator(SMDSAbs_Edge); 00083 } 00084 00089 SMDS_ElemIteratorPtr SMDS_MeshElement::facesIterator() const 00090 { 00091 return elementsIterator(SMDSAbs_Face); 00092 } 00093 00097 int SMDS_MeshElement::NbNodes() const 00098 { 00099 int nbnodes=0; 00100 SMDS_ElemIteratorPtr it=nodesIterator(); 00101 while(it->more()) 00102 { 00103 it->next(); 00104 nbnodes++; 00105 } 00106 return nbnodes; 00107 } 00108 00112 int SMDS_MeshElement::NbEdges() const 00113 { 00114 int nbedges=0; 00115 SMDS_ElemIteratorPtr it=edgesIterator(); 00116 while(it->more()) 00117 { 00118 it->next(); 00119 nbedges++; 00120 } 00121 return nbedges; 00122 } 00123 00127 int SMDS_MeshElement::NbFaces() const 00128 { 00129 int nbfaces=0; 00130 SMDS_ElemIteratorPtr it=facesIterator(); 00131 while(it->more()) 00132 { 00133 it->next(); 00134 nbfaces++; 00135 } 00136 return nbfaces; 00137 } 00138 00144 class SMDS_MeshElement_MyIterator:public SMDS_ElemIterator 00145 { 00146 const SMDS_MeshElement * myElement; 00147 bool myMore; 00148 public: 00149 SMDS_MeshElement_MyIterator(const SMDS_MeshElement * element): 00150 myElement(element),myMore(true) {} 00151 00152 bool more() 00153 { 00154 return myMore; 00155 } 00156 00157 const SMDS_MeshElement* next() 00158 { 00159 myMore=false; 00160 return myElement; 00161 } 00162 }; 00163 00164 SMDS_ElemIteratorPtr SMDS_MeshElement:: 00165 elementsIterator(SMDSAbs_ElementType type) const 00166 { 00171 if(type==GetType()) 00172 return SMDS_ElemIteratorPtr(new SMDS_MeshElement_MyIterator(this)); 00173 else 00174 { 00175 MESSAGE("Iterator not implemented"); 00176 return SMDS_ElemIteratorPtr((SMDS_ElemIterator*)NULL); 00177 } 00178 } 00179 00181 SMDS_ElemIteratorPtr SMDS_MeshElement::nodesIteratorToUNV() const 00182 { 00183 MESSAGE("Iterator not implemented"); 00184 return SMDS_ElemIteratorPtr((SMDS_ElemIterator*) NULL); 00185 } 00186 00188 SMDS_ElemIteratorPtr SMDS_MeshElement::interlacedNodesElemIterator() const 00189 { 00190 MESSAGE("Iterator not implemented"); 00191 return SMDS_ElemIteratorPtr((SMDS_ElemIterator*) NULL); 00192 } 00193 00194 bool operator<(const SMDS_MeshElement& e1, const SMDS_MeshElement& e2) 00195 { 00196 if(e1.GetType()!=e2.GetType()) return false; 00197 switch(e1.GetType()) 00198 { 00199 case SMDSAbs_Node: 00200 return static_cast<const SMDS_MeshNode &>(e1) < 00201 static_cast<const SMDS_MeshNode &>(e2); 00202 00203 case SMDSAbs_Edge: 00204 return static_cast<const SMDS_MeshEdge &>(e1) < 00205 static_cast<const SMDS_MeshEdge &>(e2); 00206 00207 case SMDSAbs_Face: 00208 return static_cast<const SMDS_MeshFace &>(e1) < 00209 static_cast<const SMDS_MeshFace &>(e2); 00210 00211 case SMDSAbs_Volume: 00212 return static_cast<const SMDS_MeshVolume &>(e1) < 00213 static_cast<const SMDS_MeshVolume &>(e2); 00214 00215 default : MESSAGE("Internal Error"); 00216 } 00217 return false; 00218 } 00219 00220 bool SMDS_MeshElement::IsValidIndex(const int ind) const 00221 { 00222 return ( ind>-1 && ind<NbNodes() ); 00223 } 00224 00225 const SMDS_MeshNode* SMDS_MeshElement::GetNode(const int ind) const 00226 { 00227 if ( ind >= 0 ) { 00228 SMDS_ElemIteratorPtr it = nodesIterator(); 00229 for ( int i = 0; i < ind; ++i ) 00230 it->next(); 00231 if ( it->more() ) 00232 return static_cast<const SMDS_MeshNode*> (it->next()); 00233 } 00234 return 0; 00235 } 00236 00237 bool SMDS_MeshElement::IsQuadratic() const 00238 { 00239 return false; 00240 } 00241 00242 bool SMDS_MeshElement::IsMediumNode(const SMDS_MeshNode* node) const 00243 { 00244 return false; 00245 } 00246 00247 //================================================================================ 00251 //================================================================================ 00252 00253 int SMDS_MeshElement::NbCornerNodes() const 00254 { 00255 return IsQuadratic() ? NbNodes() - NbEdges() : NbNodes(); 00256 } 00257 00258 //================================================================================ 00264 //================================================================================ 00265 00266 int SMDS_MeshElement::GetNodeIndex( const SMDS_MeshNode* node ) const 00267 { 00268 SMDS_ElemIteratorPtr nIt = nodesIterator(); 00269 for ( int i = 0; nIt->more(); ++i ) 00270 if ( nIt->next() == node ) 00271 return i; 00272 return -1; 00273 }