[vtkusers] Tips for the display of a fixed size origin marker
Miroslav Drahos
mdrahos at thinksurgical.com
Fri Mar 13 17:28:46 EDT 2015
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>> 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>, Fax: (514) 849-4239<tel:%28514%29%20849-4239>
More information about the vtkusers
mailing list