Skip to content


# SimplePointsReader

VTKEx/Java/IO/SimplePointsReader

### Description

A file of XYZ coordinates is a very easy format that can be used for simple storage from many applications. This example demonstrates how to read this type of file into a polydata object. An example file of three points would look like this:

0.0 0.0 0.0 1.0 0.0 0.0 0.0 1.0 0.0

As a demo, save the above three lines to a file called simple.xyz

Other languages

See (Cxx), (CSharp)

Question

If you have a simple question about this example contact us at VTKExProject If your question is more complex and may require extended discussion, please use the VTK Discourse Forum

### Code

SimplePointsReader.java

    import vtk.vtkNativeLibrary;
    import vtk.vtkRenderWindow;
    import vtk.vtkRenderWindowInteractor;
    import vtk.vtkRenderer;
    import vtk.vtkActor;
    import vtk.vtkNamedColors;
    import vtk.vtkPolyDataMapper;
    import vtk.vtkSimplePointsReader;

    public class SimplePointsReader
    {
      // -----------------------------------------------------------------
      // Load VTK library and print which library was not properly loaded
      static
      {
        if (!vtkNativeLibrary.LoadAllNativeLibraries())
        {
          for (vtkNativeLibrary lib : vtkNativeLibrary.values())
          {
            if (!lib.IsLoaded())
            {
              System.out.println(lib.GetLibraryName() + " not loaded");
            }
          }
        }
        vtkNativeLibrary.DisableOutputWindow(null);
      }
      // -----------------------------------------------------------------

      public static void main(String args[])
      {

        //parse command line arguments
        if (args.length != 1)
        {
          System.err.println("Usage: java -classpath ... Filename(.xyz) e.g simple.xyz");
          return;
        }
        String inputFilename = args[0];

        vtkNamedColors Color = new vtkNamedColors();

        //Renderer Background Color
        double BgColor[] = new double[4];

        //Change Color Name to Use your own Color for Renderer Background
        Color.GetColor("Seagreen",BgColor);

        vtkSimplePointsReader reader = new vtkSimplePointsReader();
        reader.SetFileName(inputFilename);
        reader.Update();

        // Create a mapper and actor
        vtkPolyDataMapper mapper = new vtkPolyDataMapper();
        mapper.SetInputConnection(reader.GetOutputPort());

        vtkActor actor = new vtkActor();
        actor.SetMapper(mapper);
        actor.GetProperty().SetPointSize(5);

        // Create the renderer, render window and interactor.
        vtkRenderer ren = new vtkRenderer();
        vtkRenderWindow renWin = new vtkRenderWindow();
        renWin.AddRenderer(ren);
        vtkRenderWindowInteractor iren = new vtkRenderWindowInteractor();
        iren.SetRenderWindow(renWin);

        ren.AddActor(actor);
        ren.SetBackground(BgColor);

        renWin.SetSize(300,300);
        renWin.Render();

        iren.Initialize();
        iren.Start();

      }
    }