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 import camera3d.*;
24 import javax.vecmath.*;
25 import java.util.*;
26 import javax.media.j3d.*;
27 import camera3d.test.NodeTester;
28
29 /***
30 * @author Fábio Roberto de Miranda e Carlos da Silva dos Santos
31 * @version 1.0
32 */
33 public class LineArrayGizmo extends SimpleGizmo {
34
35 public LineArrayGizmo() {
36 super();
37 }
38
39 private Vector points = new Vector(40000);
40 private double[] coordinates;
41
42 private int vertexCount;
43
44 private Shape3D shape;
45 private LineArray lineArray;
46
47 private Color3b white = new Color3b((byte)0xff, (byte)0xff, (byte)0xff);
48 private Color3f whitef = new Color3f();
49
50 private Appearance appearance = new Appearance();
51
52 /*
53 PolygonAttributes polyAtt = new PolygonAttributes( PolygonAttributes.POLYGON_LINE,
54 PolygonAttributes.CULL_NONE, 0.3f);
55 */
56 private LineAttributes lineAtt = new LineAttributes();
57
58 public String getLabel() {
59 return "LineArray";
60 }
61
62 public Color3b getDefaultColor() {
63 return white;
64 }
65
66 public void reset(){
67 points.clear();
68 }
69
70 public void addSegment(Point3d p1, Point3d p2){
71 points.add(p1);
72 points.add(p2);
73 }
74
75 public void addSegment(double[] p1, double[] p2){
76 points.add( new Point3d(p1));
77 points.add( new Point3d(p2));
78 }
79
80 public void buildGeometry(){
81 vertexCount = 3 * points.size();
82 coordinates = new double[vertexCount];
83 Iterator iter = points.iterator();
84 int i = 0;
85
86 while (iter.hasNext()) {
87 Point3d p = (Point3d) iter.next();
88 coordinates[ i + 0 ] = p.x;
89 coordinates[ i + 1 ] = p.y;
90 coordinates[ i + 2 ] = p.z;
91 //System.out.println("+");
92 i = i + 3;
93 }
94
95 whitef.set(white.get());
96
97 lineAtt.setLineWidth(2.0f);
98 appearance.setLineAttributes(lineAtt);
99 Material material = new Material();
100 material.setAmbientColor(whitef);
101 material.setEmissiveColor(whitef);
102 lineArray = new LineArray(vertexCount, LineArray.COORDINATES);
103 lineArray.setCoordinates(0, coordinates);
104
105 // added 12/07/2002
106 lineArray.setCapability(Geometry.ALLOW_INTERSECT);
107
108 shape = new Shape3D(lineArray, appearance);
109 this.addChild(shape);
110 }
111
112
113 public static void main(String[] args) {
114 LineArrayGizmo lineArrayGizmo = new LineArrayGizmo();
115 NodeTester tester = new NodeTester();
116
117 double t0 = -100;
118 double tfinal = 6 * Math.PI;
119 double delta = (tfinal - t0) / 10000.0;
120
121 for (double d = t0; d <= tfinal;) {
122 Point3d p1 = new Point3d(Math.cos(d), Math.sin(d), d);
123 //tester.add(new PointGizmo(p1));
124 d += delta;
125 Point3d p2 = new Point3d(Math.cos(d), Math.sin(d), d);
126 //tester.add(new PointGizmo(p2));
127 //tester.add(new LineGizmo(p1, p2));
128 lineArrayGizmo.addSegment(p1, p2);
129 System.out.println(".");
130 }
131
132 lineArrayGizmo.buildGeometry();
133 tester.add(lineArrayGizmo);
134 System.out.println("Object creation finished");
135 }
136 }
This page was automatically generated by Maven