-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathVertigo_Viewer.java
More file actions
324 lines (292 loc) · 8.72 KB
/
Vertigo_Viewer.java
File metadata and controls
324 lines (292 loc) · 8.72 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
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
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
/*
* $Id:$
*
* Vertigo_viewer: 3D Viewer Plugin for ImageJ.
* Copyright (C) 2013 Jean-Christophe Taveau.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*
* Authors :
* Florin Buga
* Olivier Catoliquot
* Clement Delestre
*/
import vertigo.scenegraph.Scene;
import vertigo.scenegraph.Camera;
import vertigo.scenegraph.Light;
import vertigo.scenegraph.World;
import vertigo.scenegraph.Stage;
import vertigo.scenegraph.BackStage;
import vertigo.scenegraph.Node;
import vertigo.scenegraph.Lighting;
import vertigo.scenegraph.Viewing;
import vertigo.scenegraph.transform.ArcBall;
import vertigo.graphics.Window3D;
import ij.IJ;
import ij.plugin.PlugIn;
import java.util.ArrayList;
import java.util.Iterator;
/**
* Class Vertigo_Viewer. The main class of Vertigo.
*
* @author Florin Buga
* @author Olivier Catoliquot
* @author Clement Delestre
* @version 0.1
*
*/
public class Vertigo_Viewer implements PlugIn {
/**
* The window's title
*
* @see Vertigo_Viewer#setTitle(java.lang.String)
*/
private String title_;
/**
* The window's width
*
* @see Vertigo_Viewer#setDimension(int, int)
*/
private int window_width = 512;
/**
* The window's height
*
* @see Vertigo_Viewer#setDimension(int, int)
*/
private int window_height = 512;
/**
* The window's background red component
*
* @see Vertigo_Viewer#setBackgroundColor(int, int, int)
*/
private int red = 85;
/**
* The window's background green component
*
* @see Vertigo_Viewer#setBackgroundColor(int, int, int)
*/
private int green = 85;
/**
* The window's background blue component
*
* @see Vertigo_Viewer#setBackgroundColor(int, int, int)
*/
private int blue = 85;
/**
* The scene of scenegraph
*
* @see Vertigo_Viewer#getScene()
*/
private Scene scene_;
/**
* The camera of scenegraph
*
* @see Vertigo_Viewer#getCamera()
*/
private Camera camera_;
private Window3D graphWin;
/**
* The world of scenegraph
*
* @see Vertigo_Viewer#getWorld()
*/
private World world_;
/**
* The vertigo's version
*/
public static final String VERTIGO_VERSION = "0.01";
/**
* Constructor, create a default scenegraph.
*/
public Vertigo_Viewer() {
default_scenegraph();
title_ = " ";
}
@Override
public void run(String options) {
//test();
IJ.showMessage("About VERTIGO",
"<html>"
+ "This plugin only works via scripts in JavaScript.<br />"
+ "See the tutorials in http://crazybiocomputing.blogspot.com/p/plugins.html.</html>");
}
/**
* Sets The title of the Window
*
* @param a_title a string containing the title
*/
public void setTitle(String a_title) {
title_ = a_title;
}
/**
* Sets the background color
*
* @param red integer value between 0 and 255 for the red component
* @param green integer value between 0 and 255 for the red component
* @param blue integer value between 0 and 255 for the red component
*/
public void setBackgroundColor(int red, int green, int blue) {
this.red = red;
this.green = green;
this.blue = blue;
}
/**
* Sets the window's dimension
*
* @param width
* @param height
*/
public void setDimension(int w, int h) {
window_width = w;
window_height = h;
}
/**
* Displays the window and triggers the OpenGL rendering in an infinite
* loop.
*/
public void show() {
try {
graphWin = new vertigo.graphics.lwjgl.LWJGL_Window();
show("LWJGL");
} catch (ExceptionInInitializerError e) {
try {
graphWin = new vertigo.graphics.jogl.JOGL_Window();
show("JOGL");
} catch (ExceptionInInitializerError ei) {
// try & catch for tests
try {
graphWin = (Window3D) new vertigo.graphics.text.Text_Renderer();
show("TEXT");
} catch (ExceptionInInitializerError eie) {
IJ.showMessage("Vertigo ERROR", "Please download JOGL or LWJGL.");
}
}
}
try {
graphWin.setBackgroundColor(red, green, blue);
graphWin.setDimension(window_width, window_height);
graphWin.setTitle(title_);
graphWin.setVisible(true);
} catch (NullPointerException nullp) {
IJ.showMessage("Vertigo ERROR", "Can't create a graphics window.");
}
}
/**
* Run the rendering engine for display.
*
* @param render : Name of the rendering engine
*/
public void show(String render) {
if (render.equals("G2D")) {
graphWin = (Window3D) new vertigo.graphics.G2D.G2D_Window();
initWindow();
} else if (render.equals("LWJGL")) {
try {
graphWin = new vertigo.graphics.lwjgl.LWJGL_Window();
initWindow();
} catch (ExceptionInInitializerError e) {
IJ.showMessage("Vertigo ERROR", "Can't create a graphics window. Please download LWJGL or check your ClassPath.");
}
} else if (render.equals("JOGL")) {
try {
graphWin = new vertigo.graphics.jogl.JOGL_Window();
initWindow();
} catch (ExceptionInInitializerError e) {
IJ.showMessage("Vertigo ERROR", "Can't create a graphics window. Please download JOGL or check your ClassPath.");
}
} else if (render.equals("TEXT")) {
graphWin = (Window3D) new vertigo.graphics.text.Text_Renderer(camera_, scene_);
initWindow();
}
}
/**
* Gets the world (a.k.a. root) of the scene graph.
*
* @return world
*/
public World getWorld() {
return world_;
}
/**
* Gets the scene of the scene graph. Convenient method equivalent to
* getWorld().get("Stage").get("Scene");
* @return scene
*/
public Scene getScene() {
return scene_;
}
/**
* Gets the Camera for *this* (default) scene graph. This is a convenient
* method equivalent to `getScene().getCamera()'.
* @return camera
*
*/
public Camera getCamera() {
return camera_;
}
/**
* Gets a node of the scene graph.
*
* @param name of node
* @return Node.
*/
public Node getNode(String name) {
Node a_node = searchName(world_, name);
if (a_node == null) {
IJ.log("The " + name + " node was not found");
}
return a_node;
}
private Node searchName(Node a_node, String name) {
if (a_node.getName().equals(name)) {
return a_node;
} else {
for (Node tmp : a_node.getChildren() ) {
a_node = searchName(tmp, name);
if (a_node != null) {
return a_node;
}
}
}
return null;
}
private void default_scenegraph() {
world_ = new World();
camera_ = new Camera();
scene_ = new Scene();
BackStage bs = new BackStage();
Stage stage = new Stage();
world_.add(stage);
ArcBall mouseRot = new ArcBall();
stage.add(mouseRot);
mouseRot.add(scene_);
world_.add(bs);
Viewing vw = new Viewing();
vw.add(camera_);
bs.add(vw);
Lighting lights = new Lighting();
bs.add(lights);
lights.add(new Light("sun"));
lights.add(new Light("spot"));
}
private void initWindow() {
graphWin.setBackgroundColor(red, green, blue);
graphWin.setDimension(window_width, window_height);
graphWin.setTitle(title_);
graphWin.setWorld(getWorld());
graphWin.setVisible(true);
}
}// end of class Vertigo_Viewer