-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGUIManager.cxx
More file actions
156 lines (136 loc) · 5.21 KB
/
GUIManager.cxx
File metadata and controls
156 lines (136 loc) · 5.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
// SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
// SPDX-FileCopyrightText: Copyright 2007 Sandia Corporation
// SPDX-License-Identifier: LicenseRef-BSD-3-Clause-Sandia-USGov
#include "GUIManager.h"
#include "ui_SimpleView.h"
#include <vtkCamera.h>
#include <vtkColorTransferFunction.h>
#include <vtkFixedPointVolumeRayCastMapper.h>
#include <vtkMetaImageReader.h>
#include <vtkNamedColors.h>
#include <vtkPiecewiseFunction.h>
#include <vtkRenderWindow.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkRenderer.h>
#include <vtkVolumeProperty.h>
#include <QFileDialog>
#include <qcheckbox.h>
// Constructor for GUIManager class
// Initializes the UI components, sets up signal-slot connections,
// and configures default camera and rendering modes.
GUIManager::GUIManager()
{
logger.SetLogToFile("renderer_log.txt");
this->ui = new Ui_SimpleView;
this->ui->setupUi(this);
this->ui->actionSetModeStandard->setCheckable(true);
this->ui->actionSetModeRedBlue->setCheckable(true);
this->ui->actionSetModeStereoFake->setCheckable(true);
this->ui->actionSetDisplayHMD->setCheckable(true);
this->ui->actionSetDisplayCAVE->setCheckable(true);
this->ui->actionSetDisplayTWOD->setChecked(true);
this->TableView = vtkSmartPointer<vtkQtTableView>::New();
this->ui->tableFrame->layout()->addWidget(this->TableView->GetWidget());
volume = vtkSmartPointer<vtkVolume>::New();
this->ui->qvtkWidget->setRenderWindow(renderer.GetRenderWindow());
logger.Log("Please select a file!", CaveLogger::INFO);
vtkCamera* camera = renderer.GetRenderer()->GetActiveCamera();
camera->SetViewUp(0, 0, -1);
camera->SetPosition(0, -400, 0);
camera->SetFocalPoint(0, 0, 0);
connect(this->ui->actionOpenFile, &QAction::triggered, this, &GUIManager::slotOpenFile);
connect(this->ui->actionExit, &QAction::triggered, this, &GUIManager::slotExit);
connect(this->ui->actionSetModeStandard, &QAction::triggered, this,
[this]() { setRenderMode(Renderer::Standard); });
connect(this->ui->actionSetModeRedBlue, &QAction::triggered, this,
[this]() { setRenderMode(Renderer::RedBlue); });
connect(this->ui->actionSetModeStereoFake, &QAction::triggered, this,
[this]() { setRenderMode(Renderer::StereoFake); });
connect(this->ui->actionSetDisplayTWOD, &QAction::triggered, this,
[this]() { setDisplayMode(Renderer::TWOD); });
connect(this->ui->actionSetDisplayHMD, &QAction::triggered, this,
[this]() { setDisplayMode(Renderer::HMD); });
connect(this->ui->actionSetDisplayCAVE, &QAction::triggered, this,
[this]() { setDisplayMode(Renderer::CAVE); });
setDisplayMode(Renderer::TWOD);
setRenderMode(Renderer::Standard);
}
// Destructor for GUIManager class
GUIManager::~GUIManager() {}
// Slot to handle opening a file through the file dialog
void GUIManager::slotOpenFile()
{
// Open a file dialog to select the file
QString fileName = QFileDialog::getOpenFileName(
this, tr("Open Data File"), "", tr("All Supported Files (*.mhd *.mha *.stl *.ply);;Meta Image Files (*.mhd *.mha);;STL Files (*.stl);;PLY Files (*.ply);;All Files (*)"));
if (fileName.isEmpty())
{
return;
}
renderer.LoadFile(fileName.toStdString());
logger.Log("File selected: " + fileName.toStdString(), CaveLogger::INFO);
renderer.GetRenderWindow()->Render();
}
// Slot to handle exiting the application
void GUIManager::slotExit()
{
logger.Log("Exit", CaveLogger::INFO);
if (renderer.IsCaveModeActive()) {
renderer.CloseCAVE();
}
qApp->exit();
}
// Method to set the rendering mode (Standard, Red-Blue, Stereo Fake) and mark the mode as checked
void GUIManager::setRenderMode(Renderer::RenderMode mode)
{
renderer.SetRenderMode(mode);
renderer.GetRenderWindow()->Render();
// Reset check for previous render mode
if (currentRenderModeAction) {
currentRenderModeAction->setChecked(false);
}
// Set the new render mode as checked
QAction* newAction = nullptr;
switch (mode) {
case Renderer::Standard:
newAction = this->ui->actionSetModeStandard;
break;
case Renderer::RedBlue:
newAction = this->ui->actionSetModeRedBlue;
break;
case Renderer::StereoFake:
newAction = this->ui->actionSetModeStereoFake;
break;
}
if (newAction) {
newAction->setChecked(true);
currentRenderModeAction = newAction;
}
}
// Method to set the display mode (HMD, CAVE), set checked state based on selection
void GUIManager::setDisplayMode(Renderer::DisplayMode displayMode)
{
bool selected = renderer.SetDisplayMode(displayMode);
renderer.GetRenderWindow()->Render();
if (displayMode != Renderer::TWOD) {
// Set the new display mode as checked
QAction* newAction = nullptr;
switch (displayMode) {
case Renderer::HMD:
newAction = this->ui->actionSetDisplayHMD;
break;
case Renderer::CAVE:
newAction = this->ui->actionSetDisplayCAVE;
break;
}
if (newAction) {
if (selected == true) {
newAction->setChecked(true);
}
else
{
newAction->setChecked(false);
}
}
}
}