rev |
line source |
nuclear@13
|
1 #include <stdio.h>
|
nuclear@13
|
2 #include <stdlib.h>
|
nuclear@28
|
3 #include <vector>
|
nuclear@13
|
4 #include <QtGui>
|
nuclear@13
|
5 #include "ui.h"
|
nuclear@30
|
6 #include "ui_maingl.h"
|
nuclear@30
|
7 #include "ui_sliceview.h"
|
nuclear@30
|
8 #include "ui_xferview.h"
|
nuclear@30
|
9
|
nuclear@13
|
10
|
nuclear@13
|
11 static Volume *volume;
|
nuclear@28
|
12 std::vector<QGLWidget*> glwlist;
|
nuclear@26
|
13
|
nuclear@13
|
14 MainWindow::MainWindow()
|
nuclear@13
|
15 {
|
nuclear@13
|
16 setWindowTitle("Volume Renderer");
|
nuclear@13
|
17
|
nuclear@28
|
18 // OpenGL view (this must be initialized first)
|
nuclear@27
|
19 maingl = new MainGLView;
|
nuclear@26
|
20 setCentralWidget(maingl);
|
nuclear@28
|
21 glwlist.push_back(maingl);
|
nuclear@13
|
22
|
nuclear@31
|
23 // slice view sub-window
|
nuclear@14
|
24 sidewin = new SideWindow;
|
nuclear@14
|
25 sidewin->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
|
nuclear@14
|
26 sidewin->setFeatures(QDockWidget::DockWidgetMovable | QDockWidget::DockWidgetFloatable);
|
nuclear@14
|
27 addDockWidget(Qt::LeftDockWidgetArea, sidewin);
|
nuclear@14
|
28
|
nuclear@31
|
29 // transfer function sub-window
|
nuclear@31
|
30 xferwin = new XFerWin;
|
nuclear@31
|
31 xferwin->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
|
nuclear@31
|
32 xferwin->setFeatures(QDockWidget::DockWidgetMovable | QDockWidget::DockWidgetFloatable);
|
nuclear@31
|
33 addDockWidget(Qt::LeftDockWidgetArea, xferwin);
|
nuclear@31
|
34
|
nuclear@13
|
35 // actions
|
nuclear@13
|
36 QAction *act_open = new QAction(qApp->style()->standardIcon(QStyle::SP_DialogOpenButton), "&Open...", this);
|
nuclear@13
|
37 act_open->setStatusTip("Open a volume dataset");
|
nuclear@32
|
38 act_open->setShortcut(QKeySequence::Open);
|
nuclear@13
|
39 QObject::connect(act_open, SIGNAL(triggered()), this, SLOT(open_volume()));
|
nuclear@13
|
40
|
nuclear@32
|
41 QAction *act_quit = new QAction(qApp->style()->standardIcon(QStyle::SP_DialogCloseButton), "&Quit", this);
|
nuclear@32
|
42 act_quit->setStatusTip("Exit program");
|
nuclear@32
|
43 //act_quit->setShortcut(QKeySequence::Quit);
|
nuclear@31
|
44 act_quit->setShortcut(QKeySequence(tr("Ctrl+Q", "File|Quit")));
|
nuclear@13
|
45 QObject::connect(act_quit, SIGNAL(triggered()), this, SLOT(close()));
|
nuclear@13
|
46
|
nuclear@13
|
47 // menus
|
nuclear@13
|
48 QMenu *mfile = menuBar()->addMenu("&File");
|
nuclear@13
|
49 mfile->addAction(act_open);
|
nuclear@13
|
50 mfile->addAction(act_quit);
|
nuclear@13
|
51
|
nuclear@13
|
52 // toolbars
|
nuclear@13
|
53 QToolBar *tfile = addToolBar("&File");
|
nuclear@13
|
54 tfile->addAction(act_open);
|
nuclear@13
|
55
|
nuclear@13
|
56 statusBar();
|
nuclear@13
|
57 show();
|
nuclear@13
|
58 }
|
nuclear@13
|
59
|
nuclear@13
|
60 void MainWindow::open_volume()
|
nuclear@13
|
61 {
|
nuclear@13
|
62 QString fname = QFileDialog::getOpenFileName(this, "Open volume dataset", QString(), "Volume descriptors (*.vol)");
|
nuclear@13
|
63 if(!fname.isNull()) {
|
nuclear@13
|
64 Volume *vol = new Volume;
|
nuclear@13
|
65
|
nuclear@13
|
66 if(vol->load(qPrintable(fname))) {
|
nuclear@13
|
67 delete volume;
|
nuclear@13
|
68 volume = vol;
|
nuclear@13
|
69 volray_setvolume(vol);
|
nuclear@13
|
70 post_redisplay();
|
nuclear@13
|
71 } else {
|
nuclear@13
|
72 delete vol;
|
nuclear@13
|
73 }
|
nuclear@13
|
74 }
|
nuclear@13
|
75 }
|
nuclear@13
|
76
|
nuclear@14
|
77
|
nuclear@14
|
78 SideWindow::SideWindow()
|
nuclear@14
|
79 {
|
nuclear@30
|
80 QGroupBox *group_slice = new QGroupBox("Volume slice");
|
nuclear@22
|
81 {
|
nuclear@28
|
82 slice_view = new SliceGLView(glwlist[0]);
|
nuclear@28
|
83 glwlist.push_back(slice_view);
|
nuclear@26
|
84
|
nuclear@22
|
85 QCheckBox *chk_clip = new QCheckBox("clip");
|
nuclear@30
|
86 chk_clip->setStatusTip("Enable clipping at the current slice");
|
nuclear@22
|
87 chk_clip->setChecked(false);
|
nuclear@22
|
88 connect(chk_clip, SIGNAL(stateChanged(int)), this, SLOT(clip_change(int)));
|
nuclear@21
|
89
|
nuclear@22
|
90 QSlider *zslider = new QSlider(Qt::Horizontal);
|
nuclear@30
|
91 zslider->setStatusTip("Change current Z slice");
|
nuclear@22
|
92 zslider->setRange(0, 256);
|
nuclear@29
|
93 zslider->setValue(volray_getvalue(VolRayOpt::ZCURSOR) * 256.0);
|
nuclear@22
|
94 connect(zslider, SIGNAL(valueChanged(int)), this, SLOT(zslider_change(int)));
|
nuclear@22
|
95
|
nuclear@22
|
96 QVBoxLayout *vbox = new QVBoxLayout;
|
nuclear@26
|
97 vbox->addWidget(slice_view);
|
nuclear@22
|
98 vbox->addWidget(chk_clip);
|
nuclear@22
|
99 vbox->addWidget(zslider);
|
nuclear@22
|
100
|
nuclear@30
|
101 group_slice->setLayout(vbox);
|
nuclear@30
|
102 }
|
nuclear@30
|
103
|
nuclear@31
|
104 QWidget *win = new QWidget;
|
nuclear@31
|
105 setWidget(win);
|
nuclear@31
|
106
|
nuclear@31
|
107 QVBoxLayout *vbox = new QVBoxLayout;
|
nuclear@31
|
108 vbox->addWidget(group_slice);
|
nuclear@31
|
109 vbox->addStretch();
|
nuclear@31
|
110
|
nuclear@31
|
111 win->setLayout(vbox);
|
nuclear@31
|
112 }
|
nuclear@31
|
113
|
nuclear@31
|
114 void SideWindow::zslider_change(int val)
|
nuclear@31
|
115 {
|
nuclear@31
|
116 volray_setvalue(VolRayOpt::ZCURSOR, (float)val / 256.0);
|
nuclear@31
|
117 }
|
nuclear@31
|
118
|
nuclear@31
|
119 void SideWindow::clip_change(int checked)
|
nuclear@31
|
120 {
|
nuclear@31
|
121 volray_setvalue(VolRayOpt::ZCLIP, checked);
|
nuclear@31
|
122 }
|
nuclear@31
|
123
|
nuclear@31
|
124
|
nuclear@31
|
125 XFerWin::XFerWin()
|
nuclear@31
|
126 {
|
nuclear@30
|
127 QGroupBox *group_xfer = new QGroupBox("Transfer function");
|
nuclear@30
|
128 {
|
nuclear@30
|
129 XFerGLView *xfer_view = new XFerGLView(glwlist[0]);
|
nuclear@30
|
130 glwlist.push_back(xfer_view);
|
nuclear@30
|
131
|
nuclear@30
|
132 QVBoxLayout *vbox = new QVBoxLayout;
|
nuclear@30
|
133 vbox->addWidget(xfer_view);
|
nuclear@30
|
134
|
nuclear@30
|
135 group_xfer->setLayout(vbox);
|
nuclear@22
|
136 }
|
nuclear@21
|
137
|
nuclear@21
|
138 QWidget *win = new QWidget;
|
nuclear@21
|
139 setWidget(win);
|
nuclear@22
|
140
|
nuclear@22
|
141 QVBoxLayout *vbox = new QVBoxLayout;
|
nuclear@30
|
142 vbox->addWidget(group_xfer);
|
nuclear@22
|
143 vbox->addStretch();
|
nuclear@22
|
144
|
nuclear@21
|
145 win->setLayout(vbox);
|
nuclear@21
|
146 }
|
nuclear@21
|
147
|
nuclear@28
|
148
|
nuclear@13
|
149 void post_redisplay()
|
nuclear@13
|
150 {
|
nuclear@28
|
151 for(auto glw : glwlist) {
|
nuclear@28
|
152 glw->updateGL();
|
nuclear@28
|
153 }
|
nuclear@13
|
154 }
|