Created
September 4, 2017 18:23
-
-
Save agirault/83d100c22a7f9e9c567e39b2e6935d8a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
auto picker = vtkSmartPointer<vtkPropPicker>::New(); | |
picker->Pick(screen_x, screen_y, 0, renderer); | |
// Check if pick is in bounds | |
vtkAssemblyPath* path = picker->GetPath(); | |
bool validPick = false; | |
if (path) { | |
vtkCollectionSimpleIterator sit; | |
path->InitTraversal(sit); | |
vtkAssemblyNode *node; | |
for (int i = 0; i < path->GetNumberOfItems() && !validPick; ++i) { | |
node = path->GetNextNode(sit); | |
if (vtkImageSlice::SafeDownCast(node->GetViewProp()) == labels_actor) { | |
validPick = true; | |
break; | |
} | |
} | |
} | |
// Out of bounds | |
if (!validPick) { | |
return -1; | |
} | |
// Convert from world coordinates to image coordinates | |
double p[3] = { 0. }; | |
picker->GetPickPosition(p); | |
double origin[3] = { 0. }; | |
labels_image->GetOrigin(origin); | |
double spacing[3] = { 0. }; | |
labels_image->GetSpacing(spacing); | |
int x = (p[0] - origin[0])/spacing[0]; | |
int y = (p[1] - origin[1])/spacing[1]; | |
int z = (p[2] - origin[2])/spacing[2]; | |
// Retrieving scalar value | |
return labels_image->GetScalarComponentAsFloat(x, y, z, 0); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment