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

**URL:** https://discourse.vtk.org/t/weird-behaviour-for-a-vtkimagereslice-image-to-render-in-the-full-viewport/973
**Category:** Support
**Created:** [May 15, 2019, 3:49pm UTC](https://discourse.vtk.org/t/weird-behaviour-for-a-vtkimagereslice-image-to-render-in-the-full-viewport/973 "2019-05-15T15:49:50Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![zandarina](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/z/4af34b/32.png) [@zandarina](https://discourse.vtk.org/u/zandarina)
#### Post date: [May 15, 2019, 3:49pm UTC](https://discourse.vtk.org/t/weird-behaviour-for-a-vtkimagereslice-image-to-render-in-the-full-viewport/973/1 "2019-05-15T15:49:50Z")

</div>

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

---

<div class="post-metadata">

### Author: ![zandarina](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/z/4af34b/32.png) [@zandarina](https://discourse.vtk.org/u/zandarina)
#### Post date: [May 16, 2019, 10:05am UTC](https://discourse.vtk.org/t/weird-behaviour-for-a-vtkimagereslice-image-to-render-in-the-full-viewport/973/2 "2019-05-16T10:05:06Z")

</div>

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

```auto
//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);

```
