Hi,
I try to plot a title on a DisplayImplJ3D. So I take the
DisplayRendererJ3D, the VisADCanvasJ3D, to finally find the
GraphicsContext3D. I found part of code from DisplayRendererJ3D to
calculate the point of vision.
But my code block when I try to use the GraphicsContext3D...
I dont know why ?
Is there a more simple method to plot title on a DisplayimplJ3D ?
And If not where are my mistakes ???
Thanks
-Sylvain-
...
// After creating the Display and associate all the maps and references
DisplayRendererJ3D disp_rend = (DisplayRendererJ3D)
display.getDisplayRenderer();
VisADCanvasJ3D canvas = disp_rend.getCanvas();
GraphicsContext3D graphics = canvas.getGraphicsContext3D();
// The GraphicsContext3D is not null but
// freeze with some methods (for exemple :setAppearence)
Point3d position1 = new Point3d();
Point3d position2 = new Point3d();
Point3d position3 = new Point3d();
canvas.getPixelLocationInImagePlate(1, 10, position1);
canvas.getPixelLocationInImagePlate(10, 10, position2);
canvas.getPixelLocationInImagePlate(1, 1, position3);
if (display != null && display.getGraphicsModeControl() != null)
{
// hack to move text closer to eye
if (display.getGraphicsModeControl().getProjectionPolicy() =
View.PERSPECTIVE_PROJECTION)
{
Point3d left_eye = new Point3d();
Point3d right_eye = new Point3d();
canvas.getLeftEyeInImagePlate(left_eye);
canvas.getRightEyeInImagePlate(right_eye);
Point3d eye = new Point3d((left_eye.x +
right_eye.x)/2.0,
(left_eye.y +
right_eye.y)/2.0,
(left_eye.z + right_eye.z)/2.0);
double alpha = 0.3;
position1.x = alpha * position1.x + (1.0 - alpha) *
eye.x;
position1.y = alpha * position1.y + (1.0 - alpha) *
eye.y;
position1.z = alpha * position1.z + (1.0 - alpha) *
eye.z;
position2.x = alpha * position2.x + (1.0 - alpha) *
eye.x;
position2.y = alpha * position2.y + (1.0 - alpha) *
eye.y;
position2.z = alpha * position2.z + (1.0 - alpha) *
eye.z;
position3.x = alpha * position3.x + (1.0 - alpha) *
eye.x;
position3.y = alpha * position3.y + (1.0 - alpha) *
eye.y;
position3.z = alpha * position3.z + (1.0 - alpha) *
eye.z;
}
}
// end of hack to move text closer to eye
Transform3D t = new Transform3D();
canvas.getImagePlateToVworld(t);
t.transform(position1);
t.transform(position2);
t.transform(position3);
double[] start = {(double) position1.x,
(double) position1.y,
(double) position1.z};
double[] base = {(double) (position2.x - position1.x),
(double) (position2.y - position1.y),
(double) (position2.z - position1.z)};
double[] up = {(double) (position3.x - position1.x),
(double) (position3.y - position1.y),
(double) (position3.z - position1.z)};
try
{
double[] startl = {(double) position3.x,
(double) -position3.y,
(double) position3.z};
VisADLineArray array
PlotText.render_label(opt.title, startl, base, up, false);
graphics.draw(((DisplayImplJ3D) display).makeGeometry(array));
// The code block here and nothing is drawn...
}
...