001: /*
002: *
003: * Copyright (c) 2000 Silvere Martin-Michiellot All Rights Reserved.
004: *
005: * Silvere Martin-Michiellot grants you ("Licensee") a non-exclusive,
006: * royalty free, license to use, modify and redistribute this
007: * software in source and binary code form,
008: * provided that i) this copyright notice and license appear on all copies of
009: * the software; and ii) Licensee does not utilize the software in a manner
010: * which is disparaging to Silvere Martin-Michiellot.
011: *
012: * This software is provided "AS IS," without a warranty of any kind. ALL
013: * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING ANY
014: * IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
015: * NON-INFRINGEMENT, ARE HEREBY EXCLUDED. Silvere Martin-Michiellot
016: * AND ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES
017: * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING
018: * OR DISTRIBUTING THE SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL
019: * Silvere Martin-Michiellot OR ITS LICENSORS BE LIABLE
020: * FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT,
021: * INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER
022: * CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF
023: * OR INABILITY TO USE SOFTWARE, EVEN IF Silvere Martin-Michiellot HAS BEEN
024: * ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
025: *
026: * This software is not designed or intended for use in on-line control of
027: * aircraft, air traffic, aircraft navigation or aircraft communications; or in
028: * the design, construction, operation or maintenance of any nuclear
029: * facility. Licensee represents and warrants that it will not use or
030: * redistribute the Software for such purposes.
031: *
032: * @Author: Silvere Martin-Michiellot
033: *
034: */
035:
036: package com.db.layers.underlay;
037:
038: import javax.media.*;
039: import javax.media.format.*;
040: import javax.media.control.*;
041: import java.awt.*;
042: import java.awt.event.*;
043: import java.io.File;
044: import javax.swing.*;
045: import javax.media.j3d.*;
046: import com.sun.j3d.utils.universe.SimpleUniverse;
047: import com.sun.j3d.utils.geometry.Cylinder;
048:
049: /*
050: * This is the demo program to render live video and use it as a background to overlay 3D.
051: * (Therefore this is underlayed in regard to the 3D surface)
052: */
053:
054: public class DemoJMFULVC extends JFrame implements ActionListener {
055:
056: private JMenuItem quitItem;
057:
058: private TransparentCanvas3D transparentCanvas3D;
059:
060: private SimpleUniverse simpleUniverse;
061:
062: private class AppPanel extends JPanel {
063:
064: public BranchGroup createSceneGraph(String args[]) {
065: // Create the root of the branch graph
066:
067: BranchGroup objRoot;
068:
069: objRoot = new BranchGroup();
070: //this is the place you have to put your code to
071: //DISPLAY SOMETHING in the Canvas3D
072:
073: //create a new appearance on a surface
074: Appearance appearance = new Appearance();
075: Cylinder cyl = new Cylinder(0.5f, 2.0f, appearance);
076: objRoot.addChild(cyl);
077:
078: return objRoot;
079:
080: }
081:
082: // Create the Canvas3D (both on-screen and off-screen)
083: private void createCanvas3D(String[] args) {
084:
085: String url = null;
086: boolean dc = true;
087: LiveDataSource liveDataSource;
088:
089: // Create Canvas3D
090: GraphicsConfiguration config =
091: SimpleUniverse.getPreferredConfiguration();
092:
093: transparentCanvas3D = new TransparentCanvas3D(config);
094: transparentCanvas3D.setSize(600, 450);
095:
096: // Create a simple scene and attach it to the virtual universe
097: BranchGroup scene = createSceneGraph(args);
098: simpleUniverse = new SimpleUniverse(canvas3D);
099: // This will move the ViewPlatform back a bit so the
100: // objects in the scene can be viewed.
101: simpleUniverse.getViewingPlatform().setNominalViewingTransform();
102: simpleUniverse.addBranchGraph(scene);
103:
104: setLayout(new BorderLayout());
105:
106: liveDataSource = new LiveDataSource();
107: //get input from camera
108: Capturer capturer;
109: CaptureDeviceInfo audioCapturedeviceinfo;
110: CaptureDeviceInfo videoCapturedeviceinfo;
111: AudioFormat audioFormat;
112: VideoFormat videoFormat;
113:
114: capturer = new Capturer();
115:
116: audioCapturedeviceinfo = (CaptureDeviceInfo)capturer.getAudioDevices().elementAt(0);
117: audioFormat = audioCapturedeviceinfo.getFormats()[0];
118: videoCapturedeviceinfo = (CaptureDeviceInfo)capturer.getVideoDevices().elementAt(0);
119: videoFormat = videoCapturedeviceinfo.getFormats()[0];
120: capturer.captureMedia(audioCapturedeviceinfo, audioFormat, videoCapturedeviceinfo, videoFormat);
121:
122: //get 3D image from canvas3D
123: //xor the two flows together
124: //paint the resulting pseudo canvas3D
125: XXXXXXXXXXXXXXXXXXXXXXXXX
126:
127: System.out.println("video processor start");
128:
129: }
130:
131: private AppPanel(String args[]) {
132: setLayout(new BorderLayout());
133:
134: // Create Canvas3D and scene graph
135: createCanvas3D(args);
136: add("Center", canvas3D);
137: }
138:
139: }
140:
141: public void actionPerformed(ActionEvent event) {
142:
143: Object target = event.getSource();
144:
145: if (target == quitItem) {
146: simpleUniverse.removeAllLocales();
147: System.exit(0);
148: }
149:
150: }
151:
152: private JMenuBar createMenuBar() {
153:
154: JMenuBar menuBar = new JMenuBar();
155: JMenu fileMenu = new JMenu("File");
156: quitItem = new JMenuItem("Quit");
157: quitItem.addActionListener(this );
158: fileMenu.add(quitItem);
159: menuBar.add(fileMenu);
160:
161: return menuBar;
162:
163: }
164:
165: private DemoJMFULVC(String args[]) {
166:
167: this .setTitle("Canvas3D Video Test");
168:
169: // Create and initialize menu bar
170: JPopupMenu.setDefaultLightWeightPopupEnabled(false);
171: this .setJMenuBar(createMenuBar());
172:
173: // Handle the close event
174: this .addWindowListener(new WindowAdapter() {
175: public void windowClosing(WindowEvent winEvent) {
176: System.exit(0);
177: }
178: });
179:
180: // Add main panel to top-level frame and make it visible
181: this .getContentPane().add(new AppPanel(args));
182: this .pack();
183: this .setVisible(true);
184:
185: }
186:
187: public static void main(String[] args) {
188:
189: new DemoJMFULVC(args);
190:
191: }
192:
193: public static void printUsage() {
194:
195: System.out.println("java DemoJMFULVC");
196:
197: }
198:
199: }
|