forked from CAIDA/walrus
-
Notifications
You must be signed in to change notification settings - Fork 1
/
H3CircleRenderer.java
229 lines (187 loc) · 6.12 KB
/
H3CircleRenderer.java
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
//
// 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 java.util.*;
import javax.media.j3d.*;
import javax.vecmath.*;
public class H3CircleRenderer
implements H3AdaptiveRenderer
{
////////////////////////////////////////////////////////////////////////
// CONSTRUCTORS
////////////////////////////////////////////////////////////////////////
public H3CircleRenderer(H3Graph graph, H3ViewParameters parameters,
H3RenderQueue queue, H3RenderList list)
{
m_graph = graph;
m_parameters = parameters;
m_renderQueue = queue;
m_renderList = list;
}
////////////////////////////////////////////////////////////////////////
// INTERFACE METHODS (H3AdaptiveRenderer)
////////////////////////////////////////////////////////////////////////
public void render(GraphicsContext3D gc)
{
long startTime = 0;
if (DEBUG_PRINT)
{
startTime = System.currentTimeMillis();
System.out.println("render.begin[" + startTime + "]");
}
computeRenderFrame(gc);
m_parameters.putModelTransform(gc);
m_renderList.render(gc);
if (DEBUG_PRINT)
{
long stopTime = System.currentTimeMillis();
long duration = stopTime - startTime;
System.out.println("render.end[" + stopTime + "]");
System.out.println("render.time[" + duration + "]");
}
}
public void refine(GraphicsContext3D gc)
{
long startTime = 0;
if (DEBUG_PRINT)
{
startTime = System.currentTimeMillis();
System.out.println("refine.begin[" + startTime + "]");
}
computeRefineFrame(gc);
m_parameters.putModelTransform(gc);
m_renderList.render(gc);
gc.flush(true);
if (DEBUG_PRINT)
{
long stopTime = System.currentTimeMillis();
long duration = stopTime - startTime;
System.out.println("refine.end[" + stopTime + "]");
System.out.println("refine.time[" + duration + "]");
}
}
public void reset()
{
m_numDisplayedElements = 0;
}
public boolean isFinished()
{
return m_numDisplayedElements == m_renderQueue.getCurrentNumElements()
&& m_renderQueue.isComplete();
}
public void setMaxDuration(long max)
{
m_maxDuration = max;
}
////////////////////////////////////////////////////////////////////////
// PRIVATE METHODS
////////////////////////////////////////////////////////////////////////
private void computeRenderFrame(GraphicsContext3D gc)
{
long start = System.currentTimeMillis();
m_renderList.beginFrame();
{
Transform3D transform = m_parameters.getObjectToEyeTransform();
boolean more = computeDisplay(gc, 0, m_numDisplayedElements,
transform);
while (more && System.currentTimeMillis() - start < m_maxDuration)
{
more = computeDisplay(gc, m_numDisplayedElements,
NUM_PER_ITERATION, transform);
}
}
m_renderList.endFrame();
}
private void computeRefineFrame(GraphicsContext3D gc)
{
long start = System.currentTimeMillis();
m_renderList.beginFrame();
{
Transform3D transform = m_parameters.getObjectToEyeTransform();
boolean more = true;
while (more && System.currentTimeMillis() - start < m_maxDuration)
{
more = computeDisplay(gc, m_numDisplayedElements,
NUM_PER_ITERATION, transform);
}
}
m_renderList.endFrame();
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
private boolean computeDisplay(GraphicsContext3D gc,
int index, int count,
Transform3D transform)
{
boolean retval = true;
m_numDisplayedElements = index;
H3Circle nodeImage = m_parameters.getNodeImage();
Point3d eye = m_parameters.getEye();
double nodeRadius = m_parameters.getNodeRadius();
Point3d node = new Point3d();
H3RenderQueue.Element element = new H3RenderQueue.Element();
boolean more = true;
while (more && count-- > 0)
{
if (m_renderQueue.get(m_numDisplayedElements, element))
{
++m_numDisplayedElements;
if (element.type == H3RenderQueue.Element.TYPE_NODE)
{
m_renderList.addNode(element.data);
// Render as a circle.
m_graph.getNodeCoordinates(element.data, node);
transform.transform(node);
double perspectiveScale = 1.0 / (1.0 - node.z / eye.z);
double radius = m_graph.getNodeRadius(element.data)
* nodeRadius * perspectiveScale;
double centerX = eye.x + node.x * perspectiveScale;
double centerY = eye.y + node.y * perspectiveScale;
nodeImage.draw(gc, radius, centerX, centerY);
}
else if (element.type == H3RenderQueue.Element.TYPE_TREE_LINK)
{
m_renderList.addTreeLink(element.data);
}
else //(type == H3RenderQueue.Element.TYPE_NONTREE_LINK)
{
m_renderList.addNontreeLink(element.data);
}
}
else
{
retval = false;
more = false;
}
}
return retval;
}
////////////////////////////////////////////////////////////////////////
// PRIVATE FIELDS
////////////////////////////////////////////////////////////////////////
private static final boolean DEBUG_PRINT = false;
private static final int NUM_PER_ITERATION = 25;
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
private long m_maxDuration = Long.MAX_VALUE;
private H3Graph m_graph;
private H3ViewParameters m_parameters;
private H3RenderQueue m_renderQueue;
private H3RenderList m_renderList;
private int m_numDisplayedElements = 0;
}