Statistics
| Revision:

root / trunk / libraries / lib3DMap / src / com / iver / ai2 / gvsig3d / gui / FeatureFactory.java @ 21937

History | View | Annotate | Download (28.3 KB)

1
package com.iver.ai2.gvsig3d.gui;
2

    
3
import java.awt.Color;
4
import java.util.HashMap;
5
import java.util.Iterator;
6
import java.util.List;
7

    
8
import org.apache.log4j.Logger;
9
import org.gvsig.gvsig3d.resources.ResourcesFactory;
10
import org.gvsig.osgvp.AutoTransform;
11
import org.gvsig.osgvp.Geode;
12
import org.gvsig.osgvp.Group;
13
import org.gvsig.osgvp.Node;
14
import org.gvsig.osgvp.Optimizer;
15
import org.gvsig.osgvp.Vec3;
16
import org.gvsig.osgvp.Vec4;
17
import org.gvsig.osgvp.Optimizer.OptimizationOptions;
18
import org.gvsig.osgvp.exceptions.InvalidValueException;
19
import org.gvsig.osgvp.exceptions.node.NodeException;
20
import org.gvsig.osgvp.features.PixelPoint;
21
import org.gvsig.osgvp.features.Polygon;
22
import org.gvsig.osgvp.features.PolygonExtruder;
23
import org.gvsig.osgvp.features.Polyline;
24
import org.gvsig.osgvp.features.QuadPoint;
25
import org.gvsig.osgvp.features.TessellablePolygon;
26
import org.gvsig.osgvp.features.Text;
27
import org.gvsig.osgvp.planets.Planet;
28

    
29
import com.iver.ai2.gvsig3d.labels3D.ILabel3D;
30
import com.iver.ai2.gvsig3d.utils.Punto3D;
31
import com.iver.cit.gvsig.fmap.core.v02.FLabel;
32

    
33
public class FeatureFactory extends Group {
34

    
35
        private static double radius;
36

    
37
        static Planet planet;
38
        
39
        private static Logger logger = Logger.getLogger(Hud.class.getName());
40

    
41
        public FeatureFactory(double ra, Planet m_planet) {
42
                super();
43
                radius = ra;
44
                // this.setNodeName("VECTOR");
45
                planet = m_planet;
46
                init();
47
        }
48

    
49
        private void init() {
50

    
51
                // this.addChild(insertTexto("Polo norte", poloNorte));
52
                // this.addChild(insertTexto("MADRID", valenciaCar));
53

    
54
                // Vec3 posIni = new Vec3(0, 0, 0);
55
                // Vec3 posEnd = new Vec3(0, 0, 100000);
56

    
57
                // Polyline line = (Polyline) VectorTest.insertLineS(posIni, posEnd,
58
                // new Vec4(1.0, 1.0, 1.0, 1.0), 0);
59
                // if (planet.getType() == PlanetType.PLANE_MODE)
60
                // this.addChild(line);
61

    
62
        }
63

    
64
        // public Node insertTexto(String texto, Vec3 posicion) {
65
        // // A�adiendo texto
66
        // Text text = new Text();
67
        // // text.setNodeName(texto);
68
        // text.setText(texto);
69
        // text.setCharacterSize(32);
70
        //
71
        // text.setAxisAlignment(Text.AxisAlignment.SCREEN);
72
        // text.setAlignment(Text.AlignmentType.CENTER_CENTER);
73
        // text.setCharacterSizeMode(Text.CharacterSizeMode.SCREEN_COORDS);
74
        // text.setPosition((float) posicion.x(), (float) posicion.y(),
75
        // (float) posicion.z());
76
        //
77
        // if (ResourcesFactory.exitsResouce("arial.ttf"))
78
        // text.setFont(ResourcesFactory.getResourcePath("arial.ttf"));
79
        // else
80
        // text.setFont("arial.ttf");
81
        // text.setAutoRotateToScreen(true);
82
        //                
83
        //                
84
        // Optimizer opt = new Optimizer();
85
        // opt.optimizeOptions(text, OptimizationOptions.SPATIALIZE_GROUPS);
86
        //                
87
        // return text;
88
        // }
89
        // /**
90
        // * this method create a new 3D text. With a value and position. And insert
91
        // a
92
        // * point under 3D text
93
        // *
94
        // * @param texto
95
        // * text that is visible in 3D
96
        // * @param position
97
        // * Position of 3D text in cartesian coordinates
98
        // * @return New node
99
        // */
100
        // public void insertText(String texto, Vec3 posicion) {
101
        // posicion.setZ(posicion.z() + radius);
102
        // Vec3 e = planet.convertLatLongHeightToXYZ(posicion);
103
        //
104
        // this.addChild(insertPoint(e, new Vec4(1.0, 0, 0, 1.0)));
105
        //
106
        // this.addChild(insertTexto(texto, e));
107
        // }
108
        //
109
        // /**
110
        // * this method create a new 3D point. With a color and position
111
        // *
112
        // * @param color
113
        // * Color of the point
114
        // * @param position
115
        // * Position of 3D point in cartesian coordinates
116
        // * @return
117
        // */
118
        // public Node insertPoint(Vec3 position, Vec4 color) {
119
        // // Creating point
120
        // Point p = new Point();
121
        //
122
        // // Adding position and color
123
        // for (int i = 0; i < 1; i++) {
124
        // p.setPointSize(100);
125
        // p.addPoint(position, color);
126
        // }
127
        //
128
        // return p;
129
        // }
130

    
131
        /**
132
         * Method to create a new 3D text. With a value and position. Text aligment
133
         * is LEFT CENTER, and his font is "Arial.ttf"
134
         * 
135
         * @param texto
136
         *            Text that is visible in 3D
137
         * @param position
138
         *            Position of 3D text in cartesian coordinates
139
         * @return New node
140
         */
141
        public static Node insertTextoS(String texto, Vec3 position, Vec4 color,
142
                        int tam, boolean inPixels) {
143

    
144
                // Creating text node
145
                Text text = null;
146
                try {
147
                        text = new Text();
148
                } catch (NodeException e1) {
149
                        // TODO Auto-generated catch block
150
                        e1.printStackTrace();
151
                }
152
                // Set up text properties
153
                text.setText(texto);
154
                text.setCharacterSize(tam);
155
                // Select that the text will be in pixels or screen coordinates
156
                if (inPixels) {
157
                        text.setCharacterSizeMode(Text.CharacterSizeMode.SCREEN_COORDS);
158
                } else {
159
                        text.setCharacterSizeMode(Text.CharacterSizeMode.OBJECT_COORDS);
160
                }
161
                text.setColor(color);
162
                text.setAxisAlignment(Text.AxisAlignment.SCREEN);
163
                text.setAlignment(Text.AlignmentType.LEFT_BOTTOM);
164
                text.setPosition((float) position.x(), (float) position.y(),
165
                                (float) position.z());
166

    
167
                // Search font in resources directori
168
                if (ResourcesFactory.exitsResouce("arial.ttf"))
169
                        text.setFont(ResourcesFactory.getResourcePath("arial.ttf"));
170
                else
171
                        text.setFont("arial.ttf");
172
                text.setAutoRotateToScreen(true);
173

    
174
                // Optimizer generated nodes
175
                Optimizer opt = new Optimizer();
176
                try {
177
                        opt.optimize(text, OptimizationOptions.SPATIALIZE_GROUPS);
178
                } catch (InvalidValueException e) {
179
                        // TODO Auto-generated catch block
180
                        e.printStackTrace();
181
                } catch (NodeException e) {
182
                        // TODO Auto-generated catch block
183
                        e.printStackTrace();
184
                }
185

    
186
                // Return node
187
                return text;
188

    
189
        }
190

    
191
        /**
192
         * Method to create a new 3D point. With a color, heigth and position.
193
         * 
194
         * @param position
195
         *            Position of 3D text in cartesian coordinates
196
         * @param color
197
         *            color of the 3D point
198
         * @param tam
199
         *            the heigth of the point
200
         * @return New text node
201
         */
202
        public static Node insertPointS(Vec3 position, Vec4 color, int tam) {
203
                AutoTransform au = null;
204
                try {
205
                        au = new AutoTransform();
206
                } catch (NodeException e2) {
207
                        // TODO Auto-generated catch block
208
                        e2.printStackTrace();
209
                }
210
                // Creating point
211
                PixelPoint p = null;
212
                try {
213
                        p = new PixelPoint();
214
                } catch (NodeException e1) {
215
                        // TODO Auto-generated catch block
216
                        e1.printStackTrace();
217
                }
218
                // p.setDistanceAttenuation(new Vec3(0.0,0.0,0.0000001));
219
                p.setPointSize(tam);
220
                p.addPoint(position, color);
221

    
222
                try {
223
                        au.addChild(p);
224
                } catch (NodeException e) {
225
                        logger.error("command:" + "Error adding new child.",e);
226
                }
227
                // return au;
228
                return p;
229
        }
230

    
231
        /**
232
         * Method to create a new 3D point. With a color, heigth and position.
233
         * 
234
         * @param hash
235
         *            Hash Table that contains "Puntos3D" elements
236
         * @return
237
         */
238
        public static Node insertPointS(HashMap hash) {
239

    
240
                Group g = new Group();
241

    
242
                // Iterate over the keys in the map
243
                Iterator it = hash.keySet().iterator();
244
                while (it.hasNext()) {
245
                        // Get key
246
                        Double key = (Double) it.next();
247
                        List list = (List) hash.get(key);
248

    
249
                        PixelPoint p = null;
250
                        try {
251
                                p = new PixelPoint();
252
                        } catch (NodeException e1) {
253
                                // TODO Auto-generated catch block
254
                                e1.printStackTrace();
255
                        }
256
//                        ShapePoint p = new ShapePoint();
257
//                        es.upv.ai2.osgvp.features.Sphere s = new Sphere();
258
//                        p.setShape(s);
259
//                        s.setRadius(100);
260
                        for (Iterator iter = list.iterator(); iter.hasNext();) {
261
                                // Getting PixelPoint
262
                                Punto3D element = (Punto3D) iter.next();
263
//                                Vec4 color = element.getColor();
264
                                Vec4 color = new Vec4(1,0,0,1);
265
                                
266
                                // Blending only is active if the alpha component are diferent
267
                                // that 1
268
                                if (color.w() != 1) {
269
                                        p.setEnabledBlending(true);
270
                                }
271
                                // Enabling antialiasing
272
                                p.setEnabledSmoothing(true);
273

    
274
                                // Set up size, position and color
275
//                                p.setPointSize(element.getZize());
276
                                p.setPointSize(20);
277
                                try {
278
                                        p.getOrCreateStateSet().setLightingMode(Node.Mode.OFF | Node.Mode.PROTECTED);
279
                                } catch (InvalidValueException e) {
280
                                        logger.error("command:" + "Error setting new lighthing mode.",e);
281
                                }
282
                                p.addPoint(element.getPosition(), color);
283
//                                System.err.println("posicion del punto " +element.getPosition());
284
                        }
285
                        // Adding points to group
286
                        try {
287
                                g.addChild(p);
288
                        } catch (NodeException e) {
289
                                logger.error("command:" + "Error adding new child node.",e);
290
                        }
291
                }
292
//                System.out.println("nuevo grupo");
293

    
294
                // Optimizer generated nodes
295
//                Optimizer opt = new Optimizer();
296
//                opt.optimize(g, OptimizationOptions.SPATIALIZE_GROUPS);
297

    
298
                return g;
299
        }
300

    
301
        /**
302
         * Method to add 3D points to specific point type. With a color, heigth and
303
         * position.
304
         * 
305
         * @param point
306
         *            Node to add new 3D point
307
         * @param position
308
         *            Position of 3D text in cartesian coordinates
309
         * @param color
310
         *            color of the 3D point
311
         * @param tam
312
         *            the heigth of the point
313
         * @return New text node
314
         */
315
        public static void addPointToNode(Node point, Vec3 position, Vec4 color,
316
                        int tam) {
317

    
318
                PixelPoint p = null;
319
                // Getting point
320
                if (point != null)
321
                        p = (PixelPoint) point;
322

    
323
                // If not exits create new
324
                if (p == null)
325
                        try {
326
                                p = new PixelPoint();
327
                        } catch (NodeException e1) {
328
                                // TODO Auto-generated catch block
329
                                e1.printStackTrace();
330
                        }
331

    
332
                // Blending only is active if the alpha component are diferent that 1
333
                if (color.w() != 1) {
334
                        p.setEnabledBlending(true);
335
                }
336

    
337
                // Set up size, position and color
338
                p.setPointSize(tam);
339
                p.addPoint(position, color);
340

    
341
                // Optimizer generated nodes
342
                Optimizer opt = new Optimizer();
343
                try {
344
                        opt.optimize(p, OptimizationOptions.SPATIALIZE_GROUPS);
345
                } catch (InvalidValueException e) {
346
                        logger.error("command:" + "Error Inicializing value.",e);
347
                } catch (NodeException e) {
348
                        logger.error("command:" + "Error node exception.",e);
349
                }
350

    
351
        }
352

    
353
        /**
354
         * Method to create a new 3D line. With a color, heigth and position.
355
         * 
356
         * @param ini
357
         *            Initial position of line
358
         * @param end
359
         *            End positon of line.
360
         * @param color
361
         *            color of the 3D point
362
         * @param tam
363
         *            the heigth of the point
364
         * @return New line node
365
         */
366

    
367
        public static Node insertLineS(Vec3 ini, Vec3 end, Vec4 color, int tam) {
368
                // Creating a polyline
369
                Polyline p = null;
370
                try {
371
                        p = new Polyline(ini, end);
372
                } catch (NodeException e1) {
373
                        // TODO Auto-generated catch block
374
                        e1.printStackTrace();
375
                }
376

    
377
                // Set up parameter
378
                p.setWidth(2f);
379
                p.setPattern((short) 0xFFFF);
380
                p.setFactor(2);
381
                p.setColor(color);
382

    
383
                // Optimize the node
384
                Optimizer opt = new Optimizer();
385
                try {
386
                        opt.optimize(p);
387
                } catch (NodeException e) {
388
                        logger.error("command:" + "Error setting the optimizer.",e);
389
                }
390

    
391
                // Return the node
392
                return p;
393
        }
394

    
395
        /**
396
         * Method to add new points to specific line type. With a color, heigth and
397
         * position.
398
         * 
399
         * @param line
400
         *            Node to add new point
401
         * @param position
402
         *            Position of 3D point in cartesian coordinates
403
         * @param color
404
         *            color of the 3D point
405
         * @param tam
406
         *            the heigth of the point
407
         */
408
        public static void addNodeToLine(Node line, Vec3 position, Vec4 color,
409
                        int tam) {
410
                // Getting polyline
411
                Polyline p = (Polyline) line;
412

    
413
                // If not exits, create a new
414
                if (p == null)
415
                        try {
416
                                p = new Polyline(position, position);
417
                        } catch (NodeException e) {
418
                                // TODO Auto-generated catch block
419
                                e.printStackTrace();
420
                        }
421

    
422
                // Add a point and color
423
                p.addVertex(position, color);
424

    
425
        }
426

    
427
        /**
428
         * Create a new point node with a color and size. Using a position of 3D
429
         * points
430
         * 
431
         * @param position
432
         *            Position of 3D point
433
         * @param color
434
         *            Color of the 3D point
435
         * @param tam
436
         *            Size of the point (in pixels)
437
         * @return
438
         */
439
        public static Node insertPointS(Vec3[] position, Vec4 color, int tam) {
440
                // Creating point node
441
                PixelPoint p = null;
442
                try {
443
                        p = new PixelPoint();
444
                } catch (NodeException e1) {
445
                        // TODO Auto-generated catch block
446
                        e1.printStackTrace();
447
                }
448

    
449
                // Set up parameters and insert position
450
                for (int i = 0; i < position.length; i++) {
451
                        p.setPointSize(tam);
452
                        p.addPoint(position[i], color);
453
                }
454

    
455
                // Optimizer generated nodes
456
                Optimizer opt = new Optimizer();
457
                try {
458
                        opt.optimize(p, OptimizationOptions.SPATIALIZE_GROUPS);
459
                } catch (InvalidValueException e) {
460
                        logger.error("command:" + "Error inicializing value for the optimizer.",e);
461
                } catch (NodeException e) {
462
                        logger.error("command:" + "Error adding the optimizer.",e);
463
                }
464

    
465
                // Return node
466
                return p;
467
        }
468
        
469
        /**
470
         * Create a new quad point node with a color, size and texture. Using a position of 3D
471
         * points
472
         * 
473
         * @param position
474
         *            Position of 3D point
475
         * @param color
476
         *            Color of the 3D point
477
         * @param tam
478
         *            Size of the point (in pixels)
479
         * @return
480
         */
481
        public static Node insertQuadPoints(Vec3[] position, Vec4 color, float tam, String texture) {
482
                // Creating point node
483
                QuadPoint p = null;
484
                try {
485
                        p = new QuadPoint(tam);
486
                } catch (NodeException e) {
487
                        logger.error("command:" + "Error creating quad point.",e);
488
                }
489

    
490
                // Set up parameters and insert position
491
                for (int i = 0; i < position.length; i++) {
492
                        p.setPointSize(tam);
493
                        p.addPoint(position[i], color);
494
                }
495
        
496
//                if (texture!=null)
497
//                        p.setTexture(texture);
498
                
499
                try {
500
                        p.setBillboardingEnabled(true);
501
                } catch (InvalidValueException e) {
502
                        logger.error("command:" + "Error setting billboarding value.",e);
503
                }
504
                
505
                
506
                // Optimizer generated nodes
507
                Optimizer opt = new Optimizer();
508
                try {
509
                        opt.optimize(p, OptimizationOptions.SPATIALIZE_GROUPS);
510
                } catch (InvalidValueException e) {
511
                        logger.error("command:" + "Error inciliazicing optimize values.",e);
512
                } catch (NodeException e) {
513
                        logger.error("command:" + "Error setting optimizer.",e);
514
                }
515

    
516
                // Return node
517
                return p;
518
        }
519
        /**
520
         * Create a new tesselation poligon with a color using an array of 3D points
521
         * 
522
         * @param points
523
         *            Array of 3D points
524
         * @param color
525
         *            Color of the poligon
526
         * @return Poligon node
527
         */
528
        public static Node generateQuadPoligon(Vec3 position, Vec4 color,String texture,float tam) {
529
                // Creating a polygon
530
                TessellablePolygon p = null;
531
                try {
532
                        p = new TessellablePolygon();
533
                } catch (NodeException e2) {
534
                        // TODO Auto-generated catch block
535
                        e2.printStackTrace();
536
                }
537

    
538
//                PositionAttitudeTransform pt = new PositionAttitudeTransform();
539
                AutoTransform pt = null;
540
                try {
541
                        pt = new AutoTransform();
542
                } catch (NodeException e2) {
543
                        // TODO Auto-generated catch block
544
                        e2.printStackTrace();
545
                }
546
                try {
547
                        pt.addChild(p);
548
                } catch (NodeException e1) {
549
                        logger.error("Command:" + "Error adding new child.",e1);
550
                }
551
                pt.setPosition(position);
552
                try {
553
                        pt.setAutoRotateMode(AutoTransform.AutoRotateMode.ROTATE_TO_CAMERA);
554
                } catch (InvalidValueException e1) {
555
                        logger.error("command:" + "Error setting autorotate value.",e1);
556
                }
557
                // Set up parameters
558
                // p.setType(Polygon.PolygonType.FILLED_POLYGON);
559
                p.setWidth(2f);
560
                // p.setPattern((short) 0xFFFF);
561
                // p.setFactor(2);
562
                p.setType(Polygon.PolygonType.FILLED_POLYGON);
563
                // p.setType(Polygon.PolygonType.EMPTY_POLYGON);
564
                // p.setType(Polygon.PolygonType.PATTERN_POLYGON);
565
                
566
                Vec3 bl = new Vec3(-tam/2,-tam/2,0.0);
567
                Vec3 br = new Vec3(tam/2,-tam/2,0.0);
568
                Vec3 tr = new Vec3(tam/2,tam/2,0.0);
569
                Vec3 tl = new Vec3(-tam/2,tam/2,0.0);
570
                p.setEnabledBlending(true);
571
//                Vector<Vec3> normal = new Vector<Vec3>();
572
//                normal.add(new Vec3(0,0,1));
573
//                p.setNormalArray(normal);
574
//                p.setNormalBinding(Geometry.AttributeBinding.BIND_OVERALL);
575
                
576
                try {
577
                        p.getOrCreateStateSet().setLightingMode(Mode.OFF | Mode.PROTECTED);
578
                } catch (InvalidValueException e) {
579
                        logger.error("command:" + "Error ",e);
580
                }
581
                p.addVertex(bl, color);
582
                p.addVertex(tl, color); 
583
                p.addVertex(tr, color);
584
                p.addVertex(br, color);
585
                
586
//                p.setTwoSidedLighting(true);
587
                
588
                // if there was any texture to put we would include it
589
                if (texture != null)
590
                        p.setTexture(texture);
591
                // Tesselation of this poligon
592
                p.tesselate();
593

    
594
                // Optimizer generated nodes
595
//                Optimizer opt = new Optimizer();
596
//                opt.optimize(pt, OptimizationOptions.SPATIALIZE_GROUPS);
597

    
598
                // Return node
599
                return pt;
600
        }
601

    
602
        /**
603
         * Create a new tesselation poligon with a color using an array of 3D points
604
         * 
605
         * @param points
606
         *            Array of 3D points
607
         * @param color
608
         *            Color of the poligon
609
         * @return Poligon node
610
         */
611
        public static Node insertPolygon(Vec3[] points, Vec4 color,String texture) {
612
                // Creating a polygon
613
                TessellablePolygon p = null;
614
                try {
615
                        p = new TessellablePolygon();
616
                } catch (NodeException e1) {
617
                        // TODO Auto-generated catch block
618
                        e1.printStackTrace();
619
                }
620

    
621
                // Set up parameters
622
                // p.setType(Polygon.PolygonType.FILLED_POLYGON);
623
                p.setWidth(2f);
624
                // p.setPattern((short) 0xFFFF);
625
                // p.setFactor(2);
626
                p.setType(Polygon.PolygonType.FILLED_POLYGON);
627
                // p.setType(Polygon.PolygonType.EMPTY_POLYGON);
628
                // p.setType(Polygon.PolygonType.PATTERN_POLYGON);
629

    
630
                // Adding points
631
                for (int i = 0; i < points.length - 1; i++) {
632
                        p.addVertex(points[i], color);
633
                        // System.out.println("Position: " + inv[i].x() + " " + inv[i].y() +
634
                        // " " + inv[i].z());
635
                }
636
                // if there was any texture to put we would include it
637
                if (texture != null)
638
                        p.setTexture(texture);
639
                // Tesselation of this poligon
640
                p.tesselate();
641

    
642
                // Optimizer generated nodes
643
                Optimizer opt = new Optimizer();
644
                try {
645
                        opt.optimize(p, OptimizationOptions.SPATIALIZE_GROUPS);
646
                } catch (InvalidValueException e) {
647
                        logger.error("Command:" + "Error setting optimize value.",e);
648
                } catch (NodeException e) {
649
                        logger.error("Command:" + "Error adding optimizer.",e);
650
                }
651

    
652
                // Return node
653
                return p;
654
        }
655
        
656
        
657

    
658
        /**
659
         * Create a new tesselation poligon with a color using an List of 3D points
660
         * 
661
         * @param points
662
         *            List of 3D points
663
         * @param color
664
         *            Color of the poligon
665
         * @return Poligon node
666
         */
667
        public static Node insertPolygon(List points, Vec4 color,String texture) {
668
                // Creating a polygon
669
                TessellablePolygon p = null;
670
                try {
671
                        p = new TessellablePolygon();
672
                } catch (NodeException e1) {
673
                        // TODO Auto-generated catch block
674
                        e1.printStackTrace();
675
                }
676

    
677
                // Set up parameters
678
                // p.setType(Polygon.PolygonType.FILLED_POLYGON);
679
                p.setWidth(2f);
680
                // p.setPattern((short) 0xFFFF);
681
                // p.setFactor(2);
682
                p.setType(Polygon.PolygonType.FILLED_POLYGON);
683
                // p.setType(Polygon.PolygonType.EMPTY_POLYGON);
684
                // p.setType(Polygon.PolygonType.PATTERN_POLYGON);
685

    
686
                // Blending only is active if the alpha component are diferent that 1
687
                if (color.w() != 1) {
688
                        p.setEnabledBlending(true);
689
                }
690
                // Adding points
691
                for (int i = 0; i < points.size(); i++) {
692
                        Vec3 element = (Vec3) points.get(i);
693
                        p.addVertex(element, color);
694
                }
695
        
696

    
697
                // p.setTexture("C:/modelos3d/Images/land_shallow_topo_2048.jpg");
698
                // if there was any texture to put we would include it
699
                if (texture != null)
700
                        p.setTexture(texture);
701
                // Tesselation of this poligon
702
                p.tesselate();
703

    
704
                // Optimizer generated nodes
705
                Optimizer opt = new Optimizer();
706
                try {
707
                        opt.optimize(p, OptimizationOptions.ALL_OPTIMIZATIONS);
708
                } catch (InvalidValueException e) {
709
                        logger.error("Command:" + "Error setting optimizer value.",e);
710
                } catch (NodeException e) {
711
                        logger.error("Command:" + "Error adding optimizer.",e);
712
                }
713

    
714
                // Return node
715
                return p;
716
        }
717
        public static Node insertPolygonExtruded(List points, Vec4 color,String texture,double heigth) {
718
                // Creating a polygon
719
                Polygon p = null;
720
                try {
721
                        p = new Polygon();
722
                } catch (NodeException e1) {
723
                        // TODO Auto-generated catch block
724
                        e1.printStackTrace();
725
                }
726

    
727
                // Set up parameters
728
                // p.setType(Polygon.PolygonType.FILLED_POLYGON);
729
                p.setWidth(2f);
730
                // p.setPattern((short) 0xFFFF);
731
                // p.setFactor(2);
732
                p.setType(Polygon.PolygonType.FILLED_POLYGON);
733
                // p.setType(Polygon.PolygonType.EMPTY_POLYGON);
734
                // p.setType(Polygon.PolygonType.PATTERN_POLYGON);
735

    
736
                // Blending only is active if the alpha component are diferent that 1
737
                if (color.w() != 1) {
738
                        p.setEnabledBlending(true);
739
                }
740
                // Adding points
741
                for (int i = 0; i < points.size(); i++) {
742
                        Vec3 element = (Vec3) points.get(i);
743
                        p.addVertex(element, color);
744
                }
745
                
746
                PolygonExtruder pe = new PolygonExtruder();
747
                pe.extrude(p,new Vec3 (0.0,0.0,-1.0), heigth);                
748
                
749

    
750
                // Optimizer generated nodes
751
                Optimizer opt = new Optimizer();
752
                try {
753
                        opt.optimize(p, OptimizationOptions.ALL_OPTIMIZATIONS);
754
                } catch (InvalidValueException e) {
755
                        logger.error("Command:" + "Error setting optimizer value.",e);
756
                } catch (NodeException e) {
757
                        logger.error("Command:" + "Error adding optimizer.",e);
758
                }
759

    
760
                Geode geode = new Geode();
761
                
762
                try {
763
                        geode.addDrawable(pe.getGeometry());
764
                } catch (NodeException e) {
765
                        logger.error("Command:" + "Error adding drawable object.",e);
766
                }
767
                // Return node
768
                return geode;
769
        }
770
        /**
771
         * Method to create a new 3D line. With a List of 3D points and a color
772
         * 
773
         * @param points
774
         *            List of 3D points
775
         * @param color
776
         *            Color of the line
777
         * @return
778
         * 
779
         */
780
        public static Node insertLine(List points, Vec4 color, float size) {
781
                Vec3 ori = null, fin = null;
782

    
783
                // Getting first points
784
                if (points.size() > 1) {
785
                        ori = (Vec3) points.get(0);
786
                        fin = (Vec3) points.get(1);
787
                }
788

    
789
                // If the line do not have more than 2 points return null
790
                if ((ori == null) || (fin == null))
791
                        return null;
792

    
793
                // Create new polyline
794
                Polyline p = null;
795
                try {
796
                        p = new Polyline(ori, fin);
797
                } catch (NodeException e1) {
798
                        // TODO Auto-generated catch block
799
                        e1.printStackTrace();
800
                }
801
                p.setVertexColor(0, color);
802
                p.setVertexColor(1, color);
803

    
804
                // Set up parameters
805
                p.setWidth(size);
806
                p.setPattern((short) 0xFFFF);
807
                p.setFactor(2);
808

    
809
                // Blending only is active if the alpha component are diferent that 1
810
                if (color.w() != 1) {
811
                        p.setEnabledBlending(true);
812
                }
813

    
814
                // Enabling antialiasing
815
                p.setEnabledSmoothing(true);
816

    
817
                p.setColor(color);
818

    
819
                // Adding points
820
                for (int i = 2; i < points.size(); i++) {
821
                        Vec3 element = (Vec3) points.get(i);
822
                        p.addVertex(element, color);
823
                }
824

    
825
                // Optimizer generated nodes
826
                Optimizer opt = new Optimizer();
827
                try {
828
                        opt.optimize(p);
829
                } catch (NodeException e) {
830
                        logger.error("Command:" + "Error adding optimizer.",e);
831
                }
832

    
833
                // Return node
834
                return p;
835

    
836
        }
837

    
838
        /**
839
         * Create a new group of 3D points with a color and size. Using a List of 3D
840
         * points
841
         * 
842
         * @param points
843
         *            List of 3D points
844
         * @param color
845
         *            Color of the line
846
         * @param size
847
         *            Size of the point (in pixels)
848
         * @return
849
         */
850
        public static Node insertPointL(List points, Vec4 color, float size) {
851
                // Creating point
852
                PixelPoint p = null;
853
                try {
854
                        p = new PixelPoint();
855
                } catch (NodeException e1) {
856
                        // TODO Auto-generated catch block
857
                        e1.printStackTrace();
858
                }
859

    
860
                // Set up parameters
861
                p.setPointSize(size);
862

    
863
                // Adding points
864
                for (int i = 0; i < points.size(); i++) {
865
                        Vec3 element = (Vec3) points.get(i);
866
                        p.addPoint(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
        /**
883
         * Create a new group of 3D labels with a size and heigth. Using a List of
884
         * 3D points
885
         * 
886
         * @param labels
887
         *            List of Flabels
888
         * 
889
         * @param size
890
         *            Size of the labels
891
         * @param heigth
892
         *            Heigth of labels
893
         * @param inPixels
894
         *            True indicates that size is in pixel and false indicates real
895
         *            size;
896
         * @param type
897
         * @return Node group
898
         */
899
        public static Node insertLabels(List labels, int size, float heigth,
900
                        boolean inPixels, int planetType) {
901
                // Creating a group node
902
                Group p = new Group();
903

    
904
                // Getting total size
905
                int total = labels.size();
906

    
907
                // this is for control a max of labels because the system not suport
908
                // more than 10000
909
                int max = 3000;
910
                if (total > max)
911
                        total = max;
912

    
913
                if (labels != null) {
914
                        for (int i = 0; i < total; i++) {
915
                                FLabel f = (FLabel) labels.get(i);
916

    
917
                                // Set up parameters
918

    
919
                                // Getting color
920
                                // Color co = f.getColor();
921
                                Color co = new Color(255, 255, 255, 255);
922
                                float r, g, b, a;
923
                                r = ((float) co.getRed()) / 255.0f;
924
                                g = ((float) co.getGreen()) / 255.0f;
925
                                b = ((float) co.getBlue()) / 255.0f;
926
                                a = ((float) co.getAlpha()) / 255.0f;
927
                                // Set color
928
                                Vec4 textColor = new Vec4(r, g, b, a);
929

    
930
                                // Get label name
931
                                String label = f.getString();
932
                                // double heigth = h;
933
                                Vec3 pos = null;
934
                                if (planetType == Planet.CoordinateSystemType.PROJECTED) {
935
                                        pos = new Vec3(f.getOrig().getX(), f.getOrig().getY(),
936
                                                        heigth);
937
                                } else {
938
                                        // Transform geodesical coordinates to cartesian
939
                                        Vec3 posGeo = new Vec3(f.getOrig().getY(), f.getOrig()
940
                                                        .getX(), heigth);
941

    
942
                                        pos = planet.convertLatLongHeightToXYZ(posGeo);
943
                                }
944

    
945
                                // Adding new child text nodes
946
                                try {
947
                                        p.addChild(insertTextoS(label, pos, textColor, size, inPixels));
948
                                } catch (NodeException e) {
949
                                        logger.error("Command:" + "Error adding new child text.",e);
950
                                }
951
                        }
952
                }
953

    
954
                // Optimizer generated nodes
955
                Optimizer opt = new Optimizer();
956
                try {
957
                        opt.optimize(p, OptimizationOptions.SPATIALIZE_GROUPS);
958
                } catch (InvalidValueException e) {
959
                        logger.error("Command:" + "Error setting optimizer value.",e);
960
                } catch (NodeException e) {
961
                        logger.error("Command:" + "Error adding optimizer.",e);
962
                }
963

    
964
                return p;
965

    
966
        }
967
        
968
        /**
969
         * Create a new group of 3D labels with a size and heigth. Using a List of
970
         * 3D points
971
         * 
972
         * @param labels
973
         *            List of Flabels
974
         * 
975
         * @param size
976
         *            Size of the labels
977
         * @param heigth
978
         *            Heigth of labels
979
         * @param inPixels
980
         *            True indicates that size is in pixel and false indicates real
981
         *            size;
982
         * @param type
983
         * @return Node group
984
         */
985
        public static Node insertLabels(List<ILabel3D> labels,Planet planet) {
986
                // Creating a group node
987
                Group p = new Group();
988

    
989
                // Getting total size
990
                int total = labels.size();
991

    
992
                // this is for control a max of labels because the system not suport
993
                // more than 10000
994
                int max = 3000;
995
                if (total > max)
996
                        total = max;
997

    
998
                if (labels != null) {
999
                        for (int i = 0; i < total; i++) {
1000
                                
1001
                                
1002
                                ILabel3D label3D = (ILabel3D) labels.get(i);
1003
                                FLabel f = label3D.getFlabel();
1004

    
1005
                                // Set up parameters
1006

    
1007
                                // Getting color
1008
//                                 Color original_color = f.getColor();
1009
                                Color co = new Color(255, 255, 255, 255);
1010
                                float r, g, b, a;
1011
                                r = ((float) co.getRed()) / 255.0f;
1012
                                g = ((float) co.getGreen()) / 255.0f;
1013
                                b = ((float) co.getBlue()) / 255.0f;
1014
                                a = ((float) co.getAlpha()) / 255.0f;
1015
                                // Set color
1016
                                Vec4 textColor = new Vec4(r, g, b, a);
1017

    
1018
                                // Get label name
1019
                                String label = label3D.getTextField();
1020
                                // double heigth = h;
1021
                                Vec3 pos = null;
1022
                                Vec3 originalPos = null;
1023
                                originalPos = label3D.getPosition();
1024
                                if (planet.getCoordinateSystemType()== Planet.CoordinateSystemType.PROJECTED) {
1025
                                        pos = new Vec3(originalPos.x(),originalPos.y(),originalPos.z());
1026
                                } else {
1027
                                        // Transform geodesical coordinates to cartesian
1028
                                        Vec3 posGeo = new Vec3(originalPos.y(),originalPos.x(),originalPos.z());
1029

    
1030
                                        pos = planet.convertLatLongHeightToXYZ(posGeo);
1031
                                }
1032
                                
1033
                                boolean inPixels = (label3D.getUnits() <= -1);
1034
                                int height = (int)f.getHeight()/255;
1035
                                // Adding new child text nodes
1036
                                try {
1037
                                        p.addChild(insertTextoS(label, pos,textColor,height , inPixels));
1038
                                } catch (NodeException e) {
1039
                                        logger.error("Command:" + "Error adding new child text.",e);
1040
                                }
1041
                        }
1042
                }
1043

    
1044
                // Optimizer generated nodes
1045
                Optimizer opt = new Optimizer();
1046
                try {
1047
                        opt.optimize(p, OptimizationOptions.SPATIALIZE_GROUPS);
1048
                } catch (InvalidValueException e) {
1049
                        logger.error("Command:" + "Error setting optimizer value.",e);
1050
                } catch (NodeException e) {
1051
                        logger.error("Command:" + "Error adding optimizer.",e);
1052
                }
1053

    
1054
                return p;
1055

    
1056
        }
1057

    
1058
}