ArrowSource, but not centered at (0, 0, 0)

Hello!

In vtk.js, there is an ArrowSource, which creates a nice arrow made up of a cylinder and cone. However, it is always centered at (0, 0, 0) and I would like this arrow to be offset on the side of a volume not centered at the origin (used to represent a normal vector). Sadly, ArrowSource does not have a setCenter() method like some of the other Does anyone have any simple suggestions on ways to go about doing this before I embark on adapting the ArrowSource into a very slightly modified version?

Thanks!

The position can be set from the vtkActor via setPosition

Usually the ā€œsourceā€ objects are just providing model geometry; they are not providing a way to place the geometry in the world. Placing things in the world in the job of the actors/props.

I think it makes sense to expose a center (setCenter/getCenter) parameter (like it is done in some other sources).
The goal of such center is NOT to place the arrow in the world, instead, it is to place the local origin (e.g. center of rotation) for the arrow. Should you want the center in one extremetity of the arrow or in the middle.

1 Like

Doesnā€™t setOrigin on a prop do this? I didnā€™t try it, just judging by the chain of transforms here.

Hi there,
Have you tried ā€˜SetArrowOriginToCenterā€™. I believe thereā€™s a function like that in there or may I ask what VTK version are you working with. I recall I added that functionality over a year ago. see
https://gitlab.kitware.com/SeunOdutola/vtk/-/commit/a37cd4569dd5ba82cbcc4aef4108b84ac8f70ebd

It does, but sometimes we canā€™t use prop setOrigin(). For example, ā€œsourceā€ filters are typically used as inputs for the glyph mapper (or used in the widgets).

1 Like

It is not available in vtk.js

Wow thanks for all of the responses, everyone! Iā€™ll update if any of the suggestions pan out

@finetjul, the exposing the set/getCenter is exactly what Iā€™m looking for. In the absence of it right now though, how would you recommend achieving the goal of placing an arrow in the world?"

@Ebrahim_Ebrahim, I will try both the setOrigin and setPosition methods on the vtkActor. Thanks for the find! Iā€™m not sure based on Julienā€™s comment whether this will be one of the times that setOrigin wonā€™t work, but Iā€™ll give it a shot.

@Seun, sadly, I am using vtk.js v17.17.2 :frowning:

The easiest is to add that feature yourself and create a Pull Request. Based on the other sources and what @Seun has shared, it should be straightforward.

Oh I see,
that explains why it isnā€™t in there but as @finetjul suggested, you can easily add the feature in vtk.js just the way I did it. I hope it helps (the link).

If you take a look at the link, the general idea is that the default behaviour of the arrow is to position its centre based on the overall length of the cylinder (excluding the tip of the arrow), which is why itā€™s a bit off if Iā€™m not mistaken (as I have not looked at that code in a while) - the general idea of what you want to achieve involves a bit of transformation and repositioning based on the entire length of the arrow (cylinder + arrow tip). the GitHub link is hopefully pretty straightforward & I believe you can code it up real quick.
All the best.

I really appreciate all fo the feedback and suggestions! I found that just using setPosition on the vtkActor that the arrow was mapped to was sufficient for my needs! I was able to move the arrows away from (0, 0, 0) to a location of my choosing in the space! Thanks @Ebrahim_Ebrahim!

Iā€™ll probably stick to this solution as long as it works for what we need. But I did look into the source code for the ArrowSource and indeed, it is just as you said @Seun. You would just have to accept some parameters indicating where the position should be set to and call that on the cylinder and cone (with some transformation to account for the offset and any rotations). Iā€™ll keep this in mind and open a PR making these changes if the need arises.

Thanks everyone! We can call this one solved!

2 Likes