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.gizmo; 21 22 23 24 import javax.vecmath.*; 25 import javax.media.j3d.*; 26 import camera3d.test.NodeTester; 27 28 /*** 29 * @author Fábio de Miranda 30 * @version 1.0 31 */ 32 public class SimplePointGizmo extends SimpleBagGizmo { 33 34 private Point3d point; 35 private double size = 0.1; 36 37 public SimplePointGizmo(Color3b color, Point3d point) { 38 super(color); 39 this.point = point; 40 buildPoint(point); 41 this.addChild(shape); 42 } 43 44 public SimplePointGizmo(Point3d point){ 45 this(new Color3b((byte)255, (byte)0, (byte)0), point); 46 } 47 48 49 public SimplePointGizmo(Appearance appearance, Point3d point){ 50 this(point); 51 this.appearance = appearance; 52 } 53 54 55 public void buildPoint(Point3d point){ 56 double wid = size/2.0; 57 double width = size; 58 double[][] coordinates = {{0,0,width}, 59 {0, 0, -width}, 60 {0, width, 0}, 61 {0, -width, 0}, 62 {width, 0, 0}, 63 {-width,0,0}, 64 {-wid,0.0f,-wid}, 65 {wid,0.0f,-wid}, 66 {wid,0.0f,-wid}, 67 {wid,0.0f,wid}, 68 {wid,0.0f,wid}, 69 {-wid,0.0f,wid}, 70 {-wid,0.0f,wid}, 71 {-wid,0.0f,-wid}, 72 {wid,wid,0.0f}, 73 {wid,-wid,0.0f}, 74 {wid,-wid,0.0f}, 75 {-wid,-wid,0.0f}, 76 {-wid,-wid,0.0f}, 77 {-wid,wid,0.0f}, 78 {-wid,wid,0.0f}, 79 { wid,wid,0.0f} 80 }; 81 for (int i = 0; i < coordinates.length; i++) { 82 coordinates[i][0]+=point.x; 83 coordinates[i][1]+=point.y; 84 coordinates[i][2]+=point.z; 85 } 86 87 LineAttributes lineAttributes; 88 LineArray lineArray = new LineArray(coordinates.length, LineArray.COORDINATES| LineArray.COLOR_3); 89 if (appearance!=null){ 90 lineAttributes = appearance.getLineAttributes(); 91 } else { 92 appearance = new Appearance(); 93 lineAttributes = new LineAttributes(); 94 lineAttributes.setLineWidth(1.0f); 95 appearance.setLineAttributes(lineAttributes); 96 } 97 98 for (int i=0; i<coordinates.length; i++){ 99 //lineArray.setColor(i, colorArray); 100 lineArray.setColor(i, color); 101 lineArray.setCoordinate(i, coordinates[i]); 102 } 103 104 shape = new Shape3D(lineArray, appearance); 105 106 } 107 108 109 110 public static void main(String[] args) { 111 //SimplePointGizmo point01 = new SimplePointGizmo(app, new Point3d(1.0, 1.0, 1.0)); 112 //SimplePointGizmo point01 = new SimplePointGizmo(new Color3b(), new Point3d(1.0, 1.0, 1.0)); 113 SimplePointGizmo point01 = new SimplePointGizmo(new Point3d(1.0, 1.0, 1.0)); 114 NodeTester tester = new NodeTester(); 115 tester.getFrame().setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); 116 tester.add(point01); 117 /* 118 * Code below is just for fun. Plots the points of a function 119 */ 120 for(int i=-100; i < 200; i++){ 121 double n = (double)i/10; 122 tester.add(new SimplePointGizmo(new Point3d(n,10/(1+Math.exp(-n)), 0.0))); 123 } 124 } 125 }

This page was automatically generated by Maven