nuclear@13: #include nuclear@13: #include nuclear@28: #include nuclear@13: #include nuclear@13: #include "ui.h" nuclear@30: #include "ui_maingl.h" nuclear@30: #include "ui_sliceview.h" nuclear@30: #include "ui_xferview.h" nuclear@30: nuclear@13: nuclear@13: static Volume *volume; nuclear@28: std::vector glwlist; nuclear@26: nuclear@13: MainWindow::MainWindow() nuclear@13: { nuclear@13: setWindowTitle("Volume Renderer"); nuclear@13: nuclear@28: // OpenGL view (this must be initialized first) nuclear@27: maingl = new MainGLView; nuclear@26: setCentralWidget(maingl); nuclear@28: glwlist.push_back(maingl); nuclear@13: nuclear@14: // side-window nuclear@14: sidewin = new SideWindow; nuclear@14: sidewin->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea); nuclear@14: sidewin->setFeatures(QDockWidget::DockWidgetMovable | QDockWidget::DockWidgetFloatable); nuclear@14: addDockWidget(Qt::LeftDockWidgetArea, sidewin); nuclear@14: nuclear@13: // actions nuclear@13: QAction *act_open = new QAction(qApp->style()->standardIcon(QStyle::SP_DialogOpenButton), "&Open...", this); nuclear@13: act_open->setStatusTip("Open a volume dataset"); nuclear@13: QObject::connect(act_open, SIGNAL(triggered()), this, SLOT(open_volume())); nuclear@13: nuclear@13: QAction *act_quit = new QAction("&Quit", this); nuclear@13: act_quit->setStatusTip("Quit"); nuclear@13: QObject::connect(act_quit, SIGNAL(triggered()), this, SLOT(close())); nuclear@13: nuclear@13: // menus nuclear@13: QMenu *mfile = menuBar()->addMenu("&File"); nuclear@13: mfile->addAction(act_open); nuclear@13: mfile->addAction(act_quit); nuclear@13: nuclear@13: // toolbars nuclear@13: QToolBar *tfile = addToolBar("&File"); nuclear@13: tfile->addAction(act_open); nuclear@13: nuclear@13: statusBar(); nuclear@13: show(); nuclear@13: } nuclear@13: nuclear@13: void MainWindow::open_volume() nuclear@13: { nuclear@13: QString fname = QFileDialog::getOpenFileName(this, "Open volume dataset", QString(), "Volume descriptors (*.vol)"); nuclear@13: if(!fname.isNull()) { nuclear@13: Volume *vol = new Volume; nuclear@13: nuclear@13: if(vol->load(qPrintable(fname))) { nuclear@13: delete volume; nuclear@13: volume = vol; nuclear@13: volray_setvolume(vol); nuclear@13: post_redisplay(); nuclear@13: } else { nuclear@13: delete vol; nuclear@13: } nuclear@13: } nuclear@13: } nuclear@13: nuclear@14: nuclear@14: SideWindow::SideWindow() nuclear@14: { nuclear@30: QGroupBox *group_slice = new QGroupBox("Volume slice"); nuclear@22: { nuclear@28: slice_view = new SliceGLView(glwlist[0]); nuclear@28: glwlist.push_back(slice_view); nuclear@26: nuclear@22: QCheckBox *chk_clip = new QCheckBox("clip"); nuclear@30: chk_clip->setStatusTip("Enable clipping at the current slice"); nuclear@22: chk_clip->setChecked(false); nuclear@22: connect(chk_clip, SIGNAL(stateChanged(int)), this, SLOT(clip_change(int))); nuclear@21: nuclear@22: QSlider *zslider = new QSlider(Qt::Horizontal); nuclear@30: zslider->setStatusTip("Change current Z slice"); nuclear@22: zslider->setRange(0, 256); nuclear@29: zslider->setValue(volray_getvalue(VolRayOpt::ZCURSOR) * 256.0); nuclear@22: connect(zslider, SIGNAL(valueChanged(int)), this, SLOT(zslider_change(int))); nuclear@22: nuclear@22: QVBoxLayout *vbox = new QVBoxLayout; nuclear@26: vbox->addWidget(slice_view); nuclear@22: vbox->addWidget(chk_clip); nuclear@22: vbox->addWidget(zslider); nuclear@22: nuclear@30: group_slice->setLayout(vbox); nuclear@30: } nuclear@30: nuclear@30: QGroupBox *group_xfer = new QGroupBox("Transfer function"); nuclear@30: { nuclear@30: XFerGLView *xfer_view = new XFerGLView(glwlist[0]); nuclear@30: glwlist.push_back(xfer_view); nuclear@30: nuclear@30: QVBoxLayout *vbox = new QVBoxLayout; nuclear@30: vbox->addWidget(xfer_view); nuclear@30: nuclear@30: group_xfer->setLayout(vbox); nuclear@22: } nuclear@21: nuclear@21: QWidget *win = new QWidget; nuclear@21: setWidget(win); nuclear@22: nuclear@22: QVBoxLayout *vbox = new QVBoxLayout; nuclear@30: vbox->addWidget(group_slice); nuclear@30: vbox->addWidget(group_xfer); nuclear@22: vbox->addStretch(); nuclear@22: nuclear@21: win->setLayout(vbox); nuclear@21: } nuclear@21: nuclear@21: void SideWindow::zslider_change(int val) nuclear@21: { nuclear@29: volray_setvalue(VolRayOpt::ZCURSOR, (float)val / 256.0); nuclear@14: } nuclear@14: nuclear@22: void SideWindow::clip_change(int checked) nuclear@22: { nuclear@29: volray_setvalue(VolRayOpt::ZCLIP, checked); nuclear@22: } nuclear@14: nuclear@28: nuclear@13: void post_redisplay() nuclear@13: { nuclear@28: for(auto glw : glwlist) { nuclear@28: glw->updateGL(); nuclear@28: } nuclear@13: }