[vtkusers] Re: Flipping the image with vtkCamera::Yaw() makes image disappear
dean.inglis at camris.ca
dean.inglis at camris.ca
Fri Mar 2 20:05:20 EST 2007
Hi Jesús,
you can directly set the position, the focal point, and the
view up direction of the camera, rather than using Yaw, Roll
etc. : these are just points in
space referenced to a spatial origin, so vector algebra applies.
Here are some snippits for flipping and rolling from an
app that uses vtkImageViewer2...forcing the renderer to
reset the camera clipping range always helps too...
Dean
/// flip horizontal --------
vtkRenderer* renderer;
if (this->ImageViewer && (renderer = this->ImageViewer->GetRenderer()) != NULL )
{
int axis = this->ImageViewer->GetSliceOrientation();
double vup[3];
renderer->GetActiveCamera()->GetViewUp(vup);
double cameraPosition[3];
renderer->GetActiveCamera()->GetPosition(cameraPosition);
double cameraFocalPoint[3];
renderer->GetActiveCamera()->GetPosition(cameraFocalPoint);
for ( int i = 0; i < 3; ++i )
{
vup[i] = -vup[i];
cameraPosition[i] = 2.0*cameraFocalPoint[i] - cameraPosition[i];
}
renderer->GetActiveCamera()->SetPosition(cameraPosition);
renderer->GetActiveCamera()->SetViewUp(vup);
renderer->ResetCameraClippingRange();
this->ImageViewer->Render();
}
///flip vertical ---
vtkRenderer* renderer;
if (this->ImageViewer && (renderer = this->ImageViewer->GetRenderer()) != NULL )
{
int axis = this->ImageViewer->GetSliceOrientation();
double vup[3];
renderer->GetActiveCamera()->GetViewUp(vup);
double cameraPosition[3];
renderer->GetActiveCamera()->GetPosition(cameraPosition);
double cameraFocalPoint[3];
renderer->GetActiveCamera()->GetPosition(cameraFocalPoint);
for ( int i = 0; i < 3; ++i )
{
vup[i] = -vup[i];
cameraPosition[i] = 2.0*cameraFocalPoint[i] - cameraPosition[i];
}
renderer->GetActiveCamera()->SetPosition(cameraPosition);
renderer->GetActiveCamera()->SetViewUp(vup);
renderer->ResetCameraClippingRange();
this->ImageViewer->Render();
}
///----pass an angle in degrees....e.g. +90 or -90 etc.
vtkRenderer* renderer;
if (this->ImageViewer && (renderer = this->ImageViewer->GetRenderer()) != NULL )
{
int axis = this->ImageViewer->GetSliceOrientation();
vtkTransform* transform = vtkTransform::New();
transform->Identity();
transform->PreMultiply();
switch(axis)
{
case 0: transform->RotateX(angle); break; //YZ
case 1: transform->RotateY(angle); break; //XZ
case 2: transform->RotateZ(angle); break; //XY
}
double vup[3];
renderer->GetActiveCamera()->GetViewUp(vup);
double vpri[3];
transform->MultiplyPoint(vup,vpri);
renderer->GetActiveCamera()->SetViewUp(vpri);
this->ImageViewer->Render();
transform->Delete();
}
More information about the vtkusers
mailing list