]> SALOME platform Git repositories - modules/visu.git/commitdiff
Salome HOME
To implement min/max background compilation
authorapo <apo@opencascade.com>
Fri, 16 Sep 2005 09:15:44 +0000 (09:15 +0000)
committerapo <apo@opencascade.com>
Fri, 16 Sep 2005 09:15:44 +0000 (09:15 +0000)
src/CONVERTOR/VISU_MedConvertor.cxx

index dd69788c90b95510a5e170ae76d2e3bccb131706..245f8149ec7157b8d2ce66afacc2b33a18d092a2 100644 (file)
@@ -35,6 +35,7 @@
 #include "MED_Utilities.hxx"
 
 #include <boost/thread/thread.hpp>
+#include <boost/bind.hpp>
 
 #include <vtkCellType.h>
 
@@ -48,7 +49,7 @@ using MED::EBooleen;
 #ifdef _DEBUG_
 static int MYDEBUG = 0;
 static int MYVALUEDEBUG = 0;
-static int MYTHREADDEBUG = 1;
+static int MYTHREADDEBUG = 0;
 static int MY_FAMILY_DEBUG = 0;
 static int MY_GROUP_DEBUG = 0;
 //#define _DEXCEPT_
@@ -516,93 +517,6 @@ namespace
   }
 
 
-  //---------------------------------------------------------------
-  struct TFieldMinMax;
-
-  void
-  GetMinMax(TFieldMinMax* theFieldMinMax,
-           PMEDField theField,
-           const MED::PFieldInfo& theFieldInfo,
-           TInt theNbTimeStamps,
-           MED::EEntiteMaillage theMEntity,
-           const MED::TGeom2Size& theGeom2Size,
-           const MED::TMKey2Profile& theMKey2Profile,
-           const MED::TKey2Gauss& theKey2Gauss,
-           const MED::PWrapper& theMEDWrapper,
-           VISU_MedConvertor::TMutex& theMutex)
-  {
-    //boost::mutex::scoped_lock aLock(theMutex);
-    INITMSG(MYTHREADDEBUG,"GetMinMax: - "<<theFieldMinMax<<
-           "; aFieldName = '"<<theField->myName<<"'"<<
-           "; theNbTimeStamps = "<<theNbTimeStamps<<
-           endl);
-
-    TInt aNbComp = theField->myNbComp;
-    TValField& aValField = theField->myValField;
-    TMinMaxArr& aMinMaxArr = theField->myMinMaxArr;
-    for(TInt iTimeStamp = 1; iTimeStamp <= theNbTimeStamps; iTimeStamp++){
-      INITMSG(MYTHREADDEBUG,"- "<<theFieldMinMax<<"; iTimeStamp = "<<iTimeStamp<<endl);
-
-      MED::PTimeStampInfo aTimeStampInfo = theMEDWrapper->GetPTimeStampInfo(theFieldInfo,
-                                                                           theMEntity,
-                                                                           theGeom2Size,
-                                                                           iTimeStamp);
-      MED::PTimeStampVal aTimeStampVal = theMEDWrapper->GetPTimeStampVal(aTimeStampInfo,
-                                                                        theMKey2Profile,
-                                                                        theKey2Gauss);
-      PMEDValForTime aValForTime = aValField[iTimeStamp];
-
-      const MED::TTimeStampVal& aTimeStampValRef = aTimeStampVal;
-
-      PMEDProfile aProfile = aValForTime->myProfile;
-      TGeom2SubProfile& aGeom2SubProfile = aProfile->myGeom2SubProfile;
-      TGeom2SubProfile::const_iterator anIter = aGeom2SubProfile.begin();
-      for(; anIter != aGeom2SubProfile.end(); anIter++){
-       vtkIdType aVGeom = anIter->first;
-       PMEDSubProfile aSubProfile(anIter->second);
-      
-       TInt aNbElem = aSubProfile->myNbCells;
-       TInt aNbGauss = aValForTime->GetNbGauss(aVGeom);
-       
-       if(aSubProfile->myStatus != eRemoveAll){
-         INITMSG(MYTHREADDEBUG,
-                 "- "<<theFieldMinMax<< 
-                 "; aVGeom = "<<aVGeom<<
-                 "; aNbElem = "<<aNbElem<<
-                 "; aNbGauss = "<<aNbGauss<<
-                 endl);
-         
-         MED::EGeometrieElement aMGeom = aSubProfile->myMGeom;
-         const MED::TMeshValue& aMMeshValue = aTimeStampValRef.GetMeshValue(aMGeom);
-         for(TInt iElem = 0; iElem < aNbElem; iElem++){
-           MED::TCValueSliceArr aMValueSliceArr = aMMeshValue.GetCompValueSliceArr(iElem);
-           ADDMSG(MYVALUEDEBUG,"{");
-           for(TInt iComp = 0; iComp < aNbComp; iComp++){
-             const MED::TCValueSlice& aMValueSlice = aMValueSliceArr[iComp];
-             TMinMax& aMinMax = aMinMaxArr[iComp];
-             float& aMin = aMinMax.first;
-             float& aMax = aMinMax.second;
-             for(TInt iGauss = 0; iGauss < aNbGauss; iGauss++){
-               const float& aVal = aMValueSlice[iGauss];
-               ADDMSG(MYVALUEDEBUG,aVal<<" ");
-               aMin = min(aMin,aVal);
-               aMax = max(aMax,aVal);
-             }
-             ADDMSG(MYVALUEDEBUG,"| ");
-           }
-           ADDMSG(MYVALUEDEBUG,"} ");
-         }
-         ADDMSG(MYVALUEDEBUG,"\n");
-       }
-      }
-    }
-    for(TInt iComp = 0; iComp < aNbComp; iComp++){
-      VISU::TMinMax aMinMax = theField->GetMinMax(iComp);
-      INITMSG(MYTHREADDEBUG,"- "<<theFieldMinMax<<"; "<<iComp<<": "<<aMinMax.first<<"; "<<aMinMax.second<<endl);
-    }
-  }
-
-
   //---------------------------------------------------------------
   struct TFieldMinMax
   {
@@ -634,23 +548,94 @@ namespace
       myKey2Gauss(theKey2Gauss),
       myMEDWrapper(theMEDWrapper),
       myMutex(theMutex)
-    {}
+    {
+      INITMSG(MYTHREADDEBUG,"TFieldMinMax() - "<<this<<endl);
+    }
+
+    ~TFieldMinMax()
+    {
+      INITMSG(MYTHREADDEBUG,"~TFieldMinMax() - "<<this<<endl);
+    }
 
     void
-    operator()()
+    Calculate()
     {
-      GetMinMax(this,
-               myField,
-               myFieldInfo,
-               myNbTimeStamps,
-               myMEntity,
-               myGeom2Size,
-               myMKey2Profile,
-               myKey2Gauss,
-               myMEDWrapper,
-               myMutex);
+      //boost::mutex::scoped_lock aLock(myMutex);
+      INITMSG(MYTHREADDEBUG,"TFieldMinMax::Calculate() - "<<this<<
+             "; aFieldName = '"<<myField->myName<<"'"<<
+             "; myNbTimeStamps = "<<myNbTimeStamps<<
+             endl);
+      
+      TInt aNbComp = myField->myNbComp;
+      TValField& aValField = myField->myValField;
+      TMinMaxArr& aMinMaxArr = myField->myMinMaxArr;
+      for(TInt iTimeStamp = 1; iTimeStamp <= myNbTimeStamps; iTimeStamp++){
+       INITMSG(MYTHREADDEBUG,"- "<<this<<"; iTimeStamp = "<<iTimeStamp<<endl);
+       
+       MED::PTimeStampInfo aTimeStampInfo = myMEDWrapper->GetPTimeStampInfo(myFieldInfo,
+                                                                            myMEntity,
+                                                                            myGeom2Size,
+                                                                            iTimeStamp);
+       MED::PTimeStampVal aTimeStampVal = myMEDWrapper->GetPTimeStampVal(aTimeStampInfo,
+                                                                         myMKey2Profile,
+                                                                         myKey2Gauss);
+       PMEDValForTime aValForTime = aValField[iTimeStamp];
+       
+       const MED::TTimeStampVal& aTimeStampValRef = aTimeStampVal;
+       
+       PMEDProfile aProfile = aValForTime->myProfile;
+       TGeom2SubProfile& aGeom2SubProfile = aProfile->myGeom2SubProfile;
+       TGeom2SubProfile::const_iterator anIter = aGeom2SubProfile.begin();
+       for(; anIter != aGeom2SubProfile.end(); anIter++){
+         vtkIdType aVGeom = anIter->first;
+         PMEDSubProfile aSubProfile(anIter->second);
+         
+         TInt aNbElem = aSubProfile->myNbCells;
+         TInt aNbGauss = aValForTime->GetNbGauss(aVGeom);
+         
+         if(aSubProfile->myStatus != eRemoveAll){
+           INITMSG(MYTHREADDEBUG,
+                   "- "<<this<< 
+                   "; aVGeom = "<<aVGeom<<
+                   "; aNbElem = "<<aNbElem<<
+                   "; aNbGauss = "<<aNbGauss<<
+                   endl);
+           
+           MED::EGeometrieElement aMGeom = aSubProfile->myMGeom;
+           const MED::TMeshValue& aMMeshValue = aTimeStampValRef.GetMeshValue(aMGeom);
+           for(TInt iElem = 0; iElem < aNbElem; iElem++){
+             MED::TCValueSliceArr aMValueSliceArr = aMMeshValue.GetCompValueSliceArr(iElem);
+             for(TInt iComp = 0; iComp < aNbComp; iComp++){
+               const MED::TCValueSlice& aMValueSlice = aMValueSliceArr[iComp];
+               TMinMax& aMinMax = aMinMaxArr[iComp];
+               float& aMin = aMinMax.first;
+               float& aMax = aMinMax.second;
+               for(TInt iGauss = 0; iGauss < aNbGauss; iGauss++){
+                 const float& aVal = aMValueSlice[iGauss];
+                 aMin = min(aMin,aVal);
+                 aMax = max(aMax,aVal);
+               }
+             }
+           }
+         }
+       }
+      }
+      for(TInt iComp = 0; iComp < aNbComp; iComp++){
+       VISU::TMinMax aMinMax = myField->GetMinMax(iComp);
+       INITMSG(MYTHREADDEBUG,"- "<<this<<"; "<<iComp<<": "<<aMinMax.first<<"; "<<aMinMax.second<<endl);
+      }
     }
   };
+  typedef SharedPtr<TFieldMinMax> PFieldMinMax;
+
+
+  //---------------------------------------------------------------
+  void
+  GetFieldMinMax(PFieldMinMax theFieldMinMax)
+  {
+    theFieldMinMax->Calculate();
+  }
+
 
   //---------------------------------------------------------------
   void
@@ -684,16 +669,17 @@ namespace
       TFieldMap& aFieldMap = aMeshOnEntity->myFieldMap;
       PMEDField aField = aFieldMap[aFieldName];
 
-      TFieldMinMax* aFieldMinMax = new TFieldMinMax(aField,
-                                                   aFieldInfo,
-                                                   aNbTimeStamps,
-                                                   aMEntity,
-                                                   aGeom2Size,
-                                                   theMKey2Profile,
-                                                   theKey2Gauss,
-                                                   theMEDWrapper,
-                                                   theMutex);
-      new boost::thread(*aFieldMinMax);
+      PFieldMinMax aFieldMinMax(new TFieldMinMax(aField,
+                                                aFieldInfo,
+                                                aNbTimeStamps,
+                                                aMEntity,
+                                                aGeom2Size,
+                                                theMKey2Profile,
+                                                theKey2Gauss,
+                                                theMEDWrapper,
+                                                theMutex));
+
+      boost::thread aThread(boost::bind(&GetFieldMinMax,aFieldMinMax));
     }
   }