qvolray

annotate src/ui.cc @ 31:c1dd5b120504

separated the transfer function to a different subwindow and added shortcut for quit
author John Tsiombikas <nuclear@member.fsf.org>
date Sat, 14 Apr 2012 22:32:14 +0300
parents 40df2cdc6323
children 7e5a2dd9bca6
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@13 38 QObject::connect(act_open, SIGNAL(triggered()), this, SLOT(open_volume()));
nuclear@13 39
nuclear@13 40 QAction *act_quit = new QAction("&Quit", this);
nuclear@13 41 act_quit->setStatusTip("Quit");
nuclear@31 42 //act_quit->setShortcut(QKeySequence(QKeySequence::Quit));
nuclear@31 43 act_quit->setShortcut(QKeySequence(tr("Ctrl+Q", "File|Quit")));
nuclear@13 44 QObject::connect(act_quit, SIGNAL(triggered()), this, SLOT(close()));
nuclear@13 45
nuclear@13 46 // menus
nuclear@13 47 QMenu *mfile = menuBar()->addMenu("&File");
nuclear@13 48 mfile->addAction(act_open);
nuclear@13 49 mfile->addAction(act_quit);
nuclear@13 50
nuclear@13 51 // toolbars
nuclear@13 52 QToolBar *tfile = addToolBar("&File");
nuclear@13 53 tfile->addAction(act_open);
nuclear@13 54
nuclear@13 55 statusBar();
nuclear@13 56 show();
nuclear@13 57 }
nuclear@13 58
nuclear@13 59 void MainWindow::open_volume()
nuclear@13 60 {
nuclear@13 61 QString fname = QFileDialog::getOpenFileName(this, "Open volume dataset", QString(), "Volume descriptors (*.vol)");
nuclear@13 62 if(!fname.isNull()) {
nuclear@13 63 Volume *vol = new Volume;
nuclear@13 64
nuclear@13 65 if(vol->load(qPrintable(fname))) {
nuclear@13 66 delete volume;
nuclear@13 67 volume = vol;
nuclear@13 68 volray_setvolume(vol);
nuclear@13 69 post_redisplay();
nuclear@13 70 } else {
nuclear@13 71 delete vol;
nuclear@13 72 }
nuclear@13 73 }
nuclear@13 74 }
nuclear@13 75
nuclear@14 76
nuclear@14 77 SideWindow::SideWindow()
nuclear@14 78 {
nuclear@30 79 QGroupBox *group_slice = new QGroupBox("Volume slice");
nuclear@22 80 {
nuclear@28 81 slice_view = new SliceGLView(glwlist[0]);
nuclear@28 82 glwlist.push_back(slice_view);
nuclear@26 83
nuclear@22 84 QCheckBox *chk_clip = new QCheckBox("clip");
nuclear@30 85 chk_clip->setStatusTip("Enable clipping at the current slice");
nuclear@22 86 chk_clip->setChecked(false);
nuclear@22 87 connect(chk_clip, SIGNAL(stateChanged(int)), this, SLOT(clip_change(int)));
nuclear@21 88
nuclear@22 89 QSlider *zslider = new QSlider(Qt::Horizontal);
nuclear@30 90 zslider->setStatusTip("Change current Z slice");
nuclear@22 91 zslider->setRange(0, 256);
nuclear@29 92 zslider->setValue(volray_getvalue(VolRayOpt::ZCURSOR) * 256.0);
nuclear@22 93 connect(zslider, SIGNAL(valueChanged(int)), this, SLOT(zslider_change(int)));
nuclear@22 94
nuclear@22 95 QVBoxLayout *vbox = new QVBoxLayout;
nuclear@26 96 vbox->addWidget(slice_view);
nuclear@22 97 vbox->addWidget(chk_clip);
nuclear@22 98 vbox->addWidget(zslider);
nuclear@22 99
nuclear@30 100 group_slice->setLayout(vbox);
nuclear@30 101 }
nuclear@30 102
nuclear@31 103 QWidget *win = new QWidget;
nuclear@31 104 setWidget(win);
nuclear@31 105
nuclear@31 106 QVBoxLayout *vbox = new QVBoxLayout;
nuclear@31 107 vbox->addWidget(group_slice);
nuclear@31 108 vbox->addStretch();
nuclear@31 109
nuclear@31 110 win->setLayout(vbox);
nuclear@31 111 }
nuclear@31 112
nuclear@31 113 void SideWindow::zslider_change(int val)
nuclear@31 114 {
nuclear@31 115 volray_setvalue(VolRayOpt::ZCURSOR, (float)val / 256.0);
nuclear@31 116 }
nuclear@31 117
nuclear@31 118 void SideWindow::clip_change(int checked)
nuclear@31 119 {
nuclear@31 120 volray_setvalue(VolRayOpt::ZCLIP, checked);
nuclear@31 121 }
nuclear@31 122
nuclear@31 123
nuclear@31 124 XFerWin::XFerWin()
nuclear@31 125 {
nuclear@30 126 QGroupBox *group_xfer = new QGroupBox("Transfer function");
nuclear@30 127 {
nuclear@30 128 XFerGLView *xfer_view = new XFerGLView(glwlist[0]);
nuclear@30 129 glwlist.push_back(xfer_view);
nuclear@30 130
nuclear@30 131 QVBoxLayout *vbox = new QVBoxLayout;
nuclear@30 132 vbox->addWidget(xfer_view);
nuclear@30 133
nuclear@30 134 group_xfer->setLayout(vbox);
nuclear@22 135 }
nuclear@21 136
nuclear@21 137 QWidget *win = new QWidget;
nuclear@21 138 setWidget(win);
nuclear@22 139
nuclear@22 140 QVBoxLayout *vbox = new QVBoxLayout;
nuclear@30 141 vbox->addWidget(group_xfer);
nuclear@22 142 vbox->addStretch();
nuclear@22 143
nuclear@21 144 win->setLayout(vbox);
nuclear@21 145 }
nuclear@21 146
nuclear@28 147
nuclear@13 148 void post_redisplay()
nuclear@13 149 {
nuclear@28 150 for(auto glw : glwlist) {
nuclear@28 151 glw->updateGL();
nuclear@28 152 }
nuclear@13 153 }