Thanks for the recipe David, it works like a charm!<br><br><div class="gmail_quote">On Fri, May 4, 2012 at 2:09 AM, David Gobbi <span dir="ltr"><<a href="mailto:david.gobbi@gmail.com" target="_blank">david.gobbi@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">The recipe for getting image pixels to match screen pixels is, roughly:<br>
<br>
render_window->Render();<br>
int *rsize = renderer->GetSize();<br>
int height = rsize[1];<br>
vtkCamera *camera = renderer->GetActiveCamera();<br>
camera->ParallelProjectionOn();<br>
camera->SetParallelScale(0.5*height*yspacing);<br>
render_window->Render();<br>
<br>
If the image is not yet calibrated, then it should be fine to use<br>
a yspacing of 1.<br>
<span class="HOEnZb"><font color="#888888"><br>
- David<br>
</font></span><div class="HOEnZb"><div class="h5"><br>
<br>
On Thu, May 3, 2012 at 11:33 AM, Siddharth Vikal<br>
<<a href="mailto:siddharthvikal@gmail.com">siddharthvikal@gmail.com</a>> wrote:<br>
> Thanks David for detailed response.<br>
><br>
> Thanks, yes I do understand now more clearly the series of transformations<br>
> that the image goes through when vtkImageSlice or vtkImageActor is in use.<br>
> And I completely agree and am for, equating the world coordinate system with<br>
> the DICOM patient coordinate system. It is the camera transformations and<br>
> view transformation I'm interested in (world --> view --> screen).<br>
><br>
> Perhaps, it would make more sense to you if I explain the particular<br>
> scenario a bit better. Consider the situation where the image that one has<br>
> acquired are just off the hardware, where the spacing of voxels is not yet<br>
> known. A manual calibration step is then needed to actually determine the<br>
> pixel spacing. In this case, user prefers to the see the image as and how it<br>
> comes out of the hardware i.e. the native pixel size equated to computer<br>
> monitor's pixels. Based on that calibrated pixel size, the measurements have<br>
> to added to image. My thought was that since vtkDistanceWidget works well<br>
> with vtkImageActor/vtkImageSlice, it would help to know the exact scaling so<br>
> that I can accurately calculate calibrated pixel size and enable<br>
> vtkDistanceWidget display correct measurements.<br>
><br>
> regards,<br>
> Siddharth<br>
><br>
><br>
> On Thu, May 3, 2012 at 8:38 PM, David Gobbi <<a href="mailto:david.gobbi@gmail.com">david.gobbi@gmail.com</a>> wrote:<br>
>><br>
>> Hi Siddharth,<br>
>><br>
>> If you just want to map your image pixels directly to screen pixels,<br>
>> then there's hardly any reason to use a computer graphics toolkit like<br>
>> VTK at all. The goal of vtkImageActor and vtkImageSlice is to place<br>
>> an image into a 3D scene, so that the vtkCamera can then be set up to<br>
>> view that scene from a particular viewpoint.<br>
>><br>
>> There are several coordinate transformations that occur along the way.<br>
>><br>
>> First, the sampling information for the image is applied, i.e. the<br>
>> spacing and voxels and the position of the lower-left corner voxel of<br>
>> the image volume (or upper-left in the case of DICOM). This<br>
>> transformation maps the voxels to a physical block of space (usually<br>
>> using millimetres as units).<br>
>><br>
>> Next, the prop3D transformation is applied. This establishes the<br>
>> position of the aforementioned block of space within the world<br>
>> coordinate system. For medical applications, I always equate the world<br>
>> coordinate system with the DICOM patient coordinate system of my<br>
>> primary image series, in order to keep things simple.<br>
>><br>
>> Next, there are two camera transformation that are applied (a view<br>
>> transformation and a projection transformation) that map the world<br>
>> coordinates to the view coordinates, followed by a viewport<br>
>> transformation that maps the viewport coordinates to screen pixels.<br>
>><br>
>> None of these transformations are specific to VTK. The same basic<br>
>> approach is used in virtually all modern computer graphics libraries.<br>
>><br>
>> There are recipes that you can apply to achieve basic effects (e.g<br>
>> like viewing a 2D slice of an image at a specific zoom factor), but in<br>
>> order to get the most out of VTK, it is important understand the<br>
>> computer graphics fundamentals that underlie the toolkit.<br>
>><br>
>> - David<br>
>><br>
>><br>
>> On Thu, May 3, 2012 at 7:32 AM, sidd_vtk <<a href="mailto:siddharthvikal@gmail.com">siddharthvikal@gmail.com</a>> wrote:<br>
>> > Hi David & all vtk users,<br>
>> ><br>
>> > I'm using the newly added vtkImageSlice class (I've used vtkImageActor<br>
>> > also<br>
>> > with the same issue that I'm describing below). I set up the pipeline,<br>
>> > and<br>
>> > the image shows up. The issue is that the image that comes up does not<br>
>> > preserve its original size in pixels unlike how vtkActor2D does. To be<br>
>> > more<br>
>> > specific and clear, e.g. if the image size in pixels is 512x512, the use<br>
>> > of<br>
>> > vtkActor2D results in displaying the image of size 512x512 pixels, but<br>
>> > use<br>
>> > of vtkImageSlice or vtkImageActor displays in size other than true size<br>
>> > of<br>
>> > the image. And I can't seem to figure out the scale factor that has been<br>
>> > applied.<br>
>> ><br>
>> > I need to use vtkImageSlice or vtkImageActor, because they work well<br>
>> > with<br>
>> > vtkDistanceWidget. But I also require 1:1 display of the image. If the<br>
>> > scale<br>
>> > factor is known, I can re-transform my image to get what I want.<br>
>> ><br>
>> > Can you please point me the code where this re-scaling of the image<br>
>> > happens<br>
>> > before it gets rendered? or How to fetch the scaling that has been<br>
>> > applied<br>
>> > to the image when vtkImageSlice or vtkImageActor has been used?<br>
>> ><br>
>> > Any help is greatly appreciated.<br>
>> ><br>
>> > regards,<br>
>> > Siddharth<br>
><br>
><br>
</div></div></blockquote></div><br>