import java.awt.BorderLayout;

import javax.swing.JFrame;

import vtk.vtkGeneralTransform;
import vtk.vtkImplicitBoolean;
import vtk.vtkImplicitFunction;
import vtk.vtkPanel;
import vtk.vtkPlane;


public class HexagoneImplicitFunction {

	int _halfheight = 5;
	int delta = 1;
	int _pas = 3;
	
	public HexagoneImplicitFunction() {

	}
	
	public vtkImplicitFunction getFunction(int op) {

        vtkImplicitBoolean func = new vtkImplicitBoolean();
        vtkPlane p = new vtkPlane();
        p.SetOrigin( 0, 0, _halfheight + delta );
        p.SetNormal( 0, 0, 1 );
        func.AddFunction( p );

        p = new vtkPlane();
        p.SetOrigin( 0, 0, - _halfheight - delta );
        p.SetNormal( 0, 0, -1 );
        func.AddFunction( p );
        func.SetOperationType( 1 );

        p = new vtkPlane();
        p.SetOrigin( _pas, 0, 0);
        p.SetNormal( Math.cos(Math.PI/3), Math.sin(Math.PI/3), 0 );
        func.AddFunction( p );
        func.SetOperationType( 1 );
        vtkGeneralTransform t = new vtkGeneralTransform();
        t.Translate( 0, -2 * _pas, 0 );
        p.SetNormal( -Math.cos(Math.PI/3), -Math.sin(Math.PI/3), 0 );
        func.AddFunction( p );
        func.SetOperationType( 1 );

        p = new vtkPlane();
        p.SetOrigin( 0, _pas, 0);
        p.SetNormal( 0, 1, 0 );
        func.AddFunction( p );
        func.SetOperationType( 1 );
        t = new vtkGeneralTransform();
        t.Translate( 0, -2 * _pas, 0 );
        p.SetNormal( 0, -1, 0 );
        func.AddFunction( p );
        func.SetOperationType( 1 );

        p = new vtkPlane();
        p.SetOrigin( _pas, 0, 0);
        p.SetNormal( Math.cos(Math.PI/3), -Math.sin(Math.PI/3), 0 );
        func.AddFunction( p );
        func.SetOperationType( 1 );
        t = new vtkGeneralTransform();
        t.Translate( 0, -2 * _pas, 0 );
        p.SetNormal( -Math.cos(Math.PI/3), Math.sin(Math.PI/3), 0 );
        func.AddFunction( p );
        func.SetOperationType( 1 );

        vtkImplicitBoolean nf = new vtkImplicitBoolean();
        nf.AddFunction( func );
        nf.SetOperationType( 1 );

        t = new vtkGeneralTransform();
        t.SetInput( _trans );
        t.Inverse();
        nf.SetTransform( t );

        return nf;
	}

	public static void main(String[] args) {
		
	vtkPanel panel = new vtkPanel();

    HexagoneImplicitFunction hex = new HexagoneImplicitFunction();
		
	JFrame f = new JFrame("Hexagone 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);

}
	
}
