OGS
VisualizationWidget Class Reference

Detailed Description

Widget containing the 3d VTK scene view.

Definition at line 17 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 37 of file VisualizationWidget.cpp.

38 : QWidget(parent)
39{
40 this->setupUi(this);
41
42 vtkNew<vtkRenderer> ren;
43 _vtkRender = ren;
44
45 vtkNew<vtkGenericOpenGLRenderWindow> renderWindow;
46 vtkWidget->setRenderWindow(renderWindow);
47 vtkWidget->renderWindow()->AddRenderer(ren);
48
50 renderWindow->GetInteractor()->SetInteractorStyle(_interactorStyle);
51 _interactorStyle->SetDefaultRenderer(ren);
52
54 vtkSmartPointer<vtkCellPicker> picker =
55 vtkSmartPointer<vtkCellPicker>::New();
56 picker->AddObserver(vtkCommand::EndPickEvent, _vtkPickCallback);
57 renderWindow->GetInteractor()->SetPicker(picker);
58
59 QSettings settings;
60
61 ren->SetBackground(0.0, 0.0, 0.0);
62
63 // Create an orientation marker using vtkAxesActor
64 vtkSmartPointer<vtkAxesActor> axesActor =
65 vtkSmartPointer<vtkAxesActor>::New();
66 _markerWidget = vtkOrientationMarkerWidget::New();
67 _markerWidget->SetOrientationMarker(axesActor);
68 _markerWidget->SetInteractor(renderWindow->GetInteractor());
69 _markerWidget->EnabledOn();
70 _markerWidget->InteractiveOff();
71
72 _isShowAllOnLoad = settings.value("resetViewOnLoad", true).toBool();
73
74 // Set alternate cursor shapes
75 connect(_interactorStyle, SIGNAL(cursorChanged(Qt::CursorShape)), this,
76 SLOT(setCursorShape(Qt::CursorShape)));
77
78 connect((QObject*)_interactorStyle, SIGNAL(requestViewUpdate()), this,
79 SLOT(updateView()));
80}
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 82 of file VisualizationWidget.cpp.

83{
84 _vtkPickCallback->Delete();
85 _interactorStyle->Delete();
86 _markerWidget->Delete();
87}

References _interactorStyle, _markerWidget, and _vtkPickCallback.

Member Function Documentation

◆ interactorStyle()

VtkCustomInteractorStyle * VisualizationWidget::interactorStyle ( ) const

Returns the VtkCustomInteractorStyle.

Definition at line 89 of file VisualizationWidget.cpp.

90{
91 return _interactorStyle;
92}

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 159 of file VisualizationWidget.cpp.

160{
161 _interactorStyle->setHighlightActor(checked);
162}

References _interactorStyle.

◆ on_orthogonalProjectionToolButton_toggled()

void VisualizationWidget::on_orthogonalProjectionToolButton_toggled ( bool checked)
protected

Toggles the orthogonal projection.

Definition at line 164 of file VisualizationWidget.cpp.

166{
167 _vtkRender->GetActiveCamera()->SetParallelProjection(checked);
168 this->updateView();
169}

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 67 of file VisualizationWidget.h.

67{ 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 64 of file VisualizationWidget.h.

64{ 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 73 of file VisualizationWidget.h.

73{ 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 70 of file VisualizationWidget.h.

70{ 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 79 of file VisualizationWidget.h.

79{ 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 76 of file VisualizationWidget.h.

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

References showAll().

◆ on_screenshotPushButton_pressed()

void VisualizationWidget::on_screenshotPushButton_pressed ( )
protected

Saves a screenshot.

Definition at line 171 of file VisualizationWidget.cpp.

172{
173 QSettings settings;
174 QString filename = QFileDialog::getSaveFileName(
175 this, tr("Save screenshot"),
176 settings.value("lastScreenshotDir").toString(), "PNG file (*.png)");
177 if (filename.count() > 4)
178 {
179 bool ok;
180 int magnification = QInputDialog::getInt(
181 this, tr("Screenshot magnification"),
182 tr("Enter a magnification factor for the resulting image."), 2, 1,
183 10, 1, &ok);
184 if (ok)
185 {
186 QDir dir(filename);
187 settings.setValue("lastScreenshotDir", dir.absolutePath());
188 this->screenshot(filename, magnification);
189 }
190 }
191}
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 61 of file VisualizationWidget.h.

61{ 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 137 of file VisualizationWidget.cpp.

138{
139 if (checked)
140 {
141 vtkSmartPointer<vtkInteractorStyleRubberBandZoom> interactorStyle =
142 vtkSmartPointer<vtkInteractorStyleRubberBandZoom>::New();
143 vtkWidget->renderWindow()->GetInteractor()->SetInteractorStyle(
145 QCursor cursor;
146 cursor.setShape(Qt::CrossCursor);
147 vtkWidget->setCursor(cursor);
148 }
149 else
150 {
151 vtkWidget->renderWindow()->GetInteractor()->SetInteractorStyle(
153 QCursor cursor;
154 cursor.setShape(Qt::ArrowCursor);
155 vtkWidget->setCursor(cursor);
156 }
157}
VtkCustomInteractorStyle * interactorStyle() const
Returns the VtkCustomInteractorStyle.

References _interactorStyle, and interactorStyle().

◆ renderer

vtkRenderer * VisualizationWidget::renderer ( ) const
inlineslot

Returns the vtk renderer.

Definition at line 53 of file VisualizationWidget.h.

53{ 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 193 of file VisualizationWidget.cpp.

194{
195 vtkSmartPointer<vtkWindowToImageFilter> windowToImageFilter =
196 vtkSmartPointer<vtkWindowToImageFilter>::New();
197 windowToImageFilter->SetInput(vtkWidget->renderWindow());
198 // Set the resolution of the output image
199 // magnification times the current resolution of vtk render window
200 windowToImageFilter->SetScale(magnification);
201 // Also record the alpha (transparency) channel
202 windowToImageFilter->SetInputBufferTypeToRGBA();
203 windowToImageFilter->Update();
204
205 vtkSmartPointer<vtkPNGWriter> writer = vtkSmartPointer<vtkPNGWriter>::New();
206 writer->SetFileName(filename.toStdString().c_str());
207 writer->SetInputData(windowToImageFilter->GetOutput());
208 writer->Write();
209
210 this->updateView();
211}

References updateView().

Referenced by on_screenshotPushButton_pressed().

◆ setCursorShape

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

Sets the widgets cursor shape.

Definition at line 213 of file VisualizationWidget.cpp.

214{
215 this->setCursor(QCursor(shape));
216}

Referenced by VisualizationWidget().

◆ setShowAllOnLoad()

void VisualizationWidget::setShowAllOnLoad ( bool show)
inline

See updateViewOnLoad().

Definition at line 36 of file VisualizationWidget.h.

36{ _isShowAllOnLoad = show; }

References _isShowAllOnLoad.

◆ 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 104 of file VisualizationWidget.cpp.

105{
106 _vtkRender->ResetCamera();
107 vtkCamera* cam = _vtkRender->GetActiveCamera();
108 double* fp = cam->GetFocalPoint();
109 double* p = cam->GetPosition();
110 double dist = std::sqrt(vtkMath::Distance2BetweenPoints(p, fp));
111 cam->SetPosition(fp[0] + (x * dist), fp[1] + (y * dist),
112 fp[2] + (z * dist));
113
114 if (x != 0 || y != 0)
115 {
116 cam->SetViewUp(0.0, 0.0, 1.0);
117 }
118 else
119 {
120 cam->SetViewUp(0.0, 1.0, 0.0);
121 }
122 this->updateView();
123}

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 99 of file VisualizationWidget.cpp.

100{
101 vtkWidget->renderWindow()->Render();
102}

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 125 of file VisualizationWidget.cpp.

126{
128 {
129 this->showAll(0, 0, 1);
130 }
131 else
132 {
133 updateView();
134 }
135}

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

◆ vtkPickCallback()

VtkPickCallback * VisualizationWidget::vtkPickCallback ( ) const

Returns the VtkPickCallback.

Definition at line 94 of file VisualizationWidget.cpp.

95{
96 return _vtkPickCallback;
97}

References _vtkPickCallback.

Member Data Documentation

◆ _interactorStyle

VtkCustomInteractorStyle* VisualizationWidget::_interactorStyle {nullptr}
private

◆ _isShowAllOnLoad

bool VisualizationWidget::_isShowAllOnLoad
private

Definition at line 98 of file VisualizationWidget.h.

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

◆ _markerWidget

vtkOrientationMarkerWidget* VisualizationWidget::_markerWidget {nullptr}
private

Definition at line 95 of file VisualizationWidget.h.

95{nullptr};

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

◆ _vtkPickCallback

VtkPickCallback* VisualizationWidget::_vtkPickCallback {nullptr}
private

Definition at line 97 of file VisualizationWidget.h.

97{nullptr};

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

◆ _vtkRender

vtkRenderer* VisualizationWidget::_vtkRender {nullptr}
private

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