svn-gvsig-desktop / tags / 3D_Animation_v1_0alpha_Build_5 / libraries / lib3DMap / src / org / gvsig / gvsig3d / gui / FeatureFactory.java @ 25534
History | View | Annotate | Download (31 KB)
1 |
package org.gvsig.gvsig3d.gui; |
---|---|
2 |
|
3 |
import java.awt.Color; |
4 |
import java.util.ArrayList; |
5 |
import java.util.HashMap; |
6 |
import java.util.Iterator; |
7 |
import java.util.List; |
8 |
|
9 |
import org.apache.log4j.Logger; |
10 |
import org.gvsig.gvsig3d.labels3D.ILabel3D; |
11 |
import org.gvsig.gvsig3d.labels3D.SimpleLabel3D; |
12 |
import org.gvsig.gvsig3d.utils.Punto3D; |
13 |
import org.gvsig.osgvp.AutoTransform; |
14 |
import org.gvsig.osgvp.Geode; |
15 |
import org.gvsig.osgvp.Group; |
16 |
import org.gvsig.osgvp.Node; |
17 |
import org.gvsig.osgvp.Optimizer; |
18 |
import org.gvsig.osgvp.Vec3; |
19 |
import org.gvsig.osgvp.Vec4; |
20 |
import org.gvsig.osgvp.Optimizer.OptimizationOptions; |
21 |
import org.gvsig.osgvp.exceptions.InvalidValueException; |
22 |
import org.gvsig.osgvp.exceptions.node.NodeException; |
23 |
import org.gvsig.osgvp.features.PixelPoint; |
24 |
import org.gvsig.osgvp.features.PointExtruder; |
25 |
import org.gvsig.osgvp.features.Polygon; |
26 |
import org.gvsig.osgvp.features.PolygonExtruder; |
27 |
import org.gvsig.osgvp.features.Polyline; |
28 |
import org.gvsig.osgvp.features.PolylineExtruder; |
29 |
import org.gvsig.osgvp.features.QuadPoint; |
30 |
import org.gvsig.osgvp.features.TessellablePolygon; |
31 |
import org.gvsig.osgvp.features.Text; |
32 |
import org.gvsig.osgvp.planets.Planet; |
33 |
|
34 |
import com.iver.ai2.gvsig3d.resources.ResourcesFactory; |
35 |
import com.iver.cit.gvsig.fmap.core.v02.FLabel; |
36 |
import com.iver.cit.gvsig.fmap.rendering.styling.labeling.AttrInTableLabelingStrategy; |
37 |
|
38 |
public class FeatureFactory extends Group { |
39 |
|
40 |
private static double radius; |
41 |
|
42 |
static Planet planet;
|
43 |
|
44 |
private static Logger logger = Logger.getLogger(Hud.class.getName()); |
45 |
|
46 |
public FeatureFactory(double ra, Planet m_planet) { |
47 |
super();
|
48 |
radius = ra; |
49 |
// this.setNodeName("VECTOR");
|
50 |
planet = m_planet; |
51 |
init(); |
52 |
} |
53 |
|
54 |
private void init() { |
55 |
|
56 |
// this.addChild(insertTexto("Polo norte", poloNorte));
|
57 |
// this.addChild(insertTexto("MADRID", valenciaCar));
|
58 |
|
59 |
// Vec3 posIni = new Vec3(0, 0, 0);
|
60 |
// Vec3 posEnd = new Vec3(0, 0, 100000);
|
61 |
|
62 |
// Polyline line = (Polyline) VectorTest.insertLineS(posIni, posEnd,
|
63 |
// new Vec4(1.0, 1.0, 1.0, 1.0), 0);
|
64 |
// if (planet.getType() == PlanetType.PLANE_MODE)
|
65 |
// this.addChild(line);
|
66 |
|
67 |
} |
68 |
|
69 |
// public Node insertTexto(String texto, Vec3 posicion) {
|
70 |
// // A�adiendo texto
|
71 |
// Text text = new Text();
|
72 |
// // text.setNodeName(texto);
|
73 |
// text.setText(texto);
|
74 |
// text.setCharacterSize(32);
|
75 |
//
|
76 |
// text.setAxisAlignment(Text.AxisAlignment.SCREEN);
|
77 |
// text.setAlignment(Text.AlignmentType.CENTER_CENTER);
|
78 |
// text.setCharacterSizeMode(Text.CharacterSizeMode.SCREEN_COORDS);
|
79 |
// text.setPosition((float) posicion.x(), (float) posicion.y(),
|
80 |
// (float) posicion.z());
|
81 |
//
|
82 |
// if (ResourcesFactory.exitsResouce("arial.ttf"))
|
83 |
// text.setFont(ResourcesFactory.getResourcePath("arial.ttf"));
|
84 |
// else
|
85 |
// text.setFont("arial.ttf");
|
86 |
// text.setAutoRotateToScreen(true);
|
87 |
//
|
88 |
//
|
89 |
// Optimizer opt = new Optimizer();
|
90 |
// opt.optimizeOptions(text, OptimizationOptions.SPATIALIZE_GROUPS);
|
91 |
//
|
92 |
// return text;
|
93 |
// }
|
94 |
// /**
|
95 |
// * this method create a new 3D text. With a value and position. And insert
|
96 |
// a
|
97 |
// * point under 3D text
|
98 |
// *
|
99 |
// * @param texto
|
100 |
// * text that is visible in 3D
|
101 |
// * @param position
|
102 |
// * Position of 3D text in cartesian coordinates
|
103 |
// * @return New node
|
104 |
// */
|
105 |
// public void insertText(String texto, Vec3 posicion) {
|
106 |
// posicion.setZ(posicion.z() + radius);
|
107 |
// Vec3 e = planet.convertLatLongHeightToXYZ(posicion);
|
108 |
//
|
109 |
// this.addChild(insertPoint(e, new Vec4(1.0, 0, 0, 1.0)));
|
110 |
//
|
111 |
// this.addChild(insertTexto(texto, e));
|
112 |
// }
|
113 |
//
|
114 |
// /**
|
115 |
// * this method create a new 3D point. With a color and position
|
116 |
// *
|
117 |
// * @param color
|
118 |
// * Color of the point
|
119 |
// * @param position
|
120 |
// * Position of 3D point in cartesian coordinates
|
121 |
// * @return
|
122 |
// */
|
123 |
// public Node insertPoint(Vec3 position, Vec4 color) {
|
124 |
// // Creating point
|
125 |
// Point p = new Point();
|
126 |
//
|
127 |
// // Adding position and color
|
128 |
// for (int i = 0; i < 1; i++) {
|
129 |
// p.setPointSize(100);
|
130 |
// p.addPoint(position, color);
|
131 |
// }
|
132 |
//
|
133 |
// return p;
|
134 |
// }
|
135 |
|
136 |
/**
|
137 |
* Method to create a new 3D text. With a value and position. Text aligment
|
138 |
* is LEFT CENTER, and his font is "Arial.ttf"
|
139 |
*
|
140 |
* @param texto
|
141 |
* Text that is visible in 3D
|
142 |
* @param position
|
143 |
* Position of 3D text in cartesian coordinates
|
144 |
* @return New node
|
145 |
*/
|
146 |
public static Node insertTextoS(String texto, Vec3 position, Vec4 color, |
147 |
int tam, boolean inPixels) { |
148 |
|
149 |
// Creating text node
|
150 |
Text text = null;
|
151 |
try {
|
152 |
text = new Text();
|
153 |
} catch (NodeException e1) {
|
154 |
// TODO Auto-generated catch block
|
155 |
e1.printStackTrace(); |
156 |
} |
157 |
// Set up text properties
|
158 |
text.setText(texto); |
159 |
text.setCharacterSize(tam); |
160 |
// Select that the text will be in pixels or screen coordinates
|
161 |
if (inPixels) {
|
162 |
text.setCharacterSizeMode(Text.CharacterSizeMode.SCREEN_COORDS); |
163 |
} else {
|
164 |
text.setCharacterSizeMode(Text.CharacterSizeMode.OBJECT_COORDS); |
165 |
} |
166 |
text.setColor(color); |
167 |
text.setAxisAlignment(Text.AxisAlignment.SCREEN); |
168 |
text.setAlignment(Text.AlignmentType.LEFT_BOTTOM); |
169 |
text.setPosition((float) position.x(), (float) position.y(), |
170 |
(float) position.z());
|
171 |
|
172 |
// Search font in resources directori
|
173 |
if (ResourcesFactory.exitsResouce("arial.ttf")) |
174 |
text.setFont(ResourcesFactory.getResourcePath("arial.ttf"));
|
175 |
else
|
176 |
text.setFont("arial.ttf");
|
177 |
text.setAutoRotateToScreen(true);
|
178 |
|
179 |
// Optimizer generated nodes
|
180 |
Optimizer opt = new Optimizer();
|
181 |
try {
|
182 |
opt.optimize(text, OptimizationOptions.SPATIALIZE_GROUPS); |
183 |
} catch (InvalidValueException e) {
|
184 |
// TODO Auto-generated catch block
|
185 |
e.printStackTrace(); |
186 |
} catch (NodeException e) {
|
187 |
// TODO Auto-generated catch block
|
188 |
e.printStackTrace(); |
189 |
} |
190 |
|
191 |
// Return node
|
192 |
return text;
|
193 |
|
194 |
} |
195 |
|
196 |
/**
|
197 |
* Method to create a new 3D point. With a color, heigth and position.
|
198 |
*
|
199 |
* @param position
|
200 |
* Position of 3D text in cartesian coordinates
|
201 |
* @param color
|
202 |
* color of the 3D point
|
203 |
* @param tam
|
204 |
* the heigth of the point
|
205 |
* @return New text node
|
206 |
*/
|
207 |
public static Node insertPointS(Vec3 position, Vec4 color, int tam) { |
208 |
AutoTransform au = null;
|
209 |
try {
|
210 |
au = new AutoTransform();
|
211 |
} catch (NodeException e2) {
|
212 |
// TODO Auto-generated catch block
|
213 |
e2.printStackTrace(); |
214 |
} |
215 |
// Creating point
|
216 |
PixelPoint p = null;
|
217 |
try {
|
218 |
p = new PixelPoint();
|
219 |
} catch (NodeException e1) {
|
220 |
// TODO Auto-generated catch block
|
221 |
e1.printStackTrace(); |
222 |
} |
223 |
// p.setDistanceAttenuation(new Vec3(0.0,0.0,0.0000001));
|
224 |
p.setPointSize(tam); |
225 |
p.addPoint(position, color); |
226 |
|
227 |
try {
|
228 |
au.addChild(p); |
229 |
} catch (NodeException e) {
|
230 |
logger.error("command:" + "Error adding new child.",e); |
231 |
} |
232 |
// return au;
|
233 |
return p;
|
234 |
} |
235 |
|
236 |
/**
|
237 |
* Method to create a new 3D point. With a color, heigth and position.
|
238 |
*
|
239 |
* @param hash
|
240 |
* Hash Table that contains "Puntos3D" elements
|
241 |
* @return
|
242 |
*/
|
243 |
public static Node insertPointS(HashMap hash) { |
244 |
|
245 |
Group g = new Group(); |
246 |
|
247 |
// Iterate over the keys in the map
|
248 |
Iterator it = hash.keySet().iterator();
|
249 |
while (it.hasNext()) {
|
250 |
// Get key
|
251 |
Double key = (Double) it.next(); |
252 |
List list = (List) hash.get(key); |
253 |
|
254 |
PixelPoint p = null;
|
255 |
try {
|
256 |
p = new PixelPoint();
|
257 |
} catch (NodeException e1) {
|
258 |
// TODO Auto-generated catch block
|
259 |
e1.printStackTrace(); |
260 |
} |
261 |
// ShapePoint p = new ShapePoint();
|
262 |
// es.upv.ai2.osgvp.features.Sphere s = new Sphere();
|
263 |
// p.setShape(s);
|
264 |
// s.setRadius(100);
|
265 |
for (Iterator iter = list.iterator(); iter.hasNext();) { |
266 |
// Getting PixelPoint
|
267 |
Punto3D element = (Punto3D) iter.next(); |
268 |
// Vec4 color = element.getColor();
|
269 |
Vec4 color = new Vec4(1,0,0,1); |
270 |
|
271 |
// Blending only is active if the alpha component are diferent
|
272 |
// that 1
|
273 |
if (color.w() != 1) { |
274 |
p.setEnabledBlending(true);
|
275 |
} |
276 |
// Enabling antialiasing
|
277 |
p.setEnabledSmoothing(true);
|
278 |
|
279 |
// Set up size, position and color
|
280 |
// p.setPointSize(element.getZize());
|
281 |
p.setPointSize(20);
|
282 |
try {
|
283 |
p.getOrCreateStateSet().setLightingMode(Node.Mode.OFF | Node.Mode.PROTECTED); |
284 |
} catch (InvalidValueException e) {
|
285 |
logger.error("command:" + "Error setting new lighthing mode.",e); |
286 |
} |
287 |
p.addPoint(element.getPosition(), color); |
288 |
// System.err.println("posicion del punto " +element.getPosition());
|
289 |
} |
290 |
// Adding points to group
|
291 |
try {
|
292 |
g.addChild(p); |
293 |
} catch (NodeException e) {
|
294 |
logger.error("command:" + "Error adding new child node.",e); |
295 |
} |
296 |
} |
297 |
// System.out.println("nuevo grupo");
|
298 |
|
299 |
// Optimizer generated nodes
|
300 |
// Optimizer opt = new Optimizer();
|
301 |
// opt.optimize(g, OptimizationOptions.SPATIALIZE_GROUPS);
|
302 |
|
303 |
return g;
|
304 |
} |
305 |
|
306 |
/**
|
307 |
* Method to add 3D points to specific point type. With a color, heigth and
|
308 |
* position.
|
309 |
*
|
310 |
* @param point
|
311 |
* Node to add new 3D point
|
312 |
* @param position
|
313 |
* Position of 3D text in cartesian coordinates
|
314 |
* @param color
|
315 |
* color of the 3D point
|
316 |
* @param tam
|
317 |
* the heigth of the point
|
318 |
* @return New text node
|
319 |
*/
|
320 |
public static void addPointToNode(Node point, Vec3 position, Vec4 color, |
321 |
int tam) {
|
322 |
|
323 |
PixelPoint p = null;
|
324 |
// Getting point
|
325 |
if (point != null) |
326 |
p = (PixelPoint) point; |
327 |
|
328 |
// If not exits create new
|
329 |
if (p == null) |
330 |
try {
|
331 |
p = new PixelPoint();
|
332 |
} catch (NodeException e1) {
|
333 |
// TODO Auto-generated catch block
|
334 |
e1.printStackTrace(); |
335 |
} |
336 |
|
337 |
// Blending only is active if the alpha component are diferent that 1
|
338 |
if (color.w() != 1) { |
339 |
p.setEnabledBlending(true);
|
340 |
} |
341 |
|
342 |
// Set up size, position and color
|
343 |
p.setPointSize(tam); |
344 |
p.addPoint(position, color); |
345 |
|
346 |
// Optimizer generated nodes
|
347 |
Optimizer opt = new Optimizer();
|
348 |
try {
|
349 |
opt.optimize(p, OptimizationOptions.SPATIALIZE_GROUPS); |
350 |
} catch (InvalidValueException e) {
|
351 |
logger.error("command:" + "Error Inicializing value.",e); |
352 |
} catch (NodeException e) {
|
353 |
logger.error("command:" + "Error node exception.",e); |
354 |
} |
355 |
|
356 |
} |
357 |
|
358 |
/**
|
359 |
* Method to create a new 3D line. With a color, heigth and position.
|
360 |
*
|
361 |
* @param ini
|
362 |
* Initial position of line
|
363 |
* @param end
|
364 |
* End positon of line.
|
365 |
* @param color
|
366 |
* color of the 3D point
|
367 |
* @param tam
|
368 |
* the heigth of the point
|
369 |
* @return New line node
|
370 |
*/
|
371 |
|
372 |
public static Node insertLineS(Vec3 ini, Vec3 end, Vec4 color, int tam) { |
373 |
// Creating a polyline
|
374 |
Polyline p = null;
|
375 |
try {
|
376 |
p = new Polyline(ini, end);
|
377 |
} catch (NodeException e1) {
|
378 |
// TODO Auto-generated catch block
|
379 |
e1.printStackTrace(); |
380 |
} |
381 |
|
382 |
// Set up parameter
|
383 |
p.setWidth(2f);
|
384 |
p.setPattern((short) 0xFFFF); |
385 |
p.setFactor(2);
|
386 |
p.setColor(color); |
387 |
|
388 |
// Optimize the node
|
389 |
Optimizer opt = new Optimizer();
|
390 |
try {
|
391 |
opt.optimize(p); |
392 |
} catch (NodeException e) {
|
393 |
logger.error("command:" + "Error setting the optimizer.",e); |
394 |
} |
395 |
|
396 |
// Return the node
|
397 |
return p;
|
398 |
} |
399 |
|
400 |
/**
|
401 |
* Method to add new points to specific line type. With a color, heigth and
|
402 |
* position.
|
403 |
*
|
404 |
* @param line
|
405 |
* Node to add new point
|
406 |
* @param position
|
407 |
* Position of 3D point in cartesian coordinates
|
408 |
* @param color
|
409 |
* color of the 3D point
|
410 |
* @param tam
|
411 |
* the heigth of the point
|
412 |
*/
|
413 |
public static void addNodeToLine(Node line, Vec3 position, Vec4 color, |
414 |
int tam) {
|
415 |
// Getting polyline
|
416 |
Polyline p = (Polyline) line; |
417 |
|
418 |
// If not exits, create a new
|
419 |
if (p == null) |
420 |
try {
|
421 |
p = new Polyline(position, position);
|
422 |
} catch (NodeException e) {
|
423 |
// TODO Auto-generated catch block
|
424 |
e.printStackTrace(); |
425 |
} |
426 |
|
427 |
// Add a point and color
|
428 |
p.addVertex(position, color); |
429 |
|
430 |
} |
431 |
|
432 |
/**
|
433 |
* Create a new point node with a color and size. Using a position of 3D
|
434 |
* points
|
435 |
*
|
436 |
* @param position
|
437 |
* Position of 3D point
|
438 |
* @param color
|
439 |
* Color of the 3D point
|
440 |
* @param tam
|
441 |
* Size of the point (in pixels)
|
442 |
* @return
|
443 |
*/
|
444 |
public static Node insertPointS(Vec3[] position, Vec4 color, int tam) { |
445 |
// Creating point node
|
446 |
PixelPoint p = null;
|
447 |
try {
|
448 |
p = new PixelPoint();
|
449 |
} catch (NodeException e1) {
|
450 |
// TODO Auto-generated catch block
|
451 |
e1.printStackTrace(); |
452 |
} |
453 |
|
454 |
// Set up parameters and insert position
|
455 |
for (int i = 0; i < position.length; i++) { |
456 |
p.setPointSize(tam); |
457 |
p.addPoint(position[i], color); |
458 |
} |
459 |
|
460 |
// Optimizer generated nodes
|
461 |
Optimizer opt = new Optimizer();
|
462 |
try {
|
463 |
opt.optimize(p, OptimizationOptions.SPATIALIZE_GROUPS); |
464 |
} catch (InvalidValueException e) {
|
465 |
logger.error("command:" + "Error inicializing value for the optimizer.",e); |
466 |
} catch (NodeException e) {
|
467 |
logger.error("command:" + "Error adding the optimizer.",e); |
468 |
} |
469 |
|
470 |
// Return node
|
471 |
return p;
|
472 |
} |
473 |
|
474 |
public static Node insertPointExtruded(List points, Vec4 color,String texture,double heigth) { |
475 |
// Creating a polygon
|
476 |
PixelPoint p = null;
|
477 |
try {
|
478 |
p = new PixelPoint();
|
479 |
} catch (NodeException e1) {
|
480 |
// TODO Auto-generated catch block
|
481 |
e1.printStackTrace(); |
482 |
} |
483 |
// Adding points
|
484 |
for (int i = 0; i < points.size(); i++) { |
485 |
Vec3 element = (Vec3) points.get(i); |
486 |
p.addVertex(element, color); |
487 |
//p.addPoint3D(element);
|
488 |
} |
489 |
PointExtruder pe = new PointExtruder();
|
490 |
pe.extrude(p,new Vec3 (0.0,0.0,1.0), heigth); |
491 |
|
492 |
|
493 |
Group group = new Group(); |
494 |
Geode geode = new Geode();
|
495 |
|
496 |
geode.getOrCreateStateSet().setTwoSidedLighting(true);
|
497 |
try {
|
498 |
geode.addDrawable(pe.getGeometry()); |
499 |
group.addChild(geode); |
500 |
} catch (NodeException e) {
|
501 |
logger.error("Command:" + "Error adding drawable object.",e); |
502 |
} |
503 |
|
504 |
return group;
|
505 |
} |
506 |
|
507 |
|
508 |
|
509 |
/**
|
510 |
* Create a new quad point node with a color, size and texture. Using a position of 3D
|
511 |
* points
|
512 |
*
|
513 |
* @param position
|
514 |
* Position of 3D point
|
515 |
* @param color
|
516 |
* Color of the 3D point
|
517 |
* @param tam
|
518 |
* Size of the point (in pixels)
|
519 |
* @return
|
520 |
*/
|
521 |
public static Node insertQuadPoints(Vec3[] position, Vec4 color, float tam, String texture) { |
522 |
// Creating point node
|
523 |
QuadPoint p = null;
|
524 |
try {
|
525 |
p = new QuadPoint(tam);
|
526 |
} catch (NodeException e) {
|
527 |
logger.error("command:" + "Error creating quad point.",e); |
528 |
} |
529 |
|
530 |
// Set up parameters and insert position
|
531 |
for (int i = 0; i < position.length; i++) { |
532 |
p.setPointSize(tam); |
533 |
p.addPoint(position[i], color); |
534 |
} |
535 |
|
536 |
// if (texture!=null)
|
537 |
// p.setTexture(texture);
|
538 |
|
539 |
try {
|
540 |
p.setBillboardingEnabled(true);
|
541 |
} catch (InvalidValueException e) {
|
542 |
logger.error("command:" + "Error setting billboarding value.",e); |
543 |
} |
544 |
|
545 |
|
546 |
// Optimizer generated nodes
|
547 |
Optimizer opt = new Optimizer();
|
548 |
try {
|
549 |
opt.optimize(p, OptimizationOptions.SPATIALIZE_GROUPS); |
550 |
} catch (InvalidValueException e) {
|
551 |
logger.error("command:" + "Error inciliazicing optimize values.",e); |
552 |
} catch (NodeException e) {
|
553 |
logger.error("command:" + "Error setting optimizer.",e); |
554 |
} |
555 |
|
556 |
// Return node
|
557 |
return p;
|
558 |
} |
559 |
/**
|
560 |
* Create a new tesselation poligon with a color using an array of 3D points
|
561 |
*
|
562 |
* @param points
|
563 |
* Array of 3D points
|
564 |
* @param color
|
565 |
* Color of the poligon
|
566 |
* @return Poligon node
|
567 |
*/
|
568 |
public static Node generateQuadPoligon(Vec3 position, Vec4 color,String texture,float tam) { |
569 |
// Creating a polygon
|
570 |
TessellablePolygon p = null;
|
571 |
try {
|
572 |
p = new TessellablePolygon();
|
573 |
} catch (NodeException e2) {
|
574 |
// TODO Auto-generated catch block
|
575 |
e2.printStackTrace(); |
576 |
} |
577 |
|
578 |
// PositionAttitudeTransform pt = new PositionAttitudeTransform();
|
579 |
AutoTransform pt = null;
|
580 |
try {
|
581 |
pt = new AutoTransform();
|
582 |
} catch (NodeException e2) {
|
583 |
// TODO Auto-generated catch block
|
584 |
e2.printStackTrace(); |
585 |
} |
586 |
try {
|
587 |
pt.addChild(p); |
588 |
} catch (NodeException e1) {
|
589 |
logger.error("Command:" + "Error adding new child.",e1); |
590 |
} |
591 |
pt.setPosition(position); |
592 |
try {
|
593 |
pt.setAutoRotateMode(AutoTransform.AutoRotateMode.ROTATE_TO_CAMERA); |
594 |
} catch (InvalidValueException e1) {
|
595 |
logger.error("command:" + "Error setting autorotate value.",e1); |
596 |
} |
597 |
// Set up parameters
|
598 |
// p.setType(Polygon.PolygonType.FILLED_POLYGON);
|
599 |
p.setWidth(2f);
|
600 |
// p.setPattern((short) 0xFFFF);
|
601 |
// p.setFactor(2);
|
602 |
p.setType(Polygon.PolygonType.FILLED_POLYGON);
|
603 |
// p.setType(Polygon.PolygonType.EMPTY_POLYGON);
|
604 |
// p.setType(Polygon.PolygonType.PATTERN_POLYGON);
|
605 |
|
606 |
Vec3 bl = new Vec3(-tam/2,-tam/2,0.0); |
607 |
Vec3 br = new Vec3(tam/2,-tam/2,0.0); |
608 |
Vec3 tr = new Vec3(tam/2,tam/2,0.0); |
609 |
Vec3 tl = new Vec3(-tam/2,tam/2,0.0); |
610 |
p.setEnabledBlending(true);
|
611 |
// Vector<Vec3> normal = new Vector<Vec3>();
|
612 |
// normal.add(new Vec3(0,0,1));
|
613 |
// p.setNormalArray(normal);
|
614 |
// p.setNormalBinding(Geometry.AttributeBinding.BIND_OVERALL);
|
615 |
|
616 |
try {
|
617 |
p.getOrCreateStateSet().setLightingMode(Mode.OFF | Mode.PROTECTED); |
618 |
} catch (InvalidValueException e) {
|
619 |
logger.error("command:" + "Error ",e); |
620 |
} |
621 |
p.addVertex(bl, color); |
622 |
p.addVertex(tl, color); |
623 |
p.addVertex(tr, color); |
624 |
p.addVertex(br, color); |
625 |
|
626 |
// p.setTwoSidedLighting(true);
|
627 |
|
628 |
// if there was any texture to put we would include it
|
629 |
if (texture != null) |
630 |
p.setTexture(texture); |
631 |
// Tesselation of this poligon
|
632 |
p.tesselate(); |
633 |
|
634 |
// Optimizer generated nodes
|
635 |
// Optimizer opt = new Optimizer();
|
636 |
// opt.optimize(pt, OptimizationOptions.SPATIALIZE_GROUPS);
|
637 |
|
638 |
// Return node
|
639 |
return pt;
|
640 |
} |
641 |
|
642 |
/**
|
643 |
* Create a new tesselation poligon with a color using an array of 3D points
|
644 |
*
|
645 |
* @param points
|
646 |
* Array of 3D points
|
647 |
* @param color
|
648 |
* Color of the poligon
|
649 |
* @return Poligon node
|
650 |
*/
|
651 |
public static Node insertPolygon(Vec3[] points, Vec4 color,String texture) { |
652 |
// Creating a polygon
|
653 |
TessellablePolygon p = null;
|
654 |
try {
|
655 |
p = new TessellablePolygon();
|
656 |
} catch (NodeException e1) {
|
657 |
// TODO Auto-generated catch block
|
658 |
e1.printStackTrace(); |
659 |
} |
660 |
|
661 |
// Set up parameters
|
662 |
// p.setType(Polygon.PolygonType.FILLED_POLYGON);
|
663 |
p.setWidth(2f);
|
664 |
// p.setPattern((short) 0xFFFF);
|
665 |
// p.setFactor(2);
|
666 |
p.setType(Polygon.PolygonType.FILLED_POLYGON);
|
667 |
// p.setType(Polygon.PolygonType.EMPTY_POLYGON);
|
668 |
// p.setType(Polygon.PolygonType.PATTERN_POLYGON);
|
669 |
|
670 |
// Adding points
|
671 |
for (int i = 0; i < points.length - 1; i++) { |
672 |
p.addVertex(points[i], color); |
673 |
// System.out.println("Position: " + inv[i].x() + " " + inv[i].y() +
|
674 |
// " " + inv[i].z());
|
675 |
} |
676 |
// if there was any texture to put we would include it
|
677 |
if (texture != null) |
678 |
p.setTexture(texture); |
679 |
// Tesselation of this poligon
|
680 |
p.tesselate(); |
681 |
|
682 |
// Optimizer generated nodes
|
683 |
Optimizer opt = new Optimizer();
|
684 |
try {
|
685 |
opt.optimize(p, OptimizationOptions.SPATIALIZE_GROUPS); |
686 |
} catch (InvalidValueException e) {
|
687 |
logger.error("Command:" + "Error setting optimize value.",e); |
688 |
} catch (NodeException e) {
|
689 |
logger.error("Command:" + "Error adding optimizer.",e); |
690 |
} |
691 |
|
692 |
// Return node
|
693 |
return p;
|
694 |
} |
695 |
|
696 |
|
697 |
|
698 |
/**
|
699 |
* Create a new tesselation poligon with a color using an List of 3D points
|
700 |
*
|
701 |
* @param points
|
702 |
* List of 3D points
|
703 |
* @param color
|
704 |
* Color of the poligon
|
705 |
* @return Poligon node
|
706 |
*/
|
707 |
public static Node insertPolygon(List points, Vec4 color,String texture) { |
708 |
// Creating a polygon
|
709 |
TessellablePolygon p = null;
|
710 |
try {
|
711 |
p = new TessellablePolygon();
|
712 |
} catch (NodeException e1) {
|
713 |
// TODO Auto-generated catch block
|
714 |
e1.printStackTrace(); |
715 |
} |
716 |
|
717 |
// Set up parameters
|
718 |
// p.setType(Polygon.PolygonType.FILLED_POLYGON);
|
719 |
p.setWidth(2f);
|
720 |
// p.setPattern((short) 0xFFFF);
|
721 |
// p.setFactor(2);
|
722 |
p.setType(Polygon.PolygonType.FILLED_POLYGON);
|
723 |
// p.setType(Polygon.PolygonType.EMPTY_POLYGON);
|
724 |
// p.setType(Polygon.PolygonType.PATTERN_POLYGON);
|
725 |
|
726 |
// Blending only is active if the alpha component are diferent that 1
|
727 |
if (color.w() != 1) { |
728 |
p.setEnabledBlending(true);
|
729 |
} |
730 |
// Adding points
|
731 |
for (int i = 0; i < points.size(); i++) { |
732 |
Vec3 element = (Vec3) points.get(i); |
733 |
p.addVertex(element, color); |
734 |
} |
735 |
|
736 |
|
737 |
// p.setTexture("C:/modelos3d/Images/land_shallow_topo_2048.jpg");
|
738 |
// if there was any texture to put we would include it
|
739 |
if (texture != null) |
740 |
p.setTexture(texture); |
741 |
// Tesselation of this poligon
|
742 |
p.tesselate(); |
743 |
|
744 |
// Optimizer generated nodes
|
745 |
Optimizer opt = new Optimizer();
|
746 |
try {
|
747 |
opt.optimize(p, OptimizationOptions.ALL_OPTIMIZATIONS); |
748 |
} catch (InvalidValueException e) {
|
749 |
logger.error("Command:" + "Error setting optimizer value.",e); |
750 |
} catch (NodeException e) {
|
751 |
logger.error("Command:" + "Error adding optimizer.",e); |
752 |
} |
753 |
|
754 |
// Return node
|
755 |
return p;
|
756 |
} |
757 |
public static Node insertPolygonExtruded(List points, Vec4 color,String texture,double heigth) { |
758 |
// Creating a polygon
|
759 |
Polygon p = null; |
760 |
try {
|
761 |
p = new Polygon(); |
762 |
} catch (NodeException e1) {
|
763 |
// TODO Auto-generated catch block
|
764 |
e1.printStackTrace(); |
765 |
} |
766 |
|
767 |
// Set up parameters
|
768 |
p.setWidth(2f);
|
769 |
p.setType(Polygon.PolygonType.FILLED_POLYGON);
|
770 |
// Blending only is active if the alpha component are diferent that 1
|
771 |
if (color.w() != 1) { |
772 |
p.setEnabledBlending(true);
|
773 |
} |
774 |
List positionTapa = new ArrayList(); |
775 |
// Adding points
|
776 |
for (int i = 0; i < points.size(); i++) { |
777 |
Vec3 element = (Vec3) points.get(i); |
778 |
Vec3 elementTapa = new Vec3(element.x(),element.y(),element.z()+heigth);
|
779 |
positionTapa.add(elementTapa); |
780 |
p.addVertex(element, color); |
781 |
} |
782 |
|
783 |
PolygonExtruder pe = new PolygonExtruder();
|
784 |
pe.extrude(p,new Vec3 (0.0,0.0,1.0), heigth); |
785 |
|
786 |
|
787 |
// Optimizer generated nodes
|
788 |
Optimizer opt = new Optimizer();
|
789 |
Node node = null;
|
790 |
try {
|
791 |
opt.optimize(p, OptimizationOptions.ALL_OPTIMIZATIONS); |
792 |
node = FeatureFactory.insertPolygon(positionTapa, color, null);
|
793 |
opt.optimize(node, OptimizationOptions.ALL_OPTIMIZATIONS); |
794 |
|
795 |
} catch (InvalidValueException e) {
|
796 |
logger.error("Command:" + "Error setting optimizer value.",e); |
797 |
} catch (NodeException e) {
|
798 |
logger.error("Command:" + "Error adding optimizer.",e); |
799 |
} |
800 |
Group group = new Group(); |
801 |
Geode geode = new Geode();
|
802 |
|
803 |
geode.getOrCreateStateSet().setTwoSidedLighting(true);
|
804 |
try {
|
805 |
geode.addDrawable(pe.getGeometry()); |
806 |
group.addChild(geode); |
807 |
group.addChild(node); |
808 |
} catch (NodeException e) {
|
809 |
logger.error("Command:" + "Error adding drawable object.",e); |
810 |
} |
811 |
|
812 |
return group;
|
813 |
} |
814 |
/**
|
815 |
* Method to create a new 3D line. With a List of 3D points and a color
|
816 |
*
|
817 |
* @param points
|
818 |
* List of 3D points
|
819 |
* @param color
|
820 |
* Color of the line
|
821 |
* @return
|
822 |
*
|
823 |
*/
|
824 |
public static Node insertLine(List points, Vec4 color, float size) { |
825 |
Vec3 ori = null, fin = null; |
826 |
|
827 |
// Getting first points
|
828 |
if (points.size() > 1) { |
829 |
ori = (Vec3) points.get(0);
|
830 |
fin = (Vec3) points.get(1);
|
831 |
} |
832 |
|
833 |
// If the line do not have more than 2 points return null
|
834 |
if ((ori == null) || (fin == null)) |
835 |
return null; |
836 |
|
837 |
// Create new polyline
|
838 |
Polyline p = null;
|
839 |
try {
|
840 |
p = new Polyline(ori, fin);
|
841 |
} catch (NodeException e1) {
|
842 |
// TODO Auto-generated catch block
|
843 |
e1.printStackTrace(); |
844 |
} |
845 |
p.setVertexColor(0, color);
|
846 |
p.setVertexColor(1, color);
|
847 |
|
848 |
// Set up parameters
|
849 |
p.setWidth(size); |
850 |
p.setPattern((short) 0xFFFF); |
851 |
p.setFactor(2);
|
852 |
|
853 |
// Blending only is active if the alpha component are diferent that 1
|
854 |
if (color.w() != 1) { |
855 |
p.setEnabledBlending(true);
|
856 |
} |
857 |
|
858 |
// Enabling antialiasing
|
859 |
p.setEnabledSmoothing(true);
|
860 |
|
861 |
p.setColor(color); |
862 |
|
863 |
// Adding points
|
864 |
for (int i = 2; i < points.size(); i++) { |
865 |
Vec3 element = (Vec3) points.get(i); |
866 |
p.addVertex(element, color); |
867 |
} |
868 |
|
869 |
// Optimizer generated nodes
|
870 |
Optimizer opt = new Optimizer();
|
871 |
try {
|
872 |
opt.optimize(p); |
873 |
} catch (NodeException e) {
|
874 |
logger.error("Command:" + "Error adding optimizer.",e); |
875 |
} |
876 |
|
877 |
// Return node
|
878 |
return p;
|
879 |
|
880 |
} |
881 |
|
882 |
public static Node insertLineExtruded(List points, Vec4 color,String texture,double heigth) { |
883 |
// Creating a polygon
|
884 |
Polyline p = null;
|
885 |
try {
|
886 |
p = new Polyline();
|
887 |
} catch (NodeException e1) {
|
888 |
// TODO Auto-generated catch block
|
889 |
e1.printStackTrace(); |
890 |
} |
891 |
|
892 |
// Set up parameters
|
893 |
p.setWidth(2f);
|
894 |
|
895 |
// Blending only is active if the alpha component are diferent that 1
|
896 |
if (color.w() != 1) { |
897 |
p.setEnabledBlending(true);
|
898 |
} |
899 |
// List positionTapa = new ArrayList();
|
900 |
// Adding points
|
901 |
for (int i = 0; i < points.size(); i++) { |
902 |
Vec3 element = (Vec3) points.get(i); |
903 |
p.addVertex(element, color); |
904 |
} |
905 |
PolylineExtruder pe = new PolylineExtruder();
|
906 |
pe.extrude(p,new Vec3 (0.0,0.0,1.0), heigth); |
907 |
|
908 |
|
909 |
Group group = new Group(); |
910 |
Geode geode = new Geode();
|
911 |
|
912 |
geode.getOrCreateStateSet().setTwoSidedLighting(true);
|
913 |
try {
|
914 |
geode.addDrawable(pe.getGeometry()); |
915 |
group.addChild(geode); |
916 |
} catch (NodeException e) {
|
917 |
logger.error("Command:" + "Error adding drawable object.",e); |
918 |
} |
919 |
|
920 |
return group;
|
921 |
} |
922 |
|
923 |
|
924 |
|
925 |
|
926 |
|
927 |
/**
|
928 |
* Create a new group of 3D points with a color and size. Using a List of 3D
|
929 |
* points
|
930 |
*
|
931 |
* @param points
|
932 |
* List of 3D points
|
933 |
* @param color
|
934 |
* Color of the line
|
935 |
* @param size
|
936 |
* Size of the point (in pixels)
|
937 |
* @return
|
938 |
*/
|
939 |
public static Node insertPointL(List points, Vec4 color, float size) { |
940 |
// Creating point
|
941 |
PixelPoint p = null;
|
942 |
try {
|
943 |
p = new PixelPoint();
|
944 |
} catch (NodeException e1) {
|
945 |
// TODO Auto-generated catch block
|
946 |
e1.printStackTrace(); |
947 |
} |
948 |
|
949 |
// Set up parameters
|
950 |
p.setPointSize(size); |
951 |
|
952 |
// Adding points
|
953 |
for (int i = 0; i < points.size(); i++) { |
954 |
Vec3 element = (Vec3) points.get(i); |
955 |
p.addPoint(element, color); |
956 |
} |
957 |
|
958 |
// Optimizer generated nodes
|
959 |
Optimizer opt = new Optimizer();
|
960 |
try {
|
961 |
opt.optimize(p); |
962 |
} catch (NodeException e) {
|
963 |
logger.error("Command:" + "Error adding optimizer.",e); |
964 |
} |
965 |
|
966 |
// Return node
|
967 |
return p;
|
968 |
|
969 |
} |
970 |
|
971 |
/**
|
972 |
* Create a new group of 3D labels with a size and heigth. Using a List of
|
973 |
* 3D points
|
974 |
*
|
975 |
* @param labels
|
976 |
* List of Flabels
|
977 |
*
|
978 |
* @param size
|
979 |
* Size of the labels
|
980 |
* @param heigth
|
981 |
* Heigth of labels
|
982 |
* @param inPixels
|
983 |
* True indicates that size is in pixel and false indicates real
|
984 |
* size;
|
985 |
* @param type
|
986 |
* @return Node group
|
987 |
*/
|
988 |
public static Node insertLabels(List labels, int size, float heigth, |
989 |
boolean inPixels, int planetType) { |
990 |
// Creating a group node
|
991 |
Group p = new Group(); |
992 |
|
993 |
// Getting total size
|
994 |
int total = labels.size();
|
995 |
|
996 |
// this is for control a max of labels because the system not suport
|
997 |
// more than 10000
|
998 |
int max = 3000; |
999 |
if (total > max)
|
1000 |
total = max; |
1001 |
|
1002 |
if (labels != null) { |
1003 |
for (int i = 0; i < total; i++) { |
1004 |
FLabel f = (FLabel) labels.get(i); |
1005 |
|
1006 |
// Set up parameters
|
1007 |
|
1008 |
// Getting color
|
1009 |
// Color co = f.getColor();
|
1010 |
Color co = new Color(255, 255, 255, 255); |
1011 |
float r, g, b, a;
|
1012 |
r = ((float) co.getRed()) / 255.0f; |
1013 |
g = ((float) co.getGreen()) / 255.0f; |
1014 |
b = ((float) co.getBlue()) / 255.0f; |
1015 |
a = ((float) co.getAlpha()) / 255.0f; |
1016 |
// Set color
|
1017 |
Vec4 textColor = new Vec4(r, g, b, a);
|
1018 |
|
1019 |
// Get label name
|
1020 |
String label = f.getString();
|
1021 |
// double heigth = h;
|
1022 |
Vec3 pos = null;
|
1023 |
if (planetType == Planet.CoordinateSystemType.PROJECTED) {
|
1024 |
pos = new Vec3(f.getOrig().getX(), f.getOrig().getY(),
|
1025 |
heigth); |
1026 |
} else {
|
1027 |
// Transform geodesical coordinates to cartesian
|
1028 |
Vec3 posGeo = new Vec3(f.getOrig().getY(), f.getOrig()
|
1029 |
.getX(), heigth); |
1030 |
|
1031 |
pos = planet.convertLatLongHeightToXYZ(posGeo); |
1032 |
} |
1033 |
|
1034 |
// Adding new child text nodes
|
1035 |
try {
|
1036 |
p.addChild(insertTextoS(label, pos, textColor, size, inPixels)); |
1037 |
} catch (NodeException e) {
|
1038 |
logger.error("Command:" + "Error adding new child text.",e); |
1039 |
} |
1040 |
} |
1041 |
} |
1042 |
|
1043 |
// Optimizer generated nodes
|
1044 |
Optimizer opt = new Optimizer();
|
1045 |
try {
|
1046 |
opt.optimize(p, OptimizationOptions.SPATIALIZE_GROUPS); |
1047 |
} catch (InvalidValueException e) {
|
1048 |
logger.error("Command:" + "Error setting optimizer value.",e); |
1049 |
} catch (NodeException e) {
|
1050 |
logger.error("Command:" + "Error adding optimizer.",e); |
1051 |
} |
1052 |
|
1053 |
return p;
|
1054 |
|
1055 |
} |
1056 |
|
1057 |
/**
|
1058 |
* Create a new group of 3D labels with a size and heigth. Using a List of
|
1059 |
* 3D points
|
1060 |
*
|
1061 |
* @param labels
|
1062 |
* List of Flabels
|
1063 |
*
|
1064 |
* @param size
|
1065 |
* Size of the labels
|
1066 |
* @param heigth
|
1067 |
* Heigth of labels
|
1068 |
* @param inPixels
|
1069 |
* True indicates that size is in pixel and false indicates real
|
1070 |
* size;
|
1071 |
* @param type
|
1072 |
* @return Node group
|
1073 |
*/
|
1074 |
public static Node insertLabels(List<ILabel3D> labels,Planet planet) { |
1075 |
|
1076 |
int height;
|
1077 |
AttrInTableLabelingStrategy strategy; |
1078 |
|
1079 |
// Creating a group node
|
1080 |
Group p = new Group(); |
1081 |
|
1082 |
// Getting total size
|
1083 |
int total = labels.size();
|
1084 |
|
1085 |
// this is for control a max of labels because the system not suport
|
1086 |
// more than 10000
|
1087 |
int max = 3000; |
1088 |
if (total > max)
|
1089 |
total = max; |
1090 |
|
1091 |
if (labels != null) { |
1092 |
for (int i = 0; i < total; i++) { |
1093 |
|
1094 |
|
1095 |
ILabel3D label3D = (ILabel3D) labels.get(i); |
1096 |
FLabel f = label3D.getFlabel(); |
1097 |
|
1098 |
// Set up parameters
|
1099 |
|
1100 |
// Getting color
|
1101 |
// Color co = f.getColor();
|
1102 |
Color co = new Color(255, 0, 0, 255); |
1103 |
if (label3D instanceof SimpleLabel3D) { |
1104 |
strategy = ((SimpleLabel3D) label3D).getStrategy(); |
1105 |
co = strategy.getFixedColor(); |
1106 |
height = strategy.getFont().getSize(); |
1107 |
} |
1108 |
float r, g, b, a;
|
1109 |
r = ((float) co.getRed()) / 255.0f; |
1110 |
g = ((float) co.getGreen()) / 255.0f; |
1111 |
b = ((float) co.getBlue()) / 255.0f; |
1112 |
a = ((float) co.getAlpha()) / 255.0f; |
1113 |
// Set color
|
1114 |
Vec4 textColor = new Vec4(r, g, b, a);
|
1115 |
|
1116 |
// Get label name
|
1117 |
String label = label3D.getTextField();
|
1118 |
// double heigth = h;
|
1119 |
Vec3 pos = null;
|
1120 |
Vec3 originalPos = null;
|
1121 |
originalPos = label3D.getPosition(); |
1122 |
if (planet.getCoordinateSystemType()== Planet.CoordinateSystemType.PROJECTED) {
|
1123 |
pos = new Vec3(originalPos.x(),originalPos.y(),originalPos.z());
|
1124 |
} else {
|
1125 |
// Transform geodesical coordinates to cartesian
|
1126 |
Vec3 posGeo = new Vec3(originalPos.y(),originalPos.x(),originalPos.z());
|
1127 |
|
1128 |
pos = planet.convertLatLongHeightToXYZ(posGeo); |
1129 |
} |
1130 |
|
1131 |
boolean inPixels = (label3D.getUnits() <= -1); |
1132 |
// height = (int)f.getHeight()/255;
|
1133 |
height = (int) label3D.getHeightField();;
|
1134 |
// Adding new child text nodes
|
1135 |
try {
|
1136 |
p.addChild(insertTextoS(label, pos,textColor,height , inPixels)); |
1137 |
// p.addChild(insertTextoS(label, pos,textColor,height , true));
|
1138 |
} catch (NodeException e) {
|
1139 |
logger.error("Command:" + "Error adding new child text.",e); |
1140 |
} |
1141 |
} |
1142 |
} |
1143 |
|
1144 |
// Optimizer generated nodes
|
1145 |
Optimizer opt = new Optimizer();
|
1146 |
try {
|
1147 |
opt.optimize(p, OptimizationOptions.SPATIALIZE_GROUPS); |
1148 |
} catch (InvalidValueException e) {
|
1149 |
logger.error("Command:" + "Error setting optimizer value.",e); |
1150 |
} catch (NodeException e) {
|
1151 |
logger.error("Command:" + "Error adding optimizer.",e); |
1152 |
} |
1153 |
|
1154 |
return p;
|
1155 |
|
1156 |
} |
1157 |
|
1158 |
} |