View Javadoc
1 /***************************************************************************** 2 * Virtual Mockup for Machine Vision 3 * Copyright (C) 2001-2003 Fabio R. de Miranda, Joćo E. Kogler Jr., 4 * Carlos S. Santos. 5 * Virtual Mockup for Machine Vision Project funded by SENAC-SP 6 * 7 * Permission is granted to redistribute and/or modify this 8 * software under the terms of the GNU Lesser General Public 9 * License as published by the Free Software Foundation; either 10 * version 2.1 of the License, or (at your option) any later version. 11 * 12 * This software is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 * Lesser General Public License (http://www.gnu.org/copyleft/lesser.html) 16 * for more details. 17 * 18 *****************************************************************************/ 19 20 package camera3d; 21 22 import javax.media.j3d.Shape3D; 23 import javax.media.j3d.*; 24 import com.sun.j3d.*; 25 import com.sun.j3d.utils.universe.*; 26 import com.sun.j3d.utils.behaviors.keyboard.*; 27 import javax.swing.*; 28 import javax.vecmath.*; 29 import java.awt.*; 30 //import camera3d.HelpingGrid; 31 32 33 /*** 34 * This is an copy of camera3d.test.NodeTester. Created with the sole purpose of 35 * debugging the ActiveX component.<br> 36 * An utility class to help with debugging of scene graphs. It encapsulates the basic 37 * Java3D and GUI structures, providing an access point for plugging in new nodes. 38 * 39 * @author Fabio Roberto de Miranda, Carlos da Silva dos Santos 40 */ 41 public class DummyApp { 42 43 //private Node node; 44 private TransformGroup tGroup; 45 private Canvas3D canvas3d; 46 private BranchGroup bg; 47 private JFrame frame; 48 private Background back; 49 private SimpleUniverse su; 50 51 /*** 52 * Creates a new DummyApp, assembling its scene graph. 53 */ 54 public DummyApp(){ 55 assembleGraph(); 56 frame = new JFrame(); 57 frame.getContentPane().add(canvas3d); 58 frame.setSize(300,300); 59 frame.setVisible(true); 60 frame.setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); 61 } 62 63 /*** 64 * Returns the TransformGroup under which are attached the new Nodes. 65 */ 66 /* 67 public TransformGroup getNodeTG(){ 68 return tGroup; 69 }*/ 70 71 /*** 72 * 73 */ 74 public BranchGroup getRootBG(){ 75 return this.bg; 76 } 77 78 public Canvas3D getCanvas3D(){ 79 return this.canvas3d; 80 } 81 82 public void cleanup(){ 83 su.cleanup(); 84 } 85 86 public JFrame getFrame(){ 87 return this.frame; 88 } 89 90 /*** 91 * Adds a node to the scene graph 92 */ 93 /* 94 public void add(Node n){ 95 BranchGroup bG = new BranchGroup(); 96 bG.addChild(n); 97 tGroup.addChild(bG); 98 }*/ 99 100 /* 101 public void setBackgroundColor(Color3f color){ 102 back.setColor(color); 103 }*/ 104 105 /*** 106 * Creates the java 3D basic structure. 107 */ 108 void assembleGraph() { 109 GraphicsConfigTemplate3D template = new GraphicsConfigTemplate3D(); 110 canvas3d = new Canvas3D(GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getBestConfiguration( template )); 111 su = new SimpleUniverse(canvas3d); 112 113 su.getViewingPlatform().setNominalViewingTransform(); 114 115 tGroup = new TransformGroup(); 116 tGroup.setCapability(Group.ALLOW_CHILDREN_WRITE); 117 tGroup.setCapability(Group.ALLOW_CHILDREN_READ); 118 tGroup.setCapability(Group.ALLOW_CHILDREN_EXTEND); 119 tGroup.setCapability(Node.ENABLE_PICK_REPORTING); 120 tGroup.setCapability(Node.ALLOW_BOUNDS_READ); 121 tGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_READ); 122 tGroup.setCapability(Node.ALLOW_LOCAL_TO_VWORLD_READ); 123 tGroup.setPickable(true); 124 125 int xGrids = 100; 126 int zGrids = 100; 127 System.out.println("grids: ("+xGrids+","+zGrids+")"); 128 Transform3D tempT3D = new Transform3D(); 129 tempT3D.set(new Vector3d(-10.0 ,0.0 , 10.0)); 130 HelpingGrid grid = new HelpingGrid(tempT3D, xGrids, zGrids); 131 tGroup.addChild(grid); 132 133 bg = new BranchGroup(); 134 bg.setCapability(Group.ALLOW_CHILDREN_READ); 135 bg.setCapability(Group.ALLOW_CHILDREN_WRITE); 136 bg.setCapability(Group.ALLOW_CHILDREN_EXTEND); 137 bg.setCapability(Node.ALLOW_LOCAL_TO_VWORLD_READ); 138 bg.setCapability(Group.ENABLE_PICK_REPORTING); 139 bg.setCapability(Node.ALLOW_BOUNDS_READ); 140 bg.setCapability(BranchGroup.ALLOW_DETACH); 141 bg.setPickable(true); 142 TransformGroup vpTrans = su.getViewingPlatform().getViewPlatformTransform(); 143 144 KeyNavigatorBehavior keynav = new KeyNavigatorBehavior(vpTrans); 145 BoundingSphere bounds = new BoundingSphere(new Point3d(0.0,0.0,0.0),1000); 146 back = new Background(new Color3f(0.5f, 0.5f, 0.5f)); 147 back.setCapability(Background.ALLOW_COLOR_READ); 148 back.setCapability(Background.ALLOW_COLOR_WRITE); 149 back.setApplicationBounds(bounds); 150 bg.addChild(back); 151 keynav.setSchedulingBounds(bounds); 152 tGroup.addChild(keynav); 153 Color3f white = new Color3f(1.0f,1.0f,1.0f); 154 Point3f center = new Point3f(0.0f, 0.0f, 0.0f); 155 Point3f attenuation = new Point3f(0.1f,0.1f,0.1f); 156 PointLight light = new PointLight(true, white, center, attenuation); 157 tGroup.addChild(light); 158 159 bg.addChild(tGroup); 160 su.getLocale().addBranchGraph(bg); 161 } 162 163 }

This page was automatically generated by Maven