Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENH: Expose functions for reproducing 3D view shortcuts #654

Closed
wants to merge 1 commit into from

Conversation

agirault
Copy link

@agirault agirault commented Jan 22, 2017

Before this, there was no simple way to ask programaticaly for the view
to reset the camera like it does when pressing the key pad shortcut keys.
Now the user can do this directly from python. This is potentially useful
for the scripted modules as well.
by @vovythevov

@pieper
Copy link
Member

pieper commented Jan 22, 2017

👍

@@ -792,6 +783,56 @@ void vtkThreeDViewInteractorStyle::SetModelDisplayableManager(
}

//----------------------------------------------------------------------------
void vtkThreeDViewInteractorStyle::RotateToPosterior(bool inverse)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Axis labels have been made configurable. In several places in the code, labels or orientations are still hardcoded, but we should really move away from that.

Therefore, we shouldn't use vtkThreeDViewInteractorStyle::RotateToPosterior(bool inverse), but something like this:

vtkThreeDViewInteractorStyle::RotateToViewAxis(const std::string& axisLabel)

axisLabel is "L", "R", ... is one of the labels in vtkMRMLAbstractViewNode::AxisLabels

Copy link
Author

@agirault agirault Jan 23, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good. I'll look into that. However, it looks like AxisLabel can be modified to customize the labels with SetAxisLabel. Should we pass an integer which defined the index of the axis instead? Or just go through all the values of AxisLabel and check if it exists, then infer how to rotate based on the axis id?

Also... we would have a RotateToViewAxis(int axis) in the qMRMLThreeDView, wrapping a RotateToViewAxis(int axis) in the vtkThreeDViewInteractorStyle, wrapping a RotateTo in vtkMRMLCameraNode. Do we really need all this? @vovythevov, do you remember why this was implemented in the interactor style as well as the qMRMLThreeDView? Thank you!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can get the Nth axis label by calling const char* vtkMRMLAbstractViewNode::GetAxisLabel(int labelIndex). If the view node is not accessible or you would always need to rotate to Nth axis then you can have a method like:
vtkThreeDViewInteractorStyle::RotateToViewAxis(int direction) // direction is in 0..5, same way as in abstract view node axis index (-X, +X, ..., -Z, +Z)
or
vtkThreeDViewInteractorStyle::RotateToViewAxis(int axis, bool positiveDirection) --- where axis is in 0..2

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure. Do we want this in vtkThreeDViewInteractorStyle as well as qMRMLThreeDView?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess it could be enough to just have it in qMRMLThreeDView.

{
if (!this->CameraNode)
{
return;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

log warning instead of just silently fail

@agirault
Copy link
Author

agirault commented Jan 23, 2017

Changes made.

In the future, it could be interesting to consolidate ctkAxesWidget::Axis, vtkMRMLCameraNode::Direction, and vtkMRMLAbstractViewNode order of labels.

vtkThreeDViewInteractorStyle::SafeDownCast(this->interactorStyle());
if (!style)
{
QDebug(QtCriticalMsg) << "qMRMLThreeDView::RotateToViewAxis: "
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why don't you use simply qCritical or qWarning?

Q_D(qMRMLThreeDView);
if (!d->MRMLViewNode)
{
return;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

log warning

return;
}
}
QDebug(QtWarningMsg) << "qMRMLThreeDView::RotateToViewAxis: "
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

qWarning

vtkThreeDViewInteractorStyle::SafeDownCast(this->interactorStyle());
if (!style)
{
QDebug(QtCriticalMsg) << "qMRMLThreeDView::RotateToViewAxis: "
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

qWarning

@lassoan
Copy link
Contributor

lassoan commented Jan 23, 2017

Thank you, it looks good! If you make those few trivial changes then it should be ready to merge.

Before this, there was no simple way to ask programaticaly for the view
to reset the camera like it does when pressing the key pad shortcut keys.
Now the user can do this directly from python. This is potentially useful
for the scripted modules as well.
@agirault
Copy link
Author

Integrated in r25651

@agirault agirault closed this Jan 23, 2017
@agirault agirault deleted the expose-camera-shortcuts branch January 23, 2017 21:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
4 participants