Skip to content

Commit c140a08

Browse files
authored
2346, 2354 - Landmarks zoom problem and crash on deleting all shapes (#2355)
* Fix crash when deleting all shapes * Fix #2346 - landmarks placed on wrong shape when zoomed in too far. The problem was that each viewer was checked independently regardless of which square it was in. When zoomed in, the shape is clipped, but the picker can still locate it. This fix checks which renderer was clicked first.
1 parent d152df7 commit c140a08

File tree

5 files changed

+22
-17
lines changed

5 files changed

+22
-17
lines changed

Libs/Analyze/Shape.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class Shape {
3232
public:
3333
Point(){};
3434
Point(double _x, double _y, double _z) : x(_x), y(_y), z(_z){};
35-
double x, y, z;
35+
double x = 0, y = 0, z = 0;
3636
};
3737

3838
Shape();

Studio/Interface/ShapeWorksStudioApp.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1217,7 +1217,6 @@ void ShapeWorksStudioApp::handle_project_changed() {
12171217
}
12181218

12191219
if (session_->get_shapes().size() == 0) {
1220-
new_session();
12211220
analysis_tool_->reset_stats();
12221221
lightbox_->clear_renderers();
12231222
}

Studio/Visualization/Lightbox.cpp

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -274,22 +274,26 @@ void Lightbox::redraw() {
274274
ViewerList Lightbox::get_viewers() { return viewers_; }
275275

276276
//-----------------------------------------------------------------------------
277-
void Lightbox::handle_pick(int* click_pos, bool one, bool ctrl) {
277+
void Lightbox::handle_pick(int* click_pos, bool one, bool ctrl, vtkRenderer* renderer) {
278278
if (ctrl) {
279279
for (int i = 0; i < viewers_.size(); i++) {
280-
auto result = viewers_[i]->handle_ctrl_click(click_pos);
281-
if (result.domain_ != -1) {
282-
result.subject_ = i + get_start_shape();
283-
visualizer_->handle_ctrl_click(result);
284-
return;
280+
if (viewers_[i]->get_renderer() == renderer) {
281+
auto result = viewers_[i]->handle_ctrl_click(click_pos);
282+
if (result.domain_ != -1) {
283+
result.subject_ = i + get_start_shape();
284+
visualizer_->handle_ctrl_click(result);
285+
return;
286+
}
285287
}
286288
}
287289
} else {
288290
int id = -1;
289291
Q_FOREACH (ViewerHandle viewer, viewers_) {
290-
int vid = viewer->handle_pick(click_pos);
291-
if (vid != -1) {
292-
id = vid;
292+
if (viewer->get_renderer() == renderer) {
293+
int vid = viewer->handle_pick(click_pos);
294+
if (vid != -1) {
295+
id = vid;
296+
}
293297
}
294298
}
295299

Studio/Visualization/Lightbox.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ class Lightbox : public QObject {
5656

5757
void redraw();
5858

59-
void handle_pick(int* click_pos, bool one, bool ctrl);
59+
void handle_pick(int* click_pos, bool one, bool ctrl, vtkRenderer* renderer);
6060

6161
void handle_hover(int* click_pos);
6262

@@ -89,7 +89,7 @@ class Lightbox : public QObject {
8989
void update_feature_range();
9090

9191
void update_interactor_style();
92-
92+
9393
void set_shared_brightness_and_contrast(double brightness, double contrast);
9494

9595
vtkRenderWindow* get_render_window();

Studio/Visualization/StudioInteractorStyle.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@ StudioInteractorStyle::~StudioInteractorStyle() {}
1717
//-----------------------------------------------------------------------------
1818
void StudioInteractorStyle::OnLeftButtonDown() {
1919
if (this->Interactor->GetControlKey()) {
20-
int* clickPos = this->GetInteractor()->GetEventPosition();
21-
this->lightbox_->handle_pick(clickPos, true, true);
20+
int* pos = this->GetInteractor()->GetEventPosition();
21+
vtkRenderer* renderer = GetInteractor()->FindPokedRenderer(pos[0], pos[1]);
22+
this->lightbox_->handle_pick(pos, true, true, renderer);
2223
return;
2324
}
2425

@@ -61,17 +62,18 @@ void StudioInteractorStyle::OnMouseWheelBackward() {
6162
//-----------------------------------------------------------------------------
6263
void StudioInteractorStyle::OnKeyDown() {
6364
int* click_pos = this->GetInteractor()->GetEventPosition();
65+
vtkRenderer* renderer = GetInteractor()->FindPokedRenderer(click_pos[0], click_pos[1]);
6466

6567
char keycode = this->GetInteractor()->GetKeyCode();
6668
std::string keysym = GetInteractor()->GetKeySym();
6769

6870
switch (keycode) {
6971
case '1':
70-
this->lightbox_->handle_pick(click_pos, true, false);
72+
this->lightbox_->handle_pick(click_pos, true, false, renderer);
7173
break;
7274

7375
case '2':
74-
this->lightbox_->handle_pick(click_pos, false, false);
76+
this->lightbox_->handle_pick(click_pos, false, false, renderer);
7577
break;
7678

7779
case 'r':

0 commit comments

Comments
 (0)