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