[vtkusers] generate 3D images from 2D bmp files in java

Rémi DUCCESCHI remi.ducceschi at gmail.com
Thu Jun 14 11:01:30 EDT 2012


Hello again!

To answer myself (it will maybe help someone later): it's much easier to
use vtk 5.10 to do what I want thanks to this :
http://www.cmake.org/Wiki/VTK/Image_Rendering_Classes

I still have a problem for updating the vtkRenderWindowPanel: I change the
slice by changing the position of the actor
                actor.SetPosition(pos); // pos is a double[]
                panel.Render();
it does exactly what I want, but the Panel isn't updated until I create an
event with my mouse.
if you know what I can do, you would be welcome!!!

from the beginning to the end, we have the following source code to create
and display a 3D image (see bellow)


------------------------------------- SOURCE CODE
----------------------------------
public class PrintPix extends JFrame
{
    public PrintPix (File[] paths)
    {
        int size = paths.length;
        vtkStringArray array = new vtkStringArray();

        array.SetNumberOfValues(size);
        for (int i = 0; i < size; i++)
        {
            array.SetValue(i, paths[i].getAbsolutePath());
        }

        reader = new vtkBMPReader();
        actor = new vtkImageSlice();
        int numberOfFile = paths.GetNumberOfValues() - 1; // number of open
pictures - 1

        // open pictures and create a 3D picture
        // reader.SetFileNames(paths);
        reader.SetDataExtent(0, numberOfFile, 0, numberOfFile, 0,
numberOfFile);
        reader.SetDataSpacing(1, 1, 40);
        reader.SetFileNames(array);
        reader.Update();

        // put it in a mapper
        vtkImageResliceMapper mapper = new vtkImageResliceMapper();
        mapper.SetInputConnection(reader.GetOutputPort());
        mapper.SliceFacesCameraOn();
        mapper.SliceAtFocalPointOn();

        // on créél les propriétés de l'image
        vtkImageProperty props = new vtkImageProperty();
        props.SetInterpolationTypeToLinear();

        // put all in an actor
        actor.SetMapper(mapper);
        actor.SetProperty(props);
        mapper.UpdateInformation();

        panel = new vtkRenderWindowPanel();
        vtkInteractorStyleImage it = new vtkInteractorStyleImage();
        it.SetInteractionModeToImage3D();
        panel.GetRenderer().AddActor(actor);
        panel.setInteractorStyle(it);

        panel.setPreferredSize(new Dimension(728, 728));
        panel.Render();

        add(panel, BorderLayout.CENTER);

        setTitle("image");
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        pack();
        setVisible(true);

        panel.Render();
    }
}

public static void main (String[] args)
    {
        File paths[];
        // we initialize "paths" with all the pictures we want to open
(with a JFileChooser for instance)

        PrintPix principal = new PrintPix(paths);
    }
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20120614/fc1ed25c/attachment.htm>


More information about the vtkusers mailing list