Back to index

salome-paravis  6.5.0
vtkMedUtilities.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2010-2012  CEA/DEN, EDF R&D
00002 //
00003 // This library is free software; you can redistribute it and/or
00004 // modify it under the terms of the GNU Lesser General Public
00005 // License as published by the Free Software Foundation; either
00006 // version 2.1 of the License.
00007 //
00008 // This library is distributed in the hope that it will be useful,
00009 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011 // Lesser General Public License for more details.
00012 //
00013 // You should have received a copy of the GNU Lesser General Public
00014 // License along with this library; if not, write to the Free Software
00015 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00016 //
00017 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00018 //
00019 
00020 #include "vtkMedUtilities.h"
00021 
00022 #include "vtkMedMesh.h"
00023 #include "vtkMedFamily.h"
00024 #include "vtkMedGroup.h"
00025 #include "vtkMedFamilyOnEntityOnProfile.h"
00026 #include "vtkMedFamilyOnEntity.h"
00027 #include "vtkMedEntityArray.h"
00028 #include "vtkMedIntArray.h"
00029 #include "vtkMedGrid.h"
00030 
00031 #include "vtkObjectFactory.h"
00032 #include "vtkInformation.h"
00033 #include "vtkDoubleArray.h"
00034 #include "vtkIntArray.h"
00035 #include "vtkLongLongArray.h"
00036 #include "vtkLongArray.h"
00037 #include "vtkIdTypeArray.h"
00038 #include "vtkCellType.h"
00039 #include "vtkIdList.h"
00040 #include "vtkMutableDirectedGraph.h"
00041 #include "vtkStringArray.h"
00042 #include "vtkDataSetAttributes.h"
00043 #include "vtkOutEdgeIterator.h"
00044 #include "vtkInformationIntegerKey.h"
00045 #include "vtkInformationStringVectorKey.h"
00046 #include "vtkInformationObjectBaseKey.h"
00047 
00048 #include <sstream>
00049 using namespace std;
00050 char vtkMedUtilities::Separator='/';
00051 
00052 const char* vtkMedUtilities::NoGroupName="No Group";
00053 const char* vtkMedUtilities::OnPointName="OnPoint";
00054 const char* vtkMedUtilities::OnCellName="OnCell";
00055 
00056 const int MED_TRIA_CHILD_TO_PARENT_INDEX[3][3]=
00057     {{0, 1, 3}, {1, 2, 4}, {2, 0, 5}};
00058 
00059 const int MED_QUAD_CHILD_TO_PARENT_INDEX[4][3]=
00060     {{0, 1, 4}, {1, 2, 5}, {2, 3, 6}, {3, 0, 7}};
00061 
00062 const int MED_TETRA_CHILD_TO_PARENT_INDEX[4][6]=
00063     {{0, 1, 2, 4, 5, 6},
00064      {0, 3, 1, 7, 8, 4},
00065      {1, 3, 2, 8, 9, 5},
00066      {2, 3, 0, 9, 7, 6}};
00067 
00068 const int MED_HEXA_CHILD_TO_PARENT_INDEX[6][8]=
00069   {{0, 1, 2, 3, 8, 9, 10, 11},
00070    {4, 7, 6, 5, 15, 14, 13, 12},
00071    {0, 4, 5, 1, 16, 12, 17, 8},
00072    {1, 5, 6, 2, 17, 13, 18, 9},
00073    {2, 6, 7, 3, 18, 14, 19, 10},
00074    {3, 7, 4, 0, 19, 15, 16, 11}};
00075 
00076 const int MED_PYRA_CHILD_TO_PARENT_INDEX[5][8]=
00077   {{0, 1, 2, 3, 5, 6, 7, 8},
00078    {0, 4, 1, -1, 9, 10, 5, -1},
00079    {1, 4, 2, -1, 10, 11, 6, -1},
00080    {2, 4, 3, -1, 11, 12, 7, -1},
00081    {3, 4, 0, -1, 12, 9, 8, -1}};
00082 
00083 const int MED_PENTA_CHILD_TO_PARENT_INDEX[5][8]=
00084   {{0, 1, 2, -1, 6, 7, 8, -1},
00085    {3, 5, 4, -1, 11, 10, 9, -1},
00086    {0, 3, 4, 1, 12, 9, 13, 6},
00087    {1, 4, 5, 2, 13, 10, 14, 7},
00088    {2, 5, 3, 0, 14, 11, 12, 8}};
00089 
00090 vtkInformationKeyMacro(vtkMedUtilities, ELNO, Integer);
00091 vtkInformationKeyMacro(vtkMedUtilities, ELGA, Integer);
00092 vtkInformationKeyMacro(vtkMedUtilities, BLOCK_NAME, StringVector);
00093 vtkInformationKeyMacro(vtkMedUtilities, STRUCT_ELEMENT, ObjectBase);
00094 vtkInformationKeyMacro(vtkMedUtilities, STRUCT_ELEMENT_INDEX, Integer);
00095 
00096 vtkDataArray* vtkMedUtilities::NewCoordArray()
00097 {
00098   return vtkMedUtilities::NewArray(MED_FLOAT64);
00099 }
00100 
00101 vtkDataArray* vtkMedUtilities::NewArray(med_field_type type)
00102 {
00103   switch(type)
00104   {
00105     case MED_FLOAT64:
00106       if(sizeof(double)==8 && sizeof(med_float)==8)
00107         return vtkDoubleArray::New();
00108       vtkGenericWarningMacro("double type do not match med_float, aborting")
00109       return NULL;
00110     case MED_INT32:
00111       if(sizeof(vtkIdType)==4)
00112         return vtkIdTypeArray::New();
00113       if(sizeof(int)==4)
00114         return vtkIntArray::New();
00115       if(sizeof(long)==4)
00116         return vtkLongArray::New();
00117       vtkGenericWarningMacro("No vtk type matches MED_INT32, aborting")
00118       return NULL;
00119     case MED_INT64:
00120       if(sizeof(vtkIdType)==8)
00121         return vtkIdTypeArray::New();
00122       if(sizeof(long)==8)
00123         return vtkLongArray::New();
00124       if(sizeof(long long)==8)
00125         return vtkLongLongArray::New();
00126       vtkGenericWarningMacro("No vtk type matches MED_INT64, aborting")
00127       ;
00128       return NULL;
00129     case MED_INT:
00130       if(sizeof(med_int)==4)
00131         return vtkMedUtilities::NewArray(MED_INT32);
00132       if(sizeof(med_int)==8)
00133         return vtkMedUtilities::NewArray(MED_INT64);
00134       vtkGenericWarningMacro("No vtk type matches MED_INT, aborting")
00135       return NULL;
00136     default:
00137       vtkGenericWarningMacro("the array type is not known, aborting.")
00138       return NULL;
00139   }
00140 }
00141 
00142 vtkAbstractArray* vtkMedUtilities::NewArray(med_attribute_type type)
00143 {
00144   switch(type)
00145     {
00146     case MED_ATT_FLOAT64 :
00147       if(sizeof(double) == sizeof(med_float))
00148         return vtkDoubleArray::New();
00149       vtkGenericWarningMacro("double type do not match med_float, aborting");
00150       return NULL;
00151     case MED_ATT_INT :
00152       if(sizeof(vtkIdType) == sizeof(med_int))
00153         return vtkIdTypeArray::New();
00154       if(sizeof(int) == sizeof(med_int))
00155         return vtkIntArray::New();
00156       if(sizeof(long) == sizeof(med_int))
00157         return vtkLongArray::New();
00158       if(sizeof(long long) == sizeof(med_int))
00159         return vtkLongLongArray::New();
00160       vtkGenericWarningMacro("med_int type does not match known VTK type, aborting");
00161       return NULL;
00162     case MED_ATT_NAME :
00163       return vtkStringArray::New();
00164     }
00165   return NULL;
00166 }
00167 
00168 const char* vtkMedUtilities::GeometryName(med_geometry_type geometry)
00169 {
00170   switch(geometry)
00171   {
00172     case MED_POINT1:
00173       return "MED_POINT1";
00174     case MED_SEG2:
00175       return "MED_SEG2";
00176     case MED_SEG3:
00177       return "MED_SEG3";
00178     case MED_SEG4:
00179       return "MED_SEG4";
00180     case MED_TRIA3:
00181       return "MED_TRIA3";
00182     case MED_QUAD4:
00183       return "MED_QUAD4";
00184     case MED_TRIA6:
00185       return "MED_TRIA6";
00186     case MED_TRIA7:
00187       return "MED_TRIA7";
00188     case MED_QUAD8:
00189       return "MED_QUAD8";
00190     case MED_QUAD9:
00191       return "MED_QUAD9";
00192     case MED_TETRA4:
00193       return "MED_TETRA4";
00194     case MED_PYRA5:
00195       return "MED_PYRA5";
00196     case MED_PENTA6:
00197       return "MED_PENTA6";
00198     case MED_HEXA8:
00199       return "MED_HEXA8";
00200     case MED_TETRA10:
00201       return "MED_TETRA10";
00202     case MED_OCTA12:
00203       return "MED_OCTA12";
00204     case MED_PYRA13:
00205       return "MED_PYRA13";
00206     case MED_PENTA15:
00207       return "MED_PENTA15";
00208     case MED_HEXA20:
00209       return "MED_HEXA20";
00210     case MED_HEXA27:
00211       return "MED_HEXA27";
00212     case MED_POLYGON:
00213       return "MED_POLYGON";
00214     case MED_POLYHEDRON:
00215       return "MED_POLYHEDRON";
00216     case MED_NO_GEOTYPE:
00217       return "MED_NO_GEOTYPE";
00218     default:
00219       return "UNKNOWN_GEOMETRY";
00220   }
00221 }
00222 
00223 const char* vtkMedUtilities::EntityName(med_entity_type type)
00224 {
00225   switch(type)
00226     {
00227     case MED_CELL:
00228       return "MED_CELL";
00229     case MED_DESCENDING_FACE:
00230       return "MED_DESCENDING_FACE";
00231     case MED_DESCENDING_EDGE:
00232       return "MED_DESCENDING_EDGE";
00233     case MED_NODE:
00234       return "MED_NODE";
00235     case MED_NODE_ELEMENT:
00236       return "MED_NODE_ELEMENT";
00237     case MED_STRUCT_ELEMENT:
00238       return "MED_STRUCT_ELEMENT";
00239     case MED_UNDEF_ENTITY_TYPE:
00240       return "MED_UNDEF_ENTITY_TYPE";
00241     default:
00242       return "UNKNOWN_ENTITY_TYPE ";
00243   }
00244 }
00245 
00246 const char* vtkMedUtilities::ConnectivityName(med_connectivity_mode conn)
00247 {
00248   switch(conn)
00249     {
00250     case MED_NODAL:
00251       return "MED_NODAL";
00252     case MED_DESCENDING:
00253       return "MED_DESCENDING";
00254     case MED_NO_CMODE:
00255       return "MED_NO_CMODE";
00256     default:
00257       return "UNKNOWN_CONNECTIVITY_MODE";
00258   }
00259 }
00260 
00261 const std::string vtkMedUtilities::SimplifyName(const char* medName)
00262 {
00263   ostringstream sstr;
00264   bool underscore=false;
00265   bool space=false;
00266   int l=strlen(medName);
00267   for(int cc=0; cc<l; cc++)
00268     {
00269     if(medName[cc]==' ')
00270       {
00271       space=true;
00272       continue;
00273       }
00274     else if(medName[cc]=='_')
00275       {
00276       underscore=true;
00277       continue;
00278       }
00279     else
00280       {
00281       if(underscore||space)
00282         sstr<<'_';
00283       underscore=false;
00284       space=false;
00285       sstr<<medName[cc];
00286       }
00287     }
00288   return sstr.str();
00289 }
00290 
00291 const std::string vtkMedUtilities::FamilyKey(const char* meshName,
00292     int pointOrCell, const char* familyName)
00293 {
00294   ostringstream sstr;
00295   sstr<<"FAMILY"<<Separator<<SimplifyName(meshName)<<Separator;
00296   if(pointOrCell==OnCell)
00297     sstr<<vtkMedUtilities::OnCellName;
00298   else
00299     sstr<<vtkMedUtilities::OnPointName;
00300   sstr<<Separator<<SimplifyName(familyName);
00301   return sstr.str();
00302 }
00303 
00304 const std::string vtkMedUtilities::GroupKey(const char* meshName,
00305     int pointOrCell, const char* groupName)
00306 {
00307   ostringstream sstr;
00308   sstr << "GROUP" << vtkMedUtilities::Separator
00309       << vtkMedUtilities::SimplifyName(meshName)
00310       << vtkMedUtilities::Separator;
00311   if(pointOrCell==OnCell)
00312     sstr << vtkMedUtilities::OnCellName;
00313   else
00314     sstr << vtkMedUtilities::OnPointName;
00315   if(groupName==NULL)
00316     sstr << vtkMedUtilities::Separator
00317         << vtkMedUtilities::NoGroupName;
00318   else
00319     sstr << vtkMedUtilities::Separator
00320         << vtkMedUtilities::SimplifyName(groupName);
00321 
00322   return sstr.str();
00323 }
00324 
00325 const std::string vtkMedUtilities::EntityKey(const vtkMedEntity& entity)
00326 {
00327   ostringstream sstr;
00328   sstr << "CELL_TYPE" << Separator << EntityName(entity.EntityType)
00329       << Separator<<entity.GeometryName;
00330   return sstr.str();
00331 }
00332 
00333 int vtkMedUtilities::GetNumberOfPoint(med_geometry_type geometry)
00334 {
00335   return geometry%100;
00336 }
00337 
00338 int vtkMedUtilities::GetDimension(med_geometry_type geometry)
00339 {
00340   return geometry/100;
00341 }
00342 
00343 int vtkMedUtilities::GetVTKCellType(med_geometry_type geometry)
00344 {
00345 
00346   switch(geometry)
00347   {
00348     case MED_POINT1:
00349       return VTK_VERTEX;
00350     case MED_SEG2:
00351       return VTK_LINE;
00352     case MED_SEG3:
00353       return VTK_QUADRATIC_EDGE;
00354     case MED_SEG4:
00355       return VTK_CUBIC_LINE;
00356     case MED_TRIA3:
00357       return VTK_TRIANGLE;
00358     case MED_QUAD4:
00359       return VTK_QUAD;
00360     case MED_TRIA6:
00361       return VTK_QUADRATIC_TRIANGLE;
00362     case MED_TRIA7:
00363       return VTK_BIQUADRATIC_TRIANGLE;
00364     case MED_QUAD8:
00365       return VTK_QUADRATIC_QUAD;
00366     case MED_QUAD9:
00367       return VTK_BIQUADRATIC_QUAD;
00368     case MED_TETRA4:
00369       return VTK_TETRA;
00370     case MED_PYRA5:
00371       return VTK_PYRAMID;
00372     case MED_PENTA6:
00373       return VTK_WEDGE;
00374     case MED_HEXA8:
00375       return VTK_HEXAHEDRON;
00376     case MED_TETRA10:
00377       return VTK_QUADRATIC_TETRA;
00378     case MED_OCTA12:
00379       return VTK_HEXAGONAL_PRISM;
00380     case MED_PYRA13:
00381       return VTK_QUADRATIC_PYRAMID;
00382     case MED_PENTA15:
00383       return VTK_QUADRATIC_WEDGE;
00384     case MED_HEXA20:
00385       return VTK_QUADRATIC_HEXAHEDRON;
00386     case MED_HEXA27:
00387       return VTK_TRIQUADRATIC_HEXAHEDRON;
00388     case MED_POLYGON:
00389       return VTK_POLYGON;
00390     case MED_POLYHEDRON:
00391       return VTK_POLYHEDRON;
00392     case MED_NO_GEOTYPE:
00393       return VTK_EMPTY_CELL;
00394     default:
00395       vtkGenericWarningMacro("No vtk type matches " << geometry << ", aborting")
00396       ;
00397       return VTK_EMPTY_CELL;
00398   }
00399 }
00400 
00401 int vtkMedUtilities::MedToVTKIndex(int vtktype, int node)
00402 {
00403   if(vtktype != VTK_TRIQUADRATIC_HEXAHEDRON)
00404     return node;
00405 
00406   static int VTK_TRIQUADRATIC_HEXAHEDRON_MED_TO_VTK_INDEX[27] =
00407     {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
00408      24, 22, 21, 23, 20, 25, 26};
00409 
00410   return VTK_TRIQUADRATIC_HEXAHEDRON_MED_TO_VTK_INDEX[node % 27] + static_cast<int>(27 * floor((double)node / 27));
00411 }
00412 
00413 int vtkMedUtilities::GetNumberOfNodes(med_geometry_type geometry)
00414 {
00415   switch(geometry)
00416   {
00417     case MED_POINT1:
00418       return 1;
00419     case MED_SEG2:
00420       return 2;
00421     case MED_SEG3:
00422       return 3;
00423     case MED_SEG4:
00424       return 4;
00425     case MED_TRIA3:
00426       return 3;
00427     case MED_QUAD4:
00428       return 4;
00429     case MED_TRIA6:
00430       return 6;
00431     case MED_TRIA7:
00432       return 7;
00433     case MED_QUAD8:
00434       return 8;
00435     case MED_QUAD9:
00436       return 9;
00437     case MED_TETRA4:
00438       return 4;
00439     case MED_PYRA5:
00440       return 5;
00441     case MED_PENTA6:
00442       return 5;
00443     case MED_HEXA8:
00444       return 8;
00445     case MED_TETRA10:
00446       return 10;
00447     case MED_OCTA12:
00448       return 12;
00449     case MED_PYRA13:
00450       return 13;
00451     case MED_PENTA15:
00452       return 15;
00453     case MED_HEXA20:
00454       return 20;
00455     case MED_HEXA27:
00456       return 27;
00457     case MED_POLYGON:
00458       return -1;
00459     case MED_POLYHEDRON:
00460       return -1;
00461     case MED_NO_GEOTYPE:
00462       return 0;
00463     default:
00464       vtkGenericWarningMacro("No vtk type matches "
00465                              << vtkMedUtilities::GeometryName(geometry)
00466                              << ", aborting");
00467       return -1;
00468   }
00469 }
00470 
00471 int vtkMedUtilities::GetNumberOfSubEntity(med_geometry_type geometry)
00472 {
00473   switch(geometry)
00474   {
00475     case MED_POINT1:
00476       return 0;
00477     case MED_SEG2:
00478       return 2;
00479     case MED_SEG3:
00480       return 3;
00481     case MED_SEG4:
00482       return 4;
00483     case MED_TRIA3:
00484       return 3;
00485     case MED_QUAD4:
00486       return 4;
00487     case MED_TRIA6:
00488       return 3;
00489     case MED_TRIA7:
00490       return 3;
00491     case MED_QUAD8:
00492       return 4;
00493     case MED_QUAD9:
00494       return 4;
00495     case MED_TETRA4:
00496       return 4;
00497     case MED_PYRA5:
00498       return 5;
00499     case MED_PENTA6:
00500       return 5;
00501     case MED_HEXA8:
00502       return 6;
00503     case MED_TETRA10:
00504       return 4;
00505     case MED_OCTA12:
00506       return 8;
00507     case MED_PYRA13:
00508       return 5;
00509     case MED_PENTA15:
00510       return 5;
00511     case MED_HEXA20:
00512       return 6;
00513     case MED_HEXA27:
00514       return 6;
00515     case MED_POLYGON:
00516       return -1;
00517     case MED_POLYHEDRON:
00518       return -1;
00519     case MED_NO_GEOTYPE:
00520       return 0;
00521     default:
00522       vtkGenericWarningMacro("No vtk type matches "
00523                              << geometry
00524                              << ", aborting");
00525       return -1;
00526   }
00527 }
00528 
00529 med_entity_type vtkMedUtilities::GetSubType(med_entity_type type)
00530 {
00531   switch(type)
00532     {
00533     case MED_CELL:
00534       return MED_DESCENDING_FACE;
00535     case MED_DESCENDING_FACE:
00536       return MED_DESCENDING_EDGE;
00537     case MED_DESCENDING_EDGE:
00538       return MED_NODE;
00539     default:
00540       return MED_NODE;
00541     }
00542 }
00543 
00544 med_geometry_type vtkMedUtilities::GetSubGeometry(
00545     med_geometry_type geometry, int index)
00546 {
00547   switch(geometry)
00548   {
00549     case MED_SEG2:
00550       return MED_POINT1;
00551     case MED_SEG3:
00552       return MED_POINT1;
00553     case MED_SEG4:
00554       return MED_POINT1;
00555 
00556     case MED_TRIA3:
00557       return MED_SEG2;
00558     case MED_TRIA6:
00559       return MED_SEG3;
00560     case MED_TRIA7:
00561       return MED_SEG3;
00562 
00563     case MED_QUAD4:
00564       return MED_SEG2;
00565     case MED_QUAD8:
00566       return MED_SEG3;
00567     case MED_QUAD9:
00568       return MED_SEG3;
00569 
00570     case MED_TETRA4:
00571       return MED_TRIA3;
00572     case MED_TETRA10:
00573       return MED_TRIA6;
00574 
00575     case MED_PYRA5:
00576       {
00577       if(index==0)
00578         return MED_QUAD4;
00579       return MED_TRIA3;
00580       }
00581     case MED_PYRA13:
00582       {
00583       if(index==0)
00584         return MED_QUAD8;
00585       else
00586         return MED_TRIA6;
00587       }
00588 
00589     case MED_PENTA6:
00590       {
00591       if(index==0||index==1)
00592         return MED_TRIA3;
00593       else
00594         return MED_QUAD4;
00595       }
00596     case MED_PENTA15:
00597       {
00598       if(index==0||index==1)
00599         return MED_TRIA6;
00600       else
00601         return MED_QUAD8;
00602       }
00603 
00604     case MED_HEXA8:
00605       return MED_QUAD4;
00606     case MED_HEXA20:
00607       return MED_QUAD8;
00608     case MED_HEXA27:
00609       return MED_QUAD9;
00610     default:
00611       return MED_NONE;
00612   }
00613 }
00614 
00615 int vtkMedUtilities::FormatPolyhedronForVTK(
00616     vtkMedFamilyOnEntityOnProfile* foep, vtkIdType index,
00617     vtkIdList* ids )
00618 {
00619   vtkMedEntityArray* array = foep->GetFamilyOnEntity()->GetEntityArray();
00620   vtkMedIntArray* conn = array->GetConnectivityArray();
00621   vtkMedIntArray* faceIndex = array->GetFaceIndex();
00622   vtkMedIntArray* nodeIndex = array->GetNodeIndex();
00623   med_int start = faceIndex->GetValue(index)-1;
00624   med_int end = faceIndex->GetValue(index+1)-1;
00625 
00626   // The format for the Polyhedrons is:
00627   //(numCellFaces, numFace0Pts, id1, id2, id3, numFace1Pts,id1, id2, id3, ...)
00628   ids->Reset();
00629 
00630   if (array->GetConnectivity()==MED_NODAL)
00631     {
00632     ids->InsertNextId(end-start-1);
00633     for (int ff = start; ff<end; ff++)
00634       {
00635       med_int fstart = nodeIndex->GetValue(ff)-1;
00636       med_int fend = nodeIndex->GetValue(ff+1)-1;
00637       ids->InsertNextId(fend-fstart);
00638       for (med_int pt = fstart; pt<fend; pt++)
00639         {
00640         vtkIdType realIndex = foep->GetVTKPointIndex(conn->GetValue(pt)-1);
00641         if(realIndex < 0)
00642           {
00643           vtkGenericWarningMacro("this polyhedron is not on this profile");
00644           foep->SetValid(0);
00645           return 0;
00646           }
00647         ids->InsertNextId(realIndex);
00648         }
00649       }
00650     }
00651 
00652   if (array->GetConnectivity()==MED_DESCENDING)
00653     {
00654     ids->InsertNextId(end-start);
00655     vtkSmartPointer<vtkIdList> subIds = vtkSmartPointer<vtkIdList>::New();
00656 
00657     for (int i = 0 ; i<nodeIndex->GetSize(); i++)
00658       {
00659       int numPoints =
00660           vtkMedUtilities::GetNumberOfSubEntity(nodeIndex->GetValue(i));
00661       ids->InsertNextId(numPoints);
00662 
00663       vtkMedEntity entity;
00664       entity.EntityType = MED_DESCENDING_FACE;
00665       entity.GeometryType = nodeIndex->GetValue(i);
00666 
00667       vtkMedEntityArray* theFaces =
00668           array->GetParentGrid()->GetEntityArray(entity);
00669 
00670       theFaces->GetCellVertices(conn->GetValue(i)-1, subIds);
00671 
00672       for (int j = 0 ; j< numPoints; j++)
00673         {
00674         vtkIdType realIndex = foep->GetVTKPointIndex(subIds->GetId(j));
00675         if(realIndex < 0)
00676           {
00677           vtkGenericWarningMacro("this polyhedron is not on this profile");
00678           return 0;
00679           }
00680         ids->InsertNextId(realIndex);
00681         }
00682       }
00683     }
00684   return 1;
00685 }
00686 
00687 void vtkMedUtilities::SplitGroupKey(const char* name, vtkstd::string& mesh,
00688     vtkstd::string& entity, vtkstd::string& group)
00689 {
00690   vtkstd::string remain;
00691   remain=name;
00692   mesh="*";
00693   entity="*";
00694   group="*";
00695   vtkstd::string header="*";
00696 
00697   if(remain=="*")
00698     {
00699     return;
00700     }
00701   vtkstd::string::size_type pos;
00702   // First get the header, which must be "GROUP"
00703   pos=remain.find_first_of(vtkMedUtilities::Separator);
00704   header=remain.substr(0, pos);
00705   remain=remain.substr(pos+1, remain.size()-pos-1);
00706 
00707   // then get the mesh name
00708   pos=remain.find_first_of(vtkMedUtilities::Separator);
00709   mesh=remain.substr(0, pos);
00710   if(mesh=="*"||pos==remain.size()-1)
00711     return;
00712   remain=remain.substr(pos+1, remain.size()-pos-1);
00713 
00714   // then the entity name (OnPoint or OnCell)
00715   pos=remain.find_first_of(vtkMedUtilities::Separator);
00716   entity=remain.substr(0, pos);
00717   if(entity=="*"||pos==remain.size()-1)
00718     return;
00719 
00720   // then the group
00721   group=remain.substr(pos+1, remain.size()-pos-1);
00722 }
00723 
00724 int vtkMedUtilities::GetParentNodeIndex(med_geometry_type parentGeometry,
00725     int subEntityIndex, int subEntityNodeIndex)
00726 {
00727   switch(parentGeometry)
00728   {
00729     case MED_TRIA3:
00730     case MED_TRIA6:
00731     case MED_TRIA7:
00732       return MED_TRIA_CHILD_TO_PARENT_INDEX[subEntityIndex][subEntityNodeIndex];
00733     case MED_QUAD4:
00734     case MED_QUAD8:
00735     case MED_QUAD9:
00736       return MED_QUAD_CHILD_TO_PARENT_INDEX[subEntityIndex][subEntityNodeIndex];
00737     case MED_TETRA4:
00738     case MED_TETRA10:
00739       return MED_TETRA_CHILD_TO_PARENT_INDEX[subEntityIndex][subEntityNodeIndex];
00740     case MED_PYRA5:
00741     case MED_PYRA13:
00742       return MED_PYRA_CHILD_TO_PARENT_INDEX[subEntityIndex][subEntityNodeIndex];
00743     case MED_PENTA6:
00744     case MED_PENTA15:
00745       return MED_PENTA_CHILD_TO_PARENT_INDEX[subEntityIndex][subEntityNodeIndex];
00746     case MED_HEXA8:
00747     case MED_HEXA20:
00748     case MED_HEXA27:
00749       return MED_HEXA_CHILD_TO_PARENT_INDEX[subEntityIndex][subEntityNodeIndex];
00750   }
00751   return -1;
00752 }
00753 
00754 void vtkMedUtilities::ProjectConnectivity(med_geometry_type parentGeometry,
00755     vtkIdList* parentIds, vtkIdList* subEntityIds, int subEntityIndex, bool invert)
00756 {
00757   for(int subEntityNodeIndex=0; subEntityNodeIndex
00758       <subEntityIds->GetNumberOfIds(); subEntityNodeIndex++)
00759     {
00760     int realIndex = subEntityNodeIndex;
00761     if(invert)
00762       realIndex = subEntityIds->GetNumberOfIds() - subEntityNodeIndex - 1;
00763     parentIds->SetId(GetParentNodeIndex(parentGeometry, subEntityIndex,
00764         subEntityNodeIndex), subEntityIds->GetId(realIndex));
00765     }
00766 }
00767 
00768 std::string vtkMedUtilities::GetModeKey(int index, double frequency, int maxindex)
00769 {
00770   std::ostringstream key;
00771   key<<"[";
00772   if(maxindex > 0)
00773     {
00774       int maxdecim = (int)floor(log(1.0*maxindex)/log(10.0));
00775     int decim = 0;
00776     if(index > 0)
00777       {
00778         decim = (int)floor(log(1.0*index)/log(10.0));
00779       }
00780     for(int i=decim; i<maxdecim; i++)
00781       {
00782       key << "0";
00783       }
00784     }
00785 
00786   key<<index<<"] "<<frequency;
00787   return key.str();
00788 }
00789 
00790 int vtkMedUtilities::GetModeFromKey(const char* key, int& index,
00791     double& frequency)
00792 {
00793   const std::string k(key);
00794   size_t index_start=k.find("[");
00795   size_t index_end=k.find("]");
00796   const string index_string=k.substr(index_start, index_end);
00797   stringstream indexsstr;
00798   indexsstr<<index_string;
00799   indexsstr>>index;
00800   const string freq_string=k.substr(index_end+1, string::npos);
00801   stringstream freqsstr;
00802   freqsstr<<freq_string;
00803   freqsstr>>frequency;
00804   return 1;
00805 }
00806 
00807 vtkMultiBlockDataSet* vtkMedUtilities::GetParent(vtkMultiBlockDataSet* root,
00808                                 vtkStringArray* path)
00809 {
00810     vtkMultiBlockDataSet* output=root;
00811     vtkMultiBlockDataSet* parent=output;
00812     for(int depth = 0; depth<path->GetNumberOfValues(); depth++)
00813       {
00814       vtkStdString parentName = path->GetValue(depth);
00815       bool found=false;
00816       for(int blockId=0; blockId<parent->GetNumberOfBlocks(); blockId++)
00817         {
00818         vtkInformation* metaData=parent->GetMetaData(blockId);
00819         if(metaData->Has(vtkCompositeDataSet::NAME()))
00820           {
00821           const char* blockName=metaData->Get(vtkCompositeDataSet::NAME());
00822           if(parentName==blockName &&
00823               vtkMultiBlockDataSet::SafeDownCast(
00824                   parent->GetBlock(blockId))!=NULL)
00825             {
00826             parent=vtkMultiBlockDataSet::SafeDownCast(parent->GetBlock(blockId));
00827             found=true;
00828             break;
00829             }
00830           }
00831         }
00832       if (!found)
00833         {
00834         // If I am here, it means that I did not find any block with the good name, create one
00835         int nb=parent->GetNumberOfBlocks();
00836         vtkMultiBlockDataSet* block=vtkMultiBlockDataSet::New();
00837         parent->SetBlock(nb, block);
00838         block->Delete();
00839         parent->GetMetaData(nb)->Set(vtkCompositeDataSet::NAME(),
00840             parentName.c_str());
00841         parent=block;
00842         }
00843       }
00844     return parent;
00845 }
00846 
00847 int vtkMedUtilities::SizeOf(med_attribute_type type)
00848 {
00849   switch(type)
00850     {
00851     case MED_ATT_FLOAT64 : return sizeof(med_float);
00852     case MED_ATT_INT : return sizeof(med_int);
00853     case MED_ATT_NAME : return MED_NAME_SIZE * sizeof(char);
00854     }
00855   return 0;
00856 }
00857 
00858 bool operator==(const vtkMedComputeStep& cs0, const vtkMedComputeStep& cs1)
00859 {
00860   return cs0.IterationIt == cs1.IterationIt && cs0.TimeIt == cs1.TimeIt;
00861 }
00862 
00863 bool operator!=(const vtkMedComputeStep& cs0, const vtkMedComputeStep& cs1)
00864 {
00865   return cs0.IterationIt != cs1.IterationIt || cs0.TimeIt != cs1.TimeIt;
00866 }
00867 
00868 bool operator<(const vtkMedComputeStep& cs0, const vtkMedComputeStep& cs1)
00869 {
00870   if(cs0.IterationIt != cs1.IterationIt)
00871     return cs0.IterationIt < cs1.IterationIt;
00872   return cs0.TimeIt < cs1.TimeIt;
00873 }
00874 
00875 bool operator==(const vtkMedEntity& e0, const vtkMedEntity& e1)
00876 {
00877   return e0.EntityType == e1.EntityType && e0.GeometryType == e1.GeometryType;
00878 }
00879 
00880 bool operator!=(const vtkMedEntity& e0, const vtkMedEntity& e1)
00881 {
00882   return e0.EntityType != e1.EntityType || e0.GeometryType != e1.GeometryType;
00883 }
00884 
00885 bool operator<(const vtkMedEntity& e0, const vtkMedEntity& e1)
00886 {
00887   if(e0.EntityType != e1.EntityType)
00888     return e0.EntityType < e1.EntityType;
00889   return e0.GeometryType < e1.GeometryType;
00890 }