-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathH3PickViewer.java
More file actions
130 lines (104 loc) · 3.83 KB
/
H3PickViewer.java
File metadata and controls
130 lines (104 loc) · 3.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
//
// The Walrus Graph Visualization Tool.
// Copyright (C) 2000,2001,2002 The Regents of the University of California.
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
// ######END_HEADER######
//
import javax.media.j3d.*;
import javax.vecmath.*;
public class H3PickViewer
{
public H3PickViewer(double radius)
{
createAxes(radius);
createCircle(radius);
}
// (x, y) in image-plate coordinates
public void draw(GraphicsContext3D gc, double x, double y)
{
Vector3d t = new Vector3d(x, y, 0.0);
Transform3D translation = new Transform3D();
translation.set(t);
Transform3D transform = new Transform3D(m_imageToVworld);
transform.mul(translation);
gc.setModelTransform(transform);
gc.draw(m_axes);
gc.draw(m_circle);
}
public void setImageToVworldTransform(Transform3D transform)
{
m_imageToVworld.set(transform);
}
// ===================================================================
private void createAxes(double radius)
{
LineAttributes lineAttributes = new LineAttributes();
lineAttributes.setLineWidth(1.0f);
lineAttributes.setLineAntialiasingEnable(ANTIALIASING);
ColoringAttributes coloringAttributes =
new ColoringAttributes(0.5f, 0.5f, 0.5f,
ColoringAttributes.FASTEST);
Appearance appearance = new Appearance();
appearance.setLineAttributes(lineAttributes);
appearance.setColoringAttributes(coloringAttributes);
LineArray lines = new LineArray(4, LineArray.COORDINATES);
lines.setCoordinate(0, new Point3d(-radius, 0.0, 0.0));
lines.setCoordinate(1, new Point3d(radius, 0.0, 0.0));
lines.setCoordinate(2, new Point3d(0.0, -radius, 0.0));
lines.setCoordinate(3, new Point3d(0.0, radius, 0.0));
m_axes = new Shape3D(lines, appearance);
}
private void createCircle(double radius)
{
LineAttributes lineAttributes = new LineAttributes();
lineAttributes.setLineWidth(1.0f);
lineAttributes.setLineAntialiasingEnable(ANTIALIASING);
ColoringAttributes coloringAttributes =
new ColoringAttributes(0.5f, 0.5f, 0.5f,
ColoringAttributes.FASTEST);
Appearance appearance = new Appearance();
appearance.setLineAttributes(lineAttributes);
appearance.setColoringAttributes(coloringAttributes);
int numSegments = 72;
int[] stripLengths = { numSegments + 1 };
Point3f[] xyPoints =
createXYCircleCoordinates((float)radius, numSegments);
LineStripArray xyLines = new LineStripArray(xyPoints.length,
GeometryArray.COORDINATES,
stripLengths);
xyLines.setCoordinates(0, xyPoints);
m_circle = new Shape3D(xyLines, appearance);
}
private Point3f[] createXYCircleCoordinates(float radius, int numSegments)
{
Point3f[] retval = new Point3f[numSegments + 1];
Matrix4d rot = new Matrix4d();
for (int i = 0; i <= numSegments; i++)
{
retval[i] = new Point3f(radius, 0.0f, 0.0f);
double angle = 2.0 * Math.PI * i / numSegments;
rot.rotZ(angle);
rot.transform(retval[i]);
}
return retval;
}
// =====================================================================
private static final boolean ANTIALIASING = false;
private Transform3D m_imageToVworld = new Transform3D();
private Shape3D m_axes;
private Shape3D m_circle;
}