]> SALOME platform Git repositories - modules/multipr.git/commitdiff
Salome HOME
*** empty log message ***
authorcs <cs>
Sat, 10 Mar 2007 18:59:15 +0000 (18:59 +0000)
committercs <cs>
Sat, 10 Mar 2007 18:59:15 +0000 (18:59 +0000)
16 files changed:
idl/MULTIPR.idl
src/MULTIPR/MULTIPR_DecimationFilter.cxx
src/MULTIPR/MULTIPR_Mesh.cxx
src/MULTIPR/MULTIPR_Mesh.hxx
src/MULTIPR/MULTIPR_MeshDis.cxx
src/MULTIPR/MULTIPR_MeshDis.hxx
src/MULTIPR/MULTIPR_Obj.cxx
src/MULTIPR/MULTIPR_Obj.hxx
src/MULTIPR/MULTIPR_Utils.cxx
src/MULTIPR/MULTIPR_Utils.hxx
src/MULTIPR/MULTIPR_i.cxx
src/MULTIPR/MULTIPR_i.hxx
src/MULTIPR/multipr.cxx
src/MULTIPRGUI/MULTIPR_GUI.cxx
src/MULTIPRGUI/MULTIPR_GUI.h
src/MULTIPRGUI/MULTIPR_GUI_Dlg.cxx

index c214a7c4fa5a9895a1b21b8270b4bc891019039c..34ff91f86b5addfd23370c2d0b2a0ffb8fa95d76 100644 (file)
@@ -96,14 +96,7 @@ interface MULTIPR_Obj
         */
        string getPartInfo(in string partName)
                raises (SALOME::SALOME_Exception);
-
-       /*!
-        * Remove the given part from the distributed MED file.
-        * Assume this object encapsulates a distributed MED file.
-        */
-       void removePart(in string partName)
-               raises (SALOME::SALOME_Exception);
-       
+        
        //---------------------------------------------------------------------
        // Algorithms
        //--------------------------------------------------------------------
@@ -150,6 +143,25 @@ interface MULTIPR_Obj
                in double tlow,
                in double radius)
                raises (SALOME::SALOME_Exception);
+
+       /*!
+        * Return useful information to configure decimation parameters.
+        * Depends on part, field and filter: generic operation.
+        */
+       string evalDecimationParams(
+               in string partName, 
+               in string fieldName, 
+               in long   fieldIt, 
+               in string filterName,
+               in string filterParams)
+               raises (SALOME::SALOME_Exception);
+       
+       /*!
+        * Remove all the parts starting with the given prefix from the distributed MED file.
+        * Assume this object encapsulates a distributed MED file.
+        */
+       void removeParts(in string prefixPartName)
+               raises (SALOME::SALOME_Exception);
        
        //---------------------------------------------------------------------
        // i/o
index ef9e3359264b13f31f7ea8bf16ee7b9609b29f17..cef938071a8aa1a8c499e2f75d9fd3fa479301c8 100644 (file)
@@ -218,6 +218,8 @@ void DecimationFilterGradAvg::getGradientInfo(
        *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++)
        {
index fc16c30ca1a127f283b6b9b0089ad0901468b2e3..461b54c4a202fe16b4c7361e56cb7de539f1aafa 100644 (file)
@@ -113,14 +113,20 @@ void Mesh::reset()
 }
 
 
-vector<string> Mesh::getNameFields() const
+vector<string> Mesh::getNameScalarFields() const
 {
        vector<string> res;
        
        for (int itField = 0 ; itField < mFields.size() ; itField++)
        {
                Field* currentField = mFields[itField];
-               res.push_back(currentField->getName());
+               
+               // 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;
index d72bd8babaf6e5fd783e96c42d547d241c7c0516..fde319595da1b299cca24ea532267d20c3537ed9 100644 (file)
@@ -91,10 +91,10 @@ public:
        const char* getName() const { return mMeshName; }
        
        /**
-        * Returns the name of all the fields.
-        * \return the name of all the fields.
+        * Returns the name of all the scalar fields.
+        * \return the name of all the scalar fields.
         */
-       std::vector<std::string> getNameFields() const; 
+       std::vector<std::string> getNameScalarFields() const; 
        
        /**
         * Returns the number of iteration for a given field.
index 9b93c2d070d24e43a3f6811fce359f8e9219cf5f..4f2a301699d4fedc56240923f22baba92e5162d5 100644 (file)
@@ -17,6 +17,7 @@
 
 #include "MULTIPR_MeshDis.hxx"
 #include "MULTIPR_Mesh.hxx"
+#include "MULTIPR_DecimationFilter.hxx"
 #include "MULTIPR_Utils.hxx"
 #include "MULTIPR_Globals.hxx"
 #include "MULTIPR_API.hxx"
@@ -277,11 +278,17 @@ void MeshDis::removeParts(const char* pPrefixPartName)
        
        if (pPrefixPartName == NULL) throw NullArgumentException("", __FILE__, __LINE__);
        
+       char strPrefix[256];
+       sprintf(strPrefix, "%s_", pPrefixPartName);
+       
        for (vector<MeshDisPart*>::iterator itPart = mParts.begin() ; itPart != mParts.end() ; itPart++)
        {
                MeshDisPart* currentPart = (*itPart);
                
-               if (startWith(currentPart->getPartName(), pPrefixPartName))
+               // 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) || 
+                   startWith(currentPart->getPartName(), strPrefix))
                {
                        mParts.erase(itPart);
                
@@ -360,7 +367,7 @@ vector<string> MeshDis::getFields() const
                case MeshDisPart::MULTIPR_KEEP_AS_IT: 
                case MeshDisPart::MULTIPR_WRITE_PARTS:
                {
-                       vector<pair<string, int> > tmp = multipr::getListFields(mParts[0]->getMEDFileName());
+                       vector<pair<string, int> > tmp = multipr::getListScalarFields(mParts[0]->getMEDFileName());
        
                        for (int i = 0 ; i < tmp.size() ; i++)
                        {
@@ -370,7 +377,7 @@ vector<string> MeshDis::getFields() const
                }
                        
                case MeshDisPart::MULTIPR_WRITE_MESH:
-                       return mParts[0]->mMesh->getNameFields();
+                       return mParts[0]->mMesh->getNameScalarFields();
                
                default: 
                        throw IllegalStateException("", __FILE__, __LINE__);
@@ -393,7 +400,7 @@ int MeshDis::getTimeStamps(const char* pFieldName) const
                case MeshDisPart::MULTIPR_KEEP_AS_IT: 
                case MeshDisPart::MULTIPR_WRITE_PARTS:
                {
-                       vector<pair<string, int> > tmp = multipr::getListFields(mParts[0]->getMEDFileName());
+                       vector<pair<string, int> > tmp = multipr::getListScalarFields(mParts[0]->getMEDFileName());
                
                        for (int i = 0 ; i < tmp.size() ; i++)
                        {
@@ -614,7 +621,80 @@ cout << (*this) << endl;
                        part->mId + 1);
        }
        
-cout << (*this) << endl;
+       // debug
+       //cout << (*this) << endl;
+}
+
+
+string MeshDis::evalDecimationParams(
+       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<multipr::DecimationFilterGradAvg*>(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 "";
+       }
 }
 
 
index f71a066d1e8a43dec134059d4857a6824b372df0..603bff655d0a322418a58dff1470a765c6ff1299 100644 (file)
@@ -288,6 +288,7 @@ public:
        
        /**
         * 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);
@@ -376,6 +377,23 @@ public:
                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
index f167cc408a2ee0ae10789f17b761fcc5e1bb748b..82cecfb6eaa893b320f66c201f3310ab3c42d061 100644 (file)
@@ -160,7 +160,7 @@ vector<string> Obj::getFields() const
            (mState == MULTIPR_OBJ_STATE_SEQ)) 
        {
                // CASE 1: sequential MED file
-               vector<pair<string, int> > tmp = multipr::getListFields(mMEDfilename.c_str());
+               vector<pair<string, int> > tmp = multipr::getListScalarFields(mMEDfilename.c_str());
                
                vector<string> res;
                for (int i = 0 ; i < tmp.size() ; i++)
@@ -187,7 +187,7 @@ int Obj::getTimeStamps(const char* pFieldName) const
            (mState == MULTIPR_OBJ_STATE_SEQ)) 
        {
                // CASE 1: sequential MED file
-               vector<pair<string, int> > tmp = multipr::getListFields(mMEDfilename.c_str());
+               vector<pair<string, int> > tmp = multipr::getListScalarFields(mMEDfilename.c_str());
        
                for (int i = 0 ; i < tmp.size() ; i++)
                {
@@ -384,6 +384,30 @@ vector<string> Obj::decimePartition(
 }
 
 
+string Obj::evalDecimationParams(
+       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;
+}
+
+
 vector<string> Obj::getListParts() const
 {
        if (mMeshDis == NULL) throw IllegalStateException("not a distributed mesh", __FILE__, __LINE__);
index 24a9cb9c7f1aa0f45849c69dda128ced6b960928..14800a60a6865e8dd1c4e68eb1dfad5f5f1b5b43 100644 (file)
@@ -135,6 +135,7 @@ public:
        
        /**
         * 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.
         */
@@ -200,6 +201,23 @@ public:
                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
        //---------------------------------------------------------------------
index 138743364e2301cad358ec480e01b442df88ff77..df553041928506a3a861b64c0db867962824c00f 100644 (file)
@@ -148,7 +148,7 @@ vector<string> multipr::getListMeshes(const char* pMEDfilename)
 }
 
 
-vector<pair<string,int> > multipr::getListFields(const char* pMEDfilename)
+vector<pair<string,int> > multipr::getListScalarFields(const char* pMEDfilename)
 {
        if (pMEDfilename == NULL) throw multipr::NullArgumentException("", __FILE__, __LINE__);
        
index 3300579f33689474fa9c4866b475fb221f280c44..b1d0062b6d58e471dfb28927fe1d0043cd380e06 100644 (file)
@@ -87,13 +87,14 @@ std::string realToString(med_float mV);
 
  
  /**
- * For each field in a sequential MED file, returns its name and the related number of iterations.
- * \param  pMEDfilename name of any valid sequential MED file; must not be NULL.
- * \return a list of (name, #iterations).
- * \throw  NullArgumentException if pMEDfilename is NULL.
- * \throw  IOException if any other error occurs while reading MED file.
- */
- std::vector<std::pair<std::string, int> > getListFields(const char* pMEDfilename);
+  * For each scalar field in a sequential MED file, returns its name and the related number of iterations.
+  * 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).
+  * \throw  NullArgumentException if pMEDfilename is NULL.
+  * \throw  IOException if any other error occurs while reading MED file.
+  */
+ std::vector<std::pair<std::string, int> > getListScalarFields(const char* pMEDfilename);
 
 } // namespace MULTIPR
 
index 6136568770fa247868f99adb295b39c2c2d9e9e6..03df31def1896cdb81155f92c4c5d074c1157c40 100644 (file)
@@ -346,15 +346,6 @@ char* MULTIPR_Obj_i::getPartInfo(const char* pPartName)
 }
 
 
-void MULTIPR_Obj_i::removePart(const char* pPartName)
-       throw (SALOME::SALOME_Exception)
-{
-       if (mObj == NULL) THROW_SALOME_CORBA_EXCEPTION("No associated MED file", SALOME::INTERNAL_ERROR);
-       
-       mObj->removeParts(pPartName);
-}
-
-
 MULTIPR_ORB::string_array* MULTIPR_Obj_i::partitionneDomaine()
        throw (SALOME::SALOME_Exception)
 {
@@ -459,6 +450,45 @@ MULTIPR_ORB::string_array* MULTIPR_Obj_i::decimePartition(
 }
 
 
+char* MULTIPR_Obj_i::evalDecimationParams(
+       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);
+       }
+}
+
+
+void MULTIPR_Obj_i::removeParts(const char* pPrefixPartName)
+       throw (SALOME::SALOME_Exception)
+{
+       if (mObj == NULL) THROW_SALOME_CORBA_EXCEPTION("No associated MED file", SALOME::INTERNAL_ERROR);
+       
+       mObj->removeParts(pPrefixPartName);
+}
+
+
 void MULTIPR_Obj_i::save()
        throw (SALOME::SALOME_Exception)
 {
index 510f3816cc024fb05c2a9f0d98463f17e0955f8f..98763210d2ec54248f8e9914873e20de0ff988c1 100644 (file)
@@ -125,15 +125,6 @@ public:
         */
        char* getPartInfo(const char* pPartName)
                throw (SALOME::SALOME_Exception);
-
-       /*!
-        * Removes the given part from the distributed MED file.
-        * Assume this object encapsulates a distributed MED file.
-        * \param  pPartName name of the part.
-        */
-       void removePart(const char* pPartName)
-               throw (SALOME::SALOME_Exception);
-       
        
        //---------------------------------------------------------------------
        // Algorithms
@@ -191,7 +182,33 @@ public:
                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
        //---------------------------------------------------------------------
index ccdedb7650749dd7d622c1a99f54ef53daf0c9cb..332412f0c374e77bfc71f04d26974bea8764d100 100644 (file)
@@ -591,7 +591,7 @@ int runDumpMED()
                        
                        {
                                // display list of fields contained in the MED file
-                               vector<pair<string,int> > res = multipr::getListFields(g_medFilename);
+                               vector<pair<string,int> > res = multipr::getListScalarFields(g_medFilename);
                                cout << "List of fields in this MED file:" << endl;
                                for (unsigned i = 0 ; i < res.size() ; i++)
                                {
index 6ff97df9b17338e99e542c1c3b5a1fb10fcf9815..3ce03305919b1a3c3976fb432b5ede955d14d7d2 100644 (file)
@@ -302,6 +302,7 @@ void MULTIPR_GUI::OnImportFromMEDFile()
                this->application()->desktop(), 
                true, 
                tr("USE_BUILD_PROGRESS") );
+               
        fd->setCaption(tr("MEN_IMPORT_FROM_MED_FILE"));
        fd->setFilters(aFilter);
        fd->exec();
@@ -331,23 +332,32 @@ void MULTIPR_GUI::OnImportFromMEDFile()
        }
        QApplication::restoreOverrideCursor();
        
-       try
+       if (mMULTIPRObj != NULL)
        {
-               if (mMULTIPRObj->isValidSequentialMEDFile())
+               try
                {
-                       OnPartition1();
+                       if (mMULTIPRObj->isValidSequentialMEDFile())
+                       {
+                               OnPartition1();
+                       }
                }
+               catch (...)
+               {
+               }
+               
+               getApp()->updateObjectBrowser();
        }
-       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;
@@ -356,6 +366,12 @@ void MULTIPR_GUI::OnPartition1()
 
 void MULTIPR_GUI::OnPartition2()
 {
+       // check if MULTIPRObj exists
+       if (mMULTIPRObj == NULL)
+       {
+               return;
+       }
+       
        retrieveSelectedParts();
        
        if (mSelectedParts.count() == 0)
@@ -368,6 +384,11 @@ void MULTIPR_GUI::OnPartition2()
                return;
        }
        
+       if (!removeLowerResolution())
+       {
+               return;
+       }
+       
        MULTIPR_GUI_Partition2Dlg* dialog = new MULTIPR_GUI_Partition2Dlg(this);
        dialog->exec();
        delete dialog;
@@ -377,6 +398,12 @@ void MULTIPR_GUI::OnPartition2()
 
 void MULTIPR_GUI::OnDecimate()
 {
+       // check if MULTIPRObj exists
+       if (mMULTIPRObj == NULL)
+       {
+               return;
+       }
+       
        retrieveSelectedParts();
        
        if (mSelectedParts.count() == 0)
@@ -389,66 +416,9 @@ void MULTIPR_GUI::OnDecimate()
                return;
        }
        
-       // for each selected part, check if there are lower resolution
-       // and then propose to remove them before processing new decimation
-       QStringList partNameLowerResolution;
-       for (QStringList::const_iterator it = mSelectedParts.begin(), last = mSelectedParts.end(); it != last; it++)
+       if (!removeLowerResolution())
        {
-               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("Decimation: remove previous results"),
-                               tr("Do you want to remove previous results?"),
-                               tr("&Yes"), tr("&No"),
-                               QString::null, 0, 1 ) )
-               {
-                       return;
-               }
-       
-               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->removePart(partName.latin1());
-                       }
-                       
-               }
-               catch(...)
-               {
-                       SUIT_MessageBox::error1( 
-                               getApp()->desktop(),
-                               "Remove error", 
-                               "Error while removing previous results", 
-                               tr("OK") );
-               }
-               
-               QApplication::restoreOverrideCursor();
-               
-               getApp()->updateObjectBrowser();
+               return;
        }
        
        MULTIPR_GUI_DecimateDlg* dialog = new MULTIPR_GUI_DecimateDlg(this);
@@ -460,6 +430,12 @@ void MULTIPR_GUI::OnDecimate()
 
 void MULTIPR_GUI::OnRemove()
 {
+       // check if MULTIPRObj exists
+       if (mMULTIPRObj == NULL)
+       {
+               return;
+       }
+       
        retrieveSelectedParts();
        
        if (mSelectedParts.count() == 0)
@@ -490,7 +466,7 @@ void MULTIPR_GUI::OnRemove()
                {
                        const QString& partName = (*it);
                        cout << "Remove " << partName.latin1() << endl;
-                       mMULTIPRObj->removePart(partName.latin1());
+                       mMULTIPRObj->removeParts(partName.latin1());
                }
                
        }
@@ -511,6 +487,12 @@ void MULTIPR_GUI::OnRemove()
 
 void MULTIPR_GUI::OnSave()
 {
+       // check if MULTIPRObj exists
+       if (mMULTIPRObj == NULL)
+       {
+               return;
+       }
+
        QApplication::setOverrideCursor(Qt::waitCursor);
        
        try
@@ -570,6 +552,74 @@ bool MULTIPR_GUI::isPartExist(const char* partName)
 }
 
 
+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("OK") );
+               }
+               
+               QApplication::restoreOverrideCursor();
+               
+               getApp()->updateObjectBrowser();
+       }
+       
+       return true;
+}
+
+
 //*****************************************************************************
 // Super class Data Object implementation
 //*****************************************************************************
@@ -812,74 +862,80 @@ MULTIPR_GUI_DataModel::~MULTIPR_GUI_DataModel()
 
 void MULTIPR_GUI_DataModel::build()
 {
-       MULTIPR_GUI_DataObject_Module* modelRoot = dynamic_cast<MULTIPR_GUI_DataObject_Module*>(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)
+       try
        {
-               MULTIPR_ORB::string_array* listParts = obj->getParts();
+               MULTIPR_GUI_DataObject_Module* modelRoot = dynamic_cast<MULTIPR_GUI_DataObject_Module*>(root());
+               
+               if (!modelRoot)  
+               {  
+                       // root is not set yet
+                       modelRoot = new MULTIPR_GUI_DataObject_Module(this, NULL, "MULTIPR");
+                       setRoot(modelRoot);
+               }
                
-               if (listParts->length() >= 1)
+               MULTIPR_ORB::MULTIPR_Obj_ptr obj = mMULTIPR_GUI->getMULTIPRObj();
+               
+               if (obj != NULL)
                {
-                       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) return;
+                       MULTIPR_ORB::string_array* listParts = obj->getParts();
                        
-                       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++)
+                       if (listParts->length() >= 1)
                        {
-                               const char* strItem = (*listParts)[i];
-                               char* strPartInfo = obj->getPartInfo(strItem);
+                               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(strPartInfo, "%s %d %s %s %s", 
+                               int ret = sscanf(strPartInfo0, "%s %d %s %s %s", 
                                        lMeshName,
                                        &lId,
                                        lPartName,
                                        lPath,
                                        lMEDFileName);
-                               
+                                       
                                if (ret != 5) return;
-                       
-                               //cout << "Part : " << lPartName << endl;
-                               if ((strstr(lPartName,"_MED") != NULL) || (strstr(lPartName,"_LOW") != NULL))
-                               {
-                                       //cout << "Found MED/LOW" << endl;
-                                       new MULTIPR_GUI_DataObject_Resolution(dataObjectPart_prev, strItem, strPartInfo);
-                               }
-                               else
+                               
+                               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++)
                                {
-                                       dataObjectPart_prev = new MULTIPR_GUI_DataObject_Part(dataObjectMesh, strItem, strPartInfo);
+                                       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;
+                               
+                                       //cout << "Part : " << lPartName << endl;
+                                       if ((strstr(lPartName,"_MED") != NULL) || (strstr(lPartName,"_LOW") != NULL))
+                                       {
+                                               //cout << "Found MED/LOW" << endl;
+                                               new MULTIPR_GUI_DataObject_Resolution(dataObjectPart_prev, strItem, strPartInfo);
+                                       }
+                                       else
+                                       {
+                                               dataObjectPart_prev = new MULTIPR_GUI_DataObject_Part(dataObjectMesh, strItem, strPartInfo);
+                                       }
                                }
                        }
                }
        }
+       catch (...)
+       {
+       }
 }
 
 
index 3e2e7d8914689eb02bc3a88494e3a23ec3dab9d4..499f7116078324bbe063a2982251d5dad90e6f83 100644 (file)
@@ -92,6 +92,7 @@ protected slots:
        
        void retrieveSelectedParts();
        bool isPartExist(const char* partName);
+       bool removeLowerResolution();
        
 protected:
        virtual CAM_DataModel* createDataModel();
index 1b08c61a4e79c14188f9f15018a6ea83edcc66a3..526e70d0ac1cbaea8b09ce2d898f1e7e5edd3fb8 100644 (file)
@@ -501,6 +501,8 @@ 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];
@@ -521,11 +523,17 @@ void MULTIPR_GUI_DecimateDlg::OnRadiusAuto()
        float defaultRadius = 0.5f;
        try
        {
-               multipr::Mesh* mesh = new multipr::Mesh();
-               mesh->readSequentialMED(lMEDFileName, lMeshName);
-               const int averageNumberOfNeighbours = 8;
-               defaultRadius = mesh->evalDefaultRadius(averageNumberOfNeighbours);
-               delete mesh;
+               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 (...)
        {
@@ -540,6 +548,8 @@ 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];
@@ -557,49 +567,34 @@ void MULTIPR_GUI_DecimateDlg::OnThresholdAuto()
                lMEDFileName);
        
        QApplication::setOverrideCursor(Qt::waitCursor);
-       float defaultRadius = 0.5f;
+
        try
        {
-               multipr::Mesh* mesh = new multipr::Mesh();
-               mesh->readSequentialMED(lMEDFileName, lMeshName);
-               
-               multipr::DecimationFilter* filter =
-                       multipr::DecimationFilter::create(comboBoxSelectFilter->currentText().latin1());
-               
-               double gradMin = 0.1, gradAvg = 0.15, gradMax = 0.2;
-               
-               multipr::DecimationFilterGradAvg* filterGrad = dynamic_cast<multipr::DecimationFilterGradAvg*>(filter);
-               if (filterGrad)
+               float radius;
+               ret = sscanf(lineEditRadius->text().latin1(), "%f", &radius);
+               if ((ret != 1) || (radius <= 0.0f))
                {
-                       const char* strFieldIt   = comboBoxSelectFieldIteration->currentText().latin1();
-                       int fieldIteration = atoi(strFieldIt);
-                       
-                       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;
-                       }
-                       
-                       filterGrad->getGradientInfo(
-                               mesh,
-                               comboBoxSelectFieldName->currentText().latin1(),
-                               fieldIteration,
-                               radius,
-                               spinBoxBoxing->value(),
-                               &gradMin,
-                               &gradAvg,
-                               &gradMax);
+                       SUIT_MessageBox::error1( 
+                               mModule->getAppli()->desktop(),
+                               "Decimation parameters error", 
+                               "Invalid radius (should be > 0.0)", 
+                               tr("OK") );
+                               
+                       return;
                }
                
-               delete filter;
-               delete mesh;
+               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) );
@@ -607,6 +602,7 @@ void MULTIPR_GUI_DecimateDlg::OnThresholdAuto()
        catch (...)
        {
        }
+       
        QApplication::restoreOverrideCursor();
 }