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 javax.vecmath.*;
24 import javax.media.j3d.*;
25 import camera3d.*;
26 import camera3d.test.NodeTester;
27
28 /***
29 * @author Carlos da Silva dos Santos e Fábio de Miranda
30 * @version 1.0
31 */
32 public class LineGizmo extends SimpleGizmo {
33
34 private Vector3d lineVec = new Vector3d();
35 private Point3d tempP3d = new Point3d();
36 private Point3d p1;
37 private Point3d p2;
38 private Color3b defaultColor = new Color3b((byte)127, (byte)255, (byte)0);
39
40 public LineGizmo(Color3b color, Point3d p1, Point3d p2) {
41 super(color);
42 this.p1 = p1;
43 this.p2 = p2;
44 buildLine(p1, p2);
45 this.addChild(shape);
46 }
47
48 public LineGizmo(Point3d p1, Point3d p2){
49 this(new Color3b((byte)127, (byte)255, (byte)0), p1, p2);
50 }
51
52 public LineGizmo(Point3d p1, Vector3d director, double length, Color3b color){
53 super(color);
54 lineVec.set(director);
55 lineVec.normalize();
56 tempP3d.scaleAdd(length, lineVec, p1);
57 this.p1 = p1;
58 this.p2 = tempP3d;
59 buildLine(p1, p2);
60 this.addChild(shape);
61
62 }
63
64 public LineGizmo(Point3d p1, Vector3d director, double length){
65 super(new Color3b((byte)127, (byte)255, (byte)0));
66 lineVec.set(director);
67 lineVec.normalize();
68 tempP3d.scaleAdd(length, lineVec, p1);
69 this.p1 = p1;
70 this.p2 = tempP3d;
71 buildLine(p1, p2);
72 this.addChild(shape);
73
74 }
75
76 public void buildLine(Point3d p1, Point3d p2){
77 double[][] coordinates = {{p1.x, p1.y, p1.z}, {p2.x, p2.y, p2.z}};
78
79 LineAttributes lineAttributes;
80
81 LineArray lineArray = new LineArray(coordinates.length, LineArray.COORDINATES| LineArray.COLOR_3);
82 lineArray.setCapability(Geometry.ALLOW_INTERSECT);
83
84 if (appearance!=null){
85 lineAttributes = appearance.getLineAttributes();
86 } else {
87 appearance = new Appearance();
88 lineAttributes = new LineAttributes();
89 lineAttributes.setLineWidth(2.0f);
90 appearance.setLineAttributes(lineAttributes);
91 }
92
93 for (int i=0; i<coordinates.length; i++){
94 //lineArray.setColor(i, colorArray);
95 lineArray.setColor(i, color);
96 lineArray.setCoordinate(i, coordinates[i]);
97 }
98
99 shape = new Shape3D(lineArray, appearance);
100
101 }
102
103 public String getLabel(){
104 return this.label;
105 }
106
107 public Color3b getDefaultColor(){
108 return this.defaultColor;
109 }
110
111
112 public static void main(String[] args) {
113 NodeTester tester = new NodeTester();
114 Point3d p1 = new Point3d(0.0, 0.0, 0.0);
115 Point3d p2 = new Point3d(5.0, 5.0, 5.0);
116 LineGizmo line = new LineGizmo(p1, p2);
117 PointGizmo pt1 = new PointGizmo(p1);
118 PointGizmo pt2 = new PointGizmo(p2);
119 tester.add(line);
120 tester.add(pt1);
121 tester.add(pt2);
122 }
123
124
125 }
This page was automatically generated by Maven