From 1a70ce903bbf905d02aaa8d559739db71854c68d Mon Sep 17 00:00:00 2001 From: cs Date: Tue, 27 Mar 2007 20:35:17 +0000 Subject: [PATCH] *** empty log message *** --- README | 2 +- idl/MULTIPR.idl | 8 +- src/MULTIPR/MULTIPR_API.cxx | 268 +-- src/MULTIPR/MULTIPR_API.hxx | 36 +- src/MULTIPR/MULTIPR_DecimationAccel.cxx | 433 ++--- src/MULTIPR/MULTIPR_DecimationAccel.hxx | 374 ++-- src/MULTIPR/MULTIPR_DecimationFilter.cxx | 460 ++--- src/MULTIPR/MULTIPR_DecimationFilter.hxx | 191 +- src/MULTIPR/MULTIPR_Elements.cxx | 702 ++++---- src/MULTIPR/MULTIPR_Elements.hxx | 372 ++-- src/MULTIPR/MULTIPR_Exceptions.hxx | 162 +- src/MULTIPR/MULTIPR_Family.cxx | 638 +++---- src/MULTIPR/MULTIPR_Family.hxx | 556 +++--- src/MULTIPR/MULTIPR_Field.cxx | 840 +++++---- src/MULTIPR/MULTIPR_Field.hxx | 362 ++-- src/MULTIPR/MULTIPR_GaussLoc.cxx | 314 ++-- src/MULTIPR/MULTIPR_GaussLoc.hxx | 198 +-- src/MULTIPR/MULTIPR_Mesh.cxx | 2056 +++++++++++----------- src/MULTIPR/MULTIPR_Mesh.hxx | 580 +++--- src/MULTIPR/MULTIPR_MeshDis.cxx | 1744 +++++++++--------- src/MULTIPR/MULTIPR_MeshDis.hxx | 745 ++++---- src/MULTIPR/MULTIPR_Nodes.cxx | 618 +++---- src/MULTIPR/MULTIPR_Nodes.hxx | 276 +-- src/MULTIPR/MULTIPR_Obj.cxx | 704 ++++---- src/MULTIPR/MULTIPR_Obj.hxx | 448 ++--- src/MULTIPR/MULTIPR_PointOfField.hxx | 102 +- src/MULTIPR/MULTIPR_Profil.cxx | 146 +- src/MULTIPR/MULTIPR_Profil.hxx | 174 +- src/MULTIPR/MULTIPR_ProgressCallback.hxx | 114 +- src/MULTIPR/MULTIPR_Utils.cxx | 449 ++--- src/MULTIPR/MULTIPR_Utils.hxx | 20 +- src/MULTIPR/MULTIPR_i.cxx | 703 ++++---- src/MULTIPR/MULTIPR_i.hxx | 489 ++--- src/MULTIPR/Makefile.in | 40 +- src/MULTIPR/multipr.cxx | 1005 +++++------ src/MULTIPRGUI/MULTIPR_GUI.cxx | 1268 ++++++------- src/MULTIPRGUI/MULTIPR_GUI.h | 176 +- src/MULTIPRGUI/MULTIPR_GUI_Dlg.cxx | 754 ++++---- src/MULTIPRGUI/MULTIPR_GUI_Dlg.h | 77 +- 39 files changed, 9398 insertions(+), 9206 deletions(-) diff --git a/README b/README index 1a54da8..3757d78 100755 --- a/README +++ b/README @@ -7,7 +7,7 @@ Description ----------- MULTIPR est un module pour la plateforme SALOME (v3.2). Le module sert au partitionnement et a la decimation de maillages tetraedriques (TETRA10), -dans le but de pouvoir visualiser d'importants volumes de donnees. +dans le but de pouvoir visualiser d'importants volumes de donnees scientifiques. Contenu de ce fichier diff --git a/idl/MULTIPR.idl b/idl/MULTIPR.idl index 063f037..6c54f48 100644 --- a/idl/MULTIPR.idl +++ b/idl/MULTIPR.idl @@ -57,7 +57,13 @@ interface MULTIPR_Obj */ string getFilename() raises (SALOME::SALOME_Exception); - + + /*! + * Return the name of the associated sequential MED file (for a distributed MED file). + */ + string getSeqFilename() + raises (SALOME::SALOME_Exception); + /*! * Set the mesh to be partitionned/decimated. * Assume sequential MED file. diff --git a/src/MULTIPR/MULTIPR_API.cxx b/src/MULTIPR/MULTIPR_API.cxx index 5c5fda5..29b5686 100644 --- a/src/MULTIPR/MULTIPR_API.cxx +++ b/src/MULTIPR/MULTIPR_API.cxx @@ -24,7 +24,7 @@ extern "C" { - #include "med.h" + #include "med.h" } #include "MEDSPLITTER_API.hxx" @@ -42,152 +42,154 @@ using namespace std; const char* multipr::getVersion() { - return "1.0"; + return "1.0.4"; } void multipr::partitionneDomaine(const char* pMEDfilename, const char* pMeshName) -{ - if (pMEDfilename == NULL) throw NullArgumentException("pMEDfilename should not be NULL", __FILE__, __LINE__); - if (pMeshName == NULL) throw NullArgumentException("pMeshName should not be NULL", __FILE__, __LINE__); - - //--------------------------------------------------------------------- - // Read the sequential mesh - //--------------------------------------------------------------------- - cout << "Read sequential MED file: " << pMEDfilename << ": please wait... " << endl; - - multipr::Mesh mesh; - mesh.readSequentialMED(pMEDfilename, pMeshName); - cout << mesh << endl; - - //--------------------------------------------------------------------- - // Build distributed mesh from groups - //--------------------------------------------------------------------- - cout << "Build distributed mesh: please wait... " << endl; - multipr::MeshDis* meshDis = NULL; - try - { - meshDis = mesh.splitGroupsOfElements(); - - //------------------------------------------------------------- - // Write distributed mesh - //------------------------------------------------------------- - cout << "Write distributed mesh: please wait... " << endl; - string strPrefix = removeExtension(pMEDfilename, ".med"); - meshDis->writeDistributedMED(strPrefix.c_str()); - - delete meshDis; - } - catch (RuntimeException& e) - { - delete meshDis; - throw e; - } +{ + if (pMEDfilename == NULL) throw NullArgumentException("pMEDfilename should not be NULL", __FILE__, __LINE__); + if (pMeshName == NULL) throw NullArgumentException("pMeshName should not be NULL", __FILE__, __LINE__); + + //--------------------------------------------------------------------- + // Read the sequential mesh + //--------------------------------------------------------------------- + cout << "Read sequential MED file: " << pMEDfilename << ": please wait... " << endl; + + multipr::Mesh mesh; + mesh.readSequentialMED(pMEDfilename, pMeshName); + cout << mesh << endl; + + //--------------------------------------------------------------------- + // Build distributed mesh from groups + //--------------------------------------------------------------------- + cout << "Build distributed mesh: please wait... " << endl; + + multipr::MeshDis* meshDis = NULL; + + try + { + meshDis = mesh.splitGroupsOfElements(); + + //------------------------------------------------------------- + // Write distributed mesh + //------------------------------------------------------------- + cout << "Write distributed mesh: please wait... " << endl; + string strPrefix = removeExtension(pMEDfilename, ".med"); + meshDis->writeDistributedMED(strPrefix.c_str()); + + delete meshDis; + } + catch (RuntimeException& e) + { + delete meshDis; + throw e; + } } void multipr::partitionneGrain( - const char* pMEDfilename, - const char* pGroupName, - int pNbParts, - int pPartitionner) + const char* pMEDfilename, + const char* pGroupName, + int pNbParts, + int pPartitionner) { - if (pMEDfilename == NULL) throw NullArgumentException("pMEDfilename should not be NULL", __FILE__, __LINE__); - if (pGroupName == NULL) throw NullArgumentException("pGroupName should not be NULL", __FILE__, __LINE__); - if (pNbParts < 2) throw IllegalArgumentException("pNbParts should be >= 2", __FILE__, __LINE__); - if ((pPartitionner != MULTIPR_METIS) && (pPartitionner != MULTIPR_SCOTCH)) throw NullArgumentException("pPartitionner should be METIS (0) or SCOTCH (1)", __FILE__, __LINE__); - - //--------------------------------------------------------------------- - // Read the distributed mesh - //--------------------------------------------------------------------- - MULTIPR_LOG("Read distributed MED file: " << pMEDfilename << ": please wait... " << endl); - - int ret = MEDformatConforme(pMEDfilename); - if (ret == 0) throw IOException("waiting for a distributed MED file (not a sequential one)", __FILE__, __LINE__); - - multipr::MeshDis meshDis; - meshDis.readDistributedMED(pMEDfilename); - cout << meshDis << endl; - - //--------------------------------------------------------------------- - // Split the given part (pGroupName) - //--------------------------------------------------------------------- - if (pPartitionner == MULTIPR_METIS) - { - cout << "Use METIS" << endl; - } - else if (pPartitionner == MULTIPR_SCOTCH) - { - cout << "Use SCOTCH" << endl; - } - - meshDis.splitPart(pGroupName, pNbParts, pPartitionner); - cout << meshDis << endl; - - //--------------------------------------------------------------------- - // Write new distributed mesh - //--------------------------------------------------------------------- - string strPrefix = multipr::removeExtension(pMEDfilename, ".med"); - meshDis.writeDistributedMED(strPrefix.c_str()); + if (pMEDfilename == NULL) throw NullArgumentException("pMEDfilename should not be NULL", __FILE__, __LINE__); + if (pGroupName == NULL) throw NullArgumentException("pGroupName should not be NULL", __FILE__, __LINE__); + if (pNbParts < 2) throw IllegalArgumentException("pNbParts should be >= 2", __FILE__, __LINE__); + if ((pPartitionner != MULTIPR_METIS) && (pPartitionner != MULTIPR_SCOTCH)) throw NullArgumentException("pPartitionner should be METIS (0) or SCOTCH (1)", __FILE__, __LINE__); + + //--------------------------------------------------------------------- + // Read the distributed mesh + //--------------------------------------------------------------------- + MULTIPR_LOG("Read distributed MED file: " << pMEDfilename << ": please wait... " << endl); + + int ret = MEDformatConforme(pMEDfilename); + if (ret == 0) throw IOException("waiting for a distributed MED file (not a sequential one)", __FILE__, __LINE__); + + multipr::MeshDis meshDis; + meshDis.readDistributedMED(pMEDfilename); + cout << meshDis << endl; + + //--------------------------------------------------------------------- + // Split the given part (pGroupName) + //--------------------------------------------------------------------- + if (pPartitionner == MULTIPR_METIS) + { + cout << "Use METIS" << endl; + } + else if (pPartitionner == MULTIPR_SCOTCH) + { + cout << "Use SCOTCH" << endl; + } + + meshDis.splitPart(pGroupName, pNbParts, pPartitionner); + cout << meshDis << endl; + + //--------------------------------------------------------------------- + // Write new distributed mesh + //--------------------------------------------------------------------- + string strPrefix = multipr::removeExtension(pMEDfilename, ".med"); + meshDis.writeDistributedMED(strPrefix.c_str()); } void multipr::decimePartition( - const char* pMEDfilename, - const char* pPartName, - const char* pFieldName, - int pFieldIt, - const char* pFilterName, - double pTMed, - double pTLow, - double pRadius, - int pBoxing) + const char* pMEDfilename, + const char* pPartName, + const char* pFieldName, + int pFieldIt, + const char* pFilterName, + double pTMed, + double pTLow, + double pRadius, + int pBoxing) { - //--------------------------------------------------------------------- - // Check arguments - //--------------------------------------------------------------------- - if (pMEDfilename == NULL) throw NullArgumentException("pMEDfilename should not be NULL", __FILE__, __LINE__); - if (pPartName == NULL) throw NullArgumentException("pPartName should not be NULL", __FILE__, __LINE__); - if (pFieldName == NULL) throw NullArgumentException("pFieldName should not be NULL", __FILE__, __LINE__); - if (pFieldIt < 1) throw IllegalArgumentException("pFieldIt: invalid field iteration; should be >= 1", __FILE__, __LINE__); - if (pTMed < 0.0) throw IllegalArgumentException("med res.: threshold must be > 0", __FILE__, __LINE__); - if (pTMed >= pTLow) throw IllegalArgumentException("threshold for med res. must be < threshold for low res.", __FILE__, __LINE__); - if (pRadius <= 0.0) throw IllegalArgumentException("radius should be > 0", __FILE__, __LINE__); - if ((pBoxing < 1) || (pBoxing > 200)) throw IllegalArgumentException("boxing should be in [1..200]", __FILE__, __LINE__); - - cout << "--decim file=" << pMEDfilename << " part=" << pPartName << " filter=" << pFilterName << " tmed=" << pTMed << " tlow=" << pTLow << " radius=" << pRadius << endl; - - //--------------------------------------------------------------------- - // Read the distributed mesh - //--------------------------------------------------------------------- - MULTIPR_LOG("Read distributed MED file: " << pMEDfilename << ": please wait... " << endl); - - int ret = MEDformatConforme(pMEDfilename); - if (ret == 0) throw IOException("waiting for a distributed MED file (not a sequential one)", __FILE__, __LINE__); - - multipr::MeshDis meshDis; - meshDis.readDistributedMED(pMEDfilename); - cout << meshDis << endl; - - //--------------------------------------------------------------------- - // Create 3 resolutions of the given part - //--------------------------------------------------------------------- - meshDis.decimatePart( - pPartName, - pFieldName, - pFieldIt, - pFilterName, - pTMed, - pTLow, - pRadius, - pBoxing); - cout << meshDis << endl; - - //--------------------------------------------------------------------- - // Write new distributed mesh - //--------------------------------------------------------------------- - string strPrefix = removeExtension(pMEDfilename, ".med"); // get prefix from the original MED filename - meshDis.writeDistributedMED(strPrefix.c_str()); + //--------------------------------------------------------------------- + // Check arguments + //--------------------------------------------------------------------- + if (pMEDfilename == NULL) throw NullArgumentException("pMEDfilename should not be NULL", __FILE__, __LINE__); + if (pPartName == NULL) throw NullArgumentException("pPartName should not be NULL", __FILE__, __LINE__); + if (pFieldName == NULL) throw NullArgumentException("pFieldName should not be NULL", __FILE__, __LINE__); + if (pFieldIt < 1) throw IllegalArgumentException("pFieldIt: invalid field iteration; should be >= 1", __FILE__, __LINE__); + if (pTMed < 0.0) throw IllegalArgumentException("med res.: threshold must be > 0", __FILE__, __LINE__); + if (pTMed >= pTLow) throw IllegalArgumentException("threshold for med res. must be < threshold for low res.", __FILE__, __LINE__); + if (pRadius <= 0.0) throw IllegalArgumentException("radius should be > 0", __FILE__, __LINE__); + if ((pBoxing < 1) || (pBoxing > 200)) throw IllegalArgumentException("boxing should be in [1..200]", __FILE__, __LINE__); + + cout << "--decim file=" << pMEDfilename << " part=" << pPartName << " filter=" << pFilterName << " tmed=" << pTMed << " tlow=" << pTLow << " radius=" << pRadius << endl; + + //--------------------------------------------------------------------- + // Read the distributed mesh + //--------------------------------------------------------------------- + MULTIPR_LOG("Read distributed MED file: " << pMEDfilename << ": please wait... " << endl); + + int ret = MEDformatConforme(pMEDfilename); + if (ret == 0) throw IOException("waiting for a distributed MED file (not a sequential one)", __FILE__, __LINE__); + + multipr::MeshDis meshDis; + meshDis.readDistributedMED(pMEDfilename); + cout << meshDis << endl; + + //--------------------------------------------------------------------- + // Create 3 resolutions of the given part + //--------------------------------------------------------------------- + meshDis.decimatePart( + pPartName, + pFieldName, + pFieldIt, + pFilterName, + pTMed, + pTLow, + pRadius, + pBoxing); + cout << meshDis << endl; + + //--------------------------------------------------------------------- + // Write new distributed mesh + //--------------------------------------------------------------------- + string strPrefix = removeExtension(pMEDfilename, ".med"); // get prefix from the original MED filename + meshDis.writeDistributedMED(strPrefix.c_str()); } // EOF diff --git a/src/MULTIPR/MULTIPR_API.hxx b/src/MULTIPR/MULTIPR_API.hxx index 8c42885..ae60f0e 100644 --- a/src/MULTIPR/MULTIPR_API.hxx +++ b/src/MULTIPR/MULTIPR_API.hxx @@ -21,9 +21,9 @@ namespace multipr enum Partitionner { - MULTIPR_METIS = 0, - MULTIPR_SCOTCH = 1 - + MULTIPR_METIS = 0, + MULTIPR_SCOTCH = 1 + }; // enum Partitionner @@ -48,8 +48,8 @@ const char* getVersion(); * \throw RuntimeException if any error occurs. */ void partitionneDomaine( - const char* medFilename, - const char* meshName); + const char* medFilename, + const char* meshName); /** @@ -66,10 +66,10 @@ void partitionneDomaine( * \throw RuntimeException if any error occurs. */ void partitionneGrain( - const char* medFilename, - const char* partName, - int nbParts, - int partitionner=MULTIPR_METIS); + const char* medFilename, + const char* partName, + int nbParts, + int partitionner=MULTIPR_METIS); /** @@ -90,15 +90,15 @@ void partitionneDomaine( * \throw RuntimeException if any error occurs. */ void decimePartition( - const char* medFilename, - const char* partName, - const char* fieldName, - int fieldIt, - const char* filterName, - double tmed, - double tlow, - double radius, - int boxing); + const char* medFilename, + const char* partName, + const char* fieldName, + int fieldIt, + const char* filterName, + double tmed, + double tlow, + double radius, + int boxing); } // namespace MULTIPR diff --git a/src/MULTIPR/MULTIPR_DecimationAccel.cxx b/src/MULTIPR/MULTIPR_DecimationAccel.cxx index 080613a..773e3d0 100644 --- a/src/MULTIPR/MULTIPR_DecimationAccel.cxx +++ b/src/MULTIPR/MULTIPR_DecimationAccel.cxx @@ -35,8 +35,8 @@ namespace multipr ostream& operator<<(ostream& pOs, DecimationAccel& pA) { - pOs << "DecimationAccel:" << endl; - return pOs; + pOs << "DecimationAccel:" << endl; + return pOs; } @@ -46,277 +46,278 @@ ostream& operator<<(ostream& pOs, DecimationAccel& pA) DecimationAccelGrid::DecimationAccelGrid() { - mGrid = NULL; - - reset(); + mGrid = NULL; + + reset(); } DecimationAccelGrid::~DecimationAccelGrid() { - reset(); + reset(); } void DecimationAccelGrid::reset() { - mNum = 0; - - mMin[0] = numeric_limits::quiet_NaN(); - mMin[1] = numeric_limits::quiet_NaN(); - mMin[2] = numeric_limits::quiet_NaN(); - - mMax[0] = numeric_limits::quiet_NaN(); - mMax[1] = numeric_limits::quiet_NaN(); - mMax[2] = numeric_limits::quiet_NaN(); - - mInvLen[0] = numeric_limits::quiet_NaN(); - mInvLen[1] = numeric_limits::quiet_NaN(); - mInvLen[2] = numeric_limits::quiet_NaN(); - - mSize[0] = 0; - mSize[1] = 0; - mSize[2] = 0; - - if (mGrid != NULL) - { - delete[] mGrid; - mGrid = NULL; - } - - mFlagPrintAll = false; + mNum = 0; + + mMin[0] = numeric_limits::quiet_NaN(); + mMin[1] = numeric_limits::quiet_NaN(); + mMin[2] = numeric_limits::quiet_NaN(); + + mMax[0] = numeric_limits::quiet_NaN(); + mMax[1] = numeric_limits::quiet_NaN(); + mMax[2] = numeric_limits::quiet_NaN(); + + mInvLen[0] = numeric_limits::quiet_NaN(); + mInvLen[1] = numeric_limits::quiet_NaN(); + mInvLen[2] = numeric_limits::quiet_NaN(); + + mSize[0] = 0; + mSize[1] = 0; + mSize[2] = 0; + + if (mGrid != NULL) + { + delete[] mGrid; + mGrid = NULL; + } + + mFlagPrintAll = false; } void DecimationAccelGrid::create(const std::vector& pPts) { - // check if grid have been initialized - if (mSize[0] == 0) throw IllegalStateException("call setSize() before", __FILE__, __LINE__); - - // compute bbox of the grid - computeBBox(pPts); - - // allocate the grid - int size = mSize[0] * mSize[1] * mSize[2]; - mGrid = new vector[size]; - - // fill the grid - mNum = pPts.size(); - for (int i = 0 ; i < mNum ; i++) - { - vector& cell = getCell(pPts[i]); - cell.push_back(pPts[i]); - } + // check if grid have been initialized + if (mSize[0] == 0) throw IllegalStateException("call setSize() before", __FILE__, __LINE__); + + // compute bbox of the grid + computeBBox(pPts); + + // allocate the grid + int size = mSize[0] * mSize[1] * mSize[2]; + mGrid = new vector[size]; + + // fill the grid + mNum = pPts.size(); + for (int i = 0 ; i < mNum ; i++) + { + vector& cell = getCell(pPts[i]); + cell.push_back(pPts[i]); + } } void DecimationAccelGrid::configure(const char* pArgv) { - // check arguments - if (pArgv == NULL) throw NullArgumentException("", __FILE__, __LINE__); - - int sizeX = 0; - int sizeY = 0; - int sizeZ = 0; - - int ret = sscanf(pArgv, "%d %d %d", &sizeX, &sizeY, &sizeZ); - - if (ret != 3) throw IllegalArgumentException("expected 3 parameters", __FILE__, __LINE__); - if (sizeX <= 0) throw IllegalArgumentException("number of cells along X-axis must be > 0", __FILE__, __LINE__); - if (sizeY <= 0) throw IllegalArgumentException("number of cells along Y-axis must be > 0", __FILE__, __LINE__); - if (sizeZ <= 0) throw IllegalArgumentException("number of cells along Z-axis must be > 0", __FILE__, __LINE__); - - reset(); - - mSize[0] = sizeX; - mSize[1] = sizeY; - mSize[2] = sizeZ; + // check arguments + if (pArgv == NULL) throw NullArgumentException("", __FILE__, __LINE__); + + int sizeX = 0; + int sizeY = 0; + int sizeZ = 0; + + int ret = sscanf(pArgv, "%d %d %d", &sizeX, &sizeY, &sizeZ); + + if (ret != 3) throw IllegalArgumentException("expected 3 parameters", __FILE__, __LINE__); + if (sizeX <= 0) throw IllegalArgumentException("number of cells along X-axis must be > 0", __FILE__, __LINE__); + if (sizeY <= 0) throw IllegalArgumentException("number of cells along Y-axis must be > 0", __FILE__, __LINE__); + if (sizeZ <= 0) throw IllegalArgumentException("number of cells along Z-axis must be > 0", __FILE__, __LINE__); + + reset(); + + mSize[0] = sizeX; + mSize[1] = sizeY; + mSize[2] = sizeZ; } void DecimationAccelGrid::getCellCoord( - med_float pX, med_float pY, med_float pZ, - int* pIx, int* pIy, int* pIz) const + med_float pX, med_float pY, med_float pZ, + int* pIx, int* pIy, int* pIz) const { - med_float cx = (pX - mMin[0]) * mInvLen[0]; - med_float cy = (pY - mMin[1]) * mInvLen[1]; - med_float cz = (pZ - mMin[2]) * mInvLen[2]; - - *pIx = med_int(cx); - if (*pIx >= mSize[0]) *pIx = mSize[0] - 1; - else if (*pIx < 0) *pIx = 0; - - *pIy = med_int(cy); - if (*pIy >= mSize[1]) *pIy = mSize[1] - 1; - else if (*pIy < 0) *pIy = 0; - - *pIz = med_int(cz); - if (*pIz >= mSize[2]) *pIz = mSize[2] - 1; - else if (*pIz < 0) *pIz = 0; + med_float cx = (pX - mMin[0]) * mInvLen[0]; + med_float cy = (pY - mMin[1]) * mInvLen[1]; + med_float cz = (pZ - mMin[2]) * mInvLen[2]; + + // clamp all indices to avoid overflow + *pIx = med_int(cx); + if (*pIx >= mSize[0]) *pIx = mSize[0] - 1; + else if (*pIx < 0) *pIx = 0; + + *pIy = med_int(cy); + if (*pIy >= mSize[1]) *pIy = mSize[1] - 1; + else if (*pIy < 0) *pIy = 0; + + *pIz = med_int(cz); + if (*pIz >= mSize[2]) *pIz = mSize[2] - 1; + else if (*pIz < 0) *pIz = 0; } int DecimationAccelGrid::getCellIndex(int pI, int pJ, int pK) const -{ - int index = pK * (mSize[0] * mSize[1]) + pJ * mSize[0] + pI; - - return index; +{ + int index = pK * (mSize[0] * mSize[1]) + pJ * mSize[0] + pI; + + return index; } vector& DecimationAccelGrid::getCell(const PointOfField& pPt) { - int ix, iy, iz; - - getCellCoord( - pPt.mXYZ[0], pPt.mXYZ[1], pPt.mXYZ[2], - &ix, &iy, &iz); - - int index = getCellIndex(ix, iy, iz); - - return mGrid[index]; + int ix, iy, iz; + + getCellCoord( + pPt.mXYZ[0], pPt.mXYZ[1], pPt.mXYZ[2], + &ix, &iy, &iz); + + int index = getCellIndex(ix, iy, iz); + + return mGrid[index]; } vector DecimationAccelGrid::findNeighbours( - med_float pCenterX, - med_float pCenterY, - med_float pCenterZ, - med_float pRadius) const -{ - //--------------------------------------------------------------------- - // Determine the axis aligned bounding box of the sphere ((x, y, z), r) - //--------------------------------------------------------------------- - med_float sphereBBoxMin[3]; - med_float sphereBBoxMax[3]; - - sphereBBoxMin[0] = pCenterX - pRadius; - sphereBBoxMin[1] = pCenterY - pRadius; - sphereBBoxMin[2] = pCenterZ - pRadius; - - sphereBBoxMax[0] = pCenterX + pRadius; - sphereBBoxMax[1] = pCenterY + pRadius; - sphereBBoxMax[2] = pCenterZ + pRadius; - - //--------------------------------------------------------------------- - // Determine the cells of the grid intersected by the sphere ((x, y, z), r) - // => range of cells are [iMinCell[0], iMaxCell[0]] x [iMinCell[1], iMaxCell[1]] x [iMinCell[2], iMaxCell[2]] - //--------------------------------------------------------------------- - int iMinCell[3]; - int iMaxCell[3]; - - getCellCoord(sphereBBoxMin[0], sphereBBoxMin[1], sphereBBoxMin[2], - &iMinCell[0], &iMinCell[1], &iMinCell[2]); - - getCellCoord(sphereBBoxMax[0], sphereBBoxMax[1], sphereBBoxMax[2], - &iMaxCell[0], &iMaxCell[1], &iMaxCell[2]); - - //--------------------------------------------------------------------- - // Collect points of the field which are in the sphere - //--------------------------------------------------------------------- - vector res; - + med_float pCenterX, + med_float pCenterY, + med_float pCenterZ, + med_float pRadius) const +{ + //--------------------------------------------------------------------- + // Determine the axis aligned bounding box of the sphere ((x, y, z), r) + //--------------------------------------------------------------------- + med_float sphereBBoxMin[3]; + med_float sphereBBoxMax[3]; + + sphereBBoxMin[0] = pCenterX - pRadius; + sphereBBoxMin[1] = pCenterY - pRadius; + sphereBBoxMin[2] = pCenterZ - pRadius; + + sphereBBoxMax[0] = pCenterX + pRadius; + sphereBBoxMax[1] = pCenterY + pRadius; + sphereBBoxMax[2] = pCenterZ + pRadius; + + //--------------------------------------------------------------------- + // Determine the cells of the grid intersected by the sphere ((x, y, z), r) + // => range of cells are [iMinCell[0], iMaxCell[0]] x [iMinCell[1], iMaxCell[1]] x [iMinCell[2], iMaxCell[2]] + //--------------------------------------------------------------------- + int iMinCell[3]; + int iMaxCell[3]; + + getCellCoord(sphereBBoxMin[0], sphereBBoxMin[1], sphereBBoxMin[2], + &iMinCell[0], &iMinCell[1], &iMinCell[2]); + + getCellCoord(sphereBBoxMax[0], sphereBBoxMax[1], sphereBBoxMax[2], + &iMaxCell[0], &iMaxCell[1], &iMaxCell[2]); + + //--------------------------------------------------------------------- + // Collect points of the field which are in the sphere + //--------------------------------------------------------------------- + vector res; + /* // debug cout << "Center = " << pCenterX << " " << pCenterY << " " << pCenterZ << endl; cout << "Radius = " << pRadius << endl; cout << "Visited cells : [" << iMinCell[0] << " ; " << iMaxCell[0] << "] x ["<< iMinCell[1] << " ; " << iMaxCell[1] << "] x [" << iMinCell[2] << " ; " << iMaxCell[2] << "]" << endl; */ - - // for all the cells in the grid intersected by the sphere ((x, y, z), r) - for (int i = iMinCell[0] ; i <= iMaxCell[0] ; i++) - { - for (int j = iMinCell[1] ; j <= iMaxCell[1] ; j++) - { - for (int k = iMinCell[2] ; k <= iMaxCell[2] ; k++) - { - int idCell = getCellIndex(i, j, k); + + // for all the cells in the grid intersected by the sphere ((x, y, z), r) + for (int i = iMinCell[0] ; i <= iMaxCell[0] ; i++) + { + for (int j = iMinCell[1] ; j <= iMaxCell[1] ; j++) + { + for (int k = iMinCell[2] ; k <= iMaxCell[2] ; k++) + { + int idCell = getCellIndex(i, j, k); //printf("DEBUG: visited cell(%d %d %d) -> %d\n", i, j, k, idCell); - vector& cell = mGrid[idCell]; - - // for all the points in the current cell - for (vector::const_iterator itPoint = cell.begin() ; itPoint != cell.end() ; itPoint++) - { - const PointOfField& currentPt = *itPoint; - - // test if currentPt is in the sphere ((x, y, z), r) - med_float vecX = currentPt.mXYZ[0] - pCenterX; - med_float vecY = currentPt.mXYZ[1] - pCenterY; - med_float vecZ = currentPt.mXYZ[2] - pCenterZ; - - med_float norm = med_float( sqrt( vecX*vecX + vecY*vecY + vecZ*vecZ ) ); - if (norm < pRadius) - { - // only add the point if it is different from (x, y, z) - if ((currentPt.mXYZ[0] != pCenterX) || - (currentPt.mXYZ[1] != pCenterY) || - (currentPt.mXYZ[2] != pCenterZ)) - { - res.push_back(currentPt); - } - } - } - } - } - } - - return res; + vector& cell = mGrid[idCell]; + + // for all the points in the current cell + for (vector::const_iterator itPoint = cell.begin() ; itPoint != cell.end() ; itPoint++) + { + const PointOfField& currentPt = *itPoint; + + // test if currentPt is in the sphere ((x, y, z), r) + med_float vecX = currentPt.mXYZ[0] - pCenterX; + med_float vecY = currentPt.mXYZ[1] - pCenterY; + med_float vecZ = currentPt.mXYZ[2] - pCenterZ; + + med_float norm = med_float( sqrt( vecX*vecX + vecY*vecY + vecZ*vecZ ) ); + if (norm < pRadius) + { + // only add the point if it is different from (x, y, z) + if ((currentPt.mXYZ[0] != pCenterX) || + (currentPt.mXYZ[1] != pCenterY) || + (currentPt.mXYZ[2] != pCenterZ)) + { + res.push_back(currentPt); + } + } + } + } + } + } + + return res; } void DecimationAccelGrid::computeBBox(const std::vector& pPts) { - for (int itDim = 0 ; itDim < 3 ; itDim++) - { - mMin[itDim] = numeric_limits::max(); - mMax[itDim] = -mMin[itDim]; - } - - for (unsigned i = 0 ; i < pPts.size() ; i++) - { - for (int itDim = 0 ; itDim < 3 ; itDim++) - { - med_float coord = pPts[i].mXYZ[itDim]; - if (coord < mMin[itDim]) mMin[itDim] = coord; - if (coord > mMax[itDim]) mMax[itDim] = coord; - } - } - - mInvLen[0] = med_float(mSize[0]) / (mMax[0] - mMin[0]); - mInvLen[1] = med_float(mSize[1]) / (mMax[1] - mMin[1]); - mInvLen[2] = med_float(mSize[2]) / (mMax[2] - mMin[2]); + for (int itDim = 0 ; itDim < 3 ; itDim++) + { + mMin[itDim] = numeric_limits::max(); + mMax[itDim] = -mMin[itDim]; + } + + for (unsigned i = 0 ; i < pPts.size() ; i++) + { + for (int itDim = 0 ; itDim < 3 ; itDim++) + { + med_float coord = pPts[i].mXYZ[itDim]; + if (coord < mMin[itDim]) mMin[itDim] = coord; + if (coord > mMax[itDim]) mMax[itDim] = coord; + } + } + + mInvLen[0] = med_float(mSize[0]) / (mMax[0] - mMin[0]); + mInvLen[1] = med_float(mSize[1]) / (mMax[1] - mMin[1]); + mInvLen[2] = med_float(mSize[2]) / (mMax[2] - mMin[2]); } ostream& operator<<(ostream& pOs, DecimationAccelGrid& pG) { - pOs << "DecimationAccelGrid:" << endl; - pOs << " Num=" << pG.mNum << endl; - pOs << " Size=" << pG.mSize[0] << " x " << pG.mSize[1] << " x " << pG.mSize[2] << endl; - pOs << " BBox=[" << pG.mMin[0] << " ; " << pG.mMax[0] << "] x [" << pG.mMin[1] << " ; " << pG.mMax[1] << "] x [" << pG.mMin[2] << " ; " << pG.mMax[2] << "]" << endl; - pOs << " Inv len.=" << pG.mInvLen[0] << " ; " << pG.mInvLen[1] << " ; " << pG.mInvLen[2] << endl; - - if (pG.mFlagPrintAll) - { - int checkNumCells = 0; - int numCells = pG.mSize[0] * pG.mSize[1] * pG.mSize[2]; - for (int i = 0 ; i < numCells ; i++) - { - vector& cell = pG.mGrid[i]; - cout << " Cell " << i << ": #=" << cell.size() << ": " << endl; - for (unsigned j = 0 ; j < cell.size() ; j++) - { - cout << " " << cell[j] << endl; - } - checkNumCells += cell.size(); - } - - if (pG.mNum != checkNumCells) throw IllegalStateException("", __FILE__, __LINE__); - } - - return pOs; + pOs << "DecimationAccelGrid:" << endl; + pOs << " Num=" << pG.mNum << endl; + pOs << " Size=" << pG.mSize[0] << " x " << pG.mSize[1] << " x " << pG.mSize[2] << endl; + pOs << " BBox=[" << pG.mMin[0] << " ; " << pG.mMax[0] << "] x [" << pG.mMin[1] << " ; " << pG.mMax[1] << "] x [" << pG.mMin[2] << " ; " << pG.mMax[2] << "]" << endl; + pOs << " Inv len.=" << pG.mInvLen[0] << " ; " << pG.mInvLen[1] << " ; " << pG.mInvLen[2] << endl; + + if (pG.mFlagPrintAll) + { + int checkNumCells = 0; + int numCells = pG.mSize[0] * pG.mSize[1] * pG.mSize[2]; + for (int i = 0 ; i < numCells ; i++) + { + vector& cell = pG.mGrid[i]; + cout << " Cell " << i << ": #=" << cell.size() << ": " << endl; + for (unsigned j = 0 ; j < cell.size() ; j++) + { + cout << " " << cell[j] << endl; + } + checkNumCells += cell.size(); + } + + if (pG.mNum != checkNumCells) throw IllegalStateException("", __FILE__, __LINE__); + } + + return pOs; } diff --git a/src/MULTIPR/MULTIPR_DecimationAccel.hxx b/src/MULTIPR/MULTIPR_DecimationAccel.hxx index f85f846..3697558 100644 --- a/src/MULTIPR/MULTIPR_DecimationAccel.hxx +++ b/src/MULTIPR/MULTIPR_DecimationAccel.hxx @@ -20,7 +20,7 @@ extern "C" { - #include "med.h" + #include "med.h" } #include @@ -42,81 +42,81 @@ class PointOfField; //***************************************************************************** class DecimationAccel -{ +{ public: - - /** - * Builds an empty DecimationAccel (default constructor). - */ - DecimationAccel() { /* do nothing */ } - - /** - * Destructor. Removes everything. - */ - virtual ~DecimationAccel() { /* do nothing */ } - - //--------------------------------------------------------------------- - // Algorithms - //--------------------------------------------------------------------- - - /** - * Interface. Configures this acceleration structure. String is used for genericity. - * \param pArgv all the configuration parameters in a string. - */ - virtual void configure(const char* pArgv) = 0; - - /** - * Interface. Creates a new acceleration structure and fills it with the given list of points. - * \param pPts list of points to be inserted in the acceleration structure. - */ - virtual void create(const std::vector& pPts) = 0; - - /** - * Interface. Finds all the points in a sphere defined by its center (x,y,z) and its radius. - * \param pCenterX x-coordinates of the center of the sphere. - * \param pCenterY y-coordinates of the center of the sphere. - * \param pCenterZ z-coordinates of the center of the sphere. - * \param pRadius radius of the sphere. - * \return all the points in a sphere defined by its center (x,y,z) and its radius. - */ - virtual std::vector findNeighbours( - med_float pCenterX, - med_float pCenterY, - med_float pCenterZ, - med_float pRadius) const = 0; - - //--------------------------------------------------------------------- - // I/O - //--------------------------------------------------------------------- - - /** - * Sets the flag which control the stream operator <<. - * \param pFlag new flag value. - */ - void setPrintAll(bool pFlag) { mFlagPrintAll = pFlag; } - - /** - * Dumps any GaussLoc to the given output stream. - * \param pOs any output stream. - * \param pA any DecimationAccel. - * \return the output stream pOs. - */ - friend std::ostream& operator<<(std::ostream& pOs, DecimationAccel& pA); - + + /** + * Builds an empty DecimationAccel (default constructor). + */ + DecimationAccel() { /* do nothing */ } + + /** + * Destructor. Removes everything. + */ + virtual ~DecimationAccel() { /* do nothing */ } + + //--------------------------------------------------------------------- + // Algorithms + //--------------------------------------------------------------------- + + /** + * Interface. Configures this acceleration structure. String is used for genericity. + * \param pArgv all the configuration parameters in a string. + */ + virtual void configure(const char* pArgv) = 0; + + /** + * Interface. Creates a new acceleration structure and fills it with the given list of points. + * \param pPts list of points to be inserted in the acceleration structure. + */ + virtual void create(const std::vector& pPts) = 0; + + /** + * Interface. Finds all the points in a sphere defined by its center (x,y,z) and its radius. + * \param pCenterX x-coordinates of the center of the sphere. + * \param pCenterY y-coordinates of the center of the sphere. + * \param pCenterZ z-coordinates of the center of the sphere. + * \param pRadius radius of the sphere. + * \return all the points in a sphere defined by its center (x,y,z) and its radius. + */ + virtual std::vector findNeighbours( + med_float pCenterX, + med_float pCenterY, + med_float pCenterZ, + med_float pRadius) const = 0; + + //--------------------------------------------------------------------- + // I/O + //--------------------------------------------------------------------- + + /** + * Sets the flag which control the stream operator <<. + * \param pFlag new flag value. + */ + void setPrintAll(bool pFlag) { mFlagPrintAll = pFlag; } + + /** + * Dumps any GaussLoc to the given output stream. + * \param pOs any output stream. + * \param pA any DecimationAccel. + * \return the output stream pOs. + */ + friend std::ostream& operator<<(std::ostream& pOs, DecimationAccel& pA); + protected: - bool mFlagPrintAll; /** Flag to control the behaviour of the stream operator <<. */ - + bool mFlagPrintAll; /** Flag to control the behaviour of the stream operator <<. */ + private: - - // do not allow copy constructor - DecimationAccel(const DecimationAccel&); - - // do not allow copy - DecimationAccel& operator=(const DecimationAccel&); - - // do not allow operator == - bool operator==(const DecimationAccel&); + + // do not allow copy constructor + DecimationAccel(const DecimationAccel&); + + // do not allow copy + DecimationAccel& operator=(const DecimationAccel&); + + // do not allow operator == + bool operator==(const DecimationAccel&); }; // class DecimationAccel @@ -129,124 +129,124 @@ class DecimationAccelGrid : public DecimationAccel { public: - /** - * Builds an empty DecimationAccelGrid (default constructor). - */ - DecimationAccelGrid(); - - /** - * Destructor. Removes everything. - */ - virtual ~DecimationAccelGrid(); - - /** - * Resets this object in its state by default (empty). Cleans memory. - */ - void reset(); - - //--------------------------------------------------------------------- - // Algorithms - //--------------------------------------------------------------------- - - /** - * Configures this acceleration structure. String is used for genericity. - * \param pArgv assumes "size_x size_y size_z": number of cells along each axis. - */ - virtual void configure(const char* pArgv); - - /** - * Creates a new acceleration structure and fills it with the given list of points. - * setSize() must have been called before. - * \param pPts list of points to be inserted in the acceleration structure. - * \throw IllegalStateException if setSize() has not been called before. - */ - virtual void create(const std::vector& pPts); - - /** - * Finds all the points in a sphere defined by its center (x,y,z) and its radius. - * \param pCenterX x-coordinates of the center of the sphere. - * \param pCenterY y-coordinates of the center of the sphere. - * \param pCenterZ z-coordinates of the center of the sphere. - * \param pRadius radius of the sphere. - * \return all the points in a sphere defined by its center (x,y,z) and its radius. - */ - virtual std::vector findNeighbours( - med_float pCenterX, - med_float pCenterY, - med_float pCenterZ, - med_float pRadius) const; - - /** - * Returns the coordinates of the cell which contain the point (x,y,z). - * Clamping is performed on (pIx, pIy, pIz) to avoid out of bounds. - * \param pX (in) X-coordinates of the point. - * \param pY (in) Y-coordinates of the point. - * \param pZ (in) Z-coordinates of the point. - * \param pIx (out) X-index of the cell which contain the point (x,y,z). - * \param pIy (out) Y-index. - * \param pIz (out) Z-index. - */ - void getCellCoord( - med_float pX, med_float pY, med_float pZ, - int* pIx, int* pIy, int* pIz) const; - - /** - * Returns the index of the cell whose coordinates are (i, j, k). - * \param pI - * \param pJ - * \param pK - * \return the index of the cell (i, j, k). - */ - int getCellIndex(int pI, int pJ, int pK) const; - - /** - * Returns the list of points contained in the cell of pPt. - * \param pPt any point which coordinates are in the bbox of this acceleration structure. - * \return the list of points contained in the cell of pPt. - */ - std::vector& getCell(const PointOfField& pPt); - - //--------------------------------------------------------------------- - // I/O - //--------------------------------------------------------------------- - - /** - * Dumps any GaussLoc to the given output stream. - * \param pOs any output stream. - * \param pG any DecimationAccelGrid. - * \return the output stream pOs. - */ - friend std::ostream& operator<<(std::ostream& pOs, DecimationAccelGrid& pG); - + /** + * Builds an empty DecimationAccelGrid (default constructor). + */ + DecimationAccelGrid(); + + /** + * Destructor. Removes everything. + */ + virtual ~DecimationAccelGrid(); + + /** + * Resets this object in its state by default (empty). Cleans memory. + */ + void reset(); + + //--------------------------------------------------------------------- + // Algorithms + //--------------------------------------------------------------------- + + /** + * Configures this acceleration structure. String is used for genericity. + * \param pArgv assumes "size_x size_y size_z": number of cells along each axis. + */ + virtual void configure(const char* pArgv); + + /** + * Creates a new acceleration structure and fills it with the given list of points. + * setSize() must have been called before. + * \param pPts list of points to be inserted in the acceleration structure. + * \throw IllegalStateException if setSize() has not been called before. + */ + virtual void create(const std::vector& pPts); + + /** + * Finds all the points in a sphere defined by its center (x,y,z) and its radius. + * \param pCenterX x-coordinates of the center of the sphere. + * \param pCenterY y-coordinates of the center of the sphere. + * \param pCenterZ z-coordinates of the center of the sphere. + * \param pRadius radius of the sphere. + * \return all the points in a sphere defined by its center (x,y,z) and its radius. + */ + virtual std::vector findNeighbours( + med_float pCenterX, + med_float pCenterY, + med_float pCenterZ, + med_float pRadius) const; + + /** + * Returns the coordinates of the cell which contain the point (x,y,z). + * Clamping is performed on (pIx, pIy, pIz) to avoid out of bounds. + * \param pX (in) X-coordinates of the point. + * \param pY (in) Y-coordinates of the point. + * \param pZ (in) Z-coordinates of the point. + * \param pIx (out) X-index of the cell which contain the point (x,y,z). + * \param pIy (out) Y-index. + * \param pIz (out) Z-index. + */ + void getCellCoord( + med_float pX, med_float pY, med_float pZ, + int* pIx, int* pIy, int* pIz) const; + + /** + * Returns the index of the cell whose coordinates are (i, j, k). + * \param pI + * \param pJ + * \param pK + * \return the index of the cell (i, j, k). + */ + int getCellIndex(int pI, int pJ, int pK) const; + + /** + * Returns the list of points contained in the cell of pPt. + * \param pPt any point which coordinates are in the bbox of this acceleration structure. + * \return the list of points contained in the cell of pPt. + */ + std::vector& getCell(const PointOfField& pPt); + + //--------------------------------------------------------------------- + // I/O + //--------------------------------------------------------------------- + + /** + * Dumps any GaussLoc to the given output stream. + * \param pOs any output stream. + * \param pG any DecimationAccelGrid. + * \return the output stream pOs. + */ + friend std::ostream& operator<<(std::ostream& pOs, DecimationAccelGrid& pG); + private: - - /** - * Computes the axis-aligned bounding box of a set of points. - * Sets the fields mMin/mMax. - * \param pPts list of points. - */ - void computeBBox(const std::vector& pPts); - + + /** + * Computes the axis-aligned bounding box of a set of points. + * Sets the fields mMin/mMax. + * \param pPts list of points. + */ + void computeBBox(const std::vector& pPts); + private: - - int mNum; /**< Number of points in the grid. */ - med_float mMin[3]; /**< Bounding box, min corner. */ - med_float mMax[3]; /**< Bounding box, max corner. */ - med_float mInvLen[3]; /**< 1/length of cells, along each dimension. */ - med_int mSize[3]; /**< Number of cells along each dimension. */ - std::vector* mGrid; /**< Flatten grid structure; each cell is a vector of PointOfField. */ - + + int mNum; /**< Number of points in the grid. */ + med_float mMin[3]; /**< Bounding box, min corner. */ + med_float mMax[3]; /**< Bounding box, max corner. */ + med_float mInvLen[3]; /**< 1/length of cells, along each dimension; used to accelerate getCellCoord(). */ + med_int mSize[3]; /**< Number of cells along each dimension. */ + std::vector* mGrid; /**< Flatten grid structure; each cell is a vector of PointOfField. */ + private: - - // do not allow copy constructor - DecimationAccelGrid(const DecimationAccelGrid&); - - // do not allow copy - DecimationAccelGrid& operator=(const DecimationAccelGrid&); - - // do not allow operator == - bool operator==(const DecimationAccelGrid&); - + + // do not allow copy constructor + DecimationAccelGrid(const DecimationAccelGrid&); + + // do not allow copy + DecimationAccelGrid& operator=(const DecimationAccelGrid&); + + // do not allow operator == + bool operator==(const DecimationAccelGrid&); + }; // class DecimationAccelGrid diff --git a/src/MULTIPR/MULTIPR_DecimationFilter.cxx b/src/MULTIPR/MULTIPR_DecimationFilter.cxx index 82f226b..05c5c57 100644 --- a/src/MULTIPR/MULTIPR_DecimationFilter.cxx +++ b/src/MULTIPR/MULTIPR_DecimationFilter.cxx @@ -35,19 +35,19 @@ namespace multipr // Class DecimationFilter implementation //***************************************************************************** -// factory +// Factory used to build all filters from their name. DecimationFilter* DecimationFilter::create(const char* pFilterName) { - if (pFilterName == NULL) throw NullArgumentException("filter name should not be NULL", __FILE__, __LINE__); - - if (strcmp(pFilterName, "Filtre_GradientMoyen") == 0) - { - return new DecimationFilterGradAvg(); - } - else - { - throw IllegalArgumentException("unknown filter", __FILE__, __LINE__); - } + if (pFilterName == NULL) throw NullArgumentException("filter name should not be NULL", __FILE__, __LINE__); + + if (strcmp(pFilterName, "Filtre_GradientMoyen") == 0) + { + return new DecimationFilterGradAvg(); + } + else + { + throw IllegalArgumentException("unknown filter", __FILE__, __LINE__); + } } @@ -57,250 +57,250 @@ DecimationFilter* DecimationFilter::create(const char* pFilterName) DecimationFilterGradAvg::DecimationFilterGradAvg() { - // do nothing + // do nothing } DecimationFilterGradAvg::~DecimationFilterGradAvg() { - // do nothing + // do nothing } Mesh* DecimationFilterGradAvg::apply(Mesh* pMesh, const char* pArgv, const char* pNameNewMesh) { - //--------------------------------------------------------------------- - // Retrieve and check parameters - //--------------------------------------------------------------------- - if (pMesh == NULL) throw NullArgumentException("pMesh should not be NULL", __FILE__, __LINE__); - if (pArgv == NULL) throw NullArgumentException("pArgv should not be NULL", __FILE__, __LINE__); - if (pNameNewMesh == NULL) throw NullArgumentException("pNameNewMesh should not be NULL", __FILE__, __LINE__); - - char fieldName[MED_TAILLE_NOM + 1]; - int fieldIt; - double threshold; - double radius; - int boxing; // number of cells along axis (if 100 then grid will have 100*100*100 = 10**6 cells) - - int ret = sscanf(pArgv, "%s %d %lf %lf %d", - fieldName, - &fieldIt, - &threshold, - &radius, - &boxing); - - if (ret != 5) throw IllegalArgumentException("wrong number of arguments for filter GradAvg; expected 5 parameters", __FILE__, __LINE__); - - //--------------------------------------------------------------------- - // Retrieve field = for each point: get its coordinate and the value of the field - //--------------------------------------------------------------------- - Field* field = pMesh->getFieldByName(fieldName); - - if (field == NULL) throw IllegalArgumentException("field not found", __FILE__, __LINE__); - if ((fieldIt < 1) || (fieldIt > field->getNumberOfTimeSteps())) throw IllegalArgumentException("invalid field iteration", __FILE__, __LINE__); - - vector points; - pMesh->getAllPointsOfField(field, fieldIt, points); + //--------------------------------------------------------------------- + // Retrieve and check parameters + //--------------------------------------------------------------------- + if (pMesh == NULL) throw NullArgumentException("pMesh should not be NULL", __FILE__, __LINE__); + if (pArgv == NULL) throw NullArgumentException("pArgv should not be NULL", __FILE__, __LINE__); + if (pNameNewMesh == NULL) throw NullArgumentException("pNameNewMesh should not be NULL", __FILE__, __LINE__); + + char fieldName[MED_TAILLE_NOM + 1]; + int fieldIt; + double threshold; + double radius; + int boxing; // number of cells along axis (if 100 then grid will have 100*100*100 = 10**6 cells) + + int ret = sscanf(pArgv, "%s %d %lf %lf %d", + fieldName, + &fieldIt, + &threshold, + &radius, + &boxing); + + if (ret != 5) throw IllegalArgumentException("wrong number of arguments for filter GradAvg; expected 5 parameters", __FILE__, __LINE__); + + //--------------------------------------------------------------------- + // Retrieve field = for each point: get its coordinate and the value of the field + //--------------------------------------------------------------------- + Field* field = pMesh->getFieldByName(fieldName); + + if (field == NULL) throw IllegalArgumentException("field not found", __FILE__, __LINE__); + if ((fieldIt < 1) || (fieldIt > field->getNumberOfTimeSteps())) throw IllegalArgumentException("invalid field iteration", __FILE__, __LINE__); + + vector points; + pMesh->getAllPointsOfField(field, fieldIt, points); - //--------------------------------------------------------------------- - // Creates acceleration structure used to compute gradient - //--------------------------------------------------------------------- - DecimationAccel* accel = new DecimationAccelGrid(); - char strCfg[256]; // a string is used for genericity - sprintf(strCfg, "%d %d %d", boxing, boxing, boxing); - accel->configure(strCfg); - accel->create(points); - - //--------------------------------------------------------------------- - // Collects elements of the mesh to be kept - //--------------------------------------------------------------------- - set elementsToKeep; - - int numElements = pMesh->getNumberOfElements(); - int numGaussPointsByElt = points.size() / numElements; // for a TETRA10, should be 5 for a field of elements and 10 for a field of nodes - - // for each element - for (int itElt = 0 ; itElt < numElements ; itElt++) - { - bool keepElement = false; - - // for each Gauss point of the current element - for (int itPtGauss = 0 ; itPtGauss < numGaussPointsByElt ; itPtGauss++) - { - const PointOfField& currentPt = points[itElt * numGaussPointsByElt + itPtGauss]; - - vector neighbours = accel->findNeighbours( - currentPt.mXYZ[0], - currentPt.mXYZ[1], - currentPt.mXYZ[2], - radius); - - // if no neighbours => keep element - if (neighbours.size() == 0) - { - keepElement = true; - break; - } - - // otherwise compute gradient... - med_float normGrad = computeNormGrad(currentPt, neighbours); - - // debug - //cout << (itElt * numGaussPointsByElt + j) << ": " << normGrad << endl; - - if ((normGrad >= threshold) || isnan(normGrad)) - { - keepElement = true; - break; - } - } - - if (keepElement) - { - // add index of the element to keep (index must start at 1) - elementsToKeep.insert(itElt + 1); - } - } + //--------------------------------------------------------------------- + // Creates acceleration structure used to compute gradient + //--------------------------------------------------------------------- + DecimationAccel* accel = new DecimationAccelGrid(); + char strCfg[256]; // a string is used for genericity + sprintf(strCfg, "%d %d %d", boxing, boxing, boxing); + accel->configure(strCfg); + accel->create(points); + + //--------------------------------------------------------------------- + // Collects elements of the mesh to be kept + //--------------------------------------------------------------------- + set elementsToKeep; + + int numElements = pMesh->getNumberOfElements(); + int numGaussPointsByElt = points.size() / numElements; // for a TETRA10, should be 5 for a field of elements and 10 for a field of nodes + + // for each element + for (int itElt = 0 ; itElt < numElements ; itElt++) + { + bool keepElement = false; + + // for each Gauss point of the current element + for (int itPtGauss = 0 ; itPtGauss < numGaussPointsByElt ; itPtGauss++) + { + const PointOfField& currentPt = points[itElt * numGaussPointsByElt + itPtGauss]; + + vector neighbours = accel->findNeighbours( + currentPt.mXYZ[0], + currentPt.mXYZ[1], + currentPt.mXYZ[2], + radius); + + // if no neighbours => keep element + if (neighbours.size() == 0) + { + keepElement = true; + break; + } + + // otherwise compute gradient... + med_float normGrad = computeNormGrad(currentPt, neighbours); + + // debug + //cout << (itElt * numGaussPointsByElt + j) << ": " << normGrad << endl; + + if ((normGrad >= threshold) || isnan(normGrad)) + { + keepElement = true; + break; + } + } + + if (keepElement) + { + // add index of the element to keep (index must start at 1) + elementsToKeep.insert(itElt + 1); + } + } - //--------------------------------------------------------------------- - // Cleans - //--------------------------------------------------------------------- - delete accel; - - //--------------------------------------------------------------------- - // Create the final mesh by extracting elements to keep from the current mesh - //--------------------------------------------------------------------- - Mesh* newMesh = pMesh->createFromSetOfElements(elementsToKeep, pNameNewMesh); - - return newMesh; + //--------------------------------------------------------------------- + // Cleans + //--------------------------------------------------------------------- + delete accel; + + //--------------------------------------------------------------------- + // Create the final mesh by extracting elements to keep from the current mesh + //--------------------------------------------------------------------- + Mesh* newMesh = pMesh->createFromSetOfElements(elementsToKeep, pNameNewMesh); + + return newMesh; } void DecimationFilterGradAvg::getGradientInfo( - Mesh* pMesh, - const char* pFieldName, - int pFieldIt, - double pRadius, - int pBoxing, - double* pOutGradMin, - double* pOutGradAvg, - double* pOutGradMax) + Mesh* pMesh, + const char* pFieldName, + int pFieldIt, + double pRadius, + int pBoxing, + double* pOutGradMin, + double* pOutGradAvg, + double* pOutGradMax) { - if (pMesh == NULL) throw NullArgumentException("pMesh should not be NULL", __FILE__, __LINE__); - if (pFieldName == NULL) throw NullArgumentException("pFieldName should not be NULL", __FILE__, __LINE__); - - Field* field = pMesh->getFieldByName(pFieldName); - - if (field == NULL) throw IllegalArgumentException("field not found", __FILE__, __LINE__); - if ((pFieldIt < 1) || (pFieldIt > field->getNumberOfTimeSteps())) throw IllegalArgumentException("invalid field iteration", __FILE__, __LINE__); - - vector points; - pMesh->getAllPointsOfField(field, pFieldIt, points); + if (pMesh == NULL) throw NullArgumentException("pMesh should not be NULL", __FILE__, __LINE__); + if (pFieldName == NULL) throw NullArgumentException("pFieldName should not be NULL", __FILE__, __LINE__); + + Field* field = pMesh->getFieldByName(pFieldName); + + if (field == NULL) throw IllegalArgumentException("field not found", __FILE__, __LINE__); + if ((pFieldIt < 1) || (pFieldIt > field->getNumberOfTimeSteps())) throw IllegalArgumentException("invalid field iteration", __FILE__, __LINE__); + + vector points; + pMesh->getAllPointsOfField(field, pFieldIt, points); - //--------------------------------------------------------------------- - // Creates acceleration structure used to compute gradient - //--------------------------------------------------------------------- - DecimationAccel* accel = new DecimationAccelGrid(); - char strCfg[256]; // a string is used for genericity - sprintf(strCfg, "%d %d %d", pBoxing, pBoxing, pBoxing); - accel->configure(strCfg); - accel->create(points); - - //--------------------------------------------------------------------- - // Collects elements of the mesh to be kept - //--------------------------------------------------------------------- - - int numElements = pMesh->getNumberOfElements(); - int numGaussPointsByElt = points.size() / numElements; // for a TETRA10, should be 5 for a field of elements and 10 for a field of nodes - - *pOutGradMax = -1e300; - *pOutGradMin = 1e300; - *pOutGradAvg = 0.0; - int count = 0; - - //cout << "numElements=" << numElements << endl; - //cout << "num gauss pt by elt=" << numGaussPointsByElt << endl; - - // for each element - for (int itElt = 0 ; itElt < numElements ; itElt++) - { - // for each Gauss point of the current element - for (int itPtGauss = 0 ; itPtGauss < numGaussPointsByElt ; itPtGauss++) - { - const PointOfField& currentPt = points[itElt * numGaussPointsByElt + itPtGauss]; - - vector neighbours = accel->findNeighbours( - currentPt.mXYZ[0], - currentPt.mXYZ[1], - currentPt.mXYZ[2], - pRadius); - - // if no neighbours => keep element - if (neighbours.size() == 0) - { - continue; - } - - // otherwise compute gradient... - med_float normGrad = computeNormGrad(currentPt, neighbours); - - // debug - //cout << (itElt * numGaussPointsByElt + j) << ": " << normGrad << endl; - - if (!isnan(normGrad)) - { - if (normGrad > *pOutGradMax) *pOutGradMax = normGrad; - if (normGrad < *pOutGradMin) *pOutGradMin = normGrad; - *pOutGradAvg += normGrad; - count++; - } - } - } - - if (count != 0) *pOutGradAvg /= double(count); + //--------------------------------------------------------------------- + // Creates acceleration structure used to compute gradient + //--------------------------------------------------------------------- + DecimationAccel* accel = new DecimationAccelGrid(); + char strCfg[256]; // a string is used for genericity + sprintf(strCfg, "%d %d %d", pBoxing, pBoxing, pBoxing); + accel->configure(strCfg); + accel->create(points); + + //--------------------------------------------------------------------- + // Collects elements of the mesh to be kept + //--------------------------------------------------------------------- + + int numElements = pMesh->getNumberOfElements(); + int numGaussPointsByElt = points.size() / numElements; // for a TETRA10, should be 5 for a field of elements and 10 for a field of nodes + + *pOutGradMax = -1e300; + *pOutGradMin = 1e300; + *pOutGradAvg = 0.0; + int count = 0; + + //cout << "numElements=" << numElements << endl; + //cout << "num gauss pt by elt=" << numGaussPointsByElt << endl; + + // for each element + for (int itElt = 0 ; itElt < numElements ; itElt++) + { + // for each Gauss point of the current element + for (int itPtGauss = 0 ; itPtGauss < numGaussPointsByElt ; itPtGauss++) + { + const PointOfField& currentPt = points[itElt * numGaussPointsByElt + itPtGauss]; + + vector neighbours = accel->findNeighbours( + currentPt.mXYZ[0], + currentPt.mXYZ[1], + currentPt.mXYZ[2], + pRadius); + + // if no neighbours => keep element + if (neighbours.size() == 0) + { + continue; + } + + // otherwise compute gradient... + med_float normGrad = computeNormGrad(currentPt, neighbours); + + // debug + //cout << (itElt * numGaussPointsByElt + j) << ": " << normGrad << endl; + + if (!isnan(normGrad)) + { + if (normGrad > *pOutGradMax) *pOutGradMax = normGrad; + if (normGrad < *pOutGradMin) *pOutGradMin = normGrad; + *pOutGradAvg += normGrad; + count++; + } + } + } + + if (count != 0) *pOutGradAvg /= double(count); - //--------------------------------------------------------------------- - // Cleans - //--------------------------------------------------------------------- - delete accel; + //--------------------------------------------------------------------- + // Cleans + //--------------------------------------------------------------------- + delete accel; } med_float DecimationFilterGradAvg::computeNormGrad(const PointOfField& pPt, const std::vector& pNeighbours) const { - med_float gradX = 0.0; - med_float gradY = 0.0; - med_float gradZ = 0.0; + med_float gradX = 0.0; + med_float gradY = 0.0; + med_float gradZ = 0.0; - // for each neighbour - for (unsigned i = 0 ; i < pNeighbours.size() ; i++) - { - const PointOfField& neighbourPt = pNeighbours[i]; - - med_float vecX = neighbourPt.mXYZ[0] - pPt.mXYZ[0]; - med_float vecY = neighbourPt.mXYZ[1] - pPt.mXYZ[1]; - med_float vecZ = neighbourPt.mXYZ[2] - pPt.mXYZ[2]; - - med_float norm = med_float( sqrt( vecX*vecX + vecY*vecY + vecZ*vecZ ) ); - med_float val = neighbourPt.mVal - pPt.mVal; - - val /= norm; - - gradX += vecX * val; - gradY += vecY * val; - gradZ += vecZ * val; - } - - med_float invSize = 1.0 / med_float(pNeighbours.size()); - - gradX *= invSize; - gradY *= invSize; - gradZ *= invSize; - - med_float norm = med_float( sqrt( gradX*gradX + gradY*gradY + gradZ*gradZ ) ); - - return norm; - + // for each neighbour + for (unsigned i = 0 ; i < pNeighbours.size() ; i++) + { + const PointOfField& neighbourPt = pNeighbours[i]; + + med_float vecX = neighbourPt.mXYZ[0] - pPt.mXYZ[0]; + med_float vecY = neighbourPt.mXYZ[1] - pPt.mXYZ[1]; + med_float vecZ = neighbourPt.mXYZ[2] - pPt.mXYZ[2]; + + med_float norm = med_float( sqrt( vecX*vecX + vecY*vecY + vecZ*vecZ ) ); + med_float val = neighbourPt.mVal - pPt.mVal; + + val /= norm; + + gradX += vecX * val; + gradY += vecY * val; + gradZ += vecZ * val; + } + + med_float invSize = 1.0 / med_float(pNeighbours.size()); + + gradX *= invSize; + gradY *= invSize; + gradZ *= invSize; + + med_float norm = med_float( sqrt( gradX*gradX + gradY*gradY + gradZ*gradZ ) ); + + return norm; + } diff --git a/src/MULTIPR/MULTIPR_DecimationFilter.hxx b/src/MULTIPR/MULTIPR_DecimationFilter.hxx index 828da59..34e201e 100644 --- a/src/MULTIPR/MULTIPR_DecimationFilter.hxx +++ b/src/MULTIPR/MULTIPR_DecimationFilter.hxx @@ -20,7 +20,7 @@ extern "C" { - #include "med.h" + #include "med.h" } #include @@ -40,49 +40,50 @@ class PointOfField; //***************************************************************************** // Interface DecimationFilter and factory to build filters. +// Should be derivated to implement new filter. //***************************************************************************** class DecimationFilter { public: - /** - * Decimation filter factory. - * \param pFilterName name of the filter to be instanciated. - * \return a new instance of the given filter. - */ - static DecimationFilter* create(const char* pFilterName); - + /** + * Decimation filter factory. Must be used to build any new filter from its name. + * \param pFilterName name of the filter to be instanciated. + * \return a new instance of the given filter. + */ + static DecimationFilter* create(const char* pFilterName); + public: - - /** - * Builds an empty DecimationFilter (default constructor). - */ - DecimationFilter() { } - - /** - * Destructor. Removes everything. - */ - virtual ~DecimationFilter() { } - - /** - * Interface. Creates a new Mesh by decimating the given Mesh with this DecimationFilter. - * \param pMesh any mesh to be decimated; must not be NULL. - * \param pArgv all the arguments of the filter as a string; must not be NULL. - * \param pNameNewMesh name of the decimated mesh; must not be NULL. - * \return the decimated mesh. - */ - virtual Mesh* apply(Mesh* pMesh, const char* pArgv, const char* pNameNewMesh) = 0; - + + /** + * Builds an empty DecimationFilter (default constructor). + */ + DecimationFilter() { /* do nothing */ } + + /** + * Destructor. Removes everything. + */ + virtual ~DecimationFilter() { /* do nothing */ } + + /** + * Interface. Creates a new Mesh by decimating the given Mesh with this DecimationFilter. + * \param pMesh any mesh to be decimated; must not be NULL. + * \param pArgv all the arguments of the filter as a string; must not be NULL. + * \param pNameNewMesh name of the decimated mesh; must not be NULL. + * \return the decimated mesh. + */ + virtual Mesh* apply(Mesh* pMesh, const char* pArgv, const char* pNameNewMesh) = 0; + private: - - // do not allow copy constructor - DecimationFilter(const DecimationFilter&); - - // do not allow copy - DecimationFilter& operator=(const DecimationFilter&); - - // do not allow operator == - bool operator==(const DecimationFilter&); + + // do not allow copy constructor + DecimationFilter(const DecimationFilter&); + + // do not allow copy + DecimationFilter& operator=(const DecimationFilter&); + + // do not allow operator == + bool operator==(const DecimationFilter&); }; // class DecimationFilter @@ -95,67 +96,67 @@ class DecimationFilterGradAvg : public DecimationFilter { public: - /** - * Builds an empty DecimationFilterGradAvg (default constructor). - */ - DecimationFilterGradAvg(); - - /** - * Destructor. Removes everything. - */ - virtual ~DecimationFilterGradAvg(); - - /** - * Creates a new Mesh by decimating the given Mesh with this DecimationFilter. - * - * For each element - * Keep this element if all its points (related to a field) have a |gradient| > threshold. - * - * For each point, gradient is computed by considering all the neighbours in a sphere of radius r. - * - * \param pMesh any mesh to be decimated; must not be NULL. - * \param pArgv all the arguments of the filter as a string; must not be NULL. - * for GradAvg, expected "fieldName fieldIt threshold radius boxing" (5 parameters). - * \param pNameNewMesh name of the decimated mesh; must not be NULL. - * \return the decimated mesh. - */ - virtual Mesh* apply(Mesh* pMesh, const char* pArgv, const char* pNameNewMesh); - - /** - * Returns information about gradient. - */ - void getGradientInfo( - Mesh* pMesh, - const char* pFieldName, - int pFieldIt, - double pRadius, - int pBoxing, - double* pOutGradMin, - double* pOutGradAvg, - double* pOutGradMax); - + /** + * Builds an empty DecimationFilterGradAvg (default constructor). + */ + DecimationFilterGradAvg(); + + /** + * Destructor. Removes everything. + */ + virtual ~DecimationFilterGradAvg(); + + /** + * Creates a new Mesh by decimating the given Mesh with this DecimationFilter. + * + * For each element + * Keep this element if all its points (related to a field) have a |gradient| > threshold. + * + * For each point, gradient is computed by considering all the neighbours in a sphere of radius r. + * + * \param pMesh any mesh to be decimated; must not be NULL. + * \param pArgv all the arguments of the filter as a string; must not be NULL. + * for GradAvg, expected "fieldName fieldIt threshold radius boxing" (5 parameters). + * \param pNameNewMesh name of the decimated mesh; must not be NULL. + * \return the decimated mesh. + */ + virtual Mesh* apply(Mesh* pMesh, const char* pArgv, const char* pNameNewMesh); + + /** + * Returns information about gradient. + */ + void getGradientInfo( + Mesh* pMesh, + const char* pFieldName, + int pFieldIt, + double pRadius, + int pBoxing, + double* pOutGradMin, + double* pOutGradAvg, + double* pOutGradMax); + private: - /** - * Returns the norm of the gradient of the field at the given point. - * Sub-method used by apply(). - * \param pPt any point in the field. - * \param pNeigbours neighbourhood of pPt. - * \return the norm of the gradient of the field in pPt. - */ - med_float computeNormGrad(const PointOfField& pPt, const std::vector& pNeighbours) const; - + /** + * Returns the norm of the gradient of the field at the given point. + * Sub-method used by apply(). + * \param pPt any point in the field. + * \param pNeigbours neighbourhood of pPt. + * \return the norm of the gradient of the field in pPt. + */ + med_float computeNormGrad(const PointOfField& pPt, const std::vector& pNeighbours) const; + private: - - // do not allow copy constructor - DecimationFilterGradAvg(const DecimationFilterGradAvg&); - - // do not allow copy - DecimationFilterGradAvg& operator=(const DecimationFilterGradAvg&); - - // do not allow operator == - bool operator==(const DecimationFilterGradAvg&); - + + // do not allow copy constructor + DecimationFilterGradAvg(const DecimationFilterGradAvg&); + + // do not allow copy + DecimationFilterGradAvg& operator=(const DecimationFilterGradAvg&); + + // do not allow operator == + bool operator==(const DecimationFilterGradAvg&); + }; // class DecimationFilterGradAvg diff --git a/src/MULTIPR/MULTIPR_Elements.cxx b/src/MULTIPR/MULTIPR_Elements.cxx index 226267e..832474e 100644 --- a/src/MULTIPR/MULTIPR_Elements.cxx +++ b/src/MULTIPR/MULTIPR_Elements.cxx @@ -36,421 +36,421 @@ namespace multipr Elements::Elements() { - mId = NULL; - mFamIdent = NULL; - mNames = NULL; - mCon = NULL; - - reset(); + mId = NULL; + mFamIdent = NULL; + mNames = NULL; + mCon = NULL; + + reset(); } Elements::~Elements() { - reset(); + reset(); } void Elements::reset() { - mNum = 0; - mEntity = MED_MAILLE; - mGeom = MED_NONE; - mNumNodesByElt = 0; - mDim = 0; - - if (mId != NULL) { delete[] mId; mId = NULL; } - if (mFamIdent != NULL) { delete[] mFamIdent; mFamIdent = NULL; } - if (mNames != NULL) { delete[] mNames; mNames = NULL; } - if (mCon != NULL) { delete[] mCon; mCon = NULL; } - - mSetOfNodes.clear(); - - mFlagPrintAll = false; + mNum = 0; + mEntity = MED_MAILLE; + mGeom = MED_NONE; + mNumNodesByElt = 0; + mDim = 0; + + if (mId != NULL) { delete[] mId; mId = NULL; } + if (mFamIdent != NULL) { delete[] mFamIdent; mFamIdent = NULL; } + if (mNames != NULL) { delete[] mNames; mNames = NULL; } + if (mCon != NULL) { delete[] mCon; mCon = NULL; } + + mSetOfNodes.clear(); + + mFlagPrintAll = false; } med_int Elements::getFamilyIdentifier(med_int pIndex) const { - if ((pIndex < 0) || (pIndex >= mNum)) throw IndexOutOfBoundsException("", __FILE__, __LINE__); - - return mFamIdent[pIndex]; + if ((pIndex < 0) || (pIndex >= mNum)) throw IndexOutOfBoundsException("", __FILE__, __LINE__); + + return mFamIdent[pIndex]; } const med_int* Elements::getConnectivity(int pIndex) const { - if ((pIndex < 0) || (pIndex >= mNum)) throw IndexOutOfBoundsException("", __FILE__, __LINE__); - - return mCon + mNumNodesByElt * pIndex; + if ((pIndex < 0) || (pIndex >= mNum)) throw IndexOutOfBoundsException("", __FILE__, __LINE__); + + return mCon + mNumNodesByElt * pIndex; } void Elements::getCoordinates(med_int pIndexElt, const Nodes* pNodes, med_float* pCoo, int pFirst) const { - if ((pIndexElt < 0) || (pIndexElt >= mNum)) throw IndexOutOfBoundsException("", __FILE__, __LINE__); - if (pNodes == NULL) throw NullArgumentException("", __FILE__, __LINE__); - if (pCoo == NULL) throw NullArgumentException("", __FILE__, __LINE__); - - // get the list of nodes of the element - const med_int* con = getConnectivity(pIndexElt); - - med_float* destCoo = pCoo; - int size = sizeof(med_float) * mDim; - - // for each node of the element - int n = (mNumNodesByElt < pFirst) ? mNumNodesByElt : pFirst; - for (int i = 0 ; i < n ; i++) - { - // get index of node (MED index start at 1) - med_int indexNode = con[i] - 1; - - // get coordinates of this node - const med_float* srcCoo = pNodes->getCoordinates(indexNode); - - // copy coordinates to destCoo - memcpy(destCoo, srcCoo, size); - - // prepare next point - destCoo += mDim; - } + if ((pIndexElt < 0) || (pIndexElt >= mNum)) throw IndexOutOfBoundsException("", __FILE__, __LINE__); + if (pNodes == NULL) throw NullArgumentException("", __FILE__, __LINE__); + if (pCoo == NULL) throw NullArgumentException("", __FILE__, __LINE__); + + // get the list of nodes of the element + const med_int* con = getConnectivity(pIndexElt); + + med_float* destCoo = pCoo; + int size = sizeof(med_float) * mDim; + + // for each node of the element + int n = (mNumNodesByElt < pFirst) ? mNumNodesByElt : pFirst; + for (int i = 0 ; i < n ; i++) + { + // get index of node (MED index start at 1) + med_int indexNode = con[i] - 1; + + // get coordinates of this node + const med_float* srcCoo = pNodes->getCoordinates(indexNode); + + // copy coordinates to destCoo + memcpy(destCoo, srcCoo, size); + + // prepare next point + destCoo += mDim; + } } Elements* Elements::extractSubSet(const set& pSetIndices) const { - Elements* subset = new Elements(); - - //--------------------------------------------------------------------- - // Copy parameters - //--------------------------------------------------------------------- - subset->mNum = pSetIndices.size(); - subset->mEntity = mEntity; - subset->mGeom = mGeom; // e.g. 310 for a TETRA10 - subset->mNumNodesByElt = mNumNodesByElt; // e.g. 10 for a TETRA10 - subset->mDim = mDim; // e.g. 3 for a TETRA10 - - //--------------------------------------------------------------------- - // Allocate arrays - //--------------------------------------------------------------------- - subset->mFamIdent = new med_int[subset->mNum]; - subset->mCon = new med_int[mNumNodesByElt * subset->mNum]; - - //--------------------------------------------------------------------- - // Copy subset of familys id and connectivity. - //--------------------------------------------------------------------- - med_int* destCon = subset->mCon; - set::iterator itSet = pSetIndices.begin(); - for (int itElt = 0 ; itElt < subset->mNum; itElt++) - { - med_int srcIndex = (*itSet) - 1; // MED index start at 1 - subset->mFamIdent[itElt] = mFamIdent[srcIndex]; - - med_int* srcCon = mCon + srcIndex * mNumNodesByElt; - memcpy(destCon, srcCon, sizeof(med_int) * mNumNodesByElt); - - destCon += mNumNodesByElt; - itSet++; - } - - //--------------------------------------------------------------------- - // Copy subset of identifiers if necessary - //--------------------------------------------------------------------- - if (isIdentifiers()) - { - itSet = pSetIndices.begin(); - subset->mId = new med_int[subset->mNum]; - for (int itElt = 0 ; itElt < subset->mNum; itElt++) - { - med_int srcIndex = (*itSet) - 1; // MED index start at 1 - subset->mId[itElt] = mId[srcIndex]; - - itSet++; - } - } - - //--------------------------------------------------------------------- - // Copy subset of names if necessary - //--------------------------------------------------------------------- - if (isNames()) - { - itSet = pSetIndices.begin(); - subset->mNames = new char[MED_TAILLE_PNOM * subset->mNum + 1]; - char* destPtr = subset->mNames; - for (int itElt = 0 ; itElt < subset->mNum; itElt++) - { - med_int srcIndex = (*itSet) - 1; // MED index start at 1 - char* srcPtr = mNames + srcIndex * MED_TAILLE_PNOM; - memcpy(destPtr, srcPtr, MED_TAILLE_PNOM); - - destPtr += MED_TAILLE_PNOM; - itSet++; - } - subset->mNames[MED_TAILLE_PNOM * subset->mNum] = '\0'; - } - - return subset; + Elements* subset = new Elements(); + + //--------------------------------------------------------------------- + // Copy parameters + //--------------------------------------------------------------------- + subset->mNum = pSetIndices.size(); + subset->mEntity = mEntity; + subset->mGeom = mGeom; // e.g. 310 for a TETRA10 + subset->mNumNodesByElt = mNumNodesByElt; // e.g. 10 for a TETRA10 + subset->mDim = mDim; // e.g. 3 for a TETRA10 + + //--------------------------------------------------------------------- + // Allocate arrays + //--------------------------------------------------------------------- + subset->mFamIdent = new med_int[subset->mNum]; + subset->mCon = new med_int[mNumNodesByElt * subset->mNum]; + + //--------------------------------------------------------------------- + // Copy subset of familys id and connectivity. + //--------------------------------------------------------------------- + med_int* destCon = subset->mCon; + set::iterator itSet = pSetIndices.begin(); + for (int itElt = 0 ; itElt < subset->mNum; itElt++) + { + med_int srcIndex = (*itSet) - 1; // MED index start at 1 + subset->mFamIdent[itElt] = mFamIdent[srcIndex]; + + med_int* srcCon = mCon + srcIndex * mNumNodesByElt; + memcpy(destCon, srcCon, sizeof(med_int) * mNumNodesByElt); + + destCon += mNumNodesByElt; + itSet++; + } + + //--------------------------------------------------------------------- + // Copy subset of identifiers if necessary + //--------------------------------------------------------------------- + if (isIdentifiers()) + { + itSet = pSetIndices.begin(); + subset->mId = new med_int[subset->mNum]; + for (int itElt = 0 ; itElt < subset->mNum; itElt++) + { + med_int srcIndex = (*itSet) - 1; // MED index start at 1 + subset->mId[itElt] = mId[srcIndex]; + + itSet++; + } + } + + //--------------------------------------------------------------------- + // Copy subset of names if necessary + //--------------------------------------------------------------------- + if (isNames()) + { + itSet = pSetIndices.begin(); + subset->mNames = new char[MED_TAILLE_PNOM * subset->mNum + 1]; + char* destPtr = subset->mNames; + for (int itElt = 0 ; itElt < subset->mNum; itElt++) + { + med_int srcIndex = (*itSet) - 1; // MED index start at 1 + char* srcPtr = mNames + srcIndex * MED_TAILLE_PNOM; + memcpy(destPtr, srcPtr, MED_TAILLE_PNOM); + + destPtr += MED_TAILLE_PNOM; + itSet++; + } + subset->mNames[MED_TAILLE_PNOM * subset->mNum] = '\0'; + } + + return subset; } const set& Elements::getSetOfNodes() -{ - // lazy get: test if mSetOfNodes has already been built - if (mSetOfNodes.size() == 0) - { - buildSetOfNodes(); - } - - return mSetOfNodes; +{ + // lazy get: test if mSetOfNodes has already been built + if (mSetOfNodes.size() == 0) + { + buildSetOfNodes(); + } + + return mSetOfNodes; } set Elements::getSetOfFamilies() const { - // set of families is empty at the beginning - set setOfFamilies; - - // for each element, add its family to the set - for (int itElt = 0 ; itElt < mNum ; itElt++) - { - setOfFamilies.insert(mFamIdent[itElt]); - } - - return setOfFamilies; + // set of families is empty at the beginning + set setOfFamilies; + + // for each element, add its family to the set + for (int itElt = 0 ; itElt < mNum ; itElt++) + { + setOfFamilies.insert(mFamIdent[itElt]); + } + + return setOfFamilies; } void Elements::remap() { - // build set of nodes if necessary - if (mSetOfNodes.size() == 0) - { - buildSetOfNodes(); - } - - // build the map for indices convertion - map mapOldIndexToNewIndex; - med_int newIndex = 1; // MED index start at 1 - for (set::iterator itSet = mSetOfNodes.begin(); itSet != mSetOfNodes.end() ; itSet++) - { - med_int oldIndex = (*itSet); - mapOldIndexToNewIndex.insert(make_pair(oldIndex, newIndex)); - newIndex++; - } - - // for each node referenced by this set of elements - for (int itNode = 0, size = mNum * mNumNodesByElt ; itNode < size ; itNode++) - { - // convert old index to new index (remap) - mCon[itNode] = mapOldIndexToNewIndex[mCon[itNode]]; - } - - buildSetOfNodes(); + // build set of nodes if necessary + if (mSetOfNodes.size() == 0) + { + buildSetOfNodes(); + } + + // build the map for indices convertion + map mapOldIndexToNewIndex; + med_int newIndex = 1; // MED index start at 1 + for (set::iterator itSet = mSetOfNodes.begin(); itSet != mSetOfNodes.end() ; itSet++) + { + med_int oldIndex = (*itSet); + mapOldIndexToNewIndex.insert(make_pair(oldIndex, newIndex)); + newIndex++; + } + + // for each node referenced by this set of elements + for (int itNode = 0, size = mNum * mNumNodesByElt ; itNode < size ; itNode++) + { + // convert old index to new index (remap) + mCon[itNode] = mapOldIndexToNewIndex[mCon[itNode]]; + } + + buildSetOfNodes(); } void Elements::buildSetOfNodes() { - if (mSetOfNodes.size() != 0) - { - mSetOfNodes.clear(); - } - - // for each node referenced by this set of elements - for (int itNode = 0, size = mNum * mNumNodesByElt ; itNode < size ; itNode++) - { - // add the node to the set - mSetOfNodes.insert(mCon[itNode]); - } + if (mSetOfNodes.size() != 0) + { + mSetOfNodes.clear(); + } + + // for each node referenced by this set of elements + for (int itNode = 0, size = mNum * mNumNodesByElt ; itNode < size ; itNode++) + { + // add the node to the set + mSetOfNodes.insert(mCon[itNode]); + } } void Elements::readMED( - med_idt pMEDfile, - char* pMeshName, - med_int pMeshDim, - med_entite_maillage pEntity, - med_geometrie_element pGeom) + med_idt pMEDfile, + char* pMeshName, + med_int pMeshDim, + med_entite_maillage pEntity, + med_geometrie_element pGeom) { - if (pMEDfile == 0) throw IOException("", __FILE__, __LINE__); - if (pMeshName == NULL) throw NullArgumentException("", __FILE__, __LINE__); - if ((pMeshDim < 1) || (pMeshDim > 3)) throw IllegalArgumentException("", __FILE__, __LINE__); - - reset(); - - mEntity = pEntity; - mGeom = pGeom; - mNumNodesByElt = mGeom % 100; - mDim = mGeom / 100; - - mNum = MEDnEntMaa( - pMEDfile, - pMeshName, - MED_CONN, // type of information requested = CONNECTIVITY - pEntity, - pGeom, - MED_NOD); // nodal connectivity - - if (mNum < 0) throw IOException("i/o error while reading information about elements in MED file", __FILE__, __LINE__); - - mCon = new med_int[mNumNodesByElt * mNum]; - mNames = new char[MED_TAILLE_PNOM * mNum + 1]; - mId = new med_int[mNum]; - mFamIdent = new med_int[mNum]; - med_booleen isNames; - med_booleen isIdentifiers; - - med_err ret = MEDelementsLire( - pMEDfile, - pMeshName, - pMeshDim, - mCon, - MED_FULL_INTERLACE, - mNames, - &isNames, - mId, - &isIdentifiers, - mFamIdent, - mNum, - mEntity, - mGeom, - MED_NOD); // NODAL CONNECTIVITY - - if (ret != 0) throw IOException("i/o error while reading elements in MED file", __FILE__, __LINE__); - - if (!isNames) - { - delete[] mNames; - mNames = NULL; - } - - if (!isIdentifiers) - { - delete[] mId; - mId = NULL; - } + if (pMEDfile == 0) throw IOException("", __FILE__, __LINE__); + if (pMeshName == NULL) throw NullArgumentException("", __FILE__, __LINE__); + if ((pMeshDim < 1) || (pMeshDim > 3)) throw IllegalArgumentException("", __FILE__, __LINE__); + + reset(); + + mEntity = pEntity; + mGeom = pGeom; + mNumNodesByElt = mGeom % 100; + mDim = mGeom / 100; + + mNum = MEDnEntMaa( + pMEDfile, + pMeshName, + MED_CONN, // type of information requested = CONNECTIVITY + pEntity, + pGeom, + MED_NOD); // nodal connectivity + + if (mNum < 0) throw IOException("i/o error while reading information about elements in MED file", __FILE__, __LINE__); + + mCon = new med_int[mNumNodesByElt * mNum]; + mNames = new char[MED_TAILLE_PNOM * mNum + 1]; + mId = new med_int[mNum]; + mFamIdent = new med_int[mNum]; + med_booleen isNames; + med_booleen isIdentifiers; + + med_err ret = MEDelementsLire( + pMEDfile, + pMeshName, + pMeshDim, + mCon, + MED_FULL_INTERLACE, + mNames, + &isNames, + mId, + &isIdentifiers, + mFamIdent, + mNum, + mEntity, + mGeom, + MED_NOD); // NODAL CONNECTIVITY + + if (ret != 0) throw IOException("i/o error while reading elements in MED file", __FILE__, __LINE__); + + if (!isNames) + { + delete[] mNames; + mNames = NULL; + } + + if (!isIdentifiers) + { + delete[] mId; + mId = NULL; + } } void Elements::writeMED(med_idt pMEDfile, char* pMeshName, med_int pMeshDim) { - if (pMEDfile == 0) throw IOException("", __FILE__, __LINE__); - if (pMeshName == NULL) throw NullArgumentException("", __FILE__, __LINE__); - if (strlen(pMeshName) > MED_TAILLE_NOM) throw IllegalArgumentException("", __FILE__, __LINE__); - if ((pMeshDim < 1) || (pMeshDim > 3)) throw IllegalArgumentException("", __FILE__, __LINE__); - - // special case: if no elements => do nothing - if (mNum == 0) return; - - med_err ret = MEDelementsEcr( - pMEDfile, - pMeshName, - pMeshDim, - mCon, - MED_FULL_INTERLACE, - mNames, - isNames()?MED_VRAI:MED_FAUX, - mId, - isIdentifiers()?MED_VRAI:MED_FAUX, - mFamIdent, - mNum, - mEntity, - mGeom, - MED_NOD); // NODAL CONNECTIVITY - - if (ret != 0) throw IOException("i/o error while writing elements in MED file", __FILE__, __LINE__); + if (pMEDfile == 0) throw IOException("", __FILE__, __LINE__); + if (pMeshName == NULL) throw NullArgumentException("", __FILE__, __LINE__); + if (strlen(pMeshName) > MED_TAILLE_NOM) throw IllegalArgumentException("", __FILE__, __LINE__); + if ((pMeshDim < 1) || (pMeshDim > 3)) throw IllegalArgumentException("", __FILE__, __LINE__); + + // special case: if no elements => do nothing + if (mNum == 0) return; + + med_err ret = MEDelementsEcr( + pMEDfile, + pMeshName, + pMeshDim, + mCon, + MED_FULL_INTERLACE, + mNames, + isNames()?MED_VRAI:MED_FAUX, + mId, + isIdentifiers()?MED_VRAI:MED_FAUX, + mFamIdent, + mNum, + mEntity, + mGeom, + MED_NOD); // NODAL CONNECTIVITY + + if (ret != 0) throw IOException("i/o error while writing elements in MED file", __FILE__, __LINE__); } ostream& operator<<(ostream& pOs, Elements& pE) { - char strEntity[16]; - switch (pE.mEntity) - { - case MED_MAILLE: strcpy(strEntity, "MED_MAILLE"); break; - case MED_FACE: strcpy(strEntity, "MED_FACE"); break; - case MED_ARETE: strcpy(strEntity, "MED_ARETE"); break; - case MED_NOEUD: strcpy(strEntity, "MED_NOEUD"); break; - default: strcpy(strEntity, "UNKNOWN"); break; - } - - pOs << "Elements: " << endl; - pOs << " #number =" << pE.mNum << endl; - pOs << " Entity =" << strEntity << endl; - pOs << " Geom =" << pE.mGeom << endl; - pOs << " Has names?" << (pE.isNames()?"yes":"no") << endl; - pOs << " Has id ?" << (pE.isIdentifiers()?"yes":"no") << endl; - - { - set setOfFam = pE.getSetOfFamilies(); - if (setOfFam.size() == 0) - { - pOs << " Families: #fam=0" << endl; - } - else - { - set::iterator itFam = setOfFam.end(); - itFam--; - pOs << " Families: #fam=" << setOfFam.size() << " id_min=" << (*(setOfFam.begin())) << " id_max=" << (*itFam) << endl; - - if (pE.mFlagPrintAll) - { - for (int i = 0 ; i < pE.mNum; i++) - { - pOs << " Elt " << (i + 1) << ": " << pE.mFamIdent[i] << endl; - } - } - } - } - - { - set setOfNodes = pE.getSetOfNodes(); - if (setOfNodes.size() == 0) - { - pOs << " Connectivity: #nodes=0" << endl; - } - else - { - set::iterator itNode = setOfNodes.end(); - itNode--; - pOs << " Connectivity: #nodes=" << setOfNodes.size() << " id_min=" << (*(setOfNodes.begin())) << " id_max=" << (*itNode) << endl; - - if (pE.mFlagPrintAll) - { - for (int i = 0 ; i < pE.mNum ; i++) - { - pOs << " Elt " << (i + 1) << ": "; - for (int j = 0 ; j < pE.mNumNodesByElt ; j++) - { - pOs << pE.mCon[i * pE.mNumNodesByElt + j] << " "; - } - pOs << endl; - } - } - } - } - - if (pE.mFlagPrintAll) - { - - if (pE.isIdentifiers()) - { - pOs << " Num (identifier): " << endl; - for (int i = 0 ; i < pE.mNum; i++) - { - pOs << " Elt " << (i + 1) << ": " << pE.mId[i] << " " << endl; - } - } - - if (pE.isNames()) - { - pE.mNames[MED_TAILLE_PNOM * pE.mNum] = '\0'; - pOs << " Names: |" << pE.mNames << "|" << endl; - } - - } - - return pOs; + char strEntity[16]; + switch (pE.mEntity) + { + case MED_MAILLE: strcpy(strEntity, "MED_MAILLE"); break; + case MED_FACE: strcpy(strEntity, "MED_FACE"); break; + case MED_ARETE: strcpy(strEntity, "MED_ARETE"); break; + case MED_NOEUD: strcpy(strEntity, "MED_NOEUD"); break; + default: strcpy(strEntity, "UNKNOWN"); break; + } + + pOs << "Elements: " << endl; + pOs << " #number =" << pE.mNum << endl; + pOs << " Entity =" << strEntity << endl; + pOs << " Geom =" << pE.mGeom << endl; + pOs << " Has names?" << (pE.isNames()?"yes":"no") << endl; + pOs << " Has id ?" << (pE.isIdentifiers()?"yes":"no") << endl; + + { + set setOfFam = pE.getSetOfFamilies(); + if (setOfFam.size() == 0) + { + pOs << " Families: #fam=0" << endl; + } + else + { + set::iterator itFam = setOfFam.end(); + itFam--; + pOs << " Families: #fam=" << setOfFam.size() << " id_min=" << (*(setOfFam.begin())) << " id_max=" << (*itFam) << endl; + + if (pE.mFlagPrintAll) + { + for (int i = 0 ; i < pE.mNum; i++) + { + pOs << " Elt " << (i + 1) << ": " << pE.mFamIdent[i] << endl; + } + } + } + } + + { + set setOfNodes = pE.getSetOfNodes(); + if (setOfNodes.size() == 0) + { + pOs << " Connectivity: #nodes=0" << endl; + } + else + { + set::iterator itNode = setOfNodes.end(); + itNode--; + pOs << " Connectivity: #nodes=" << setOfNodes.size() << " id_min=" << (*(setOfNodes.begin())) << " id_max=" << (*itNode) << endl; + + if (pE.mFlagPrintAll) + { + for (int i = 0 ; i < pE.mNum ; i++) + { + pOs << " Elt " << (i + 1) << ": "; + for (int j = 0 ; j < pE.mNumNodesByElt ; j++) + { + pOs << pE.mCon[i * pE.mNumNodesByElt + j] << " "; + } + pOs << endl; + } + } + } + } + + if (pE.mFlagPrintAll) + { + + if (pE.isIdentifiers()) + { + pOs << " Num (identifier): " << endl; + for (int i = 0 ; i < pE.mNum; i++) + { + pOs << " Elt " << (i + 1) << ": " << pE.mId[i] << " " << endl; + } + } + + if (pE.isNames()) + { + pE.mNames[MED_TAILLE_PNOM * pE.mNum] = '\0'; + pOs << " Names: |" << pE.mNames << "|" << endl; + } + + } + + return pOs; } diff --git a/src/MULTIPR/MULTIPR_Elements.hxx b/src/MULTIPR/MULTIPR_Elements.hxx index 178aa4c..47c717f 100644 --- a/src/MULTIPR/MULTIPR_Elements.hxx +++ b/src/MULTIPR/MULTIPR_Elements.hxx @@ -23,7 +23,7 @@ extern "C" { - #include "med.h" + #include "med.h" } #include @@ -47,196 +47,196 @@ class Elements { public: - /** - * Builds an empty set of elements (default constructor). - */ - Elements(); - - /** - * Destructor. Removes everything. - */ - ~Elements(); - - /** - * Resets this object in its state by default (empty). Cleans memory. - */ - void reset(); - - //--------------------------------------------------------------------- - // Basic accessors/mutators - //--------------------------------------------------------------------- - - /** - * Returns true iff this object contains no elements (table of elements is empty). - * \return true iff this object contains no elements. - */ - bool isEmpty() const { return (mNum == 0); } - - /** - * Returns true iff elements have a name. - * \return true iff elements have a name. - */ - bool isNames() const { return (mNames != NULL); } - - /** - * Returns true iff elements have an identifier (= a number). - * \return true iff elements have an identifier (= a number). - */ - bool isIdentifiers() const { return (mId != NULL); } - - /** - * Returns the number of elements. - * \return the number of elements. - */ - int getNumberOfElements() const { return mNum; } - - /** - * Returns the type of primitives (e.g. MED_TETRA10). - * \return the type of primitives - */ - med_geometrie_element getTypeOfPrimitives() const { return mGeom; } - - /** - * Returns the number of nodes that composed an element. - * \return the number of nodes that composed an element. - */ - int getNumberOfNodesByElement() const { return mNumNodesByElt; } - - /** - * Returns the family associated with an element. - * \param pIndex index of any element in [0..NUMBER_OF_ELEMENTS-1]. - * \return the family associated with an element. - * \throw IndexOutOfBoundsException if pIndex is invalid. - */ - med_int getFamilyIdentifier(med_int pIndex) const; - - /** - * Returns the connectivity of one element. - * \param pIndex must be in [0..NUMBER_OF_ELEMENTS-1]. - * \return a pointer towards the table of connectivity of the element. - * \throw IndexOutOfBoundsException if pIndex is invalid. - */ - const med_int* getConnectivity(int pIndex) const; - - /** - * Returns the coordinates of all the nodes of one element. - * \param pIndexElt must be in [0..NUMBER_OF_ELEMENTS-1]. - * \param pNodes table of nodes, used to retrieve coordinates. - * \param pCoo (out) table of coordinates of nodes (e.g. 30 = 3 * 10 med_float for a TETRA10). - * \param pFirst only get the pFirst coordinates. - * \throw IndexOutOfBoundsException if pIndex is invalid. - */ - void getCoordinates(med_int pIndexElt, const Nodes* pNodes, med_float* pCoo, int pFirst = 100) const; - - //--------------------------------------------------------------------- - // Algorithms - //--------------------------------------------------------------------- - - /** - * Constructor. Creates a subset of this set of elements from a set of indices. - * \param pSetIndices set of indices (start at 1). - * \return a restriction of this set of elements. - */ - Elements* extractSubSet(const std::set& pSetIndices) const; - - /** - * Returns the set of indices (starting at 1) of all nodes used by this set of elements. - * \return the set of indices of all nodes used by this set of elements. - */ - const std::set& getSetOfNodes(); - - /** - * Returns the set of families referenced by this set of elements. - * Each family is described by its identifier. - * \return Returns the set of families referenced by this set of elements. - */ - std::set getSetOfFamilies() const; - - /** - * Remaps this set of elements such that indices of nodes are continous 1 2 3 4 5 ... * - * This method is intended to be used after extractSubSet(). - */ - void remap(); - - //--------------------------------------------------------------------- - // I/O - //--------------------------------------------------------------------- - - /** - * Reads a set of elements from a MED file. - * You must give: name of mesh, dimension of the mesh, type of entity and type of elements. - * \param pMEDfile any valid MED file opened for reading. - * \param pMeshName name of the mesh. - * \param pMeshDim dimension of the mesh. - * \param pEntity entity to be read (e.g. MED_MAILLE). - * \param pGeom type of primitves to be read (e.g. MED_TETRA10). - * \throw IOException if any i/o error occurs. - */ - void readMED( - med_idt pMEDfile, - char* pMeshName, - med_int pMeshDim, - med_entite_maillage pEntity, - med_geometrie_element pGeom); - - /** - * Writes this set of elements to a MED file. - * WARNING: mesh must have been created and added to the MED file before. - * \param pMEDfile any valid MED file opened for writing. - * \param pMeshName name of the mesh. - * \param pMeshDim dimension of the mesh. - * \throw IOException if any i/o error occurs. - */ - void writeMED(med_idt pMEDfile, char* pMeshName, med_int pMeshDim); - - /** - * Sets the flag which control the stream operator <<. - * \param pFlag new flag value. - */ - void setPrintAll(bool pFlag) { mFlagPrintAll = pFlag; } - - /** - * Dumps any Elements to the given output stream. - * \param pOs any output stream. - * \param pE any Elements. - * \return the output stream pOs. - */ - friend std::ostream& operator<<(std::ostream& pOs, Elements& pE); + /** + * Builds an empty set of elements (default constructor). + */ + Elements(); + + /** + * Destructor. Removes everything. + */ + ~Elements(); + + /** + * Resets this object in its state by default (empty). Cleans memory. + */ + void reset(); + + //--------------------------------------------------------------------- + // Basic accessors/mutators + //--------------------------------------------------------------------- + + /** + * Returns true iff this object contains no elements (table of elements is empty). + * \return true iff this object contains no elements. + */ + bool isEmpty() const { return (mNum == 0); } + + /** + * Returns true iff elements have a name. + * \return true iff elements have a name. + */ + bool isNames() const { return (mNames != NULL); } + + /** + * Returns true iff elements have an identifier (= a number). + * \return true iff elements have an identifier (= a number). + */ + bool isIdentifiers() const { return (mId != NULL); } + + /** + * Returns the number of elements. + * \return the number of elements. + */ + int getNumberOfElements() const { return mNum; } + + /** + * Returns the type of primitives (e.g. MED_TETRA10). + * \return the type of primitives + */ + med_geometrie_element getTypeOfPrimitives() const { return mGeom; } + + /** + * Returns the number of nodes that composed an element. + * \return the number of nodes that composed an element. + */ + int getNumberOfNodesByElement() const { return mNumNodesByElt; } + + /** + * Returns the family associated with an element. + * \param pIndex index of any element in [0..NUMBER_OF_ELEMENTS-1]. + * \return the family associated with an element. + * \throw IndexOutOfBoundsException if pIndex is invalid. + */ + med_int getFamilyIdentifier(med_int pIndex) const; + + /** + * Returns the connectivity of one element. + * \param pIndex must be in [0..NUMBER_OF_ELEMENTS-1]. + * \return a pointer towards the table of connectivity of the element. + * \throw IndexOutOfBoundsException if pIndex is invalid. + */ + const med_int* getConnectivity(int pIndex) const; + + /** + * Returns the coordinates of all the nodes of one element. + * \param pIndexElt must be in [0..NUMBER_OF_ELEMENTS-1]. + * \param pNodes table of nodes, used to retrieve coordinates. + * \param pCoo (out) table of coordinates of nodes (e.g. 30 = 3 * 10 med_float for a TETRA10). + * \param pFirst only get the pFirst coordinates. + * \throw IndexOutOfBoundsException if pIndex is invalid. + */ + void getCoordinates(med_int pIndexElt, const Nodes* pNodes, med_float* pCoo, int pFirst = 100) const; + + //--------------------------------------------------------------------- + // Algorithms + //--------------------------------------------------------------------- + + /** + * Constructor. Creates a subset of this set of elements from a set of indices. + * \param pSetIndices set of indices (start at 1). + * \return a restriction of this set of elements. + */ + Elements* extractSubSet(const std::set& pSetIndices) const; + + /** + * Returns the set of indices (starting at 1) of all nodes used by this set of elements. + * \return the set of indices of all nodes used by this set of elements. + */ + const std::set& getSetOfNodes(); + + /** + * Returns the set of families referenced by this set of elements. + * Each family is described by its identifier. + * \return Returns the set of families referenced by this set of elements. + */ + std::set getSetOfFamilies() const; + + /** + * Remaps this set of elements such that indices of nodes are continous 1 2 3 4 5 ... * + * This method is intended to be used after extractSubSet(). + */ + void remap(); + + //--------------------------------------------------------------------- + // I/O + //--------------------------------------------------------------------- + + /** + * Reads a set of elements from a MED file. + * You must give: name of mesh, dimension of the mesh, type of entity and type of elements. + * \param pMEDfile any valid MED file opened for reading. + * \param pMeshName name of the mesh. + * \param pMeshDim dimension of the mesh. + * \param pEntity entity to be read (e.g. MED_MAILLE). + * \param pGeom type of primitves to be read (e.g. MED_TETRA10). + * \throw IOException if any i/o error occurs. + */ + void readMED( + med_idt pMEDfile, + char* pMeshName, + med_int pMeshDim, + med_entite_maillage pEntity, + med_geometrie_element pGeom); + + /** + * Writes this set of elements to a MED file. + * WARNING: mesh must have been created and added to the MED file before. + * \param pMEDfile any valid MED file opened for writing. + * \param pMeshName name of the mesh. + * \param pMeshDim dimension of the mesh. + * \throw IOException if any i/o error occurs. + */ + void writeMED(med_idt pMEDfile, char* pMeshName, med_int pMeshDim); + + /** + * Sets the flag which control the stream operator <<. + * \param pFlag new flag value. + */ + void setPrintAll(bool pFlag) { mFlagPrintAll = pFlag; } + + /** + * Dumps any Elements to the given output stream. + * \param pOs any output stream. + * \param pE any Elements. + * \return the output stream pOs. + */ + friend std::ostream& operator<<(std::ostream& pOs, Elements& pE); private: - - /** - * Builds the set of nodes used by this set of elements. - * If the set already exist, then it is cleared and a new set is computed. - */ - void buildSetOfNodes(); - + + /** + * Builds the set of nodes used by this set of elements. + * If the set already exist, then it is cleared and a new set is computed. + */ + void buildSetOfNodes(); + private: - - med_int mNum; /**< Number of elements. */ - med_entite_maillage mEntity; /**< Type of entity, e.g. MED_MAILLE. */ - med_geometrie_element mGeom; /**< Type of primitive, e.g. MED_TETRA10. */ - int mDim; /**< Dimension of elements = mGeom / 100. */ - int mNumNodesByElt; /**< Number of nodes by element = mGeom % 100. */ - med_int* mId; /**< Optional; for each element, its identifier; NULL if undefined. */ - med_int* mFamIdent; /**< For each element, its family (identifier). */ - char* mNames; /**< Optional; for each element, its name; NULL if undefined. */ - med_int* mCon; /**< For each element, list of nodes (index in 1..*) = table of connectivity. */ - std::set mSetOfNodes; /**< Set of all nodes used by this set of elements. */ - - bool mFlagPrintAll; /** Flag to control the behaviour of the stream operator <<. */ - + + med_int mNum; /**< Number of elements. */ + med_entite_maillage mEntity; /**< Type of entity, e.g. MED_MAILLE. */ + med_geometrie_element mGeom; /**< Type of primitive, e.g. MED_TETRA10. */ + int mDim; /**< Dimension of elements = mGeom / 100. */ + int mNumNodesByElt; /**< Number of nodes by element = mGeom % 100. */ + med_int* mId; /**< Optional; for each element, its identifier; NULL if undefined. */ + med_int* mFamIdent; /**< For each element, its family (identifier). */ + char* mNames; /**< Optional; for each element, its name; NULL if undefined. */ + med_int* mCon; /**< For each element, list of nodes (index in 1..*) = table of connectivity. */ + std::set mSetOfNodes; /**< Set of all nodes used by this set of elements. */ + + bool mFlagPrintAll; /** Flag to control the behaviour of the stream operator <<. */ + private: - // do not allow copy constructor - Elements(const Elements&); - - // do not allow copy - Elements& operator=(const Elements&); - - // do not allow operator == - bool operator==(const Elements&); - + // do not allow copy constructor + Elements(const Elements&); + + // do not allow copy + Elements& operator=(const Elements&); + + // do not allow operator == + bool operator==(const Elements&); + }; // class Elements diff --git a/src/MULTIPR/MULTIPR_Exceptions.hxx b/src/MULTIPR/MULTIPR_Exceptions.hxx index 2b25de1..14c200e 100644 --- a/src/MULTIPR/MULTIPR_Exceptions.hxx +++ b/src/MULTIPR/MULTIPR_Exceptions.hxx @@ -33,74 +33,74 @@ namespace multipr class RuntimeException { public: - - /** - * Constructor. Build a new RuntimeException. - * \param pMsg message to be associated with this exception. - * \param pFile name of the file where the probem occur (you can use the macro __FILE__); "unknown" by default. - * \param pLine number of the line where the probem occur (you can use the macro __LINE__); 0 by default. - */ - RuntimeException( - const std::string& pMsg, - const std::string& pFile = "unknown", - int pLine = 0) - { - mMsg = pMsg; - mFile = pFile; - mLine = pLine; - mType = "RuntimeException"; - } - - /** - * Dumps info about this exception to the given output stream. - */ - void dump(std::ostream& pOs) const - { - pOs << "MULTIPR: " << mType << " (" << mFile << ", line " << mLine << "): " << mMsg << std::endl; - } - + + /** + * Constructor. Build a new RuntimeException. + * \param pMsg message to be associated with this exception. + * \param pFile name of the file where the probem occur (you can use the macro __FILE__); "unknown" by default. + * \param pLine number of the line where the probem occur (you can use the macro __LINE__); 0 by default. + */ + RuntimeException( + const std::string& pMsg, + const std::string& pFile = "unknown", + int pLine = 0) + { + mMsg = pMsg; + mFile = pFile; + mLine = pLine; + mType = "RuntimeException"; + } + + /** + * Dumps info about this exception to the given output stream. + */ + void dump(std::ostream& pOs) const + { + pOs << "MULTIPR: " << mType << " (" << mFile << ", line " << mLine << "): " << mMsg << std::endl; + } + protected: - std::string mMsg; /**< Message associated with this exception. */ - std::string mFile; /**< Name of the source file where the problem occurs. */ - int mLine; /**< Number of the line where the problem occurs. */ - std::string mType; /**< Type of this exception. */ + std::string mMsg; /**< Message associated with this exception. */ + std::string mFile; /**< Name of the source file where the problem occurs (macro __FILE__ can be used to retrieve this field). */ + int mLine; /**< Number of the line where the problem occurs (macro __LINE__ can be used to retrieve this field). */ + std::string mType; /**< Type of this exception. */ }; //***************************************************************************** // Class NullArgumentException -// Should be used for a NULL pointer +// Should be used when an unexpected NULL pointer occurs //***************************************************************************** class NullArgumentException : public RuntimeException { public: - NullArgumentException( - const std::string& pMsg, - const std::string& pFile="unknown", - int pLine=0) : RuntimeException(pMsg, pFile, pLine) - { - mType = "NullArgumentException"; - } + NullArgumentException( + const std::string& pMsg, + const std::string& pFile="unknown", + int pLine=0) : RuntimeException(pMsg, pFile, pLine) + { + mType = "NullArgumentException"; + } }; //***************************************************************************** // Class IllegalArgumentException -// Should be used when a parameter is invalid (check precondition) +// Should be used when an invalid parameter is detected (check precondition) //***************************************************************************** class IllegalArgumentException : public RuntimeException { public: - IllegalArgumentException( - const std::string& pMsg, - const std::string& pFile="unknown", - int pLine=0) : RuntimeException(pMsg, pFile, pLine) - { - mType = "IllegalArgumentException"; - } + IllegalArgumentException( + const std::string& pMsg, + const std::string& pFile="unknown", + int pLine=0) : RuntimeException(pMsg, pFile, pLine) + { + mType = "IllegalArgumentException"; + } }; @@ -112,13 +112,13 @@ public: class IllegalStateException : public RuntimeException { public: - IllegalStateException( - const std::string& pMsg, - const std::string& pFile="unknown", - int pLine=0) : RuntimeException(pMsg, pFile, pLine) - { - mType = "IllegalStateException"; - } + IllegalStateException( + const std::string& pMsg, + const std::string& pFile="unknown", + int pLine=0) : RuntimeException(pMsg, pFile, pLine) + { + mType = "IllegalStateException"; + } }; @@ -130,13 +130,13 @@ public: class IndexOutOfBoundsException : public RuntimeException { public: - IndexOutOfBoundsException( - const std::string& pMsg, - const std::string& pFile="unknown", - int pLine=0) : RuntimeException(pMsg, pFile, pLine) - { - mType = "IndexOutOfBoundsException"; - } + IndexOutOfBoundsException( + const std::string& pMsg, + const std::string& pFile="unknown", + int pLine=0) : RuntimeException(pMsg, pFile, pLine) + { + mType = "IndexOutOfBoundsException"; + } }; @@ -148,13 +148,13 @@ public: class IOException : public RuntimeException { public: - IOException( - const std::string& pMsg, - const std::string& pFile="unknown", - int pLine=0) : RuntimeException(pMsg, pFile, pLine) - { - mType = "IOException"; - } + IOException( + const std::string& pMsg, + const std::string& pFile="unknown", + int pLine=0) : RuntimeException(pMsg, pFile, pLine) + { + mType = "IOException"; + } }; @@ -166,13 +166,13 @@ public: class FileNotFoundException : public IOException { public: - FileNotFoundException( - const std::string& pMsg, - const std::string& pFile="unknown", - int pLine=0) : IOException(pMsg, pFile, pLine) - { - mType = "FileNotFoundException"; - } + FileNotFoundException( + const std::string& pMsg, + const std::string& pFile="unknown", + int pLine=0) : IOException(pMsg, pFile, pLine) + { + mType = "FileNotFoundException"; + } }; @@ -185,13 +185,13 @@ public: class UnsupportedOperationException : public RuntimeException { public: - UnsupportedOperationException( - const std::string& pMsg, - const std::string& pFile="unknown", - int pLine=0) : RuntimeException(pMsg, pFile, pLine) - { - mType = "UnsupportedOperationException"; - } + UnsupportedOperationException( + const std::string& pMsg, + const std::string& pFile="unknown", + int pLine=0) : RuntimeException(pMsg, pFile, pLine) + { + mType = "UnsupportedOperationException"; + } }; diff --git a/src/MULTIPR/MULTIPR_Family.cxx b/src/MULTIPR/MULTIPR_Family.cxx index e6ab2fc..66462ca 100644 --- a/src/MULTIPR/MULTIPR_Family.cxx +++ b/src/MULTIPR/MULTIPR_Family.cxx @@ -33,112 +33,112 @@ namespace multipr Attributs::Attributs() { - mId = NULL; - mVal = NULL; - mDesc = NULL; - - reset(); + mId = NULL; + mVal = NULL; + mDesc = NULL; + + reset(); } Attributs::~Attributs() { - reset(); + reset(); } Attributs& Attributs::operator=(const Attributs& pAttr) { - if (this != &pAttr) // check for self-assignement - { - reset(); - - mNum = pAttr.mNum; - - if (mNum < 0) throw IllegalStateException("", __FILE__, __LINE__); - - if (pAttr.mId != NULL) - { - mId = new med_int[mNum]; - memcpy(mId, pAttr.mId, sizeof(med_int) * mNum); - } - - if (pAttr.mVal != NULL) - { - mVal = new med_int[mNum]; - memcpy(mVal, pAttr.mVal, sizeof(med_int) * mNum); - } - - if (pAttr.mDesc != NULL) - { - mDesc = new char[MED_TAILLE_DESC * mNum + 1]; - memcpy(mDesc, pAttr.mDesc, MED_TAILLE_DESC * mNum + 1); - } - } - - return *this; + if (this != &pAttr) // check for self-assignement + { + reset(); + + mNum = pAttr.mNum; + + if (mNum < 0) throw IllegalStateException("", __FILE__, __LINE__); + + if (pAttr.mId != NULL) + { + mId = new med_int[mNum]; + memcpy(mId, pAttr.mId, sizeof(med_int) * mNum); + } + + if (pAttr.mVal != NULL) + { + mVal = new med_int[mNum]; + memcpy(mVal, pAttr.mVal, sizeof(med_int) * mNum); + } + + if (pAttr.mDesc != NULL) + { + mDesc = new char[MED_TAILLE_DESC * mNum + 1]; + memcpy(mDesc, pAttr.mDesc, MED_TAILLE_DESC * mNum + 1); + } + } + + return *this; } void Attributs::reset() { - mNum = 0; - - if (mId != NULL) { delete[] mId; mId = NULL; } - if (mVal != NULL) { delete[] mVal; mVal = NULL; } - if (mDesc != NULL) { delete[] mDesc; mDesc = NULL; } + mNum = 0; + + if (mId != NULL) { delete[] mId; mId = NULL; } + if (mVal != NULL) { delete[] mVal; mVal = NULL; } + if (mDesc != NULL) { delete[] mDesc; mDesc = NULL; } } ostream& operator<<(ostream& pOs, Attributs& pA) { - if (pA.mNum == 0) - { - pOs << "NONE" << endl; - } - else - { - pOs << endl << " #attr=" << pA.mNum << endl; - - if (pA.mId != NULL) - { - pOs << " Id =["; - for (int i = 0 ; i < pA.mNum ; i++) - { - pOs << pA.mId[i] << " "; - } - pOs << "]" << endl; - } - else - { - pOs << " Id =NULL" << endl; - } - - if (pA.mVal != NULL) - { - pOs << " Val =["; - for (int i = 0 ; i < pA.mNum ; i++) - { - pOs << pA.mVal[i] << " "; - } - pOs << "]" << endl; - } - else - { - pOs << " Val =NULL"; - } - - if (pA.mDesc != NULL) - { - pOs << " Desc=|" << pA.mDesc << "|" << endl; - } - else - { - pOs << " Desc=NULL" << endl; - } - } - - return pOs; + if (pA.mNum == 0) + { + pOs << "NONE" << endl; + } + else + { + pOs << endl << " #attr=" << pA.mNum << endl; + + if (pA.mId != NULL) + { + pOs << " Id =["; + for (int i = 0 ; i < pA.mNum ; i++) + { + pOs << pA.mId[i] << " "; + } + pOs << "]" << endl; + } + else + { + pOs << " Id =NULL" << endl; + } + + if (pA.mVal != NULL) + { + pOs << " Val =["; + for (int i = 0 ; i < pA.mNum ; i++) + { + pOs << pA.mVal[i] << " "; + } + pOs << "]" << endl; + } + else + { + pOs << " Val =NULL"; + } + + if (pA.mDesc != NULL) + { + pOs << " Desc=|" << pA.mDesc << "|" << endl; + } + else + { + pOs << " Desc=NULL" << endl; + } + } + + return pOs; } @@ -148,242 +148,242 @@ ostream& operator<<(ostream& pOs, Attributs& pA) Family::Family() { - reset(); + reset(); } Family::~Family() { - reset(); + reset(); } void Family::reset() { - mName[0] = '\0'; - mId = 0; - mStrNameGroups = ""; - - mElt.clear(); - mNameGroups.clear(); - mAttributs.reset(); - - mIsFamilyOfNodes = true; - - mFlagPrintAll = false; + mName[0] = '\0'; + mId = 0; + mStrNameGroups = ""; + + mElt.clear(); + mNameGroups.clear(); + mAttributs.reset(); + + mIsFamilyOfNodes = true; + + mFlagPrintAll = false; } void Family::insertElt(med_int pIndexElt) { - if (pIndexElt < 1) throw new IllegalArgumentException("", __FILE__, __LINE__); - - mElt.insert(pIndexElt); + if (pIndexElt < 1) throw new IllegalArgumentException("", __FILE__, __LINE__); + + mElt.insert(pIndexElt); } void Family::buildGroups(vector& pGroups, map& pGroupNameToGroup) const { - // pGroups / pGroupNameToGroup can be empty or not - - // for each group in this family - for (unsigned itGroup = 0 ; itGroup < mNameGroups.size() ; itGroup++) - { - const string& keyName = mNameGroups[itGroup]; - - // check if the group already exist - map::iterator it = pGroupNameToGroup.find(keyName); - - Group* group = NULL; - if (it != pGroupNameToGroup.end()) - { - // the group already exists - group = (*it).second; - } - else - { - // a new group have been identified: create a new entry - group = new Group(); - group->setName(keyName); - group->setIsGroupOfNodes(isFamilyOfNodes()); - - pGroups.push_back(group); - pGroupNameToGroup.insert(make_pair(keyName, group)); - } - - // add all elements of the this family to the group - for (set::iterator itElt = mElt.begin() ; itElt != mElt.end() ; itElt++) - { - group->insertElt(*itElt); - } - - } + // pGroups / pGroupNameToGroup can be empty or not + + // for each group in this family + for (unsigned itGroup = 0 ; itGroup < mNameGroups.size() ; itGroup++) + { + const string& keyName = mNameGroups[itGroup]; + + // check if the group already exist + map::iterator it = pGroupNameToGroup.find(keyName); + + Group* group = NULL; + if (it != pGroupNameToGroup.end()) + { + // the group already exists + group = (*it).second; + } + else + { + // a new group have been identified: create a new entry + group = new Group(); + group->setName(keyName); + group->setIsGroupOfNodes(isFamilyOfNodes()); + + pGroups.push_back(group); + pGroupNameToGroup.insert(make_pair(keyName, group)); + } + + // add all elements of the this family to the group + for (set::iterator itElt = mElt.begin() ; itElt != mElt.end() ; itElt++) + { + group->insertElt(*itElt); + } + + } } Family* Family::extractGroup(const char* pGroupName) { - Family* family = new Family(); - - strcpy(family->mName, mName); - family->mId = mId; - family->mAttributs = mAttributs; - - if (pGroupName == NULL) - { - family->mStrNameGroups = mStrNameGroups; - family->mNameGroups = mNameGroups; - } - else - { - if (strlen(pGroupName) > MED_TAILLE_LNOM) throw IllegalArgumentException("", __FILE__, __LINE__); - if (strlen(pGroupName) == 0) throw IllegalArgumentException("", __FILE__, __LINE__); - - if (strstr(mStrNameGroups.c_str(), pGroupName) == 0) - { - // pGroupName found in the list of groups => just keep pGroupName - family->mStrNameGroups = mStrNameGroups; - family->mNameGroups = mNameGroups; - } - else - { - // pGroupName not found in the current list of groups - // probably not a group of the same nature => keep all the groups - family->mStrNameGroups = pGroupName; - family->mNameGroups.push_back(pGroupName); - } - } - - return family; + Family* family = new Family(); + + strcpy(family->mName, mName); + family->mId = mId; + family->mAttributs = mAttributs; + + if (pGroupName == NULL) + { + family->mStrNameGroups = mStrNameGroups; + family->mNameGroups = mNameGroups; + } + else + { + if (strlen(pGroupName) > MED_TAILLE_LNOM) throw IllegalArgumentException("", __FILE__, __LINE__); + if (strlen(pGroupName) == 0) throw IllegalArgumentException("", __FILE__, __LINE__); + + if (strstr(mStrNameGroups.c_str(), pGroupName) == 0) + { + // pGroupName found in the list of groups => just keep pGroupName + family->mStrNameGroups = mStrNameGroups; + family->mNameGroups = mNameGroups; + } + else + { + // pGroupName not found in the current list of groups + // probably not a group of the same nature => keep all the groups + family->mStrNameGroups = pGroupName; + family->mNameGroups.push_back(pGroupName); + } + } + + return family; } void Family::readMED(med_idt pMEDfile, char* pMeshName, med_int pIndex) { - if (pMEDfile == 0) throw IOException("", __FILE__, __LINE__); - if (pMeshName == NULL) throw NullArgumentException("", __FILE__, __LINE__); - if (strlen(pMeshName) > MED_TAILLE_NOM) throw IllegalArgumentException("", __FILE__, __LINE__); - if (pIndex < 1) throw IllegalArgumentException("", __FILE__, __LINE__); - - reset(); - - med_int numGroups = MEDnGroupe(pMEDfile, pMeshName, pIndex); - - if (numGroups < 0) throw IOException("i/o error while reading number of groups in MED file", __FILE__, __LINE__); - - med_int numAttr = MEDnAttribut(pMEDfile, pMeshName, pIndex); - - med_int* attrId = new med_int[numAttr]; - med_int* attrVal = new med_int[numAttr]; - char* attrDesc = new char[MED_TAILLE_DESC * numAttr + 1]; - attrDesc[0] = '\0'; - - char* nameGroups = new char[MED_TAILLE_LNOM * numGroups + 1]; - nameGroups[0] = '\0'; - - med_err ret = MEDfamInfo( - pMEDfile, - pMeshName, - pIndex, - mName, - &mId, - attrId, - attrVal, - attrDesc, - &numAttr, - nameGroups, - &numGroups); - - if (ret != 0) throw IOException("i/o error while reading family information in MED file", __FILE__, __LINE__); - - attrDesc[MED_TAILLE_DESC * numAttr] = '\0'; - - mAttributs.mNum = numAttr; - mAttributs.mId = attrId; - mAttributs.mVal = attrVal; - mAttributs.mDesc = attrDesc; - - mStrNameGroups = nameGroups; - - // split nameGroups - for (int itGroup = 0 ; itGroup < numGroups ; itGroup++) - { - char str[MED_TAILLE_LNOM + 1]; - strncpy(str, nameGroups + itGroup * MED_TAILLE_LNOM, MED_TAILLE_LNOM); - str[MED_TAILLE_LNOM] = '\0'; - mNameGroups.push_back(str); - } - - delete[] nameGroups; - - // MEDfamLire is not necessary as we used MEDnoeudsLire/MEDelementsLire instead + if (pMEDfile == 0) throw IOException("", __FILE__, __LINE__); + if (pMeshName == NULL) throw NullArgumentException("", __FILE__, __LINE__); + if (strlen(pMeshName) > MED_TAILLE_NOM) throw IllegalArgumentException("", __FILE__, __LINE__); + if (pIndex < 1) throw IllegalArgumentException("", __FILE__, __LINE__); + + reset(); + + med_int numGroups = MEDnGroupe(pMEDfile, pMeshName, pIndex); + + if (numGroups < 0) throw IOException("i/o error while reading number of groups in MED file", __FILE__, __LINE__); + + med_int numAttr = MEDnAttribut(pMEDfile, pMeshName, pIndex); + + med_int* attrId = new med_int[numAttr]; + med_int* attrVal = new med_int[numAttr]; + char* attrDesc = new char[MED_TAILLE_DESC * numAttr + 1]; + attrDesc[0] = '\0'; + + char* nameGroups = new char[MED_TAILLE_LNOM * numGroups + 1]; + nameGroups[0] = '\0'; + + med_err ret = MEDfamInfo( + pMEDfile, + pMeshName, + pIndex, + mName, + &mId, + attrId, + attrVal, + attrDesc, + &numAttr, + nameGroups, + &numGroups); + + if (ret != 0) throw IOException("i/o error while reading family information in MED file", __FILE__, __LINE__); + + attrDesc[MED_TAILLE_DESC * numAttr] = '\0'; + + mAttributs.mNum = numAttr; + mAttributs.mId = attrId; + mAttributs.mVal = attrVal; + mAttributs.mDesc = attrDesc; + + mStrNameGroups = nameGroups; + + // split nameGroups + for (int itGroup = 0 ; itGroup < numGroups ; itGroup++) + { + char str[MED_TAILLE_LNOM + 1]; + strncpy(str, nameGroups + itGroup * MED_TAILLE_LNOM, MED_TAILLE_LNOM); + str[MED_TAILLE_LNOM] = '\0'; + mNameGroups.push_back(str); + } + + delete[] nameGroups; + + // MEDfamLire is not necessary as we used MEDnoeudsLire/MEDelementsLire instead } void Family::writeMED(med_idt pMEDfile, char* pMeshName) { - if (pMEDfile == 0) throw IOException("", __FILE__, __LINE__); - if (pMeshName == NULL) throw NullArgumentException("", __FILE__, __LINE__); - if (strlen(pMeshName) > MED_TAILLE_NOM) throw IllegalArgumentException("", __FILE__, __LINE__); - if (strlen(mName) > MED_TAILLE_NOM) throw IllegalArgumentException("", __FILE__, __LINE__); - if (mAttributs.mVal == NULL) throw IllegalStateException("", __FILE__, __LINE__); - if (mAttributs.mDesc == NULL) throw IllegalStateException("", __FILE__, __LINE__); - if (mAttributs.mId == NULL) throw IllegalStateException("", __FILE__, __LINE__); - - med_err ret = MEDfamCr( - pMEDfile, - pMeshName, - mName, - mId, - mAttributs.mId, - mAttributs.mVal, - mAttributs.mDesc, - mAttributs.mNum, - const_cast(mStrNameGroups.c_str()), - mNameGroups.size()); - - if (ret != 0) throw IOException("i/o error while creating family in MED file", __FILE__, __LINE__); - - // MEDfamEcr is not necessary as we used MEDnoeudsEcr/MEDelementsEcr instead + if (pMEDfile == 0) throw IOException("", __FILE__, __LINE__); + if (pMeshName == NULL) throw NullArgumentException("", __FILE__, __LINE__); + if (strlen(pMeshName) > MED_TAILLE_NOM) throw IllegalArgumentException("", __FILE__, __LINE__); + if (strlen(mName) > MED_TAILLE_NOM) throw IllegalArgumentException("", __FILE__, __LINE__); + if (mAttributs.mVal == NULL) throw IllegalStateException("", __FILE__, __LINE__); + if (mAttributs.mDesc == NULL) throw IllegalStateException("", __FILE__, __LINE__); + if (mAttributs.mId == NULL) throw IllegalStateException("", __FILE__, __LINE__); + + med_err ret = MEDfamCr( + pMEDfile, + pMeshName, + mName, + mId, + mAttributs.mId, + mAttributs.mVal, + mAttributs.mDesc, + mAttributs.mNum, + const_cast(mStrNameGroups.c_str()), + mNameGroups.size()); + + if (ret != 0) throw IOException("i/o error while creating family in MED file", __FILE__, __LINE__); + + // MEDfamEcr is not necessary as we used MEDnoeudsEcr/MEDelementsEcr instead } ostream& operator<<(ostream& pOs, Family& pF) { - pOs << "Family: " << endl; - pOs << " Name =|" << pF.mName << "| size=" << strlen(pF.mName) << endl; - pOs << " Id =" << pF.mId << endl; - pOs << " Family of =" << (pF.isFamilyOfNodes()?"NODES":"ELEMENTS") << endl; - - pOs << " Groups: #groups=" << pF.mNameGroups.size() << endl; - for (unsigned itGroup = 0 ; itGroup < pF.mNameGroups.size() ; itGroup++) - { - pOs << " Group " << (itGroup + 1) << ": |" << pF.mNameGroups[itGroup] << "| size=" << pF.mNameGroups[itGroup].length() << endl; - } - pOs << " Attributs: " << pF.mAttributs; - - if (pF.mElt.size() != 0) - { - set::iterator itSet = pF.mElt.end(); - itSet--; - pOs << " Elements: #elt=" << pF.mElt.size() << " min_id=" << (*(pF.mElt.begin())) << " max_id=" << (*itSet) << endl; - if (pF.mFlagPrintAll) - { - pOs << " "; - for (set::iterator itSet = pF.mElt.begin() ; itSet != pF.mElt.end() ; itSet++) - { - pOs << (*itSet) << " "; - } - pOs << endl; - } - } - else - { - pOs << " Elements: #elt=0" << endl; - } - - return pOs; + pOs << "Family: " << endl; + pOs << " Name =|" << pF.mName << "| size=" << strlen(pF.mName) << endl; + pOs << " Id =" << pF.mId << endl; + pOs << " Family of =" << (pF.isFamilyOfNodes()?"NODES":"ELEMENTS") << endl; + + pOs << " Groups: #groups=" << pF.mNameGroups.size() << endl; + for (unsigned itGroup = 0 ; itGroup < pF.mNameGroups.size() ; itGroup++) + { + pOs << " Group " << (itGroup + 1) << ": |" << pF.mNameGroups[itGroup] << "| size=" << pF.mNameGroups[itGroup].length() << endl; + } + pOs << " Attributs: " << pF.mAttributs; + + if (pF.mElt.size() != 0) + { + set::iterator itSet = pF.mElt.end(); + itSet--; + pOs << " Elements: #elt=" << pF.mElt.size() << " min_id=" << (*(pF.mElt.begin())) << " max_id=" << (*itSet) << endl; + if (pF.mFlagPrintAll) + { + pOs << " "; + for (set::iterator itSet = pF.mElt.begin() ; itSet != pF.mElt.end() ; itSet++) + { + pOs << (*itSet) << " "; + } + pOs << endl; + } + } + else + { + pOs << " Elements: #elt=0" << endl; + } + + return pOs; } @@ -393,68 +393,68 @@ ostream& operator<<(ostream& pOs, Family& pF) Group::Group() { - reset(); + reset(); } Group::~Group() { - reset(); + reset(); } void Group::reset() { - mName = ""; - mElt.clear(); - mIsGroupOfNodes = true; - - mFlagPrintAll = false; + mName = ""; + mElt.clear(); + mIsGroupOfNodes = true; + + mFlagPrintAll = false; } void Group::setName(const string& pName) { - if (pName.length() > MED_TAILLE_LNOM) throw IllegalArgumentException("", __FILE__, __LINE__); - - mName = pName; + if (pName.length() > MED_TAILLE_LNOM) throw IllegalArgumentException("", __FILE__, __LINE__); + + mName = pName; } void Group::insertElt(med_int pIndexElt) { - if (pIndexElt < 1) throw IllegalArgumentException("", __FILE__, __LINE__); - - mElt.insert(pIndexElt); + if (pIndexElt < 1) throw IllegalArgumentException("", __FILE__, __LINE__); + + mElt.insert(pIndexElt); } ostream& operator<<(ostream& pOs, Group& pG) { - pOs << "Group: " << endl; - pOs << " Name =|" << pG.mName << "| size=" << pG.mName.length() << endl; - pOs << " Group of =" << (pG.isGroupOfNodes()?"NODES":"ELEMENTS") << endl; - - if (pG.mElt.size() != 0) - { - set::iterator itSet = pG.mElt.end(); - itSet--; - pOs << " Elements: #elt=" << pG.mElt.size() << " min_id=" << (*(pG.mElt.begin())) << " max_id=" << (*itSet) << endl; - if (pG.mFlagPrintAll) - { - pOs << " "; - for (set::iterator itSet = pG.mElt.begin() ; itSet != pG.mElt.end() ; itSet++) - { - pOs << (*itSet) << " "; - } - pOs << endl; - } - } - else - { - pOs << " Elements: #elt=0" << endl; - } - - return pOs; + pOs << "Group: " << endl; + pOs << " Name =|" << pG.mName << "| size=" << pG.mName.length() << endl; + pOs << " Group of =" << (pG.isGroupOfNodes()?"NODES":"ELEMENTS") << endl; + + if (pG.mElt.size() != 0) + { + set::iterator itSet = pG.mElt.end(); + itSet--; + pOs << " Elements: #elt=" << pG.mElt.size() << " min_id=" << (*(pG.mElt.begin())) << " max_id=" << (*itSet) << endl; + if (pG.mFlagPrintAll) + { + pOs << " "; + for (set::iterator itSet = pG.mElt.begin() ; itSet != pG.mElt.end() ; itSet++) + { + pOs << (*itSet) << " "; + } + pOs << endl; + } + } + else + { + pOs << " Elements: #elt=0" << endl; + } + + return pOs; } diff --git a/src/MULTIPR/MULTIPR_Family.hxx b/src/MULTIPR/MULTIPR_Family.hxx index 15d1833..31c7ffc 100644 --- a/src/MULTIPR/MULTIPR_Family.hxx +++ b/src/MULTIPR/MULTIPR_Family.hxx @@ -20,7 +20,7 @@ extern "C" { - #include "med.h" + #include "med.h" } @@ -47,56 +47,56 @@ class Group; class Attributs { public: - - /** - * Builds an empty Attributs (default constructor). - */ - Attributs(); - - /** - * Destructor. Removes everything. - */ - ~Attributs(); - - /** - * Assignment operator (deep copy). - * \param pAttr any Atttibuts to be copied. - * \return a reference towards the copy. - */ - Attributs& operator=(const Attributs& pAttr); - - /** - * Resets this object in its state by default (empty). Cleans memory. - */ - void reset(); - - //--------------------------------------------------------------------- - // I/O - //--------------------------------------------------------------------- - - /** - * Dumps any Attributs to the given output stream. - * \param pOs any output stream. - * \param pA any Attributs. - * \return the output stream pOs. - */ - friend std::ostream& operator<<(std::ostream& pOs, Attributs& pA); - + + /** + * Builds an empty Attributs (default constructor). + */ + Attributs(); + + /** + * Destructor. Removes everything. + */ + ~Attributs(); + + /** + * Assignment operator (deep copy). + * \param pAttr any Atttibuts to be copied. + * \return a reference towards the copy. + */ + Attributs& operator=(const Attributs& pAttr); + + /** + * Resets this object in its state by default (empty). Cleans memory. + */ + void reset(); + + //--------------------------------------------------------------------- + // I/O + //--------------------------------------------------------------------- + + /** + * Dumps any Attributs to the given output stream. + * \param pOs any output stream. + * \param pA any Attributs. + * \return the output stream pOs. + */ + friend std::ostream& operator<<(std::ostream& pOs, Attributs& pA); + public: - med_int mNum; /**< Number of attributes. */ - med_int* mId; /**< Table of identifiers: for each attribute, its identifier. */ - med_int* mVal; /**< Table of values; for each attribute, its value. */ - char* mDesc; /**< Table of description; for each attribute, its description. */ - + med_int mNum; /**< Number of attributes. */ + med_int* mId; /**< Table of identifiers: for each attribute, its identifier. */ + med_int* mVal; /**< Table of values; for each attribute, its value. */ + char* mDesc; /**< Table of description; for each attribute, its description. */ + private: - // do not allow copy constructor - Attributs(const Attributs&); - - // do not allow operator == - bool operator==(const Attributs&); - + // do not allow copy constructor + Attributs(const Attributs&); + + // do not allow operator == + bool operator==(const Attributs&); + }; // class Attribut @@ -108,145 +108,145 @@ class Family { public: - /** - * Builds an empty Family (default constructor). - */ - Family(); - - /** - * Destructor. Removes everything. - */ - ~Family(); - - /** - * Resets this object in its state by default (empty). Cleans memory. - */ - void reset(); - - //--------------------------------------------------------------------- - // Basic accessors/mutators - //--------------------------------------------------------------------- - - /** - * Returns the identifier (= number) of this Family. - * \return the identifier of this Family. - */ - med_int getId() const { return mId; } - - /** - * Returns the name of this Family. - * \return the name of this Family. - */ - const char* getName() const { return mName; } - - /** - * Returns true if this Family if a family of nodes, false if is a family of elements (=cells)). - * \return true iff this Family if a family of nodes. - */ - bool isFamilyOfNodes() const { return mIsFamilyOfNodes; } - - /** - * Sets whether this Family is a family of nodes or family of elements (= cells). - * \param pIsFamilyOfNodes flag. - */ - void setIsFamilyOfNodes(bool pIsFamilyOfNodes) { mIsFamilyOfNodes = pIsFamilyOfNodes; } - - /** - * Inserts a new element (by its index) into this Family. - * \param pIndexElt index of the element to be added; must be >= 1. - * \throw IllegalArgumentException if pIndexElt <= 0. - */ - void insertElt(med_int pIndexElt); - - /** - * Returns the number of elements in this Family. - * \return the number of elements in this Family. - */ - int getSize() const { return mElt.size(); } - - //--------------------------------------------------------------------- - // Algorithms - //--------------------------------------------------------------------- - - /** - * Adds all the groups of this Family into the set of groups described by (pGroups, pGroupNameToGroup). - * \param pGroups current list of groups. - * \param pGroupNameToGroup table (map) to retrieve a Group* from its name. - */ - void buildGroups( - std::vector& pGroups, - std::map& pGroupNameToGroup) const; - - /** - * Constructor. Returns a copy of this family restricted to the given group if pGroupName != NULL. - * Examples: - * 1. If current family have 3 groups "A", "B" and "C" and pGroupName="B", then the new family will only reference the group "B" - * 2. If current family have 3 groups "A", "B" and "C" and pGroupName="D", then the new family will reference groups "A", "B" and "C". - * WARNING: elements are not copied - * \param pGroupName name of the group to keep. - * \return a copy of this family. - */ - Family* extractGroup(const char* pGroupName); - - //--------------------------------------------------------------------- - // I/O - //--------------------------------------------------------------------- - - /** - * Reads a Family from a MED file. - * \param pMEDfile any valid MED file opened for reading. - * \param pMeshName name of the mesh. - * \param pIndex index of the family to be read (must be >= 1). - * \throw IOException if any i/o error occurs. - */ - void readMED(med_idt pMEDfile, char* pMeshName, med_int pIndex); - - /** - * Writes this Family to a MED file. - * WARNING: mesh must have been created and added to the MED file before. - * \param pMEDfile any valid MED file opened for writing. - * \param pPeshName name of the mesh. - * \throw IOException if any i/o error occurs. - */ - void writeMED(med_idt pMEDfile, char* pMeshName); - - /** - * Sets the flag which control the stream operator <<. - * \param pFlag new flag value. - */ - void setPrintAll(bool pFlag) { mFlagPrintAll = pFlag; } - - /** - * Dumps any Family to the given output stream. - * \param pOs any output stream. - * \param pF any Family. - * \return the output stream pOs. - */ - friend std::ostream& operator<<(std::ostream& pOs, Family& pF); - + /** + * Builds an empty Family (default constructor). + */ + Family(); + + /** + * Destructor. Removes everything. + */ + ~Family(); + + /** + * Resets this object in its state by default (empty). Cleans memory. + */ + void reset(); + + //--------------------------------------------------------------------- + // Basic accessors/mutators + //--------------------------------------------------------------------- + + /** + * Returns the identifier (= number) of this Family. + * \return the identifier of this Family. + */ + med_int getId() const { return mId; } + + /** + * Returns the name of this Family. + * \return the name of this Family. + */ + const char* getName() const { return mName; } + + /** + * Returns true if this Family if a family of nodes, false if is a family of elements (=cells)). + * \return true iff this Family if a family of nodes. + */ + bool isFamilyOfNodes() const { return mIsFamilyOfNodes; } + + /** + * Sets whether this Family is a family of nodes or family of elements (= cells). + * \param pIsFamilyOfNodes flag. + */ + void setIsFamilyOfNodes(bool pIsFamilyOfNodes) { mIsFamilyOfNodes = pIsFamilyOfNodes; } + + /** + * Inserts a new element (by its index) into this Family. + * \param pIndexElt index of the element to be added; must be >= 1. + * \throw IllegalArgumentException if pIndexElt <= 0. + */ + void insertElt(med_int pIndexElt); + + /** + * Returns the number of elements in this Family. + * \return the number of elements in this Family. + */ + int getSize() const { return mElt.size(); } + + //--------------------------------------------------------------------- + // Algorithms + //--------------------------------------------------------------------- + + /** + * Adds all the groups of this Family into the set of groups described by (pGroups, pGroupNameToGroup). + * \param pGroups current list of groups. + * \param pGroupNameToGroup table (map) to retrieve a Group* from its name. + */ + void buildGroups( + std::vector& pGroups, + std::map& pGroupNameToGroup) const; + + /** + * Constructor. Returns a copy of this family restricted to the given group if pGroupName != NULL. + * Examples: + * 1. If current family have 3 groups "A", "B" and "C" and pGroupName="B", then the new family will only reference the group "B" + * 2. If current family have 3 groups "A", "B" and "C" and pGroupName="D", then the new family will reference groups "A", "B" and "C". + * WARNING: elements are not copied + * \param pGroupName name of the group to keep. + * \return a copy of this family. + */ + Family* extractGroup(const char* pGroupName); + + //--------------------------------------------------------------------- + // I/O + //--------------------------------------------------------------------- + + /** + * Reads a Family from a MED file. + * \param pMEDfile any valid MED file opened for reading. + * \param pMeshName name of the mesh. + * \param pIndex index of the family to be read (must be >= 1). + * \throw IOException if any i/o error occurs. + */ + void readMED(med_idt pMEDfile, char* pMeshName, med_int pIndex); + + /** + * Writes this Family to a MED file. + * WARNING: mesh must have been created and added to the MED file before. + * \param pMEDfile any valid MED file opened for writing. + * \param pPeshName name of the mesh. + * \throw IOException if any i/o error occurs. + */ + void writeMED(med_idt pMEDfile, char* pMeshName); + + /** + * Sets the flag which control the stream operator <<. + * \param pFlag new flag value. + */ + void setPrintAll(bool pFlag) { mFlagPrintAll = pFlag; } + + /** + * Dumps any Family to the given output stream. + * \param pOs any output stream. + * \param pF any Family. + * \return the output stream pOs. + */ + friend std::ostream& operator<<(std::ostream& pOs, Family& pF); + private: - - char mName[MED_TAILLE_NOM + 1]; /** Name of the Family */ - med_int mId; /**< Id: > 0 if family of nodes; < 0 if family of elements. */ - std::set mElt; /**< Set of all the elements (by their index in 1..*). */ - std::string mStrNameGroups; /**< A string with name of all groups which contain the Family. */ - std::vector mNameGroups; /**< List of groups (by name) which contain the Family. */ - Attributs mAttributs; /**< All the attributed related to the Family. */ - bool mIsFamilyOfNodes; /**< Is it a family of nodes or a family of elements? */ - - bool mFlagPrintAll; /** Flag to control the behaviour of the stream operator <<. */ - + + char mName[MED_TAILLE_NOM + 1]; /** Name of the Family */ + med_int mId; /**< Id: > 0 if family of nodes; < 0 if family of elements. */ + std::set mElt; /**< Set of all the elements (by their index in 1..*). */ + std::string mStrNameGroups; /**< A string with name of all groups which contain the Family. */ + std::vector mNameGroups; /**< List of groups (by name) which contain the Family. */ + Attributs mAttributs; /**< All the attributed related to the Family. */ + bool mIsFamilyOfNodes; /**< Is it a family of nodes or a family of elements? */ + + bool mFlagPrintAll; /** Flag to control the behaviour of the stream operator <<. */ + private: - // do not allow copy constructor - Family(const Family&); - - // do not allow copy - Family& operator=(const Family&); - - // do not allow operator == - bool operator==(const Family&); - + // do not allow copy constructor + Family(const Family&); + + // do not allow copy + Family& operator=(const Family&); + + // do not allow operator == + bool operator==(const Family&); + }; // class Family @@ -258,104 +258,104 @@ class Group { public: - /** - * Builds an empty group (default constructor). - */ - Group(); - - /** - * Destructor. Removes everything. - */ - ~Group(); - - /** - * Resets this object in its state by default (empty). Cleans memory. - */ - void reset(); - - //--------------------------------------------------------------------- - // Basic accessors/mutators - //--------------------------------------------------------------------- - - /** - * Returns true if it is a group of nodes, false if it is a group of elements. - * \return true if it is a group of nodes, false if it is a group of elements. - */ - bool isGroupOfNodes() const { return mIsGroupOfNodes; } - - /** - * Sets whether it is a group of nodes or a group of elements. - * \param pIsGroupOfNodes true for a group of nodes, false for a group of elements. - */ - void setIsGroupOfNodes(bool pIsGroupOfNodes) { mIsGroupOfNodes = pIsGroupOfNodes; } - - /** - * Returns the name of this Group. - * \return the name of this Group. - */ - const std::string& getName() const { return mName; } - - /** - * Sets the name of this Group. - * \param pName new name of this Group (length of name must not exceed MED_TAILLE_LNOM). - */ - void setName(const std::string& pName); - - /** - * Adds the index of a new element to this Group. - * \param pIndexElt must be >= 1. - */ - void insertElt(med_int pIndexElt); - - /** - * Returns the set of all the elements referenced in this Group. - * \return the set of all the elements referenced in this Group. - */ - const std::set& getSetOfElt() const { return mElt; } - - /** - * Returns the number of elements referenced in this Group. - * \return the number of elements referenced in this Group. - */ - int getSize() const { return mElt.size(); } - - //--------------------------------------------------------------------- - // I/O - //--------------------------------------------------------------------- - - /** - * Sets the flag which control the stream operator <<. - * \param pFlag new flag value. - */ - void setPrintAll(bool pFlag) { mFlagPrintAll = pFlag; } - - /** - * Dumps any Group to the given output stream. - * \param pOs any output stream. - * \param pG any Group. - * \return the output stream pOs. - */ - friend std::ostream& operator<<(std::ostream& pOs, Group& pG); - + /** + * Builds an empty group (default constructor). + */ + Group(); + + /** + * Destructor. Removes everything. + */ + ~Group(); + + /** + * Resets this object in its state by default (empty). Cleans memory. + */ + void reset(); + + //--------------------------------------------------------------------- + // Basic accessors/mutators + //--------------------------------------------------------------------- + + /** + * Returns true if it is a group of nodes, false if it is a group of elements. + * \return true if it is a group of nodes, false if it is a group of elements. + */ + bool isGroupOfNodes() const { return mIsGroupOfNodes; } + + /** + * Sets whether it is a group of nodes or a group of elements. + * \param pIsGroupOfNodes true for a group of nodes, false for a group of elements. + */ + void setIsGroupOfNodes(bool pIsGroupOfNodes) { mIsGroupOfNodes = pIsGroupOfNodes; } + + /** + * Returns the name of this Group. + * \return the name of this Group. + */ + const std::string& getName() const { return mName; } + + /** + * Sets the name of this Group. + * \param pName new name of this Group (length of name must not exceed MED_TAILLE_LNOM). + */ + void setName(const std::string& pName); + + /** + * Adds the index of a new element to this Group. + * \param pIndexElt must be >= 1. + */ + void insertElt(med_int pIndexElt); + + /** + * Returns the set of all the elements referenced in this Group. + * \return the set of all the elements referenced in this Group. + */ + const std::set& getSetOfElt() const { return mElt; } + + /** + * Returns the number of elements referenced in this Group. + * \return the number of elements referenced in this Group. + */ + int getSize() const { return mElt.size(); } + + //--------------------------------------------------------------------- + // I/O + //--------------------------------------------------------------------- + + /** + * Sets the flag which control the stream operator <<. + * \param pFlag new flag value. + */ + void setPrintAll(bool pFlag) { mFlagPrintAll = pFlag; } + + /** + * Dumps any Group to the given output stream. + * \param pOs any output stream. + * \param pG any Group. + * \return the output stream pOs. + */ + friend std::ostream& operator<<(std::ostream& pOs, Group& pG); + private: - - std::string mName; /**< Name of the group. */ - std::set mElt; /**< All elements of this group; each element is referenced by its index >= 1; each element is unique. */ - bool mIsGroupOfNodes; /**< Is it a group of nodes or a group of elements? */ - - bool mFlagPrintAll; /** Flag to control the behaviour of the stream operator <<. */ - + + std::string mName; /**< Name of the group. */ + std::set mElt; /**< All elements of this group; each element is referenced by its index >= 1; each element is unique. */ + bool mIsGroupOfNodes; /**< Is it a group of nodes or a group of elements? */ + + bool mFlagPrintAll; /** Flag to control the behaviour of the stream operator <<. */ + private: - // do not allow copy constructor - Group(const Group&); - - // do not allow copy - Group& operator=(const Group&); - - // do not allow operator == - bool operator==(const Group&); - + // do not allow copy constructor + Group(const Group&); + + // do not allow copy + Group& operator=(const Group&); + + // do not allow operator == + bool operator==(const Group&); + }; // class Group diff --git a/src/MULTIPR/MULTIPR_Field.cxx b/src/MULTIPR/MULTIPR_Field.cxx index 6d1854a..f72ce36 100644 --- a/src/MULTIPR/MULTIPR_Field.cxx +++ b/src/MULTIPR/MULTIPR_Field.cxx @@ -33,489 +33,483 @@ namespace multipr Field::Field() { - reset(); + reset(); } Field::~Field() { - reset(); + reset(); } void Field::reset() { - mName[0] = '\0'; - mEntity = MED_NOEUD; - mGeom = MED_NONE; - mType = MED_FLOAT64; - mSizeOfType = 8; - mNumComponents = 0; - mStrComponent = ""; - mStrUnit = ""; - - mNGauss.clear(); - mDT.clear(); - mNumDT.clear(); - mDTUnit.clear(); - mNumO.clear(); - mGaussLoc.clear(); - mProfil.clear(); - mSizeOfData.clear(); - mNVal.clear(); - - for (unsigned it = 0 ; it < mVal.size() ; it++) - { - delete[] mVal[it]; - } - mVal.clear(); - - mFlagPrintAll = false; + mName[0] = '\0'; + mEntity = MED_NOEUD; + mGeom = MED_NONE; + mType = MED_FLOAT64; + mSizeOfType = 8; + mNumComponents = 0; + mStrComponent = ""; + mStrUnit = ""; + + mNGauss.clear(); + mDT.clear(); + mNumDT.clear(); + mDTUnit.clear(); + mNumO.clear(); + mGaussLoc.clear(); + mProfil.clear(); + mSizeOfData.clear(); + mNVal.clear(); + + for (unsigned it = 0 ; it < mVal.size() ; it++) + { + delete[] mVal[it]; + } + mVal.clear(); + + mFlagPrintAll = false; } bool Field::isEmpty() const { - return (mNGauss.size() == 0); + return (mNGauss.size() == 0); } int Field::getNumberOfGaussPointsByElement(int pTimeStepIt) const { - if ((pTimeStepIt < 1) || (pTimeStepIt > int(mNGauss.size()))) throw IndexOutOfBoundsException("", __FILE__, __LINE__); - - return mNGauss[pTimeStepIt - 1]; + if ((pTimeStepIt < 1) || (pTimeStepIt > int(mNGauss.size()))) throw IndexOutOfBoundsException("", __FILE__, __LINE__); + + return mNGauss[pTimeStepIt - 1]; } const string& Field::getNameGaussLoc(int pTimeStepIt) const { - if ((pTimeStepIt < 1) || (pTimeStepIt > int(mNGauss.size()))) throw IndexOutOfBoundsException("", __FILE__, __LINE__); - - return mGaussLoc[pTimeStepIt - 1]; + if ((pTimeStepIt < 1) || (pTimeStepIt > int(mNGauss.size()))) throw IndexOutOfBoundsException("", __FILE__, __LINE__); + + return mGaussLoc[pTimeStepIt - 1]; } const unsigned char* Field::getValue(int pTimeStepIt, int pIndex) const { - if ((pTimeStepIt < 1) || (pTimeStepIt > int(mNGauss.size()))) throw IndexOutOfBoundsException("", __FILE__, __LINE__); - if ((pIndex < 1) || (pIndex > mNVal[pTimeStepIt - 1] / mNGauss[pTimeStepIt - 1])) throw IndexOutOfBoundsException("", __FILE__, __LINE__); - - // size of one data = size of type * number of components * number of Gauss points - int sizeOfOneData = mSizeOfType * mNumComponents * mNGauss[pTimeStepIt - 1]; - - unsigned char* ret = mVal[pTimeStepIt - 1] + (pIndex - 1) * sizeOfOneData; - - return ret; + if ((pTimeStepIt < 1) || (pTimeStepIt > int(mNGauss.size()))) throw IndexOutOfBoundsException("", __FILE__, __LINE__); + if ((pIndex < 1) || (pIndex > mNVal[pTimeStepIt - 1] / mNGauss[pTimeStepIt - 1])) throw IndexOutOfBoundsException("", __FILE__, __LINE__); + + // size of one data = size of type * number of components * number of Gauss points + int sizeOfOneData = mSizeOfType * mNumComponents * mNGauss[pTimeStepIt - 1]; + + unsigned char* ret = mVal[pTimeStepIt - 1] + (pIndex - 1) * sizeOfOneData; + + return ret; } Field* Field::extractSubSet(const set& pSetIndices) const { - Field* subset = new Field(); - - memcpy(subset->mName, mName, MED_TAILLE_NOM + 1); - subset->mEntity = mEntity; - subset->mGeom = mGeom; - subset->mType = mType; - subset->mSizeOfType = mSizeOfType; - subset->mNumComponents = mNumComponents; - subset->mStrComponent = mStrComponent; - subset->mStrUnit = mStrUnit; - - subset->mNGauss = mNGauss; - subset->mDT = mDT; - subset->mNumDT = mNumDT; - subset->mDTUnit = mDTUnit; - subset->mNumO = mNumO; - subset->mGaussLoc = mGaussLoc; - subset->mProfil = mProfil; - - // for each time step - for (unsigned itTimeStep = 0 ; itTimeStep < mNGauss.size() ; itTimeStep++) - { - if (mProfil[itTimeStep].size() != 0) throw UnsupportedOperationException("", __FILE__, __LINE__); - // TODO ??? - // WARNING : do not manage profil for the moment - // if there is a profil, - // 1. we should set mProfil to NO_PROFIL for this time_step - // 2. we should extract data according to the profil - - int nval = pSetIndices.size() * subset->mNGauss[itTimeStep]; - subset->mNVal.push_back(nval); - - int sizeOfData = nval * mSizeOfType * mNumComponents; - subset->mSizeOfData.push_back(sizeOfData); - - unsigned char* data = new unsigned char[sizeOfData]; - unsigned char* dest = data; - int sizeOfOneData = mSizeOfType * mNumComponents * subset->mNGauss[itTimeStep]; - - //cout << "Size of 1 data = " << sizeOfOneData << endl; // debug - - // for each element to extract - for (set::iterator itSet = pSetIndices.begin() ; itSet != pSetIndices.end() ; itSet++) - { - int indexElt = (*itSet); - - // MED index start at 1. - if (indexElt < 1) throw new IllegalArgumentException("", __FILE__, __LINE__); - - unsigned char* src = mVal[itTimeStep] + (indexElt - 1) * sizeOfOneData; - memcpy(dest, src, sizeOfOneData); - - dest += sizeOfOneData; - } - subset->mVal.push_back(data); - } - - return subset; + Field* subset = new Field(); + + memcpy(subset->mName, mName, MED_TAILLE_NOM + 1); + subset->mEntity = mEntity; + subset->mGeom = mGeom; + subset->mType = mType; + subset->mSizeOfType = mSizeOfType; + subset->mNumComponents = mNumComponents; + subset->mStrComponent = mStrComponent; + subset->mStrUnit = mStrUnit; + + subset->mNGauss = mNGauss; + subset->mDT = mDT; + subset->mNumDT = mNumDT; + subset->mDTUnit = mDTUnit; + subset->mNumO = mNumO; + subset->mGaussLoc = mGaussLoc; + subset->mProfil = mProfil; + + // for each time step + for (unsigned itTimeStep = 0 ; itTimeStep < mNGauss.size() ; itTimeStep++) + { + if (mProfil[itTimeStep].size() != 0) throw UnsupportedOperationException("", __FILE__, __LINE__); + // WARNING : do not manage profil for the moment + // if there is a profil, + // 1. we should set mProfil to NO_PROFIL for this time_step + // 2. we should extract data according to the profil + + int nval = pSetIndices.size() * subset->mNGauss[itTimeStep]; + subset->mNVal.push_back(nval); + + int sizeOfData = nval * mSizeOfType * mNumComponents; + subset->mSizeOfData.push_back(sizeOfData); + + unsigned char* data = new unsigned char[sizeOfData]; + unsigned char* dest = data; + int sizeOfOneData = mSizeOfType * mNumComponents * subset->mNGauss[itTimeStep]; + + // for each element to extract + for (set::iterator itSet = pSetIndices.begin() ; itSet != pSetIndices.end() ; itSet++) + { + int indexElt = (*itSet); + + // MED index start at 1. + if (indexElt < 1) throw new IllegalArgumentException("", __FILE__, __LINE__); + + unsigned char* src = mVal[itTimeStep] + (indexElt - 1) * sizeOfOneData; + memcpy(dest, src, sizeOfOneData); + + dest += sizeOfOneData; + } + subset->mVal.push_back(data); + } + + return subset; } void Field::getSetOfGaussLoc(set& pSetOfGaussLoc) const { - for (unsigned itGaussLoc = 0 ; itGaussLoc < mGaussLoc.size() ; itGaussLoc++) - { - const string& gaussLocName = mGaussLoc[itGaussLoc]; - - if (gaussLocName.length() != 0) - { - pSetOfGaussLoc.insert(gaussLocName); - } - } + for (unsigned itGaussLoc = 0 ; itGaussLoc < mGaussLoc.size() ; itGaussLoc++) + { + const string& gaussLocName = mGaussLoc[itGaussLoc]; + + if (gaussLocName.length() != 0) + { + pSetOfGaussLoc.insert(gaussLocName); + } + } } void Field::readMED(med_idt pMEDfile, med_int pIndex, char* pMeshName) { - if (pMEDfile == 0) throw IOException("", __FILE__, __LINE__); - if (pMeshName == NULL) throw NullArgumentException("", __FILE__, __LINE__); - if (strlen(pMeshName) > MED_TAILLE_NOM) throw IllegalArgumentException("", __FILE__, __LINE__); - if (pIndex < 1) throw IllegalArgumentException("", __FILE__, __LINE__); - - reset(); - - mNumComponents = MEDnChamp(pMEDfile, pIndex); - - if (mNumComponents < 0) throw IOException("", __FILE__, __LINE__); - - char* strComponent = new char[mNumComponents * MED_TAILLE_PNOM + 1]; - char* strUnit = new char[mNumComponents * MED_TAILLE_PNOM + 1]; - - strComponent[0] = '\0'; - strUnit[0] = '\0'; - - med_err ret = MEDchampInfo( - pMEDfile, - pIndex, - mName, - &(mType), - strComponent, - strUnit, - mNumComponents); - - if (ret != 0) throw IOException("", __FILE__, __LINE__); - - mStrComponent = strComponent; - mStrUnit = strUnit; - - delete[] strUnit; - delete[] strComponent; - - switch (mType) - { - case MED_FLOAT64: mSizeOfType = 8; break; - case MED_INT64: mSizeOfType = 8; break; - case MED_INT32: mSizeOfType = 4; break; - case MED_INT: mSizeOfType = 4; break; - default: throw IllegalStateException("should not be there", __FILE__, __LINE__); - } - - //--------------------------------------------------------------------- - // Read fields over nodes - //--------------------------------------------------------------------- - bool fieldOnNodes = false; - { - med_int numTimeStepNodes = MEDnPasdetemps( - pMEDfile, - mName, - MED_NOEUD, - (med_geometrie_element) 0); - - if (numTimeStepNodes < 0) throw IOException("", __FILE__, __LINE__); - - if (numTimeStepNodes != 0) - { - fieldOnNodes = true; - mEntity = MED_NOEUD; - mGeom = (med_geometrie_element) 0; - readMEDtimeSteps(pMEDfile, numTimeStepNodes, pMeshName); - } - } - - //--------------------------------------------------------------------- - // Read fields over elements - //--------------------------------------------------------------------- - { - med_int numTimeStepElt = MEDnPasdetemps( - pMEDfile, - mName, - MED_MAILLE, - MED_TETRA10); - - if (numTimeStepElt < 0) throw IOException("", __FILE__, __LINE__); - - if (numTimeStepElt != 0) - { - if (fieldOnNodes) throw IllegalStateException("", __FILE__, __LINE__); - - mEntity = MED_MAILLE; - mGeom = MED_TETRA10; - readMEDtimeSteps(pMEDfile, numTimeStepElt, pMeshName); - } - } + if (pMEDfile == 0) throw IOException("", __FILE__, __LINE__); + if (pMeshName == NULL) throw NullArgumentException("", __FILE__, __LINE__); + if (strlen(pMeshName) > MED_TAILLE_NOM) throw IllegalArgumentException("", __FILE__, __LINE__); + if (pIndex < 1) throw IllegalArgumentException("", __FILE__, __LINE__); + + reset(); + + mNumComponents = MEDnChamp(pMEDfile, pIndex); + + if (mNumComponents < 0) throw IOException("", __FILE__, __LINE__); + + char* strComponent = new char[mNumComponents * MED_TAILLE_PNOM + 1]; + char* strUnit = new char[mNumComponents * MED_TAILLE_PNOM + 1]; + + strComponent[0] = '\0'; + strUnit[0] = '\0'; + + med_err ret = MEDchampInfo( + pMEDfile, + pIndex, + mName, + &(mType), + strComponent, + strUnit, + mNumComponents); + + if (ret != 0) throw IOException("", __FILE__, __LINE__); + + mStrComponent = strComponent; + mStrUnit = strUnit; + + delete[] strUnit; + delete[] strComponent; + + switch (mType) + { + case MED_FLOAT64: mSizeOfType = 8; break; + case MED_INT64: mSizeOfType = 8; break; + case MED_INT32: mSizeOfType = 4; break; + case MED_INT: mSizeOfType = 4; break; + default: throw IllegalStateException("should not be there", __FILE__, __LINE__); + } + + //--------------------------------------------------------------------- + // Read fields over nodes + //--------------------------------------------------------------------- + bool fieldOnNodes = false; + { + med_int numTimeStepNodes = MEDnPasdetemps( + pMEDfile, + mName, + MED_NOEUD, + (med_geometrie_element) 0); + + if (numTimeStepNodes < 0) throw IOException("", __FILE__, __LINE__); + + if (numTimeStepNodes != 0) + { + fieldOnNodes = true; + mEntity = MED_NOEUD; + mGeom = (med_geometrie_element) 0; + readMEDtimeSteps(pMEDfile, numTimeStepNodes, pMeshName); + } + } + + //--------------------------------------------------------------------- + // Read fields over elements + //--------------------------------------------------------------------- + { + med_int numTimeStepElt = MEDnPasdetemps( + pMEDfile, + mName, + MED_MAILLE, + MED_TETRA10); + + if (numTimeStepElt < 0) throw IOException("", __FILE__, __LINE__); + + if (numTimeStepElt != 0) + { + if (fieldOnNodes) throw IllegalStateException("", __FILE__, __LINE__); + + mEntity = MED_MAILLE; + mGeom = MED_TETRA10; + readMEDtimeSteps(pMEDfile, numTimeStepElt, pMeshName); + } + } } void Field::readMEDtimeSteps(med_idt pMEDfile, med_int pNumberOfTimeSteps, char* pMeshName) { - if (pMEDfile == 0) throw IOException("", __FILE__, __LINE__); - if (pMeshName == NULL) throw NullArgumentException("", __FILE__, __LINE__); - if (strlen(pMeshName) > MED_TAILLE_NOM) throw IllegalArgumentException("", __FILE__, __LINE__); - if (pNumberOfTimeSteps < 0) throw IllegalArgumentException("", __FILE__, __LINE__); - - char strEntity[8]; - switch (mEntity) - { - case MED_ARETE: - case MED_FACE: - case MED_MAILLE: strcpy(strEntity, "CELLS"); break; - case MED_NOEUD: strcpy(strEntity, "NODES"); break; - default: strcpy(strEntity, "UNKNOWN"); break; - } - - // iterates over time step - for (int itTimeStep = 1 ; itTimeStep <= pNumberOfTimeSteps ; itTimeStep++) - { - med_int ngauss; - med_int numdt; - med_int numo; - char dtunit[MED_TAILLE_PNOM + 1]; - med_float dt; - char maa[MED_TAILLE_NOM + 1]; - med_booleen local; - med_int nmaa; - - med_err ret = MEDpasdetempsInfo( - pMEDfile, - mName, - mEntity, - mGeom, - itTimeStep, - &ngauss, - &numdt, - &numo, - dtunit, - &dt, - maa, - &local, - &nmaa); - - if (ret != 0) throw IOException("i/o error while reading #timesteps in MED file", __FILE__, __LINE__); - - // mesh must be local - if (local != MED_VRAI) throw IllegalStateException("only local fields are currently supported", __FILE__, __LINE__); - - // #mesh must be 1 - if (nmaa != 1) throw IllegalStateException("field shoud be associated with 1 mesh only", __FILE__, __LINE__); - - // mesh must be pMeshName - //MULTIPR_CHECK((strcmp(maa, pMeshName) == 0), MED_ILLEGAL_FILE, pMEDfile); - // if field does not apply on the current mesh, skip - if (strcmp(maa, pMeshName) != 0) - { - continue; - } - - mNGauss.push_back(ngauss); - mDT.push_back(dt); - mNumDT.push_back(numdt); - mDTUnit.push_back(dtunit); - mNumO.push_back(numo); - - //MULTIPR_LOG("Time step #" << itTimeStep << ": #gauss=" << ngauss << " dt=" << dt << " maa=" << maa << " has_dt?" << ((numdt==MED_NOPDT)?"no":"yes") << " numdt=" << numdt << " unit=" << dtunit << " has_order?" << ((numo==MED_NONOR)?"no":"yes") << " numo:" << numo << endl); - - med_int nval = MEDnVal( - pMEDfile, - mName, - mEntity, - mGeom, - numdt, - numo, - pMeshName, - MED_GLOBAL); - - if (nval < 0) throw IOException("i/o error while reading field in MED file", __FILE__, __LINE__); - - mNVal.push_back(nval); - - char gaussLocName[MED_TAILLE_NOM + 1]; - char profilName[MED_TAILLE_NOM + 1]; - int sizeOfData = mSizeOfType * mNumComponents * nval; - mSizeOfData.push_back(sizeOfData); - unsigned char* fieldData = new unsigned char[sizeOfData]; - - ret = MEDchampLire( - pMEDfile, - pMeshName, - mName, - fieldData, - MED_FULL_INTERLACE, - MED_ALL, - gaussLocName, - profilName, - MED_COMPACT, //MED_GLOBAL, MED_NO_PFLMOD, MED_COMPACT - mEntity, - mGeom, - numdt, - numo); - - if (ret != 0) throw IOException("i/o error while reading field in MED file", __FILE__, __LINE__); - - mGaussLoc.push_back(gaussLocName); - mProfil.push_back(profilName); - mVal.push_back(fieldData); - } + if (pMEDfile == 0) throw IOException("", __FILE__, __LINE__); + if (pMeshName == NULL) throw NullArgumentException("", __FILE__, __LINE__); + if (strlen(pMeshName) > MED_TAILLE_NOM) throw IllegalArgumentException("", __FILE__, __LINE__); + if (pNumberOfTimeSteps < 0) throw IllegalArgumentException("", __FILE__, __LINE__); + + char strEntity[8]; + switch (mEntity) + { + case MED_ARETE: + case MED_FACE: + case MED_MAILLE: strcpy(strEntity, "CELLS"); break; + case MED_NOEUD: strcpy(strEntity, "NODES"); break; + default: strcpy(strEntity, "UNKNOWN"); break; + } + + // iterates over time step + for (int itTimeStep = 1 ; itTimeStep <= pNumberOfTimeSteps ; itTimeStep++) + { + med_int ngauss; + med_int numdt; + med_int numo; + char dtunit[MED_TAILLE_PNOM + 1]; + med_float dt; + char maa[MED_TAILLE_NOM + 1]; + med_booleen local; + med_int nmaa; + + med_err ret = MEDpasdetempsInfo( + pMEDfile, + mName, + mEntity, + mGeom, + itTimeStep, + &ngauss, + &numdt, + &numo, + dtunit, + &dt, + maa, + &local, + &nmaa); + + if (ret != 0) throw IOException("i/o error while reading #timesteps in MED file", __FILE__, __LINE__); + + // mesh must be local + if (local != MED_VRAI) throw IllegalStateException("only local fields are currently supported", __FILE__, __LINE__); + + // #mesh must be 1 + if (nmaa != 1) throw IllegalStateException("field shoud be associated with 1 mesh only", __FILE__, __LINE__); + + // mesh must be pMeshName + // if field does not apply on the current mesh, skip + if (strcmp(maa, pMeshName) != 0) + { + continue; + } + + mNGauss.push_back(ngauss); + mDT.push_back(dt); + mNumDT.push_back(numdt); + mDTUnit.push_back(dtunit); + mNumO.push_back(numo); + + med_int nval = MEDnVal( + pMEDfile, + mName, + mEntity, + mGeom, + numdt, + numo, + pMeshName, + MED_GLOBAL); + + if (nval < 0) throw IOException("i/o error while reading field in MED file", __FILE__, __LINE__); + + mNVal.push_back(nval); + + char gaussLocName[MED_TAILLE_NOM + 1]; + char profilName[MED_TAILLE_NOM + 1]; + int sizeOfData = mSizeOfType * mNumComponents * nval; + mSizeOfData.push_back(sizeOfData); + unsigned char* fieldData = new unsigned char[sizeOfData]; + + ret = MEDchampLire( + pMEDfile, + pMeshName, + mName, + fieldData, + MED_FULL_INTERLACE, + MED_ALL, + gaussLocName, + profilName, + MED_COMPACT, // should be: MED_GLOBAL, MED_NO_PFLMOD, MED_COMPACT + mEntity, + mGeom, + numdt, + numo); + + if (ret != 0) throw IOException("i/o error while reading field in MED file", __FILE__, __LINE__); + + mGaussLoc.push_back(gaussLocName); + mProfil.push_back(profilName); + mVal.push_back(fieldData); + } } void Field::writeMED(med_idt pMEDfile, char* pMeshName) { - if (pMEDfile == 0) throw IOException("", __FILE__, __LINE__); - if (pMeshName == NULL) throw NullArgumentException("", __FILE__, __LINE__); - if (strlen(pMeshName) > MED_TAILLE_NOM) throw IllegalArgumentException("", __FILE__, __LINE__); - if (mNumComponents < 1) throw IllegalStateException("", __FILE__, __LINE__); - - med_err ret = MEDchampCr( - pMEDfile, - mName, // name of the field - mType, // type of data (MED_FLOAT64, MED_INT32, etc.) - const_cast(mStrComponent.c_str()), // name of components - const_cast(mStrUnit.c_str()), // name of units - mNumComponents); // number of components - - if (ret != 0) throw IOException("i/o error while creating field in MED file", __FILE__, __LINE__); - - // for each time step - for (unsigned i = 0 ; i < mNGauss.size() ; i++) - { - // skip if no values - if (mNVal[i] == 0) continue; - - ret = MEDchampEcr( - pMEDfile, - pMeshName, // name of the mesh (first call to MEDchampEcr => name of reference) - mName, // name of the field - mVal[i], // data (= values) - MED_FULL_INTERLACE, // data organization - mNVal[i], // number of values - const_cast(mGaussLoc[i].c_str()), // name of Gauss reference - MED_ALL, // components to be selected - const_cast(mProfil[i].c_str()), // name of profil - MED_GLOBAL, // how to read data: MED_NO_PFLMOD,MED_COMPACT,MED_GLOBAL - mEntity, // type of entity (MED_NOEUD, MED_MAILLE, etc.) - mGeom, // type of geometry (TETRA10, etc.) - mNumDT[i], // time step iteration - const_cast(mDTUnit[i].c_str()), // unit of time step - mDT[i], // time key - mNumO[i]); // order number - - if (ret != 0) throw IOException("i/o error while writing field in MED file", __FILE__, __LINE__); - } + if (pMEDfile == 0) throw IOException("", __FILE__, __LINE__); + if (pMeshName == NULL) throw NullArgumentException("", __FILE__, __LINE__); + if (strlen(pMeshName) > MED_TAILLE_NOM) throw IllegalArgumentException("", __FILE__, __LINE__); + if (mNumComponents < 1) throw IllegalStateException("", __FILE__, __LINE__); + + med_err ret = MEDchampCr( + pMEDfile, + mName, // name of the field + mType, // type of data (MED_FLOAT64, MED_INT32, etc.) + const_cast(mStrComponent.c_str()), // name of components + const_cast(mStrUnit.c_str()), // name of units + mNumComponents); // number of components + + if (ret != 0) throw IOException("i/o error while creating field in MED file", __FILE__, __LINE__); + + // for each time step + for (unsigned i = 0 ; i < mNGauss.size() ; i++) + { + // skip if no values + if (mNVal[i] == 0) continue; + + ret = MEDchampEcr( + pMEDfile, + pMeshName, // name of the mesh (first call to MEDchampEcr => name of reference) + mName, // name of the field + mVal[i], // data (= values) + MED_FULL_INTERLACE, // data organization + mNVal[i], // number of values + const_cast(mGaussLoc[i].c_str()), // name of Gauss reference + MED_ALL, // components to be selected + const_cast(mProfil[i].c_str()), // name of profil + MED_GLOBAL, // how to read data: MED_NO_PFLMOD,MED_COMPACT,MED_GLOBAL + mEntity, // type of entity (MED_NOEUD, MED_MAILLE, etc.) + mGeom, // type of geometry (TETRA10, etc.) + mNumDT[i], // time step iteration + const_cast(mDTUnit[i].c_str()), // unit of time step + mDT[i], // time key + mNumO[i]); // order number + + if (ret != 0) throw IOException("i/o error while writing field in MED file", __FILE__, __LINE__); + } } ostream& operator<<(ostream& pOs, Field& pF) { - char strEntity[16]; - switch (pF.mEntity) - { - case MED_MAILLE: strcpy(strEntity, "MED_MAILLE"); break; - case MED_FACE: strcpy(strEntity, "MED_FACE"); break; - case MED_ARETE: strcpy(strEntity, "MED_ARETE"); break; - case MED_NOEUD: strcpy(strEntity, "MED_NOEUD"); break; - default: strcpy(strEntity, "UNKNOWN"); break; - } - - char strType[16]; - switch (pF.mType) - { - case MED_FLOAT64: strcpy(strType, "MED_FLOAT64"); break; - case MED_INT32: strcpy(strType, "MED_INT32"); break; - case MED_INT64: strcpy(strType, "MED_INT64"); break; - case MED_INT: strcpy(strType, "MED_INT"); break; - default: strcpy(strType, "UNKNOWN"); break; - } - - pOs << "Field: " << endl; - pOs << " Name =|" << pF.mName << "|" << endl; - pOs << " Entity =" << strEntity << endl; - pOs << " Geom =" << pF.mGeom << endl; - pOs << " Type =" << strType << " (size=" << pF.mSizeOfType << ")" << endl; - pOs << " #Components=" << pF.mNumComponents << endl; - pOs << " Name component=|" << pF.mStrComponent << "|" << endl; - pOs << " Unit component=|" << pF.mStrUnit << "|" << endl; - pOs << " #Time steps=" << pF.mNGauss.size() << endl; - - for (unsigned itTimeStep = 0 ; itTimeStep < pF.mNGauss.size() ; itTimeStep++) - { - pOs << " Time=" << pF.mDT[itTimeStep]; - pOs << " it=" << pF.mNumDT[itTimeStep]; - pOs << " order=" << pF.mNumO[itTimeStep]; - pOs << " #gauss=" << pF.mNGauss[itTimeStep]; - pOs << " #val=" << pF.mNVal[itTimeStep]; - pOs << " sizeof_val=" << pF.mSizeOfData[itTimeStep]; - pOs << " gauss_loc=|" << ((pF.mGaussLoc[itTimeStep].size() == 0)?"NONE":pF.mGaussLoc[itTimeStep]) << "| size=" << pF.mGaussLoc[itTimeStep].size(); - pOs << " profil=|" << ((pF.mProfil[itTimeStep].size() == 0)?"NONE":pF.mProfil[itTimeStep]) << "| size=" << pF.mProfil[itTimeStep].size() << endl; - - if (pF.mFlagPrintAll) - { - cout << " Values: "; - switch (pF.mType) - { - case MED_FLOAT64: - { - med_float* src = reinterpret_cast(pF.mVal[itTimeStep]); - for (int itVal = 0 ; itVal < pF.mNVal[itTimeStep] * pF.mNumComponents ; itVal++) - { - cout << src[itVal] << " "; - } - } - break; - case MED_INT: - case MED_INT32: - { - med_int* src = reinterpret_cast(pF.mVal[itTimeStep]); - for (int itVal = 0 ; itVal < pF.mNVal[itTimeStep] * pF.mNumComponents ; itVal++) - { - cout << src[itVal] << " "; - } - } - break; - case MED_INT64: - // not yet implemented - throw UnsupportedOperationException("not yet implemented", __FILE__, __LINE__); - default: - // should not be there - throw IllegalStateException("should not be there", __FILE__, __LINE__); - } - cout << endl; - } - - } - - return pOs; + char strEntity[16]; + switch (pF.mEntity) + { + case MED_MAILLE: strcpy(strEntity, "MED_MAILLE"); break; + case MED_FACE: strcpy(strEntity, "MED_FACE"); break; + case MED_ARETE: strcpy(strEntity, "MED_ARETE"); break; + case MED_NOEUD: strcpy(strEntity, "MED_NOEUD"); break; + default: strcpy(strEntity, "UNKNOWN"); break; + } + + char strType[16]; + switch (pF.mType) + { + case MED_FLOAT64: strcpy(strType, "MED_FLOAT64"); break; + case MED_INT32: strcpy(strType, "MED_INT32"); break; + case MED_INT64: strcpy(strType, "MED_INT64"); break; + case MED_INT: strcpy(strType, "MED_INT"); break; + default: strcpy(strType, "UNKNOWN"); break; + } + + pOs << "Field: " << endl; + pOs << " Name =|" << pF.mName << "|" << endl; + pOs << " Entity =" << strEntity << endl; + pOs << " Geom =" << pF.mGeom << endl; + pOs << " Type =" << strType << " (size=" << pF.mSizeOfType << ")" << endl; + pOs << " #Components=" << pF.mNumComponents << endl; + pOs << " Name component=|" << pF.mStrComponent << "|" << endl; + pOs << " Unit component=|" << pF.mStrUnit << "|" << endl; + pOs << " #Time steps=" << pF.mNGauss.size() << endl; + + for (unsigned itTimeStep = 0 ; itTimeStep < pF.mNGauss.size() ; itTimeStep++) + { + pOs << " Time=" << pF.mDT[itTimeStep]; + pOs << " it=" << pF.mNumDT[itTimeStep]; + pOs << " order=" << pF.mNumO[itTimeStep]; + pOs << " #gauss=" << pF.mNGauss[itTimeStep]; + pOs << " #val=" << pF.mNVal[itTimeStep]; + pOs << " sizeof_val=" << pF.mSizeOfData[itTimeStep]; + pOs << " gauss_loc=|" << ((pF.mGaussLoc[itTimeStep].size() == 0)?"NONE":pF.mGaussLoc[itTimeStep]) << "| size=" << pF.mGaussLoc[itTimeStep].size(); + pOs << " profil=|" << ((pF.mProfil[itTimeStep].size() == 0)?"NONE":pF.mProfil[itTimeStep]) << "| size=" << pF.mProfil[itTimeStep].size() << endl; + + if (pF.mFlagPrintAll) + { + cout << " Values: "; + switch (pF.mType) + { + case MED_FLOAT64: + { + med_float* src = reinterpret_cast(pF.mVal[itTimeStep]); + for (int itVal = 0 ; itVal < pF.mNVal[itTimeStep] * pF.mNumComponents ; itVal++) + { + cout << src[itVal] << " "; + } + } + break; + case MED_INT: + case MED_INT32: + { + med_int* src = reinterpret_cast(pF.mVal[itTimeStep]); + for (int itVal = 0 ; itVal < pF.mNVal[itTimeStep] * pF.mNumComponents ; itVal++) + { + cout << src[itVal] << " "; + } + } + break; + case MED_INT64: + // not yet implemented + throw UnsupportedOperationException("not yet implemented", __FILE__, __LINE__); + default: + // should not be there + throw IllegalStateException("should not be there", __FILE__, __LINE__); + } + cout << endl; + } + + } + + return pOs; } diff --git a/src/MULTIPR/MULTIPR_Field.hxx b/src/MULTIPR/MULTIPR_Field.hxx index 2e82140..c573b3a 100644 --- a/src/MULTIPR/MULTIPR_Field.hxx +++ b/src/MULTIPR/MULTIPR_Field.hxx @@ -20,7 +20,7 @@ extern "C" { - #include "med.h" + #include "med.h" } #include @@ -40,191 +40,191 @@ class Field { public: - /** - * Builds an empty field (default constructor). - */ - Field(); - - /** - * Destructor. Removes everything. - */ - ~Field(); - - /** - * Resets this object in its state by default (empty). Cleans memory. - */ - void reset(); - - //--------------------------------------------------------------------- - // Basic accessors/mutators - //--------------------------------------------------------------------- - - /** - * Returns true iff this field is empty (no data). - * \return true if this field is empty, false otherwise. - */ - bool isEmpty() const; - - /** - * Returns true iff this field apply on nodes (otherwise, information are related to elements). - * \return true iff this field apply on nodes. - */ - bool isFieldOnNodes() const { return (mEntity == MED_NOEUD); } - - /** - * Returns the name of this Field. - * \return the name of this Field. - */ - const char* getName() const { return mName; } - - /** - * Returns the number of time steps in this Field. - * \return the number of time steps in this Field. - */ - int getNumberOfTimeSteps() const { return mNGauss.size(); } - - /** - * Returns the numeric type of information contained in this Field (e.g. MED_FLOAT64). - * \return the numeric type of this Field. - */ - med_type_champ getType() const { return mType; } - - /** - * Returns the number of components of this Field. - * \return the number of components of this Field. - */ - int getNumberOfComponents() const { return mNumComponents; } - - /** - * Returns the number of Gauss points for each element at the given time step. - * \param pTimeStepIt iteration of the field; must be in [1..MAX_ITERATION]. - * \return number of Gauss points in the elements of this Field at the given iteration. - * \throw IndexOutOfBoundsException if pTimeStepIt not in [1..MAX_ITERATION]. - */ - int getNumberOfGaussPointsByElement(int pTimeStepIt) const; - - /** - * Returns the name of the Gauss localization related to the given iteration. - * \param pTimeStepIt iteration of the field; must be in [1..MAX_ITERATION]. - * \return the name of the Gauss localization related to the given iteration. - * \throw IndexOutOfBoundsException if pTimeStepIt not in [1..MAX_ITERATION]. - */ - const std::string& getNameGaussLoc(int pTimeStepIt) const; - - /** - * Returns a pointer towards the first value of this Field for the given element at the given time step. - * \param pTimeStepIt iteration of the field; must be in [1..MAX_ITERATION]. - * \param pIndex index of the element; must be >= 1. - * \return the value of this Field for the given element at the given time step. - * \throw IndexOutOfBoundsException if pTimeStepIt or pIndex are invalid. - */ - const unsigned char* getValue(int pTimeStepIt, int pIndex) const; - - //--------------------------------------------------------------------- - // Algorithms - //--------------------------------------------------------------------- - - /** - * Creates a subset of this Field restricted to a set of elements (NODES or CELLS). - * This method performs a projection of this Field on the given set of elements. - * \param pSetIndices WARNING: indices start at 1. - * \return a new Field restricted to the given set of elements. - */ - Field* extractSubSet(const std::set& pSetIndices) const; - - /** - * Adds the set of GaussLoc used by this Field into the given set. - * \param pSetOfGauss any set of Gauss localisation. - */ - void getSetOfGaussLoc(std::set& pSetOfGaussLoc) const; - - //--------------------------------------------------------------------- - // I/O - //--------------------------------------------------------------------- - - /** - * Reads a field from a MED file. - * If the field is not related to the given mesh, the result is an empty field. - * \param pMEDfile any valid MED file opened for reading. - * \param pIndex index of the field to be read; must be >= 1. - * \param pMeshName name of the mesh (a field is always related to a mesh). - * \throw IOException if any i/o error occurs. - */ - void readMED(med_idt pMEDfile, med_int pIndex, char* pMeshName); - - /** - * Writes this field to a MED file. The field is linked to the given mesh. - * WARNING: all related Gauss info must have been added to the MED file before. - * \param pMEDfile any valid MED file opened for writing. - * \param pMeshName name of the mesh. - * \throw IOException if any i/o error occurs. - */ - void writeMED(med_idt pMEDfile, char* pMeshName); - - /** - * Sets the flag which control the stream operator <<. - * \param pFlag new flag value. - */ - void setPrintAll(bool pFlag) { mFlagPrintAll = pFlag; } - - /** - * Dumps any Field to the given output stream. - * \param pOs any output stream. - * \param pF any Field. - * \return the output stream pOs. - */ - friend std::ostream& operator<<(std::ostream& pOs, Field& pF); - + /** + * Builds an empty field (default constructor). + */ + Field(); + + /** + * Destructor. Removes everything. + */ + ~Field(); + + /** + * Resets this object in its state by default (empty). Cleans memory. + */ + void reset(); + + //--------------------------------------------------------------------- + // Basic accessors/mutators + //--------------------------------------------------------------------- + + /** + * Returns true iff this field is empty (no data). + * \return true if this field is empty, false otherwise. + */ + bool isEmpty() const; + + /** + * Returns true iff this field apply on nodes (otherwise, information are related to elements). + * \return true iff this field apply on nodes. + */ + bool isFieldOnNodes() const { return (mEntity == MED_NOEUD); } + + /** + * Returns the name of this Field. + * \return the name of this Field. + */ + const char* getName() const { return mName; } + + /** + * Returns the number of time steps in this Field. + * \return the number of time steps in this Field. + */ + int getNumberOfTimeSteps() const { return mNGauss.size(); } + + /** + * Returns the numeric type of information contained in this Field (e.g. MED_FLOAT64). + * \return the numeric type of this Field. + */ + med_type_champ getType() const { return mType; } + + /** + * Returns the number of components of this Field. + * \return the number of components of this Field. + */ + int getNumberOfComponents() const { return mNumComponents; } + + /** + * Returns the number of Gauss points for each element at the given time step. + * \param pTimeStepIt iteration of the field; must be in [1..MAX_ITERATION]. + * \return number of Gauss points in the elements of this Field at the given iteration. + * \throw IndexOutOfBoundsException if pTimeStepIt not in [1..MAX_ITERATION]. + */ + int getNumberOfGaussPointsByElement(int pTimeStepIt) const; + + /** + * Returns the name of the Gauss localization related to the given iteration. + * \param pTimeStepIt iteration of the field; must be in [1..MAX_ITERATION]. + * \return the name of the Gauss localization related to the given iteration. + * \throw IndexOutOfBoundsException if pTimeStepIt not in [1..MAX_ITERATION]. + */ + const std::string& getNameGaussLoc(int pTimeStepIt) const; + + /** + * Returns a pointer towards the first value of this Field for the given element at the given time step. + * \param pTimeStepIt iteration of the field; must be in [1..MAX_ITERATION]. + * \param pIndex index of the element; must be >= 1. + * \return the value of this Field for the given element at the given time step. + * \throw IndexOutOfBoundsException if pTimeStepIt or pIndex are invalid. + */ + const unsigned char* getValue(int pTimeStepIt, int pIndex) const; + + //--------------------------------------------------------------------- + // Algorithms + //--------------------------------------------------------------------- + + /** + * Creates a subset of this Field restricted to a set of elements (NODES or CELLS). + * This method performs a projection of this Field on the given set of elements. + * \param pSetIndices WARNING: indices start at 1. + * \return a new Field restricted to the given set of elements. + */ + Field* extractSubSet(const std::set& pSetIndices) const; + + /** + * Adds the set of GaussLoc used by this Field into the given set. + * \param pSetOfGauss any set of Gauss localisation. + */ + void getSetOfGaussLoc(std::set& pSetOfGaussLoc) const; + + //--------------------------------------------------------------------- + // I/O + //--------------------------------------------------------------------- + + /** + * Reads a field from a MED file. + * If the field is not related to the given mesh, the result is an empty field. + * \param pMEDfile any valid MED file opened for reading. + * \param pIndex index of the field to be read; must be >= 1. + * \param pMeshName name of the mesh (a field is always related to a mesh). + * \throw IOException if any i/o error occurs. + */ + void readMED(med_idt pMEDfile, med_int pIndex, char* pMeshName); + + /** + * Writes this field to a MED file. The field is linked to the given mesh. + * WARNING: all related Gauss info must have been added to the MED file before. + * \param pMEDfile any valid MED file opened for writing. + * \param pMeshName name of the mesh. + * \throw IOException if any i/o error occurs. + */ + void writeMED(med_idt pMEDfile, char* pMeshName); + + /** + * Sets the flag which control the stream operator <<. + * \param pFlag new flag value. + */ + void setPrintAll(bool pFlag) { mFlagPrintAll = pFlag; } + + /** + * Dumps any Field to the given output stream. + * \param pOs any output stream. + * \param pF any Field. + * \return the output stream pOs. + */ + friend std::ostream& operator<<(std::ostream& pOs, Field& pF); + private: - /** - * Reads all the information related to its field and a given time step (by its index). - * \param pMEDfile MED file handle. - * \param pNumberOfTimeSteps number of timesteps (iteration) to be read. - * \param pMeshName name of the mesh. - * \throw IOException if any i/o error occurs. - */ - void readMEDtimeSteps(med_idt pMEDfile, med_int pNumberOfTimeSteps, char* pMeshName); - + /** + * Reads all the information related to its field and a given time step (by its index). + * \param pMEDfile MED file handle. + * \param pNumberOfTimeSteps number of timesteps (iteration) to be read. + * \param pMeshName name of the mesh. + * \throw IOException if any i/o error occurs. + */ + void readMEDtimeSteps(med_idt pMEDfile, med_int pNumberOfTimeSteps, char* pMeshName); + private: - - char mName[MED_TAILLE_NOM + 1]; - med_entite_maillage mEntity; // type of entity, e.g. MED_MAILLE - med_geometrie_element mGeom; // type of primitives, e.g. MED_TETRA10 (MED_NONE for a field on nodes) - med_type_champ mType; // type of field, e.g. MED_FLOAT64, MED_INT32 - int mSizeOfType; // 8 for MED_FLOAT64, 4 for MED_INT32, etc. - med_int mNumComponents; - std::string mStrComponent; - std::string mStrUnit; - - // Information related to time steps. - // Each vector should contain the same number of elements. - // Number of time step = mNGauss.size() = mDT.size() = ... - - std::vector mNGauss; /**< For each time step, number of Gauss points in the field. */ - std::vector mDT; /**< For each time step, value of time step. */ - std::vector mNumDT; /**< For each time step, iteration number. */ - std::vector mDTUnit; /**< For each time step, units. */ - std::vector mNumO; /**< For each time step, order number. */ - std::vector mGaussLoc; /**< For each time step, name of Gauss localization to be used (empty if none). */ - std::vector mProfil; /**< For each time step, name of the profil to be used (empty if none). */ - std::vector mSizeOfData; /**< For each time step, sizeof data (mVal) in bytes. */ - std::vector mNVal; /**< For each time step, number of values. */ - std::vector mVal; /**< For each time step, raw data; can be MED_FLOAT64, MED_INT32, etc. see mType. */ - - bool mFlagPrintAll; /**< Flag to control the behaviour of the stream operator <<. */ - + + char mName[MED_TAILLE_NOM + 1]; + med_entite_maillage mEntity; // type of entity, e.g. MED_MAILLE + med_geometrie_element mGeom; // type of primitives, e.g. MED_TETRA10 (MED_NONE for a field on nodes) + med_type_champ mType; // type of field, e.g. MED_FLOAT64, MED_INT32 + int mSizeOfType; // 8 for MED_FLOAT64, 4 for MED_INT32, etc. + med_int mNumComponents; + std::string mStrComponent; + std::string mStrUnit; + + // Information related to time steps. + // Each vector should contain the same number of elements. + // Number of time step = mNGauss.size() = mDT.size() = ... + + std::vector mNGauss; /**< For each time step, number of Gauss points in the field. */ + std::vector mDT; /**< For each time step, value of time step. */ + std::vector mNumDT; /**< For each time step, iteration number. */ + std::vector mDTUnit; /**< For each time step, units. */ + std::vector mNumO; /**< For each time step, order number. */ + std::vector mGaussLoc; /**< For each time step, name of Gauss localization to be used (empty if none). */ + std::vector mProfil; /**< For each time step, name of the profil to be used (empty if none). */ + std::vector mSizeOfData; /**< For each time step, sizeof data (mVal) in bytes. */ + std::vector mNVal; /**< For each time step, number of values. */ + std::vector mVal; /**< For each time step, raw data; can be MED_FLOAT64, MED_INT32, etc. see mType. */ + + bool mFlagPrintAll; /**< Flag to control the behaviour of the stream operator <<. */ + private: - // do not allow copy constructor - Field(const Field&); - - // do not allow copy - Field& operator=(const Field&); - - // do not allow operator == - bool operator==(const Field&); - + // do not allow copy constructor + Field(const Field&); + + // do not allow copy + Field& operator=(const Field&); + + // do not allow operator == + bool operator==(const Field&); + }; // class Field diff --git a/src/MULTIPR/MULTIPR_GaussLoc.cxx b/src/MULTIPR/MULTIPR_GaussLoc.cxx index 7fd8566..31ad42b 100644 --- a/src/MULTIPR/MULTIPR_GaussLoc.cxx +++ b/src/MULTIPR/MULTIPR_GaussLoc.cxx @@ -34,199 +34,197 @@ namespace multipr GaussLoc::GaussLoc() { - mRefCoo = NULL; - mGaussCoo = NULL; - mWeight = NULL; - - reset(); + mRefCoo = NULL; + mGaussCoo = NULL; + mWeight = NULL; + + reset(); } GaussLoc::GaussLoc(const GaussLoc& pGaussLoc) { - mRefCoo = NULL; - mGaussCoo = NULL; - mWeight = NULL; - - strcpy(mName, pGaussLoc.mName); - - mGeom = pGaussLoc.mGeom; - mDim = pGaussLoc.mDim; - mNumNodes = pGaussLoc.mNumNodes; - mNumGauss = pGaussLoc.mNumGauss; - - if (mDim != (mGeom / 100)) throw IllegalStateException("", __FILE__, __LINE__); - if (mNumNodes != (mGeom % 100)) throw IllegalStateException("", __FILE__, __LINE__); - - if (pGaussLoc.mRefCoo != NULL) - { - mRefCoo = new med_float[mDim * mNumNodes]; - memcpy(mRefCoo, pGaussLoc.mRefCoo, sizeof(med_float) * mDim * mNumNodes); - } - - if (pGaussLoc.mGaussCoo != NULL) - { - mGaussCoo = new med_float[mDim * mNumGauss]; - memcpy(mGaussCoo, pGaussLoc.mGaussCoo, sizeof(med_float) * mDim * mNumGauss); - } - - if (pGaussLoc.mWeight != NULL) - { - mWeight = new med_float[mNumGauss]; - memcpy(mWeight, pGaussLoc.mWeight, sizeof(med_float) * mNumGauss); - } + mRefCoo = NULL; + mGaussCoo = NULL; + mWeight = NULL; + + strcpy(mName, pGaussLoc.mName); + + mGeom = pGaussLoc.mGeom; + mDim = pGaussLoc.mDim; + mNumNodes = pGaussLoc.mNumNodes; + mNumGauss = pGaussLoc.mNumGauss; + + if (mDim != (mGeom / 100)) throw IllegalStateException("", __FILE__, __LINE__); + if (mNumNodes != (mGeom % 100)) throw IllegalStateException("", __FILE__, __LINE__); + + if (pGaussLoc.mRefCoo != NULL) + { + mRefCoo = new med_float[mDim * mNumNodes]; + memcpy(mRefCoo, pGaussLoc.mRefCoo, sizeof(med_float) * mDim * mNumNodes); + } + + if (pGaussLoc.mGaussCoo != NULL) + { + mGaussCoo = new med_float[mDim * mNumGauss]; + memcpy(mGaussCoo, pGaussLoc.mGaussCoo, sizeof(med_float) * mDim * mNumGauss); + } + + if (pGaussLoc.mWeight != NULL) + { + mWeight = new med_float[mNumGauss]; + memcpy(mWeight, pGaussLoc.mWeight, sizeof(med_float) * mNumGauss); + } } GaussLoc::~GaussLoc() { - reset(); + reset(); } void GaussLoc::reset() { - mName[0] = '\0'; - mGeom = MED_NONE; - mDim = 0; - mNumNodes = 0; - mNumGauss = 0; - - if (mRefCoo != NULL) { delete[] mRefCoo; mRefCoo = NULL; } - if (mGaussCoo != NULL) { delete[] mGaussCoo; mGaussCoo = NULL; } - if (mWeight != NULL) { delete[] mWeight; mWeight = NULL; } + mName[0] = '\0'; + mGeom = MED_NONE; + mDim = 0; + mNumNodes = 0; + mNumGauss = 0; + + if (mRefCoo != NULL) { delete[] mRefCoo; mRefCoo = NULL; } + if (mGaussCoo != NULL) { delete[] mGaussCoo; mGaussCoo = NULL; } + if (mWeight != NULL) { delete[] mWeight; mWeight = NULL; } } void GaussLoc::getCoordGaussPoints( - const med_float* pCooElt, - med_float* pCooGaussPoints) const + const med_float* pCooElt, + med_float* pCooGaussPoints) const { - // debug - //printArray2D(pCooElt, mNumNodes, mDim, "Node"); - - // WARNING: assumes TETRA10 !!! - // This method is not completely generic and should be extended to support all cases. - if (mGeom != MED_TETRA10) throw UnsupportedOperationException("only support TETRA10 for the moment", __FILE__, __LINE__); - - const med_float* pt1 = pCooElt; - const med_float* pt2 = pt1 + mDim; - const med_float* pt3 = pt2 + mDim; - const med_float* pt4 = pt3 + mDim; - - const med_float* coeff = mGaussCoo; - med_float* dest = pCooGaussPoints; - - // for each Gauss point - for (int i = 0 ; i < mNumGauss ; i++) - { - dest[0] = pt2[0] + (pt4[0] - pt2[0]) * coeff[0] + (pt1[0] - pt2[0]) * coeff[1] + (pt3[0] - pt2[0]) * coeff[2]; - dest[1] = pt2[1] + (pt4[1] - pt2[1]) * coeff[0] + (pt1[1] - pt2[1]) * coeff[1] + (pt3[1] - pt2[1]) * coeff[2]; - dest[2] = pt2[2] + (pt4[2] - pt2[2]) * coeff[0] + (pt1[2] - pt2[2]) * coeff[1] + (pt3[2] - pt2[2]) * coeff[2]; - - // prepare next point - coeff += mDim; - dest += mDim; - } + // debug + //printArray2D(pCooElt, mNumNodes, mDim, "Node"); + + // WARNING: assumes TETRA10 !!! + // This method is not completely generic and should be extended to support all cases. + if (mGeom != MED_TETRA10) throw UnsupportedOperationException("only support TETRA10 for the moment", __FILE__, __LINE__); + + const med_float* pt1 = pCooElt; + const med_float* pt2 = pt1 + mDim; + const med_float* pt3 = pt2 + mDim; + const med_float* pt4 = pt3 + mDim; + + const med_float* coeff = mGaussCoo; + med_float* dest = pCooGaussPoints; + + // for each Gauss point + for (int i = 0 ; i < mNumGauss ; i++) + { + dest[0] = pt2[0] + (pt4[0] - pt2[0]) * coeff[0] + (pt1[0] - pt2[0]) * coeff[1] + (pt3[0] - pt2[0]) * coeff[2]; + dest[1] = pt2[1] + (pt4[1] - pt2[1]) * coeff[0] + (pt1[1] - pt2[1]) * coeff[1] + (pt3[1] - pt2[1]) * coeff[2]; + dest[2] = pt2[2] + (pt4[2] - pt2[2]) * coeff[0] + (pt1[2] - pt2[2]) * coeff[1] + (pt3[2] - pt2[2]) * coeff[2]; + + // prepare next point + coeff += mDim; + dest += mDim; + } } void GaussLoc::readMED(med_idt pMEDfile, med_int pIndex) { - if (pMEDfile == 0) throw IOException("pMEDfile should not be NULL", __FILE__, __LINE__); - if (pIndex < 1) throw IllegalArgumentException("pIndex should be >= 1", __FILE__, __LINE__); - - reset(); - - med_err ret = MEDgaussInfo( - pMEDfile, - pIndex, - mName, - &mGeom, - &mNumGauss); - - if (ret != 0) throw IOException("i/o error while reading Gauss localization information in MED file", __FILE__, __LINE__); - - mDim = mGeom / 100; - mNumNodes = mGeom % 100; - - mRefCoo = new med_float[mDim * mNumNodes]; - mGaussCoo = new med_float[mDim * mNumGauss]; - mWeight = new med_float[mNumGauss]; - - ret = MEDgaussLire( - pMEDfile, - mRefCoo, - mGaussCoo, - mWeight, - MED_FULL_INTERLACE, - mName); - - if (ret != 0) throw IOException("i/o error while reading Gauss localization in MED file", __FILE__, __LINE__); + if (pMEDfile == 0) throw IOException("pMEDfile should not be NULL", __FILE__, __LINE__); + if (pIndex < 1) throw IllegalArgumentException("pIndex should be >= 1", __FILE__, __LINE__); + + reset(); + + med_err ret = MEDgaussInfo( + pMEDfile, + pIndex, + mName, + &mGeom, + &mNumGauss); + + if (ret != 0) throw IOException("i/o error while reading Gauss localization information in MED file", __FILE__, __LINE__); + + mDim = mGeom / 100; + mNumNodes = mGeom % 100; + + mRefCoo = new med_float[mDim * mNumNodes]; + mGaussCoo = new med_float[mDim * mNumGauss]; + mWeight = new med_float[mNumGauss]; + + ret = MEDgaussLire( + pMEDfile, + mRefCoo, + mGaussCoo, + mWeight, + MED_FULL_INTERLACE, + mName); + + if (ret != 0) throw IOException("i/o error while reading Gauss localization in MED file", __FILE__, __LINE__); } void GaussLoc::writeMED(med_idt pMEDfile) { - if (pMEDfile == 0) throw IOException("", __FILE__, __LINE__); - if (mNumGauss < 0) throw IllegalStateException("", __FILE__, __LINE__); - if (mRefCoo == NULL) throw IllegalStateException("", __FILE__, __LINE__); - if (mGaussCoo == NULL) throw IllegalStateException("", __FILE__, __LINE__); - if (mWeight == NULL) throw IllegalStateException("", __FILE__, __LINE__); - if (strlen(mName) > MED_TAILLE_NOM) throw IllegalStateException("", __FILE__, __LINE__); - - med_err ret = MEDgaussEcr( - pMEDfile, - mGeom, - mRefCoo, - MED_FULL_INTERLACE, - mNumGauss, - mGaussCoo, - mWeight, - mName); - - if (ret != 0) throw IOException("i/o error while writing Gauss localization", __FILE__, __LINE__); + if (pMEDfile == 0) throw IOException("", __FILE__, __LINE__); + if (mNumGauss < 0) throw IllegalStateException("", __FILE__, __LINE__); + if (mRefCoo == NULL) throw IllegalStateException("", __FILE__, __LINE__); + if (mGaussCoo == NULL) throw IllegalStateException("", __FILE__, __LINE__); + if (mWeight == NULL) throw IllegalStateException("", __FILE__, __LINE__); + if (strlen(mName) > MED_TAILLE_NOM) throw IllegalStateException("", __FILE__, __LINE__); + + med_err ret = MEDgaussEcr( + pMEDfile, + mGeom, + mRefCoo, + MED_FULL_INTERLACE, + mNumGauss, + mGaussCoo, + mWeight, + mName); + + if (ret != 0) throw IOException("i/o error while writing Gauss localization", __FILE__, __LINE__); } ostream& operator<<(ostream& pOs, GaussLoc& pG) { - pOs << "Gauss ref:" << endl; - pOs << " Name =|" << pG.mName << "|" << endl; - pOs << " Geom =" << pG.mGeom << endl; - pOs << " #Pt Gauss=" << pG.mNumGauss << endl; - - pOs << " Ref nodes coords.: (#nodes=" << pG.mNumNodes << " dim=" << pG.mDim << ")" << endl; - for (int itNode = 0 ; itNode < pG.mNumNodes ; itNode++) - { - pOs << " Node " << (itNode + 1) << ": "; - for (int itDim = 0; itDim < pG.mDim ; itDim++) - { - pOs << pG.mRefCoo[itNode * pG.mDim + itDim] << " "; - } - pOs << endl; - } - - pOs << " Gauss coords. and weight:" << endl; - for (int itGauss = 0 ; itGauss < pG.mNumGauss ; itGauss++) - { - pOs << " Pt " << (itGauss+1) << ": "; - for (int itDim = 0; itDim < pG.mDim ; itDim++) - { - pOs << pG.mGaussCoo[itGauss * pG.mDim + itDim] << " "; - } - pOs << "weight=" << pG.mWeight[itGauss]; - pOs << endl; - } - - /* - // debug - med_float res[15]; - pG.getCoordGaussPoints(pG.mRefCoo, res); - printArray2D(res, pG.mNumGauss, pG.mDim, "Gauss pt"); - */ - - return pOs; + pOs << "Gauss ref:" << endl; + pOs << " Name =|" << pG.mName << "|" << endl; + pOs << " Geom =" << pG.mGeom << endl; + pOs << " #Pt Gauss=" << pG.mNumGauss << endl; + + pOs << " Ref nodes coords.: (#nodes=" << pG.mNumNodes << " dim=" << pG.mDim << ")" << endl; + for (int itNode = 0 ; itNode < pG.mNumNodes ; itNode++) + { + pOs << " Node " << (itNode + 1) << ": "; + for (int itDim = 0; itDim < pG.mDim ; itDim++) + { + pOs << pG.mRefCoo[itNode * pG.mDim + itDim] << " "; + } + pOs << endl; + } + + pOs << " Gauss coords. and weight:" << endl; + for (int itGauss = 0 ; itGauss < pG.mNumGauss ; itGauss++) + { + pOs << " Pt " << (itGauss+1) << ": "; + for (int itDim = 0; itDim < pG.mDim ; itDim++) + { + pOs << pG.mGaussCoo[itGauss * pG.mDim + itDim] << " "; + } + pOs << "weight=" << pG.mWeight[itGauss]; + pOs << endl; + } + + // debug + //med_float res[15]; + //pG.getCoordGaussPoints(pG.mRefCoo, res); + //printArray2D(res, pG.mNumGauss, pG.mDim, "Gauss pt"); + + return pOs; } diff --git a/src/MULTIPR/MULTIPR_GaussLoc.hxx b/src/MULTIPR/MULTIPR_GaussLoc.hxx index d55deb7..dcaa4d4 100644 --- a/src/MULTIPR/MULTIPR_GaussLoc.hxx +++ b/src/MULTIPR/MULTIPR_GaussLoc.hxx @@ -20,7 +20,7 @@ extern "C" { - #include "med.h" + #include "med.h" } #include @@ -38,107 +38,107 @@ class GaussLoc { public: - /** - * Builds an empty Gauss reference (default constructor). - */ - GaussLoc(); - - /** - * Copy constructor (deep copy). - * \param pGaussLoc the GaussLoc to copy. - */ - GaussLoc(const GaussLoc& pGaussLoc); - - /** - * Destructor. Removes everything. - */ - ~GaussLoc(); - - /** - * Resets this object in its state by default (empty). Cleans memory. - */ - void reset(); - - //--------------------------------------------------------------------- - // Basic accessors/mutators - //-------------------------------------------------------------------- - - /** - * Returns the name of this GaussLoc. - * \return the name of this GaussLoc. - */ - std::string getName() const { return mName; } - - /** - * Returns dimension of Gauss points which is also the dimension of reference nodes. - * \return dimension of Gauss points. - */ - int getDim() const { return mDim; } - - /** - * Returns number of Gauss points. - * \return number of Gauss points. - */ - int getNumGaussPoints() const { return mNumGauss; } - - //--------------------------------------------------------------------- - // Algorithms - //-------------------------------------------------------------------- - - /** - * Returns the coordinates of all the Gauss points for a given element. - * \param pCooElt (in) coordinates of nodes of an element. - * \param pCoo (out) coordinates of all the Gauss points (interlaced); memory must have been allocated. - */ - void getCoordGaussPoints(const med_float* pCooElt, med_float* pCooGaussPoints) const; - - //--------------------------------------------------------------------- - // I/O - //--------------------------------------------------------------------- - - /** - * Reads a GaussLoc object from a MED file. - * \param pMEDfile any valid MED file opened for reading. - * \param pIndex index of the gauss localization to be read; must be >= 1. - * \throw IOException if any i/o error occurs. - */ - void readMED(med_idt pMEDfile, med_int pIndex); - - /** - * Writes this GaussLoc object to the given MED file. - * \param pMEDfile any valid MED file opened for writing. - * \throw IOException if any i/o error occurs. - */ - void writeMED(med_idt pMEDfile); - - /** - * Dumps any GaussLoc to the given output stream. - * \param pOs any output stream. - * \param pF any Field. - * \return the output stream pOs. - */ - friend std::ostream& operator<<(std::ostream& pOs, GaussLoc& pG); + /** + * Builds an empty Gauss reference (default constructor). + */ + GaussLoc(); + + /** + * Copy constructor (deep copy). + * \param pGaussLoc the GaussLoc to copy. + */ + GaussLoc(const GaussLoc& pGaussLoc); + + /** + * Destructor. Removes everything. + */ + ~GaussLoc(); + + /** + * Resets this object in its state by default (empty). Cleans memory. + */ + void reset(); + + //--------------------------------------------------------------------- + // Basic accessors/mutators + //-------------------------------------------------------------------- + + /** + * Returns the name of this GaussLoc. + * \return the name of this GaussLoc. + */ + std::string getName() const { return mName; } + + /** + * Returns dimension of Gauss points which is also the dimension of reference nodes. + * \return dimension of Gauss points. + */ + int getDim() const { return mDim; } + + /** + * Returns number of Gauss points. + * \return number of Gauss points. + */ + int getNumGaussPoints() const { return mNumGauss; } + + //--------------------------------------------------------------------- + // Algorithms + //-------------------------------------------------------------------- + + /** + * Returns the coordinates of all the Gauss points for a given element. + * \param pCooElt (in) coordinates of nodes of an element. + * \param pCoo (out) coordinates of all the Gauss points (interlaced); memory must have been allocated. + */ + void getCoordGaussPoints(const med_float* pCooElt, med_float* pCooGaussPoints) const; + + //--------------------------------------------------------------------- + // I/O + //--------------------------------------------------------------------- + + /** + * Reads a GaussLoc object from a MED file. + * \param pMEDfile any valid MED file opened for reading. + * \param pIndex index of the gauss localization to be read; must be >= 1. + * \throw IOException if any i/o error occurs. + */ + void readMED(med_idt pMEDfile, med_int pIndex); + + /** + * Writes this GaussLoc object to the given MED file. + * \param pMEDfile any valid MED file opened for writing. + * \throw IOException if any i/o error occurs. + */ + void writeMED(med_idt pMEDfile); + + /** + * Dumps any GaussLoc to the given output stream. + * \param pOs any output stream. + * \param pF any Field. + * \return the output stream pOs. + */ + friend std::ostream& operator<<(std::ostream& pOs, GaussLoc& pG); private: - - char mName[MED_TAILLE_NOM + 1]; /**< Name of the Gauss info. */ - med_geometrie_element mGeom; /**< Type of elements, e.g. TETRA10 (code is 310). */ - int mDim; /**< Dimension of nodes, e.g. 3 for a TETRA10. */ - int mNumNodes; /**< Number of nodes in the reference element, e.g. 10 for a TETRA10. */ - med_int mNumGauss; /**< Number of Gauss points. */ - med_float* mRefCoo; /**< Table of coordinates of nodes. - Example: for a TETRA10: 10 nodes, 3 components => 30 med_float. */ - med_float* mGaussCoo; /**< Table of coordinates of Gauss points. */ - med_float* mWeight; /**< Table of weights of Gauss points. */ - + + char mName[MED_TAILLE_NOM + 1]; /**< Name of the Gauss info. */ + med_geometrie_element mGeom; /**< Type of elements, e.g. TETRA10 (code is 310). */ + int mDim; /**< Dimension of nodes, e.g. 3 for a TETRA10. */ + int mNumNodes; /**< Number of nodes in the reference element, e.g. 10 for a TETRA10. */ + med_int mNumGauss; /**< Number of Gauss points. */ + med_float* mRefCoo; /**< Table of coordinates of nodes. + Example: for a TETRA10: 10 nodes, 3 components => 30 med_float. */ + med_float* mGaussCoo; /**< Table of coordinates of Gauss points. */ + med_float* mWeight; /**< Table of weights of Gauss points. */ + private: - - // do not allow copy - GaussLoc& operator=(const GaussLoc&); - - // do not allow operator == - bool operator==(const GaussLoc&); - + + // do not allow copy + GaussLoc& operator=(const GaussLoc&); + + // do not allow operator == + bool operator==(const GaussLoc&); + }; // class GaussLoc diff --git a/src/MULTIPR/MULTIPR_Mesh.cxx b/src/MULTIPR/MULTIPR_Mesh.cxx index f0c1979..eb8db9c 100644 --- a/src/MULTIPR/MULTIPR_Mesh.cxx +++ b/src/MULTIPR/MULTIPR_Mesh.cxx @@ -43,1152 +43,1150 @@ namespace multipr Mesh::Mesh() { - mNodes = NULL; - mElements = NULL; - - reset(); + mNodes = NULL; + mElements = NULL; + + reset(); } Mesh::~Mesh() { - reset(); + reset(); } void Mesh::reset() { - mMEDfilename[0] = '\0'; - mMEDfile = 0; - - mMeshName[0] = '\0'; - mMeshUName[0] = '\0'; - mMeshDesc[0] = '\0'; - mMeshDim = -1; - mMeshType = MED_NON_STRUCTURE; - - for (int itDim = 0 ; itDim < 3 ; itDim++) - { - mMeshBBoxMin[itDim] = numeric_limits::quiet_NaN(); - mMeshBBoxMax[itDim] = numeric_limits::quiet_NaN(); - } - - if (mNodes != NULL) { delete mNodes; mNodes = NULL; } - if (mElements != NULL) { delete mElements; mElements = NULL; } - - for (unsigned itFam = 0 ; itFam < mFamilies.size() ; itFam++) - { - delete mFamilies[itFam]; - } - mFamilies.clear(); - mFamIdToFam.clear(); - - for (unsigned itGroup = 0 ; itGroup < mGroups.size() ; itGroup++) - { - delete mGroups[itGroup]; - } - mGroups.clear(); - mGroupNameToGroup.clear(); - - for (unsigned itGaussLoc = 0 ; itGaussLoc < mGaussLoc.size() ; itGaussLoc++) - { - delete mGaussLoc[itGaussLoc]; - } - mGaussLoc.clear(); - mGaussLocNameToGaussLoc.clear(); - - for (unsigned itField = 0 ; itField < mFields.size() ; itField++) - { - delete mFields[itField]; - } - mFields.clear(); - - for (unsigned itProfil = 0 ; itProfil < mProfils.size() ; itProfil++) - { - delete mProfils[itProfil]; - } - mProfils.clear(); - - mFlagPrintAll = false; + mMEDfilename[0] = '\0'; + mMEDfile = 0; + + mMeshName[0] = '\0'; + mMeshUName[0] = '\0'; + mMeshDesc[0] = '\0'; + mMeshDim = -1; + mMeshType = MED_NON_STRUCTURE; + + for (int itDim = 0 ; itDim < 3 ; itDim++) + { + mMeshBBoxMin[itDim] = numeric_limits::quiet_NaN(); + mMeshBBoxMax[itDim] = numeric_limits::quiet_NaN(); + } + + if (mNodes != NULL) { delete mNodes; mNodes = NULL; } + if (mElements != NULL) { delete mElements; mElements = NULL; } + + for (unsigned itFam = 0 ; itFam < mFamilies.size() ; itFam++) + { + delete mFamilies[itFam]; + } + mFamilies.clear(); + mFamIdToFam.clear(); + + for (unsigned itGroup = 0 ; itGroup < mGroups.size() ; itGroup++) + { + delete mGroups[itGroup]; + } + mGroups.clear(); + mGroupNameToGroup.clear(); + + for (unsigned itGaussLoc = 0 ; itGaussLoc < mGaussLoc.size() ; itGaussLoc++) + { + delete mGaussLoc[itGaussLoc]; + } + mGaussLoc.clear(); + mGaussLocNameToGaussLoc.clear(); + + for (unsigned itField = 0 ; itField < mFields.size() ; itField++) + { + delete mFields[itField]; + } + mFields.clear(); + + for (unsigned itProfil = 0 ; itProfil < mProfils.size() ; itProfil++) + { + delete mProfils[itProfil]; + } + mProfils.clear(); + + mFlagPrintAll = false; } vector Mesh::getNameScalarFields() const { - vector res; - - for (int itField = 0 ; itField < mFields.size() ; itField++) - { - Field* currentField = mFields[itField]; - - // only get scalar fields, not vectorial fields - // (because, currently, decimation can only be performed on scalar fields) - if (currentField->getNumberOfComponents() == 1) - { - res.push_back(currentField->getName()); - } - } - - return res; + vector res; + + for (unsigned itField = 0 ; itField < mFields.size() ; itField++) + { + Field* currentField = mFields[itField]; + + // only get scalar fields, not vectorial fields + // (because, currently, decimation can only be performed on scalar fields) + if (currentField->getNumberOfComponents() == 1) + { + res.push_back(currentField->getName()); + } + } + + return res; } int Mesh::getTimeStamps(const char* pFieldName) const { - for (int itField = 0 ; itField < mFields.size() ; itField++) - { - Field* currentField = mFields[itField]; - if (strcmp(currentField->getName(), pFieldName) == 0) - { - return currentField->getNumberOfTimeSteps(); - } - } - - return 0; + for (unsigned itField = 0 ; itField < mFields.size() ; itField++) + { + Field* currentField = mFields[itField]; + if (strcmp(currentField->getName(), pFieldName) == 0) + { + return currentField->getNumberOfTimeSteps(); + } + } + + return 0; } Field* Mesh::getFieldByName(const char* pFieldName) const { - if (pFieldName == NULL) throw NullArgumentException("pFieldName should not be NULL", __FILE__, __LINE__); - - Field* retField = NULL; - - // for each field - for (unsigned itField = 0 ; itField < mFields.size() ; itField++) - { - Field* currentField = mFields[itField]; - if (strcmp(pFieldName, currentField->getName()) == 0) - { - // field found! - retField = currentField; - break; - } - } - - return retField; + if (pFieldName == NULL) throw NullArgumentException("pFieldName should not be NULL", __FILE__, __LINE__); + + Field* retField = NULL; + + // for each field + for (unsigned itField = 0 ; itField < mFields.size() ; itField++) + { + Field* currentField = mFields[itField]; + if (strcmp(pFieldName, currentField->getName()) == 0) + { + // field found! + retField = currentField; + break; + } + } + + return retField; } GaussLoc* Mesh::getGaussLocByName(const char* pGaussLocName) const { - if (pGaussLocName == NULL) throw NullArgumentException("pGaussLocName should not be NULL", __FILE__, __LINE__); - - map::const_iterator itGaussLoc = mGaussLocNameToGaussLoc.find(pGaussLocName); - GaussLoc* retGaussLoc = NULL; - - if (itGaussLoc != mGaussLocNameToGaussLoc.end()) - { - retGaussLoc = (*itGaussLoc).second; - } - - return retGaussLoc; + if (pGaussLocName == NULL) throw NullArgumentException("pGaussLocName should not be NULL", __FILE__, __LINE__); + + map::const_iterator itGaussLoc = mGaussLocNameToGaussLoc.find(pGaussLocName); + GaussLoc* retGaussLoc = NULL; + + if (itGaussLoc != mGaussLocNameToGaussLoc.end()) + { + retGaussLoc = (*itGaussLoc).second; + } + + return retGaussLoc; } int Mesh::getNumberOfElements() const { - if (mElements == NULL) throw IllegalStateException("", __FILE__, __LINE__); - - return mElements->getNumberOfElements(); + if (mElements == NULL) throw IllegalStateException("", __FILE__, __LINE__); + + return mElements->getNumberOfElements(); } Mesh* Mesh::createFromSetOfElements(const std::set& pSetOfElements, const char* pNewMeshName) { - if (pNewMeshName == NULL) throw NullArgumentException("pNewMeshName", __FILE__, __LINE__); - - //--------------------------------------------------------------------- - // Create a new mesh - //--------------------------------------------------------------------- - Mesh* mesh = new Mesh(); - - //--------------------------------------------------------------------- - // Build name of the new mesh - //--------------------------------------------------------------------- - strcpy(mesh->mMeshName, pNewMeshName); - - MULTIPR_LOG("Mesh name=|" << mesh->mMeshName << "|" << endl); - - //--------------------------------------------------------------------- - // Fill general infos - //--------------------------------------------------------------------- - strcpy(mesh->mMeshUName, mMeshUName); - strcpy(mesh->mMeshDesc, mMeshDesc); - - mesh->mMeshDim = mMeshDim; - mesh->mMeshType = mMeshType; - - MULTIPR_LOG("Mesh u. name=|" << mesh->mMeshUName << "|" << endl); - MULTIPR_LOG("Mesh desc=|" << mesh->mMeshDesc << "|" << endl); - MULTIPR_LOG("Mesh dim=" << mesh->mMeshDim << endl); - MULTIPR_LOG("Mesh Type=" << mesh->mMeshType << endl); - - //--------------------------------------------------------------------- - // Build nodes and elements - //--------------------------------------------------------------------- - // get all elements involved - mesh->mElements = mElements->extractSubSet(pSetOfElements); - MULTIPR_LOG((*(mesh->mElements)) << endl); - - // get all nodes involved - const set setOfNodes = mesh->mElements->getSetOfNodes(); - mesh->mNodes = mNodes->extractSubSet(setOfNodes); - MULTIPR_LOG((*(mesh->mNodes)) << endl); - - //--------------------------------------------------------------------- - // Remap nodes - //--------------------------------------------------------------------- - mesh->mElements->remap(); - MULTIPR_LOG((*(mesh->mElements)) << endl); + if (pNewMeshName == NULL) throw NullArgumentException("pNewMeshName", __FILE__, __LINE__); + + //--------------------------------------------------------------------- + // Create a new mesh + //--------------------------------------------------------------------- + Mesh* mesh = new Mesh(); + + //--------------------------------------------------------------------- + // Build name of the new mesh + //--------------------------------------------------------------------- + strcpy(mesh->mMeshName, pNewMeshName); + + MULTIPR_LOG("Mesh name=|" << mesh->mMeshName << "|" << endl); + + //--------------------------------------------------------------------- + // Fill general infos + //--------------------------------------------------------------------- + strcpy(mesh->mMeshUName, mMeshUName); + strcpy(mesh->mMeshDesc, mMeshDesc); + + mesh->mMeshDim = mMeshDim; + mesh->mMeshType = mMeshType; + + MULTIPR_LOG("Mesh u. name=|" << mesh->mMeshUName << "|" << endl); + MULTIPR_LOG("Mesh desc=|" << mesh->mMeshDesc << "|" << endl); + MULTIPR_LOG("Mesh dim=" << mesh->mMeshDim << endl); + MULTIPR_LOG("Mesh Type=" << mesh->mMeshType << endl); + + //--------------------------------------------------------------------- + // Build nodes and elements + //--------------------------------------------------------------------- + // get all elements involved + mesh->mElements = mElements->extractSubSet(pSetOfElements); + MULTIPR_LOG((*(mesh->mElements)) << endl); + + // get all nodes involved + const set setOfNodes = mesh->mElements->getSetOfNodes(); + mesh->mNodes = mNodes->extractSubSet(setOfNodes); + MULTIPR_LOG((*(mesh->mNodes)) << endl); + + //--------------------------------------------------------------------- + // Remap nodes + //--------------------------------------------------------------------- + mesh->mElements->remap(); + MULTIPR_LOG((*(mesh->mElements)) << endl); - //--------------------------------------------------------------------- - // Build families - //--------------------------------------------------------------------- - MULTIPR_LOG("Build fam.:" << endl); - // get families of nodes - { - set famOfNodes = mesh->mNodes->getSetOfFamilies(); - for (set::iterator itFam = famOfNodes.begin() ; itFam != famOfNodes.end() ; itFam++) - { - Family* famSrc = mFamIdToFam[*itFam]; - cout << (*famSrc) << endl; - Family* famDest = famSrc->extractGroup(NULL); - mesh->mFamilies.push_back(famDest); - } - } - - // get families of elements - { - set famOfElt = mesh->mElements->getSetOfFamilies(); - for (set::iterator itFam = famOfElt.begin() ; itFam != famOfElt.end() ; itFam++) - { - Family* famSrc = mFamIdToFam[*itFam]; - Family* famDest = famSrc->extractGroup(NULL); - mesh->mFamilies.push_back(famDest); - } - } - - MULTIPR_LOG("Finalize:"); - - // fill families with elements and build groups - mesh->finalizeFamiliesAndGroups(); - - MULTIPR_LOG("OK\n"); - - //--------------------------------------------------------------------- - // Create new fields and collect Gauss - //--------------------------------------------------------------------- - // for each field - set newSetOfGauss; - for (unsigned itField = 0 ; itField < mFields.size() ; itField++) - { - Field* currentField = mFields[itField]; - - Field* newField; - if (currentField->isFieldOnNodes()) - { - newField = currentField->extractSubSet(setOfNodes); - } - else - { - newField = currentField->extractSubSet(pSetOfElements); - } - - if (!newField->isEmpty()) - { - mesh->mFields.push_back(newField); - newField->getSetOfGaussLoc(newSetOfGauss); - } - } - MULTIPR_LOG("Collect fields: ok: #gauss=" << newSetOfGauss.size() << endl); + //--------------------------------------------------------------------- + // Build families + //--------------------------------------------------------------------- + MULTIPR_LOG("Build fam.:" << endl); + // get families of nodes + { + set famOfNodes = mesh->mNodes->getSetOfFamilies(); + for (set::iterator itFam = famOfNodes.begin() ; itFam != famOfNodes.end() ; itFam++) + { + Family* famSrc = mFamIdToFam[*itFam]; + cout << (*famSrc) << endl; + Family* famDest = famSrc->extractGroup(NULL); + mesh->mFamilies.push_back(famDest); + } + } + + // get families of elements + { + set famOfElt = mesh->mElements->getSetOfFamilies(); + for (set::iterator itFam = famOfElt.begin() ; itFam != famOfElt.end() ; itFam++) + { + Family* famSrc = mFamIdToFam[*itFam]; + Family* famDest = famSrc->extractGroup(NULL); + mesh->mFamilies.push_back(famDest); + } + } + + MULTIPR_LOG("Finalize:"); + + // fill families with elements and build groups + mesh->finalizeFamiliesAndGroups(); + + MULTIPR_LOG("OK\n"); + + //--------------------------------------------------------------------- + // Create new fields and collect Gauss + //--------------------------------------------------------------------- + // for each field + set newSetOfGauss; + for (unsigned itField = 0 ; itField < mFields.size() ; itField++) + { + Field* currentField = mFields[itField]; + + Field* newField; + if (currentField->isFieldOnNodes()) + { + newField = currentField->extractSubSet(setOfNodes); + } + else + { + newField = currentField->extractSubSet(pSetOfElements); + } + + if (!newField->isEmpty()) + { + mesh->mFields.push_back(newField); + newField->getSetOfGaussLoc(newSetOfGauss); + } + } + MULTIPR_LOG("Collect fields: ok: #gauss=" << newSetOfGauss.size() << endl); - //--------------------------------------------------------------------- - // Build Gauss infos - //--------------------------------------------------------------------- - for (set::iterator itSet = newSetOfGauss.begin() ; itSet != newSetOfGauss.end(); itSet++) - { - const string& keyName = (*itSet); - - GaussLoc* gaussLoc = getGaussLocByName(keyName.c_str()); - if (gaussLoc != NULL) - { - GaussLoc* copyGaussLoc = new GaussLoc(*gaussLoc); - mesh->mGaussLoc.push_back(copyGaussLoc); - mesh->mGaussLocNameToGaussLoc.insert(make_pair(copyGaussLoc->getName(), copyGaussLoc)); - } - } - - //--------------------------------------------------------------------- - // Compute bbox - //--------------------------------------------------------------------- - mesh->mNodes->getBBox(mesh->mMeshBBoxMin, mesh->mMeshBBoxMax); - - return mesh; + //--------------------------------------------------------------------- + // Build Gauss infos + //--------------------------------------------------------------------- + for (set::iterator itSet = newSetOfGauss.begin() ; itSet != newSetOfGauss.end(); itSet++) + { + const string& keyName = (*itSet); + + GaussLoc* gaussLoc = getGaussLocByName(keyName.c_str()); + if (gaussLoc != NULL) + { + GaussLoc* copyGaussLoc = new GaussLoc(*gaussLoc); + mesh->mGaussLoc.push_back(copyGaussLoc); + mesh->mGaussLocNameToGaussLoc.insert(make_pair(copyGaussLoc->getName(), copyGaussLoc)); + } + } + + //--------------------------------------------------------------------- + // Compute bbox + //--------------------------------------------------------------------- + mesh->mNodes->getBBox(mesh->mMeshBBoxMin, mesh->mMeshBBoxMax); + + return mesh; } Mesh* Mesh::createFromGroup(const Group* pGroup, const char* pNewMeshName) { - if (pGroup == NULL) throw NullArgumentException("pGroup should not be NULL", __FILE__, __LINE__); - if (pNewMeshName == NULL) throw NullArgumentException("pNewMeshName should not be NULL", __FILE__, __LINE__); - if (strlen(pNewMeshName) > MED_TAILLE_NOM) throw IllegalArgumentException("pNewMeshName length too long", __FILE__, __LINE__); - - //--------------------------------------------------------------------- - // Create a new mesh - //--------------------------------------------------------------------- - Mesh* mesh = new Mesh(); - - //--------------------------------------------------------------------- - // Build name of the new mesh - //--------------------------------------------------------------------- - strcpy(mesh->mMeshName, pNewMeshName); - - MULTIPR_LOG("Mesh name=|" << mesh->mMeshName << "|" << endl); - - //--------------------------------------------------------------------- - // Fill general infos - //--------------------------------------------------------------------- - strcpy(mesh->mMeshUName, mMeshUName); - strcpy(mesh->mMeshDesc, mMeshDesc); - - mesh->mMeshDim = mMeshDim; - mesh->mMeshType = mMeshType; - - MULTIPR_LOG("Mesh u. name=|" << mesh->mMeshUName << "|" << endl); - MULTIPR_LOG("Mesh desc=|" << mesh->mMeshDesc << "|" << endl); - MULTIPR_LOG("Mesh dim=" << mesh->mMeshDim << endl); - MULTIPR_LOG("Mesh Type=" << mesh->mMeshType << endl); - - //--------------------------------------------------------------------- - // Build nodes and elements - //--------------------------------------------------------------------- - // get all elements involved - const set setOfElt = pGroup->getSetOfElt(); - mesh->mElements = mElements->extractSubSet(setOfElt); - MULTIPR_LOG((*(mesh->mElements)) << endl); - - // get all nodes involved - const set setOfNodes = mesh->mElements->getSetOfNodes(); - mesh->mNodes = mNodes->extractSubSet(setOfNodes); - MULTIPR_LOG((*(mesh->mNodes)) << endl); - - //--------------------------------------------------------------------- - // Remap nodes - //--------------------------------------------------------------------- - mesh->mElements->remap(); - MULTIPR_LOG((*(mesh->mElements)) << endl); + if (pGroup == NULL) throw NullArgumentException("pGroup should not be NULL", __FILE__, __LINE__); + if (pNewMeshName == NULL) throw NullArgumentException("pNewMeshName should not be NULL", __FILE__, __LINE__); + if (strlen(pNewMeshName) > MED_TAILLE_NOM) throw IllegalArgumentException("pNewMeshName length too long", __FILE__, __LINE__); + + //--------------------------------------------------------------------- + // Create a new mesh + //--------------------------------------------------------------------- + Mesh* mesh = new Mesh(); + + //--------------------------------------------------------------------- + // Build name of the new mesh + //--------------------------------------------------------------------- + strcpy(mesh->mMeshName, pNewMeshName); + + MULTIPR_LOG("Mesh name=|" << mesh->mMeshName << "|" << endl); + + //--------------------------------------------------------------------- + // Fill general infos + //--------------------------------------------------------------------- + strcpy(mesh->mMeshUName, mMeshUName); + strcpy(mesh->mMeshDesc, mMeshDesc); + + mesh->mMeshDim = mMeshDim; + mesh->mMeshType = mMeshType; + + MULTIPR_LOG("Mesh u. name=|" << mesh->mMeshUName << "|" << endl); + MULTIPR_LOG("Mesh desc=|" << mesh->mMeshDesc << "|" << endl); + MULTIPR_LOG("Mesh dim=" << mesh->mMeshDim << endl); + MULTIPR_LOG("Mesh Type=" << mesh->mMeshType << endl); + + //--------------------------------------------------------------------- + // Build nodes and elements + //--------------------------------------------------------------------- + // get all elements involved + const set setOfElt = pGroup->getSetOfElt(); + mesh->mElements = mElements->extractSubSet(setOfElt); + MULTIPR_LOG((*(mesh->mElements)) << endl); + + // get all nodes involved + const set setOfNodes = mesh->mElements->getSetOfNodes(); + mesh->mNodes = mNodes->extractSubSet(setOfNodes); + MULTIPR_LOG((*(mesh->mNodes)) << endl); + + //--------------------------------------------------------------------- + // Remap nodes + //--------------------------------------------------------------------- + mesh->mElements->remap(); + MULTIPR_LOG((*(mesh->mElements)) << endl); - //--------------------------------------------------------------------- - // Build families - //--------------------------------------------------------------------- - MULTIPR_LOG("Build fam.:" << endl); - // get families of nodes - { - set famOfNodes = mesh->mNodes->getSetOfFamilies(); - for (set::iterator itFam = famOfNodes.begin() ; itFam != famOfNodes.end() ; itFam++) - { - Family* famSrc = mFamIdToFam[*itFam]; - Family* famDest = famSrc->extractGroup(pGroup->getName().c_str()); - mesh->mFamilies.push_back(famDest); - } - } - - // get families of elements - { - set famOfElt = mesh->mElements->getSetOfFamilies(); - for (set::iterator itFam = famOfElt.begin() ; itFam != famOfElt.end() ; itFam++) - { - Family* famSrc = mFamIdToFam[*itFam]; - Family* famDest = famSrc->extractGroup(pGroup->getName().c_str()); - mesh->mFamilies.push_back(famDest); - } - } - - MULTIPR_LOG("Finalize:"); - - // fill families with elements and build groups - mesh->finalizeFamiliesAndGroups(); - - MULTIPR_LOG("OK\n"); - - //--------------------------------------------------------------------- - // Create new fields and collect Gauss - //--------------------------------------------------------------------- - // for each field - set newSetOfGauss; - for (unsigned itField = 0 ; itField < mFields.size() ; itField++) - { - Field* currentField = mFields[itField]; - - Field* newField; - if (currentField->isFieldOnNodes()) - { - newField = currentField->extractSubSet(setOfNodes); - } - else - { - newField = currentField->extractSubSet(setOfElt); - } - - if (!newField->isEmpty()) - { - mesh->mFields.push_back(newField); - newField->getSetOfGaussLoc(newSetOfGauss); - } - } - MULTIPR_LOG("Collect fields: ok: #gauss=" << newSetOfGauss.size() << endl); + //--------------------------------------------------------------------- + // Build families + //--------------------------------------------------------------------- + MULTIPR_LOG("Build fam.:" << endl); + // get families of nodes + { + set famOfNodes = mesh->mNodes->getSetOfFamilies(); + for (set::iterator itFam = famOfNodes.begin() ; itFam != famOfNodes.end() ; itFam++) + { + Family* famSrc = mFamIdToFam[*itFam]; + Family* famDest = famSrc->extractGroup(pGroup->getName().c_str()); + mesh->mFamilies.push_back(famDest); + } + } + + // get families of elements + { + set famOfElt = mesh->mElements->getSetOfFamilies(); + for (set::iterator itFam = famOfElt.begin() ; itFam != famOfElt.end() ; itFam++) + { + Family* famSrc = mFamIdToFam[*itFam]; + Family* famDest = famSrc->extractGroup(pGroup->getName().c_str()); + mesh->mFamilies.push_back(famDest); + } + } + + MULTIPR_LOG("Finalize:"); + + // fill families with elements and build groups + mesh->finalizeFamiliesAndGroups(); + + MULTIPR_LOG("OK\n"); + + //--------------------------------------------------------------------- + // Create new fields and collect Gauss + //--------------------------------------------------------------------- + // for each field + set newSetOfGauss; + for (unsigned itField = 0 ; itField < mFields.size() ; itField++) + { + Field* currentField = mFields[itField]; + + Field* newField; + if (currentField->isFieldOnNodes()) + { + newField = currentField->extractSubSet(setOfNodes); + } + else + { + newField = currentField->extractSubSet(setOfElt); + } + + if (!newField->isEmpty()) + { + mesh->mFields.push_back(newField); + newField->getSetOfGaussLoc(newSetOfGauss); + } + } + MULTIPR_LOG("Collect fields: ok: #gauss=" << newSetOfGauss.size() << endl); - //--------------------------------------------------------------------- - // Build Gauss infos - //--------------------------------------------------------------------- - for (set::iterator itSet = newSetOfGauss.begin() ; itSet != newSetOfGauss.end(); itSet++) - { - const string& keyName = (*itSet); - - GaussLoc* gaussLoc = getGaussLocByName(keyName.c_str()); - if (gaussLoc != NULL) - { - GaussLoc* copyGaussLoc = new GaussLoc(*gaussLoc); - mesh->mGaussLoc.push_back(copyGaussLoc); - mesh->mGaussLocNameToGaussLoc.insert(make_pair(copyGaussLoc->getName(), copyGaussLoc)); - } - } - - //--------------------------------------------------------------------- - // Compute bbox - //--------------------------------------------------------------------- - mesh->mNodes->getBBox(mesh->mMeshBBoxMin, mesh->mMeshBBoxMax); - - return mesh; + //--------------------------------------------------------------------- + // Build Gauss infos + //--------------------------------------------------------------------- + for (set::iterator itSet = newSetOfGauss.begin() ; itSet != newSetOfGauss.end(); itSet++) + { + const string& keyName = (*itSet); + + GaussLoc* gaussLoc = getGaussLocByName(keyName.c_str()); + if (gaussLoc != NULL) + { + GaussLoc* copyGaussLoc = new GaussLoc(*gaussLoc); + mesh->mGaussLoc.push_back(copyGaussLoc); + mesh->mGaussLocNameToGaussLoc.insert(make_pair(copyGaussLoc->getName(), copyGaussLoc)); + } + } + + //--------------------------------------------------------------------- + // Compute bbox + //--------------------------------------------------------------------- + mesh->mNodes->getBBox(mesh->mMeshBBoxMin, mesh->mMeshBBoxMax); + + return mesh; } MeshDis* Mesh::splitGroupsOfElements() { - MeshDis* meshDis = new MeshDis(); - - // get prefix from the original MED filename - string strPrefix = removeExtension(mMEDfilename, ".med"); - - int numGroup = 1; - - // for each group - for (unsigned itGroup = 0 ; itGroup < mGroups.size() ; itGroup++) - { - Group* currentGroup = mGroups[itGroup]; - - // skip this group if it is a group of nodes - if (currentGroup->isGroupOfNodes()) - { - continue; - } - - char strPartName[256]; - sprintf(strPartName, "%s_%d", mMeshName, numGroup); - - char strMEDfilename[256]; - sprintf(strMEDfilename, "%s_grain%d.med", strPrefix.c_str(), numGroup); - - Mesh* mesh = createFromGroup(currentGroup, mMeshName); - - // skip the group which contain all the others groups, even it contains only 1 group - if ((mesh->mElements->getNumberOfElements() == mElements->getNumberOfElements()) && (mGroups.size() > 1)) - { - delete mesh; - continue; - } - - meshDis->addMesh( - MeshDisPart::MULTIPR_WRITE_MESH, - mMeshName, - numGroup, - strPartName, - "localhost", - strMEDfilename, - mesh); - - numGroup++; - } - - return meshDis; + MeshDis* meshDis = new MeshDis(); + meshDis->setSequentialMEDFilename(mMEDfilename); + + // get prefix from the original MED filename + string strPrefix = removeExtension(mMEDfilename, ".med"); + + int numGroup = 1; + + // for each group + for (unsigned itGroup = 0 ; itGroup < mGroups.size() ; itGroup++) + { + Group* currentGroup = mGroups[itGroup]; + + // skip this group if it is a group of nodes + if (currentGroup->isGroupOfNodes()) + { + continue; + } + + char strPartName[256]; + sprintf(strPartName, "%s_%d", mMeshName, numGroup); + + char strMEDfilename[256]; + sprintf(strMEDfilename, "%s_grain%d.med", strPrefix.c_str(), numGroup); + + Mesh* mesh = createFromGroup(currentGroup, mMeshName); + + // skip the group which contain all the others groups, even it contains only 1 group + if ((mesh->mElements->getNumberOfElements() == mElements->getNumberOfElements()) && (mGroups.size() > 1)) + { + delete mesh; + continue; + } + + meshDis->addMesh( + MeshDisPart::MULTIPR_WRITE_MESH, + mMeshName, + numGroup, + strPartName, + "localhost", + strMEDfilename, + mesh); + + numGroup++; + } + + return meshDis; } Mesh* Mesh::decimate( - const char* pFilterName, - const char* pArgv, - const char* pNameNewMesh) + const char* pFilterName, + const char* pArgv, + const char* pNameNewMesh) { - //--------------------------------------------------------------------- - // Check parameters - //--------------------------------------------------------------------- - if (pFilterName == NULL) throw NullArgumentException("pFilterName should not be NULL", __FILE__, __LINE__); - if (pArgv == NULL) throw NullArgumentException("pArgv should not be NULL", __FILE__, __LINE__); - if (pNameNewMesh == NULL) throw NullArgumentException("pNameNewMesh should not be NULL", __FILE__, __LINE__); - - //--------------------------------------------------------------------- - // Instanciate filter used for decimation - //--------------------------------------------------------------------- - DecimationFilter* filter = DecimationFilter::create(pFilterName); - - //--------------------------------------------------------------------- - // Create new mesh by decimating current one - //--------------------------------------------------------------------- - Mesh* decimatedMesh = filter->apply(this, pArgv, pNameNewMesh); - - //--------------------------------------------------------------------- - // Cleans - //--------------------------------------------------------------------- - delete filter; - - return decimatedMesh; + //--------------------------------------------------------------------- + // Check parameters + //--------------------------------------------------------------------- + if (pFilterName == NULL) throw NullArgumentException("pFilterName should not be NULL", __FILE__, __LINE__); + if (pArgv == NULL) throw NullArgumentException("pArgv should not be NULL", __FILE__, __LINE__); + if (pNameNewMesh == NULL) throw NullArgumentException("pNameNewMesh should not be NULL", __FILE__, __LINE__); + + //--------------------------------------------------------------------- + // Instanciate filter used for decimation + //--------------------------------------------------------------------- + DecimationFilter* filter = DecimationFilter::create(pFilterName); + + //--------------------------------------------------------------------- + // Create new mesh by decimating current one + //--------------------------------------------------------------------- + Mesh* decimatedMesh = filter->apply(this, pArgv, pNameNewMesh); + + //--------------------------------------------------------------------- + // Cleans + //--------------------------------------------------------------------- + delete filter; + + return decimatedMesh; } void Mesh::getAllPointsOfField(Field* pField, int pTimeStepIt, std::vector& pPoints) { - //--------------------------------------------------------------------- - // Check arguments - //--------------------------------------------------------------------- - - if (pField == NULL) throw NullArgumentException("field should not be NULL", __FILE__, __LINE__); - if (pTimeStepIt < 1) throw IllegalArgumentException("invalid field iteration; should be >= 1", __FILE__, __LINE__); - - if (mMeshDim != 3) throw UnsupportedOperationException("not yet implemented", __FILE__, __LINE__); - if (pField->getType() != MED_FLOAT64) throw UnsupportedOperationException("not yet implemented", __FILE__, __LINE__); - if (pField->getNumberOfComponents() != 1) throw UnsupportedOperationException("field have more than 1 component (vectorial field, expected scalar field)", __FILE__, __LINE__); - - //--------------------------------------------------------------------- - // Collect points - //--------------------------------------------------------------------- - - if (pField->isFieldOnNodes()) - { - //------------------------------------------------------------- - // Case 1: field of nodes - //------------------------------------------------------------- - if (mNodes == NULL) throw IllegalStateException("no nodes in the current mesh", __FILE__, __LINE__); - - // for each node - for (int itNode = 0, size = mNodes->getNumberOfNodes() ; itNode < size ; itNode++) - { - // collect coordinates and value of the point - const med_float* coo = mNodes->getCoordinates(itNode); - - const med_float* val = - reinterpret_cast(pField->getValue(pTimeStepIt, itNode + 1)); + //--------------------------------------------------------------------- + // Check arguments + //--------------------------------------------------------------------- + + if (pField == NULL) throw NullArgumentException("field should not be NULL", __FILE__, __LINE__); + if (pTimeStepIt < 1) throw IllegalArgumentException("invalid field iteration; should be >= 1", __FILE__, __LINE__); + + if (mMeshDim != 3) throw UnsupportedOperationException("not yet implemented", __FILE__, __LINE__); + if (pField->getType() != MED_FLOAT64) throw UnsupportedOperationException("not yet implemented", __FILE__, __LINE__); + if (pField->getNumberOfComponents() != 1) throw UnsupportedOperationException("field have more than 1 component (vectorial field, expected scalar field)", __FILE__, __LINE__); + + //--------------------------------------------------------------------- + // Collect points + //--------------------------------------------------------------------- + + if (pField->isFieldOnNodes()) + { + //------------------------------------------------------------- + // Case 1: field of nodes + //------------------------------------------------------------- + if (mNodes == NULL) throw IllegalStateException("no nodes in the current mesh", __FILE__, __LINE__); + + // for each node + for (int itNode = 0, size = mNodes->getNumberOfNodes() ; itNode < size ; itNode++) + { + // collect coordinates and value of the point + const med_float* coo = mNodes->getCoordinates(itNode); + + const med_float* val = + reinterpret_cast(pField->getValue(pTimeStepIt, itNode + 1)); - // add new point - pPoints.push_back(PointOfField(coo[0], coo[1], coo[2], val[0])); - } - } - else - { - //------------------------------------------------------------- - // Case 2: field of elements - //------------------------------------------------------------- - - if (mElements == NULL) throw IllegalStateException("no elements in the current mesh", __FILE__, __LINE__); - if (mElements->getTypeOfPrimitives() != MED_TETRA10) throw UnsupportedOperationException("only support TETRA10 mesh", __FILE__, __LINE__); - - const string& nameGaussLoc = pField->getNameGaussLoc(pTimeStepIt); - GaussLoc* gaussLoc = getGaussLocByName(nameGaussLoc.c_str()); - if (gaussLoc == NULL) throw IllegalStateException("no Gauss localization for these elements", __FILE__, __LINE__); - - int numGauss = pField->getNumberOfGaussPointsByElement(pTimeStepIt); - - int size = gaussLoc->getDim() * gaussLoc->getNumGaussPoints(); - med_float* cooGaussPts = new med_float[size]; - - int dim = mElements->getTypeOfPrimitives() / 100; - int numNodes = mElements->getTypeOfPrimitives() % 100; - size = dim * numNodes; - med_float* cooNodes = new med_float[size]; - - // for each elements - for (int itElt = 0, size = mElements->getNumberOfElements() ; itElt < size ; itElt++) - { - // get coordinates of nodes of the current elements - // OPTIMIZATION: ASSUME TETRA10: ONLY GETS THE 4 FIRST NODES OF EACH ELEMENT - mElements->getCoordinates(itElt, mNodes, cooNodes, 4); - - // compute coordinates of gauss points - gaussLoc->getCoordGaussPoints(cooNodes, cooGaussPts); - - //printArray2D(cooGaussPts, 5, 3, "Gauss pt"); - - const med_float* val = - reinterpret_cast(pField->getValue(pTimeStepIt, itElt + 1)); - - // for each point of Gauss of the element - med_float* srcCoo = cooGaussPts; - for (int itPtGauss = 0 ; itPtGauss < numGauss ; itPtGauss++) - { - pPoints.push_back(PointOfField(srcCoo[0], srcCoo[1], srcCoo[2], val[itPtGauss])); - srcCoo += 3; - } - } - - delete[] cooNodes; - delete[] cooGaussPts; - } + // add new point + pPoints.push_back(PointOfField(coo[0], coo[1], coo[2], val[0])); + } + } + else + { + //------------------------------------------------------------- + // Case 2: field of elements + //------------------------------------------------------------- + + if (mElements == NULL) throw IllegalStateException("no elements in the current mesh", __FILE__, __LINE__); + if (mElements->getTypeOfPrimitives() != MED_TETRA10) throw UnsupportedOperationException("only support TETRA10 mesh", __FILE__, __LINE__); + + const string& nameGaussLoc = pField->getNameGaussLoc(pTimeStepIt); + GaussLoc* gaussLoc = getGaussLocByName(nameGaussLoc.c_str()); + if (gaussLoc == NULL) throw IllegalStateException("no Gauss localization for these elements", __FILE__, __LINE__); + + int numGauss = pField->getNumberOfGaussPointsByElement(pTimeStepIt); + + int size = gaussLoc->getDim() * gaussLoc->getNumGaussPoints(); + med_float* cooGaussPts = new med_float[size]; + + int dim = mElements->getTypeOfPrimitives() / 100; + int numNodes = mElements->getTypeOfPrimitives() % 100; + size = dim * numNodes; + med_float* cooNodes = new med_float[size]; + + // for each elements + for (int itElt = 0, size = mElements->getNumberOfElements() ; itElt < size ; itElt++) + { + // get coordinates of nodes of the current elements + // OPTIMIZATION: ASSUME TETRA10: ONLY GETS THE 4 FIRST NODES OF EACH ELEMENT + mElements->getCoordinates(itElt, mNodes, cooNodes, 4); + + // compute coordinates of gauss points + gaussLoc->getCoordGaussPoints(cooNodes, cooGaussPts); + + //printArray2D(cooGaussPts, 5, 3, "Gauss pt"); // debug + + const med_float* val = + reinterpret_cast(pField->getValue(pTimeStepIt, itElt + 1)); + + // for each point of Gauss of the element + med_float* srcCoo = cooGaussPts; + for (int itPtGauss = 0 ; itPtGauss < numGauss ; itPtGauss++) + { + pPoints.push_back(PointOfField(srcCoo[0], srcCoo[1], srcCoo[2], val[itPtGauss])); + srcCoo += 3; + } + } + + delete[] cooNodes; + delete[] cooGaussPts; + } } float Mesh::evalDefaultRadius(int pN) const { - if (mFields.size() == 0) return 1.0f; - - //--------------------------------------------------------------------- - // Compute default radius - //--------------------------------------------------------------------- - - med_float volumeBBox = - (mMeshBBoxMax[0] - mMeshBBoxMin[0]) * - (mMeshBBoxMax[1] - mMeshBBoxMin[1]) * - (mMeshBBoxMax[2] - mMeshBBoxMin[2]); - - if (isnan(volumeBBox)) - { - return 1.0f; - } - - const med_float k = 0.8; // considered 80% of the volume - - // get nunmber of gauss points in the field - try - { - Field* anyField = mFields[mFields.size()-1]; - int numTimeSteps = anyField->getNumberOfTimeSteps(); - - int numGaussPoints = getNumberOfElements() * anyField->getNumberOfGaussPointsByElement(numTimeSteps-1); - - med_float radius = med_float(pow( (3.0/4.0) * pN * k * volumeBBox / (3.1415 * numGaussPoints), 1.0/3.0)); - - return float(radius); - } - catch (...) - { - return 1.0f; - } + if (mFields.size() == 0) return 1.0f; + + //--------------------------------------------------------------------- + // Compute default radius + //--------------------------------------------------------------------- + + med_float volumeBBox = + (mMeshBBoxMax[0] - mMeshBBoxMin[0]) * + (mMeshBBoxMax[1] - mMeshBBoxMin[1]) * + (mMeshBBoxMax[2] - mMeshBBoxMin[2]); + + if (isnan(volumeBBox)) + { + return 1.0f; + } + + const med_float k = 0.8; // considered 80% of the volume + + // get nunmber of gauss points in the field + try + { + Field* anyField = mFields[mFields.size()-1]; + int numTimeSteps = anyField->getNumberOfTimeSteps(); + + int numGaussPoints = getNumberOfElements() * anyField->getNumberOfGaussPointsByElement(numTimeSteps-1); + + med_float radius = med_float(pow( (3.0/4.0) * pN * k * volumeBBox / (3.1415 * numGaussPoints), 1.0/3.0)); + + return float(radius); + } + catch (...) + { + return 1.0f; + } } med_geometrie_element CELL_TYPES[MED_NBR_GEOMETRIE_MAILLE] = { - MED_POINT1, - MED_SEG2, - MED_SEG3, - MED_TRIA3, - MED_TRIA6, - MED_QUAD4, - MED_QUAD8, - MED_TETRA4, - MED_TETRA10, - MED_HEXA8, - MED_HEXA20, - MED_PENTA6, - MED_PENTA15 + MED_POINT1, + MED_SEG2, + MED_SEG3, + MED_TRIA3, + MED_TRIA6, + MED_QUAD4, + MED_QUAD8, + MED_TETRA4, + MED_TETRA10, + MED_HEXA8, + MED_HEXA20, + MED_PENTA6, + MED_PENTA15 }; char CELL_NAMES[MED_NBR_GEOMETRIE_MAILLE][MED_TAILLE_NOM + 1] = { - "MED_POINT1", - "MED_SEG2", - "MED_SEG3", - "MED_TRIA3", - "MED_TRIA6", - "MED_QUAD4", - "MED_QUAD8", - "MED_TETRA4", - "MED_TETRA10", - "MED_HEXA8", - "MED_HEXA20", - "MED_PENTA6", - "MED_PENTA15", - "MED_PYRA5", - "MED_PYRA13" + "MED_POINT1", + "MED_SEG2", + "MED_SEG3", + "MED_TRIA3", + "MED_TRIA6", + "MED_QUAD4", + "MED_QUAD8", + "MED_TETRA4", + "MED_TETRA10", + "MED_HEXA8", + "MED_HEXA20", + "MED_PENTA6", + "MED_PENTA15", + "MED_PYRA5", + "MED_PYRA13" }; void Mesh::readSequentialMED(const char* pMEDfilename, const char* pMeshName) -{ - //cout << "File: |" << multipr::getFilenameWithoutPath(pMEDfilename) << "|" << endl; - //cout << "Path: |" << multipr::getPath(pMEDfilename) << "|" << endl; - - reset(); - - //--------------------------------------------------------------------- - // Check arguments - //--------------------------------------------------------------------- - MULTIPR_LOG("Check arguments: "); - if (pMEDfilename == NULL) throw NullArgumentException("pMEDfilename should not be NULL", __FILE__, __LINE__); - if (pMeshName == NULL) throw NullArgumentException("pMeshName should not be NULL", __FILE__, __LINE__); - MULTIPR_LOG("OK\n"); - - strncpy(mMEDfilename, pMEDfilename, 256); - strncpy(mMeshName, pMeshName, MED_TAILLE_NOM); - - //--------------------------------------------------------------------- - // Open MED file (READ_ONLY) - //--------------------------------------------------------------------- - MULTIPR_LOG("Open MED file: "); - mMEDfile = MEDouvrir(mMEDfilename, MED_LECTURE); // open MED file for reading - if (mMEDfile <= 0) throw FileNotFoundException("MED file not found", __FILE__, __LINE__); - MULTIPR_LOG("OK\n"); - - //--------------------------------------------------------------------- - // Check valid HDF format - //--------------------------------------------------------------------- - MULTIPR_LOG("Format HDF: "); - if (MEDformatConforme(mMEDfilename) != 0) throw IOException("invalid file", __FILE__, __LINE__); - MULTIPR_LOG("OK\n"); - - //--------------------------------------------------------------------- - // Get MED version - //--------------------------------------------------------------------- - MULTIPR_LOG("MED version: "); - med_int verMajor, verMinor, verRelease; - med_err ret = MEDversionLire(mMEDfile, &verMajor, &verMinor, &verRelease); - if (ret != 0) throw IOException("error while reading MED version", __FILE__, __LINE__); - MULTIPR_LOG(verMajor << "." << verMinor << "." << verRelease << ": OK\n"); - - //--------------------------------------------------------------------- - // Check that there is no profil - //--------------------------------------------------------------------- - MULTIPR_LOG("#profils must be 0: "); - med_int nbProfils = MEDnProfil(mMEDfile); - if (nbProfils != 0) throw UnsupportedOperationException("not yet implemented", __FILE__, __LINE__); - MULTIPR_LOG("OK\n"); - - //--------------------------------------------------------------------- - // Read all Gauss localizations - //--------------------------------------------------------------------- - readGaussLoc(); - - //--------------------------------------------------------------------- - // Read scalars (should be 0) - //--------------------------------------------------------------------- - MULTIPR_LOG("Scalars: "); - med_int nbScalars = MEDnScalaire(mMEDfile); - if (nbScalars != 0) throw UnsupportedOperationException("not yet implemented", __FILE__, __LINE__); - MULTIPR_LOG(nbScalars << ": OK\n"); - - //--------------------------------------------------------------------- - // Find the mesh - //--------------------------------------------------------------------- - // read number of meshes - MULTIPR_LOG("Num meshes: "); - med_int nbMeshes = MEDnMaa(mMEDfile); - if (nbMeshes <= 0) throw IOException("i/o error while reading number of meshes in MED file", __FILE__, __LINE__); - MULTIPR_LOG(nbMeshes << ": OK\n"); - - med_int meshIndex = -1; - // iteration over mesh to find the mesh we want - // for each mesh in the file (warning: first mesh is number 1) - for (int itMesh = 1 ; itMesh <= nbMeshes ; itMesh++) - { - char meshName[MED_TAILLE_NOM + 1]; - - ret = MEDmaaInfo( - mMEDfile, - itMesh, - meshName, - &mMeshDim, - &mMeshType, - mMeshDesc); - - if (ret != 0) throw IOException("i/o error while reading mesh information in MED file", __FILE__, __LINE__); - MULTIPR_LOG("Mesh: |" << meshName << "|"); - - // test if the current mesh is the mesh we want - if (strcmp(pMeshName, meshName) == 0) - { - // *** mesh found *** - MULTIPR_LOG(" OK (found)\n"); - meshIndex = itMesh; - break; - } - else - { - // not the mesh we want: skip this mesh - MULTIPR_LOG(" skipped\n"); - } - } - - if (meshIndex == -1) - { - throw IllegalStateException("mesh not found in the given MED file", __FILE__, __LINE__); - } - - //--------------------------------------------------------------------- - // Check mesh validity - //--------------------------------------------------------------------- - // dimension of the mesh must be 3 (= 3D mesh) - MULTIPR_LOG("Mesh is 3D: "); - if (mMeshDim != 3) throw UnsupportedOperationException("dimension of the mesh should be 3; other dimension not yet implemented", __FILE__, __LINE__); - MULTIPR_LOG("OK\n"); - - // mesh must not be a grid - MULTIPR_LOG("Mesh is not a grid: "); - if (mMeshType != MED_NON_STRUCTURE) - throw UnsupportedOperationException("grid not supported", __FILE__, __LINE__); - MULTIPR_LOG("OK\n"); - - // mesh must only contain TETRA10 elements - MULTIPR_LOG("Only TETRA10: "); - med_connectivite connectivite = MED_NOD; // NODAL CONNECTIVITY ONLY - bool onlyTETRA10 = true; - int numTetra10 = -1; - for (int itCell = 0 ; itCell < MED_NBR_GEOMETRIE_MAILLE ; itCell++) - { - med_int meshNumCells = MEDnEntMaa( - mMEDfile, - mMeshName, - MED_CONN, - MED_MAILLE, - CELL_TYPES[itCell], - connectivite); - - if ((meshNumCells > 0) && (strcmp(CELL_NAMES[itCell], "MED_TETRA10") != 0)) - { - onlyTETRA10 = false; - break; - } - if (strcmp(CELL_NAMES[itCell], "MED_TETRA10") == 0) - { - numTetra10 = meshNumCells; - } - } - - if (!onlyTETRA10) throw UnsupportedOperationException("mesh should only contain TETRA10 elements", __FILE__, __LINE__); - MULTIPR_LOG(numTetra10 << ": OK\n"); - - // everything is OK... - - //--------------------------------------------------------------------- - // Check num joint = 0 - //--------------------------------------------------------------------- - MULTIPR_LOG("Num joints: "); - med_int numJoints = MEDnJoint(mMEDfile, mMeshName); - MULTIPR_LOG(numJoints << ": OK\n"); - - //--------------------------------------------------------------------- - // Check num equivalence = 0 - //--------------------------------------------------------------------- - MULTIPR_LOG("Num equivalences: "); - med_int numEquiv = MEDnEquiv(mMEDfile, mMeshName); - MULTIPR_LOG(numEquiv << ": OK\n"); - - //--------------------------------------------------------------------- - // Read nodes - //--------------------------------------------------------------------- - mNodes = new Nodes(); - mNodes->readMED(mMEDfile, mMeshName, mMeshDim); - mNodes->getBBox(mMeshBBoxMin, mMeshBBoxMax); - - //--------------------------------------------------------------------- - // Read elements - //--------------------------------------------------------------------- - mElements = new Elements(); - mElements->readMED(mMEDfile, mMeshName, mMeshDim, MED_MAILLE, MED_TETRA10); - - //--------------------------------------------------------------------- - // Read families - //--------------------------------------------------------------------- - readFamilies(); - finalizeFamiliesAndGroups(); - - //--------------------------------------------------------------------- - // Read fields - //--------------------------------------------------------------------- - readFields(); - - //--------------------------------------------------------------------- - // Close the MED file - //--------------------------------------------------------------------- - MULTIPR_LOG("Close MED file: "); - ret = MEDfermer(mMEDfile); - if (ret != 0) throw IOException("i/o error while closing MED file", __FILE__, __LINE__); - MULTIPR_LOG("OK\n"); +{ + reset(); + + //--------------------------------------------------------------------- + // Check arguments + //--------------------------------------------------------------------- + MULTIPR_LOG("Check arguments: "); + if (pMEDfilename == NULL) throw NullArgumentException("pMEDfilename should not be NULL", __FILE__, __LINE__); + if (pMeshName == NULL) throw NullArgumentException("pMeshName should not be NULL", __FILE__, __LINE__); + MULTIPR_LOG("OK\n"); + + strncpy(mMEDfilename, pMEDfilename, 256); + strncpy(mMeshName, pMeshName, MED_TAILLE_NOM); + + //--------------------------------------------------------------------- + // Open MED file (READ_ONLY) + //--------------------------------------------------------------------- + MULTIPR_LOG("Open MED file: "); + mMEDfile = MEDouvrir(mMEDfilename, MED_LECTURE); // open MED file for reading + if (mMEDfile <= 0) throw FileNotFoundException("MED file not found", __FILE__, __LINE__); + MULTIPR_LOG("OK\n"); + + //--------------------------------------------------------------------- + // Check valid HDF format + //--------------------------------------------------------------------- + MULTIPR_LOG("Format HDF: "); + if (MEDformatConforme(mMEDfilename) != 0) throw IOException("invalid file", __FILE__, __LINE__); + MULTIPR_LOG("OK\n"); + + //--------------------------------------------------------------------- + // Get MED version + //--------------------------------------------------------------------- + MULTIPR_LOG("MED version: "); + med_int verMajor, verMinor, verRelease; + med_err ret = MEDversionLire(mMEDfile, &verMajor, &verMinor, &verRelease); + if (ret != 0) throw IOException("error while reading MED version", __FILE__, __LINE__); + MULTIPR_LOG(verMajor << "." << verMinor << "." << verRelease << ": OK\n"); + + //--------------------------------------------------------------------- + // Check that there is no profil + //--------------------------------------------------------------------- + MULTIPR_LOG("#profils must be 0: "); + med_int nbProfils = MEDnProfil(mMEDfile); + if (nbProfils != 0) throw UnsupportedOperationException("not yet implemented", __FILE__, __LINE__); + MULTIPR_LOG("OK\n"); + + //--------------------------------------------------------------------- + // Read all Gauss localizations + //--------------------------------------------------------------------- + readGaussLoc(); + + //--------------------------------------------------------------------- + // Read scalars (should be 0) + //--------------------------------------------------------------------- + MULTIPR_LOG("Scalars: "); + med_int nbScalars = MEDnScalaire(mMEDfile); + if (nbScalars != 0) throw UnsupportedOperationException("not yet implemented", __FILE__, __LINE__); + MULTIPR_LOG(nbScalars << ": OK\n"); + + //--------------------------------------------------------------------- + // Find the mesh + //--------------------------------------------------------------------- + // read number of meshes + MULTIPR_LOG("Num meshes: "); + med_int nbMeshes = MEDnMaa(mMEDfile); + if (nbMeshes <= 0) throw IOException("i/o error while reading number of meshes in MED file", __FILE__, __LINE__); + MULTIPR_LOG(nbMeshes << ": OK\n"); + + med_int meshIndex = -1; + // iteration over mesh to find the mesh we want + // for each mesh in the file (warning: first mesh is number 1) + for (int itMesh = 1 ; itMesh <= nbMeshes ; itMesh++) + { + char meshName[MED_TAILLE_NOM + 1]; + + ret = MEDmaaInfo( + mMEDfile, + itMesh, + meshName, + &mMeshDim, + &mMeshType, + mMeshDesc); + + if (ret != 0) throw IOException("i/o error while reading mesh information in MED file", __FILE__, __LINE__); + MULTIPR_LOG("Mesh: |" << meshName << "|"); + + // test if the current mesh is the mesh we want + if (strcmp(pMeshName, meshName) == 0) + { + // *** mesh found *** + MULTIPR_LOG(" OK (found)\n"); + meshIndex = itMesh; + break; + } + else + { + // not the mesh we want: skip this mesh + MULTIPR_LOG(" skipped\n"); + } + } + + if (meshIndex == -1) + { + throw IllegalStateException("mesh not found in the given MED file", __FILE__, __LINE__); + } + + //--------------------------------------------------------------------- + // Check mesh validity + //--------------------------------------------------------------------- + // dimension of the mesh must be 3 (= 3D mesh) + MULTIPR_LOG("Mesh is 3D: "); + if (mMeshDim != 3) throw UnsupportedOperationException("dimension of the mesh should be 3; other dimension not yet implemented", __FILE__, __LINE__); + MULTIPR_LOG("OK\n"); + + // mesh must not be a grid + MULTIPR_LOG("Mesh is not a grid: "); + if (mMeshType != MED_NON_STRUCTURE) + throw UnsupportedOperationException("grid not supported", __FILE__, __LINE__); + MULTIPR_LOG("OK\n"); + + // mesh must only contain TETRA10 elements + MULTIPR_LOG("Only TETRA10: "); + med_connectivite connectivite = MED_NOD; // NODAL CONNECTIVITY ONLY + bool onlyTETRA10 = true; + int numTetra10 = -1; + for (int itCell = 0 ; itCell < MED_NBR_GEOMETRIE_MAILLE ; itCell++) + { + med_int meshNumCells = MEDnEntMaa( + mMEDfile, + mMeshName, + MED_CONN, + MED_MAILLE, + CELL_TYPES[itCell], + connectivite); + + if ((meshNumCells > 0) && (strcmp(CELL_NAMES[itCell], "MED_TETRA10") != 0)) + { + onlyTETRA10 = false; + break; + } + if (strcmp(CELL_NAMES[itCell], "MED_TETRA10") == 0) + { + numTetra10 = meshNumCells; + } + } + + if (!onlyTETRA10) throw UnsupportedOperationException("mesh should only contain TETRA10 elements", __FILE__, __LINE__); + MULTIPR_LOG(numTetra10 << ": OK\n"); + + // everything is OK... + + //--------------------------------------------------------------------- + // Check num joint = 0 + //--------------------------------------------------------------------- + MULTIPR_LOG("Num joints: "); + med_int numJoints = MEDnJoint(mMEDfile, mMeshName); + MULTIPR_LOG(numJoints << ": OK\n"); + + //--------------------------------------------------------------------- + // Check num equivalence = 0 + //--------------------------------------------------------------------- + MULTIPR_LOG("Num equivalences: "); + med_int numEquiv = MEDnEquiv(mMEDfile, mMeshName); + MULTIPR_LOG(numEquiv << ": OK\n"); + + //--------------------------------------------------------------------- + // Read nodes + //--------------------------------------------------------------------- + mNodes = new Nodes(); + mNodes->readMED(mMEDfile, mMeshName, mMeshDim); + mNodes->getBBox(mMeshBBoxMin, mMeshBBoxMax); + + //--------------------------------------------------------------------- + // Read elements + //--------------------------------------------------------------------- + mElements = new Elements(); + mElements->readMED(mMEDfile, mMeshName, mMeshDim, MED_MAILLE, MED_TETRA10); + + //--------------------------------------------------------------------- + // Read families + //--------------------------------------------------------------------- + readFamilies(); + finalizeFamiliesAndGroups(); + + //--------------------------------------------------------------------- + // Read fields + //--------------------------------------------------------------------- + readFields(); + + //--------------------------------------------------------------------- + // Close the MED file + //--------------------------------------------------------------------- + MULTIPR_LOG("Close MED file: "); + ret = MEDfermer(mMEDfile); + if (ret != 0) throw IOException("i/o error while closing MED file", __FILE__, __LINE__); + MULTIPR_LOG("OK\n"); } void Mesh::writeMED(const char* pMEDfilename) { - MULTIPR_LOG("Write MED: " << pMEDfilename << endl); + MULTIPR_LOG("Write MED: " << pMEDfilename << endl); - if (pMEDfilename == NULL) throw NullArgumentException("pMEDfilename should not be NULL", __FILE__, __LINE__); - if (strlen(pMEDfilename) == 0) throw IllegalArgumentException("pMEDfilename size is 0", __FILE__, __LINE__); - - remove(pMEDfilename); - - //--------------------------------------------------------------------- - // Create the new MED file (WRITE_ONLY) - //--------------------------------------------------------------------- - med_idt newMEDfile = MEDouvrir(const_cast(pMEDfilename), MED_CREATION); - if (newMEDfile == -1) throw IOException("", __FILE__, __LINE__); - - //--------------------------------------------------------------------- - // Write scalars - //--------------------------------------------------------------------- - // no scalars to write - - //--------------------------------------------------------------------- - // Create mesh: must be created first - //--------------------------------------------------------------------- - med_err ret = MEDmaaCr( - newMEDfile, - mMeshName, - mMeshDim, - MED_NON_STRUCTURE, - mMeshDesc); - - if (ret != 0) throw IOException("", __FILE__, __LINE__); - MULTIPR_LOG(" Create mesh: |" << mMeshName << "|: OK" << endl); - - //--------------------------------------------------------------------- - // Write nodes and elements (mesh must exist) - //--------------------------------------------------------------------- - mNodes->writeMED(newMEDfile, mMeshName); - MULTIPR_LOG(" Write nodes: ok" << endl); - mElements->writeMED(newMEDfile, mMeshName, mMeshDim); - MULTIPR_LOG(" write elt: ok" << endl); - - //--------------------------------------------------------------------- - // Write families (mesh must exist) - //--------------------------------------------------------------------- - for (unsigned itFam = 0 ; itFam < mFamilies.size() ; itFam++) - { - Family* fam = mFamilies[itFam]; - fam->writeMED(newMEDfile, mMeshName); - } - MULTIPR_LOG(" Write families: ok" << endl); - - //--------------------------------------------------------------------- - // Write profil - //--------------------------------------------------------------------- - // no profil - - //--------------------------------------------------------------------- - // Write Gauss localization (must be written before fields) - //--------------------------------------------------------------------- - for (unsigned itGaussLoc = 0 ; itGaussLoc < mGaussLoc.size() ; itGaussLoc++) - { - - GaussLoc* gaussLoc = mGaussLoc[itGaussLoc]; - gaussLoc->writeMED(newMEDfile); - } - MULTIPR_LOG(" Write Gauss: ok" << endl); - - //--------------------------------------------------------------------- - // Write fields - //--------------------------------------------------------------------- - for (unsigned itField = 0 ; itField < mFields.size() ; itField++) - { - Field* field = mFields[itField]; - field->writeMED(newMEDfile, mMeshName); - } - MULTIPR_LOG(" Write fields: ok" << endl); - - //--------------------------------------------------------------------- - // Close the new MED file - //--------------------------------------------------------------------- - ret = MEDfermer(newMEDfile); - if (ret != 0) throw IOException("", __FILE__, __LINE__); + if (pMEDfilename == NULL) throw NullArgumentException("pMEDfilename should not be NULL", __FILE__, __LINE__); + if (strlen(pMEDfilename) == 0) throw IllegalArgumentException("pMEDfilename size is 0", __FILE__, __LINE__); + + remove(pMEDfilename); + + //--------------------------------------------------------------------- + // Create the new MED file (WRITE_ONLY) + //--------------------------------------------------------------------- + med_idt newMEDfile = MEDouvrir(const_cast(pMEDfilename), MED_CREATION); + if (newMEDfile == -1) throw IOException("", __FILE__, __LINE__); + + //--------------------------------------------------------------------- + // Write scalars + //--------------------------------------------------------------------- + // no scalars to write + + //--------------------------------------------------------------------- + // Create mesh: must be created first + //--------------------------------------------------------------------- + med_err ret = MEDmaaCr( + newMEDfile, + mMeshName, + mMeshDim, + MED_NON_STRUCTURE, + mMeshDesc); + + if (ret != 0) throw IOException("", __FILE__, __LINE__); + MULTIPR_LOG(" Create mesh: |" << mMeshName << "|: OK" << endl); + + //--------------------------------------------------------------------- + // Write nodes and elements (mesh must exist) + //--------------------------------------------------------------------- + mNodes->writeMED(newMEDfile, mMeshName); + MULTIPR_LOG(" Write nodes: ok" << endl); + mElements->writeMED(newMEDfile, mMeshName, mMeshDim); + MULTIPR_LOG(" write elt: ok" << endl); + + //--------------------------------------------------------------------- + // Write families (mesh must exist) + //--------------------------------------------------------------------- + for (unsigned itFam = 0 ; itFam < mFamilies.size() ; itFam++) + { + Family* fam = mFamilies[itFam]; + fam->writeMED(newMEDfile, mMeshName); + } + MULTIPR_LOG(" Write families: ok" << endl); + + //--------------------------------------------------------------------- + // Write profil + //--------------------------------------------------------------------- + // no profil + + //--------------------------------------------------------------------- + // Write Gauss localization (must be written before fields) + //--------------------------------------------------------------------- + for (unsigned itGaussLoc = 0 ; itGaussLoc < mGaussLoc.size() ; itGaussLoc++) + { + + GaussLoc* gaussLoc = mGaussLoc[itGaussLoc]; + gaussLoc->writeMED(newMEDfile); + } + MULTIPR_LOG(" Write Gauss: ok" << endl); + + //--------------------------------------------------------------------- + // Write fields + //--------------------------------------------------------------------- + for (unsigned itField = 0 ; itField < mFields.size() ; itField++) + { + Field* field = mFields[itField]; + field->writeMED(newMEDfile, mMeshName); + } + MULTIPR_LOG(" Write fields: ok" << endl); + + //--------------------------------------------------------------------- + // Close the new MED file + //--------------------------------------------------------------------- + ret = MEDfermer(newMEDfile); + if (ret != 0) throw IOException("", __FILE__, __LINE__); } void Mesh::readGaussLoc() { - MULTIPR_LOG("Gauss ref: "); - med_int numGauss = MEDnGauss(mMEDfile); - if (numGauss < 0) throw IOException("", __FILE__, __LINE__); - MULTIPR_LOG(numGauss << ": OK\n"); - - for (int itGauss = 1 ; itGauss <= numGauss ; itGauss++) - { - GaussLoc* gaussLoc = new GaussLoc(); - gaussLoc->readMED(mMEDfile, itGauss); - - MULTIPR_LOG((*gaussLoc) << endl); - - mGaussLoc.push_back(gaussLoc); - mGaussLocNameToGaussLoc.insert(make_pair(gaussLoc->getName(), gaussLoc)); - } + MULTIPR_LOG("Gauss ref: "); + med_int numGauss = MEDnGauss(mMEDfile); + if (numGauss < 0) throw IOException("", __FILE__, __LINE__); + MULTIPR_LOG(numGauss << ": OK\n"); + + for (int itGauss = 1 ; itGauss <= numGauss ; itGauss++) + { + GaussLoc* gaussLoc = new GaussLoc(); + gaussLoc->readMED(mMEDfile, itGauss); + + MULTIPR_LOG((*gaussLoc) << endl); + + mGaussLoc.push_back(gaussLoc); + mGaussLocNameToGaussLoc.insert(make_pair(gaussLoc->getName(), gaussLoc)); + } } void Mesh::readFamilies() { - med_int numFamilies = MEDnFam(mMEDfile, mMeshName); - if (numFamilies <= 0) throw IOException("", __FILE__, __LINE__); - - for (int itFam = 1 ; itFam <= numFamilies ; itFam++) - { - Family* fam = new Family(); - fam->readMED(mMEDfile, mMeshName, itFam); - mFamilies.push_back(fam); - } + med_int numFamilies = MEDnFam(mMEDfile, mMeshName); + if (numFamilies <= 0) throw IOException("", __FILE__, __LINE__); + + for (int itFam = 1 ; itFam <= numFamilies ; itFam++) + { + Family* fam = new Family(); + fam->readMED(mMEDfile, mMeshName, itFam); + mFamilies.push_back(fam); + } } void Mesh::finalizeFamiliesAndGroups() { - //--------------------------------------------------------------------- - // Build mapping between family id and pointers towards families - //--------------------------------------------------------------------- - for (unsigned itFam = 0 ; itFam < mFamilies.size() ; itFam++) - { - Family* fam = mFamilies[itFam]; - mFamIdToFam.insert(make_pair(fam->getId(), fam)); - } - - //--------------------------------------------------------------------- - // Fill families of nodes - //--------------------------------------------------------------------- - for (int itNode = 1 ; itNode <= mNodes->getNumberOfNodes() ; itNode++) - { - // get family of the ith nodes - int famIdent = mNodes->getFamIdent(itNode - 1); // MED nodes start at 1 - map::iterator itFam = mFamIdToFam.find(famIdent); - - if (itFam == mFamIdToFam.end()) throw IllegalStateException("", __FILE__, __LINE__); - - Family* fam = (*itFam).second; - - // insert the current node to its family - fam->insertElt(itNode); - fam->setIsFamilyOfNodes(true); - } - - //--------------------------------------------------------------------- - // Fill families of elements - //--------------------------------------------------------------------- - for (int itElt = 1 ; itElt <= mElements->getNumberOfElements() ; itElt++) - { - // get family of the ith element (MED index start at 1) - int famIdent = mElements->getFamilyIdentifier(itElt - 1); - map::iterator itFam = mFamIdToFam.find(famIdent); - - if (itFam == mFamIdToFam.end()) throw IllegalStateException("", __FILE__, __LINE__); - - Family* fam = (*itFam).second; - - // insert the current node its family - fam->insertElt(itElt); - fam->setIsFamilyOfNodes(false); - } - - //--------------------------------------------------------------------- - // Build groups - //--------------------------------------------------------------------- - // for each family - for (unsigned itFam = 0 ; itFam < mFamilies.size() ; itFam++) - { - mFamilies[itFam]->buildGroups(mGroups, mGroupNameToGroup); - } + //--------------------------------------------------------------------- + // Build mapping between family id and pointers towards families + //--------------------------------------------------------------------- + for (unsigned itFam = 0 ; itFam < mFamilies.size() ; itFam++) + { + Family* fam = mFamilies[itFam]; + mFamIdToFam.insert(make_pair(fam->getId(), fam)); + } + + //--------------------------------------------------------------------- + // Fill families of nodes + //--------------------------------------------------------------------- + for (int itNode = 1 ; itNode <= mNodes->getNumberOfNodes() ; itNode++) + { + // get family of the ith nodes + int famIdent = mNodes->getFamIdent(itNode - 1); // MED nodes start at 1 + map::iterator itFam = mFamIdToFam.find(famIdent); + + if (itFam == mFamIdToFam.end()) throw IllegalStateException("", __FILE__, __LINE__); + + Family* fam = (*itFam).second; + + // insert the current node to its family + fam->insertElt(itNode); + fam->setIsFamilyOfNodes(true); + } + + //--------------------------------------------------------------------- + // Fill families of elements + //--------------------------------------------------------------------- + for (int itElt = 1 ; itElt <= mElements->getNumberOfElements() ; itElt++) + { + // get family of the ith element (MED index start at 1) + int famIdent = mElements->getFamilyIdentifier(itElt - 1); + map::iterator itFam = mFamIdToFam.find(famIdent); + + if (itFam == mFamIdToFam.end()) throw IllegalStateException("", __FILE__, __LINE__); + + Family* fam = (*itFam).second; + + // insert the current node its family + fam->insertElt(itElt); + fam->setIsFamilyOfNodes(false); + } + + //--------------------------------------------------------------------- + // Build groups + //--------------------------------------------------------------------- + // for each family + for (unsigned itFam = 0 ; itFam < mFamilies.size() ; itFam++) + { + mFamilies[itFam]->buildGroups(mGroups, mGroupNameToGroup); + } } void Mesh::readFields() { - //--------------------------------------------------------------------- - // Read number of fields - //--------------------------------------------------------------------- - MULTIPR_LOG("Read fields: "); - med_int numFields = MEDnChamp(mMEDfile, 0); - if (numFields <= 0) throw IOException("", __FILE__, __LINE__); - MULTIPR_LOG(numFields << ": OK\n"); + //--------------------------------------------------------------------- + // Read number of fields + //--------------------------------------------------------------------- + MULTIPR_LOG("Read fields: "); + med_int numFields = MEDnChamp(mMEDfile, 0); + if (numFields <= 0) throw IOException("", __FILE__, __LINE__); + MULTIPR_LOG(numFields << ": OK\n"); - //--------------------------------------------------------------------- - // Iterate over fields - //--------------------------------------------------------------------- - // for each field, read number of components and others infos - for (int itField = 1 ; itField <= numFields ; itField++) - { - Field* field = new Field(); - field->readMED(mMEDfile, itField, mMeshName); - - // if the nth field does not apply on our mesh => slip it - if (field->isEmpty()) - { - delete field; - } - else - { - mFields.push_back(field); - } - } + //--------------------------------------------------------------------- + // Iterate over fields + //--------------------------------------------------------------------- + // for each field, read number of components and others infos + for (int itField = 1 ; itField <= numFields ; itField++) + { + Field* field = new Field(); + field->readMED(mMEDfile, itField, mMeshName); + + // if the nth field does not apply on our mesh => slip it + if (field->isEmpty()) + { + delete field; + } + else + { + mFields.push_back(field); + } + } } ostream& operator<<(ostream& pOs, Mesh& pM) { - pOs << "Mesh: " << endl; - pOs << " MED file =|" << pM.mMEDfilename << "|" << endl; - pOs << " Name =|" << pM.mMeshName << "|" << endl; - pOs << " Unv name =|" << pM.mMeshUName << "|" << endl; - pOs << " Desc =|" << pM.mMeshDesc << "|" << endl; - pOs << " Dim =" << pM.mMeshDim << endl; - pOs << " Type =" << ((pM.mMeshType == MED_STRUCTURE)?"STRUCTURE":"NON_STRUCTURE") << endl; - pOs << " BBox =[" << pM.mMeshBBoxMin[0] << " ; " << pM.mMeshBBoxMax[0] << "] x [" << pM.mMeshBBoxMin[1] << " ; " << pM.mMeshBBoxMax[1] << "] x [" << pM.mMeshBBoxMin[2] << " ; " << pM.mMeshBBoxMax[2] << "]" << endl; - - if (pM.mFlagPrintAll) - { - cout << (*(pM.mNodes)) << endl; - cout << (*(pM.mElements)) << endl; - - pOs << " Families : #=" << pM.mFamilies.size() << endl; - for (unsigned i = 0 ; i < pM.mFamilies.size() ; i++) - { - cout << (*(pM.mFamilies[i])) << endl; - } - - pOs << " Groups : #=" << pM.mGroups.size() << endl; - for (unsigned i = 0 ; i < pM.mGroups.size() ; i++) - { - cout << (*(pM.mGroups[i])) << endl; - } - - pOs << " Gauss loc: #=" << pM.mGaussLoc.size() << endl; - for (unsigned i = 0 ; i < pM.mGaussLoc.size() ; i++) - { - cout << (*(pM.mGaussLoc[i])) << endl; - } - - pOs << " Fields : #=" << pM.mFields.size() << endl; - for (unsigned i = 0 ; i < pM.mFields.size() ; i++) - { - cout << (*(pM.mFields[i])) << endl; - } - } - else - { - pOs << " Nodes : #=" << pM.mNodes->getNumberOfNodes() << endl; - - const set& setOfNodes = pM.mElements->getSetOfNodes(); - if (setOfNodes.size() == 0) - { - pOs << " Elt : #=" << pM.mElements->getNumberOfElements() << endl; - } - else - { - set::iterator itNode = setOfNodes.end(); - itNode--; - pOs << " Elt : #=" << pM.mElements->getNumberOfElements() << " node_id_min=" << (*(setOfNodes.begin())) << " node_id_max=" << (*itNode) << endl; - } - - pOs << " Families : #=" << pM.mFamilies.size() << endl; - pOs << " Groups : #=" << pM.mGroups.size() << endl; - pOs << " Gauss loc: #=" << pM.mGaussLoc.size() << endl; - pOs << " Fields : #=" << pM.mFields.size() << endl; - } - - return pOs; + pOs << "Mesh: " << endl; + pOs << " MED file =|" << pM.mMEDfilename << "|" << endl; + pOs << " Name =|" << pM.mMeshName << "|" << endl; + pOs << " Unv name =|" << pM.mMeshUName << "|" << endl; + pOs << " Desc =|" << pM.mMeshDesc << "|" << endl; + pOs << " Dim =" << pM.mMeshDim << endl; + pOs << " Type =" << ((pM.mMeshType == MED_STRUCTURE)?"STRUCTURE":"NON_STRUCTURE") << endl; + pOs << " BBox =[" << pM.mMeshBBoxMin[0] << " ; " << pM.mMeshBBoxMax[0] << "] x [" << pM.mMeshBBoxMin[1] << " ; " << pM.mMeshBBoxMax[1] << "] x [" << pM.mMeshBBoxMin[2] << " ; " << pM.mMeshBBoxMax[2] << "]" << endl; + + if (pM.mFlagPrintAll) + { + cout << (*(pM.mNodes)) << endl; + cout << (*(pM.mElements)) << endl; + + pOs << " Families : #=" << pM.mFamilies.size() << endl; + for (unsigned i = 0 ; i < pM.mFamilies.size() ; i++) + { + cout << (*(pM.mFamilies[i])) << endl; + } + + pOs << " Groups : #=" << pM.mGroups.size() << endl; + for (unsigned i = 0 ; i < pM.mGroups.size() ; i++) + { + cout << (*(pM.mGroups[i])) << endl; + } + + pOs << " Gauss loc: #=" << pM.mGaussLoc.size() << endl; + for (unsigned i = 0 ; i < pM.mGaussLoc.size() ; i++) + { + cout << (*(pM.mGaussLoc[i])) << endl; + } + + pOs << " Fields : #=" << pM.mFields.size() << endl; + for (unsigned i = 0 ; i < pM.mFields.size() ; i++) + { + cout << (*(pM.mFields[i])) << endl; + } + } + else + { + pOs << " Nodes : #=" << pM.mNodes->getNumberOfNodes() << endl; + + const set& setOfNodes = pM.mElements->getSetOfNodes(); + if (setOfNodes.size() == 0) + { + pOs << " Elt : #=" << pM.mElements->getNumberOfElements() << endl; + } + else + { + set::iterator itNode = setOfNodes.end(); + itNode--; + pOs << " Elt : #=" << pM.mElements->getNumberOfElements() << " node_id_min=" << (*(setOfNodes.begin())) << " node_id_max=" << (*itNode) << endl; + } + + pOs << " Families : #=" << pM.mFamilies.size() << endl; + pOs << " Groups : #=" << pM.mGroups.size() << endl; + pOs << " Gauss loc: #=" << pM.mGaussLoc.size() << endl; + pOs << " Fields : #=" << pM.mFields.size() << endl; + } + + return pOs; } diff --git a/src/MULTIPR/MULTIPR_Mesh.hxx b/src/MULTIPR/MULTIPR_Mesh.hxx index fde3195..79f8117 100644 --- a/src/MULTIPR/MULTIPR_Mesh.hxx +++ b/src/MULTIPR/MULTIPR_Mesh.hxx @@ -20,7 +20,7 @@ extern "C" { - #include "med.h" + #include "med.h" } #include @@ -65,308 +65,294 @@ class Mesh { public: - /** - * Builds an empty Mesh (default constructor). - */ - Mesh(); - - /** - * Destructor. Removes everything. - */ - ~Mesh(); - - /** - * Resets this object in its state by default (empty). Cleans memory. - */ - void reset(); - - //--------------------------------------------------------------------- - // Basic accessors/mutators - //--------------------------------------------------------------------- - - /** - * Returns the name of this Mesh. - * \return the name of this Mesh. - */ - const char* getName() const { return mMeshName; } - - /** - * Returns the name of all the scalar fields. - * \return the name of all the scalar fields. - */ - std::vector getNameScalarFields() const; - - /** - * Returns the number of iteration for a given field. - * \return the number of iteration for a given field. - */ - int getTimeStamps(const char* pFieldName) const; - - /** - * Returns a Field from its name; NULL if it does not exist. - * \param pFieldName name of the field to be retrieved. - * \return the Field pFieldName of it exists, NULL otherwise. - * \throw NullArgumentException if pFieldName is NULL. - */ - Field* getFieldByName(const char* pFieldName) const; - - /** - * Returns a GaussLoc from its name; NULL if it does not exist. - * \param pGaussLocName name of the GaussLoc to be retrieved. - * \return the GaussLoc pGaussLocName if it exists, NULL otherwise. - * \throw NullArgumentException if pGaussLocName is NULL. - */ - GaussLoc* getGaussLocByName(const char* pGaussLocName) const; - - /** - * Returns true iff the given 3D-point is in the bounding box of this Mesh. - * \param pX - * \param pY - * \param pZ - * \return true iff the given 3D-point is in the bounding box of this Mesh. - */ - bool isInBBox(med_float pX, med_float pY, med_float pZ) const - { - return ((pX >= mMeshBBoxMin[0]) && (pX <= mMeshBBoxMax[0]) && - (pY >= mMeshBBoxMin[1]) && (pY <= mMeshBBoxMax[1]) && - (pZ >= mMeshBBoxMin[2]) && (pZ <= mMeshBBoxMax[2])); - } - - /** - * Returns the number of elements. - * \return the number of elements. - */ - int getNumberOfElements() const; - - //--------------------------------------------------------------------- - // Algorithms - //--------------------------------------------------------------------- - - /** - * Creates a Mesh from a subset of its elements (cells). - * \param pSetOfElements subset of elements to keep. - * \param pNewMeshName name of the new Mesh. - * \return a new Mesh which is a restriction of this Mesh to the given set of elements. - * \throw NullArgumentException if pNewMeshName is NULL. - */ - Mesh* createFromSetOfElements(const std::set& pSetOfElements, const char* pNewMeshName); - - /** - * Creates a Mesh from one of its group. - * \param pGroup any group of this Mesh. - * \param pNewMeshName name of the new Mesh. - * \return a new Mesh which is a restriction of this Mesh to pGroup. - * \throw NullArgumentException if pGroup or pNewMeshName is NULL. - */ - Mesh* createFromGroup(const Group* pGroup, const char* pNewMeshName); - - /** - * Creates a distributed mesh (MeshDis) by creating a new mesh for each group of elements in this Mesh. - * \return a distributed mesh from groups of this Mesh. - */ - MeshDis* splitGroupsOfElements(); - - /** - * Creates a new mesh by decimating this one. - * \param pFilterName name of the filter to be used for decimation (e.g. Filtre_GradientMoyen); should not be NULL. - * \param pArgv all the arguments for filtering as a single string. - * \param pNameNewMesh name of the new mesh. - * \return the decimated mesh. - * \throw NullArgumentException if one of the arguments is NULL. - * \throw RuntimeException if any error occurs while decimating data. - */ - Mesh* decimate( - const char* pFilterName, - const char* pArgv, - const char* pNameNewMesh); - - /** - * Gets all the points in a field. Each point has coordinates and a value. - * \param pField any field of this Mesh. - * \param pTimeStepIt time step iteration. - * \param pPoints (out) list of points. - * \throw NullArgumentException if pField is NULL. - * \throw IllegalArgumentException if pTimeStepIt is invalid. - */ - void getAllPointsOfField(Field* pField, int pTimeStepIt, std::vector& pPoints); - - /** - * Returns a default value for neighborhood radius. - * Return value is such that, for any point in the field, average number of neighbours is pN. - * \param pN average number of neighbours. - * \return a default value for neighborhood radius; 1.0 if some error occurs. - */ - float evalDefaultRadius(int pN) const; - - //--------------------------------------------------------------------- - // I/O - //--------------------------------------------------------------------- - - /** - * Reads a Mesh from a sequential MED file. Resets the object before. - * \param pMEDfilename - * \param pMeshName - * \throw IOException if any i/o error occurs. - */ - void readSequentialMED(const char* pMEDfilename, const char* pMeshName); - - /** - * Writes this Mesh and all related things into a MED file. - * \param pMEDfilename - * \throw IOException if any i/o error occurs. - */ - void writeMED(const char* pMEDfilename); - - /** - * Sets the flag which control the stream operator <<. - * \param pFlag new flag value. - */ - void setPrintAll(bool pFlag) { mFlagPrintAll = pFlag; } - - /** - * Dumps any Mesh to the given output stream. - * \param pOs any output stream. - * \param pM any Mesh. - * \return the output stream pOs. - */ - friend std::ostream& operator<<(std::ostream& pOs, Mesh& pM); - + /** + * Builds an empty Mesh (default constructor). + */ + Mesh(); + + /** + * Destructor. Removes everything. + */ + ~Mesh(); + + /** + * Resets this object in its state by default (empty). Cleans memory. + */ + void reset(); + + //--------------------------------------------------------------------- + // Basic accessors/mutators + //--------------------------------------------------------------------- + + /** + * Returns the name of this Mesh. + * \return the name of this Mesh. + */ + const char* getName() const { return mMeshName; } + + /** + * Returns the name of all the scalar fields. + * \return the name of all the scalar fields. + */ + std::vector getNameScalarFields() const; + + /** + * Returns the number of iteration for a given field. + * \return the number of iteration for a given field. + */ + int getTimeStamps(const char* pFieldName) const; + + /** + * Returns a Field from its name; NULL if it does not exist. + * \param pFieldName name of the field to be retrieved. + * \return the Field pFieldName of it exists, NULL otherwise. + * \throw NullArgumentException if pFieldName is NULL. + */ + Field* getFieldByName(const char* pFieldName) const; + + /** + * Returns a GaussLoc from its name; NULL if it does not exist. + * \param pGaussLocName name of the GaussLoc to be retrieved. + * \return the GaussLoc pGaussLocName if it exists, NULL otherwise. + * \throw NullArgumentException if pGaussLocName is NULL. + */ + GaussLoc* getGaussLocByName(const char* pGaussLocName) const; + + /** + * Returns the number of elements. + * \return the number of elements. + */ + int getNumberOfElements() const; + + //--------------------------------------------------------------------- + // Algorithms + //--------------------------------------------------------------------- + + /** + * Creates a Mesh from a subset of its elements (cells). + * \param pSetOfElements subset of elements to keep. + * \param pNewMeshName name of the new Mesh. + * \return a new Mesh which is a restriction of this Mesh to the given set of elements. + * \throw NullArgumentException if pNewMeshName is NULL. + */ + Mesh* createFromSetOfElements(const std::set& pSetOfElements, const char* pNewMeshName); + + /** + * Creates a Mesh from one of its group. + * \param pGroup any group of this Mesh. + * \param pNewMeshName name of the new Mesh. + * \return a new Mesh which is a restriction of this Mesh to pGroup. + * \throw NullArgumentException if pGroup or pNewMeshName is NULL. + */ + Mesh* createFromGroup(const Group* pGroup, const char* pNewMeshName); + + /** + * Creates a distributed mesh (MeshDis) by creating a new mesh for each group of elements in this Mesh. + * \return a distributed mesh from groups of this Mesh. + */ + MeshDis* splitGroupsOfElements(); + + /** + * Creates a new mesh by decimating this one. + * \param pFilterName name of the filter to be used for decimation (e.g. Filtre_GradientMoyen); should not be NULL. + * \param pArgv all the arguments for filtering as a single string. + * \param pNameNewMesh name of the new mesh. + * \return the decimated mesh. + * \throw NullArgumentException if one of the arguments is NULL. + * \throw RuntimeException if any error occurs while decimating data. + */ + Mesh* decimate( + const char* pFilterName, + const char* pArgv, + const char* pNameNewMesh); + + /** + * Gets all the points in a field. Each point has coordinates and a value. + * \param pField any field of this Mesh. + * \param pTimeStepIt time step iteration. + * \param pPoints (out) list of points. + * \throw NullArgumentException if pField is NULL. + * \throw IllegalArgumentException if pTimeStepIt is invalid. + */ + void getAllPointsOfField(Field* pField, int pTimeStepIt, std::vector& pPoints); + + /** + * Returns a default value for neighborhood radius. + * Return value is such that, for any point in the field, average number of neighbours is pN. + * \param pN average number of neighbours. + * \return a default value for neighborhood radius; 1.0 if some error occurs. + */ + float evalDefaultRadius(int pN) const; + + //--------------------------------------------------------------------- + // I/O + //--------------------------------------------------------------------- + + /** + * Reads a Mesh from a sequential MED file. Resets the object before. + * \param pMEDfilename + * \param pMeshName + * \throw IOException if any i/o error occurs. + */ + void readSequentialMED(const char* pMEDfilename, const char* pMeshName); + + /** + * Writes this Mesh and all related things into a MED file. + * \param pMEDfilename + * \throw IOException if any i/o error occurs. + */ + void writeMED(const char* pMEDfilename); + + /** + * Sets the flag which control the stream operator <<. + * \param pFlag new flag value. + */ + void setPrintAll(bool pFlag) { mFlagPrintAll = pFlag; } + + /** + * Dumps any Mesh to the given output stream. + * \param pOs any output stream. + * \param pM any Mesh. + * \return the output stream pOs. + */ + friend std::ostream& operator<<(std::ostream& pOs, Mesh& pM); + private: - - /** - * Reads all Gauss localizations in the current MED file. - * \throw IOException if an i/o error occurs. - */ - void readGaussLoc(); - - /** - * Reads families in the currentMED file and build groups. - * \throw IOException if an i/o error occurs. - */ - void readFamilies(); - - /** - * Finalizes the constructions of families and groups. - * Fill structures with elements. - */ - void finalizeFamiliesAndGroups(); - - /** - * Reads fields related to this mesh in the current MED file. - * \throw IOException if an i/o error occurs. - */ - void readFields(); - + + /** + * Reads all Gauss localizations in the current MED file. + * \throw IOException if an i/o error occurs. + */ + void readGaussLoc(); + + /** + * Reads families in the currentMED file and build groups. + * \throw IOException if an i/o error occurs. + */ + void readFamilies(); + + /** + * Finalizes the constructions of families and groups. + * Fill structures with elements. + */ + void finalizeFamiliesAndGroups(); + + /** + * Reads fields related to this mesh in the current MED file. + * \throw IOException if an i/o error occurs. + */ + void readFields(); + private: - /** - * Name of the associated MED file. - */ - char mMEDfilename[256]; - - /** - * MED file handle. - */ - med_idt mMEDfile; - - /** - * Name of this mesh. - */ - char mMeshName[MED_TAILLE_NOM + 1]; - - /** - * Universal name of this mesh. - */ - char mMeshUName[MED_TAILLE_DESC + 1]; - - /** - * Description. - */ - char mMeshDesc[MED_TAILLE_DESC + 1]; - - /** - * Dimension. - */ - med_int mMeshDim; - - /** - * Type of mesh (MED_NON_STRUCTURE or MED_STRUCTURE (=grid)) - */ - med_maillage mMeshType; - - /** - * Axis aligned bounding box of this mesh. - */ - med_float mMeshBBoxMin[3]; - med_float mMeshBBoxMax[3]; + /** + * Name of the associated MED file. + */ + char mMEDfilename[256]; + + /** + * MED file handle. + */ + med_idt mMEDfile; + + /** + * Name of this mesh. + */ + char mMeshName[MED_TAILLE_NOM + 1]; + + /** + * Universal name of this mesh. + */ + char mMeshUName[MED_TAILLE_DESC + 1]; + + /** + * Description. + */ + char mMeshDesc[MED_TAILLE_DESC + 1]; + + /** + * Dimension. + */ + med_int mMeshDim; + + /** + * Type of mesh (MED_NON_STRUCTURE or MED_STRUCTURE (=grid)) + */ + med_maillage mMeshType; + + /** + * Axis aligned bounding box of this mesh. + */ + med_float mMeshBBoxMin[3]; + med_float mMeshBBoxMax[3]; - /** - * All the nodes used by this mesh. - */ - Nodes* mNodes; - - /** - * All the TETRA10 elements used by this mesh. - */ - Elements* mElements; - - /** - * Table of families used by this mesh. - */ - std::vector mFamilies; - - /** - * Map to retrieve a Family from its name. - */ - std::map mFamIdToFam; - - /** - * Table of groups used by this mesh. - */ - std::vector mGroups; - - /** - * Map to retrieve a Group from its name. - */ - std::map mGroupNameToGroup; - - /** - * Table of GaussLoc. - */ - std::vector mGaussLoc; - - /** - * Map to retrieve a Gauss info from its name. - */ - std::map mGaussLocNameToGaussLoc; - - /** - * Table of fields related to this mesh. - * Number of fiels = mFields.size(). - */ - std::vector mFields; - - /** - * Table of profils. - */ - std::vector mProfils; - - /** - * Flag to control the behaviour of the stream operator <<. - */ - bool mFlagPrintAll; - + /** + * All the nodes used by this mesh. + */ + Nodes* mNodes; + + /** + * All the TETRA10 elements used by this mesh. + */ + Elements* mElements; + + /** + * Table of families used by this mesh. + */ + std::vector mFamilies; + + /** + * Map to retrieve a Family from its name. + */ + std::map mFamIdToFam; + + /** + * Table of groups used by this mesh. + */ + std::vector mGroups; + + /** + * Map to retrieve a Group from its name. + */ + std::map mGroupNameToGroup; + + /** + * Table of GaussLoc. + */ + std::vector mGaussLoc; + + /** + * Map to retrieve a Gauss info from its name. + */ + std::map mGaussLocNameToGaussLoc; + + /** + * Table of fields related to this mesh. + * Number of fiels = mFields.size(). + */ + std::vector mFields; + + /** + * Table of profils. + */ + std::vector mProfils; + + /** + * Flag to control the behaviour of the stream operator <<. + */ + bool mFlagPrintAll; + private: - // do not allow copy constructor - Mesh(const Mesh&); - - // do not allow copy - Mesh& operator=(const Mesh&); - - // do not allow operator == - bool operator==(const Mesh&); - + // do not allow copy constructor + Mesh(const Mesh&); + + // do not allow copy + Mesh& operator=(const Mesh&); + + // do not allow operator == + bool operator==(const Mesh&); + }; // class Mesh diff --git a/src/MULTIPR/MULTIPR_MeshDis.cxx b/src/MULTIPR/MULTIPR_MeshDis.cxx index 3c0571e..5dfd948 100644 --- a/src/MULTIPR/MULTIPR_MeshDis.cxx +++ b/src/MULTIPR/MULTIPR_MeshDis.cxx @@ -40,8 +40,12 @@ namespace multipr // Global variables (exported) //***************************************************************************** +// callback used to report progress about a long task (e.g. save to disk) MULTIPR_ProgressCallback* gProgressCallback = NULL; +// callback used to report empty meshes +MULTIPR_EmptyMeshCallback* gEmptyMeshCallback = NULL; + //***************************************************************************** // Class MeshDisEntry implementation @@ -49,130 +53,129 @@ MULTIPR_ProgressCallback* gProgressCallback = NULL; MeshDisPart::MeshDisPart() { - mMesh = NULL; - mCollection = NULL; - mOldCollection = NULL; - - reset(); + mMesh = NULL; + mCollection = NULL; + mOldCollection = NULL; + + reset(); } MeshDisPart::~MeshDisPart() { - reset(); + reset(); } void MeshDisPart::reset() { - mToDoOnNextWrite = MULTIPR_UNDEFINED; - - mMeshName[0] = '\0'; - mId = 0; - mPartName[0] = '\0'; - mPath[0] = '\0'; - mMEDFileName[0] = '\0'; - - if (mMesh != NULL) - { - delete mMesh; - mMesh = NULL; - } - - mSplit = 0; - - if (mCollection != NULL) - { - delete mCollection; - mCollection = NULL; - } - - if (mOldCollection != NULL) - { - delete mOldCollection; - mOldCollection = NULL; - } + mToDoOnNextWrite = MULTIPR_UNDEFINED; + + mMeshName[0] = '\0'; + mId = 0; + mPartName[0] = '\0'; + mPath[0] = '\0'; + mMEDFileName[0] = '\0'; + + if (mMesh != NULL) + { + delete mMesh; + mMesh = NULL; + } + + mSplit = 0; + + if (mCollection != NULL) + { + delete mCollection; + mCollection = NULL; + } + + if (mOldCollection != NULL) + { + delete mOldCollection; + mOldCollection = NULL; + } } const char* MeshDisPart::getMEDFileNameSuffix() const -{ - // "agregat100grains_12pas_grain97.med" -> "grain97" - // "agregat100grains_12pas_grain100_part2.med" -> "grain100_part2" - // "aagregat100grains_12pas_grain98_gradmoy-low-25.0-0.3.med" -> "grain98_gradmoy-low-25-0.3" - - string prefix = removeExtension(mMEDFileName, ".med"); - prefix.erase(0, prefix.rfind("grain")); - return prefix.c_str(); +{ + // Examples: + // "agregat100grains_12pas_grain97.med" -> "grain97" + // "agregat100grains_12pas_grain100_part2.med" -> "grain100_part2" + // "aagregat100grains_12pas_grain98_gradmoy-low-25.0-0.3.med" -> "grain98_gradmoy-low-25-0.3" + + string prefix = removeExtension(mMEDFileName, ".med"); + prefix.erase(0, prefix.rfind("grain")); + return prefix.c_str(); } void MeshDisPart::create( - OnNextWrite pToDoOnNextWrite, - const char* pMeshName, - int pId, - const char* pPartName, - const char* pPath, - const char* pMEDFileName, - Mesh* pMesh) + OnNextWrite pToDoOnNextWrite, + const char* pMeshName, + int pId, + const char* pPartName, + const char* pPath, + const char* pMEDFileName, + Mesh* pMesh) { - if (pToDoOnNextWrite == MULTIPR_UNDEFINED) throw IllegalArgumentException("", __FILE__, __LINE__); - if (pMeshName == NULL) throw NullArgumentException("", __FILE__, __LINE__); - if (pId < 1) throw IllegalArgumentException("", __FILE__, __LINE__); - if (pPartName == NULL) throw NullArgumentException("", __FILE__, __LINE__); - if (pPath == NULL) throw NullArgumentException("", __FILE__, __LINE__); - if (pMEDFileName == NULL) throw NullArgumentException("", __FILE__, __LINE__); - - reset(); - - mToDoOnNextWrite = pToDoOnNextWrite; - strcpy(mMeshName, pMeshName); - mId = pId; - strcpy(mPartName, pPartName); - strcpy(mPath, pPath); - strcpy(mMEDFileName, pMEDFileName); - mMesh = pMesh; - + if (pToDoOnNextWrite == MULTIPR_UNDEFINED) throw IllegalArgumentException("", __FILE__, __LINE__); + if (pMeshName == NULL) throw NullArgumentException("", __FILE__, __LINE__); + if (pId < 1) throw IllegalArgumentException("", __FILE__, __LINE__); + if (pPartName == NULL) throw NullArgumentException("", __FILE__, __LINE__); + if (pPath == NULL) throw NullArgumentException("", __FILE__, __LINE__); + if (pMEDFileName == NULL) throw NullArgumentException("", __FILE__, __LINE__); + + reset(); + + mToDoOnNextWrite = pToDoOnNextWrite; + strcpy(mMeshName, pMeshName); + mId = pId; + strcpy(mPartName, pPartName); + strcpy(mPath, pPath); + strcpy(mMEDFileName, pMEDFileName); + mMesh = pMesh; + } void MeshDisPart::readMED() { - if (mMesh != NULL) throw IllegalStateException("", __FILE__, __LINE__); - if (mCollection != NULL) throw IllegalStateException("", __FILE__, __LINE__); - if (mOldCollection != NULL) throw IllegalStateException("", __FILE__, __LINE__); - - //cout << "read MED : mesh=" << mMEDfilename << endl; - - mMesh = new Mesh(); - mMesh->readSequentialMED(mMEDFileName, mMeshName); + if (mMesh != NULL) throw IllegalStateException("", __FILE__, __LINE__); + if (mCollection != NULL) throw IllegalStateException("", __FILE__, __LINE__); + if (mOldCollection != NULL) throw IllegalStateException("", __FILE__, __LINE__); + + mMesh = new Mesh(); + mMesh->readSequentialMED(mMEDFileName, mMeshName); } ostream& operator<<(ostream& pOs, MeshDisPart& pM) { - switch (pM.mToDoOnNextWrite) - { - case MeshDisPart::MULTIPR_UNDEFINED: - pOs << "undefined"; - break; - - case MeshDisPart::MULTIPR_KEEP_AS_IT: - pOs << pM.mMeshName << " " << pM.mId << " " << pM.mPartName << " " << pM.mPath << " " << pM.mMEDFileName; - break; - - case MeshDisPart::MULTIPR_WRITE_MESH: - pOs << pM.mMeshName << " " << pM.mId << " " << pM.mPartName << " " << pM.mPath << " " << pM.mMEDFileName; - break; - - case MeshDisPart::MULTIPR_WRITE_PARTS: - pOs << pM.mMeshName << " " << pM.mId << " " << pM.mPartName << " " << pM.mPath << " " << pM.mMEDFileName << " SPLIT " << pM.mSplit; - break; - - default: throw IllegalStateException("", __FILE__, __LINE__); - } - - return pOs; + switch (pM.mToDoOnNextWrite) + { + case MeshDisPart::MULTIPR_UNDEFINED: + pOs << "undefined"; + break; + + case MeshDisPart::MULTIPR_KEEP_AS_IT: + pOs << pM.mMeshName << " " << pM.mId << " " << pM.mPartName << " " << pM.mPath << " " << pM.mMEDFileName; + break; + + case MeshDisPart::MULTIPR_WRITE_MESH: + pOs << pM.mMeshName << " " << pM.mId << " " << pM.mPartName << " " << pM.mPath << " " << pM.mMEDFileName; + break; + + case MeshDisPart::MULTIPR_WRITE_PARTS: + pOs << pM.mMeshName << " " << pM.mId << " " << pM.mPartName << " " << pM.mPath << " " << pM.mMEDFileName << " SPLIT " << pM.mSplit; + break; + + default: throw IllegalStateException("", __FILE__, __LINE__); + } + + return pOs; } @@ -182,642 +185,666 @@ ostream& operator<<(ostream& pOs, MeshDisPart& pM) MeshDis::MeshDis() { - reset(); + reset(); } MeshDis::~MeshDis() { - reset(); + reset(); } void MeshDis::reset() { - mMEDfilename[0] = '\0'; - - for (unsigned itPart = 0 ; itPart != mParts.size() ; itPart++) - { - MeshDisPart* part = mParts[itPart]; - delete part; - } - mParts.clear(); - - //mProgressCallback = NULL; + mSequentialMEDFilename[0] = '\0'; + mDistributedMEDFilename[0] = '\0'; + + for (unsigned itPart = 0 ; itPart != mParts.size() ; itPart++) + { + MeshDisPart* part = mParts[itPart]; + delete part; + } + mParts.clear(); + + //mProgressCallback = NULL; +} + + +void MeshDis::setSequentialMEDFilename(const char* pFilename) +{ + strcpy(mSequentialMEDFilename, pFilename); } void MeshDis::addMesh( - MeshDisPart::OnNextWrite pToDoOnNextWrite, - const char* pMeshName, - int pId, - const char* pPartName, - const char* pPath, - const char* pMEDFileName, - Mesh* pMesh) + MeshDisPart::OnNextWrite pToDoOnNextWrite, + const char* pMeshName, + int pId, + const char* pPartName, + const char* pPath, + const char* pMEDFileName, + Mesh* pMesh) { - MeshDisPart* part = new MeshDisPart(); - - part->create( - pToDoOnNextWrite, - pMeshName, - pId, - pPartName, - pPath, - pMEDFileName, - pMesh); - - mParts.push_back(part); + MeshDisPart* part = new MeshDisPart(); + + part->create( + pToDoOnNextWrite, + pMeshName, + pId, + pPartName, + pPath, + pMEDFileName, + pMesh); + + mParts.push_back(part); } void MeshDis::insertMesh( - MeshDisPart::OnNextWrite pToDoOnNextWrite, - const char* pMeshName, - int pId, - const char* pPartName, - const char* pPath, - const char* pMEDFileName, - Mesh* pMesh, - int pPosition) + MeshDisPart::OnNextWrite pToDoOnNextWrite, + const char* pMeshName, + int pId, + const char* pPartName, + const char* pPath, + const char* pMEDFileName, + Mesh* pMesh, + int pPosition) { - MeshDisPart* part = new MeshDisPart(); - - part->create( - pToDoOnNextWrite, - pMeshName, - pId, - pPartName, - pPath, - pMEDFileName, - pMesh); - - mParts.insert(mParts.begin() + pPosition, part); - - // rename id of following parts - for (unsigned i = pPosition + 1 ; i < mParts.size() ; i++) - { - mParts[i]->mId++; - } + MeshDisPart* part = new MeshDisPart(); + + part->create( + pToDoOnNextWrite, + pMeshName, + pId, + pPartName, + pPath, + pMEDFileName, + pMesh); + + mParts.insert(mParts.begin() + pPosition, part); + + // rename id of following parts + for (unsigned i = pPosition + 1 ; i < mParts.size() ; i++) + { + mParts[i]->mId++; + } } void MeshDis::removeParts(const char* pPrefixPartName) { - if (pPrefixPartName == NULL) throw NullArgumentException("", __FILE__, __LINE__); - - char strPrefix[256]; - sprintf(strPrefix, "%s_", pPrefixPartName); - - for (vector::iterator itPart = mParts.begin() ; itPart != mParts.end() ; itPart++) - { - MeshDisPart* currentPart = (*itPart); - - // remove part which have the same name and all sub_parts - // e.g. if pPrefixPartName="PART_4" => remove "PART_4" and "PART_4_*", but not "PART41" - if ((strcmp(currentPart->getPartName(), pPrefixPartName) == 0) || - startsWith(currentPart->getPartName(), strPrefix)) - { - mParts.erase(itPart); - - // decrement id of following parts - for (vector::iterator itPart2 = itPart ; itPart2 != mParts.end() ; itPart2++) - { - (*itPart2)->mId--; - } - - itPart--; - if (currentPart->mMEDFileName != NULL) - { - remove(currentPart->mMEDFileName); - } - - delete currentPart; - } - } + if (pPrefixPartName == NULL) throw NullArgumentException("", __FILE__, __LINE__); + + char strPrefix[256]; + sprintf(strPrefix, "%s_", pPrefixPartName); + + for (vector::iterator itPart = mParts.begin() ; itPart != mParts.end() ; itPart++) + { + MeshDisPart* currentPart = (*itPart); + + // remove part which have the same name and all sub_parts + // e.g. if pPrefixPartName="PART_4" => remove "PART_4" and "PART_4_*", but not "PART41" + if ((strcmp(currentPart->getPartName(), pPrefixPartName) == 0) || + startsWith(currentPart->getPartName(), strPrefix)) + { + mParts.erase(itPart); + + // decrement id of following parts + for (vector::iterator itPart2 = itPart ; itPart2 != mParts.end() ; itPart2++) + { + (*itPart2)->mId--; + } + + itPart--; + if (currentPart->mMEDFileName != NULL) + { + remove(currentPart->mMEDFileName); + } + + delete currentPart; + } + } } MeshDisPart* MeshDis::findPart(const char* pPartName) { - if (pPartName == NULL) throw NullArgumentException("", __FILE__, __LINE__); - - MeshDisPart* part = NULL; - - for (unsigned itPart = 0 ; itPart < mParts.size() ; itPart++) - { - MeshDisPart* currentPart = mParts[itPart]; - - if (strcmp(currentPart->getPartName(), pPartName) == 0) - { - part = currentPart; - break; - } - } - - return part; - + if (pPartName == NULL) throw NullArgumentException("", __FILE__, __LINE__); + + MeshDisPart* part = NULL; + + for (unsigned itPart = 0 ; itPart < mParts.size() ; itPart++) + { + MeshDisPart* currentPart = mParts[itPart]; + + if (strcmp(currentPart->getPartName(), pPartName) == 0) + { + part = currentPart; + break; + } + } + + return part; + } vector MeshDis::getMeshes() const { - vector res; - - if (mParts.size() > 0) - { - MeshDisPart* part = mParts[0]; - const char* meshName = part->getMeshName(); - res.push_back(meshName); - } - - return res; + vector res; + + if (mParts.size() > 0) + { + MeshDisPart* part = mParts[0]; + const char* meshName = part->getMeshName(); + res.push_back(meshName); + } + + return res; } vector MeshDis::getFields() const { - vector res; - - if (mParts.size() == 0) - { - return res; - } - - // all the parts of the distributed MED file should have the same fields - // => just return the name of fields of the first part - switch (mParts[0]->mToDoOnNextWrite) - { - case MeshDisPart::MULTIPR_KEEP_AS_IT: - case MeshDisPart::MULTIPR_WRITE_PARTS: - { - vector > tmp = multipr::getListScalarFields(mParts[0]->getMEDFileName()); - - for (int i = 0 ; i < tmp.size() ; i++) - { - res.push_back(tmp[i].first); - } - return res; - } - - case MeshDisPart::MULTIPR_WRITE_MESH: - return mParts[0]->mMesh->getNameScalarFields(); - - default: - throw IllegalStateException("", __FILE__, __LINE__); - } + vector res; + + if (mParts.size() == 0) + { + return res; + } + + // all the parts of the distributed MED file should have the same fields + // => just return the name of fields of the first part + switch (mParts[0]->mToDoOnNextWrite) + { + case MeshDisPart::MULTIPR_KEEP_AS_IT: + case MeshDisPart::MULTIPR_WRITE_PARTS: + { + vector > tmp = multipr::getListScalarFields(mParts[0]->getMEDFileName()); + + for (unsigned i = 0 ; i < tmp.size() ; i++) + { + res.push_back(tmp[i].first); + } + return res; + } + + case MeshDisPart::MULTIPR_WRITE_MESH: + return mParts[0]->mMesh->getNameScalarFields(); + + default: + throw IllegalStateException("", __FILE__, __LINE__); + } } int MeshDis::getTimeStamps(const char* pFieldName) const { - if (mParts.size() == 0) - { - // no parts in this distributed MED file => no fields => #iteration = 0 - return 0; - } - - // all the parts of the distributed MED file should have the same fields - // => just return the number of iteration found in the field of the first part - switch (mParts[0]->mToDoOnNextWrite) - { - case MeshDisPart::MULTIPR_KEEP_AS_IT: - case MeshDisPart::MULTIPR_WRITE_PARTS: - { - vector > tmp = multipr::getListScalarFields(mParts[0]->getMEDFileName()); - - for (int i = 0 ; i < tmp.size() ; i++) - { - if (strcmp(tmp[i].first.c_str(), pFieldName) == 0) - { - return tmp[i].second; - } - } - - // pFieldName not found in the list of fields - return 0; - } - - case MeshDisPart::MULTIPR_WRITE_MESH: - return mParts[0]->mMesh->getTimeStamps(pFieldName); - - default: - throw IllegalStateException("", __FILE__, __LINE__); - } + if (mParts.size() == 0) + { + // no parts in this distributed MED file => no fields => #iteration = 0 + return 0; + } + + // all the parts of the distributed MED file should have the same fields + // => just return the number of iteration found in the field of the first part + switch (mParts[0]->mToDoOnNextWrite) + { + case MeshDisPart::MULTIPR_KEEP_AS_IT: + case MeshDisPart::MULTIPR_WRITE_PARTS: + { + vector > tmp = multipr::getListScalarFields(mParts[0]->getMEDFileName()); + + for (int i = 0 ; i < tmp.size() ; i++) + { + if (strcmp(tmp[i].first.c_str(), pFieldName) == 0) + { + return tmp[i].second; + } + } + + // pFieldName not found in the list of fields + return 0; + } + + case MeshDisPart::MULTIPR_WRITE_MESH: + return mParts[0]->mMesh->getTimeStamps(pFieldName); + + default: + throw IllegalStateException("", __FILE__, __LINE__); + } } string MeshDis::getPartInfo(const char* pPartName) { - MeshDisPart* part = findPart(pPartName); - - if (part != NULL) - { - char num[16]; - sprintf(num, "%d", part->mId); - - string res = - string(part->mMeshName) + - string(" ") + - string(num) + - string(" ") + - string(part->mPartName) + - string(" ") + - string(part->mPath) + - string(" ") + - string(part->mMEDFileName); - - return res; - } - else - { - // part not found => return empty string - return ""; - } + MeshDisPart* part = findPart(pPartName); + + if (part != NULL) + { + char num[16]; + sprintf(num, "%d", part->mId); + + string res = + string(part->mMeshName) + + string(" ") + + string(num) + + string(" ") + + string(part->mPartName) + + string(" ") + + string(part->mPath) + + string(" ") + + string(part->mMEDFileName); + + return res; + } + else + { + // part not found => return empty string + return ""; + } } void MeshDis::splitPart(const char* pPartName, int pNbParts, int pPartitionner) { - cout << "MULTIPR: MeshDis::splitPart()" << endl; - if (pPartName == NULL) throw NullArgumentException("", __FILE__, __LINE__); - if (pNbParts < 2) throw IllegalArgumentException("", __FILE__, __LINE__); - if ((pPartitionner != MULTIPR_METIS) && (pPartitionner != MULTIPR_SCOTCH)) throw IllegalArgumentException("should be 0=METIS or 1=SCOTCH", __FILE__, __LINE__); - - cout << "MULTIPR: MeshDis::splitPart(): args OK" << endl; - //--------------------------------------------------------------------- - // Find the MED file corresponding to the given part - //--------------------------------------------------------------------- - MeshDisPart* part = findPart(pPartName); - - if (part == NULL) - { - throw IllegalArgumentException("part not found in this distributed MED file", __FILE__, __LINE__); - } - - cout << "MULTIPR: MeshDis::splitPart(): find part OK" << endl; - - //--------------------------------------------------------------------- - // Load the sequential MED file - //--------------------------------------------------------------------- - MEDSPLITTER::MESHCollection* collection; - collection = new MEDSPLITTER::MESHCollection(part->getMEDFileName(), part->getMeshName()); - - cout << "MULTIPR: MeshDis::splitPart(): MEDSPLITTER collection OK" << endl; - //--------------------------------------------------------------------- - // Partition the group - //--------------------------------------------------------------------- - MEDSPLITTER::Topology* topology; - if (pPartitionner == MULTIPR_METIS) - { - try - { - topology = collection->createPartition(pNbParts, MEDSPLITTER::Graph::METIS); - } - catch (...) - { - throw RuntimeException("MEDSPLITTER error: createPartition(), using METIS", __FILE__, __LINE__); - } - } - else if (pPartitionner == MULTIPR_SCOTCH) - { - try - { - cout << "MULTIPR: try to create partition using SCOTCH: #parts=" << pNbParts << endl; - topology = collection->createPartition(pNbParts, MEDSPLITTER::Graph::SCOTCH); - cout << "MULTIPR: assigned SCOTCH" << endl; - } - catch (...) - { - throw RuntimeException("MEDSPLITTER error: createPartition(), using SCOTCH", __FILE__, __LINE__); - } - } - else - { - throw IllegalStateException("unknown partitionner", __FILE__, __LINE__); - } - - try - { - MEDSPLITTER::MESHCollection* newCollection = new MEDSPLITTER::MESHCollection(*collection, topology); - - part->mToDoOnNextWrite = MeshDisPart::MULTIPR_WRITE_PARTS; - part->mSplit = pNbParts; - part->mOldCollection = collection; - part->mCollection = newCollection; - } - catch (...) - { - cout << "MEDSPLITTER error: new MESHCollection()" << endl; - throw RuntimeException("MEDSPLITTER error: new MESHCollection()", __FILE__, __LINE__); - } + cout << "MULTIPR: MeshDis::splitPart()" << endl; + if (pPartName == NULL) throw NullArgumentException("", __FILE__, __LINE__); + if (pNbParts < 2) throw IllegalArgumentException("", __FILE__, __LINE__); + if ((pPartitionner != MULTIPR_METIS) && (pPartitionner != MULTIPR_SCOTCH)) throw IllegalArgumentException("should be 0=METIS or 1=SCOTCH", __FILE__, __LINE__); + + cout << "MULTIPR: file=" << __FILE__ << " line=" << __LINE__ << " args OK" << endl; + + //--------------------------------------------------------------------- + // Find the MED file corresponding to the given part + //--------------------------------------------------------------------- + MeshDisPart* part = findPart(pPartName); + + if (part == NULL) + { + throw IllegalArgumentException("part not found in this distributed MED file", __FILE__, __LINE__); + } + + cout << "MULTIPR: file=" << __FILE__ << " line=" << __LINE__ << " find part OK" << endl; + + //--------------------------------------------------------------------- + // Load the sequential MED file + //--------------------------------------------------------------------- + MEDSPLITTER::MESHCollection* collection; + collection = new MEDSPLITTER::MESHCollection(part->getMEDFileName(), part->getMeshName()); + + cout << "MULTIPR: file=" << __FILE__ << " line=" << __LINE__ << " MEDSPLITTER collection OK" << endl; + //--------------------------------------------------------------------- + // Partition the group + //--------------------------------------------------------------------- + MEDSPLITTER::Topology* topology; + if (pPartitionner == MULTIPR_METIS) + { + try + { + topology = collection->createPartition(pNbParts, MEDSPLITTER::Graph::METIS); + } + catch (...) + { + throw RuntimeException("MEDSPLITTER error: createPartition(), using METIS", __FILE__, __LINE__); + } + } + else if (pPartitionner == MULTIPR_SCOTCH) + { + try + { + cout << "MULTIPR: file=" << __FILE__ << " line=" << __LINE__ << " try to create partition using SCOTCH: #parts=" << pNbParts << endl; + topology = collection->createPartition(pNbParts, MEDSPLITTER::Graph::SCOTCH); + cout << "MULTIPR: file=" << __FILE__ << " line=" << __LINE__ << " assigned SCOTCH" << endl; + } + catch (...) + { + throw RuntimeException("MEDSPLITTER error: createPartition(), using SCOTCH", __FILE__, __LINE__); + } + } + else + { + throw IllegalStateException("unknown partitionner", __FILE__, __LINE__); + } + + try + { + MEDSPLITTER::MESHCollection* newCollection = new MEDSPLITTER::MESHCollection(*collection, topology); + + part->mToDoOnNextWrite = MeshDisPart::MULTIPR_WRITE_PARTS; + part->mSplit = pNbParts; + part->mOldCollection = collection; + part->mCollection = newCollection; + } + catch (...) + { + cout << "MEDSPLITTER error: new MESHCollection()" << endl; + throw RuntimeException("MEDSPLITTER error: new MESHCollection()", __FILE__, __LINE__); + } } void MeshDis::decimatePart( - const char* pPartName, - const char* pFieldName, - med_int pFieldIt, - const char* pFilterName, - med_float pTMed, - med_float pTLow, - med_float pRadius, - int pBoxing) + const char* pPartName, + const char* pFieldName, + med_int pFieldIt, + const char* pFilterName, + med_float pTMed, + med_float pTLow, + med_float pRadius, + int pBoxing) { - //--------------------------------------------------------------------- - // Check arguments - //--------------------------------------------------------------------- - if (pPartName == NULL) throw NullArgumentException("partname should not be NULL", __FILE__, __LINE__); - if (pFieldName == NULL) throw NullArgumentException("fieldname should not be NULL", __FILE__, __LINE__); - if (pFieldIt < med_int(1)) throw IllegalArgumentException("invalid field iteration; should be >= 1", __FILE__, __LINE__); - if (pTMed < 0.0) throw IllegalArgumentException("med res.: threshold must be > 0", __FILE__, __LINE__); - if (pTMed >= pTLow) throw IllegalArgumentException("threshold for med res. must be < threshold for low res.", __FILE__, __LINE__); - if (pRadius <= med_float(0.0)) throw IllegalArgumentException("radius should be > 0", __FILE__, __LINE__); - if ((pBoxing < 1) || (pBoxing > 200)) throw IllegalArgumentException("boxing should be in [1..200]", __FILE__, __LINE__); - - //--------------------------------------------------------------------- - // Find the MED file corresponding to the given part - //--------------------------------------------------------------------- - MeshDisPart* part = findPart(pPartName); - if (part == NULL) - { - throw IllegalArgumentException("part not found in the given distributed MED file", __FILE__, __LINE__); - } - - //--------------------------------------------------------------------- - // Load the associated sequential MED file - //--------------------------------------------------------------------- - if (part->mMesh == NULL) - { - part->readMED(); - } - - Mesh* meshFull = part->mMesh; - cout << (*meshFull) << endl; - - const char* originalFilename = part->getMEDFileName(); - string strPrefix = removeExtension(originalFilename, ".med"); - - // debug - //cout << (*this) << endl; - - //--------------------------------------------------------------------- - // Decimates the given mesh - //--------------------------------------------------------------------- - // arguments for decimation are passed as a string for genericity - char argv[256]; - char newPartName[MED_TAILLE_NOM + 1]; - char newMEDFileName[256]; - - // *** create a new mesh = MEDIUM resolution *** - sprintf(argv, "%s %d %lf %lf %d", pFieldName, pFieldIt, pTMed, pRadius, pBoxing); - sprintf(newPartName, "%s_MED", pPartName); - sprintf(newMEDFileName, "%s_gradmoy-med-%s-%s.med", - strPrefix.c_str(), - realToString(pTMed).c_str(), - realToString(pRadius).c_str()); - - { - Mesh* meshMedium = meshFull->decimate(pFilterName, argv, part->getMeshName()); - cout << (*meshMedium) << endl; - - insertMesh( - MeshDisPart::MULTIPR_WRITE_MESH, - part->getMeshName(), - part->mId + 1, - newPartName, - "localhost", - newMEDFileName, - meshMedium, - part->mId + 0); - } - - // *** create a new mesh = LOW resolution *** - sprintf(argv, "%s %d %lf %lf %d", pFieldName, pFieldIt, pTLow, pRadius, pBoxing); - sprintf(newPartName, "%s_LOW", pPartName); - sprintf(newMEDFileName, "%s_gradmoy-low-%s-%s.med", - strPrefix.c_str(), - realToString(pTLow).c_str(), - realToString(pRadius).c_str()); - - { - Mesh* meshLow = meshFull->decimate(pFilterName, argv, part->getMeshName()); - cout << (*meshLow) << endl; - - insertMesh( - MeshDisPart::MULTIPR_WRITE_MESH, - part->getMeshName(), - part->mId + 2, - newPartName, - "localhost", - newMEDFileName, - meshLow, - part->mId + 1); - } - - // debug - //cout << (*this) << endl; + //--------------------------------------------------------------------- + // Check arguments + //--------------------------------------------------------------------- + if (pPartName == NULL) throw NullArgumentException("partname should not be NULL", __FILE__, __LINE__); + if (pFieldName == NULL) throw NullArgumentException("fieldname should not be NULL", __FILE__, __LINE__); + if (pFieldIt < med_int(1)) throw IllegalArgumentException("invalid field iteration; should be >= 1", __FILE__, __LINE__); + if (pTMed < 0.0) throw IllegalArgumentException("med res.: threshold must be > 0", __FILE__, __LINE__); + if (pTMed >= pTLow) throw IllegalArgumentException("threshold for med res. must be < threshold for low res.", __FILE__, __LINE__); + if (pRadius <= med_float(0.0)) throw IllegalArgumentException("radius should be > 0", __FILE__, __LINE__); + if ((pBoxing < 1) || (pBoxing > 200)) throw IllegalArgumentException("boxing should be in [1..200]", __FILE__, __LINE__); + + //--------------------------------------------------------------------- + // Find the MED file corresponding to the given part + //--------------------------------------------------------------------- + MeshDisPart* part = findPart(pPartName); + if (part == NULL) + { + throw IllegalArgumentException("part not found in the given distributed MED file", __FILE__, __LINE__); + } + + //--------------------------------------------------------------------- + // Load the associated sequential MED file + //--------------------------------------------------------------------- + if (part->mMesh == NULL) + { + part->readMED(); + } + + Mesh* meshFull = part->mMesh; + cout << (*meshFull) << endl; + + const char* originalFilename = part->getMEDFileName(); + string strPrefix = removeExtension(originalFilename, ".med"); + + // debug + //cout << (*this) << endl; + + //--------------------------------------------------------------------- + // Decimates the given mesh + //--------------------------------------------------------------------- + // arguments for decimation are passed as a string for genericity + char argv[256]; + char newPartName[MED_TAILLE_NOM + 1]; + char newMEDFileName[256]; + + // *** create a new mesh = MEDIUM resolution *** + sprintf(argv, "%s %d %lf %lf %d", pFieldName, pFieldIt, pTMed, pRadius, pBoxing); + sprintf(newPartName, "%s_MED", pPartName); + sprintf(newMEDFileName, "%s_gradmoy-med-%s-%s.med", + strPrefix.c_str(), + realToString(pTMed).c_str(), + realToString(pRadius).c_str()); + + { + Mesh* meshMedium = meshFull->decimate(pFilterName, argv, part->getMeshName()); + cout << (*meshMedium) << endl; + + insertMesh( + MeshDisPart::MULTIPR_WRITE_MESH, + part->getMeshName(), + part->mId + 1, + newPartName, + "localhost", + newMEDFileName, + meshMedium, + part->mId + 0); + + if ((meshMedium->getNumberOfElements() == 0) && (gEmptyMeshCallback != NULL)) + { + gEmptyMeshCallback->reportEmptyMesh(newPartName); + } + } + + // *** create a new mesh = LOW resolution *** + sprintf(argv, "%s %d %lf %lf %d", pFieldName, pFieldIt, pTLow, pRadius, pBoxing); + sprintf(newPartName, "%s_LOW", pPartName); + sprintf(newMEDFileName, "%s_gradmoy-low-%s-%s.med", + strPrefix.c_str(), + realToString(pTLow).c_str(), + realToString(pRadius).c_str()); + + { + Mesh* meshLow = meshFull->decimate(pFilterName, argv, part->getMeshName()); + cout << (*meshLow) << endl; + + insertMesh( + MeshDisPart::MULTIPR_WRITE_MESH, + part->getMeshName(), + part->mId + 2, + newPartName, + "localhost", + newMEDFileName, + meshLow, + part->mId + 1); + + if ((meshLow->getNumberOfElements() == 0) && (gEmptyMeshCallback != NULL)) + { + gEmptyMeshCallback->reportEmptyMesh(newPartName); + } + } + + // debug + //cout << (*this) << endl; } string MeshDis::evalDecimationParams( - const char* pPartName, - const char* pFieldName, - int pFieldIt, - const char* pFilterName, - const char* pFilterParams) + const char* pPartName, + const char* pFieldName, + int pFieldIt, + const char* pFilterName, + const char* pFilterParams) { - MeshDisPart* part = findPart(pPartName); - if (part == NULL) - { - return ""; - } - - try - { - if (part->mMesh == NULL) - { - part->readMED(); - } - - multipr::DecimationFilter* filter = multipr::DecimationFilter::create(pFilterName); - if (filter == NULL) - { - return ""; - } - - multipr::DecimationFilterGradAvg* filterGrad = dynamic_cast(filter); - - if (filterGrad != NULL) - { - int mode; - - int ret = sscanf(pFilterParams, "%d", &mode); - - // mode 2 = GET RADIUS - if ((ret == 1) && (mode == 2)) - { - double radius = part->mMesh->evalDefaultRadius(8); - char res[256]; - sprintf(res, "%f", radius); - return res; - } - - float radius; - int boxing; - - ret = sscanf(pFilterParams, "%d %f %d", &mode, &radius, &boxing); - - // mode 1 = GET GRADIENT MIN, MAX and AVG - if ((ret == 3) && (mode == 1)) - { - double gradMin = 0.1, gradAvg = 0.15, gradMax = 0.2; - - filterGrad->getGradientInfo( - part->mMesh, - pFieldName, - pFieldIt, - radius, - boxing, - &gradMin, - &gradAvg, - &gradMax); - - char res[2048]; - sprintf(res, "%f %f %f", gradMin, gradAvg, gradMax); - return res; - } - } - - delete filter; - } - catch(...) - { - } - - return ""; + MeshDisPart* part = findPart(pPartName); + if (part == NULL) + { + return ""; + } + + try + { + if (part->mMesh == NULL) + { + part->readMED(); + } + + multipr::DecimationFilter* filter = multipr::DecimationFilter::create(pFilterName); + if (filter == NULL) + { + return ""; + } + + multipr::DecimationFilterGradAvg* filterGrad = dynamic_cast(filter); + + if (filterGrad != NULL) + { + int mode; + + int ret = sscanf(pFilterParams, "%d", &mode); + + // mode 2 = GET RADIUS + if ((ret == 1) && (mode == 2)) + { + double radius = part->mMesh->evalDefaultRadius(8); + char res[256]; + sprintf(res, "%f", radius); + return res; + } + + float radius; + int boxing; + + ret = sscanf(pFilterParams, "%d %f %d", &mode, &radius, &boxing); + + // mode 1 = GET GRADIENT MIN, MAX and AVG + if ((ret == 3) && (mode == 1)) + { + double gradMin = 0.1, gradAvg = 0.15, gradMax = 0.2; + + filterGrad->getGradientInfo( + part->mMesh, + pFieldName, + pFieldIt, + radius, + boxing, + &gradMin, + &gradAvg, + &gradMax); + + char res[2048]; + sprintf(res, "%f %f %f", gradMin, gradAvg, gradMax); + return res; + } + } + + delete filter; + } + catch(...) + { + } + + return ""; } int MeshDis::computeNumParts() { - int numParts = 0; - - for (unsigned itPart = 0 ; itPart < mParts.size() ; itPart++) - { - switch (mParts[itPart]->mToDoOnNextWrite) - { - case MeshDisPart::MULTIPR_KEEP_AS_IT: - case MeshDisPart::MULTIPR_WRITE_MESH: - numParts++; - break; - - case MeshDisPart::MULTIPR_WRITE_PARTS: - numParts += mParts[itPart]->mSplit; - break; - - default: throw IllegalStateException("", __FILE__, __LINE__); - } - } - - return numParts; + int numParts = 0; + + for (unsigned itPart = 0 ; itPart < mParts.size() ; itPart++) + { + switch (mParts[itPart]->mToDoOnNextWrite) + { + case MeshDisPart::MULTIPR_KEEP_AS_IT: + case MeshDisPart::MULTIPR_WRITE_MESH: + numParts++; + break; + + case MeshDisPart::MULTIPR_WRITE_PARTS: + numParts += mParts[itPart]->mSplit; + break; + + default: throw IllegalStateException("", __FILE__, __LINE__); + } + } + + return numParts; } void MeshDis::readDistributedMED(const char* pMEDfilename) { - //cout << "DBG: readDistributedMED" << endl; - if (pMEDfilename == NULL) throw NullArgumentException("filename should not be NULL", __FILE__, __LINE__); - - const int MAX_SIZEOF_LINE = 1024; - - reset(); - strcpy(mMEDfilename, pMEDfilename); - - //--------------------------------------------------------------------- - // Open master file (ASCII file) - //--------------------------------------------------------------------- - ifstream fileMaster(mMEDfilename); - if (fileMaster.fail()) throw IOException("i/o error while opening MED master file", __FILE__, __LINE__); - - //cout << "DBG: readDistributedMED: open" << endl; - - //--------------------------------------------------------------------- - // Read header - //--------------------------------------------------------------------- - char charbuffer[MAX_SIZEOF_LINE]; - fileMaster.getline(charbuffer, MAX_SIZEOF_LINE); - if (fileMaster.fail()) throw IOException("i/o error while reading MED master file", __FILE__, __LINE__); - - // check format - if ((charbuffer[0] != '#') || - (charbuffer[1] != ' ') || - (charbuffer[2] != 'M') || - (charbuffer[3] != 'E') || - (charbuffer[4] != 'D')) - throw IOException("not a valid distributed MED file", __FILE__, __LINE__); - - while ((charbuffer[0] == '#') || (strlen(charbuffer) == 0)) - { - fileMaster.getline(charbuffer, MAX_SIZEOF_LINE); - if (fileMaster.fail()) throw IOException("i/o error while reading MED master file", __FILE__, __LINE__); - } - - // read number of parts - int nbParts = atoi(charbuffer); - //cout << "readDistributedMED: #parts=" << nbParts << endl; - - //--------------------------------------------------------------------- - // Read infos about sub-parts - //--------------------------------------------------------------------- - char lMeshName[MED_TAILLE_NOM + 1]; - int lId; - char lPartName[MED_TAILLE_NOM + 1]; - char lPath[256]; - char lMEDFileName[256]; - - for (int i = 0 ; i < nbParts ; i++) - { - fileMaster.getline(charbuffer, MAX_SIZEOF_LINE); - if (fileMaster.fail()) throw IOException("i/o error while reading MED master file", __FILE__, __LINE__); - - while ((charbuffer[0] == '#') || (strlen(charbuffer) == 0)) - { - fileMaster.getline(charbuffer, MAX_SIZEOF_LINE); - if (fileMaster.fail()) throw IOException("i/o error while reading MED master file", __FILE__, __LINE__); - } - - lMeshName[0] = '\0'; - lId = 0; - lPartName[0] = '\0'; - lPath[0] = '\0'; - lMEDFileName[0] = '\0'; - - int ret = sscanf(charbuffer, "%s %d %s %s %s", - lMeshName, - &lId, - lPartName, - lPath, - lMEDFileName); - - if (ret != 5) throw IOException("i/o error while reading MED master file; bad format", __FILE__, __LINE__); - - //cout << "DBG: read: " << lMeshName << " " << lId << " " << lPartName << endl; - addMesh( - MeshDisPart::MULTIPR_KEEP_AS_IT, - lMeshName, - lId, - lPartName, - lPath, - lMEDFileName, - NULL); - } - - //--------------------------------------------------------------------- - // Close master file - //--------------------------------------------------------------------- - fileMaster.close(); - if (fileMaster.fail()) throw IOException("i/o error while closing MED master file", __FILE__, __LINE__); + if (pMEDfilename == NULL) throw NullArgumentException("filename should not be NULL", __FILE__, __LINE__); + + const int MAX_SIZEOF_LINE = 1024; + + reset(); + strcpy(mDistributedMEDFilename, pMEDfilename); + + //--------------------------------------------------------------------- + // Open master file (ASCII file) + //--------------------------------------------------------------------- + ifstream fileMaster(mDistributedMEDFilename); + if (fileMaster.fail()) throw IOException("i/o error while opening MED master file", __FILE__, __LINE__); + + //--------------------------------------------------------------------- + // Read header + //--------------------------------------------------------------------- + char charbuffer[MAX_SIZEOF_LINE]; + fileMaster.getline(charbuffer, MAX_SIZEOF_LINE); + if (fileMaster.fail()) throw IOException("i/o error while reading MED master file", __FILE__, __LINE__); + + // check format + if ((charbuffer[0] != '#') || + (charbuffer[1] != ' ') || + (charbuffer[2] != 'M') || + (charbuffer[3] != 'E') || + (charbuffer[4] != 'D')) + throw IOException("not a valid distributed MED file", __FILE__, __LINE__); + + while ((charbuffer[0] == '#') || (strlen(charbuffer) == 0)) + { + char* strTag = NULL; + if ((charbuffer[0] == '#') && ((strTag = strstr(charbuffer, "[SOURCE]=")) != NULL)) + { + char strSequentialMEDFilename[256]; + int ret = sscanf(strTag, "[SOURCE]=%s", strSequentialMEDFilename); + if (ret == 1) + { + setSequentialMEDFilename(strSequentialMEDFilename); + } + } + fileMaster.getline(charbuffer, MAX_SIZEOF_LINE); + if (fileMaster.fail()) throw IOException("i/o error while reading MED master file", __FILE__, __LINE__); + } + + // read number of parts + int nbParts = atoi(charbuffer); + + //--------------------------------------------------------------------- + // Read infos about sub-parts + //--------------------------------------------------------------------- + char lMeshName[MED_TAILLE_NOM + 1]; + int lId; + char lPartName[MED_TAILLE_NOM + 1]; + char lPath[256]; + char lMEDFileName[256]; + + for (int i = 0 ; i < nbParts ; i++) + { + fileMaster.getline(charbuffer, MAX_SIZEOF_LINE); + if (fileMaster.fail()) throw IOException("i/o error while reading MED master file", __FILE__, __LINE__); + + while ((charbuffer[0] == '#') || (strlen(charbuffer) == 0)) + { + fileMaster.getline(charbuffer, MAX_SIZEOF_LINE); + if (fileMaster.fail()) throw IOException("i/o error while reading MED master file", __FILE__, __LINE__); + } + + lMeshName[0] = '\0'; + lId = 0; + lPartName[0] = '\0'; + lPath[0] = '\0'; + lMEDFileName[0] = '\0'; + + int ret = sscanf(charbuffer, "%s %d %s %s %s", + lMeshName, + &lId, + lPartName, + lPath, + lMEDFileName); + + if (ret != 5) throw IOException("i/o error while reading MED master file; bad format", __FILE__, __LINE__); + + //cout << "DBG: read: " << lMeshName << " " << lId << " " << lPartName << endl; + addMesh( + MeshDisPart::MULTIPR_KEEP_AS_IT, + lMeshName, + lId, + lPartName, + lPath, + lMEDFileName, + NULL); + } + + //--------------------------------------------------------------------- + // Close master file + //--------------------------------------------------------------------- + fileMaster.close(); + if (fileMaster.fail()) throw IOException("i/o error while closing MED master file", __FILE__, __LINE__); } @@ -826,218 +853,219 @@ void MeshDis::readDistributedMED(const char* pMEDfilename) */ int convertMedsplitterToMultipr(ofstream& pFileMaster, const char* pTmpFilename, int pId, MeshDisPart* pPart, string pDestPath) { - MULTIPR_LOG("convert" << endl); - - const int MAX_SIZEOF_LINE = 1024; - char charbuffer[MAX_SIZEOF_LINE]; - - // Open medsplitter master file (ASCII file) - ifstream fileMasterMedsplitter(pTmpFilename); - if (fileMasterMedsplitter.fail()) throw IOException("i/o error while opening MEDSPLITTER master file", __FILE__, __LINE__); - - fileMasterMedsplitter.getline(charbuffer, MAX_SIZEOF_LINE); - if (fileMasterMedsplitter.fail()) throw IOException("i/o error while reading MEDSPLITTER master file", __FILE__, __LINE__); - - while ((charbuffer[0] == '#') || (strlen(charbuffer) == 0)) - { - fileMasterMedsplitter.getline(charbuffer, MAX_SIZEOF_LINE); - if (fileMasterMedsplitter.fail()) throw IOException("i/o error while reading MEDSPLITTER master file", __FILE__, __LINE__); - } - - // read number of parts - int nbParts = atoi(charbuffer); - //cout << "nb parts=" << nbParts << endl; - - char lMeshName[MED_TAILLE_NOM + 1]; - int lId; - char lPartName[MED_TAILLE_NOM + 1]; - char lPath[256]; - char lMEDFileName[256]; - - for (int i = 0 ; i < nbParts ; i++) - { - fileMasterMedsplitter.getline(charbuffer, MAX_SIZEOF_LINE); - if (fileMasterMedsplitter.fail()) throw IOException("", __FILE__, __LINE__); - - // parses the current line - lMeshName[0] = '\0'; - lId = 0; - lPartName[0] = '\0'; - lPath[0] = '\0'; - lMEDFileName[0] = '\0'; - - int ret = sscanf(charbuffer, "%s %d %s %s %s", - lMeshName, - &lId, - lPartName, - lPath, - lMEDFileName); - - if (ret != 5) throw IOException("i/o error while reading MEDSPLITTER master file; bad format", __FILE__, __LINE__); - - //cout << lMeshName << " " << (pId + i) << " " << pPart->getPartName() << "_" << (i + 1) << " " << lPath << " " << lMEDFileName << endl; - - string strDestFilename = pDestPath + multipr::getFilenameWithoutPath(lMEDFileName); - if (strcmp(lMEDFileName, strDestFilename.c_str()) != 0) - { - multipr::copyFile(lMEDFileName, pDestPath.c_str()); - strcpy(lMEDFileName, strDestFilename.c_str()); - } - - pFileMaster << lMeshName << " " << (pId + i) << " " << pPart->getPartName() << "_" << (i + 1) << " " << lPath << " " << lMEDFileName << endl; - } - - fileMasterMedsplitter.close(); - if (fileMasterMedsplitter.fail()) throw IOException("i/o error while closing MEDSPLITTER master file", __FILE__, __LINE__); - - // remove master file generated by MEDSPLITTER - remove(pTmpFilename); - - return nbParts; + MULTIPR_LOG("convert" << endl); + + const int MAX_SIZEOF_LINE = 1024; + char charbuffer[MAX_SIZEOF_LINE]; + + // Open medsplitter master file (ASCII file) + ifstream fileMasterMedsplitter(pTmpFilename); + if (fileMasterMedsplitter.fail()) throw IOException("i/o error while opening MEDSPLITTER master file", __FILE__, __LINE__); + + fileMasterMedsplitter.getline(charbuffer, MAX_SIZEOF_LINE); + if (fileMasterMedsplitter.fail()) throw IOException("i/o error while reading MEDSPLITTER master file", __FILE__, __LINE__); + + while ((charbuffer[0] == '#') || (strlen(charbuffer) == 0)) + { + fileMasterMedsplitter.getline(charbuffer, MAX_SIZEOF_LINE); + if (fileMasterMedsplitter.fail()) throw IOException("i/o error while reading MEDSPLITTER master file", __FILE__, __LINE__); + } + + // read number of parts + int nbParts = atoi(charbuffer); + //cout << "nb parts=" << nbParts << endl; + + char lMeshName[MED_TAILLE_NOM + 1]; + int lId; + char lPartName[MED_TAILLE_NOM + 1]; + char lPath[256]; + char lMEDFileName[256]; + + for (int i = 0 ; i < nbParts ; i++) + { + fileMasterMedsplitter.getline(charbuffer, MAX_SIZEOF_LINE); + if (fileMasterMedsplitter.fail()) throw IOException("", __FILE__, __LINE__); + + // parses the current line + lMeshName[0] = '\0'; + lId = 0; + lPartName[0] = '\0'; + lPath[0] = '\0'; + lMEDFileName[0] = '\0'; + + int ret = sscanf(charbuffer, "%s %d %s %s %s", + lMeshName, + &lId, + lPartName, + lPath, + lMEDFileName); + + if (ret != 5) throw IOException("i/o error while reading MEDSPLITTER master file; bad format", __FILE__, __LINE__); + + string strDestFilename = pDestPath + multipr::getFilenameWithoutPath(lMEDFileName); + if (strcmp(lMEDFileName, strDestFilename.c_str()) != 0) + { + multipr::copyFile(lMEDFileName, pDestPath.c_str()); + strcpy(lMEDFileName, strDestFilename.c_str()); + } + + pFileMaster << lMeshName << " " << (pId + i) << " " << pPart->getPartName() << "_" << (i + 1) << " " << lPath << " " << lMEDFileName << endl; + } + + fileMasterMedsplitter.close(); + if (fileMasterMedsplitter.fail()) throw IOException("i/o error while closing MEDSPLITTER master file", __FILE__, __LINE__); + + // remove master file generated by MEDSPLITTER + remove(pTmpFilename); + + return nbParts; } void MeshDis::writeDistributedMED(const char* pMEDfilenamePrefix) { - if (pMEDfilenamePrefix == NULL) throw NullArgumentException("", __FILE__, __LINE__); - - //--------------------------------------------------------------------- - // Build master filename - //--------------------------------------------------------------------- - string strPrefix = string(pMEDfilenamePrefix); - const char* strExtension = ".med"; - string strMasterFilename; - - // add suffix "_grains_maitre" iff it is not yet in the filename - if (strstr(pMEDfilenamePrefix, "_grains_maitre") == 0) - { - strMasterFilename= strPrefix + "_grains_maitre" + strExtension; - } - else - { - strMasterFilename = strPrefix + strExtension; - } - - string strDestPath = multipr::getPath(strMasterFilename.c_str()); - - MULTIPR_LOG("Create master: " << strMasterFilename << endl); - strcpy(mMEDfilename, strMasterFilename.c_str()); - - //--------------------------------------------------------------------- - // Create an ASCII master file for the resulting distributed mesh and write header - //--------------------------------------------------------------------- - remove(strMasterFilename.c_str()); - ofstream fileMaster(strMasterFilename.c_str()); - - if (fileMaster == 0) throw IOException("i/o error while creating MED master file", __FILE__, __LINE__); - - fileMaster << "# MED file v2.3 - Master file created by MULTIPR v" << getVersion() << endl; - fileMaster << "#" << " " << endl; - - fileMaster << computeNumParts() << endl; - if (fileMaster.fail()) throw IOException("i/o error while writing MED master file", __FILE__, __LINE__); - - //--------------------------------------------------------------------- - // Create a new MED file (v2.3) - //--------------------------------------------------------------------- - int id = 1; - - if (gProgressCallback != NULL) gProgressCallback->start("Save mesh", mParts.size()); - - try - { - - // for each sub-meshes - for (unsigned itPart = 0 ; itPart < mParts.size() ; itPart++) - { - switch (mParts[itPart]->mToDoOnNextWrite) - { - case MeshDisPart::MULTIPR_KEEP_AS_IT: - { - mParts[itPart]->mId = id; - id++; - - // copy file in another directory? - string strSrcPath = multipr::getPath(mParts[itPart]->getMEDFileName()); - if (strSrcPath != strDestPath) - { - cout << "Write: KEEP_AS_IT: copy file" << endl; - string strDestFilename = strDestPath + multipr::getFilenameWithoutPath(mParts[itPart]->getMEDFileName()); - multipr::copyFile(mParts[itPart]->getMEDFileName(), strDestPath.c_str()); - strcpy(mParts[itPart]->mMEDFileName, strDestFilename.c_str()); - } - - fileMaster << (*mParts[itPart]) << endl; - cout << (*mParts[itPart]) << endl; - break; - } - - case MeshDisPart::MULTIPR_WRITE_MESH: - { - if (strlen(mParts[itPart]->getMEDFileName()) == 0) throw IOException("MED filename is empty", __FILE__, __LINE__); - if (mParts[itPart]->mMesh == NULL) throw IllegalStateException("invalid mesh (shoult not be NULL)", __FILE__, __LINE__); - - string strDestFilename = strDestPath + multipr::getFilenameWithoutPath(mParts[itPart]->getMEDFileName()); - strcpy(mParts[itPart]->mMEDFileName, strDestFilename.c_str()); - - mParts[itPart]->mMesh->writeMED(mParts[itPart]->getMEDFileName()); - mParts[itPart]->mId = id; - id++; - fileMaster << (*mParts[itPart]) << endl; - cout << (*mParts[itPart]) << endl; - break; - } - - case MeshDisPart::MULTIPR_WRITE_PARTS: - { - // split this part using medsplitter - if (mParts[itPart]->mOldCollection == NULL) throw IllegalStateException("", __FILE__, __LINE__); - string strPrefix = removeExtension(mParts[itPart]->getMEDFileName(), ".med"); - char tmpFilename[256]; - sprintf(tmpFilename, "%s_part", strPrefix.c_str()); - mParts[itPart]->mCollection->write(tmpFilename); - mParts[itPart]->mCollection->castAllFields(*(mParts[itPart]->mOldCollection)); - int ret = convertMedsplitterToMultipr(fileMaster, tmpFilename, id, mParts[itPart], strDestPath); - id += ret; - remove(mParts[itPart]->getMEDFileName()); - break; - } - - default: throw IllegalStateException("should not be there", __FILE__, __LINE__); - } - - if (gProgressCallback != NULL) gProgressCallback->moveOn(); - } - - } - catch (RuntimeException& e) - { - if (gProgressCallback != NULL) gProgressCallback->done(); - throw e; - } - - if (gProgressCallback != NULL) gProgressCallback->done(); - - //--------------------------------------------------------------------- - // Close master file - //--------------------------------------------------------------------- - fileMaster.close(); - if (fileMaster.fail()) throw IOException("i/o error while closing MED master file", __FILE__, __LINE__); + if (pMEDfilenamePrefix == NULL) throw NullArgumentException("", __FILE__, __LINE__); + + //--------------------------------------------------------------------- + // Build master filename + //--------------------------------------------------------------------- + string strPrefix = string(pMEDfilenamePrefix); + const char* strExtension = ".med"; + string strMasterFilename; + + // add suffix "_grains_maitre" iff it is not yet in the filename + if (strstr(pMEDfilenamePrefix, "_grains_maitre") == 0) + { + strMasterFilename= strPrefix + "_grains_maitre" + strExtension; + } + else + { + strMasterFilename = strPrefix + strExtension; + } + + string strDestPath = multipr::getPath(strMasterFilename.c_str()); + + MULTIPR_LOG("Create master: " << strMasterFilename << endl); + strcpy(mDistributedMEDFilename, strMasterFilename.c_str()); + + //--------------------------------------------------------------------- + // Create an ASCII master file for the resulting distributed mesh and write header + //--------------------------------------------------------------------- + remove(strMasterFilename.c_str()); + ofstream fileMaster(strMasterFilename.c_str()); + + if (fileMaster == 0) throw IOException("i/o error while creating MED master file", __FILE__, __LINE__); + + fileMaster << "# MED file v2.3 - Master file created by MULTIPR v" << getVersion() << endl; + fileMaster << "#" << " " << endl; + fileMaster << "# [SOURCE]=" << mSequentialMEDFilename << endl; + fileMaster << "#" << " " << endl; + + fileMaster << computeNumParts() << endl; + if (fileMaster.fail()) throw IOException("i/o error while writing MED master file", __FILE__, __LINE__); + + //--------------------------------------------------------------------- + // Create a new MED file (v2.3) + //--------------------------------------------------------------------- + int id = 1; + + if (gProgressCallback != NULL) gProgressCallback->start("Save mesh", mParts.size()); + + try + { + + // for each sub-meshes + for (unsigned itPart = 0 ; itPart < mParts.size() ; itPart++) + { + switch (mParts[itPart]->mToDoOnNextWrite) + { + case MeshDisPart::MULTIPR_KEEP_AS_IT: + { + mParts[itPart]->mId = id; + id++; + + // copy file in another directory? + string strSrcPath = multipr::getPath(mParts[itPart]->getMEDFileName()); + if (strSrcPath != strDestPath) + { + cout << "Write: KEEP_AS_IT: copy file" << endl; + string strDestFilename = strDestPath + multipr::getFilenameWithoutPath(mParts[itPart]->getMEDFileName()); + multipr::copyFile(mParts[itPart]->getMEDFileName(), strDestPath.c_str()); + strcpy(mParts[itPart]->mMEDFileName, strDestFilename.c_str()); + } + + fileMaster << (*mParts[itPart]) << endl; + cout << (*mParts[itPart]) << endl; + break; + } + + case MeshDisPart::MULTIPR_WRITE_MESH: + { + if (strlen(mParts[itPart]->getMEDFileName()) == 0) throw IOException("MED filename is empty", __FILE__, __LINE__); + if (mParts[itPart]->mMesh == NULL) throw IllegalStateException("invalid mesh (shoult not be NULL)", __FILE__, __LINE__); + + string strDestFilename = strDestPath + multipr::getFilenameWithoutPath(mParts[itPart]->getMEDFileName()); + strcpy(mParts[itPart]->mMEDFileName, strDestFilename.c_str()); + + mParts[itPart]->mMesh->writeMED(mParts[itPart]->getMEDFileName()); + mParts[itPart]->mId = id; + id++; + fileMaster << (*mParts[itPart]) << endl; + cout << (*mParts[itPart]) << endl; + break; + } + + case MeshDisPart::MULTIPR_WRITE_PARTS: + { + // split this part using medsplitter + if (mParts[itPart]->mOldCollection == NULL) throw IllegalStateException("", __FILE__, __LINE__); + string strPrefix = removeExtension(mParts[itPart]->getMEDFileName(), ".med"); + char tmpFilename[256]; + sprintf(tmpFilename, "%s_part", strPrefix.c_str()); + mParts[itPart]->mCollection->write(tmpFilename); + mParts[itPart]->mCollection->castAllFields(*(mParts[itPart]->mOldCollection)); + int ret = convertMedsplitterToMultipr(fileMaster, tmpFilename, id, mParts[itPart], strDestPath); + id += ret; + remove(mParts[itPart]->getMEDFileName()); + break; + } + + default: throw IllegalStateException("should not be there", __FILE__, __LINE__); + } + + if (gProgressCallback != NULL) gProgressCallback->moveOn(); + } + + } + catch (RuntimeException& e) + { + if (gProgressCallback != NULL) gProgressCallback->done(); + throw e; + } + + if (gProgressCallback != NULL) gProgressCallback->done(); + + //--------------------------------------------------------------------- + // Close master file + //--------------------------------------------------------------------- + fileMaster.close(); + if (fileMaster.fail()) throw IOException("i/o error while closing MED master file", __FILE__, __LINE__); } ostream& operator<<(ostream& pOs, MeshDis& pM) { - pOs << "Mesh Dis.:" << endl; - pOs << " Filename =|" << pM.mMEDfilename << "|" << endl; - pOs << " #Sub-meshes=" << pM.mParts.size() << endl; - - for (unsigned itPart = 0 ; itPart < pM.mParts.size() ; itPart++) - { - cout << " " << (itPart + 1) << ": " << (*(pM.mParts[itPart])) << endl; - } - - return pOs; + pOs << "Mesh Dis.:" << endl; + pOs << " Sequential filename (source) =|" << pM.mSequentialMEDFilename << "|" << endl; + pOs << " Distributed filename (master)=|" << pM.mDistributedMEDFilename << "|" << endl; + pOs << " #Sub-meshes =" << pM.mParts.size() << endl; + + for (unsigned itPart = 0 ; itPart < pM.mParts.size() ; itPart++) + { + cout << " " << (itPart + 1) << ": " << (*(pM.mParts[itPart])) << endl; + } + + return pOs; } diff --git a/src/MULTIPR/MULTIPR_MeshDis.hxx b/src/MULTIPR/MULTIPR_MeshDis.hxx index da4abf4..81b6b4d 100644 --- a/src/MULTIPR/MULTIPR_MeshDis.hxx +++ b/src/MULTIPR/MULTIPR_MeshDis.hxx @@ -21,7 +21,7 @@ extern "C" { - #include "med.h" + #include "med.h" } #include @@ -60,154 +60,154 @@ class MeshDisPart public: - /** - * Action to be done for this part on next writing on disk. - */ - enum OnNextWrite - { - MULTIPR_UNDEFINED, - MULTIPR_KEEP_AS_IT, - MULTIPR_WRITE_MESH, - MULTIPR_WRITE_PARTS - }; - + /** + * Action to be done for this part on next writing on disk. + */ + enum OnNextWrite + { + MULTIPR_UNDEFINED, + MULTIPR_KEEP_AS_IT, + MULTIPR_WRITE_MESH, + MULTIPR_WRITE_PARTS + }; + public: - /** - * Builds an empty part of a distributed mesh (default constructor). - */ - MeshDisPart(); - - /** - * Destructor. Removes everything. - */ - ~MeshDisPart(); - - /** - * Resets this object in its state by default (empty). Cleans memory. - */ - void reset(); - - /** - * Creates a MeshDisPart. - * \param pToDoOnNextWrite - * \param pMeshName - * \param pId - * \param pPartName - * \param pPath - * \param pMEDFileName file name excluding the path. - * \param pMesh can be NULL. - */ - void create( - OnNextWrite pToDoOnNextWrite, - const char* pMeshName, - int pId, - const char* pPartName, - const char* pPath, - const char* pMEDFileName, - Mesh* pMesh); - - //--------------------------------------------------------------------- - // Basic accessors/mutators - //--------------------------------------------------------------------- - - /** - * Returns the name of this part. - * \return the name of this part. - */ - const char* getPartName() const { return mPartName; } - - /** - * Returns the name of the mesh of this part. - * \return the name of the mesh of this part. - */ - const char* getMeshName() const { return mMeshName; } - - /** - * Returns the MED filename which contain this part. - * \return the MED filename which contain this part. - */ - const char* getMEDFileName() const { return mMEDFileName; } - - /** - * Returns the suffix of the related MED filename (without .med extension). - * For examples: - * 1. "agregat100grains_12pas_grain97.med" -> "grain97" - * 2. "agregat100grains_12pas_grain100_part2.med" -> "grain100_part2" - * 3. "aagregat100grains_12pas_grain98_gradmoy-low-25.0-0.3.med" -> "grain98_gradmoy-low-25-0.3" - */ - const char* getMEDFileNameSuffix() const; - - /** - * Returns the action to be performed on this part on next write. - * \return the action to be performed on this part on next write. - */ - OnNextWrite getOnNextWrite() const { return mToDoOnNextWrite; } - - //--------------------------------------------------------------------- - // I/O - //--------------------------------------------------------------------- - - /** - * Reads the sequentiel MED file corresponding to this part. - * \throw IOException if an i/o error occurs. - */ - void readMED(); - - /** - * Dumps any MeshDisPart to the given output stream. - * \param pOs any output stream. - * \param pM any MeshDisPart. - * \return the output stream pOs. - */ - friend std::ostream& operator<<(std::ostream& pOs, MeshDisPart& pM); - + /** + * Builds an empty part of a distributed mesh (default constructor). + */ + MeshDisPart(); + + /** + * Destructor. Removes everything. + */ + ~MeshDisPart(); + + /** + * Resets this object in its state by default (empty). Cleans memory. + */ + void reset(); + + /** + * Creates a MeshDisPart. + * \param pToDoOnNextWrite + * \param pMeshName + * \param pId + * \param pPartName + * \param pPath + * \param pMEDFileName file name excluding the path. + * \param pMesh can be NULL. + */ + void create( + OnNextWrite pToDoOnNextWrite, + const char* pMeshName, + int pId, + const char* pPartName, + const char* pPath, + const char* pMEDFileName, + Mesh* pMesh); + + //--------------------------------------------------------------------- + // Basic accessors/mutators + //--------------------------------------------------------------------- + + /** + * Returns the name of this part. + * \return the name of this part. + */ + const char* getPartName() const { return mPartName; } + + /** + * Returns the name of the mesh of this part. + * \return the name of the mesh of this part. + */ + const char* getMeshName() const { return mMeshName; } + + /** + * Returns the MED filename which contain this part. + * \return the MED filename which contain this part. + */ + const char* getMEDFileName() const { return mMEDFileName; } + + /** + * Returns the suffix of the related MED filename (without .med extension). + * For examples: + * 1. "agregat100grains_12pas_grain97.med" -> "grain97" + * 2. "agregat100grains_12pas_grain100_part2.med" -> "grain100_part2" + * 3. "aagregat100grains_12pas_grain98_gradmoy-low-25.0-0.3.med" -> "grain98_gradmoy-low-25-0.3" + */ + const char* getMEDFileNameSuffix() const; + + /** + * Returns the action to be performed on this part on next write. + * \return the action to be performed on this part on next write. + */ + OnNextWrite getOnNextWrite() const { return mToDoOnNextWrite; } + + //--------------------------------------------------------------------- + // I/O + //--------------------------------------------------------------------- + + /** + * Reads the sequentiel MED file corresponding to this part. + * \throw IOException if an i/o error occurs. + */ + void readMED(); + + /** + * Dumps any MeshDisPart to the given output stream. + * \param pOs any output stream. + * \param pM any MeshDisPart. + * \return the output stream pOs. + */ + friend std::ostream& operator<<(std::ostream& pOs, MeshDisPart& pM); + private: - // MeshDisPart can be used: - // 1 (KEEP_AS_IT) : To store data read from one line of an ASCII master file (distributed MED file) - // 2 (WRITE_MESH) : As a temporary structure to store all infos about a mesh corresponding to a group (before writing on disk). - // 3 (WRITE_PARTS) : As a temporary structure to store all infos about splitting using MEDSPLITTER. - - OnNextWrite mToDoOnNextWrite; /**< See enum OnNextWrite. */ - - //--------------------------------------------------------------------- - // Case 1, 2, and 3 - //--------------------------------------------------------------------- - char mMeshName[MED_TAILLE_NOM + 1]; /**< Name of the mesh. */ - int mId; /**< Id of this part in [1..n]. */ - char mPartName[MED_TAILLE_NOM + 1]; /**< Name of this part. */ - char mPath[256]; /**< Path of the MED file. */ - char mMEDFileName[256]; /**< Name of the MED file which contain this part. */ - - //--------------------------------------------------------------------- - // Case 2: mesh of the related sequential MED file (can be NULL if not loaded) - //--------------------------------------------------------------------- - Mesh* mMesh; /**< Mesh associated with this part; can be NULL. */ - - //--------------------------------------------------------------------- - // Case 3 only: temporary result of MEDSPLITTER - //--------------------------------------------------------------------- - int mSplit; /**< For MEDSPLITTER: number of parts. Temporary. */ - MEDSPLITTER::MESHCollection* mCollection; /**< New data after splitting. */ - MEDSPLITTER::MESHCollection* mOldCollection; /**< Data before splitting (we need them when we want to write new data on disk. */ - + // MeshDisPart can be used: + // 1 (KEEP_AS_IT) : To store data read from one line of an ASCII master file (distributed MED file) + // 2 (WRITE_MESH) : As a temporary structure to store all infos about a mesh corresponding to a group (before writing on disk). + // 3 (WRITE_PARTS) : As a temporary structure to store all infos about splitting using MEDSPLITTER. + + OnNextWrite mToDoOnNextWrite; /**< See enum OnNextWrite. */ + + //--------------------------------------------------------------------- + // Case 1, 2, and 3 + //--------------------------------------------------------------------- + char mMeshName[MED_TAILLE_NOM + 1]; /**< Name of the mesh. */ + int mId; /**< Id of this part in [1..n]. */ + char mPartName[MED_TAILLE_NOM + 1]; /**< Name of this part. */ + char mPath[256]; /**< Path of the MED file. */ + char mMEDFileName[256]; /**< Name of the MED file which contain this part. */ + + //--------------------------------------------------------------------- + // Case 2: mesh of the related sequential MED file (can be NULL if not loaded) + //--------------------------------------------------------------------- + Mesh* mMesh; /**< Mesh associated with this part; can be NULL. */ + + //--------------------------------------------------------------------- + // Case 3 only: temporary result of MEDSPLITTER + //--------------------------------------------------------------------- + int mSplit; /**< For MEDSPLITTER: number of parts. Temporary. */ + MEDSPLITTER::MESHCollection* mCollection; /**< New data after splitting. */ + MEDSPLITTER::MESHCollection* mOldCollection; /**< Data before splitting (we need them when we want to write new data on disk. */ + private: - // do not allow copy constructor - MeshDisPart(const MeshDisPart&); - - // do not allow copy - MeshDisPart& operator=(const MeshDisPart&); - - // do not allow operator == - bool operator==(const MeshDisPart&); - - //--------------------------------------------------------------------- - // Friends - //--------------------------------------------------------------------- - friend class MeshDis; - + // do not allow copy constructor + MeshDisPart(const MeshDisPart&); + + // do not allow copy + MeshDisPart& operator=(const MeshDisPart&); + + // do not allow operator == + bool operator==(const MeshDisPart&); + + //--------------------------------------------------------------------- + // Friends + //--------------------------------------------------------------------- + friend class MeshDis; + }; // class MeshDisPart @@ -219,236 +219,249 @@ class MeshDis { public: - /** - * Builds an empty mesh (default constructor). - */ - MeshDis(); - - /** - * Destructor. Removes everything. - */ - ~MeshDis(); - - /** - * Resets this object in its state by default (empty). Clean memory. - */ - void reset(); - - //--------------------------------------------------------------------- - // Basic accessors/mutators - //--------------------------------------------------------------------- + /** + * Builds an empty mesh (default constructor). + */ + MeshDis(); + + /** + * Destructor. Removes everything. + */ + ~MeshDis(); + + /** + * Resets this object in its state by default (empty). Clean memory. + */ + void reset(); + + //--------------------------------------------------------------------- + // Basic accessors/mutators + //--------------------------------------------------------------------- - /** - * Returns the name of this distributed MED file (=name of the master file). - * \return the name of this distributed MED file (=name of the master file). - */ - const char* getFilename() const { return mMEDfilename; } - - /** - * Adds a new part to this distributed mesh. - * Used by the split process (extract groups). - * \param pToDoOnNextWrite - * \param pMeshName - * \param pId - * \param pPartName - * \param pPath - * \param pMEDFileName - * \param pMesh can be NULL. - */ - void addMesh( - MeshDisPart::OnNextWrite pToDoOnNextWrite, - const char* pMeshName, - int pId, - const char* pPartName, - const char* pPath, - const char* pMEDFileName, - Mesh* pMesh); - - /** - * Inserts a new part to this distributed mesh. - * Used by the decimation process. - * \param pToDoOnNextWrite - * \param pMeshName - * \param pId - * \param pPartName - * \param pPath - * \param pMEDFileName - * \param pMesh can be NULL. - * \param pPosition insert after this position. Start at 1. - */ - void insertMesh( - MeshDisPart::OnNextWrite pToDoOnNextWrite, - const char* pMeshName, - int pId, - const char* pPartName, - const char* pPath, - const char* pMEDFileName, - Mesh* pMesh, - int pPosition); - - /** - * Removes all the part beginning by pPrefixPartName from this distributed mesh. - * Example: if pPrefixPartName="PART_4" => remove "PART_4" and all sub-parts "PART_4_*", but not "PART41". - * \param pPrefixPartName name of the part. - */ - void removeParts(const char* pPrefixPartName); - - /** - * Returns the current number of parts in this distributed mesh. - * \return the current number of parts in this distributed mesh. - */ - int getNumParts() const { return mParts.size(); } - - /** - * Returns the nth part of this distributed mesh. - * \param pIndex index of the part (in 0..getNumParts()-1). - * \return the nth part of this distributed mesh. - */ - MeshDisPart* getPart(int pIndex) const { return mParts[pIndex]; } - - /** - * Returns the list of meshes contained in this distributed MED file. - * \return the list of meshes contained in this distributed MED file. - */ - std::vector getMeshes() const; - - /** - * Returns the list of fields contained in this distributed MED file. - * \return the list of fields contained in this distributed MED file. - */ - std::vector getFields() const; - - /** - * Returns the number of iteration for a given field. - * \param pFieldName field name. - * \return the number of iteration for a given field. - */ - int getTimeStamps(const char* pFieldName) const; - - /** - * Returns all information about a part. - * \param pPartName name of the part. - * \return all information about a part. - */ - std::string getPartInfo(const char* pPartName); - - //--------------------------------------------------------------------- - // Algorithms - //--------------------------------------------------------------------- - - /** - * Finds a part of this distributed mesh by its name. - * Returns NULL if the part does not exist. - * \param pPartName part to be found; must not be NULL. - * \return a pointer towards the part if it exists, NULL otherwise. - * \throw NullArgumentException if pPartName is NULL. - */ - MeshDisPart* findPart(const char* pPartName); - - /** - * Updates this distributed mesh by splitting one of its part. - * This splitting method leans on medsplitter, by V. Bergeaud (CEA). - * \param pPartName name of the part to be splitted. - * \param pNbParts number of sub-parts. - * \param pPartitionner MULTIPR_METIS or MULTIPR_SCOTCH. - * \throw RuntimeException if any error occurs. - */ - void splitPart(const char* pPartName, int pNbParts, int pPartitionner); - - /** - * Creates 3 resolution (CURRENT = FULL, MEDIUM and LOW) of a part of this distributed mesh. - * Names of new meshes are _MED and _LOW. - * \param pPartName - * \param pFielName - * \param pFieldIt - * \param pFilterName - * \param pTMed threshold used to generate MEDIUM resolution. - * \param pTLow threshold used to generate LOW resolution (must be >= pTMed). - * \param pRadius - * \param pBoxing number of cells along each axis; e.g. if 100 then grid will have 100*100*100 = 10**6 cells; 100 by default. - * \throw RuntimeException if any error occurs. - */ - void decimatePart( - const char* pPartName, - const char* pFieldName, - med_int pFieldIt, - const char* pFilterName, - med_float pTMed, - med_float pTLow, - med_float pRadius, - int pBoxing = 100); - - /** - * Returns useful information to configure decimation parameters. - * Depends on part, field and filter: generic operation. - * \param pPartName name of the part. - * \param pFieldName name of the field used for decimation. - * \param pFieldIt iteration (time step) of the field. - * \param pFilterName name of the filter to be used. - * \param pFilterParams params to be used with the filter (depends on filter; this string will be parsed). - * \return - */ - std::string evalDecimationParams( - const char* pPartName, - const char* pFieldName, - int pFieldIt, - const char* pFilterName, - const char* pFilterParams); - - //--------------------------------------------------------------------- - // I/O - //--------------------------------------------------------------------- - - /** - * Reads the master file of a distributed MED file. - * \param pMEDfilename - * \throw NullArgumentException if pMEDfilename is NULL. - * \throw IOException if any i/o error occurs. - */ - void readDistributedMED(const char* pMEDfilename); - - /** - * Writes this distributed MED file (including master file and sub MED files if necessary). - * \param pMEDfilenamePrefix - * \throw NullArgumentException if pMEDfilename is NULL. - * \throw IOException if any i/o error occurs. - */ - void writeDistributedMED(const char* pMEDfilenamePrefix); - - /** - * Dumps any MeshDis to the given output stream. - * \param pOs any output stream. - * \param pM any MeshDis. - * \return the output stream pOs. - */ - friend std::ostream& operator<<(std::ostream& pOs, MeshDis& pM); - + /** + * Sets the name of the associated sequential MED file (=original MED file). + * \param pFilename name of the associated sequential MED file. + */ + void setSequentialMEDFilename(const char* pFilename); + + /** + * Returns the name of this sequential MED file (=original MED file). + * \return the name of this sequential MED file (=original MED file). + */ + const char* getSequentialMEDFilename() const { return mSequentialMEDFilename; } + + /** + * Returns the name of this distributed MED file (=name of the master file). + * \return the name of this distributed MED file (=name of the master file). + */ + const char* getDistributedMEDFilename() const { return mDistributedMEDFilename; } + + /** + * Adds a new part to this distributed mesh. + * Used by the split process (extract groups). + * \param pToDoOnNextWrite + * \param pMeshName + * \param pId + * \param pPartName + * \param pPath + * \param pMEDFileName + * \param pMesh can be NULL. + */ + void addMesh( + MeshDisPart::OnNextWrite pToDoOnNextWrite, + const char* pMeshName, + int pId, + const char* pPartName, + const char* pPath, + const char* pMEDFileName, + Mesh* pMesh); + + /** + * Inserts a new part to this distributed mesh. + * Used by the decimation process. + * \param pToDoOnNextWrite + * \param pMeshName + * \param pId + * \param pPartName + * \param pPath + * \param pMEDFileName + * \param pMesh can be NULL. + * \param pPosition insert after this position. Start at 1. + */ + void insertMesh( + MeshDisPart::OnNextWrite pToDoOnNextWrite, + const char* pMeshName, + int pId, + const char* pPartName, + const char* pPath, + const char* pMEDFileName, + Mesh* pMesh, + int pPosition); + + /** + * Removes all the part beginning by pPrefixPartName from this distributed mesh. + * Example: if pPrefixPartName="PART_4" => remove "PART_4" and all sub-parts "PART_4_*", but not "PART41". + * \param pPrefixPartName name of the part. + */ + void removeParts(const char* pPrefixPartName); + + /** + * Returns the current number of parts in this distributed mesh. + * \return the current number of parts in this distributed mesh. + */ + int getNumParts() const { return mParts.size(); } + + /** + * Returns the nth part of this distributed mesh. + * \param pIndex index of the part (in 0..getNumParts()-1). + * \return the nth part of this distributed mesh. + */ + MeshDisPart* getPart(int pIndex) const { return mParts[pIndex]; } + + /** + * Returns the list of meshes contained in this distributed MED file. + * \return the list of meshes contained in this distributed MED file. + */ + std::vector getMeshes() const; + + /** + * Returns the list of fields contained in this distributed MED file. + * \return the list of fields contained in this distributed MED file. + */ + std::vector getFields() const; + + /** + * Returns the number of iteration for a given field. + * \param pFieldName field name. + * \return the number of iteration for a given field. + */ + int getTimeStamps(const char* pFieldName) const; + + /** + * Returns all information about a part. + * \param pPartName name of the part. + * \return all information about a part. + */ + std::string getPartInfo(const char* pPartName); + + //--------------------------------------------------------------------- + // Algorithms + //--------------------------------------------------------------------- + + /** + * Finds a part of this distributed mesh by its name. + * Returns NULL if the part does not exist. + * \param pPartName part to be found; must not be NULL. + * \return a pointer towards the part if it exists, NULL otherwise. + * \throw NullArgumentException if pPartName is NULL. + */ + MeshDisPart* findPart(const char* pPartName); + + /** + * Updates this distributed mesh by splitting one of its part. + * This splitting method leans on medsplitter, by V. Bergeaud (CEA). + * \param pPartName name of the part to be splitted. + * \param pNbParts number of sub-parts. + * \param pPartitionner MULTIPR_METIS or MULTIPR_SCOTCH. + * \throw RuntimeException if any error occurs. + */ + void splitPart(const char* pPartName, int pNbParts, int pPartitionner); + + /** + * Creates 3 resolution (CURRENT = FULL, MEDIUM and LOW) of a part of this distributed mesh. + * Names of new meshes are _MED and _LOW. + * \param pPartName + * \param pFielName + * \param pFieldIt + * \param pFilterName + * \param pTMed threshold used to generate MEDIUM resolution. + * \param pTLow threshold used to generate LOW resolution (must be >= pTMed). + * \param pRadius + * \param pBoxing number of cells along each axis; e.g. if 100 then grid will have 100*100*100 = 10**6 cells; 100 by default. + * \throw RuntimeException if any error occurs. + */ + void decimatePart( + const char* pPartName, + const char* pFieldName, + med_int pFieldIt, + const char* pFilterName, + med_float pTMed, + med_float pTLow, + med_float pRadius, + int pBoxing = 100); + + /** + * Returns useful information to configure decimation parameters. + * Depends on part, field and filter: generic operation. + * \param pPartName name of the part. + * \param pFieldName name of the field used for decimation. + * \param pFieldIt iteration (time step) of the field. + * \param pFilterName name of the filter to be used. + * \param pFilterParams params to be used with the filter (depends on filter; this string will be parsed). + * \return + */ + std::string evalDecimationParams( + const char* pPartName, + const char* pFieldName, + int pFieldIt, + const char* pFilterName, + const char* pFilterParams); + + //--------------------------------------------------------------------- + // I/O + //--------------------------------------------------------------------- + + /** + * Reads the master file of a distributed MED file. + * \param pMEDfilename + * \throw NullArgumentException if pMEDfilename is NULL. + * \throw IOException if any i/o error occurs. + */ + void readDistributedMED(const char* pMEDfilename); + + /** + * Writes this distributed MED file (including master file and sub MED files if necessary). + * \param pMEDfilenamePrefix + * \throw NullArgumentException if pMEDfilename is NULL. + * \throw IOException if any i/o error occurs. + */ + void writeDistributedMED(const char* pMEDfilenamePrefix); + + /** + * Dumps any MeshDis to the given output stream. + * \param pOs any output stream. + * \param pM any MeshDis. + * \return the output stream pOs. + */ + friend std::ostream& operator<<(std::ostream& pOs, MeshDis& pM); + private: - /** - * Recomputes the number of parts in this distributed mesh. - * This method is used by writeDistributedMED(). - * \return the number of parts in this distributed mesh. - */ - int computeNumParts(); - + /** + * Recomputes the number of parts in this distributed mesh. + * This method is used by writeDistributedMED(). + * \return the number of parts in this distributed mesh. + */ + int computeNumParts(); + private: - char mMEDfilename[256]; /** Name of this distributed MED file (= name of the master file). */ - std::vector mParts; /**< Table of sub-parts; a distributed mesh is composed of N sub-part, where N = mParts.size(). */ - //MULTIPR_ProgressCallback* mProgressCallback; - + char mSequentialMEDFilename[256]; /**< Name of the original MED file used to build distribyuted MED. */ + char mDistributedMEDFilename[256]; /**< Name of this distributed MED file (= name of the master file). */ + std::vector mParts; /**< Table of sub-parts; a distributed mesh is composed of N sub-part, where N = mParts.size(). */ + //MULTIPR_ProgressCallback* mProgressCallback; + private: - // do not allow copy constructor - MeshDis(const MeshDis&); - - // do not allow copy - MeshDis& operator=(const MeshDis&); - - // do not allow operator == - bool operator==(const MeshDis&); - + // do not allow copy constructor + MeshDis(const MeshDis&); + + // do not allow copy + MeshDis& operator=(const MeshDis&); + + // do not allow operator == + bool operator==(const MeshDis&); + }; // class MeshDis diff --git a/src/MULTIPR/MULTIPR_Nodes.cxx b/src/MULTIPR/MULTIPR_Nodes.cxx index a499c95..d717d2b 100644 --- a/src/MULTIPR/MULTIPR_Nodes.cxx +++ b/src/MULTIPR/MULTIPR_Nodes.cxx @@ -33,365 +33,365 @@ namespace multipr Nodes::Nodes() { - mId = NULL; - mFamIdent = NULL; - mNames = NULL; - mCoo = NULL; - mNamesCoo = NULL; - mNamesUnitCoo = NULL; - - reset(); + mId = NULL; + mFamIdent = NULL; + mNames = NULL; + mCoo = NULL; + mNamesCoo = NULL; + mNamesUnitCoo = NULL; + + reset(); } Nodes::~Nodes() { - reset(); + reset(); } void Nodes::reset() { - mNum = 0; - mDim = 0; - mCoordSystem = MED_CART; - - if (mId != NULL) { delete[] mId; mId = NULL; } - if (mFamIdent != NULL) { delete[] mFamIdent; mFamIdent = NULL; } - if (mNames != NULL) { delete[] mNames; mNames = NULL; } - if (mCoo != NULL) { delete[] mCoo; mCoo = NULL; } - if (mNamesCoo != NULL) { delete[] mNamesCoo; mNamesCoo = NULL; } - if (mNamesUnitCoo != NULL) { delete[] mNamesUnitCoo; mNamesUnitCoo = NULL; } - - mFlagPrintAll = false; + mNum = 0; + mDim = 0; + mCoordSystem = MED_CART; + + if (mId != NULL) { delete[] mId; mId = NULL; } + if (mFamIdent != NULL) { delete[] mFamIdent; mFamIdent = NULL; } + if (mNames != NULL) { delete[] mNames; mNames = NULL; } + if (mCoo != NULL) { delete[] mCoo; mCoo = NULL; } + if (mNamesCoo != NULL) { delete[] mNamesCoo; mNamesCoo = NULL; } + if (mNamesUnitCoo != NULL) { delete[] mNamesUnitCoo; mNamesUnitCoo = NULL; } + + mFlagPrintAll = false; } const med_float* Nodes::getCoordinates(med_int pIndexNode) const { - if ((pIndexNode < 0) || (pIndexNode >= mNum)) throw IndexOutOfBoundsException("", __FILE__, __LINE__); - - return mCoo + pIndexNode * mDim; + if ((pIndexNode < 0) || (pIndexNode >= mNum)) throw IndexOutOfBoundsException("", __FILE__, __LINE__); + + return mCoo + pIndexNode * mDim; } med_int Nodes::getFamIdent(med_int pIndexNode) const { - if ((pIndexNode < 0) || (pIndexNode >= mNum)) throw IndexOutOfBoundsException("", __FILE__, __LINE__); - - return mFamIdent[pIndexNode]; + if ((pIndexNode < 0) || (pIndexNode >= mNum)) throw IndexOutOfBoundsException("", __FILE__, __LINE__); + + return mFamIdent[pIndexNode]; } void Nodes::getBBox(med_float pMin[3], med_float pMax[3]) const { - //--------------------------------------------------------------------- - // Special case: no nodes => bbox = [0 ; 0] x [0 ; 0] x [0 ; 0] - //--------------------------------------------------------------------- - if (mNum == 0) - { - for (int itDim = 0 ; itDim < mDim ; itDim++) - { - pMin[itDim] = med_float(0.0); - pMax[itDim] = med_float(0.0); - } - - return; - } - - //--------------------------------------------------------------------- - // Compute axis-aligned bounding box - //--------------------------------------------------------------------- - for (int itDim = 0 ; itDim < mDim ; itDim++) - { - pMin[itDim] = numeric_limits::max(); - pMax[itDim] = -pMin[itDim]; - } - for (int itNode = 0 ; itNode < mNum ; itNode++) - { - for (int itDim = 0 ; itDim < mDim ; itDim++) - { - med_float coord = mCoo[itNode * mDim + itDim]; - if (coord < pMin[itDim]) pMin[itDim] = coord; - if (coord > pMax[itDim]) pMax[itDim] = coord; - } - } + //--------------------------------------------------------------------- + // Special case: no nodes => bbox = [0 ; 0] x [0 ; 0] x [0 ; 0] + //--------------------------------------------------------------------- + if (mNum == 0) + { + for (int itDim = 0 ; itDim < mDim ; itDim++) + { + pMin[itDim] = med_float(0.0); + pMax[itDim] = med_float(0.0); + } + + return; + } + + //--------------------------------------------------------------------- + // Compute axis-aligned bounding box + //--------------------------------------------------------------------- + for (int itDim = 0 ; itDim < mDim ; itDim++) + { + pMin[itDim] = numeric_limits::max(); + pMax[itDim] = -pMin[itDim]; + } + for (int itNode = 0 ; itNode < mNum ; itNode++) + { + for (int itDim = 0 ; itDim < mDim ; itDim++) + { + med_float coord = mCoo[itNode * mDim + itDim]; + if (coord < pMin[itDim]) pMin[itDim] = coord; + if (coord > pMax[itDim]) pMax[itDim] = coord; + } + } } set Nodes::getSetOfFamilies() const { - set setOfFamilies; - - // for each node, ad its family to the set - for (int itNode = 0 ; itNode < mNum ; itNode++) - { - setOfFamilies.insert(mFamIdent[itNode]); - } - - return setOfFamilies; + set setOfFamilies; + + // for each node, ad its family to the set + for (int itNode = 0 ; itNode < mNum ; itNode++) + { + setOfFamilies.insert(mFamIdent[itNode]); + } + + return setOfFamilies; } Nodes* Nodes::extractSubSet(const set& pSetIndices) const { - Nodes* subset = new Nodes(); - - subset->mNum = pSetIndices.size(); - subset->mDim = mDim; - subset->mCoordSystem = mCoordSystem; - - //--------------------------------------------------------------------- - // Allocate arrays - //--------------------------------------------------------------------- - subset->mFamIdent = new med_int[subset->mNum]; - subset->mCoo = new med_float[subset->mDim * subset->mNum]; - subset->mNamesCoo = new char[subset->mDim * MED_TAILLE_PNOM + 1]; - subset->mNamesUnitCoo = new char[subset->mDim * MED_TAILLE_PNOM + 1]; - - memcpy(subset->mNamesCoo, mNamesCoo, subset->mDim * MED_TAILLE_PNOM + 1); - memcpy(subset->mNamesUnitCoo, mNamesUnitCoo, subset->mDim * MED_TAILLE_PNOM + 1); - - //--------------------------------------------------------------------- - // Copy subset of familys id and coords. - //--------------------------------------------------------------------- - set::iterator itSet = pSetIndices.begin(); - for (int i = 0 ; i < subset->mNum; i++) - { - - med_int srcIndex = (*itSet) - 1; // MED index start at 1 - subset->mFamIdent[i] = mFamIdent[srcIndex]; - - med_float* srcCoo = mCoo + srcIndex * mDim; - med_float* destCoo = subset->mCoo + i * subset->mDim; - for (int itDim = 0 ; itDim < mDim ; itDim++) - { - destCoo[itDim] = srcCoo[itDim]; - } - - itSet++; - } - - //--------------------------------------------------------------------- - // Copy subset of identifiers if necessary - //--------------------------------------------------------------------- - if (isIdentifiers()) - { - itSet = pSetIndices.begin(); - subset->mId = new med_int[subset->mNum]; - for (int i = 0 ; i < subset->mNum; i++) - { - med_int srcIndex = (*itSet) - 1; // MED index start at 1 - subset->mId[i] = mId[srcIndex]; - - itSet++; - } - } - - //--------------------------------------------------------------------- - // Copy subset of names if necessary - //--------------------------------------------------------------------- - if (isNames()) - { - subset->mNames = new char[MED_TAILLE_PNOM * subset->mNum + 1]; - char* destPtr = subset->mNames; - itSet = pSetIndices.begin(); - for (int i = 0 ; i < subset->mNum; i++) - { - med_int srcIndex = (*itSet) - 1; // MED index start at 1 - char* srcPtr = mNames + srcIndex * MED_TAILLE_PNOM; - memcpy(destPtr, srcPtr, MED_TAILLE_PNOM); - destPtr += MED_TAILLE_PNOM; - - itSet++; - } - subset->mNames[MED_TAILLE_PNOM * subset->mNum] = '\0'; - } - - return subset; + Nodes* subset = new Nodes(); + + subset->mNum = pSetIndices.size(); + subset->mDim = mDim; + subset->mCoordSystem = mCoordSystem; + + //--------------------------------------------------------------------- + // Allocate arrays + //--------------------------------------------------------------------- + subset->mFamIdent = new med_int[subset->mNum]; + subset->mCoo = new med_float[subset->mDim * subset->mNum]; + subset->mNamesCoo = new char[subset->mDim * MED_TAILLE_PNOM + 1]; + subset->mNamesUnitCoo = new char[subset->mDim * MED_TAILLE_PNOM + 1]; + + memcpy(subset->mNamesCoo, mNamesCoo, subset->mDim * MED_TAILLE_PNOM + 1); + memcpy(subset->mNamesUnitCoo, mNamesUnitCoo, subset->mDim * MED_TAILLE_PNOM + 1); + + //--------------------------------------------------------------------- + // Copy subset of familys id and coords. + //--------------------------------------------------------------------- + set::iterator itSet = pSetIndices.begin(); + for (int i = 0 ; i < subset->mNum; i++) + { + + med_int srcIndex = (*itSet) - 1; // MED index start at 1 + subset->mFamIdent[i] = mFamIdent[srcIndex]; + + med_float* srcCoo = mCoo + srcIndex * mDim; + med_float* destCoo = subset->mCoo + i * subset->mDim; + for (int itDim = 0 ; itDim < mDim ; itDim++) + { + destCoo[itDim] = srcCoo[itDim]; + } + + itSet++; + } + + //--------------------------------------------------------------------- + // Copy subset of identifiers if necessary + //--------------------------------------------------------------------- + if (isIdentifiers()) + { + itSet = pSetIndices.begin(); + subset->mId = new med_int[subset->mNum]; + for (int i = 0 ; i < subset->mNum; i++) + { + med_int srcIndex = (*itSet) - 1; // MED index start at 1 + subset->mId[i] = mId[srcIndex]; + + itSet++; + } + } + + //--------------------------------------------------------------------- + // Copy subset of names if necessary + //--------------------------------------------------------------------- + if (isNames()) + { + subset->mNames = new char[MED_TAILLE_PNOM * subset->mNum + 1]; + char* destPtr = subset->mNames; + itSet = pSetIndices.begin(); + for (int i = 0 ; i < subset->mNum; i++) + { + med_int srcIndex = (*itSet) - 1; // MED index start at 1 + char* srcPtr = mNames + srcIndex * MED_TAILLE_PNOM; + memcpy(destPtr, srcPtr, MED_TAILLE_PNOM); + destPtr += MED_TAILLE_PNOM; + + itSet++; + } + subset->mNames[MED_TAILLE_PNOM * subset->mNum] = '\0'; + } + + return subset; } void Nodes::readMED(med_idt pMEDfile, char* pMeshName, med_int pDim) { - if (pMEDfile == 0) throw IOException("", __FILE__, __LINE__); - if (pMeshName == NULL) throw NullArgumentException("", __FILE__, __LINE__); - if (pDim != 3) throw IllegalArgumentException("", __FILE__, __LINE__); - - reset(); - - mDim = pDim; - mNum = MEDnEntMaa( - pMEDfile, - pMeshName, - MED_COOR, - MED_NOEUD, - med_geometrie_element(0), - med_connectivite(0)); - - if (mNum <= 0) throw IOException("", __FILE__, __LINE__); - - mId = new med_int[mNum]; - mFamIdent = new med_int[mNum]; - mNames = new char[MED_TAILLE_PNOM * mNum + 1]; - mCoo = new med_float[mDim * mNum]; - mNamesCoo = new char[mDim * MED_TAILLE_PNOM + 1]; - mNamesUnitCoo = new char[mDim * MED_TAILLE_PNOM + 1]; - - mNames[0] = '\0'; - mNamesCoo[0] = '\0'; - mNamesUnitCoo[0] = '\0'; - - med_booleen isIdentifiers; - med_booleen isNames; - - med_err ret = MEDnoeudsLire( - pMEDfile, - pMeshName, - mDim, - mCoo, - MED_FULL_INTERLACE, - &mCoordSystem, - mNamesCoo, - mNamesUnitCoo, - mNames, - &isNames, - mId, - &isIdentifiers, - mFamIdent, - mNum); - - if (ret != 0) throw IOException("", __FILE__, __LINE__); - - // check if coordinates system is CARTESIAN - if (mCoordSystem != MED_CART) throw IllegalStateException("", __FILE__, __LINE__); - - if (!isNames) - { - delete[] mNames; - mNames = NULL; - } - - if (!isIdentifiers) - { - delete[] mId; - mId = NULL; - } + if (pMEDfile == 0) throw IOException("", __FILE__, __LINE__); + if (pMeshName == NULL) throw NullArgumentException("", __FILE__, __LINE__); + if (pDim != 3) throw IllegalArgumentException("", __FILE__, __LINE__); + + reset(); + + mDim = pDim; + mNum = MEDnEntMaa( + pMEDfile, + pMeshName, + MED_COOR, + MED_NOEUD, + med_geometrie_element(0), + med_connectivite(0)); + + if (mNum <= 0) throw IOException("", __FILE__, __LINE__); + + mId = new med_int[mNum]; + mFamIdent = new med_int[mNum]; + mNames = new char[MED_TAILLE_PNOM * mNum + 1]; + mCoo = new med_float[mDim * mNum]; + mNamesCoo = new char[mDim * MED_TAILLE_PNOM + 1]; + mNamesUnitCoo = new char[mDim * MED_TAILLE_PNOM + 1]; + + mNames[0] = '\0'; + mNamesCoo[0] = '\0'; + mNamesUnitCoo[0] = '\0'; + + med_booleen isIdentifiers; + med_booleen isNames; + + med_err ret = MEDnoeudsLire( + pMEDfile, + pMeshName, + mDim, + mCoo, + MED_FULL_INTERLACE, + &mCoordSystem, + mNamesCoo, + mNamesUnitCoo, + mNames, + &isNames, + mId, + &isIdentifiers, + mFamIdent, + mNum); + + if (ret != 0) throw IOException("", __FILE__, __LINE__); + + // check if coordinates system is CARTESIAN + if (mCoordSystem != MED_CART) throw IllegalStateException("", __FILE__, __LINE__); + + if (!isNames) + { + delete[] mNames; + mNames = NULL; + } + + if (!isIdentifiers) + { + delete[] mId; + mId = NULL; + } } void Nodes::writeMED(med_idt pMEDfile, char* pMeshName) const { - if (pMEDfile == 0) throw IOException("", __FILE__, __LINE__); - if (pMeshName == NULL) throw NullArgumentException("", __FILE__, __LINE__); - if (strlen(pMeshName) > MED_TAILLE_NOM) throw IllegalArgumentException("", __FILE__, __LINE__); - if ((mDim < 1) || (mDim > 3)) throw IllegalStateException("", __FILE__, __LINE__); - if (mFamIdent == NULL) throw IllegalStateException("", __FILE__, __LINE__); - if (mCoo == NULL) throw IllegalStateException("", __FILE__, __LINE__); - if (mNamesCoo == NULL) throw IllegalStateException("", __FILE__, __LINE__); - if (mNamesUnitCoo == NULL) throw IllegalStateException("", __FILE__, __LINE__); - - // special case: if no nodes => do nothing - if (mNum == 0) return; - - med_err ret = MEDnoeudsEcr( - pMEDfile, - pMeshName, - mDim, - mCoo, - MED_FULL_INTERLACE, - mCoordSystem, - mNamesCoo, - mNamesUnitCoo, - mNames, - isNames()?MED_VRAI:MED_FAUX, - mId, - isIdentifiers()?MED_VRAI:MED_FAUX, - mFamIdent, - mNum); - - if (ret != 0) throw IOException("i/o error while writing nodes", __FILE__, __LINE__); - + if (pMEDfile == 0) throw IOException("", __FILE__, __LINE__); + if (pMeshName == NULL) throw NullArgumentException("", __FILE__, __LINE__); + if (strlen(pMeshName) > MED_TAILLE_NOM) throw IllegalArgumentException("", __FILE__, __LINE__); + if ((mDim < 1) || (mDim > 3)) throw IllegalStateException("", __FILE__, __LINE__); + if (mFamIdent == NULL) throw IllegalStateException("", __FILE__, __LINE__); + if (mCoo == NULL) throw IllegalStateException("", __FILE__, __LINE__); + if (mNamesCoo == NULL) throw IllegalStateException("", __FILE__, __LINE__); + if (mNamesUnitCoo == NULL) throw IllegalStateException("", __FILE__, __LINE__); + + // special case: if no nodes => do nothing + if (mNum == 0) return; + + med_err ret = MEDnoeudsEcr( + pMEDfile, + pMeshName, + mDim, + mCoo, + MED_FULL_INTERLACE, + mCoordSystem, + mNamesCoo, + mNamesUnitCoo, + mNames, + isNames()?MED_VRAI:MED_FAUX, + mId, + isIdentifiers()?MED_VRAI:MED_FAUX, + mFamIdent, + mNum); + + if (ret != 0) throw IOException("i/o error while writing nodes", __FILE__, __LINE__); + } ostream& operator<<(ostream& pOs, Nodes& pN) { - char strCoordSystem[16]; - switch (pN.mCoordSystem) - { - case MED_CART: strcpy(strCoordSystem, "CARTESIAN"); break; - case MED_CYL: strcpy(strCoordSystem, "CYLINDRIC"); break; - case MED_SPHER: strcpy(strCoordSystem, "SPHERIC"); break; - default: strcpy(strCoordSystem, "UNKNOWN"); break; - } - - pOs << "Nodes: " << endl; - pOs << " #number =" << pN.mNum << endl; - pOs << " Dimension =" << pN.mDim << endl; - pOs << " Coord. system=" << strCoordSystem << endl; - pOs << " Has names ?" << (pN.isNames()?"yes":"no") << endl; - pOs << " Has id ?" << (pN.isIdentifiers()?"yes":"no") << endl; - pOs << " Axis names =" << "|" << pN.mNamesCoo << "|" << endl; - pOs << " Unit axis =" << "|" << pN.mNamesUnitCoo << "|" << endl; - - { - set setOfFam = pN.getSetOfFamilies(); - if (setOfFam.size() == 0) - { - pOs << " Families: #fam=0" << endl; - } - else - { - set::iterator itFam = setOfFam.end(); - itFam--; - pOs << " Families: #fam=" << setOfFam.size() << " id_min=" << (*(setOfFam.begin())) << " id_max=" << (*itFam) << endl; - } - - if (pN.mFlagPrintAll) - { - for (int itNode = 0 ; itNode < pN.mNum; itNode++) - { - pOs << " Node " << (itNode+1) << ": " << pN.mFamIdent[itNode] << endl; - } - } - } - - med_float bboxMin[3], bboxMax[3]; - pN.getBBox(bboxMin, bboxMax); - pOs << " BBox: [" << bboxMin[0] << " ; " << bboxMax[0] << "] x [" << bboxMin[1] << " ; " << bboxMax[1] << "] x [" << bboxMin[2] << " ; " << bboxMax[2] << "]" << endl; - - if (pN.mFlagPrintAll) - { - pOs << " Coordinates: " << endl; - for (int itNode = 0 ; itNode < pN.mNum ; itNode++) - { - pOs << " Node " << (itNode+1) << ": "; - for (int itDim = 0 ; itDim < pN.mDim ; itDim++) - { - pOs << pN.mCoo[itNode * pN.mDim + itDim] << " "; - } - pOs << endl; - } - - if (pN.isIdentifiers()) - { - pOs << " Num: " << endl; - for (int itNode = 0 ; itNode < pN.mNum; itNode++) - { - pOs << " Node " << (itNode+1) << ": " << pN.mId[itNode] << endl; - } - } - - if (pN.isNames()) - { - pN.mNames[MED_TAILLE_PNOM * pN.mNum] = '\0'; - pOs << " Names: |" << pN.mNames << "|" << endl; - } - - } - - return pOs; + char strCoordSystem[16]; + switch (pN.mCoordSystem) + { + case MED_CART: strcpy(strCoordSystem, "CARTESIAN"); break; + case MED_CYL: strcpy(strCoordSystem, "CYLINDRIC"); break; + case MED_SPHER: strcpy(strCoordSystem, "SPHERIC"); break; + default: strcpy(strCoordSystem, "UNKNOWN"); break; + } + + pOs << "Nodes: " << endl; + pOs << " #number =" << pN.mNum << endl; + pOs << " Dimension =" << pN.mDim << endl; + pOs << " Coord. system=" << strCoordSystem << endl; + pOs << " Has names ?" << (pN.isNames()?"yes":"no") << endl; + pOs << " Has id ?" << (pN.isIdentifiers()?"yes":"no") << endl; + pOs << " Axis names =" << "|" << pN.mNamesCoo << "|" << endl; + pOs << " Unit axis =" << "|" << pN.mNamesUnitCoo << "|" << endl; + + { + set setOfFam = pN.getSetOfFamilies(); + if (setOfFam.size() == 0) + { + pOs << " Families: #fam=0" << endl; + } + else + { + set::iterator itFam = setOfFam.end(); + itFam--; + pOs << " Families: #fam=" << setOfFam.size() << " id_min=" << (*(setOfFam.begin())) << " id_max=" << (*itFam) << endl; + } + + if (pN.mFlagPrintAll) + { + for (int itNode = 0 ; itNode < pN.mNum; itNode++) + { + pOs << " Node " << (itNode+1) << ": " << pN.mFamIdent[itNode] << endl; + } + } + } + + med_float bboxMin[3], bboxMax[3]; + pN.getBBox(bboxMin, bboxMax); + pOs << " BBox: [" << bboxMin[0] << " ; " << bboxMax[0] << "] x [" << bboxMin[1] << " ; " << bboxMax[1] << "] x [" << bboxMin[2] << " ; " << bboxMax[2] << "]" << endl; + + if (pN.mFlagPrintAll) + { + pOs << " Coordinates: " << endl; + for (int itNode = 0 ; itNode < pN.mNum ; itNode++) + { + pOs << " Node " << (itNode+1) << ": "; + for (int itDim = 0 ; itDim < pN.mDim ; itDim++) + { + pOs << pN.mCoo[itNode * pN.mDim + itDim] << " "; + } + pOs << endl; + } + + if (pN.isIdentifiers()) + { + pOs << " Num: " << endl; + for (int itNode = 0 ; itNode < pN.mNum; itNode++) + { + pOs << " Node " << (itNode+1) << ": " << pN.mId[itNode] << endl; + } + } + + if (pN.isNames()) + { + pN.mNames[MED_TAILLE_PNOM * pN.mNum] = '\0'; + pOs << " Names: |" << pN.mNames << "|" << endl; + } + + } + + return pOs; } diff --git a/src/MULTIPR/MULTIPR_Nodes.hxx b/src/MULTIPR/MULTIPR_Nodes.hxx index ed39c9d..60eb195 100644 --- a/src/MULTIPR/MULTIPR_Nodes.hxx +++ b/src/MULTIPR/MULTIPR_Nodes.hxx @@ -20,7 +20,7 @@ extern "C" { - #include "med.h" + #include "med.h" } #include @@ -39,146 +39,146 @@ class Nodes { public: - /** - * Builds an empty set of nodes (default constructor). - */ - Nodes(); - - /** - * Destructor. Removes everything. - */ - ~Nodes(); - - /** - * Resets this object in its state by default (empty). Cleans memory. - */ - void reset(); - - //--------------------------------------------------------------------- - // Basic accessors/mutators - //--------------------------------------------------------------------- - - /** - * Returns true if nodes have a name. - * \return true if nodes have a name. - */ - bool isNames() const { return (mNames != NULL); } - - /** - * Returns true if elements have an identifier (= a number). - * \return true if elements have an identifier (= a number). - */ - bool isIdentifiers() const { return (mId != NULL); } - - /** - * Returns the coordinates of one node according to its index. - * \param pIndexNode index of node in [0..NUMBER_OF_NODES-1]. - * \return the coordinates of one node. - * \throw IndexOutOfBoundsException if pIndexNode is invalid. - */ - const med_float* getCoordinates(med_int pIndexNode) const; - - /** - * Returns the family of one node. - * \param pIndexNode index of node in [0..NUMBER_OF_NODES-1]. - * \return the family of the given node. - * \throw IndexOutOfBoundsException if pIndexNode is invalid. - */ - med_int getFamIdent(med_int pIndexNode) const; - - /** - * Returns the number of nodes. - * \return the number of nodes. - */ - int getNumberOfNodes() const { return mNum; } - - //--------------------------------------------------------------------- - // Algorithms - //--------------------------------------------------------------------- - - /** - * Returns the axis-aligned bounding box (CARTESIAN coordinates system) of this set of nodes. - * \param pMin (out) coordinates of the min-corner of the bbox. - * \param pMin (out) coordinates of the max-corner of the bbox. - */ - void getBBox(med_float pMin[3], med_float pMax[3]) const; - - /** - * Returns the set of families referenced by this set of nodes. - * Each family is described by its identifier. - * \return the set of families referenced by this set of nodes. - */ - std::set getSetOfFamilies() const; - - /** - * Constructor. Creates a subset of this set of nodes from a set of indices. - * \param pSetOfIndices set of indices; each index must be >= 1. - * \return a subset of this set of nodes from a set of indices. - */ - Nodes* extractSubSet(const std::set& pSetIndices) const; - - //--------------------------------------------------------------------- - // I/O - //--------------------------------------------------------------------- - - /** - * Reads all nodes of a mesh from a MED file. - * \param pMEDfile any valid MED file opened for reading. - * \param pMeshName name of the mesh to be read. - * \param pDim dimension of the mesh. - * \throw IOException if any i/o error occurs. - */ - void readMED(med_idt pMEDfile, char* pMeshName, med_int pDim); - - /** - * Writes this set of nodes to a MED file. Nodes are associated with the given mesh. - * WARNING: mesh must have been created and added to the MED file before. - * \param pMEDfile any valid MED file opened for writing. - * \param pMeshName any mesh of the MED file. - * \throw IOException if any i/o error occurs. - */ - void writeMED(med_idt pMEDfile, char* pMeshName) const; - - /** - * Sets the flag which control the stream operator <<. - * \param pFlag new flag value. - */ - void setPrintAll(bool pFlag) { mFlagPrintAll = pFlag; } - - /** - * Dumps any Nodes to the given output stream. - * \param pOs any output stream. - * \param pN any Nodes. - * \return the output stream pOs. - */ - friend std::ostream& operator<<(std::ostream& pOs, Nodes& pN); - + /** + * Builds an empty set of nodes (default constructor). + */ + Nodes(); + + /** + * Destructor. Removes everything. + */ + ~Nodes(); + + /** + * Resets this object in its state by default (empty). Cleans memory. + */ + void reset(); + + //--------------------------------------------------------------------- + // Basic accessors/mutators + //--------------------------------------------------------------------- + + /** + * Returns true if nodes have a name. + * \return true if nodes have a name. + */ + bool isNames() const { return (mNames != NULL); } + + /** + * Returns true if elements have an identifier (= a number). + * \return true if elements have an identifier (= a number). + */ + bool isIdentifiers() const { return (mId != NULL); } + + /** + * Returns the coordinates of one node according to its index. + * \param pIndexNode index of node in [0..NUMBER_OF_NODES-1]. + * \return the coordinates of one node. + * \throw IndexOutOfBoundsException if pIndexNode is invalid. + */ + const med_float* getCoordinates(med_int pIndexNode) const; + + /** + * Returns the family of one node. + * \param pIndexNode index of node in [0..NUMBER_OF_NODES-1]. + * \return the family of the given node. + * \throw IndexOutOfBoundsException if pIndexNode is invalid. + */ + med_int getFamIdent(med_int pIndexNode) const; + + /** + * Returns the number of nodes. + * \return the number of nodes. + */ + int getNumberOfNodes() const { return mNum; } + + //--------------------------------------------------------------------- + // Algorithms + //--------------------------------------------------------------------- + + /** + * Returns the axis-aligned bounding box (CARTESIAN coordinates system) of this set of nodes. + * \param pMin (out) coordinates of the min-corner of the bbox. + * \param pMin (out) coordinates of the max-corner of the bbox. + */ + void getBBox(med_float pMin[3], med_float pMax[3]) const; + + /** + * Returns the set of families referenced by this set of nodes. + * Each family is described by its identifier. + * \return the set of families referenced by this set of nodes. + */ + std::set getSetOfFamilies() const; + + /** + * Constructor. Creates a subset of this set of nodes from a set of indices. + * \param pSetOfIndices set of indices; each index must be >= 1. + * \return a subset of this set of nodes from a set of indices. + */ + Nodes* extractSubSet(const std::set& pSetIndices) const; + + //--------------------------------------------------------------------- + // I/O + //--------------------------------------------------------------------- + + /** + * Reads all nodes of a mesh from a MED file. + * \param pMEDfile any valid MED file opened for reading. + * \param pMeshName name of the mesh to be read. + * \param pDim dimension of the mesh. + * \throw IOException if any i/o error occurs. + */ + void readMED(med_idt pMEDfile, char* pMeshName, med_int pDim); + + /** + * Writes this set of nodes to a MED file. Nodes are associated with the given mesh. + * WARNING: mesh must have been created and added to the MED file before. + * \param pMEDfile any valid MED file opened for writing. + * \param pMeshName any mesh of the MED file. + * \throw IOException if any i/o error occurs. + */ + void writeMED(med_idt pMEDfile, char* pMeshName) const; + + /** + * Sets the flag which control the stream operator <<. + * \param pFlag new flag value. + */ + void setPrintAll(bool pFlag) { mFlagPrintAll = pFlag; } + + /** + * Dumps any Nodes to the given output stream. + * \param pOs any output stream. + * \param pN any Nodes. + * \return the output stream pOs. + */ + friend std::ostream& operator<<(std::ostream& pOs, Nodes& pN); + private: - - med_int mNum; /**< Number of nodes in this set. */ - med_int mDim; /**< Dimension of nodes. */ - med_repere mCoordSystem; /**< Type of coordinates system; should be MED_CART for cartesian. */ - - med_int* mId; /**< Optional; for each node, its identifier; NULL if undefined. */ - med_int* mFamIdent; /**< For each node, its identifier of its family. */ - char* mNames; /**< Optional; for each node, its name; NULL if undefined. */ - med_float* mCoo; /**< For each node, coordinates of node; array is interlaced: x1 y1 z1 x2 y2 z2 ...*/ - char* mNamesCoo; /**< Names of axis of the coordinates system. */ - char* mNamesUnitCoo; /**< Unit of axis of the coordinates system. */ - - bool mFlagPrintAll; /** Flag to control the behaviour of the stream operator <<. */ - + + med_int mNum; /**< Number of nodes in this set. */ + med_int mDim; /**< Dimension of nodes. */ + med_repere mCoordSystem; /**< Type of coordinates system; should be MED_CART for cartesian. */ + + med_int* mId; /**< Optional; for each node, its identifier; NULL if undefined. */ + med_int* mFamIdent; /**< For each node, its identifier of its family. */ + char* mNames; /**< Optional; for each node, its name; NULL if undefined. */ + med_float* mCoo; /**< For each node, coordinates of node; array is interlaced: x1 y1 z1 x2 y2 z2 ...*/ + char* mNamesCoo; /**< Names of axis of the coordinates system. */ + char* mNamesUnitCoo; /**< Unit of axis of the coordinates system. */ + + bool mFlagPrintAll; /** Flag to control the behaviour of the stream operator <<. */ + private: - // do not allow copy constructor - Nodes(const Nodes&); - - // do not allow copy - Nodes& operator=(const Nodes&); - - // do not allow operator == - bool operator==(const Nodes&); - + // do not allow copy constructor + Nodes(const Nodes&); + + // do not allow copy + Nodes& operator=(const Nodes&); + + // do not allow operator == + bool operator==(const Nodes&); + }; // class Nodes diff --git a/src/MULTIPR/MULTIPR_Obj.cxx b/src/MULTIPR/MULTIPR_Obj.cxx index 30fd595..99352eb 100644 --- a/src/MULTIPR/MULTIPR_Obj.cxx +++ b/src/MULTIPR/MULTIPR_Obj.cxx @@ -37,438 +37,448 @@ namespace multipr Obj::Obj() { - mMeshDis = NULL; - - reset(); + mMeshDis = NULL; + + reset(); } Obj::~Obj() { - reset(); + reset(); } void Obj::reset() { - mMEDfilename = ""; - mMeshName = ""; - mState = MULTIPR_OBJ_STATE_RESET; - - if (mMeshDis != NULL) { delete mMeshDis; mMeshDis = NULL; } + mMEDfilename = ""; + mMeshName = ""; + mState = MULTIPR_OBJ_STATE_RESET; + + if (mMeshDis != NULL) { delete mMeshDis; mMeshDis = NULL; } } void Obj::create(const char* pMEDfilename) { - if (pMEDfilename == NULL) throw multipr::NullArgumentException("file name must not be NULL", __FILE__, __LINE__); - - // reset everything before associating a new MED file to this object - reset(); - - mMEDfilename = pMEDfilename; - - // check if file exists - FILE* f = fopen(pMEDfilename, "rb"); - if (f == 0) - { - // file does not exist - mState = MULTIPR_OBJ_STATE_ERROR; - throw FileNotFoundException("file not found", __FILE__, __LINE__); - } - fclose(f); - - // test whether it is a sequential MED file or a distributed MED file - med_idt file = MEDouvrir(const_cast(pMEDfilename), MED_LECTURE); // open sequential MED file for reading - if (file > 0) - { - // sequential MED file has been sucessfuly openened - - // CASE 1: sequential MED file - med_int ret = MEDfermer(file); - - if (ret != 0) - { - // error while closing sequential MED file - mState = MULTIPR_OBJ_STATE_ERROR; - throw multipr::IOException("i/o error while closing MED file", __FILE__, __LINE__); - } - - mState = MULTIPR_OBJ_STATE_SEQ_INIT; - cout << "Sequential MED file " << pMEDfilename << " has been successfuly opened" << endl; - } - else - { - // CASE 2: distributed MED file? - try - { - mMeshDis = new multipr::MeshDis(); - mMeshDis->readDistributedMED(pMEDfilename); - - mState = MULTIPR_OBJ_STATE_DIS; - cout << "Distributed MED file " << pMEDfilename << " has been successfuly opened" << endl; - } - catch (...) - { - // neither a sequential MED file, nor a distributed MED file => error - mState = MULTIPR_OBJ_STATE_ERROR; - throw IOException("file is nor a sequential MED file, neither a distributed MED file", __FILE__, __LINE__); - } - } + if (pMEDfilename == NULL) throw multipr::NullArgumentException("file name must not be NULL", __FILE__, __LINE__); + + // reset everything before associating a new MED file to this object + reset(); + + mMEDfilename = pMEDfilename; + + // check if file exists + FILE* f = fopen(pMEDfilename, "rb"); + if (f == 0) + { + // file does not exist + mState = MULTIPR_OBJ_STATE_ERROR; + throw FileNotFoundException("file not found", __FILE__, __LINE__); + } + fclose(f); + + // test whether it is a sequential MED file or a distributed MED file + med_idt file = MEDouvrir(const_cast(pMEDfilename), MED_LECTURE); // open sequential MED file for reading + if (file > 0) + { + // sequential MED file has been sucessfuly openened + + // CASE 1: sequential MED file + med_int ret = MEDfermer(file); + + if (ret != 0) + { + // error while closing sequential MED file + mState = MULTIPR_OBJ_STATE_ERROR; + throw multipr::IOException("i/o error while closing MED file", __FILE__, __LINE__); + } + + mState = MULTIPR_OBJ_STATE_SEQ_INIT; + cout << "Sequential MED file " << pMEDfilename << " has been successfuly opened" << endl; + } + else + { + // CASE 2: distributed MED file? + try + { + mMeshDis = new multipr::MeshDis(); + mMeshDis->readDistributedMED(pMEDfilename); + + mState = MULTIPR_OBJ_STATE_DIS; + cout << "Distributed MED file " << pMEDfilename << " has been successfuly opened" << endl; + } + catch (...) + { + // neither a sequential MED file, nor a distributed MED file => error + mState = MULTIPR_OBJ_STATE_ERROR; + throw IOException("file is nor a sequential MED file, neither a distributed MED file", __FILE__, __LINE__); + } + } +} + + +std::string Obj::getSequentialMEDFilename() const +{ + // partitionneGrain() is only available for distributed MED file (not sequential MED file) + if ((mState != MULTIPR_OBJ_STATE_DIS_MEM) && + (mState != MULTIPR_OBJ_STATE_DIS)) throw IllegalStateException("unexpected operation", __FILE__, __LINE__); + + return mMeshDis->getSequentialMEDFilename(); } void Obj::setMesh(const char* pMeshName) { - // setMesh() is only available for sequential MED file (not distributed MED file) - if ((mState != MULTIPR_OBJ_STATE_SEQ_INIT) && - (mState != MULTIPR_OBJ_STATE_SEQ)) throw IllegalStateException("expected a sequential MED file", __FILE__, __LINE__); - - mMeshName = pMeshName; - - // change state to MULTIPR_OBJ_STATE_SEQ (in case of state=MULTIPR_OBJ_STATE_SEQ_INIT) - mState = MULTIPR_OBJ_STATE_SEQ; + // setMesh() is only available for sequential MED file (not distributed MED file) + if ((mState != MULTIPR_OBJ_STATE_SEQ_INIT) && + (mState != MULTIPR_OBJ_STATE_SEQ)) throw IllegalStateException("expected a sequential MED file", __FILE__, __LINE__); + + mMeshName = pMeshName; + + // change state to MULTIPR_OBJ_STATE_SEQ (in case of state=MULTIPR_OBJ_STATE_SEQ_INIT) + mState = MULTIPR_OBJ_STATE_SEQ; } vector Obj::getMeshes() const { - // test whether it is a sequential MED file or a distributed MED file - if ((mState == MULTIPR_OBJ_STATE_SEQ_INIT) || - (mState == MULTIPR_OBJ_STATE_SEQ)) - { - // CASE 1: sequential MED file - return multipr::getListMeshes(mMEDfilename.c_str()); - } - else - { - // CASE 2: distributed MED file - if (mMeshDis == NULL) - { - throw IllegalStateException("distributed MED file should not be NULL", __FILE__, __LINE__); - } - - return mMeshDis->getMeshes(); - } + // test whether it is a sequential MED file or a distributed MED file + if ((mState == MULTIPR_OBJ_STATE_SEQ_INIT) || + (mState == MULTIPR_OBJ_STATE_SEQ)) + { + // CASE 1: sequential MED file + return multipr::getListMeshes(mMEDfilename.c_str()); + } + else + { + // CASE 2: distributed MED file + if (mMeshDis == NULL) + { + throw IllegalStateException("distributed MED file should not be NULL", __FILE__, __LINE__); + } + + return mMeshDis->getMeshes(); + } } vector Obj::getFields() const { - // test whether it is a sequential MED file or a distributed MED file - if ((mState == MULTIPR_OBJ_STATE_SEQ_INIT) || - (mState == MULTIPR_OBJ_STATE_SEQ)) - { - // CASE 1: sequential MED file - vector > tmp = multipr::getListScalarFields(mMEDfilename.c_str()); - - vector res; - for (int i = 0 ; i < tmp.size() ; i++) - { - res.push_back(tmp[i].first); - } - - return res; - } - else - { - // CASE 2: distributed MED file - if (mMeshDis == NULL) throw IllegalStateException("distributed MED file should not be NULL", __FILE__, __LINE__); - - return mMeshDis->getFields(); - } + // test whether it is a sequential MED file or a distributed MED file + if ((mState == MULTIPR_OBJ_STATE_SEQ_INIT) || + (mState == MULTIPR_OBJ_STATE_SEQ)) + { + // CASE 1: sequential MED file + vector > tmp = multipr::getListScalarFields(mMEDfilename.c_str()); + + vector res; + for (int i = 0 ; i < tmp.size() ; i++) + { + res.push_back(tmp[i].first); + } + + return res; + } + else + { + // CASE 2: distributed MED file + if (mMeshDis == NULL) throw IllegalStateException("distributed MED file should not be NULL", __FILE__, __LINE__); + + return mMeshDis->getFields(); + } } int Obj::getTimeStamps(const char* pFieldName) const { - // test whether it is a sequential MED file or a distributed MED file - if ((mState == MULTIPR_OBJ_STATE_SEQ_INIT) || - (mState == MULTIPR_OBJ_STATE_SEQ)) - { - // CASE 1: sequential MED file - vector > tmp = multipr::getListScalarFields(mMEDfilename.c_str()); - - for (int i = 0 ; i < tmp.size() ; i++) - { - if (strcmp(tmp[i].first.c_str(), pFieldName) == 0) - { - return tmp[i].second; - } - } - - // pFieldName not found in the list of fields - return 0; - } - else - { - // CASE 2: distributed MED file - if (mMeshDis == NULL) throw IllegalStateException("distributed MED file should not be NULL", __FILE__, __LINE__); - - return mMeshDis->getTimeStamps(pFieldName); - } + // test whether it is a sequential MED file or a distributed MED file + if ((mState == MULTIPR_OBJ_STATE_SEQ_INIT) || + (mState == MULTIPR_OBJ_STATE_SEQ)) + { + // CASE 1: sequential MED file + vector > tmp = multipr::getListScalarFields(mMEDfilename.c_str()); + + for (int i = 0 ; i < tmp.size() ; i++) + { + if (strcmp(tmp[i].first.c_str(), pFieldName) == 0) + { + return tmp[i].second; + } + } + + // pFieldName not found in the list of fields + return 0; + } + else + { + // CASE 2: distributed MED file + if (mMeshDis == NULL) throw IllegalStateException("distributed MED file should not be NULL", __FILE__, __LINE__); + + return mMeshDis->getTimeStamps(pFieldName); + } } vector Obj::getParts() const { - // getParts() is only available for distributed MED file (not sequential MED file) - if ((mState != MULTIPR_OBJ_STATE_DIS) && - (mState != MULTIPR_OBJ_STATE_DIS_MEM)) throw IllegalStateException("expected a distributed MED file", __FILE__, __LINE__); - - return getListParts(); + // getParts() is only available for distributed MED file (not sequential MED file) + if ((mState != MULTIPR_OBJ_STATE_DIS) && + (mState != MULTIPR_OBJ_STATE_DIS_MEM)) throw IllegalStateException("expected a distributed MED file", __FILE__, __LINE__); + + return getListParts(); } string Obj::getPartInfo(const char* pPartName) const { - // getParts() is only available for distributed MED file (not sequential MED file) - if ((mState != MULTIPR_OBJ_STATE_DIS) && - (mState != MULTIPR_OBJ_STATE_DIS_MEM)) throw IllegalStateException("expected a distributed MED file", __FILE__, __LINE__); - - if (mMeshDis == NULL) throw IllegalStateException("distributed MED file should not be NULL", __FILE__, __LINE__); - - return mMeshDis->getPartInfo(pPartName); - + // getParts() is only available for distributed MED file (not sequential MED file) + if ((mState != MULTIPR_OBJ_STATE_DIS) && + (mState != MULTIPR_OBJ_STATE_DIS_MEM)) throw IllegalStateException("expected a distributed MED file", __FILE__, __LINE__); + + if (mMeshDis == NULL) throw IllegalStateException("distributed MED file should not be NULL", __FILE__, __LINE__); + + return mMeshDis->getPartInfo(pPartName); + } void Obj::removeParts(const char* pPrefixPartName) { - // removePart() is only available for distributed MED file (not sequential MED file) - if ((mState != MULTIPR_OBJ_STATE_DIS) && - (mState != MULTIPR_OBJ_STATE_DIS_MEM)) throw IllegalStateException("expected a distributed MED file", __FILE__, __LINE__); - - if (mMeshDis == NULL) throw IllegalStateException("distributed MED file should not be NULL", __FILE__, __LINE__); - - mMeshDis->removeParts(pPrefixPartName); - mState = MULTIPR_OBJ_STATE_DIS_MEM; + // removePart() is only available for distributed MED file (not sequential MED file) + if ((mState != MULTIPR_OBJ_STATE_DIS) && + (mState != MULTIPR_OBJ_STATE_DIS_MEM)) throw IllegalStateException("expected a distributed MED file", __FILE__, __LINE__); + + if (mMeshDis == NULL) throw IllegalStateException("distributed MED file should not be NULL", __FILE__, __LINE__); + + mMeshDis->removeParts(pPrefixPartName); + mState = MULTIPR_OBJ_STATE_DIS_MEM; } vector Obj::partitionneDomaine() { - if (mState == MULTIPR_OBJ_STATE_SEQ_INIT) throw IllegalStateException("use setMesh() before", __FILE__, __LINE__); - - // partitionneDomaine() is only available for sequential MED file (not distributed MED file) - if (mState != MULTIPR_OBJ_STATE_SEQ) throw IllegalStateException("unexpected operation", __FILE__, __LINE__); - - //------------------------------------------------------------- - // Read the sequential mesh - //------------------------------------------------------------- - cout << "Read sequential MED file: " << mMEDfilename << ": please wait... " << endl; - - Mesh mesh; - mesh.readSequentialMED(mMEDfilename.c_str(), mMeshName.c_str()); - cout << mesh << endl; - - //------------------------------------------------------------- - // Build distributed mesh from groups - //------------------------------------------------------------- - cout << "Build distributed mesh: please wait... " << endl; - try - { - mMeshDis = mesh.splitGroupsOfElements(); - } - catch (RuntimeException& e) - { - delete mMeshDis; - mMeshDis = NULL; - throw e; - } - - mState = MULTIPR_OBJ_STATE_DIS_MEM; - - return getListParts(); + if (mState == MULTIPR_OBJ_STATE_SEQ_INIT) throw IllegalStateException("use setMesh() before", __FILE__, __LINE__); + + // partitionneDomaine() is only available for sequential MED file (not distributed MED file) + if (mState != MULTIPR_OBJ_STATE_SEQ) throw IllegalStateException("unexpected operation", __FILE__, __LINE__); + + //------------------------------------------------------------- + // Read the sequential mesh + //------------------------------------------------------------- + cout << "Read sequential MED file: " << mMEDfilename << ": please wait... " << endl; + + Mesh mesh; + mesh.readSequentialMED(mMEDfilename.c_str(), mMeshName.c_str()); + cout << mesh << endl; + + //------------------------------------------------------------- + // Build distributed mesh from groups + //------------------------------------------------------------- + cout << "Build distributed mesh: please wait... " << endl; + try + { + mMeshDis = mesh.splitGroupsOfElements(); + } + catch (RuntimeException& e) + { + delete mMeshDis; + mMeshDis = NULL; + throw e; + } + + mState = MULTIPR_OBJ_STATE_DIS_MEM; + + return getListParts(); } vector Obj::partitionneGrain( - const char* pPartName, - int pNbParts, - int pPartitionner) + const char* pPartName, + int pNbParts, + int pPartitionner) { - if (mMeshDis == NULL) throw IllegalStateException("expected a distributed MED file", __FILE__, __LINE__); - if (pPartName == NULL) throw NullArgumentException("", __FILE__, __LINE__); - if (pNbParts < 2) throw IllegalArgumentException("", __FILE__, __LINE__); - if ((pPartitionner != 0) && (pPartitionner != 1)) throw IllegalArgumentException("partitionner should be 0=METIS or 1=SCOTCH", __FILE__, __LINE__); - - // partitionneGrain() is only available for distributed MED file (not sequential MED file) - if ((mState != MULTIPR_OBJ_STATE_DIS_MEM) && - (mState != MULTIPR_OBJ_STATE_DIS)) throw IllegalStateException("unexpected operation", __FILE__, __LINE__); - - // if distributed MED file is currently in memory, then write to disk before performing partitionneGrain() - // (because MEDSPLIITER starts from a file) - if (mState == MULTIPR_OBJ_STATE_DIS_MEM) - { - //----------------------------------------------------- - // Write distributed mesh - //----------------------------------------------------- - cout << "Write distributed mesh: please wait... " << endl; - string strPrefix = removeExtension(mMEDfilename.c_str(), ".med"); - mMeshDis->writeDistributedMED(strPrefix.c_str()); - - mMEDfilename = mMeshDis->getFilename(); - - delete mMeshDis; - - //--------------------------------------------------------------------- - // Read the distributed mesh - //--------------------------------------------------------------------- - int ret = MEDformatConforme(mMEDfilename.c_str()); - if (ret == 0) throw IOException("waiting for a distributed MED file (not a sequential one)", __FILE__, __LINE__); - - mMeshDis = new MeshDis(); - mMeshDis->readDistributedMED(mMEDfilename.c_str()); - - mState = MULTIPR_OBJ_STATE_DIS; - } - - //--------------------------------------------------------------------- - // Split the given part (pGroupName) - //--------------------------------------------------------------------- - mMeshDis->splitPart(pPartName, pNbParts, pPartitionner); - cout << mMeshDis << endl; - - //--------------------------------------------------------------------- - // Write new distributed mesh - //--------------------------------------------------------------------- - string strPrefix = multipr::removeExtension(mMEDfilename.c_str(), ".med"); - mMeshDis->writeDistributedMED(strPrefix.c_str()); - - //--------------------------------------------------------------------- - // Read the distributed mesh - //--------------------------------------------------------------------- - delete mMeshDis; - mMeshDis = new MeshDis(); - //cout << "read dis MED file: filename=" << mMEDfilename << endl; - mMeshDis->readDistributedMED(mMEDfilename.c_str()); - - return getListParts(); + if (mMeshDis == NULL) throw IllegalStateException("expected a distributed MED file", __FILE__, __LINE__); + if (pPartName == NULL) throw NullArgumentException("", __FILE__, __LINE__); + if (pNbParts < 2) throw IllegalArgumentException("", __FILE__, __LINE__); + if ((pPartitionner != 0) && (pPartitionner != 1)) throw IllegalArgumentException("partitionner should be 0=METIS or 1=SCOTCH", __FILE__, __LINE__); + + // partitionneGrain() is only available for distributed MED file (not sequential MED file) + if ((mState != MULTIPR_OBJ_STATE_DIS_MEM) && + (mState != MULTIPR_OBJ_STATE_DIS)) throw IllegalStateException("unexpected operation", __FILE__, __LINE__); + + // if distributed MED file is currently in memory, then write to disk before performing partitionneGrain() + // (because MEDSPLIITER starts from a file) + if (mState == MULTIPR_OBJ_STATE_DIS_MEM) + { + //----------------------------------------------------- + // Write distributed mesh + //----------------------------------------------------- + cout << "Write distributed mesh: please wait... " << endl; + string strPrefix = removeExtension(mMEDfilename.c_str(), ".med"); + mMeshDis->writeDistributedMED(strPrefix.c_str()); + + mMEDfilename = mMeshDis->getDistributedMEDFilename(); + + delete mMeshDis; + + //--------------------------------------------------------------------- + // Read the distributed mesh + //--------------------------------------------------------------------- + int ret = MEDformatConforme(mMEDfilename.c_str()); + if (ret == 0) throw IOException("waiting for a distributed MED file (not a sequential one)", __FILE__, __LINE__); + + mMeshDis = new MeshDis(); + mMeshDis->readDistributedMED(mMEDfilename.c_str()); + + mState = MULTIPR_OBJ_STATE_DIS; + } + + //--------------------------------------------------------------------- + // Split the given part (pGroupName) + //--------------------------------------------------------------------- + mMeshDis->splitPart(pPartName, pNbParts, pPartitionner); + cout << mMeshDis << endl; + + //--------------------------------------------------------------------- + // Write new distributed mesh + //--------------------------------------------------------------------- + string strPrefix = multipr::removeExtension(mMEDfilename.c_str(), ".med"); + mMeshDis->writeDistributedMED(strPrefix.c_str()); + + //--------------------------------------------------------------------- + // Read the distributed mesh + //--------------------------------------------------------------------- + delete mMeshDis; + mMeshDis = new MeshDis(); + //cout << "read dis MED file: filename=" << mMEDfilename << endl; + mMeshDis->readDistributedMED(mMEDfilename.c_str()); + + return getListParts(); } vector Obj::decimePartition( - const char* pPartName, - const char* pFieldName, - int pFieldIt, - const char* pFilterName, - double pTmed, - double pTlow, - double pRadius, - int pBoxing) + const char* pPartName, + const char* pFieldName, + int pFieldIt, + const char* pFilterName, + double pTmed, + double pTlow, + double pRadius, + int pBoxing) { - - // decimePartition() is only available for distributed MED file (not sequential MED file) - if ((mState != MULTIPR_OBJ_STATE_DIS_MEM) && - (mState != MULTIPR_OBJ_STATE_DIS)) throw IllegalStateException("unexpected operation", __FILE__, __LINE__); - - if (mMeshDis == NULL) throw IllegalStateException("expected a distributed MED file", __FILE__, __LINE__); - - //--------------------------------------------------------------------- - // Decimate - //--------------------------------------------------------------------- - mMeshDis->decimatePart( - pPartName, - pFieldName, - pFieldIt, - pFilterName, - pTmed, - pTlow, - pRadius, - pBoxing); - - mState = MULTIPR_OBJ_STATE_DIS_MEM; - - return getListParts(); + + // decimePartition() is only available for distributed MED file (not sequential MED file) + if ((mState != MULTIPR_OBJ_STATE_DIS_MEM) && + (mState != MULTIPR_OBJ_STATE_DIS)) throw IllegalStateException("unexpected operation", __FILE__, __LINE__); + + if (mMeshDis == NULL) throw IllegalStateException("expected a distributed MED file", __FILE__, __LINE__); + + //--------------------------------------------------------------------- + // Decimate + //--------------------------------------------------------------------- + mMeshDis->decimatePart( + pPartName, + pFieldName, + pFieldIt, + pFilterName, + pTmed, + pTlow, + pRadius, + pBoxing); + + mState = MULTIPR_OBJ_STATE_DIS_MEM; + + return getListParts(); } string Obj::evalDecimationParams( - const char* pPartName, - const char* pFieldName, - int pFieldIt, - const char* pFilterName, - const char* pFilterParams) + const char* pPartName, + const char* pFieldName, + int pFieldIt, + const char* pFilterName, + const char* pFilterParams) { - // decimePartition() is only available for distributed MED file (not sequential MED file) - if ((mState != MULTIPR_OBJ_STATE_DIS_MEM) && - (mState != MULTIPR_OBJ_STATE_DIS)) throw IllegalStateException("unexpected operation", __FILE__, __LINE__); - - if (mMeshDis == NULL) throw IllegalStateException("expected a distributed MED file", __FILE__, __LINE__); - - string res = mMeshDis->evalDecimationParams( - pPartName, - pFieldName, - pFieldIt, - pFilterName, - pFilterParams); - - return res; + // decimePartition() is only available for distributed MED file (not sequential MED file) + if ((mState != MULTIPR_OBJ_STATE_DIS_MEM) && + (mState != MULTIPR_OBJ_STATE_DIS)) throw IllegalStateException("unexpected operation", __FILE__, __LINE__); + + if (mMeshDis == NULL) throw IllegalStateException("expected a distributed MED file", __FILE__, __LINE__); + + string res = mMeshDis->evalDecimationParams( + pPartName, + pFieldName, + pFieldIt, + pFilterName, + pFilterParams); + + return res; } vector Obj::getListParts() const { - if (mMeshDis == NULL) throw IllegalStateException("not a distributed mesh", __FILE__, __LINE__); - - vector names; - - int numParts = mMeshDis->getNumParts(); - for (int i = 0 ; i < numParts ; i++) - { - names.push_back( mMeshDis->getPart(i)->getPartName() ); - } - - return names; + if (mMeshDis == NULL) throw IllegalStateException("not a distributed mesh", __FILE__, __LINE__); + + vector names; + + int numParts = mMeshDis->getNumParts(); + for (int i = 0 ; i < numParts ; i++) + { + names.push_back( mMeshDis->getPart(i)->getPartName() ); + } + + return names; } void Obj::save(const char* pPath) { - static string prevPath = ""; - - // only save file if it is a distributed MED file currently in memory or path has changed - if ((mState == MULTIPR_OBJ_STATE_DIS_MEM) || (strcmp(pPath, prevPath.c_str()) != 0)) - { - prevPath = pPath; - - //------------------------------------------------------------- - // Write new distributed mesh - //------------------------------------------------------------- - string filename; - if (strlen(pPath) == 0) - { - filename = multipr::removeExtension(mMEDfilename.c_str(), ".med"); - } - else - { - filename = string(pPath) + string("/") + multipr::getFilenameWithoutPath(mMEDfilename.c_str()); - } - string strPrefix = multipr::removeExtension(filename.c_str(), ".med"); - mMeshDis->writeDistributedMED(strPrefix.c_str()); - mMEDfilename = mMeshDis->getFilename(); - - cout << "Write MED master file: " << mMEDfilename << ": OK" << endl; - - //------------------------------------------------------------- - // Read the distributed mesh - //------------------------------------------------------------- - delete mMeshDis; - mMeshDis = new MeshDis(); - mMeshDis->readDistributedMED(mMEDfilename.c_str()); - - mState = MULTIPR_OBJ_STATE_DIS; - } + static string prevPath = ""; + + // only save file if it is a distributed MED file currently in memory or path has changed + if ((mState == MULTIPR_OBJ_STATE_DIS_MEM) || (strcmp(pPath, prevPath.c_str()) != 0)) + { + prevPath = pPath; + + //------------------------------------------------------------- + // Write new distributed mesh + //------------------------------------------------------------- + string filename; + if (strlen(pPath) == 0) + { + filename = multipr::removeExtension(mMEDfilename.c_str(), ".med"); + } + else + { + filename = string(pPath) + string("/") + multipr::getFilenameWithoutPath(mMEDfilename.c_str()); + } + string strPrefix = multipr::removeExtension(filename.c_str(), ".med"); + mMeshDis->writeDistributedMED(strPrefix.c_str()); + mMEDfilename = mMeshDis->getDistributedMEDFilename(); + + cout << "Write MED master file: " << mMEDfilename << ": OK" << endl; + + //------------------------------------------------------------- + // Read the distributed mesh + //------------------------------------------------------------- + delete mMeshDis; + mMeshDis = new MeshDis(); + mMeshDis->readDistributedMED(mMEDfilename.c_str()); + + mState = MULTIPR_OBJ_STATE_DIS; + } } ostream& operator<<(ostream& pOs, Obj& pO) { - pOs << "Obj:" << endl; - pOs << " Name:" << pO.mMEDfilename << endl; - - return pOs; + pOs << "Obj:" << endl; + pOs << " Name:" << pO.mMEDfilename << endl; + + return pOs; } diff --git a/src/MULTIPR/MULTIPR_Obj.hxx b/src/MULTIPR/MULTIPR_Obj.hxx index 7d981e6..0eed384 100644 --- a/src/MULTIPR/MULTIPR_Obj.hxx +++ b/src/MULTIPR/MULTIPR_Obj.hxx @@ -37,12 +37,12 @@ class MeshDis; enum ObjState { - MULTIPR_OBJ_STATE_ERROR, - MULTIPR_OBJ_STATE_RESET, - MULTIPR_OBJ_STATE_SEQ_INIT, - MULTIPR_OBJ_STATE_SEQ, - MULTIPR_OBJ_STATE_DIS, - MULTIPR_OBJ_STATE_DIS_MEM + MULTIPR_OBJ_STATE_ERROR, + MULTIPR_OBJ_STATE_RESET, + MULTIPR_OBJ_STATE_SEQ_INIT, + MULTIPR_OBJ_STATE_SEQ, + MULTIPR_OBJ_STATE_DIS, + MULTIPR_OBJ_STATE_DIS_MEM }; // enum ObjState @@ -50,227 +50,233 @@ class Obj { public: - /** - * Builds an empty Gauss reference (default constructor). - */ - Obj(); - - /** - * Destructor. Removes everything. - */ - ~Obj(); - - /** - * Resets this object in its state by default (empty). Cleans memory. - */ - void reset(); - - /** - * Associate a MED file (sequential or distributed) with this object. - * This method also: - * - reset everything before starting - * - determine if the given file is a sequential (SEQ) or a distributed (DIS) MED file - * - read the ASCII master file if it is a distributed MED file - * - set state - */ - void create(const char* pMEDfilename); - - //--------------------------------------------------------------------- - // Basic accessors/mutators - //-------------------------------------------------------------------- - - /** - * Returns true iff this obj represents a valid sequential MED file. - * \return true iff this obj represents a valid sequential MED file. - */ - bool isValidSequentialMEDFile() const { return (mState == MULTIPR_OBJ_STATE_SEQ) || (mState == MULTIPR_OBJ_STATE_SEQ_INIT); } - - /** - * Returns true iff this obj represents a valid distributed MED file. - * \return true iff this obj represents a valid distributed MED file. - */ - bool isValidDistributedMEDFile() const { return (mState == MULTIPR_OBJ_STATE_DIS) || (mState == MULTIPR_OBJ_STATE_DIS_MEM); } - - /** - * Returns the name of the associated MED file. - * \return the name of the associated MED file. - */ - std::string getMEDFilename() const { return mMEDfilename; } - - /** - * Defines the mesh to be processed. - * \param pMeshName name of the mesh to be partitionned. - */ - void setMesh(const char* pMeshName); - - /** - * Returns the list of meshes contained in the sequential MED file. - * Assumes this object encapsulates a sequential MED file. - * \return the list of meshes contained in the sequential MED file. - */ - std::vector getMeshes() const; - - /** - * Returns the list of fields contained in the sequential MED file. - * Assumes this object encapsulates a sequential MED file. - * \return the list of fields contained in the sequential MED file. - */ - std::vector getFields() const; - - /** - * Returns the number of timestamps for a given field. - * Assumes this object encapsulates a sequential MED file. - * \param pFieldName name of any field. - * \return the number of timestamps for a given field; 0 if field not found. - */ - int getTimeStamps(const char* pFieldName) const; - - /** - * Returns the name of all partitions. - * Assumes this object encapsulates a distributed MED file. - * \return the name of all partitions. - */ - std::vector getParts() const; - - /** - * Returns all information about a part. - * \param pPartName name of the part. - * \return all information about a part. - */ - std::string getPartInfo(const char* pPartName) const; - - /** - * Removes all the part beginning by pPrefixPartName from the distributed MED file. - * Example: if pPrefixPartName="PART_4" => remove "PART_4" and all sub-parts "PART_4_*", but not "PART41". - * Assume this object encapsulates a distributed MED file. - * \param pPrefixPartName name of the part. - */ - void removeParts(const char* pPrefixPartName); - - - //--------------------------------------------------------------------- - // Algorithms - //-------------------------------------------------------------------- - - /** - * Creates a distributed MED file (v2.3) by extracting all the groups from the current mesh of the current MED sequential MED file. - * Assumes: - * - the file is in MED format and can be read using MED file v2.3. - * - the file is sequential (not a distributed MED). - * - the file only contains TETRA10 elements (dimension of space and mesh is 3). - * - the file have no profil. - * \return the name of each part. - * \throw RuntimeException if any error occurs. - */ - std::vector partitionneDomaine(); - - /** - * Creates a distributed MED file (V2.3) by splitting a group of a MED file previously created by partitionneDomaine. - * Assumes: - * - the file is a distributed MED file, previously created by partitionneDomaine() - * (=> each part only contain 1 mesh, TETRA10 elements only) - * - nbPart > 1 - * \param pPartName name of the part to be splitted. - * \param pNbParts number of parts; must be > 1. - * \param pPartitionner use value 0=MULTIPR_METIS for Metis or 1=MULTIPR_SCOTCH for Scotch. - * \return the name of each part. - * \throw RuntimeException if any error occurs. - */ - std::vector partitionneGrain( - const char* pPartName, - int pNbParts, - int pPartitionner=0); - - /** - * Creates 3 resolutions of the given part of a distributed MED file (V2.3). - * Assumes: - * - the file is a distributed MED file, previously created by partitionneDomaine() or partitionneGrain() - * (=> each part only contain 1 mesh, TETRA10 elements only) - * \param pPartName name of the part to be decimated. - * \param pFieldName name of the field used for decimation. - * \param pFieldIt iteration (time step) of the field. - * \param pFilterName name of the filter to be used. - * \param pTmed threshold used for medium resolution. - * \param pTlow threshold used for low resolution; tmed must be less than tlow - * \param pTadius radius used to determine the neighbourhood. - * \param pBoxing number of cells along each axis; must be >= 1; e.g. if 100 then acceleration grid will have 100*100*100 = 10**6 cells. - * \return the name of each part. - * \throw RuntimeException if any error occurs. - */ - std::vector decimePartition( - const char* pPartName, - const char* pFieldName, - int pFieldIt, - const char* pFilterName, - double pTmed, - double pTlow, - double pRadius, - int pBoxing); - - /** - * Returns useful information to configure decimation parameters. - * Depends on part, field and filter: generic operation. - * \param pPartName name of the part. - * \param pFieldName name of the field used for decimation. - * \param pFieldIt iteration (time step) of the field. - * \param pFilterName name of the filter to be used. - * \param pFilterParams params to be used with the filter (depends on filter; this string will be parsed). - */ - std::string evalDecimationParams( - const char* pPartName, - const char* pFieldName, - int pFieldIt, - const char* pFilterName, - const char* pFilterParams); - - - //--------------------------------------------------------------------- - // I/O - //--------------------------------------------------------------------- - - /** - * Saves the associated MED file if necessary. - * \param pPath path where to save the file. - * \throw IOException if any i/o error occurs. - */ - void save(const char* pPath); + /** + * Builds an empty Gauss reference (default constructor). + */ + Obj(); + + /** + * Destructor. Removes everything. + */ + ~Obj(); + + /** + * Resets this object in its state by default (empty). Cleans memory. + */ + void reset(); + + /** + * Associate a MED file (sequential or distributed) with this object. + * This method also: + * - reset everything before starting + * - determine if the given file is a sequential (SEQ) or a distributed (DIS) MED file + * - read the ASCII master file if it is a distributed MED file + * - set state + */ + void create(const char* pMEDfilename); + + //--------------------------------------------------------------------- + // Basic accessors/mutators + //-------------------------------------------------------------------- + + /** + * Returns true iff this obj represents a valid sequential MED file. + * \return true iff this obj represents a valid sequential MED file. + */ + bool isValidSequentialMEDFile() const { return (mState == MULTIPR_OBJ_STATE_SEQ) || (mState == MULTIPR_OBJ_STATE_SEQ_INIT); } + + /** + * Returns true iff this obj represents a valid distributed MED file. + * \return true iff this obj represents a valid distributed MED file. + */ + bool isValidDistributedMEDFile() const { return (mState == MULTIPR_OBJ_STATE_DIS) || (mState == MULTIPR_OBJ_STATE_DIS_MEM); } + + /** + * Returns the name of the associated MED file. + * \return the name of the associated MED file. + */ + std::string getMEDFilename() const { return mMEDfilename; } + + /** + * Returns the name of the associated sequential MED file. + * \return the name of the associated sequential MED file. + */ + std::string getSequentialMEDFilename() const; + + /** + * Defines the mesh to be processed. + * \param pMeshName name of the mesh to be partitionned. + */ + void setMesh(const char* pMeshName); + + /** + * Returns the list of meshes contained in the sequential MED file. + * Assumes this object encapsulates a sequential MED file. + * \return the list of meshes contained in the sequential MED file. + */ + std::vector getMeshes() const; + + /** + * Returns the list of fields contained in the sequential MED file. + * Assumes this object encapsulates a sequential MED file. + * \return the list of fields contained in the sequential MED file. + */ + std::vector getFields() const; + + /** + * Returns the number of timestamps for a given field. + * Assumes this object encapsulates a sequential MED file. + * \param pFieldName name of any field. + * \return the number of timestamps for a given field; 0 if field not found. + */ + int getTimeStamps(const char* pFieldName) const; + + /** + * Returns the name of all partitions. + * Assumes this object encapsulates a distributed MED file. + * \return the name of all partitions. + */ + std::vector getParts() const; + + /** + * Returns all information about a part. + * \param pPartName name of the part. + * \return all information about a part. + */ + std::string getPartInfo(const char* pPartName) const; + + /** + * Removes all the part beginning by pPrefixPartName from the distributed MED file. + * Example: if pPrefixPartName="PART_4" => remove "PART_4" and all sub-parts "PART_4_*", but not "PART41". + * Assume this object encapsulates a distributed MED file. + * \param pPrefixPartName name of the part. + */ + void removeParts(const char* pPrefixPartName); + + + //--------------------------------------------------------------------- + // Algorithms + //-------------------------------------------------------------------- + + /** + * Creates a distributed MED file (v2.3) by extracting all the groups from the current mesh of the current MED sequential MED file. + * Assumes: + * - the file is in MED format and can be read using MED file v2.3. + * - the file is sequential (not a distributed MED). + * - the file only contains TETRA10 elements (dimension of space and mesh is 3). + * - the file have no profil. + * \return the name of each part. + * \throw RuntimeException if any error occurs. + */ + std::vector partitionneDomaine(); + + /** + * Creates a distributed MED file (V2.3) by splitting a group of a MED file previously created by partitionneDomaine. + * Assumes: + * - the file is a distributed MED file, previously created by partitionneDomaine() + * (=> each part only contain 1 mesh, TETRA10 elements only) + * - nbPart > 1 + * \param pPartName name of the part to be splitted. + * \param pNbParts number of parts; must be > 1. + * \param pPartitionner use value 0=MULTIPR_METIS for Metis or 1=MULTIPR_SCOTCH for Scotch. + * \return the name of each part. + * \throw RuntimeException if any error occurs. + */ + std::vector partitionneGrain( + const char* pPartName, + int pNbParts, + int pPartitionner=0); + + /** + * Creates 3 resolutions of the given part of a distributed MED file (V2.3). + * Assumes: + * - the file is a distributed MED file, previously created by partitionneDomaine() or partitionneGrain() + * (=> each part only contain 1 mesh, TETRA10 elements only) + * \param pPartName name of the part to be decimated. + * \param pFieldName name of the field used for decimation. + * \param pFieldIt iteration (time step) of the field. + * \param pFilterName name of the filter to be used. + * \param pTmed threshold used for medium resolution. + * \param pTlow threshold used for low resolution; tmed must be less than tlow + * \param pTadius radius used to determine the neighbourhood. + * \param pBoxing number of cells along each axis; must be >= 1; e.g. if 100 then acceleration grid will have 100*100*100 = 10**6 cells. + * \return the name of each part. + * \throw RuntimeException if any error occurs. + */ + std::vector decimePartition( + const char* pPartName, + const char* pFieldName, + int pFieldIt, + const char* pFilterName, + double pTmed, + double pTlow, + double pRadius, + int pBoxing); + + /** + * Returns useful information to configure decimation parameters. + * Depends on part, field and filter: generic operation. + * \param pPartName name of the part. + * \param pFieldName name of the field used for decimation. + * \param pFieldIt iteration (time step) of the field. + * \param pFilterName name of the filter to be used. + * \param pFilterParams params to be used with the filter (depends on filter; this string will be parsed). + */ + std::string evalDecimationParams( + const char* pPartName, + const char* pFieldName, + int pFieldIt, + const char* pFilterName, + const char* pFilterParams); + + + //--------------------------------------------------------------------- + // I/O + //--------------------------------------------------------------------- + + /** + * Saves the associated MED file if necessary. + * \param pPath path where to save the file. + * \throw IOException if any i/o error occurs. + */ + void save(const char* pPath); - /** - * Dumps any Obj to the given output stream. - * \param pOs any output stream. - * \param pO any Obj. - * \return the output stream pOs. - */ - friend std::ostream& operator<<(std::ostream& pOs, Obj& pO); - + /** + * Dumps any Obj to the given output stream. + * \param pOs any output stream. + * \param pO any Obj. + * \return the output stream pOs. + */ + friend std::ostream& operator<<(std::ostream& pOs, Obj& pO); + private: - /** - * Returns the list of parts contained in the current distributed mesh. - * \return the list of parts contained in the current distributed mesh. - * \throw IllegalStateException if the distributed mesh does not still exist. - */ - std::vector getListParts() const; + /** + * Returns the list of parts contained in the current distributed mesh. + * \return the list of parts contained in the current distributed mesh. + * \throw IllegalStateException if the distributed mesh does not still exist. + */ + std::vector getListParts() const; private: - - std::string mMEDfilename; /**< Name of the MED file: sequential or distributed. */ - std::string mMeshName; /**< Mesh to be partitionned. */ - ObjState mState; /**< State of this object. */ - MeshDis* mMeshDis; /**< Distributed mesh. */ - - + + std::string mMEDfilename; /**< Name of the MED file: sequential or distributed. */ + std::string mMeshName; /**< Mesh to be partitionned. */ + ObjState mState; /**< State of this object. */ + MeshDis* mMeshDis; /**< Distributed mesh. */ + + private: - - // do not allow copy constructor - Obj(const Obj&); - - // do not allow copy - Obj& operator=(const Obj&); - - // do not allow operator == - bool operator==(const Obj&); - + + // do not allow copy constructor + Obj(const Obj&); + + // do not allow copy + Obj& operator=(const Obj&); + + // do not allow operator == + bool operator==(const Obj&); + }; // class Obj diff --git a/src/MULTIPR/MULTIPR_PointOfField.hxx b/src/MULTIPR/MULTIPR_PointOfField.hxx index 907aab4..bcf3406 100644 --- a/src/MULTIPR/MULTIPR_PointOfField.hxx +++ b/src/MULTIPR/MULTIPR_PointOfField.hxx @@ -20,7 +20,7 @@ extern "C" { - #include "med.h" + #include "med.h" } @@ -36,59 +36,59 @@ class PointOfField { public: - /** - * Builds an empty set of elements (default constructor). - */ - PointOfField() { reset(); } - - /** - * Constructor. - * \param pX x-coordinate of the point. - * \param pY y-coordinate of the point. - * \param pZ z-coordinate of the point. - * \param pVal value of the field at the given point. - */ - PointOfField(med_float pX, med_float pY, med_float pZ, med_float pVal) - { - mXYZ[0] = pX; - mXYZ[1] = pY; - mXYZ[2] = pZ; - mVal = pVal; - } - - /** - * Destructor. Removes everything. - */ - ~PointOfField() { reset(); } - - /** - * Resets this object in its state by default (empty). - */ - void reset() - { - mXYZ[0] = std::numeric_limits::quiet_NaN(); - mXYZ[1] = std::numeric_limits::quiet_NaN(); - mXYZ[2] = std::numeric_limits::quiet_NaN(); - mVal = std::numeric_limits::quiet_NaN(); - } - - /** - * Dumps any PointOfField to the given output stream. - * \param pOs any output stream. - * \param pP any PointOfField. - * \return the output stream pOs. - */ - friend std::ostream& operator<<(std::ostream& pOs, PointOfField& pP) - { - pOs << "[ " << pP.mXYZ[0] << " ; " << pP.mXYZ[1] << " ; " << pP.mXYZ[2] << "]: " << pP.mVal; - return pOs; - } + /** + * Builds an empty set of elements (default constructor). + */ + PointOfField() { reset(); } + + /** + * Constructor. + * \param pX x-coordinate of the point. + * \param pY y-coordinate of the point. + * \param pZ z-coordinate of the point. + * \param pVal value of the field at the given point. + */ + PointOfField(med_float pX, med_float pY, med_float pZ, med_float pVal) + { + mXYZ[0] = pX; + mXYZ[1] = pY; + mXYZ[2] = pZ; + mVal = pVal; + } + + /** + * Destructor. Removes everything. + */ + ~PointOfField() { reset(); } + + /** + * Resets this object in its state by default (empty). + */ + void reset() + { + mXYZ[0] = std::numeric_limits::quiet_NaN(); + mXYZ[1] = std::numeric_limits::quiet_NaN(); + mXYZ[2] = std::numeric_limits::quiet_NaN(); + mVal = std::numeric_limits::quiet_NaN(); + } + + /** + * Dumps any PointOfField to the given output stream. + * \param pOs any output stream. + * \param pP any PointOfField. + * \return the output stream pOs. + */ + friend std::ostream& operator<<(std::ostream& pOs, PointOfField& pP) + { + pOs << "[ " << pP.mXYZ[0] << " ; " << pP.mXYZ[1] << " ; " << pP.mXYZ[2] << "]: " << pP.mVal; + return pOs; + } public: - med_float mXYZ[3]; /**< 3D-position. */ - med_float mVal; /**< Value of the field on this point. */ - + med_float mXYZ[3]; /**< 3D-position. */ + med_float mVal; /**< Value of the field at this point. */ + }; // class PointOfField diff --git a/src/MULTIPR/MULTIPR_Profil.cxx b/src/MULTIPR/MULTIPR_Profil.cxx index 89dfea4..4a7f8b0 100644 --- a/src/MULTIPR/MULTIPR_Profil.cxx +++ b/src/MULTIPR/MULTIPR_Profil.cxx @@ -33,125 +33,125 @@ namespace multipr Profil::Profil() { - reset(); + reset(); } Profil::~Profil() { - reset(); + reset(); } void Profil::reset() { - mName[0] = '\0'; - mTable.clear(); + mName[0] = '\0'; + mTable.clear(); } void Profil::create(const char* pName) { - if (pName == NULL) throw NullArgumentException("", __FILE__, __LINE__); - - reset(); - strcpy(mName, pName); + if (pName == NULL) throw NullArgumentException("", __FILE__, __LINE__); + + reset(); + strcpy(mName, pName); } const char* Profil::getName() const { - return mName; + return mName; } med_int Profil::get(med_int pIndex) const { - if ((pIndex < 0) || (pIndex >= med_int(mTable.size()))) throw IndexOutOfBoundsException("", __FILE__, __LINE__); - - return mTable[pIndex]; + if ((pIndex < 0) || (pIndex >= med_int(mTable.size()))) throw IndexOutOfBoundsException("", __FILE__, __LINE__); + + return mTable[pIndex]; } void Profil::add(med_int pElt) { - mTable.push_back(pElt); + mTable.push_back(pElt); } void Profil::readMED(med_idt pMEDfile, med_int pIndexProfil) { - if (pMEDfile == 0) throw IOException("", __FILE__, __LINE__); - if (pIndexProfil < 1) throw IllegalArgumentException("", __FILE__, __LINE__); - - reset(); - - med_int numData; - med_err ret = MEDprofilInfo( - pMEDfile, - pIndexProfil, - mName, - &numData); - - if (ret != 0) throw IOException("", __FILE__, __LINE__); - - med_int* dataTmp = new med_int[numData]; - - ret = MEDprofilLire( - pMEDfile, - dataTmp, - mName); - - if (ret != 0) throw IOException("", __FILE__, __LINE__); - - for (int itData = 0 ; itData < numData ; itData++) - { - mTable.push_back(dataTmp[itData]); - } - - delete[] dataTmp; + if (pMEDfile == 0) throw IOException("", __FILE__, __LINE__); + if (pIndexProfil < 1) throw IllegalArgumentException("", __FILE__, __LINE__); + + reset(); + + med_int numData; + med_err ret = MEDprofilInfo( + pMEDfile, + pIndexProfil, + mName, + &numData); + + if (ret != 0) throw IOException("", __FILE__, __LINE__); + + med_int* dataTmp = new med_int[numData]; + + ret = MEDprofilLire( + pMEDfile, + dataTmp, + mName); + + if (ret != 0) throw IOException("", __FILE__, __LINE__); + + for (int itData = 0 ; itData < numData ; itData++) + { + mTable.push_back(dataTmp[itData]); + } + + delete[] dataTmp; } void Profil::writeMED(med_idt pMEDfile) { - if (pMEDfile == 0) throw IOException("", __FILE__, __LINE__); - if (strlen(mName) > MED_TAILLE_NOM) throw IllegalStateException("", __FILE__, __LINE__); - if (mTable.size() == 0) throw IllegalStateException("", __FILE__, __LINE__); - - med_int* dataTmp = new med_int[mTable.size()]; - for (unsigned itData = 0 ; itData < mTable.size() ; itData++) - { - dataTmp[itData] = mTable[itData]; - } - - med_err ret = MEDprofilEcr( - pMEDfile, - dataTmp, - mTable.size(), - mName); - - if (ret != 0) throw IOException("", __FILE__, __LINE__); - - delete[] dataTmp; + if (pMEDfile == 0) throw IOException("", __FILE__, __LINE__); + if (strlen(mName) > MED_TAILLE_NOM) throw IllegalStateException("", __FILE__, __LINE__); + if (mTable.size() == 0) throw IllegalStateException("", __FILE__, __LINE__); + + med_int* dataTmp = new med_int[mTable.size()]; + for (unsigned itData = 0 ; itData < mTable.size() ; itData++) + { + dataTmp[itData] = mTable[itData]; + } + + med_err ret = MEDprofilEcr( + pMEDfile, + dataTmp, + mTable.size(), + mName); + + if (ret != 0) throw IOException("", __FILE__, __LINE__); + + delete[] dataTmp; } ostream& operator<<(ostream& pOs, Profil& pP) { - pOs << "Profil:" << endl; - pOs << " Name=|" << pP.mName << "|" << endl; - pOs << " Size=" << pP.mTable.size() << endl; - - pOs << " Entities=["; - for (unsigned itElt = 0; itElt < pP.mTable.size() ; itElt++) - { - pOs << pP.mTable[itElt] << " "; - } - pOs << "]"; - - return pOs; + pOs << "Profil:" << endl; + pOs << " Name=|" << pP.mName << "|" << endl; + pOs << " Size=" << pP.mTable.size() << endl; + + pOs << " Entities=["; + for (unsigned itElt = 0; itElt < pP.mTable.size() ; itElt++) + { + pOs << pP.mTable[itElt] << " "; + } + pOs << "]"; + + return pOs; } diff --git a/src/MULTIPR/MULTIPR_Profil.hxx b/src/MULTIPR/MULTIPR_Profil.hxx index 6a12b25..d070cd3 100644 --- a/src/MULTIPR/MULTIPR_Profil.hxx +++ b/src/MULTIPR/MULTIPR_Profil.hxx @@ -22,7 +22,7 @@ extern "C" { - #include "med.h" + #include "med.h" } #include @@ -40,95 +40,95 @@ class Profil { public: - /** - * Builds an empty profil (default constructor). - */ - Profil(); - - /** - * Destructor. Removes everything. - */ - ~Profil(); - - /** - * Resets this object in its state by default (empty). Cleans memory. - */ - void reset(); - - /** - * Creates a profil from its name (reset before). - * \param pName name of the profil to be created. - * \throw NullArgumentException if pName is NULL. - */ - void create(const char* pName); - - //--------------------------------------------------------------------- - // Basic accessors/mutators - //--------------------------------------------------------------------- - - /** - * Returns the name of this profil. - * \return the name of this profil. - */ - const char* getName() const; - - /** - * Returns the nth elements of this profil. - * \param pIndex index of the element to get; must be in [0..NUMBER_OF_ELEMENTS-1]. - * \return the nth elements of this profil. - * \throw IndexOutOfBoundsException if index is invalid. - */ - med_int get(med_int pIndex) const; - - /** - * Adds a new element to this profil. - * \param pElt element to be added; must be >= 1. - */ - void add(med_int pElt); - - //--------------------------------------------------------------------- - // I/O - //--------------------------------------------------------------------- - - /** - * Reads a Profil from a MED file. - * \param pMEDfile any valid MED file opened for reading. - * \param pIndexProfil index of the profil to be read; must be >= 1. - * \throw IOException if any i/o error occurs. - */ - void readMED(med_idt pMEDfile, med_int pIndexProfil); - - /** - * Writes this profil to a MED file. - * \param pMEDfile any valid MED file opened for writing. - * \throw IOException if any i/o error occurs. - */ - void writeMED(med_idt pMEDfile); - - /** - * Dumps any Profil to the given output stream. - * \param pOs any output stream. - * \param pP any Profil. - * \return the output stream pOs. - */ - friend std::ostream& operator<<(std::ostream& pOs, Profil& pP); - + /** + * Builds an empty profil (default constructor). + */ + Profil(); + + /** + * Destructor. Removes everything. + */ + ~Profil(); + + /** + * Resets this object in its state by default (empty). Cleans memory. + */ + void reset(); + + /** + * Creates a profil from its name (reset before). + * \param pName name of the profil to be created. + * \throw NullArgumentException if pName is NULL. + */ + void create(const char* pName); + + //--------------------------------------------------------------------- + // Basic accessors/mutators + //--------------------------------------------------------------------- + + /** + * Returns the name of this profil. + * \return the name of this profil. + */ + const char* getName() const; + + /** + * Returns the nth elements of this profil. + * \param pIndex index of the element to get; must be in [0..NUMBER_OF_ELEMENTS-1]. + * \return the nth elements of this profil. + * \throw IndexOutOfBoundsException if index is invalid. + */ + med_int get(med_int pIndex) const; + + /** + * Adds a new element to this profil. + * \param pElt element to be added; must be >= 1. + */ + void add(med_int pElt); + + //--------------------------------------------------------------------- + // I/O + //--------------------------------------------------------------------- + + /** + * Reads a Profil from a MED file. + * \param pMEDfile any valid MED file opened for reading. + * \param pIndexProfil index of the profil to be read; must be >= 1. + * \throw IOException if any i/o error occurs. + */ + void readMED(med_idt pMEDfile, med_int pIndexProfil); + + /** + * Writes this profil to a MED file. + * \param pMEDfile any valid MED file opened for writing. + * \throw IOException if any i/o error occurs. + */ + void writeMED(med_idt pMEDfile); + + /** + * Dumps any Profil to the given output stream. + * \param pOs any output stream. + * \param pP any Profil. + * \return the output stream pOs. + */ + friend std::ostream& operator<<(std::ostream& pOs, Profil& pP); + private: - - char mName[MED_TAILLE_NOM + 1]; /**< Name of the profil. */ - std::vector mTable; /**< Table of elements. */ - + + char mName[MED_TAILLE_NOM + 1]; /**< Name of the profil. */ + std::vector mTable; /**< Table of elements. */ + private: - // do not allow copy constructor - Profil(const Profil&); - - // do not allow copy - Profil& operator=(const Profil&); - - // do not allow operator == - bool operator==(const Profil&); - + // do not allow copy constructor + Profil(const Profil&); + + // do not allow copy + Profil& operator=(const Profil&); + + // do not allow operator == + bool operator==(const Profil&); + }; // class Profil diff --git a/src/MULTIPR/MULTIPR_ProgressCallback.hxx b/src/MULTIPR/MULTIPR_ProgressCallback.hxx index f8e0ff6..7193708 100644 --- a/src/MULTIPR/MULTIPR_ProgressCallback.hxx +++ b/src/MULTIPR/MULTIPR_ProgressCallback.hxx @@ -27,56 +27,84 @@ class MULTIPR_ProgressCallback { public: - - /** - * Builds a new MULTIPR_ProgressCallback (default constructor). - */ - MULTIPR_ProgressCallback() { init(100); } - - /** - * Destructor. Removes everything. - */ - ~MULTIPR_ProgressCallback() { /* do nothing */ } - - /** - * Starts to provide feedback on the progress of a slow operation. - * \param pTaskTitle name of the task to be monitored. - * \param pNumSteps number of steps in the task. - */ - virtual void start(const char* pTaskTitle, int pNumSteps) = 0; - - /** - * Moves on the current amount of progress made. - */ - void moveOn() { mCurrentStep++; float percent = float(mCurrentStep)/float(mTotalSteps)*100.0f; progress(percent); } - - /** - * Termines to provide feedback. - */ - virtual void done() = 0; - + + /** + * Builds a new MULTIPR_ProgressCallback (default constructor). + */ + MULTIPR_ProgressCallback() { init(100); } + + /** + * Destructor. Removes everything. + */ + ~MULTIPR_ProgressCallback() { /* do nothing */ } + + /** + * Starts to provide feedback on the progress of a slow operation. + * \param pTaskTitle name of the task to be monitored. + * \param pNumSteps number of steps in the task. + */ + virtual void start(const char* pTaskTitle, int pNumSteps) = 0; + + /** + * Moves on the current amount of progress made. + */ + void moveOn() { mCurrentStep++; float percent = float(mCurrentStep)/float(mTotalSteps)*100.0f; progress(percent); } + + /** + * Termines to provide feedback. + */ + virtual void done() = 0; + protected: - - /** - * Resets this progress callback. - * \param pNumSteps number of steps in the task to be monitored. - */ - void init(int pNumSteps) { mCurrentStep = 0; mTotalSteps = pNumSteps; } - - /** - * Callback. Called on each progress. - * \param pPercent percent accomplished. - */ - virtual void progress(float pPercent) = 0; + + /** + * Resets this progress callback. + * \param pNumSteps number of steps in the task to be monitored. + */ + void init(int pNumSteps) { mCurrentStep = 0; mTotalSteps = pNumSteps; } + + /** + * Callback. Called on each progress. + * \param pPercent percent accomplished. + */ + virtual void progress(float pPercent) = 0; private: - int mCurrentStep; - int mTotalSteps; - + int mCurrentStep; + int mTotalSteps; + }; // class MULTIPR_ProgressCallback +//***************************************************************************** +// Class MULTIPR_EmptyMeshCallback +// Used to provide feedback when an empty mesh is produced. +//***************************************************************************** + +class MULTIPR_EmptyMeshCallback +{ +public: + + /** + * Builds a new MULTIPR_EmptyMeshCallback (default constructor). + */ + MULTIPR_EmptyMeshCallback() { /* do nothing */ } + + /** + * Destructor. Removes everything. + */ + ~MULTIPR_EmptyMeshCallback() { /* do nothing */ } + + /** + * Callback. Called each time an empty mesh is produced. + * \param pInfo information related to the empty mesh. + */ + virtual void reportEmptyMesh(std::string pInfo) = 0; + +}; // class MULTIPR_EmptyMeshCallback + + #endif // MULTIPR_PROGRESS_CALLBACK_HXX // EOF diff --git a/src/MULTIPR/MULTIPR_Utils.cxx b/src/MULTIPR/MULTIPR_Utils.cxx index a5f9f0c..194aced 100644 --- a/src/MULTIPR/MULTIPR_Utils.cxx +++ b/src/MULTIPR/MULTIPR_Utils.cxx @@ -29,271 +29,280 @@ using namespace std; void multipr::trim(char* pStr, char pChar) { - int len = strlen(pStr) - 1; - int p = len; - while (pStr[p] == pChar) - { - p--; - } - if (p != len) - { - pStr[p + 1] = '\0'; - } + int len = strlen(pStr) - 1; + int p = len; + while (pStr[p] == pChar) + { + p--; + } + if (p != len) + { + pStr[p + 1] = '\0'; + } } bool multipr::startsWith(const char* pStr, const char* pStrPrefix) { - int i = 0; - while ((pStr[i] != '\0') && (pStrPrefix[i] != '\0') && (pStr[i] == pStrPrefix[i])) - { - i++; - } - return (pStrPrefix[i] == '\0'); + int i = 0; + while ((pStr[i] != '\0') && (pStrPrefix[i] != '\0') && (pStr[i] == pStrPrefix[i])) + { + i++; + } + return (pStrPrefix[i] == '\0'); } string multipr::removeExtension(const char* pFilename, const char* pExtension) { - string strPrefix(pFilename); - strPrefix.erase(strPrefix.rfind(pExtension), strlen(pExtension)); - - return strPrefix; + string strPrefix(pFilename); + strPrefix.erase(strPrefix.rfind(pExtension), strlen(pExtension)); + + return strPrefix; } string multipr::getFilenameWithoutPath(const char* pFilename) { - char* res = strrchr(pFilename, '/'); - if (res == NULL) - { - return pFilename; - } - else - { - char* name = res + 1; - return name; - } + char* res = strrchr(pFilename, '/'); + if (res == NULL) + { + return pFilename; + } + else + { + char* name = res + 1; + return name; + } } string multipr::getPath(const char* pFilename) { - char* res = strrchr(pFilename, '/'); - if (res == NULL) - { - return ""; - } - else - { - int size = res - pFilename + 1; - char path[256]; - memcpy(path, pFilename, size); - path[size] = '\0'; - return path; - } + // find (reverse) the first occurrence of '/' in the given string + char* res = strrchr(pFilename, '/'); + + // if there is no '/'... + if (res == NULL) + { + return ""; + } + else + { + int size = res - pFilename + 1; + char path[256]; + memcpy(path, pFilename, size); + path[size] = '\0'; + return path; + } } void multipr::copyFile(const char* pFilename, const char* pDestDir) { - const char* srcDir = multipr::getPath(pFilename).c_str(); - if (strcmp(srcDir, pDestDir) == 0) return; - - const char* filenameWithoutPath = multipr::getFilenameWithoutPath(pFilename).c_str(); - char pDstFilename[256]; - sprintf(pDstFilename, "%s%s", pDestDir, filenameWithoutPath); - - FILE* src = fopen(pFilename, "rb"); - if (src == NULL) return; - FILE* dst = fopen(pDstFilename, "wb"); - if (dst == NULL) return; - - const int size = 65536; - char* buf = new char[size]; - int ret; - ret = fread(buf, 1, size, src); - while (ret != 0) - { - fwrite(buf, 1, ret, dst); - ret = fread(buf, 1, size, src); - } - - delete[] buf; - fclose(src); - fclose(dst); + const char* srcDir = multipr::getPath(pFilename).c_str(); + if (strcmp(srcDir, pDestDir) == 0) return; + + const char* filenameWithoutPath = multipr::getFilenameWithoutPath(pFilename).c_str(); + char pDstFilename[256]; + sprintf(pDstFilename, "%s%s", pDestDir, filenameWithoutPath); + + // open binary source file + FILE* src = fopen(pFilename, "rb"); + if (src == NULL) return; + + // open (create) binary destination file + FILE* dst = fopen(pDstFilename, "wb"); + if (dst == NULL) return; + + const int size = 65536; // size of buffer is 64Kb + char* buf = new char[size]; + int ret; + ret = fread(buf, 1, size, src); + while (ret != 0) + { + fwrite(buf, 1, ret, dst); // write to destination + ret = fread(buf, 1, size, src); // read from source + } + + delete[] buf; + fclose(src); + fclose(dst); } void multipr::printArray2D( - const med_float* pData, - const int pNumElt, - const int pDimElt, - const char* pPrefix) + const med_float* pData, + const int pNumElt, + const int pDimElt, + const char* pPrefix) { - for (int itElt = 0 ; itElt < pNumElt ; itElt++) - { - cout << pPrefix << " " << (itElt + 1) << ": "; - for (int itDim = 0 ; itDim < pDimElt ; itDim++) - { - cout << pData[itElt * pDimElt + itDim] << " "; - } - cout << endl; - } + for (int itElt = 0 ; itElt < pNumElt ; itElt++) + { + cout << pPrefix << " " << (itElt + 1) << ": "; + for (int itDim = 0 ; itDim < pDimElt ; itDim++) + { + cout << pData[itElt * pDimElt + itDim] << " "; + } + cout << endl; + } } string multipr::realToString(med_float mV) { - char str[32]; - sprintf(str, "%lf", mV); - trim(str, '0'); - int len = strlen(str); - if (str[len - 1] == '.') - { - str[len] = '0'; - str[len + 1] = '\0'; - } - return string(str); + char str[32]; + sprintf(str, "%lf", mV); + trim(str, '0'); + int len = strlen(str); + if (str[len - 1] == '.') + { + str[len] = '0'; + str[len + 1] = '\0'; + } + return string(str); } vector multipr::getListMeshes(const char* pMEDfilename) { - if (pMEDfilename == NULL) throw multipr::NullArgumentException("", __FILE__, __LINE__); - - vector res; - med_err ret; - - //--------------------------------------------------------------------- - // Open MED file (READ_ONLY) - //--------------------------------------------------------------------- - med_idt file = MEDouvrir(const_cast(pMEDfilename), MED_LECTURE); // open MED file for reading - if (file <= 0) throw multipr::IOException("MED file not found or not a sequential MED file", __FILE__, __LINE__); - - //--------------------------------------------------------------------- - // Read name of meshes - //--------------------------------------------------------------------- - med_int nbMeshes = MEDnMaa(file); - if (nbMeshes <= 0) throw multipr::IOException("i/o error while reading number of meshes in MED file", __FILE__, __LINE__); - - // for each mesh in the file (warning: first mesh is number 1) - for (int itMesh = 1 ; itMesh <= nbMeshes ; itMesh++) - { - char meshName[MED_TAILLE_NOM + 1]; - - int meshDim; - med_maillage meshType; - char meshDesc[MED_TAILLE_DESC + 1]; - - ret = MEDmaaInfo( - file, - itMesh, - meshName, - &meshDim, - &meshType, - meshDesc); - - if (ret != 0) throw multipr::IOException("i/o error while reading mesh information in MED file", __FILE__, __LINE__); - - res.push_back(meshName); - } - - //--------------------------------------------------------------------- - // Close the MED file - //--------------------------------------------------------------------- - ret = MEDfermer(file); - if (ret != 0) throw multipr::IOException("i/o error while closing MED file", __FILE__, __LINE__); - - return res; + if (pMEDfilename == NULL) throw multipr::NullArgumentException("", __FILE__, __LINE__); + + vector res; + med_err ret; + + //--------------------------------------------------------------------- + // Open MED file (READ_ONLY) + //--------------------------------------------------------------------- + med_idt file = MEDouvrir(const_cast(pMEDfilename), MED_LECTURE); // open MED file for reading + if (file <= 0) throw multipr::IOException("MED file not found or not a sequential MED file", __FILE__, __LINE__); + + //--------------------------------------------------------------------- + // Read name of meshes + //--------------------------------------------------------------------- + med_int nbMeshes = MEDnMaa(file); + if (nbMeshes <= 0) throw multipr::IOException("i/o error while reading number of meshes in MED file", __FILE__, __LINE__); + + // for each mesh in the file (warning: first mesh is number 1) + for (int itMesh = 1 ; itMesh <= nbMeshes ; itMesh++) + { + char meshName[MED_TAILLE_NOM + 1]; + + int meshDim; + med_maillage meshType; + char meshDesc[MED_TAILLE_DESC + 1]; + + ret = MEDmaaInfo( + file, + itMesh, + meshName, + &meshDim, + &meshType, + meshDesc); + + if (ret != 0) throw multipr::IOException("i/o error while reading mesh information in MED file", __FILE__, __LINE__); + + res.push_back(meshName); + } + + //--------------------------------------------------------------------- + // Close the MED file + //--------------------------------------------------------------------- + ret = MEDfermer(file); + if (ret != 0) throw multipr::IOException("i/o error while closing MED file", __FILE__, __LINE__); + + return res; } vector > multipr::getListScalarFields(const char* pMEDfilename) { - if (pMEDfilename == NULL) throw multipr::NullArgumentException("", __FILE__, __LINE__); - - vector > res; - med_err ret; - - //--------------------------------------------------------------------- - // Open MED file (READ_ONLY) - //--------------------------------------------------------------------- - med_idt file = MEDouvrir(const_cast(pMEDfilename), MED_LECTURE); // open MED file for reading - if (file <= 0) throw multipr::IOException("MED file not found or not a sequential MED file", __FILE__, __LINE__); - - //--------------------------------------------------------------------- - // Read number of fields - //--------------------------------------------------------------------- - med_int numFields = MEDnChamp(file, 0); - if (numFields <= 0) throw IOException("", __FILE__, __LINE__); - - //--------------------------------------------------------------------- - // For each field, read its name - //--------------------------------------------------------------------- - for (int itField = 1 ; itField <= numFields ; itField++) - { - char name[MED_TAILLE_NOM + 1]; - med_type_champ type; - - med_int numComponents = MEDnChamp(file, itField); - - if (numComponents < 0) throw IOException("", __FILE__, __LINE__); - - // collect scalar field only (not vectorial fields) - if (numComponents != 1) - continue; - - char* strComponent = new char[numComponents * MED_TAILLE_PNOM + 1]; - char* strUnit = new char[numComponents * MED_TAILLE_PNOM + 1]; - - strComponent[0] = '\0'; - strUnit[0] = '\0'; - - med_err ret = MEDchampInfo( - file, - itField, - name, - &(type), - strComponent, - strUnit, - numComponents); - - if (ret != 0) throw IOException("", __FILE__, __LINE__); - - delete[] strUnit; - delete[] strComponent; - - med_int numTimeStep = MEDnPasdetemps( - file, - name, - MED_NOEUD, - (med_geometrie_element) 0); - - if (numTimeStep < 0) throw IOException("", __FILE__, __LINE__); - - if (numTimeStep == 0) - { - numTimeStep = MEDnPasdetemps( - file, - name, - MED_MAILLE, - MED_TETRA10); - - if (numTimeStep < 0) throw IOException("", __FILE__, __LINE__); - - } - - res.push_back(make_pair(name, numTimeStep)); - } - - //--------------------------------------------------------------------- - // Close the MED file - //--------------------------------------------------------------------- - ret = MEDfermer(file); - if (ret != 0) throw multipr::IOException("i/o error while closing MED file", __FILE__, __LINE__); - - return res; + if (pMEDfilename == NULL) throw multipr::NullArgumentException("", __FILE__, __LINE__); + + vector > res; + med_err ret; + + //--------------------------------------------------------------------- + // Open MED file (READ_ONLY) + //--------------------------------------------------------------------- + med_idt file = MEDouvrir(const_cast(pMEDfilename), MED_LECTURE); // open MED file for reading + if (file <= 0) throw multipr::IOException("MED file not found or not a sequential MED file", __FILE__, __LINE__); + + //--------------------------------------------------------------------- + // Read number of fields + //--------------------------------------------------------------------- + med_int numFields = MEDnChamp(file, 0); + if (numFields <= 0) throw IOException("", __FILE__, __LINE__); + + //--------------------------------------------------------------------- + // For each field, read its name + //--------------------------------------------------------------------- + for (int itField = 1 ; itField <= numFields ; itField++) + { + char name[MED_TAILLE_NOM + 1]; + med_type_champ type; + + med_int numComponents = MEDnChamp(file, itField); + + if (numComponents < 0) throw IOException("", __FILE__, __LINE__); + + // collect scalar field only (not vectorial fields) + if (numComponents != 1) + continue; + + // temporary buffers + char* strComponent = new char[numComponents * MED_TAILLE_PNOM + 1]; + char* strUnit = new char[numComponents * MED_TAILLE_PNOM + 1]; + + strComponent[0] = '\0'; + strUnit[0] = '\0'; + + med_err ret = MEDchampInfo( + file, + itField, + name, + &(type), + strComponent, + strUnit, + numComponents); + + if (ret != 0) throw IOException("", __FILE__, __LINE__); + + delete[] strUnit; + delete[] strComponent; + + med_int numTimeStamps = MEDnPasdetemps( + file, + name, + MED_NOEUD, + (med_geometrie_element) 0); + + if (numTimeStamps < 0) throw IOException("", __FILE__, __LINE__); + + if (numTimeStamps == 0) + { + numTimeStamps = MEDnPasdetemps( + file, + name, + MED_MAILLE, + MED_TETRA10); + + if (numTimeStamps < 0) throw IOException("", __FILE__, __LINE__); + + } + + // add the pair(name, #time stamps) to the result + res.push_back( make_pair(name, numTimeStamps) ); + } + + //--------------------------------------------------------------------- + // Close the MED file + //--------------------------------------------------------------------- + ret = MEDfermer(file); + if (ret != 0) throw multipr::IOException("i/o error while closing MED file", __FILE__, __LINE__); + + // return the list of fields + return res; } diff --git a/src/MULTIPR/MULTIPR_Utils.hxx b/src/MULTIPR/MULTIPR_Utils.hxx index d6b0640..46362e7 100644 --- a/src/MULTIPR/MULTIPR_Utils.hxx +++ b/src/MULTIPR/MULTIPR_Utils.hxx @@ -16,7 +16,7 @@ extern "C" { - #include "med.h" + #include "med.h" } #include @@ -75,7 +75,7 @@ std::string getPath(const char* pFilename); /** * Copies the given file into a directory. - * \param pFilename file to be copied. + * \param pFilename name of any file to be copied. * \param pDestDir destination directory. */ void copyFile(const char* pFilename, const char* pDestDir); @@ -89,11 +89,11 @@ void copyFile(const char* pFilename, const char* pDestDir); * \param pPrefix string to display before each element. */ void printArray2D( - const med_float* pData, - const int pNumElt, - const int pDimElt, - const char* pPrefix); - + const med_float* pData, + const int pNumElt, + const int pDimElt, + const char* pPrefix); + /** * Converts any float value to a string (remove unecessary 0). @@ -113,14 +113,14 @@ std::string realToString(med_float mV); /** - * For each scalar field in a sequential MED file, returns its name and the related number of iterations. + * For each scalar field in a sequential MED file, returns its name and the related number of time stamps. * Do not returns info about vectorial fields (because, currently, decimation can only be performed on scalar fields). * \param pMEDfilename name of any valid sequential MED file; must not be NULL. - * \return a list of (name, #iterations). + * \return a list of (name, #time stamps). * \throw NullArgumentException if pMEDfilename is NULL. * \throw IOException if any other error occurs while reading MED file. */ - std::vector > getListScalarFields(const char* pMEDfilename); + std::vector< std::pair > getListScalarFields(const char* pMEDfilename); } // namespace MULTIPR diff --git a/src/MULTIPR/MULTIPR_i.cxx b/src/MULTIPR/MULTIPR_i.cxx index a8eff22..e45c3e7 100644 --- a/src/MULTIPR/MULTIPR_i.cxx +++ b/src/MULTIPR/MULTIPR_i.cxx @@ -32,16 +32,16 @@ using namespace std; //***************************************************************************** MULTIPR_Gen_i::MULTIPR_Gen_i( - CORBA::ORB_ptr orb, - PortableServer::POA_ptr poa, - PortableServer::ObjectId* contId, - const char* instanceName, - const char* interfaceName) : - Engines_Component_i(orb, poa, contId, instanceName, interfaceName) + CORBA::ORB_ptr orb, + PortableServer::POA_ptr poa, + PortableServer::ObjectId* contId, + const char* instanceName, + const char* interfaceName) : + Engines_Component_i(orb, poa, contId, instanceName, interfaceName) { - MESSAGE("activate object"); - _thisObj = this ; - _id = _poa->activate_object(_thisObj); + MESSAGE("activate object"); + _thisObj = this ; + _id = _poa->activate_object(_thisObj); } @@ -55,96 +55,96 @@ MULTIPR_Gen_i::~MULTIPR_Gen_i() //----------------------------------------------------------------------------- char* MULTIPR_Gen_i::getVersion() - throw (SALOME::SALOME_Exception) + throw (SALOME::SALOME_Exception) { - return CORBA::string_dup(multipr::getVersion()); + return CORBA::string_dup(multipr::getVersion()); } void MULTIPR_Gen_i::partitionneDomaine( - const char* medFilename, - const char* meshName) - throw (SALOME::SALOME_Exception) + const char* medFilename, + const char* meshName) + throw (SALOME::SALOME_Exception) { - try - { - multipr::partitionneDomaine(medFilename, meshName); - } - catch (multipr::RuntimeException& e) - { - e.dump(cout); - THROW_SALOME_CORBA_EXCEPTION("partitionneDomaine() failed", SALOME::INTERNAL_ERROR); - } + try + { + multipr::partitionneDomaine(medFilename, meshName); + } + catch (multipr::RuntimeException& e) + { + e.dump(cout); + THROW_SALOME_CORBA_EXCEPTION("partitionneDomaine() failed", SALOME::INTERNAL_ERROR); + } } void MULTIPR_Gen_i::partitionneGrain( - const char* medFilename, - const char* partName, - CORBA::Long nbParts, - CORBA::Long partitionner) - throw (SALOME::SALOME_Exception) + const char* medFilename, + const char* partName, + CORBA::Long nbParts, + CORBA::Long partitionner) + throw (SALOME::SALOME_Exception) { - try - { - multipr::partitionneGrain( - medFilename, - partName, - nbParts, - partitionner); - } - catch (multipr::RuntimeException& e) - { - e.dump(cout); - THROW_SALOME_CORBA_EXCEPTION("partitionneGrain() failed", SALOME::INTERNAL_ERROR); - } + try + { + multipr::partitionneGrain( + medFilename, + partName, + nbParts, + partitionner); + } + catch (multipr::RuntimeException& e) + { + e.dump(cout); + THROW_SALOME_CORBA_EXCEPTION("partitionneGrain() failed", SALOME::INTERNAL_ERROR); + } } void MULTIPR_Gen_i::decimePartition( - const char* medFilename, - const char* partName, - const char* fieldName, - CORBA::Long fieldIt, - const char* filterName, - CORBA::Double tmed, - CORBA::Double tlow, - CORBA::Double radius, - CORBA::Long boxing) - throw (SALOME::SALOME_Exception) + const char* medFilename, + const char* partName, + const char* fieldName, + CORBA::Long fieldIt, + const char* filterName, + CORBA::Double tmed, + CORBA::Double tlow, + CORBA::Double radius, + CORBA::Long boxing) + throw (SALOME::SALOME_Exception) { - /* - // debug - cout << "File : " << medFilename << endl; - cout << "Part : " << partName << endl; - cout << "Field : " << fieldName << endl; - cout << "It : " << fieldIt << endl; - cout << "Filter: " << filterName << endl; - cout << "Med : " << tmed << endl; - cout << "Low : " << tlow << endl; - cout << "Rad : " << radius << endl; - cout << "Box : " << boxing << endl; - cout << endl; - */ - - try - { - multipr::decimePartition( - medFilename, - partName, - fieldName, - fieldIt, - filterName, - tmed, - tlow, - radius, - boxing); - } - catch (multipr::RuntimeException& e) - { - e.dump(cout); - THROW_SALOME_CORBA_EXCEPTION("decimePartition() failed", SALOME::INTERNAL_ERROR); - } + /* + // debug + cout << "File : " << medFilename << endl; + cout << "Part : " << partName << endl; + cout << "Field : " << fieldName << endl; + cout << "It : " << fieldIt << endl; + cout << "Filter: " << filterName << endl; + cout << "Med : " << tmed << endl; + cout << "Low : " << tlow << endl; + cout << "Rad : " << radius << endl; + cout << "Box : " << boxing << endl; + cout << endl; + */ + + try + { + multipr::decimePartition( + medFilename, + partName, + fieldName, + fieldIt, + filterName, + tmed, + tlow, + radius, + boxing); + } + catch (multipr::RuntimeException& e) + { + e.dump(cout); + THROW_SALOME_CORBA_EXCEPTION("decimePartition() failed", SALOME::INTERNAL_ERROR); + } } @@ -153,382 +153,391 @@ void MULTIPR_Gen_i::decimePartition( //----------------------------------------------------------------------------- MULTIPR_ORB::MULTIPR_Obj_ptr MULTIPR_Gen_i::getObject(const char* medFilename) - throw (SALOME::SALOME_Exception) + throw (SALOME::SALOME_Exception) { MULTIPR_Obj_i* obj = new MULTIPR_Obj_i(medFilename); - return obj->POA_MULTIPR_ORB::MULTIPR_Obj::_this(); + return obj->POA_MULTIPR_ORB::MULTIPR_Obj::_this(); } MULTIPR_Obj_i::MULTIPR_Obj_i(const char* medFilename) - throw (SALOME::SALOME_Exception) + throw (SALOME::SALOME_Exception) { - mObj = new multipr::Obj(); - mBoxing = 100; - - try - { - cout << "Load " << medFilename << endl; - mObj->create(medFilename); - cout << endl; - } - catch (multipr::RuntimeException& e) - { - delete mObj; - mObj = NULL; - e.dump(cout); - THROW_SALOME_CORBA_EXCEPTION("Unable to create object", SALOME::INTERNAL_ERROR); - } + mObj = new multipr::Obj(); + mBoxing = 100; + + try + { + cout << "Load " << medFilename << endl; + mObj->create(medFilename); + cout << endl; + } + catch (multipr::RuntimeException& e) + { + delete mObj; + mObj = NULL; + e.dump(cout); + THROW_SALOME_CORBA_EXCEPTION("Unable to create object", SALOME::INTERNAL_ERROR); + } } MULTIPR_Obj_i::~MULTIPR_Obj_i() { - if (mObj != NULL) - { - cout << "MULTIPR: Destructor: remove mObj" << endl; - delete mObj; - mObj = NULL; - } + if (mObj != NULL) + { + cout << "MULTIPR: Destructor: remove mObj" << endl; + delete mObj; + mObj = NULL; + } } CORBA::Boolean MULTIPR_Obj_i::isValidSequentialMEDFile() - throw (SALOME::SALOME_Exception) + throw (SALOME::SALOME_Exception) { - if (mObj == NULL) THROW_SALOME_CORBA_EXCEPTION("No associated MED file", SALOME::INTERNAL_ERROR); - - return mObj->isValidSequentialMEDFile(); + if (mObj == NULL) THROW_SALOME_CORBA_EXCEPTION("No associated MED file", SALOME::INTERNAL_ERROR); + + return mObj->isValidSequentialMEDFile(); } CORBA::Boolean MULTIPR_Obj_i::isValidDistributedMEDFile() - throw (SALOME::SALOME_Exception) + throw (SALOME::SALOME_Exception) { - if (mObj == NULL) THROW_SALOME_CORBA_EXCEPTION("No associated MED file", SALOME::INTERNAL_ERROR); - - return mObj->isValidDistributedMEDFile(); + if (mObj == NULL) THROW_SALOME_CORBA_EXCEPTION("No associated MED file", SALOME::INTERNAL_ERROR); + + return mObj->isValidDistributedMEDFile(); } char* MULTIPR_Obj_i::getFilename() - throw (SALOME::SALOME_Exception) + throw (SALOME::SALOME_Exception) { - if (mObj == NULL) THROW_SALOME_CORBA_EXCEPTION("No associated MED file", SALOME::INTERNAL_ERROR); - - return CORBA::string_dup(mObj->getMEDFilename().c_str()); + if (mObj == NULL) THROW_SALOME_CORBA_EXCEPTION("No associated MED file", SALOME::INTERNAL_ERROR); + + return CORBA::string_dup(mObj->getMEDFilename().c_str()); +} + + +char* MULTIPR_Obj_i::getSeqFilename() + throw (SALOME::SALOME_Exception) +{ + if (mObj == NULL) THROW_SALOME_CORBA_EXCEPTION("No associated MED file", SALOME::INTERNAL_ERROR); + + return CORBA::string_dup(mObj->getSequentialMEDFilename().c_str()); } void MULTIPR_Obj_i::setMesh(const char* meshName) - throw (SALOME::SALOME_Exception) + throw (SALOME::SALOME_Exception) { - if (mObj == NULL) THROW_SALOME_CORBA_EXCEPTION("No associated MED file", SALOME::INTERNAL_ERROR); - - try - { - mObj->setMesh(meshName); - - cout << "Set mesh OK" << endl << endl; - } - catch (multipr::RuntimeException& e) - { - e.dump(cout); - THROW_SALOME_CORBA_EXCEPTION("Unable to set mesh", SALOME::INTERNAL_ERROR); - } + if (mObj == NULL) THROW_SALOME_CORBA_EXCEPTION("No associated MED file", SALOME::INTERNAL_ERROR); + + try + { + mObj->setMesh(meshName); + + cout << "Set mesh OK" << endl << endl; + } + catch (multipr::RuntimeException& e) + { + e.dump(cout); + THROW_SALOME_CORBA_EXCEPTION("Unable to set mesh", SALOME::INTERNAL_ERROR); + } } void MULTIPR_Obj_i::setBoxing(CORBA::Long pBoxing) - throw (SALOME::SALOME_Exception) + throw (SALOME::SALOME_Exception) { - if (mBoxing < 0) THROW_SALOME_CORBA_EXCEPTION("Invalid boxing parameter; should be >= 1", SALOME::INTERNAL_ERROR); - if (mBoxing > 200) THROW_SALOME_CORBA_EXCEPTION("Invalid boxing parameter; should be <= 200", SALOME::INTERNAL_ERROR); - - mBoxing = pBoxing; + if (mBoxing < 0) THROW_SALOME_CORBA_EXCEPTION("Invalid boxing parameter; should be >= 1", SALOME::INTERNAL_ERROR); + if (mBoxing > 200) THROW_SALOME_CORBA_EXCEPTION("Invalid boxing parameter; should be <= 200", SALOME::INTERNAL_ERROR); + + mBoxing = pBoxing; } MULTIPR_ORB::string_array* MULTIPR_Obj_i::getMeshes() - throw (SALOME::SALOME_Exception) + throw (SALOME::SALOME_Exception) { - if (mObj == NULL) THROW_SALOME_CORBA_EXCEPTION("No associated MED file", SALOME::INTERNAL_ERROR); - - MULTIPR_ORB::string_array_var mySeq = new MULTIPR_ORB::string_array(); - - try - { - std::vector listMeshes = mObj->getMeshes(); - mySeq->length(listMeshes.size()); - - for (int i = 0 ; i < listMeshes.size() ; i++) + if (mObj == NULL) THROW_SALOME_CORBA_EXCEPTION("No associated MED file", SALOME::INTERNAL_ERROR); + + MULTIPR_ORB::string_array_var mySeq = new MULTIPR_ORB::string_array(); + + try + { + std::vector listMeshes = mObj->getMeshes(); + mySeq->length(listMeshes.size()); + + for (int i = 0 ; i < listMeshes.size() ; i++) { - mySeq[i] = CORBA::string_dup(listMeshes[i].c_str()); + mySeq[i] = CORBA::string_dup(listMeshes[i].c_str()); } - } - catch (multipr::RuntimeException& e) - { - e.dump(cout); - THROW_SALOME_CORBA_EXCEPTION("Unable to get meshes", SALOME::INTERNAL_ERROR); - } - + } + catch (multipr::RuntimeException& e) + { + e.dump(cout); + THROW_SALOME_CORBA_EXCEPTION("Unable to get meshes", SALOME::INTERNAL_ERROR); + } + return mySeq._retn(); } MULTIPR_ORB::string_array* MULTIPR_Obj_i::getFields() - throw (SALOME::SALOME_Exception) + throw (SALOME::SALOME_Exception) { - if (mObj == NULL) THROW_SALOME_CORBA_EXCEPTION("No associated MED file", SALOME::INTERNAL_ERROR); - - MULTIPR_ORB::string_array_var mySeq = new MULTIPR_ORB::string_array(); - - try - { - std::vector listFields = mObj->getFields(); - mySeq->length(listFields.size()); - - for (int i = 0 ; i < listFields.size() ; i++) + if (mObj == NULL) THROW_SALOME_CORBA_EXCEPTION("No associated MED file", SALOME::INTERNAL_ERROR); + + MULTIPR_ORB::string_array_var mySeq = new MULTIPR_ORB::string_array(); + + try + { + std::vector listFields = mObj->getFields(); + mySeq->length(listFields.size()); + + for (int i = 0 ; i < listFields.size() ; i++) { - mySeq[i] = CORBA::string_dup(listFields[i].c_str()); + mySeq[i] = CORBA::string_dup(listFields[i].c_str()); } - } - catch (multipr::RuntimeException& e) - { - e.dump(cout); - THROW_SALOME_CORBA_EXCEPTION("Unable to get fields", SALOME::INTERNAL_ERROR); - } - + } + catch (multipr::RuntimeException& e) + { + e.dump(cout); + THROW_SALOME_CORBA_EXCEPTION("Unable to get fields", SALOME::INTERNAL_ERROR); + } + return mySeq._retn(); } CORBA::Long MULTIPR_Obj_i::getTimeStamps(const char* fieldName) - throw (SALOME::SALOME_Exception) + throw (SALOME::SALOME_Exception) { - if (mObj == NULL) THROW_SALOME_CORBA_EXCEPTION("No associated MED file", SALOME::INTERNAL_ERROR); - - try - { - return mObj->getTimeStamps(fieldName); - } - catch (multipr::RuntimeException& e) - { - e.dump(cout); - THROW_SALOME_CORBA_EXCEPTION("Unable to get time stamps", SALOME::INTERNAL_ERROR); - } + if (mObj == NULL) THROW_SALOME_CORBA_EXCEPTION("No associated MED file", SALOME::INTERNAL_ERROR); + + try + { + return mObj->getTimeStamps(fieldName); + } + catch (multipr::RuntimeException& e) + { + e.dump(cout); + THROW_SALOME_CORBA_EXCEPTION("Unable to get time stamps", SALOME::INTERNAL_ERROR); + } } MULTIPR_ORB::string_array* MULTIPR_Obj_i::getParts() - throw (SALOME::SALOME_Exception) + throw (SALOME::SALOME_Exception) { - if (mObj == NULL) THROW_SALOME_CORBA_EXCEPTION("No associated MED file", SALOME::INTERNAL_ERROR); - - MULTIPR_ORB::string_array_var mySeq = new MULTIPR_ORB::string_array(); - - try - { - std::vector listParts = mObj->getParts(); - mySeq->length(listParts.size()); - - for (int i = 0 ; i < listParts.size() ; i++) + if (mObj == NULL) THROW_SALOME_CORBA_EXCEPTION("No associated MED file", SALOME::INTERNAL_ERROR); + + MULTIPR_ORB::string_array_var mySeq = new MULTIPR_ORB::string_array(); + + try + { + std::vector listParts = mObj->getParts(); + mySeq->length(listParts.size()); + + for (int i = 0 ; i < listParts.size() ; i++) { - mySeq[i] = CORBA::string_dup(listParts[i].c_str()); + mySeq[i] = CORBA::string_dup(listParts[i].c_str()); } - } - catch (multipr::RuntimeException& e) - { - e.dump(cout); - THROW_SALOME_CORBA_EXCEPTION("Unable to get parts", SALOME::INTERNAL_ERROR); - } - + } + catch (multipr::RuntimeException& e) + { + e.dump(cout); + THROW_SALOME_CORBA_EXCEPTION("Unable to get parts", SALOME::INTERNAL_ERROR); + } + return mySeq._retn(); } char* MULTIPR_Obj_i::getPartInfo(const char* pPartName) - throw (SALOME::SALOME_Exception) + throw (SALOME::SALOME_Exception) { - if (mObj == NULL) THROW_SALOME_CORBA_EXCEPTION("No associated MED file", SALOME::INTERNAL_ERROR); - - return CORBA::string_dup(mObj->getPartInfo(pPartName).c_str()); + if (mObj == NULL) THROW_SALOME_CORBA_EXCEPTION("No associated MED file", SALOME::INTERNAL_ERROR); + + return CORBA::string_dup(mObj->getPartInfo(pPartName).c_str()); } MULTIPR_ORB::string_array* MULTIPR_Obj_i::partitionneDomaine() - throw (SALOME::SALOME_Exception) + throw (SALOME::SALOME_Exception) { - if (mObj == NULL) THROW_SALOME_CORBA_EXCEPTION("No associated MED file", SALOME::INTERNAL_ERROR); - - MULTIPR_ORB::string_array_var mySeq = new MULTIPR_ORB::string_array(); - - try - { - std::vector listParts = mObj->partitionneDomaine(); - mySeq->length(listParts.size()); - - for (int i = 0 ; i < listParts.size() ; i++) + if (mObj == NULL) THROW_SALOME_CORBA_EXCEPTION("No associated MED file", SALOME::INTERNAL_ERROR); + + MULTIPR_ORB::string_array_var mySeq = new MULTIPR_ORB::string_array(); + + try + { + std::vector listParts = mObj->partitionneDomaine(); + mySeq->length(listParts.size()); + + for (int i = 0 ; i < listParts.size() ; i++) { - mySeq[i] = CORBA::string_dup(listParts[i].c_str()); + mySeq[i] = CORBA::string_dup(listParts[i].c_str()); } - } - catch (multipr::RuntimeException& e) - { - e.dump(cout); - THROW_SALOME_CORBA_EXCEPTION("Unable to partition mesh", SALOME::INTERNAL_ERROR); - } - + } + catch (multipr::RuntimeException& e) + { + e.dump(cout); + THROW_SALOME_CORBA_EXCEPTION("Unable to partition mesh", SALOME::INTERNAL_ERROR); + } + return mySeq._retn(); } MULTIPR_ORB::string_array* MULTIPR_Obj_i::partitionneGrain( - const char* pPartName, - CORBA::Long pNbParts, - CORBA::Long pPartitionner) - throw (SALOME::SALOME_Exception) + const char* pPartName, + CORBA::Long pNbParts, + CORBA::Long pPartitionner) + throw (SALOME::SALOME_Exception) { - if (mObj == NULL) THROW_SALOME_CORBA_EXCEPTION("No associated MED file", SALOME::INTERNAL_ERROR); - - MULTIPR_ORB::string_array_var mySeq = new MULTIPR_ORB::string_array(); - - try - { - std::vector listParts = mObj->partitionneGrain( - pPartName, - pNbParts, - pPartitionner); - - mySeq->length(listParts.size()); - - for (int i = 0 ; i < listParts.size() ; i++) + if (mObj == NULL) THROW_SALOME_CORBA_EXCEPTION("No associated MED file", SALOME::INTERNAL_ERROR); + + MULTIPR_ORB::string_array_var mySeq = new MULTIPR_ORB::string_array(); + + try + { + std::vector listParts = mObj->partitionneGrain( + pPartName, + pNbParts, + pPartitionner); + + mySeq->length(listParts.size()); + + for (int i = 0 ; i < listParts.size() ; i++) { - mySeq[i] = CORBA::string_dup(listParts[i].c_str()); + mySeq[i] = CORBA::string_dup(listParts[i].c_str()); } - } - catch (multipr::RuntimeException& e) - { - e.dump(cout); - THROW_SALOME_CORBA_EXCEPTION("Unable to partition group", SALOME::INTERNAL_ERROR); - } - + } + catch (multipr::RuntimeException& e) + { + e.dump(cout); + THROW_SALOME_CORBA_EXCEPTION("Unable to partition group", SALOME::INTERNAL_ERROR); + } + return mySeq._retn(); } MULTIPR_ORB::string_array* MULTIPR_Obj_i::decimePartition( - const char* pPartName, - const char* pFieldName, - CORBA::Long pFieldIt, - const char* pFilterName, - CORBA::Double pTmed, - CORBA::Double pTlow, - CORBA::Double pRadius) - throw (SALOME::SALOME_Exception) + const char* pPartName, + const char* pFieldName, + CORBA::Long pFieldIt, + const char* pFilterName, + CORBA::Double pTmed, + CORBA::Double pTlow, + CORBA::Double pRadius) + throw (SALOME::SALOME_Exception) { - if (mObj == NULL) THROW_SALOME_CORBA_EXCEPTION("No associated MED file", SALOME::INTERNAL_ERROR); - - MULTIPR_ORB::string_array_var mySeq = new MULTIPR_ORB::string_array(); - - try - { - std::vector listParts = mObj->decimePartition( - pPartName, - pFieldName, - pFieldIt, - pFilterName, - pTmed, - pTlow, - pRadius, - mBoxing); - - mySeq->length(listParts.size()); - - for (int i = 0 ; i < listParts.size() ; i++) + if (mObj == NULL) THROW_SALOME_CORBA_EXCEPTION("No associated MED file", SALOME::INTERNAL_ERROR); + + MULTIPR_ORB::string_array_var mySeq = new MULTIPR_ORB::string_array(); + + try + { + std::vector listParts = mObj->decimePartition( + pPartName, + pFieldName, + pFieldIt, + pFilterName, + pTmed, + pTlow, + pRadius, + mBoxing); + + mySeq->length(listParts.size()); + + for (int i = 0 ; i < listParts.size() ; i++) { - mySeq[i] = CORBA::string_dup(listParts[i].c_str()); + mySeq[i] = CORBA::string_dup(listParts[i].c_str()); } - } - catch (multipr::RuntimeException& e) - { - e.dump(cout); - THROW_SALOME_CORBA_EXCEPTION("Unable to decimate", SALOME::INTERNAL_ERROR); - } - - return mySeq._retn(); + } + catch (multipr::RuntimeException& e) + { + e.dump(cout); + THROW_SALOME_CORBA_EXCEPTION("Unable to decimate", SALOME::INTERNAL_ERROR); + } + + return mySeq._retn(); } char* MULTIPR_Obj_i::evalDecimationParams( - const char* pPartName, - const char* pFieldName, - CORBA::Long pFieldIt, - const char* pFilterName, - const char* pFilterParams) - throw (SALOME::SALOME_Exception) + const char* pPartName, + const char* pFieldName, + CORBA::Long pFieldIt, + const char* pFilterName, + const char* pFilterParams) + throw (SALOME::SALOME_Exception) { - if (mObj == NULL) THROW_SALOME_CORBA_EXCEPTION("No associated MED file", SALOME::INTERNAL_ERROR); - - try - { - string res = mObj->evalDecimationParams( - pPartName, - pFieldName, - pFieldIt, - pFilterName, - pFilterParams); - - return CORBA::string_dup(res.c_str()); - - } - catch (multipr::RuntimeException& e) - { - e.dump(cout); - THROW_SALOME_CORBA_EXCEPTION("Unable to evaluate decimation parameters", SALOME::INTERNAL_ERROR); - } + if (mObj == NULL) THROW_SALOME_CORBA_EXCEPTION("No associated MED file", SALOME::INTERNAL_ERROR); + + try + { + string res = mObj->evalDecimationParams( + pPartName, + pFieldName, + pFieldIt, + pFilterName, + pFilterParams); + + return CORBA::string_dup(res.c_str()); + + } + catch (multipr::RuntimeException& e) + { + e.dump(cout); + THROW_SALOME_CORBA_EXCEPTION("Unable to evaluate decimation parameters", SALOME::INTERNAL_ERROR); + } } void MULTIPR_Obj_i::removeParts(const char* pPrefixPartName) - throw (SALOME::SALOME_Exception) + throw (SALOME::SALOME_Exception) { - if (mObj == NULL) THROW_SALOME_CORBA_EXCEPTION("No associated MED file", SALOME::INTERNAL_ERROR); - - mObj->removeParts(pPrefixPartName); + if (mObj == NULL) THROW_SALOME_CORBA_EXCEPTION("No associated MED file", SALOME::INTERNAL_ERROR); + + mObj->removeParts(pPrefixPartName); } void MULTIPR_Obj_i::save(const char* pPath) - throw (SALOME::SALOME_Exception) + throw (SALOME::SALOME_Exception) { - if (mObj == NULL) THROW_SALOME_CORBA_EXCEPTION("No associated MED file", SALOME::INTERNAL_ERROR); - - try - { - mObj->save(pPath); - - } - catch (multipr::RuntimeException& e) - { - e.dump(cout); - THROW_SALOME_CORBA_EXCEPTION("Unable to save MED file", SALOME::INTERNAL_ERROR); - } + if (mObj == NULL) THROW_SALOME_CORBA_EXCEPTION("No associated MED file", SALOME::INTERNAL_ERROR); + + try + { + mObj->save(pPath); + + } + catch (multipr::RuntimeException& e) + { + e.dump(cout); + THROW_SALOME_CORBA_EXCEPTION("Unable to save MED file", SALOME::INTERNAL_ERROR); + } } extern "C" { - PortableServer::ObjectId* MULTIPREngine_factory( - CORBA::ORB_ptr orb, - PortableServer::POA_ptr poa, - PortableServer::ObjectId * contId, - const char* instanceName, - const char* interfaceName) - { - MESSAGE("PortableServer::ObjectId* MULTIPREngine_factory()"); - SCRUTE(interfaceName); - MULTIPR_Gen_i* myMULTIPR = new MULTIPR_Gen_i(orb, poa, contId, instanceName, interfaceName); - return myMULTIPR->getId(); - } + PortableServer::ObjectId* MULTIPREngine_factory( + CORBA::ORB_ptr orb, + PortableServer::POA_ptr poa, + PortableServer::ObjectId * contId, + const char* instanceName, + const char* interfaceName) + { + MESSAGE("PortableServer::ObjectId* MULTIPREngine_factory()"); + SCRUTE(interfaceName); + MULTIPR_Gen_i* myMULTIPR = new MULTIPR_Gen_i(orb, poa, contId, instanceName, interfaceName); + return myMULTIPR->getId(); + } } diff --git a/src/MULTIPR/MULTIPR_i.hxx b/src/MULTIPR/MULTIPR_i.hxx index 961b44d..23f567a 100644 --- a/src/MULTIPR/MULTIPR_i.hxx +++ b/src/MULTIPR/MULTIPR_i.hxx @@ -34,213 +34,219 @@ //***************************************************************************** class MULTIPR_Obj_i : - public POA_MULTIPR_ORB::MULTIPR_Obj + public POA_MULTIPR_ORB::MULTIPR_Obj { public: - /** - * Constructor. - * Associate a MED file (sequential or distributed) with this object. - * \param pMEDFilename MED file to be associated with this object. - */ + /** + * Constructor. + * Associate a MED file (sequential or distributed) with this object. + * \param pMEDFilename MED file to be associated with this object. + */ MULTIPR_Obj_i(const char* pMEDFilename) - throw (SALOME::SALOME_Exception); - - /** - * Destructor. - */ + throw (SALOME::SALOME_Exception); + + /** + * Destructor. + */ virtual ~MULTIPR_Obj_i(); - - //--------------------------------------------------------------------- - // Basic accessors/mutators - //-------------------------------------------------------------------- - - /** - * Returns true iff this obj represents a valid sequential MED file. - * \return true iff this obj represents a valid sequential MED file. - */ - CORBA::Boolean isValidSequentialMEDFile() - throw (SALOME::SALOME_Exception); - - /** - * Returns true iff this obj represents a valid distributed MED file. - * \return true iff this obj represents a valid distributed MED file. - */ - CORBA::Boolean isValidDistributedMEDFile() - throw (SALOME::SALOME_Exception); - - /** - * Returns the name of the associated MED file. - * \return the name of the associated MED file. - */ - char* getFilename() - throw (SALOME::SALOME_Exception); - - /** - * Defines the mesh to be processed. - * \param pMeshName name of the mesh to be partitionned. - */ - void setMesh(const char* pMeshName) - throw (SALOME::SALOME_Exception); - - /** - * Sets boxing parameters for decimation (100 by default). - * \param pBoxing number of cells along each axis of the grid (= acceleration structure) ; should be in [1..200]. - */ - void setBoxing(CORBA::Long pBoxing) - throw (SALOME::SALOME_Exception); + + //--------------------------------------------------------------------- + // Basic accessors/mutators + //-------------------------------------------------------------------- + + /** + * Returns true iff this obj represents a valid sequential MED file. + * \return true iff this obj represents a valid sequential MED file. + */ + CORBA::Boolean isValidSequentialMEDFile() + throw (SALOME::SALOME_Exception); + + /** + * Returns true iff this obj represents a valid distributed MED file. + * \return true iff this obj represents a valid distributed MED file. + */ + CORBA::Boolean isValidDistributedMEDFile() + throw (SALOME::SALOME_Exception); + + /** + * Returns the name of the associated MED file. + * \return the name of the associated MED file. + */ + char* getFilename() + throw (SALOME::SALOME_Exception); + + /** + * Returns the name of the associated sequential MED file (for a distributed MED file). + * \return the name of the associated sequential MED file (for a distributed MED file). + */ + char* getSeqFilename() + throw (SALOME::SALOME_Exception); + /** + * Defines the mesh to be processed. + * \param pMeshName name of the mesh to be partitionned. + */ + void setMesh(const char* pMeshName) + throw (SALOME::SALOME_Exception); + + /** + * Sets boxing parameters for decimation (100 by default). + * \param pBoxing number of cells along each axis of the grid (= acceleration structure) ; should be in [1..200]. + */ + void setBoxing(CORBA::Long pBoxing) + throw (SALOME::SALOME_Exception); - /** - * Returns the list of meshes contained in the sequential MED file. - * Assumes this object encapsulates a sequential MED file. - * \return the list of meshes contained in the sequential MED file. - */ - MULTIPR_ORB::string_array* getMeshes() - throw (SALOME::SALOME_Exception); + /** + * Returns the list of meshes contained in the sequential MED file. + * Assumes this object encapsulates a sequential MED file. + * \return the list of meshes contained in the sequential MED file. + */ + MULTIPR_ORB::string_array* getMeshes() + throw (SALOME::SALOME_Exception); - /** - * Returns the list of fields contained in the sequential MED file. - * Assumes this object encapsulates a sequential MED file. - * \return the list of fields contained in the sequential MED file. - */ - MULTIPR_ORB::string_array* getFields() - throw (SALOME::SALOME_Exception); - - /** - * Returns the number of timestamps for a given field. - * Assumes this object encapsulates a sequential MED file. - * \param pFieldName name of any field. - * \return the number of timestamps for a given field; 0 if field not found. - */ - CORBA::Long getTimeStamps(const char* pFieldName) - throw (SALOME::SALOME_Exception); - - /** - * Returns the name of all partitions. - * Assumes this object encapsulates a distributed MED file. - * \return the name of all partitions. - */ - MULTIPR_ORB::string_array* getParts() - throw (SALOME::SALOME_Exception); + /** + * Returns the list of fields contained in the sequential MED file. + * Assumes this object encapsulates a sequential MED file. + * \return the list of fields contained in the sequential MED file. + */ + MULTIPR_ORB::string_array* getFields() + throw (SALOME::SALOME_Exception); + + /** + * Returns the number of timestamps for a given field. + * Assumes this object encapsulates a sequential MED file. + * \param pFieldName name of any field. + * \return the number of timestamps for a given field; 0 if field not found. + */ + CORBA::Long getTimeStamps(const char* pFieldName) + throw (SALOME::SALOME_Exception); + + /** + * Returns the name of all partitions. + * Assumes this object encapsulates a distributed MED file. + * \return the name of all partitions. + */ + MULTIPR_ORB::string_array* getParts() + throw (SALOME::SALOME_Exception); - /** - * Returns all information abour a part. - * Assumes this object encapsulates a distributed MED file. - * \param pPartName name of the part. - * \return information about a part. - */ - char* getPartInfo(const char* pPartName) - throw (SALOME::SALOME_Exception); - - //--------------------------------------------------------------------- - // Algorithms - //--------------------------------------------------------------------- - - /** - * Creates a distributed MED file (v2.3) by extracting all the groups from the current mesh of the current MED sequential MED file. - * Assumes: - * - the file is in MED format and can be read using MED file v2.3. - * - the file is sequential (not a distributed MED). - * - the file only contains TETRA10 elements (dimension of space and mesh is 3). - * - the file have no profil. - * \return the name of each part. - */ - MULTIPR_ORB::string_array* partitionneDomaine() - throw (SALOME::SALOME_Exception); - - /** - * Creates a distributed MED file (V2.3) by splitting a group of a MED file previously created by partitionneDomaine. - * Assumes: - * - the file is a distributed MED file, previously created by partitionneDomaine() - * (=> each part only contain 1 mesh, TETRA10 elements only) - * - nbPart > 1 - * \param pPartName name of the part to be splitted. - * \param pNbParts number of parts; must be > 1. - * \param pPartitionner use value 0=MULTIPR_METIS for Metis or 1=MULTIPR_SCOTCH for Scotch. - * \return the name of each part. - */ - MULTIPR_ORB::string_array* partitionneGrain( - const char* pPartName, - CORBA::Long pNbParts, - CORBA::Long pPartitionner) - throw (SALOME::SALOME_Exception); - - /** - * Creates 3 resolutions of the given part of a distributed MED file (V2.3). - * Assumes: - * - the file is a distributed MED file, previously created by partitionneDomaine() or partitionneGrain() - * (=> each part only contain 1 mesh, TETRA10 elements only) - * \param pPartName name of the part to be decimated. - * \param pFieldName name of the field used for decimation. - * \param pFieldIt iteration (time step) of the field. - * \param pFilterName name of the filter to be used. - * \param pTmed threshold used for medium resolution. - * \param pTlow threshold used for low resolution; tmed must be less than tlow - * \param pTadius radius used to determine the neighbourhood. - * \return the name of each part. - */ - MULTIPR_ORB::string_array* decimePartition( - const char* pPartName, - const char* pFieldName, - CORBA::Long pFieldIt, - const char* pFilterName, - CORBA::Double pTmed, - CORBA::Double pTlow, - CORBA::Double pRadius) - throw (SALOME::SALOME_Exception); - - /** - * Returns useful information to configure decimation parameters. - * Depends on part, field and filter: generic operation. - * \param pPartName name of the part. - * \param pFieldName name of the field used for decimation. - * \param pFieldIt iteration (time step) of the field. - * \param pFilterName name of the filter to be used. - * \param pFilterParams params to be used with the filter (depends on filter; this string will be parsed). - */ - char* evalDecimationParams( - const char* pPartName, - const char* pFieldName, - CORBA::Long pFieldIt, - const char* pFilterName, - const char* pFilterParams) - throw (SALOME::SALOME_Exception); - - /*! - * Removes all the parts starting with "pPrefixPartName" from the distributed MED file. - * Example: if pPrefixPartName="PART_4" => remove "PART_4" and all sub-parts "PART_4_*", but not "PART41". - * Assume this object encapsulates a distributed MED file. - * \param pPrefixPartName name of the part. - */ - void removeParts(const char* pPrefixPartName) - throw (SALOME::SALOME_Exception); - - //--------------------------------------------------------------------- - // I/O - //--------------------------------------------------------------------- - - /** - * Saves the associated MED file if necessary. - * \param pPath path where to save the file. - */ - void save(const char* pPath) - throw (SALOME::SALOME_Exception); - + /** + * Returns all information abour a part. + * Assumes this object encapsulates a distributed MED file. + * \param pPartName name of the part. + * \return information about a part. + */ + char* getPartInfo(const char* pPartName) + throw (SALOME::SALOME_Exception); + + //--------------------------------------------------------------------- + // Algorithms + //--------------------------------------------------------------------- + + /** + * Creates a distributed MED file (v2.3) by extracting all the groups from the current mesh of the current MED sequential MED file. + * Assumes: + * - the file is in MED format and can be read using MED file v2.3. + * - the file is sequential (not a distributed MED). + * - the file only contains TETRA10 elements (dimension of space and mesh is 3). + * - the file have no profil. + * \return the name of each part. + */ + MULTIPR_ORB::string_array* partitionneDomaine() + throw (SALOME::SALOME_Exception); + + /** + * Creates a distributed MED file (V2.3) by splitting a group of a MED file previously created by partitionneDomaine. + * Assumes: + * - the file is a distributed MED file, previously created by partitionneDomaine() + * (=> each part only contain 1 mesh, TETRA10 elements only) + * - nbPart > 1 + * \param pPartName name of the part to be splitted. + * \param pNbParts number of parts; must be > 1. + * \param pPartitionner use value 0=MULTIPR_METIS for Metis or 1=MULTIPR_SCOTCH for Scotch. + * \return the name of each part. + */ + MULTIPR_ORB::string_array* partitionneGrain( + const char* pPartName, + CORBA::Long pNbParts, + CORBA::Long pPartitionner) + throw (SALOME::SALOME_Exception); + + /** + * Creates 3 resolutions of the given part of a distributed MED file (V2.3). + * Assumes: + * - the file is a distributed MED file, previously created by partitionneDomaine() or partitionneGrain() + * (=> each part only contain 1 mesh, TETRA10 elements only) + * \param pPartName name of the part to be decimated. + * \param pFieldName name of the field used for decimation. + * \param pFieldIt iteration (time step) of the field. + * \param pFilterName name of the filter to be used. + * \param pTmed threshold used for medium resolution. + * \param pTlow threshold used for low resolution; tmed must be less than tlow + * \param pTadius radius used to determine the neighbourhood. + * \return the name of each part. + */ + MULTIPR_ORB::string_array* decimePartition( + const char* pPartName, + const char* pFieldName, + CORBA::Long pFieldIt, + const char* pFilterName, + CORBA::Double pTmed, + CORBA::Double pTlow, + CORBA::Double pRadius) + throw (SALOME::SALOME_Exception); + + /** + * Returns useful information to configure decimation parameters. + * Depends on part, field and filter: generic operation. + * \param pPartName name of the part. + * \param pFieldName name of the field used for decimation. + * \param pFieldIt iteration (time step) of the field. + * \param pFilterName name of the filter to be used. + * \param pFilterParams params to be used with the filter (depends on filter; this string will be parsed). + */ + char* evalDecimationParams( + const char* pPartName, + const char* pFieldName, + CORBA::Long pFieldIt, + const char* pFilterName, + const char* pFilterParams) + throw (SALOME::SALOME_Exception); + + /*! + * Removes all the parts starting with "pPrefixPartName" from the distributed MED file. + * Example: if pPrefixPartName="PART_4" => remove "PART_4" and all sub-parts "PART_4_*", but not "PART41". + * Assume this object encapsulates a distributed MED file. + * \param pPrefixPartName name of the part. + */ + void removeParts(const char* pPrefixPartName) + throw (SALOME::SALOME_Exception); + + //--------------------------------------------------------------------- + // I/O + //--------------------------------------------------------------------- + + /** + * Saves the associated MED file if necessary. + * \param pPath path where to save the file. + */ + void save(const char* pPath) + throw (SALOME::SALOME_Exception); + private: - /** - * The associated MULTIPR object. - */ - multipr::Obj* mObj; - - /** - * Boxing paremeter: number of cells along each axis. - * E.g. if mBoxing=10 then total number of cells = 10*10*10 = 1000. - * By default, mBoxing=100. - */ - int mBoxing; - + /** + * The associated MULTIPR object. + */ + multipr::Obj* mObj; + + /** + * Boxing paremeter: number of cells along each axis. + * E.g. if mBoxing=10 then total number of cells = 10*10*10 = 1000. + * By default, mBoxing=100. + */ + int mBoxing; + }; @@ -250,58 +256,61 @@ private: //***************************************************************************** class MULTIPR_Gen_i : - public POA_MULTIPR_ORB::MULTIPR_Gen, - public Engines_Component_i + public POA_MULTIPR_ORB::MULTIPR_Gen, + public Engines_Component_i { public: - MULTIPR_Gen_i( - CORBA::ORB_ptr orb, - PortableServer::POA_ptr poa, - PortableServer::ObjectId* contId, - const char* instanceName, - const char* interfaceName); - - virtual ~MULTIPR_Gen_i(); - - char* getVersion() - throw (SALOME::SALOME_Exception); - - void partitionneDomaine( - const char* medFilename, - const char* meshName) - throw (SALOME::SALOME_Exception); - - void partitionneGrain( - const char* medFilename, - const char* partName, - CORBA::Long nbParts, - CORBA::Long partitionner) - throw (SALOME::SALOME_Exception); - - void decimePartition( - const char* medFilename, - const char* partName, - const char* fieldName, - CORBA::Long fieldIt, - const char* filterName, - CORBA::Double tmed, - CORBA::Double tlow, - CORBA::Double radius, - CORBA::Long boxing) - throw (SALOME::SALOME_Exception); + MULTIPR_Gen_i( + CORBA::ORB_ptr orb, + PortableServer::POA_ptr poa, + PortableServer::ObjectId* contId, + const char* instanceName, + const char* interfaceName); + + virtual ~MULTIPR_Gen_i(); + + char* getVersion() + throw (SALOME::SALOME_Exception); + + void partitionneDomaine( + const char* medFilename, + const char* meshName) + throw (SALOME::SALOME_Exception); + + void partitionneGrain( + const char* medFilename, + const char* partName, + CORBA::Long nbParts, + CORBA::Long partitionner) + throw (SALOME::SALOME_Exception); + + void decimePartition( + const char* medFilename, + const char* partName, + const char* fieldName, + CORBA::Long fieldIt, + const char* filterName, + CORBA::Double tmed, + CORBA::Double tlow, + CORBA::Double radius, + CORBA::Long boxing) + throw (SALOME::SALOME_Exception); - MULTIPR_ORB::MULTIPR_Obj_ptr getObject(const char* medFilename) - throw (SALOME::SALOME_Exception); + MULTIPR_ORB::MULTIPR_Obj_ptr getObject(const char* medFilename) + throw (SALOME::SALOME_Exception); }; extern "C" PortableServer::ObjectId* MULTIPREngine_factory( - CORBA::ORB_ptr orb, - PortableServer::POA_ptr poa, - PortableServer::ObjectId * contId, - const char* instanceName, - const char* interfaceName); + CORBA::ORB_ptr orb, + PortableServer::POA_ptr poa, + PortableServer::ObjectId * contId, + const char* instanceName, + const char* interfaceName); #endif // __MULTIPR_IMPLEMENTATION_CORBA__ + +// EOF + diff --git a/src/MULTIPR/Makefile.in b/src/MULTIPR/Makefile.in index 584c9ed..3290eb6 100644 --- a/src/MULTIPR/Makefile.in +++ b/src/MULTIPR/Makefile.in @@ -31,18 +31,52 @@ MACHINE=PCLINUX # Libraries targets LIB = libMULTIPREngine.la -LIB_SRC = MULTIPR_i.cxx MULTIPR_API.cxx MULTIPR_Mesh.cxx MULTIPR_Profil.cxx MULTIPR_GaussLoc.cxx MULTIPR_Field.cxx MULTIPR_Nodes.cxx MULTIPR_Elements.cxx MULTIPR_Family.cxx MULTIPR_MeshDis.cxx MULTIPR_DecimationFilter.cxx MULTIPR_DecimationAccel.cxx MULTIPR_Utils.cxx MULTIPR_Obj.cxx + +LIB_SRC = \ +MULTIPR_i.cxx \ +MULTIPR_API.cxx \ +MULTIPR_Mesh.cxx \ +MULTIPR_Profil.cxx \ +MULTIPR_GaussLoc.cxx \ +MULTIPR_Field.cxx \ +MULTIPR_Nodes.cxx \ +MULTIPR_Elements.cxx \ +MULTIPR_Family.cxx \ +MULTIPR_MeshDis.cxx \ +MULTIPR_DecimationFilter.cxx \ +MULTIPR_DecimationAccel.cxx \ +MULTIPR_Utils.cxx \ +MULTIPR_Obj.cxx + LIB_SERVER_IDL = MULTIPR.idl + LIB_CLIENT_IDL = SALOME_Component.idl SALOME_Exception.idl SALOMEDS.idl SALOME_GenericObj.idl Logger.idl -EXPORT_HEADERS = MULTIPR_API.hxx MULTIPR_DecimationAccel.hxx MULTIPR_DecimationFilter.hxx MULTIPR_Elements.hxx MULTIPR_Exceptions.hxx MULTIPR_Family.hxx MULTIPR_Field.hxx MULTIPR_GaussLoc.hxx MULTIPR_Globals.hxx MULTIPR_MeshDis.hxx MULTIPR_Mesh.hxx MULTIPR_Nodes.hxx MULTIPR_PointOfField.hxx MULTIPR_Profil.hxx MULTIPR_Utils.hxx MULTIPR_Obj.hxx MULTIPR_ProgressCallback.hxx +EXPORT_HEADERS = \ +MULTIPR_API.hxx \ +MULTIPR_DecimationAccel.hxx \ +MULTIPR_DecimationFilter.hxx \ +MULTIPR_Elements.hxx \ +MULTIPR_Exceptions.hxx \ +MULTIPR_Family.hxx \ +MULTIPR_Field.hxx \ +MULTIPR_GaussLoc.hxx \ +MULTIPR_Globals.hxx \ +MULTIPR_MeshDis.hxx \ +MULTIPR_Mesh.hxx \ +MULTIPR_Nodes.hxx \ +MULTIPR_PointOfField.hxx \ +MULTIPR_Profil.hxx \ +MULTIPR_Utils.hxx \ +MULTIPR_Obj.hxx \ +MULTIPR_ProgressCallback.hxx BIN = multipr BIN_SRC = # additionnal information to compile and link file -CPPFLAGS += $(KERNEL_CXXFLAGS) $(MED_CXXFLAGS) $(MED2_INCLUDES) -Wno-deprecated -Wparentheses -Wreturn-type -pthread +CPPFLAGS += $(KERNEL_CXXFLAGS) $(MED_CXXFLAGS) $(MED2_INCLUDES) -Wall -pthread CPPFLAGSFORBIN=$(CPPFLAGS) diff --git a/src/MULTIPR/multipr.cxx b/src/MULTIPR/multipr.cxx index c542fdf..1665b6c 100644 --- a/src/MULTIPR/multipr.cxx +++ b/src/MULTIPR/multipr.cxx @@ -49,13 +49,13 @@ const int MULTIPR_APP_FAILED = 1; */ enum Usage { - MULTIPR_USAGE_UNKNOWN, - MULTIPR_USAGE_DISPLAY_HELP, - MULTIPR_USAGE_AUTOTEST, - MULTIPR_USAGE_PARTITION1, - MULTIPR_USAGE_PARTITION2, - MULTIPR_USAGE_DECIMATION, - MULTIPR_USAGE_INFO + MULTIPR_USAGE_UNKNOWN, + MULTIPR_USAGE_DISPLAY_HELP, + MULTIPR_USAGE_AUTOTEST, + MULTIPR_USAGE_PARTITION1, + MULTIPR_USAGE_PARTITION2, + MULTIPR_USAGE_DECIMATION, + MULTIPR_USAGE_INFO }; @@ -64,13 +64,13 @@ enum Usage */ enum Error { - MULTIPR_APP_NO_ERROR, - MULTIPR_APP_UNKNOWN_USAGE, - MULTIPR_APP_WRONG_NUMBER_OF_ARGUMENTS, - MULTIPR_APP_ILLEGAL_ARGUMENT, - MULTIPR_APP_FILE_NOT_FOUND, - MULTIPR_APP_IO_ERROR, - MULTIPR_APP_UNDEFINED_ERROR + MULTIPR_APP_NO_ERROR, + MULTIPR_APP_UNKNOWN_USAGE, + MULTIPR_APP_WRONG_NUMBER_OF_ARGUMENTS, + MULTIPR_APP_ILLEGAL_ARGUMENT, + MULTIPR_APP_FILE_NOT_FOUND, + MULTIPR_APP_IO_ERROR, + MULTIPR_APP_UNDEFINED_ERROR }; @@ -97,29 +97,29 @@ int g_boxing = 100; */ const char* getUsage(int usage) { - switch(usage) - { - case MULTIPR_USAGE_DISPLAY_HELP: - return "--help: display help"; - - case MULTIPR_USAGE_AUTOTEST: - return "--auto: unit tests"; - - case MULTIPR_USAGE_PARTITION1: - return "--part1: extract all groups of a sequential MED file"; - - case MULTIPR_USAGE_PARTITION2: - return "--part2: split a part of a distributed MED file"; - - case MULTIPR_USAGE_DECIMATION: - return "--decim: generated level of details of a part of a distributed MED file"; - - case MULTIPR_USAGE_INFO: - return "--info: prints all infos about a mesh in a sequential MED file"; - - default: - return "unknown"; - } + switch(usage) + { + case MULTIPR_USAGE_DISPLAY_HELP: + return "--help: display help"; + + case MULTIPR_USAGE_AUTOTEST: + return "--auto: perform all unit tests"; + + case MULTIPR_USAGE_PARTITION1: + return "--part1: extract all groups of a sequential MED file"; + + case MULTIPR_USAGE_PARTITION2: + return "--part2: split a part of a distributed MED file"; + + case MULTIPR_USAGE_DECIMATION: + return "--decim: generated level of details of a part of a distributed MED file"; + + case MULTIPR_USAGE_INFO: + return "--info: prints all infos about a mesh in a sequential MED file"; + + default: + return "unknown"; + } } @@ -129,13 +129,13 @@ const char* getUsage(int usage) */ void printDescription() { - cout << "Keywords:" << endl; - cout << " Post-processing numerical simulation, Salome platform, " << endl; - cout << " Large data set visualization, 3D meshes and fields" << endl; - cout << "Description:" << endl; - cout << " multipr is a partitionning/decimation tool of MED files." << endl; - cout << " See http://www.salome-platform.org for information about MED or Salome." << endl; - cout << " Note: current version only accept TETRA10 meshes." << endl; + cout << "Keywords:" << endl; + cout << " Post-processing numerical simulation, Salome platform, " << endl; + cout << " Large data set visualization, 3D meshes and fields" << endl; + cout << "Description:" << endl; + cout << " multipr is a partitionning/decimation tool of MED files." << endl; + cout << " See http://www.salome-platform.org for information about MED or Salome." << endl; + cout << " Note: current version only accept TETRA10 meshes." << endl; } @@ -145,23 +145,23 @@ void printDescription() */ void printUsage() { - cout << "Usages:" << endl; - cout << " --auto Autotest: performs some unit tests on the MULTIPR API" << endl; - cout << " * Usage: --auto path (path where to find test file \"agregat100grains_12pas.med\")" << endl; - cout << " --part1 Extracts all groups from a sequential MED file (V2.2 or higher)" << endl; - cout << " * Usage: --part1 file.med meshName" << endl; - cout << " --part2 Split a group of a distributed MED file (V2.3) produced with --part1" << endl; - cout << " * Usage: --part2 file.med partName nbParts [splitter (0=METIS 1=SCOTCH)]" << endl; - cout << " --decim Generates 3 level of details (full, medium and low) of a part" << endl; - cout << " of a distributed MED file (V2.3)" << endl; - cout << " * Usage: --decim file.med partName fieldName fieldIt filterName [...]" << endl; - cout << " * Only one filter is currently available: Filtre_GradientMoyen" << endl; - cout << " * Usage: --decim file.med partName fieldName fieldIt Filtre_GradientMoyen m l radius" << endl; - cout << " where m=threshold for medium res. and l=threshold for low res.; assume m < l" << endl; - cout << " --info Dumps all infos related to a mesh in a sequential MED file" << endl; - cout << " * Usage: --info file.med [meshName]" << endl; - cout << " --help Displays this help page" << endl; - cout << endl; + cout << "Usages:" << endl; + cout << " --auto Autotest: performs some unit tests on the MULTIPR API" << endl; + cout << " * Usage: --auto path (path where to find test file \"agregat100grains_12pas.med\")" << endl; + cout << " --part1 Extracts all groups from a sequential MED file (V2.2 or higher)" << endl; + cout << " * Usage: --part1 file.med meshName" << endl; + cout << " --part2 Split a group of a distributed MED file (V2.3) produced with --part1" << endl; + cout << " * Usage: --part2 file.med partName nbParts [splitter (0=METIS 1=SCOTCH)]" << endl; + cout << " --decim Generates 3 level of details (full, medium and low) of a part" << endl; + cout << " of a distributed MED file (V2.3)" << endl; + cout << " * Usage: --decim file.med partName fieldName fieldIt filterName [...]" << endl; + cout << " * Only one filter is currently available: Filtre_GradientMoyen" << endl; + cout << " * Usage: --decim file.med partName fieldName fieldIt Filtre_GradientMoyen m l radius" << endl; + cout << " where m=threshold for medium res. and l=threshold for low res.; assume m < l" << endl; + cout << " --info Dumps all infos related to a mesh in a sequential MED file" << endl; + cout << " * Usage: --info file.med [meshName]" << endl; + cout << " --help Displays this help page" << endl; + cout << endl; } @@ -171,25 +171,25 @@ void printUsage() */ void printGlobals() { - cout << endl; - cout << "********************************************************************************" << endl; - cout << "CONFIGURATION" << endl; - cout << "--------------------------------------------------------------------------------" << endl; - cout << "Mode : " << getUsage(g_usage) << endl; - cout << "Med filename : " << ((g_medFilename != NULL) ? g_medFilename : "UNDEFINED") << endl; - cout << "Mesh name : " << ((g_meshName != NULL) ? g_meshName : "UNDEFINED") << endl; - cout << "Part name : " << ((g_partName != NULL) ? g_partName : "UNDEFINED") << endl; - cout << "Nb parts : " << g_nbParts << endl; - cout << "Decimation:" << endl; - cout << " Field name : " << ((g_fieldName != NULL) ? g_fieldName : "UNDEFINED") << endl; - cout << " Time step iteration : " << g_fieldTimeStepIt << endl; - cout << " Filter name : " << ((g_filterName != NULL) ? g_filterName : "UNDEFINED") << endl; - cout << " Threshold for med. res. : " << g_decimThresholdMed << endl; - cout << " Threshold for low res. : " << g_decimThresholdLow << endl; - cout << " Radius : " << g_decimRadius << endl; - cout << " Boxing : " << g_boxing << endl; - cout << "********************************************************************************" << endl; - cout << endl; + cout << endl; + cout << "********************************************************************************" << endl; + cout << "CONFIGURATION" << endl; + cout << "--------------------------------------------------------------------------------" << endl; + cout << "Mode : " << getUsage(g_usage) << endl; + cout << "Med filename : " << ((g_medFilename != NULL) ? g_medFilename : "UNDEFINED") << endl; + cout << "Mesh name : " << ((g_meshName != NULL) ? g_meshName : "UNDEFINED") << endl; + cout << "Part name : " << ((g_partName != NULL) ? g_partName : "UNDEFINED") << endl; + cout << "Nb parts : " << g_nbParts << endl; + cout << "Decimation:" << endl; + cout << " Field name : " << ((g_fieldName != NULL) ? g_fieldName : "UNDEFINED") << endl; + cout << " Time step iteration : " << g_fieldTimeStepIt << endl; + cout << " Filter name : " << ((g_filterName != NULL) ? g_filterName : "UNDEFINED") << endl; + cout << " Threshold for med. res. : " << g_decimThresholdMed << endl; + cout << " Threshold for low res. : " << g_decimThresholdLow << endl; + cout << " Radius : " << g_decimRadius << endl; + cout << " Boxing : " << g_boxing << endl; + cout << "********************************************************************************" << endl; + cout << endl; } @@ -200,29 +200,29 @@ void printGlobals() */ const char* getErrorMsg() { - switch (g_errorCode) - { - case MULTIPR_APP_NO_ERROR: - return "no error"; - - case MULTIPR_APP_UNKNOWN_USAGE: - return "unknown usage"; - - case MULTIPR_APP_WRONG_NUMBER_OF_ARGUMENTS: - return "wrong number of arguments"; - - case MULTIPR_APP_ILLEGAL_ARGUMENT: - return "illegal argument"; - - case MULTIPR_APP_FILE_NOT_FOUND: - return "file not found"; - - case MULTIPR_APP_IO_ERROR: - return "i/o error"; - - default: - return "error (undefined)"; - } + switch (g_errorCode) + { + case MULTIPR_APP_NO_ERROR: + return "no error"; + + case MULTIPR_APP_UNKNOWN_USAGE: + return "unknown usage"; + + case MULTIPR_APP_WRONG_NUMBER_OF_ARGUMENTS: + return "wrong number of arguments"; + + case MULTIPR_APP_ILLEGAL_ARGUMENT: + return "illegal argument"; + + case MULTIPR_APP_FILE_NOT_FOUND: + return "file not found"; + + case MULTIPR_APP_IO_ERROR: + return "i/o error"; + + default: + return "error (undefined)"; + } } @@ -234,111 +234,111 @@ const char* getErrorMsg() */ void parseCommandLine(int argc, char** argv) { - if (argc == 1) - { - g_usage = MULTIPR_USAGE_UNKNOWN; - return; - } - - if (strcmp(argv[1],"--help") == 0) - { - g_usage = MULTIPR_USAGE_DISPLAY_HELP; - } - else if (strcmp(argv[1],"--auto") == 0) - { - if (argc != 3) - { - g_usage = MULTIPR_USAGE_UNKNOWN; - g_errorCode = MULTIPR_APP_WRONG_NUMBER_OF_ARGUMENTS; - } - else - { - g_usage = MULTIPR_USAGE_AUTOTEST; - g_medFilename = argv[2]; - } - } - else if (strcmp(argv[1],"--part1") == 0) - { - if (argc != 4) - { - g_usage = MULTIPR_USAGE_UNKNOWN; - g_errorCode = MULTIPR_APP_WRONG_NUMBER_OF_ARGUMENTS; - } - else - { - g_usage = MULTIPR_USAGE_PARTITION1; - g_medFilename = argv[2]; - g_meshName = argv[3]; - } - } - else if (strcmp(argv[1],"--part2") == 0) - { - if ((argc != 5) && (argc != 6)) - { - g_usage = MULTIPR_USAGE_UNKNOWN; - g_errorCode = MULTIPR_APP_WRONG_NUMBER_OF_ARGUMENTS; - } - else - { - g_usage = MULTIPR_USAGE_PARTITION2; - g_medFilename = argv[2]; - g_partName = argv[3]; - g_nbParts = atoi(argv[4]); - - if (argc == 6) - { - g_splitter = atoi(argv[5]); - } - } - } - else if (strcmp(argv[1],"--decim") == 0) - { - if ((argc != 10) && (argc != 11)) - { - g_usage = MULTIPR_USAGE_UNKNOWN; - g_errorCode = MULTIPR_APP_WRONG_NUMBER_OF_ARGUMENTS; - } - else - { - g_usage = MULTIPR_USAGE_DECIMATION; - g_medFilename = argv[2]; - g_partName = argv[3]; - g_fieldName = argv[4]; - g_fieldTimeStepIt = atoi(argv[5]); - g_filterName = argv[6]; - g_decimThresholdMed = atof(argv[7]); - g_decimThresholdLow = atof(argv[8]); - g_decimRadius = atof(argv[9]); - - if (argc == 11) - { - g_boxing = atoi(argv[10]); - } - } - } - else if (strcmp(argv[1],"--info") == 0) - { - if ((argc != 3) && (argc != 4)) - { - g_usage = MULTIPR_USAGE_UNKNOWN; - g_errorCode = MULTIPR_APP_WRONG_NUMBER_OF_ARGUMENTS; - } - else - { - g_usage = MULTIPR_USAGE_INFO; - g_medFilename = argv[2]; - - if (argc == 4) - { - g_meshName = argv[3]; - } - } - } - else - { - g_usage = MULTIPR_USAGE_UNKNOWN; - g_errorCode = MULTIPR_APP_UNKNOWN_USAGE; - } + if (argc == 1) + { + g_usage = MULTIPR_USAGE_UNKNOWN; + return; + } + + if (strcmp(argv[1],"--help") == 0) + { + g_usage = MULTIPR_USAGE_DISPLAY_HELP; + } + else if (strcmp(argv[1],"--auto") == 0) + { + if (argc != 3) + { + g_usage = MULTIPR_USAGE_UNKNOWN; + g_errorCode = MULTIPR_APP_WRONG_NUMBER_OF_ARGUMENTS; + } + else + { + g_usage = MULTIPR_USAGE_AUTOTEST; + g_medFilename = argv[2]; + } + } + else if (strcmp(argv[1],"--part1") == 0) + { + if (argc != 4) + { + g_usage = MULTIPR_USAGE_UNKNOWN; + g_errorCode = MULTIPR_APP_WRONG_NUMBER_OF_ARGUMENTS; + } + else + { + g_usage = MULTIPR_USAGE_PARTITION1; + g_medFilename = argv[2]; + g_meshName = argv[3]; + } + } + else if (strcmp(argv[1],"--part2") == 0) + { + if ((argc != 5) && (argc != 6)) + { + g_usage = MULTIPR_USAGE_UNKNOWN; + g_errorCode = MULTIPR_APP_WRONG_NUMBER_OF_ARGUMENTS; + } + else + { + g_usage = MULTIPR_USAGE_PARTITION2; + g_medFilename = argv[2]; + g_partName = argv[3]; + g_nbParts = atoi(argv[4]); + + if (argc == 6) + { + g_splitter = atoi(argv[5]); + } + } + } + else if (strcmp(argv[1],"--decim") == 0) + { + if ((argc != 10) && (argc != 11)) + { + g_usage = MULTIPR_USAGE_UNKNOWN; + g_errorCode = MULTIPR_APP_WRONG_NUMBER_OF_ARGUMENTS; + } + else + { + g_usage = MULTIPR_USAGE_DECIMATION; + g_medFilename = argv[2]; + g_partName = argv[3]; + g_fieldName = argv[4]; + g_fieldTimeStepIt = atoi(argv[5]); + g_filterName = argv[6]; + g_decimThresholdMed = atof(argv[7]); + g_decimThresholdLow = atof(argv[8]); + g_decimRadius = atof(argv[9]); + + if (argc == 11) + { + g_boxing = atoi(argv[10]); + } + } + } + else if (strcmp(argv[1],"--info") == 0) + { + if ((argc != 3) && (argc != 4)) + { + g_usage = MULTIPR_USAGE_UNKNOWN; + g_errorCode = MULTIPR_APP_WRONG_NUMBER_OF_ARGUMENTS; + } + else + { + g_usage = MULTIPR_USAGE_INFO; + g_medFilename = argv[2]; + + if (argc == 4) + { + g_meshName = argv[3]; + } + } + } + else + { + g_usage = MULTIPR_USAGE_UNKNOWN; + g_errorCode = MULTIPR_APP_UNKNOWN_USAGE; + } } @@ -349,95 +349,95 @@ void parseCommandLine(int argc, char** argv) */ int runAutotest() { - cout << "Start autotest..." << endl; - - int ret = MULTIPR_APP_OK; - try - { - string strMEDfilename = g_medFilename; - strMEDfilename += "/agregat100grains_12pas.med"; - - cout << "Test file: " << strMEDfilename << endl << endl; - - //--------------------------------------------------------------------- - // Test partionneDomaine() = extract groups from a sequential MED file - //--------------------------------------------------------------------- - multipr::partitionneDomaine(strMEDfilename.c_str(), "MAIL"); - - //--------------------------------------------------------------------- - // Test partitionneGrain() = split a group from a distributed MED file - // using MEDSPLITTER (METIS) - //--------------------------------------------------------------------- - string strDistributedMEDfilename = g_medFilename; - strDistributedMEDfilename += "/agregat100grains_12pas_grains_maitre.med"; - - multipr::partitionneGrain( - strDistributedMEDfilename.c_str(), - "MAIL_1", - 4, - multipr::MULTIPR_SCOTCH); - - multipr::partitionneGrain( - strDistributedMEDfilename.c_str(), - "MAIL_97", - 3, - multipr::MULTIPR_METIS); - - //--------------------------------------------------------------------- - // Test decimePartition() = generate 2 lower resolution of a mesh - // using decimation based on gradient - //--------------------------------------------------------------------- - multipr::decimePartition( - strDistributedMEDfilename.c_str(), - "MAIL_98", - "SIG_____SIEF_ELGA_______________", - 12, - "Filtre_GradientMoyen", - 10.0, - 25.0, - 0.3, - 100); - - multipr::decimePartition( - strDistributedMEDfilename.c_str(), - "MAIL_92", - "SIG_____SIEF_ELGA_______________", - 11, - "Filtre_GradientMoyen", - 10.0, - 25.0, - 0.5, - 10); - - multipr::decimePartition( - strDistributedMEDfilename.c_str(), - "MAIL_97_2", - "SIG_____SIEF_ELGA_______________", - 10, - "Filtre_GradientMoyen", - 10.0, - 25.0, - 0.4, - 20); - - //--------------------------------------------------------------------- - // Test passed: OK! - //--------------------------------------------------------------------- - cout << endl; - cout << "Test passed: everything seems to be OK" << endl; - cout << "OK" << endl << endl; - - } - catch (multipr::RuntimeException& e) - { - e.dump(cout); - cout << endl; - cout << "Test failed" << endl; - cout << "Failure" << endl << endl; - ret = MULTIPR_APP_FAILED; - } - - return ret; + cout << "Start autotest..." << endl; + + int ret = MULTIPR_APP_OK; + try + { + string strMEDfilename = g_medFilename; + strMEDfilename += "/agregat100grains_12pas.med"; + + cout << "Test file: " << strMEDfilename << endl << endl; + + //--------------------------------------------------------------------- + // Test partionneDomaine() = extract groups from a sequential MED file + //--------------------------------------------------------------------- + multipr::partitionneDomaine(strMEDfilename.c_str(), "MAIL"); + + //--------------------------------------------------------------------- + // Test partitionneGrain() = split a group from a distributed MED file + // using MEDSPLITTER (METIS) + //--------------------------------------------------------------------- + string strDistributedMEDfilename = g_medFilename; + strDistributedMEDfilename += "/agregat100grains_12pas_grains_maitre.med"; + + multipr::partitionneGrain( + strDistributedMEDfilename.c_str(), + "MAIL_1", + 4, + multipr::MULTIPR_SCOTCH); + + multipr::partitionneGrain( + strDistributedMEDfilename.c_str(), + "MAIL_97", + 3, + multipr::MULTIPR_METIS); + + //--------------------------------------------------------------------- + // Test decimePartition() = generate 2 lower resolution of a mesh + // using decimation based on gradient + //--------------------------------------------------------------------- + multipr::decimePartition( + strDistributedMEDfilename.c_str(), + "MAIL_98", + "SIG_____SIEF_ELGA_______________", + 12, + "Filtre_GradientMoyen", + 10.0, + 25.0, + 0.3, + 100); + + multipr::decimePartition( + strDistributedMEDfilename.c_str(), + "MAIL_92", + "SIG_____SIEF_ELGA_______________", + 11, + "Filtre_GradientMoyen", + 10.0, + 25.0, + 0.5, + 10); + + multipr::decimePartition( + strDistributedMEDfilename.c_str(), + "MAIL_97_2", + "SIG_____SIEF_ELGA_______________", + 10, + "Filtre_GradientMoyen", + 10.0, + 25.0, + 0.4, + 20); + + //--------------------------------------------------------------------- + // Test passed: OK! + //--------------------------------------------------------------------- + cout << endl; + cout << "Test passed: everything seems to be OK" << endl; + cout << "OK" << endl << endl; + + } + catch (multipr::RuntimeException& e) + { + e.dump(cout); + cout << endl; + cout << "Test failed" << endl; + cout << "Failure" << endl << endl; + ret = MULTIPR_APP_FAILED; + } + + return ret; } @@ -448,18 +448,18 @@ int runAutotest() */ int runPartition1() { - int ret = MULTIPR_APP_OK; - try - { - multipr::partitionneDomaine(g_medFilename, g_meshName); - } - catch (multipr::RuntimeException& e) - { - e.dump(cout); - ret = MULTIPR_APP_FAILED; - } - - return ret; + int ret = MULTIPR_APP_OK; + try + { + multipr::partitionneDomaine(g_medFilename, g_meshName); + } + catch (multipr::RuntimeException& e) + { + e.dump(cout); + ret = MULTIPR_APP_FAILED; + } + + return ret; } @@ -469,23 +469,23 @@ int runPartition1() * \return MULTIPR_APP_OK if successful, MULTIPR_APP_FAILED if failure. */ int runPartition2() -{ - int ret = MULTIPR_APP_OK; - try - { - multipr::partitionneGrain( - g_medFilename, - g_partName, - g_nbParts, - g_splitter); - } - catch (multipr::RuntimeException& e) - { - e.dump(cout); - ret = MULTIPR_APP_FAILED; - } - - return ret; +{ + int ret = MULTIPR_APP_OK; + try + { + multipr::partitionneGrain( + g_medFilename, + g_partName, + g_nbParts, + g_splitter); + } + catch (multipr::RuntimeException& e) + { + e.dump(cout); + ret = MULTIPR_APP_FAILED; + } + + return ret; } @@ -495,28 +495,28 @@ int runPartition2() * \return MULTIPR_APP_OK if successful, MULTIPR_APP_FAILED if failure. */ int runDecimation() -{ - int ret = MULTIPR_APP_OK; - try - { - multipr::decimePartition( - g_medFilename, - g_partName, - g_fieldName, - g_fieldTimeStepIt, - g_filterName, - g_decimThresholdMed, - g_decimThresholdLow, - g_decimRadius, - g_boxing); - } - catch (multipr::RuntimeException& e) - { - e.dump(cout); - ret = MULTIPR_APP_FAILED; - } - - return ret; +{ + int ret = MULTIPR_APP_OK; + try + { + multipr::decimePartition( + g_medFilename, + g_partName, + g_fieldName, + g_fieldTimeStepIt, + g_filterName, + g_decimThresholdMed, + g_decimThresholdLow, + g_decimRadius, + g_boxing); + } + catch (multipr::RuntimeException& e) + { + e.dump(cout); + ret = MULTIPR_APP_FAILED; + } + + return ret; } @@ -528,100 +528,100 @@ int runDecimation() int runDumpMED() { #ifdef MULTIPR_USE_OBJ_API - int ret = MULTIPR_APP_OK; - try - { - // if mesh is unknown, then list all the meshes in the given MED file - if (g_meshName == NULL) - { - multipr::Obj obj; - obj.create(g_medFilename); - - { - // display list of meshes contained in the MED file - vector res = obj.getMeshes(); - cout << "List of meshes in this MED file:" << endl; - for (unsigned i = 0 ; i < res.size() ; i++) - { - cout << "Mesh " << (i + 1) << ": " << res[i] << endl; - } - } - - cout << endl; - - { - // display list of fields contained in the MED file - vector names = obj.getFields(); - cout << "List of fields in this MED file:" << endl; - for (unsigned i = 0 ; i < names.size() ; i++) - { - cout << "Field " << (i + 1) << ": " << names[i] << " #it=" << obj.getTimeStamps(names[i].c_str()) << endl; - } - } - } - else - { - // display all infos about one mesh in a MED file - multipr::Mesh mesh; - mesh.readSequentialMED(g_medFilename, g_meshName); - mesh.setPrintAll(true); - cout << mesh << endl; - } - cout << "OK" << endl; - } - catch (multipr::RuntimeException& e) - { - e.dump(cout); - ret = MULTIPR_APP_FAILED; - } - - return ret; + int ret = MULTIPR_APP_OK; + try + { + // if mesh is unknown, then list all the meshes in the given MED file + if (g_meshName == NULL) + { + multipr::Obj obj; + obj.create(g_medFilename); + + { + // display list of meshes contained in the MED file + vector res = obj.getMeshes(); + cout << "List of meshes in this MED file:" << endl; + for (unsigned i = 0 ; i < res.size() ; i++) + { + cout << "Mesh " << (i + 1) << ": \"" << res[i] << "\"" << endl; + } + } + + cout << endl; + + { + // display list of fields contained in the MED file + vector names = obj.getFields(); + cout << "List of scalar fields in this MED file:" << endl; + for (unsigned i = 0 ; i < names.size() ; i++) + { + cout << "Field " << (i + 1) << ": \"" << names[i] << "\" #Time stamps=" << obj.getTimeStamps(names[i].c_str()) << endl; + } + } + } + else + { + // display all infos about one mesh in a MED file + multipr::Mesh mesh; + mesh.readSequentialMED(g_medFilename, g_meshName); + mesh.setPrintAll(true); + cout << mesh << endl; + } + cout << "OK" << endl; + } + catch (multipr::RuntimeException& e) + { + e.dump(cout); + ret = MULTIPR_APP_FAILED; + } + + return ret; #else - int ret = MULTIPR_APP_OK; - try - { - // if mesh is unknown, then list all the meshes in the given MED file - if (g_meshName == NULL) - { - { - // display list of meshes contained in the MED file - vector res = multipr::getListMeshes(g_medFilename); - cout << "List of meshes in this MED file:" << endl; - for (unsigned i = 0 ; i < res.size() ; i++) - { - cout << "Mesh " << (i + 1) << ": " << res[i] << endl; - } - } - - cout << endl; - - { - // display list of fields contained in the MED file - vector > res = multipr::getListScalarFields(g_medFilename); - cout << "List of fields in this MED file:" << endl; - for (unsigned i = 0 ; i < res.size() ; i++) - { - cout << "Field " << (i + 1) << ": " << res[i].first << " #it=" << res[i].second << endl; - } - } - } - else - { - // display all infos about one mesh in a MED file - multipr::Mesh mesh; - mesh.readSequentialMED(g_medFilename, g_meshName); - mesh.setPrintAll(true); - cout << mesh << endl; - } - cout << "OK" << endl; - } - catch (multipr::RuntimeException& e) - { - e.dump(cout); - ret = MULTIPR_APP_FAILED; - } - - return ret; + int ret = MULTIPR_APP_OK; + try + { + // if mesh is unknown, then list all the meshes in the given MED file + if (g_meshName == NULL) + { + { + // display list of meshes contained in the MED file + vector res = multipr::getListMeshes(g_medFilename); + cout << "List of meshes in this MED file:" << endl; + for (unsigned i = 0 ; i < res.size() ; i++) + { + cout << "Mesh " << (i + 1) << ": \"" << res[i] << "\"" << endl; + } + } + + cout << endl; + + { + // display list of fields contained in the MED file + vector > res = multipr::getListScalarFields(g_medFilename); + cout << "List of scalar fields in this MED file:" << endl; + for (unsigned i = 0 ; i < res.size() ; i++) + { + cout << "Field " << (i + 1) << ": \"" << res[i].first << "\" #Time stamps=" << res[i].second << endl; + } + } + } + else + { + // display all infos about one mesh in a MED file + multipr::Mesh mesh; + mesh.readSequentialMED(g_medFilename, g_meshName); + mesh.setPrintAll(true); + cout << mesh << endl; + } + cout << "OK" << endl; + } + catch (multipr::RuntimeException& e) + { + e.dump(cout); + ret = MULTIPR_APP_FAILED; + } + + return ret; #endif } @@ -633,23 +633,23 @@ int runDumpMED() */ int run() { - printGlobals(); - - int ret = MULTIPR_APP_OK; - switch (g_usage) - { - case MULTIPR_USAGE_AUTOTEST: ret = runAutotest(); break; - case MULTIPR_USAGE_PARTITION1: ret = runPartition1(); break; - case MULTIPR_USAGE_PARTITION2: ret = runPartition2(); break; - case MULTIPR_USAGE_DECIMATION: ret = runDecimation(); break; - case MULTIPR_USAGE_INFO: ret = runDumpMED(); break; - default: - cout << "ERROR: unknown usage" << endl; - ret = MULTIPR_APP_FAILED; - break; - } - - return ret; + printGlobals(); + + int ret = MULTIPR_APP_OK; + switch (g_usage) + { + case MULTIPR_USAGE_AUTOTEST: ret = runAutotest(); break; + case MULTIPR_USAGE_PARTITION1: ret = runPartition1(); break; + case MULTIPR_USAGE_PARTITION2: ret = runPartition2(); break; + case MULTIPR_USAGE_DECIMATION: ret = runDecimation(); break; + case MULTIPR_USAGE_INFO: ret = runDumpMED(); break; + default: + cout << "ERROR: unknown usage" << endl; + ret = MULTIPR_APP_FAILED; + break; + } + + return ret; } @@ -662,48 +662,53 @@ int run() */ int main(int argc, char** argv) { - cout << "multipr v" << multipr::getVersion() << " - by EDF/CS - 01/2007" << endl; - cout << "==================================" << endl; - - #ifdef MULTIPR_USE_OBJ_API - cout << "Version MULTIPR_Obj" << endl; - #else - cout << "Version MULTIPR_API" << endl; - #endif - - parseCommandLine(argc, argv); - - int ret = MULTIPR_APP_OK; // assume no error at the beginning - - if (g_usage == MULTIPR_USAGE_UNKNOWN) - { - if (argc != 1) - { - // if usage is unknown and there are some arguments, print an error message - cout << "ERROR: " << getErrorMsg() << endl; - cout << endl; - ret = MULTIPR_APP_FAILED; - } - else - { - // if no argument, print a description of this application - printDescription(); - } - - printUsage(); - } - else if (g_usage == MULTIPR_USAGE_DISPLAY_HELP) - { - printDescription(); - printUsage(); - } - else - { - // the application seems to be configured properly: it can be executed - ret = run(); - } - - return ret; + string strTitle = string("multipr v") + string(multipr::getVersion()) + string(" - by EDF/CS - 03/2007"); + string strUnderline = ""; + + for (int i = 0, len = strTitle.length() ; i < len ; i++) strUnderline += '='; + + cout << strTitle << endl; + cout << strUnderline << endl; + + #ifdef MULTIPR_USE_OBJ_API + cout << "Version MULTIPR_Obj" << endl; + #else + cout << "Version MULTIPR_API" << endl; + #endif + + parseCommandLine(argc, argv); + + int ret = MULTIPR_APP_OK; // assume no error at the beginning + + if (g_usage == MULTIPR_USAGE_UNKNOWN) + { + if (argc != 1) + { + // if usage is unknown and there are some arguments, print an error message + cout << "ERROR: " << getErrorMsg() << endl; + cout << endl; + ret = MULTIPR_APP_FAILED; + } + else + { + // if no argument, print a description of this application + printDescription(); + } + + printUsage(); + } + else if (g_usage == MULTIPR_USAGE_DISPLAY_HELP) + { + printDescription(); + printUsage(); + } + else + { + // the application seems to be configured properly: it can be executed + ret = run(); + } + + return ret; } // EOF diff --git a/src/MULTIPRGUI/MULTIPR_GUI.cxx b/src/MULTIPRGUI/MULTIPR_GUI.cxx index d54fa0c..d74519e 100644 --- a/src/MULTIPRGUI/MULTIPR_GUI.cxx +++ b/src/MULTIPRGUI/MULTIPR_GUI.cxx @@ -71,8 +71,9 @@ using namespace std; namespace multipr { - // progress callback used by the MULTIPR library - extern MULTIPR_ProgressCallback* gProgressCallback; + // progress callback used by the MULTIPR library + extern MULTIPR_ProgressCallback* gProgressCallback; + extern MULTIPR_EmptyMeshCallback* gEmptyMeshCallback; } @@ -83,23 +84,23 @@ namespace multipr // singleton MULTIPR_ORB::MULTIPR_Gen_ptr GetMultiprGen(const CAM_Module* theModule) { - static MULTIPR_ORB::MULTIPR_Gen_ptr aGen = NULL; + static MULTIPR_ORB::MULTIPR_Gen_ptr aGen = NULL; - if (!aGen) - { - SALOME_LifeCycleCORBA aLCC(SalomeApp_Application::namingService()); - Engines::Component_var aComponent = aLCC.FindOrLoad_Component("FactoryServer", "MULTIPR"); - aGen = MULTIPR_ORB::MULTIPR_Gen::_narrow(aComponent); - if (!CORBA::is_nil(aGen)) - { - //aGen->SetCurrentStudy(GetDSStudy(GetCStudy(GetAppStudy(theModule)))); - } - } + if (!aGen) + { + SALOME_LifeCycleCORBA aLCC(SalomeApp_Application::namingService()); + Engines::Component_var aComponent = aLCC.FindOrLoad_Component("FactoryServer", "MULTIPR"); + aGen = MULTIPR_ORB::MULTIPR_Gen::_narrow(aComponent); + if (!CORBA::is_nil(aGen)) + { + //aGen->SetCurrentStudy(GetDSStudy(GetCStudy(GetAppStudy(theModule)))); + } + } - if (CORBA::is_nil(aGen)) - throw std::runtime_error("Can't find MULTIPR component"); + if (CORBA::is_nil(aGen)) + throw std::runtime_error("Can't find MULTIPR component"); - return aGen; + return aGen; } @@ -109,574 +110,577 @@ MULTIPR_ORB::MULTIPR_Gen_ptr GetMultiprGen(const CAM_Module* theModule) MULTIPR_GUI::MULTIPR_GUI() : SalomeApp_Module("MULTIPR") { - mMEDFileName = ""; - mMULTIPRObj = NULL; + mMEDFileName = ""; + mMULTIPRObj = NULL; } MULTIPR_GUI::~MULTIPR_GUI() { - if (mMULTIPRObj != NULL) - { - CORBA::release(mMULTIPRObj); - } + if (mMULTIPRObj != NULL) + { + CORBA::release(mMULTIPRObj); + } } MULTIPR_ORB::MULTIPR_Obj_ptr MULTIPR_GUI::getMULTIPRObj() { - return mMULTIPRObj; + return mMULTIPRObj; } SalomeApp_Application* MULTIPR_GUI::getAppli() const { - return getApp(); + return getApp(); } void MULTIPR_GUI::initialize(CAM_Application* app) { - SalomeApp_Module::initialize(app); - - GetMultiprGen(this); - - QWidget* aParent = app->desktop(); - SUIT_ResourceMgr* aResourceMgr = app->resourceMgr(); - - //------------------------------------------------------------------------- - // create actions - //------------------------------------------------------------------------- - QPixmap aPixmapImportFromMEDFile = aResourceMgr->loadPixmap("MULTIPR", tr("MULTIPR_ICON_IMPORT_MED")); - - createAction( - ACTION_IMPORT_MED, - tr("MULTIPR_TLT_IMPORT_FROM_MED_FILE"), - QIconSet(aPixmapImportFromMEDFile), - tr("MULTIPR_MEN_IMPORT_FROM_MED_FILE"), - tr("MULTIPR_STS_IMPORT_FROM_MED_FILE"), - (CTRL + Key_I), - aParent, - false, - this, - SLOT(OnImportFromMEDFile())); - - createAction( - ACTION_SPLIT, - tr("MULTIPR_TLT_SPLIT"), - QIconSet(), - tr("MULTIPR_MEN_SPLIT"), - tr("MULTIPR_STS_SPLIT"), - 0, - aParent, - false, - this, - SLOT(OnPartition2())); - - createAction( - ACTION_DECIMATE, - tr("MULTIPR_TLT_DECIMATE"), - QIconSet(), - tr("MULTIPR_MEN_DECIMATE"), - tr("MULTIPR_STS_DECIMATE"), - 0, - aParent, - false, - this, - SLOT(OnDecimate())); - - createAction( - ACTION_REMOVE, - tr("MULTIPR_TLT_REMOVE"), - QIconSet(), - tr("MULTIPR_MEN_REMOVE"), - tr("MULTIPR_STS_REMOVE"), - 0, - aParent, - false, - this, - SLOT(OnRemove())); - - QPixmap aPixmapSaveMEDFile = aResourceMgr->loadPixmap("MULTIPR", tr("MULTIPR_ICON_SAVE_MED")); - - createAction( - ACTION_SAVE, - tr("MULTIPR_TLT_SAVE"), - QIconSet(aPixmapSaveMEDFile), - tr("MULTIPR_MEN_SAVE"), - tr("MULTIPR_STS_SAVE"), - 0, - aParent, - false, - this, - SLOT(OnSave())); - - //------------------------------------------------------------------------- - // create menus - //------------------------------------------------------------------------- - int aMenuId; - aMenuId = createMenu(tr("MULTIPR_MEN_FILE"), -1, -1); - createMenu(separator(), aMenuId, -1, 10); - aMenuId = createMenu(tr("MULTIPR_MEN_FILE_MULTIPR"), aMenuId, -1, 10); - createMenu(ACTION_IMPORT_MED, aMenuId); - - aMenuId = createMenu(tr("MULTIPR_MEN_MULTIPR"), -1, -1, 30); - createMenu(ACTION_IMPORT_MED, aMenuId, 10); - createMenu(ACTION_SAVE, aMenuId, 10); - createMenu(ACTION_SPLIT, aMenuId, 10); - createMenu(ACTION_DECIMATE, aMenuId, 10); - createMenu(ACTION_REMOVE, aMenuId, 10); - - //------------------------------------------------------------------------- - // create toolbars - //------------------------------------------------------------------------- - int aToolId = createTool(tr("MULTIPR_TOOL_MULTIPR")); - createTool(ACTION_IMPORT_MED, aToolId); - createTool(ACTION_SAVE, aToolId); - - //------------------------------------------------------------------------- - // create popup menus - //------------------------------------------------------------------------- - QtxPopupMgr* mgr = popupMgr(); - mgr->insert( action(ACTION_SPLIT), -1, -1, -1 ); - mgr->insert( action(ACTION_DECIMATE), -1, -1, -1 ); - mgr->insert( action(ACTION_REMOVE), -1, -1, -1 ); - mgr->insert( action(ACTION_SAVE), -1, -1, -1 ); - - QString aRule = "client='ObjectBrowser' and selcount>=1"; // $type in {'VISU::TMESH'}"; - mgr->setRule(action(ACTION_SPLIT), aRule, true); - mgr->setRule(action(ACTION_DECIMATE), aRule, true); - mgr->setRule(action(ACTION_REMOVE), aRule, true); - mgr->setRule(action(ACTION_SAVE), aRule, true); - - //------------------------------------------------------------------------- - // set progress dialog - //------------------------------------------------------------------------- - MULTIPR_GUI_ProgressCallbackDlg* progressDlg = new MULTIPR_GUI_ProgressCallbackDlg(application()->desktop()); - multipr::gProgressCallback = progressDlg; + SalomeApp_Module::initialize(app); + + GetMultiprGen(this); + + QWidget* aParent = app->desktop(); + SUIT_ResourceMgr* aResourceMgr = app->resourceMgr(); + + //------------------------------------------------------------------------- + // create actions + //------------------------------------------------------------------------- + QPixmap aPixmapImportFromMEDFile = aResourceMgr->loadPixmap("MULTIPR", tr("MULTIPR_ICON_IMPORT_MED")); + + createAction( + ACTION_IMPORT_MED, + tr("MULTIPR_TLT_IMPORT_FROM_MED_FILE"), + QIconSet(aPixmapImportFromMEDFile), + tr("MULTIPR_MEN_IMPORT_FROM_MED_FILE"), + tr("MULTIPR_STS_IMPORT_FROM_MED_FILE"), + (CTRL + Key_I), + aParent, + false, + this, + SLOT(OnImportFromMEDFile())); + + createAction( + ACTION_SPLIT, + tr("MULTIPR_TLT_SPLIT"), + QIconSet(), + tr("MULTIPR_MEN_SPLIT"), + tr("MULTIPR_STS_SPLIT"), + 0, + aParent, + false, + this, + SLOT(OnPartition2())); + + createAction( + ACTION_DECIMATE, + tr("MULTIPR_TLT_DECIMATE"), + QIconSet(), + tr("MULTIPR_MEN_DECIMATE"), + tr("MULTIPR_STS_DECIMATE"), + 0, + aParent, + false, + this, + SLOT(OnDecimate())); + + createAction( + ACTION_REMOVE, + tr("MULTIPR_TLT_REMOVE"), + QIconSet(), + tr("MULTIPR_MEN_REMOVE"), + tr("MULTIPR_STS_REMOVE"), + 0, + aParent, + false, + this, + SLOT(OnRemove())); + + QPixmap aPixmapSaveMEDFile = aResourceMgr->loadPixmap("MULTIPR", tr("MULTIPR_ICON_SAVE_MED")); + + createAction( + ACTION_SAVE, + tr("MULTIPR_TLT_SAVE"), + QIconSet(aPixmapSaveMEDFile), + tr("MULTIPR_MEN_SAVE"), + tr("MULTIPR_STS_SAVE"), + 0, + aParent, + false, + this, + SLOT(OnSave())); + + //------------------------------------------------------------------------- + // create menus + //------------------------------------------------------------------------- + int aMenuId; + aMenuId = createMenu(tr("MULTIPR_MEN_FILE"), -1, -1); + createMenu(separator(), aMenuId, -1, 10); + aMenuId = createMenu(tr("MULTIPR_MEN_FILE_MULTIPR"), aMenuId, -1, 10); + createMenu(ACTION_IMPORT_MED, aMenuId); + + aMenuId = createMenu(tr("MULTIPR_MEN_MULTIPR"), -1, -1, 30); + createMenu(ACTION_IMPORT_MED, aMenuId, 10); + createMenu(ACTION_SAVE, aMenuId, 10); + createMenu(ACTION_SPLIT, aMenuId, 10); + createMenu(ACTION_DECIMATE, aMenuId, 10); + createMenu(ACTION_REMOVE, aMenuId, 10); + + //------------------------------------------------------------------------- + // create toolbars + //------------------------------------------------------------------------- + int aToolId = createTool(tr("MULTIPR_TOOL_MULTIPR")); + createTool(ACTION_IMPORT_MED, aToolId); + createTool(ACTION_SAVE, aToolId); + + //------------------------------------------------------------------------- + // create popup menus + //------------------------------------------------------------------------- + QtxPopupMgr* mgr = popupMgr(); + mgr->insert( action(ACTION_SPLIT), -1, -1, -1 ); + mgr->insert( action(ACTION_DECIMATE), -1, -1, -1 ); + mgr->insert( action(ACTION_REMOVE), -1, -1, -1 ); + mgr->insert( action(ACTION_SAVE), -1, -1, -1 ); + + QString aRule = "client='ObjectBrowser' and selcount>=1"; // $type in {'VISU::TMESH'}"; + mgr->setRule(action(ACTION_SPLIT), aRule, true); + mgr->setRule(action(ACTION_DECIMATE), aRule, true); + mgr->setRule(action(ACTION_REMOVE), aRule, true); + mgr->setRule(action(ACTION_SAVE), aRule, true); + + //------------------------------------------------------------------------- + // set progress dialog + //------------------------------------------------------------------------- + MULTIPR_GUI_ProgressCallbackDlg* progressDlg = new MULTIPR_GUI_ProgressCallbackDlg(application()->desktop()); + multipr::gProgressCallback = progressDlg; + + MULTIPR_GUI_EmptyMeshCallbackDlg* emptyMeshDlg = new MULTIPR_GUI_EmptyMeshCallbackDlg(application()->desktop()); + multipr::gEmptyMeshCallback = emptyMeshDlg; } CAM_DataModel* MULTIPR_GUI::createDataModel() { - return new MULTIPR_GUI_DataModel(this); + return new MULTIPR_GUI_DataModel(this); } QString MULTIPR_GUI::engineIOR() const { - CORBA::String_var anIOR = getApp()->orb()->object_to_string(GetMultiprGen(this)); - return QString(anIOR.in()); + CORBA::String_var anIOR = getApp()->orb()->object_to_string(GetMultiprGen(this)); + return QString(anIOR.in()); } bool MULTIPR_GUI::activateModule(SUIT_Study* theStudy) { - bool bOk = SalomeApp_Module::activateModule(theStudy); - - setMenuShown(true); - setToolShown(true); - - action(ACTION_IMPORT_MED)->setAccel(QKeySequence(CTRL + Key_I)); - - return bOk; + bool bOk = SalomeApp_Module::activateModule(theStudy); + + setMenuShown(true); + setToolShown(true); + + action(ACTION_IMPORT_MED)->setAccel(QKeySequence(CTRL + Key_I)); + + return bOk; } bool MULTIPR_GUI::deactivateModule(SUIT_Study* theStudy) { - setMenuShown(false); - setToolShown(false); - - // Unset actions accelerator keys - action(ACTION_IMPORT_MED)->setAccel(QKeySequence()); + setMenuShown(false); + setToolShown(false); + + // Unset actions accelerator keys + action(ACTION_IMPORT_MED)->setAccel(QKeySequence()); - return SalomeApp_Module::deactivateModule(theStudy); + return SalomeApp_Module::deactivateModule(theStudy); } void MULTIPR_GUI::windows(QMap& theMap) const { - theMap.clear(); - theMap.insert(SalomeApp_Application::WT_ObjectBrowser, Qt::DockLeft); - theMap.insert(SalomeApp_Application::WT_PyConsole, Qt::DockBottom); + theMap.clear(); + theMap.insert(SalomeApp_Application::WT_ObjectBrowser, Qt::DockLeft); + theMap.insert(SalomeApp_Application::WT_PyConsole, Qt::DockBottom); } void MULTIPR_GUI::selected(QStringList& entries, const bool multiple) { - LightApp_SelectionMgr* mgr = getApp()->selectionMgr(); - - if(!mgr) return; - - SUIT_DataOwnerPtrList anOwnersList; - mgr->selected(anOwnersList); - - for (int i = 0 ; i < anOwnersList.size() ; i++) - { - const LightApp_DataOwner* owner = dynamic_cast(anOwnersList[i].get()); - - if (!entries.contains(owner->entry())) - { - entries.append(owner->entry()); - } - - if (!multiple) - break; - } + LightApp_SelectionMgr* mgr = getApp()->selectionMgr(); + + if(!mgr) return; + + SUIT_DataOwnerPtrList anOwnersList; + mgr->selected(anOwnersList); + + for (int i = 0 ; i < anOwnersList.size() ; i++) + { + const LightApp_DataOwner* owner = dynamic_cast(anOwnersList[i].get()); + + if (!entries.contains(owner->entry())) + { + entries.append(owner->entry()); + } + + if (!multiple) + break; + } } void MULTIPR_GUI::OnImportFromMEDFile() { - // Get file name - QStringList aFilter; - aFilter.append(tr("MULTIPR_FLT_MED_FILES")); - aFilter.append(tr("MULTIPR_FLT_ALL_FILES")); - - SalomeApp_CheckFileDlg* fd = new SalomeApp_CheckFileDlg( - this->application()->desktop(), - true, - tr("") ); - - fd->setCaption(tr("MULTIPR_MEN_IMPORT_FROM_MED_FILE")); - fd->setFilters(aFilter); - if (fd->exec() == QDialog::Rejected) - { - delete fd; - return; - } - - QFileInfo aFileInfo(fd->selectedFile()); - delete fd; - - // Check the file name - if (!aFileInfo.exists()) - return; - - mMEDFileName = aFileInfo.filePath(); - - QApplication::setOverrideCursor(Qt::waitCursor); - - try - { - MULTIPR_ORB::MULTIPR_Gen_ptr multiprgen = GetMultiprGen(this); - mMULTIPRObj = multiprgen->getObject(mMEDFileName.latin1()); - } - catch(...) - { - SUIT_MessageBox::error1( - getApp()->desktop(), - "Import MED file error", - "Invalid MED file (not recognized by MULTIPR)", - tr("MULTIPR_BUT_OK") ); - } - QApplication::restoreOverrideCursor(); - - if (mMULTIPRObj != NULL) - { - try - { - if (mMULTIPRObj->isValidSequentialMEDFile()) - { - OnPartition1(); - } - } - catch (...) - { - } - - getApp()->updateObjectBrowser(); - } + // Get file name + QStringList aFilter; + aFilter.append(tr("MULTIPR_FLT_MED_FILES")); + aFilter.append(tr("MULTIPR_FLT_ALL_FILES")); + + SalomeApp_CheckFileDlg* fd = new SalomeApp_CheckFileDlg( + this->application()->desktop(), + true, + tr("") ); + + fd->setCaption(tr("MULTIPR_MEN_IMPORT_FROM_MED_FILE")); + fd->setFilters(aFilter); + if (fd->exec() == QDialog::Rejected) + { + delete fd; + return; + } + + QFileInfo aFileInfo(fd->selectedFile()); + delete fd; + + // Check the file name + if (!aFileInfo.exists()) + return; + + mMEDFileName = aFileInfo.filePath(); + + QApplication::setOverrideCursor(Qt::waitCursor); + + try + { + MULTIPR_ORB::MULTIPR_Gen_ptr multiprgen = GetMultiprGen(this); + mMULTIPRObj = multiprgen->getObject(mMEDFileName.latin1()); + } + catch(...) + { + SUIT_MessageBox::error1( + getApp()->desktop(), + "Import MED file error", + "Invalid MED file (not recognized by MULTIPR)", + tr("MULTIPR_BUT_OK") ); + } + QApplication::restoreOverrideCursor(); + + if (mMULTIPRObj != NULL) + { + try + { + if (mMULTIPRObj->isValidSequentialMEDFile()) + { + OnPartition1(); + } + } + catch (...) + { + } + + getApp()->updateObjectBrowser(); + } } void MULTIPR_GUI::OnPartition1() { - // check if MULTIPRObj exists - if (mMULTIPRObj == NULL) - { - return; - } - - MULTIPR_GUI_Partition1Dlg* dialog = new MULTIPR_GUI_Partition1Dlg(this); - dialog->exec(); - delete dialog; + // check if MULTIPRObj exists + if (mMULTIPRObj == NULL) + { + return; + } + + MULTIPR_GUI_Partition1Dlg* dialog = new MULTIPR_GUI_Partition1Dlg(this); + dialog->exec(); + delete dialog; } void MULTIPR_GUI::OnPartition2() { - // check if MULTIPRObj exists - if (mMULTIPRObj == NULL) - { - return; - } - - retrieveSelectedParts(); - - if (mSelectedParts.count() == 0) - { - SUIT_MessageBox::warn1( - getApp()->desktop(), - "Split warning", - "No parts selected", - tr("MULTIPR_BUT_OK") ); - return; - } - - if (!removeLowerResolution()) - { - return; - } - - MULTIPR_GUI_Partition2Dlg* dialog = new MULTIPR_GUI_Partition2Dlg(this); - dialog->exec(); - delete dialog; - getApp()->updateObjectBrowser(); + // check if MULTIPRObj exists + if (mMULTIPRObj == NULL) + { + return; + } + + retrieveSelectedParts(); + + if (mSelectedParts.count() == 0) + { + SUIT_MessageBox::warn1( + getApp()->desktop(), + "Split warning", + "No parts selected", + tr("MULTIPR_BUT_OK") ); + return; + } + + if (!removeLowerResolution()) + { + return; + } + + MULTIPR_GUI_Partition2Dlg* dialog = new MULTIPR_GUI_Partition2Dlg(this); + dialog->exec(); + delete dialog; + getApp()->updateObjectBrowser(); } void MULTIPR_GUI::OnDecimate() { - // check if MULTIPRObj exists - if (mMULTIPRObj == NULL) - { - return; - } - - retrieveSelectedParts(); - - if (mSelectedParts.count() == 0) - { - SUIT_MessageBox::warn1( - getApp()->desktop(), - "Decimation warning", - "No parts selected", - tr("MULTIPR_BUT_OK") ); - return; - } - - if (!removeLowerResolution()) - { - return; - } - - MULTIPR_GUI_DecimateDlg* dialog = new MULTIPR_GUI_DecimateDlg(this); - dialog->exec(); - delete dialog; - getApp()->updateObjectBrowser(); + // check if MULTIPRObj exists + if (mMULTIPRObj == NULL) + { + return; + } + + retrieveSelectedParts(); + + if (mSelectedParts.count() == 0) + { + SUIT_MessageBox::warn1( + getApp()->desktop(), + "Decimation warning", + "No parts selected", + tr("MULTIPR_BUT_OK") ); + return; + } + + if (!removeLowerResolution()) + { + return; + } + + MULTIPR_GUI_DecimateDlg* dialog = new MULTIPR_GUI_DecimateDlg(this); + dialog->exec(); + delete dialog; + getApp()->updateObjectBrowser(); } void MULTIPR_GUI::OnRemove() { - // check if MULTIPRObj exists - if (mMULTIPRObj == NULL) - { - return; - } - - retrieveSelectedParts(); - - if (mSelectedParts.count() == 0) - { - SUIT_MessageBox::warn1( - getApp()->desktop(), - "Remove warning", - "No parts selected", - tr("MULTIPR_BUT_OK") ); - return; - } - - if (QMessageBox::question( + // check if MULTIPRObj exists + if (mMULTIPRObj == NULL) + { + return; + } + + retrieveSelectedParts(); + + if (mSelectedParts.count() == 0) + { + SUIT_MessageBox::warn1( + getApp()->desktop(), + "Remove warning", + "No parts selected", + tr("MULTIPR_BUT_OK") ); + return; + } + + if (QMessageBox::question( getApp()->desktop(), tr("Remove selected part(s)"), tr("Do you want to remove selected part(s)?"), tr("&Yes"), tr("&No"), QString::null, 0, 1 ) ) - { - return; - } - - QApplication::setOverrideCursor(Qt::waitCursor); - - try - { - for (QStringList::const_iterator it = mSelectedParts.begin(), last = mSelectedParts.end(); it != last; it++) - { - const QString& partName = (*it); - cout << "Remove " << partName.latin1() << endl; - mMULTIPRObj->removeParts(partName.latin1()); - } - - } - catch(...) - { - SUIT_MessageBox::error1( - getApp()->desktop(), - "Remove error", - "Error while removing selected part(s)", - tr("MULTIPR_BUT_OK") ); - } - - QApplication::restoreOverrideCursor(); - - getApp()->updateObjectBrowser(); + { + return; + } + + QApplication::setOverrideCursor(Qt::waitCursor); + + try + { + for (QStringList::const_iterator it = mSelectedParts.begin(), last = mSelectedParts.end(); it != last; it++) + { + const QString& partName = (*it); + cout << "Remove " << partName.latin1() << endl; + mMULTIPRObj->removeParts(partName.latin1()); + } + + } + catch(...) + { + SUIT_MessageBox::error1( + getApp()->desktop(), + "Remove error", + "Error while removing selected part(s)", + tr("MULTIPR_BUT_OK") ); + } + + QApplication::restoreOverrideCursor(); + + getApp()->updateObjectBrowser(); } void MULTIPR_GUI::OnSave() { - // check if MULTIPRObj exists - if (mMULTIPRObj == NULL) - { - return; - } - - SalomeApp_CheckFileDlg* fd = new SalomeApp_CheckFileDlg( - this->application()->desktop(), - true, - tr("") ); - - fd->setCaption(tr("Save distributed MED file - Destination directory")); - fd->setMode(QFileDialog::DirectoryOnly); - - if (fd->exec() == QDialog::Rejected) - { - delete fd; - return; - } - - QFileInfo aFileInfo(fd->selectedFile()); - delete fd; - - QString path = aFileInfo.filePath(); - - QApplication::setOverrideCursor(Qt::waitCursor); - - try - { - mMULTIPRObj->save(path); - getApp()->updateObjectBrowser(); - } - catch(...) - { - SUIT_MessageBox::error1( - getApp()->desktop(), - "Save distributed MED file error", - "Error while writing distributed MED file", - tr("MULTIPR_BUT_OK") ); - } - - QApplication::restoreOverrideCursor(); + // check if MULTIPRObj exists + if (mMULTIPRObj == NULL) + { + return; + } + + SalomeApp_CheckFileDlg* fd = new SalomeApp_CheckFileDlg( + this->application()->desktop(), + true, + tr("") ); + + fd->setCaption(tr("Save distributed MED file - Destination directory")); + fd->setMode(QFileDialog::DirectoryOnly); + + if (fd->exec() == QDialog::Rejected) + { + delete fd; + return; + } + + QFileInfo aFileInfo(fd->selectedFile()); + delete fd; + + QString path = aFileInfo.filePath(); + + QApplication::setOverrideCursor(Qt::waitCursor); + + try + { + mMULTIPRObj->save(path); + getApp()->updateObjectBrowser(); + } + catch(...) + { + SUIT_MessageBox::error1( + getApp()->desktop(), + "Save distributed MED file error", + "Error while writing distributed MED file", + tr("MULTIPR_BUT_OK") ); + } + + QApplication::restoreOverrideCursor(); } void MULTIPR_GUI::retrieveSelectedParts() { - mSelectedParts.clear(); - - QStringList userSelection; - selected(userSelection, true); - for (QStringList::const_iterator it = userSelection.begin(), last = userSelection.end(); it != last; it++) - { - const QString& str = (*it); - QStringList words = QStringList::split(":", str); - if (words.count() == 2) - { - if (words[0] == "MULTIPR_PART") - { - mSelectedParts.push_back(words[1]); - } - } + mSelectedParts.clear(); + + QStringList userSelection; + selected(userSelection, true); + for (QStringList::const_iterator it = userSelection.begin(), last = userSelection.end(); it != last; it++) + { + const QString& str = (*it); + QStringList words = QStringList::split(":", str); + if (words.count() == 2) + { + if (words[0] == "MULTIPR_PART") + { + mSelectedParts.push_back(words[1]); + } + } } } bool MULTIPR_GUI::isPartExist(const char* partName) { - if (mMULTIPRObj == NULL) return false; - - MULTIPR_ORB::string_array* listParts = mMULTIPRObj->getParts(); - for (int i=0 ; ilength() ; i++) - { - const char* strItem = (*listParts)[i]; - if (strcmp(strItem, partName) == 0) - { - return true; - } - } - return false; + if (mMULTIPRObj == NULL) return false; + + MULTIPR_ORB::string_array* listParts = mMULTIPRObj->getParts(); + for (int i=0 ; ilength() ; i++) + { + const char* strItem = (*listParts)[i]; + if (strcmp(strItem, partName) == 0) + { + return true; + } + } + return false; } bool MULTIPR_GUI::removeLowerResolution() { - // for each selected part, check if there are lower resolution - // and then propose to remove them before performing new process - QStringList partNameLowerResolution; - for (QStringList::const_iterator it = mSelectedParts.begin(), last = mSelectedParts.end(); it != last; it++) - { - const QString& partName = (*it); - QString partNameLow = partName + "_LOW"; - QString partNameMed = partName + "_MED"; - const char* strPartNameLow = partNameLow.latin1(); - const char* strPartNameMed = partNameMed.latin1(); - - if (isPartExist(strPartNameLow)) - { - partNameLowerResolution.push_back(partNameLow); - cout << "Part to be removed: " << partNameLow << endl; - } - - if (isPartExist(strPartNameMed)) - { - partNameLowerResolution.push_back(partNameMed); - cout << "Part to be removed: " << partNameMed << endl; - } - } - - if (partNameLowerResolution.count() > 0) - { - if (QMessageBox::question( - getApp()->desktop(), - tr("Remove previous results"), - tr("Do you want to remove previous results?"), - tr("&Yes"), tr("&No"), - QString::null, 0, 1 ) ) - { - return false; - } - - QApplication::setOverrideCursor(Qt::waitCursor); - - try - { - for (QStringList::const_iterator it = partNameLowerResolution.begin(), last = partNameLowerResolution.end(); it != last; it++) - { - const QString& partName = (*it); - cout << "Remove " << partName.latin1() << endl; - mMULTIPRObj->removeParts(partName.latin1()); - } - - } - catch(...) - { - SUIT_MessageBox::error1( - getApp()->desktop(), - "Remove error", - "Error while removing previous results", - tr("MULTIPR_BUT_OK") ); - } - - QApplication::restoreOverrideCursor(); - - getApp()->updateObjectBrowser(); - } - - return true; + // for each selected part, check if there are lower resolution + // and then propose to remove them before performing new process + QStringList partNameLowerResolution; + for (QStringList::const_iterator it = mSelectedParts.begin(), last = mSelectedParts.end(); it != last; it++) + { + const QString& partName = (*it); + QString partNameLow = partName + "_LOW"; + QString partNameMed = partName + "_MED"; + const char* strPartNameLow = partNameLow.latin1(); + const char* strPartNameMed = partNameMed.latin1(); + + if (isPartExist(strPartNameLow)) + { + partNameLowerResolution.push_back(partNameLow); + cout << "Part to be removed: " << partNameLow << endl; + } + + if (isPartExist(strPartNameMed)) + { + partNameLowerResolution.push_back(partNameMed); + cout << "Part to be removed: " << partNameMed << endl; + } + } + + if (partNameLowerResolution.count() > 0) + { + if (QMessageBox::question( + getApp()->desktop(), + tr("Remove previous results"), + tr("Do you want to remove previous results?"), + tr("&Yes"), tr("&No"), + QString::null, 0, 1 ) ) + { + return false; + } + + QApplication::setOverrideCursor(Qt::waitCursor); + + try + { + for (QStringList::const_iterator it = partNameLowerResolution.begin(), last = partNameLowerResolution.end(); it != last; it++) + { + const QString& partName = (*it); + cout << "Remove " << partName.latin1() << endl; + mMULTIPRObj->removeParts(partName.latin1()); + } + + } + catch(...) + { + SUIT_MessageBox::error1( + getApp()->desktop(), + "Remove error", + "Error while removing previous results", + tr("MULTIPR_BUT_OK") ); + } + + QApplication::restoreOverrideCursor(); + + getApp()->updateObjectBrowser(); + } + + return true; } @@ -685,22 +689,22 @@ bool MULTIPR_GUI::removeLowerResolution() //***************************************************************************** MULTIPR_GUI_DataObject::MULTIPR_GUI_DataObject(SUIT_DataObject* parent, const char* name) : - LightApp_DataObject(parent), - CAM_DataObject(parent) + LightApp_DataObject(parent), + CAM_DataObject(parent) { - mName = name; + mName = name; } MULTIPR_GUI_DataObject::~MULTIPR_GUI_DataObject() { - // do nothing! + // do nothing! } QString MULTIPR_GUI_DataObject::entry() const { - return QString("MULTIPR_OBJECT"); + return QString("MULTIPR_OBJECT"); } @@ -712,16 +716,16 @@ QString MULTIPR_GUI_DataObject::name() const QPixmap MULTIPR_GUI_DataObject::icon() const { - //static QPixmap icon = SUIT_Session::session()->resourceMgr()->loadPixmap("MULTIPR", QObject::tr("ICON_IMPORT_MED"), false); - return QPixmap(); - + //static QPixmap icon = SUIT_Session::session()->resourceMgr()->loadPixmap("MULTIPR", QObject::tr("ICON_IMPORT_MED"), false); + return QPixmap(); + } QString MULTIPR_GUI_DataObject::toolTip() const { - // default behaviour: return an empty string - return ""; + // default behaviour: return an empty string + return ""; } @@ -730,23 +734,23 @@ QString MULTIPR_GUI_DataObject::toolTip() const //***************************************************************************** MULTIPR_GUI_DataObject_Module::MULTIPR_GUI_DataObject_Module(CAM_DataModel* dm, SUIT_DataObject* parent, const char* name) : - MULTIPR_GUI_DataObject(parent, name), - LightApp_ModuleObject(dm, parent), - CAM_DataObject(parent) + MULTIPR_GUI_DataObject(parent, name), + LightApp_ModuleObject(dm, parent), + CAM_DataObject(parent) { - // do nothing! + // do nothing! } MULTIPR_GUI_DataObject_Module::~MULTIPR_GUI_DataObject_Module() { - // do nothing! + // do nothing! } QString MULTIPR_GUI_DataObject_Module::entry() const { - return QString("MULTIPR_MODULE:" + mName); + return QString("MULTIPR_MODULE:" + mName); } @@ -758,13 +762,13 @@ QString MULTIPR_GUI_DataObject_Module::name() const QPixmap MULTIPR_GUI_DataObject_Module::icon() const { - return QPixmap(); + return QPixmap(); } QString MULTIPR_GUI_DataObject_Module::toolTip() const { - return QString("Module MULTIPR"); + return QString("Module MULTIPR"); } @@ -773,34 +777,34 @@ QString MULTIPR_GUI_DataObject_Module::toolTip() const //***************************************************************************** MULTIPR_GUI_DataObject_Mesh::MULTIPR_GUI_DataObject_Mesh(SUIT_DataObject* parent, const char* name) : - MULTIPR_GUI_DataObject(parent, name), - CAM_DataObject(parent) + MULTIPR_GUI_DataObject(parent, name), + CAM_DataObject(parent) { - // do nothing! + // do nothing! } MULTIPR_GUI_DataObject_Mesh::~MULTIPR_GUI_DataObject_Mesh() { - // do nothing! + // do nothing! } QString MULTIPR_GUI_DataObject_Mesh::entry() const { - return QString("MULTIPR_MESH:") + mName; + return QString("MULTIPR_MESH:") + mName; } QPixmap MULTIPR_GUI_DataObject_Mesh::icon() const { - return QPixmap(); + return QPixmap(); } QString MULTIPR_GUI_DataObject_Mesh::toolTip() const { - return QString("Original mesh"); + return QString("Original mesh"); } @@ -809,61 +813,61 @@ QString MULTIPR_GUI_DataObject_Mesh::toolTip() const //***************************************************************************** MULTIPR_GUI_DataObject_Part::MULTIPR_GUI_DataObject_Part(SUIT_DataObject* parent, const char* name, const char* info) : - MULTIPR_GUI_DataObject(parent, name), - CAM_DataObject(parent) -{ - mMeshName = ""; - mId = 0; - mPath = ""; - mMEDFileName = ""; - - mTooltip = info; - - // parse info to retrieve all the fields - char lMeshName[256]; - int lId; - char lPartName[256]; - char lPath[256]; - char lMEDFileName[256]; - - int ret = sscanf(info, "%s %d %s %s %s", - lMeshName, - &lId, - lPartName, - lPath, - lMEDFileName); - - // number of read parameters should be 5 - if (ret != 5) return; - - mMeshName = lMeshName; - mId = lId; - mPath = lPath; - mMEDFileName = lMEDFileName; + MULTIPR_GUI_DataObject(parent, name), + CAM_DataObject(parent) +{ + mMeshName = ""; + mId = 0; + mPath = ""; + mMEDFileName = ""; + + mTooltip = info; + + // parse info to retrieve all the fields + char lMeshName[256]; + int lId; + char lPartName[256]; + char lPath[256]; + char lMEDFileName[256]; + + int ret = sscanf(info, "%s %d %s %s %s", + lMeshName, + &lId, + lPartName, + lPath, + lMEDFileName); + + // number of read parameters should be 5 + if (ret != 5) return; + + mMeshName = lMeshName; + mId = lId; + mPath = lPath; + mMEDFileName = lMEDFileName; } MULTIPR_GUI_DataObject_Part::~MULTIPR_GUI_DataObject_Part() { - // do nothing! + // do nothing! } QString MULTIPR_GUI_DataObject_Part::entry() const { - return QString("MULTIPR_PART:") + mName; + return QString("MULTIPR_PART:") + mName; } QPixmap MULTIPR_GUI_DataObject_Part::icon() const { - return QPixmap(); + return QPixmap(); } QString MULTIPR_GUI_DataObject_Part::toolTip() const { - return mTooltip; + return mTooltip; } @@ -872,34 +876,34 @@ QString MULTIPR_GUI_DataObject_Part::toolTip() const //***************************************************************************** MULTIPR_GUI_DataObject_Resolution::MULTIPR_GUI_DataObject_Resolution(SUIT_DataObject* parent, const char* name, const char* info) : - MULTIPR_GUI_DataObject_Part(parent, name, info), - CAM_DataObject(parent) + MULTIPR_GUI_DataObject_Part(parent, name, info), + CAM_DataObject(parent) { - // do nothing! + // do nothing! } MULTIPR_GUI_DataObject_Resolution::~MULTIPR_GUI_DataObject_Resolution() { - // do nothing! + // do nothing! } QString MULTIPR_GUI_DataObject_Resolution::entry() const { - return QString("MULTIPR_RESOLUTION:") + mName; + return QString("MULTIPR_RESOLUTION:") + mName; } QPixmap MULTIPR_GUI_DataObject_Resolution::icon() const { - return QPixmap(); + return QPixmap(); } QString MULTIPR_GUI_DataObject_Resolution::toolTip() const { - return mTooltip; + return mTooltip; } @@ -908,106 +912,106 @@ QString MULTIPR_GUI_DataObject_Resolution::toolTip() const //***************************************************************************** MULTIPR_GUI_DataModel::MULTIPR_GUI_DataModel(CAM_Module* module) : - LightApp_DataModel(module) + LightApp_DataModel(module) { - mMULTIPR_GUI = dynamic_cast(module); + mMULTIPR_GUI = dynamic_cast(module); } MULTIPR_GUI_DataModel::~MULTIPR_GUI_DataModel() { - // do nothing! + // do nothing! } void MULTIPR_GUI_DataModel::build() { - try - { - MULTIPR_GUI_DataObject_Module* modelRoot = dynamic_cast(root()); - - if (!modelRoot) - { - // root is not set yet - modelRoot = new MULTIPR_GUI_DataObject_Module(this, NULL, "MULTIPR"); - setRoot(modelRoot); - } - - MULTIPR_ORB::MULTIPR_Obj_ptr obj = mMULTIPR_GUI->getMULTIPRObj(); - - if (obj != NULL) - { - MULTIPR_ORB::string_array* listParts = obj->getParts(); - - if (listParts->length() >= 1) - { - const char* strPartName0 = (*listParts)[0]; - char* strPartInfo0 = obj->getPartInfo(strPartName0); - - char lMeshName[256]; - int lId; - char lPartName[256]; - char lPath[256]; - char lMEDFileName[256]; - - // parse infos - int ret = sscanf(strPartInfo0, "%s %d %s %s %s", - lMeshName, - &lId, - lPartName, - lPath, - lMEDFileName); - - if (ret != 5) - { - cout << "MULTIPR: build() tree; error while parsing part info" << endl; - std::runtime_error("MULTIPR: build() tree; error while parsing part info"); - return; - } - - MULTIPR_GUI_DataObject_Mesh* dataObjectMesh = new MULTIPR_GUI_DataObject_Mesh(modelRoot, lMeshName); - - MULTIPR_GUI_DataObject_Part* dataObjectPart_prev = NULL; - - for (int i = 0 ; i < listParts->length() ; i++) - { - const char* strItem = (*listParts)[i]; - char* strPartInfo = obj->getPartInfo(strItem); - - // parse infos - int ret = sscanf(strPartInfo, "%s %d %s %s %s", - lMeshName, - &lId, - lPartName, - lPath, - lMEDFileName); - - if (ret != 5) return; - - if ((strstr(lPartName,"_MED") != NULL) || (strstr(lPartName,"_LOW") != NULL)) - { - new MULTIPR_GUI_DataObject_Resolution(dataObjectPart_prev, strItem, strPartInfo); - } - else - { - dataObjectPart_prev = new MULTIPR_GUI_DataObject_Part(dataObjectMesh, strItem, strPartInfo); - } - } - } - } - } - catch (...) - { - } + try + { + MULTIPR_GUI_DataObject_Module* modelRoot = dynamic_cast(root()); + + if (!modelRoot) + { + // root is not set yet + modelRoot = new MULTIPR_GUI_DataObject_Module(this, NULL, "MULTIPR"); + setRoot(modelRoot); + } + + MULTIPR_ORB::MULTIPR_Obj_ptr obj = mMULTIPR_GUI->getMULTIPRObj(); + + if (obj != NULL) + { + MULTIPR_ORB::string_array* listParts = obj->getParts(); + + if (listParts->length() >= 1) + { + const char* strPartName0 = (*listParts)[0]; + char* strPartInfo0 = obj->getPartInfo(strPartName0); + + char lMeshName[256]; + int lId; + char lPartName[256]; + char lPath[256]; + char lMEDFileName[256]; + + // parse infos + int ret = sscanf(strPartInfo0, "%s %d %s %s %s", + lMeshName, + &lId, + lPartName, + lPath, + lMEDFileName); + + if (ret != 5) + { + cout << "MULTIPR: build() tree; error while parsing part info" << endl; + std::runtime_error("MULTIPR: build() tree; error while parsing part info"); + return; + } + + MULTIPR_GUI_DataObject_Mesh* dataObjectMesh = new MULTIPR_GUI_DataObject_Mesh(modelRoot, lMeshName); + + MULTIPR_GUI_DataObject_Part* dataObjectPart_prev = NULL; + + for (int i = 0 ; i < listParts->length() ; i++) + { + const char* strItem = (*listParts)[i]; + char* strPartInfo = obj->getPartInfo(strItem); + + // parse infos + int ret = sscanf(strPartInfo, "%s %d %s %s %s", + lMeshName, + &lId, + lPartName, + lPath, + lMEDFileName); + + if (ret != 5) return; + + if ((strstr(lPartName,"_MED") != NULL) || (strstr(lPartName,"_LOW") != NULL)) + { + new MULTIPR_GUI_DataObject_Resolution(dataObjectPart_prev, strItem, strPartInfo); + } + else + { + dataObjectPart_prev = new MULTIPR_GUI_DataObject_Part(dataObjectMesh, strItem, strPartInfo); + } + } + } + } + } + catch (...) + { + } } extern "C" { - CAM_Module* createModule() - { - return new MULTIPR_GUI(); - } + CAM_Module* createModule() + { + return new MULTIPR_GUI(); + } } diff --git a/src/MULTIPRGUI/MULTIPR_GUI.h b/src/MULTIPRGUI/MULTIPR_GUI.h index 91fd6cc..bab9f4a 100644 --- a/src/MULTIPRGUI/MULTIPR_GUI.h +++ b/src/MULTIPRGUI/MULTIPR_GUI.h @@ -55,66 +55,66 @@ class QPushButton; class MULTIPR_GUI: public SalomeApp_Module { - Q_OBJECT + Q_OBJECT public: - MULTIPR_GUI(); - - virtual ~MULTIPR_GUI(); - - void initialize(CAM_Application*); - - QString engineIOR() const; - - void windows(QMap&) const; - - MULTIPR_ORB::MULTIPR_Obj_ptr getMULTIPRObj(); - - SalomeApp_Application* getAppli() const; - - void selected(QStringList&, const bool); - - const QStringList& getSelectedParts() const { return mSelectedParts; } + MULTIPR_GUI(); + + virtual ~MULTIPR_GUI(); + + void initialize(CAM_Application*); + + QString engineIOR() const; + + void windows(QMap&) const; + + MULTIPR_ORB::MULTIPR_Obj_ptr getMULTIPRObj(); + + SalomeApp_Application* getAppli() const; + + void selected(QStringList&, const bool); + + const QStringList& getSelectedParts() const { return mSelectedParts; } public slots: - bool deactivateModule(SUIT_Study*); - bool activateModule(SUIT_Study*); + bool deactivateModule(SUIT_Study*); + bool activateModule(SUIT_Study*); protected slots: - void OnImportFromMEDFile(); - void OnPartition1(); - void OnPartition2(); - void OnDecimate(); - void OnRemove(); - void OnSave(); - + void OnImportFromMEDFile(); + void OnPartition1(); + void OnPartition2(); + void OnDecimate(); + void OnRemove(); + void OnSave(); + protected: - virtual CAM_DataModel* createDataModel(); - - void retrieveSelectedParts(); - bool isPartExist(const char* partName); - bool removeLowerResolution(); - + virtual CAM_DataModel* createDataModel(); + + void retrieveSelectedParts(); + bool isPartExist(const char* partName); + bool removeLowerResolution(); + protected: - enum - { - ACTION_IMPORT_MED = 190, - ACTION_SAVE, - ACTION_REMOVE, - ACTION_SPLIT, - ACTION_DECIMATE - }; - + enum + { + ACTION_IMPORT_MED = 190, + ACTION_SAVE, + ACTION_REMOVE, + ACTION_SPLIT, + ACTION_DECIMATE + }; + private: - QString mMEDFileName; - QStringList mSelectedParts; - MULTIPR_ORB::MULTIPR_Obj_ptr mMULTIPRObj; + QString mMEDFileName; + QStringList mSelectedParts; + MULTIPR_ORB::MULTIPR_Obj_ptr mMULTIPRObj; }; // class MULTIPR_GUI @@ -128,17 +128,17 @@ class MULTIPR_GUI_DataObject : public LightApp_DataObject { public: - MULTIPR_GUI_DataObject(SUIT_DataObject* parent, const char* name); - virtual ~MULTIPR_GUI_DataObject(); - - virtual QString entry() const; - virtual QString name() const; - virtual QPixmap icon() const; - virtual QString toolTip() const; + MULTIPR_GUI_DataObject(SUIT_DataObject* parent, const char* name); + virtual ~MULTIPR_GUI_DataObject(); + + virtual QString entry() const; + virtual QString name() const; + virtual QPixmap icon() const; + virtual QString toolTip() const; protected: - QString mName; + QString mName; }; @@ -150,13 +150,13 @@ class MULTIPR_GUI_DataObject_Module : public MULTIPR_GUI_DataObject, public Ligh { public: - MULTIPR_GUI_DataObject_Module(CAM_DataModel* dm, SUIT_DataObject* parent, const char* name); - virtual ~MULTIPR_GUI_DataObject_Module(); - - virtual QString entry() const; - virtual QString name() const; - virtual QPixmap icon() const; - virtual QString toolTip() const; + MULTIPR_GUI_DataObject_Module(CAM_DataModel* dm, SUIT_DataObject* parent, const char* name); + virtual ~MULTIPR_GUI_DataObject_Module(); + + virtual QString entry() const; + virtual QString name() const; + virtual QPixmap icon() const; + virtual QString toolTip() const; }; @@ -168,12 +168,12 @@ class MULTIPR_GUI_DataObject_Mesh : public MULTIPR_GUI_DataObject { public: - MULTIPR_GUI_DataObject_Mesh(SUIT_DataObject* parent, const char* name); - virtual ~MULTIPR_GUI_DataObject_Mesh(); - - virtual QString entry() const; - virtual QPixmap icon() const; - virtual QString toolTip() const; + MULTIPR_GUI_DataObject_Mesh(SUIT_DataObject* parent, const char* name); + virtual ~MULTIPR_GUI_DataObject_Mesh(); + + virtual QString entry() const; + virtual QPixmap icon() const; + virtual QString toolTip() const; }; @@ -185,20 +185,20 @@ class MULTIPR_GUI_DataObject_Part : public MULTIPR_GUI_DataObject { public: - MULTIPR_GUI_DataObject_Part(SUIT_DataObject* parent, const char* name, const char* info); - virtual ~MULTIPR_GUI_DataObject_Part(); - - virtual QString entry() const; - virtual QPixmap icon() const; - virtual QString toolTip() const; + MULTIPR_GUI_DataObject_Part(SUIT_DataObject* parent, const char* name, const char* info); + virtual ~MULTIPR_GUI_DataObject_Part(); + + virtual QString entry() const; + virtual QPixmap icon() const; + virtual QString toolTip() const; protected: - QString mMeshName; - int mId; - QString mPath; - QString mMEDFileName; - QString mTooltip; + QString mMeshName; + int mId; + QString mPath; + QString mMEDFileName; + QString mTooltip; }; @@ -210,12 +210,12 @@ class MULTIPR_GUI_DataObject_Resolution : public MULTIPR_GUI_DataObject_Part { public: - MULTIPR_GUI_DataObject_Resolution(SUIT_DataObject* parent, const char* name, const char* info); - virtual ~MULTIPR_GUI_DataObject_Resolution(); - - virtual QString entry() const; - virtual QPixmap icon() const; - virtual QString toolTip() const; + MULTIPR_GUI_DataObject_Resolution(SUIT_DataObject* parent, const char* name, const char* info); + virtual ~MULTIPR_GUI_DataObject_Resolution(); + + virtual QString entry() const; + virtual QPixmap icon() const; + virtual QString toolTip() const; }; @@ -227,16 +227,16 @@ class MULTIPR_GUI_DataModel : public LightApp_DataModel { public: - MULTIPR_GUI_DataModel(CAM_Module*); - virtual ~MULTIPR_GUI_DataModel(); + MULTIPR_GUI_DataModel(CAM_Module*); + virtual ~MULTIPR_GUI_DataModel(); protected: - virtual void build(); - + virtual void build(); + private: - MULTIPR_GUI* mMULTIPR_GUI; + MULTIPR_GUI* mMULTIPR_GUI; }; diff --git a/src/MULTIPRGUI/MULTIPR_GUI_Dlg.cxx b/src/MULTIPRGUI/MULTIPR_GUI_Dlg.cxx index d17ccac..0e2667b 100644 --- a/src/MULTIPRGUI/MULTIPR_GUI_Dlg.cxx +++ b/src/MULTIPRGUI/MULTIPR_GUI_Dlg.cxx @@ -2,15 +2,15 @@ // Partitioning/decimation module for the SALOME v3.2 platform /** - * \file MULTIPR_GUI_Dlg.cxx - * - * \brief see MULTIPR_GUI_Dlg.h - * - * \author Olivier LE ROUX - CS, Virtual Reality Dpt - * - * \date 01/2007 - */ - +* \file MULTIPR_GUI_Dlg.cxx +* +* \brief see MULTIPR_GUI_Dlg.h +* +* \author Olivier LE ROUX - CS, Virtual Reality Dpt +* +* \date 01/2007 +*/ + //***************************************************************************** // Includes section //***************************************************************************** @@ -51,20 +51,20 @@ using namespace std; MULTIPR_GUI_Partition1Dlg::MULTIPR_GUI_Partition1Dlg(MULTIPR_GUI* theModule) : - QDialog( - theModule->application()->desktop(), - 0, - false, - WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu) + QDialog( + theModule->application()->desktop(), + 0, + false, + WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu) { - mModule = theModule; - + mModule = theModule; + buttonGroupProcess = new QButtonGroup( this, "buttonGroupProcess" ); buttonGroupProcess->setGeometry( QRect( 10, 110, 450, 60 ) ); - pushButtonOK = new QPushButton( buttonGroupProcess, "pushButtonOK" ); + pushButtonOK = new QPushButton( buttonGroupProcess, "pushButtonOK" ); pushButtonOK->setGeometry( QRect( 10, 10, 110, 41 ) ); - + pushButtonCancel = new QPushButton( buttonGroupProcess, "pushButtonCancel" ); pushButtonCancel->setGeometry( QRect( 321, 10, 110, 41 ) ); @@ -73,35 +73,35 @@ MULTIPR_GUI_Partition1Dlg::MULTIPR_GUI_Partition1Dlg(MULTIPR_GUI* theModule) : comboBoxSelectMesh = new QComboBox( FALSE, buttonGroupSelectMesh, "comboBoxSelectMesh" ); comboBoxSelectMesh->setGeometry( QRect( 160, 30, 280, 40 ) ); - MULTIPR_ORB::string_array* listMeshes = theModule->getMULTIPRObj()->getMeshes(); - for (int i=0; ilength() ; i++) - { - const char* strItem = (*listMeshes)[i]; - comboBoxSelectMesh->insertItem(strItem); - } - comboBoxSelectMesh->setEditable(false); + MULTIPR_ORB::string_array* listMeshes = theModule->getMULTIPRObj()->getMeshes(); + for (int i=0; ilength() ; i++) + { + const char* strItem = (*listMeshes)[i]; + comboBoxSelectMesh->insertItem(strItem); + } + comboBoxSelectMesh->setEditable(false); textLabelSelectMesh = new QLabel( buttonGroupSelectMesh, "textLabelSelectMesh" ); textLabelSelectMesh->setGeometry( QRect( 20, 30, 110, 40 ) ); - setCaption( tr( "Extract groups from sequential MED file" ) ); + setCaption( tr( "Extract groups from sequential MED file" ) ); buttonGroupProcess->setTitle( QString::null ); pushButtonCancel->setText( tr( "Cancel" ) ); pushButtonOK->setText( tr("OK") ); buttonGroupSelectMesh->setTitle( tr( "Select mesh" ) ); textLabelSelectMesh->setText( tr( "Mesh name" ) ); - + resize( QSize(471, 185).expandedTo(minimumSizeHint()) ); clearWState( WState_Polished ); - - connect(pushButtonOK, SIGNAL(clicked()), this, SLOT(accept())); - connect(pushButtonCancel, SIGNAL(clicked()), this, SLOT(reject())); + + connect(pushButtonOK, SIGNAL(clicked()), this, SLOT(accept())); + connect(pushButtonCancel, SIGNAL(clicked()), this, SLOT(reject())); } /* - * Destroys the object and frees any allocated resources - */ +* Destroys the object and frees any allocated resources +*/ MULTIPR_GUI_Partition1Dlg::~MULTIPR_GUI_Partition1Dlg() { // no need to delete child widgets, Qt does it all for us @@ -110,45 +110,45 @@ MULTIPR_GUI_Partition1Dlg::~MULTIPR_GUI_Partition1Dlg() void MULTIPR_GUI_Partition1Dlg::accept() { - const char* meshName = comboBoxSelectMesh->currentText().latin1(); - - try - { - mModule->getMULTIPRObj()->setMesh(meshName); - - QApplication::setOverrideCursor(Qt::waitCursor); - mModule->getMULTIPRObj()->partitionneDomaine(); - QApplication::restoreOverrideCursor(); - - } - catch(...) - { - SUIT_MessageBox::error1( - mModule->getAppli()->desktop(), - "Import MED file error", - "Unable to set mesh", - tr("OK") ); - } - - QDialog::accept(); + const char* meshName = comboBoxSelectMesh->currentText().latin1(); + + try + { + mModule->getMULTIPRObj()->setMesh(meshName); + + QApplication::setOverrideCursor(Qt::waitCursor); + mModule->getMULTIPRObj()->partitionneDomaine(); + QApplication::restoreOverrideCursor(); + + } + catch(...) + { + SUIT_MessageBox::error1( + mModule->getAppli()->desktop(), + "Import MED file error", + "Unable to set mesh", + tr("OK") ); + } + + QDialog::accept(); } void MULTIPR_GUI_Partition1Dlg::reject() { - QDialog::reject(); + QDialog::reject(); } MULTIPR_GUI_Partition2Dlg::MULTIPR_GUI_Partition2Dlg(MULTIPR_GUI* theModule) : - QDialog( - theModule->application()->desktop(), - 0, - false, - WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu) + QDialog( + theModule->application()->desktop(), + 0, + false, + WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu) { - mModule = theModule; - + mModule = theModule; + buttonGroupSplitParameters = new QButtonGroup( this, "buttonGroupSplitParameters" ); buttonGroupSplitParameters->setGeometry( QRect( 10, 10, 380, 140 ) ); @@ -160,9 +160,9 @@ MULTIPR_GUI_Partition2Dlg::MULTIPR_GUI_Partition2Dlg(MULTIPR_GUI* theModule) : comboBoxSelectSplitter = new QComboBox( FALSE, buttonGroupSplitParameters, "comboBoxSelectSplitter" ); comboBoxSelectSplitter->setGeometry( QRect( 210, 80, 150, 40 ) ); - comboBoxSelectSplitter->insertItem("METIS"); - comboBoxSelectSplitter->insertItem("SCOTCH"); - comboBoxSelectSplitter->setEditable(false); + comboBoxSelectSplitter->insertItem("METIS"); + comboBoxSelectSplitter->insertItem("SCOTCH"); + comboBoxSelectSplitter->setEditable(false); spinBoxNbParts = new QSpinBox( buttonGroupSplitParameters, "spinBoxNbParts" ); spinBoxNbParts->setGeometry( QRect( 210, 30, 150, 30 ) ); @@ -179,25 +179,25 @@ MULTIPR_GUI_Partition2Dlg::MULTIPR_GUI_Partition2Dlg(MULTIPR_GUI* theModule) : pushButtonCancel = new QPushButton( buttonGroupProcess, "pushButtonCancel" ); pushButtonCancel->setGeometry( QRect( 250, 10, 110, 41 ) ); - setCaption( tr( "Split selected part" ) ); + setCaption( tr( "Split selected part" ) ); buttonGroupSplitParameters->setTitle( tr( "Split parameters" ) ); textLabelSelectNbParts->setText( tr( "Number of sub-parts" ) ); textLabelSelectSplitter->setText( tr( "Splitter" ) ); buttonGroupProcess->setTitle( QString::null ); pushButtonOK->setText( tr("OK") ); pushButtonCancel->setText( tr( "Cancel" ) ); - + resize( QSize(403, 234).expandedTo(minimumSizeHint()) ); clearWState( WState_Polished ); - - connect(pushButtonOK, SIGNAL(clicked()), this, SLOT(accept())); - connect(pushButtonCancel, SIGNAL(clicked()), this, SLOT(reject())); + + connect(pushButtonOK, SIGNAL(clicked()), this, SLOT(accept())); + connect(pushButtonCancel, SIGNAL(clicked()), this, SLOT(reject())); } /* - * Destroys the object and frees any allocated resources - */ +* Destroys the object and frees any allocated resources +*/ MULTIPR_GUI_Partition2Dlg::~MULTIPR_GUI_Partition2Dlg() { // no need to delete child widgets, Qt does it all for us @@ -206,60 +206,60 @@ MULTIPR_GUI_Partition2Dlg::~MULTIPR_GUI_Partition2Dlg() void MULTIPR_GUI_Partition2Dlg::accept() { - const char* strSplitter = comboBoxSelectSplitter->currentText().latin1(); - int nbParts = spinBoxNbParts->value(); - int partitionner = -1; - if (strcmp(strSplitter, "METIS") == 0) - { - partitionner = 0; - } - else if (strcmp(strSplitter, "SCOTCH") == 0) - { - partitionner = 1; - } - - QApplication::setOverrideCursor(Qt::waitCursor); - - try - { - const QStringList& partsList = mModule->getSelectedParts(); - for (QStringList::const_iterator it = partsList.begin(), last = partsList.end(); it != last; it++) - { - const QString& partName = (*it); - //cout << "Split " << partName.latin1() << " #parts=" << nbParts << " splitter=" << strSplitter << endl; - mModule->getMULTIPRObj()->partitionneGrain(partName.latin1(), nbParts, partitionner); - } - - } - catch(...) - { - SUIT_MessageBox::error1( - mModule->getAppli()->desktop(), - "Split error", - "Error while splitting selected part(s)", - tr("OK") ); - } - - QApplication::restoreOverrideCursor(); - QDialog::accept(); + const char* strSplitter = comboBoxSelectSplitter->currentText().latin1(); + int nbParts = spinBoxNbParts->value(); + int partitionner = -1; + if (strcmp(strSplitter, "METIS") == 0) + { + partitionner = 0; + } + else if (strcmp(strSplitter, "SCOTCH") == 0) + { + partitionner = 1; + } + + QApplication::setOverrideCursor(Qt::waitCursor); + + try + { + const QStringList& partsList = mModule->getSelectedParts(); + for (QStringList::const_iterator it = partsList.begin(), last = partsList.end(); it != last; it++) + { + const QString& partName = (*it); + //cout << "Split " << partName.latin1() << " #parts=" << nbParts << " splitter=" << strSplitter << endl; + mModule->getMULTIPRObj()->partitionneGrain(partName.latin1(), nbParts, partitionner); + } + + } + catch(...) + { + SUIT_MessageBox::error1( + mModule->getAppli()->desktop(), + "Split error", + "Error while splitting selected part(s)", + tr("OK") ); + } + + QApplication::restoreOverrideCursor(); + QDialog::accept(); } void MULTIPR_GUI_Partition2Dlg::reject() { - QDialog::reject(); + QDialog::reject(); } MULTIPR_GUI_DecimateDlg::MULTIPR_GUI_DecimateDlg(MULTIPR_GUI* theModule) : - QDialog( - theModule->application()->desktop(), - 0, - false, - WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu) + QDialog( + theModule->application()->desktop(), + 0, + false, + WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu) { - mModule = theModule; - + mModule = theModule; + buttonGroupSelectField = new QButtonGroup( this, "buttonGroupSelectField" ); buttonGroupSelectField->setGeometry( QRect( 10, 10, 450, 140 ) ); @@ -269,34 +269,34 @@ MULTIPR_GUI_DecimateDlg::MULTIPR_GUI_DecimateDlg(MULTIPR_GUI* theModule) : textLabelSelectFieldIteration = new QLabel( buttonGroupSelectField, "textLabelSelectFieldIteration" ); textLabelSelectFieldIteration->setGeometry( QRect( 30, 80, 111, 31 ) ); - MULTIPR_ORB::string_array* listFields = theModule->getMULTIPRObj()->getFields(); - int maxIteration = 0; - for (int i=0 ; ilength() ; i++) - { - const char* strItem = (*listFields)[i]; - CORBA::Long nbIteration = theModule->getMULTIPRObj()->getTimeStamps(strItem); - if (nbIteration > maxIteration) - { - maxIteration = nbIteration; - } - } - + MULTIPR_ORB::string_array* listFields = theModule->getMULTIPRObj()->getFields(); + int maxIteration = 0; + for (int i=0 ; ilength() ; i++) + { + const char* strItem = (*listFields)[i]; + CORBA::Long nbIteration = theModule->getMULTIPRObj()->getTimeStamps(strItem); + if (nbIteration > maxIteration) + { + maxIteration = nbIteration; + } + } + comboBoxSelectFieldIteration = new QComboBox( FALSE, buttonGroupSelectField, "comboBoxSelectFieldIteration" ); comboBoxSelectFieldIteration->setGeometry( QRect( 150, 80, 280, 40 ) ); - for (int i=1 ; i<=maxIteration ; i++) - { - comboBoxSelectFieldIteration->insertItem(QString::number(i)); - } + for (int i=1 ; i<=maxIteration ; i++) + { + comboBoxSelectFieldIteration->insertItem(QString::number(i)); + } comboBoxSelectFieldName = new QComboBox( FALSE, buttonGroupSelectField, "comboBoxSelectFieldName" ); comboBoxSelectFieldName->setGeometry( QRect( 150, 30, 280, 40 ) ); - for (int i=0 ; ilength() ; i++) - { - const char* strItem = (*listFields)[i]; - comboBoxSelectFieldName->insertItem(strItem); - } - comboBoxSelectFieldName->setEditable(false); - QToolTip::add( comboBoxSelectFieldName, tr( "only scalar fields are listed (multi-component fields are not displayed)" ) ); + for (int i=0 ; ilength() ; i++) + { + const char* strItem = (*listFields)[i]; + comboBoxSelectFieldName->insertItem(strItem); + } + comboBoxSelectFieldName->setEditable(false); + QToolTip::add( comboBoxSelectFieldName, tr( "only scalar fields are listed (multi-component fields are not displayed)" ) ); buttonGroupSelectFilter = new QButtonGroup( this, "buttonGroupSelectFilter" ); buttonGroupSelectFilter->setGeometry( QRect( 10, 160, 450, 90 ) ); @@ -306,7 +306,7 @@ MULTIPR_GUI_DecimateDlg::MULTIPR_GUI_DecimateDlg(MULTIPR_GUI* theModule) : comboBoxSelectFilter = new QComboBox( FALSE, buttonGroupSelectFilter, "comboBoxSelectFilter" ); comboBoxSelectFilter->setGeometry( QRect( 150, 30, 280, 40 ) ); - comboBoxSelectFilter->insertItem("Filtre_GradientMoyen"); + comboBoxSelectFilter->insertItem("Filtre_GradientMoyen"); buttonGroupParameters = new QButtonGroup( this, "buttonGroupParameters" ); buttonGroupParameters->setGeometry( QRect( 10, 260, 450, 210 ) ); @@ -337,19 +337,19 @@ MULTIPR_GUI_DecimateDlg::MULTIPR_GUI_DecimateDlg(MULTIPR_GUI* theModule) : spinBoxBoxing->setMaxValue( 200 ); spinBoxBoxing->setMinValue( 2 ); spinBoxBoxing->setValue( 100 ); - QToolTip::add( spinBoxBoxing, tr( "grid: number of cells along each axis" ) ); + QToolTip::add( spinBoxBoxing, tr( "grid: number of cells along each axis" ) ); buttonGroupProcess = new QButtonGroup( this, "buttonGroupProcess" ); buttonGroupProcess->setGeometry( QRect( 10, 480, 450, 60 ) ); - pushButtonOK = new QPushButton( buttonGroupProcess, "pushButtonOK" ); + pushButtonOK = new QPushButton( buttonGroupProcess, "pushButtonOK" ); pushButtonOK->setGeometry( QRect( 10, 10, 110, 41 ) ); - + pushButtonCancel = new QPushButton( buttonGroupProcess, "pushButtonCancel" ); pushButtonCancel->setGeometry( QRect( 321, 10, 110, 41 ) ); - pushButtonCancel->setAccel( QKeySequence( tr( "Esc" ) ) ); + pushButtonCancel->setAccel( QKeySequence( tr( "Esc" ) ) ); - setCaption( tr( "Decimation" ) ); + setCaption( tr( "Decimation" ) ); buttonGroupSelectField->setTitle( tr( "Select field" ) ); textLabelSelectFieldName->setText( tr( "Field name" ) ); textLabelSelectFieldIteration->setText( tr( "Field iteration" ) ); @@ -363,18 +363,18 @@ MULTIPR_GUI_DecimateDlg::MULTIPR_GUI_DecimateDlg(MULTIPR_GUI* theModule) : lineEditTMed->setText( tr( "0.1" ) ); lineEditTLow->setText( tr( "0.2" ) ); - float defaultRadius = 0.5f; + float defaultRadius = 0.5f; lineEditRadius->setText( QString::number(defaultRadius) ); buttonGroupProcess->setTitle( QString::null ); pushButtonCancel->setText( tr( "Cancel" ) ); pushButtonOK->setText( tr("OK") ); - - pushButtonThresholdAuto = new QPushButton( buttonGroupParameters, "pushButtonThresholdAuto" ); + + pushButtonThresholdAuto = new QPushButton( buttonGroupParameters, "pushButtonThresholdAuto" ); pushButtonThresholdAuto->setGeometry( QRect( 260, 80, 50, 30 ) ); QFont pushButtonThresholdAuto_font( pushButtonThresholdAuto->font() ); pushButtonThresholdAuto_font.setPointSize( 11 ); pushButtonThresholdAuto->setFont( pushButtonThresholdAuto_font ); - pushButtonThresholdAuto->setText( tr( "auto" ) ); + pushButtonThresholdAuto->setText( tr( "auto" ) ); QToolTip::add( pushButtonThresholdAuto, tr( "compute extremum for gradient (set medium=MIN and low=MAX)" ) ); pushButtonRadiusAuto = new QPushButton( buttonGroupParameters, "pushButtonRadiusAuto" ); @@ -384,20 +384,20 @@ MULTIPR_GUI_DecimateDlg::MULTIPR_GUI_DecimateDlg(MULTIPR_GUI* theModule) : pushButtonRadiusAuto->setFont( pushButtonRadiusAuto_font ); pushButtonRadiusAuto->setText( tr( "auto" ) ); QToolTip::add( pushButtonRadiusAuto, tr( "set radius automatically (average #neighbours equal to 8)" ) ); - + resize( QSize(470, 554).expandedTo(minimumSizeHint()) ); clearWState( WState_Polished ); - - connect(pushButtonOK, SIGNAL(clicked()), this, SLOT(accept())); - connect(pushButtonCancel, SIGNAL(clicked()), this, SLOT(reject())); - connect(pushButtonRadiusAuto, SIGNAL(clicked()), this, SLOT(OnRadiusAuto())); - connect(pushButtonThresholdAuto, SIGNAL(clicked()), this, SLOT(OnThresholdAuto())); + + connect(pushButtonOK, SIGNAL(clicked()), this, SLOT(accept())); + connect(pushButtonCancel, SIGNAL(clicked()), this, SLOT(reject())); + connect(pushButtonRadiusAuto, SIGNAL(clicked()), this, SLOT(OnRadiusAuto())); + connect(pushButtonThresholdAuto, SIGNAL(clicked()), this, SLOT(OnThresholdAuto())); } /* - * Destroys the object and frees any allocated resources - */ +* Destroys the object and frees any allocated resources +*/ MULTIPR_GUI_DecimateDlg::~MULTIPR_GUI_DecimateDlg() { // no need to delete child widgets, Qt does it all for us @@ -405,214 +405,214 @@ MULTIPR_GUI_DecimateDlg::~MULTIPR_GUI_DecimateDlg() void MULTIPR_GUI_DecimateDlg::accept() -{ - const char* strFieldName = comboBoxSelectFieldName->currentText().latin1(); - const char* strFieldIt = comboBoxSelectFieldIteration->currentText().latin1(); - int fieldIteration = atoi(strFieldIt); - - double thresholdMed; - int ret = sscanf(lineEditTMed->text().latin1(), "%lf", &thresholdMed); - if ((ret != 1) || (thresholdMed <= 0.0f)) - { - SUIT_MessageBox::error1( - mModule->getAppli()->desktop(), - "Decimation parameters error", - "Invalid medium threshold (should be > 0.0)", - tr("OK") ); - - return; - } - - double thresholdLow; - ret = sscanf(lineEditTLow->text().latin1(), "%lf", &thresholdLow); - if ((ret != 1) || (thresholdLow <= 0.0f)) - { - SUIT_MessageBox::error1( - mModule->getAppli()->desktop(), - "Decimation parameters error", - "Invalid low threshold (should be > 0.0)", - tr("OK") ); - - return; - } - - if (thresholdMed >= thresholdLow) - { - SUIT_MessageBox::error1( - mModule->getAppli()->desktop(), - "Decimation parameters error", - "Medium threshold must be < low threshold", - tr("OK") ); - - return; - } - - double radius; - ret = sscanf(lineEditRadius->text().latin1(), "%lf", &radius); - if ((ret != 1) || (radius <= 0.0f)) - { - SUIT_MessageBox::error1( - mModule->getAppli()->desktop(), - "Decimation parameters error", - "Invalid radius (should be > 0.0)", - tr("OK") ); - - return; - } - - QApplication::setOverrideCursor(Qt::waitCursor); - - try - { - const QStringList& partsList = mModule->getSelectedParts(); - for (QStringList::const_iterator it = partsList.begin(), last = partsList.end(); it != last; it++) - { - const QString& partName = (*it); - - mModule->getMULTIPRObj()->setBoxing(spinBoxBoxing->value()); - - mModule->getMULTIPRObj()->decimePartition( - partName.latin1(), - strFieldName, - fieldIteration, - comboBoxSelectFilter->currentText().latin1(), - thresholdMed, - thresholdLow, - radius); - } - } - catch(...) - { - SUIT_MessageBox::error1( - mModule->getAppli()->desktop(), - "Decimation error", - "Error while decimating selected part(s)", - tr("OK") ); - } - - QApplication::restoreOverrideCursor(); - QDialog::accept(); +{ + const char* strFieldName = comboBoxSelectFieldName->currentText().latin1(); + const char* strFieldIt = comboBoxSelectFieldIteration->currentText().latin1(); + int fieldIteration = atoi(strFieldIt); + + double thresholdMed; + int ret = sscanf(lineEditTMed->text().latin1(), "%lf", &thresholdMed); + if ((ret != 1) || (thresholdMed <= 0.0f)) + { + SUIT_MessageBox::error1( + mModule->getAppli()->desktop(), + "Decimation parameters error", + "Invalid medium threshold (should be > 0.0)", + tr("OK") ); + + return; + } + + double thresholdLow; + ret = sscanf(lineEditTLow->text().latin1(), "%lf", &thresholdLow); + if ((ret != 1) || (thresholdLow <= 0.0f)) + { + SUIT_MessageBox::error1( + mModule->getAppli()->desktop(), + "Decimation parameters error", + "Invalid low threshold (should be > 0.0)", + tr("OK") ); + + return; + } + + if (thresholdMed >= thresholdLow) + { + SUIT_MessageBox::error1( + mModule->getAppli()->desktop(), + "Decimation parameters error", + "Medium threshold must be < low threshold", + tr("OK") ); + + return; + } + + double radius; + ret = sscanf(lineEditRadius->text().latin1(), "%lf", &radius); + if ((ret != 1) || (radius <= 0.0f)) + { + SUIT_MessageBox::error1( + mModule->getAppli()->desktop(), + "Decimation parameters error", + "Invalid radius (should be > 0.0)", + tr("OK") ); + + return; + } + + QApplication::setOverrideCursor(Qt::waitCursor); + + try + { + const QStringList& partsList = mModule->getSelectedParts(); + for (QStringList::const_iterator it = partsList.begin(), last = partsList.end(); it != last; it++) + { + const QString& partName = (*it); + + mModule->getMULTIPRObj()->setBoxing(spinBoxBoxing->value()); + + mModule->getMULTIPRObj()->decimePartition( + partName.latin1(), + strFieldName, + fieldIteration, + comboBoxSelectFilter->currentText().latin1(), + thresholdMed, + thresholdLow, + radius); + } + } + catch(...) + { + SUIT_MessageBox::error1( + mModule->getAppli()->desktop(), + "Decimation error", + "Error while decimating selected part(s)", + tr("OK") ); + } + + QApplication::restoreOverrideCursor(); + QDialog::accept(); } void MULTIPR_GUI_DecimateDlg::reject() { - QDialog::reject(); + QDialog::reject(); } void MULTIPR_GUI_DecimateDlg::OnRadiusAuto() { - // evaluates default radius for the first selected part - const QStringList& partsList = mModule->getSelectedParts(); - const char* strFieldIt = comboBoxSelectFieldIteration->currentText().latin1(); - int fieldIteration = atoi(strFieldIt); - char* strPartInfo0 = mModule->getMULTIPRObj()->getPartInfo(partsList[0].latin1()); - - char lMeshName[256]; - int lId; - char lPartName[256]; - char lPath[256]; - char lMEDFileName[256]; - - // parse infos - int ret = sscanf(strPartInfo0, "%s %d %s %s %s", - lMeshName, - &lId, - lPartName, - lPath, - lMEDFileName); - - if (ret != 5) - { - return; - } - - QApplication::setOverrideCursor(Qt::waitCursor); - float defaultRadius = 0.5f; - try - { - char strParams[256]; - sprintf(strParams, "2"); - - char* res = mModule->getMULTIPRObj()->evalDecimationParams( - lPartName, - comboBoxSelectFieldName->currentText().latin1(), - fieldIteration, - comboBoxSelectFilter->currentText().latin1(), - strParams); - - sscanf(res, "%f", &defaultRadius); - } - catch (...) - { - } - QApplication::restoreOverrideCursor(); - + // evaluates default radius for the first selected part + const QStringList& partsList = mModule->getSelectedParts(); + const char* strFieldIt = comboBoxSelectFieldIteration->currentText().latin1(); + int fieldIteration = atoi(strFieldIt); + char* strPartInfo0 = mModule->getMULTIPRObj()->getPartInfo(partsList[0].latin1()); + + char lMeshName[256]; + int lId; + char lPartName[256]; + char lPath[256]; + char lMEDFileName[256]; + + // parse infos + int ret = sscanf(strPartInfo0, "%s %d %s %s %s", + lMeshName, + &lId, + lPartName, + lPath, + lMEDFileName); + + if (ret != 5) + { + return; + } + + QApplication::setOverrideCursor(Qt::waitCursor); + float defaultRadius = 0.5f; + try + { + char strParams[256]; + sprintf(strParams, "2"); + + char* res = mModule->getMULTIPRObj()->evalDecimationParams( + lPartName, + comboBoxSelectFieldName->currentText().latin1(), + fieldIteration, + comboBoxSelectFilter->currentText().latin1(), + strParams); + + sscanf(res, "%f", &defaultRadius); + } + catch (...) + { + } + QApplication::restoreOverrideCursor(); + lineEditRadius->setText( QString::number(defaultRadius) ); } void MULTIPR_GUI_DecimateDlg::OnThresholdAuto() { - // evaluates default radius for the first selected part - const QStringList& partsList = mModule->getSelectedParts(); - const char* strFieldIt = comboBoxSelectFieldIteration->currentText().latin1(); - int fieldIteration = atoi(strFieldIt); - char* strPartInfo0 = mModule->getMULTIPRObj()->getPartInfo(partsList[0].latin1()); - - char lMeshName[256]; - int lId; - char lPartName[256]; - char lPath[256]; - char lMEDFileName[256]; - - // parse infos - int ret = sscanf(strPartInfo0, "%s %d %s %s %s", - lMeshName, - &lId, - lPartName, - lPath, - lMEDFileName); - - QApplication::setOverrideCursor(Qt::waitCursor); - - try - { - float radius; - ret = sscanf(lineEditRadius->text().latin1(), "%f", &radius); - if ((ret != 1) || (radius <= 0.0f)) - { - SUIT_MessageBox::error1( - mModule->getAppli()->desktop(), - "Decimation parameters error", - "Invalid radius (should be > 0.0)", - tr("OK") ); - - return; - } - - char strParams[256]; - sprintf(strParams, "1 %f %d", radius, spinBoxBoxing->value()); - - char* res = mModule->getMULTIPRObj()->evalDecimationParams( - lPartName, - comboBoxSelectFieldName->currentText().latin1(), - fieldIteration, - comboBoxSelectFilter->currentText().latin1(), - strParams); - - float gradMin, gradAvg, gradMax; - sscanf(res, "%f %f %f", &gradMin, &gradAvg, &gradMax); - - lineEditTMed->setText( QString::number(gradMin) ); - lineEditTLow->setText( QString::number(gradMax) ); - } - catch (...) - { - } - - QApplication::restoreOverrideCursor(); + // evaluates default radius for the first selected part + const QStringList& partsList = mModule->getSelectedParts(); + const char* strFieldIt = comboBoxSelectFieldIteration->currentText().latin1(); + int fieldIteration = atoi(strFieldIt); + char* strPartInfo0 = mModule->getMULTIPRObj()->getPartInfo(partsList[0].latin1()); + + char lMeshName[256]; + int lId; + char lPartName[256]; + char lPath[256]; + char lMEDFileName[256]; + + // parse infos + int ret = sscanf(strPartInfo0, "%s %d %s %s %s", + lMeshName, + &lId, + lPartName, + lPath, + lMEDFileName); + + QApplication::setOverrideCursor(Qt::waitCursor); + + try + { + float radius; + ret = sscanf(lineEditRadius->text().latin1(), "%f", &radius); + if ((ret != 1) || (radius <= 0.0f)) + { + SUIT_MessageBox::error1( + mModule->getAppli()->desktop(), + "Decimation parameters error", + "Invalid radius (should be > 0.0)", + tr("OK") ); + + return; + } + + char strParams[256]; + sprintf(strParams, "1 %f %d", radius, spinBoxBoxing->value()); + + char* res = mModule->getMULTIPRObj()->evalDecimationParams( + lPartName, + comboBoxSelectFieldName->currentText().latin1(), + fieldIteration, + comboBoxSelectFilter->currentText().latin1(), + strParams); + + float gradMin, gradAvg, gradMax; + sscanf(res, "%f %f %f", &gradMin, &gradAvg, &gradMax); + + lineEditTMed->setText( QString::number(gradMin) ); + lineEditTLow->setText( QString::number(gradMax) ); + } + catch (...) + { + } + + QApplication::restoreOverrideCursor(); } @@ -622,40 +622,70 @@ void MULTIPR_GUI_DecimateDlg::OnThresholdAuto() //***************************************************************************** MULTIPR_GUI_ProgressCallbackDlg::MULTIPR_GUI_ProgressCallbackDlg(QWidget* parent) : - QProgressDialog( - parent, - 0, - false, - WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu) + QProgressDialog( + parent, + 0, + false, + WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu) { - setLabel(new QLabel(this, "Please wait")); - setLabelText("Please wait"); - setTotalSteps(100); + setLabel(new QLabel(this, "Please wait")); + setLabelText("Please wait"); + setTotalSteps(100); } MULTIPR_GUI_ProgressCallbackDlg::~MULTIPR_GUI_ProgressCallbackDlg() { - // do nothing + // do nothing } void MULTIPR_GUI_ProgressCallbackDlg::start(const char* pTaskTitle, int pNumStep) { - setCaption(pTaskTitle); - MULTIPR_ProgressCallback::init(pNumStep); + setCaption(pTaskTitle); + MULTIPR_ProgressCallback::init(pNumStep); } void MULTIPR_GUI_ProgressCallbackDlg::done() { - setProgress(100); + setProgress(100); } - + void MULTIPR_GUI_ProgressCallbackDlg::progress(float pPercent) { - setProgress(int(pPercent)); + setProgress(int(pPercent)); +} + + +//***************************************************************************** +// MULTIPR_GUI_EmptyMeshCallbackDlg +// QT dialog box used to inform about empty meshes +//***************************************************************************** + +MULTIPR_GUI_EmptyMeshCallbackDlg::MULTIPR_GUI_EmptyMeshCallbackDlg(QWidget* parent) +{ + mParent = parent; +} + + +MULTIPR_GUI_EmptyMeshCallbackDlg::~MULTIPR_GUI_EmptyMeshCallbackDlg() +{ + // do nothing +} + + +void MULTIPR_GUI_EmptyMeshCallbackDlg::reportEmptyMesh(string pInfo) +{ + char msg[256]; + sprintf(msg, "Empty mesh detected (%s)", pInfo.c_str()); + + SUIT_MessageBox::warn1( + mParent, + "Empty mesh detected", + msg, + "OK" ); } // EOF diff --git a/src/MULTIPRGUI/MULTIPR_GUI_Dlg.h b/src/MULTIPRGUI/MULTIPR_GUI_Dlg.h index 0ae32c5..888cad7 100644 --- a/src/MULTIPRGUI/MULTIPR_GUI_Dlg.h +++ b/src/MULTIPRGUI/MULTIPR_GUI_Dlg.h @@ -68,11 +68,11 @@ public: QLabel* textLabelSelectMesh; protected slots: - void accept(); - void reject(); - + void accept(); + void reject(); + private: - MULTIPR_GUI* mModule; + MULTIPR_GUI* mModule; }; @@ -100,11 +100,11 @@ public: QPushButton* pushButtonCancel; protected slots: - void accept(); - void reject(); + void accept(); + void reject(); private: - MULTIPR_GUI* mModule; + MULTIPR_GUI* mModule; }; @@ -141,19 +141,19 @@ public: QButtonGroup* buttonGroupProcess; QPushButton* pushButtonCancel; QPushButton* pushButtonOK; - QPushButton* pushButtonThresholdAuto; + QPushButton* pushButtonThresholdAuto; QPushButton* pushButtonRadiusAuto; protected: protected slots: - void accept(); - void reject(); - void OnRadiusAuto(); - void OnThresholdAuto(); + void accept(); + void reject(); + void OnRadiusAuto(); + void OnThresholdAuto(); private: - MULTIPR_GUI* mModule; + MULTIPR_GUI* mModule; }; @@ -163,25 +163,46 @@ private: //***************************************************************************** class MULTIPR_GUI_ProgressCallbackDlg : - public QProgressDialog, - public MULTIPR_ProgressCallback - + public QProgressDialog, + public MULTIPR_ProgressCallback + { - Q_OBJECT - + Q_OBJECT + +public: + + MULTIPR_GUI_ProgressCallbackDlg(QWidget* parent); + + ~MULTIPR_GUI_ProgressCallbackDlg(); + + virtual void start(const char* pTaskTitle, int pNumStep); + + virtual void done(); + +protected: + + virtual void progress(float pPercent); +}; + + +//***************************************************************************** +// Class MULTIPR_GUI_EmptyMeshCallbackDlg +//***************************************************************************** + +class MULTIPR_GUI_EmptyMeshCallbackDlg : public MULTIPR_EmptyMeshCallback +{ public: - MULTIPR_GUI_ProgressCallbackDlg(QWidget* parent); - - ~MULTIPR_GUI_ProgressCallbackDlg(); - - virtual void start(const char* pTaskTitle, int pNumStep); - - virtual void done(); - + MULTIPR_GUI_EmptyMeshCallbackDlg(QWidget* parent); + + ~MULTIPR_GUI_EmptyMeshCallbackDlg(); + + virtual void reportEmptyMesh(std::string pInfo); + protected: - - virtual void progress(float pPercent); + + QWidget* mParent; + }; -- 2.39.2