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