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