Skip to content

Commit

Permalink
ENH: Add option to enable/disable a single DRR
Browse files Browse the repository at this point in the history
  • Loading branch information
NicerNewerCar committed Oct 19, 2023
1 parent 16e4606 commit 2d96a12
Show file tree
Hide file tree
Showing 9 changed files with 102 additions and 6 deletions.
2 changes: 2 additions & 0 deletions autoscoper/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ set(autoscoper_FORMS_HEADERS
src/ui/VolumeDockWidget.h
src/ui/WorldViewWindow.h
src/ui/VolumeBox.h
src/ui/VolumeListWidgetItem.h
src/net/Socket.h
src/ui/AboutAutoscoper.h
)
Expand Down Expand Up @@ -62,6 +63,7 @@ set(autoscoper_FORMS_SOURCES
src/ui/WorldViewWindow.cpp
src/ui/VolumeDockWidget.cpp
src/ui/VolumeBox.cpp
src/ui/VolumeListWidgetItem.cpp
src/net/Socket.cpp
)

Expand Down
2 changes: 1 addition & 1 deletion autoscoper/src/ui/AutoscoperMainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -594,7 +594,7 @@ void AutoscoperMainWindow::setupUI()
//Add Volumes
for (unsigned int i = 0; i < tracker->trial()->volumes.size(); i++) {
std::cout << "Volume Name: " << tracker->trial()->volumes[i].name() << std::endl;
volumes_widget->addVolume(tracker->trial()->volumes[i].name());
volumes_widget->addVolume(tracker->trial()->volumes[i].name(), i);
}

//Add the new cameras
Expand Down
11 changes: 8 additions & 3 deletions autoscoper/src/ui/VolumeDockWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
#include "ui_VolumeDockWidget.h"
#include "ui/VolumeDockWidget.h"
#include "ui/AutoscoperMainWindow.h"
#include "ui/VolumeListWidgetItem.h"

#include "Tracker.hpp"
#include "Trial.hpp"
#include "View.hpp"

#include <QFileInfo>

Expand Down Expand Up @@ -42,12 +44,15 @@ void VolumeDockWidget::clearVol(){
n = dock->listWidget->count();*/
}

void VolumeDockWidget::addVolume(const std::string& filename){
QListWidgetItem* volumeItem = new QListWidgetItem();
void VolumeDockWidget::addVolume(const std::string& filename, int idx){
QFileInfo fi (QString::fromStdString(filename));

volumeItem->setText(fi.completeBaseName());
std::vector<xromm::gpu::RayCaster*> renderers = {};
for (xromm::gpu::View *view : mainwindow->getTracker()->views()) {
renderers.push_back(view->drrRenderer(idx));
}

QListWidgetItem* volumeItem = new VolumeListWidgetItem(dock->listWidget, fi.completeBaseName() ,mainwindow, &renderers);
dock->listWidget->addItem(volumeItem);
dock->listWidget->setCurrentItem(volumeItem);

Expand Down
2 changes: 1 addition & 1 deletion autoscoper/src/ui/VolumeDockWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class VolumeDockWidget : public QDockWidget{
AutoscoperMainWindow * getMainWindow(){return mainwindow;};

void clearVol();
void addVolume(const std::string& filename);
void addVolume(const std::string& filename, int idx);


QString getVolumeName(int volume_index);
Expand Down
48 changes: 48 additions & 0 deletions autoscoper/src/ui/VolumeListWidgetItem.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#include "ui/VolumeListWidgetItem.h"
#include "ui/AutoscoperMainWindow.h"

#include <QCheckBox>
#include <QDockWidget>
#include <QLabel>
#include <QGridLayout>
#include <QSpacerItem>

#if defined(Autoscoper_RENDERING_USE_CUDA_BACKEND)
#include <gpu/cuda/RayCaster.hpp>
#elif defined(Autoscoper_RENDERING_USE_OpenCL_BACKEND)
#include <gpu/opencl/RayCaster.hpp>
#endif

VolumeListWidgetItem::VolumeListWidgetItem(QListWidget* listWidget,QString name, AutoscoperMainWindow* main_window, std::vector< xromm::gpu::RayCaster*>* renderers) : QListWidgetItem(listWidget) {
this->name_ = name;
this->main_window_ = main_window;
for (xromm::gpu::RayCaster* renderer : *renderers) {
renderers_.push_back(renderer);
}
setup(listWidget);
}

void VolumeListWidgetItem::setup(QListWidget* listWidget) {
// add a layout
QFrame* pFrame = new QFrame(listWidget);
pFrame->setMinimumHeight(32);
QGridLayout* pLayout = new QGridLayout(pFrame);
pLayout->addWidget(new QLabel(name_), 0, 1);
visibleCheckBox_ = new QCheckBox();
visibleCheckBox_->setChecked(true);
pLayout->addWidget(visibleCheckBox_, 0, 0);
pLayout->addItem(new QSpacerItem(1, 1, QSizePolicy::Expanding, QSizePolicy::Minimum), 0, 2);
pLayout->setMargin(5);
pFrame->setLayout(pLayout);
listWidget->setItemWidget(this, pFrame);
visibleCheckBox_->connect(visibleCheckBox_, SIGNAL(stateChanged(int)), this, SLOT(on_visibleCheckBox__stateChanged(int)));
}

void VolumeListWidgetItem::on_visibleCheckBox__stateChanged(int state) {
if (renderers_.size() > 0) {
for (xromm::gpu::RayCaster* renderer : renderers_) {
renderer->setVisible((bool)state);
}
}
main_window_->volume_changed(); // update the volume
}
30 changes: 30 additions & 0 deletions autoscoper/src/ui/VolumeListWidgetItem.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#ifndef VOLUMELISTWIDGETITEM_H
#define VOLUMELISTWIDGETITEM_H

#include <QListWidgetItem>
#include <QObject>

class AutoscoperMainWindow;
class QCheckBox;
namespace xromm {
namespace gpu {
class RayCaster;
}
}

class VolumeListWidgetItem : public QObject, public QListWidgetItem {
// List Object to display the volume name and a checkbox to toggle visibility
Q_OBJECT
public:
VolumeListWidgetItem(QListWidget* listWidget, QString name, AutoscoperMainWindow* main_window, std::vector< xromm::gpu::RayCaster*>* renderers);
private:
std::vector< xromm::gpu::RayCaster*> renderers_;
QCheckBox *visibleCheckBox_;
QString name_;
AutoscoperMainWindow* main_window_;

void setup(QListWidget* listWidget);
public slots:
void on_visibleCheckBox__stateChanged(int state);
};
#endif // !VOLUMELISTWIDGETITEM_H
2 changes: 1 addition & 1 deletion autoscoper/src/ui/ui-files/VolumeDockWidget.ui
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<property name="minimumSize">
<size>
<width>250</width>
<height>137</height>
<height>209</height>
</size>
</property>
<property name="windowTitle">
Expand Down
6 changes: 6 additions & 0 deletions libautoscoper/src/gpu/opencl/RayCaster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ RayCaster::RayCaster() : volumeDescription_(0),

b_viewport_ = new Buffer(4*sizeof(float), CL_MEM_READ_ONLY);
b_viewport_->read(viewport_);
visible_ = true;
}

RayCaster::~RayCaster()
Expand Down Expand Up @@ -160,6 +161,11 @@ RayCaster::render(const Buffer* buffer, unsigned width, unsigned height)
return;
}

if (!visible_) {
buffer->fill((char)0x00);
return;
}

Kernel* kernel = raycaster_program_.compile(
RayCaster_cl, "volume_render_kernel");

Expand Down
5 changes: 5 additions & 0 deletions libautoscoper/src/gpu/opencl/RayCaster.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ class RayCaster
void setViewport(float x, float y, float width, float height);
void render(const Buffer* buffer, unsigned width, unsigned height);

void setVisible(bool visible) {
visible_ = visible;
}

float getSampleDistance() const {
return sampleDistance_;
}
Expand Down Expand Up @@ -109,6 +113,7 @@ class RayCaster
float rayIntensity_;
float cutoff_;
std::string name_;
bool visible_;
};

} } // namespace xromm::opencl
Expand Down

0 comments on commit 2d96a12

Please sign in to comment.