1 // VISU VISUGUI : GUI of VISU component
3 // Copyright (C) 2003 CEA/DEN, EDF R&D
7 // File : VVTK_SegmentationCursorDlg.cxx
8 // Author : Oleg Uvarov
11 #include "VVTK_SegmentationCursorDlg.h"
12 #include "VVTK_PrimitiveBox.h"
13 #include "VVTK_SizeBox.h"
15 #include "VISU_GaussPtsAct.h"
16 #include "VISU_GaussPtsSettings.h"
18 #include "VISU_WidgetCtrl.hxx"
19 #include "VISU_PlanesWidget.hxx"
20 #include "VISU_SphereWidget.hxx"
22 #include "VISU_GaussPointsPL.hxx"
23 #include "VISU_OpenGLPointSpriteMapper.hxx"
25 #include "LightApp_Application.h"
26 #include "SUIT_MessageBox.h"
27 #include "SUIT_ResourceMgr.h"
28 #include "SUIT_Session.h"
30 #include "SVTK_RenderWindowInteractor.h"
32 #include <vtkActorCollection.h>
33 #include <vtkCallbackCommand.h>
34 #include <vtkObjectFactory.h>
35 #include <vtkRenderer.h>
36 #include <vtkRenderWindowInteractor.h>
37 #include <vtkSmartPointer.h>
38 #include <vtkImageData.h>
40 #include "utilities.h"
42 #include <qbuttongroup.h>
43 #include <qcolordialog.h>
44 #include <qfiledialog.h>
45 #include <qgroupbox.h>
48 #include <qlineedit.h>
49 #include <qpushbutton.h>
50 #include <qradiobutton.h>
51 #include <qtabwidget.h>
54 #include "QtxAction.h"
55 #include "QtxDblSpinBox.h"
56 #include "QtxIntSpinBox.h"
61 //----------------------------------------------------------------
66 Image2VTI(const QString& theImageFileName)
68 QFileInfo aFileInfo(theImageFileName);
69 QString aFormat = aFileInfo.extension(FALSE);
70 QString aVTIName = QString("/tmp/") + getenv("USER") + "-" + aFileInfo.baseName(TRUE) + ".vti";
71 QString aCommand = QString( "VISU_img2vti " ) + aFormat + " " + theImageFileName + " " + aVTIName;
73 if(system( aCommand.latin1() ) == 0)
81 RemoveFile(const QString& theFileName)
83 if( !theFileName.isNull() ){
84 QString aCommand = QString( "rm -fr " ) + theFileName;
85 system( aCommand.latin1() );
91 GetTexture(const QString& theMainTexture,
92 const QString& theAlphaTexture)
94 typedef std::pair<std::string,std::string> TTextureKey;
95 typedef std::map<TTextureKey,TTextureValue> TTextureMap;
97 static TTextureMap aTextureMap;
99 TTextureValue aTextureValue;
100 TTextureKey aTextureKey(theMainTexture.latin1(),theAlphaTexture.latin1());
101 TTextureMap::const_iterator anIter = aTextureMap.find(aTextureKey);
102 if(anIter != aTextureMap.end()){
103 aTextureValue = anIter->second;
105 QString aMainTextureVTI = Image2VTI(theMainTexture);
106 QString anAlphaTextureVTI = Image2VTI(theAlphaTexture);
108 if( !aMainTextureVTI.isNull() && !anAlphaTextureVTI.isNull() ){
110 VISU_GaussPointsPL::MakeTexture( aMainTextureVTI.latin1(),
111 anAlphaTextureVTI.latin1());
113 if( aTextureValue.GetPointer() )
114 aTextureMap[aTextureKey] = aTextureValue;
117 RemoveFile(aMainTextureVTI);
118 RemoveFile(anAlphaTextureVTI);
121 return aTextureValue;
126 //----------------------------------------------------------------
127 VVTK_SegmentationCursorDlg::VVTK_SegmentationCursorDlg( QWidget* parent, const char* name )
128 :QDialog( parent, name, false, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu ),
129 myEventCallbackCommand( vtkCallbackCommand::New() ),
130 myInsideCursorSettings( VISU_InsideCursorSettings::New() ),
131 myOutsideCursorSettings( VISU_OutsideCursorSettings::New() ),
132 myIsPlaneSegmentation( true ),
137 myEventCallbackCommand->Delete();
138 myEventCallbackCommand->SetClientData(this);
139 myEventCallbackCommand->SetCallback(VVTK_SegmentationCursorDlg::ProcessEvents);
141 myInsideCursorSettings->AddObserver(VISU::UpdateFromSettingsEvent,
142 myEventCallbackCommand.GetPointer(),
145 setCaption( tr( "SEGMENTATION_CURSOR_DLG_TITLE" ) );
146 setSizeGripEnabled(TRUE);
148 QVBoxLayout* TopLayout = new QVBoxLayout( this );
149 TopLayout->setSpacing(6);
150 TopLayout->setMargin(11);
152 myTabBox = new QTabWidget( this );
154 // Segmentation cursor pane
155 mySegmentationCursorBox = new QVBox( this );
156 mySegmentationCursorBox->setMargin(11);
157 mySegmentationCursorBox->setSpacing(6);
158 mySegmentationCursorBox->layout()->setAlignment(Qt::AlignTop);
161 myOriginGroup = new QGroupBox( tr( "ORIGIN_TITLE" ), mySegmentationCursorBox, "OriginGroup" );
162 myOriginGroup->setColumnLayout( 0, Qt::Vertical );
163 myOriginGroup->layout()->setSpacing( 0 );
164 myOriginGroup->layout()->setMargin( 0 );
166 QGridLayout* OriginGroupLayout = new QGridLayout( myOriginGroup->layout() );
167 OriginGroupLayout->setAlignment(Qt::AlignTop | Qt::AlignCenter);
168 OriginGroupLayout->setSpacing(6);
169 OriginGroupLayout->setMargin(11);
171 QLabel* XOriginLabel = new QLabel( tr( "ORIGIN_X" ), myOriginGroup );
172 myXOriginSpinBox = new QtxDblSpinBox( -1000.0, 1000.0, 0.1, myOriginGroup );
173 myXOriginSpinBox->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
174 myXOriginSpinBox->setMinimumWidth( 100 );
175 myXOriginSpinBox->setValue( 0.0 );
177 QLabel* YOriginLabel = new QLabel( tr( "ORIGIN_Y" ), myOriginGroup );
178 myYOriginSpinBox = new QtxDblSpinBox( -1000.0, 1000.0, 0.1, myOriginGroup );
179 myYOriginSpinBox->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
180 myYOriginSpinBox->setMinimumWidth( 100 );
181 myYOriginSpinBox->setValue( 0.0 );
183 QLabel* ZOriginLabel = new QLabel( tr( "ORIGIN_Z" ), myOriginGroup );
184 myZOriginSpinBox = new QtxDblSpinBox( -1000.0, 1000.0, 0.1, myOriginGroup );
185 //myZOriginSpinBox->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
186 myZOriginSpinBox->setMinimumWidth( 100 );
187 myZOriginSpinBox->setValue( 1.0 );
189 OriginGroupLayout->addWidget( XOriginLabel, 0, 0 );
190 OriginGroupLayout->addWidget( myXOriginSpinBox, 0, 1 );
191 OriginGroupLayout->addWidget( YOriginLabel, 0, 2 );
192 OriginGroupLayout->addWidget( myYOriginSpinBox, 0, 3 );
193 OriginGroupLayout->addWidget( ZOriginLabel, 0, 4 );
194 OriginGroupLayout->addWidget( myZOriginSpinBox, 0, 5 );
196 // Direction ( Plane Segmentation )
197 myDirectionGroup = new QGroupBox( tr( "DIRECTION_TITLE" ), mySegmentationCursorBox, "DirectionGroup" );
198 myDirectionGroup->setColumnLayout( 0, Qt::Vertical );
199 myDirectionGroup->layout()->setSpacing( 0 );
200 myDirectionGroup->layout()->setMargin( 0 );
202 QGridLayout* DirectionGroupLayout = new QGridLayout( myDirectionGroup->layout() );
203 DirectionGroupLayout->setAlignment(Qt::AlignTop | Qt::AlignCenter);
204 DirectionGroupLayout->setSpacing(6);
205 DirectionGroupLayout->setMargin(11);
207 QLabel* DXDirectionLabel = new QLabel( tr( "DIRECTION_DX" ), myDirectionGroup );
208 myDXDirectionSpinBox = new QtxDblSpinBox( -1.0, 1.0, 0.1, myDirectionGroup );
209 myDXDirectionSpinBox->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
210 myDXDirectionSpinBox->setMinimumWidth( 100 );
211 myDXDirectionSpinBox->setValue( 0.0 );
213 QLabel* DYDirectionLabel = new QLabel( tr( "DIRECTION_DY" ), myDirectionGroup );
214 myDYDirectionSpinBox = new QtxDblSpinBox( -1.0, 1.0, 0.1, myDirectionGroup );
215 myDYDirectionSpinBox->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
216 myDYDirectionSpinBox->setMinimumWidth( 100 );
217 myDYDirectionSpinBox->setValue( 0.0 );
219 QLabel* DZDirectionLabel = new QLabel( tr( "DIRECTION_DZ" ), myDirectionGroup );
220 myDZDirectionSpinBox = new QtxDblSpinBox( -1.0, 1.0, 0.1, myDirectionGroup );
221 myDZDirectionSpinBox->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
222 myDZDirectionSpinBox->setMinimumWidth( 100 );
223 myDZDirectionSpinBox->setValue( 1.0 );
225 DirectionGroupLayout->addWidget( DXDirectionLabel, 0, 0 );
226 DirectionGroupLayout->addWidget( myDXDirectionSpinBox, 0, 1 );
227 DirectionGroupLayout->addWidget( DYDirectionLabel, 0, 2 );
228 DirectionGroupLayout->addWidget( myDYDirectionSpinBox, 0, 3 );
229 DirectionGroupLayout->addWidget( DZDirectionLabel, 0, 4 );
230 DirectionGroupLayout->addWidget( myDZDirectionSpinBox, 0, 5 );
232 // Depth ( Plane Segmentation )
233 myDepthGroup = new QGroupBox( tr( "DEPTH_TITLE" ), mySegmentationCursorBox, "DepthGroup" );
234 myDepthGroup->setColumnLayout( 0, Qt::Vertical );
235 myDepthGroup->layout()->setSpacing( 0 );
236 myDepthGroup->layout()->setMargin( 0 );
238 QGridLayout* DepthGroupLayout = new QGridLayout( myDepthGroup->layout() );
239 DepthGroupLayout->setAlignment(Qt::AlignTop | Qt::AlignCenter);
240 DepthGroupLayout->setSpacing(6);
241 DepthGroupLayout->setMargin(11);
243 QLabel* DepthLabel = new QLabel( tr( "DEPTH" ), myDepthGroup );
244 myDepthSpinBox = new QtxDblSpinBox( 0.0, VTK_LARGE_FLOAT, 0.1, myDepthGroup );
245 myDepthSpinBox->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
246 myDepthSpinBox->setMinimumWidth( 100 );
247 myDepthSpinBox->setValue( 1.0 );
249 DepthGroupLayout->addWidget( DepthLabel, 0, 0 );
250 DepthGroupLayout->addWidget( myDepthSpinBox, 0, 1 );
252 // Radius ( Sphere Segmentation )
253 myRadiusGroup = new QGroupBox( tr( "RADIUS_TITLE" ), mySegmentationCursorBox, "RadiusGroup" );
254 myRadiusGroup->setColumnLayout( 0, Qt::Vertical );
255 myRadiusGroup->layout()->setSpacing( 0 );
256 myRadiusGroup->layout()->setMargin( 0 );
258 QGridLayout* RadiusGroupLayout = new QGridLayout( myRadiusGroup->layout() );
259 RadiusGroupLayout->setAlignment(Qt::AlignTop | Qt::AlignCenter);
260 RadiusGroupLayout->setSpacing(6);
261 RadiusGroupLayout->setMargin(11);
263 QLabel* RadiusLabel = new QLabel( tr( "RADIUS" ),myRadiusGroup );
264 myRadiusSpinBox = new QtxDblSpinBox( 0.0, 1000.0, 1.0,myRadiusGroup );
265 myRadiusSpinBox->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
266 myRadiusSpinBox->setMinimumWidth( 100 );
267 myRadiusSpinBox->setValue( 100.0 );
269 QLabel* RatioLabel = new QLabel( tr( "RATIO" ), myRadiusGroup );
270 myRatioSpinBox = new QtxDblSpinBox( 0.1, 10.0, 0.1,myRadiusGroup );
271 myRatioSpinBox->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
272 myRatioSpinBox->setMinimumWidth( 100 );
273 myRatioSpinBox->setValue( 2.0 );
275 RadiusGroupLayout->addWidget( RadiusLabel, 0, 0 );
276 RadiusGroupLayout->addWidget( myRadiusSpinBox, 0, 1 );
277 RadiusGroupLayout->addWidget( RatioLabel, 0, 2 );
278 RadiusGroupLayout->addWidget( myRatioSpinBox, 0, 3 );
281 myTabBox->addTab( mySegmentationCursorBox, tr( "SEGMENTATION_CURSOR_TAB" ) );
285 myGaussPointsBox = new QVBox( this );
286 myGaussPointsBox->setMargin(11);
287 myGaussPointsBox->setSpacing(6);
289 // Inside Gauss points
290 QGroupBox* anInsideGroup = new QGroupBox( tr( "INSIDE_GAUSS_POINTS" ), myGaussPointsBox );
291 anInsideGroup->setColumnLayout( 0, Qt::Vertical );
292 anInsideGroup->layout()->setSpacing( 0 );
293 anInsideGroup->layout()->setMargin( 0 );
295 QGridLayout* anInsideGroupLayout = new QGridLayout( anInsideGroup->layout() );
296 anInsideGroupLayout->setAlignment(Qt::AlignTop | Qt::AlignCenter);
297 anInsideGroupLayout->setSpacing(6);
298 anInsideGroupLayout->setMargin(11);
301 myInsidePrimitiveBox = new VVTK_PrimitiveBox( anInsideGroup );
304 myInsideSizeBox = new VVTK_SizeBox( anInsideGroup );
305 myInsideSizeBox->setType( VVTK_SizeBox::Inside );
307 anInsideGroupLayout->addWidget( myInsidePrimitiveBox, 0, 0 );
308 anInsideGroupLayout->addWidget( myInsideSizeBox, 1, 0 );
310 // Outside Gauss points
311 QGroupBox* anOutsideGroup = new QGroupBox( tr( "OUTSIDE_GAUSS_POINTS" ), myGaussPointsBox );
312 anOutsideGroup->setColumnLayout( 0, Qt::Vertical );
313 anOutsideGroup->layout()->setSpacing( 0 );
314 anOutsideGroup->layout()->setMargin( 0 );
316 QGridLayout* anOutsideGroupLayout = new QGridLayout( anOutsideGroup->layout() );
317 anOutsideGroupLayout->setAlignment(Qt::AlignTop | Qt::AlignCenter);
318 anOutsideGroupLayout->setSpacing(6);
319 anOutsideGroupLayout->setMargin(11);
322 myOutsidePrimitiveBox = new VVTK_PrimitiveBox( anOutsideGroup );
325 myOutsideSizeBox = new VVTK_SizeBox( anOutsideGroup );
326 myOutsideSizeBox->setType( VVTK_SizeBox::Outside );
328 anOutsideGroupLayout->addWidget( myOutsidePrimitiveBox, 0, 0 );
329 anOutsideGroupLayout->addWidget( myOutsideSizeBox, 1, 0 );
333 QGroupBox* MagnificationGroup = new QGroupBox ( tr( "MAGNIFICATION_TITLE" ), myGaussPointsBox, "MagnificationGroup" );
334 MagnificationGroup->setColumnLayout(0, Qt::Vertical );
335 MagnificationGroup->layout()->setSpacing( 0 );
336 MagnificationGroup->layout()->setMargin( 0 );
338 QGridLayout* MagnificationGroupLayout = new QGridLayout (MagnificationGroup->layout());
339 MagnificationGroupLayout->setAlignment(Qt::AlignTop | Qt::AlignCenter);
340 MagnificationGroupLayout->setSpacing(6);
341 MagnificationGroupLayout->setMargin(11);
343 myMagnificationLabel = new QLabel( tr( "MAGNIFICATION" ), MagnificationGroup );
344 myMagnificationSpinBox = new QtxIntSpinBox( 1, 10000, 10, MagnificationGroup );
345 myMagnificationSpinBox->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
347 MagnificationGroupLayout->addWidget( myMagnificationLabel, 0, 0 );
348 MagnificationGroupLayout->addWidget( myMagnificationSpinBox, 0, 1 );
351 myIncrementLabel = new QLabel( tr( "INCREMENT" ), MagnificationGroup );
352 myIncrementSpinBox = new QtxDblSpinBox( 0.01, 10, 0.1, MagnificationGroup );
353 myIncrementSpinBox->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
355 MagnificationGroupLayout->addWidget( myIncrementLabel, 0, 2 );
356 MagnificationGroupLayout->addWidget( myIncrementSpinBox, 0, 3 );
359 myTabBox->addTab( myGaussPointsBox, tr( "GAUSS_POINTS_TAB" ) );
360 myTabBox->showPage( myGaussPointsBox );
363 // Common buttons ===========================================================
364 QGroupBox* GroupButtons = new QGroupBox( this, "GroupButtons" );
365 GroupButtons->setColumnLayout(0, Qt::Vertical );
366 GroupButtons->layout()->setSpacing( 0 );
367 GroupButtons->layout()->setMargin( 0 );
368 QGridLayout* GroupButtonsLayout = new QGridLayout( GroupButtons->layout() );
369 GroupButtonsLayout->setAlignment( Qt::AlignTop );
370 GroupButtonsLayout->setSpacing( 6 );
371 GroupButtonsLayout->setMargin( 11 );
373 QPushButton* buttonApply = new QPushButton( tr( "&Apply" ), GroupButtons, "buttonApply" );
374 buttonApply->setAutoDefault( TRUE );
375 buttonApply->setDefault( TRUE );
376 GroupButtonsLayout->addWidget( buttonApply, 0, 0 );
377 GroupButtonsLayout->addItem( new QSpacerItem( 5, 5, QSizePolicy::Expanding, QSizePolicy::Minimum ), 0, 1 );
379 QPushButton* buttonClose = new QPushButton( tr( "&Close" ) , GroupButtons, "buttonClose" );
380 buttonClose->setAutoDefault( TRUE );
381 GroupButtonsLayout->addWidget( buttonClose, 0, 2 );
383 QPushButton* buttonHelp = new QPushButton( tr( "&Help" ) , GroupButtons, "buttonHelp" );
384 buttonHelp->setAutoDefault( TRUE );
385 GroupButtonsLayout->addWidget( buttonHelp, 0, 3 );
387 TopLayout->addWidget( myTabBox );
388 TopLayout->addWidget( GroupButtons );
390 connect( buttonApply, SIGNAL( clicked() ), this, SLOT( onClickApply() ) );
391 connect( buttonClose, SIGNAL( clicked() ), this, SLOT( onClickClose() ) );
392 connect( buttonHelp, SIGNAL( clicked() ), this, SLOT( onClickHelp() ) );
394 connect(parent, SIGNAL(Show( QShowEvent * )), this, SLOT(onParentShow()));
395 connect(parent, SIGNAL(Hide( QHideEvent * )), this, SLOT(onParentHide()));
398 VVTK_SegmentationCursorDlg::~VVTK_SegmentationCursorDlg()
403 float VVTK_SegmentationCursorDlg::getMagnification() const
405 return myMagnificationSpinBox->value() / 100.0;
408 void VVTK_SegmentationCursorDlg::setMagnification( float theMagnification )
410 myMagnificationSpinBox->setValue( ( int )( theMagnification * 100 ) );
413 float VVTK_SegmentationCursorDlg::getIncrement() const
415 return myIncrementSpinBox->value();
418 void VVTK_SegmentationCursorDlg::setIncrement( float theIncrement )
420 myIncrementSpinBox->setValue( theIncrement );
424 void VVTK_SegmentationCursorDlg::SetWidgetCtrl( VISU_WidgetCtrl* theWidgetCtrl )
426 if(myWidgetCtrl == theWidgetCtrl)
430 myWidgetCtrl->RemoveObserver(myEventCallbackCommand.GetPointer());
432 myWidgetCtrl = theWidgetCtrl;
435 theWidgetCtrl->AddObserver(vtkCommand::EndInteractionEvent,
436 myEventCallbackCommand.GetPointer(),
440 void VVTK_SegmentationCursorDlg::ProcessEvents(vtkObject* vtkNotUsed(theObject),
441 unsigned long theEvent,
443 void* vtkNotUsed(theCallData))
445 VVTK_SegmentationCursorDlg* self = reinterpret_cast<VVTK_SegmentationCursorDlg*>(theClientData);
448 case vtkCommand::EndInteractionEvent:
449 self->UpdateSegmentation();
451 case VISU::UpdateFromSettingsEvent:
452 self->GetOutsideCursorSettings()->SetMagnification( self->GetInsideCursorSettings()->GetMagnification() );
453 self->GetOutsideCursorSettings()->SetIncrement( self->GetInsideCursorSettings()->GetIncrement() );
455 self->UpdateInsideGaussPoints();
456 self->UpdateOutsideGaussPoints();
458 self->GetInsideCursorSettings()->InvokeEvent(VISU::UpdateInsideSettingsEvent,NULL);
459 self->GetOutsideCursorSettings()->InvokeEvent(VISU::UpdateOutsideSettingsEvent,NULL);
464 void VVTK_SegmentationCursorDlg::UpdateSegmentation()
466 if( myIsPlaneSegmentation )
468 myDirectionGroup->show();
469 myDepthGroup->show();
470 myRadiusGroup->hide();
472 VISU_PlanesWidget *pPlanesWidget=myWidgetCtrl->GetPlanesWidget();
473 vtkFloatingPointType origin[3];
474 pPlanesWidget->GetOrigin( origin );
475 myXOriginSpinBox->setValue( origin[0] );
476 myYOriginSpinBox->setValue( origin[1] );
477 myZOriginSpinBox->setValue( origin[2] );
479 vtkFloatingPointType normal[3];
480 pPlanesWidget->GetNormal( normal );
481 myDXDirectionSpinBox->setValue( normal[0] );
482 myDYDirectionSpinBox->setValue( normal[1] );
483 myDZDirectionSpinBox->setValue( normal[2] );
485 myDepthSpinBox->setValue( pPlanesWidget->Distance() );
489 myDirectionGroup->hide();
490 myDepthGroup->hide();
491 myRadiusGroup->show();
493 VISU_SphereWidget *pSphereWidget=myWidgetCtrl->GetSphereWidget();
494 vtkFloatingPointType origin[3], aRadius;
495 pSphereWidget->GetCenter(origin);
496 myXOriginSpinBox->setValue( origin[0] );
497 myYOriginSpinBox->setValue( origin[1] );
498 myZOriginSpinBox->setValue( origin[2] );
499 aRadius=pSphereWidget->GetRadius();
500 myRadiusSpinBox->setValue(aRadius);
501 myRatioSpinBox->setValue(pSphereWidget->GetRatio());
505 void VVTK_SegmentationCursorDlg::UpdateInsideGaussPoints()
507 int aPrimitiveType = VISU_OpenGLPointSpriteMapper::PointSprite;
508 vtkFloatingPointType aClamp = 200.0;
509 QString aMainTexture = QString( getenv( "VISU_ROOT_DIR") ) + "/share/salome/resources/sprite_texture.bmp";
510 QString anAlphaTexture = QString( getenv( "VISU_ROOT_DIR") ) + "/share/salome/resources/sprite_alpha.bmp";
511 vtkFloatingPointType anAlphaThreshold = 0.1;
515 int aMagnification = 100;
516 vtkFloatingPointType anIncrement = 2.0;
518 if( !myInsideCursorSettings->GetInitial() )
520 myInsidePrimitiveBox->setPrimitiveType( myInsideCursorSettings->GetPrimitiveType() );
521 myInsidePrimitiveBox->setClamp( myInsideCursorSettings->GetClamp() );
522 myInsidePrimitiveBox->setMainTexture( myInsideMainTexture );
523 myInsidePrimitiveBox->setAlphaTexture( myInsideAlphaTexture );
524 myInsidePrimitiveBox->setAlphaThreshold( myInsideCursorSettings->GetAlphaThreshold() );
525 myInsidePrimitiveBox->setResolution( myInsideCursorSettings->GetResolution() );
527 myInsideSizeBox->setMinSize( myInsideCursorSettings->GetMinSize() );
528 myInsideSizeBox->setMaxSize( myInsideCursorSettings->GetMaxSize() );
530 this->setMagnification( myInsideCursorSettings->GetMagnification() );
531 this->setIncrement( myInsideCursorSettings->GetIncrement() );
536 SUIT_ResourceMgr* aResourceMgr = SUIT_Session::session()->resourceMgr();
538 aPrimitiveType = aResourceMgr->integerValue( "VISU", "inside_point_sprite_primitive_type", aPrimitiveType );
539 myInsidePrimitiveBox->setPrimitiveType( aPrimitiveType );
541 aClamp = aResourceMgr->doubleValue( "VISU", "inside_point_sprite_clamp", aClamp );
542 myInsidePrimitiveBox->setClamp( aClamp );
544 aMainTexture = aResourceMgr->stringValue( "VISU", "inside_point_sprite_main_texture", aMainTexture );
545 myInsidePrimitiveBox->setMainTexture( aMainTexture );
547 anAlphaTexture = aResourceMgr->stringValue( "VISU", "inside_point_sprite_alpha_texture", anAlphaTexture );
548 myInsidePrimitiveBox->setAlphaTexture( anAlphaTexture );
550 anAlphaThreshold = aResourceMgr->doubleValue( "VISU", "inside_point_sprite_alpha_threshold", anAlphaThreshold );
551 myInsidePrimitiveBox->setAlphaThreshold( anAlphaThreshold );
553 aResolution = aResourceMgr->integerValue( "VISU", "inside_geom_sphere_resolution", aResolution );
554 myInsidePrimitiveBox->setResolution( aResolution );
556 aMinSize = aResourceMgr->integerValue( "VISU", "inside_point_sprite_min_size", aMinSize );
557 myInsideSizeBox->setMinSize( aMinSize / 100.0 );
559 aMaxSize = aResourceMgr->integerValue( "VISU", "inside_point_sprite_max_size", aMaxSize );
560 myInsideSizeBox->setMaxSize( aMaxSize / 100.0 );
562 aMagnification = aResourceMgr->integerValue( "VISU", "inside_point_sprite_magnification", aMagnification );
563 this->setMagnification( aMagnification / 100.0 );
565 anIncrement = aResourceMgr->doubleValue( "VISU", "inside_point_sprite_increment", anIncrement );
566 this->setIncrement( anIncrement );
568 myInsidePrimitiveBox->setFaceLimit( 50000 );
570 ApplyInsideGaussPoints();
573 void VVTK_SegmentationCursorDlg::UpdateOutsideGaussPoints()
575 vtkFloatingPointType aClamp = 256.0;
576 int aPrimitiveType = VISU_OpenGLPointSpriteMapper::PointSprite;
577 QString aMainTexture = QString( getenv( "VISU_ROOT_DIR") ) + "/share/salome/resources/sprite_texture.bmp";
578 QString anAlphaTexture = QString( getenv( "VISU_ROOT_DIR") ) + "/share/salome/resources/sprite_alpha.bmp";
579 vtkFloatingPointType anAlphaThreshold = 0.1;
582 bool aUniform = false;
583 QColor aColor = Qt::blue;
585 if( !myOutsideCursorSettings->GetInitial() )
587 myOutsidePrimitiveBox->setPrimitiveType( myOutsideCursorSettings->GetPrimitiveType() );
588 myOutsidePrimitiveBox->setClamp( myOutsideCursorSettings->GetClamp() );
589 myOutsidePrimitiveBox->setMainTexture( myOutsideMainTexture );
590 myOutsidePrimitiveBox->setAlphaTexture( myOutsideAlphaTexture );
591 myOutsidePrimitiveBox->setAlphaThreshold( myOutsideCursorSettings->GetAlphaThreshold() );
592 myOutsidePrimitiveBox->setResolution( myOutsideCursorSettings->GetResolution() );
594 myOutsideSizeBox->setOutsideSize( myOutsideCursorSettings->GetSize() );
595 myOutsideSizeBox->setUniform( myOutsideCursorSettings->GetUniform() );
597 vtkFloatingPointType* aColor = myOutsideCursorSettings->GetColor();
598 myOutsideSizeBox->setColor( QColor( ( int )( aColor[0] * 255.0 ),
599 ( int )( aColor[1] * 255.0 ),
600 ( int )( aColor[2] * 255.0 ) ) );
605 SUIT_ResourceMgr* aResourceMgr = SUIT_Session::session()->resourceMgr();
607 aPrimitiveType = aResourceMgr->integerValue( "VISU", "outside_point_sprite_primitive_type", aPrimitiveType );
608 myOutsidePrimitiveBox->setPrimitiveType( aPrimitiveType );
610 aClamp = aResourceMgr->doubleValue( "VISU", "outside_point_sprite_clamp", aClamp );
611 myOutsidePrimitiveBox->setClamp( aClamp );
613 aMainTexture = aResourceMgr->stringValue( "VISU", "outside_point_sprite_main_texture", aMainTexture );
614 myOutsidePrimitiveBox->setMainTexture( aMainTexture );
616 anAlphaTexture = aResourceMgr->stringValue( "VISU", "outside_point_sprite_alpha_texture", anAlphaTexture );
617 myOutsidePrimitiveBox->setAlphaTexture( anAlphaTexture );
619 anAlphaThreshold = aResourceMgr->doubleValue( "VISU", "outside_point_sprite_alpha_threshold", anAlphaThreshold );
620 myOutsidePrimitiveBox->setAlphaThreshold( anAlphaThreshold );
622 aResolution = aResourceMgr->integerValue( "VISU", "outside_geom_sphere_resolution", aResolution );
623 myOutsidePrimitiveBox->setResolution( aResolution );
625 aSize = aResourceMgr->integerValue( "VISU", "outside_point_sprite_size", aSize );
626 myOutsideSizeBox->setOutsideSize( aSize / 100.0 );
628 aUniform = aResourceMgr->booleanValue( "VISU", "outside_point_sprite_uniform", aUniform );
629 myOutsideSizeBox->setUniform( aUniform );
631 aColor = aResourceMgr->colorValue( "VISU", "outside_point_sprite_color", aColor );
632 myOutsideSizeBox->setColor( aColor );
634 myOutsidePrimitiveBox->setFaceLimit( 50000 );
636 ApplyOutsideGaussPoints();
639 VISU_InsideCursorSettings* VVTK_SegmentationCursorDlg::GetInsideCursorSettings()
641 return myInsideCursorSettings.GetPointer();
644 VISU_OutsideCursorSettings* VVTK_SegmentationCursorDlg::GetOutsideCursorSettings()
646 return myOutsideCursorSettings.GetPointer();
650 VVTK_SegmentationCursorDlg
651 ::MakeImageData( bool theInside,
652 const QString& theMainTexture,
653 const QString& theAlphaTexture )
657 bool updateMainTexture = myInsideMainTexture != theMainTexture;
658 bool updateAlphaTexture = myInsideAlphaTexture != theAlphaTexture;
659 if( !updateMainTexture && !updateAlphaTexture )
662 myInsideMainTexture = theMainTexture;
663 myInsideAlphaTexture = theAlphaTexture;
667 bool updateMainTexture = myOutsideMainTexture != theMainTexture;
668 bool updateAlphaTexture = myOutsideAlphaTexture != theAlphaTexture;
669 if( !updateMainTexture && !updateAlphaTexture )
672 myOutsideMainTexture = theMainTexture;
673 myOutsideAlphaTexture = theAlphaTexture;
676 return VISU::GetTexture( theMainTexture.latin1(),
677 theAlphaTexture.latin1());
680 void VVTK_SegmentationCursorDlg::onClickApply()
682 if( myTabBox->currentPage() == mySegmentationCursorBox )
683 ApplySegmentationCursor();
686 QString aWarning = "The number of faces needed to perform the 'Geometrical Sphere' primitive\n";
687 aWarning.append( "presentation might be too important to ensure an acceptable frame rate.\n\n" );
688 aWarning.append( "Can you please confirm that you want to continue anyway?" );
689 bool toApply = CheckNumberOfFaces() ||
690 SUIT_MessageBox::warn2( this, tr( "Warning" ), aWarning,
691 tr( "&OK" ), tr( "&Cancel" ), 0, 1, 1 ) == 0;
695 ApplyInsideGaussPoints();
696 ApplyOutsideGaussPoints();
701 void VVTK_SegmentationCursorDlg::ApplySegmentationCursor()
703 if( myIsPlaneSegmentation )
705 VISU_PlanesWidget *pPlanesWidget=myWidgetCtrl->GetPlanesWidget();
706 vtkFloatingPointType origin[3];
707 origin[0] = myXOriginSpinBox->value();
708 origin[1] = myYOriginSpinBox->value();
709 origin[2] = myZOriginSpinBox->value();
710 pPlanesWidget->SetOrigin( origin );
712 vtkFloatingPointType normal[3];
713 normal[0] = myDXDirectionSpinBox->value();
714 normal[1] = myDYDirectionSpinBox->value();
715 normal[2] = myDZDirectionSpinBox->value();
717 if( normal[0] == 0.0 && normal[1] == 0.0 && normal[2] == 0.0 )
720 myDZDirectionSpinBox->setValue( 1.0 );
722 pPlanesWidget->SetNormal( normal );
724 pPlanesWidget->SetDistance( myDepthSpinBox->value() );
726 myWidgetCtrl->InvokeEvent(vtkCommand::EndInteractionEvent,NULL);
727 myWidgetCtrl->GetInteractor()->Render();
731 VISU_SphereWidget *pSphereWidget=myWidgetCtrl->GetSphereWidget();
732 vtkFloatingPointType origin[3], aRadius;
733 origin[0] = myXOriginSpinBox->value();
734 origin[1] = myYOriginSpinBox->value();
735 origin[2] = myZOriginSpinBox->value();
736 pSphereWidget->SetCenter(origin);
738 aRadius=myRadiusSpinBox->value();
739 pSphereWidget->SetRadius(aRadius);
741 pSphereWidget->SetRatio(myRatioSpinBox->value());
743 myWidgetCtrl->InvokeEvent(vtkCommand::EndInteractionEvent,NULL);
744 myWidgetCtrl->GetInteractor()->Render();
748 void VVTK_SegmentationCursorDlg::ApplyInsideGaussPoints()
750 QString anInsideMainTexture = myInsidePrimitiveBox->getMainTexture();
751 QString anInsideAlphaTexture = myInsidePrimitiveBox->getAlphaTexture();
752 VISU::TTextureValue aTexture = MakeImageData( true, anInsideMainTexture, anInsideAlphaTexture );
754 if( aTexture.GetPointer() )
755 myInsideCursorSettings->SetTexture( aTexture.GetPointer() );
757 myInsideCursorSettings->SetInitial( false );
758 myInsideCursorSettings->SetPrimitiveType( myInsidePrimitiveBox->getPrimitiveType() );
759 myInsideCursorSettings->SetClamp( myInsidePrimitiveBox->getClamp() );
760 myInsideCursorSettings->SetAlphaThreshold( myInsidePrimitiveBox->getAlphaThreshold() );
761 myInsideCursorSettings->SetResolution( myInsidePrimitiveBox->getResolution() );
763 myInsideCursorSettings->SetMinSize( myInsideSizeBox->getMinSize() );
764 myInsideCursorSettings->SetMaxSize( myInsideSizeBox->getMaxSize() );
766 myInsideCursorSettings->SetMagnification( this->getMagnification() );
767 myInsideCursorSettings->SetIncrement( this->getIncrement() );
769 myInsideCursorSettings->InvokeEvent(VISU::UpdateInsideSettingsEvent,NULL);
772 void VVTK_SegmentationCursorDlg::ApplyOutsideGaussPoints()
774 QString anOutsideMainTexture = myOutsidePrimitiveBox->getMainTexture();
775 QString anOutsideAlphaTexture = myOutsidePrimitiveBox->getAlphaTexture();
776 VISU::TTextureValue aTexture = MakeImageData( false, anOutsideMainTexture, anOutsideAlphaTexture );
778 if( aTexture.GetPointer() )
779 myOutsideCursorSettings->SetTexture( aTexture.GetPointer() );
781 myOutsideCursorSettings->SetInitial( false );
782 myOutsideCursorSettings->SetPrimitiveType( myOutsidePrimitiveBox->getPrimitiveType() );
783 myOutsideCursorSettings->SetClamp( myOutsidePrimitiveBox->getClamp() );
784 myOutsideCursorSettings->SetAlphaThreshold( myOutsidePrimitiveBox->getAlphaThreshold() );
785 myOutsideCursorSettings->SetResolution( myOutsidePrimitiveBox->getResolution() );
787 myOutsideCursorSettings->SetSize( myOutsideSizeBox->getOutsideSize() );
788 myOutsideCursorSettings->SetUniform( myOutsideSizeBox->getUniform() );
790 QColor aButtonColor = myOutsideSizeBox->getColor();
791 vtkFloatingPointType aColor[3];
792 aColor[0] = aButtonColor.red() / 255.0;
793 aColor[1] = aButtonColor.green() / 255.0;
794 aColor[2] = aButtonColor.blue() / 255.0;
795 myOutsideCursorSettings->SetColor( aColor );
797 myOutsideCursorSettings->SetMagnification( this->getMagnification() );
798 myOutsideCursorSettings->SetIncrement( this->getIncrement() );
800 myOutsideCursorSettings->InvokeEvent(VISU::UpdateOutsideSettingsEvent,NULL);
803 void VVTK_SegmentationCursorDlg::onClickClose()
805 myPlaneAction->setOn( false );
806 mySphereAction->setOn( false );
813 void VVTK_SegmentationCursorDlg::onClickHelp()
815 QString aHelpFileName = "segmentation.htm";
816 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
818 app->onHelpContextModule(app->activeModule() ? app->moduleName(app->activeModule()->moduleName()) : QString(""), aHelpFileName);
820 SUIT_MessageBox::warn1(0, QObject::tr("WRN_WARNING"),
821 QObject::tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
822 arg(app->resourceMgr()->stringValue("ExternalBrowser", "application")).arg(aHelpFileName),
823 QObject::tr("BUT_OK"));
827 void VVTK_SegmentationCursorDlg::done( int r )
829 myPlaneAction->setOn( false );
830 mySphereAction->setOn( false );
837 void VVTK_SegmentationCursorDlg::onParentShow()
839 if(myPlaneAction->isOn() || mySphereAction->isOn())
845 void VVTK_SegmentationCursorDlg::onParentHide()
850 bool VVTK_SegmentationCursorDlg::CheckNumberOfFaces()
855 vtkRenderer* aRenderer = myInteractor->getRenderer();
860 int aNumberOfPoints = 0;
863 vtkActorCollection* anActColl = aRenderer->GetActors();
864 for( anActColl->InitTraversal(); ( anActor = anActColl->GetNextActor() ) != NULL; )
866 if( VISU_GaussPtsAct1* aGaussActor = VISU_GaussPtsAct1::SafeDownCast( anActor ) )
867 aNumberOfPoints += aGaussActor->GetInput()->GetNumberOfCells();
869 return !( myInsidePrimitiveBox->getPrimitiveType() == VISU_OpenGLPointSpriteMapper::GeomSphere &&
870 aNumberOfPoints * myInsidePrimitiveBox->getFaceNumber() * 2 > myInsidePrimitiveBox->getFaceLimit() ||
871 myOutsidePrimitiveBox->getPrimitiveType() == VISU_OpenGLPointSpriteMapper::GeomSphere &&
872 aNumberOfPoints * myOutsidePrimitiveBox->getFaceNumber() > myOutsidePrimitiveBox->getFaceLimit() );