svn-gvsig-desktop / trunk / libraries / lib3DMap / src / com / iver / ai2 / gvsig3d / gui / FeatureFactory.java @ 18219
History | View | Annotate | Download (19.2 KB)
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.osgvp.AutoTransform; |
13 |
import es.upv.ai2.osgvp.Group; |
14 |
import es.upv.ai2.osgvp.Node; |
15 |
import es.upv.ai2.osgvp.Optimizer; |
16 |
import es.upv.ai2.osgvp.Vec3; |
17 |
import es.upv.ai2.osgvp.Vec4; |
18 |
import es.upv.ai2.osgvp.Optimizer.OptimizationOptions; |
19 |
import es.upv.ai2.osgvp.features.PixelPoint; |
20 |
import es.upv.ai2.osgvp.features.Polygon; |
21 |
import es.upv.ai2.osgvp.features.Polyline; |
22 |
import es.upv.ai2.osgvp.features.QuadPoint; |
23 |
import es.upv.ai2.osgvp.features.TessellablePolygon; |
24 |
import es.upv.ai2.osgvp.features.Text; |
25 |
import es.upv.ai2.osgvp.planets.Planet; |
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 |
Double key = (Double) it.next(); |
209 |
List list = (List) hash.get(key); |
210 |
|
211 |
PixelPoint p = new PixelPoint();
|
212 |
// ShapePoint p = new ShapePoint();
|
213 |
// es.upv.ai2.osgvp.features.Sphere s = new Sphere();
|
214 |
// p.setShape(s);
|
215 |
// s.setRadius(100);
|
216 |
for (Iterator iter = list.iterator(); iter.hasNext();) { |
217 |
// Getting PixelPoint
|
218 |
Punto3D element = (Punto3D) iter.next(); |
219 |
// Vec4 color = element.getColor();
|
220 |
Vec4 color = new Vec4(1,0,0,1); |
221 |
|
222 |
// Blending only is active if the alpha component are diferent
|
223 |
// that 1
|
224 |
if (color.w() != 1) { |
225 |
p.setEnabledBlending(true);
|
226 |
} |
227 |
// Enabling antialiasing
|
228 |
p.setEnabledSmoothing(true);
|
229 |
|
230 |
// Set up size, position and color
|
231 |
// p.setPointSize(element.getZize());
|
232 |
p.setPointSize(20);
|
233 |
p.setLightingMode(Node.Mode.OFF | Node.Mode.PROTECTED); |
234 |
p.addPoint(element.getPosition(), color); |
235 |
// System.err.println("posicion del punto " +element.getPosition());
|
236 |
} |
237 |
// Adding points to group
|
238 |
g.addChild(p); |
239 |
} |
240 |
// System.out.println("nuevo grupo");
|
241 |
|
242 |
// Optimizer generated nodes
|
243 |
// Optimizer opt = new Optimizer();
|
244 |
// opt.optimize(g, OptimizationOptions.SPATIALIZE_GROUPS);
|
245 |
|
246 |
return g;
|
247 |
} |
248 |
|
249 |
/**
|
250 |
* Method to add 3D points to specific point type. With a color, heigth and
|
251 |
* position.
|
252 |
*
|
253 |
* @param point
|
254 |
* Node to add new 3D point
|
255 |
* @param position
|
256 |
* Position of 3D text in cartesian coordinates
|
257 |
* @param color
|
258 |
* color of the 3D point
|
259 |
* @param tam
|
260 |
* the heigth of the point
|
261 |
* @return New text node
|
262 |
*/
|
263 |
public static void addPointToNode(Node point, Vec3 position, Vec4 color, |
264 |
int tam) {
|
265 |
|
266 |
PixelPoint p = null;
|
267 |
// Getting point
|
268 |
if (point != null) |
269 |
p = (PixelPoint) point; |
270 |
|
271 |
// If not exits create new
|
272 |
if (p == null) |
273 |
p = new PixelPoint();
|
274 |
|
275 |
// Blending only is active if the alpha component are diferent that 1
|
276 |
if (color.w() != 1) { |
277 |
p.setEnabledBlending(true);
|
278 |
} |
279 |
|
280 |
// Set up size, position and color
|
281 |
p.setPointSize(tam); |
282 |
p.addPoint(position, color); |
283 |
|
284 |
// Optimizer generated nodes
|
285 |
Optimizer opt = new Optimizer();
|
286 |
opt.optimize(p, OptimizationOptions.SPATIALIZE_GROUPS); |
287 |
|
288 |
} |
289 |
|
290 |
/**
|
291 |
* Method to create a new 3D line. With a color, heigth and position.
|
292 |
*
|
293 |
* @param ini
|
294 |
* Initial position of line
|
295 |
* @param end
|
296 |
* End positon of line.
|
297 |
* @param color
|
298 |
* color of the 3D point
|
299 |
* @param tam
|
300 |
* the heigth of the point
|
301 |
* @return New line node
|
302 |
*/
|
303 |
|
304 |
public static Node insertLineS(Vec3 ini, Vec3 end, Vec4 color, int tam) { |
305 |
// Creating a polyline
|
306 |
Polyline p = new Polyline(ini, end);
|
307 |
|
308 |
// Set up parameter
|
309 |
p.setWidth(2f);
|
310 |
p.setPattern((short) 0xFFFF); |
311 |
p.setFactor(2);
|
312 |
p.setColor(color); |
313 |
|
314 |
// Optimize the node
|
315 |
Optimizer opt = new Optimizer();
|
316 |
opt.optimize(p); |
317 |
|
318 |
// Return the node
|
319 |
return p;
|
320 |
} |
321 |
|
322 |
/**
|
323 |
* Method to add new points to specific line type. With a color, heigth and
|
324 |
* position.
|
325 |
*
|
326 |
* @param line
|
327 |
* Node to add new point
|
328 |
* @param position
|
329 |
* Position of 3D point in cartesian coordinates
|
330 |
* @param color
|
331 |
* color of the 3D point
|
332 |
* @param tam
|
333 |
* the heigth of the point
|
334 |
*/
|
335 |
public static void addNodeToLine(Node line, Vec3 position, Vec4 color, |
336 |
int tam) {
|
337 |
// Getting polyline
|
338 |
Polyline p = (Polyline) line; |
339 |
|
340 |
// If not exits, create a new
|
341 |
if (p == null) |
342 |
p = new Polyline(position, position);
|
343 |
|
344 |
// Add a point and color
|
345 |
p.addVertex(position, color); |
346 |
|
347 |
} |
348 |
|
349 |
/**
|
350 |
* Create a new point node with a color and size. Using a position of 3D
|
351 |
* points
|
352 |
*
|
353 |
* @param position
|
354 |
* Position of 3D point
|
355 |
* @param color
|
356 |
* Color of the 3D point
|
357 |
* @param tam
|
358 |
* Size of the point (in pixels)
|
359 |
* @return
|
360 |
*/
|
361 |
public static Node insertPointS(Vec3[] position, Vec4 color, int tam) { |
362 |
// Creating point node
|
363 |
PixelPoint p = new PixelPoint();
|
364 |
|
365 |
// Set up parameters and insert position
|
366 |
for (int i = 0; i < position.length; i++) { |
367 |
p.setPointSize(tam); |
368 |
p.addPoint(position[i], color); |
369 |
} |
370 |
|
371 |
// Optimizer generated nodes
|
372 |
Optimizer opt = new Optimizer();
|
373 |
opt.optimize(p, OptimizationOptions.SPATIALIZE_GROUPS); |
374 |
|
375 |
// Return node
|
376 |
return p;
|
377 |
} |
378 |
|
379 |
/**
|
380 |
* Create a new quad point node with a color, size and texture. Using a position of 3D
|
381 |
* points
|
382 |
*
|
383 |
* @param position
|
384 |
* Position of 3D point
|
385 |
* @param color
|
386 |
* Color of the 3D point
|
387 |
* @param tam
|
388 |
* Size of the point (in pixels)
|
389 |
* @return
|
390 |
*/
|
391 |
public static Node insertQuadPoints(Vec3[] position, Vec4 color, float tam, String texture) { |
392 |
// Creating point node
|
393 |
QuadPoint p = new QuadPoint(tam);
|
394 |
|
395 |
// Set up parameters and insert position
|
396 |
for (int i = 0; i < position.length; i++) { |
397 |
p.setPointSize(tam); |
398 |
p.addPoint(position[i], color); |
399 |
} |
400 |
|
401 |
// if (texture!=null)
|
402 |
// p.setTexture(texture);
|
403 |
|
404 |
p.setBillboardingEnabled(true);
|
405 |
|
406 |
|
407 |
// Optimizer generated nodes
|
408 |
Optimizer opt = new Optimizer();
|
409 |
opt.optimize(p, OptimizationOptions.SPATIALIZE_GROUPS); |
410 |
|
411 |
// Return node
|
412 |
return p;
|
413 |
} |
414 |
/**
|
415 |
* Create a new tesselation poligon with a color using an array of 3D points
|
416 |
*
|
417 |
* @param points
|
418 |
* Array of 3D points
|
419 |
* @param color
|
420 |
* Color of the poligon
|
421 |
* @return Poligon node
|
422 |
*/
|
423 |
public static Node generateQuadPoligon(Vec3 position, Vec4 color,String texture,float tam) { |
424 |
// Creating a polygon
|
425 |
TessellablePolygon p = new TessellablePolygon();
|
426 |
|
427 |
// PositionAttitudeTransform pt = new PositionAttitudeTransform();
|
428 |
AutoTransform pt = new AutoTransform();
|
429 |
pt.addChild(p); |
430 |
pt.setPosition(position); |
431 |
pt.setAutoRotateMode(AutoTransform.AutoRotateMode.ROTATE_TO_CAMERA); |
432 |
// Set up parameters
|
433 |
// p.setType(Polygon.PolygonType.FILLED_POLYGON);
|
434 |
p.setWidth(2f);
|
435 |
// p.setPattern((short) 0xFFFF);
|
436 |
// p.setFactor(2);
|
437 |
p.setType(Polygon.PolygonType.FILLED_POLYGON);
|
438 |
// p.setType(Polygon.PolygonType.EMPTY_POLYGON);
|
439 |
// p.setType(Polygon.PolygonType.PATTERN_POLYGON);
|
440 |
|
441 |
Vec3 bl = new Vec3(-tam/2,-tam/2,0.0); |
442 |
Vec3 br = new Vec3(tam/2,-tam/2,0.0); |
443 |
Vec3 tr = new Vec3(tam/2,tam/2,0.0); |
444 |
Vec3 tl = new Vec3(-tam/2,tam/2,0.0); |
445 |
p.setEnabledBlending(true);
|
446 |
|
447 |
p.addVertex(bl, color); |
448 |
p.addVertex(tl, color); |
449 |
p.addVertex(tr, color); |
450 |
p.addVertex(br, color); |
451 |
|
452 |
p.setTwoSidedLighting(true);
|
453 |
|
454 |
// if there was any texture to put we would include it
|
455 |
if (texture != null) |
456 |
p.setTexture(texture); |
457 |
// Tesselation of this poligon
|
458 |
p.tesselate(); |
459 |
|
460 |
// Optimizer generated nodes
|
461 |
// Optimizer opt = new Optimizer();
|
462 |
// opt.optimize(pt, OptimizationOptions.SPATIALIZE_GROUPS);
|
463 |
|
464 |
// Return node
|
465 |
return pt;
|
466 |
} |
467 |
|
468 |
/**
|
469 |
* Create a new tesselation poligon with a color using an array of 3D points
|
470 |
*
|
471 |
* @param points
|
472 |
* Array of 3D points
|
473 |
* @param color
|
474 |
* Color of the poligon
|
475 |
* @return Poligon node
|
476 |
*/
|
477 |
public static Node insertPolygon(Vec3[] points, Vec4 color,String texture) { |
478 |
// Creating a polygon
|
479 |
TessellablePolygon p = new TessellablePolygon();
|
480 |
|
481 |
// Set up parameters
|
482 |
// p.setType(Polygon.PolygonType.FILLED_POLYGON);
|
483 |
p.setWidth(2f);
|
484 |
// p.setPattern((short) 0xFFFF);
|
485 |
// p.setFactor(2);
|
486 |
p.setType(Polygon.PolygonType.FILLED_POLYGON);
|
487 |
// p.setType(Polygon.PolygonType.EMPTY_POLYGON);
|
488 |
// p.setType(Polygon.PolygonType.PATTERN_POLYGON);
|
489 |
|
490 |
// Adding points
|
491 |
for (int i = 0; i < points.length - 1; i++) { |
492 |
p.addVertex(points[i], color); |
493 |
// System.out.println("Position: " + inv[i].x() + " " + inv[i].y() +
|
494 |
// " " + inv[i].z());
|
495 |
} |
496 |
// if there was any texture to put we would include it
|
497 |
if (texture != null) |
498 |
p.setTexture(texture); |
499 |
// Tesselation of this poligon
|
500 |
p.tesselate(); |
501 |
|
502 |
// Optimizer generated nodes
|
503 |
Optimizer opt = new Optimizer();
|
504 |
opt.optimize(p, OptimizationOptions.SPATIALIZE_GROUPS); |
505 |
|
506 |
// Return node
|
507 |
return p;
|
508 |
} |
509 |
|
510 |
|
511 |
|
512 |
/**
|
513 |
* Create a new tesselation poligon with a color using an List of 3D points
|
514 |
*
|
515 |
* @param points
|
516 |
* List of 3D points
|
517 |
* @param color
|
518 |
* Color of the poligon
|
519 |
* @return Poligon node
|
520 |
*/
|
521 |
public static Node insertPolygon(List points, Vec4 color,String texture) { |
522 |
// Creating a polygon
|
523 |
TessellablePolygon p = new TessellablePolygon();
|
524 |
|
525 |
// Set up parameters
|
526 |
// p.setType(Polygon.PolygonType.FILLED_POLYGON);
|
527 |
p.setWidth(2f);
|
528 |
// p.setPattern((short) 0xFFFF);
|
529 |
// p.setFactor(2);
|
530 |
p.setType(Polygon.PolygonType.FILLED_POLYGON);
|
531 |
// p.setType(Polygon.PolygonType.EMPTY_POLYGON);
|
532 |
// p.setType(Polygon.PolygonType.PATTERN_POLYGON);
|
533 |
|
534 |
// Blending only is active if the alpha component are diferent that 1
|
535 |
if (color.w() != 1) { |
536 |
p.setEnabledBlending(true);
|
537 |
} |
538 |
// Adding points
|
539 |
for (int i = 0; i < points.size(); i++) { |
540 |
Vec3 element = (Vec3) points.get(i); |
541 |
p.addVertex(element, color); |
542 |
} |
543 |
|
544 |
|
545 |
// p.setTexture("C:/modelos3d/Images/land_shallow_topo_2048.jpg");
|
546 |
// if there was any texture to put we would include it
|
547 |
if (texture != null) |
548 |
p.setTexture(texture); |
549 |
// Tesselation of this poligon
|
550 |
p.tesselate(); |
551 |
|
552 |
// Optimizer generated nodes
|
553 |
Optimizer opt = new Optimizer();
|
554 |
opt.optimize(p, OptimizationOptions.ALL_OPTIMIZATIONS); |
555 |
|
556 |
// Return node
|
557 |
return p;
|
558 |
} |
559 |
|
560 |
/**
|
561 |
* Method to create a new 3D line. With a List of 3D points and a color
|
562 |
*
|
563 |
* @param points
|
564 |
* List of 3D points
|
565 |
* @param color
|
566 |
* Color of the line
|
567 |
* @return
|
568 |
*
|
569 |
*/
|
570 |
public static Node insertLine(List points, Vec4 color, float size) { |
571 |
Vec3 ori = null, fin = null; |
572 |
|
573 |
// Getting first points
|
574 |
if (points.size() > 1) { |
575 |
ori = (Vec3) points.get(0);
|
576 |
fin = (Vec3) points.get(1);
|
577 |
} |
578 |
|
579 |
// If the line do not have more than 2 points return null
|
580 |
if ((ori == null) || (fin == null)) |
581 |
return null; |
582 |
|
583 |
// Create new polyline
|
584 |
Polyline p = new Polyline(ori, fin);
|
585 |
p.setVertexColor(0, color);
|
586 |
p.setVertexColor(1, color);
|
587 |
|
588 |
// Set up parameters
|
589 |
p.setWidth(size); |
590 |
p.setPattern((short) 0xFFFF); |
591 |
p.setFactor(2);
|
592 |
|
593 |
// Blending only is active if the alpha component are diferent that 1
|
594 |
if (color.w() != 1) { |
595 |
p.setEnabledBlending(true);
|
596 |
} |
597 |
|
598 |
// Enabling antialiasing
|
599 |
p.setEnabledSmoothing(true);
|
600 |
|
601 |
p.setColor(color); |
602 |
|
603 |
// Adding points
|
604 |
for (int i = 2; i < points.size(); i++) { |
605 |
Vec3 element = (Vec3) points.get(i); |
606 |
p.addVertex(element, color); |
607 |
} |
608 |
|
609 |
// Optimizer generated nodes
|
610 |
Optimizer opt = new Optimizer();
|
611 |
opt.optimize(p); |
612 |
|
613 |
// Return node
|
614 |
return p;
|
615 |
|
616 |
} |
617 |
|
618 |
/**
|
619 |
* Create a new group of 3D points with a color and size. Using a List of 3D
|
620 |
* points
|
621 |
*
|
622 |
* @param points
|
623 |
* List of 3D points
|
624 |
* @param color
|
625 |
* Color of the line
|
626 |
* @param size
|
627 |
* Size of the point (in pixels)
|
628 |
* @return
|
629 |
*/
|
630 |
public static Node insertPoints(List points, Vec4 color, float size) { |
631 |
// Creating point
|
632 |
PixelPoint p = new PixelPoint();
|
633 |
|
634 |
// Set up parameters
|
635 |
p.setPointSize(size); |
636 |
|
637 |
// Adding points
|
638 |
for (int i = 0; i < points.size(); i++) { |
639 |
Vec3 element = (Vec3) points.get(i); |
640 |
p.addPoint(element, color); |
641 |
} |
642 |
|
643 |
// Optimizer generated nodes
|
644 |
Optimizer opt = new Optimizer();
|
645 |
opt.optimize(p); |
646 |
|
647 |
// Return node
|
648 |
return p;
|
649 |
|
650 |
} |
651 |
|
652 |
/**
|
653 |
* Create a new group of 3D labels with a size and heigth. Using a List of
|
654 |
* 3D points
|
655 |
*
|
656 |
* @param labels
|
657 |
* List of Flabels
|
658 |
*
|
659 |
* @param size
|
660 |
* Size of the labels
|
661 |
* @param heigth
|
662 |
* Heigth of labels
|
663 |
* @param inPixels
|
664 |
* True indicates that size is in pixel and false indicates real
|
665 |
* size;
|
666 |
* @param type
|
667 |
* @return Node group
|
668 |
*/
|
669 |
public static Node insertLabels(List labels, int size, float heigth, |
670 |
boolean inPixels, int planetType) { |
671 |
// Creating a group node
|
672 |
Group p = new Group(); |
673 |
|
674 |
// Getting total size
|
675 |
int total = labels.size();
|
676 |
|
677 |
// this is for control a max of labels because the system not suport
|
678 |
// more than 10000
|
679 |
int max = 3000; |
680 |
if (total > max)
|
681 |
total = max; |
682 |
|
683 |
if (labels != null) { |
684 |
for (int i = 0; i < total; i++) { |
685 |
FLabel f = (FLabel) labels.get(i); |
686 |
|
687 |
// Set up parameters
|
688 |
|
689 |
// Getting color
|
690 |
// Color co = f.getColor();
|
691 |
Color co = new Color(255, 255, 255, 255); |
692 |
float r, g, b, a;
|
693 |
r = ((float) co.getRed()) / 255.0f; |
694 |
g = ((float) co.getGreen()) / 255.0f; |
695 |
b = ((float) co.getBlue()) / 255.0f; |
696 |
a = ((float) co.getAlpha()) / 255.0f; |
697 |
// Set color
|
698 |
Vec4 textColor = new Vec4(r, g, b, a);
|
699 |
|
700 |
// Get label name
|
701 |
String label = f.getString();
|
702 |
// double heigth = h;
|
703 |
Vec3 pos = null;
|
704 |
if (planetType == Planet.CoordinateSystemType.PROJECTED) {
|
705 |
pos = new Vec3(f.getOrig().getX(), f.getOrig().getY(),
|
706 |
heigth); |
707 |
} else {
|
708 |
// Transform geodesical coordinates to cartesian
|
709 |
Vec3 posGeo = new Vec3(f.getOrig().getY(), f.getOrig()
|
710 |
.getX(), heigth); |
711 |
|
712 |
pos = planet.convertLatLongHeightToXYZ(posGeo); |
713 |
} |
714 |
|
715 |
// Adding new child text nodes
|
716 |
p.addChild(insertTextoS(label, pos, textColor, size, inPixels)); |
717 |
} |
718 |
} |
719 |
|
720 |
// Optimizer generated nodes
|
721 |
Optimizer opt = new Optimizer();
|
722 |
opt.optimize(p, OptimizationOptions.SPATIALIZE_GROUPS); |
723 |
|
724 |
return p;
|
725 |
|
726 |
} |
727 |
|
728 |
} |