no one please, is this normal?<div class="gmail_extra"><br><br><div class="gmail_quote">On Tue, Dec 11, 2012 at 9:45 AM, José M. Rodriguez Bacallao <span dir="ltr">&lt;<a href="mailto:jmrbcu@gmail.com" target="_blank">jmrbcu@gmail.com</a>&gt;</span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">hi folks, I am trying to implement a MPR viewer, so far so good. I am using the new image classes, this is test code:<div>

<br></div><div><div>#!/usr/bin/env python</div><div><br></div><div>import os</div><div>import gdcm, vtkgdcm, vtk</div>
<div><br></div><div><br></div><div>def key_press(sender, event):</div><div>    key = interactor.GetKeySym()</div><div>    style.SetCurrentRenderer(renderer)</div><div>    if key == &#39;a&#39;:</div><div>        print &#39;axial&#39;</div>


<div>        style.SetImageOrientation(</div><div>            style.GetZViewRightVector(),</div><div>            style.GetZViewUpVector()</div><div>        )</div><div>    elif key == &#39;c&#39;:</div><div>        print &#39;coronal&#39;</div>


<div>        style.SetImageOrientation(</div><div>            style.GetYViewRightVector(),</div><div>            style.GetYViewUpVector()</div><div>        )</div><div>    elif key == &#39;s&#39;:</div><div>        print &#39;axial&#39;</div>


<div>        style.SetImageOrientation(</div><div>            style.GetXViewRightVector(),</div><div>            style.GetXViewUpVector()</div><div>        )</div><div>    render_window.Render()</div><div><br></div><div>

<br>
</div><div><br></div><div>interactor = vtk.vtkRenderWindowInteractor()</div><div>render_window = vtk.vtkRenderWindow()</div><div>render_window.SetSize(400, 400)</div><div>interactor.SetRenderWindow(render_window)</div><div>


<br></div><div>style = vtk.vtkInteractorStyleImage()</div><div>style.SetInteractionModeToImageSlicing()</div><div>interactor.SetInteractorStyle(style)</div><div>style.AddObserver(&#39;CharEvent&#39;, key_press)</div><div>


<br></div><div>print &#39;sorting files...&#39;</div><div>path = &#39;/home/jmrbcu/pictures/workpictures/dicom/BRAIN/&#39;</div><div>files = [os.path.join(path, x) for x in os.listdir(path)]</div><div><br></div><div>ipp = gdcm.IPPSorter()</div>


<div>ipp.SetComputeZSpacing(True)</div><div>ipp.SetZSpacingTolerance(1e-3)</div><div>result = ipp.Sort(files)</div><div><br></div><div>sorted_files, zspacing = files, 0</div><div>if result:</div><div>    sorted_files = ipp.GetFilenames()</div>


<div>    zspacing = ipp.GetZSpacing()</div><div>    print &#39;files sorted, z spacing is: %s&#39; % zspacing</div><div>else:</div><div>    print &#39;cannot sort files, this is not a valid volume&#39;</div><div><br></div>


<div>vtk_files = vtk.vtkStringArray()</div><div>map(vtk_files.InsertNextValue, sorted_files)</div><div><br></div><div>reader = vtkgdcm.vtkGDCMImageReader()</div><div>reader.FileLowerLeftOn()</div><div>reader.SetFileNames(vtk_files)</div>


<div>reader.Update()</div><div><br></div><div>spacing = reader.GetOutput().GetSpacing()</div><div>change = vtk.vtkImageChangeInformation()</div><div>change.SetInputConnection(reader.GetOutputPort())</div><div>change.SetOutputSpacing(spacing[0], spacing[1], zspacing)</div>


<div><br></div><div>im = vtk.vtkImageResliceMapper()</div><div>im.SetInputConnection(change.GetOutputPort())</div><div>im.SliceFacesCameraOn()</div><div>im.SliceAtFocalPointOn()</div><div>im.BorderOff()</div><div><br></div>


<div>ip = vtk.vtkImageProperty()</div><div>ip.SetColorWindow(255)</div><div>ip.SetColorLevel(128)</div><div>ip.SetAmbient(0.0)</div><div>ip.SetDiffuse(1.0)</div><div>ip.SetOpacity(1.0)</div><div>ip.SetInterpolationTypeToLinear()</div>


<div><br></div><div>ia = vtk.vtkImageSlice()</div><div>ia.SetMapper(im)</div><div>ia.SetProperty(ip)</div><div><br></div><div>renderer = vtk.vtkRenderer()</div><div>renderer.AddViewProp(ia)</div><div>renderer.SetBackground(0 , 0, 0)</div>


<div>render_window.AddRenderer(renderer)</div><div><br></div><div>style.SetCurrentRenderer(renderer)</div><div>style.SetZViewRightVector((1, 0, 0))</div><div>style.SetZViewUpVector((0, -1, 0))</div><div><br></div><div>style.SetXViewRightVector((0, 1, 0))</div>


<div>style.SetXViewUpVector((0, 0, 1))</div><div><br></div><div>style.SetYViewRightVector((1, 0, 0))</div><div>style.SetYViewUpVector((0, 0, 1))</div><div>style.SetImageOrientation(style.GetZViewRightVector(), style.GetZViewUpVector())</div>


<div><br></div><div># render the image</div><div>renderer.ResetCamera()</div><div>renderer.GetActiveCamera().ParallelProjectionOn()</div><div>renderer.ResetCameraClippingRange()</div><div>render_window.Render()</div><div>


<br></div><div>interactor.Initialize()</div><div>interactor.Start()</div></div><div><br></div><div>the problems arise in this sequence:</div><div><br></div><div>1-  initially display the image: ok</div><div>2-  slice the image to a different slice with ctrl + mosue left: ok</div>


<div>3-  change the orientation to a different one (sagital or coronal, doesn&#39;t matter): this is the problem, orientation of the image is changed fine to the new one but the image is panned to a different position in the render window/renderer, not the center of it and in a different slice (the middle slice of the whole image)</div>


<div><br></div><div>how can I avoid this, I mean, keep the image centered in the render window/renderer when the image orientation is changed and in the correct slice location?</div>
</blockquote></div><br></div>