]> SALOME platform Git repositories - modules/visu.git/commitdiff
Salome HOME
Cache improvement
authorouv <ouv@opencascade.com>
Thu, 30 Nov 2006 16:59:51 +0000 (16:59 +0000)
committerouv <ouv@opencascade.com>
Thu, 30 Nov 2006 16:59:51 +0000 (16:59 +0000)
src/VISUGUI/VisuGUI_CacheDlg.cxx
src/VISUGUI/VisuGUI_CacheDlg.h
src/VISUGUI/VisuGUI_Slider.cxx
src/VISU_I/VISU_ColoredPrs3dCache_i.cc
src/VISU_I/VISU_ColoredPrs3dCache_i.hh

index 5e0be2c29faea800cf1e08e4a4ef2c4c5e22bfc5..a17535f2fdd7460111ebc7c17f9c2871847b1012 100644 (file)
@@ -84,6 +84,35 @@ VisuGUI_CacheDlg::VisuGUI_CacheDlg( VISU::ColoredPrs3dCache_var theCache,
 
   connect( myLimitedMemoryButton, SIGNAL( toggled( bool ) ), myLimitedMemory, SLOT( setEnabled( bool ) ) );
 
+  // Current state
+  QGroupBox* aStateGroup = new QGroupBox( tr( "MEMORY STATE" ), this );
+  aStateGroup->setColumnLayout( 0, Qt::Vertical );
+  aStateGroup->layout()->setSpacing( 0 );
+  aStateGroup->layout()->setMargin( 0 );
+
+  QGridLayout* aStateLayout = new QGridLayout( aStateGroup->layout(), 2, 2 );
+  aStateLayout->setSpacing(6);
+  aStateLayout->setMargin(6);
+
+  QLabel* aUsedMemoryLabel = new QLabel( tr( "USED_BY_CACHE" ), aStateGroup );
+  myUsedMemory = new QLineEdit( aStateGroup );
+  myUsedMemory->setText( QString::number( (double)myCache->GetMemorySize() ) + " Mb" );
+  myUsedMemory->setReadOnly( true );
+  myUsedMemory->setEnabled( false );
+  myUsedMemory->setPaletteForegroundColor( Qt::black );
+
+  QLabel* aFreeMemoryLabel = new QLabel( tr( "FREE" ), aStateGroup );
+  myFreeMemory = new QLineEdit( aStateGroup );
+  myFreeMemory->setText( QString::number( aLimitedMemoryMax ) + " Mb" );
+  myFreeMemory->setReadOnly( true );
+  myFreeMemory->setEnabled( false );
+  myFreeMemory->setPaletteForegroundColor( Qt::black );
+
+  aStateLayout->addWidget( aUsedMemoryLabel, 0, 0 );
+  aStateLayout->addWidget( myUsedMemory, 0, 1 );
+  aStateLayout->addWidget( aFreeMemoryLabel, 1, 0 );
+  aStateLayout->addWidget( myFreeMemory, 1, 1 );
+
   // Ok / Cancel
   QGroupBox* GroupButtons = new QGroupBox( this, "GroupButtons" );
   GroupButtons->setColumnLayout(0, Qt::Vertical );
index f60521f84659bcbc3d803643badb3a85e2c683cf..71693e76b8bea213cb52973fdf21af524cf511e6 100644 (file)
@@ -63,6 +63,9 @@ private:
   QRadioButton*   myMimimalMemoryButton;
   QRadioButton*   myLimitedMemoryButton;
   QtxDblSpinBox*  myLimitedMemory;
+
+  QLineEdit*      myUsedMemory;
+  QLineEdit*      myFreeMemory;
 };
 
 #endif
index 068783ea38e2c49ae6a95d7bbb7277e5396cde77..1d19139042d41d118291c65e40d45f3afd1bf6f4 100644 (file)
@@ -68,6 +68,8 @@
 #include <qtimer.h>
 #include <qfont.h>
 
+#define SHOW_MEMORY_STATE
+
 /*!
   Constructor
 */
@@ -102,6 +104,7 @@ VisuGUI_Slider::VisuGUI_Slider( VisuGUI_Module* theModule,
   aSliderLayout->addWidget( myFirstTimeStamp );
 
   mySlider = new QSlider( aWidget );
+  mySlider->setMinValue( 0 );
   mySlider->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
   mySlider->setOrientation( QSlider::Horizontal );
   mySlider->setTracking( false );
@@ -160,6 +163,7 @@ VisuGUI_Slider::VisuGUI_Slider( VisuGUI_Module* theModule,
 
   aButtonsLayout->addItem( new QSpacerItem( 24, 24, QSizePolicy::Expanding, QSizePolicy::Minimum ) );
 
+#ifdef SHOW_MEMORY_STATE
   // Memory state
   QLabel* aCacheMemoryLabel = new QLabel( tr( "CACHE_MEMORY" ), aWidget );
   aCacheMemoryLabel->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed);
@@ -178,6 +182,7 @@ VisuGUI_Slider::VisuGUI_Slider( VisuGUI_Module* theModule,
   aButtonsLayout->addWidget( myFreeMemory );
 
   aButtonsLayout->addItem( new QSpacerItem( 24, 24, QSizePolicy::Expanding, QSizePolicy::Minimum ) );
+#endif
 
   // Speed
   QLabel* aSpeedLabel = new QLabel( tr( "SPEED" ), aWidget );
@@ -262,9 +267,6 @@ void VisuGUI_Slider::enableControls( bool on )
     VISU::ColoredPrs3dHolder::BasicInput_var anInput = aHolder->GetBasicInput();
     CORBA::Long aTimeStampNumber = anInput->myTimeStampNumber;
 
-    mySlider->setMinValue( 0 );
-    mySlider->setMaxValue( aLength-1 );
-
     myFirstTimeStamp->setText( aTimeStampsRange[0].myTime.in() );
     myLastTimeStamp->setText( aTimeStampsRange[aLength-1].myTime.in() );
     myTimeStampsNumber->setText( QString("(") + QString::number( aLength ) + ")" );
@@ -291,6 +293,7 @@ void VisuGUI_Slider::enableControls( bool on )
 
     myTimeStampStrings->setCurrentItem( a_current_index );
     myTimeStampIndices->setCurrentItem( a_current_index );
+    mySlider->setMaxValue( aLength-1 );
     mySlider->setValue( a_current_index );
   }
   else
@@ -302,6 +305,7 @@ void VisuGUI_Slider::enableControls( bool on )
 
 void VisuGUI_Slider::updateMemoryState()
 {
+#ifdef SHOW_MEMORY_STATE
   if( checkHolderList() )
     return;
 
@@ -314,6 +318,7 @@ void VisuGUI_Slider::updateMemoryState()
   long aMb = 1024 * 1024;
   double aFreeMemory = (double)VISU_PipeLine::GetAvailableMemory( 2048 * aMb ) / (double)aMb;
   myFreeMemory->setText( QString::number( aFreeMemory ) + " Mb" );
+#endif
 }
 
 void VisuGUI_Slider::onSelectionChanged()
index 3e7e61dab195ee9b84ce61c9bb95d8e4f1b32e0c..c1af621fc5a50e227349a23edf7fca02cf09dd5f 100644 (file)
@@ -33,6 +33,9 @@
 #include "VISU_View_i.hh"
 #include "VISU_Actor.h"
 
+#include "VTKViewer_Algorithm.h"
+#include "SVTK_Functor.h"
+
 #include "VVTK_ViewWindow.h"
 #include "SUIT_ResourceMgr.h"
 
@@ -111,7 +114,8 @@ VISU::ColoredPrs3dCache_i
 int
 VISU::ColoredPrs3dCache_i
 ::IsPossible(VISU::VISUType theType,
-            const VISU::ColoredPrs3dHolder::BasicInput& theInput)
+            const VISU::ColoredPrs3dHolder::BasicInput& theInput,
+            float& theMemoryToClear)
 {
   //cout << "VISU::ColoredPrs3dCache_i::IsPossible " << endl;
   size_t aMemory = VISU::CheckIsPossible(theType, theInput, true);
@@ -122,7 +126,11 @@ VISU::ColoredPrs3dCache_i
       CORBA::Float aMemoryLimit = GetLimitedMemory();
       CORBA::Float aMemoryNeeded = CORBA::Float(aMemory/(1024.0*1024.0)); // convert to Mb
       //cout<<"Memory needed: "<<aMemoryNeeded<<"; used: "<<aMemoryUsed<<"; limit: "<<aMemoryLimit<<endl;
-      return aMemoryUsed + aMemoryNeeded < aMemoryLimit;
+      if( aMemoryUsed + aMemoryNeeded < aMemoryLimit )
+       return true;
+
+      theMemoryToClear = aMemoryNeeded;
+      return true;
     }
   }
   return aMemory > 0;
@@ -163,9 +171,14 @@ VISU::ColoredPrs3dCache_i
 ::CreateHolder(VISU::VISUType theType,
               const VISU::ColoredPrs3dHolder::BasicInput& theInput)
 {
-  if(IsPossible(theType, theInput))
+  float aMemoryToClear = 0.;
+  if(IsPossible(theType, theInput, aMemoryToClear))
   {
     VISU::ColoredPrs3dHolder_i* aHolder = new VISU::ColoredPrs3dHolder_i(theType, theInput, *this);
+
+    if( aMemoryToClear > 1 / VTK_LARGE_FLOAT )
+      ClearMemory( aMemoryToClear, aHolder );
+
     VISU::ColoredPrs3d_i* aColoredPrs3d = CreateColoredPrs3d(theType, theInput);
     std::string aComment = std::string("myComment=") + aColoredPrs3d->GetComment();
     std::string aName = aColoredPrs3d->GenerateName().latin1();
@@ -206,6 +219,7 @@ void
 VISU::ColoredPrs3dCache_i
 ::SetLimitedMemory(CORBA::Float theMemorySize)
 {
+  ClearCache(theMemorySize);
   myLimitedMemory = theMemorySize;
 }
 
@@ -351,10 +365,13 @@ VISU::ColoredPrs3dCache_i
   TLastVisitedPrsList& aLastVisitedPrsList = GetLastVisitedPrsList(theHolder);
   TPrs3dPtr aPrs3d = FindPrsByInput(aLastVisitedPrsList, theInput);
   bool anIsCheckPossible = GetMemoryMode() == VISU::ColoredPrs3dCache::LIMITED;
+  float aMemoryToClear = 0.;
   if(aPrs3d.GetPointer()){
     aLastVisitedPrsList.push_front(aPrs3d);
     //cout << "FindPrsByInput " << aPrs3d;
-  }else if(anIsCheckPossible && IsPossible(theHolder->GetPrsType(), theInput)){
+  }else if(anIsCheckPossible && IsPossible(theHolder->GetPrsType(), theInput, aMemoryToClear)){
+    if( aMemoryToClear > 1 / VTK_LARGE_FLOAT )
+      ClearMemory(aMemoryToClear, theHolder);
     aPrs3d = CreatePrs(theHolder->GetPrsType(), theInput, theHolder);
     //cout << "Created " << aPrs3d;
   }else{
@@ -413,19 +430,101 @@ VISU::ColoredPrs3dCache_i
 //----------------------------------------------------------------------------
 void
 VISU::ColoredPrs3dCache_i
-::ClearCache()
+::ClearCache(float theMemory)
+{
+  //cout << "VISU::ColoredPrs3dCache_i::ClearCache( " << theMemory << " )" << endl;
+
+  float aCurrentMemory = GetMemorySize();
+  ClearMemory( aCurrentMemory - theMemory, NULL );
+}
+
+
+//----------------------------------------------------------------------------
+void
+VISU::ColoredPrs3dCache_i
+::ClearMemory(float theMemory, VISU::ColoredPrs3dHolder_i* theActiveHolder)
+{
+  if(MYDEBUG) cout << "VISU::ColoredPrs3dCache_i::ClearMemory( " << theMemory << " )" << endl;
+
+  if( theMemory < 1 / VTK_LARGE_FLOAT )
+    return;
+
+  if(MYDEBUG) PrintCache();
+
+  TColoredPrs3dHolderMap::iterator aHolderIter = myHolderMap.begin();
+  TColoredPrs3dHolderMap::iterator aHolderIterEnd = myHolderMap.end();
+
+  int anIteration = 0;
+  for( ; aHolderIter != aHolderIterEnd; aHolderIter++ )
+  {
+    TLastVisitedPrsList& aPrsList = aHolderIter->second;
+    anIteration = QMAX( aPrsList.size() - 1, anIteration );
+  }
+  if(MYDEBUG) cout << "Iteration - " << anIteration << endl;
+
+  std::string anEntry;
+  if( theActiveHolder )
+    anEntry = theActiveHolder->GetEntry();
+
+  float aMemory, aGatheredMemory = 0.;
+  while( anIteration > 0 )
+  {
+    for( aHolderIter = myHolderMap.begin(); aHolderIter != aHolderIterEnd; aHolderIter++ )
+    {
+      //if( aHolderIter->first == anEntry )
+      //continue;
+
+      TLastVisitedPrsList& aPrsList = aHolderIter->second;
+      if( anIteration < aPrsList.size() )
+      {
+       TPrs3dPtr aPrs3d = aPrsList[anIteration];
+       if(MYDEBUG) cout << aPrs3d.GetPointer() << " ";
+       if( !aPrs3d.GetPointer() )
+         continue;
+
+       aMemory = aPrs3d->GetMemorySize();
+       aGatheredMemory += aMemory;
+       if(MYDEBUG) cout << aMemory << " >> " << aGatheredMemory;
+
+       aPrsList.pop_back();
+
+       if( aGatheredMemory > theMemory )
+       {
+         if(MYDEBUG) cout << " STOP" << endl;
+         goto stop;
+       }
+       if(MYDEBUG) cout << endl;
+      }
+    }
+
+    anIteration--;
+  }
+
+ stop:
+  if(MYDEBUG) PrintCache();
+}
+
+
+//----------------------------------------------------------------------------
+void
+VISU::ColoredPrs3dCache_i
+::PrintCache()
 {
+  cout << "VISU::ColoredPrs3dCache_i::PrintCache()" << endl;
+
+  cout << "Cache memory - " << GetMemorySize() << " Mb" << endl;
   TColoredPrs3dHolderMap::const_iterator aHolderIter = myHolderMap.begin();
   TColoredPrs3dHolderMap::const_iterator aHolderIterEnd = myHolderMap.end();
   for(; aHolderIter != aHolderIterEnd; aHolderIter++){
     const TLastVisitedPrsList& aPrsList = aHolderIter->second;
     TLastVisitedPrsList::const_iterator aPrsIter = aPrsList.begin();
     TLastVisitedPrsList::const_iterator aPrsIterEnd = aPrsList.end();
-    for(; aPrsIter != aPrsIterEnd; aPrsIter++){
+
+    cout << "Holder - " << aHolderIter->first.c_str() << endl;
+    cout << "Size   - " << aPrsList.size() << endl;
+    for(aPrsIter++; aPrsIter != aPrsIterEnd; aPrsIter++)
       if(TPrs3dPtr aPrs3d = *aPrsIter)
-      {
-      }
-    }
+       cout << aPrs3d.GetPointer() << " (" << aPrs3d->GetMemorySize() << " Mb)"<< endl;
   }
 }
 
index ae7970d4d834f035cc657969020e82cdd8ad8408..45f0ebc53f7899c09d2e3ff8291847ffd1213479 100644 (file)
@@ -160,22 +160,31 @@ namespace VISU
                         const VISU::ColoredPrs3dHolder::BasicInput& theInput,
                         VISU::View3D_ptr theView3D);
 
-    // Unregister the holder instance from cache
+    //! Unregister the holder instance from cache
     void
     RemoveHolder(VISU::ColoredPrs3dHolder_i* theHolder);
-
-    void
-    ClearCache();
-
+  protected:
     //----------------------------------------------------------------------------
     virtual int
     IsPossible(VISU::VISUType theType,
-              const VISU::ColoredPrs3dHolder::BasicInput& theInput);
+              const VISU::ColoredPrs3dHolder::BasicInput& theInput,
+              float& theMemoryToClear);
 
     TPrs3dPtr
     FindPrsByInput(TLastVisitedPrsList& theLastVisitedPrsList,
                   const VISU::ColoredPrs3dHolder::BasicInput& theInput);
 
+    //----------------------------------------------------------------------------
+    void
+    ClearCache(float theMemory = 0);
+
+    void
+    ClearMemory(float theMemory,
+               VISU::ColoredPrs3dHolder_i* theActiveHolder);
+
+    void
+    PrintCache();
+
   private:
     CORBA::Float myLimitedMemory;
     VISU::ColoredPrs3dCache::MemoryMode myMemoryMode;