Revision 15441
import/ext3D/branches/ext3D_v1.1/ext3D/src/com/iver/ai2/gvsig3d/gui/VectorTest.java | ||
---|---|---|
1 |
package com.iver.ai2.gvsig3d.gui; |
|
2 |
|
|
3 |
import java.awt.Color; |
|
4 |
import java.util.HashMap; |
|
5 |
import java.util.Iterator; |
|
6 |
import java.util.List; |
|
7 |
|
|
8 |
import sun.security.action.GetBooleanAction; |
|
9 |
|
|
10 |
import com.iver.ai2.gvsig3d.resources.ResourcesFactory; |
|
11 |
import com.iver.ai2.gvsig3d.utils.Punto3D; |
|
12 |
import com.iver.cit.gvsig.fmap.core.v02.FLabel; |
|
13 |
|
|
14 |
import es.upv.ai2.libjosg.AutoTransform; |
|
15 |
import es.upv.ai2.libjosg.Group; |
|
16 |
import es.upv.ai2.libjosg.Node; |
|
17 |
import es.upv.ai2.libjosg.Optimizer; |
|
18 |
import es.upv.ai2.libjosg.Vec3; |
|
19 |
import es.upv.ai2.libjosg.Vec4; |
|
20 |
import es.upv.ai2.libjosg.Optimizer.OptimizationOptions; |
|
21 |
import es.upv.ai2.libjosg.features.Point; |
|
22 |
import es.upv.ai2.libjosg.features.Polygon; |
|
23 |
import es.upv.ai2.libjosg.features.Polyline; |
|
24 |
import es.upv.ai2.libjosg.features.TesselablePolygon; |
|
25 |
import es.upv.ai2.libjosg.features.Text; |
|
26 |
import es.upv.ai2.libjosg.planets.Planet; |
|
27 |
import es.upv.ai2.libjosg.planets.Planet.PlanetType; |
|
28 |
|
|
29 |
public class VectorTest extends Group { |
|
30 |
|
|
31 |
private static double radius; |
|
32 |
|
|
33 |
static Planet planet; |
|
34 |
|
|
35 |
public VectorTest(double ra, Planet m_planet) { |
|
36 |
super(); |
|
37 |
radius = ra; |
|
38 |
// this.setNodeName("VECTOR"); |
|
39 |
planet = m_planet; |
|
40 |
init(); |
|
41 |
} |
|
42 |
|
|
43 |
private void init() { |
|
44 |
|
|
45 |
// this.addChild(insertTexto("Polo norte", poloNorte)); |
|
46 |
// this.addChild(insertTexto("MADRID", valenciaCar)); |
|
47 |
|
|
48 |
// Vec3 posIni = new Vec3(0, 0, 0); |
|
49 |
// Vec3 posEnd = new Vec3(0, 0, 100000); |
|
50 |
|
|
51 |
// Polyline line = (Polyline) VectorTest.insertLineS(posIni, posEnd, |
|
52 |
// new Vec4(1.0, 1.0, 1.0, 1.0), 0); |
|
53 |
// if (planet.getType() == PlanetType.PLANE_MODE) |
|
54 |
// this.addChild(line); |
|
55 |
|
|
56 |
} |
|
57 |
|
|
58 |
// public Node insertTexto(String texto, Vec3 posicion) { |
|
59 |
// // A?adiendo texto |
|
60 |
// Text text = new Text(); |
|
61 |
// // text.setNodeName(texto); |
|
62 |
// text.setText(texto); |
|
63 |
// text.setCharacterSize(32); |
|
64 |
// |
|
65 |
// text.setAxisAlignment(Text.AxisAlignment.SCREEN); |
|
66 |
// text.setAlignment(Text.AlignmentType.CENTER_CENTER); |
|
67 |
// text.setCharacterSizeMode(Text.CharacterSizeMode.SCREEN_COORDS); |
|
68 |
// text.setPosition((float) posicion.x(), (float) posicion.y(), |
|
69 |
// (float) posicion.z()); |
|
70 |
// |
|
71 |
// if (ResourcesFactory.exitsResouce("arial.ttf")) |
|
72 |
// text.setFont(ResourcesFactory.getResourcePath("arial.ttf")); |
|
73 |
// else |
|
74 |
// text.setFont("arial.ttf"); |
|
75 |
// text.setAutoRotateToScreen(true); |
|
76 |
// |
|
77 |
// |
|
78 |
// Optimizer opt = new Optimizer(); |
|
79 |
// opt.optimizeOptions(text, OptimizationOptions.SPATIALIZE_GROUPS); |
|
80 |
// |
|
81 |
// return text; |
|
82 |
// } |
|
83 |
// /** |
|
84 |
// * this method create a new 3D text. With a value and position. And insert |
|
85 |
// a |
|
86 |
// * point under 3D text |
|
87 |
// * |
|
88 |
// * @param texto |
|
89 |
// * text that is visible in 3D |
|
90 |
// * @param position |
|
91 |
// * Position of 3D text in cartesian coordinates |
|
92 |
// * @return New node |
|
93 |
// */ |
|
94 |
// public void insertText(String texto, Vec3 posicion) { |
|
95 |
// posicion.setZ(posicion.z() + radius); |
|
96 |
// Vec3 e = planet.convertLatLongHeightToXYZ(posicion); |
|
97 |
// |
|
98 |
// this.addChild(insertPoint(e, new Vec4(1.0, 0, 0, 1.0))); |
|
99 |
// |
|
100 |
// this.addChild(insertTexto(texto, e)); |
|
101 |
// } |
|
102 |
// |
|
103 |
// /** |
|
104 |
// * this method create a new 3D point. With a color and position |
|
105 |
// * |
|
106 |
// * @param color |
|
107 |
// * Color of the point |
|
108 |
// * @param position |
|
109 |
// * Position of 3D point in cartesian coordinates |
|
110 |
// * @return |
|
111 |
// */ |
|
112 |
// public Node insertPoint(Vec3 position, Vec4 color) { |
|
113 |
// // Creating point |
|
114 |
// Point p = new Point(); |
|
115 |
// |
|
116 |
// // Adding position and color |
|
117 |
// for (int i = 0; i < 1; i++) { |
|
118 |
// p.setPointSize(100); |
|
119 |
// p.addPoint(position, color); |
|
120 |
// } |
|
121 |
// |
|
122 |
// return p; |
|
123 |
// } |
|
124 |
|
|
125 |
/** |
|
126 |
* Method to create a new 3D text. With a value and position. Text aligment |
|
127 |
* is LEFT CENTER, and his font is "Arial.ttf" |
|
128 |
* |
|
129 |
* @param texto |
|
130 |
* Text that is visible in 3D |
|
131 |
* @param position |
|
132 |
* Position of 3D text in cartesian coordinates |
|
133 |
* @return New node |
|
134 |
*/ |
|
135 |
public static Node insertTextoS(String texto, Vec3 position, Vec4 color, |
|
136 |
int tam, boolean inPixels) { |
|
137 |
|
|
138 |
// Creating text node |
|
139 |
Text text = new Text(); |
|
140 |
// Set up text properties |
|
141 |
text.setText(texto); |
|
142 |
text.setCharacterSize(tam); |
|
143 |
// Select that the text will be in pixels or screen coordinates |
|
144 |
if (inPixels) { |
|
145 |
text.setCharacterSizeMode(Text.CharacterSizeMode.SCREEN_COORDS); |
|
146 |
} else { |
|
147 |
text.setCharacterSizeMode(Text.CharacterSizeMode.OBJECT_COORDS); |
|
148 |
} |
|
149 |
text.setColor(color); |
|
150 |
text.setAxisAlignment(Text.AxisAlignment.SCREEN); |
|
151 |
text.setAlignment(Text.AlignmentType.LEFT_BOTTOM); |
|
152 |
text.setPosition((float) position.x(), (float) position.y(), |
|
153 |
(float) position.z()); |
|
154 |
|
|
155 |
// Search font in resources directori |
|
156 |
if (ResourcesFactory.exitsResouce("arial.ttf")) |
|
157 |
text.setFont(ResourcesFactory.getResourcePath("arial.ttf")); |
|
158 |
else |
|
159 |
text.setFont("arial.ttf"); |
|
160 |
text.setAutoRotateToScreen(true); |
|
161 |
|
|
162 |
// Optimizer generated nodes |
|
163 |
Optimizer opt = new Optimizer(); |
|
164 |
opt.optimizeOptions(text, OptimizationOptions.SPATIALIZE_GROUPS); |
|
165 |
|
|
166 |
// Return node |
|
167 |
return text; |
|
168 |
|
|
169 |
} |
|
170 |
|
|
171 |
/** |
|
172 |
* Method to create a new 3D point. With a color, heigth and position. |
|
173 |
* |
|
174 |
* @param position |
|
175 |
* Position of 3D text in cartesian coordinates |
|
176 |
* @param color |
|
177 |
* color of the 3D point |
|
178 |
* @param tam |
|
179 |
* the heigth of the point |
|
180 |
* @return New text node |
|
181 |
*/ |
|
182 |
public static Node insertPointS(Vec3 position, Vec4 color, int tam) { |
|
183 |
AutoTransform au = new AutoTransform(); |
|
184 |
// Creating point |
|
185 |
Point p = new Point(); |
|
186 |
// p.setDistanceAttenuation(new Vec3(0.0,0.0,0.0000001)); |
|
187 |
p.setPointSize(tam); |
|
188 |
p.addPoint(position, color); |
|
189 |
|
|
190 |
au.addChild(p); |
|
191 |
// return au; |
|
192 |
return p; |
|
193 |
} |
|
194 |
|
|
195 |
/** |
|
196 |
* Method to create a new 3D point. With a color, heigth and position. |
|
197 |
* |
|
198 |
* @param hash |
|
199 |
* Hash Table that contains "Puntos3D" elements |
|
200 |
* @return |
|
201 |
*/ |
|
202 |
public static Node insertPointS(HashMap hash) { |
|
203 |
|
|
204 |
Group g = new Group(); |
|
205 |
|
|
206 |
// Iterate over the keys in the map |
|
207 |
Iterator it = hash.keySet().iterator(); |
|
208 |
while (it.hasNext()) { |
|
209 |
// Get key |
|
210 |
Integer key = (Integer) it.next(); |
|
211 |
List list = (List) hash.get(key); |
|
212 |
|
|
213 |
Point p = new Point(); |
|
214 |
for (Iterator iter = list.iterator(); iter.hasNext();) { |
|
215 |
// Getting point |
|
216 |
Punto3D element = (Punto3D) iter.next(); |
|
217 |
Vec4 color = element.getColor(); |
|
218 |
// Blending only is active if the alpha component are diferent |
|
219 |
// that 1 |
|
220 |
if (color.w() != 1) { |
|
221 |
p.setEnabledBlending(true); |
|
222 |
} |
|
223 |
// Enabling antialiasing |
|
224 |
p.setEnabledSmoothing(true); |
|
225 |
|
|
226 |
// Set up size, position and color |
|
227 |
p.setPointSize(element.getZize()); |
|
228 |
p.addPoint(element.getPosition(), color); |
|
229 |
} |
|
230 |
// Adding points to group |
|
231 |
g.addChild(p); |
|
232 |
} |
|
233 |
|
|
234 |
// Optimizer generated nodes |
|
235 |
Optimizer opt = new Optimizer(); |
|
236 |
opt.optimizeOptions(g, OptimizationOptions.SPATIALIZE_GROUPS); |
|
237 |
|
|
238 |
return g; |
|
239 |
} |
|
240 |
|
|
241 |
/** |
|
242 |
* Method to add 3D points to specific point type. With a color, heigth and |
|
243 |
* position. |
|
244 |
* |
|
245 |
* @param point |
|
246 |
* Node to add new 3D point |
|
247 |
* @param position |
|
248 |
* Position of 3D text in cartesian coordinates |
|
249 |
* @param color |
|
250 |
* color of the 3D point |
|
251 |
* @param tam |
|
252 |
* the heigth of the point |
|
253 |
* @return New text node |
|
254 |
*/ |
|
255 |
public static void addNodeToPoint(Node point, Vec3 position, Vec4 color, |
|
256 |
int tam) { |
|
257 |
|
|
258 |
Point p = null; |
|
259 |
// Getting point |
|
260 |
if (point != null) |
|
261 |
p = (Point) point; |
|
262 |
|
|
263 |
// If not exits create new |
|
264 |
if (p == null) |
|
265 |
p = new Point(); |
|
266 |
|
|
267 |
// Blending only is active if the alpha component are diferent that 1 |
|
268 |
if (color.w() != 1) { |
|
269 |
p.setEnabledBlending(true); |
|
270 |
} |
|
271 |
|
|
272 |
// Set up size, position and color |
|
273 |
p.setPointSize(tam); |
|
274 |
p.addPoint(position, color); |
|
275 |
|
|
276 |
// Optimizer generated nodes |
|
277 |
Optimizer opt = new Optimizer(); |
|
278 |
opt.optimizeOptions(p, OptimizationOptions.SPATIALIZE_GROUPS); |
|
279 |
|
|
280 |
} |
|
281 |
|
|
282 |
/** |
|
283 |
* Method to create a new 3D line. With a color, heigth and position. |
|
284 |
* |
|
285 |
* @param ini |
|
286 |
* Initial position of line |
|
287 |
* @param end |
|
288 |
* End positon of line. |
|
289 |
* @param color |
|
290 |
* color of the 3D point |
|
291 |
* @param tam |
|
292 |
* the heigth of the point |
|
293 |
* @return New line node |
|
294 |
*/ |
|
295 |
|
|
296 |
public static Node insertLineS(Vec3 ini, Vec3 end, Vec4 color, int tam) { |
|
297 |
// Creating a polyline |
|
298 |
Polyline p = new Polyline(ini, end); |
|
299 |
|
|
300 |
// Set up parameter |
|
301 |
p.setWidth(2f); |
|
302 |
p.setPattern((short) 0xFFFF); |
|
303 |
p.setFactor(2); |
|
304 |
p.setColor(color); |
|
305 |
|
|
306 |
// Optimize the node |
|
307 |
Optimizer opt = new Optimizer(); |
|
308 |
opt.optimize(p); |
|
309 |
|
|
310 |
// Return the node |
|
311 |
return p; |
|
312 |
} |
|
313 |
|
|
314 |
/** |
|
315 |
* Method to add new points to specific line type. With a color, heigth and |
|
316 |
* position. |
|
317 |
* |
|
318 |
* @param line |
|
319 |
* Node to add new point |
|
320 |
* @param position |
|
321 |
* Position of 3D point in cartesian coordinates |
|
322 |
* @param color |
|
323 |
* color of the 3D point |
|
324 |
* @param tam |
|
325 |
* the heigth of the point |
|
326 |
*/ |
|
327 |
public static void addNodeToLine(Node line, Vec3 position, Vec4 color, |
|
328 |
int tam) { |
|
329 |
// Getting polyline |
|
330 |
Polyline p = (Polyline) line; |
|
331 |
|
|
332 |
// If not exits, create a new |
|
333 |
if (p == null) |
|
334 |
p = new Polyline(position, position); |
|
335 |
|
|
336 |
// Add a point and color |
|
337 |
p.addPoint(position, color); |
|
338 |
|
|
339 |
} |
|
340 |
|
|
341 |
/** |
|
342 |
* Create a new point node with a color and size. Using a position of 3D |
|
343 |
* points |
|
344 |
* |
|
345 |
* @param position |
|
346 |
* Position of 3D point |
|
347 |
* @param color |
|
348 |
* Color of the 3D point |
|
349 |
* @param tam |
|
350 |
* Size of the point (in pixels) |
|
351 |
* @return |
|
352 |
*/ |
|
353 |
public static Node insertPointS(Vec3[] position, Vec4 color, int tam) { |
|
354 |
// Creating point node |
|
355 |
Point p = new Point(); |
|
356 |
|
|
357 |
// Set up parameters and insert position |
|
358 |
for (int i = 0; i < position.length; i++) { |
|
359 |
p.setPointSize(tam); |
|
360 |
p.addPoint(position[i], color); |
|
361 |
} |
|
362 |
|
|
363 |
// Optimizer generated nodes |
|
364 |
Optimizer opt = new Optimizer(); |
|
365 |
opt.optimizeOptions(p, OptimizationOptions.SPATIALIZE_GROUPS); |
|
366 |
|
|
367 |
// Return node |
|
368 |
return p; |
|
369 |
} |
|
370 |
|
|
371 |
/** |
|
372 |
* Create a new tesselation poligon with a color using an array of 3D points |
|
373 |
* |
|
374 |
* @param points |
|
375 |
* Array of 3D points |
|
376 |
* @param color |
|
377 |
* Color of the poligon |
|
378 |
* @return Poligon node |
|
379 |
*/ |
|
380 |
public static Node insertPolygon(Vec3[] points, Vec4 color) { |
|
381 |
// Creating a polygon |
|
382 |
TesselablePolygon p = new TesselablePolygon(); |
|
383 |
|
|
384 |
// Set up parameters |
|
385 |
// p.setType(Polygon.PolygonType.FILLED_POLYGON); |
|
386 |
p.setWidth(2f); |
|
387 |
// p.setPattern((short) 0xFFFF); |
|
388 |
// p.setFactor(2); |
|
389 |
p.setType(Polygon.PolygonType.FILLED_POLYGON); |
|
390 |
// p.setType(Polygon.PolygonType.EMPTY_POLYGON); |
|
391 |
// p.setType(Polygon.PolygonType.PATTERN_POLYGON); |
|
392 |
|
|
393 |
// Adding points |
|
394 |
for (int i = 0; i < points.length - 1; i++) { |
|
395 |
p.addPoint(points[i], color); |
|
396 |
// System.out.println("Position: " + inv[i].x() + " " + inv[i].y() + |
|
397 |
// " " + inv[i].z()); |
|
398 |
} |
|
399 |
|
|
400 |
// Tesselation of this poligon |
|
401 |
p.tesselate(); |
|
402 |
|
|
403 |
// Optimizer generated nodes |
|
404 |
Optimizer opt = new Optimizer(); |
|
405 |
opt.optimizeOptions(p, OptimizationOptions.SPATIALIZE_GROUPS); |
|
406 |
|
|
407 |
// Return node |
|
408 |
return p; |
|
409 |
} |
|
410 |
|
|
411 |
/** |
|
412 |
* Create a new tesselation poligon with a color using an List of 3D points |
|
413 |
* |
|
414 |
* @param points |
|
415 |
* List of 3D points |
|
416 |
* @param color |
|
417 |
* Color of the poligon |
|
418 |
* @return Poligon node |
|
419 |
*/ |
|
420 |
public static Node insertPolygon(List points, Vec4 color) { |
|
421 |
// Creating a polygon |
|
422 |
TesselablePolygon p = new TesselablePolygon(); |
|
423 |
|
|
424 |
// Set up parameters |
|
425 |
// p.setType(Polygon.PolygonType.FILLED_POLYGON); |
|
426 |
p.setWidth(2f); |
|
427 |
// p.setPattern((short) 0xFFFF); |
|
428 |
// p.setFactor(2); |
|
429 |
p.setType(Polygon.PolygonType.FILLED_POLYGON); |
|
430 |
// p.setType(Polygon.PolygonType.EMPTY_POLYGON); |
|
431 |
// p.setType(Polygon.PolygonType.PATTERN_POLYGON); |
|
432 |
|
|
433 |
// Blending only is active if the alpha component are diferent that 1 |
|
434 |
if (color.w() != 1) { |
|
435 |
p.setEnabledBlending(true); |
|
436 |
} |
|
437 |
// Adding points |
|
438 |
for (int i = 0; i < points.size(); i++) { |
|
439 |
Vec3 element = (Vec3) points.get(i); |
|
440 |
p.addPoint(element, color); |
|
441 |
} |
|
442 |
|
|
443 |
// p.setTexture("C:/modelos3d/Images/land_shallow_topo_2048.jpg"); |
|
444 |
|
|
445 |
// Tesselation of this poligon |
|
446 |
p.tesselate(); |
|
447 |
|
|
448 |
// Optimizer generated nodes |
|
449 |
Optimizer opt = new Optimizer(); |
|
450 |
opt.optimizeOptions(p, OptimizationOptions.ALL_OPTIMIZATIONS); |
|
451 |
|
|
452 |
// Return node |
|
453 |
return p; |
|
454 |
} |
|
455 |
|
|
456 |
/** |
|
457 |
* Method to create a new 3D line. With a List of 3D points and a color |
|
458 |
* |
|
459 |
* @param points |
|
460 |
* List of 3D points |
|
461 |
* @param color |
|
462 |
* Color of the line |
|
463 |
* @return |
|
464 |
* |
|
465 |
*/ |
|
466 |
public static Node insertLine(List points, Vec4 color, float size) { |
|
467 |
Vec3 ori = null, fin = null; |
|
468 |
|
|
469 |
// Getting first points |
|
470 |
if (points.size() > 1) { |
|
471 |
ori = (Vec3) points.get(0); |
|
472 |
fin = (Vec3) points.get(1); |
|
473 |
} |
|
474 |
|
|
475 |
// If the line do not have more than 2 points return null |
|
476 |
if ((ori == null) || (fin == null)) |
|
477 |
return null; |
|
478 |
|
|
479 |
// Create new polyline |
|
480 |
Polyline p = new Polyline(ori, fin); |
|
481 |
p.setPointColor(0, color); |
|
482 |
p.setPointColor(1, color); |
|
483 |
|
|
484 |
// Set up parameters |
|
485 |
p.setWidth(size); |
|
486 |
p.setPattern((short) 0xFFFF); |
|
487 |
p.setFactor(2); |
|
488 |
|
|
489 |
// Blending only is active if the alpha component are diferent that 1 |
|
490 |
if (color.w() != 1) { |
|
491 |
p.setEnabledBlending(true); |
|
492 |
} |
|
493 |
|
|
494 |
// Enabling antialiasing |
|
495 |
p.setEnabledSmoothing(true); |
|
496 |
|
|
497 |
p.setColor(color); |
|
498 |
|
|
499 |
// Adding points |
|
500 |
for (int i = 2; i < points.size(); i++) { |
|
501 |
Vec3 element = (Vec3) points.get(i); |
|
502 |
p.addPoint(element, color); |
|
503 |
} |
|
504 |
|
|
505 |
// Optimizer generated nodes |
|
506 |
Optimizer opt = new Optimizer(); |
|
507 |
opt.optimize(p); |
|
508 |
|
|
509 |
// Return node |
|
510 |
return p; |
|
511 |
|
|
512 |
} |
|
513 |
|
|
514 |
/** |
|
515 |
* Create a new group of 3D points with a color and size. Using a List of 3D |
|
516 |
* points |
|
517 |
* |
|
518 |
* @param points |
|
519 |
* List of 3D points |
|
520 |
* @param color |
|
521 |
* Color of the line |
|
522 |
* @param size |
|
523 |
* Size of the point (in pixels) |
|
524 |
* @return |
|
525 |
*/ |
|
526 |
public static Node insertPoints(List points, Vec4 color, float size) { |
|
527 |
// Creating point |
|
528 |
Point p = new Point(); |
|
529 |
|
|
530 |
// Set up parameters |
|
531 |
p.setPointSize(size); |
|
532 |
|
|
533 |
// Adding points |
|
534 |
for (int i = 0; i < points.size(); i++) { |
|
535 |
Vec3 element = (Vec3) points.get(i); |
|
536 |
p.addPoint(element, color); |
|
537 |
} |
|
538 |
|
|
539 |
// Optimizer generated nodes |
|
540 |
Optimizer opt = new Optimizer(); |
|
541 |
opt.optimize(p); |
|
542 |
|
|
543 |
// Return node |
|
544 |
return p; |
|
545 |
|
|
546 |
} |
|
547 |
|
|
548 |
/** |
|
549 |
* Create a new group of 3D labels with a size and heigth. Using a List of |
|
550 |
* 3D points |
|
551 |
* |
|
552 |
* @param labels |
|
553 |
* List of Flabels |
|
554 |
* |
|
555 |
* @param size |
|
556 |
* Size of the labels |
|
557 |
* @param heigth |
|
558 |
* Heigth of labels |
|
559 |
* @param inPixels |
|
560 |
* True indicates that size is in pixel and false indicates real |
|
561 |
* size; |
|
562 |
* @param type |
|
563 |
* @return Node group |
|
564 |
*/ |
|
565 |
public static Node insertLabels(List labels, int size, float heigth, |
|
566 |
boolean inPixels, int planetType) { |
|
567 |
// Creating a group node |
|
568 |
Group p = new Group(); |
|
569 |
|
|
570 |
// Getting total size |
|
571 |
int total = labels.size(); |
|
572 |
|
|
573 |
// this is for control a max of labels because the system not suport |
|
574 |
// more than 10000 |
|
575 |
int max = 3000; |
|
576 |
if (total > max) |
|
577 |
total = max; |
|
578 |
|
|
579 |
if (labels != null) { |
|
580 |
for (int i = 0; i < total; i++) { |
|
581 |
FLabel f = (FLabel) labels.get(i); |
|
582 |
|
|
583 |
// Set up parameters |
|
584 |
|
|
585 |
// Getting color |
|
586 |
// Color co = f.getColor(); |
|
587 |
Color co = new Color(255, 255, 255, 255); |
|
588 |
float r, g, b, a; |
|
589 |
r = ((float) co.getRed()) / 255.0f; |
|
590 |
g = ((float) co.getGreen()) / 255.0f; |
|
591 |
b = ((float) co.getBlue()) / 255.0f; |
|
592 |
a = ((float) co.getAlpha()) / 255.0f; |
|
593 |
// Set color |
|
594 |
Vec4 textColor = new Vec4(r, g, b, a); |
|
595 |
|
|
596 |
// Get label name |
|
597 |
String label = f.getString(); |
|
598 |
// double heigth = h; |
|
599 |
Vec3 pos = null; |
|
600 |
if (planetType == PlanetType.PLANE_MODE) { |
|
601 |
pos = new Vec3(f.getOrig().getX(), f.getOrig().getY(), |
|
602 |
heigth); |
|
603 |
} else { |
|
604 |
// Transform geodesical coordinates to cartesian |
|
605 |
Vec3 posGeo = new Vec3(f.getOrig().getY(), f.getOrig() |
|
606 |
.getX(), heigth); |
|
607 |
|
|
608 |
pos = planet.convertLatLongHeightToXYZ(posGeo); |
|
609 |
} |
|
610 |
|
|
611 |
// Adding new child text nodes |
|
612 |
p.addChild(insertTextoS(label, pos, textColor, size, inPixels)); |
|
613 |
} |
|
614 |
} |
|
615 |
|
|
616 |
// Optimizer generated nodes |
|
617 |
Optimizer opt = new Optimizer(); |
|
618 |
opt.optimizeOptions(p, OptimizationOptions.SPATIALIZE_GROUPS); |
|
619 |
|
|
620 |
return p; |
|
621 |
|
|
622 |
} |
|
623 |
|
|
624 |
} |
import/ext3D/branches/ext3D_v1.1/ext3D/src/com/iver/ai2/gvsig3d/gui/Hud.java | ||
---|---|---|
13 | 13 |
import es.upv.ai2.libjosg.Vec4; |
14 | 14 |
import es.upv.ai2.libjosg.features.Text; |
15 | 15 |
import es.upv.ai2.libjosg.planets.Planet; |
16 |
import es.upv.ai2.libjosg.planets.PlanetViewer; |
|
16 | 17 |
import es.upv.ai2.libjosg.planets.Planet.PlanetType; |
17 | 18 |
import es.upv.ai2.libjosg.viewer.IViewerContainer; |
18 | 19 |
|
... | ... | |
25 | 26 |
public class Hud extends Group implements MouseMotionListener { |
26 | 27 |
|
27 | 28 |
private IViewerContainer m_canvas3d = null; |
28 |
|
|
29 |
|
|
29 | 30 |
private Planet m_planet = null; |
30 | 31 |
|
31 | 32 |
private String lonText; |
import/ext3D/branches/ext3D_v1.1/ext3D/src/com/iver/ai2/gvsig3d/gui/FeatureFactory.java | ||
---|---|---|
1 |
package com.iver.ai2.gvsig3d.gui; |
|
2 |
|
|
3 |
import java.awt.Color; |
|
4 |
import java.util.HashMap; |
|
5 |
import java.util.Iterator; |
|
6 |
import java.util.List; |
|
7 |
|
|
8 |
import com.iver.ai2.gvsig3d.resources.ResourcesFactory; |
|
9 |
import com.iver.ai2.gvsig3d.utils.Punto3D; |
|
10 |
import com.iver.cit.gvsig.fmap.core.v02.FLabel; |
|
11 |
|
|
12 |
import es.upv.ai2.libjosg.AutoTransform; |
|
13 |
import es.upv.ai2.libjosg.Group; |
|
14 |
import es.upv.ai2.libjosg.Node; |
|
15 |
import es.upv.ai2.libjosg.Optimizer; |
|
16 |
import es.upv.ai2.libjosg.Vec3; |
|
17 |
import es.upv.ai2.libjosg.Vec4; |
|
18 |
import es.upv.ai2.libjosg.Optimizer.OptimizationOptions; |
|
19 |
import es.upv.ai2.libjosg.features.PixelPoint; |
|
20 |
import es.upv.ai2.libjosg.features.Polygon; |
|
21 |
import es.upv.ai2.libjosg.features.Polyline; |
|
22 |
import es.upv.ai2.libjosg.features.TessellablePolygon; |
|
23 |
import es.upv.ai2.libjosg.features.Text; |
|
24 |
import es.upv.ai2.libjosg.planets.Planet; |
|
25 |
import es.upv.ai2.libjosg.planets.Planet.PlanetType; |
|
26 |
|
|
27 |
public class FeatureFactory extends Group { |
|
28 |
|
|
29 |
private static double radius; |
|
30 |
|
|
31 |
static Planet planet; |
|
32 |
|
|
33 |
public FeatureFactory(double ra, Planet m_planet) { |
|
34 |
super(); |
|
35 |
radius = ra; |
|
36 |
// this.setNodeName("VECTOR"); |
|
37 |
planet = m_planet; |
|
38 |
init(); |
|
39 |
} |
|
40 |
|
|
41 |
private void init() { |
|
42 |
|
|
43 |
// this.addChild(insertTexto("Polo norte", poloNorte)); |
|
44 |
// this.addChild(insertTexto("MADRID", valenciaCar)); |
|
45 |
|
|
46 |
// Vec3 posIni = new Vec3(0, 0, 0); |
|
47 |
// Vec3 posEnd = new Vec3(0, 0, 100000); |
|
48 |
|
|
49 |
// Polyline line = (Polyline) VectorTest.insertLineS(posIni, posEnd, |
|
50 |
// new Vec4(1.0, 1.0, 1.0, 1.0), 0); |
|
51 |
// if (planet.getType() == PlanetType.PLANE_MODE) |
|
52 |
// this.addChild(line); |
|
53 |
|
|
54 |
} |
|
55 |
|
|
56 |
// public Node insertTexto(String texto, Vec3 posicion) { |
|
57 |
// // A?adiendo texto |
|
58 |
// Text text = new Text(); |
|
59 |
// // text.setNodeName(texto); |
|
60 |
// text.setText(texto); |
|
61 |
// text.setCharacterSize(32); |
|
62 |
// |
|
63 |
// text.setAxisAlignment(Text.AxisAlignment.SCREEN); |
|
64 |
// text.setAlignment(Text.AlignmentType.CENTER_CENTER); |
|
65 |
// text.setCharacterSizeMode(Text.CharacterSizeMode.SCREEN_COORDS); |
|
66 |
// text.setPosition((float) posicion.x(), (float) posicion.y(), |
|
67 |
// (float) posicion.z()); |
|
68 |
// |
|
69 |
// if (ResourcesFactory.exitsResouce("arial.ttf")) |
|
70 |
// text.setFont(ResourcesFactory.getResourcePath("arial.ttf")); |
|
71 |
// else |
|
72 |
// text.setFont("arial.ttf"); |
|
73 |
// text.setAutoRotateToScreen(true); |
|
74 |
// |
|
75 |
// |
|
76 |
// Optimizer opt = new Optimizer(); |
|
77 |
// opt.optimizeOptions(text, OptimizationOptions.SPATIALIZE_GROUPS); |
|
78 |
// |
|
79 |
// return text; |
|
80 |
// } |
|
81 |
// /** |
|
82 |
// * this method create a new 3D text. With a value and position. And insert |
|
83 |
// a |
|
84 |
// * point under 3D text |
|
85 |
// * |
|
86 |
// * @param texto |
|
87 |
// * text that is visible in 3D |
|
88 |
// * @param position |
|
89 |
// * Position of 3D text in cartesian coordinates |
|
90 |
// * @return New node |
|
91 |
// */ |
|
92 |
// public void insertText(String texto, Vec3 posicion) { |
|
93 |
// posicion.setZ(posicion.z() + radius); |
|
94 |
// Vec3 e = planet.convertLatLongHeightToXYZ(posicion); |
|
95 |
// |
|
96 |
// this.addChild(insertPoint(e, new Vec4(1.0, 0, 0, 1.0))); |
|
97 |
// |
|
98 |
// this.addChild(insertTexto(texto, e)); |
|
99 |
// } |
|
100 |
// |
|
101 |
// /** |
|
102 |
// * this method create a new 3D point. With a color and position |
|
103 |
// * |
|
104 |
// * @param color |
|
105 |
// * Color of the point |
|
106 |
// * @param position |
|
107 |
// * Position of 3D point in cartesian coordinates |
|
108 |
// * @return |
|
109 |
// */ |
|
110 |
// public Node insertPoint(Vec3 position, Vec4 color) { |
|
111 |
// // Creating point |
|
112 |
// Point p = new Point(); |
|
113 |
// |
|
114 |
// // Adding position and color |
|
115 |
// for (int i = 0; i < 1; i++) { |
|
116 |
// p.setPointSize(100); |
|
117 |
// p.addPoint(position, color); |
|
118 |
// } |
|
119 |
// |
|
120 |
// return p; |
|
121 |
// } |
|
122 |
|
|
123 |
/** |
|
124 |
* Method to create a new 3D text. With a value and position. Text aligment |
|
125 |
* is LEFT CENTER, and his font is "Arial.ttf" |
|
126 |
* |
|
127 |
* @param texto |
|
128 |
* Text that is visible in 3D |
|
129 |
* @param position |
|
130 |
* Position of 3D text in cartesian coordinates |
|
131 |
* @return New node |
|
132 |
*/ |
|
133 |
public static Node insertTextoS(String texto, Vec3 position, Vec4 color, |
|
134 |
int tam, boolean inPixels) { |
|
135 |
|
|
136 |
// Creating text node |
|
137 |
Text text = new Text(); |
|
138 |
// Set up text properties |
|
139 |
text.setText(texto); |
|
140 |
text.setCharacterSize(tam); |
|
141 |
// Select that the text will be in pixels or screen coordinates |
|
142 |
if (inPixels) { |
|
143 |
text.setCharacterSizeMode(Text.CharacterSizeMode.SCREEN_COORDS); |
|
144 |
} else { |
|
145 |
text.setCharacterSizeMode(Text.CharacterSizeMode.OBJECT_COORDS); |
|
146 |
} |
|
147 |
text.setColor(color); |
|
148 |
text.setAxisAlignment(Text.AxisAlignment.SCREEN); |
|
149 |
text.setAlignment(Text.AlignmentType.LEFT_BOTTOM); |
|
150 |
text.setPosition((float) position.x(), (float) position.y(), |
|
151 |
(float) position.z()); |
|
152 |
|
|
153 |
// Search font in resources directori |
|
154 |
if (ResourcesFactory.exitsResouce("arial.ttf")) |
|
155 |
text.setFont(ResourcesFactory.getResourcePath("arial.ttf")); |
|
156 |
else |
|
157 |
text.setFont("arial.ttf"); |
|
158 |
text.setAutoRotateToScreen(true); |
|
159 |
|
|
160 |
// Optimizer generated nodes |
|
161 |
Optimizer opt = new Optimizer(); |
|
162 |
opt.optimize(text, OptimizationOptions.SPATIALIZE_GROUPS); |
|
163 |
|
|
164 |
// Return node |
|
165 |
return text; |
|
166 |
|
|
167 |
} |
|
168 |
|
|
169 |
/** |
|
170 |
* Method to create a new 3D point. With a color, heigth and position. |
|
171 |
* |
|
172 |
* @param position |
|
173 |
* Position of 3D text in cartesian coordinates |
|
174 |
* @param color |
|
175 |
* color of the 3D point |
|
176 |
* @param tam |
|
177 |
* the heigth of the point |
|
178 |
* @return New text node |
|
179 |
*/ |
|
180 |
public static Node insertPointS(Vec3 position, Vec4 color, int tam) { |
|
181 |
AutoTransform au = new AutoTransform(); |
|
182 |
// Creating point |
|
183 |
PixelPoint p = new PixelPoint(); |
|
184 |
// p.setDistanceAttenuation(new Vec3(0.0,0.0,0.0000001)); |
|
185 |
p.setPointSize(tam); |
|
186 |
p.addPoint(position, color); |
|
187 |
|
|
188 |
au.addChild(p); |
|
189 |
// return au; |
|
190 |
return p; |
|
191 |
} |
|
192 |
|
|
193 |
/** |
|
194 |
* Method to create a new 3D point. With a color, heigth and position. |
|
195 |
* |
|
196 |
* @param hash |
|
197 |
* Hash Table that contains "Puntos3D" elements |
|
198 |
* @return |
|
199 |
*/ |
|
200 |
public static Node insertPointS(HashMap hash) { |
|
201 |
|
|
202 |
Group g = new Group(); |
|
203 |
|
|
204 |
// Iterate over the keys in the map |
|
205 |
Iterator it = hash.keySet().iterator(); |
|
206 |
while (it.hasNext()) { |
|
207 |
// Get key |
|
208 |
Integer key = (Integer) it.next(); |
|
209 |
List list = (List) hash.get(key); |
|
210 |
|
|
211 |
PixelPoint p = new PixelPoint(); |
|
212 |
for (Iterator iter = list.iterator(); iter.hasNext();) { |
|
213 |
// Getting PixelPoint |
|
214 |
Punto3D element = (Punto3D) iter.next(); |
|
215 |
Vec4 color = element.getColor(); |
|
216 |
// Blending only is active if the alpha component are diferent |
|
217 |
// that 1 |
|
218 |
if (color.w() != 1) { |
|
219 |
p.setEnabledBlending(true); |
|
220 |
} |
|
221 |
// Enabling antialiasing |
|
222 |
p.setEnabledSmoothing(true); |
|
223 |
|
|
224 |
// Set up size, position and color |
|
225 |
p.setPointSize(element.getZize()); |
|
226 |
p.addPoint(element.getPosition(), color); |
|
227 |
} |
|
228 |
// Adding points to group |
|
229 |
g.addChild(p); |
|
230 |
} |
|
231 |
|
|
232 |
// Optimizer generated nodes |
|
233 |
Optimizer opt = new Optimizer(); |
|
234 |
opt.optimize(g, OptimizationOptions.SPATIALIZE_GROUPS); |
|
235 |
|
|
236 |
return g; |
|
237 |
} |
|
238 |
|
|
239 |
/** |
|
240 |
* Method to add 3D points to specific point type. With a color, heigth and |
|
241 |
* position. |
|
242 |
* |
|
243 |
* @param point |
|
244 |
* Node to add new 3D point |
|
245 |
* @param position |
|
246 |
* Position of 3D text in cartesian coordinates |
|
247 |
* @param color |
|
248 |
* color of the 3D point |
|
249 |
* @param tam |
|
250 |
* the heigth of the point |
|
251 |
* @return New text node |
|
252 |
*/ |
|
253 |
public static void addNodeToPoint(Node point, Vec3 position, Vec4 color, |
|
254 |
int tam) { |
|
255 |
|
|
256 |
PixelPoint p = null; |
|
257 |
// Getting point |
|
258 |
if (point != null) |
|
259 |
p = (PixelPoint) point; |
|
260 |
|
|
261 |
// If not exits create new |
|
262 |
if (p == null) |
|
263 |
p = new PixelPoint(); |
|
264 |
|
|
265 |
// Blending only is active if the alpha component are diferent that 1 |
|
266 |
if (color.w() != 1) { |
|
267 |
p.setEnabledBlending(true); |
|
268 |
} |
|
269 |
|
|
270 |
// Set up size, position and color |
|
271 |
p.setPointSize(tam); |
|
272 |
p.addPoint(position, color); |
|
273 |
|
|
274 |
// Optimizer generated nodes |
|
275 |
Optimizer opt = new Optimizer(); |
|
276 |
opt.optimize(p, OptimizationOptions.SPATIALIZE_GROUPS); |
|
277 |
|
|
278 |
} |
|
279 |
|
|
280 |
/** |
|
281 |
* Method to create a new 3D line. With a color, heigth and position. |
|
282 |
* |
|
283 |
* @param ini |
|
284 |
* Initial position of line |
|
285 |
* @param end |
|
286 |
* End positon of line. |
|
287 |
* @param color |
|
288 |
* color of the 3D point |
|
289 |
* @param tam |
|
290 |
* the heigth of the point |
|
291 |
* @return New line node |
|
292 |
*/ |
|
293 |
|
|
294 |
public static Node insertLineS(Vec3 ini, Vec3 end, Vec4 color, int tam) { |
|
295 |
// Creating a polyline |
|
296 |
Polyline p = new Polyline(ini, end); |
|
297 |
|
|
298 |
// Set up parameter |
|
299 |
p.setWidth(2f); |
|
300 |
p.setPattern((short) 0xFFFF); |
|
301 |
p.setFactor(2); |
|
302 |
p.setColor(color); |
|
303 |
|
|
304 |
// Optimize the node |
|
305 |
Optimizer opt = new Optimizer(); |
|
306 |
opt.optimize(p); |
|
307 |
|
|
308 |
// Return the node |
|
309 |
return p; |
|
310 |
} |
|
311 |
|
|
312 |
/** |
|
313 |
* Method to add new points to specific line type. With a color, heigth and |
|
314 |
* position. |
|
315 |
* |
|
316 |
* @param line |
|
317 |
* Node to add new point |
|
318 |
* @param position |
|
319 |
* Position of 3D point in cartesian coordinates |
|
320 |
* @param color |
|
321 |
* color of the 3D point |
|
322 |
* @param tam |
|
323 |
* the heigth of the point |
|
324 |
*/ |
|
325 |
public static void addNodeToLine(Node line, Vec3 position, Vec4 color, |
|
326 |
int tam) { |
|
327 |
// Getting polyline |
|
328 |
Polyline p = (Polyline) line; |
|
329 |
|
|
330 |
// If not exits, create a new |
|
331 |
if (p == null) |
|
332 |
p = new Polyline(position, position); |
|
333 |
|
|
334 |
// Add a point and color |
|
335 |
p.addVertex(position, color); |
|
336 |
|
|
337 |
} |
|
338 |
|
|
339 |
/** |
|
340 |
* Create a new point node with a color and size. Using a position of 3D |
|
341 |
* points |
|
342 |
* |
|
343 |
* @param position |
|
344 |
* Position of 3D point |
|
345 |
* @param color |
|
346 |
* Color of the 3D point |
|
347 |
* @param tam |
|
348 |
* Size of the point (in pixels) |
|
349 |
* @return |
|
350 |
*/ |
|
351 |
public static Node insertPointS(Vec3[] position, Vec4 color, int tam) { |
|
352 |
// Creating point node |
|
353 |
PixelPoint p = new PixelPoint(); |
|
354 |
|
|
355 |
// Set up parameters and insert position |
|
356 |
for (int i = 0; i < position.length; i++) { |
|
357 |
p.setPointSize(tam); |
|
358 |
p.addPoint(position[i], color); |
|
359 |
} |
|
360 |
|
|
361 |
// Optimizer generated nodes |
|
362 |
Optimizer opt = new Optimizer(); |
|
363 |
opt.optimize(p, OptimizationOptions.SPATIALIZE_GROUPS); |
|
364 |
|
|
365 |
// Return node |
|
366 |
return p; |
|
367 |
} |
|
368 |
|
|
369 |
/** |
|
370 |
* Create a new tesselation poligon with a color using an array of 3D points |
|
371 |
* |
|
372 |
* @param points |
|
373 |
* Array of 3D points |
|
374 |
* @param color |
|
375 |
* Color of the poligon |
|
376 |
* @return Poligon node |
|
377 |
*/ |
|
378 |
public static Node insertPolygon(Vec3[] points, Vec4 color) { |
|
379 |
// Creating a polygon |
|
380 |
TessellablePolygon p = new TessellablePolygon(); |
|
381 |
|
|
382 |
// Set up parameters |
|
383 |
// p.setType(Polygon.PolygonType.FILLED_POLYGON); |
|
384 |
p.setWidth(2f); |
|
385 |
// p.setPattern((short) 0xFFFF); |
|
386 |
// p.setFactor(2); |
|
387 |
p.setType(Polygon.PolygonType.FILLED_POLYGON); |
|
388 |
// p.setType(Polygon.PolygonType.EMPTY_POLYGON); |
|
389 |
// p.setType(Polygon.PolygonType.PATTERN_POLYGON); |
|
390 |
|
|
391 |
// Adding points |
|
392 |
for (int i = 0; i < points.length - 1; i++) { |
|
393 |
p.addVertex(points[i], color); |
|
394 |
// System.out.println("Position: " + inv[i].x() + " " + inv[i].y() + |
|
395 |
// " " + inv[i].z()); |
|
396 |
} |
|
397 |
|
|
398 |
// Tesselation of this poligon |
|
399 |
p.tesselate(); |
|
400 |
|
|
401 |
// Optimizer generated nodes |
|
402 |
Optimizer opt = new Optimizer(); |
|
403 |
opt.optimize(p, OptimizationOptions.SPATIALIZE_GROUPS); |
|
404 |
|
|
405 |
// Return node |
|
406 |
return p; |
|
407 |
} |
|
408 |
|
|
409 |
/** |
|
410 |
* Create a new tesselation poligon with a color using an List of 3D points |
|
411 |
* |
|
412 |
* @param points |
|
413 |
* List of 3D points |
|
414 |
* @param color |
|
415 |
* Color of the poligon |
|
416 |
* @return Poligon node |
|
417 |
*/ |
|
418 |
public static Node insertPolygon(List points, Vec4 color) { |
|
419 |
// Creating a polygon |
|
420 |
TessellablePolygon p = new TessellablePolygon(); |
|
421 |
|
|
422 |
// Set up parameters |
|
423 |
// p.setType(Polygon.PolygonType.FILLED_POLYGON); |
|
424 |
p.setWidth(2f); |
|
425 |
// p.setPattern((short) 0xFFFF); |
|
426 |
// p.setFactor(2); |
|
427 |
p.setType(Polygon.PolygonType.FILLED_POLYGON); |
|
428 |
// p.setType(Polygon.PolygonType.EMPTY_POLYGON); |
|
429 |
// p.setType(Polygon.PolygonType.PATTERN_POLYGON); |
|
430 |
|
|
431 |
// Blending only is active if the alpha component are diferent that 1 |
|
432 |
if (color.w() != 1) { |
|
433 |
p.setEnabledBlending(true); |
|
434 |
} |
|
435 |
// Adding points |
|
436 |
for (int i = 0; i < points.size(); i++) { |
|
437 |
Vec3 element = (Vec3) points.get(i); |
|
438 |
p.addVertex(element, color); |
|
439 |
} |
|
440 |
|
|
441 |
// p.setTexture("C:/modelos3d/Images/land_shallow_topo_2048.jpg"); |
|
442 |
|
|
443 |
// Tesselation of this poligon |
|
444 |
p.tesselate(); |
|
445 |
|
|
446 |
// Optimizer generated nodes |
|
447 |
Optimizer opt = new Optimizer(); |
|
448 |
opt.optimize(p, OptimizationOptions.ALL_OPTIMIZATIONS); |
|
449 |
|
|
450 |
// Return node |
|
451 |
return p; |
|
452 |
} |
|
453 |
|
|
454 |
/** |
|
455 |
* Method to create a new 3D line. With a List of 3D points and a color |
|
456 |
* |
|
457 |
* @param points |
|
458 |
* List of 3D points |
|
459 |
* @param color |
|
460 |
* Color of the line |
|
461 |
* @return |
|
462 |
* |
|
463 |
*/ |
|
464 |
public static Node insertLine(List points, Vec4 color, float size) { |
|
465 |
Vec3 ori = null, fin = null; |
|
466 |
|
|
467 |
// Getting first points |
|
468 |
if (points.size() > 1) { |
|
469 |
ori = (Vec3) points.get(0); |
|
470 |
fin = (Vec3) points.get(1); |
|
471 |
} |
|
472 |
|
|
473 |
// If the line do not have more than 2 points return null |
|
474 |
if ((ori == null) || (fin == null)) |
|
475 |
return null; |
|
476 |
|
|
477 |
// Create new polyline |
|
478 |
Polyline p = new Polyline(ori, fin); |
|
479 |
p.getEditableGeometry().setVertexColor(0, color); |
|
480 |
p.getEditableGeometry().setVertexColor(1, color); |
|
481 |
|
|
482 |
// Set up parameters |
|
483 |
p.setWidth(size); |
|
484 |
p.setPattern((short) 0xFFFF); |
|
485 |
p.setFactor(2); |
|
486 |
|
|
487 |
// Blending only is active if the alpha component are diferent that 1 |
|
488 |
if (color.w() != 1) { |
|
489 |
p.setEnabledBlending(true); |
|
490 |
} |
|
491 |
|
|
492 |
// Enabling antialiasing |
|
493 |
p.setEnabledSmoothing(true); |
|
494 |
|
|
495 |
p.setColor(color); |
|
496 |
|
|
497 |
// Adding points |
|
498 |
for (int i = 2; i < points.size(); i++) { |
|
499 |
Vec3 element = (Vec3) points.get(i); |
|
500 |
p.addVertex(element, color); |
|
501 |
} |
|
502 |
|
|
503 |
// Optimizer generated nodes |
|
504 |
Optimizer opt = new Optimizer(); |
|
505 |
opt.optimize(p); |
|
506 |
|
|
507 |
// Return node |
|
508 |
return p; |
|
509 |
|
|
510 |
} |
|
511 |
|
|
512 |
/** |
|
513 |
* Create a new group of 3D points with a color and size. Using a List of 3D |
|
514 |
* points |
|
515 |
* |
|
516 |
* @param points |
|
517 |
* List of 3D points |
|
518 |
* @param color |
|
519 |
* Color of the line |
|
520 |
* @param size |
|
521 |
* Size of the point (in pixels) |
|
522 |
* @return |
|
523 |
*/ |
|
524 |
public static Node insertPoints(List points, Vec4 color, float size) { |
|
525 |
// Creating point |
|
526 |
PixelPoint p = new PixelPoint(); |
|
527 |
|
|
528 |
// Set up parameters |
|
529 |
p.setPointSize(size); |
|
530 |
|
|
531 |
// Adding points |
|
532 |
for (int i = 0; i < points.size(); i++) { |
|
533 |
Vec3 element = (Vec3) points.get(i); |
|
534 |
p.addPoint(element, color); |
|
535 |
} |
|
536 |
|
|
537 |
// Optimizer generated nodes |
|
538 |
Optimizer opt = new Optimizer(); |
|
539 |
opt.optimize(p); |
|
540 |
|
|
541 |
// Return node |
|
542 |
return p; |
|
543 |
|
|
544 |
} |
|
545 |
|
|
546 |
/** |
|
547 |
* Create a new group of 3D labels with a size and heigth. Using a List of |
|
548 |
* 3D points |
|
549 |
* |
|
550 |
* @param labels |
|
551 |
* List of Flabels |
|
552 |
* |
|
553 |
* @param size |
|
554 |
* Size of the labels |
|
555 |
* @param heigth |
|
556 |
* Heigth of labels |
|
557 |
* @param inPixels |
|
558 |
* True indicates that size is in pixel and false indicates real |
|
559 |
* size; |
|
560 |
* @param type |
|
561 |
* @return Node group |
|
562 |
*/ |
|
563 |
public static Node insertLabels(List labels, int size, float heigth, |
|
564 |
boolean inPixels, int planetType) { |
|
565 |
// Creating a group node |
|
566 |
Group p = new Group(); |
|
567 |
|
|
568 |
// Getting total size |
|
569 |
int total = labels.size(); |
|
570 |
|
|
571 |
// this is for control a max of labels because the system not suport |
|
572 |
// more than 10000 |
|
573 |
int max = 3000; |
|
574 |
if (total > max) |
|
575 |
total = max; |
|
576 |
|
|
577 |
if (labels != null) { |
|
578 |
for (int i = 0; i < total; i++) { |
|
579 |
FLabel f = (FLabel) labels.get(i); |
|
580 |
|
|
581 |
// Set up parameters |
|
582 |
|
|
583 |
// Getting color |
|
584 |
// Color co = f.getColor(); |
|
585 |
Color co = new Color(255, 255, 255, 255); |
|
586 |
float r, g, b, a; |
|
587 |
r = ((float) co.getRed()) / 255.0f; |
|
588 |
g = ((float) co.getGreen()) / 255.0f; |
|
589 |
b = ((float) co.getBlue()) / 255.0f; |
|
590 |
a = ((float) co.getAlpha()) / 255.0f; |
|
591 |
// Set color |
|
592 |
Vec4 textColor = new Vec4(r, g, b, a); |
|
593 |
|
|
594 |
// Get label name |
|
595 |
String label = f.getString(); |
|
596 |
// double heigth = h; |
|
597 |
Vec3 pos = null; |
|
598 |
if (planetType == PlanetType.PLANE_MODE) { |
|
599 |
pos = new Vec3(f.getOrig().getX(), f.getOrig().getY(), |
|
600 |
heigth); |
|
601 |
} else { |
|
602 |
// Transform geodesical coordinates to cartesian |
|
603 |
Vec3 posGeo = new Vec3(f.getOrig().getY(), f.getOrig() |
|
604 |
.getX(), heigth); |
|
605 |
|
|
606 |
pos = planet.convertLatLongHeightToXYZ(posGeo); |
|
607 |
} |
|
608 |
|
|
609 |
// Adding new child text nodes |
|
610 |
p.addChild(insertTextoS(label, pos, textColor, size, inPixels)); |
|
611 |
} |
|
612 |
} |
|
613 |
|
|
614 |
// Optimizer generated nodes |
|
615 |
Optimizer opt = new Optimizer(); |
|
616 |
opt.optimize(p, OptimizationOptions.SPATIALIZE_GROUPS); |
|
617 |
|
|
618 |
return p; |
|
619 |
|
|
620 |
} |
|
621 |
|
|
622 |
} |
import/ext3D/branches/ext3D_v1.1/ext3D/src/com/iver/ai2/gvsig3d/map3d/ViewPort3D.java | ||
---|---|---|
14 | 14 |
import com.iver.utiles.StringUtilities; |
15 | 15 |
import com.iver.utiles.XMLEntity; |
16 | 16 |
|
17 |
import es.upv.ai2.libjosg.Node; |
|
17 | 18 |
import es.upv.ai2.libjosg.Vec3; |
18 | 19 |
import es.upv.ai2.libjosg.planets.Planet; |
19 |
import es.upv.ai2.libjosg.viewer.Hit; |
|
20 | 20 |
import es.upv.ai2.libjosg.viewer.IViewerContainer; |
21 |
import es.upv.ai2.libjosg.viewer.Intersections; |
|
21 | 22 |
|
22 | 23 |
public class ViewPort3D extends ViewPort implements MouseListener { |
23 | 24 |
|
... | ... | |
78 | 79 |
int x = (int) pScreen.getX(); |
79 | 80 |
int y = this.getImageHeight() - (int) pScreen.getY() - 1; |
80 | 81 |
|
81 |
// get XYZ coordinates on planet |
|
82 |
Hit hit = canvas3d.getOSGViewer().pick(x, y); |
|
83 |
boolean falseHit = false; |
|
84 |
if (hit.getX() == 0.0 && hit.getY() == 0.0 && hit.getZ() == 0.0) // no |
|
85 |
// hit |
|
86 |
falseHit = true; |
|
87 |
|
|
88 |
// convert to geo coordinates |
|
82 |
Intersections hits = canvas3d.getOSGViewer().rayPick(x, y); |
|
89 | 83 |
Point2D pWorld = new Point2D.Double(); |
90 |
if (proj.getAbrev().compareToIgnoreCase("EPSG:4326") == 0) { |
|
91 |
if (falseHit) { |
|
92 |
pWorld.setLocation(360, 120); // an absurd location |
|
93 |
} else { |
|
84 |
if (hits.containsIntersections()) { |
|
85 |
// get XYZ coordinates on planet |
|
86 |
Vec3 hit = hits.getFirstIntersection().getIntersectionPoint(); |
|
87 |
// convert to geo coordinates |
|
88 |
|
|
89 |
if (proj.getAbrev().compareToIgnoreCase("EPSG:4326") == 0) { |
|
94 | 90 |
Vec3 geoPt = planet.convertXYZToLatLongHeight(new Vec3( |
95 |
(double) hit.getX(), (double) hit.getY(), (double) hit |
|
96 |
.getZ())); |
|
91 |
(double) hit.x(), (double) hit.y(), (double) hit.x())); |
|
97 | 92 |
pWorld.setLocation(geoPt.y(), geoPt.x()); |
98 |
} |
|
93 |
} else |
|
94 |
pWorld.setLocation((double) hit.x(), (double) hit.y()); |
|
99 | 95 |
} else { |
100 |
if (falseHit)
|
|
101 |
pWorld.setLocation(1e100, 1e100); // an absurd location
|
|
102 |
else |
|
103 |
pWorld.setLocation((double) hit.getX(), (double) hit.getY());
|
|
96 |
if (proj.getAbrev().compareToIgnoreCase("EPSG:4326") == 0) {
|
|
97 |
pWorld.setLocation(360, 120);
|
|
98 |
} else
|
|
99 |
pWorld.setLocation(1e100, 1e100);
|
|
104 | 100 |
} |
105 | 101 |
|
106 | 102 |
return pWorld; |
... | ... | |
142 | 138 |
|
143 | 139 |
} |
144 | 140 |
|
145 |
/* (non-Javadoc) |
|
141 |
/* |
|
142 |
* (non-Javadoc) |
|
143 |
* |
|
146 | 144 |
* @see java.awt.event.MouseListener#mouseReleased(java.awt.event.MouseEvent) |
147 | 145 |
*/ |
148 | 146 |
public void mouseReleased(MouseEvent e) { |
149 | 147 |
// Center point of locator |
150 | 148 |
Point2D center = null; |
151 |
//Scale factor |
|
149 |
// Scale factor
|
|
152 | 150 |
double factor = 0; |
153 | 151 |
if (planet != null) { |
154 | 152 |
// Getting center point longitude and latitude |
import/ext3D/branches/ext3D_v1.1/ext3D/src/com/iver/ai2/gvsig3d/map3d/MapContext3D.java | ||
---|---|---|
27 | 27 |
import com.iver.cit.gvsig.fmap.layers.FLayers; |
28 | 28 |
import com.iver.cit.gvsig.fmap.layers.FLyrDefault; |
29 | 29 |
import com.iver.cit.gvsig.fmap.layers.FLyrVect; |
30 |
import com.iver.cit.gvsig.fmap.layers.FLyrWCS; |
|
30 | 31 |
import com.iver.cit.gvsig.fmap.layers.GraphicLayer; |
31 | 32 |
import com.iver.cit.gvsig.fmap.layers.LayerEvent; |
32 | 33 |
import com.iver.cit.gvsig.fmap.layers.LayerListener; |
... | ... | |
42 | 43 |
import es.upv.ai2.libjosg.Node; |
43 | 44 |
import es.upv.ai2.libjosg.Vec3; |
44 | 45 |
import es.upv.ai2.libjosg.planets.Planet; |
46 |
import es.upv.ai2.libjosg.planets.PlanetViewer; |
|
45 | 47 |
import es.upv.ai2.libjosg.planets.RequestLayerListener; |
46 | 48 |
import es.upv.ai2.libjosg.planets.TileCreatedListener; |
47 | 49 |
import es.upv.ai2.libjosg.planets.TileEvent; |
... | ... | |
56 | 58 |
private Planet m_planet; |
57 | 59 |
|
58 | 60 |
private IViewerContainer m_canvas3d; |
61 |
|
|
62 |
private PlanetViewer planetViewer; |
|
59 | 63 |
|
60 | 64 |
// separate lists for image, elevation and vector layers |
61 | 65 |
private ArrayList m_layerLists = new ArrayList(); |
... | ... | |
137 | 141 |
|
138 | 142 |
public void setViewer(IViewerContainer canvas) { |
139 | 143 |
m_canvas3d = canvas; |
144 |
this.planetViewer = (PlanetViewer)m_canvas3d.getOSGViewer(); |
|
140 | 145 |
} |
141 | 146 |
|
142 | 147 |
public IProjection getViewProjection() { |
... | ... | |
151 | 156 |
return m_canvas3d; |
152 | 157 |
} |
153 | 158 |
|
154 |
public void setCanvas3d(IViewerContainer m_canvas3d) { |
|
155 |
this.m_canvas3d = m_canvas3d; |
|
156 |
} |
|
159 |
// public void setCanvas3d(IViewerContainer m_canvas3d) { |
|
160 |
// this.m_canvas3d = m_canvas3d; |
|
161 |
// |
|
162 |
// } |
|
157 | 163 |
|
158 | 164 |
public float getVerticalExageration() { |
159 | 165 |
return verticalExageration; |
... | ... | |
555 | 561 |
layerExtent = new Rectangle2D.Double(-20000000.0, |
556 | 562 |
-10000000.0, 40000000.0, 20000000.0); |
557 | 563 |
// TODO toggle comment because this code use WCS extension. When WCS extension runs correctly uncoment!!! |
558 |
/* |
|
564 |
|
|
559 | 565 |
if (layer instanceof FLyrWCS) |
560 | 566 |
((FLyrWCS) layer).setFullExtent(layerExtent); |
561 |
*/ |
|
567 |
/**/
|
|
562 | 568 |
} |
563 | 569 |
if (props3D.getType() == Layer3DProps.layer3DElevation) |
564 | 570 |
m_planet.addHeightfieldLayer(layerExtent, 3); |
... | ... | |
779 | 785 |
|
780 | 786 |
// UtilCoord.imprimeCamara(cam); |
781 | 787 |
|
782 |
m_canvas3d.getOSGViewer().setCamera(cam);
|
|
788 |
planetViewer.setCamera(cam);
|
|
783 | 789 |
// REPAINTING VIEWER |
784 | 790 |
if (m_canvas3d != null) |
785 | 791 |
m_canvas3d.repaint(); |
... | ... | |
1108 | 1114 |
} |
1109 | 1115 |
|
1110 | 1116 |
public GraphicLayer getGraphicsLayer() { |
1111 |
GraphicLayer3D gra3D = new GraphicLayer3D(getCanvas3d(), getPlanet());
|
|
1117 |
GraphicLayer3D gra3D = new GraphicLayer3D(this.planetViewer, getPlanet());
|
|
1112 | 1118 |
return gra3D; |
1113 | 1119 |
} |
1114 | 1120 |
|
1115 | 1121 |
public Node getSpecialNode() { |
1116 |
return this.m_canvas3d.getOSGViewer().getSpecialNode(0);
|
|
1122 |
return planetViewer.getSpecialNode(0);
|
|
1117 | 1123 |
} |
1118 | 1124 |
|
1119 | 1125 |
public ViewPort getViewPort() { |
... | ... | |
1122 | 1128 |
ViewPort3D vp = (ViewPort3D) super.getViewPort(); |
1123 | 1129 |
|
1124 | 1130 |
|
1125 |
if (m_canvas3d != null) |
|
1126 |
vp.setImageSize(new Dimension(m_canvas3d.getWidth(), m_canvas3d
|
|
1131 |
if (m_canvas3d != null)
|
|
1132 |
vp.setImageSize(new Dimension(planetViewer.getWidth(), planetViewer
|
|
1127 | 1133 |
.getHeight())); |
1128 | 1134 |
vp.setPlanet(this.getPlanet()); |
1129 | 1135 |
vp.setViewer(this.m_canvas3d); |
import/ext3D/branches/ext3D_v1.1/ext3D/src/com/iver/ai2/gvsig3d/map3d/layers/Layer3DProps.java | ||
---|---|---|
6 | 6 |
import java.io.FileReader; |
7 | 7 |
import java.io.FileWriter; |
8 | 8 |
import java.util.HashMap; |
9 |
import java.util.Hashtable; |
|
9 | 10 |
import java.util.Vector; |
10 | 11 |
|
11 | 12 |
import javax.swing.JOptionPane; |
... | ... | |
21 | 22 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
22 | 23 |
import com.iver.cit.gvsig.fmap.layers.FLyrDefault; |
23 | 24 |
import com.iver.cit.gvsig.fmap.layers.FLyrVect; |
25 |
import com.iver.cit.gvsig.fmap.layers.FLyrWCS; |
|
26 |
import com.iver.cit.gvsig.fmap.layers.FLyrWMS; |
|
24 | 27 |
import com.iver.cit.gvsig.fmap.layers.layerOperations.Classifiable; |
25 | 28 |
import com.iver.cit.gvsig.fmap.layers.layerOperations.ClassifiableVectorial; |
26 | 29 |
import com.iver.cit.gvsig.fmap.rendering.ILegend; |
... | ... | |
112 | 115 |
boolean bCanBeElev = false; |
113 | 116 |
|
114 | 117 |
// TODO Un toggle this comment to use WMS extensions |
115 |
/* |
|
118 |
|
|
116 | 119 |
if (layer instanceof FLyrWMS) { |
117 | 120 |
FLyrWMS wmsLayer = (FLyrWMS) layer; |
118 | 121 |
String format = wmsLayer.getFormat(); |
... | ... | |
129 | 132 |
bCanBeElev = true; |
130 | 133 |
} |
131 | 134 |
// FEATURES |
132 |
else */ if (layer instanceof ClassifiableVectorial) { |
|
135 |
else /**/ if (layer instanceof ClassifiableVectorial) {
|
|
133 | 136 |
|
134 | 137 |
vectorLayerMenu = new VectorLayerMenu(this,layer.getName()); |
135 | 138 |
vectorLayerMenu.setModal(true); |
... | ... | |
167 | 170 |
|
168 | 171 |
} else if (layer instanceof FLyrRasterSE) { |
169 | 172 |
FLyrRasterSE rasterLayer = (FLyrRasterSE) layer; |
170 |
/* |
|
171 |
if (rasterLayer.getSource().getNumBands() == 1) |
|
173 |
if (rasterLayer.getBandCount() == 1) |
Also available in: Unified diff