hi David:<div><br></div><div>saving the focal point did the trick!!! thanks very much </div><div>another question, how do I know the current slice number given the camera parameters, for example, if my image have the following dimensions: (0, 256, 0, 256, 0, 199), the vtkInteractorStyleImage put the initial view in the center using an axial orientation, this is the slice: 99. If I want the user of my class can call a function named, for example: set_slice(slice_number) where slice_number will be the number of the desired slice to view, in this example a number between 0 and 199, how do I do that?</div>

<div class="gmail_extra"><br><br><div class="gmail_quote">On Wed, Dec 12, 2012 at 8:54 AM, David Gobbi <span dir="ltr">&lt;<a href="mailto:david.gobbi@gmail.com" target="_blank">david.gobbi@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">Arrgh.  Another typo.  The code should be:<br>
<br>
  camera.SetFocalPoint(focal_point_for_axial_view)<br>
  style.SetImageOrientation(orientation_for_axial_view)<br>
<br>
And of course you should save the focal point for the<br>
previous orientation at the same time.<br>
<span class="HOEnZb"><font color="#888888"><br>
 - David<br>
</font></span><div class="im HOEnZb"><br>
On Wed, Dec 12, 2012 at 6:53 AM, David Gobbi &lt;<a href="mailto:david.gobbi@gmail.com">david.gobbi@gmail.com</a>&gt; wrote:<br>
&gt; On Wed, Dec 12, 2012 at 6:51 AM, David Gobbi &lt;<a href="mailto:david.gobbi@gmail.com">david.gobbi@gmail.com</a>&gt; wrote:<br>
&gt;&gt; The slicing and the panning are both controlled via the camera&#39;s focal<br>
&gt;&gt; point.  So slicing through the axial images causes the camera&#39;s<br>
&gt;&gt; FocalPoint to move in and out along the Z axis.  Then, when you switch<br>
&gt;&gt; to a new orientation, this &quot;Z&quot; position is centered in the window.<br>
&gt;&gt;<br>
&gt;&gt; If you want to avoid this, you should save the FocalPoint for each<br>
&gt;&gt; view orientation.  Then, you can restore the focal point before you<br>
&gt;&gt; call SetImageOrientation, e.g.<br>
&gt;&gt;<br>
&gt;&gt; camera.SetFocalPoint(focal_point_for_axial_view)<br>
&gt;&gt; camera.SetImageOrientation(orientation_for_axial_view)<br>
&gt;&gt;<br>
</div><div class="HOEnZb"><div class="h5">&gt;&gt;  - David<br>
&gt;&gt;<br>
&gt;&gt; On Wed, Dec 12, 2012 at 5:24 AM, José M. Rodriguez Bacallao<br>
&gt;&gt; &lt;<a href="mailto:jmrbcu@gmail.com">jmrbcu@gmail.com</a>&gt; wrote:<br>
&gt;&gt;&gt; no one please, is this normal?<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; On Tue, Dec 11, 2012 at 9:45 AM, José M. Rodriguez Bacallao<br>
&gt;&gt;&gt; &lt;<a href="mailto:jmrbcu@gmail.com">jmrbcu@gmail.com</a>&gt; wrote:<br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt; hi folks, I am trying to implement a MPR viewer, so far so good. I am<br>
&gt;&gt;&gt;&gt; using the new image classes, this is test code:<br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt; #!/usr/bin/env python<br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt; import os<br>
&gt;&gt;&gt;&gt; import gdcm, vtkgdcm, vtk<br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt; def key_press(sender, event):<br>
&gt;&gt;&gt;&gt;     key = interactor.GetKeySym()<br>
&gt;&gt;&gt;&gt;     style.SetCurrentRenderer(renderer)<br>
&gt;&gt;&gt;&gt;     if key == &#39;a&#39;:<br>
&gt;&gt;&gt;&gt;         print &#39;axial&#39;<br>
&gt;&gt;&gt;&gt;         style.SetImageOrientation(<br>
&gt;&gt;&gt;&gt;             style.GetZViewRightVector(),<br>
&gt;&gt;&gt;&gt;             style.GetZViewUpVector()<br>
&gt;&gt;&gt;&gt;         )<br>
&gt;&gt;&gt;&gt;     elif key == &#39;c&#39;:<br>
&gt;&gt;&gt;&gt;         print &#39;coronal&#39;<br>
&gt;&gt;&gt;&gt;         style.SetImageOrientation(<br>
&gt;&gt;&gt;&gt;             style.GetYViewRightVector(),<br>
&gt;&gt;&gt;&gt;             style.GetYViewUpVector()<br>
&gt;&gt;&gt;&gt;         )<br>
&gt;&gt;&gt;&gt;     elif key == &#39;s&#39;:<br>
&gt;&gt;&gt;&gt;         print &#39;axial&#39;<br>
&gt;&gt;&gt;&gt;         style.SetImageOrientation(<br>
&gt;&gt;&gt;&gt;             style.GetXViewRightVector(),<br>
&gt;&gt;&gt;&gt;             style.GetXViewUpVector()<br>
&gt;&gt;&gt;&gt;         )<br>
&gt;&gt;&gt;&gt;     render_window.Render()<br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt; interactor = vtk.vtkRenderWindowInteractor()<br>
&gt;&gt;&gt;&gt; render_window = vtk.vtkRenderWindow()<br>
&gt;&gt;&gt;&gt; render_window.SetSize(400, 400)<br>
&gt;&gt;&gt;&gt; interactor.SetRenderWindow(render_window)<br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt; style = vtk.vtkInteractorStyleImage()<br>
&gt;&gt;&gt;&gt; style.SetInteractionModeToImageSlicing()<br>
&gt;&gt;&gt;&gt; interactor.SetInteractorStyle(style)<br>
&gt;&gt;&gt;&gt; style.AddObserver(&#39;CharEvent&#39;, key_press)<br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt; print &#39;sorting files...&#39;<br>
&gt;&gt;&gt;&gt; path = &#39;/home/jmrbcu/pictures/workpictures/dicom/BRAIN/&#39;<br>
&gt;&gt;&gt;&gt; files = [os.path.join(path, x) for x in os.listdir(path)]<br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt; ipp = gdcm.IPPSorter()<br>
&gt;&gt;&gt;&gt; ipp.SetComputeZSpacing(True)<br>
&gt;&gt;&gt;&gt; ipp.SetZSpacingTolerance(1e-3)<br>
&gt;&gt;&gt;&gt; result = ipp.Sort(files)<br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt; sorted_files, zspacing = files, 0<br>
&gt;&gt;&gt;&gt; if result:<br>
&gt;&gt;&gt;&gt;     sorted_files = ipp.GetFilenames()<br>
&gt;&gt;&gt;&gt;     zspacing = ipp.GetZSpacing()<br>
&gt;&gt;&gt;&gt;     print &#39;files sorted, z spacing is: %s&#39; % zspacing<br>
&gt;&gt;&gt;&gt; else:<br>
&gt;&gt;&gt;&gt;     print &#39;cannot sort files, this is not a valid volume&#39;<br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt; vtk_files = vtk.vtkStringArray()<br>
&gt;&gt;&gt;&gt; map(vtk_files.InsertNextValue, sorted_files)<br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt; reader = vtkgdcm.vtkGDCMImageReader()<br>
&gt;&gt;&gt;&gt; reader.FileLowerLeftOn()<br>
&gt;&gt;&gt;&gt; reader.SetFileNames(vtk_files)<br>
&gt;&gt;&gt;&gt; reader.Update()<br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt; spacing = reader.GetOutput().GetSpacing()<br>
&gt;&gt;&gt;&gt; change = vtk.vtkImageChangeInformation()<br>
&gt;&gt;&gt;&gt; change.SetInputConnection(reader.GetOutputPort())<br>
&gt;&gt;&gt;&gt; change.SetOutputSpacing(spacing[0], spacing[1], zspacing)<br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt; im = vtk.vtkImageResliceMapper()<br>
&gt;&gt;&gt;&gt; im.SetInputConnection(change.GetOutputPort())<br>
&gt;&gt;&gt;&gt; im.SliceFacesCameraOn()<br>
&gt;&gt;&gt;&gt; im.SliceAtFocalPointOn()<br>
&gt;&gt;&gt;&gt; im.BorderOff()<br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt; ip = vtk.vtkImageProperty()<br>
&gt;&gt;&gt;&gt; ip.SetColorWindow(255)<br>
&gt;&gt;&gt;&gt; ip.SetColorLevel(128)<br>
&gt;&gt;&gt;&gt; ip.SetAmbient(0.0)<br>
&gt;&gt;&gt;&gt; ip.SetDiffuse(1.0)<br>
&gt;&gt;&gt;&gt; ip.SetOpacity(1.0)<br>
&gt;&gt;&gt;&gt; ip.SetInterpolationTypeToLinear()<br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt; ia = vtk.vtkImageSlice()<br>
&gt;&gt;&gt;&gt; ia.SetMapper(im)<br>
&gt;&gt;&gt;&gt; ia.SetProperty(ip)<br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt; renderer = vtk.vtkRenderer()<br>
&gt;&gt;&gt;&gt; renderer.AddViewProp(ia)<br>
&gt;&gt;&gt;&gt; renderer.SetBackground(0 , 0, 0)<br>
&gt;&gt;&gt;&gt; render_window.AddRenderer(renderer)<br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt; style.SetCurrentRenderer(renderer)<br>
&gt;&gt;&gt;&gt; style.SetZViewRightVector((1, 0, 0))<br>
&gt;&gt;&gt;&gt; style.SetZViewUpVector((0, -1, 0))<br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt; style.SetXViewRightVector((0, 1, 0))<br>
&gt;&gt;&gt;&gt; style.SetXViewUpVector((0, 0, 1))<br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt; style.SetYViewRightVector((1, 0, 0))<br>
&gt;&gt;&gt;&gt; style.SetYViewUpVector((0, 0, 1))<br>
&gt;&gt;&gt;&gt; style.SetImageOrientation(style.GetZViewRightVector(),<br>
&gt;&gt;&gt;&gt; style.GetZViewUpVector())<br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt; # render the image<br>
&gt;&gt;&gt;&gt; renderer.ResetCamera()<br>
&gt;&gt;&gt;&gt; renderer.GetActiveCamera().ParallelProjectionOn()<br>
&gt;&gt;&gt;&gt; renderer.ResetCameraClippingRange()<br>
&gt;&gt;&gt;&gt; render_window.Render()<br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt; interactor.Initialize()<br>
&gt;&gt;&gt;&gt; interactor.Start()<br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt; the problems arise in this sequence:<br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt; 1-  initially display the image: ok<br>
&gt;&gt;&gt;&gt; 2-  slice the image to a different slice with ctrl + mosue left: ok<br>
&gt;&gt;&gt;&gt; 3-  change the orientation to a different one (sagital or coronal, doesn&#39;t<br>
&gt;&gt;&gt;&gt; matter): this is the problem, orientation of the image is changed fine to<br>
&gt;&gt;&gt;&gt; the new one but the image is panned to a different position in the render<br>
&gt;&gt;&gt;&gt; window/renderer, not the center of it and in a different slice (the middle<br>
&gt;&gt;&gt;&gt; slice of the whole image)<br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt; how can I avoid this, I mean, keep the image centered in the render<br>
&gt;&gt;&gt;&gt; window/renderer when the image orientation is changed and in the correct<br>
&gt;&gt;&gt;&gt; slice location?<br>
</div></div></blockquote></div><br></div>