Statistics
| Revision:

svn-gvsig-desktop / trunk / libraries / lib3DMap / src / com / iver / ai2 / gvsig3d / gui / FeatureFactory.java @ 20124

History | View | Annotate | Download (22.8 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 com.iver.ai2.gvsig3d.labels3D.ILabel3D;
9
import com.iver.ai2.gvsig3d.resources.ResourcesFactory;
10
import com.iver.ai2.gvsig3d.utils.Punto3D;
11
import com.iver.cit.gvsig.fmap.core.v02.FLabel;
12

    
13
import es.upv.ai2.osgvp.AutoTransform;
14
import es.upv.ai2.osgvp.Geode;
15
import es.upv.ai2.osgvp.Group;
16
import es.upv.ai2.osgvp.Node;
17
import es.upv.ai2.osgvp.Optimizer;
18
import es.upv.ai2.osgvp.Vec3;
19
import es.upv.ai2.osgvp.Vec4;
20
import es.upv.ai2.osgvp.Optimizer.OptimizationOptions;
21
import es.upv.ai2.osgvp.features.PixelPoint;
22
import es.upv.ai2.osgvp.features.Polygon;
23
import es.upv.ai2.osgvp.features.PolygonExtruder;
24
import es.upv.ai2.osgvp.features.Polyline;
25
import es.upv.ai2.osgvp.features.QuadPoint;
26
import es.upv.ai2.osgvp.features.TessellablePolygon;
27
import es.upv.ai2.osgvp.features.Text;
28
import es.upv.ai2.osgvp.planets.Planet;
29

    
30
public class FeatureFactory extends Group {
31

    
32
        private static double radius;
33

    
34
        static Planet planet;
35

    
36
        public FeatureFactory(double ra, Planet m_planet) {
37
                super();
38
                radius = ra;
39
                // this.setNodeName("VECTOR");
40
                planet = m_planet;
41
                init();
42
        }
43

    
44
        private void init() {
45

    
46
                // this.addChild(insertTexto("Polo norte", poloNorte));
47
                // this.addChild(insertTexto("MADRID", valenciaCar));
48

    
49
                // Vec3 posIni = new Vec3(0, 0, 0);
50
                // Vec3 posEnd = new Vec3(0, 0, 100000);
51

    
52
                // Polyline line = (Polyline) VectorTest.insertLineS(posIni, posEnd,
53
                // new Vec4(1.0, 1.0, 1.0, 1.0), 0);
54
                // if (planet.getType() == PlanetType.PLANE_MODE)
55
                // this.addChild(line);
56

    
57
        }
58

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

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

    
139
                // Creating text node
140
                Text text = new Text();
141
                // Set up text properties
142
                text.setText(texto);
143
                text.setCharacterSize(tam);
144
                // Select that the text will be in pixels or screen coordinates
145
                if (inPixels) {
146
                        text.setCharacterSizeMode(Text.CharacterSizeMode.SCREEN_COORDS);
147
                } else {
148
                        text.setCharacterSizeMode(Text.CharacterSizeMode.OBJECT_COORDS);
149
                }
150
                text.setColor(color);
151
                text.setAxisAlignment(Text.AxisAlignment.SCREEN);
152
                text.setAlignment(Text.AlignmentType.LEFT_BOTTOM);
153
                text.setPosition((float) position.x(), (float) position.y(),
154
                                (float) position.z());
155

    
156
                // Search font in resources directori
157
                if (ResourcesFactory.exitsResouce("arial.ttf"))
158
                        text.setFont(ResourcesFactory.getResourcePath("arial.ttf"));
159
                else
160
                        text.setFont("arial.ttf");
161
                text.setAutoRotateToScreen(true);
162

    
163
                // Optimizer generated nodes
164
                Optimizer opt = new Optimizer();
165
                opt.optimize(text, OptimizationOptions.SPATIALIZE_GROUPS);
166

    
167
                // Return node
168
                return text;
169

    
170
        }
171

    
172
        /**
173
         * Method to create a new 3D point. With a color, heigth and position.
174
         * 
175
         * @param position
176
         *            Position of 3D text in cartesian coordinates
177
         * @param color
178
         *            color of the 3D point
179
         * @param tam
180
         *            the heigth of the point
181
         * @return New text node
182
         */
183
        public static Node insertPointS(Vec3 position, Vec4 color, int tam) {
184
                AutoTransform au = new AutoTransform();
185
                // Creating point
186
                PixelPoint p = new PixelPoint();
187
                // p.setDistanceAttenuation(new Vec3(0.0,0.0,0.0000001));
188
                p.setPointSize(tam);
189
                p.addPoint(position, color);
190

    
191
                au.addChild(p);
192
                // return au;
193
                return p;
194
        }
195

    
196
        /**
197
         * Method to create a new 3D point. With a color, heigth and position.
198
         * 
199
         * @param hash
200
         *            Hash Table that contains "Puntos3D" elements
201
         * @return
202
         */
203
        public static Node insertPointS(HashMap hash) {
204

    
205
                Group g = new Group();
206

    
207
                // Iterate over the keys in the map
208
                Iterator it = hash.keySet().iterator();
209
                while (it.hasNext()) {
210
                        // Get key
211
                        Double key = (Double) it.next();
212
                        List list = (List) hash.get(key);
213

    
214
                        PixelPoint p = new PixelPoint();
215
//                        ShapePoint p = new ShapePoint();
216
//                        es.upv.ai2.osgvp.features.Sphere s = new Sphere();
217
//                        p.setShape(s);
218
//                        s.setRadius(100);
219
                        for (Iterator iter = list.iterator(); iter.hasNext();) {
220
                                // Getting PixelPoint
221
                                Punto3D element = (Punto3D) iter.next();
222
//                                Vec4 color = element.getColor();
223
                                Vec4 color = new Vec4(1,0,0,1);
224
                                
225
                                // Blending only is active if the alpha component are diferent
226
                                // that 1
227
                                if (color.w() != 1) {
228
                                        p.setEnabledBlending(true);
229
                                }
230
                                // Enabling antialiasing
231
                                p.setEnabledSmoothing(true);
232

    
233
                                // Set up size, position and color
234
//                                p.setPointSize(element.getZize());
235
                                p.setPointSize(20);
236
                                p.setLightingMode(Node.Mode.OFF | Node.Mode.PROTECTED);
237
                                p.addPoint(element.getPosition(), color);
238
//                                System.err.println("posicion del punto " +element.getPosition());
239
                        }
240
                        // Adding points to group
241
                        g.addChild(p);
242
                }
243
//                System.out.println("nuevo grupo");
244

    
245
                // Optimizer generated nodes
246
//                Optimizer opt = new Optimizer();
247
//                opt.optimize(g, OptimizationOptions.SPATIALIZE_GROUPS);
248

    
249
                return g;
250
        }
251

    
252
        /**
253
         * Method to add 3D points to specific point type. With a color, heigth and
254
         * position.
255
         * 
256
         * @param point
257
         *            Node to add new 3D point
258
         * @param position
259
         *            Position of 3D text in cartesian coordinates
260
         * @param color
261
         *            color of the 3D point
262
         * @param tam
263
         *            the heigth of the point
264
         * @return New text node
265
         */
266
        public static void addPointToNode(Node point, Vec3 position, Vec4 color,
267
                        int tam) {
268

    
269
                PixelPoint p = null;
270
                // Getting point
271
                if (point != null)
272
                        p = (PixelPoint) point;
273

    
274
                // If not exits create new
275
                if (p == null)
276
                        p = new PixelPoint();
277

    
278
                // Blending only is active if the alpha component are diferent that 1
279
                if (color.w() != 1) {
280
                        p.setEnabledBlending(true);
281
                }
282

    
283
                // Set up size, position and color
284
                p.setPointSize(tam);
285
                p.addPoint(position, color);
286

    
287
                // Optimizer generated nodes
288
                Optimizer opt = new Optimizer();
289
                opt.optimize(p, OptimizationOptions.SPATIALIZE_GROUPS);
290

    
291
        }
292

    
293
        /**
294
         * Method to create a new 3D line. With a color, heigth and position.
295
         * 
296
         * @param ini
297
         *            Initial position of line
298
         * @param end
299
         *            End positon of line.
300
         * @param color
301
         *            color of the 3D point
302
         * @param tam
303
         *            the heigth of the point
304
         * @return New line node
305
         */
306

    
307
        public static Node insertLineS(Vec3 ini, Vec3 end, Vec4 color, int tam) {
308
                // Creating a polyline
309
                Polyline p = new Polyline(ini, end);
310

    
311
                // Set up parameter
312
                p.setWidth(2f);
313
                p.setPattern((short) 0xFFFF);
314
                p.setFactor(2);
315
                p.setColor(color);
316

    
317
                // Optimize the node
318
                Optimizer opt = new Optimizer();
319
                opt.optimize(p);
320

    
321
                // Return the node
322
                return p;
323
        }
324

    
325
        /**
326
         * Method to add new points to specific line type. With a color, heigth and
327
         * position.
328
         * 
329
         * @param line
330
         *            Node to add new point
331
         * @param position
332
         *            Position of 3D point in cartesian coordinates
333
         * @param color
334
         *            color of the 3D point
335
         * @param tam
336
         *            the heigth of the point
337
         */
338
        public static void addNodeToLine(Node line, Vec3 position, Vec4 color,
339
                        int tam) {
340
                // Getting polyline
341
                Polyline p = (Polyline) line;
342

    
343
                // If not exits, create a new
344
                if (p == null)
345
                        p = new Polyline(position, position);
346

    
347
                // Add a point and color
348
                p.addVertex(position, color);
349

    
350
        }
351

    
352
        /**
353
         * Create a new point node with a color and size. Using a position of 3D
354
         * points
355
         * 
356
         * @param position
357
         *            Position of 3D point
358
         * @param color
359
         *            Color of the 3D point
360
         * @param tam
361
         *            Size of the point (in pixels)
362
         * @return
363
         */
364
        public static Node insertPointS(Vec3[] position, Vec4 color, int tam) {
365
                // Creating point node
366
                PixelPoint p = new PixelPoint();
367

    
368
                // Set up parameters and insert position
369
                for (int i = 0; i < position.length; i++) {
370
                        p.setPointSize(tam);
371
                        p.addPoint(position[i], color);
372
                }
373

    
374
                // Optimizer generated nodes
375
                Optimizer opt = new Optimizer();
376
                opt.optimize(p, OptimizationOptions.SPATIALIZE_GROUPS);
377

    
378
                // Return node
379
                return p;
380
        }
381
        
382
        /**
383
         * Create a new quad point node with a color, size and texture. Using a position of 3D
384
         * points
385
         * 
386
         * @param position
387
         *            Position of 3D point
388
         * @param color
389
         *            Color of the 3D point
390
         * @param tam
391
         *            Size of the point (in pixels)
392
         * @return
393
         */
394
        public static Node insertQuadPoints(Vec3[] position, Vec4 color, float tam, String texture) {
395
                // Creating point node
396
                QuadPoint p = new QuadPoint(tam);
397

    
398
                // Set up parameters and insert position
399
                for (int i = 0; i < position.length; i++) {
400
                        p.setPointSize(tam);
401
                        p.addPoint(position[i], color);
402
                }
403
        
404
//                if (texture!=null)
405
//                        p.setTexture(texture);
406
                
407
                p.setBillboardingEnabled(true);
408
                
409
                
410
                // Optimizer generated nodes
411
                Optimizer opt = new Optimizer();
412
                opt.optimize(p, OptimizationOptions.SPATIALIZE_GROUPS);
413

    
414
                // Return node
415
                return p;
416
        }
417
        /**
418
         * Create a new tesselation poligon with a color using an array of 3D points
419
         * 
420
         * @param points
421
         *            Array of 3D points
422
         * @param color
423
         *            Color of the poligon
424
         * @return Poligon node
425
         */
426
        public static Node generateQuadPoligon(Vec3 position, Vec4 color,String texture,float tam) {
427
                // Creating a polygon
428
                TessellablePolygon p = new TessellablePolygon();
429

    
430
//                PositionAttitudeTransform pt = new PositionAttitudeTransform();
431
                AutoTransform pt = new AutoTransform();
432
                pt.addChild(p);
433
                pt.setPosition(position);
434
                pt.setAutoRotateMode(AutoTransform.AutoRotateMode.ROTATE_TO_CAMERA);
435
                // Set up parameters
436
                // p.setType(Polygon.PolygonType.FILLED_POLYGON);
437
                p.setWidth(2f);
438
                // p.setPattern((short) 0xFFFF);
439
                // p.setFactor(2);
440
                p.setType(Polygon.PolygonType.FILLED_POLYGON);
441
                // p.setType(Polygon.PolygonType.EMPTY_POLYGON);
442
                // p.setType(Polygon.PolygonType.PATTERN_POLYGON);
443
                
444
                Vec3 bl = new Vec3(-tam/2,-tam/2,0.0);
445
                Vec3 br = new Vec3(tam/2,-tam/2,0.0);
446
                Vec3 tr = new Vec3(tam/2,tam/2,0.0);
447
                Vec3 tl = new Vec3(-tam/2,tam/2,0.0);
448
                p.setEnabledBlending(true);
449
//                Vector<Vec3> normal = new Vector<Vec3>();
450
//                normal.add(new Vec3(0,0,1));
451
//                p.setNormalArray(normal);
452
//                p.setNormalBinding(Geometry.AttributeBinding.BIND_OVERALL);
453
                
454
                p.setLightingMode(Mode.OFF | Mode.PROTECTED);
455
                p.addVertex(bl, color);
456
                p.addVertex(tl, color); 
457
                p.addVertex(tr, color);
458
                p.addVertex(br, color);
459
                
460
//                p.setTwoSidedLighting(true);
461
                
462
                // if there was any texture to put we would include it
463
                if (texture != null)
464
                        p.setTexture(texture);
465
                // Tesselation of this poligon
466
                p.tesselate();
467

    
468
                // Optimizer generated nodes
469
//                Optimizer opt = new Optimizer();
470
//                opt.optimize(pt, OptimizationOptions.SPATIALIZE_GROUPS);
471

    
472
                // Return node
473
                return pt;
474
        }
475

    
476
        /**
477
         * Create a new tesselation poligon with a color using an array of 3D points
478
         * 
479
         * @param points
480
         *            Array of 3D points
481
         * @param color
482
         *            Color of the poligon
483
         * @return Poligon node
484
         */
485
        public static Node insertPolygon(Vec3[] points, Vec4 color,String texture) {
486
                // Creating a polygon
487
                TessellablePolygon p = new TessellablePolygon();
488

    
489
                // Set up parameters
490
                // p.setType(Polygon.PolygonType.FILLED_POLYGON);
491
                p.setWidth(2f);
492
                // p.setPattern((short) 0xFFFF);
493
                // p.setFactor(2);
494
                p.setType(Polygon.PolygonType.FILLED_POLYGON);
495
                // p.setType(Polygon.PolygonType.EMPTY_POLYGON);
496
                // p.setType(Polygon.PolygonType.PATTERN_POLYGON);
497

    
498
                // Adding points
499
                for (int i = 0; i < points.length - 1; i++) {
500
                        p.addVertex(points[i], color);
501
                        // System.out.println("Position: " + inv[i].x() + " " + inv[i].y() +
502
                        // " " + inv[i].z());
503
                }
504
                // if there was any texture to put we would include it
505
                if (texture != null)
506
                        p.setTexture(texture);
507
                // Tesselation of this poligon
508
                p.tesselate();
509

    
510
                // Optimizer generated nodes
511
                Optimizer opt = new Optimizer();
512
                opt.optimize(p, OptimizationOptions.SPATIALIZE_GROUPS);
513

    
514
                // Return node
515
                return p;
516
        }
517
        
518
        
519

    
520
        /**
521
         * Create a new tesselation poligon with a color using an List of 3D points
522
         * 
523
         * @param points
524
         *            List of 3D points
525
         * @param color
526
         *            Color of the poligon
527
         * @return Poligon node
528
         */
529
        public static Node insertPolygon(List points, Vec4 color,String texture) {
530
                // Creating a polygon
531
                TessellablePolygon p = new TessellablePolygon();
532

    
533
                // Set up parameters
534
                // p.setType(Polygon.PolygonType.FILLED_POLYGON);
535
                p.setWidth(2f);
536
                // p.setPattern((short) 0xFFFF);
537
                // p.setFactor(2);
538
                p.setType(Polygon.PolygonType.FILLED_POLYGON);
539
                // p.setType(Polygon.PolygonType.EMPTY_POLYGON);
540
                // p.setType(Polygon.PolygonType.PATTERN_POLYGON);
541

    
542
                // Blending only is active if the alpha component are diferent that 1
543
                if (color.w() != 1) {
544
                        p.setEnabledBlending(true);
545
                }
546
                // Adding points
547
                for (int i = 0; i < points.size(); i++) {
548
                        Vec3 element = (Vec3) points.get(i);
549
                        p.addVertex(element, color);
550
                }
551
        
552

    
553
                // p.setTexture("C:/modelos3d/Images/land_shallow_topo_2048.jpg");
554
                // if there was any texture to put we would include it
555
                if (texture != null)
556
                        p.setTexture(texture);
557
                // Tesselation of this poligon
558
                p.tesselate();
559

    
560
                // Optimizer generated nodes
561
                Optimizer opt = new Optimizer();
562
                opt.optimize(p, OptimizationOptions.ALL_OPTIMIZATIONS);
563

    
564
                // Return node
565
                return p;
566
        }
567
        public static Node insertPolygonExtruded(List points, Vec4 color,String texture,double heigth) {
568
                // Creating a polygon
569
                Polygon p = new Polygon();
570

    
571
                // Set up parameters
572
                // p.setType(Polygon.PolygonType.FILLED_POLYGON);
573
                p.setWidth(2f);
574
                // p.setPattern((short) 0xFFFF);
575
                // p.setFactor(2);
576
                p.setType(Polygon.PolygonType.FILLED_POLYGON);
577
                // p.setType(Polygon.PolygonType.EMPTY_POLYGON);
578
                // p.setType(Polygon.PolygonType.PATTERN_POLYGON);
579

    
580
                // Blending only is active if the alpha component are diferent that 1
581
                if (color.w() != 1) {
582
                        p.setEnabledBlending(true);
583
                }
584
                // Adding points
585
                for (int i = 0; i < points.size(); i++) {
586
                        Vec3 element = (Vec3) points.get(i);
587
                        p.addVertex(element, color);
588
                }
589
                
590
                PolygonExtruder pe = new PolygonExtruder();
591
                pe.extrude(p,new Vec3 (0.0,0.0,-1.0), heigth);                
592
                
593

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

    
598
                Geode geode = new Geode();
599
                
600
                geode.addDrawable(pe.getGeometry());
601
                // Return node
602
                return geode;
603
        }
604
        /**
605
         * Method to create a new 3D line. With a List of 3D points and a color
606
         * 
607
         * @param points
608
         *            List of 3D points
609
         * @param color
610
         *            Color of the line
611
         * @return
612
         * 
613
         */
614
        public static Node insertLine(List points, Vec4 color, float size) {
615
                Vec3 ori = null, fin = null;
616

    
617
                // Getting first points
618
                if (points.size() > 1) {
619
                        ori = (Vec3) points.get(0);
620
                        fin = (Vec3) points.get(1);
621
                }
622

    
623
                // If the line do not have more than 2 points return null
624
                if ((ori == null) || (fin == null))
625
                        return null;
626

    
627
                // Create new polyline
628
                Polyline p = new Polyline(ori, fin);
629
                p.setVertexColor(0, color);
630
                p.setVertexColor(1, color);
631

    
632
                // Set up parameters
633
                p.setWidth(size);
634
                p.setPattern((short) 0xFFFF);
635
                p.setFactor(2);
636

    
637
                // Blending only is active if the alpha component are diferent that 1
638
                if (color.w() != 1) {
639
                        p.setEnabledBlending(true);
640
                }
641

    
642
                // Enabling antialiasing
643
                p.setEnabledSmoothing(true);
644

    
645
                p.setColor(color);
646

    
647
                // Adding points
648
                for (int i = 2; i < points.size(); i++) {
649
                        Vec3 element = (Vec3) points.get(i);
650
                        p.addVertex(element, color);
651
                }
652

    
653
                // Optimizer generated nodes
654
                Optimizer opt = new Optimizer();
655
                opt.optimize(p);
656

    
657
                // Return node
658
                return p;
659

    
660
        }
661

    
662
        /**
663
         * Create a new group of 3D points with a color and size. Using a List of 3D
664
         * points
665
         * 
666
         * @param points
667
         *            List of 3D points
668
         * @param color
669
         *            Color of the line
670
         * @param size
671
         *            Size of the point (in pixels)
672
         * @return
673
         */
674
        public static Node insertPointL(List points, Vec4 color, float size) {
675
                // Creating point
676
                PixelPoint p = new PixelPoint();
677

    
678
                // Set up parameters
679
                p.setPointSize(size);
680

    
681
                // Adding points
682
                for (int i = 0; i < points.size(); i++) {
683
                        Vec3 element = (Vec3) points.get(i);
684
                        p.addPoint(element, color);
685
                }
686

    
687
                // Optimizer generated nodes
688
                Optimizer opt = new Optimizer();
689
                opt.optimize(p);
690

    
691
                // Return node
692
                return p;
693

    
694
        }
695

    
696
        /**
697
         * Create a new group of 3D labels with a size and heigth. Using a List of
698
         * 3D points
699
         * 
700
         * @param labels
701
         *            List of Flabels
702
         * 
703
         * @param size
704
         *            Size of the labels
705
         * @param heigth
706
         *            Heigth of labels
707
         * @param inPixels
708
         *            True indicates that size is in pixel and false indicates real
709
         *            size;
710
         * @param type
711
         * @return Node group
712
         */
713
        public static Node insertLabels(List labels, int size, float heigth,
714
                        boolean inPixels, int planetType) {
715
                // Creating a group node
716
                Group p = new Group();
717

    
718
                // Getting total size
719
                int total = labels.size();
720

    
721
                // this is for control a max of labels because the system not suport
722
                // more than 10000
723
                int max = 3000;
724
                if (total > max)
725
                        total = max;
726

    
727
                if (labels != null) {
728
                        for (int i = 0; i < total; i++) {
729
                                FLabel f = (FLabel) labels.get(i);
730

    
731
                                // Set up parameters
732

    
733
                                // Getting color
734
                                // Color co = f.getColor();
735
                                Color co = new Color(255, 255, 255, 255);
736
                                float r, g, b, a;
737
                                r = ((float) co.getRed()) / 255.0f;
738
                                g = ((float) co.getGreen()) / 255.0f;
739
                                b = ((float) co.getBlue()) / 255.0f;
740
                                a = ((float) co.getAlpha()) / 255.0f;
741
                                // Set color
742
                                Vec4 textColor = new Vec4(r, g, b, a);
743

    
744
                                // Get label name
745
                                String label = f.getString();
746
                                // double heigth = h;
747
                                Vec3 pos = null;
748
                                if (planetType == Planet.CoordinateSystemType.PROJECTED) {
749
                                        pos = new Vec3(f.getOrig().getX(), f.getOrig().getY(),
750
                                                        heigth);
751
                                } else {
752
                                        // Transform geodesical coordinates to cartesian
753
                                        Vec3 posGeo = new Vec3(f.getOrig().getY(), f.getOrig()
754
                                                        .getX(), heigth);
755

    
756
                                        pos = planet.convertLatLongHeightToXYZ(posGeo);
757
                                }
758

    
759
                                // Adding new child text nodes
760
                                p.addChild(insertTextoS(label, pos, textColor, size, inPixels));
761
                        }
762
                }
763

    
764
                // Optimizer generated nodes
765
                Optimizer opt = new Optimizer();
766
                opt.optimize(p, OptimizationOptions.SPATIALIZE_GROUPS);
767

    
768
                return p;
769

    
770
        }
771
        
772
        /**
773
         * Create a new group of 3D labels with a size and heigth. Using a List of
774
         * 3D points
775
         * 
776
         * @param labels
777
         *            List of Flabels
778
         * 
779
         * @param size
780
         *            Size of the labels
781
         * @param heigth
782
         *            Heigth of labels
783
         * @param inPixels
784
         *            True indicates that size is in pixel and false indicates real
785
         *            size;
786
         * @param type
787
         * @return Node group
788
         */
789
        public static Node insertLabels(List<ILabel3D> labels,Planet planet) {
790
                // Creating a group node
791
                Group p = new Group();
792

    
793
                // Getting total size
794
                int total = labels.size();
795

    
796
                // this is for control a max of labels because the system not suport
797
                // more than 10000
798
                int max = 3000;
799
                if (total > max)
800
                        total = max;
801

    
802
                if (labels != null) {
803
                        for (int i = 0; i < total; i++) {
804
                                
805
                                
806
                                ILabel3D label3D = (ILabel3D) labels.get(i);
807
                                FLabel f = label3D.getFlabel();
808

    
809
                                // Set up parameters
810

    
811
                                // Getting color
812
//                                 Color original_color = f.getColor();
813
                                Color co = new Color(255, 255, 255, 255);
814
                                float r, g, b, a;
815
                                r = ((float) co.getRed()) / 255.0f;
816
                                g = ((float) co.getGreen()) / 255.0f;
817
                                b = ((float) co.getBlue()) / 255.0f;
818
                                a = ((float) co.getAlpha()) / 255.0f;
819
                                // Set color
820
                                Vec4 textColor = new Vec4(r, g, b, a);
821

    
822
                                // Get label name
823
                                String label = label3D.getTextField();
824
                                // double heigth = h;
825
                                Vec3 pos = null;
826
                                Vec3 originalPos = null;
827
                                originalPos = label3D.getPosition();
828
                                if (planet.getCoordinateSystemType()== Planet.CoordinateSystemType.PROJECTED) {
829
                                        pos = new Vec3(originalPos.x(),originalPos.y(),originalPos.z());
830
                                } else {
831
                                        // Transform geodesical coordinates to cartesian
832
                                        Vec3 posGeo = new Vec3(originalPos.y(),originalPos.x(),originalPos.z());
833

    
834
                                        pos = planet.convertLatLongHeightToXYZ(posGeo);
835
                                }
836
                                
837
                                boolean inPixels = (label3D.getUnits() <= -1);
838
                                int height = (int)f.getHeight()/255;
839
                                // Adding new child text nodes
840
                                p.addChild(insertTextoS(label, pos,textColor,height , inPixels));
841
                        }
842
                }
843

    
844
                // Optimizer generated nodes
845
                Optimizer opt = new Optimizer();
846
                opt.optimize(p, OptimizationOptions.SPATIALIZE_GROUPS);
847

    
848
                return p;
849

    
850
        }
851

    
852
}