Back to index

salome-smesh  6.5.0
MeshCut_Utils.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2006-2012  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 "MeshCut_Utils.hxx"
00021 
00022 #include <iostream>
00023 #include <string>
00024 #include <sstream>
00025 #include <cstdlib>
00026 #include <cstring>
00027 #include <ctime>
00028 
00029 using namespace std;
00030 using namespace MESHCUT;
00031 
00032 //string pathUsers = (string) "/var/www/XMeshLab/users/";
00033 
00034 bool MESHCUT::estUnTypeMaille(std::string S)
00035 {
00036   if (S == (string) "POI1" || S == (string) "SEG2" || S == (string) "SEG3" || S == (string) "TRIA3" || S
00037       == (string) "TRIA6" || S == (string) "QUAD4" || S == (string) "QUAD8" || S == (string) "QUAD9" || S
00038       == (string) "TETRA4" || S == (string) "TETRA10" || S == (string) "PYRAM5" || S == (string) "PYRAM13" || S
00039       == (string) "PENTA6" || S == (string) "PENTA15" || S == (string) "HEXA8" || S == (string) "HEXA20" || S
00040       == (string) "HEXA27")
00041     return true;
00042   else
00043     return false;
00044 }
00045 
00046 void MESHCUT::ERREUR(const char* msg)
00047 {
00048   cout << endl << "====== ERROR ====== " << msg << endl << endl;
00049   exit(-1);
00050 }
00051 
00052 char* MESHCUT::string2char(std::string str)
00053 {
00054   // créer le buffer pour copier la chaîne
00055   size_t size = str.size() + 1;
00056   char* buffer = new char[size];
00057   // copier la chaîne
00058   strncpy(buffer, str.c_str(), size);
00059 
00060   // libérer la mémoire
00061   //delete [] buffer;
00062 
00063   return buffer;
00064 }
00065 
00066 std::string MESHCUT::int2string(int k)
00067 {
00068   std::stringstream oss;
00069   oss << k;
00070   return oss.str(); //  oss.seekp (ios_base::beg);
00071 }
00072 
00073 float MESHCUT::char2float(const char* ch)
00074 {
00075   return atof(ch);
00076 }
00077 
00078 std::string MESHCUT::float2string(float f)
00079 {
00080   stringstream buf;
00081   buf << fixed << f;
00082   string s = buf.str();
00083   return s;
00084 }
00085 
00086 bool MESHCUT::appartient(std::string e, std::string tableau[], int taille)
00087 {
00088   for (int i = 0; i < taille; i++)
00089     if (tableau[i] == e)
00090       return true;
00091   return false;
00092 }
00093 
00094 float MESHCUT::arrondi(float x)
00095 {
00096   if (x > 0 && x < 1.0e-5)
00097     return 0;
00098   else if (x < 0 && x > -1.0e-5)
00099     return 0;
00100   else
00101     return x;
00102 }
00103 
00104 int MESHCUT::numNoeudPointe(std::string b1, std::string b2, std::string b3)
00105 {
00106   if (b1 == "1" && b2 == "1" && b3 == "2")
00107     return 2;
00108   else if (b1 == "1" && b2 == "2" && b3 == "1")
00109     return 1;
00110   else if (b1 == "1" && b2 == "2" && b3 == "2")
00111     return 2;
00112   else if (b1 == "2" && b2 == "1" && b3 == "1")
00113     return 3;
00114   else if (b1 == "2" && b2 == "1" && b3 == "2")
00115     return 3;
00116   else if (b1 == "2" && b2 == "2" && b3 == "1")
00117     return 1;
00118   else
00119     return -1;
00120 }
00121 
00122 std::string MESHCUT::strip(std::string S)
00123 {
00124   if (S.empty())
00125     return S;
00126   int startIndex = S.find_first_not_of(" ");
00127   int endIndex = S.find_last_not_of(" ");
00128   return S.substr(startIndex, (endIndex - startIndex + 1));
00129 }
00130 
00131 std::string MESHCUT::entierSur10_g(int i)
00132 {
00133   if (i > 999999999)
00134     ERREUR("trying to write a number superior to 999999999 on more than 10 chars");
00135   if (i < 10)
00136     return int2string(i) + (string) "         ";
00137   else if (i < 100)
00138     return int2string(i) + (string) "        ";
00139   else if (i < 1000)
00140     return int2string(i) + (string) "       ";
00141   else if (i < 10000)
00142     return int2string(i) + (string) "      ";
00143   else if (i < 100000)
00144     return int2string(i) + (string) "     ";
00145   else if (i < 1000000)
00146     return int2string(i) + (string) "    ";
00147   else if (i < 10000000)
00148     return int2string(i) + (string) "   ";
00149   else if (i < 100000000)
00150     return int2string(i) + (string) "  ";
00151   else if (i < 1000000000)
00152     return int2string(i) + (string) " ";
00153   else
00154     return int2string(i);
00155 }
00156 
00157 std::string MESHCUT::entierSur10_d(int i)
00158 {
00159   if (i > 999999999)
00160     ERREUR("trying to write a number superior to 999999999 on more than 10 chars");
00161   if (i < 10)
00162     return (string) "         " + int2string(i);
00163   else if (i < 100)
00164     return (string) "        " + int2string(i);
00165   else if (i < 1000)
00166     return (string) "       " + int2string(i);
00167   else if (i < 10000)
00168     return (string) "      " + int2string(i);
00169   else if (i < 100000)
00170     return (string) "     " + int2string(i);
00171   else if (i < 1000000)
00172     return (string) "    " + int2string(i);
00173   else if (i < 10000000)
00174     return (string) "   " + int2string(i);
00175   else if (i < 100000000)
00176     return (string) "  " + int2string(i);
00177   else if (i < 1000000000)
00178     return (string) " " + int2string(i);
00179   else
00180     return int2string(i);
00181 }
00182 
00183 std::string MESHCUT::typeEnsight(std::string type)
00184 {
00185   if (type == (string) "POI1")
00186     return (string) "point";
00187   else if (type == (string) "SEG2")
00188     return (string) "bar2";
00189   else if (type == (string) "SEG3")
00190     return (string) "bar2";// ATTENTION, triche!
00191   else if (type == (string) "TRIA3")
00192     return (string) "tria3";
00193   else if (type == (string) "TRIA6")
00194     return (string) "tria3";// ATTENTION, triche!
00195   else if (type == (string) "QUAD4")
00196     return (string) "quad4";
00197   else if (type == (string) "QUAD8")
00198     return (string) "quad4"; // ATTENTION, triche!
00199   else if (type == (string) "QUAD9")
00200     ERREUR("Type QUAD9 not supported by Ensight");
00201   else if (type == (string) "TETRA4")
00202     return (string) "tetra4";
00203   else if (type == (string) "TETRA10")
00204     return (string) "tetra4"; // ATTENTION, triche!
00205   else if (type == (string) "PYRAM5")
00206     return (string) "pyramid5";
00207   else if (type == (string) "PYRAM13")
00208     return (string) "pyramid5"; // ATTENTION, triche!
00209   else if (type == (string) "PENTA6")
00210     return (string) "penta6";
00211   else if (type == (string) "PENTA15")
00212     return (string) "penta6"; // ATTENTION, triche!
00213   else if (type == (string) "HEXA8")
00214     return (string) "hexa8";
00215   else if (type == (string) "HEXA20")
00216     return (string) "hexa8"; // ATTENTION, triche!
00217   else if (type == (string) "HEXA27")
00218     ERREUR("Type HEXA27 not supported by Ensight");
00219   else
00220     ERREUR("Type of element not accepted (method \"typeEnsight\"");
00221   return (string) "";
00222 }
00223 
00224 int MESHCUT::Nnoeuds(TYPE_MAILLE type)
00225 {
00226   switch (type)
00227   {
00228     case POI1:
00229       {
00230         return 1;
00231         break;
00232       }
00233     case SEG2:
00234       {
00235         return 2;
00236         break;
00237       }
00238     case SEG3:
00239       {
00240         return 3;
00241         break;
00242       }
00243     case TRIA3:
00244       {
00245         return 3;
00246         break;
00247       }
00248     case TRIA6:
00249       {
00250         return 6;
00251         break;
00252       }
00253     case QUAD4:
00254       {
00255         return 4;
00256         break;
00257       }
00258     case QUAD8:
00259       {
00260         return 8;
00261         break;
00262       }
00263       //case QUAD9:                   { return 9; break; }
00264     case TETRA4:
00265       {
00266         return 4;
00267         break;
00268       }
00269     case TETRA10:
00270       {
00271         return 10;
00272         break;
00273       }
00274     case PYRAM5:
00275       {
00276         return 5;
00277         break;
00278       }
00279     case PYRAM13:
00280       {
00281         return 13;
00282         break;
00283       }
00284     case PENTA6:
00285       {
00286         return 6;
00287         break;
00288       }
00289     case PENTA15:
00290       {
00291         return 15;
00292         break;
00293       }
00294     case HEXA8:
00295       {
00296         return 8;
00297         break;
00298       }
00299     case HEXA20:
00300       {
00301         return 20;
00302         break;
00303       }
00304       //case HEXA27:                      { return 27;    break; }
00305     default:
00306       ERREUR("Type of elem not accepted (method Nnoeuds)");
00307   }
00308   return 0;
00309 }
00310 
00311 int MESHCUT::NnoeudsGeom(TYPE_MAILLE type)
00312 {
00313   switch (type)
00314   {
00315     case POI1:
00316       {
00317         return 1;
00318         break;
00319       }
00320     case SEG2:
00321       {
00322         return 2;
00323         break;
00324       }
00325     case SEG3:
00326       {
00327         return 2;
00328         break;
00329       }
00330     case TRIA3:
00331       {
00332         return 3;
00333         break;
00334       }
00335     case TRIA6:
00336       {
00337         return 3;
00338         break;
00339       }
00340     case QUAD4:
00341       {
00342         return 4;
00343         break;
00344       }
00345     case QUAD8:
00346       {
00347         return 4;
00348         break;
00349       }
00350       //case QUAD9:                   { return 9; break; }
00351     case TETRA4:
00352       {
00353         return 4;
00354         break;
00355       }
00356     case TETRA10:
00357       {
00358         return 4;
00359         break;
00360       }
00361     case PYRAM5:
00362       {
00363         return 5;
00364         break;
00365       }
00366     case PYRAM13:
00367       {
00368         return 5;
00369         break;
00370       }
00371     case PENTA6:
00372       {
00373         return 6;
00374         break;
00375       }
00376     case PENTA15:
00377       {
00378         return 6;
00379         break;
00380       }
00381     case HEXA8:
00382       {
00383         return 8;
00384         break;
00385       }
00386     case HEXA20:
00387       {
00388         return 8;
00389         break;
00390       }
00391       //case HEXA27:                      { return 27;    break; }
00392     default:
00393       ERREUR("Type of elem not accepted (method NnoeudsGeom)");
00394   }
00395   return 0;
00396 }
00397 
00398 int MESHCUT::codeGMSH(std::string type)
00399 {
00400   if (type == (string) "POI1")
00401     ERREUR("POI1 not taken into account by GMSH");
00402   else if (type == (string) "SEG2")
00403     return 1;
00404   else if (type == (string) "SEG3")
00405     return 8;
00406   else if (type == (string) "TRIA3")
00407     return 2;
00408   else if (type == (string) "TRIA6")
00409     return 9;
00410   else if (type == (string) "QUAD4")
00411     return 3;
00412   else if (type == (string) "QUAD8")
00413     return 16;
00414   else if (type == (string) "QUAD9")
00415     return 10;
00416   else if (type == (string) "TETRA4")
00417     return 4;
00418   else if (type == (string) "TETRA10")
00419     return 11;
00420   else if (type == (string) "PYRAM5")
00421     return 7;
00422   else if (type == (string) "PENTA6")
00423     return 6;
00424   else if (type == (string) "PENTA15")
00425     return 18;
00426   else if (type == (string) "HEXA8")
00427     return 5;
00428   else if (type == (string) "HEXA20")
00429     return 17;
00430   else if (type == (string) "HEXA27")
00431     return 12;
00432   else
00433     ERREUR("Type of elem not accepted (method codeGMSH)");
00434   return 0;
00435 }
00436 
00437 std::string MESHCUT::floatEnsight(float x)
00438 {
00439   char buf[12];
00440   string s;
00441   if (x < 0.0)
00442     sprintf(buf, "%1.5E", x);
00443   else
00444     sprintf(buf, " %1.5E", x);
00445   s = (string) buf;
00446   s.erase(10, 1);
00447   return s;
00448 }
00449 
00450 bool MESHCUT::typeComplexe(std::string type)
00451 {
00452   if (type == (string) "SEG3")
00453     return true;
00454   else if (type == (string) "TRIA6")
00455     return true;
00456   else if (type == (string) "QUAD8")
00457     return true;
00458   else if (type == (string) "QUAD9")
00459     return true;
00460   else if (type == (string) "TETRA10")
00461     return true;
00462   else if (type == (string) "PYRAM13")
00463     return true;
00464   else if (type == (string) "PENTA15")
00465     return true;
00466   else if (type == (string) "HEXA20")
00467     return true;
00468   else if (type == (string) "HEXA27")
00469     return true;
00470   else
00471     return false;
00472 }
00473 
00474 std::string MESHCUT::ASTER8(std::string s)
00475 {
00476   if (s.size() == 0)
00477     return (s + (string) "        ");
00478   else if (s.size() == 1)
00479     return (s + (string) "       ");
00480   else if (s.size() == 2)
00481     return (s + (string) "      ");
00482   else if (s.size() == 3)
00483     return (s + (string) "     ");
00484   else if (s.size() == 4)
00485     return (s + (string) "    ");
00486   else if (s.size() == 5)
00487     return (s + (string) "   ");
00488   else if (s.size() == 6)
00489     return (s + (string) "  ");
00490   else if (s.size() == 7)
00491     return (s + (string) " ");
00492   else if (s.size() == 8)
00493     return (s);
00494   else
00495     ERREUR("More than 8 char for an ASTER string");
00496   return (s);
00497 }
00498 
00511 float MESHCUT::dObservateur(float a, float b, float c)
00512 {
00513   return (max(a, b) / 2.0 + c);
00514 }
00515 
00516 int MESHCUT::copieFichier(std::string source, std::string cible)
00517 {
00518   FILE *fsource, *fcible;
00519   char buffer[512];
00520   int NbLu;
00521   if ((fsource = fopen(string2char(source), "rb")) == NULL)
00522     return -1;
00523   if ((fcible = fopen(string2char(cible), "wb")) == NULL)
00524     {
00525       fclose(fsource);
00526       return -2;
00527     }
00528   while ((NbLu = fread(buffer, 1, 512, fsource)) != 0)
00529     fwrite(buffer, 1, NbLu, fcible);
00530   fclose(fcible);
00531   fclose(fsource);
00532   return 0;
00533 }
00534 
00535 med_geometry_type MESHCUT::InstanceMGE(TYPE_MAILLE TYPE)
00536 {
00537   med_geometry_type typeBanaliseMED;
00538 
00539   switch (TYPE)
00540   {
00541     case POI1:
00542       typeBanaliseMED = MED_POINT1;
00543       break; // Attention, piège !
00544     case SEG2:
00545       typeBanaliseMED = MED_SEG2;
00546       break;
00547     case SEG3:
00548       typeBanaliseMED = MED_SEG3;
00549       break;
00550     case TRIA3:
00551       typeBanaliseMED = MED_TRIA3;
00552       break;
00553     case TRIA6:
00554       typeBanaliseMED = MED_TRIA6;
00555       break;
00556     case QUAD4:
00557       typeBanaliseMED = MED_QUAD4;
00558       break;
00559     case QUAD8:
00560       typeBanaliseMED = MED_QUAD8;
00561       break;
00562     case TETRA4:
00563       typeBanaliseMED = MED_TETRA4;
00564       break;
00565     case TETRA10:
00566       typeBanaliseMED = MED_TETRA10;
00567       break;
00568     case PYRAM5:
00569       typeBanaliseMED = MED_PYRA5;
00570       break; // Attention, piège !
00571     case PYRAM13:
00572       typeBanaliseMED = MED_PYRA13;
00573       break; // Attention, piège !
00574     case PENTA6:
00575       typeBanaliseMED = MED_PENTA6;
00576       break;
00577     case PENTA15:
00578       typeBanaliseMED = MED_PENTA15;
00579       break;
00580     case HEXA8:
00581       typeBanaliseMED = MED_HEXA8;
00582       break;
00583     case HEXA20:
00584       typeBanaliseMED = MED_HEXA20;
00585       break;
00586     default:
00587       ERREUR("Method InstanceMGE, unknown type ");
00588   }
00589   return typeBanaliseMED;
00590 }
00591 
00592 int MESHCUT::chrono()
00593 {
00594   return clock() / CLOCKS_PER_SEC;
00595 }
00596 
00597 TYPE_MAILLE MESHCUT::typeMaille(std::string type)
00598 {
00599   if (type == (string) "POI1")
00600     return POI1;
00601   else if (type == (string) "SEG2")
00602     return SEG2;
00603   else if (type == (string) "SEG3")
00604     return SEG3;
00605   else if (type == (string) "TRIA3")
00606     return TRIA3;
00607   else if (type == (string) "TRIA6")
00608     return TRIA6;
00609   else if (type == (string) "QUAD4")
00610     return QUAD4;
00611   else if (type == (string) "QUAD8")
00612     return QUAD8;
00613   else if (type == (string) "TETRA4")
00614     return TETRA4;
00615   else if (type == (string) "TETRA10")
00616     return TETRA10;
00617   else if (type == (string) "PYRAM5")
00618     return PYRAM5;
00619   else if (type == (string) "PYRAM13")
00620     return PYRAM13;
00621   else if (type == (string) "PENTA6")
00622     return PENTA6;
00623   else if (type == (string) "PENTA15")
00624     return PENTA15;
00625   else if (type == (string) "HEXA8")
00626     return HEXA8;
00627   else if (type == (string) "HEXA20")
00628     return HEXA20;
00629   else
00630     ERREUR("ERROR method typeMaille, unknown type");
00631   return POI1;
00632 }
00633 
00634 std::string MESHCUT::MGE2string(med_geometry_type MGE)
00635 {
00636   if (MGE == MED_NONE)
00637     return (string) "NOEUD";
00638   else if (MGE == MED_POINT1)
00639     return (string) "POI1";
00640   else if (MGE == MED_SEG2)
00641     return (string) "SEG2";
00642   else if (MGE == MED_SEG3)
00643     return (string) "SEG3";
00644   else if (MGE == MED_TRIA3)
00645     return (string) "TRIA3";
00646   else if (MGE == MED_TRIA6)
00647     return (string) "TRIA6";
00648   else if (MGE == MED_QUAD4)
00649     return (string) "QUAD4";
00650   else if (MGE == MED_QUAD8)
00651     return (string) "QUAD8";
00652   else if (MGE == MED_TETRA4)
00653     return (string) "TETRA4";
00654   else if (MGE == MED_TETRA10)
00655     return (string) "TETRA10";
00656   else if (MGE == MED_PYRA5)
00657     return (string) "PYRAM5";
00658   else if (MGE == MED_PYRA13)
00659     return (string) "PYRAM13";
00660   else if (MGE == MED_PENTA6)
00661     return (string) "PENTA6";
00662   else if (MGE == MED_PENTA15)
00663     return (string) "PENTA15";
00664   else if (MGE == MED_HEXA8)
00665     return (string) "HEXA8";
00666   else if (MGE == MED_HEXA20)
00667     return (string) "HEXA20";
00668   else
00669     ERREUR("ERROR method MGE2string, unknown type");
00670   return (string) "NOEUD";
00671 }
00672 
00673 std::string MESHCUT::TM2string(TYPE_MAILLE MGE)
00674 {
00675   if (MGE == POI1)
00676     return (string) "POI1";
00677   else if (MGE == SEG2)
00678     return (string) "SEG2";
00679   else if (MGE == SEG3)
00680     return (string) "SEG3";
00681   else if (MGE == TRIA3)
00682     return (string) "TRIA3";
00683   else if (MGE == TRIA6)
00684     return (string) "TRIA6";
00685   else if (MGE == QUAD4)
00686     return (string) "QUAD4";
00687   else if (MGE == QUAD8)
00688     return (string) "QUAD8";
00689   else if (MGE == TETRA4)
00690     return (string) "TETRA4";
00691   else if (MGE == TETRA10)
00692     return (string) "TETRA10";
00693   else if (MGE == PYRAM5)
00694     return (string) "PYRAM5";
00695   else if (MGE == PYRAM13)
00696     return (string) "PYRAM13";
00697   else if (MGE == PENTA6)
00698     return (string) "PENTA6";
00699   else if (MGE == PENTA15)
00700     return (string) "PENTA15";
00701   else if (MGE == HEXA8)
00702     return (string) "HEXA8";
00703   else if (MGE == HEXA20)
00704     return (string) "HEXA20";
00705   else
00706     ERREUR("ERROR method TM2string, unknown type");
00707   return (string) "POI1";
00708 }
00709 
00710 TYPE_MAILLE MESHCUT::string2TM(std::string stm)
00711 {
00712   if (stm == (string) "POI1")
00713     return POI1;
00714   else if (stm == (string) "SEG2")
00715     return SEG2;
00716   else if (stm == (string) "SEG3")
00717     return SEG3;
00718   else if (stm == (string) "TRIA3")
00719     return TRIA3;
00720   else if (stm == (string) "TRIA6")
00721     return TRIA6;
00722   else if (stm == (string) "QUAD4")
00723     return QUAD4;
00724   else if (stm == (string) "QUAD8")
00725     return QUAD8;
00726   else if (stm == (string) "TETRA4")
00727     return TETRA4;
00728   else if (stm == (string) "TETRA10")
00729     return TETRA10;
00730   else if (stm == (string) "PYRAM5")
00731     return PYRAM5;
00732   else if (stm == (string) "PYRAM13")
00733     return PYRAM13;
00734   else if (stm == (string) "PENTA6")
00735     return PENTA6;
00736   else if (stm == (string) "PENTA15")
00737     return PENTA15;
00738   else if (stm == (string) "HEXA8")
00739     return HEXA8;
00740   else if (stm == (string) "HEXA20")
00741     return HEXA20;
00742   else
00743     ERREUR("ERROR method string2TM, unknown type");
00744   return POI1;
00745 }
00746 
00747 std::string MESHCUT::coordIndex_ILS(TYPE_MAILLE tm)
00748 {
00749   if (tm == SEG2)
00750     return (string) " 0,1 ";
00751   else if (tm == SEG3)
00752     return (string) " 0,1 "; // Idem SEG2
00753   else if (tm == TRIA3)
00754     return (string) " 0,1,2,0 ";
00755   else if (tm == TRIA6)
00756     return (string) " 0,1,2,0 ";
00757   else if (tm == QUAD4)
00758     return (string) " 0,1,2,3,0 ";
00759   else if (tm == QUAD8)
00760     return (string) " 0,1,2,3,0 ";
00761   else if (tm == TETRA4)
00762     return (string) " 0,1,2,0,-1, 0,3,-1, 1,3,-1, 2,3,-1 ";
00763   else if (tm == TETRA10)
00764     return (string) " 0,1,2,0,-1, 0,3,-1, 1,3,-1, 2,3,-1 ";
00765   else if (tm == PYRAM5)
00766     return (string) " 0,1,2,3,0,-1, 0,4,-1, 1,4,-1, 2,4,-1, 3,4,-1 ";
00767   else if (tm == PYRAM13)
00768     return (string) " 0,1,2,3,0,-1, 0,4,-1, 1,4,-1, 2,4,-1, 3,4,-1 ";
00769   else if (tm == PENTA6)
00770     return (string) " 0,1,2,0,-1, 3,4,5,3,-1, 0,3,-1, 1,4,-1, 2,5,-1 ";
00771   else if (tm == PENTA15)
00772     return (string) " 0,1,2,0,-1, 3,4,5,3,-1, 0,3,-1, 1,4,-1, 2,5,-1 ";
00773   else if (tm == HEXA8)
00774     return (string) " 0,1,2,3,0,-1, 4,5,6,7,4,-1, 0,4,-1, 1,5,-1, 2,6,-1, 3,7,-1 ";
00775   else if (tm == HEXA20)
00776     return (string) " 0,1,2,3,0,-1, 4,5,6,7,4,-1, 0,4,-1, 1,5,-1, 2,6,-1, 3,7,-1 ";
00777   else
00778     return (string) "";
00779 }
00780 
00781 std::string MESHCUT::coordIndex_IFS(TYPE_MAILLE tm)
00782 {
00783   if (tm == SEG2)
00784     return (string) "  ";
00785   else if (tm == SEG3)
00786     return (string) "  "; // Idem SEG2
00787   else if (tm == TRIA3)
00788     return (string) " 0,1,2,0,-1, 0,2,1,0,-1 ";
00789   else if (tm == TRIA6)
00790     return (string) " 0,1,2,0,-1, 0,2,1,0,-1 ";
00791   else if (tm == QUAD4)
00792     return (string) " 0,1,2,3,0,-1, 0,3,2,1,0,-1 ";
00793   else if (tm == QUAD8)
00794     return (string) " 0,1,2,3,0,-1, 0,3,2,1,0,-1 ";
00795   else if (tm == TETRA4)
00796     return (string) " 0,1,2,0,-1, 0,2,1,0,-1, 0,3,1,0,-1, 0,1,3,0,-1, 1,3,2,1,-1, 1,2,3,1,-1, 0,2,3,0,-1, 0,3,2,0,-1 ";
00797   else if (tm == TETRA10)
00798     return (string) " 0,1,2,0,-1, 0,2,1,0,-1, 0,3,1,0,-1, 0,1,3,0,-1, 1,3,2,1,-1, 1,2,3,1,-1, 0,2,3,0,-1, 0,3,2,0,-1 ";
00799   else if (tm == PYRAM5)
00800     return (string) " 0,1,2,3,0,-1, 0,3,2,1,0,-1, 0,1,4,0,-1, 0,4,1,0,-1, 1,2,4,1,-1, 1,4,2,1,-1, 2,4,3,2,-1, 2,3,4,2,-1, 3,4,0,3,-1, 3,0,4,3,-1 ";
00801   else if (tm == PYRAM13)
00802     return (string) " 0,1,2,3,0,-1, 0,3,2,1,0,-1, 0,1,4,0,-1, 0,4,1,0,-1, 1,2,4,1,-1, 1,4,2,1,-1, 2,4,3,2,-1, 2,3,4,2,-1, 3,4,0,3,-1, 3,0,4,3,-1 ";
00803   else if (tm == PENTA6)
00804     return (string) " 0,1,2,0,-1, 0,2,1,0,-1, 3,4,5,3,-1, 3,5,4,3,-1, 0,1,4,3,0,-1, 0,3,4,1,0,-1, 1,4,5,2,1,-1, 1,2,5,4,1,-1, 0,3,5,2,0,-1, 0,2,5,3,0,-1 ";
00805   else if (tm == PENTA15)
00806     return (string) " 0,1,2,0,-1, 0,2,1,0,-1, 3,4,5,3,-1, 3,5,4,3,-1, 0,1,4,3,0,-1, 0,3,4,1,0,-1, 1,4,5,2,1,-1, 1,2,5,4,1,-1, 0,3,5,2,0,-1, 0,2,5,3,0,-1 ";
00807   else if (tm == HEXA8)
00808     return (string) " 0,1,2,3,0,-1, 0,3,2,1,0,-1, 1,5,6,2,1,-1, 1,2,6,5,1,-1, 5,4,7,6,5,-1, 5,6,7,4,5,-1, 4,0,3,7,4,-1, 4,7,3,0,4,-1, 0,4,5,1,0,-1, 0,1,5,4,0,-1, 3,7,6,2,3,-1, 3,2,6,7,3,-1 ";
00809   else if (tm == HEXA20)
00810     return (string) " 0,1,2,3,0,-1, 0,3,2,1,0,-1, 1,5,6,2,1,-1, 1,2,6,5,1,-1, 5,4,7,6,5,-1, 5,6,7,4,5,-1, 4,0,3,7,4,-1, 4,7,3,0,4,-1, 0,4,5,1,0,-1, 0,1,5,4,0,-1, 3,7,6,2,3,-1, 3,2,6,7,3,-1 ";
00811   else
00812     return (string) "";
00813 }
00814 
00815 std::string MESHCUT::SIGNE(double x)
00816 {
00817   if (x < 0)
00818     return "-";
00819   else if (x > 0)
00820     return "+";
00821   else
00822     return "0";
00823 }
00824 
00825 void MESHCUT::champType(std::string type, med_entity_type MEM, med_geometry_type MGE, med_idt fid, med_idt fidout,
00826                         char *maa, char *nomChamp, char *nomChampMoy, med_field_type typeChamp, char *compChamp,
00827                         char *unitChamp, med_int nCompChamp, std::map<std::string, int> REFGAUSS, int ichamp)
00828 {
00829 
00830   bool debug = true;
00831   int ipt, nmailles, ngauss, imaille, igauss, icomp;
00832   //  int ival, ngpdt;
00833   med_int nval, numdt, numo, nPasTemps;
00834   char dtunit[MED_SNAME_SIZE + 1] = "";
00835   char locname[MED_NAME_SIZE + 1] = "";
00836   char nomprofil[MED_NAME_SIZE + 1] = "";
00837   med_float dt = 0.0;
00838   med_float *valr = NULL;
00839   med_float *valr2 = NULL;
00840   med_bool local;
00841   //  med_int nbrefmaa;
00842   med_field_type fieldType;
00843 
00844   if (MEDfieldInfo(fid, ichamp, nomChamp, maa, &local, &fieldType, compChamp, unitChamp, dtunit, &nPasTemps) < 0)
00845     ERREUR("Error MEDfieldInfo");
00846   cout << type << " : " << (int) nPasTemps << " timestep  " << endl;
00847 
00848   for (ipt = 1; ipt <= nPasTemps; ipt++)
00849     {
00850       //for (ipt=1; ipt<=min(nPasTemps,1); ipt++) {
00851       if (debug)
00852         cout << endl;
00853       if (debug)
00854         cout << "************************************************************" << endl;
00855       if (debug)
00856         cout << "                    FIELD " << ichamp << endl;
00857       if (debug)
00858         cout << "          " << nomChamp << endl;
00859       if (debug)
00860         cout << "          " << type << "   ---   Timestep " << ipt << endl;
00861       if (debug)
00862         cout << "************************************************************" << endl;
00863       if (debug)
00864         cout << endl;
00865 
00866       if (MEDfieldComputingStepInfo(fid, nomChamp, ipt, &numdt, &numo, &dt) < 0)
00867         {
00868           cout << endl;
00869           cout << endl << "####################################################################" << endl;
00870           cout << "                   ERROR MEDpasdetempsInfo                         " << endl;
00871           cout << endl << "####################################################################" << endl;
00872           cout << "                  Field: " << (string) nomChamp << endl;
00873           cout << "                  Geometrie: " << MGE2string(MGE) << endl;
00874           cout << "                  Timestep " << ipt << " ignored" << endl;
00875 
00876           continue;
00877         }
00878 
00879       med_int profilesize, nintegrationpoint;
00880       nval = MEDfieldnValueWithProfile(fid, nomChamp, numdt, numo, MEM, MGE, ipt, MED_COMPACT_PFLMODE, nomprofil,
00881                                        &profilesize, locname, &nintegrationpoint);
00882       if (debug)
00883         cout << "     Number of values in this timestep: " << (int) nval << endl;
00884 
00885       if (typeChamp == MED_FLOAT64)
00886         valr = (med_float*) calloc(nCompChamp * nval, sizeof(med_float));
00887       else
00888         ERREUR("Type of field not taken into account");
00889 
00890       if (MEDfieldValueWithProfileRd(fid, maa, numdt, numo, MEM, MGE, MED_COMPACT_PFLMODE, nomprofil,
00891                                      MED_FULL_INTERLACE, MED_ALL_CONSTITUENT, (unsigned char*) valr) < 0)
00892         {
00893           cout << endl;
00894           cout << endl << "####################################################################" << endl;
00895           cout << "                         ERROR MEDchampLire                        " << endl;
00896           cout << endl << "####################################################################" << endl;
00897           cout << endl;
00898           cout << "   Field: " << (string) nomChamp << endl;
00899           cout << "   Geometry: " << MGE2string(MGE) << endl;
00900           cout << "   Timestep " << ipt << " ignored" << endl;
00901           cout << endl << endl;
00902           continue;
00903         }
00904 
00905       if (debug)
00906         cout << "       profile  = " << (string) nomprofil << endl;
00907       // Localisation du champ aux points de Gauss
00908       if (debug)
00909         cout << "       locname = " << (string) locname << endl;
00910 
00911       if (REFGAUSS[(string) locname])
00912         {
00913           ngauss = REFGAUSS[(string) locname];
00914           if (debug)
00915             cout << "       " << ngauss << " Gauss points by element)" << endl;
00916         }
00917       else
00918         ngauss = 1;
00919 
00920       nmailles = nval / ngauss;
00921       if (debug)
00922         cout << "      Nbre de mailles: " << nmailles << endl;
00923 
00924       if (debug)
00925         {
00926           cout << endl << "       Liste des valeurs du champ brut aux 3 premiers éléments:" << endl;
00927           for (imaille = 0; imaille < min(nmailles, 3); imaille++)
00928             {
00929               cout << "         Maille " << imaille << endl;
00930               for (igauss = 0; igauss < ngauss; igauss++)
00931                 {
00932                   cout << "             PG " << igauss << " : ";
00933                   for (icomp = 0; icomp < nCompChamp; icomp++)
00934                     cout << " " << *(valr + imaille * ngauss * nCompChamp + igauss * nCompChamp + icomp);
00935                   cout << endl;
00936                 }
00937               cout << endl;
00938             }
00939           cout << endl;
00940         }
00941 
00942       if (ngauss > 1)
00943         {
00944 
00945           valr2 = (med_float*) calloc(nCompChamp * nmailles, sizeof(med_float));
00946 
00947           if (debug)
00948             cout << endl << "       Moyenne sur les PG des mailles" << endl;
00949           for (imaille = 0; imaille < nmailles; imaille++)
00950             {
00951               for (icomp = 0; icomp < nCompChamp; icomp++)
00952                 {
00953                   float valCompMaille = 0.0;
00954                   for (igauss = 0; igauss < ngauss; igauss++)
00955                     valCompMaille += *(valr + imaille * ngauss * nCompChamp + igauss * nCompChamp + icomp);
00956                   *(valr2 + imaille * nCompChamp + icomp) = valCompMaille / ngauss;
00957 
00958                 }
00959             }
00960 
00961           //cout << endl << "Nom champ moy = " <<  (string)nomChampMoy << endl;
00962           //cout << endl << "Type champ = " <<  typeChamp << endl;
00963           //cout << endl << "Comp champ = " <<  (string)compChamp << endl;
00964           //cout << endl << "Unit champ = " <<  (string)unitChamp << endl;
00965           //cout << endl << "N comp champ = " <<  nCompChamp << endl;
00966 
00967           if (MEDfieldValueWithProfileWr(fidout, nomChampMoy, numdt, numo, dt, MEM, MGE, MED_COMPACT_PFLMODE,
00968                                          nomprofil, MED_NO_LOCALIZATION, MED_FULL_INTERLACE, MED_ALL_CONSTITUENT,
00969                                          (med_int) nmailles, (unsigned char*) valr2) < 0)
00970             {
00971               cout << endl;
00972               cout << endl << "********************************************************************" << endl;
00973               cout << "********************                         ***********************" << endl;
00974               cout << "********************   ERROR MEDchampEcr     ***********************" << endl;
00975               cout << "********************                         ***********************" << endl;
00976               cout << "********************************************************************" << endl;
00977               cout << endl;
00978               cout << "   Champ: " << (string) nomChampMoy << endl;
00979               cout << "   Géométrie: " << MGE2string(MGE) << endl;
00980               cout << "   Pas de temps " << ipt << " ignoré" << endl;
00981               cout << endl << endl;
00982               continue;
00983             }
00984 
00985           if (debug)
00986             cout << "    Writing mean values in new field: OK " << endl;
00987 
00988           // Restitution du champ moyenné
00989           if (debug)
00990             {
00991               cout << endl << "       Liste des valeurs du champ moyenné aux 3 premiers éléments:" << endl;
00992               for (imaille = 0; imaille < min(nmailles, 3); imaille++)
00993                 {
00994                   cout << "         Maille " << imaille << endl;
00995                   for (icomp = 0; icomp < nCompChamp; icomp++)
00996                     cout << " " << *(valr2 + imaille * nCompChamp + icomp);
00997                   cout << endl;
00998                 }
00999               cout << endl;
01000             }
01001 
01002         }
01003 
01004       free(valr);
01005       free(valr2);
01006 
01007     } // boucle sur les pas de temps
01008 
01009   cout << endl;
01010 }
01011 
01012 std::string MESHCUT::nomMaille(TYPE_MAILLE tm, int nl)
01013 {
01014   return (TM2string(tm) + (string) "_" + int2string(nl));
01015 }
01016 
01017 bool MESHCUT::appartientVN(int n, std::vector<int> V)
01018 {
01019   bool app = false;
01020   for (unsigned int i = 0; i < V.size(); i++)
01021     if (n == V[i])
01022       {
01023         app = true;
01024         break;
01025       }
01026   return app;
01027 }
01028 
01029 float MESHCUT::distance2(float x1, float y1, float z1, float x2, float y2, float z2)
01030 {
01031   return (x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1) + (z2 - z1) * (z2 - z1);
01032 }
01033 
01037 void MESHCUT::conversionCNX(int *CNXtm, TYPE_MAILLE tm, int N)
01038 {
01039 
01040   int n = Nnoeuds(tm);
01041 
01042   if (tm == TETRA4)
01043     {
01044       for (int i = 0; i < N; i++)
01045         {
01046           int i1 = CNXtm[i * n + 1];
01047           int i2 = CNXtm[i * n + 2];
01048           CNXtm[i * n + 1] = i2;
01049           CNXtm[i * n + 2] = i1;
01050         }
01051     }
01052   else if (tm == PYRAM5)
01053     {
01054       for (int i = 0; i < N; i++)
01055         {
01056           int i1 = CNXtm[i * n + 1];
01057           int i3 = CNXtm[i * n + 3];
01058           CNXtm[i * n + 1] = i3;
01059           CNXtm[i * n + 3] = i1;
01060         }
01061     }
01062   else if (tm == PENTA6)
01063     {
01064       for (int i = 0; i < N; i++)
01065         {
01066           int i0 = CNXtm[i * n + 0];
01067           int i1 = CNXtm[i * n + 1];
01068           int i2 = CNXtm[i * n + 2];
01069           int i3 = CNXtm[i * n + 3];
01070           int i4 = CNXtm[i * n + 4];
01071           int i5 = CNXtm[i * n + 5];
01072           CNXtm[i * n + 0] = i3;
01073           CNXtm[i * n + 1] = i4;
01074           CNXtm[i * n + 2] = i5;
01075           CNXtm[i * n + 3] = i0;
01076           CNXtm[i * n + 4] = i1;
01077           CNXtm[i * n + 5] = i2;
01078         }
01079     }
01080 
01081   else if (tm == HEXA8)
01082     {
01083       for (int i = 0; i < N; i++)
01084         {
01085           int i0 = CNXtm[i * n + 0];
01086           int i1 = CNXtm[i * n + 1];
01087           int i2 = CNXtm[i * n + 2];
01088           int i3 = CNXtm[i * n + 3];
01089           int i4 = CNXtm[i * n + 4];
01090           int i5 = CNXtm[i * n + 5];
01091           int i6 = CNXtm[i * n + 6];
01092           int i7 = CNXtm[i * n + 7];
01093           CNXtm[i * n + 0] = i4;
01094           CNXtm[i * n + 1] = i5;
01095           CNXtm[i * n + 2] = i6;
01096           CNXtm[i * n + 3] = i7;
01097           CNXtm[i * n + 4] = i0;
01098           CNXtm[i * n + 5] = i1;
01099           CNXtm[i * n + 6] = i2;
01100           CNXtm[i * n + 7] = i3;
01101         }
01102     }
01103 }
01104