[vtkusers] converting java array to vtkimage data

Sebastien Jourdain sebastien.jourdain at kitware.com
Fri Apr 23 17:35:32 EDT 2010


Try that and hit the "r" key to reset camera once it is loaded...

public class VTKSample {

	public static void main(String[] args) {
		// Build the VTK 3D view
		// (Should be done before using any vtk
		//  object or load the native
		//  library first)
		vtkPanel panel3D = new vtkPanel();

                // ..... Put your code and pipeline here .....
                vtkActor yourActor = new vtkActor();
                // ..... Put your code and pipeline here .....

		// Add actor in 3D Panel
		panel3D.GetRenderer().AddActor(yourActor);

		// Build Java Frame and include the VTK view
		JFrame frame = new JFrame("Test");
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frame.getContentPane().setLayout(new BorderLayout());
		frame.getContentPane().add(panel3D, BorderLayout.CENTER);
		frame.setSize(500, 500);
		frame.setLocationRelativeTo(null); // Center on desktop
		frame.setVisible(true);
	}
}



On Fri, Apr 23, 2010 at 4:04 PM, nikhil singhania <niksinghania at gmail.com>wrote:

> Sir,
> Thank you for your reply.It proved to be a great help.All errors are
> gone but in spite of giving rendered object it gives a renderer window
> with a red square which vanishes at once.Here is the whole code.
>
> package javaapplication2;
> import java.io.*;
> import vtk.*;
>
>
> public class fileread
> {
>    static{
>  System.loadLibrary("vtkFilteringJava");
>
> System.loadLibrary("vtkIOJava");
>  System.loadLibrary("vtkImagingJava");
>
> System.loadLibrary("vtkGraphicsJava");
>  System.loadLibrary("vtkRenderingJava");
>
> try {
>  System.loadLibrary("vtkHybridJava");
>  } catch (Throwable e) {
>
> System.out.println("cannot load vtkHybrid, skipping...");
>  }
>  try {
>  System.loadLibrary("vtkVolumeRenderingJava");
>
> } catch (Throwable e) {
>  System.out.println("cannot load vtkVolumeRendering, skipping...");
> }
>
> }
>     public static FileOutputStream Output;
>    public static FileInputStream fstream;
>    public static PrintStream file;
>    public static char[][][] arr=new char[50][500][500];
>
>    public static int i = 0;
>    public static int j = 0;
>    public static int k = 0;
>
>     public static void main(String argv[])
>     {
>          try
>          {
>
>             fstream=new
>
> FileInputStream("C:\\Users\\nikhil\\Desktop\\JavaApplication2\\VH_1760_1024_1878.raw");
>            // Output = new FileOutputStream("aq5.raw");
>             BufferedInputStream bis=new BufferedInputStream(fstream);
>
>             DataInputStream in = new DataInputStream(bis);
>                long l;
>              l=in.skip(13);
>              System.out.println("l value="+l);
>
>            // file = new PrintStream(Output);
>           for(k =0;k < 50 ;k += 1)
>            {
>              for(i = 0; i < 500;i += 1)
>                {
>                    for(j = 0; j < 500;j += 1){
>                        arr[k][i][j] =(char) in.readByte();
>
>              }
>                 l=in.skip(1260);
>              }
>               l=in.skip(524*1760);
>           }
>
>     }
>          catch(Exception e)
>          {
>               System.out.println("Could not load file!");
>          }
>
>  new vtkPanel();
>  vtkImageData image = new vtkImageData();
>  image.SetDimensions(500, 500, 50);
>  image.SetOrigin(0.0, 0.0, 0.0);
>  image.SetSpacing(0.33,0.33,0.33);
> image.SetScalarTypeToShort();
> image.AllocateScalars();
>  vtkDataArray array = image.GetPointData().GetScalars();
>
>  for(int iZ = 0; iZ < 50; iZ++){
>  for(int iY= 0; iY < 500; iY++){
>  for(int iX = 0; iX < 500; iX++){
>  array.InsertNextTuple1(arr[iZ][iY][iX]);
> }
>  }
>  }
>
>
>           vtkImageDataGeometryFilter imgfilt = new
> vtkImageDataGeometryFilter();
>            imgfilt.SetInput(image);
>            vtkWarpScalar warp = new vtkWarpScalar();
>            warp.SetInputConnection(imgfilt.GetOutputPort());
>           vtkPolyDataMapper mapper =new vtkPolyDataMapper();
>            mapper.SetInputConnection(warp.GetOutputPort());
>
>            vtkActor actor =new vtkActor();
>            actor.SetMapper(mapper);
>            vtkRenderer ren = new vtkRenderer();
>            ren.AddActor(actor);
>            vtkRenderWindow renWin =new vtkRenderWindow();
>            renWin.AddRenderer(ren);
>            renWin.Render();
>     }
> }
> Thank You.
>
> With regards,
>
> Nikhil
>
> On 23/04/2010, Sebastien Jourdain <sebastien.jourdain at kitware.com> wrote:
> > Hi Nikhil,
> >
> > "Exception in thread "main"
> > java.lang.UnsatisfiedLinkError:vtk.vtkImageData.VTKInit()J
> >
> > Means their is an issue with the link to the native layer.
> >
> > So make sure those library have well been loaded before. Because
> depending
> > on your code and system,
> > those library might not be loaded when you use vtkImageData and might be
> > loaded when used with other VTK functions. Try to write  "new
> vtkPanel();"
> > prior the "vtkImageData image = new vtkImageData();".
> > (vtkPanel embed this native library loading lines...)
> >
> > Seb
> >
> >
> > On Fri, Apr 23, 2010 at 3:20 PM, nikhil singhania
> > <niksinghania at gmail.com>wrote:
> >
> >> Sir,
> >> Thank you for your reply.The code is working for all other vtk
> >> functions just giving error for  vtkimagedata .Does vtkimagedata
> >> require any additional file to be loaded. Environmental variable  path
> >> is also set.
> >> Thank You.
> >>
> >> Best regards,
> >> Nikhil
> >>
> >> On 23/04/2010, Sebastien Jourdain <sebastien.jourdain at kitware.com>
> wrote:
> >> > Hi Nikhil,
> >> >
> >> > You forgot to load the system library.
> >> >
> >> > You have to add the following line in your code as well as having
> >> depending
> >> > on your system the directory that content the vtk library inside the
> >> > environment vairiable PATH/LD_LIBRARY_PATH/DYLD_LIBRARY_PATH
> >> (win/unix/mac).
> >> >
> >> > static {
> >> >     System.loadLibrary("vtkCommonJava");
> >> >     System.loadLibrary("vtkFilteringJava");
> >> >     System.loadLibrary("vtkIOJava");
> >> >     System.loadLibrary("vtkImagingJava");
> >> >     System.loadLibrary("vtkGraphicsJava");
> >> >     System.loadLibrary("vtkRenderingJava");
> >> >     try {
> >> >       System.loadLibrary("vtkHybridJava");
> >> >     } catch (Throwable e) {
> >> >       System.out.println("cannot load vtkHybrid, skipping...");
> >> >     }
> >> >     try {
> >> >       System.loadLibrary("vtkVolumeRenderingJava");
> >> >     } catch (Throwable e) {
> >> >       System.out.println("cannot load vtkVolumeRendering,
> skipping...");
> >> >     }
> >> >   }
> >> >
> >> > Seb
> >> >
> >> > On Fri, Apr 23, 2010 at 2:57 PM, nikhil singhania
> >> > <niksinghania at gmail.com>wrote:
> >> >
> >> >> Sir,
> >> >> I am writing a code to convert java array to image data..but getting
> an
> >> >> error:
> >> >>
> >> >> "Exception in thread "main" java.lang.UnsatisfiedLinkError:
> >> >> vtk.vtkImageData.VTKInit()J
> >> >>        at vtk.vtkImageData.VTKInit(Native Method)
> >> >>        at vtk.vtkObject.<init>(vtkObject.java:96)
> >> >>        at vtk.vtkDataObject.<init>(vtkDataObject.java:1206)
> >> >>        at vtk.vtkDataSet.<init>(vtkDataSet.java:225)
> >> >>        at vtk.vtkImageData.<init>(vtkImageData.java:347)
> >> >>        at javaapplication2.fileread.main(fileread.java:49)"
> >> >>
> >> >> here is some part of code...
> >> >>
> >> >>  vtkImageData image = new vtkImageData();
> >> >>  image.SetDimensions(500, 500, 50);
> >> >>  image.SetOrigin(0.0, 0.0, 0.0);
> >> >>  image.SetSpacing(0.33,0.33,0.33);
> >> >>  image.SetScalarTypeToChar();
> >> >>  image.AllocateScalars();
> >> >>  vtkDataArray array = image.GetPointData().GetScalars();
> >> >>
> >> >>  for(int iZ = 0; iZ < 50; iZ++){
> >> >>            for(int iY= 0; iY < 500; iY++){
> >> >>                      for(int iX = 0; iX < 500; iX++){
> >> >>
> >> >> array.InsertNextTuple1(arr[iZ][iY][iX]);
> >> >>                        }
> >> >>               }
> >> >>   }
> >> >>
> >> >> Please help.
> >> >>
> >> >> Thank You.
> >> >> --
> >> >> Nikhil Kumar
> >> >> rit2007033
> >> >> b.tech IT 6th sem
> >> >> IIIT Allahabad
> >> >> contact at 9793905858
> >> >> email: rit2007033 at iiita.ac.in
> >> >>          niksinghania at gmail.com
> >> >> http://profile.iiita.ac.in/RIT2007033/
> >> >> _______________________________________________
> >> >> Powered by www.kitware.com
> >> >>
> >> >> Visit other Kitware open-source projects at
> >> >> http://www.kitware.com/opensource/opensource.html
> >> >>
> >> >> Please keep messages on-topic and check the VTK FAQ at:
> >> >> http://www.vtk.org/Wiki/VTK_FAQ
> >> >>
> >> >> Follow this link to subscribe/unsubscribe:
> >> >> http://www.vtk.org/mailman/listinfo/vtkusers
> >> >>
> >> >
> >>
> >>
> >> --
> >> Nikhil Kumar
> >> rit2007033
> >> b.tech IT 6th sem
> >> IIIT Allahabad
> >> contact at 9793905858
> >> email: rit2007033 at iiita.ac.in
> >>          niksinghania at gmail.com
> >> http://profile.iiita.ac.in/RIT2007033/
> >>
> >
>
>
> --
> Nikhil Kumar
> rit2007033
> b.tech IT 6th sem
> IIIT Allahabad
> contact at 9793905858
> email: rit2007033 at iiita.ac.in
>          niksinghania at gmail.com
> http://profile.iiita.ac.in/RIT2007033/
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20100423/273755f2/attachment.htm>


More information about the vtkusers mailing list