-
-
Notifications
You must be signed in to change notification settings - Fork 4.6k
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
Add overload to PCLVisualizer::addText3D()
that allows specifying text orientation
#2038
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Your new method (with orientation) is an exact copy of the method above (without orientation), with the added line in which you set the orientation. In order to reduce code repetition, the method without orientation should be modified to invoke your new one with the rotation set to zeros.
/** \brief Add a 3d text to the scene | ||
* \param[in] text the text to add | ||
* \param[in] position the world position where the text should be added | ||
* \param[in] orientation the angles of rotation regarding x-, y-, z-axis for the text |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What rotation representation is this exactly? A rodrigues vector? Euler? It's important for that to be clear in the comment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am currently trying to figure it out from the VTK documentation and from my experiments but I completly agree, it's not so clear.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't forget to update this description here with the latest findings, i.e. a ZXY intrinsic rotation. I'm considering even to include a link to wikipedia just to be sure.
That being said, I don't really understand why would VTK would adopt a rotation representation which suffers from gimbal lock. I also wouldn't know how to construct this ZYX rotation from a Rodrigues vector for instance.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll update the documentation soon with the wikipedia link which seems to be essential!
I'm like you about the VTK choice. I learned recently about the gimbal lock issue with Euler angle. I still don't find a canonical way to handle them, but it's the VTK API. I hesitated to send a mail to VTK, but it doesn't worth it for me. (I don't know the Rodrigues vector, but it's surely more pleasant.)
By the way can you post some screenshots of the effect of the text rotation. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
VTK API behavious
@SergioRAgostinho : I finally understand the API proposed by VTK. It's subtle and not easy to use (but do I have the choice?!?).
This first example is straightforward. I give as example 4 texts in different orienations in the following animation.
The label no_rot
is displayed without any orientation/rotation.
The label x_90
shows an orientation 90° in relation to the X-axis (in red).
The labels y_90
and z_90
show respectively an orientation 90° in relation to the Y-axis (in green) and the Z-axis (in blue).
All these orientations/rotations are done in the direct trigonometric way.
The subtle of the API comes in this second example. There's also 4 labels.
The label no_rot
is displayed without any orientation/rotation.
The label z_90
shows an orientation 90° in relation to the Z-axis (in blue).
Then the label z_90_n_x_90
shows an orientation of 90° in the Z and X directions. The VTK documentation specifies that the rotations are chained in the order Z, X and Y. For this label, the rotation of 90° around the Z-axis is effectively done around the blue vector. But the next rotation around the X-axis is not done around the red vector, it is done around the green vector so the Y vector.
Why is it done this way? After a while I finally understand that after the first rotation around the Z axis, the next rotation will be done not in the original/absolute coordinate system, but rather in a relative coordinate system that has been rotated by the first rotation around the Z axis. In this example, after the first rotation, here is the situation:
- the new/relative X vector = the original Y vector (the green one)
- the new/relative Y vector = the original -X vector (not represented)
- the new/relative Z vector = the original Z vector (the blue one)
In this new/relative coordinate system, the rotation around the X-axis is done, so in fact around the original Y vector (in green).
Finally the label z_90_n_x_90_n_y_90
shows an orientation of 90° in the Z, X and Y directions. The situation after the rotation around X-axis can be sum up like:
- the relative X vector = the absolute Y vector (the green one)
- the relative Y vector = the absolute Z vector (the blue one)
- the relative Z vector = the absolute X vector (the red one)
So the final rotation around the relative Y vector mean in fact a rotation around the absolute X vector.
The fact that the rotation are done in successive rotate coordinate system is not said in the VTK documentation...
To be complet, you'll find attached to this message the source files that I use to produce the animation.
pcl_text.tar.gz
What to do?
After all, even if the API is not intuitive, this is the way that VTK provide to give an orientation to a text. This is what I need. I would like to see this feature in the main version of PCL.
// Should we add the actor to all renderers or just to i-nth renderer? | ||
if (viewport == 0 || viewport == i) | ||
{ | ||
vtkSmartPointer<vtkActor> textActor = vtkSmartPointer<vtkActor>::New (); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@SergioRAgostinho : This new method is not exactly the same as the previous one because of the vtkActor
type. With this type, the object added to the display doesn't change it's orientation, what ever is the camera point of view.
In the previous method the actor type was vtkFollower
, which means, the letters will always face the camera point of view. It's easier to see the tag even if you rotate the scene but it's not what I need.
In my opinion, it is not relevant to merge the two addText3D()
methods (but certainly there is something better to do). What's your feeling?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I would create a third method in which you supply the vtkActor in the signature, which is invoked by both methods. That way you can specialize the vtkActor for both use cases and the rest is the same. The only thing I don't like is exposing vtk types in a function signature, but I don't think I'm able to hide it from the public API because the methods which would call it are templated on the point type.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you want, I can try do an attempt in this way. As you say, it explose VTK types... Maybe you can hide this if you propose in the API 2 methods:
addText3D_follow()
: follow the view point of the cameraaddText3D_oriented()
: the text stay oriented independently of the camera
You keep the addText3D()
function for historical reason, and this function just call addText3D_follow()
. Behind addText3D_follow()
and addText3D_oriented()
you manage the VTK types internally.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It sounds to me that this is exactly the same situation as now, only that instead of making use of function overload, you're assigning different names to functions.
@taketwo what's your feeling on exposing an overload which allows you to provide the vtkActor directly, in the public API?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't like exposing VTK classes in the API and would ideally view the fact that we use VTK backend as an implementation detail. (True, we have some VTK classes in the interface of addModelFromPolyData()
family of functions, but that's it.)
Now getting back to this specific function, I don't get why we need to create multiple actors (one per viewport) in the oriented text case. Unlike the follow-camera text, they are all the same, aren't they?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@taketwo : you should be right, so the textActor
variable should be created outside the while loop, isn't it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see the need for the loop at all. Just use addActorToRenderer (actor, viewport)
as in other functions that add something to the visualizer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's done.
Thanks for the analysis.
So VTK seem to be accepting orientation as ZXY with intrinsic rotations.
In principle, we can accept orientation in any other form that we find more intuitive and internally convert to VTK representation. But I do not think that it's worth it. I'd stick with VTK representation and provide a clear documentation. |
@taketwo Many thank for the link about intrinsic rotations. It will be helpful to set the good orientation for my labels. Also I agree with you, I would keep handling the VTK to set the good orientation. |
I just rebase the 'text3D' branch on top on the 'master' branch. |
The documentation is up to date. Let me know if you are OK with it. |
PCLVisualizer::addText3D()
that allows specifying text orientation
Add a function
addText3D()
which allows to specify the orientation of a text.