Skip to content

Commit

Permalink
Studio analysis updates (#2322)
Browse files Browse the repository at this point in the history
* Reduce the number of places where the number of viewers gets reset as it is really annoying when you are on a single viewer and change a setting and it goes back to 4x4.

* Fix scalar bar text positioning changing by changing order of actor adding.  Not sure why this fixes it or what the original problem was.

* Adding ability to show colormap on slice contour.

* Fixing colormap for contour slice view

* Fixing colormap issues.  No longer resetting view when changing uniform on/off

* Fixing display of contours without feature maps.

* Fix bug where transform is mistakenly inverted with slice change

* Fix display of non-feature contour

* Add ability to show shape intersection with multiple domains.
  • Loading branch information
akenmorris authored Sep 4, 2024
1 parent 141af99 commit 9fbc86f
Show file tree
Hide file tree
Showing 11 changed files with 108 additions and 56 deletions.
6 changes: 2 additions & 4 deletions Studio/Analysis/AnalysisTool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -323,9 +323,6 @@ QSharedPointer<Session> AnalysisTool::get_session() { return session_; }
//---------------------------------------------------------------------------
void AnalysisTool::set_app(ShapeWorksStudioApp* app) { app_ = app; }

//---------------------------------------------------------------------------
void AnalysisTool::update_analysis_mode() { handle_analysis_options(); }

//---------------------------------------------------------------------------
void AnalysisTool::update_interface() {
ui_->show_good_bad->setEnabled(session_->get_good_bad_particles().size() == session_->get_num_particles());
Expand Down Expand Up @@ -393,6 +390,7 @@ void AnalysisTool::handle_analysis_options() {

update_difference_particles();

Q_EMIT analysis_mode_changed();
Q_EMIT update_view();
}

Expand Down Expand Up @@ -978,7 +976,7 @@ bool AnalysisTool::pca_shape_plus_scalar_mode() { return ui_->pca_shape_and_scal
bool AnalysisTool::pca_shape_only_mode() { return ui_->pca_scalar_shape_only->isChecked(); }

//---------------------------------------------------------------------------
void AnalysisTool::on_tabWidget_currentChanged() { update_analysis_mode(); }
void AnalysisTool::on_tabWidget_currentChanged() { handle_analysis_options(); }

//---------------------------------------------------------------------------
void AnalysisTool::on_pcaSlider_valueChanged() {
Expand Down
3 changes: 2 additions & 1 deletion Studio/Analysis/AnalysisTool.h
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ class AnalysisTool : public QWidget {
Q_SIGNALS:

void update_view();
void analysis_mode_changed();
void pca_update();
void progress(int);
void reconstruction_complete();
Expand All @@ -217,7 +218,7 @@ class AnalysisTool : public QWidget {
bool active_ = false;

void pca_labels_changed(QString value, QString eigen, QString lambda);
void update_analysis_mode();

void update_interface();

bool group_pvalues_valid();
Expand Down
17 changes: 17 additions & 0 deletions Studio/Data/Session.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -944,6 +944,17 @@ void Session::set_feature_range_max(double value) {
Q_EMIT feature_range_changed();
}

//---------------------------------------------------------------------------
void Session::set_feature_uniform_scale(bool value) {
if (!is_loading()) {
params_.set("feature_uniform_scale", value);
Q_EMIT feature_range_changed();
}
}

//---------------------------------------------------------------------------
bool Session::get_feature_uniform_scale() { return params_.get("feature_uniform_scale", true); }

//---------------------------------------------------------------------------
void Session::handle_ctrl_click(PickResult result) {
if (get_tool_state() != Session::DATA_C) {
Expand Down Expand Up @@ -1174,11 +1185,17 @@ bool Session::is_loading() { return is_loading_; }

//---------------------------------------------------------------------------
void Session::set_tool_state(std::string state) {
std::string current_state = get_tool_state();
if (state == current_state) {
return;
}

parameters().set("tool_state", state);
// these need to be updated so that the handles appear/disappear
trigger_landmarks_changed();
trigger_planes_changed();
Q_EMIT ffc_paint_mode_changed();
Q_EMIT tool_state_changed();
}

//---------------------------------------------------------------------------
Expand Down
4 changes: 4 additions & 0 deletions Studio/Data/Session.h
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,9 @@ class Session : public QObject, public QEnableSharedFromThis<Session> {
void set_feature_range_min(double value);
void set_feature_range_max(double value);

void set_feature_uniform_scale(bool value);
bool get_feature_uniform_scale();

void handle_ctrl_click(PickResult result);

void trigger_landmarks_changed();
Expand Down Expand Up @@ -286,6 +289,7 @@ class Session : public QObject, public QEnableSharedFromThis<Session> {
Q_SIGNALS:
/// signal that the data has changed
void data_changed();
void tool_state_changed();
void points_changed();
void landmarks_changed();
void planes_changed();
Expand Down
47 changes: 17 additions & 30 deletions Studio/Interface/ShapeWorksStudioApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ ShapeWorksStudioApp::ShapeWorksStudioApp() {
ui_->stacked_widget->addWidget(analysis_tool_.data());
connect(analysis_tool_.data(), &AnalysisTool::update_view, this,
&ShapeWorksStudioApp::handle_display_setting_changed);
connect(analysis_tool_.data(), &AnalysisTool::analysis_mode_changed, this, &ShapeWorksStudioApp::reset_num_viewers);
connect(analysis_tool_.data(), &AnalysisTool::pca_update, this, &ShapeWorksStudioApp::handle_pca_update);
connect(analysis_tool_.data(), &AnalysisTool::progress, this, &ShapeWorksStudioApp::handle_progress);
connect(analysis_tool_.data(), &AnalysisTool::reconstruction_complete, this,
Expand Down Expand Up @@ -974,6 +975,7 @@ void ShapeWorksStudioApp::new_session() {
connect(session_.data(), &Session::new_mesh, this, &ShapeWorksStudioApp::handle_new_mesh);
connect(session_.data(), &Session::reinsert_shapes, this, [&]() { update_display(true); });
connect(session_.data(), &Session::save, this, &ShapeWorksStudioApp::on_action_save_project_triggered);
connect(session_.data(), &Session::tool_state_changed, this, &ShapeWorksStudioApp::update_tool_mode);

connect(ui_->feature_auto_scale, &QCheckBox::toggled, this, &ShapeWorksStudioApp::update_feature_map_scale);
connect(ui_->feature_auto_scale, &QCheckBox::toggled, session_.data(), &Session::set_feature_auto_scale);
Expand Down Expand Up @@ -1077,6 +1079,9 @@ void ShapeWorksStudioApp::update_tool_mode() {
->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
ui_->stacked_widget->adjustSize();

reset_num_viewers();
visualizer_->reset_camera();

update_view_combo();

on_actionShow_Tool_Window_triggered();
Expand Down Expand Up @@ -1148,37 +1153,19 @@ bool ShapeWorksStudioApp::is_view_combo_item_enabled(int item) {
}

//---------------------------------------------------------------------------
void ShapeWorksStudioApp::on_action_import_mode_triggered() {
session_->set_tool_state(Session::DATA_C);
update_tool_mode();
}
void ShapeWorksStudioApp::on_action_import_mode_triggered() { session_->set_tool_state(Session::DATA_C); }

//---------------------------------------------------------------------------
void ShapeWorksStudioApp::on_action_groom_mode_triggered() {
session_->set_tool_state(Session::GROOM_C);
update_tool_mode();
}
void ShapeWorksStudioApp::on_action_groom_mode_triggered() { session_->set_tool_state(Session::GROOM_C); }

//---------------------------------------------------------------------------
void ShapeWorksStudioApp::on_action_optimize_mode_triggered() {
session_->set_tool_state(Session::OPTIMIZE_C);
update_tool_mode();
visualizer_->reset_camera();
}
void ShapeWorksStudioApp::on_action_optimize_mode_triggered() { session_->set_tool_state(Session::OPTIMIZE_C); }

//---------------------------------------------------------------------------
void ShapeWorksStudioApp::on_action_analysis_mode_triggered() {
session_->set_tool_state(Session::ANALYSIS_C);
update_tool_mode();
visualizer_->reset_camera();
}
void ShapeWorksStudioApp::on_action_analysis_mode_triggered() { session_->set_tool_state(Session::ANALYSIS_C); }

//---------------------------------------------------------------------------
void ShapeWorksStudioApp::on_action_deepssm_mode_triggered() {
session_->set_tool_state(Session::DEEPSSM_C);
update_tool_mode();
visualizer_->reset_camera();
}
void ShapeWorksStudioApp::on_action_deepssm_mode_triggered() { session_->set_tool_state(Session::DEEPSSM_C); }

//---------------------------------------------------------------------------
void ShapeWorksStudioApp::handle_project_changed() {
Expand Down Expand Up @@ -1429,8 +1416,9 @@ void ShapeWorksStudioApp::update_display(bool force) {

lightbox_->update_interactor_style();

if ((force || change) && !session_->is_loading()) { // do not override if loading
reset_num_viewers();
// if ((force || change) && !session_->is_loading()) { // do not override if loading
if (change && !session_->is_loading()) { // do not override if loading
// reset_num_viewers();
}

update_scrollbar();
Expand Down Expand Up @@ -2050,6 +2038,7 @@ void ShapeWorksStudioApp::update_feature_map_scale() {
bool auto_mode = ui_->feature_auto_scale->isChecked();
ui_->feature_min->setEnabled(!auto_mode);
ui_->feature_max->setEnabled(!auto_mode);
ui_->feature_auto_scale->setEnabled(ui_->feature_uniform_scale->isChecked());
if (!auto_mode) {
if (session_->get_feature_range_min() == 0 && session_->get_feature_range_max() == 0) {
if (visualizer_->get_feature_range_valid()) {
Expand All @@ -2068,15 +2057,13 @@ void ShapeWorksStudioApp::image_combo_changed(int index) {

//---------------------------------------------------------------------------
bool ShapeWorksStudioApp::get_feature_uniform_scale() {
return session_->parameters().get("feature_uniform_scale", true);
return session_->get_feature_uniform_scale();
}

//---------------------------------------------------------------------------
void ShapeWorksStudioApp::set_feature_uniform_scale(bool value) {
if (!session_->is_loading()) {
session_->parameters().set("feature_uniform_scale", value);
update_view_mode();
}
session_->set_feature_uniform_scale(value);
update_feature_map_scale();
}

//---------------------------------------------------------------------------
Expand Down
9 changes: 7 additions & 2 deletions Studio/Visualization/Lightbox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -509,9 +509,14 @@ void Lightbox::set_orientation_marker_viewport() {

//-----------------------------------------------------------------------------
void Lightbox::update_feature_range() {
if (visualizer_->get_feature_map() != "" && visualizer_->get_uniform_feature_range()) {
for (int i = 0; i < viewers_.size(); i++) {
if (visualizer_->get_feature_map() == "") {
return;
}
for (int i = 0; i < viewers_.size(); i++) {
if (visualizer_->get_uniform_feature_range()) {
viewers_[i]->update_feature_range(visualizer_->get_feature_range());
} else {
viewers_[i]->reset_feature_range();
}
}
}
Expand Down
29 changes: 24 additions & 5 deletions Studio/Visualization/SliceView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <vtkImageActorPointPlacer.h>
#include <vtkImageProperty.h>
#include <vtkImageSliceMapper.h>
#include <vtkLookupTable.h>
#include <vtkNamedColors.h>
#include <vtkPolyDataMapper.h>
#include <vtkProperty.h>
Expand Down Expand Up @@ -57,9 +58,7 @@ vtkSmartPointer<vtkActor> SliceView::create_shape_actor(vtkSmartPointer<vtkPolyD
//-----------------------------------------------------------------------------
SliceView::SliceView(Viewer *viewer) : viewer_(viewer) {
image_slice_ = vtkSmartPointer<vtkImageActor>::New();

slice_mapper_ = vtkSmartPointer<vtkImageSliceMapper>::New();

placer_ = vtkSmartPointer<vtkImageActorPointPlacer>::New();
placer_->SetImageActor(image_slice_);
}
Expand Down Expand Up @@ -139,6 +138,22 @@ void SliceView::set_orientation(int orientation) {
//-----------------------------------------------------------------------------
bool SliceView::is_image_loaded() { return volume_ != nullptr; }

//-----------------------------------------------------------------------------
void SliceView::update_colormap() {
for (auto &actor : cut_actors_) {
auto mapper = actor->GetMapper();
if (viewer_->showing_feature_map()) {
mapper->SetScalarVisibility(true);
mapper->SetColorModeToMapScalars();
mapper->SetLookupTable(viewer_->get_surface_lut());
mapper->SetScalarRange(viewer_->get_surface_lut()->GetTableRange());
} else{
mapper->SetScalarVisibility(false);
mapper->SetScalarModeToDefault();
}
}
}

//-----------------------------------------------------------------------------
void SliceView::update_renderer() {
auto renderer = viewer_->get_renderer();
Expand Down Expand Up @@ -245,9 +260,13 @@ Point SliceView::get_slice_position() {

// convert to world coordinates
auto transform = viewer_->get_image_transform();
transform->Update();
transform->Inverse();
transform->TransformPoint(origin, origin);

// make a local copy
vtkSmartPointer<vtkTransform> transform_copy = vtkSmartPointer<vtkTransform>::New();
transform_copy->SetMatrix(transform->GetMatrix());
transform_copy->Update();
transform_copy->Inverse();
transform_copy->TransformPoint(origin, origin);

return Point({origin[0], origin[1], origin[2]});
}
Expand Down
2 changes: 2 additions & 0 deletions Studio/Visualization/SliceView.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class SliceView {

bool is_image_loaded();

void update_colormap();
void update_renderer();

void update_camera();
Expand Down Expand Up @@ -84,6 +85,7 @@ class SliceView {
int current_slice_number_ = 0;

std::vector<vtkSmartPointer<vtkActor>> cut_actors_;
///std::vector<vtkSmartPointer<vtkPolyDataMapper>>

std::vector<vtkSmartPointer<vtkPolyData>> poly_datas_;
};
Expand Down
34 changes: 22 additions & 12 deletions Studio/Visualization/Viewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1038,6 +1038,8 @@ void Viewer::update_actors() {
renderer_->RemoveActor(compare_actors_[i]);
}

// now add back

if (show_glyphs_) {
renderer_->AddActor(glyph_actor_);

Expand All @@ -1046,10 +1048,6 @@ void Viewer::update_actors() {
}
}

if ((show_glyphs_ && arrows_visible_) || showing_feature_map()) {
renderer_->AddActor(scalar_bar_actor_);
}

if (show_surface_ && meshes_.valid()) {
for (int i = 0; i < number_of_domains_; i++) {
renderer_->AddActor(unclipped_surface_actors_[i]);
Expand All @@ -1071,6 +1069,10 @@ void Viewer::update_actors() {
}
}

if ((show_glyphs_ && arrows_visible_) || showing_feature_map()) {
renderer_->AddActor(scalar_bar_actor_);
}

slice_view_.update_renderer();

update_opacities();
Expand Down Expand Up @@ -1139,6 +1141,8 @@ void Viewer::set_scalar_visibility(vtkSmartPointer<vtkPolyData> poly_data, vtkSm
if (scalars) {
double range[2];
scalars->GetRange(range);
lut_min_ = range[0];
lut_max_ = range[1];
update_difference_lut(range[0], range[1]);
mapper->SetScalarRange(range[0], range[1]);
visualizer_->update_feature_range(range);
Expand All @@ -1154,14 +1158,16 @@ void Viewer::update_image_volume(bool force) {

if (meshes_.valid()) {
slice_view_.clear_meshes();
auto poly_data = meshes_.meshes()[0]->get_poly_data();
slice_view_.add_mesh(poly_data);

if (session_->get_image_thickness_feature()) {
auto target_feature = session_->get_feature_map();
if (target_feature != "" && target_feature != "-none-") {
Mesh inner = mesh::compute_inner_mesh(poly_data, target_feature);
slice_view_.add_mesh(inner.getVTKMesh());
for (size_t i = 0; i < meshes_.meshes().size(); i++) {
auto poly_data = meshes_.meshes()[i]->get_poly_data();
slice_view_.add_mesh(poly_data);

if (session_->get_image_thickness_feature()) {
auto target_feature = session_->get_feature_map();
if (target_feature != "" && target_feature != "-none-") {
Mesh inner = mesh::compute_inner_mesh(poly_data, target_feature);
slice_view_.add_mesh(inner.getVTKMesh());
}
}
}
}
Expand Down Expand Up @@ -1283,6 +1289,7 @@ void Viewer::update_difference_lut(float r0, float r1) {
arrow_glyph_mapper_->SetScalarRange(range);
glyph_mapper_->SetScalarRange(range);
scalar_bar_actor_->SetLookupTable(surface_lut_);
slice_view_.update_colormap();
if (rd > 100) {
scalar_bar_actor_->SetLabelFormat("%.0f");
} else if (rd > 1) {
Expand All @@ -1303,6 +1310,9 @@ bool Viewer::showing_feature_map() {
//-----------------------------------------------------------------------------
void Viewer::update_feature_range(double* range) { update_difference_lut(range[0], range[1]); }

//-----------------------------------------------------------------------------
void Viewer::reset_feature_range() { update_difference_lut(lut_min_, lut_max_); }

//-----------------------------------------------------------------------------
void Viewer::update_opacities() {
auto opacities = visualizer_->get_opacities();
Expand Down
Loading

0 comments on commit 9fbc86f

Please sign in to comment.