Back to index

salome-smesh  6.5.0
SMDS_PolyhedralVolumeOfNodes.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_PolyhedralVolumeOfNodes.hxx"
00030 #include "SMDS_MeshNode.hxx"
00031 #include "SMDS_SetIterator.hxx"
00032 #include "SMDS_VolumeTool.hxx"
00033 #include "utilities.h"
00034 
00035 #include <set>
00036 
00037 using namespace std;
00038 
00039 //=======================================================================
00040 //function : Constructor
00041 //purpose  : Create a volume of many faces
00042 //=======================================================================
00043 SMDS_PolyhedralVolumeOfNodes::SMDS_PolyhedralVolumeOfNodes
00044                                 (vector<const SMDS_MeshNode *> nodes,
00045                                  vector<int>                   quantities)
00046 : SMDS_VolumeOfNodes(NULL, NULL, NULL, NULL)
00047 {
00048   //MESSAGE("****************************************** SMDS_PolyhedralVolumeOfNodes");
00049   ChangeNodes(nodes, quantities);
00050 }
00051 
00052 //=======================================================================
00053 //function : GetType
00054 //purpose  : 
00055 //=======================================================================
00056 SMDSAbs_ElementType SMDS_PolyhedralVolumeOfNodes::GetType() const
00057 {
00058 //  return SMDSAbs_PolyhedralVolume;
00059   return SMDSAbs_Volume;
00060 }
00061 
00062 //=======================================================================
00063 //function : ChangeNodes
00064 //purpose  : 
00065 //=======================================================================
00066 bool SMDS_PolyhedralVolumeOfNodes::ChangeNodes (const vector<const SMDS_MeshNode *>& nodes,
00067                                                 const vector<int>&                   quantities)
00068 {
00069   myNodesByFaces = nodes;
00070   myQuantities = quantities;
00071 
00072   // Init fields of parent class, it allows to get only unique nodes(?)
00073 
00074   set<const SMDS_MeshNode *> aSet;
00075   aSet.insert( nodes.begin(), nodes.end());
00076   //SMDS_VolumeOfNodes::ChangeNodes(aNodes, aNbNodes);
00077   delete [] myNodes;
00078   myNbNodes = aSet.size();
00079   myNodes = new const SMDS_MeshNode* [myNbNodes];
00080   set<const SMDS_MeshNode *>::iterator anIter = aSet.begin();
00081   for (int k=0; anIter != aSet.end(); anIter++, k++)
00082     myNodes[k] = *anIter;
00083 
00084   return true;
00085 }
00086 
00087 //=======================================================================
00088 //function : NbEdges
00089 //purpose  : 
00090 //=======================================================================
00091 int SMDS_PolyhedralVolumeOfNodes::NbNodes() const
00092 {
00093   return myNodesByFaces.size();
00094 }
00095 
00096 //=======================================================================
00097 //function : NbEdges
00098 //purpose  : 
00099 //=======================================================================
00100 int SMDS_PolyhedralVolumeOfNodes::NbEdges() const
00101 {
00102   int nbEdges = 0;
00103 
00104   for (int ifa = 0; ifa < myQuantities.size(); ifa++) {
00105     nbEdges += myQuantities[ifa];
00106   }
00107   nbEdges /= 2;
00108 
00109   return nbEdges;
00110 }
00111 
00112 //=======================================================================
00113 //function : NbFaces
00114 //purpose  : 
00115 //=======================================================================
00116 int SMDS_PolyhedralVolumeOfNodes::NbFaces() const
00117 {
00118   return myQuantities.size();
00119 }
00120 
00121 //=======================================================================
00122 //function : NbFaceNodes
00123 //purpose  : 
00124 //=======================================================================
00125 int SMDS_PolyhedralVolumeOfNodes::NbFaceNodes (const int face_ind) const
00126 {
00127   if (face_ind < 1 || myQuantities.size() < face_ind)
00128     return 0;
00129   return myQuantities[face_ind - 1];
00130 }
00131 
00132 //=======================================================================
00133 //function : GetFaceNode
00134 //purpose  : 
00135 //=======================================================================
00136 const SMDS_MeshNode* SMDS_PolyhedralVolumeOfNodes::GetFaceNode (const int face_ind,
00137                                                                 const int node_ind) const
00138 {
00139   if (node_ind < 1 || NbFaceNodes(face_ind) < node_ind)
00140     return NULL;
00141 
00142   int i, first_node = 0;
00143   for (i = 0; i < face_ind - 1; i++) {
00144     first_node += myQuantities[i];
00145   }
00146 
00147   return myNodesByFaces[first_node + node_ind - 1];
00148 }
00149 
00150 //=======================================================================
00151 //function : Print
00152 //purpose  : 
00153 //=======================================================================
00154 void SMDS_PolyhedralVolumeOfNodes::Print (ostream & OS) const
00155 {
00156   OS << "polyhedral volume <" << GetID() << "> : ";
00157 
00158   int faces_len = myQuantities.size();
00159   //int nodes_len = myNodesByFaces.size();
00160   int cur_first_node = 0;
00161 
00162   int i, j;
00163   for (i = 0; i < faces_len; i++) {
00164     OS << "face_" << i << " (";
00165     for (j = 0; j < myQuantities[i] - 1; j++) {
00166       OS << myNodesByFaces[cur_first_node + j] << ",";
00167     }
00168     OS << myNodesByFaces[cur_first_node + j] << ") ";
00169     cur_first_node += myQuantities[i];
00170   }
00171 }
00172 
00173 //=======================================================================
00174 //function : ChangeNodes
00175 //purpose  : usage disabled
00176 //=======================================================================
00177 bool SMDS_PolyhedralVolumeOfNodes::ChangeNodes (const SMDS_MeshNode* nodes[],
00178                                                 const int            nbNodes)
00179 {
00180   return false;
00181 }
00182 
00184 
00187 
00188 
00189 struct _MyIterator:public SMDS_NodeVectorElemIterator
00190 {
00191   _MyIterator(const vector<const SMDS_MeshNode *>& nodes):
00192     SMDS_NodeVectorElemIterator( nodes.begin(), nodes.end()) {}
00193 };
00194 
00196 
00199 
00200 
00201 class _MySubIterator : public SMDS_ElemIterator
00202 {
00203   vector< const SMDS_MeshElement* > myElems;
00204   int myIndex;
00205 public:
00206   _MySubIterator(const SMDS_MeshVolume* vol, SMDSAbs_ElementType type):myIndex(0) {
00207     SMDS_VolumeTool vTool(vol);
00208     if (type == SMDSAbs_Face)
00209       vTool.GetAllExistingFaces( myElems );
00210     else
00211       vTool.GetAllExistingEdges( myElems );
00212   }
00214   virtual bool more() { return myIndex < myElems.size(); }
00215 
00217   virtual const SMDS_MeshElement* next() { return myElems[ myIndex++ ]; }
00218 };
00219 
00220 //================================================================================
00224 //================================================================================
00225 
00226 SMDS_ElemIteratorPtr SMDS_PolyhedralVolumeOfNodes::elementsIterator(SMDSAbs_ElementType type) const
00227 {
00228   switch(type)
00229   {
00230   case SMDSAbs_Volume:
00231     return SMDS_MeshElement::elementsIterator(SMDSAbs_Volume);
00232   case SMDSAbs_Node:
00233     return SMDS_ElemIteratorPtr(new _MyIterator(myNodesByFaces));
00234   case SMDSAbs_Face:
00235     return SMDS_ElemIteratorPtr(new _MySubIterator(this,SMDSAbs_Face));
00236   case SMDSAbs_Edge:
00237     return SMDS_ElemIteratorPtr(new _MySubIterator(this,SMDSAbs_Edge));
00238   default:
00239     MESSAGE("ERROR : Iterator not implemented");
00240     return SMDS_ElemIteratorPtr((SMDS_ElemIterator*)NULL);
00241   }
00242 }
00243 
00244 //================================================================================
00248 //================================================================================
00249 
00250 SMDS_ElemIteratorPtr SMDS_PolyhedralVolumeOfNodes::uniqueNodesIterator() const
00251 {
00252   return SMDS_ElemIteratorPtr
00253     (new SMDS_NodeArrayElemIterator( myNodes, & myNodes[ myNbNodes ]));
00254 }
00255 
00256 //================================================================================
00260 //================================================================================
00261 
00262 const SMDS_MeshNode* SMDS_PolyhedralVolumeOfNodes::GetNode(const int ind) const
00263 {
00264   return myNodesByFaces[ ind ];
00265 }