|
|
import vtk.*; public class Polygonal { public static void main(String[] argv) { PolygonalDataset pd=new PolygonalDataset("data", 5); // geometry // index x y z pd.setPoint( 0, 1.5, 0 , 0 ); pd.setPoint( 1, 0 , 1.5, 0 ); pd.setPoint( 2, 1.5, 1.5, 0 ); pd.setPoint( 3, 0 , 0 , 0 ); pd.setPoint( 4, -1.5,-1.5, 0 ); // topology pd.addPolygon(new int[] {0, 1, 2, 0}); pd.addLines (new int[] {3, 4}); // fields (here only one) ColorField cf = new ColorField("lut", 5,1,1); // set colour of points // index r g b alpha cf.setColor(0,0,0, 1,0,0, 1); cf.setColor(1,0,0, 0,1,0, 1); cf.setColor(2,0,0, 0,0,1, 1); cf.setColor(3,0,0, 0,0,0, 1); cf.setColor(4,0,0, 0,0,0, 1); // add colour field to this Polygonal Dataset pd.add(cf); pd.write("polygonal.vtk"); } } |
# vtk DataFile Version 2.0 data ASCII DATASET POLYDATA POINTS 5 float 1.5 0.0 0.0 0.0 1.5 0.0 1.5 1.5 0.0 0.0 0.0 0.0 -1.5 -1.5 0.0 LINES 1 3 2 3 4 POLYGONS 1 5 4 0 1 2 0 POINT_DATA 5 COLOR_SCALARS lut 4 1.0 0.0 0.0 1.0 0.0 1.0 0.0 1.0 0.0 0.0 1.0 1.0 0.0 0.0 0.0 1.0 0.0 0.0 0.0 1.0 |
the components of a dataset | |
geometry | a set of 3-dimensional points |
topology | a structure defined on these points, e.g. a grid or a set of polygons |
one or more fields | mappings that map each point to either a scalar, a vector, or a color |
abstract class Field { private String name; private int nx, ny, nz; // dimensions public String getName(); public int[/*3*/] getDimensions(); } |
class ScalarField extends Field { public ScalarField(String name, int nx, int ny, int nz); public double getScalar(int i, int j, int k); public void setScalar(int i, int j, int k, double value); }
class ColorField extends Field { public ColorField(String name, int nx, int ny, int nz); public double[] getColor(int i, int j, int k); public void setColor(int i, int j, int k, double r, double g, double b, double alpha); }
class VectorField extends Field { public VectorField(String name, int nx, int ny, int nz); public double[] getVector(int i, int j, int k); public void setVector(int i, int j, int k, double x, double y, double z); }
abstract class Dataset { private String name; ... public String getName(); public int getNumberOfPoints(); public void add(ScalarField sf); public void add(VectorField vf); public void add(ColorField cf); public void write(String filename); ... } |
class PolygonalDataset extends Dataset { public PolygonalDataset(String name, int n); public void addVertices(int[] pi); public void addLines(int[] pi); public void addPolygon(int[] pi); public void setPoint(int i, double x, double y, double z); ... } |
abstract class StructuredDataset extends Dataset { private int nx, ny, nz; // dimensions public int[/*3*/] getDimensions(); }
class StructuredPoints extends StructuredDataset { public StructuredPoints(String name, int nx, int ny, int nz); public void setOrigin(double x, double y, double z); public void setSpacing(double sx, double sy, double sz); ... } |
class StructuredGrid extends StructuredDataset { public StructuredGrid(String name, int nx, int ny, int nz); public void setPoint(int i, int j, int k, double x, double y, double z); ... } |
import vtk.*; public class Polygonal { public static void main(String[] argv) { PolygonalDataset pd=new PolygonalDataset("data", 5); // geometry // index x y z pd.setPoint( 0, 1.5, 0 , 0 ); pd.setPoint( 1, 0 , 1.5, 0 ); pd.setPoint( 2, 1.5, 1.5, 0 ); pd.setPoint( 3, 0 , 0 , 0 ); pd.setPoint( 4, -1.5,-1.5, 0 ); // topology pd.addPolygon(new int[] {0, 1, 2, 0}); pd.addLines (new int[] {3, 4}); // fields (here only one) ColorField cf = new ColorField("lut", 5,1,1); // set colour of points // index r g b alpha cf.setColor(0,0,0, 1,0,0, 1); cf.setColor(1,0,0, 0,1,0, 1); cf.setColor(2,0,0, 0,0,1, 1); cf.setColor(3,0,0, 0,0,0, 1); cf.setColor(4,0,0, 0,0,0, 1); // add colour field to this Polygonal Dataset pd.add(cf); pd.write("polygonal.vtk"); } } |
import vtk.*; public class StructPoints { public static void main(String[] argv) { int[] dim = new int[] { 20, 10 , 5 }; // dimensions // create a Structured Points Dataset StructuredPoints sp = new StructuredPoints("structured points", dim[0], dim[1], dim[2]); sp.setOrigin(0,0,0); sp.setSpacing(0.1,0.1,0.1); ScalarField sf = new ScalarField("data",dim[0],dim[1],dim[2]); for(int i = 0; i < dim[0]; i = i+1) for(int j = 0; j < dim[1]; j = j+1) for(int k = 0; k < dim[2]; k=k+1) { double dx=i-(dim[0]-1)/2d; double dy=j-(dim[1]-1)/2d; double dz=k-(dim[2]-1)/2d; sf.setScalar(i, j, k, dx*dx + dy*dy + dz*dz); } sp.add(sf); sp.write("points.vtk"); } } |
import vtk.*; public class StructGrid { public static void main(String[] argv) { int[] dim = new int[] { 20, 20 , 1 }; // dimensions StructuredGrid sg = new StructuredGrid("structured grid", dim[0], dim[1], dim[2]); for(int i = 0; i < dim[0]; i = i+1) for(int j = 0; j < dim[1]; j = j+1) for(int k = 0; k < dim[2]; k=k+1) { double x=Math.log(10*i+1); double y=Math.log(10*j+1); double z=0; sg.setPoint(i , j, k, x, y, z); } VectorField vf = new VectorField("data",dim[0],dim[1],dim[2]); for(int i = 0; i < dim[0]; i = i+1) for(int j = 0; j < dim[1]; j = j+1) for(int k = 0; k < dim[2]; k=k+1) { double x=0; double y=0; double z=i+j; vf.setVector(i,j,k,x,y,z); } sg.add(vf); sg.write("grid.vtk"); } } |