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 "SUIT_MessageBox.h"
26 #include "SUIT_ResourceMgr.h"
27 #include "SUIT_Session.h"
29 #include "SVTK_RenderWindowInteractor.h"
31 #include <vtkActorCollection.h>
32 #include <vtkCallbackCommand.h>
33 #include <vtkObjectFactory.h>
34 #include <vtkRenderer.h>
35 #include <vtkRenderWindowInteractor.h>
36 #include <vtkSmartPointer.h>
37 #include <vtkImageData.h>
39 #include "utilities.h"
41 #include <qbuttongroup.h>
42 #include <qcolordialog.h>
43 #include <qfiledialog.h>
44 #include <qgroupbox.h>
47 #include <qlineedit.h>
48 #include <qpushbutton.h>
49 #include <qradiobutton.h>
50 #include <qtabwidget.h>
53 #include "QtxAction.h"
54 #include "QtxDblSpinBox.h"
55 #include "QtxIntSpinBox.h"
60 //----------------------------------------------------------------
65 Image2VTI(const QString& theImageFileName)
67 QFileInfo aFileInfo(theImageFileName);
68 QString aFormat = aFileInfo.extension(FALSE);
69 QString aVTIName = QString("/tmp/") + getenv("USER") + "-" + aFileInfo.baseName(TRUE) + ".vti";
70 QString aCommand = QString( "VISU_img2vti " ) + aFormat + " " + theImageFileName + " " + aVTIName;
72 if(system( aCommand.latin1() ) == 0)
80 RemoveFile(const QString& theFileName)
82 if( !theFileName.isNull() ){
83 QString aCommand = QString( "rm -fr " ) + theFileName;
84 system( aCommand.latin1() );
90 GetTexture(const QString& theMainTexture,
91 const QString& theAlphaTexture)
93 typedef std::pair<std::string,std::string> TTextureKey;
94 typedef std::map<TTextureKey,TTextureValue> TTextureMap;
96 static TTextureMap aTextureMap;
98 TTextureValue aTextureValue;
99 TTextureKey aTextureKey(theMainTexture,theAlphaTexture);
100 TTextureMap::const_iterator anIter = aTextureMap.find(aTextureKey);
101 if(anIter != aTextureMap.end()){
102 aTextureValue = anIter->second;
104 QString aMainTextureVTI = Image2VTI(theMainTexture);
105 QString anAlphaTextureVTI = Image2VTI(theAlphaTexture);
107 if( !aMainTextureVTI.isNull() && !anAlphaTextureVTI.isNull() ){
109 VISU_GaussPointsPL::MakeTexture( aMainTextureVTI.latin1(),
110 anAlphaTextureVTI.latin1());
112 if( aTextureValue.GetPointer() )
113 aTextureMap[aTextureKey] = aTextureValue;
116 RemoveFile(aMainTextureVTI);
117 RemoveFile(anAlphaTextureVTI);
120 return aTextureValue;
125 //----------------------------------------------------------------
126 VVTK_SegmentationCursorDlg::VVTK_SegmentationCursorDlg( QWidget* parent, const char* name )
127 :QDialog( parent, name, false, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu ),
128 myEventCallbackCommand( vtkCallbackCommand::New() ),
129 myInsideCursorSettings( VISU_InsideCursorSettings::New() ),
130 myOutsideCursorSettings( VISU_OutsideCursorSettings::New() ),
131 myIsPlaneSegmentation( true ),
136 myEventCallbackCommand->Delete();
137 myEventCallbackCommand->SetClientData(this);
138 myEventCallbackCommand->SetCallback(VVTK_SegmentationCursorDlg::ProcessEvents);
140 myInsideCursorSettings->AddObserver(VISU::UpdateFromSettingsEvent,
141 myEventCallbackCommand.GetPointer(),
144 SUIT_ResourceMgr* aResourceMgr = SUIT_Session::session()->resourceMgr();
146 setCaption( tr( "SEGMENTATION_CURSOR_DLG_TITLE" ) );
147 setSizeGripEnabled(TRUE);
149 QVBoxLayout* TopLayout = new QVBoxLayout( this );
150 TopLayout->setSpacing(6);
151 TopLayout->setMargin(11);
153 myTabBox = new QTabWidget( this );
155 // Segmentation cursor pane
156 mySegmentationCursorBox = new QVBox( this );
157 mySegmentationCursorBox->setMargin(11);
158 mySegmentationCursorBox->setSpacing(6);
159 mySegmentationCursorBox->layout()->setAlignment(Qt::AlignTop);
162 myOriginGroup = new QGroupBox( tr( "ORIGIN_TITLE" ), mySegmentationCursorBox, "OriginGroup" );
163 myOriginGroup->setColumnLayout( 0, Qt::Vertical );
164 myOriginGroup->layout()->setSpacing( 0 );
165 myOriginGroup->layout()->setMargin( 0 );
167 QGridLayout* OriginGroupLayout = new QGridLayout( myOriginGroup->layout() );
168 OriginGroupLayout->setAlignment(Qt::AlignTop | Qt::AlignCenter);
169 OriginGroupLayout->setSpacing(6);
170 OriginGroupLayout->setMargin(11);
172 QLabel* XOriginLabel = new QLabel( tr( "ORIGIN_X" ), myOriginGroup );
173 myXOriginSpinBox = new QtxDblSpinBox( -1000.0, 1000.0, 0.1, myOriginGroup );
174 myXOriginSpinBox->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
175 myXOriginSpinBox->setMinimumWidth( 100 );
176 myXOriginSpinBox->setValue( 0.0 );
178 QLabel* YOriginLabel = new QLabel( tr( "ORIGIN_Y" ), myOriginGroup );
179 myYOriginSpinBox = new QtxDblSpinBox( -1000.0, 1000.0, 0.1, myOriginGroup );
180 myYOriginSpinBox->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
181 myYOriginSpinBox->setMinimumWidth( 100 );
182 myYOriginSpinBox->setValue( 0.0 );
184 QLabel* ZOriginLabel = new QLabel( tr( "ORIGIN_Z" ), myOriginGroup );
185 myZOriginSpinBox = new QtxDblSpinBox( -1000.0, 1000.0, 0.1, myOriginGroup );
186 myZOriginSpinBox->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
187 myZOriginSpinBox->setMinimumWidth( 100 );
188 myZOriginSpinBox->setValue( 0.0 );
190 OriginGroupLayout->addWidget( XOriginLabel, 0, 0 );
191 OriginGroupLayout->addWidget( myXOriginSpinBox, 0, 1 );
192 OriginGroupLayout->addWidget( YOriginLabel, 0, 2 );
193 OriginGroupLayout->addWidget( myYOriginSpinBox, 0, 3 );
194 OriginGroupLayout->addWidget( ZOriginLabel, 0, 4 );
195 OriginGroupLayout->addWidget( myZOriginSpinBox, 0, 5 );
197 // Direction ( Plane Segmentation )
198 myDirectionGroup = new QGroupBox( tr( "DIRECTION_TITLE" ), mySegmentationCursorBox, "DirectionGroup" );
199 myDirectionGroup->setColumnLayout( 0, Qt::Vertical );
200 myDirectionGroup->layout()->setSpacing( 0 );
201 myDirectionGroup->layout()->setMargin( 0 );
203 QGridLayout* DirectionGroupLayout = new QGridLayout( myDirectionGroup->layout() );
204 DirectionGroupLayout->setAlignment(Qt::AlignTop | Qt::AlignCenter);
205 DirectionGroupLayout->setSpacing(6);
206 DirectionGroupLayout->setMargin(11);
208 QLabel* DXDirectionLabel = new QLabel( tr( "DIRECTION_DX" ), myDirectionGroup );
209 myDXDirectionSpinBox = new QtxDblSpinBox( -1.0, 1.0, 0.1, myDirectionGroup );
210 myDXDirectionSpinBox->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
211 myDXDirectionSpinBox->setMinimumWidth( 100 );
212 myDXDirectionSpinBox->setValue( 0.0 );
214 QLabel* DYDirectionLabel = new QLabel( tr( "DIRECTION_DY" ), myDirectionGroup );
215 myDYDirectionSpinBox = new QtxDblSpinBox( -1.0, 1.0, 0.1, myDirectionGroup );
216 myDYDirectionSpinBox->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
217 myDYDirectionSpinBox->setMinimumWidth( 100 );
218 myDYDirectionSpinBox->setValue( 0.0 );
220 QLabel* DZDirectionLabel = new QLabel( tr( "DIRECTION_DZ" ), myDirectionGroup );
221 myDZDirectionSpinBox = new QtxDblSpinBox( -1.0, 1.0, 0.1, myDirectionGroup );
222 myDZDirectionSpinBox->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
223 myDZDirectionSpinBox->setMinimumWidth( 100 );
224 myDZDirectionSpinBox->setValue( 1.0 );
226 DirectionGroupLayout->addWidget( DXDirectionLabel, 0, 0 );
227 DirectionGroupLayout->addWidget( myDXDirectionSpinBox, 0, 1 );
228 DirectionGroupLayout->addWidget( DYDirectionLabel, 0, 2 );
229 DirectionGroupLayout->addWidget( myDYDirectionSpinBox, 0, 3 );
230 DirectionGroupLayout->addWidget( DZDirectionLabel, 0, 4 );
231 DirectionGroupLayout->addWidget( myDZDirectionSpinBox, 0, 5 );
233 // Depth ( Plane Segmentation )
234 myDepthGroup = new QGroupBox( tr( "DEPTH_TITLE" ), mySegmentationCursorBox, "DepthGroup" );
235 myDepthGroup->setColumnLayout( 0, Qt::Vertical );
236 myDepthGroup->layout()->setSpacing( 0 );
237 myDepthGroup->layout()->setMargin( 0 );
239 QGridLayout* DepthGroupLayout = new QGridLayout( myDepthGroup->layout() );
240 DepthGroupLayout->setAlignment(Qt::AlignTop | Qt::AlignCenter);
241 DepthGroupLayout->setSpacing(6);
242 DepthGroupLayout->setMargin(11);
244 QLabel* DepthLabel = new QLabel( tr( "DEPTH" ), myDepthGroup );
245 myDepthSpinBox = new QtxDblSpinBox( 0.0, VTK_LARGE_FLOAT, 0.1, myDepthGroup );
246 myDepthSpinBox->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
247 myDepthSpinBox->setMinimumWidth( 100 );
248 myDepthSpinBox->setValue( 1.0 );
250 DepthGroupLayout->addWidget( DepthLabel, 0, 0 );
251 DepthGroupLayout->addWidget( myDepthSpinBox, 0, 1 );
253 // Radius ( Sphere Segmentation )
254 myRadiusGroup = new QGroupBox( tr( "RADIUS_TITLE" ), mySegmentationCursorBox, "RadiusGroup" );
255 myRadiusGroup->setColumnLayout( 0, Qt::Vertical );
256 myRadiusGroup->layout()->setSpacing( 0 );
257 myRadiusGroup->layout()->setMargin( 0 );
259 QGridLayout* RadiusGroupLayout = new QGridLayout( myRadiusGroup->layout() );
260 RadiusGroupLayout->setAlignment(Qt::AlignTop | Qt::AlignCenter);
261 RadiusGroupLayout->setSpacing(6);
262 RadiusGroupLayout->setMargin(11);
264 QLabel* RadiusLabel = new QLabel( tr( "RADIUS" ),myRadiusGroup );
265 myRadiusSpinBox = new QtxDblSpinBox( 0.0, 1000.0, 1.0,myRadiusGroup );
266 myRadiusSpinBox->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
267 myRadiusSpinBox->setMinimumWidth( 100 );
268 myRadiusSpinBox->setValue( 100.0 );
270 QLabel* RatioLabel = new QLabel( tr( "RATIO" ), myRadiusGroup );
271 myRatioSpinBox = new QtxDblSpinBox( 0.1, 10.0, 0.1,myRadiusGroup );
272 myRatioSpinBox->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
273 myRatioSpinBox->setMinimumWidth( 100 );
274 myRatioSpinBox->setValue( 2.0 );
276 RadiusGroupLayout->addWidget( RadiusLabel, 0, 0 );
277 RadiusGroupLayout->addWidget( myRadiusSpinBox, 0, 1 );
278 RadiusGroupLayout->addWidget( RatioLabel, 0, 2 );
279 RadiusGroupLayout->addWidget( myRatioSpinBox, 0, 3 );
282 myTabBox->addTab( mySegmentationCursorBox, tr( "SEGMENTATION_CURSOR_TAB" ) );
286 myGaussPointsBox = new QVBox( this );
287 myGaussPointsBox->setMargin(11);
288 myGaussPointsBox->setSpacing(6);
290 // Inside Gauss points
291 QGroupBox* anInsideGroup = new QGroupBox( tr( "INSIDE_GAUSS_POINTS" ), myGaussPointsBox );
292 anInsideGroup->setColumnLayout( 0, Qt::Vertical );
293 anInsideGroup->layout()->setSpacing( 0 );
294 anInsideGroup->layout()->setMargin( 0 );
296 QGridLayout* anInsideGroupLayout = new QGridLayout( anInsideGroup->layout() );
297 anInsideGroupLayout->setAlignment(Qt::AlignTop | Qt::AlignCenter);
298 anInsideGroupLayout->setSpacing(6);
299 anInsideGroupLayout->setMargin(11);
302 myInsidePrimitiveBox = new VVTK_PrimitiveBox( anInsideGroup );
305 myInsideSizeBox = new VVTK_SizeBox( anInsideGroup );
306 myInsideSizeBox->setType( VVTK_SizeBox::Inside );
308 anInsideGroupLayout->addWidget( myInsidePrimitiveBox, 0, 0 );
309 anInsideGroupLayout->addWidget( myInsideSizeBox, 1, 0 );
311 // Outside Gauss points
312 QGroupBox* anOutsideGroup = new QGroupBox( tr( "OUTSIDE_GAUSS_POINTS" ), myGaussPointsBox );
313 anOutsideGroup->setColumnLayout( 0, Qt::Vertical );
314 anOutsideGroup->layout()->setSpacing( 0 );
315 anOutsideGroup->layout()->setMargin( 0 );
317 QGridLayout* anOutsideGroupLayout = new QGridLayout( anOutsideGroup->layout() );
318 anOutsideGroupLayout->setAlignment(Qt::AlignTop | Qt::AlignCenter);
319 anOutsideGroupLayout->setSpacing(6);
320 anOutsideGroupLayout->setMargin(11);
323 myOutsidePrimitiveBox = new VVTK_PrimitiveBox( anOutsideGroup );
326 myOutsideSizeBox = new VVTK_SizeBox( anOutsideGroup );
327 myOutsideSizeBox->setType( VVTK_SizeBox::Outside );
329 anOutsideGroupLayout->addWidget( myOutsidePrimitiveBox, 0, 0 );
330 anOutsideGroupLayout->addWidget( myOutsideSizeBox, 1, 0 );
334 QGroupBox* MagnificationGroup = new QGroupBox ( tr( "MAGNIFICATION_TITLE" ), myGaussPointsBox, "MagnificationGroup" );
335 MagnificationGroup->setColumnLayout(0, Qt::Vertical );
336 MagnificationGroup->layout()->setSpacing( 0 );
337 MagnificationGroup->layout()->setMargin( 0 );
339 QGridLayout* MagnificationGroupLayout = new QGridLayout (MagnificationGroup->layout());
340 MagnificationGroupLayout->setAlignment(Qt::AlignTop | Qt::AlignCenter);
341 MagnificationGroupLayout->setSpacing(6);
342 MagnificationGroupLayout->setMargin(11);
344 myMagnificationLabel = new QLabel( tr( "MAGNIFICATION" ), MagnificationGroup );
345 myMagnificationSpinBox = new QtxIntSpinBox( 1, 10000, 10, MagnificationGroup );
346 myMagnificationSpinBox->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
348 MagnificationGroupLayout->addWidget( myMagnificationLabel, 0, 0 );
349 MagnificationGroupLayout->addWidget( myMagnificationSpinBox, 0, 1 );
352 myIncrementLabel = new QLabel( tr( "INCREMENT" ), MagnificationGroup );
353 myIncrementSpinBox = new QtxDblSpinBox( 0.01, 10, 0.1, MagnificationGroup );
354 myIncrementSpinBox->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
356 MagnificationGroupLayout->addWidget( myIncrementLabel, 0, 2 );
357 MagnificationGroupLayout->addWidget( myIncrementSpinBox, 0, 3 );
360 myTabBox->addTab( myGaussPointsBox, tr( "GAUSS_POINTS_TAB" ) );
361 myTabBox->showPage( myGaussPointsBox );
364 // Common buttons ===========================================================
365 QGroupBox* GroupButtons = new QGroupBox( this, "GroupButtons" );
366 GroupButtons->setColumnLayout(0, Qt::Vertical );
367 GroupButtons->layout()->setSpacing( 0 );
368 GroupButtons->layout()->setMargin( 0 );
369 QGridLayout* GroupButtonsLayout = new QGridLayout( GroupButtons->layout() );
370 GroupButtonsLayout->setAlignment( Qt::AlignTop );
371 GroupButtonsLayout->setSpacing( 6 );
372 GroupButtonsLayout->setMargin( 11 );
374 QPushButton* buttonApply = new QPushButton( tr( "&Apply" ), GroupButtons, "buttonApply" );
375 buttonApply->setAutoDefault( TRUE );
376 buttonApply->setDefault( TRUE );
377 GroupButtonsLayout->addWidget( buttonApply, 0, 0 );
378 GroupButtonsLayout->addItem( new QSpacerItem( 5, 5, QSizePolicy::Expanding, QSizePolicy::Minimum ), 0, 1 );
380 QPushButton* buttonClose = new QPushButton( tr( "&Close" ) , GroupButtons, "buttonClose" );
381 buttonClose->setAutoDefault( TRUE );
382 GroupButtonsLayout->addWidget( buttonClose, 0, 2 );
384 TopLayout->addWidget( myTabBox );
385 TopLayout->addWidget( GroupButtons );
387 connect( buttonApply, SIGNAL( clicked() ), this, SLOT( onClickApply() ) );
388 connect( buttonClose, SIGNAL( clicked() ), this, SLOT( onClickClose() ) );
391 VVTK_SegmentationCursorDlg::~VVTK_SegmentationCursorDlg()
396 float VVTK_SegmentationCursorDlg::getMagnification() const
398 return myMagnificationSpinBox->value() / 100.0;
401 void VVTK_SegmentationCursorDlg::setMagnification( float theMagnification )
403 myMagnificationSpinBox->setValue( ( int )( theMagnification * 100 ) );
406 float VVTK_SegmentationCursorDlg::getIncrement() const
408 return myIncrementSpinBox->value();
411 void VVTK_SegmentationCursorDlg::setIncrement( float theIncrement )
413 myIncrementSpinBox->setValue( theIncrement );
417 void VVTK_SegmentationCursorDlg::SetWidgetCtrl( VISU_WidgetCtrl* theWidgetCtrl )
419 if(myWidgetCtrl == theWidgetCtrl)
423 myWidgetCtrl->RemoveObserver(myEventCallbackCommand.GetPointer());
425 myWidgetCtrl = theWidgetCtrl;
428 theWidgetCtrl->AddObserver(vtkCommand::EndInteractionEvent,
429 myEventCallbackCommand.GetPointer(),
433 void VVTK_SegmentationCursorDlg::ProcessEvents(vtkObject* vtkNotUsed(theObject),
434 unsigned long theEvent,
436 void* vtkNotUsed(theCallData))
438 VVTK_SegmentationCursorDlg* self = reinterpret_cast<VVTK_SegmentationCursorDlg*>(theClientData);
441 case vtkCommand::EndInteractionEvent:
442 self->UpdateSegmentation();
444 case VISU::UpdateFromSettingsEvent:
445 self->GetOutsideCursorSettings()->SetMagnification( self->GetInsideCursorSettings()->GetMagnification() );
446 self->GetOutsideCursorSettings()->SetIncrement( self->GetInsideCursorSettings()->GetIncrement() );
448 self->UpdateInsideGaussPoints();
449 self->UpdateOutsideGaussPoints();
451 self->GetInsideCursorSettings()->InvokeEvent(VISU::UpdateInsideSettingsEvent,NULL);
452 self->GetOutsideCursorSettings()->InvokeEvent(VISU::UpdateOutsideSettingsEvent,NULL);
457 void VVTK_SegmentationCursorDlg::UpdateSegmentation()
459 if( myIsPlaneSegmentation )
461 myDirectionGroup->show();
462 myDepthGroup->show();
463 myRadiusGroup->hide();
465 VISU_PlanesWidget *pPlanesWidget=myWidgetCtrl->GetPlanesWidget();
467 pPlanesWidget->GetOrigin( origin );
468 myXOriginSpinBox->setValue( origin[0] );
469 myYOriginSpinBox->setValue( origin[1] );
470 myZOriginSpinBox->setValue( origin[2] );
473 pPlanesWidget->GetNormal( normal );
474 myDXDirectionSpinBox->setValue( normal[0] );
475 myDYDirectionSpinBox->setValue( normal[1] );
476 myDZDirectionSpinBox->setValue( normal[2] );
478 myDepthSpinBox->setValue( pPlanesWidget->Distance() );
482 myDirectionGroup->hide();
483 myDepthGroup->hide();
484 myRadiusGroup->show();
486 VISU_SphereWidget *pSphereWidget=myWidgetCtrl->GetSphereWidget();
487 float origin[3], aRadius;
488 pSphereWidget->GetCenter(origin);
489 myXOriginSpinBox->setValue( origin[0] );
490 myYOriginSpinBox->setValue( origin[1] );
491 myZOriginSpinBox->setValue( origin[2] );
492 aRadius=pSphereWidget->GetRadius();
493 myRadiusSpinBox->setValue(aRadius);
494 myRatioSpinBox->setValue(pSphereWidget->GetRatio());
498 void VVTK_SegmentationCursorDlg::UpdateInsideGaussPoints()
500 int aPrimitiveType = VISU_OpenGLPointSpriteMapper::PointSprite;
501 float aClamp = 200.0;
502 QString aMainTexture = QString( getenv( "VISU_ROOT_DIR") ) + "/share/salome/resources/sprite_texture.bmp";
503 QString anAlphaTexture = QString( getenv( "VISU_ROOT_DIR") ) + "/share/salome/resources/sprite_alpha.bmp";
504 float anAlphaThreshold = 0.1;
508 int aMagnification = 100;
509 float anIncrement = 2.0;
511 if( !myInsideCursorSettings->GetInitial() )
513 myInsidePrimitiveBox->setPrimitiveType( myInsideCursorSettings->GetPrimitiveType() );
514 myInsidePrimitiveBox->setClamp( myInsideCursorSettings->GetClamp() );
515 myInsidePrimitiveBox->setMainTexture( myInsideMainTexture );
516 myInsidePrimitiveBox->setAlphaTexture( myInsideAlphaTexture );
517 myInsidePrimitiveBox->setAlphaThreshold( myInsideCursorSettings->GetAlphaThreshold() );
518 myInsidePrimitiveBox->setResolution( myInsideCursorSettings->GetResolution() );
520 myInsideSizeBox->setMinSize( myInsideCursorSettings->GetMinSize() );
521 myInsideSizeBox->setMaxSize( myInsideCursorSettings->GetMaxSize() );
523 this->setMagnification( myInsideCursorSettings->GetMagnification() );
524 this->setIncrement( myInsideCursorSettings->GetIncrement() );
529 SUIT_ResourceMgr* aResourceMgr = SUIT_Session::session()->resourceMgr();
531 aPrimitiveType = aResourceMgr->integerValue( "VISU", "inside_point_sprite_primitive_type", aPrimitiveType );
532 myInsidePrimitiveBox->setPrimitiveType( aPrimitiveType );
534 aClamp = aResourceMgr->doubleValue( "VISU", "inside_point_sprite_clamp", aClamp );
535 myInsidePrimitiveBox->setClamp( aClamp );
537 aMainTexture = aResourceMgr->stringValue( "VISU", "inside_point_sprite_main_texture", aMainTexture );
538 myInsidePrimitiveBox->setMainTexture( aMainTexture );
540 anAlphaTexture = aResourceMgr->stringValue( "VISU", "inside_point_sprite_alpha_texture", anAlphaTexture );
541 myInsidePrimitiveBox->setAlphaTexture( anAlphaTexture );
543 anAlphaThreshold = aResourceMgr->doubleValue( "VISU", "inside_point_sprite_alpha_threshold", anAlphaThreshold );
544 myInsidePrimitiveBox->setAlphaThreshold( anAlphaThreshold );
546 aResolution = aResourceMgr->integerValue( "VISU", "inside_geom_sphere_resolution", aResolution );
547 myInsidePrimitiveBox->setResolution( aResolution );
549 aMinSize = aResourceMgr->integerValue( "VISU", "inside_point_sprite_min_size", aMinSize );
550 myInsideSizeBox->setMinSize( aMinSize / 100.0 );
552 aMaxSize = aResourceMgr->integerValue( "VISU", "inside_point_sprite_max_size", aMaxSize );
553 myInsideSizeBox->setMaxSize( aMaxSize / 100.0 );
555 aMagnification = aResourceMgr->integerValue( "VISU", "inside_point_sprite_magnification", aMagnification );
556 this->setMagnification( aMagnification / 100.0 );
558 anIncrement = aResourceMgr->doubleValue( "VISU", "inside_point_sprite_increment", anIncrement );
559 this->setIncrement( anIncrement );
561 myInsidePrimitiveBox->setFaceLimit( 50000 );
563 ApplyInsideGaussPoints();
566 void VVTK_SegmentationCursorDlg::UpdateOutsideGaussPoints()
568 float aClamp = 256.0;
569 int aPrimitiveType = VISU_OpenGLPointSpriteMapper::PointSprite;
570 QString aMainTexture = QString( getenv( "VISU_ROOT_DIR") ) + "/share/salome/resources/sprite_texture.bmp";
571 QString anAlphaTexture = QString( getenv( "VISU_ROOT_DIR") ) + "/share/salome/resources/sprite_alpha.bmp";
572 float anAlphaThreshold = 0.1;
575 bool aUniform = false;
576 QColor aColor = Qt::blue;
578 if( !myOutsideCursorSettings->GetInitial() )
580 myOutsidePrimitiveBox->setPrimitiveType( myOutsideCursorSettings->GetPrimitiveType() );
581 myOutsidePrimitiveBox->setClamp( myOutsideCursorSettings->GetClamp() );
582 myOutsidePrimitiveBox->setMainTexture( myOutsideMainTexture );
583 myOutsidePrimitiveBox->setAlphaTexture( myOutsideAlphaTexture );
584 myOutsidePrimitiveBox->setAlphaThreshold( myOutsideCursorSettings->GetAlphaThreshold() );
585 myOutsidePrimitiveBox->setResolution( myOutsideCursorSettings->GetResolution() );
587 myOutsideSizeBox->setOutsideSize( myOutsideCursorSettings->GetSize() );
588 myOutsideSizeBox->setUniform( myOutsideCursorSettings->GetUniform() );
590 float* aColor = myOutsideCursorSettings->GetColor();
591 myOutsideSizeBox->setColor( QColor( ( int )( aColor[0] * 255.0 ),
592 ( int )( aColor[1] * 255.0 ),
593 ( int )( aColor[2] * 255.0 ) ) );
598 SUIT_ResourceMgr* aResourceMgr = SUIT_Session::session()->resourceMgr();
600 aPrimitiveType = aResourceMgr->integerValue( "VISU", "outside_point_sprite_primitive_type", aPrimitiveType );
601 myOutsidePrimitiveBox->setPrimitiveType( aPrimitiveType );
603 aClamp = aResourceMgr->doubleValue( "VISU", "outside_point_sprite_clamp", aClamp );
604 myOutsidePrimitiveBox->setClamp( aClamp );
606 aMainTexture = aResourceMgr->stringValue( "VISU", "outside_point_sprite_main_texture", aMainTexture );
607 myOutsidePrimitiveBox->setMainTexture( aMainTexture );
609 anAlphaTexture = aResourceMgr->stringValue( "VISU", "outside_point_sprite_alpha_texture", anAlphaTexture );
610 myOutsidePrimitiveBox->setAlphaTexture( anAlphaTexture );
612 anAlphaThreshold = aResourceMgr->doubleValue( "VISU", "outside_point_sprite_alpha_threshold", anAlphaThreshold );
613 myOutsidePrimitiveBox->setAlphaThreshold( anAlphaThreshold );
615 aResolution = aResourceMgr->integerValue( "VISU", "outside_geom_sphere_resolution", aResolution );
616 myOutsidePrimitiveBox->setResolution( aResolution );
618 aSize = aResourceMgr->integerValue( "VISU", "outside_point_sprite_size", aSize );
619 myOutsideSizeBox->setOutsideSize( aSize / 100.0 );
621 aUniform = aResourceMgr->booleanValue( "VISU", "outside_point_sprite_uniform", aUniform );
622 myOutsideSizeBox->setUniform( aUniform );
624 aColor = aResourceMgr->colorValue( "VISU", "outside_point_sprite_color", aColor );
625 myOutsideSizeBox->setColor( aColor );
627 myOutsidePrimitiveBox->setFaceLimit( 50000 );
629 ApplyOutsideGaussPoints();
632 VISU_InsideCursorSettings* VVTK_SegmentationCursorDlg::GetInsideCursorSettings()
634 return myInsideCursorSettings.GetPointer();
637 VISU_OutsideCursorSettings* VVTK_SegmentationCursorDlg::GetOutsideCursorSettings()
639 return myOutsideCursorSettings.GetPointer();
643 VVTK_SegmentationCursorDlg
644 ::MakeImageData( bool theInside,
645 const QString& theMainTexture,
646 const QString& theAlphaTexture )
650 bool updateMainTexture = myInsideMainTexture != theMainTexture;
651 bool updateAlphaTexture = myInsideAlphaTexture != theAlphaTexture;
652 if( !updateMainTexture && !updateAlphaTexture )
655 myInsideMainTexture = theMainTexture;
656 myInsideAlphaTexture = theAlphaTexture;
660 bool updateMainTexture = myOutsideMainTexture != theMainTexture;
661 bool updateAlphaTexture = myOutsideAlphaTexture != theAlphaTexture;
662 if( !updateMainTexture && !updateAlphaTexture )
665 myOutsideMainTexture = theMainTexture;
666 myOutsideAlphaTexture = theAlphaTexture;
669 return VISU::GetTexture( theMainTexture.latin1(),
670 theAlphaTexture.latin1());
673 void VVTK_SegmentationCursorDlg::onClickApply()
675 if( myTabBox->currentPage() == mySegmentationCursorBox )
676 ApplySegmentationCursor();
679 QString aWarning = "The number of faces needed to perform the 'Geometrical Sphere' primitive\n";
680 aWarning.append( "presentation might be too important to ensure an acceptable frame rate.\n\n" );
681 aWarning.append( "Can you please confirm that you want to continue anyway?" );
682 bool toApply = CheckNumberOfFaces() ||
683 SUIT_MessageBox::warn2( this, tr( "Warning" ), aWarning,
684 tr( "&OK" ), tr( "&Cancel" ), 0, 1, 1 ) == 0;
688 ApplyInsideGaussPoints();
689 ApplyOutsideGaussPoints();
694 void VVTK_SegmentationCursorDlg::ApplySegmentationCursor()
696 if( myIsPlaneSegmentation )
698 VISU_PlanesWidget *pPlanesWidget=myWidgetCtrl->GetPlanesWidget();
700 origin[0] = myXOriginSpinBox->value();
701 origin[1] = myYOriginSpinBox->value();
702 origin[2] = myZOriginSpinBox->value();
703 pPlanesWidget->SetOrigin( origin );
706 normal[0] = myDXDirectionSpinBox->value();
707 normal[1] = myDYDirectionSpinBox->value();
708 normal[2] = myDZDirectionSpinBox->value();
710 if( normal[0] == 0.0 && normal[1] == 0.0 && normal[2] == 0.0 )
713 myDZDirectionSpinBox->setValue( 1.0 );
715 pPlanesWidget->SetNormal( normal );
717 pPlanesWidget->SetDistance( myDepthSpinBox->value() );
719 myWidgetCtrl->InvokeEvent(vtkCommand::EndInteractionEvent,NULL);
720 myWidgetCtrl->GetInteractor()->Render();
724 VISU_SphereWidget *pSphereWidget=myWidgetCtrl->GetSphereWidget();
725 float origin[3], aRadius;
726 origin[0] = myXOriginSpinBox->value();
727 origin[1] = myYOriginSpinBox->value();
728 origin[2] = myZOriginSpinBox->value();
729 pSphereWidget->SetCenter(origin);
731 aRadius=myRadiusSpinBox->value();
732 pSphereWidget->SetRadius(aRadius);
734 pSphereWidget->SetRatio(myRatioSpinBox->value());
736 myWidgetCtrl->InvokeEvent(vtkCommand::EndInteractionEvent,NULL);
737 myWidgetCtrl->GetInteractor()->Render();
741 void VVTK_SegmentationCursorDlg::ApplyInsideGaussPoints()
743 QString anInsideMainTexture = myInsidePrimitiveBox->getMainTexture();
744 QString anInsideAlphaTexture = myInsidePrimitiveBox->getAlphaTexture();
745 VISU::TTextureValue aTexture = MakeImageData( true, anInsideMainTexture, anInsideAlphaTexture );
747 if( aTexture.GetPointer() )
748 myInsideCursorSettings->SetTexture( aTexture.GetPointer() );
750 myInsideCursorSettings->SetInitial( false );
751 myInsideCursorSettings->SetPrimitiveType( myInsidePrimitiveBox->getPrimitiveType() );
752 myInsideCursorSettings->SetClamp( myInsidePrimitiveBox->getClamp() );
753 myInsideCursorSettings->SetAlphaThreshold( myInsidePrimitiveBox->getAlphaThreshold() );
754 myInsideCursorSettings->SetResolution( myInsidePrimitiveBox->getResolution() );
756 myInsideCursorSettings->SetMinSize( myInsideSizeBox->getMinSize() );
757 myInsideCursorSettings->SetMaxSize( myInsideSizeBox->getMaxSize() );
759 myInsideCursorSettings->SetMagnification( this->getMagnification() );
760 myInsideCursorSettings->SetIncrement( this->getIncrement() );
762 myInsideCursorSettings->InvokeEvent(VISU::UpdateInsideSettingsEvent,NULL);
765 void VVTK_SegmentationCursorDlg::ApplyOutsideGaussPoints()
767 QString anOutsideMainTexture = myOutsidePrimitiveBox->getMainTexture();
768 QString anOutsideAlphaTexture = myOutsidePrimitiveBox->getAlphaTexture();
769 VISU::TTextureValue aTexture = MakeImageData( false, anOutsideMainTexture, anOutsideAlphaTexture );
771 if( aTexture.GetPointer() )
772 myOutsideCursorSettings->SetTexture( aTexture.GetPointer() );
774 myOutsideCursorSettings->SetInitial( false );
775 myOutsideCursorSettings->SetPrimitiveType( myOutsidePrimitiveBox->getPrimitiveType() );
776 myOutsideCursorSettings->SetClamp( myOutsidePrimitiveBox->getClamp() );
777 myOutsideCursorSettings->SetAlphaThreshold( myOutsidePrimitiveBox->getAlphaThreshold() );
778 myOutsideCursorSettings->SetResolution( myOutsidePrimitiveBox->getResolution() );
780 myOutsideCursorSettings->SetSize( myOutsideSizeBox->getOutsideSize() );
781 myOutsideCursorSettings->SetUniform( myOutsideSizeBox->getUniform() );
783 QColor aButtonColor = myOutsideSizeBox->getColor();
785 aColor[0] = aButtonColor.red() / 255.0;
786 aColor[1] = aButtonColor.green() / 255.0;
787 aColor[2] = aButtonColor.blue() / 255.0;
788 myOutsideCursorSettings->SetColor( aColor );
790 myOutsideCursorSettings->SetMagnification( this->getMagnification() );
791 myOutsideCursorSettings->SetIncrement( this->getIncrement() );
793 myOutsideCursorSettings->InvokeEvent(VISU::UpdateOutsideSettingsEvent,NULL);
796 void VVTK_SegmentationCursorDlg::onClickClose()
798 myPlaneAction->setOn( false );
799 mySphereAction->setOn( false );
806 void VVTK_SegmentationCursorDlg::done( int r )
808 myPlaneAction->setOn( false );
809 mySphereAction->setOn( false );
816 bool VVTK_SegmentationCursorDlg::CheckNumberOfFaces()
821 vtkRenderer* aRenderer = myInteractor->getRenderer();
826 int aNumberOfPoints = 0;
829 vtkActorCollection* anActColl = aRenderer->GetActors();
830 for( anActColl->InitTraversal(); ( anActor = anActColl->GetNextActor() ) != NULL; )
832 if( VISU_GaussPtsAct1* aGaussActor = VISU_GaussPtsAct1::SafeDownCast( anActor ) )
833 aNumberOfPoints += aGaussActor->GetInput()->GetNumberOfCells();
835 return !( myInsidePrimitiveBox->getPrimitiveType() == VISU_OpenGLPointSpriteMapper::GeomSphere &&
836 aNumberOfPoints * myInsidePrimitiveBox->getFaceNumber() * 2 > myInsidePrimitiveBox->getFaceLimit() ||
837 myOutsidePrimitiveBox->getPrimitiveType() == VISU_OpenGLPointSpriteMapper::GeomSphere &&
838 aNumberOfPoints * myOutsidePrimitiveBox->getFaceNumber() > myOutsidePrimitiveBox->getFaceLimit() );