#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"
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() );
}
#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() ),
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 )
{
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()
{
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() );
{
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() );