Back to index

salome-smesh  6.5.0
SMDS_VolumeOfNodes.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_VolumeOfNodes.hxx"
00030 #include "SMDS_MeshNode.hxx"
00031 #include "SMDS_SetIterator.hxx"
00032 #include "SMDS_VolumeTool.hxx"
00033 #include "SMDS_Mesh.hxx"
00034 #include "utilities.h"
00035 
00036 using namespace std;
00037 
00042 SMDS_VolumeOfNodes::SMDS_VolumeOfNodes(
00043                 const SMDS_MeshNode * node1,
00044                 const SMDS_MeshNode * node2,
00045                 const SMDS_MeshNode * node3,
00046                 const SMDS_MeshNode * node4,
00047                 const SMDS_MeshNode * node5,
00048                 const SMDS_MeshNode * node6,
00049                 const SMDS_MeshNode * node7,
00050                 const SMDS_MeshNode * node8)
00051 {
00052   //MESSAGE("***************************************************** SMDS_VolumeOfNodes");
00053         myNbNodes = 8;
00054         myNodes = new const SMDS_MeshNode* [myNbNodes];
00055         myNodes[0]=node1;
00056         myNodes[1]=node2;
00057         myNodes[2]=node3;
00058         myNodes[3]=node4;
00059         myNodes[4]=node5;
00060         myNodes[5]=node6;
00061         myNodes[6]=node7;
00062         myNodes[7]=node8;
00063 }
00064 
00065 SMDS_VolumeOfNodes::SMDS_VolumeOfNodes(
00066                 const SMDS_MeshNode * node1,
00067                 const SMDS_MeshNode * node2,
00068                 const SMDS_MeshNode * node3,
00069                 const SMDS_MeshNode * node4)
00070 {
00071   //MESSAGE("***************************************************** SMDS_VolumeOfNodes");
00072         myNbNodes = 4;
00073         myNodes = new const SMDS_MeshNode* [myNbNodes];
00074         myNodes[0]=node1;
00075         myNodes[1]=node2;
00076         myNodes[2]=node3;
00077         myNodes[3]=node4;
00078 }
00079 
00080 SMDS_VolumeOfNodes::SMDS_VolumeOfNodes(
00081                 const SMDS_MeshNode * node1,
00082                 const SMDS_MeshNode * node2,
00083                 const SMDS_MeshNode * node3,
00084                 const SMDS_MeshNode * node4,
00085                 const SMDS_MeshNode * node5)
00086 {
00087   //MESSAGE("***************************************************** SMDS_VolumeOfNodes");
00088         myNbNodes = 5;
00089         myNodes = new const SMDS_MeshNode* [myNbNodes];
00090         myNodes[0]=node1;
00091         myNodes[1]=node2;
00092         myNodes[2]=node3;
00093         myNodes[3]=node4;
00094         myNodes[4]=node5;
00095 }
00096 
00097 SMDS_VolumeOfNodes::SMDS_VolumeOfNodes(
00098                 const SMDS_MeshNode * node1,
00099                 const SMDS_MeshNode * node2,
00100                 const SMDS_MeshNode * node3,
00101                 const SMDS_MeshNode * node4,
00102                 const SMDS_MeshNode * node5,
00103                 const SMDS_MeshNode * node6)
00104 {
00105   //MESSAGE("***************************************************** SMDS_VolumeOfNodes");
00106         myNbNodes = 6;
00107         myNodes = new const SMDS_MeshNode* [myNbNodes];
00108         myNodes[0]=node1;
00109         myNodes[1]=node2;
00110         myNodes[2]=node3;
00111         myNodes[3]=node4;
00112         myNodes[4]=node5;
00113         myNodes[5]=node6;
00114 }
00115 
00116 bool SMDS_VolumeOfNodes::ChangeNodes(const SMDS_MeshNode* nodes[],
00117                                      const int            nbNodes)
00118 {
00119   if (nbNodes < 4 || nbNodes > 8 || nbNodes == 7)
00120     return false;
00121 
00122   delete [] myNodes;
00123   myNbNodes = nbNodes;
00124   myNodes = new const SMDS_MeshNode* [myNbNodes];
00125   for ( int i = 0; i < nbNodes; i++ )
00126     myNodes[ i ] = nodes [ i ];
00127 
00128   return true;
00129 }
00130 
00131 SMDS_VolumeOfNodes::~SMDS_VolumeOfNodes()
00132 {
00133   if (myNodes != NULL) {
00134     delete [] myNodes;
00135     myNodes = NULL;
00136   }
00137 }
00138 
00139 void SMDS_VolumeOfNodes::Print(ostream & OS) const
00140 {
00141         OS << "volume <" << GetID() << "> : ";
00142         int i;
00143         for (i = 0; i < NbNodes()-1; ++i) OS << myNodes[i] << ",";
00144         OS << myNodes[NbNodes()-1]<< ") " << endl;
00145 }
00146 
00147 int SMDS_VolumeOfNodes::NbFaces() const
00148 {
00149         switch(NbNodes())
00150         {
00151         case 4: return 4;
00152         case 5: return 5;
00153         case 6: return 5;
00154         case 8: return 6;
00155         default: MESSAGE("invalid number of nodes");
00156         }
00157         return 0;
00158 }
00159 
00160 int SMDS_VolumeOfNodes::NbNodes() const
00161 {
00162         return myNbNodes;
00163 }
00164 
00165 int SMDS_VolumeOfNodes::NbEdges() const
00166 {
00167         switch(NbNodes())
00168         {
00169         case 4: return 6;
00170         case 5: return 8;
00171         case 6: return 9;
00172         case 8: return 12;
00173         default: MESSAGE("invalid number of nodes");
00174         }
00175         return 0;
00176 }
00177 
00181 class SMDS_VolumeOfNodes_MyIterator:public SMDS_NodeArrayElemIterator
00182 {
00183  public:
00184   SMDS_VolumeOfNodes_MyIterator(const SMDS_MeshNode* const* s, int l):
00185     SMDS_NodeArrayElemIterator( s, & s[ l ]) {}
00186 };
00187 
00191 class _MySubIterator : public SMDS_ElemIterator
00192 {
00193   vector< const SMDS_MeshElement* > myElems;
00194   int myIndex;
00195 public:
00196   _MySubIterator(const SMDS_VolumeOfNodes* vol, SMDSAbs_ElementType type):myIndex(0) {
00197     SMDS_VolumeTool vTool(vol);
00198     if (type == SMDSAbs_Face)
00199       vTool.GetAllExistingFaces( myElems );
00200     else
00201       vTool.GetAllExistingFaces( myElems );
00202   }
00204   virtual bool more() { return myIndex < myElems.size(); }
00205 
00207   virtual const SMDS_MeshElement* next() { return myElems[ myIndex++ ]; }
00208 };
00209 
00210 SMDS_ElemIteratorPtr SMDS_VolumeOfNodes::elementsIterator(SMDSAbs_ElementType type) const
00211 {
00212   switch(type)
00213   {
00214   case SMDSAbs_Volume:
00215     return SMDS_MeshElement::elementsIterator(SMDSAbs_Volume);
00216   case SMDSAbs_Node:
00217     return SMDS_ElemIteratorPtr(new SMDS_VolumeOfNodes_MyIterator(myNodes,myNbNodes));
00218   case SMDSAbs_Face:
00219     return SMDS_ElemIteratorPtr(new _MySubIterator(this,SMDSAbs_Face));
00220   case SMDSAbs_Edge:
00221     return SMDS_ElemIteratorPtr(new _MySubIterator(this,SMDSAbs_Edge));
00222   default:
00223     MESSAGE("ERROR : Iterator not implemented");
00224     return SMDS_ElemIteratorPtr((SMDS_ElemIterator*)NULL);
00225   }
00226 }
00227 
00228 SMDSAbs_ElementType SMDS_VolumeOfNodes::GetType() const
00229 {
00230         return SMDSAbs_Volume;
00231 }
00232 
00238 const SMDS_MeshNode* SMDS_VolumeOfNodes::GetNode(const int ind) const
00239 {
00240   return myNodes[ ind ];
00241 }
00242 
00243 SMDSAbs_EntityType SMDS_VolumeOfNodes::GetEntityType() const
00244 {
00245   SMDSAbs_EntityType aType = SMDSEntity_Tetra;
00246   switch(myNbNodes)
00247   {
00248   case 4: aType = SMDSEntity_Tetra;   break;
00249   case 5: aType = SMDSEntity_Pyramid; break;
00250   case 6: aType = SMDSEntity_Penta;   break;
00251   case 8:
00252   default: aType = SMDSEntity_Hexa;    break;
00253   }
00254   return aType;
00255 }
00256 
00257