import java.awt.BorderLayout;

import javax.swing.JFrame;

import vtk.vtkActor;
import vtk.vtkAlgorithmOutput;
import vtk.vtkCutter;
import vtk.vtkDataSetMapper;
import vtk.vtkDataSetReader;
import vtk.vtkLookupTable;
import vtk.vtkPanel;
import vtk.vtkPlane;
import vtk.vtkScalarBarActor;


public class VtkWriter {
	public static void main(String[] args) {
		vtkPanel panel = new vtkPanel();
		//
		vtkDataSetReader reader = new vtkDataSetReader();
		reader.SetFileName("image.txt");
		reader.Update();
		reader.CloseVTKFile();
		
		//vtkDataSet data = reader.GetOutput();
		vtkAlgorithmOutput output = reader.GetOutputPort();
		vtkDataSetMapper mapper = new vtkDataSetMapper();
		vtkActor actor = new vtkActor();
		//
		vtkCutter cutter = new vtkCutter();
		vtkPlane plan = new vtkPlane();
		plan.SetOrigin(0,0,0);
		plan.SetNormal(0,0,1);
		cutter.SetCutFunction(plan);
		
		cutter.SetInputConnection(output);
		
		vtkLookupTable lookuptable = new vtkLookupTable();
		lookuptable.SetHueRange(0.66667,0);
		//lookuptable.SetRange(reader.GetOutput().GetScalarRange());
		lookuptable.Build();
		
		cutter.GetOutput().Update();
		FiltreGeo filtregeo= new FiltreGeo();
		filtregeo.SetInput(cutter.GetOutput());
		filtregeo.GetOutput().Update();
		FiltreData filtredata = new FiltreData();
		filtredata.SetInputConnection(filtregeo.GetOutputPort());
		filtredata.GetOutput().Update();
		
		
		mapper.SetLookupTable(lookuptable);
		mapper.SetScalarRange(filtredata.GetOutput().GetScalarRange());
		
		vtkScalarBarActor baractor = new vtkScalarBarActor();
		baractor.SetLookupTable(lookuptable);
		
		//
		mapper.SetInputConnection(filtredata.GetOutputPort());
		actor.SetMapper(mapper);
		//
		panel.GetRenderer().AddActor(actor);
		panel.GetRenderer().AddActor2D(baractor);
		
		//
		JFrame f = new JFrame("Cutting test");
		f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		f.setSize(500, 500);
		f.setLocationRelativeTo(null);
		f.getContentPane().setLayout(new BorderLayout());
		f.getContentPane().add(panel, BorderLayout.CENTER);
		f.setVisible(true);
	}

}
