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 );
#include <qtimer.h>
#include <qfont.h>
+#define SHOW_MEMORY_STATE
+
/*!
Constructor
*/
aSliderLayout->addWidget( myFirstTimeStamp );
mySlider = new QSlider( aWidget );
+ mySlider->setMinValue( 0 );
mySlider->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
mySlider->setOrientation( QSlider::Horizontal );
mySlider->setTracking( false );
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);
aButtonsLayout->addWidget( myFreeMemory );
aButtonsLayout->addItem( new QSpacerItem( 24, 24, QSizePolicy::Expanding, QSizePolicy::Minimum ) );
+#endif
// Speed
QLabel* aSpeedLabel = new QLabel( tr( "SPEED" ), aWidget );
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 ) + ")" );
myTimeStampStrings->setCurrentItem( a_current_index );
myTimeStampIndices->setCurrentItem( a_current_index );
+ mySlider->setMaxValue( aLength-1 );
mySlider->setValue( a_current_index );
}
else
void VisuGUI_Slider::updateMemoryState()
{
+#ifdef SHOW_MEMORY_STATE
if( checkHolderList() )
return;
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()
#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"
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);
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;
::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();
VISU::ColoredPrs3dCache_i
::SetLimitedMemory(CORBA::Float theMemorySize)
{
+ ClearCache(theMemorySize);
myLimitedMemory = theMemorySize;
}
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{
//----------------------------------------------------------------------------
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;
}
}