Skip to content

Commit

Permalink
ENH: Add setting to switch between viewport logic
Browse files Browse the repository at this point in the history
  • Loading branch information
NicerNewerCar committed Oct 18, 2023
1 parent 16e4606 commit ecb375e
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 2 deletions.
8 changes: 8 additions & 0 deletions autoscoper/src/ui/AutoscoperMainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1130,6 +1130,7 @@ bool AutoscoperMainWindow::openTrial(QString filename){
try {
Trial * trial = new Trial(filename.toStdString().c_str());
tracker->load(*trial);
tracker->SetViewportLogic(this->use_new_viewport_logic_);
delete trial;

trial_filename = filename.toStdString().c_str();
Expand Down Expand Up @@ -1721,6 +1722,13 @@ void AutoscoperMainWindow::on_actionLoad_xml_batch_triggered(bool checked){
}
}

void AutoscoperMainWindow::on_actionUse_New_Viewport_Logic_triggered(bool checked) {
this->use_new_viewport_logic_ = checked;
if (tracker != NULL) {
tracker->SetViewportLogic(checked);
}
}


//Edit menu
void AutoscoperMainWindow::on_actionUndo_triggered(bool checked){
Expand Down
2 changes: 2 additions & 0 deletions autoscoper/src/ui/AutoscoperMainWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ class AutoscoperMainWindow : public QMainWindow{
Tracker * tracker;
GLTracker * gltracker;
QOpenGLContext* shared_glcontext;
bool use_new_viewport_logic_ = false;

//Manipulator
std::vector <Manip3D *> manipulator;
Expand Down Expand Up @@ -222,6 +223,7 @@ class AutoscoperMainWindow : public QMainWindow{
void on_actionSave_Test_Sequence_triggered(bool checked);
void on_actionSaveForBatch_triggered(bool checked);
void on_actionLoad_xml_batch_triggered(bool checked);
void on_actionUse_New_Viewport_Logic_triggered(bool checked);

//Edit
void on_actionUndo_triggered(bool checked);
Expand Down
10 changes: 10 additions & 0 deletions autoscoper/src/ui/ui-files/AutoscoperMainWindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,8 @@ Dialog</string>
<addaction name="separator"/>
<addaction name="actionSave_Test_Sequence"/>
<addaction name="separator"/>
<addaction name="actionUse_New_Viewport_Logic"/>
<addaction name="separator"/>
<addaction name="actionQuit"/>
</widget>
<widget class="QMenu" name="menuEdit">
Expand Down Expand Up @@ -717,6 +719,14 @@ Dialog</string>
<string>Thick Line Mode</string>
</property>
</action>
<action name="actionUse_New_Viewport_Logic">
<property name="checkable">
<bool>true</bool>
</property>
<property name="text">
<string>Use New Viewport Logic</string>
</property>
</action>
</widget>
<resources>
<include location="../autoscoper_resource.qrc"/>
Expand Down
11 changes: 9 additions & 2 deletions libautoscoper/src/Tracker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -601,8 +601,12 @@ std::vector <double> Tracker::trackFrame(unsigned int volumeID, double* xyzypr)

// Calculate the size of the image to render based on the viewport
// For more information, see https://github.com/BrownBiomechanics/Autoscoper/issues/203
unsigned render_width = (trial_.render_width * (viewport[2] + 1)) / 2;
unsigned render_height = (trial_.render_height * (viewport[3] + 1)) / 2;
unsigned render_width = viewport[2] * trial_.render_width / views_[i]->camera()->viewport()[2];
unsigned render_height = viewport[3] * trial_.render_height / views_[i]->camera()->viewport()[3];
if (this->use_new_viewport_logic_) {
render_width = ((trial_.render_width * (viewport[2] + 1)) / 2) - ((trial_.render_width * (viewport[0] + 1)) / 2); // (width * (max_x + 1)) / 2 - (width * (min_x + 1)) / 2
render_height = ((trial_.render_height * (viewport[3] + 1)) / 2) - ((trial_.render_height * (viewport[1] + 1)) / 2); // (height * (max_y + 1)) / 2 - (height * (min_y + 1)) / 2
}

if (render_width > trial_.render_width || render_height > trial_.render_height) {
throw std::runtime_error("Tracker::trackFrame(): Rendered image is larger than the viewport buffer!\n" + std::to_string(render_width) + " > " + std::to_string(trial_.render_width) + " || " + std::to_string(render_height) + " > " + std::to_string(trial_.render_height));
Expand Down Expand Up @@ -882,6 +886,9 @@ void Tracker::getFullDRR(unsigned int volumeID) const
}
}

void Tracker::SetViewportLogic(bool use_new) {
this->use_new_viewport_logic_ = use_new;
}



Expand Down
2 changes: 2 additions & 0 deletions libautoscoper/src/Tracker.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ namespace xromm
//std::vector<double> trackImplantFrame(unsigned int volumeID, double * xyzypr) const;

void getFullDRR(unsigned int volumeID) const;
void SetViewportLogic(bool use_new);


private:
Expand All @@ -111,6 +112,7 @@ namespace xromm
Trial trial_;
std::vector <gpu::VolumeDescription*> volumeDescription_;
std::vector <gpu::View*> views_;
bool use_new_viewport_logic_ = false;
#if defined(Autoscoper_RENDERING_USE_CUDA_BACKEND)
Buffer* rendered_drr_;
Buffer* rendered_rad_;
Expand Down

0 comments on commit ecb375e

Please sign in to comment.