]> SALOME platform Git repositories - modules/visu.git/commitdiff
Salome HOME
To introduce caching for textures
authorapo <apo@opencascade.com>
Tue, 6 Dec 2005 07:14:42 +0000 (07:14 +0000)
committerapo <apo@opencascade.com>
Tue, 6 Dec 2005 07:14:42 +0000 (07:14 +0000)
src/VISU_I/VISU_GaussPoints_i.cc
src/VVTK/VVTK_SegmentationCursorDlg.cxx
src/VVTK/VVTK_SegmentationCursorDlg.h

index 18097a654b78d7abe34073b92d07ca70cb7fc606..96b027261f58ea1847b46abe146e47f112d21ba2 100644 (file)
@@ -30,6 +30,7 @@
 #include "VISU_Result_i.hh"
 #include "VISU_GaussPtsAct.h"
 #include "VISU_GaussPointsPL.hxx"
+#include "VVTK_SegmentationCursorDlg.h"
 
 #include "VISU_OpenGLPointSpriteMapper.hxx"
 #include "VISU_ScalarBarCtrl.hxx"
@@ -725,28 +726,9 @@ VISU::GaussPoints_i
   if( !updateMainTexture && !updateAlphaTexture )
     return;
 
-  QString mainTextureFormat = theMainTexture.section( '.', -1 );
-  QString mainTextureVTI = theMainTexture.section( '.', 0, -2 ) + ".vti";
-  QString command1 = QString( "VISU_img2vti " ) + mainTextureFormat +
-                     " " + theMainTexture + " " + mainTextureVTI;
-  //cout << command1.latin1() << endl;
-  bool convertMainTexture = system( command1.latin1() ) == 0;
-
-  QString alphaTextureFormat = theAlphaTexture.section( '.', -1 );
-  QString alphaTextureVTI = theAlphaTexture.section( '.', 0, -2 ) + ".vti";
-  QString command2 = QString( "VISU_img2vti " ) + alphaTextureFormat +
-                     " " + theAlphaTexture + " " + alphaTextureVTI;
-  //cout << command2.latin1() << endl;
-  bool convertAlphaTexture = system( command2.latin1() ) == 0;
-
-  if( convertMainTexture && convertAlphaTexture ){
-    vtkImageData* anImageData =
-      VISU_GaussPointsPL::MakeTexture( mainTextureVTI.latin1(), 
-                                      alphaTextureVTI.latin1());
-    myGaussPointsPL->SetImageData( anImageData );
-    if( anImageData )
-      anImageData->Delete();
-  }
+  using namespace VISU;
+  TTextureValue aTextureValue = GetTexture(theMainTexture,theAlphaTexture);
+  myGaussPointsPL->SetImageData( aTextureValue.GetPointer() );
 }
 
 
index c81d39cbc44ab0473167f8feae8407c32e951973..1a62c4964fb08fbe26218f48ac925a99342e1f61 100644 (file)
@@ -31,6 +31,7 @@
 #include <vtkRenderer.h>
 #include <vtkRenderWindowInteractor.h>
 #include <vtkSmartPointer.h>
+#include <vtkImageData.h>
 
 #include "utilities.h"
 
 
 using namespace std;
 
+
+//----------------------------------------------------------------
+namespace VISU
+{
+  inline
+  QString
+  Image2VTI(const QString& theImageFileName)
+  {
+    QFileInfo aFileInfo(theImageFileName);
+    QString aFormat = aFileInfo.extension(FALSE);
+    QString aVTIName = QString("/tmp/") + getenv("USER")  + "-" + aFileInfo.baseName(TRUE) + ".vti";
+    QString aCommand = QString( "VISU_img2vti " ) + aFormat + " " +  theImageFileName + " " + aVTIName;
+
+    if(system( aCommand.latin1() ) == 0)
+      return aVTIName;
+
+    return QString::null;
+  }
+
+  inline
+  void
+  RemoveFile(const QString& theFileName)
+  {
+    if( !theFileName.isNull() ){
+      QString aCommand = QString( "rm -fr " ) + theFileName;
+      system( aCommand.latin1() );
+    }
+  }
+  
+  
+  TTextureValue
+  GetTexture(const QString& theMainTexture, 
+            const QString& theAlphaTexture)
+  {
+    typedef std::pair<std::string,std::string> TTextureKey;
+    typedef std::map<TTextureKey,TTextureValue> TTextureMap;
+    
+    static TTextureMap aTextureMap;
+    
+    TTextureValue aTextureValue;
+    TTextureKey aTextureKey(theMainTexture,theAlphaTexture);
+    TTextureMap::const_iterator anIter = aTextureMap.find(aTextureKey);
+    if(anIter != aTextureMap.end()){
+      aTextureValue = anIter->second;
+    }else{
+      QString aMainTextureVTI = Image2VTI(theMainTexture);
+      QString anAlphaTextureVTI = Image2VTI(theAlphaTexture);
+      
+      if( !aMainTextureVTI.isNull() && !anAlphaTextureVTI.isNull() ){
+       aTextureValue =
+         VISU_GaussPointsPL::MakeTexture( aMainTextureVTI.latin1(), 
+                                          anAlphaTextureVTI.latin1());
+
+       if( aTextureValue.GetPointer() )
+         aTextureMap[aTextureKey] = aTextureValue;
+      }
+
+      RemoveFile(aMainTextureVTI);
+      RemoveFile(anAlphaTextureVTI);
+    }
+
+    return aTextureValue;
+  }
+}
+
+
+//----------------------------------------------------------------
 VVTK_SegmentationCursorDlg::VVTK_SegmentationCursorDlg( QWidget* parent, const char* name )
   :QDialog( parent, name, false, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu ),
    myEventCallbackCommand( vtkCallbackCommand::New() ),
@@ -488,9 +556,11 @@ VISU_OutsideCursorSettings* VVTK_SegmentationCursorDlg::GetOutsideCursorSettings
   return myOutsideCursorSettings.GetPointer();
 }
 
-vtkImageData* VVTK_SegmentationCursorDlg::MakeImageData( bool theInside,
-                                                        const QString& theMainTexture, 
-                                                        const QString& theAlphaTexture )
+VISU::TTextureValue 
+VVTK_SegmentationCursorDlg
+::MakeImageData( bool theInside,
+                const QString& theMainTexture, 
+                const QString& theAlphaTexture )
 {
   if( theInside )
   {
@@ -513,25 +583,8 @@ vtkImageData* VVTK_SegmentationCursorDlg::MakeImageData( bool theInside,
     myOutsideAlphaTexture = theAlphaTexture;
   }
 
-  QString mainTextureFormat = theMainTexture.section( '.', -1 );
-  QString mainTextureVTI = theMainTexture.section( '.', 0, -2 ) + ".vti";
-  QString command1 = QString( "VISU_img2vti " ) + mainTextureFormat +
-                     " " + theMainTexture + " " + mainTextureVTI;
-  //cout << command1.latin1() << endl;
-  bool convertMainTexture = system( command1.latin1() ) == 0;
-
-  QString alphaTextureFormat = theAlphaTexture.section( '.', -1 );
-  QString alphaTextureVTI = theAlphaTexture.section( '.', 0, -2 ) + ".vti";
-  QString command2 = QString( "VISU_img2vti " ) + alphaTextureFormat +
-                     " " + theAlphaTexture + " " + alphaTextureVTI;
-  //cout << command2.latin1() << endl;
-  bool convertAlphaTexture = system( command2.latin1() ) == 0;
-
-  if( !convertMainTexture || !convertAlphaTexture )
-    return 0;
-
-  return VISU_GaussPointsPL::MakeTexture( mainTextureVTI.latin1(), 
-                                         alphaTextureVTI.latin1());
+  return VISU::GetTexture( theMainTexture.latin1(), 
+                          theAlphaTexture.latin1());
 }
 
 void VVTK_SegmentationCursorDlg::onClickApply()
@@ -594,10 +647,10 @@ void VVTK_SegmentationCursorDlg::ApplyInsideGaussPoints()
 {
   QString anInsideMainTexture = myInsidePrimitiveBox->getMainTexture();
   QString anInsideAlphaTexture = myInsidePrimitiveBox->getAlphaTexture();
-  vtkImageData* aTexture = this->MakeImageData( true, anInsideMainTexture, anInsideAlphaTexture );
+  VISU::TTextureValue aTexture = MakeImageData( true, anInsideMainTexture, anInsideAlphaTexture );
 
-  if( aTexture )
-    myInsideCursorSettings->SetTexture( aTexture );
+  if( aTexture.GetPointer() )
+    myInsideCursorSettings->SetTexture( aTexture.GetPointer() );
 
   myInsideCursorSettings->SetInitial( false );
   myInsideCursorSettings->SetPrimitiveType( myInsidePrimitiveBox->getPrimitiveType() );
@@ -617,10 +670,10 @@ void VVTK_SegmentationCursorDlg::ApplyOutsideGaussPoints()
 {
   QString anOutsideMainTexture = myOutsidePrimitiveBox->getMainTexture();
   QString anOutsideAlphaTexture = myOutsidePrimitiveBox->getAlphaTexture();
-  vtkImageData* aTexture = this->MakeImageData( false, anOutsideMainTexture, anOutsideAlphaTexture );
+  VISU::TTextureValue aTexture = MakeImageData( false, anOutsideMainTexture, anOutsideAlphaTexture );
 
-  if( aTexture )
-    myOutsideCursorSettings->SetTexture( aTexture );
+  if( aTexture.GetPointer() )
+    myOutsideCursorSettings->SetTexture( aTexture.GetPointer() );
 
   myOutsideCursorSettings->SetInitial( false );
   myOutsideCursorSettings->SetPrimitiveType( myOutsidePrimitiveBox->getPrimitiveType() );
index 39c0c118a061809e16a91e7f4497b8bde54f2460..29f5fed251137f233ab7cec0fd4ac59ba830204a 100644 (file)
@@ -39,6 +39,15 @@ class VISU_WidgetCtrl;
 class VVTK_PrimitiveBox;
 class VVTK_SizeBox;
 
+namespace VISU
+{
+  typedef vtkSmartPointer<vtkImageData> TTextureValue;
+
+  TTextureValue
+  GetTexture(const QString& theMainTexture, 
+            const QString& theAlphaTexture);
+}
+
 //! Segmentation Cursor Dialog.
 /*!
  * Uses for set up Segmentation and Outside Cursor Gauss Points preferenses
@@ -75,9 +84,10 @@ protected:
   void             ApplyInsideGaussPoints();
   void             ApplyOutsideGaussPoints();
 
-  vtkImageData*    MakeImageData( bool theInside,
-                                 const QString& theMainTexture, 
-                                 const QString& theAlphaTexture );
+  VISU::TTextureValue
+  MakeImageData( bool theInside,
+                const QString& theMainTexture, 
+                const QString& theAlphaTexture );
 
 private:
   static void      ProcessEvents(vtkObject* theObject,