[vtkusers] Java example for bottle
Todd Simons
todd.a.simons at gmail.com
Wed Dec 20 10:20:07 EST 2006
Hello all,
I'm a relatively new VTK developer. I am using Java as the gui for my VTK
applications. I had a hard time getting started and finding examples
written in Java. I have ported a dozen examples to Java to get familiar
with it. I wanted to post my examples so other Java enthusiasts could get
up to speed on VTK a bit more easily. I hope this helps.
Best Regards,
Todd
package examples;
/*-----------------------------------------------------------
bottle.tcl converted to Java
This example shows how create a rotationally symmetric object
-----------------------------------------------------------*/
import vtk.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
public class Bottle {
// in the static contructor we load in the native code
// The libraries must be in your path to work
static {
System.loadLibrary("vtkCommonJava");
System.loadLibrary("vtkFilteringJava");
System.loadLibrary("vtkIOJava");
System.loadLibrary("vtkImagingJava");
System.loadLibrary("vtkGraphicsJava");
System.loadLibrary("vtkRenderingJava");
}
public static void main(String s[]) {
double x[][]={{0.01, 0.0, 0.0},
{1.5, 0.0, 0.0},
{1.5, 0.0, 3.5},
{1.25, 0.0, 3.75},
{0.75, 0.0, 4.00},
{0.6, 0.0, 4.35},
{0.7, 0.0, 4.65},
{1.0, 0.0, 4.75},
{1.0, 0.0, 5.0},
{0.2, 0.0, 5.0}};
vtkPoints points = new vtkPoints();
points.Allocate(10,10);
for (int i=0; i<10; i++) points.InsertPoint(i,x[i]);
points.SetNumberOfPoints(10);
vtkCellArray lines = new vtkCellArray();
lines.Allocate(10,10);
lines.InsertNextCell(10); //number of points in line
for (int i=0; i<10; i++) {
lines.InsertCellPoint(i);
}
vtkPolyData profile=new vtkPolyData();
profile.SetPoints(points);
profile.SetLines(lines);
//vtkDataSetMapper uMap = new vtkDataSetMapper();
//uMap.SetInput(profile);
//extrude profile to make bottle
vtkRotationalExtrusionFilter extrude=new vtkRotationalExtrusionFilter ();
extrude.SetInput(profile);
extrude.SetResolution(60);
extrude.Update();
vtkPolyDataMapper map = new vtkPolyDataMapper();
map.SetInput(extrude.GetOutput());
vtkActor bottle=new vtkActor();
bottle.SetMapper(map);
bottle.GetProperty().SetColor(0.3800, 0.7000, 0.1600);
//bottle.GetProperty().BackfaceCullingOff();
//bottle.GetProperty().FrontfaceCullingOn();
//Add the actors to the renderer, set the background and size
vtkRenderer renderer = new vtkRenderer ();
vtkRenderWindow renWin = new vtkRenderWindow();
renWin.AddRenderer(renderer);
renderer.AddActor(bottle);
renderer.SetBackground(1, 1, 1);
vtkRenderWindowInteractor iren = new vtkRenderWindowInteractor();
iren.SetRenderWindow(renWin);
renWin.SetSize(500, 500);
renWin.Render();
iren.Start();
} //main
} //class Bottle
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20061220/78556f59/attachment.htm>
More information about the vtkusers
mailing list