qvolray

view src/ui.cc @ 28:aeef3c2ae472

the slice widget works fine
author John Tsiombikas <nuclear@member.fsf.org>
date Sat, 14 Apr 2012 16:35:30 +0300
parents 011ac823600c
children 93d889a3726a
line source
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <vector>
4 #include <QtGui>
5 #include "ui.h"
7 static Volume *volume;
8 std::vector<QGLWidget*> glwlist;
10 MainWindow::MainWindow()
11 {
12 setWindowTitle("Volume Renderer");
14 // OpenGL view (this must be initialized first)
15 maingl = new MainGLView;
16 setCentralWidget(maingl);
17 glwlist.push_back(maingl);
19 // side-window
20 sidewin = new SideWindow;
21 sidewin->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
22 sidewin->setFeatures(QDockWidget::DockWidgetMovable | QDockWidget::DockWidgetFloatable);
23 addDockWidget(Qt::LeftDockWidgetArea, sidewin);
25 // actions
26 QAction *act_open = new QAction(qApp->style()->standardIcon(QStyle::SP_DialogOpenButton), "&Open...", this);
27 act_open->setStatusTip("Open a volume dataset");
28 QObject::connect(act_open, SIGNAL(triggered()), this, SLOT(open_volume()));
30 QAction *act_quit = new QAction("&Quit", this);
31 act_quit->setStatusTip("Quit");
32 QObject::connect(act_quit, SIGNAL(triggered()), this, SLOT(close()));
34 // menus
35 QMenu *mfile = menuBar()->addMenu("&File");
36 mfile->addAction(act_open);
37 mfile->addAction(act_quit);
39 // toolbars
40 QToolBar *tfile = addToolBar("&File");
41 tfile->addAction(act_open);
43 statusBar();
44 show();
45 }
47 void MainWindow::open_volume()
48 {
49 QString fname = QFileDialog::getOpenFileName(this, "Open volume dataset", QString(), "Volume descriptors (*.vol)");
50 if(!fname.isNull()) {
51 Volume *vol = new Volume;
53 if(vol->load(qPrintable(fname))) {
54 delete volume;
55 volume = vol;
56 volray_setvolume(vol);
57 post_redisplay();
58 } else {
59 delete vol;
60 }
61 }
62 }
65 SideWindow::SideWindow()
66 {
67 QGroupBox *groupbox = new QGroupBox("Volume slice");
68 {
69 slice_view = new SliceGLView(glwlist[0]);
70 glwlist.push_back(slice_view);
72 QCheckBox *chk_clip = new QCheckBox("clip");
73 chk_clip->setChecked(false);
74 connect(chk_clip, SIGNAL(stateChanged(int)), this, SLOT(clip_change(int)));
76 QSlider *zslider = new QSlider(Qt::Horizontal);
77 zslider->setRange(0, 256);
78 zslider->setValue(volray_getvalue(VOLRAY_ZCURSOR) * 256.0);
79 connect(zslider, SIGNAL(valueChanged(int)), this, SLOT(zslider_change(int)));
81 QVBoxLayout *vbox = new QVBoxLayout;
82 vbox->addWidget(slice_view);
83 vbox->addWidget(chk_clip);
84 vbox->addWidget(zslider);
86 groupbox->setLayout(vbox);
87 }
89 QWidget *win = new QWidget;
90 setWidget(win);
92 QVBoxLayout *vbox = new QVBoxLayout;
93 vbox->addWidget(groupbox);
94 vbox->addStretch();
96 win->setLayout(vbox);
97 }
99 void SideWindow::zslider_change(int val)
100 {
101 volray_setvalue(VOLRAY_ZCURSOR, (float)val / 256.0);
102 }
104 void SideWindow::clip_change(int checked)
105 {
106 volray_setvalue(VOLRAY_ZCLIP, checked);
107 }
110 void post_redisplay()
111 {
112 for(auto glw : glwlist) {
113 glw->updateGL();
114 }
115 }