Back to index

salome-smesh  6.5.0
SMDS_QuadraticFaceOfNodes.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 // File:      SMDS_QuadraticFaceOfNodes.cxx
00025 // Created:   16.01.06 17:12:58
00026 // Author:    Sergey KUUL
00027 //
00028 #include "SMDS_QuadraticFaceOfNodes.hxx"
00029 
00030 #include "SMDS_SetIterator.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 //=======================================================================
00041 //function : SMDS_QuadraticFaceOfNodes()
00042 //purpose  : Constructor
00043 //=======================================================================
00044 
00045 SMDS_QuadraticFaceOfNodes::SMDS_QuadraticFaceOfNodes(const SMDS_MeshNode * n1,
00046                                                      const SMDS_MeshNode * n2,
00047                                                      const SMDS_MeshNode * n3,
00048                                                      const SMDS_MeshNode * n12,
00049                                                      const SMDS_MeshNode * n23,
00050                                                      const SMDS_MeshNode * n31)
00051 {
00052   //MESSAGE("********************************************** SMDS_QuadraticFaceOfNodes 1");
00053   myNodes.resize( 6 );
00054   myNodes[ 0 ] = n1;
00055   myNodes[ 1 ] = n2;
00056   myNodes[ 2 ] = n3;
00057   myNodes[ 3 ] = n12;
00058   myNodes[ 4 ] = n23;
00059   myNodes[ 5 ] = n31;
00060 }
00061 
00062 
00063 //=======================================================================
00064 //function : SMDS_QuadraticFaceOfNodes()
00065 //purpose  : Constructor
00066 //=======================================================================
00067 
00068 SMDS_QuadraticFaceOfNodes::SMDS_QuadraticFaceOfNodes(const SMDS_MeshNode * n1,
00069                                                      const SMDS_MeshNode * n2,
00070                                                      const SMDS_MeshNode * n3,
00071                                                      const SMDS_MeshNode * n4,
00072                                                      const SMDS_MeshNode * n12,
00073                                                      const SMDS_MeshNode * n23,
00074                                                      const SMDS_MeshNode * n34,
00075                                                      const SMDS_MeshNode * n41)
00076 {
00077   //MESSAGE("********************************************* SMDS_QuadraticFaceOfNodes 2");
00078   myNodes.resize( 8 );
00079   myNodes[ 0 ] = n1;
00080   myNodes[ 1 ] = n2;
00081   myNodes[ 2 ] = n3;
00082   myNodes[ 3 ] = n4;
00083   myNodes[ 4 ] = n12;
00084   myNodes[ 5 ] = n23;
00085   myNodes[ 6 ] = n34;
00086   myNodes[ 7 ] = n41;
00087 }
00088 
00089 
00090 //=======================================================================
00091 //function : IsMediumNode
00092 //purpose  : 
00093 //=======================================================================
00094 
00095 bool SMDS_QuadraticFaceOfNodes::IsMediumNode(const SMDS_MeshNode * node) const
00096 {
00097   int i=NbNodes()/2;
00098   for(; i<NbNodes(); i++) {
00099     if(myNodes[i]==node) return true;
00100   }
00101   return false;
00102 }
00103 
00104 
00105 //=======================================================================
00106 //function : ChangeNodes
00107 //purpose  : 
00108 //=======================================================================
00109 
00110 bool SMDS_QuadraticFaceOfNodes::ChangeNodes(const SMDS_MeshNode* nodes[],
00111                                             const int            nbNodes)
00112 {
00113   if( nbNodes==6 || nbNodes==8 ) {
00114     myNodes.resize(nbNodes);
00115     int i=0;
00116     for(; i<nbNodes; i++) {
00117       myNodes[i] = nodes[i];
00118     }
00119     return true;
00120   }
00121   return false;
00122 }
00123 
00124 
00125 //=======================================================================
00126 //function : NbNodes
00127 //purpose  : 
00128 //=======================================================================
00129 int SMDS_QuadraticFaceOfNodes::NbNodes() const
00130 {
00131   return myNodes.size();
00132 }
00133 
00134 
00135 //=======================================================================
00136 //function : NbEdges
00137 //purpose  : 
00138 //=======================================================================
00139 int SMDS_QuadraticFaceOfNodes::NbEdges() const
00140 {
00141   return NbNodes()/2;
00142 }
00143 
00144 
00145 //=======================================================================
00146 //function : NbFaces
00147 //purpose  : 
00148 //=======================================================================
00149 int SMDS_QuadraticFaceOfNodes::NbFaces() const
00150 {
00151   return 1;
00152 }
00153 
00154 //=======================================================================
00155 //function : Print
00156 //purpose  : 
00157 //=======================================================================
00158 void SMDS_QuadraticFaceOfNodes::Print(ostream & OS) const
00159 {
00160   OS << "quadratic face <" << GetID() << " > : ";
00161   int i, nbNodes = myNodes.size();
00162   for (i = 0; i < nbNodes - 1; i++)
00163     OS << myNodes[i] << ",";
00164   OS << myNodes[i] << ") " << endl;
00165 }
00166 
00167 namespace {
00168 
00169   //=======================================================================
00170   //class : _MyInterlacedNodeIterator
00171   //purpose  : 
00172   //=======================================================================
00173 
00174   class _MyInterlacedNodeIterator:public SMDS_NodeIterator
00175   {
00176     const vector<const SMDS_MeshNode *>& mySet;
00177     int myIndex;
00178     const int * myInterlace;
00179   public:
00180     _MyInterlacedNodeIterator(const vector<const SMDS_MeshNode *>& s,
00181                               const int * interlace):
00182       mySet(s),myIndex(0),myInterlace(interlace) {}
00183 
00184     bool more()
00185     {
00186       return myIndex < mySet.size();
00187     }
00188 
00189     const SMDS_MeshNode* next()
00190     {
00191       return mySet[ myInterlace[ myIndex++ ]];
00192     }
00193   };
00194 
00195   //=======================================================================
00196   //class : _MyInterlacedNodeElemIterator
00197   //purpose  : 
00198   //=======================================================================
00199 
00200   class _MyInterlacedNodeElemIterator : public SMDS_ElemIterator
00201   {
00202     SMDS_NodeIteratorPtr myItr;
00203   public:
00204     _MyInterlacedNodeElemIterator(SMDS_NodeIteratorPtr interlacedNodeItr):
00205       myItr( interlacedNodeItr ) {}
00206     bool more()                    { return myItr->more(); }
00207     const SMDS_MeshElement* next() { return myItr->next(); }
00208   };
00209 
00210   //=======================================================================
00211   //class : _MyNodeIterator
00212   //purpose  : 
00213   //=======================================================================
00214 
00215   class _MyNodeIterator : public SMDS_NodeVectorElemIterator
00216   {
00217   public:
00218     _MyNodeIterator(const vector<const SMDS_MeshNode *>& s):
00219       SMDS_NodeVectorElemIterator( s.begin(), s.end() ) {}
00220   };
00221   
00222 }
00223 
00224 //=======================================================================
00225 //function : interlacedNodesIterator
00226 //purpose  : 
00227 //=======================================================================
00228 
00229 SMDS_NodeIteratorPtr SMDS_QuadraticFaceOfNodes::interlacedNodesIterator() const
00230 {
00231   static int triaInterlace [] = { 0, 3, 1, 4, 2, 5 };
00232   static int quadInterlace [] = { 0, 4, 1, 5, 2, 6, 3, 7 };
00233   return SMDS_NodeIteratorPtr
00234     (new _MyInterlacedNodeIterator (myNodes, myNodes.size()==6 ? triaInterlace : quadInterlace));
00235 }
00236 
00237 //=======================================================================
00238 //function : interlacedNodesElemIterator
00239 //purpose  : 
00240 //=======================================================================
00241 
00242 SMDS_ElemIteratorPtr SMDS_QuadraticFaceOfNodes::interlacedNodesElemIterator() const
00243 {
00244   return SMDS_ElemIteratorPtr
00245     (new _MyInterlacedNodeElemIterator ( interlacedNodesIterator() ));
00246 }
00248 
00251 
00252 
00253 class _MyEdgeIterator : public SMDS_ElemIterator
00254 {
00255   vector< const SMDS_MeshElement* > myElems;
00256   int myIndex;
00257 public:
00258   _MyEdgeIterator(const SMDS_QuadraticFaceOfNodes* face):myIndex(0) {
00259     myElems.reserve( face->NbNodes() );
00260     SMDS_ElemIteratorPtr nIt = face->interlacedNodesElemIterator();
00261     const SMDS_MeshNode* n0 = face->GetNodeWrap( -1 );
00262     while ( nIt->more() ) {
00263       const SMDS_MeshNode* n1 = static_cast<const SMDS_MeshNode*>( nIt->next() );
00264       const SMDS_MeshElement* edge = SMDS_Mesh::FindEdge( n0, n1 );
00265       if ( edge )
00266         myElems.push_back( edge );
00267       n0 = n1;
00268     }
00269   }
00271   virtual bool more() { return myIndex < myElems.size(); }
00272 
00274   virtual const SMDS_MeshElement* next() { return myElems[ myIndex++ ]; }
00275 };
00276 
00277 //=======================================================================
00278 //function : elementsIterator
00279 //purpose  : 
00280 //=======================================================================
00281 
00282 SMDS_ElemIteratorPtr SMDS_QuadraticFaceOfNodes::elementsIterator
00283                                          (SMDSAbs_ElementType type) const
00284 {
00285   switch(type)
00286   {
00287   case SMDSAbs_Face:
00288     return SMDS_MeshElement::elementsIterator(SMDSAbs_Face);
00289   case SMDSAbs_Node:
00290     return SMDS_ElemIteratorPtr(new _MyNodeIterator(myNodes));
00291   case SMDSAbs_Edge:
00292     return SMDS_ElemIteratorPtr(new _MyEdgeIterator( this ));
00293     break;
00294   default:
00295     return SMDS_ElemIteratorPtr
00296       (new SMDS_IteratorOfElements
00297        (this,type,SMDS_ElemIteratorPtr (new _MyNodeIterator(myNodes))));
00298   }
00299   return SMDS_ElemIteratorPtr();
00300 }
00301 
00307 const SMDS_MeshNode* SMDS_QuadraticFaceOfNodes::GetNode(const int ind) const
00308 {
00309   return myNodes[ ind ];
00310 }
00311 
00312 SMDSAbs_EntityType SMDS_QuadraticFaceOfNodes::GetEntityType() const
00313 {
00314   return NbNodes() == 6 ? SMDSEntity_Quad_Triangle : SMDSEntity_Quad_Quadrangle;
00315 }