svn-gvsig-desktop / trunk / libraries / lib3DMap / src / org / gvsig / gvsig3d / gui / FeatureFactory.java @ 25189
History | View | Annotate | Download (29.5 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.Geometry; |
16 |
import org.gvsig.osgvp.Group; |
17 |
import org.gvsig.osgvp.Node; |
18 |
import org.gvsig.osgvp.Optimizer; |
19 |
import org.gvsig.osgvp.Vec3; |
20 |
import org.gvsig.osgvp.Vec4; |
21 |
import org.gvsig.osgvp.Optimizer.OptimizationOptions; |
22 |
import org.gvsig.osgvp.exceptions.InvalidValueException; |
23 |
import org.gvsig.osgvp.exceptions.node.NodeException; |
24 |
import org.gvsig.osgvp.features.PixelPoint; |
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.QuadPoint; |
29 |
import org.gvsig.osgvp.features.TessellablePolygon; |
30 |
import org.gvsig.osgvp.features.Text; |
31 |
import org.gvsig.osgvp.planets.Planet; |
32 |
|
33 |
import com.hardcode.gdbms.driver.exceptions.ReadDriverException; |
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 |
/**
|
475 |
* Create a new quad point node with a color, size and texture. Using a position of 3D
|
476 |
* points
|
477 |
*
|
478 |
* @param position
|
479 |
* Position of 3D point
|
480 |
* @param color
|
481 |
* Color of the 3D point
|
482 |
* @param tam
|
483 |
* Size of the point (in pixels)
|
484 |
* @return
|
485 |
*/
|
486 |
public static Node insertQuadPoints(Vec3[] position, Vec4 color, float tam, String texture) { |
487 |
// Creating point node
|
488 |
QuadPoint p = null;
|
489 |
try {
|
490 |
p = new QuadPoint(tam);
|
491 |
} catch (NodeException e) {
|
492 |
logger.error("command:" + "Error creating quad point.",e); |
493 |
} |
494 |
|
495 |
// Set up parameters and insert position
|
496 |
for (int i = 0; i < position.length; i++) { |
497 |
p.setPointSize(tam); |
498 |
p.addPoint(position[i], color); |
499 |
} |
500 |
|
501 |
// if (texture!=null)
|
502 |
// p.setTexture(texture);
|
503 |
|
504 |
try {
|
505 |
p.setBillboardingEnabled(true);
|
506 |
} catch (InvalidValueException e) {
|
507 |
logger.error("command:" + "Error setting billboarding value.",e); |
508 |
} |
509 |
|
510 |
|
511 |
// Optimizer generated nodes
|
512 |
Optimizer opt = new Optimizer();
|
513 |
try {
|
514 |
opt.optimize(p, OptimizationOptions.SPATIALIZE_GROUPS); |
515 |
} catch (InvalidValueException e) {
|
516 |
logger.error("command:" + "Error inciliazicing optimize values.",e); |
517 |
} catch (NodeException e) {
|
518 |
logger.error("command:" + "Error setting optimizer.",e); |
519 |
} |
520 |
|
521 |
// Return node
|
522 |
return p;
|
523 |
} |
524 |
/**
|
525 |
* Create a new tesselation poligon with a color using an array of 3D points
|
526 |
*
|
527 |
* @param points
|
528 |
* Array of 3D points
|
529 |
* @param color
|
530 |
* Color of the poligon
|
531 |
* @return Poligon node
|
532 |
*/
|
533 |
public static Node generateQuadPoligon(Vec3 position, Vec4 color,String texture,float tam) { |
534 |
// Creating a polygon
|
535 |
TessellablePolygon p = null;
|
536 |
try {
|
537 |
p = new TessellablePolygon();
|
538 |
} catch (NodeException e2) {
|
539 |
// TODO Auto-generated catch block
|
540 |
e2.printStackTrace(); |
541 |
} |
542 |
|
543 |
// PositionAttitudeTransform pt = new PositionAttitudeTransform();
|
544 |
AutoTransform pt = null;
|
545 |
try {
|
546 |
pt = new AutoTransform();
|
547 |
} catch (NodeException e2) {
|
548 |
// TODO Auto-generated catch block
|
549 |
e2.printStackTrace(); |
550 |
} |
551 |
try {
|
552 |
pt.addChild(p); |
553 |
} catch (NodeException e1) {
|
554 |
logger.error("Command:" + "Error adding new child.",e1); |
555 |
} |
556 |
pt.setPosition(position); |
557 |
try {
|
558 |
pt.setAutoRotateMode(AutoTransform.AutoRotateMode.ROTATE_TO_CAMERA); |
559 |
} catch (InvalidValueException e1) {
|
560 |
logger.error("command:" + "Error setting autorotate value.",e1); |
561 |
} |
562 |
// Set up parameters
|
563 |
// p.setType(Polygon.PolygonType.FILLED_POLYGON);
|
564 |
p.setWidth(2f);
|
565 |
// p.setPattern((short) 0xFFFF);
|
566 |
// p.setFactor(2);
|
567 |
p.setType(Polygon.PolygonType.FILLED_POLYGON);
|
568 |
// p.setType(Polygon.PolygonType.EMPTY_POLYGON);
|
569 |
// p.setType(Polygon.PolygonType.PATTERN_POLYGON);
|
570 |
|
571 |
Vec3 bl = new Vec3(-tam/2,-tam/2,0.0); |
572 |
Vec3 br = new Vec3(tam/2,-tam/2,0.0); |
573 |
Vec3 tr = new Vec3(tam/2,tam/2,0.0); |
574 |
Vec3 tl = new Vec3(-tam/2,tam/2,0.0); |
575 |
p.setEnabledBlending(true);
|
576 |
// Vector<Vec3> normal = new Vector<Vec3>();
|
577 |
// normal.add(new Vec3(0,0,1));
|
578 |
// p.setNormalArray(normal);
|
579 |
// p.setNormalBinding(Geometry.AttributeBinding.BIND_OVERALL);
|
580 |
|
581 |
try {
|
582 |
p.getOrCreateStateSet().setLightingMode(Mode.OFF | Mode.PROTECTED); |
583 |
} catch (InvalidValueException e) {
|
584 |
logger.error("command:" + "Error ",e); |
585 |
} |
586 |
p.addVertex(bl, color); |
587 |
p.addVertex(tl, color); |
588 |
p.addVertex(tr, color); |
589 |
p.addVertex(br, color); |
590 |
|
591 |
// p.setTwoSidedLighting(true);
|
592 |
|
593 |
// if there was any texture to put we would include it
|
594 |
if (texture != null) |
595 |
p.setTexture(texture); |
596 |
// Tesselation of this poligon
|
597 |
p.tesselate(); |
598 |
|
599 |
// Optimizer generated nodes
|
600 |
// Optimizer opt = new Optimizer();
|
601 |
// opt.optimize(pt, OptimizationOptions.SPATIALIZE_GROUPS);
|
602 |
|
603 |
// Return node
|
604 |
return pt;
|
605 |
} |
606 |
|
607 |
/**
|
608 |
* Create a new tesselation poligon with a color using an array of 3D points
|
609 |
*
|
610 |
* @param points
|
611 |
* Array of 3D points
|
612 |
* @param color
|
613 |
* Color of the poligon
|
614 |
* @return Poligon node
|
615 |
*/
|
616 |
public static Node insertPolygon(Vec3[] points, Vec4 color,String texture) { |
617 |
// Creating a polygon
|
618 |
TessellablePolygon p = null;
|
619 |
try {
|
620 |
p = new TessellablePolygon();
|
621 |
} catch (NodeException e1) {
|
622 |
// TODO Auto-generated catch block
|
623 |
e1.printStackTrace(); |
624 |
} |
625 |
|
626 |
// Set up parameters
|
627 |
// p.setType(Polygon.PolygonType.FILLED_POLYGON);
|
628 |
p.setWidth(2f);
|
629 |
// p.setPattern((short) 0xFFFF);
|
630 |
// p.setFactor(2);
|
631 |
p.setType(Polygon.PolygonType.FILLED_POLYGON);
|
632 |
// p.setType(Polygon.PolygonType.EMPTY_POLYGON);
|
633 |
// p.setType(Polygon.PolygonType.PATTERN_POLYGON);
|
634 |
|
635 |
// Adding points
|
636 |
for (int i = 0; i < points.length - 1; i++) { |
637 |
p.addVertex(points[i], color); |
638 |
// System.out.println("Position: " + inv[i].x() + " " + inv[i].y() +
|
639 |
// " " + inv[i].z());
|
640 |
} |
641 |
// if there was any texture to put we would include it
|
642 |
if (texture != null) |
643 |
p.setTexture(texture); |
644 |
// Tesselation of this poligon
|
645 |
p.tesselate(); |
646 |
|
647 |
// Optimizer generated nodes
|
648 |
Optimizer opt = new Optimizer();
|
649 |
try {
|
650 |
opt.optimize(p, OptimizationOptions.SPATIALIZE_GROUPS); |
651 |
} catch (InvalidValueException e) {
|
652 |
logger.error("Command:" + "Error setting optimize value.",e); |
653 |
} catch (NodeException e) {
|
654 |
logger.error("Command:" + "Error adding optimizer.",e); |
655 |
} |
656 |
|
657 |
// Return node
|
658 |
return p;
|
659 |
} |
660 |
|
661 |
|
662 |
|
663 |
/**
|
664 |
* Create a new tesselation poligon with a color using an List of 3D points
|
665 |
*
|
666 |
* @param points
|
667 |
* List of 3D points
|
668 |
* @param color
|
669 |
* Color of the poligon
|
670 |
* @return Poligon node
|
671 |
*/
|
672 |
public static Node insertPolygon(List points, Vec4 color,String texture) { |
673 |
// Creating a polygon
|
674 |
TessellablePolygon p = null;
|
675 |
try {
|
676 |
p = new TessellablePolygon();
|
677 |
} catch (NodeException e1) {
|
678 |
// TODO Auto-generated catch block
|
679 |
e1.printStackTrace(); |
680 |
} |
681 |
|
682 |
// Set up parameters
|
683 |
// p.setType(Polygon.PolygonType.FILLED_POLYGON);
|
684 |
p.setWidth(2f);
|
685 |
// p.setPattern((short) 0xFFFF);
|
686 |
// p.setFactor(2);
|
687 |
p.setType(Polygon.PolygonType.FILLED_POLYGON);
|
688 |
// p.setType(Polygon.PolygonType.EMPTY_POLYGON);
|
689 |
// p.setType(Polygon.PolygonType.PATTERN_POLYGON);
|
690 |
|
691 |
// Blending only is active if the alpha component are diferent that 1
|
692 |
if (color.w() != 1) { |
693 |
p.setEnabledBlending(true);
|
694 |
} |
695 |
// Adding points
|
696 |
for (int i = 0; i < points.size(); i++) { |
697 |
Vec3 element = (Vec3) points.get(i); |
698 |
p.addVertex(element, color); |
699 |
} |
700 |
|
701 |
|
702 |
// p.setTexture("C:/modelos3d/Images/land_shallow_topo_2048.jpg");
|
703 |
// if there was any texture to put we would include it
|
704 |
if (texture != null) |
705 |
p.setTexture(texture); |
706 |
// Tesselation of this poligon
|
707 |
p.tesselate(); |
708 |
|
709 |
// Optimizer generated nodes
|
710 |
Optimizer opt = new Optimizer();
|
711 |
try {
|
712 |
opt.optimize(p, OptimizationOptions.ALL_OPTIMIZATIONS); |
713 |
} catch (InvalidValueException e) {
|
714 |
logger.error("Command:" + "Error setting optimizer value.",e); |
715 |
} catch (NodeException e) {
|
716 |
logger.error("Command:" + "Error adding optimizer.",e); |
717 |
} |
718 |
|
719 |
// Return node
|
720 |
return p;
|
721 |
} |
722 |
public static Node insertPolygonExtruded(List points, Vec4 color,String texture,double heigth) { |
723 |
// Creating a polygon
|
724 |
Polygon p = null; |
725 |
try {
|
726 |
p = new Polygon(); |
727 |
} catch (NodeException e1) {
|
728 |
// TODO Auto-generated catch block
|
729 |
e1.printStackTrace(); |
730 |
} |
731 |
|
732 |
// Set up parameters
|
733 |
// p.setType(Polygon.PolygonType.FILLED_POLYGON);
|
734 |
p.setWidth(2f);
|
735 |
// p.setPattern((short) 0xFFFF);
|
736 |
// p.setFactor(2);
|
737 |
p.setType(Polygon.PolygonType.FILLED_POLYGON);
|
738 |
// p.setType(Polygon.PolygonType.EMPTY_POLYGON);
|
739 |
// p.setType(Polygon.PolygonType.PATTERN_POLYGON);
|
740 |
|
741 |
// Blending only is active if the alpha component are diferent that 1
|
742 |
// if (color.w() != 1) {
|
743 |
// p.setEnabledBlending(true);
|
744 |
// }
|
745 |
List positionTapa = new ArrayList(); |
746 |
// Adding points
|
747 |
for (int i = 0; i < points.size(); i++) { |
748 |
Vec3 element = (Vec3) points.get(i); |
749 |
Vec3 elementTapa = new Vec3(element.x(),element.y(),element.z()+heigth);
|
750 |
positionTapa.add(elementTapa); |
751 |
// System.out.println("posicion : " + element.z());
|
752 |
p.addVertex(element, color); |
753 |
} |
754 |
|
755 |
|
756 |
|
757 |
PolygonExtruder pe = new PolygonExtruder();
|
758 |
pe.extrude(p,new Vec3 (0.0,0.0,1.0), heigth); |
759 |
|
760 |
|
761 |
// Optimizer generated nodes
|
762 |
Optimizer opt = new Optimizer();
|
763 |
Node node = null;
|
764 |
try {
|
765 |
opt.optimize(p, OptimizationOptions.ALL_OPTIMIZATIONS); |
766 |
node = FeatureFactory.insertPolygon(positionTapa, color, null);
|
767 |
opt.optimize(node, OptimizationOptions.ALL_OPTIMIZATIONS); |
768 |
|
769 |
} catch (InvalidValueException e) {
|
770 |
logger.error("Command:" + "Error setting optimizer value.",e); |
771 |
} catch (NodeException e) {
|
772 |
logger.error("Command:" + "Error adding optimizer.",e); |
773 |
} |
774 |
Group group = new Group(); |
775 |
Geode geode = new Geode();
|
776 |
|
777 |
geode.getOrCreateStateSet().setTwoSidedLighting(true);
|
778 |
try {
|
779 |
geode.addDrawable(pe.getGeometry()); |
780 |
group.addChild(geode); |
781 |
group.addChild(node); |
782 |
// if (color.w() != 1) {
|
783 |
// group.getOrCreateStateSet().setEnabledBlending(true);
|
784 |
// }
|
785 |
} catch (NodeException e) {
|
786 |
logger.error("Command:" + "Error adding drawable object.",e); |
787 |
} |
788 |
|
789 |
// Return node
|
790 |
// return geode;
|
791 |
return group;
|
792 |
} |
793 |
/**
|
794 |
* Method to create a new 3D line. With a List of 3D points and a color
|
795 |
*
|
796 |
* @param points
|
797 |
* List of 3D points
|
798 |
* @param color
|
799 |
* Color of the line
|
800 |
* @return
|
801 |
*
|
802 |
*/
|
803 |
public static Node insertLine(List points, Vec4 color, float size) { |
804 |
Vec3 ori = null, fin = null; |
805 |
|
806 |
// Getting first points
|
807 |
if (points.size() > 1) { |
808 |
ori = (Vec3) points.get(0);
|
809 |
fin = (Vec3) points.get(1);
|
810 |
} |
811 |
|
812 |
// If the line do not have more than 2 points return null
|
813 |
if ((ori == null) || (fin == null)) |
814 |
return null; |
815 |
|
816 |
// Create new polyline
|
817 |
Polyline p = null;
|
818 |
try {
|
819 |
p = new Polyline(ori, fin);
|
820 |
} catch (NodeException e1) {
|
821 |
// TODO Auto-generated catch block
|
822 |
e1.printStackTrace(); |
823 |
} |
824 |
p.setVertexColor(0, color);
|
825 |
p.setVertexColor(1, color);
|
826 |
|
827 |
// Set up parameters
|
828 |
p.setWidth(size); |
829 |
p.setPattern((short) 0xFFFF); |
830 |
p.setFactor(2);
|
831 |
|
832 |
// Blending only is active if the alpha component are diferent that 1
|
833 |
if (color.w() != 1) { |
834 |
p.setEnabledBlending(true);
|
835 |
} |
836 |
|
837 |
// Enabling antialiasing
|
838 |
p.setEnabledSmoothing(true);
|
839 |
|
840 |
p.setColor(color); |
841 |
|
842 |
// Adding points
|
843 |
for (int i = 2; i < points.size(); i++) { |
844 |
Vec3 element = (Vec3) points.get(i); |
845 |
p.addVertex(element, color); |
846 |
} |
847 |
|
848 |
// Optimizer generated nodes
|
849 |
Optimizer opt = new Optimizer();
|
850 |
try {
|
851 |
opt.optimize(p); |
852 |
} catch (NodeException e) {
|
853 |
logger.error("Command:" + "Error adding optimizer.",e); |
854 |
} |
855 |
|
856 |
// Return node
|
857 |
return p;
|
858 |
|
859 |
} |
860 |
|
861 |
/**
|
862 |
* Create a new group of 3D points with a color and size. Using a List of 3D
|
863 |
* points
|
864 |
*
|
865 |
* @param points
|
866 |
* List of 3D points
|
867 |
* @param color
|
868 |
* Color of the line
|
869 |
* @param size
|
870 |
* Size of the point (in pixels)
|
871 |
* @return
|
872 |
*/
|
873 |
public static Node insertPointL(List points, Vec4 color, float size) { |
874 |
// Creating point
|
875 |
PixelPoint p = null;
|
876 |
try {
|
877 |
p = new PixelPoint();
|
878 |
} catch (NodeException e1) {
|
879 |
// TODO Auto-generated catch block
|
880 |
e1.printStackTrace(); |
881 |
} |
882 |
|
883 |
// Set up parameters
|
884 |
p.setPointSize(size); |
885 |
|
886 |
// Adding points
|
887 |
for (int i = 0; i < points.size(); i++) { |
888 |
Vec3 element = (Vec3) points.get(i); |
889 |
p.addPoint(element, color); |
890 |
} |
891 |
|
892 |
// Optimizer generated nodes
|
893 |
Optimizer opt = new Optimizer();
|
894 |
try {
|
895 |
opt.optimize(p); |
896 |
} catch (NodeException e) {
|
897 |
logger.error("Command:" + "Error adding optimizer.",e); |
898 |
} |
899 |
|
900 |
// Return node
|
901 |
return p;
|
902 |
|
903 |
} |
904 |
|
905 |
/**
|
906 |
* Create a new group of 3D labels with a size and heigth. Using a List of
|
907 |
* 3D points
|
908 |
*
|
909 |
* @param labels
|
910 |
* List of Flabels
|
911 |
*
|
912 |
* @param size
|
913 |
* Size of the labels
|
914 |
* @param heigth
|
915 |
* Heigth of labels
|
916 |
* @param inPixels
|
917 |
* True indicates that size is in pixel and false indicates real
|
918 |
* size;
|
919 |
* @param type
|
920 |
* @return Node group
|
921 |
*/
|
922 |
public static Node insertLabels(List labels, int size, float heigth, |
923 |
boolean inPixels, int planetType) { |
924 |
// Creating a group node
|
925 |
Group p = new Group(); |
926 |
|
927 |
// Getting total size
|
928 |
int total = labels.size();
|
929 |
|
930 |
// this is for control a max of labels because the system not suport
|
931 |
// more than 10000
|
932 |
int max = 3000; |
933 |
if (total > max)
|
934 |
total = max; |
935 |
|
936 |
if (labels != null) { |
937 |
for (int i = 0; i < total; i++) { |
938 |
FLabel f = (FLabel) labels.get(i); |
939 |
|
940 |
// Set up parameters
|
941 |
|
942 |
// Getting color
|
943 |
// Color co = f.getColor();
|
944 |
Color co = new Color(255, 255, 255, 255); |
945 |
float r, g, b, a;
|
946 |
r = ((float) co.getRed()) / 255.0f; |
947 |
g = ((float) co.getGreen()) / 255.0f; |
948 |
b = ((float) co.getBlue()) / 255.0f; |
949 |
a = ((float) co.getAlpha()) / 255.0f; |
950 |
// Set color
|
951 |
Vec4 textColor = new Vec4(r, g, b, a);
|
952 |
|
953 |
// Get label name
|
954 |
String label = f.getString();
|
955 |
// double heigth = h;
|
956 |
Vec3 pos = null;
|
957 |
if (planetType == Planet.CoordinateSystemType.PROJECTED) {
|
958 |
pos = new Vec3(f.getOrig().getX(), f.getOrig().getY(),
|
959 |
heigth); |
960 |
} else {
|
961 |
// Transform geodesical coordinates to cartesian
|
962 |
Vec3 posGeo = new Vec3(f.getOrig().getY(), f.getOrig()
|
963 |
.getX(), heigth); |
964 |
|
965 |
pos = planet.convertLatLongHeightToXYZ(posGeo); |
966 |
} |
967 |
|
968 |
// Adding new child text nodes
|
969 |
try {
|
970 |
p.addChild(insertTextoS(label, pos, textColor, size, inPixels)); |
971 |
} catch (NodeException e) {
|
972 |
logger.error("Command:" + "Error adding new child text.",e); |
973 |
} |
974 |
} |
975 |
} |
976 |
|
977 |
// Optimizer generated nodes
|
978 |
Optimizer opt = new Optimizer();
|
979 |
try {
|
980 |
opt.optimize(p, OptimizationOptions.SPATIALIZE_GROUPS); |
981 |
} catch (InvalidValueException e) {
|
982 |
logger.error("Command:" + "Error setting optimizer value.",e); |
983 |
} catch (NodeException e) {
|
984 |
logger.error("Command:" + "Error adding optimizer.",e); |
985 |
} |
986 |
|
987 |
return p;
|
988 |
|
989 |
} |
990 |
|
991 |
/**
|
992 |
* Create a new group of 3D labels with a size and heigth. Using a List of
|
993 |
* 3D points
|
994 |
*
|
995 |
* @param labels
|
996 |
* List of Flabels
|
997 |
*
|
998 |
* @param size
|
999 |
* Size of the labels
|
1000 |
* @param heigth
|
1001 |
* Heigth of labels
|
1002 |
* @param inPixels
|
1003 |
* True indicates that size is in pixel and false indicates real
|
1004 |
* size;
|
1005 |
* @param type
|
1006 |
* @return Node group
|
1007 |
*/
|
1008 |
public static Node insertLabels(List<ILabel3D> labels,Planet planet) { |
1009 |
|
1010 |
int height;
|
1011 |
AttrInTableLabelingStrategy strategy; |
1012 |
|
1013 |
// Creating a group node
|
1014 |
Group p = new Group(); |
1015 |
|
1016 |
// Getting total size
|
1017 |
int total = labels.size();
|
1018 |
|
1019 |
// this is for control a max of labels because the system not suport
|
1020 |
// more than 10000
|
1021 |
int max = 3000; |
1022 |
if (total > max)
|
1023 |
total = max; |
1024 |
|
1025 |
if (labels != null) { |
1026 |
for (int i = 0; i < total; i++) { |
1027 |
|
1028 |
|
1029 |
ILabel3D label3D = (ILabel3D) labels.get(i); |
1030 |
FLabel f = label3D.getFlabel(); |
1031 |
|
1032 |
// Set up parameters
|
1033 |
|
1034 |
// Getting color
|
1035 |
// Color co = f.getColor();
|
1036 |
Color co = new Color(255, 0, 0, 255); |
1037 |
if (label3D instanceof SimpleLabel3D) { |
1038 |
strategy = ((SimpleLabel3D) label3D).getStrategy(); |
1039 |
co = strategy.getFixedColor(); |
1040 |
height = strategy.getFont().getSize(); |
1041 |
} |
1042 |
float r, g, b, a;
|
1043 |
r = ((float) co.getRed()) / 255.0f; |
1044 |
g = ((float) co.getGreen()) / 255.0f; |
1045 |
b = ((float) co.getBlue()) / 255.0f; |
1046 |
a = ((float) co.getAlpha()) / 255.0f; |
1047 |
// Set color
|
1048 |
Vec4 textColor = new Vec4(r, g, b, a);
|
1049 |
|
1050 |
// Get label name
|
1051 |
String label = label3D.getTextField();
|
1052 |
// double heigth = h;
|
1053 |
Vec3 pos = null;
|
1054 |
Vec3 originalPos = null;
|
1055 |
originalPos = label3D.getPosition(); |
1056 |
if (planet.getCoordinateSystemType()== Planet.CoordinateSystemType.PROJECTED) {
|
1057 |
pos = new Vec3(originalPos.x(),originalPos.y(),originalPos.z());
|
1058 |
} else {
|
1059 |
// Transform geodesical coordinates to cartesian
|
1060 |
Vec3 posGeo = new Vec3(originalPos.y(),originalPos.x(),originalPos.z());
|
1061 |
|
1062 |
pos = planet.convertLatLongHeightToXYZ(posGeo); |
1063 |
} |
1064 |
|
1065 |
boolean inPixels = (label3D.getUnits() <= -1); |
1066 |
// height = (int)f.getHeight()/255;
|
1067 |
height = (int) label3D.getHeightField();;
|
1068 |
// Adding new child text nodes
|
1069 |
try {
|
1070 |
p.addChild(insertTextoS(label, pos,textColor,height , inPixels)); |
1071 |
// p.addChild(insertTextoS(label, pos,textColor,height , true));
|
1072 |
} catch (NodeException e) {
|
1073 |
logger.error("Command:" + "Error adding new child text.",e); |
1074 |
} |
1075 |
} |
1076 |
} |
1077 |
|
1078 |
// Optimizer generated nodes
|
1079 |
Optimizer opt = new Optimizer();
|
1080 |
try {
|
1081 |
opt.optimize(p, OptimizationOptions.SPATIALIZE_GROUPS); |
1082 |
} catch (InvalidValueException e) {
|
1083 |
logger.error("Command:" + "Error setting optimizer value.",e); |
1084 |
} catch (NodeException e) {
|
1085 |
logger.error("Command:" + "Error adding optimizer.",e); |
1086 |
} |
1087 |
|
1088 |
return p;
|
1089 |
|
1090 |
} |
1091 |
|
1092 |
} |