[vtkusers] Tips for the display of a fixed size origin marker

David Gobbi david.gobbi at gmail.com
Fri Mar 13 17:23:44 EDT 2015


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> 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
> 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/20150313/8b646dbd/attachment.html>


More information about the vtkusers mailing list