[vtkusers] Problems with vtkVectorText and vtkFollower in Java
Carlos Martínez Burgos
cmarbur at iti.upv.es
Wed Dec 11 05:55:37 EST 2002
Hi again.
I have done some code to show what I want to do? The files are attached.
On Grid1 I show what I want to do, drawing spheres instead of text.
On Grid2 I use the same code but drawing text instead of spheres. I can't
see any text on screen so I think there is a bug in the Java wrapper
because I can see texts in tcl examples. If you run this example and can
see any text please let me know.
Does somebody tried text drawings using java wrapper?
Thanks in advance.
On Tue, 10 Dec 2002, Jeff Lee wrote:
> perhaps you could post some sample code so we can see what you are
> trying to do?
> -Jeff
>
> Carlos Martínez Burgos wrote:
>
> >Hi all.
> >
> >I try to do a grid plane using vtkPlaneSource. I have to put some legend.
> >At first I had tried to include a vtkCubeAxisActor2D but its behaviour is
> >not as I want. I want to assign a number/leter to each axis of the grid.
> >This shows it:
> >
> > A B C
> > +-+-+-+
> >1 | | | |
> > +-+-+-+
> >2 | | | |
> > +-+-+-+
> >3 | | | |
> > +-+-+-+
> >
> >I have tried to use vtkVectorText and vtkFollower but nothing is showed.
> >I'm using the Java wrapper. If I run the Tcl sample programs the text is
> >showed. Even then when I do a "zoom extent" to show all the objects on the
> >renderer, it seems that the actor is there because the extent is bigger
> >that when I don't add the actor.
> >
> >I have tried not using vtkFollower and I have got the same result.
> >
> >I have tried other text objects (vtkTextActor) and nothing changes.
> >
> >This seems there is a problem with texts in Java. Perhaps is because I use
> >Linux. Have you got good results in Windows?
> >
> >I wish to know if somebody is using java and has got good results showing
> >texts in Linux.
> >
> >Thanks.
> >
> >
> >
> >
>
--
----------------------------------------------------------------------
Carlos Martínez Burgos | Instituto Tecnológico de Informática
Ingeniero Informático | Universidad Politécnica de Valencia
Tlf: +34 963877237 | Camí de Vera, S/N
cmarbur at iti.upv.es | 46071 Valencia - Spain
www.iti.upv.es/~cmarbur | www.iti.upv.es
----------------------------------------------------------------------
-------------- next part --------------
import java.awt.BorderLayout;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent;
import javax.swing.JFrame;
import javax.swing.JPanel;
import vtk.*;
public class Grid2 extends JPanel {
static {
System.loadLibrary("vtkHybridJava");
};
protected double x, y, z, w, h;
protected int xr, yr;
protected vtkPanel renderPane = new vtkPanel();
public Grid2() {
this(0, 0, 0, 10, 10, 10, 10);
}
public Grid2(double x, double y, double z, double w, double h, int xr, int yr) {
super();
this.x = x;
this.y = y;
this.z = z;
this.w = w;
this.h = h;
this.xr = xr;
this.yr = yr;
initGUI();
}
private void initGUI() {
addComponentListener(new ComponentAdapter() {
public void componentResized(ComponentEvent e) {
updateSize();
}
});
vtkRenderer renderer = renderPane.GetRenderer();
renderer.SetBackground(1, 1, 1);
vtkPlaneSource plane = new vtkPlaneSource();
plane.SetOrigin(x, y, z);
plane.SetPoint1(x + w, y, z);
plane.SetPoint2(x, y + h, z);
plane.SetXResolution(xr);
plane.SetYResolution(yr);
vtkPolyDataMapper mapper = new vtkPolyDataMapper();
mapper.SetInput(plane.GetOutput());
vtkActor actor = new vtkActor();
actor.SetMapper(mapper);
actor.GetProperty().SetRepresentationToWireframe();
actor.GetProperty().SetColor(0, 0, 0);
renderer.AddActor(actor);
for (int i = 0; i < xr; i++) {
String label = String.valueOf((char) ('A' + i));
double xt = x + (0.5 + i) * (w / xr);
double yt = y - (h / (2 * yr));
vtkVectorText text = new vtkVectorText();
text.SetText(label);
vtkPolyDataMapper textMapper = new vtkPolyDataMapper();
textMapper.SetInput(text.GetOutput());
vtkFollower textActor = new vtkFollower();
textActor.SetMapper(textMapper);
textActor.SetPosition(xt, yt, z);
textActor.GetProperty().SetColor(0, 0, 0);
textActor.SetCamera(renderer.GetActiveCamera());
renderer.AddActor(textActor);
}
for (int i = 0; i < yr; i++) {
String label = String.valueOf(i + 1);
double xt = x - (w / (2 * xr));
double yt = y + (0.5 + i) * (h / yr);
vtkVectorText text = new vtkVectorText();
text.SetText(label);
vtkPolyDataMapper textMapper = new vtkPolyDataMapper();
textMapper.SetInput(text.GetOutput());
vtkFollower textActor = new vtkFollower();
textActor.SetMapper(textMapper);
textActor.SetPosition(xt, yt, z);
textActor.GetProperty().SetColor(0, 0, 0);
textActor.SetCamera(renderer.GetActiveCamera());
renderer.AddActor(textActor);
}
add(renderPane);
}
private void updateSize() {
renderPane.setSize(getWidth(), getHeight());
}
public static void main(String[] args) {
JFrame f = new JFrame("Grid test");
f.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
f.getContentPane().add(new Grid2());
f.pack();
f.setVisible(true);
}
}
-------------- next part --------------
import java.awt.BorderLayout;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent;
import javax.swing.JFrame;
import javax.swing.JPanel;
import vtk.*;
public class Grid1 extends JPanel {
static {
System.loadLibrary("vtkHybridJava");
};
protected double x, y, z, w, h;
protected int xr, yr;
protected vtkPanel renderPane = new vtkPanel();
public Grid1() {
this(0, 0, 0, 10, 10, 10, 10);
}
public Grid1(double x, double y, double z, double w, double h, int xr, int yr) {
super();
this.x = x;
this.y = y;
this.z = z;
this.w = w;
this.h = h;
this.xr = xr;
this.yr = yr;
initGUI();
}
private void initGUI() {
addComponentListener(new ComponentAdapter() {
public void componentResized(ComponentEvent e) {
updateSize();
}
});
vtkRenderer renderer = renderPane.GetRenderer();
renderer.SetBackground(1, 1, 1);
vtkPlaneSource plane = new vtkPlaneSource();
plane.SetOrigin(x, y, z);
plane.SetPoint1(x + w, y, z);
plane.SetPoint2(x, y + h, z);
plane.SetXResolution(xr);
plane.SetYResolution(yr);
vtkPolyDataMapper mapper = new vtkPolyDataMapper();
mapper.SetInput(plane.GetOutput());
vtkActor actor = new vtkActor();
actor.SetMapper(mapper);
actor.GetProperty().SetRepresentationToWireframe();
actor.GetProperty().SetColor(0, 0, 0);
renderer.AddActor(actor);
for (int i = 0; i < xr; i++) {
double xs = x + (0.5 + i) * (w / xr);
double ys = y - (h / (2 * yr));
double r = 0.1;
vtkSphereSource sphere = new vtkSphereSource();
sphere.SetCenter(xs, ys, z);
sphere.SetRadius(r);
vtkPolyDataMapper sphereMapper = new vtkPolyDataMapper();
sphereMapper.SetInput(sphere.GetOutput());
vtkActor sphereActor = new vtkActor();
sphereActor.SetMapper(sphereMapper);
sphereActor.GetProperty().SetColor(0, 0, 0);
renderer.AddActor(sphereActor);
}
for (int i = 0; i < yr; i++) {
double xs = x - (w / (2 * xr));
double ys = y + (0.5 + i) * (h / yr);
double r = 0.1;
vtkSphereSource sphere = new vtkSphereSource();
sphere.SetCenter(xs, ys, z);
sphere.SetRadius(r);
vtkPolyDataMapper sphereMapper = new vtkPolyDataMapper();
sphereMapper.SetInput(sphere.GetOutput());
vtkActor sphereActor = new vtkActor();
sphereActor.SetMapper(sphereMapper);
sphereActor.GetProperty().SetColor(0, 0, 0);
renderer.AddActor(sphereActor);
}
add(renderPane);
}
private void updateSize() {
renderPane.setSize(getWidth(), getHeight());
}
public static void main(String[] args) {
JFrame f = new JFrame("Grid test");
f.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
f.getContentPane().add(new Grid1(), BorderLayout.CENTER);
f.pack();
f.setVisible(true);
}
}
More information about the vtkusers
mailing list