qvolray

annotate 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
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@14 23 // side-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@13 29 // actions
nuclear@13 30 QAction *act_open = new QAction(qApp->style()->standardIcon(QStyle::SP_DialogOpenButton), "&Open...", this);
nuclear@13 31 act_open->setStatusTip("Open a volume dataset");
nuclear@13 32 QObject::connect(act_open, SIGNAL(triggered()), this, SLOT(open_volume()));
nuclear@13 33
nuclear@13 34 QAction *act_quit = new QAction("&Quit", this);
nuclear@13 35 act_quit->setStatusTip("Quit");
nuclear@13 36 QObject::connect(act_quit, SIGNAL(triggered()), this, SLOT(close()));
nuclear@13 37
nuclear@13 38 // menus
nuclear@13 39 QMenu *mfile = menuBar()->addMenu("&File");
nuclear@13 40 mfile->addAction(act_open);
nuclear@13 41 mfile->addAction(act_quit);
nuclear@13 42
nuclear@13 43 // toolbars
nuclear@13 44 QToolBar *tfile = addToolBar("&File");
nuclear@13 45 tfile->addAction(act_open);
nuclear@13 46
nuclear@13 47 statusBar();
nuclear@13 48 show();
nuclear@13 49 }
nuclear@13 50
nuclear@13 51 void MainWindow::open_volume()
nuclear@13 52 {
nuclear@13 53 QString fname = QFileDialog::getOpenFileName(this, "Open volume dataset", QString(), "Volume descriptors (*.vol)");
nuclear@13 54 if(!fname.isNull()) {
nuclear@13 55 Volume *vol = new Volume;
nuclear@13 56
nuclear@13 57 if(vol->load(qPrintable(fname))) {
nuclear@13 58 delete volume;
nuclear@13 59 volume = vol;
nuclear@13 60 volray_setvolume(vol);
nuclear@13 61 post_redisplay();
nuclear@13 62 } else {
nuclear@13 63 delete vol;
nuclear@13 64 }
nuclear@13 65 }
nuclear@13 66 }
nuclear@13 67
nuclear@14 68
nuclear@14 69 SideWindow::SideWindow()
nuclear@14 70 {
nuclear@30 71 QGroupBox *group_slice = new QGroupBox("Volume slice");
nuclear@22 72 {
nuclear@28 73 slice_view = new SliceGLView(glwlist[0]);
nuclear@28 74 glwlist.push_back(slice_view);
nuclear@26 75
nuclear@22 76 QCheckBox *chk_clip = new QCheckBox("clip");
nuclear@30 77 chk_clip->setStatusTip("Enable clipping at the current slice");
nuclear@22 78 chk_clip->setChecked(false);
nuclear@22 79 connect(chk_clip, SIGNAL(stateChanged(int)), this, SLOT(clip_change(int)));
nuclear@21 80
nuclear@22 81 QSlider *zslider = new QSlider(Qt::Horizontal);
nuclear@30 82 zslider->setStatusTip("Change current Z slice");
nuclear@22 83 zslider->setRange(0, 256);
nuclear@29 84 zslider->setValue(volray_getvalue(VolRayOpt::ZCURSOR) * 256.0);
nuclear@22 85 connect(zslider, SIGNAL(valueChanged(int)), this, SLOT(zslider_change(int)));
nuclear@22 86
nuclear@22 87 QVBoxLayout *vbox = new QVBoxLayout;
nuclear@26 88 vbox->addWidget(slice_view);
nuclear@22 89 vbox->addWidget(chk_clip);
nuclear@22 90 vbox->addWidget(zslider);
nuclear@22 91
nuclear@30 92 group_slice->setLayout(vbox);
nuclear@30 93 }
nuclear@30 94
nuclear@30 95 QGroupBox *group_xfer = new QGroupBox("Transfer function");
nuclear@30 96 {
nuclear@30 97 XFerGLView *xfer_view = new XFerGLView(glwlist[0]);
nuclear@30 98 glwlist.push_back(xfer_view);
nuclear@30 99
nuclear@30 100 QVBoxLayout *vbox = new QVBoxLayout;
nuclear@30 101 vbox->addWidget(xfer_view);
nuclear@30 102
nuclear@30 103 group_xfer->setLayout(vbox);
nuclear@22 104 }
nuclear@21 105
nuclear@21 106 QWidget *win = new QWidget;
nuclear@21 107 setWidget(win);
nuclear@22 108
nuclear@22 109 QVBoxLayout *vbox = new QVBoxLayout;
nuclear@30 110 vbox->addWidget(group_slice);
nuclear@30 111 vbox->addWidget(group_xfer);
nuclear@22 112 vbox->addStretch();
nuclear@22 113
nuclear@21 114 win->setLayout(vbox);
nuclear@21 115 }
nuclear@21 116
nuclear@21 117 void SideWindow::zslider_change(int val)
nuclear@21 118 {
nuclear@29 119 volray_setvalue(VolRayOpt::ZCURSOR, (float)val / 256.0);
nuclear@14 120 }
nuclear@14 121
nuclear@22 122 void SideWindow::clip_change(int checked)
nuclear@22 123 {
nuclear@29 124 volray_setvalue(VolRayOpt::ZCLIP, checked);
nuclear@22 125 }
nuclear@14 126
nuclear@28 127
nuclear@13 128 void post_redisplay()
nuclear@13 129 {
nuclear@28 130 for(auto glw : glwlist) {
nuclear@28 131 glw->updateGL();
nuclear@28 132 }
nuclear@13 133 }