1 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License.
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // Lesser General Public License for more details.
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 // File : VVTK_SegmentationCursorDlg.cxx
21 // Author : Oleg Uvarov
24 #include "VVTK_SegmentationCursorDlg.h"
25 #include "VVTK_PrimitiveBox.h"
26 #include "VVTK_SizeBox.h"
28 #include "VISU_GaussPtsAct.h"
29 #include "VISU_GaussPtsSettings.h"
31 #include "VISU_WidgetCtrl.hxx"
32 #include "VISU_PlanesWidget.hxx"
33 #include "VISU_SphereWidget.hxx"
35 #include "VISU_GaussPointsPL.hxx"
36 #include "VISU_OpenGLPointSpriteMapper.hxx"
38 #include "LightApp_Application.h"
39 #include "SUIT_MessageBox.h"
40 #include "SUIT_ResourceMgr.h"
41 #include "SUIT_Session.h"
43 #include "SVTK_RenderWindowInteractor.h"
45 #include <vtkActorCollection.h>
46 #include <vtkCallbackCommand.h>
47 #include <vtkObjectFactory.h>
48 #include <vtkRenderer.h>
49 #include <vtkRenderWindowInteractor.h>
50 #include <vtkSmartPointer.h>
51 #include <vtkImageData.h>
53 #include "utilities.h"
55 #include <qbuttongroup.h>
56 #include <qcolordialog.h>
57 #include <qfiledialog.h>
58 #include <qgroupbox.h>
61 #include <qlineedit.h>
62 #include <qpushbutton.h>
63 #include <qradiobutton.h>
64 #include <qtabwidget.h>
67 #include "QtxAction.h"
68 #include "QtxDblSpinBox.h"
69 #include "QtxIntSpinBox.h"
71 //----------------------------------------------------------------
72 VVTK_SegmentationCursorDlg::VVTK_SegmentationCursorDlg( QWidget* parent, const char* name )
73 :QDialog( parent, name, false, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu ),
74 myEventCallbackCommand( vtkCallbackCommand::New() ),
75 myInsideCursorSettings( VISU_InsideCursorSettings::New() ),
76 myOutsideCursorSettings( VISU_OutsideCursorSettings::New() ),
77 myIsPlaneSegmentation( true ),
82 myEventCallbackCommand->Delete();
83 myEventCallbackCommand->SetClientData(this);
84 myEventCallbackCommand->SetCallback(VVTK_SegmentationCursorDlg::ProcessEvents);
86 myInsideCursorSettings->AddObserver(VISU::UpdateFromSettingsEvent,
87 myEventCallbackCommand.GetPointer(),
90 setCaption( tr( "SEGMENTATION_CURSOR_DLG_TITLE" ) );
91 setSizeGripEnabled(TRUE);
93 QVBoxLayout* TopLayout = new QVBoxLayout( this );
94 TopLayout->setSpacing(6);
95 TopLayout->setMargin(11);
97 myTabBox = new QTabWidget( this );
99 // Segmentation cursor pane
100 mySegmentationCursorBox = new QVBox( this );
101 mySegmentationCursorBox->setMargin(11);
102 mySegmentationCursorBox->setSpacing(6);
103 mySegmentationCursorBox->layout()->setAlignment(Qt::AlignTop);
106 myOriginGroup = new QGroupBox( tr( "ORIGIN_TITLE" ), mySegmentationCursorBox, "OriginGroup" );
107 myOriginGroup->setColumnLayout( 0, Qt::Vertical );
108 myOriginGroup->layout()->setSpacing( 0 );
109 myOriginGroup->layout()->setMargin( 0 );
111 QGridLayout* OriginGroupLayout = new QGridLayout( myOriginGroup->layout() );
112 OriginGroupLayout->setAlignment(Qt::AlignTop | Qt::AlignCenter);
113 OriginGroupLayout->setSpacing(6);
114 OriginGroupLayout->setMargin(11);
116 QLabel* XOriginLabel = new QLabel( tr( "ORIGIN_X" ), myOriginGroup );
117 myXOriginSpinBox = new QtxDblSpinBox( -1000.0, 1000.0, 0.1, myOriginGroup );
118 myXOriginSpinBox->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
119 myXOriginSpinBox->setMinimumWidth( 100 );
120 myXOriginSpinBox->setValue( 0.0 );
122 QLabel* YOriginLabel = new QLabel( tr( "ORIGIN_Y" ), myOriginGroup );
123 myYOriginSpinBox = new QtxDblSpinBox( -1000.0, 1000.0, 0.1, myOriginGroup );
124 myYOriginSpinBox->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
125 myYOriginSpinBox->setMinimumWidth( 100 );
126 myYOriginSpinBox->setValue( 0.0 );
128 QLabel* ZOriginLabel = new QLabel( tr( "ORIGIN_Z" ), myOriginGroup );
129 myZOriginSpinBox = new QtxDblSpinBox( -1000.0, 1000.0, 0.1, myOriginGroup );
130 //myZOriginSpinBox->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
131 myZOriginSpinBox->setMinimumWidth( 100 );
132 myZOriginSpinBox->setValue( 1.0 );
134 OriginGroupLayout->addWidget( XOriginLabel, 0, 0 );
135 OriginGroupLayout->addWidget( myXOriginSpinBox, 0, 1 );
136 OriginGroupLayout->addWidget( YOriginLabel, 0, 2 );
137 OriginGroupLayout->addWidget( myYOriginSpinBox, 0, 3 );
138 OriginGroupLayout->addWidget( ZOriginLabel, 0, 4 );
139 OriginGroupLayout->addWidget( myZOriginSpinBox, 0, 5 );
141 // Direction ( Plane Segmentation )
142 myDirectionGroup = new QGroupBox( tr( "DIRECTION_TITLE" ), mySegmentationCursorBox, "DirectionGroup" );
143 myDirectionGroup->setColumnLayout( 0, Qt::Vertical );
144 myDirectionGroup->layout()->setSpacing( 0 );
145 myDirectionGroup->layout()->setMargin( 0 );
147 QGridLayout* DirectionGroupLayout = new QGridLayout( myDirectionGroup->layout() );
148 DirectionGroupLayout->setAlignment(Qt::AlignTop | Qt::AlignCenter);
149 DirectionGroupLayout->setSpacing(6);
150 DirectionGroupLayout->setMargin(11);
152 QLabel* DXDirectionLabel = new QLabel( tr( "DIRECTION_DX" ), myDirectionGroup );
153 myDXDirectionSpinBox = new QtxDblSpinBox( -1.0, 1.0, 0.1, myDirectionGroup );
154 myDXDirectionSpinBox->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
155 myDXDirectionSpinBox->setMinimumWidth( 100 );
156 myDXDirectionSpinBox->setValue( 0.0 );
158 QLabel* DYDirectionLabel = new QLabel( tr( "DIRECTION_DY" ), myDirectionGroup );
159 myDYDirectionSpinBox = new QtxDblSpinBox( -1.0, 1.0, 0.1, myDirectionGroup );
160 myDYDirectionSpinBox->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
161 myDYDirectionSpinBox->setMinimumWidth( 100 );
162 myDYDirectionSpinBox->setValue( 0.0 );
164 QLabel* DZDirectionLabel = new QLabel( tr( "DIRECTION_DZ" ), myDirectionGroup );
165 myDZDirectionSpinBox = new QtxDblSpinBox( -1.0, 1.0, 0.1, myDirectionGroup );
166 myDZDirectionSpinBox->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
167 myDZDirectionSpinBox->setMinimumWidth( 100 );
168 myDZDirectionSpinBox->setValue( 1.0 );
170 DirectionGroupLayout->addWidget( DXDirectionLabel, 0, 0 );
171 DirectionGroupLayout->addWidget( myDXDirectionSpinBox, 0, 1 );
172 DirectionGroupLayout->addWidget( DYDirectionLabel, 0, 2 );
173 DirectionGroupLayout->addWidget( myDYDirectionSpinBox, 0, 3 );
174 DirectionGroupLayout->addWidget( DZDirectionLabel, 0, 4 );
175 DirectionGroupLayout->addWidget( myDZDirectionSpinBox, 0, 5 );
177 // Depth ( Plane Segmentation )
178 myDepthGroup = new QGroupBox( tr( "DEPTH_TITLE" ), mySegmentationCursorBox, "DepthGroup" );
179 myDepthGroup->setColumnLayout( 0, Qt::Vertical );
180 myDepthGroup->layout()->setSpacing( 0 );
181 myDepthGroup->layout()->setMargin( 0 );
183 QGridLayout* DepthGroupLayout = new QGridLayout( myDepthGroup->layout() );
184 DepthGroupLayout->setAlignment(Qt::AlignTop | Qt::AlignCenter);
185 DepthGroupLayout->setSpacing(6);
186 DepthGroupLayout->setMargin(11);
188 QLabel* DepthLabel = new QLabel( tr( "DEPTH" ), myDepthGroup );
189 myDepthSpinBox = new QtxDblSpinBox( 0.0, VTK_LARGE_FLOAT, 0.1, myDepthGroup );
190 myDepthSpinBox->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
191 myDepthSpinBox->setMinimumWidth( 100 );
192 myDepthSpinBox->setValue( 1.0 );
194 DepthGroupLayout->addWidget( DepthLabel, 0, 0 );
195 DepthGroupLayout->addWidget( myDepthSpinBox, 0, 1 );
197 // Radius ( Sphere Segmentation )
198 myRadiusGroup = new QGroupBox( tr( "RADIUS_TITLE" ), mySegmentationCursorBox, "RadiusGroup" );
199 myRadiusGroup->setColumnLayout( 0, Qt::Vertical );
200 myRadiusGroup->layout()->setSpacing( 0 );
201 myRadiusGroup->layout()->setMargin( 0 );
203 QGridLayout* RadiusGroupLayout = new QGridLayout( myRadiusGroup->layout() );
204 RadiusGroupLayout->setAlignment(Qt::AlignTop | Qt::AlignCenter);
205 RadiusGroupLayout->setSpacing(6);
206 RadiusGroupLayout->setMargin(11);
208 QLabel* RadiusLabel = new QLabel( tr( "RADIUS" ),myRadiusGroup );
209 myRadiusSpinBox = new QtxDblSpinBox( 0.0, 1000.0, 1.0,myRadiusGroup );
210 myRadiusSpinBox->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
211 myRadiusSpinBox->setMinimumWidth( 100 );
212 myRadiusSpinBox->setValue( 100.0 );
214 QLabel* RatioLabel = new QLabel( tr( "RATIO" ), myRadiusGroup );
215 myRatioSpinBox = new QtxDblSpinBox( 0.1, 10.0, 0.1,myRadiusGroup );
216 myRatioSpinBox->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
217 myRatioSpinBox->setMinimumWidth( 100 );
218 myRatioSpinBox->setValue( 2.0 );
220 RadiusGroupLayout->addWidget( RadiusLabel, 0, 0 );
221 RadiusGroupLayout->addWidget( myRadiusSpinBox, 0, 1 );
222 RadiusGroupLayout->addWidget( RatioLabel, 0, 2 );
223 RadiusGroupLayout->addWidget( myRatioSpinBox, 0, 3 );
226 myTabBox->addTab( mySegmentationCursorBox, tr( "SEGMENTATION_CURSOR_TAB" ) );
230 myGaussPointsBox = new QVBox( this );
231 myGaussPointsBox->setMargin(11);
232 myGaussPointsBox->setSpacing(6);
234 // Inside Gauss points
235 QGroupBox* anInsideGroup = new QGroupBox( tr( "INSIDE_GAUSS_POINTS" ), myGaussPointsBox );
236 anInsideGroup->setColumnLayout( 0, Qt::Vertical );
237 anInsideGroup->layout()->setSpacing( 0 );
238 anInsideGroup->layout()->setMargin( 0 );
240 QGridLayout* anInsideGroupLayout = new QGridLayout( anInsideGroup->layout() );
241 anInsideGroupLayout->setAlignment(Qt::AlignTop | Qt::AlignCenter);
242 anInsideGroupLayout->setSpacing(6);
243 anInsideGroupLayout->setMargin(11);
246 myInsidePrimitiveBox = new VVTK_PrimitiveBox( anInsideGroup );
249 myInsideSizeBox = new VVTK_SizeBox( anInsideGroup );
250 myInsideSizeBox->setType( VVTK_SizeBox::Inside );
252 anInsideGroupLayout->addWidget( myInsidePrimitiveBox, 0, 0 );
253 anInsideGroupLayout->addWidget( myInsideSizeBox, 1, 0 );
255 // Outside Gauss points
256 QGroupBox* anOutsideGroup = new QGroupBox( tr( "OUTSIDE_GAUSS_POINTS" ), myGaussPointsBox );
257 anOutsideGroup->setColumnLayout( 0, Qt::Vertical );
258 anOutsideGroup->layout()->setSpacing( 0 );
259 anOutsideGroup->layout()->setMargin( 0 );
261 QGridLayout* anOutsideGroupLayout = new QGridLayout( anOutsideGroup->layout() );
262 anOutsideGroupLayout->setAlignment(Qt::AlignTop | Qt::AlignCenter);
263 anOutsideGroupLayout->setSpacing(6);
264 anOutsideGroupLayout->setMargin(11);
267 myOutsidePrimitiveBox = new VVTK_PrimitiveBox( anOutsideGroup );
270 myOutsideSizeBox = new VVTK_SizeBox( anOutsideGroup );
271 myOutsideSizeBox->setType( VVTK_SizeBox::Outside );
273 anOutsideGroupLayout->addWidget( myOutsidePrimitiveBox, 0, 0 );
274 anOutsideGroupLayout->addWidget( myOutsideSizeBox, 1, 0 );
278 QGroupBox* MagnificationGroup = new QGroupBox ( tr( "MAGNIFICATION_TITLE" ), myGaussPointsBox, "MagnificationGroup" );
279 MagnificationGroup->setColumnLayout(0, Qt::Vertical );
280 MagnificationGroup->layout()->setSpacing( 0 );
281 MagnificationGroup->layout()->setMargin( 0 );
283 QGridLayout* MagnificationGroupLayout = new QGridLayout (MagnificationGroup->layout());
284 MagnificationGroupLayout->setAlignment(Qt::AlignTop | Qt::AlignCenter);
285 MagnificationGroupLayout->setSpacing(6);
286 MagnificationGroupLayout->setMargin(11);
288 myMagnificationLabel = new QLabel( tr( "MAGNIFICATION" ), MagnificationGroup );
289 myMagnificationSpinBox = new QtxIntSpinBox( 1, 10000, 10, MagnificationGroup );
290 myMagnificationSpinBox->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
292 MagnificationGroupLayout->addWidget( myMagnificationLabel, 0, 0 );
293 MagnificationGroupLayout->addWidget( myMagnificationSpinBox, 0, 1 );
296 myIncrementLabel = new QLabel( tr( "INCREMENT" ), MagnificationGroup );
297 myIncrementSpinBox = new QtxDblSpinBox( 0.01, 10, 0.1, MagnificationGroup );
298 myIncrementSpinBox->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
300 MagnificationGroupLayout->addWidget( myIncrementLabel, 0, 2 );
301 MagnificationGroupLayout->addWidget( myIncrementSpinBox, 0, 3 );
304 myTabBox->addTab( myGaussPointsBox, tr( "GAUSS_POINTS_TAB" ) );
305 myTabBox->showPage( myGaussPointsBox );
308 // Common buttons ===========================================================
309 QGroupBox* GroupButtons = new QGroupBox( this, "GroupButtons" );
310 GroupButtons->setColumnLayout(0, Qt::Vertical );
311 GroupButtons->layout()->setSpacing( 0 );
312 GroupButtons->layout()->setMargin( 0 );
313 QGridLayout* GroupButtonsLayout = new QGridLayout( GroupButtons->layout() );
314 GroupButtonsLayout->setAlignment( Qt::AlignTop );
315 GroupButtonsLayout->setSpacing( 6 );
316 GroupButtonsLayout->setMargin( 11 );
318 QPushButton* buttonApply = new QPushButton( tr( "&Apply" ), GroupButtons, "buttonApply" );
319 buttonApply->setAutoDefault( TRUE );
320 buttonApply->setDefault( TRUE );
321 GroupButtonsLayout->addWidget( buttonApply, 0, 0 );
322 GroupButtonsLayout->addItem( new QSpacerItem( 5, 5, QSizePolicy::Expanding, QSizePolicy::Minimum ), 0, 1 );
324 QPushButton* buttonClose = new QPushButton( tr( "&Close" ) , GroupButtons, "buttonClose" );
325 buttonClose->setAutoDefault( TRUE );
326 GroupButtonsLayout->addWidget( buttonClose, 0, 2 );
328 QPushButton* buttonHelp = new QPushButton( tr( "&Help" ) , GroupButtons, "buttonHelp" );
329 buttonHelp->setAutoDefault( TRUE );
330 GroupButtonsLayout->addWidget( buttonHelp, 0, 3 );
332 TopLayout->addWidget( myTabBox );
333 TopLayout->addWidget( GroupButtons );
335 connect( buttonApply, SIGNAL( clicked() ), this, SLOT( onClickApply() ) );
336 connect( buttonClose, SIGNAL( clicked() ), this, SLOT( onClickClose() ) );
337 connect( buttonHelp, SIGNAL( clicked() ), this, SLOT( onClickHelp() ) );
339 connect(parent, SIGNAL(Show( QShowEvent * )), this, SLOT(onParentShow()));
340 connect(parent, SIGNAL(Hide( QHideEvent * )), this, SLOT(onParentHide()));
343 VVTK_SegmentationCursorDlg::~VVTK_SegmentationCursorDlg()
348 float VVTK_SegmentationCursorDlg::getMagnification() const
350 return myMagnificationSpinBox->value() / 100.0;
353 void VVTK_SegmentationCursorDlg::setMagnification( float theMagnification )
355 myMagnificationSpinBox->setValue( ( int )( theMagnification * 100 ) );
358 float VVTK_SegmentationCursorDlg::getIncrement() const
360 return myIncrementSpinBox->value();
363 void VVTK_SegmentationCursorDlg::setIncrement( float theIncrement )
365 myIncrementSpinBox->setValue( theIncrement );
369 void VVTK_SegmentationCursorDlg::SetWidgetCtrl( VISU_WidgetCtrl* theWidgetCtrl )
371 if(myWidgetCtrl == theWidgetCtrl)
375 myWidgetCtrl->RemoveObserver(myEventCallbackCommand.GetPointer());
377 myWidgetCtrl = theWidgetCtrl;
380 theWidgetCtrl->AddObserver(vtkCommand::EndInteractionEvent,
381 myEventCallbackCommand.GetPointer(),
385 void VVTK_SegmentationCursorDlg::ProcessEvents(vtkObject* vtkNotUsed(theObject),
386 unsigned long theEvent,
388 void* vtkNotUsed(theCallData))
390 VVTK_SegmentationCursorDlg* self = reinterpret_cast<VVTK_SegmentationCursorDlg*>(theClientData);
393 case vtkCommand::EndInteractionEvent:
394 self->UpdateSegmentation();
396 case VISU::UpdateFromSettingsEvent:
397 self->GetOutsideCursorSettings()->SetMagnification( self->GetInsideCursorSettings()->GetMagnification() );
398 self->GetOutsideCursorSettings()->SetIncrement( self->GetInsideCursorSettings()->GetIncrement() );
400 self->UpdateInsideGaussPoints();
401 self->UpdateOutsideGaussPoints();
403 self->GetInsideCursorSettings()->InvokeEvent(VISU::UpdateInsideSettingsEvent,NULL);
404 self->GetOutsideCursorSettings()->InvokeEvent(VISU::UpdateOutsideSettingsEvent,NULL);
409 void VVTK_SegmentationCursorDlg::UpdateSegmentation()
411 if( myIsPlaneSegmentation )
413 myDirectionGroup->show();
414 myDepthGroup->show();
415 myRadiusGroup->hide();
417 VISU_PlanesWidget *pPlanesWidget=myWidgetCtrl->GetPlanesWidget();
418 vtkFloatingPointType origin[3];
419 pPlanesWidget->GetOrigin( origin );
420 myXOriginSpinBox->setValue( origin[0] );
421 myYOriginSpinBox->setValue( origin[1] );
422 myZOriginSpinBox->setValue( origin[2] );
424 vtkFloatingPointType normal[3];
425 pPlanesWidget->GetNormal( normal );
426 myDXDirectionSpinBox->setValue( normal[0] );
427 myDYDirectionSpinBox->setValue( normal[1] );
428 myDZDirectionSpinBox->setValue( normal[2] );
430 myDepthSpinBox->setValue( pPlanesWidget->Distance() );
434 myDirectionGroup->hide();
435 myDepthGroup->hide();
436 myRadiusGroup->show();
438 VISU_SphereWidget *pSphereWidget=myWidgetCtrl->GetSphereWidget();
439 vtkFloatingPointType origin[3], aRadius;
440 pSphereWidget->GetCenter(origin);
441 myXOriginSpinBox->setValue( origin[0] );
442 myYOriginSpinBox->setValue( origin[1] );
443 myZOriginSpinBox->setValue( origin[2] );
444 aRadius=pSphereWidget->GetRadius();
445 myRadiusSpinBox->setValue(aRadius);
446 myRatioSpinBox->setValue(pSphereWidget->GetRatio());
450 void VVTK_SegmentationCursorDlg::UpdateInsideGaussPoints()
452 int aPrimitiveType = VISU_OpenGLPointSpriteMapper::PointSprite;
453 vtkFloatingPointType aClamp = 200.0;
454 QString aMainTexture = QString( getenv( "VISU_ROOT_DIR") ) + "/share/salome/resources/visu/sprite_texture.bmp";
455 QString anAlphaTexture = QString( getenv( "VISU_ROOT_DIR") ) + "/share/salome/resources/visu/sprite_alpha.bmp";
456 vtkFloatingPointType anAlphaThreshold = 0.1;
460 int aMagnification = 100;
461 vtkFloatingPointType anIncrement = 2.0;
463 if( !myInsideCursorSettings->GetInitial() )
465 myInsidePrimitiveBox->setPrimitiveType( myInsideCursorSettings->GetPrimitiveType() );
466 myInsidePrimitiveBox->setClamp( myInsideCursorSettings->GetClamp() );
467 myInsidePrimitiveBox->setMainTexture( myInsideMainTexture );
468 myInsidePrimitiveBox->setAlphaTexture( myInsideAlphaTexture );
469 myInsidePrimitiveBox->setAlphaThreshold( myInsideCursorSettings->GetAlphaThreshold() );
470 myInsidePrimitiveBox->setResolution( myInsideCursorSettings->GetResolution() );
472 myInsideSizeBox->setMinSize( myInsideCursorSettings->GetMinSize() );
473 myInsideSizeBox->setMaxSize( myInsideCursorSettings->GetMaxSize() );
475 this->setMagnification( myInsideCursorSettings->GetMagnification() );
476 this->setIncrement( myInsideCursorSettings->GetIncrement() );
481 SUIT_ResourceMgr* aResourceMgr = SUIT_Session::session()->resourceMgr();
483 aPrimitiveType = aResourceMgr->integerValue( "VISU", "inside_point_sprite_primitive_type", aPrimitiveType );
484 myInsidePrimitiveBox->setPrimitiveType( aPrimitiveType );
486 aClamp = aResourceMgr->doubleValue( "VISU", "inside_point_sprite_clamp", aClamp );
487 myInsidePrimitiveBox->setClamp( aClamp );
489 aMainTexture = aResourceMgr->stringValue( "VISU", "inside_point_sprite_main_texture", aMainTexture );
490 myInsidePrimitiveBox->setMainTexture( aMainTexture );
492 anAlphaTexture = aResourceMgr->stringValue( "VISU", "inside_point_sprite_alpha_texture", anAlphaTexture );
493 myInsidePrimitiveBox->setAlphaTexture( anAlphaTexture );
495 anAlphaThreshold = aResourceMgr->doubleValue( "VISU", "inside_point_sprite_alpha_threshold", anAlphaThreshold );
496 myInsidePrimitiveBox->setAlphaThreshold( anAlphaThreshold );
498 aResolution = aResourceMgr->integerValue( "VISU", "inside_geom_sphere_resolution", aResolution );
499 myInsidePrimitiveBox->setResolution( aResolution );
501 aMinSize = aResourceMgr->integerValue( "VISU", "inside_point_sprite_min_size", aMinSize );
502 myInsideSizeBox->setMinSize( aMinSize / 100.0 );
504 aMaxSize = aResourceMgr->integerValue( "VISU", "inside_point_sprite_max_size", aMaxSize );
505 myInsideSizeBox->setMaxSize( aMaxSize / 100.0 );
507 aMagnification = aResourceMgr->integerValue( "VISU", "inside_point_sprite_magnification", aMagnification );
508 this->setMagnification( aMagnification / 100.0 );
510 anIncrement = aResourceMgr->doubleValue( "VISU", "inside_point_sprite_increment", anIncrement );
511 this->setIncrement( anIncrement );
513 myInsidePrimitiveBox->setFaceLimit( 50000 );
515 ApplyInsideGaussPoints();
518 void VVTK_SegmentationCursorDlg::UpdateOutsideGaussPoints()
520 vtkFloatingPointType aClamp = 256.0;
521 int aPrimitiveType = VISU_OpenGLPointSpriteMapper::PointSprite;
522 QString aMainTexture = QString( getenv( "VISU_ROOT_DIR") ) + "/share/salome/resources/visu/sprite_texture.bmp";
523 QString anAlphaTexture = QString( getenv( "VISU_ROOT_DIR") ) + "/share/salome/resources/visu/sprite_alpha.bmp";
524 vtkFloatingPointType anAlphaThreshold = 0.1;
527 bool aUniform = false;
528 QColor aColor = Qt::blue;
530 if( !myOutsideCursorSettings->GetInitial() )
532 myOutsidePrimitiveBox->setPrimitiveType( myOutsideCursorSettings->GetPrimitiveType() );
533 myOutsidePrimitiveBox->setClamp( myOutsideCursorSettings->GetClamp() );
534 myOutsidePrimitiveBox->setMainTexture( myOutsideMainTexture );
535 myOutsidePrimitiveBox->setAlphaTexture( myOutsideAlphaTexture );
536 myOutsidePrimitiveBox->setAlphaThreshold( myOutsideCursorSettings->GetAlphaThreshold() );
537 myOutsidePrimitiveBox->setResolution( myOutsideCursorSettings->GetResolution() );
539 myOutsideSizeBox->setOutsideSize( myOutsideCursorSettings->GetSize() );
540 myOutsideSizeBox->setUniform( myOutsideCursorSettings->GetUniform() );
542 vtkFloatingPointType* aColor = myOutsideCursorSettings->GetColor();
543 myOutsideSizeBox->setColor( QColor( ( int )( aColor[0] * 255.0 ),
544 ( int )( aColor[1] * 255.0 ),
545 ( int )( aColor[2] * 255.0 ) ) );
550 SUIT_ResourceMgr* aResourceMgr = SUIT_Session::session()->resourceMgr();
552 aPrimitiveType = aResourceMgr->integerValue( "VISU", "outside_point_sprite_primitive_type", aPrimitiveType );
553 myOutsidePrimitiveBox->setPrimitiveType( aPrimitiveType );
555 aClamp = aResourceMgr->doubleValue( "VISU", "outside_point_sprite_clamp", aClamp );
556 myOutsidePrimitiveBox->setClamp( aClamp );
558 aMainTexture = aResourceMgr->stringValue( "VISU", "outside_point_sprite_main_texture", aMainTexture );
559 myOutsidePrimitiveBox->setMainTexture( aMainTexture );
561 anAlphaTexture = aResourceMgr->stringValue( "VISU", "outside_point_sprite_alpha_texture", anAlphaTexture );
562 myOutsidePrimitiveBox->setAlphaTexture( anAlphaTexture );
564 anAlphaThreshold = aResourceMgr->doubleValue( "VISU", "outside_point_sprite_alpha_threshold", anAlphaThreshold );
565 myOutsidePrimitiveBox->setAlphaThreshold( anAlphaThreshold );
567 aResolution = aResourceMgr->integerValue( "VISU", "outside_geom_sphere_resolution", aResolution );
568 myOutsidePrimitiveBox->setResolution( aResolution );
570 aSize = aResourceMgr->integerValue( "VISU", "outside_point_sprite_size", aSize );
571 myOutsideSizeBox->setOutsideSize( aSize / 100.0 );
573 aUniform = aResourceMgr->booleanValue( "VISU", "outside_point_sprite_uniform", aUniform );
574 myOutsideSizeBox->setUniform( aUniform );
576 aColor = aResourceMgr->colorValue( "VISU", "outside_point_sprite_color", aColor );
577 myOutsideSizeBox->setColor( aColor );
579 myOutsidePrimitiveBox->setFaceLimit( 50000 );
581 ApplyOutsideGaussPoints();
584 VISU_InsideCursorSettings* VVTK_SegmentationCursorDlg::GetInsideCursorSettings()
586 return myInsideCursorSettings.GetPointer();
589 VISU_OutsideCursorSettings* VVTK_SegmentationCursorDlg::GetOutsideCursorSettings()
591 return myOutsideCursorSettings.GetPointer();
595 VVTK_SegmentationCursorDlg
596 ::MakeImageData( bool theInside,
597 const QString& theMainTexture,
598 const QString& theAlphaTexture )
602 bool updateMainTexture = myInsideMainTexture != theMainTexture;
603 bool updateAlphaTexture = myInsideAlphaTexture != theAlphaTexture;
604 if( !updateMainTexture && !updateAlphaTexture )
607 myInsideMainTexture = theMainTexture;
608 myInsideAlphaTexture = theAlphaTexture;
612 bool updateMainTexture = myOutsideMainTexture != theMainTexture;
613 bool updateAlphaTexture = myOutsideAlphaTexture != theAlphaTexture;
614 if( !updateMainTexture && !updateAlphaTexture )
617 myOutsideMainTexture = theMainTexture;
618 myOutsideAlphaTexture = theAlphaTexture;
621 return VISU::GetTexture( theMainTexture.latin1(),
622 theAlphaTexture.latin1());
625 void VVTK_SegmentationCursorDlg::onClickApply()
627 if( myTabBox->currentPage() == mySegmentationCursorBox )
628 ApplySegmentationCursor();
631 QString aWarning = "The number of faces needed to perform the 'Geometrical Sphere' primitive\n";
632 aWarning.append( "presentation might be too important to ensure an acceptable frame rate.\n\n" );
633 aWarning.append( "Can you please confirm that you want to continue anyway?" );
634 bool toApply = CheckNumberOfFaces() ||
635 SUIT_MessageBox::warn2( this, tr( "Warning" ), aWarning,
636 tr( "&OK" ), tr( "&Cancel" ), 0, 1, 1 ) == 0;
640 ApplyInsideGaussPoints();
641 ApplyOutsideGaussPoints();
646 void VVTK_SegmentationCursorDlg::ApplySegmentationCursor()
648 if( myIsPlaneSegmentation )
650 VISU_PlanesWidget *pPlanesWidget=myWidgetCtrl->GetPlanesWidget();
651 vtkFloatingPointType origin[3];
652 origin[0] = myXOriginSpinBox->value();
653 origin[1] = myYOriginSpinBox->value();
654 origin[2] = myZOriginSpinBox->value();
655 pPlanesWidget->SetOrigin( origin );
657 vtkFloatingPointType normal[3];
658 normal[0] = myDXDirectionSpinBox->value();
659 normal[1] = myDYDirectionSpinBox->value();
660 normal[2] = myDZDirectionSpinBox->value();
662 if( normal[0] == 0.0 && normal[1] == 0.0 && normal[2] == 0.0 )
665 myDZDirectionSpinBox->setValue( 1.0 );
667 pPlanesWidget->SetNormal( normal );
669 pPlanesWidget->SetDistance( myDepthSpinBox->value() );
671 myWidgetCtrl->InvokeEvent(vtkCommand::EndInteractionEvent,NULL);
672 myWidgetCtrl->GetInteractor()->Render();
676 VISU_SphereWidget *pSphereWidget=myWidgetCtrl->GetSphereWidget();
677 vtkFloatingPointType origin[3], aRadius;
678 origin[0] = myXOriginSpinBox->value();
679 origin[1] = myYOriginSpinBox->value();
680 origin[2] = myZOriginSpinBox->value();
681 pSphereWidget->SetCenter(origin);
683 aRadius=myRadiusSpinBox->value();
684 pSphereWidget->SetRadius(aRadius);
686 pSphereWidget->SetRatio(myRatioSpinBox->value());
688 myWidgetCtrl->InvokeEvent(vtkCommand::EndInteractionEvent,NULL);
689 myWidgetCtrl->GetInteractor()->Render();
693 void VVTK_SegmentationCursorDlg::ApplyInsideGaussPoints()
695 QString anInsideMainTexture = myInsidePrimitiveBox->getMainTexture();
696 QString anInsideAlphaTexture = myInsidePrimitiveBox->getAlphaTexture();
697 VISU::TTextureValue aTexture = MakeImageData( true, anInsideMainTexture, anInsideAlphaTexture );
699 if( aTexture.GetPointer() )
700 myInsideCursorSettings->SetTexture( aTexture.GetPointer() );
702 myInsideCursorSettings->SetInitial( false );
703 myInsideCursorSettings->SetPrimitiveType( myInsidePrimitiveBox->getPrimitiveType() );
704 myInsideCursorSettings->SetClamp( myInsidePrimitiveBox->getClamp() );
705 myInsideCursorSettings->SetAlphaThreshold( myInsidePrimitiveBox->getAlphaThreshold() );
706 myInsideCursorSettings->SetResolution( myInsidePrimitiveBox->getResolution() );
708 myInsideCursorSettings->SetMinSize( myInsideSizeBox->getMinSize() );
709 myInsideCursorSettings->SetMaxSize( myInsideSizeBox->getMaxSize() );
711 myInsideCursorSettings->SetMagnification( this->getMagnification() );
712 myInsideCursorSettings->SetIncrement( this->getIncrement() );
714 myInsideCursorSettings->InvokeEvent(VISU::UpdateInsideSettingsEvent,NULL);
717 void VVTK_SegmentationCursorDlg::ApplyOutsideGaussPoints()
719 QString anOutsideMainTexture = myOutsidePrimitiveBox->getMainTexture();
720 QString anOutsideAlphaTexture = myOutsidePrimitiveBox->getAlphaTexture();
721 VISU::TTextureValue aTexture = MakeImageData( false, anOutsideMainTexture, anOutsideAlphaTexture );
723 if( aTexture.GetPointer() )
724 myOutsideCursorSettings->SetTexture( aTexture.GetPointer() );
726 myOutsideCursorSettings->SetInitial( false );
727 myOutsideCursorSettings->SetPrimitiveType( myOutsidePrimitiveBox->getPrimitiveType() );
728 myOutsideCursorSettings->SetClamp( myOutsidePrimitiveBox->getClamp() );
729 myOutsideCursorSettings->SetAlphaThreshold( myOutsidePrimitiveBox->getAlphaThreshold() );
730 myOutsideCursorSettings->SetResolution( myOutsidePrimitiveBox->getResolution() );
732 myOutsideCursorSettings->SetSize( myOutsideSizeBox->getOutsideSize() );
733 myOutsideCursorSettings->SetUniform( myOutsideSizeBox->getUniform() );
735 QColor aButtonColor = myOutsideSizeBox->getColor();
736 vtkFloatingPointType aColor[3];
737 aColor[0] = aButtonColor.red() / 255.0;
738 aColor[1] = aButtonColor.green() / 255.0;
739 aColor[2] = aButtonColor.blue() / 255.0;
740 myOutsideCursorSettings->SetColor( aColor );
742 myOutsideCursorSettings->SetMagnification( this->getMagnification() );
743 myOutsideCursorSettings->SetIncrement( this->getIncrement() );
745 myOutsideCursorSettings->InvokeEvent(VISU::UpdateOutsideSettingsEvent,NULL);
748 void VVTK_SegmentationCursorDlg::onClickClose()
750 myPlaneAction->setOn( false );
751 mySphereAction->setOn( false );
758 void VVTK_SegmentationCursorDlg::onClickHelp()
760 QString aHelpFileName = "segmentation.htm";
761 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
763 app->onHelpContextModule(app->activeModule() ? app->moduleName(app->activeModule()->moduleName()) : QString(""), aHelpFileName);
767 platform = "winapplication";
769 platform = "application";
771 SUIT_MessageBox::warn1(0, QObject::tr("WRN_WARNING"),
772 QObject::tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
773 arg(app->resourceMgr()->stringValue("ExternalBrowser", platform)).arg(aHelpFileName),
774 QObject::tr("BUT_OK"));
778 void VVTK_SegmentationCursorDlg::done( int r )
780 myPlaneAction->setOn( false );
781 mySphereAction->setOn( false );
788 void VVTK_SegmentationCursorDlg::onParentShow()
790 if(myPlaneAction->isOn() || mySphereAction->isOn())
796 void VVTK_SegmentationCursorDlg::onParentHide()
801 bool VVTK_SegmentationCursorDlg::CheckNumberOfFaces()
806 vtkRenderer* aRenderer = myInteractor->getRenderer();
811 int aNumberOfPoints = 0;
814 vtkActorCollection* anActColl = aRenderer->GetActors();
815 for( anActColl->InitTraversal(); ( anActor = anActColl->GetNextActor() ) != NULL; )
817 if( VISU_GaussPtsAct1* aGaussActor = VISU_GaussPtsAct1::SafeDownCast( anActor ) )
818 aNumberOfPoints += aGaussActor->GetInput()->GetNumberOfCells();
820 return !( myInsidePrimitiveBox->getPrimitiveType() == VISU_OpenGLPointSpriteMapper::GeomSphere &&
821 aNumberOfPoints * myInsidePrimitiveBox->getFaceNumber() * 2 > myInsidePrimitiveBox->getFaceLimit() ||
822 myOutsidePrimitiveBox->getPrimitiveType() == VISU_OpenGLPointSpriteMapper::GeomSphere &&
823 aNumberOfPoints * myOutsidePrimitiveBox->getFaceNumber() > myOutsidePrimitiveBox->getFaceLimit() );
826 void VVTK_SegmentationCursorDlg::keyPressEvent( QKeyEvent* e )
828 QDialog::keyPressEvent( e );
829 if ( e->isAccepted() )
832 if ( e->key() == Key_F1 )