qvolray

annotate 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
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@13 6
nuclear@13 7 static Volume *volume;
nuclear@28 8 std::vector<QGLWidget*> glwlist;
nuclear@26 9
nuclear@13 10 MainWindow::MainWindow()
nuclear@13 11 {
nuclear@13 12 setWindowTitle("Volume Renderer");
nuclear@13 13
nuclear@28 14 // OpenGL view (this must be initialized first)
nuclear@27 15 maingl = new MainGLView;
nuclear@26 16 setCentralWidget(maingl);
nuclear@28 17 glwlist.push_back(maingl);
nuclear@13 18
nuclear@14 19 // side-window
nuclear@14 20 sidewin = new SideWindow;
nuclear@14 21 sidewin->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
nuclear@14 22 sidewin->setFeatures(QDockWidget::DockWidgetMovable | QDockWidget::DockWidgetFloatable);
nuclear@14 23 addDockWidget(Qt::LeftDockWidgetArea, sidewin);
nuclear@14 24
nuclear@13 25 // actions
nuclear@13 26 QAction *act_open = new QAction(qApp->style()->standardIcon(QStyle::SP_DialogOpenButton), "&Open...", this);
nuclear@13 27 act_open->setStatusTip("Open a volume dataset");
nuclear@13 28 QObject::connect(act_open, SIGNAL(triggered()), this, SLOT(open_volume()));
nuclear@13 29
nuclear@13 30 QAction *act_quit = new QAction("&Quit", this);
nuclear@13 31 act_quit->setStatusTip("Quit");
nuclear@13 32 QObject::connect(act_quit, SIGNAL(triggered()), this, SLOT(close()));
nuclear@13 33
nuclear@13 34 // menus
nuclear@13 35 QMenu *mfile = menuBar()->addMenu("&File");
nuclear@13 36 mfile->addAction(act_open);
nuclear@13 37 mfile->addAction(act_quit);
nuclear@13 38
nuclear@13 39 // toolbars
nuclear@13 40 QToolBar *tfile = addToolBar("&File");
nuclear@13 41 tfile->addAction(act_open);
nuclear@13 42
nuclear@13 43 statusBar();
nuclear@13 44 show();
nuclear@13 45 }
nuclear@13 46
nuclear@13 47 void MainWindow::open_volume()
nuclear@13 48 {
nuclear@13 49 QString fname = QFileDialog::getOpenFileName(this, "Open volume dataset", QString(), "Volume descriptors (*.vol)");
nuclear@13 50 if(!fname.isNull()) {
nuclear@13 51 Volume *vol = new Volume;
nuclear@13 52
nuclear@13 53 if(vol->load(qPrintable(fname))) {
nuclear@13 54 delete volume;
nuclear@13 55 volume = vol;
nuclear@13 56 volray_setvolume(vol);
nuclear@13 57 post_redisplay();
nuclear@13 58 } else {
nuclear@13 59 delete vol;
nuclear@13 60 }
nuclear@13 61 }
nuclear@13 62 }
nuclear@13 63
nuclear@14 64
nuclear@14 65 SideWindow::SideWindow()
nuclear@14 66 {
nuclear@22 67 QGroupBox *groupbox = new QGroupBox("Volume slice");
nuclear@22 68 {
nuclear@28 69 slice_view = new SliceGLView(glwlist[0]);
nuclear@28 70 glwlist.push_back(slice_view);
nuclear@26 71
nuclear@22 72 QCheckBox *chk_clip = new QCheckBox("clip");
nuclear@22 73 chk_clip->setChecked(false);
nuclear@22 74 connect(chk_clip, SIGNAL(stateChanged(int)), this, SLOT(clip_change(int)));
nuclear@21 75
nuclear@22 76 QSlider *zslider = new QSlider(Qt::Horizontal);
nuclear@22 77 zslider->setRange(0, 256);
nuclear@22 78 zslider->setValue(volray_getvalue(VOLRAY_ZCURSOR) * 256.0);
nuclear@22 79 connect(zslider, SIGNAL(valueChanged(int)), this, SLOT(zslider_change(int)));
nuclear@22 80
nuclear@22 81 QVBoxLayout *vbox = new QVBoxLayout;
nuclear@26 82 vbox->addWidget(slice_view);
nuclear@22 83 vbox->addWidget(chk_clip);
nuclear@22 84 vbox->addWidget(zslider);
nuclear@22 85
nuclear@22 86 groupbox->setLayout(vbox);
nuclear@22 87 }
nuclear@21 88
nuclear@21 89 QWidget *win = new QWidget;
nuclear@21 90 setWidget(win);
nuclear@22 91
nuclear@22 92 QVBoxLayout *vbox = new QVBoxLayout;
nuclear@22 93 vbox->addWidget(groupbox);
nuclear@22 94 vbox->addStretch();
nuclear@22 95
nuclear@21 96 win->setLayout(vbox);
nuclear@21 97 }
nuclear@21 98
nuclear@21 99 void SideWindow::zslider_change(int val)
nuclear@21 100 {
nuclear@21 101 volray_setvalue(VOLRAY_ZCURSOR, (float)val / 256.0);
nuclear@14 102 }
nuclear@14 103
nuclear@22 104 void SideWindow::clip_change(int checked)
nuclear@22 105 {
nuclear@22 106 volray_setvalue(VOLRAY_ZCLIP, checked);
nuclear@22 107 }
nuclear@14 108
nuclear@28 109
nuclear@13 110 void post_redisplay()
nuclear@13 111 {
nuclear@28 112 for(auto glw : glwlist) {
nuclear@28 113 glw->updateGL();
nuclear@28 114 }
nuclear@13 115 }