qvolray

view src/ui.cc @ 30:40df2cdc6323

transfer function window
author John Tsiombikas <nuclear@member.fsf.org>
date Sat, 14 Apr 2012 22:10:30 +0300
parents 93d889a3726a
children c1dd5b120504
line source
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <vector>
4 #include <QtGui>
5 #include "ui.h"
6 #include "ui_maingl.h"
7 #include "ui_sliceview.h"
8 #include "ui_xferview.h"
11 static Volume *volume;
12 std::vector<QGLWidget*> glwlist;
14 MainWindow::MainWindow()
15 {
16 setWindowTitle("Volume Renderer");
18 // OpenGL view (this must be initialized first)
19 maingl = new MainGLView;
20 setCentralWidget(maingl);
21 glwlist.push_back(maingl);
23 // side-window
24 sidewin = new SideWindow;
25 sidewin->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
26 sidewin->setFeatures(QDockWidget::DockWidgetMovable | QDockWidget::DockWidgetFloatable);
27 addDockWidget(Qt::LeftDockWidgetArea, sidewin);
29 // actions
30 QAction *act_open = new QAction(qApp->style()->standardIcon(QStyle::SP_DialogOpenButton), "&Open...", this);
31 act_open->setStatusTip("Open a volume dataset");
32 QObject::connect(act_open, SIGNAL(triggered()), this, SLOT(open_volume()));
34 QAction *act_quit = new QAction("&Quit", this);
35 act_quit->setStatusTip("Quit");
36 QObject::connect(act_quit, SIGNAL(triggered()), this, SLOT(close()));
38 // menus
39 QMenu *mfile = menuBar()->addMenu("&File");
40 mfile->addAction(act_open);
41 mfile->addAction(act_quit);
43 // toolbars
44 QToolBar *tfile = addToolBar("&File");
45 tfile->addAction(act_open);
47 statusBar();
48 show();
49 }
51 void MainWindow::open_volume()
52 {
53 QString fname = QFileDialog::getOpenFileName(this, "Open volume dataset", QString(), "Volume descriptors (*.vol)");
54 if(!fname.isNull()) {
55 Volume *vol = new Volume;
57 if(vol->load(qPrintable(fname))) {
58 delete volume;
59 volume = vol;
60 volray_setvolume(vol);
61 post_redisplay();
62 } else {
63 delete vol;
64 }
65 }
66 }
69 SideWindow::SideWindow()
70 {
71 QGroupBox *group_slice = new QGroupBox("Volume slice");
72 {
73 slice_view = new SliceGLView(glwlist[0]);
74 glwlist.push_back(slice_view);
76 QCheckBox *chk_clip = new QCheckBox("clip");
77 chk_clip->setStatusTip("Enable clipping at the current slice");
78 chk_clip->setChecked(false);
79 connect(chk_clip, SIGNAL(stateChanged(int)), this, SLOT(clip_change(int)));
81 QSlider *zslider = new QSlider(Qt::Horizontal);
82 zslider->setStatusTip("Change current Z slice");
83 zslider->setRange(0, 256);
84 zslider->setValue(volray_getvalue(VolRayOpt::ZCURSOR) * 256.0);
85 connect(zslider, SIGNAL(valueChanged(int)), this, SLOT(zslider_change(int)));
87 QVBoxLayout *vbox = new QVBoxLayout;
88 vbox->addWidget(slice_view);
89 vbox->addWidget(chk_clip);
90 vbox->addWidget(zslider);
92 group_slice->setLayout(vbox);
93 }
95 QGroupBox *group_xfer = new QGroupBox("Transfer function");
96 {
97 XFerGLView *xfer_view = new XFerGLView(glwlist[0]);
98 glwlist.push_back(xfer_view);
100 QVBoxLayout *vbox = new QVBoxLayout;
101 vbox->addWidget(xfer_view);
103 group_xfer->setLayout(vbox);
104 }
106 QWidget *win = new QWidget;
107 setWidget(win);
109 QVBoxLayout *vbox = new QVBoxLayout;
110 vbox->addWidget(group_slice);
111 vbox->addWidget(group_xfer);
112 vbox->addStretch();
114 win->setLayout(vbox);
115 }
117 void SideWindow::zslider_change(int val)
118 {
119 volray_setvalue(VolRayOpt::ZCURSOR, (float)val / 256.0);
120 }
122 void SideWindow::clip_change(int checked)
123 {
124 volray_setvalue(VolRayOpt::ZCLIP, checked);
125 }
128 void post_redisplay()
129 {
130 for(auto glw : glwlist) {
131 glw->updateGL();
132 }
133 }