Skip to main content

Stereo vision interlaced or page flipping by j3d. Help me!

17 replies [Last post]
raffaele1983
Offline
Joined: 2009-06-26

Hi all,
I'm a student of University of Federico II, Naples (ITALY).
Should I build an application that transforms the image left and right image (taken from two cameras) in the stereoscopic image. I would like to have a single image which should give the feeling of depth.
I understand that the techniques used are the technique of interlace and page flipping.
If someone can give me some information on how to transform the two images in stereoscopic image.
Can I implement this kind of stereoscopic vision with java 3d?
My graphics card is a Nvidia Quadro FX 5500 and I use a CRT monitor on which I would like to see the stereoscopic image. I use LCD shutter glasses and an emitter synchronized with the monitor.
I have no experience with stereoscopy.
I hope someone can help me.
I'm sorry for my English.
Thanks very much for any help.

The Best Regards

Raffaele Califano

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
richie_chr
Offline
Joined: 2010-10-14

my code:

import java.applet.Applet;
import java.awt.BorderLayout;
import java.awt.GraphicsConfiguration;
import java.io.FileNotFoundException;
import java.net.MalformedURLException;
import java.net.URL;

import javax.media.j3d.Alpha;
import javax.media.j3d.AmbientLight;
import javax.media.j3d.Background;
import javax.media.j3d.BoundingSphere;
import javax.media.j3d.BranchGroup;
import javax.media.j3d.Canvas3D;
import javax.media.j3d.DirectionalLight;
import javax.media.j3d.RotationInterpolator;
import javax.media.j3d.Transform3D;
import javax.media.j3d.TransformGroup;
import javax.vecmath.Color3f;
import javax.vecmath.Point3d;
import javax.vecmath.Vector3f;

import com.sun.j3d.loaders.IncorrectFormatException;
import com.sun.j3d.loaders.ParsingErrorException;
import com.sun.j3d.loaders.Scene;
import com.sun.j3d.loaders.objectfile.ObjectFile;
import com.sun.j3d.utils.applet.MainFrame;
import com.sun.j3d.utils.behaviors.vp.OrbitBehavior;
import com.sun.j3d.utils.universe.PlatformGeometry;
import com.sun.j3d.utils.universe.SimpleUniverse;
import com.sun.j3d.utils.universe.ViewingPlatform;

public class ObjLoad extends Applet {

private boolean spin = false;

private boolean noTriangulate = false;

private boolean noStripify = false;

private double creaseAngle = 60.0;

private URL filename = null;

private SimpleUniverse u;

private BoundingSphere bounds;

public BranchGroup createSceneGraph() {
// Create the root of the branch graph
BranchGroup objRoot = new BranchGroup();

// Create a Transformgroup to scale all objects so they
// appear in the scene.
TransformGroup objScale = new TransformGroup();
Transform3D t3d = new Transform3D();
t3d.setScale(0.7);
objScale.setTransform(t3d);
objRoot.addChild(objScale);

// Create the transform group node and initialize it to the
// identity. Enable the TRANSFORM_WRITE capability so that
// our behavior code can modify it at runtime. Add it to the
// root of the subgraph.
TransformGroup objTrans = new TransformGroup();
objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
objScale.addChild(objTrans);

int flags = ObjectFile.RESIZE;
if (!noTriangulate)
flags |= ObjectFile.TRIANGULATE;
if (!noStripify)
flags |= ObjectFile.STRIPIFY;
ObjectFile f = new ObjectFile(flags,
(float) (creaseAngle * Math.PI / 180.0));
Scene s = null;
try {
s = f.load(filename);
} catch (FileNotFoundException e) {
System.err.println(e);
System.exit(1);
} catch (ParsingErrorException e) {
System.err.println(e);
System.exit(1);
} catch (IncorrectFormatException e) {
System.err.println(e);
System.exit(1);
}

objTrans.addChild(s.getSceneGroup());

bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0);

if (spin) {
Transform3D yAxis = new Transform3D();
Alpha rotationAlpha = new Alpha(-1, Alpha.INCREASING_ENABLE, 0, 0,
4000, 0, 0, 0, 0, 0);

RotationInterpolator rotator = new RotationInterpolator(
rotationAlpha, objTrans, yAxis, 0.0f,
(float) Math.PI * 2.0f);
rotator.setSchedulingBounds(bounds);
objTrans.addChild(rotator);
}

// Set up the background
Color3f bgColor = new Color3f(0.05f, 0.05f, 0.5f);
Background bgNode = new Background(bgColor);
bgNode.setApplicationBounds(bounds);
objRoot.addChild(bgNode);

return objRoot;
}

private void usage() {
System.out
.println("Usage: java ObjLoad [-s] [-n] [-t] [-c degrees] <.obj file>");
System.out.println(" -s Spin (no user interaction)");
System.out.println(" -n No triangulation");
System.out.println(" -t No stripification");
System.out
.println(" -c Set crease angle for normal generation (default is 60 without");
System.out
.println(" smoothing group info, otherwise 180 within smoothing groups)");
System.exit(0);
} // End of usage

public void init() {
if (filename == null) {
// Applet
try {
URL path = getCodeBase();
filename = new URL(path.toString() + "./Bedroom.obj");
} catch (MalformedURLException e) {
System.err.println(e);
System.exit(1);
}
}

setLayout(new BorderLayout());
GraphicsConfiguration config = SimpleUniverse
.getPreferredConfiguration();

Canvas3D c = new Canvas3D(config);
add("Center", c);

// Create a simple scene and attach it to the virtual universe
BranchGroup scene = createSceneGraph();
u = new SimpleUniverse(c);

// add mouse behaviors to the ViewingPlatform
ViewingPlatform viewingPlatform = u.getViewingPlatform();

PlatformGeometry pg = new PlatformGeometry();

// Set up the ambient light
Color3f ambientColor = new Color3f(0.1f, 0.1f, 0.1f);
AmbientLight ambientLightNode = new AmbientLight(ambientColor);
ambientLightNode.setInfluencingBounds(bounds);
pg.addChild(ambientLightNode);

// Set up the directional lights
Color3f light1Color = new Color3f(1.0f, 1.0f, 0.9f);
Vector3f light1Direction = new Vector3f(1.0f, 1.0f, 1.0f);
Color3f light2Color = new Color3f(1.0f, 1.0f, 1.0f);
Vector3f light2Direction = new Vector3f(-1.0f, -1.0f, -1.0f);

DirectionalLight light1 = new DirectionalLight(light1Color,
light1Direction);
light1.setInfluencingBounds(bounds);
pg.addChild(light1);

DirectionalLight light2 = new DirectionalLight(light2Color,
light2Direction);
light2.setInfluencingBounds(bounds);
pg.addChild(light2);

viewingPlatform.setPlatformGeometry(pg);

// This will move the ViewPlatform back a bit so the
// objects in the scene can be viewed.
viewingPlatform.setNominalViewingTransform();

if (!spin) {
OrbitBehavior orbit = new OrbitBehavior(c,
OrbitBehavior.REVERSE_ALL);
BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0,
0.0), 100.0);
orbit.setSchedulingBounds(bounds);
viewingPlatform.setViewPlatformBehavior(orbit);
}

u.addBranchGraph(scene);
}

// Caled if running as a program
public ObjLoad(String[] args) {
if (args.length != 0) {
for (int i = 0; i < args.length; i++) {
if (args[i].startsWith("-")) {
if (args[i].equals("-s")) {
spin = true;
} else if (args[i].equals("-n")) {
noTriangulate = true;
} else if (args[i].equals("-t")) {
noStripify = true;
} else if (args[i].equals("-c")) {
if (i < args.length - 1) {
creaseAngle = (new Double(args[++i])).doubleValue();
} else
usage();
} else {
usage();
}
} else {
try {
if ((args[i].indexOf("file:") == 0)
|| (args[i].indexOf("http") == 0)) {
filename = new URL(args[i]);
} else if (args[i].charAt(0) != '/') {
filename = new URL("file:./" + args[i]);
} else {
filename = new URL("file:" + args[i]);
}
} catch (MalformedURLException e) {
System.err.println(e);
System.exit(1);
}
}
}
}
}

// Running as an applet
public ObjLoad() {
}

public void destroy() {
u.cleanup();
}

//
// The following allows ObjLoad to be run as an application
// as well as an applet
//
public static void main(String[] args) {
new MainFrame(new ObjLoad(args), 700, 700);
}
}

richie_chr
Offline
Joined: 2010-10-14

Hi raffaele,
I am richards, a student from india. i am doing a project on java 3D to create a virtual environment in 3d for interactive learning. i am new to j3D. i have modelled my 3D objects in Maya and got it inside j3D using obj loader. I want to render my scene in 3D. can you please help.
My code:

import java.applet.Applet;
import java.awt.BorderLayout;
import java.awt.GraphicsConfiguration;
import java.io.FileNotFoundException;
import java.net.MalformedURLException;
import java.net.URL;

import javax.media.j3d.Alpha;
import javax.media.j3d.AmbientLight;
import javax.media.j3d.Background;
import javax.media.j3d.BoundingSphere;
import javax.media.j3d.BranchGroup;
import javax.media.j3d.Canvas3D;
import javax.media.j3d.DirectionalLight;
import javax.media.j3d.RotationInterpolator;
import javax.media.j3d.Transform3D;
import javax.media.j3d.TransformGroup;
import javax.vecmath.Color3f;
import javax.vecmath.Point3d;
import javax.vecmath.Vector3f;

import com.sun.j3d.loaders.IncorrectFormatException;
import com.sun.j3d.loaders.ParsingErrorException;
import com.sun.j3d.loaders.Scene;
import com.sun.j3d.loaders.objectfile.ObjectFile;
import com.sun.j3d.utils.applet.MainFrame;
import com.sun.j3d.utils.behaviors.vp.OrbitBehavior;
import com.sun.j3d.utils.universe.PlatformGeometry;
import com.sun.j3d.utils.universe.SimpleUniverse;
import com.sun.j3d.utils.universe.ViewingPlatform;

public class ObjLoad extends Applet {

private boolean spin = false;

private boolean noTriangulate = false;

private boolean noStripify = false;

private double creaseAngle = 60.0;

private URL filename = null;

private SimpleUniverse u;

private BoundingSphere bounds;

public BranchGroup createSceneGraph() {
// Create the root of the branch graph
BranchGroup objRoot = new BranchGroup();

// Create a Transformgroup to scale all objects so they
// appear in the scene.
TransformGroup objScale = new TransformGroup();
Transform3D t3d = new Transform3D();
t3d.setScale(0.7);
objScale.setTransform(t3d);
objRoot.addChild(objScale);

// Create the transform group node and initialize it to the
// identity. Enable the TRANSFORM_WRITE capability so that
// our behavior code can modify it at runtime. Add it to the
// root of the subgraph.
TransformGroup objTrans = new TransformGroup();
objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
objScale.addChild(objTrans);

int flags = ObjectFile.RESIZE;
if (!noTriangulate)
flags |= ObjectFile.TRIANGULATE;
if (!noStripify)
flags |= ObjectFile.STRIPIFY;
ObjectFile f = new ObjectFile(flags,
(float) (creaseAngle * Math.PI / 180.0));
Scene s = null;
try {
s = f.load(filename);
} catch (FileNotFoundException e) {
System.err.println(e);
System.exit(1);
} catch (ParsingErrorException e) {
System.err.println(e);
System.exit(1);
} catch (IncorrectFormatException e) {
System.err.println(e);
System.exit(1);
}

objTrans.addChild(s.getSceneGroup());

bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0);

if (spin) {
Transform3D yAxis = new Transform3D();
Alpha rotationAlpha = new Alpha(-1, Alpha.INCREASING_ENABLE, 0, 0,
4000, 0, 0, 0, 0, 0);

RotationInterpolator rotator = new RotationInterpolator(
rotationAlpha, objTrans, yAxis, 0.0f,
(float) Math.PI * 2.0f);
rotator.setSchedulingBounds(bounds);
objTrans.addChild(rotator);
}

// Set up the background
Color3f bgColor = new Color3f(0.05f, 0.05f, 0.5f);
Background bgNode = new Background(bgColor);
bgNode.setApplicationBounds(bounds);
objRoot.addChild(bgNode);

return objRoot;
}

private void usage() {
System.out
.println("Usage: java ObjLoad [-s] [-n] [-t] [-c degrees] <.obj file>");
System.out.println(" -s Spin (no user interaction)");
System.out.println(" -n No triangulation");
System.out.println(" -t No stripification");
System.out
.println(" -c Set crease angle for normal generation (default is 60 without");
System.out
.println(" smoothing group info, otherwise 180 within smoothing groups)");
System.exit(0);
} // End of usage

public void init() {
if (filename == null) {
// Applet
try {
URL path = getCodeBase();
filename = new URL(path.toString() + "./Bedroom.obj");
} catch (MalformedURLException e) {
System.err.println(e);
System.exit(1);
}
}

setLayout(new BorderLayout());
GraphicsConfiguration config = SimpleUniverse
.getPreferredConfiguration();

Canvas3D c = new Canvas3D(config);
add("Center", c);

// Create a simple scene and attach it to the virtual universe
BranchGroup scene = createSceneGraph();
u = new SimpleUniverse(c);

// add mouse behaviors to the ViewingPlatform
ViewingPlatform viewingPlatform = u.getViewingPlatform();

PlatformGeometry pg = new PlatformGeometry();

// Set up the ambient light
Color3f ambientColor = new Color3f(0.1f, 0.1f, 0.1f);
AmbientLight ambientLightNode = new AmbientLight(ambientColor);
ambientLightNode.setInfluencingBounds(bounds);
pg.addChild(ambientLightNode);

// Set up the directional lights
Color3f light1Color = new Color3f(1.0f, 1.0f, 0.9f);
Vector3f light1Direction = new Vector3f(1.0f, 1.0f, 1.0f);
Color3f light2Color = new Color3f(1.0f, 1.0f, 1.0f);
Vector3f light2Direction = new Vector3f(-1.0f, -1.0f, -1.0f);

DirectionalLight light1 = new DirectionalLight(light1Color,
light1Direction);
light1.setInfluencingBounds(bounds);
pg.addChild(light1);

DirectionalLight light2 = new DirectionalLight(light2Color,
light2Direction);
light2.setInfluencingBounds(bounds);
pg.addChild(light2);

viewingPlatform.setPlatformGeometry(pg);

// This will move the ViewPlatform back a bit so the
// objects in the scene can be viewed.
viewingPlatform.setNominalViewingTransform();

if (!spin) {
OrbitBehavior orbit = new OrbitBehavior(c,
OrbitBehavior.REVERSE_ALL);
BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0,
0.0), 100.0);
orbit.setSchedulingBounds(bounds);
viewingPlatform.setViewPlatformBehavior(orbit);
}

u.addBranchGraph(scene);
}

// Caled if running as a program
public ObjLoad(String[] args) {
if (args.length != 0) {
for (int i = 0; i < args.length; i++) {
if (args[i].startsWith("-")) {
if (args[i].equals("-s")) {
spin = true;
} else if (args[i].equals("-n")) {
noTriangulate = true;
} else if (args[i].equals("-t")) {
noStripify = true;
} else if (args[i].equals("-c")) {
if (i < args.length - 1) {
creaseAngle = (new Double(args[++i])).doubleValue();
} else
usage();
} else {
usage();
}
} else {
try {
if ((args[i].indexOf("file:") == 0)
|| (args[i].indexOf("http") == 0)) {
filename = new URL(args[i]);
} else if (args[i].charAt(0) != '/') {
filename = new URL("file:./" + args[i]);
} else {
filename = new URL("file:" + args[i]);
}
} catch (MalformedURLException e) {
System.err.println(e);
System.exit(1);
}
}
}
}
}

// Running as an applet
public ObjLoad() {
}

public void destroy() {
u.cleanup();
}

//
// The following allows ObjLoad to be run as an application
// as well as an applet
//
public static void main(String[] args) {
new MainFrame(new ObjLoad(args), 700, 700);
}
}

raffaele1983
Offline
Joined: 2009-06-26

Hi all,
page flipping run very well.
I swap the left and right image and the stereo visualization is splendid!
I enough changed my code by add this code:

[code]
canvas = new Canvas3D(config);
canvas.setLeftManualEyeInImagePlate(new Point3d(-0.033,0,0));
canvas.setRightManualEyeInImagePlate(new Point3d(0.033,0,0));
.....
[/code]

:-)

Message was edited by: raffaele1983

aces
Offline
Joined: 2003-07-17

(my previous post just disappeared. I 'll post it again, so sorry if appears twice.)

Use a NVidia Quadro class video card for Stereo.
Quadro allows windowed 3D stereo, as well on full screen mode.
Quadro FX 370 is entry model, and is not very expensive.

Use page flipping with shutter glasses.
DLP projetion *may* require inverting Left<->Right eye on video card driver control panel.

raffaele1983
Offline
Joined: 2009-06-26

Excuse me, but with java 3d is possible implement stereoscopic page flipping? I need of information or example code.

zesharp
Offline
Joined: 2006-12-21

>but with java 3d is possible implement stereoscopic page flipping?

Yes, of course ! Java3D uses OpenGL quad-buffer API for 3D stereo.
Quad buffer uses page flipping for switching left <-> right eye color buffer image.
Quad buffer stereo is available on professional OpenGL video cards as AMD/ATI FireGL and NVidia Quadro.

> I need of information or example code.

See below:
[code]

// create GraphConfig template for stereo
GraphicsConfigTemplate3D template = new GraphicsConfigTemplate3D();
// PREFERRED uses stereo, IFF available. If stereo is not available, it falls back to
// monoscopic view.
template.setStereo(GraphicsConfigTemplate3D.PREFERRED);

// check system
GraphicsConfiguration conf = GraphicsEnvironment
.getLocalGraphicsEnvironment()
.getDefaultScreenDevice()
.getBestConfiguration(template);

// check if conf is OK
if (conf == null){
throw new Exception("Graphics mode unsupported");
}

// create Canvas.
Canvas3D canvas = new Canvas3D( conf ) ;

[/code]

best luck ;)

raffaele1983
Offline
Joined: 2009-06-26

Hello zesharp,
thank you for your answer.
Your code is similar my. I know how enable stereo mode, but I don't know how to display the left and right image by page flipping.
My function doesn't work, it is:

[code]
public void render() {
if (gc == null) {
// Set up Graphics context
gc = canvas.getGraphicsContext3D();
gc.setAppearance(new Appearance());
gc.setBufferOverride(true);
}
gc.setStereoMode(GraphicsContext3D.STEREO_BOTH);
gc.clear();
if (g2d == null)
g2d = canvas.getGraphics2D();
gc.setStereoMode(GraphicsContext3D.STEREO_LEFT);
g2d.drawAndFlushImage(imageLeft, (xSize-imageLeft.getWidth())/2, (ySize-imageLeft.getHeight())/2, null);
gc.setStereoMode(GraphicsContext3D.STEREO_RIGHT);
g2d.drawAndFlushImage(imageRight, (xSize-imageLeft.getWidth())/2, (ySize-imageLeft.getHeight())/2, null);
gc.flush(true);
canvas.swap();
}
[/code]

Can you give me any suggestion?

zesharp
Offline
Joined: 2006-12-21

Hi !

For ordinary 3D stereo use you don't have to worry about overriding Canvas.
This is a straight forward operation:

1) create a Canvas with Stereo set as preferred;
2) call canvas3d.setStereoEnable(true) and your screen starts flicking stereo immediately;

Or are you trying to use java3D to show static 2D stereo images ?
I guess there are some demos of this, but must google it.

In this case, I guess you must override Canvas.renderField(int) method.
Please read Canvas3D javadocs :

[code]
The basic Java 3D stereo rendering loop, executed for each Canvas3D, is as follows:

clear canvas (both eyes)
call preRender() // user-supplied method
set left eye view
render opaque scene graph objects
call renderField(FIELD_LEFT) // user-supplied method
render transparent scene graph objects
set right eye view
render opaque scene graph objects again
call renderField(FIELD_RIGHT) // user-supplied method
render transparent scene graph objects again
call postRender() // user-supplied method
synchronize and swap buffers
call postSwap() // user-supplied method

[/code]

By the way, use a Nvidia Quadro . It save you a LOT of headache and pay itself in a couple of man-hours .

raffaele1983
Offline
Joined: 2009-06-26

Hi zesharp,
thank you for your answer.
I try to implement your second suggestion.
I will inform you about the resutl.
Thank you very much.

Raffaele

raffaele1983
Offline
Joined: 2009-06-26

I didn't resolve my problem...

zesharp
Offline
Joined: 2006-12-21

>>build an application that transforms the image left and right image (taken from two cameras) in the stereoscopic image. I would like to have a single image which should give the feeling of depth.

>I didn't resolve my problem...

What have you done, so far ?
Are those images static or is it a live shot from web cam ?

raffaele1983
Offline
Joined: 2009-06-26

Hi zesharp,
the images are static... I now resolved my problem but I must perform the application.
I see the stereo image with shutter glasses but when I leave from screen the image (in particular the widgets of the image that are in foreground) doesn't come out from screen.
I'm trying to set the left and right eye position. Do you suggest anything?
This my code (page flipping work very well)

[code]
import java.awt.Color;
import java.awt.GraphicsConfiguration;
import java.awt.GraphicsEnvironment;
import java.awt.Toolkit;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.image.BufferedImage;

import javax.media.j3d.Appearance;
import javax.media.j3d.Canvas3D;
import javax.media.j3d.GraphicsConfigTemplate3D;
import javax.media.j3d.GraphicsContext3D;
import javax.media.j3d.J3DGraphics2D;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.vecmath.Point3d;

import com.sun.j3d.utils.universe.SimpleUniverse;

public class StereoView2 extends JFrame implements Runnable {
private SimpleUniverse univ = null;
private Canvas3D canvas;
private GraphicsContext3D gc = null;
private J3DGraphics2D g2d = null;
private BufferedImage imageLeft = null;
private BufferedImage imageRight = null;
private int xSize = 0;
private int ySize = 0;
// Set this to true when the graphics card use shared z buffer
// in stereo mode.
public static String defaultSharedStereoZbuffer = Boolean.TRUE.toString();
private boolean sharedStereoZbuffer;
private boolean stereoSupport;

//
// Renders a single frame by clearing the canvas, drawing the
// geometry, and swapping the draw and display buffer.
//
public void render() {
if (gc == null) {
// Set up Graphics context
gc = canvas.getGraphicsContext3D();
gc.setAppearance(new Appearance());
gc.setBufferOverride(true);
}
if (stereoSupport) {
if (!sharedStereoZbuffer) {
gc.setStereoMode(GraphicsContext3D.STEREO_BOTH);
// This clear both left and right buffers, we
// must set STEREO_BOTH before it. Otherwise
// it only clear LEFT or RIGHT buffer unless
// this is invoke twice for each buffer.
gc.clear();
}
}
gc.clear();
if (g2d == null)
g2d = canvas.getGraphics2D();
gc.setStereoMode(GraphicsContext3D.STEREO_LEFT);
g2d.drawImage(imageLeft, (xSize-imageLeft.getWidth())/2, (ySize-imageLeft.getHeight())/2,
(xSize-imageLeft.getWidth())/2+imageLeft.getWidth(), (ySize-imageLeft.getHeight())/2+imageLeft.getHeight(),
0, 0, imageLeft.getWidth(), imageLeft.getHeight(), this);
System.out.println("sto visualizzando l'immagine sinistra");
g2d.flush(true);
gc.clear();
gc.setStereoMode(GraphicsContext3D.STEREO_RIGHT);
g2d.drawImage(imageRight, (xSize-imageRight.getWidth())/2, (ySize-imageRight.getHeight())/2,
(xSize-imageRight.getWidth())/2+imageRight.getWidth(), (ySize-imageRight.getHeight())/2+imageRight.getHeight(),
0, 0, imageRight.getWidth(), imageRight.getHeight(), this);
System.out.println("sto visualizzando l'immagine destra");
g2d.flush(true);
canvas.swap();
}

//
// Run method for our immediate mode rendering thread.
//
public void run() {
System.out.println("SterioView.run: starting main loop");
while (true) {
render();
//Thread.yield();
}
}

private void createUniverse() {
// Get the preferred graphics configuration for the default screen
GraphicsConfigTemplate3D gct = new GraphicsConfigTemplate3D();
gct.setStereo(GraphicsConfigTemplate3D.PREFERRED);
GraphicsConfiguration config =
GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getBestConfiguration(gct);
// Create a Canvas3D using the preferred configuration
canvas = new Canvas3D(config);
stereoSupport = canvas.getStereoAvailable();
if (stereoSupport)
{
System.out.println("This machine support stereo");
String str = System.getProperty("j3d.sharedstereozbuffer",
defaultSharedStereoZbuffer);
sharedStereoZbuffer = (new Boolean(str)).booleanValue();
canvas.setStereoEnable(true);
}
else
{
JOptionPane.showMessageDialog(null, "Stereo is not support","Attenzione",JOptionPane.WARNING_MESSAGE);
}

if (!canvas.getDoubleBufferAvailable())
{
System.out.println("Double buffer is not support !");
}
canvas.setBackground(Color.black);
canvas.addKeyListener(new KeyAdapter(){
public void keyPressed(KeyEvent e)
{
if (e.getKeyCode()==KeyEvent.VK_ESCAPE)
{
dispose();
}
}
});
canvas.stopRenderer();
// Create simple universe with view branch
univ = new SimpleUniverse(canvas);

// This will move the ViewPlatform back a bit so the
// objects in the scene can be viewed.
univ.getViewingPlatform().setNominalViewingTransform();

// Ensure at least 5 msec per frame (i.e., < 200Hz)
univ.getViewer().getView().setMinimumFrameCycleTime(5);
}

public StereoView2(BufferedImage imageLeft, BufferedImage imageRight) {
this.imageLeft = imageLeft;
this.imageRight = imageRight;
// Initialize the GUI components
initComponents();

// Create Canvas3D and SimpleUniverse; add canvas to JFrame
createUniverse();
this.add(canvas);

// Start a new thread that will continuously render
new Thread(this).start();
}

private void initComponents() {
this.setUndecorated(true);
Toolkit tk = Toolkit.getDefaultToolkit();
xSize = ((int) tk.getScreenSize().getWidth());
ySize = ((int) tk.getScreenSize().getHeight());
this.setSize(xSize,ySize);
this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
}
}

[/code]

Message was edited by: raffaele1983

Message was edited by: raffaele1983

runiter
Offline
Joined: 2007-09-22

The answer to your question can be found here:

http://forums.java.net/jive/thread.jspa?messageID=344437&#344437

raffaele1983
Offline
Joined: 2009-06-26

Hi ruinter,
thank you very much for your fast answer, I am very grateful.
But the my shutter glasses are not filter red/cyan and therefore I'm interest to stereo interlaced or pafge flipping. Excuse me if I was not precise.
I'm looking your link for information and I hope that it helps me.
If you have any information tell me also.
Tahnk you very much in advance.

Raffaele Califano

runiter
Offline
Joined: 2007-09-22

For shutter glasses it's even easier since Java3D has built-in mechanism for that. For example you can run the sample HelloUniverse in stereo mode by running it like this:

java -Dj3d.stereo=PREFERRED HelloUniverse

You can find more info about that here:

http://java3d.j3d.org/faq/stereo.html

raffaele1983
Offline
Joined: 2009-06-26

Excuse me if I am boring, but I'm looking for some examples to see a interlaced image in stereo mode.
I now enable the graphics card to display the stereo, but the interlaced image (constructed of rows of the left image and with the odd rows of the right image) not seen with stereo glasses, but I see it like without glasses.
This is my code, it is the class for stereo vision:
(The image is the interlaced image)

import java.awt.Color;
import java.awt.GraphicsConfiguration;
import java.awt.GraphicsEnvironment;
import java.awt.Toolkit;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.image.BufferedImage;

import javax.media.j3d.Appearance;
import javax.media.j3d.Canvas3D;
import javax.media.j3d.GraphicsConfigTemplate3D;
import javax.media.j3d.GraphicsContext3D;
import javax.media.j3d.J3DGraphics2D;
import javax.media.j3d.View;
import javax.swing.JFrame;
import javax.swing.JOptionPane;

import com.sun.j3d.utils.universe.SimpleUniverse;

public class StereoView extends JFrame implements Runnable {
private SimpleUniverse univ = null;
private Canvas3D canvas;
private GraphicsContext3D gc = null;
private J3DGraphics2D g2d = null;
private BufferedImage image3d = null;
private int xSize = 0;
private int ySize = 0;
// Set this to true when the graphics card use shared z buffer
// in stereo mode.
public static String defaultSharedStereoZbuffer = Boolean.TRUE.toString();
private boolean sharedStereoZbuffer;
private boolean stereoSupport;

//
// Renders a single frame by clearing the canvas, drawing the
// geometry, and swapping the draw and display buffer.
//
public void render() {
if (gc == null) {
// Set up Graphics context
gc = canvas.getGraphicsContext3D();
gc.setAppearance(new Appearance());
gc.setBufferOverride(true);
}
if (stereoSupport) {
if (!sharedStereoZbuffer) {
gc.setStereoMode(GraphicsContext3D.STEREO_BOTH);
// This clear both left and right buffers, we
// must set STEREO_BOTH before it. Otherwise
// it only clear LEFT or RIGHT buffer unless
// this is invoke twice for each buffer.
gc.clear();
}
}
gc.clear();
if (g2d == null)
g2d = canvas.getGraphics2D();
g2d.drawImage(image3d, (xSize-image3d.getWidth())/2, (ySize-image3d.getHeight())/2,
(xSize-image3d.getWidth())/2+image3d.getWidth(), (ySize-image3d.getHeight())/2+image3d.getHeight(),
0, 0, image3d.getWidth(), image3d.getHeight(), this);
g2d.flush(false);
canvas.swap();
}

//
// Run method for our immediate mode rendering thread.
//
public void run() {
System.out.println("SterioView.run: starting main loop");
while (true) {
render();
Thread.yield();
}
}

private void createUniverse() {
// Get the preferred graphics configuration for the default screen
GraphicsConfigTemplate3D gct = new GraphicsConfigTemplate3D();
gct.setStereo(GraphicsConfigTemplate3D.PREFERRED);
GraphicsConfiguration config =
GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getBestConfiguration(gct);
// Create a Canvas3D using the preferred configuration
canvas = new Canvas3D(config);
stereoSupport = canvas.getStereoAvailable();
if (stereoSupport)
{
System.out.println("This machine support stereo");
String str = System.getProperty("j3d.sharedstereozbuffer",
defaultSharedStereoZbuffer);
sharedStereoZbuffer = (new Boolean(str)).booleanValue();
}
else
{
JOptionPane.showMessageDialog(null, "Stereo is not support","Attenzione",JOptionPane.WARNING_MESSAGE);
}

if (!canvas.getDoubleBufferAvailable())
{
System.out.println("Double buffer is not support !");
}
canvas.setBackground(Color.black);
canvas.addKeyListener(new KeyAdapter(){
public void keyPressed(KeyEvent e)
{
if (e.getKeyCode()==KeyEvent.VK_ESCAPE)
{
dispose();
}
}
});
canvas.stopRenderer();
// Create simple universe with view branch
univ = new SimpleUniverse(canvas);

// This will move the ViewPlatform back a bit so the
// objects in the scene can be viewed.
univ.getViewingPlatform().setNominalViewingTransform();

// Ensure at least 5 msec per frame (i.e., < 200Hz)
univ.getViewer().getView().setMinimumFrameCycleTime(5);
}

public StereoView(BufferedImage image3d) {
this.image3d = image3d;
// Initialize the GUI components
initComponents();

// Create Canvas3D and SimpleUniverse; add canvas to JFrame
createUniverse();
this.add(canvas);

// Start a new thread that will continuously render
new Thread(this).start();
}

private void initComponents() {
this.setUndecorated(true);
Toolkit tk = Toolkit.getDefaultToolkit();
xSize = ((int) tk.getScreenSize().getWidth());
ySize = ((int) tk.getScreenSize().getHeight());
this.setSize(xSize,ySize);
this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
}
}

Can you suggest me any trick?

Message was edited by: raffaele1983

runiter
Offline
Joined: 2007-09-22

I wouldn't be able to help you much on this topic since I never done stereo myself and don't have access to stereo glasses either.