OGS
VisualizationWidget Class Reference

Detailed Description

Widget containing the 3d VTK scene view.

Definition at line 28 of file VisualizationWidget.h.

#include <VisualizationWidget.h>

Inheritance diagram for VisualizationWidget:
[legend]
Collaboration diagram for VisualizationWidget:
[legend]

Public Slots

void updateView ()
 Updates the the 3d view.
 
void showAll (int x, int y, int z)
 Shows the entire scene on the views. x,y,z are in {-1, 0, 1} and specify from which direction the scene is displayed.
 
void updateViewOnLoad ()
 Updates the view only or additionally shows the entire scene.
 
void screenshot (QString filename, int magnification)
 Saves a magnified image of the current render window to a file.
 
vtkRenderer * renderer () const
 Returns the vtk renderer.
 
void setCursorShape (Qt::CursorShape shape)
 Sets the widgets cursor shape.
 

Public Member Functions

 VisualizationWidget (QWidget *parent=nullptr)
 Constructor.
 
 ~VisualizationWidget () override
 Destructor.
 
VtkCustomInteractorStyleinteractorStyle () const
 Returns the VtkCustomInteractorStyle.
 
VtkPickCallbackvtkPickCallback () const
 Returns the VtkPickCallback.
 
void setShowAllOnLoad (bool show)
 See updateViewOnLoad().
 

Protected Slots

void on_showAllPushButton_pressed ()
 Resets the camera to view the entire scene.
 

Protected Member Functions

void on_rotateXPosPushButton_pressed ()
 Reset camera to view entire scene from +x perspective.
 
void on_rotateXNegPushButton_pressed ()
 Reset camera to view entire scene from -x perspective.
 
void on_rotateYPosPushButton_pressed ()
 Reset camera to view entire scene from +y perspective.
 
void on_rotateYNegPushButton_pressed ()
 Reset camera to view entire scene from -y perspective.
 
void on_rotateZPosPushButton_pressed ()
 Reset camera to view entire scene from +z perspective.
 
void on_rotateZNegPushButton_pressed ()
 Reset camera to view entire scene from -z perspective.
 
void on_zoomToolButton_toggled (bool checked)
 Toggles rectangular zooming mode.
 
void on_highlightToolButton_toggled (bool checked)
 Toggles the display of bounding boxes around.
 
void on_orthogonalProjectionToolButton_toggled (bool checked)
 Toggles the orthogonal projection.
 
void on_screenshotPushButton_pressed ()
 Saves a screenshot.
 

Private Attributes

vtkRenderer * _vtkRender {nullptr}
 
vtkOrientationMarkerWidget * _markerWidget {nullptr}
 
VtkCustomInteractorStyle_interactorStyle {nullptr}
 
VtkPickCallback_vtkPickCallback {nullptr}
 
bool _isShowAllOnLoad
 

Constructor & Destructor Documentation

◆ VisualizationWidget()

VisualizationWidget::VisualizationWidget ( QWidget * parent = nullptr)
explicit

Constructor.

Definition at line 48 of file VisualizationWidget.cpp.

49 : QWidget(parent)
50{
51 this->setupUi(this);
52
53 vtkNew<vtkRenderer> ren;
54 _vtkRender = ren;
55
56 vtkNew<vtkGenericOpenGLRenderWindow> renderWindow;
57 vtkWidget->setRenderWindow(renderWindow);
58 vtkWidget->renderWindow()->AddRenderer(ren);
59
61 renderWindow->GetInteractor()->SetInteractorStyle(_interactorStyle);
62 _interactorStyle->SetDefaultRenderer(ren);
63
65 vtkSmartPointer<vtkCellPicker> picker =
66 vtkSmartPointer<vtkCellPicker>::New();
67 picker->AddObserver(vtkCommand::EndPickEvent, _vtkPickCallback);
68 renderWindow->GetInteractor()->SetPicker(picker);
69
70 QSettings settings;
71
72 ren->SetBackground(0.0, 0.0, 0.0);
73
74 // Create an orientation marker using vtkAxesActor
75 vtkSmartPointer<vtkAxesActor> axesActor =
76 vtkSmartPointer<vtkAxesActor>::New();
77 _markerWidget = vtkOrientationMarkerWidget::New();
78 _markerWidget->SetOrientationMarker(axesActor);
79 _markerWidget->SetInteractor(renderWindow->GetInteractor());
80 _markerWidget->EnabledOn();
81 _markerWidget->InteractiveOff();
82
83 _isShowAllOnLoad = settings.value("resetViewOnLoad", true).toBool();
84
85 // Set alternate cursor shapes
86 connect(_interactorStyle, SIGNAL(cursorChanged(Qt::CursorShape)), this,
87 SLOT(setCursorShape(Qt::CursorShape)));
88
89 connect((QObject*)_interactorStyle, SIGNAL(requestViewUpdate()), this,
90 SLOT(updateView()));
91}
VtkCustomInteractorStyle * _interactorStyle
vtkOrientationMarkerWidget * _markerWidget
void updateView()
Updates the the 3d view.
VtkPickCallback * _vtkPickCallback
void setCursorShape(Qt::CursorShape shape)
Sets the widgets cursor shape.
static VtkCustomInteractorStyle * New()
static VtkPickCallback * New()

References _interactorStyle, _isShowAllOnLoad, _markerWidget, _vtkPickCallback, _vtkRender, VtkCustomInteractorStyle::New(), VtkPickCallback::New(), setCursorShape(), and updateView().

◆ ~VisualizationWidget()

VisualizationWidget::~VisualizationWidget ( )
override

Destructor.

Definition at line 93 of file VisualizationWidget.cpp.

94{
95 _vtkPickCallback->Delete();
96 _interactorStyle->Delete();
97 _markerWidget->Delete();
98}

References _interactorStyle, _markerWidget, and _vtkPickCallback.

Member Function Documentation

◆ interactorStyle()

VtkCustomInteractorStyle * VisualizationWidget::interactorStyle ( ) const

Returns the VtkCustomInteractorStyle.

Definition at line 100 of file VisualizationWidget.cpp.

101{
102 return _interactorStyle;
103}

References _interactorStyle.

Referenced by on_zoomToolButton_toggled().

◆ on_highlightToolButton_toggled()

void VisualizationWidget::on_highlightToolButton_toggled ( bool checked)
protected

Toggles the display of bounding boxes around.

Definition at line 170 of file VisualizationWidget.cpp.

References _interactorStyle, and VtkCustomInteractorStyle::setHighlightActor().

◆ on_orthogonalProjectionToolButton_toggled()

void VisualizationWidget::on_orthogonalProjectionToolButton_toggled ( bool checked)
protected

Toggles the orthogonal projection.

Definition at line 175 of file VisualizationWidget.cpp.

177{
178 _vtkRender->GetActiveCamera()->SetParallelProjection(checked);
179 this->updateView();
180}

References _vtkRender, and updateView().

◆ on_rotateXNegPushButton_pressed()

void VisualizationWidget::on_rotateXNegPushButton_pressed ( )
inlineprotected

Reset camera to view entire scene from -x perspective.

Definition at line 78 of file VisualizationWidget.h.

78{ this->showAll(-1,0,0); };
void showAll(int x, int y, int z)
Shows the entire scene on the views. x,y,z are in {-1, 0, 1} and specify from which direction the sce...

References showAll().

◆ on_rotateXPosPushButton_pressed()

void VisualizationWidget::on_rotateXPosPushButton_pressed ( )
inlineprotected

Reset camera to view entire scene from +x perspective.

Definition at line 75 of file VisualizationWidget.h.

75{ this->showAll(1,0,0); };

References showAll().

◆ on_rotateYNegPushButton_pressed()

void VisualizationWidget::on_rotateYNegPushButton_pressed ( )
inlineprotected

Reset camera to view entire scene from -y perspective.

Definition at line 84 of file VisualizationWidget.h.

84{ this->showAll(0,-1,0); };

References showAll().

◆ on_rotateYPosPushButton_pressed()

void VisualizationWidget::on_rotateYPosPushButton_pressed ( )
inlineprotected

Reset camera to view entire scene from +y perspective.

Definition at line 81 of file VisualizationWidget.h.

81{ this->showAll(0,1,0); };

References showAll().

◆ on_rotateZNegPushButton_pressed()

void VisualizationWidget::on_rotateZNegPushButton_pressed ( )
inlineprotected

Reset camera to view entire scene from -z perspective.

Definition at line 90 of file VisualizationWidget.h.

90{ this->showAll(0,0,-1); };

References showAll().

◆ on_rotateZPosPushButton_pressed()

void VisualizationWidget::on_rotateZPosPushButton_pressed ( )
inlineprotected

Reset camera to view entire scene from +z perspective.

Definition at line 87 of file VisualizationWidget.h.

87{ this->showAll(0,0,1); };

References showAll().

◆ on_screenshotPushButton_pressed()

void VisualizationWidget::on_screenshotPushButton_pressed ( )
protected

Saves a screenshot.

Definition at line 182 of file VisualizationWidget.cpp.

183{
184 QSettings settings;
185 QString filename = QFileDialog::getSaveFileName(
186 this, tr("Save screenshot"),
187 settings.value("lastScreenshotDir").toString(), "PNG file (*.png)");
188 if (filename.count() > 4)
189 {
190 bool ok;
191 int magnification = QInputDialog::getInt(
192 this, tr("Screenshot magnification"),
193 tr("Enter a magnification factor for the resulting image."), 2, 1,
194 10, 1, &ok);
195 if (ok)
196 {
197 QDir dir(filename);
198 settings.setValue("lastScreenshotDir", dir.absolutePath());
199 this->screenshot(filename, magnification);
200 }
201 }
202}
void screenshot(QString filename, int magnification)
Saves a magnified image of the current render window to a file.

References screenshot().

◆ on_showAllPushButton_pressed

void VisualizationWidget::on_showAllPushButton_pressed ( )
inlineprotectedslot

Resets the camera to view the entire scene.

Definition at line 72 of file VisualizationWidget.h.

72{ this->showAll(0,0,1); };

References showAll().

◆ on_zoomToolButton_toggled()

void VisualizationWidget::on_zoomToolButton_toggled ( bool checked)
protected

Toggles rectangular zooming mode.

Definition at line 148 of file VisualizationWidget.cpp.

149{
150 if (checked)
151 {
152 vtkSmartPointer<vtkInteractorStyleRubberBandZoom> interactorStyle =
153 vtkSmartPointer<vtkInteractorStyleRubberBandZoom>::New();
154 vtkWidget->renderWindow()->GetInteractor()->SetInteractorStyle(
156 QCursor cursor;
157 cursor.setShape(Qt::CrossCursor);
158 vtkWidget->setCursor(cursor);
159 }
160 else
161 {
162 vtkWidget->renderWindow()->GetInteractor()->SetInteractorStyle(
164 QCursor cursor;
165 cursor.setShape(Qt::ArrowCursor);
166 vtkWidget->setCursor(cursor);
167 }
168}
VtkCustomInteractorStyle * interactorStyle() const
Returns the VtkCustomInteractorStyle.

References _interactorStyle, and interactorStyle().

◆ renderer

vtkRenderer * VisualizationWidget::renderer ( ) const
inlineslot

Returns the vtk renderer.

Definition at line 64 of file VisualizationWidget.h.

64{ return _vtkRender; }

References _vtkRender.

◆ screenshot

void VisualizationWidget::screenshot ( QString filename,
int magnification )
slot

Saves a magnified image of the current render window to a file.

Definition at line 204 of file VisualizationWidget.cpp.

205{
206 vtkSmartPointer<vtkWindowToImageFilter> windowToImageFilter =
207 vtkSmartPointer<vtkWindowToImageFilter>::New();
208 windowToImageFilter->SetInput(vtkWidget->renderWindow());
209 // Set the resolution of the output image
210 // magnification times the current resolution of vtk render window
211 windowToImageFilter->SetScale(magnification);
212 // Also record the alpha (transparency) channel
213 windowToImageFilter->SetInputBufferTypeToRGBA();
214 windowToImageFilter->Update();
215
216 vtkSmartPointer<vtkPNGWriter> writer = vtkSmartPointer<vtkPNGWriter>::New();
217 writer->SetFileName(filename.toStdString().c_str());
218 writer->SetInputData(windowToImageFilter->GetOutput());
219 writer->Write();
220
221 this->updateView();
222}

References updateView().

Referenced by on_screenshotPushButton_pressed().

◆ setCursorShape

void VisualizationWidget::setCursorShape ( Qt::CursorShape shape)
slot

Sets the widgets cursor shape.

Definition at line 224 of file VisualizationWidget.cpp.

225{
226 this->setCursor(QCursor(shape));
227}

Referenced by VisualizationWidget().

◆ setShowAllOnLoad()

void VisualizationWidget::setShowAllOnLoad ( bool show)
inline

◆ showAll

void VisualizationWidget::showAll ( int x,
int y,
int z )
slot

Shows the entire scene on the views. x,y,z are in {-1, 0, 1} and specify from which direction the scene is displayed.

Definition at line 115 of file VisualizationWidget.cpp.

116{
117 _vtkRender->ResetCamera();
118 vtkCamera* cam = _vtkRender->GetActiveCamera();
119 double* fp = cam->GetFocalPoint();
120 double* p = cam->GetPosition();
121 double dist = std::sqrt(vtkMath::Distance2BetweenPoints(p, fp));
122 cam->SetPosition(fp[0] + (x * dist), fp[1] + (y * dist),
123 fp[2] + (z * dist));
124
125 if (x != 0 || y != 0)
126 {
127 cam->SetViewUp(0.0, 0.0, 1.0);
128 }
129 else
130 {
131 cam->SetViewUp(0.0, 1.0, 0.0);
132 }
133 this->updateView();
134}

References _vtkRender, and updateView().

Referenced by on_rotateXNegPushButton_pressed(), on_rotateXPosPushButton_pressed(), on_rotateYNegPushButton_pressed(), on_rotateYPosPushButton_pressed(), on_rotateZNegPushButton_pressed(), on_rotateZPosPushButton_pressed(), on_showAllPushButton_pressed(), and updateViewOnLoad().

◆ updateView

void VisualizationWidget::updateView ( )
slot

Updates the the 3d view.

Definition at line 110 of file VisualizationWidget.cpp.

111{
112 vtkWidget->renderWindow()->Render();
113}

Referenced by VisualizationWidget(), on_orthogonalProjectionToolButton_toggled(), screenshot(), showAll(), and updateViewOnLoad().

◆ updateViewOnLoad

void VisualizationWidget::updateViewOnLoad ( )
slot

Updates the view only or additionally shows the entire scene.

Definition at line 136 of file VisualizationWidget.cpp.

137{
139 {
140 this->showAll(0, 0, 1);
141 }
142 else
143 {
144 updateView();
145 }
146}

References _isShowAllOnLoad, showAll(), and updateView().

◆ vtkPickCallback()

VtkPickCallback * VisualizationWidget::vtkPickCallback ( ) const

Returns the VtkPickCallback.

Definition at line 105 of file VisualizationWidget.cpp.

106{
107 return _vtkPickCallback;
108}

References _vtkPickCallback.

Member Data Documentation

◆ _interactorStyle

VtkCustomInteractorStyle* VisualizationWidget::_interactorStyle {nullptr}
private

◆ _isShowAllOnLoad

bool VisualizationWidget::_isShowAllOnLoad
private

Definition at line 109 of file VisualizationWidget.h.

Referenced by VisualizationWidget(), setShowAllOnLoad(), and updateViewOnLoad().

◆ _markerWidget

vtkOrientationMarkerWidget* VisualizationWidget::_markerWidget {nullptr}
private

Definition at line 106 of file VisualizationWidget.h.

106{nullptr};

Referenced by VisualizationWidget(), and ~VisualizationWidget().

◆ _vtkPickCallback

VtkPickCallback* VisualizationWidget::_vtkPickCallback {nullptr}
private

Definition at line 108 of file VisualizationWidget.h.

108{nullptr};

Referenced by VisualizationWidget(), ~VisualizationWidget(), and vtkPickCallback().

◆ _vtkRender

vtkRenderer* VisualizationWidget::_vtkRender {nullptr}
private

The documentation for this class was generated from the following files: