[Insight-users] Re: [vtkusers] camera
Renaud Isabelle
renauisa at yahoo.fr
Tue May 31 09:19:34 EDT 2005
Hi luis,
I did what you told me concerning the camera.Here is my code:
vtkImageData * image = m_Actor->GetInput();
int dim[3]; image->GetDimensions(dim);
float spacing[3]; image->GetSpacing(spacing);
float origin[3]; image->GetOrigin(origin);
float Cx = (dim[0] * spacing[0])/2. + origin[0];
float Cy = (dim[1] * spacing[1])/2. + origin[1];
m_Camera->SetPosition(Cx,Cy,1);
m_Camera->SetFocalPoint(Cx,Cy,0);
m_Camera->SetViewUp (0, 1, 0);
//parallel projection is used
m_Camera->ParallelProjectionOn();
m_Renderer->SetActiveCamera(m_Camera);
m_Renderer->ResetCamera();
When displaying, all I can see in dark image.
So I tried to zoom:
//to fit the image to the render window,
double max = MAX(spacing[0] * dim[0], spacing[1] * dim[1]);
m_Camera->SetParallelScale( max/16. * m_ZoomFactor );
I can see something only with a scale factor of max/16. My image is centered, so my camera is right in front of the middle of my slice, as you adviced me. But, why my volume is so far away of my camera? Yet, my camera position in Z axis is at Z=1. Where is my volume in Z axis?
isabelle
Luis Ibanez <luis.ibanez at kitware.com> a écrit :
Hi Isabelle,
You are pointing the camera to the origin of coordinates
m_Camera->SetFocalPoint(0,0,0);
That's usually located in the *corner* of the image.
You probably want to change that to be pointing to the
middle of the image, so the image gets centered in the
render window.
Typically if your image has
(Nx,Ny) pixels and
(Sx,Sy) millimeter of pixel size
(Ox,Oy) origin in millimeters
then you want to set up your camera in front of the middle
of the image, and point to the center of the image:
Cx = Nx * Sx / 2.0 + Ox
Cy = Ny * Sy / 2.0 + Oy
m_Camera->SetPosition(Cx,Cy,F);
m_Camera->SetFocalPoint(Cx,Cy,0);
F is actually irrelevant here
since you are using ParallelProjection.
You don't want to put your "view up" to
m_Camera->SetViewUp (0, 0, -1);
because the "up" of the image is actually along the Y axis.
A better choice for you might be:
m_Camera->SetViewUp (0, 1, 0);
Note that, there is nothing misterious about positioning the
camera. Just think of your image as a 2D plane segment
floating in 3D space, and think of your camera as a
photograpic camera that must be placed in such a way that
you look at the middle of the image.
Regards,
Luis
---------------------------
Renaud Isabelle wrote:
> Hi Luis,
>
> I followed your advice and tried to create my own class to display my
> image with VTK.
>
> However, as Ì'm still new to VTK, I'm not familiar with all this notions
> of camera, actor, mapper and so on. I tried to set up my own parameters
> of a camera. However, I succed to view only a part of my image 1552*128.
>
> Here is what I did:
>
> * m_Camera = vtkCamera::New();
> m_Actor = vtkImageActor::New();
> m_Renderer = vtkRenderer::New();
> m_RenderWindow = vtkRenderWindow::New();*
> **
> * //setup the pipeline
> m_Renderer->AddActor( m_Actor );
> m_RenderWindow->AddRenderer( m_Renderer ); *
> * *
> * // The usual rendering stuff
> m_Camera->ComputeViewPlaneNormal();
> m_Camera->SetViewUp (0, 0, -1);
> m_Camera->SetPosition(0,0,1);
> m_Camera->SetFocalPoint(0,0,0);
> m_Camera->ParallelProjectionOn(); *
> **
> * m_Renderer->SetActiveCamera(m_Camera);
> m_Renderer->ResetCamera();
> m_Renderer->SetBackground(0,0,0); //set a background color *
> **
> * m_Actor->SetInput( image)
> m_Camera->SetClippingRange( 0.1, 1000.);
> m_RenderWindow->Render();*
>
> Do you think one or several parameters are not correct and explain my
> result, If so, could you tell me which one.
>
> Isabelle
>
> */Luis Ibanez /* a écrit :
>
>
> Hi Isabelle,
>
> In order to have more control over the rendering of the image
> you should replace the vtkImageViewer class with the individual
> components used in ImageSliceViewer, namely:
>
>
> vtkImageActor * m_Actor;
> vtkRenderer * m_Renderer;
> vtkCamera * m_Camera;
> vtkRenderWindow * m_RenderWindow;
>
>
>
> The vtkImageViewer is actually a grouping of
>
> vtkRenderWindow *RenderWindow;
> vtkRenderer *Renderer;
> vtkImageMapper *ImageMapper;
> vtkActor2D *Actor2D;
> vtkRenderWindowInteractor *Interactor;
> vtkInteractorStyleImage *InteractorStyle;
>
>
> into a single class, just for convenience of use.
> http://www.vtk.org/doc/nightly/html/classvtkImageViewer.html
>
> Regards,
>
> Luis
>
> ------------------------------------------------------------------------
> Découvrez le nouveau Yahoo! Mail : 1 Go d'espace de stockage pour vos
> mails, photos et vidéos !
> Créez votre Yahoo! Mail
>
>
---------------------------------
Découvrez le nouveau Yahoo! Mail : 1 Go d'espace de stockage pour vos mails, photos et vidéos !
Créez votre Yahoo! Mail
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://public.kitware.com/pipermail/insight-users/attachments/20050531/6a8d255b/attachment.html
More information about the Insight-users
mailing list