svn-gvsig-desktop / trunk / libraries / lib3DMap / src / com / iver / ai2 / gvsig3d / gui / FeatureFactory.java @ 18954
History | View | Annotate | Download (19.4 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 |
import java.util.Vector; |
8 |
|
9 |
import com.iver.ai2.gvsig3d.resources.ResourcesFactory; |
10 |
import com.iver.ai2.gvsig3d.utils.Punto3D; |
11 |
import com.iver.cit.gvsig.fmap.core.v02.FLabel; |
12 |
|
13 |
import es.upv.ai2.osgvp.AutoTransform; |
14 |
import es.upv.ai2.osgvp.Group; |
15 |
import es.upv.ai2.osgvp.Node; |
16 |
import es.upv.ai2.osgvp.Optimizer; |
17 |
import es.upv.ai2.osgvp.Vec3; |
18 |
import es.upv.ai2.osgvp.Vec4; |
19 |
import es.upv.ai2.osgvp.Optimizer.OptimizationOptions; |
20 |
import es.upv.ai2.osgvp.features.PixelPoint; |
21 |
import es.upv.ai2.osgvp.features.Polygon; |
22 |
import es.upv.ai2.osgvp.features.Polyline; |
23 |
import es.upv.ai2.osgvp.features.QuadPoint; |
24 |
import es.upv.ai2.osgvp.features.TessellablePolygon; |
25 |
import es.upv.ai2.osgvp.features.Text; |
26 |
import es.upv.ai2.osgvp.planets.Planet; |
27 |
|
28 |
public class FeatureFactory extends Group { |
29 |
|
30 |
private static double radius; |
31 |
|
32 |
static Planet planet;
|
33 |
|
34 |
public FeatureFactory(double ra, Planet m_planet) { |
35 |
super();
|
36 |
radius = ra; |
37 |
// this.setNodeName("VECTOR");
|
38 |
planet = m_planet; |
39 |
init(); |
40 |
} |
41 |
|
42 |
private void init() { |
43 |
|
44 |
// this.addChild(insertTexto("Polo norte", poloNorte));
|
45 |
// this.addChild(insertTexto("MADRID", valenciaCar));
|
46 |
|
47 |
// Vec3 posIni = new Vec3(0, 0, 0);
|
48 |
// Vec3 posEnd = new Vec3(0, 0, 100000);
|
49 |
|
50 |
// Polyline line = (Polyline) VectorTest.insertLineS(posIni, posEnd,
|
51 |
// new Vec4(1.0, 1.0, 1.0, 1.0), 0);
|
52 |
// if (planet.getType() == PlanetType.PLANE_MODE)
|
53 |
// this.addChild(line);
|
54 |
|
55 |
} |
56 |
|
57 |
// public Node insertTexto(String texto, Vec3 posicion) {
|
58 |
// // A�adiendo texto
|
59 |
// Text text = new Text();
|
60 |
// // text.setNodeName(texto);
|
61 |
// text.setText(texto);
|
62 |
// text.setCharacterSize(32);
|
63 |
//
|
64 |
// text.setAxisAlignment(Text.AxisAlignment.SCREEN);
|
65 |
// text.setAlignment(Text.AlignmentType.CENTER_CENTER);
|
66 |
// text.setCharacterSizeMode(Text.CharacterSizeMode.SCREEN_COORDS);
|
67 |
// text.setPosition((float) posicion.x(), (float) posicion.y(),
|
68 |
// (float) posicion.z());
|
69 |
//
|
70 |
// if (ResourcesFactory.exitsResouce("arial.ttf"))
|
71 |
// text.setFont(ResourcesFactory.getResourcePath("arial.ttf"));
|
72 |
// else
|
73 |
// text.setFont("arial.ttf");
|
74 |
// text.setAutoRotateToScreen(true);
|
75 |
//
|
76 |
//
|
77 |
// Optimizer opt = new Optimizer();
|
78 |
// opt.optimizeOptions(text, OptimizationOptions.SPATIALIZE_GROUPS);
|
79 |
//
|
80 |
// return text;
|
81 |
// }
|
82 |
// /**
|
83 |
// * this method create a new 3D text. With a value and position. And insert
|
84 |
// a
|
85 |
// * point under 3D text
|
86 |
// *
|
87 |
// * @param texto
|
88 |
// * text that is visible in 3D
|
89 |
// * @param position
|
90 |
// * Position of 3D text in cartesian coordinates
|
91 |
// * @return New node
|
92 |
// */
|
93 |
// public void insertText(String texto, Vec3 posicion) {
|
94 |
// posicion.setZ(posicion.z() + radius);
|
95 |
// Vec3 e = planet.convertLatLongHeightToXYZ(posicion);
|
96 |
//
|
97 |
// this.addChild(insertPoint(e, new Vec4(1.0, 0, 0, 1.0)));
|
98 |
//
|
99 |
// this.addChild(insertTexto(texto, e));
|
100 |
// }
|
101 |
//
|
102 |
// /**
|
103 |
// * this method create a new 3D point. With a color and position
|
104 |
// *
|
105 |
// * @param color
|
106 |
// * Color of the point
|
107 |
// * @param position
|
108 |
// * Position of 3D point in cartesian coordinates
|
109 |
// * @return
|
110 |
// */
|
111 |
// public Node insertPoint(Vec3 position, Vec4 color) {
|
112 |
// // Creating point
|
113 |
// Point p = new Point();
|
114 |
//
|
115 |
// // Adding position and color
|
116 |
// for (int i = 0; i < 1; i++) {
|
117 |
// p.setPointSize(100);
|
118 |
// p.addPoint(position, color);
|
119 |
// }
|
120 |
//
|
121 |
// return p;
|
122 |
// }
|
123 |
|
124 |
/**
|
125 |
* Method to create a new 3D text. With a value and position. Text aligment
|
126 |
* is LEFT CENTER, and his font is "Arial.ttf"
|
127 |
*
|
128 |
* @param texto
|
129 |
* Text that is visible in 3D
|
130 |
* @param position
|
131 |
* Position of 3D text in cartesian coordinates
|
132 |
* @return New node
|
133 |
*/
|
134 |
public static Node insertTextoS(String texto, Vec3 position, Vec4 color, |
135 |
int tam, boolean inPixels) { |
136 |
|
137 |
// Creating text node
|
138 |
Text text = new Text();
|
139 |
// Set up text properties
|
140 |
text.setText(texto); |
141 |
text.setCharacterSize(tam); |
142 |
// Select that the text will be in pixels or screen coordinates
|
143 |
if (inPixels) {
|
144 |
text.setCharacterSizeMode(Text.CharacterSizeMode.SCREEN_COORDS); |
145 |
} else {
|
146 |
text.setCharacterSizeMode(Text.CharacterSizeMode.OBJECT_COORDS); |
147 |
} |
148 |
text.setColor(color); |
149 |
text.setAxisAlignment(Text.AxisAlignment.SCREEN); |
150 |
text.setAlignment(Text.AlignmentType.LEFT_BOTTOM); |
151 |
text.setPosition((float) position.x(), (float) position.y(), |
152 |
(float) position.z());
|
153 |
|
154 |
// Search font in resources directori
|
155 |
if (ResourcesFactory.exitsResouce("arial.ttf")) |
156 |
text.setFont(ResourcesFactory.getResourcePath("arial.ttf"));
|
157 |
else
|
158 |
text.setFont("arial.ttf");
|
159 |
text.setAutoRotateToScreen(true);
|
160 |
|
161 |
// Optimizer generated nodes
|
162 |
Optimizer opt = new Optimizer();
|
163 |
opt.optimize(text, OptimizationOptions.SPATIALIZE_GROUPS); |
164 |
|
165 |
// Return node
|
166 |
return text;
|
167 |
|
168 |
} |
169 |
|
170 |
/**
|
171 |
* Method to create a new 3D point. With a color, heigth and position.
|
172 |
*
|
173 |
* @param position
|
174 |
* Position of 3D text in cartesian coordinates
|
175 |
* @param color
|
176 |
* color of the 3D point
|
177 |
* @param tam
|
178 |
* the heigth of the point
|
179 |
* @return New text node
|
180 |
*/
|
181 |
public static Node insertPointS(Vec3 position, Vec4 color, int tam) { |
182 |
AutoTransform au = new AutoTransform();
|
183 |
// Creating point
|
184 |
PixelPoint p = new PixelPoint();
|
185 |
// p.setDistanceAttenuation(new Vec3(0.0,0.0,0.0000001));
|
186 |
p.setPointSize(tam); |
187 |
p.addPoint(position, color); |
188 |
|
189 |
au.addChild(p); |
190 |
// return au;
|
191 |
return p;
|
192 |
} |
193 |
|
194 |
/**
|
195 |
* Method to create a new 3D point. With a color, heigth and position.
|
196 |
*
|
197 |
* @param hash
|
198 |
* Hash Table that contains "Puntos3D" elements
|
199 |
* @return
|
200 |
*/
|
201 |
public static Node insertPointS(HashMap hash) { |
202 |
|
203 |
Group g = new Group(); |
204 |
|
205 |
// Iterate over the keys in the map
|
206 |
Iterator it = hash.keySet().iterator();
|
207 |
while (it.hasNext()) {
|
208 |
// Get key
|
209 |
Double key = (Double) it.next(); |
210 |
List list = (List) hash.get(key); |
211 |
|
212 |
PixelPoint p = new PixelPoint();
|
213 |
// ShapePoint p = new ShapePoint();
|
214 |
// es.upv.ai2.osgvp.features.Sphere s = new Sphere();
|
215 |
// p.setShape(s);
|
216 |
// s.setRadius(100);
|
217 |
for (Iterator iter = list.iterator(); iter.hasNext();) { |
218 |
// Getting PixelPoint
|
219 |
Punto3D element = (Punto3D) iter.next(); |
220 |
// Vec4 color = element.getColor();
|
221 |
Vec4 color = new Vec4(1,0,0,1); |
222 |
|
223 |
// Blending only is active if the alpha component are diferent
|
224 |
// that 1
|
225 |
if (color.w() != 1) { |
226 |
p.setEnabledBlending(true);
|
227 |
} |
228 |
// Enabling antialiasing
|
229 |
p.setEnabledSmoothing(true);
|
230 |
|
231 |
// Set up size, position and color
|
232 |
// p.setPointSize(element.getZize());
|
233 |
p.setPointSize(20);
|
234 |
p.setLightingMode(Node.Mode.OFF | Node.Mode.PROTECTED); |
235 |
p.addPoint(element.getPosition(), color); |
236 |
// System.err.println("posicion del punto " +element.getPosition());
|
237 |
} |
238 |
// Adding points to group
|
239 |
g.addChild(p); |
240 |
} |
241 |
// System.out.println("nuevo grupo");
|
242 |
|
243 |
// Optimizer generated nodes
|
244 |
// Optimizer opt = new Optimizer();
|
245 |
// opt.optimize(g, OptimizationOptions.SPATIALIZE_GROUPS);
|
246 |
|
247 |
return g;
|
248 |
} |
249 |
|
250 |
/**
|
251 |
* Method to add 3D points to specific point type. With a color, heigth and
|
252 |
* position.
|
253 |
*
|
254 |
* @param point
|
255 |
* Node to add new 3D point
|
256 |
* @param position
|
257 |
* Position of 3D text in cartesian coordinates
|
258 |
* @param color
|
259 |
* color of the 3D point
|
260 |
* @param tam
|
261 |
* the heigth of the point
|
262 |
* @return New text node
|
263 |
*/
|
264 |
public static void addPointToNode(Node point, Vec3 position, Vec4 color, |
265 |
int tam) {
|
266 |
|
267 |
PixelPoint p = null;
|
268 |
// Getting point
|
269 |
if (point != null) |
270 |
p = (PixelPoint) point; |
271 |
|
272 |
// If not exits create new
|
273 |
if (p == null) |
274 |
p = new PixelPoint();
|
275 |
|
276 |
// Blending only is active if the alpha component are diferent that 1
|
277 |
if (color.w() != 1) { |
278 |
p.setEnabledBlending(true);
|
279 |
} |
280 |
|
281 |
// Set up size, position and color
|
282 |
p.setPointSize(tam); |
283 |
p.addPoint(position, color); |
284 |
|
285 |
// Optimizer generated nodes
|
286 |
Optimizer opt = new Optimizer();
|
287 |
opt.optimize(p, OptimizationOptions.SPATIALIZE_GROUPS); |
288 |
|
289 |
} |
290 |
|
291 |
/**
|
292 |
* Method to create a new 3D line. With a color, heigth and position.
|
293 |
*
|
294 |
* @param ini
|
295 |
* Initial position of line
|
296 |
* @param end
|
297 |
* End positon of line.
|
298 |
* @param color
|
299 |
* color of the 3D point
|
300 |
* @param tam
|
301 |
* the heigth of the point
|
302 |
* @return New line node
|
303 |
*/
|
304 |
|
305 |
public static Node insertLineS(Vec3 ini, Vec3 end, Vec4 color, int tam) { |
306 |
// Creating a polyline
|
307 |
Polyline p = new Polyline(ini, end);
|
308 |
|
309 |
// Set up parameter
|
310 |
p.setWidth(2f);
|
311 |
p.setPattern((short) 0xFFFF); |
312 |
p.setFactor(2);
|
313 |
p.setColor(color); |
314 |
|
315 |
// Optimize the node
|
316 |
Optimizer opt = new Optimizer();
|
317 |
opt.optimize(p); |
318 |
|
319 |
// Return the node
|
320 |
return p;
|
321 |
} |
322 |
|
323 |
/**
|
324 |
* Method to add new points to specific line type. With a color, heigth and
|
325 |
* position.
|
326 |
*
|
327 |
* @param line
|
328 |
* Node to add new point
|
329 |
* @param position
|
330 |
* Position of 3D point in cartesian coordinates
|
331 |
* @param color
|
332 |
* color of the 3D point
|
333 |
* @param tam
|
334 |
* the heigth of the point
|
335 |
*/
|
336 |
public static void addNodeToLine(Node line, Vec3 position, Vec4 color, |
337 |
int tam) {
|
338 |
// Getting polyline
|
339 |
Polyline p = (Polyline) line; |
340 |
|
341 |
// If not exits, create a new
|
342 |
if (p == null) |
343 |
p = new Polyline(position, position);
|
344 |
|
345 |
// Add a point and color
|
346 |
p.addVertex(position, color); |
347 |
|
348 |
} |
349 |
|
350 |
/**
|
351 |
* Create a new point node with a color and size. Using a position of 3D
|
352 |
* points
|
353 |
*
|
354 |
* @param position
|
355 |
* Position of 3D point
|
356 |
* @param color
|
357 |
* Color of the 3D point
|
358 |
* @param tam
|
359 |
* Size of the point (in pixels)
|
360 |
* @return
|
361 |
*/
|
362 |
public static Node insertPointS(Vec3[] position, Vec4 color, int tam) { |
363 |
// Creating point node
|
364 |
PixelPoint p = new PixelPoint();
|
365 |
|
366 |
// Set up parameters and insert position
|
367 |
for (int i = 0; i < position.length; i++) { |
368 |
p.setPointSize(tam); |
369 |
p.addPoint(position[i], color); |
370 |
} |
371 |
|
372 |
// Optimizer generated nodes
|
373 |
Optimizer opt = new Optimizer();
|
374 |
opt.optimize(p, OptimizationOptions.SPATIALIZE_GROUPS); |
375 |
|
376 |
// Return node
|
377 |
return p;
|
378 |
} |
379 |
|
380 |
/**
|
381 |
* Create a new quad point node with a color, size and texture. Using a position of 3D
|
382 |
* points
|
383 |
*
|
384 |
* @param position
|
385 |
* Position of 3D point
|
386 |
* @param color
|
387 |
* Color of the 3D point
|
388 |
* @param tam
|
389 |
* Size of the point (in pixels)
|
390 |
* @return
|
391 |
*/
|
392 |
public static Node insertQuadPoints(Vec3[] position, Vec4 color, float tam, String texture) { |
393 |
// Creating point node
|
394 |
QuadPoint p = new QuadPoint(tam);
|
395 |
|
396 |
// Set up parameters and insert position
|
397 |
for (int i = 0; i < position.length; i++) { |
398 |
p.setPointSize(tam); |
399 |
p.addPoint(position[i], color); |
400 |
} |
401 |
|
402 |
// if (texture!=null)
|
403 |
// p.setTexture(texture);
|
404 |
|
405 |
p.setBillboardingEnabled(true);
|
406 |
|
407 |
|
408 |
// Optimizer generated nodes
|
409 |
Optimizer opt = new Optimizer();
|
410 |
opt.optimize(p, OptimizationOptions.SPATIALIZE_GROUPS); |
411 |
|
412 |
// Return node
|
413 |
return p;
|
414 |
} |
415 |
/**
|
416 |
* Create a new tesselation poligon with a color using an array of 3D points
|
417 |
*
|
418 |
* @param points
|
419 |
* Array of 3D points
|
420 |
* @param color
|
421 |
* Color of the poligon
|
422 |
* @return Poligon node
|
423 |
*/
|
424 |
public static Node generateQuadPoligon(Vec3 position, Vec4 color,String texture,float tam) { |
425 |
// Creating a polygon
|
426 |
TessellablePolygon p = new TessellablePolygon();
|
427 |
|
428 |
// PositionAttitudeTransform pt = new PositionAttitudeTransform();
|
429 |
AutoTransform pt = new AutoTransform();
|
430 |
pt.addChild(p); |
431 |
pt.setPosition(position); |
432 |
pt.setAutoRotateMode(AutoTransform.AutoRotateMode.ROTATE_TO_CAMERA); |
433 |
// Set up parameters
|
434 |
// p.setType(Polygon.PolygonType.FILLED_POLYGON);
|
435 |
p.setWidth(2f);
|
436 |
// p.setPattern((short) 0xFFFF);
|
437 |
// p.setFactor(2);
|
438 |
p.setType(Polygon.PolygonType.FILLED_POLYGON);
|
439 |
// p.setType(Polygon.PolygonType.EMPTY_POLYGON);
|
440 |
// p.setType(Polygon.PolygonType.PATTERN_POLYGON);
|
441 |
|
442 |
Vec3 bl = new Vec3(-tam/2,-tam/2,0.0); |
443 |
Vec3 br = new Vec3(tam/2,-tam/2,0.0); |
444 |
Vec3 tr = new Vec3(tam/2,tam/2,0.0); |
445 |
Vec3 tl = new Vec3(-tam/2,tam/2,0.0); |
446 |
p.setEnabledBlending(true);
|
447 |
// Vector<Vec3> normal = new Vector<Vec3>();
|
448 |
// normal.add(new Vec3(0,0,1));
|
449 |
// p.setNormalArray(normal);
|
450 |
// p.setNormalBinding(Geometry.AttributeBinding.BIND_OVERALL);
|
451 |
|
452 |
p.setLightingMode(Mode.OFF | Mode.PROTECTED); |
453 |
p.addVertex(bl, color); |
454 |
p.addVertex(tl, color); |
455 |
p.addVertex(tr, color); |
456 |
p.addVertex(br, color); |
457 |
|
458 |
// p.setTwoSidedLighting(true);
|
459 |
|
460 |
// if there was any texture to put we would include it
|
461 |
if (texture != null) |
462 |
p.setTexture(texture); |
463 |
// Tesselation of this poligon
|
464 |
p.tesselate(); |
465 |
|
466 |
// Optimizer generated nodes
|
467 |
// Optimizer opt = new Optimizer();
|
468 |
// opt.optimize(pt, OptimizationOptions.SPATIALIZE_GROUPS);
|
469 |
|
470 |
// Return node
|
471 |
return pt;
|
472 |
} |
473 |
|
474 |
/**
|
475 |
* Create a new tesselation poligon with a color using an array of 3D points
|
476 |
*
|
477 |
* @param points
|
478 |
* Array of 3D points
|
479 |
* @param color
|
480 |
* Color of the poligon
|
481 |
* @return Poligon node
|
482 |
*/
|
483 |
public static Node insertPolygon(Vec3[] points, Vec4 color,String texture) { |
484 |
// Creating a polygon
|
485 |
TessellablePolygon p = new TessellablePolygon();
|
486 |
|
487 |
// Set up parameters
|
488 |
// p.setType(Polygon.PolygonType.FILLED_POLYGON);
|
489 |
p.setWidth(2f);
|
490 |
// p.setPattern((short) 0xFFFF);
|
491 |
// p.setFactor(2);
|
492 |
p.setType(Polygon.PolygonType.FILLED_POLYGON);
|
493 |
// p.setType(Polygon.PolygonType.EMPTY_POLYGON);
|
494 |
// p.setType(Polygon.PolygonType.PATTERN_POLYGON);
|
495 |
|
496 |
// Adding points
|
497 |
for (int i = 0; i < points.length - 1; i++) { |
498 |
p.addVertex(points[i], color); |
499 |
// System.out.println("Position: " + inv[i].x() + " " + inv[i].y() +
|
500 |
// " " + inv[i].z());
|
501 |
} |
502 |
// if there was any texture to put we would include it
|
503 |
if (texture != null) |
504 |
p.setTexture(texture); |
505 |
// Tesselation of this poligon
|
506 |
p.tesselate(); |
507 |
|
508 |
// Optimizer generated nodes
|
509 |
Optimizer opt = new Optimizer();
|
510 |
opt.optimize(p, OptimizationOptions.SPATIALIZE_GROUPS); |
511 |
|
512 |
// Return node
|
513 |
return p;
|
514 |
} |
515 |
|
516 |
|
517 |
|
518 |
/**
|
519 |
* Create a new tesselation poligon with a color using an List of 3D points
|
520 |
*
|
521 |
* @param points
|
522 |
* List of 3D points
|
523 |
* @param color
|
524 |
* Color of the poligon
|
525 |
* @return Poligon node
|
526 |
*/
|
527 |
public static Node insertPolygon(List points, Vec4 color,String texture) { |
528 |
// Creating a polygon
|
529 |
TessellablePolygon p = new TessellablePolygon();
|
530 |
|
531 |
// Set up parameters
|
532 |
// p.setType(Polygon.PolygonType.FILLED_POLYGON);
|
533 |
p.setWidth(2f);
|
534 |
// p.setPattern((short) 0xFFFF);
|
535 |
// p.setFactor(2);
|
536 |
p.setType(Polygon.PolygonType.FILLED_POLYGON);
|
537 |
// p.setType(Polygon.PolygonType.EMPTY_POLYGON);
|
538 |
// p.setType(Polygon.PolygonType.PATTERN_POLYGON);
|
539 |
|
540 |
// Blending only is active if the alpha component are diferent that 1
|
541 |
if (color.w() != 1) { |
542 |
p.setEnabledBlending(true);
|
543 |
} |
544 |
// Adding points
|
545 |
for (int i = 0; i < points.size(); i++) { |
546 |
Vec3 element = (Vec3) points.get(i); |
547 |
p.addVertex(element, color); |
548 |
} |
549 |
|
550 |
|
551 |
// p.setTexture("C:/modelos3d/Images/land_shallow_topo_2048.jpg");
|
552 |
// if there was any texture to put we would include it
|
553 |
if (texture != null) |
554 |
p.setTexture(texture); |
555 |
// Tesselation of this poligon
|
556 |
p.tesselate(); |
557 |
|
558 |
// Optimizer generated nodes
|
559 |
Optimizer opt = new Optimizer();
|
560 |
opt.optimize(p, OptimizationOptions.ALL_OPTIMIZATIONS); |
561 |
|
562 |
// Return node
|
563 |
return p;
|
564 |
} |
565 |
|
566 |
/**
|
567 |
* Method to create a new 3D line. With a List of 3D points and a color
|
568 |
*
|
569 |
* @param points
|
570 |
* List of 3D points
|
571 |
* @param color
|
572 |
* Color of the line
|
573 |
* @return
|
574 |
*
|
575 |
*/
|
576 |
public static Node insertLine(List points, Vec4 color, float size) { |
577 |
Vec3 ori = null, fin = null; |
578 |
|
579 |
// Getting first points
|
580 |
if (points.size() > 1) { |
581 |
ori = (Vec3) points.get(0);
|
582 |
fin = (Vec3) points.get(1);
|
583 |
} |
584 |
|
585 |
// If the line do not have more than 2 points return null
|
586 |
if ((ori == null) || (fin == null)) |
587 |
return null; |
588 |
|
589 |
// Create new polyline
|
590 |
Polyline p = new Polyline(ori, fin);
|
591 |
p.setVertexColor(0, color);
|
592 |
p.setVertexColor(1, color);
|
593 |
|
594 |
// Set up parameters
|
595 |
p.setWidth(size); |
596 |
p.setPattern((short) 0xFFFF); |
597 |
p.setFactor(2);
|
598 |
|
599 |
// Blending only is active if the alpha component are diferent that 1
|
600 |
if (color.w() != 1) { |
601 |
p.setEnabledBlending(true);
|
602 |
} |
603 |
|
604 |
// Enabling antialiasing
|
605 |
p.setEnabledSmoothing(true);
|
606 |
|
607 |
p.setColor(color); |
608 |
|
609 |
// Adding points
|
610 |
for (int i = 2; i < points.size(); i++) { |
611 |
Vec3 element = (Vec3) points.get(i); |
612 |
p.addVertex(element, color); |
613 |
} |
614 |
|
615 |
// Optimizer generated nodes
|
616 |
Optimizer opt = new Optimizer();
|
617 |
opt.optimize(p); |
618 |
|
619 |
// Return node
|
620 |
return p;
|
621 |
|
622 |
} |
623 |
|
624 |
/**
|
625 |
* Create a new group of 3D points with a color and size. Using a List of 3D
|
626 |
* points
|
627 |
*
|
628 |
* @param points
|
629 |
* List of 3D points
|
630 |
* @param color
|
631 |
* Color of the line
|
632 |
* @param size
|
633 |
* Size of the point (in pixels)
|
634 |
* @return
|
635 |
*/
|
636 |
public static Node insertPointL(List points, Vec4 color, float size) { |
637 |
// Creating point
|
638 |
PixelPoint p = new PixelPoint();
|
639 |
|
640 |
// Set up parameters
|
641 |
p.setPointSize(size); |
642 |
|
643 |
// Adding points
|
644 |
for (int i = 0; i < points.size(); i++) { |
645 |
Vec3 element = (Vec3) points.get(i); |
646 |
p.addPoint(element, color); |
647 |
} |
648 |
|
649 |
// Optimizer generated nodes
|
650 |
Optimizer opt = new Optimizer();
|
651 |
opt.optimize(p); |
652 |
|
653 |
// Return node
|
654 |
return p;
|
655 |
|
656 |
} |
657 |
|
658 |
/**
|
659 |
* Create a new group of 3D labels with a size and heigth. Using a List of
|
660 |
* 3D points
|
661 |
*
|
662 |
* @param labels
|
663 |
* List of Flabels
|
664 |
*
|
665 |
* @param size
|
666 |
* Size of the labels
|
667 |
* @param heigth
|
668 |
* Heigth of labels
|
669 |
* @param inPixels
|
670 |
* True indicates that size is in pixel and false indicates real
|
671 |
* size;
|
672 |
* @param type
|
673 |
* @return Node group
|
674 |
*/
|
675 |
public static Node insertLabels(List labels, int size, float heigth, |
676 |
boolean inPixels, int planetType) { |
677 |
// Creating a group node
|
678 |
Group p = new Group(); |
679 |
|
680 |
// Getting total size
|
681 |
int total = labels.size();
|
682 |
|
683 |
// this is for control a max of labels because the system not suport
|
684 |
// more than 10000
|
685 |
int max = 3000; |
686 |
if (total > max)
|
687 |
total = max; |
688 |
|
689 |
if (labels != null) { |
690 |
for (int i = 0; i < total; i++) { |
691 |
FLabel f = (FLabel) labels.get(i); |
692 |
|
693 |
// Set up parameters
|
694 |
|
695 |
// Getting color
|
696 |
// Color co = f.getColor();
|
697 |
Color co = new Color(255, 255, 255, 255); |
698 |
float r, g, b, a;
|
699 |
r = ((float) co.getRed()) / 255.0f; |
700 |
g = ((float) co.getGreen()) / 255.0f; |
701 |
b = ((float) co.getBlue()) / 255.0f; |
702 |
a = ((float) co.getAlpha()) / 255.0f; |
703 |
// Set color
|
704 |
Vec4 textColor = new Vec4(r, g, b, a);
|
705 |
|
706 |
// Get label name
|
707 |
String label = f.getString();
|
708 |
// double heigth = h;
|
709 |
Vec3 pos = null;
|
710 |
if (planetType == Planet.CoordinateSystemType.PROJECTED) {
|
711 |
pos = new Vec3(f.getOrig().getX(), f.getOrig().getY(),
|
712 |
heigth); |
713 |
} else {
|
714 |
// Transform geodesical coordinates to cartesian
|
715 |
Vec3 posGeo = new Vec3(f.getOrig().getY(), f.getOrig()
|
716 |
.getX(), heigth); |
717 |
|
718 |
pos = planet.convertLatLongHeightToXYZ(posGeo); |
719 |
} |
720 |
|
721 |
// Adding new child text nodes
|
722 |
p.addChild(insertTextoS(label, pos, textColor, size, inPixels)); |
723 |
} |
724 |
} |
725 |
|
726 |
// Optimizer generated nodes
|
727 |
Optimizer opt = new Optimizer();
|
728 |
opt.optimize(p, OptimizationOptions.SPATIALIZE_GROUPS); |
729 |
|
730 |
return p;
|
731 |
|
732 |
} |
733 |
|
734 |
} |