weird behaviour for a vtkimagereslice image to render in the full viewport

Hi everybody,

I would like to render the image with maximum zoom to the full viewport. I am using [
vtkImageResliceViewer which has the same problem as vtkimageViewer2. For the axial image obtained by default i use the following code and i get the image correctly rendered in the center with maximum size. The problem comes when this image is obtained from vtkimagereslice. When i render the image i get a very small image, i only get it in the full viewport if i change the spacing to 1 and i render it twice setting the camera with the following code. I wonder what’s wrong. The spacing, the extent was correct, it is the same i set in the vtkimagereslice.

Someone knows what´s wrong?

The code i use to get the whole viewport is the following: For the axial it works, i only have problems with the resliced images i get with my customized orientation which they have a correct spacing and extent.

//To enlarge the image the whole viewport
double origin[3];
image_data->GetOrigin(origin);
int extent[6];
image_data->GetExtent(extent);
double spacing[3];
image_data->GetSpacing(spacing);

camera->ParallelProjectionOn();
double xc = origin[0] + 0.5*(extent[0] + extent[1])*spacing[0];
double yc = origin[1] + 0.5*(extent[2] + extent[3])*spacing[1];
double yd = (extent[3] - extent[2] + 1)*spacing[1];

double d = camera->GetDistance();
//degreesToRadians
//double viewAngleRadians = 3.1416*(camera->GetViewAngle())/180;
//double d = yd / viewAngleRadians;
camera->SetParallelScale(0.5f*static_cast<float>(yd));
camera->SetFocalPoint(xc, yc, 0.0);
camera->SetPosition(xc, yc, +d);

Thanks in advance

1 Like

I have fixed to have the whole viewport without changing the spacing BUT i still need to run the setting of the camera, then render and setting the camera again and render. Someone knows why i have to set it twice and render twice?. Thanks

//To enlarge the image the whole viewport
double origin[3];
image_data->GetOrigin(origin);
int extent[6];
image_data->GetExtent(extent);
double spacing[3];
image_data->GetSpacing(spacing);

camera->ParallelProjectionOn();
double xc = origin[0] + 0.5*(extent[0] + extent[1])*spacing[0];
double yc = origin[1] + 0.5*(extent[2] + extent[3])*spacing[1];
double yd = (extent[3] - extent[2] + 1)*spacing[1];

double d = camera->GetDistance();
//degreesToRadians
//double viewAngleRadians = 3.1416*(camera->GetViewAngle())/180;
//double d = yd / viewAngleRadians;
camera->SetParallelScale(0.5f*static_cast<float>(yd));
camera->SetFocalPoint(xc, yc, 0.0);
camera->SetPosition(xc, yc, +d);