1 // Copyright (C) 2007-2015 CEA/DEN, EDF R&D, OPEN CASCADE
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 // SALOME VTKViewer : build VTK viewer into Salome desktop
24 #include "SVTK_ViewParameterDlg.h"
25 #include "SVTK_ViewWindow.h"
26 #include "SVTK_RenderWindowInteractor.h"
27 #include "SVTK_Event.h"
28 #include "SVTK_InteractorStyle.h"
30 #include "VTKViewer_Utilities.h"
32 #include "QtxAction.h"
37 #include <QPushButton>
38 #include <QGridLayout>
39 #include <QDoubleValidator>
41 #include <QRadioButton>
42 #include <QButtonGroup>
44 #include <vtkCallbackCommand.h>
45 #include <vtkRenderer.h>
46 #include <vtkCamera.h>
47 #include <vtkGenericRenderWindowInteractor.h>
52 SVTK_ViewParameterDlg::SVTK_ViewParameterDlg(QtxAction* theAction,
53 SVTK_ViewWindow* theParent,
55 ViewerTools_DialogBase(theAction, theParent, theName),
56 myMainWindow(theParent),
58 myEventCallbackCommand(vtkCallbackCommand::New()),
59 myRWInteractor(theParent->GetInteractor())
61 setWindowTitle(tr("DLG_TITLE"));
62 setSizeGripEnabled(TRUE);
65 QVBoxLayout* aTopLayout = new QVBoxLayout(this);
66 aTopLayout->setSpacing(6);
67 aTopLayout->setMargin(11);
70 QGroupBox* aGroupBoxMode = new QGroupBox(tr("PROJECTION_MODE"), this);
71 QHBoxLayout* aLayout1 = new QHBoxLayout(aGroupBoxMode);
73 QRadioButton* aOrtho = new QRadioButton(tr("ORTHOGONAL_MODE"), aGroupBoxMode);
74 QRadioButton* aPersp = new QRadioButton(tr("PERSPECTIVE_MODE"), aGroupBoxMode);
76 aLayout1->addWidget(aOrtho);
77 aLayout1->addWidget(aPersp);
79 myProjectionMode = new QButtonGroup(aGroupBoxMode);
80 myProjectionMode->addButton(aOrtho, 0);
81 myProjectionMode->addButton(aPersp, 1);
82 connect(myProjectionMode, SIGNAL(buttonClicked(int)), SLOT(onProjectionModeChanged(int)));
85 QGroupBox* aGroupBoxFocal = new QGroupBox(tr("FOCAL_POINT"), this);
86 QVBoxLayout* aLayout2 = new QVBoxLayout(aGroupBoxFocal);
88 myToBBCenter = new QPushButton(aGroupBoxFocal);
89 myToBBCenter->setText(tr("LBL_TOBBCENTER"));
90 aLayout2->addWidget(myToBBCenter);
91 connect(myToBBCenter, SIGNAL(clicked()), this, SLOT(onToBBCenter()));
93 myToOrigin = new QPushButton(aGroupBoxFocal);
94 myToOrigin->setText(tr("LBL_TOORIGIN"));
95 aLayout2->addWidget(myToOrigin);
96 connect(myToOrigin, SIGNAL(clicked()), this, SLOT(onToOrigin()));
98 mySelectPoint = new QPushButton(aGroupBoxFocal);
99 mySelectPoint->setText(tr("LBL_SELECTPOINT"));
100 mySelectPoint->setCheckable(true);
101 aLayout2->addWidget(mySelectPoint);
102 connect(mySelectPoint, SIGNAL(clicked()), this, SLOT(onSelectPoint()));
104 // Focal point coordinates
105 myFocalCoords = new QFrame(aGroupBoxFocal);
106 myFocalCoords->setObjectName("FocalPointCoordinates");
108 QHBoxLayout* aCoordLayout = new QHBoxLayout(myFocalCoords);
109 aCoordLayout->setSpacing(6);
110 aCoordLayout->setMargin(0);
112 QLabel* aLabelX = new QLabel(tr("LBL_X"), myFocalCoords);
113 aLabelX->setFixedWidth(25);
114 myFocalX = new QLineEdit(myFocalCoords);
115 myFocalX->setValidator(new QDoubleValidator(myFocalX));
116 myFocalX->setText(QString::number(0.0));
117 connect(myFocalX, SIGNAL(textChanged(const QString&)), SLOT(onFocalCoordChanged()));
119 QLabel* aLabelY = new QLabel(tr("LBL_Y"), myFocalCoords);
120 aLabelY->setFixedWidth(25);
121 myFocalY = new QLineEdit(myFocalCoords);
122 myFocalY->setValidator(new QDoubleValidator(myFocalY));
123 myFocalY->setText(QString::number(0.0));
124 connect(myFocalY, SIGNAL(textChanged(const QString&)), SLOT(onFocalCoordChanged()));
126 QLabel* aLabelZ = new QLabel(tr("LBL_Z"), myFocalCoords);
127 aLabelZ->setFixedWidth(25);
128 myFocalZ = new QLineEdit(myFocalCoords);
129 myFocalZ->setValidator(new QDoubleValidator(myFocalZ));
130 myFocalZ->setText(QString::number(0.0));
131 connect(myFocalZ, SIGNAL(textChanged(const QString&)), SLOT(onFocalCoordChanged()));
133 aCoordLayout->addWidget(aLabelX);
134 aCoordLayout->addWidget(myFocalX);
135 aCoordLayout->addWidget(aLabelY);
136 aCoordLayout->addWidget(myFocalY);
137 aCoordLayout->addWidget(aLabelZ);
138 aCoordLayout->addWidget(myFocalZ);
139 aLayout2->addWidget(myFocalCoords);
142 QGroupBox* aGroupBoxCamera = new QGroupBox(tr("CAMERA_POSITION"), this);
143 QVBoxLayout* aLayout3 = new QVBoxLayout(aGroupBoxCamera);
145 QRadioButton* aWorld = new QRadioButton(tr("WORLD_COORDINATES"), aGroupBoxCamera);
146 QRadioButton* aRelative = new QRadioButton(tr("FOCAL_RELATIVE"), aGroupBoxCamera);
148 QHBoxLayout* aHLayout = new QHBoxLayout;
149 aHLayout->addWidget(aWorld);
150 aHLayout->addWidget(aRelative);
151 aLayout3->addLayout(aHLayout);
153 myCameraPositionMode = new QButtonGroup(aGroupBoxCamera);
154 myCameraPositionMode->addButton(aWorld, 0);
155 myCameraPositionMode->addButton(aRelative, 1);
156 connect(myCameraPositionMode, SIGNAL(buttonClicked(int)), SLOT(onPositionModeChanged(int)));
158 // Camera coordinates
159 myCameraCoords = new QFrame(aGroupBoxCamera);
160 myCameraCoords->setObjectName("CameraCoordinates");
162 aCoordLayout = new QHBoxLayout(myCameraCoords);
163 aCoordLayout->setSpacing(6);
164 aCoordLayout->setMargin(0);
166 aLabelX = new QLabel(tr("LBL_X"), myCameraCoords);
167 aLabelX->setFixedWidth(25);
168 myCameraX = new QLineEdit(myCameraCoords);
169 myCameraX->setValidator(new QDoubleValidator(myCameraX));
170 myCameraX->setText(QString::number(0.0));
171 connect(myCameraX, SIGNAL(textChanged(const QString&)), SLOT(onCameraCoordChanged()));
173 aLabelY = new QLabel(tr("LBL_Y"), myCameraCoords);
174 aLabelY->setFixedWidth(25);
175 myCameraY = new QLineEdit(myCameraCoords);
176 myCameraY->setValidator(new QDoubleValidator(myCameraY));
177 myCameraY->setText(QString::number(0.0));
178 connect(myCameraY, SIGNAL(textChanged(const QString&)), SLOT(onCameraCoordChanged()));
180 aLabelZ = new QLabel(tr("LBL_Z"), myCameraCoords);
181 aLabelZ->setFixedWidth(25);
182 myCameraZ = new QLineEdit(myCameraCoords);
183 myCameraZ->setValidator(new QDoubleValidator(myCameraZ));
184 myCameraZ->setText(QString::number(1.0));
185 connect(myCameraZ, SIGNAL(textChanged(const QString&)), SLOT(onCameraCoordChanged()));
187 aCoordLayout->addWidget(aLabelX);
188 aCoordLayout->addWidget(myCameraX);
189 aCoordLayout->addWidget(aLabelY);
190 aCoordLayout->addWidget(myCameraY);
191 aCoordLayout->addWidget(aLabelZ);
192 aCoordLayout->addWidget(myCameraZ);
193 aLayout3->addWidget(myCameraCoords);
195 // Projection direction
196 QFrame* line1 = new QFrame(aGroupBoxCamera);
197 line1->setFrameStyle(QFrame::HLine | QFrame::Sunken);
198 aLayout3->addWidget(line1);
200 QLabel* aLabel = new QLabel(tr("PROJECTION_DIRECTION"), aGroupBoxCamera);
201 aLayout3->addWidget(aLabel);
203 myProjDirection = new QFrame(aGroupBoxCamera);
204 myProjDirection->setObjectName("ProjectionDirection");
206 aCoordLayout = new QHBoxLayout(myProjDirection);
207 aCoordLayout->setSpacing(6);
208 aCoordLayout->setMargin(0);
210 aLabelX = new QLabel(tr("LBL_DX"), myProjDirection);
211 aLabelX->setFixedWidth(25);
212 myProjDirX = new QLineEdit(myProjDirection);
213 myProjDirX->setValidator(new QDoubleValidator(myProjDirX));
214 myProjDirX->setText(QString::number(0.0));
215 connect(myProjDirX, SIGNAL(textChanged(const QString&)), SLOT(onDirectionChanged()));
217 aLabelY = new QLabel(tr("LBL_DY"), myProjDirection);
218 aLabelY->setFixedWidth(25);
219 myProjDirY = new QLineEdit(myProjDirection);
220 myProjDirY->setValidator(new QDoubleValidator(myProjDirY));
221 myProjDirY->setText(QString::number(0.0));
222 connect(myProjDirY, SIGNAL(textChanged(const QString&)), SLOT(onDirectionChanged()));
224 aLabelZ = new QLabel(tr("LBL_DZ"), myProjDirection);
225 aLabelZ->setFixedWidth(25);
226 myProjDirZ = new QLineEdit(myProjDirection);
227 myProjDirZ->setValidator(new QDoubleValidator(myProjDirZ));
228 myProjDirZ->setText(QString::number(-1.0));
229 connect(myProjDirZ, SIGNAL(textChanged(const QString&)), SLOT(onDirectionChanged()));
231 aCoordLayout->addWidget(aLabelX);
232 aCoordLayout->addWidget(myProjDirX);
233 aCoordLayout->addWidget(aLabelY);
234 aCoordLayout->addWidget(myProjDirY);
235 aCoordLayout->addWidget(aLabelZ);
236 aCoordLayout->addWidget(myProjDirZ);
237 aLayout3->addWidget(myProjDirection);
239 // Distance to focal point
240 QHBoxLayout* aHorLayout = new QHBoxLayout;
241 aHorLayout->setSpacing(6);
243 aLabel = new QLabel(tr("FOCAL_DISTANCE"), aGroupBoxCamera);
244 myDistance = new QLineEdit(aGroupBoxCamera);
245 QDoubleValidator* aVal = new QDoubleValidator(myDistance);
246 aVal->setBottom(0.0002); // VTK minimal distance
247 myDistance->setValidator(aVal);
248 myDistance->setText(QString::number(1.0));
249 connect(myDistance, SIGNAL(textChanged(const QString&)), SLOT(onDistanceChanged()));
251 aHorLayout->addWidget(aLabel);
252 aHorLayout->addWidget(myDistance);
253 aLayout3->addLayout(aHorLayout);
256 QFrame* line2 = new QFrame(aGroupBoxCamera);
257 line2->setFrameStyle(QFrame::HLine | QFrame::Sunken);
258 aLayout3->addWidget(line2);
260 aLabel = new QLabel(tr("VIEW_UP_DIRECTION"), aGroupBoxCamera);
261 aLayout3->addWidget(aLabel);
263 myViewDirection = new QFrame(aGroupBoxCamera);
264 myViewDirection->setObjectName("ViewUpDirection");
265 aLayout3->addWidget(myViewDirection);
267 aCoordLayout = new QHBoxLayout(myViewDirection);
268 aCoordLayout->setSpacing(6);
269 aCoordLayout->setMargin(0);
271 aLabelX = new QLabel(tr("LBL_DX"), myViewDirection);
272 aLabelX->setFixedWidth(25);
273 myViewDirX = new QLineEdit(myViewDirection);
274 myViewDirX->setValidator(new QDoubleValidator(myViewDirX));
275 myViewDirX->setText(QString::number(0.0));
276 connect(myViewDirX, SIGNAL(textChanged(const QString&)), SLOT(onViewDirectionChanged()));
278 aLabelY = new QLabel(tr("LBL_DY"), myViewDirection);
279 aLabelY->setFixedWidth(25);
280 myViewDirY = new QLineEdit(myViewDirection);
281 myViewDirY->setValidator(new QDoubleValidator(myViewDirY));
282 myViewDirY->setText(QString::number(1.0));
283 connect(myViewDirY, SIGNAL(textChanged(const QString&)), SLOT(onViewDirectionChanged()));
285 aLabelZ = new QLabel(tr("LBL_DZ"), myViewDirection);
286 aLabelZ->setFixedWidth(25);
287 myViewDirZ = new QLineEdit(myViewDirection);
288 myViewDirZ->setValidator(new QDoubleValidator(myViewDirZ));
289 myViewDirZ->setText(QString::number(0.0));
290 connect(myViewDirZ, SIGNAL(textChanged(const QString&)), SLOT(onViewDirectionChanged()));
292 aCoordLayout->addWidget(aLabelX);
293 aCoordLayout->addWidget(myViewDirX);
294 aCoordLayout->addWidget(aLabelY);
295 aCoordLayout->addWidget(myViewDirY);
296 aCoordLayout->addWidget(aLabelZ);
297 aCoordLayout->addWidget(myViewDirZ);
300 QGroupBox* aGroupBoxZoom = new QGroupBox(tr("ZOOMING"), this);
301 QVBoxLayout* aLayout4 = new QVBoxLayout(aGroupBoxZoom);
304 myScaleBox = new QFrame(aGroupBoxZoom);
305 myScaleBox->setObjectName("ScaleValue");
307 aHorLayout = new QHBoxLayout(myScaleBox);
308 aHorLayout->setSpacing(6);
309 aHorLayout->setMargin(0);
311 aLabel = new QLabel(tr("LBL_SCALE"), myScaleBox);
312 myScale = new QLineEdit(myScaleBox);
313 QDoubleValidator* aVal2 = new QDoubleValidator(myScale);
314 aVal2->setBottom(0.000001); // VTK minimal scale
315 myScale->setValidator(aVal2);
316 myScale->setText(QString::number(1.0));
317 connect(myScale, SIGNAL(textChanged(const QString&)), SLOT(onZoomChanged()));
319 aHorLayout->addWidget(aLabel);
320 aHorLayout->addWidget(myScale);
321 aLayout4->addWidget(myScaleBox);
324 myViewAngleBox = new QFrame(aGroupBoxZoom);
325 myViewAngleBox->setObjectName("ViewAngle");
327 aHorLayout = new QHBoxLayout(myViewAngleBox);
328 aHorLayout->setSpacing(6);
329 aHorLayout->setMargin(0);
331 aLabel = new QLabel(tr("LBL_VIEW_ANGLE"), myViewAngleBox);
332 myViewAngle = new QLineEdit(myViewAngleBox);
333 QDoubleValidator* aVal3 = new QDoubleValidator(myViewAngle);
334 aVal3->setBottom(0.000001); // VTK minimal scale
335 aVal3->setTop(179); // VTK minimal scale
336 myViewAngle->setValidator(aVal3);
337 myViewAngle->setText(QString::number(30.0));
338 connect(myViewAngle, SIGNAL(textChanged(const QString&)), SLOT(onZoomChanged()));
340 aHorLayout->addWidget(aLabel);
341 aHorLayout->addWidget(myViewAngle);
342 aLayout4->addWidget(myViewAngleBox);
345 QGroupBox* aGroupBox = new QGroupBox(this);
346 QHBoxLayout* aHBoxLayout2 = new QHBoxLayout(aGroupBox);
347 aHBoxLayout2->setMargin(11);
348 aHBoxLayout2->setSpacing(6);
350 QPushButton* m_bClose = new QPushButton(tr("&Close"), aGroupBox );
351 m_bClose->setObjectName("m_bClose");
352 m_bClose->setAutoDefault(TRUE);
353 m_bClose->setFixedSize(m_bClose->sizeHint());
354 connect(m_bClose, SIGNAL(clicked()), this, SLOT(onClickClose()));
357 aHBoxLayout2->addWidget(m_bClose);
359 // Layout top level widgets
360 aTopLayout->addWidget(aGroupBoxMode);
361 aTopLayout->addWidget(aGroupBoxFocal);
362 aTopLayout->addWidget(aGroupBoxCamera);
363 aTopLayout->addWidget(aGroupBoxZoom);
364 aTopLayout->addWidget(aGroupBox);
365 aTopLayout->addStretch();
368 myProjectionMode->button(0)->setChecked(true);
369 myCameraPositionMode->button(0)->setChecked(true);
371 setEnabled(myCameraCoords, myCameraPositionMode->checkedId() == 0);
373 myScaleBox->setVisible(myProjectionMode->checkedId() == 0);
374 myViewAngleBox->setVisible(myProjectionMode->checkedId() == 1);
378 this->resize(400, this->sizeHint().height());
380 myEventCallbackCommand->Delete();
381 myEventCallbackCommand->SetClientData(this);
382 myEventCallbackCommand->SetCallback(SVTK_ViewParameterDlg::ProcessEvents);
383 myIsObserverAdded = false;
388 * Destroys the object and frees any allocated resources
390 SVTK_ViewParameterDlg::~SVTK_ViewParameterDlg()
392 // no need to delete child widgets, Qt does it all for us
395 void SVTK_ViewParameterDlg::addObserver()
397 if ( !myIsObserverAdded ) {
398 vtkInteractorStyle* aIStyle = myRWInteractor->GetInteractorStyle();
399 aIStyle->AddObserver(SVTK::FocalPointChanged, myEventCallbackCommand.GetPointer(), myPriority);
401 vtkRenderer *aRenderer = myRWInteractor->getRenderer();
402 aRenderer->AddObserver(vtkCommand::EndEvent, myEventCallbackCommand.GetPointer(), myPriority);
404 myIsObserverAdded = true;
411 void SVTK_ViewParameterDlg::ProcessEvents(vtkObject* vtkNotUsed(theObject),
412 unsigned long theEvent,
416 SVTK_ViewParameterDlg* self = reinterpret_cast<SVTK_ViewParameterDlg*>(theClientData);
418 switch ( theEvent ) {
419 case SVTK::FocalPointChanged:
422 aCoord = (double*)theCallData;
424 self->myFocalX->setText( QString::number(aCoord[0]) );
425 self->myFocalY->setText( QString::number(aCoord[1]) );
426 self->myFocalZ->setText( QString::number(aCoord[2]) );
427 self->myBusy = false;
428 self->onFocalCoordChanged();
431 case vtkCommand::EndEvent:
432 if ( self->myRWInteractor->getRenderer()->GetActiveCamera()->GetMTime() > self->myCameraMTime )
438 void SVTK_ViewParameterDlg::updateData()
441 vtkCamera* aCamera = myRWInteractor->getRenderer()->GetActiveCamera();
443 int aParallel = aCamera->GetParallelProjection();
444 myProjectionMode->button(aParallel?0:1)->setChecked(true);
445 onProjectionModeChanged( myProjectionMode->checkedId() );
447 double focal[3], pos[3], vup[3], proj[3], dist, scale, angle;
449 aCamera->GetFocalPoint(focal);
450 myFocalX->setText(QString::number(focal[0]));
451 myFocalY->setText(QString::number(focal[1]));
452 myFocalZ->setText(QString::number(focal[2]));
454 aCamera->GetPosition(pos);
455 myCameraX->setText(QString::number(pos[0]));
456 myCameraY->setText(QString::number(pos[1]));
457 myCameraZ->setText(QString::number(pos[2]));
459 aCamera->GetDirectionOfProjection(proj);
460 myProjDirX->setText(QString::number(proj[0]));
461 myProjDirY->setText(QString::number(proj[1]));
462 myProjDirZ->setText(QString::number(proj[2]));
464 aCamera->GetViewUp(vup);
465 myViewDirX->setText(QString::number(vup[0]));
466 myViewDirY->setText(QString::number(vup[1]));
467 myViewDirZ->setText(QString::number(vup[2]));
469 dist = aCamera->GetDistance();
470 myDistance->setText(QString::number(dist));
472 scale = aCamera->GetParallelScale();
473 myScale->setText(QString::number(scale));
475 angle = aCamera->GetViewAngle();
476 myViewAngle->setText(QString::number(angle));
478 myCameraMTime.Modified();
482 void SVTK_ViewParameterDlg::setEnabled(QFrame* theWidget, const bool theState)
484 QObjectList aChildren(theWidget->children());
486 for(int i = 0; i < aChildren.size(); i++)
488 anObj = aChildren.at(i);
489 if (anObj !=0 && anObj->inherits("QLineEdit"))
490 ((QLineEdit*)anObj)->setReadOnly(!theState);
491 if (anObj !=0 && anObj->inherits("QPushButton"))
492 ((QLineEdit*)anObj)->setEnabled(theState);
497 void SVTK_ViewParameterDlg::onProjectionModeChanged(int mode)
499 int aBtn = myProjectionMode->checkedId();
501 vtkCamera* aCamera = myRWInteractor->getRenderer()->GetActiveCamera();
502 aCamera->SetParallelProjection(aBtn == 0);
504 myMainWindow->activateProjectionMode(aBtn);
507 myRWInteractor->GetDevice()->CreateTimer(VTKI_TIMER_FIRST);
510 myViewAngleBox->setVisible(false);
511 myScaleBox->setVisible(true);
514 myScaleBox->setVisible(false);
515 myViewAngleBox->setVisible(true);
519 void SVTK_ViewParameterDlg::onPositionModeChanged(int mode)
521 setEnabled(myCameraCoords, myCameraPositionMode->checkedId() == 0);
524 void SVTK_ViewParameterDlg::onToBBCenter()
526 if ( mySelectPoint->isChecked() )
527 mySelectPoint->toggle();
529 myMainWindow->activateSetFocalPointGravity();
532 void SVTK_ViewParameterDlg::onToOrigin()
534 if ( mySelectPoint->isChecked() )
535 mySelectPoint->toggle();
538 myFocalX->setText(QString::number(0.0));
539 myFocalY->setText(QString::number(0.0));
540 myFocalZ->setText(QString::number(0.0));
543 onFocalCoordChanged();
546 void SVTK_ViewParameterDlg::onSelectPoint()
548 if ( mySelectPoint->isChecked() )
549 myMainWindow->activateStartFocalPointSelection();
551 mySelectPoint->toggle();
554 void SVTK_ViewParameterDlg::onFocalCoordChanged()
556 if ( myBusy ) return;
558 if ( mySelectPoint->isChecked() )
559 mySelectPoint->toggle();
561 vtkCamera* aCamera = myRWInteractor->getRenderer()->GetActiveCamera();
562 aCamera->SetFocalPoint(myFocalX->text().toDouble(),
563 myFocalY->text().toDouble(),
564 myFocalZ->text().toDouble());
566 aCamera->OrthogonalizeViewUp();
567 myRWInteractor->getRenderer()->ResetCameraClippingRange();
570 myRWInteractor->GetDevice()->CreateTimer(VTKI_TIMER_FIRST);
572 myMainWindow->activateSetFocalPointSelected();
574 //updateProjection();
577 void SVTK_ViewParameterDlg::onCameraCoordChanged()
579 if ( myBusy ) return;
581 vtkCamera* aCamera = myRWInteractor->getRenderer()->GetActiveCamera();
582 aCamera->SetPosition(myCameraX->text().toDouble(),
583 myCameraY->text().toDouble(),
584 myCameraZ->text().toDouble());
586 aCamera->OrthogonalizeViewUp();
587 myRWInteractor->getRenderer()->ResetCameraClippingRange();
590 myRWInteractor->GetDevice()->CreateTimer(VTKI_TIMER_FIRST);
592 //updateProjection();
595 void SVTK_ViewParameterDlg::onDirectionChanged()
597 if ( myBusy ) return;
602 void SVTK_ViewParameterDlg::onDistanceChanged()
604 if ( myBusy ) return;
609 void SVTK_ViewParameterDlg::onViewDirectionChanged()
611 if ( myBusy ) return;
613 vtkCamera* aCamera = myRWInteractor->getRenderer()->GetActiveCamera();
614 aCamera->SetViewUp(myViewDirX->text().toDouble(),
615 myViewDirY->text().toDouble(),
616 myViewDirZ->text().toDouble());
619 myRWInteractor->GetDevice()->CreateTimer(VTKI_TIMER_FIRST);
622 void SVTK_ViewParameterDlg::onZoomChanged()
624 if ( myBusy ) return;
626 vtkCamera* aCamera = myRWInteractor->getRenderer()->GetActiveCamera();
628 switch( myProjectionMode->checkedId() ) {
630 aCamera->SetParallelScale(myScale->text().toDouble());
633 aCamera->SetViewAngle(myViewAngle->text().toDouble());
638 myRWInteractor->GetDevice()->CreateTimer(VTKI_TIMER_FIRST);
641 void SVTK_ViewParameterDlg::onClickClose()
646 void SVTK_ViewParameterDlg::updateProjection()
648 double pnt[3], pos[3], dir[3], dist;
650 pnt[0] = myFocalX->text().toDouble();
651 pnt[1] = myFocalY->text().toDouble();
652 pnt[2] = myFocalZ->text().toDouble();
654 pos[0] = myCameraX->text().toDouble();
655 pos[1] = myCameraY->text().toDouble();
656 pos[2] = myCameraZ->text().toDouble();
658 dir[0] = pnt[0] - pos[0];
659 dir[1] = pnt[1] - pos[1];
660 dir[2] = pnt[2] - pos[2];
662 dist = sqrt( dir[0]*dir[0] + dir[1]*dir[1] + dir[2]*dir[2] );
664 if ( dist > 0.0002 ) {
665 dir[0] = dir[0] / dist;
666 dir[1] = dir[1] / dist;
667 dir[2] = dir[2] / dist;
671 myProjDirX->setText(QString::number(dir[0]));
672 myProjDirY->setText(QString::number(dir[1]));
673 myProjDirZ->setText(QString::number(dir[2]));
675 myDistance->setText(QString::number(dist));
679 void SVTK_ViewParameterDlg::updateCoordinates()
681 double pnt[3], pos[3], dir[3], dist;
683 pnt[0] = myFocalX->text().toDouble();
684 pnt[1] = myFocalY->text().toDouble();
685 pnt[2] = myFocalZ->text().toDouble();
687 pos[0] = myCameraX->text().toDouble();
688 pos[1] = myCameraY->text().toDouble();
689 pos[2] = myCameraZ->text().toDouble();
691 dir[0] = myProjDirX->text().toDouble();
692 dir[1] = myProjDirY->text().toDouble();
693 dir[2] = myProjDirZ->text().toDouble();
695 dist = myDistance->text().toDouble();
697 if (myCameraPositionMode->checkedId() == 1) {
698 // recompute camera position
699 dir[0] = -dir[0]; dir[1] = -dir[1]; dir[2] = -dir[2];
700 if (computePoint(pnt, dir, dist, pos)) {
702 myCameraX->setText(QString::number(pos[0]));
703 myCameraY->setText(QString::number(pos[1]));
704 myCameraZ->setText(QString::number(pos[2]));
706 onCameraCoordChanged();
710 // recompute focal point
711 if (computePoint(pos, dir, dist, pnt)) {
712 if (mySelectPoint->isChecked())
713 mySelectPoint->toggle();
715 myFocalX->setText(QString::number(pnt[0]));
716 myFocalY->setText(QString::number(pnt[1]));
717 myFocalZ->setText(QString::number(pnt[2]));
719 onFocalCoordChanged();
724 bool SVTK_ViewParameterDlg::computePoint(const double start[3],
729 double d = sqrt(dir[0]*dir[0]+dir[1]*dir[1]+dir[2]*dir[2]);
730 if ( d < 0.0002 ) return false;
732 for (int i = 0; i < 3; i++)
733 result[i] = start[i] + dir[i] * dist / d;