#include "VVTK_SegmentationCursorDlg.h"
+#include "VISU_GaussPtsAct.h"
#include "VISU_ImplicitFunctionWidget.h"
-#include "QtxAction.h"
-#include "QtxDblSpinBox.h"
+#include "VISU_GaussPointsPL.hxx"
+
+#include "SUIT_ResourceMgr.h"
+#include "SUIT_Session.h"
+
+#include <vtkActorCollection.h>
+#include <vtkCallbackCommand.h>
+#include <vtkObjectFactory.h>
+#include <vtkRenderer.h>
+#include <vtkRenderWindowInteractor.h>
+#include <vtkSmartPointer.h>
#include "utilities.h"
-#include <qtabwidget.h>
-#include <qvbox.h>
+#include <qbuttongroup.h>
+#include <qcolordialog.h>
+#include <qfiledialog.h>
#include <qgroupbox.h>
#include <qlabel.h>
-#include <qpushbutton.h>
#include <qlayout.h>
+#include <qlineedit.h>
+#include <qpushbutton.h>
+#include <qradiobutton.h>
+#include <qtabwidget.h>
+#include <qvbox.h>
-#include <vtkRenderer.h>
-#include <vtkRenderWindowInteractor.h>
+#include "QtxAction.h"
+#include "QtxDblSpinBox.h"
using namespace std;
VVTK_SegmentationCursorDlg::VVTK_SegmentationCursorDlg( QWidget* parent, const char* name )
:QDialog( parent, name, false, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu ),
- myEventCallbackCommand( vtkCallbackCommand::New() )
+ myEventCallbackCommand( vtkCallbackCommand::New() ),
+ myActorCollection( vtkActorCollection::New() ),
+ myOutsideCursorSettings( VISU_OutsideCursorSettings::New() )
{
myPriority = 0.0;
myEventCallbackCommand->Delete();
myEventCallbackCommand->SetClientData(this);
myEventCallbackCommand->SetCallback(VVTK_SegmentationCursorDlg::ProcessEvents);
+ SUIT_ResourceMgr* aResourceMgr = SUIT_Session::session()->resourceMgr();
+
setCaption( tr( "SEGMENTATION_CURSOR_DLG_TITLE" ) );
setSizeGripEnabled(TRUE);
TopLayout->setSpacing(6);
TopLayout->setMargin(11);
- QTabWidget* TabBox = new QTabWidget( this );
+ myTabBox = new QTabWidget( this );
// Segmentation cursor pane
- QVBox* SegmentationCursorBox = new QVBox( this );
- SegmentationCursorBox->setMargin(11);
- SegmentationCursorBox->setSpacing(6);
+ mySegmentationCursorBox = new QVBox( this );
+ mySegmentationCursorBox->setMargin(11);
+ mySegmentationCursorBox->setSpacing(6);
// Origin
- QGroupBox* OriginGroup = new QGroupBox( tr( "ORIGIN_TITLE" ), SegmentationCursorBox, "OriginGroup" );
+ QGroupBox* OriginGroup = new QGroupBox( tr( "ORIGIN_TITLE" ), mySegmentationCursorBox, "OriginGroup" );
OriginGroup->setColumnLayout( 0, Qt::Vertical );
OriginGroup->layout()->setSpacing( 0 );
OriginGroup->layout()->setMargin( 0 );
OriginGroupLayout->setMargin(11);
QLabel* XOriginLabel = new QLabel( tr( "ORIGIN_X" ), OriginGroup );
- myXOriginSpinBox = new QtxDblSpinBox( -1000.0, 1000.0, 1.0, OriginGroup );
+ myXOriginSpinBox = new QtxDblSpinBox( -1000.0, 1000.0, 0.1, OriginGroup );
myXOriginSpinBox->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
myXOriginSpinBox->setMinimumWidth( 100 );
myXOriginSpinBox->setValue( 0.0 );
QLabel* YOriginLabel = new QLabel( tr( "ORIGIN_Y" ), OriginGroup );
- myYOriginSpinBox = new QtxDblSpinBox( -1000.0, 1000.0, 1.0, OriginGroup );
+ myYOriginSpinBox = new QtxDblSpinBox( -1000.0, 1000.0, 0.1, OriginGroup );
myYOriginSpinBox->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
myYOriginSpinBox->setMinimumWidth( 100 );
myYOriginSpinBox->setValue( 0.0 );
QLabel* ZOriginLabel = new QLabel( tr( "ORIGIN_Z" ), OriginGroup );
- myZOriginSpinBox = new QtxDblSpinBox( -1000.0, 1000.0, 1.0, OriginGroup );
+ myZOriginSpinBox = new QtxDblSpinBox( -1000.0, 1000.0, 0.1, OriginGroup );
myZOriginSpinBox->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
myZOriginSpinBox->setMinimumWidth( 100 );
myZOriginSpinBox->setValue( 0.0 );
OriginGroupLayout->addWidget( myZOriginSpinBox, 0, 5 );
// Direction
- QGroupBox* DirectionGroup = new QGroupBox( tr( "DIRECTION_TITLE" ), SegmentationCursorBox, "DirectionGroup" );
+ QGroupBox* DirectionGroup = new QGroupBox( tr( "DIRECTION_TITLE" ), mySegmentationCursorBox, "DirectionGroup" );
DirectionGroup->setColumnLayout( 0, Qt::Vertical );
DirectionGroup->layout()->setSpacing( 0 );
DirectionGroup->layout()->setMargin( 0 );
DirectionGroupLayout->addWidget( myDZDirectionSpinBox, 0, 5 );
// Depth
- QGroupBox* DepthGroup = new QGroupBox( tr( "DEPTH_TITLE" ), SegmentationCursorBox, "DepthGroup" );
+ QGroupBox* DepthGroup = new QGroupBox( tr( "DEPTH_TITLE" ), mySegmentationCursorBox, "DepthGroup" );
DepthGroup->setColumnLayout( 0, Qt::Vertical );
DepthGroup->layout()->setSpacing( 0 );
DepthGroup->layout()->setMargin( 0 );
DepthGroupLayout->setMargin(11);
QLabel* DepthLabel = new QLabel( tr( "DEPTH" ), DepthGroup );
- myDepthSpinBox = new QtxDblSpinBox( 0.0, 100.0, 1.0, DepthGroup );
+ myDepthSpinBox = new QtxDblSpinBox( 0.0, 100.0, 0.1, DepthGroup );
myDepthSpinBox->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
myDepthSpinBox->setMinimumWidth( 100 );
myDepthSpinBox->setValue( 10.0 );
DepthGroupLayout->addWidget( myDepthSpinBox, 0, 1 );
- TabBox->addTab( SegmentationCursorBox, tr("SEGMENTATION_CURSOR_TAB") );
+ myTabBox->addTab( mySegmentationCursorBox, tr("SEGMENTATION_CURSOR_TAB") );
+
+
+ // Outside cursor pane
+ myOutsideCursorBox = new QVBox( this );
+ myOutsideCursorBox->setMargin(11);
+ myOutsideCursorBox->setSpacing(6);
+
+ // Primitive
+ QGroupBox* PrimitiveGroup = new QGroupBox( tr( "PRIMITIVE_TITLE" ), myOutsideCursorBox, "PrimitiveGroup" );
+ PrimitiveGroup->setColumnLayout(0, Qt::Vertical );
+ PrimitiveGroup->layout()->setSpacing( 0 );
+ PrimitiveGroup->layout()->setMargin( 0 );
+
+ QGridLayout* PrimitiveGroupLayout = new QGridLayout (PrimitiveGroup->layout());
+ PrimitiveGroupLayout->setAlignment(Qt::AlignTop | Qt::AlignCenter);
+ PrimitiveGroupLayout->setSpacing(6);
+ PrimitiveGroupLayout->setMargin(11);
+
+ // Primitive Type
+ QButtonGroup* PrimitiveTypeGroup = new QButtonGroup( 3, Qt::Horizontal, PrimitiveGroup, "PrimitiveTypeGroup" );
+ PrimitiveTypeGroup->setRadioButtonExclusive( true );
+ PrimitiveTypeGroup->setFrameStyle( QFrame::NoFrame );
+ PrimitiveTypeGroup->layout()->setMargin( 0 );
+
+ QRadioButton* PointSpriteButton = new QRadioButton( tr( "POINT_SPRITE" ), PrimitiveTypeGroup );
+ PointSpriteButton->setChecked( true );
+
+ QRadioButton* OpenGLPointButton = new QRadioButton( tr( "OPENGL_POINT" ), PrimitiveTypeGroup );
+ OpenGLPointButton->setEnabled( false );
+
+ QRadioButton* GeometricalSphereButton = new QRadioButton( tr( "GEOMETRICAL_SPHERE" ), PrimitiveTypeGroup );
+ GeometricalSphereButton->setEnabled( false );
+
+ PrimitiveGroupLayout->addMultiCellWidget( PrimitiveTypeGroup, 0, 0, 0, 2 );
+
+ // Clamp
+ QLabel* ClampLabel = new QLabel( tr( "MAXIMUM_SIZE" ), PrimitiveGroup );
+ myClampSpinBox = new QtxDblSpinBox( 1.0, 512.0, 1.0, PrimitiveGroup );
+ myClampSpinBox->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
+
+ PrimitiveGroupLayout->addWidget( ClampLabel, 1, 0 );
+ PrimitiveGroupLayout->addMultiCellWidget( myClampSpinBox, 1, 1, 1, 2 );
+
+ // Main Texture
+ QLabel* MainTextureLabel = new QLabel( tr( "MAIN_TEXTURE" ), PrimitiveGroup );
+ myMainTextureLineEdit = new QLineEdit( PrimitiveGroup );
+ QPushButton* MainTextureButton = new QPushButton( PrimitiveGroup );
+ MainTextureButton->setAutoDefault( false );
+ MainTextureButton->setPixmap( aResourceMgr->loadPixmap( "VISU", tr( "ICON_LOAD_TEXTURE" ) ) );
+ connect( MainTextureButton, SIGNAL( clicked() ), this, SLOT( onBrowseMainTexture() ) );
+
+ PrimitiveGroupLayout->addWidget( MainTextureLabel, 2, 0 );
+ PrimitiveGroupLayout->addWidget( myMainTextureLineEdit, 2, 1 );
+ PrimitiveGroupLayout->addWidget( MainTextureButton, 2, 2 );
+
+ // Alpha Texture
+ QLabel* AlphaTextureLabel = new QLabel( tr( "ALPHA_TEXTURE" ), PrimitiveGroup );
+ myAlphaTextureLineEdit = new QLineEdit( PrimitiveGroup );
+ QPushButton* AlphaTextureButton = new QPushButton( PrimitiveGroup );
+ AlphaTextureButton->setAutoDefault( false );
+ AlphaTextureButton->setPixmap( aResourceMgr->loadPixmap( "VISU", tr( "ICON_LOAD_TEXTURE" ) ) );
+ connect( AlphaTextureButton, SIGNAL( clicked() ), this, SLOT( onBrowseAlphaTexture() ) );
+
+ PrimitiveGroupLayout->addWidget( AlphaTextureLabel, 3, 0 );
+ PrimitiveGroupLayout->addWidget( myAlphaTextureLineEdit, 3, 1 );
+ PrimitiveGroupLayout->addWidget( AlphaTextureButton, 3, 2 );
+
+ // Alpha Threshold
+ QLabel* AlphaThresholdLabel = new QLabel( tr( "ALPHA_THRESHOLD" ), PrimitiveGroup );
+ myAlphaThresholdSpinBox = new QtxDblSpinBox( 0.0, 1.0, 0.1, PrimitiveGroup );
+ myAlphaThresholdSpinBox->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
+
+ PrimitiveGroupLayout->addWidget( AlphaThresholdLabel, 4, 0 );
+ PrimitiveGroupLayout->addMultiCellWidget( myAlphaThresholdSpinBox, 4, 4, 1, 2 );
+
+ // Size
+ QGroupBox* SizeGroup = new QGroupBox ( tr( "SIZE_TITLE" ), myOutsideCursorBox, "SizeGroup" );
+ SizeGroup->setColumnLayout(0, Qt::Vertical );
+ SizeGroup->layout()->setSpacing( 0 );
+ SizeGroup->layout()->setMargin( 0 );
+
+ QGridLayout* SizeGroupLayout = new QGridLayout (SizeGroup->layout());
+ SizeGroupLayout->setAlignment(Qt::AlignTop | Qt::AlignCenter);
+ SizeGroupLayout->setSpacing(6);
+ SizeGroupLayout->setMargin(11);
+
+ // Geometry Size
+ mySizeLabel = new QLabel( tr( "SIZE" ), SizeGroup );
+ mySizeSpinBox = new QtxDblSpinBox( 0, 100, 1, SizeGroup );
+ mySizeSpinBox->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
+
+ SizeGroupLayout->addWidget( mySizeLabel, 0, 0 );
+ SizeGroupLayout->addWidget( mySizeSpinBox, 0, 1 );
+
+ // Color
+ QGroupBox* ColorGroup = new QGroupBox ( tr( "COLOR_TITLE" ), myOutsideCursorBox, "ColorGroup" );
+ ColorGroup->setColumnLayout(0, Qt::Vertical );
+ ColorGroup->layout()->setSpacing( 0 );
+ ColorGroup->layout()->setMargin( 0 );
+
+ QGridLayout* ColorGroupLayout = new QGridLayout (ColorGroup->layout());
+ ColorGroupLayout->setAlignment(Qt::AlignTop | Qt::AlignLeft);
+ ColorGroupLayout->setSpacing(6);
+ ColorGroupLayout->setMargin(11);
+
+ myColorLabel = new QLabel( tr( "COLOR" ), ColorGroup );
+ myColorButton = new QPushButton( ColorGroup );
+ myColorButton->setPaletteBackgroundColor( Qt::blue );
+ myColorButton->setPaletteForegroundColor( Qt::blue );
+
+ ColorGroupLayout->addWidget( myColorLabel, 0, 0 );
+ ColorGroupLayout->addWidget( myColorButton, 0, 1 );
+
+ connect( myColorButton, SIGNAL( clicked() ), this, SLOT( onColorButtonPressed() ) );
+
+
+ myTabBox->addTab( myOutsideCursorBox, tr("OUTSIDE_CURSOR_TAB") );
+ myTabBox->showPage( myOutsideCursorBox );
+
+
// Common buttons ===========================================================
QGroupBox* GroupButtons = new QGroupBox( this, "GroupButtons" );
buttonClose->setAutoDefault( TRUE );
GroupButtonsLayout->addWidget( buttonClose, 0, 2 );
- TopLayout->addWidget( TabBox );
+ TopLayout->addWidget( myTabBox );
TopLayout->addWidget( GroupButtons );
connect( buttonApply, SIGNAL( clicked() ), this, SLOT( onClickApply() ) );
{
}
+void VVTK_SegmentationCursorDlg::AddActor( VISU_GaussPtsAct* theActor )
+{
+ myActorCollection->AddItem( theActor );
+
+ theActor->SetOutsideCursorSettings( myOutsideCursorSettings.GetPointer() );
+}
+
+void VVTK_SegmentationCursorDlg::RemoveActor( VISU_GaussPtsAct* theActor )
+{
+ myActorCollection->RemoveItem( theActor );
+}
+
void VVTK_SegmentationCursorDlg::SetWidget( VISU_ImplicitFunctionWidget* theWidget )
{
myWidget = theWidget;
switch(theEvent){
case vtkCommand::EndInteractionEvent:
- self->OnEndInteractionEvent();
+ self->UpdateSegmentation();
break;
}
}
-void VVTK_SegmentationCursorDlg::OnEndInteractionEvent()
-{
- Update();
-}
-
-void VVTK_SegmentationCursorDlg::Update()
+void VVTK_SegmentationCursorDlg::UpdateSegmentation()
{
float origin[3];
myWidget->GetOrigin( origin );
myDepthSpinBox->setValue( myWidget->Distance() );
}
+void VVTK_SegmentationCursorDlg::onBrowseMainTexture()
+{
+ QString aRootDir = QString( getenv( "VISU_ROOT_DIR") ) + "/share/salome/resources/";
+ QString aFileName = QFileDialog::getOpenFileName( aRootDir, "Bitmap (*.bmp *.jpg *.png)", this );
+
+ if( aFileName.isNull() )
+ return;
+
+ myMainTexture = aFileName;
+ myMainTextureLineEdit->setText( aFileName.section( '/', -1 ) );
+}
+
+void VVTK_SegmentationCursorDlg::onBrowseAlphaTexture()
+{
+ QString aRootDir = QString( getenv( "VISU_ROOT_DIR") ) + "/share/salome/resources/";
+ QString aFileName = QFileDialog::getOpenFileName( aRootDir, "Bitmap (*.bmp *.jpg *.png)", this );
+
+ if( aFileName.isNull() )
+ return;
+
+ myAlphaTexture = aFileName;
+ myAlphaTextureLineEdit->setText( aFileName.section( '/', -1 ) );
+}
+
+void VVTK_SegmentationCursorDlg::onColorButtonPressed()
+{
+ QColor aColor = QColorDialog::getColor( myColorButton->paletteBackgroundColor(), this );
+ if( aColor.isValid() )
+ myColorButton->setPaletteBackgroundColor( aColor );
+}
+
+void VVTK_SegmentationCursorDlg::UpdateOutsideCursor()
+{
+ float aClamp = 200.0;
+ QString aMainTexture = QString( getenv( "VISU_ROOT_DIR") ) + "/share/salome/resources/sprite_texture.bmp";
+ QString anAlphaTexture = QString( getenv( "VISU_ROOT_DIR") ) + "/share/salome/resources/sprite_alpha.bmp";
+ float anAlphaThreshold = 0.1;
+ float aSize = 0.25;
+ QColor aColor = Qt::blue;
+
+ if( !myOutsideCursorSettings->GetInitial() )
+ {
+ myClampSpinBox->setValue( myOutsideCursorSettings->GetClamp() );
+ myMainTextureLineEdit->setText( myMainTexture.section( '/', -1 ) );
+ myAlphaTextureLineEdit->setText( myAlphaTexture.section( '/', -1 ) );
+ myAlphaThresholdSpinBox->setValue( myOutsideCursorSettings->GetAlphaThreshold() );
+ mySizeSpinBox->setValue( myOutsideCursorSettings->GetSize() * 100.0 );
+
+ float* aColor = myOutsideCursorSettings->GetColor();
+ myColorButton->setPaletteBackgroundColor( QColor( ( int )( aColor[0] * 255.0 ),
+ ( int )( aColor[1] * 255.0 ),
+ ( int )( aColor[2] * 255.0 ) ) );
+
+ return;
+ }
+
+ SUIT_ResourceMgr* aResourceMgr = SUIT_Session::session()->resourceMgr();
+
+ aClamp = aResourceMgr->doubleValue( "VISU", "point_sprite_clamp", aClamp );
+ myClampSpinBox->setValue( aClamp );
+
+ myMainTexture = aResourceMgr->stringValue( "VISU", "point_sprite_main_texture", aMainTexture );
+ myMainTextureLineEdit->setText( myMainTexture.section( '/', -1 ) );
+
+ myAlphaTexture = aResourceMgr->stringValue( "VISU", "point_sprite_alpha_texture", anAlphaTexture );
+ myAlphaTextureLineEdit->setText( myAlphaTexture.section( '/', -1 ) );
+
+ anAlphaThreshold = aResourceMgr->doubleValue( "VISU", "point_sprite_alpha_threshold", anAlphaThreshold );
+ myAlphaThresholdSpinBox->setValue( anAlphaThreshold );
+
+ aSize = aResourceMgr->doubleValue( "VISU", "point_sprite_size", aSize );
+ mySizeSpinBox->setValue( aSize * 100.0 );
+
+ aColor = aResourceMgr->colorValue( "VISU", "point_sprite_color", aColor );
+ myColorButton->setPaletteBackgroundColor( aColor );
+
+ ApplyOutsideCursor();
+}
+
+vtkImageData* VVTK_SegmentationCursorDlg::MakeImageData( const QString& theMainTexture,
+ const QString& theAlphaTexture )
+{
+ //bool updateMainTexture = myMainTexture != theMainTexture;
+ //bool updateAlphaTexture = myAlphaTexture != theAlphaTexture;
+ //if( !updateMainTexture && !updateAlphaTexture )
+ // return 0;
+
+ //myMainTexture = theMainTexture;
+ //myAlphaTexture = 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());
+}
+
void VVTK_SegmentationCursorDlg::onClickApply()
+{
+ if( myTabBox->currentPage() == mySegmentationCursorBox )
+ ApplySegmentationCursor();
+ else
+ ApplyOutsideCursor();
+}
+
+void VVTK_SegmentationCursorDlg::ApplySegmentationCursor()
{
float origin[3];
origin[0] = myXOriginSpinBox->value();
myWidget->SetDistance( myDepthSpinBox->value() );
- myWidget->UpdatePlacement();
-
+ myWidget->InvokeEvent(vtkCommand::EndInteractionEvent,NULL);
myWidget->GetInteractor()->Render();
}
+void VVTK_SegmentationCursorDlg::ApplyOutsideCursor()
+{
+ vtkImageData* aTexture = this->MakeImageData( myMainTexture, myAlphaTexture );
+
+ myOutsideCursorSettings->SetInitial( false );
+ myOutsideCursorSettings->SetClamp( myClampSpinBox->value() );
+ myOutsideCursorSettings->SetTexture( aTexture );
+ myOutsideCursorSettings->SetAlphaThreshold( myAlphaThresholdSpinBox->value() );
+ myOutsideCursorSettings->SetSize( mySizeSpinBox->value() / 100.0 );
+
+ QColor aButtonColor = myColorButton->paletteBackgroundColor();
+ float aColor[3];
+ aColor[0] = aButtonColor.red() / 255.0;
+ aColor[1] = aButtonColor.green() / 255.0;
+ aColor[2] = aButtonColor.blue() / 255.0;
+ myOutsideCursorSettings->SetColor( aColor );
+
+ vtkActor* anActor;
+ for( myActorCollection->InitTraversal(); ( anActor = myActorCollection->GetNextActor() ) != 0; )
+ {
+ VISU_GaussPtsAct* aGPActor = dynamic_cast<VISU_GaussPtsAct*>( anActor );
+ if( aGPActor )
+ aGPActor->UpdateOutsideCursorSettings();
+ }
+}
+
void VVTK_SegmentationCursorDlg::onClickClose()
{
+ myAction->setOn( false );
+
reject();
+}
+void VVTK_SegmentationCursorDlg::closeEvent( QCloseEvent* )
+{
myAction->setOn( false );
}