[vtkusers] Tips for the display of a fixed size origin marker
David Gobbi
david.gobbi at gmail.com
Mon Mar 16 09:50:00 EDT 2015
Hi Serge,
In this case, you can just set both the renderers to have the same camera.
- David
On Mon, Mar 16, 2015 at 7:46 AM, Serge Lalonde <serge at infolytica.com> wrote:
> Hi Miroslav and David,
>
> Thanks for the suggestions. That's what I was looking for.
> I'll implement it using a separate renderer to avoid mixing actors and to
> set the layer.
> I just need to read up on synchronizing the cameras between the two
> renderers and it should work.
>
> Thanks!
>
>
> On 3/13/2015 5:32 PM, Miroslav Drahos wrote:
>
> Sent my email response a bit too early, sorry.
>
> If you decide to layer the renderers, you'll probably want to set the foreground renderer as non-interactive (vtkRenderer::SetInteractive(0)) otherwise it will be grabbing the events from interactors.
> Cheers,
> Miro
>
>
> ________________________________________
> From: Miroslav Drahos
> Sent: Friday, March 13, 2015 2:28 PM
> To: David Gobbi; Serge Lalonde
> Cc: vtkusers at vtk.org
> Subject: RE: [vtkusers] Tips for the display of a fixed size origin marker
>
> You could stack two renderers, assign the layer number to them (vtkRenderer::SetLayer(int) and vtkRenderWindow::SetNumberOfLayers(int) ) and have the one that's on top contain the origin label actor. That way it will always be visible (as a top layer).
>
> ________________________________________
> From: vtkusers [vtkusers-bounces at vtk.org] On Behalf Of David Gobbi [david.gobbi at gmail.com]
> Sent: Friday, March 13, 2015 2:23 PM
> To: Serge Lalonde
> Cc: vtkusers at vtk.org
> Subject: Re: [vtkusers] Tips for the display of a fixed size origin marker
>
> Hi Serge,
>
> To get the scale right, I add an observer for the renderer's StartEvent
> that does all the necessary calculations to set the position and scale
> of the actor correctly just before the render occurs. It's kind of messy,
> but I don't know a better way. The code that I use to compute the
> correct actor scale is as follows:
>
> void ComputeScale(const double position[3], vtkRenderer *renderer)
> {
> // Find the cursor scale factor such that 1 data unit length
> // equals 1 screen pixel at the cursor's distance from the camera.
> // Start by computing the height of the window at the cursor position.
> double worldHeight = 1.0;
> vtkCamera *camera = renderer->GetActiveCamera();
> if (camera->GetParallelProjection())
> {
> worldHeight = 2*camera->GetParallelScale();
> }
> else
> {
> vtkMatrix4x4 *matrix = camera->GetViewTransformMatrix();
> // Get a 3x3 matrix with the camera orientation
> double cvz[3];
> cvz[0] = matrix->GetElement(2, 0);
> cvz[1] = matrix->GetElement(2, 1);
> cvz[2] = matrix->GetElement(2, 2);
>
> double cameraPosition[3];
> camera->GetPosition(cameraPosition);
>
> double v[3];
> v[0] = cameraPosition[0] - position[0];
> v[1] = cameraPosition[1] - position[1];
> v[2] = cameraPosition[2] - position[2];
>
> worldHeight = 2*(vtkMath::Dot(v,cvz)
> * tan(0.5*camera->GetViewAngle()/57.296));
> }
>
> // Compare world height to window height.
> int windowHeight = renderer->GetSize()[1];
> double scale = 1.0;
> if (windowHeight > 0)
> {
> scale = worldHeight/windowHeight;
> }
>
> return scale;
> }
>
> For the other question, it sounds like you want VTK to ignore the depth
> buffer when it renders your actor. I don't know if this is possible. If I need
> an annotation or a cursor to be in front of everything, I do a pick to find the
> depth (i.e. frontmost object) at the position where I want to render my cursor,
> and then I place my cursor at that depth.
>
> - David
>
>
> On Fri, Mar 13, 2015 at 2:54 PM, Serge Lalonde <serge at infolytica.com<mailto:serge at infolytica.com> <serge at infolytica.com>> wrote:
> Anyone have any suggestions on how to implement the display of the origin?
> It doesn't have to be axes (although that would be nice).
> The trick is to get it to be a fixed size regardless of the camera zoom and to make it visible even if "hidden" inside of another actor.
>
> Thanks for any tips.
> --www.infolytica.com <http:://www.infolytica.com>
> 300 Leo Pariseau, Suite 2222, Montreal, QC, Canada, H2X 4B3(514) 849-8752 x236<tel:%28514%29%20849-8752%20x236> <%28514%29%20849-8752%20x236>, Fax: (514) 849-4239<tel:%28514%29%20849-4239> <%28514%29%20849-4239>
>
>
>
> --
> www.infolytica.com
> 300 Leo Pariseau, Suite 2222, Montreal, QC, Canada, H2X 4B3
> (514) 849-8752 x236, Fax: (514) 849-4239
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20150316/342218a7/attachment.html>
More information about the vtkusers
mailing list