Statistics
| Revision:

svn-gvsig-desktop / branches / v10 / libraries / libLidar / src / com / dielmo / lidar / BINPoint2001.java @ 25423

History | View | Annotate | Download (20.8 KB)

1
/* DielmoOpenLiDAR
2
 *
3
 * Copyright (C) 2008 DIELMO 3D S.L. (DIELMO) and Infrastructures  
4
 * and Transports Department of the Valencian Government (CIT)
5
 * 
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 * 
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 * 
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
19
 * MA  02110-1301, USA.
20
 *
21
 * For more information, contact:
22
 *
23
 * DIELMO 3D S.L.
24
 * Plaza Vicente Andr?s Estell?s 1 Bajo E
25
 * 46950 Xirivella, Valencia
26
 * SPAIN
27
 *   
28
 * +34 963137212
29
 * dielmo@dielmo.com
30
 * www.dielmo.com
31
 * 
32
 * or
33
 * 
34
 * Generalitat Valenciana
35
 * Conselleria d'Infraestructures i Transport
36
 * Av. Blasco Ib??ez, 50
37
 * 46010 VALENCIA
38
 * SPAIN
39
 *
40
 * +34 963862235
41
 * gvsig@gva.es
42
 * www.gvsig.gva.es
43
 */
44

    
45
/*
46
 * AUTHORS (In addition to DIELMO and CIT):
47
 *  
48
 */
49

    
50
package com.dielmo.lidar;
51

    
52
import java.awt.geom.Point2D;
53
import java.nio.ByteBuffer;
54
import java.sql.Types;
55

    
56
import com.hardcode.gdbms.engine.values.DoubleValue;
57
import com.hardcode.gdbms.engine.values.IntValue;
58
import com.hardcode.gdbms.engine.values.Value;
59
import com.hardcode.gdbms.engine.values.ValueFactory;
60
import com.iver.cit.gvsig.fmap.drivers.FieldDescription;
61
import com.iver.utiles.bigfile.BigByteBuffer2;
62

    
63
/**
64
 * BIN point that implement the BIN point data version BIN 20010712
65
 * 
66
 * @author Oscar Garcia
67
 */
68
public class BINPoint2001 implements LidarPoint{
69
        
70
        /**
71
         * size of point format
72
         */
73
        private int sizeFormat;
74
        
75
        /**
76
         * indicates if content color.
77
         */
78
        private boolean isColor;
79
        
80
        /**
81
         * indicates if content time GPS.
82
         */
83
        private boolean isTimeGPS;
84
        
85
        /**
86
         * Color RGB
87
         */
88
        private char color[] = new char[4];
89
        
90
        /**
91
         * indicates if content color.
92
         */
93
        private int time;
94

    
95
        
96
        /**
97
         * X value
98
         */
99
        private int x;
100
        
101
        /**
102
         * Y value
103
         */
104
        private int y;
105
        
106
        /**
107
         * Z value
108
         */
109
        private int z;
110
        
111
        /**
112
         * The intensity value is the integer representation of the 
113
         * pulse return magnitude.
114
         */
115
        private int intensity;
116
        
117
        /**
118
         * The echo information of BIN is the pulse return number for a given output
119
         * pulse.
120
         * 
121
         * 0 Only echo
122
         * 1 First of many echo
123
         * 2 Intermediate echo
124
         * 3 Last if many echo
125
         */
126
        private byte echoInformation; 
127
        
128
        /**
129
         * The flight line number.
130
         */
131
        private char flightLine;
132
        
133
        /**
134
         * The classification field is a number to signify a given
135
         * classification during filter processing.
136
         */
137
        private char classification;
138

    
139
        
140
        /**
141
         * Default constructor, without arguments.
142
         * Initializes all components to zero.
143
         */ 
144
        public BINPoint2001(boolean c, boolean t) {
145
                
146
                x = 0;
147
                y = 0;
148
                z = 0;
149
                intensity = 0;
150
                echoInformation = 0;
151
                flightLine = 0;
152
                classification = 0;
153
                isColor = c;
154
                isTimeGPS = t;
155
                color[0] = 0;
156
                color[1] = 0;
157
                color[2] = 0;
158
                color[3] = 0;
159
                time = 0;
160
                sizeFormat = 16;
161
                
162
                if(c)
163
                        sizeFormat += 4;
164
                if(t)
165
                        sizeFormat += 4;
166
        }
167

    
168
        // GET METHODS
169
        /**
170
         * Get GPS time as long.
171
         */
172
        public int getTime() {
173
                return time;
174
        }
175
        
176
        /**
177
         * Get Color RGB
178
         */
179
        public char[] getcolor() {
180
                return color;
181
        }
182
        
183
        /**
184
         * Get red value of color
185
         */
186
        public char getR() {
187
                return color[0];
188
        }
189
        
190
        /**
191
         * Get green value of color
192
         */
193
        public char getG() {
194
                return color[1];
195
        }
196
        
197
        /**
198
         * Get blue value of color
199
         */
200
        public char getB() {
201
                return color[2];
202
        }
203
        
204
        /**
205
         * Get infrared value of color
206
         */
207
        public char getI() {
208
                return color[3];
209
        }
210
        
211
        /**
212
         * Return X value that is stored as long integer. The corresponding
213
         * X scale from the public header block change this long integer to
214
         * true floating point value. The corresponding offset value can
215
         * also be used for projections with very large numbers.
216
         * 
217
         * the coordinate = (X-OrgX)/Units
218
         * 
219
         * @return x value
220
         */ 
221
        public int getX() {
222
                return x;
223
        }
224
        
225
        /**
226
         * Return Y value that is stored as long integer. The corresponding
227
         * Y scale from the public header block change this long integer to
228
         * true floating point value. The corresponding offset value can
229
         * also be used for projections with very large numbers.
230
         * 
231
         * the coordinate = (Y-OrgY)/Units
232
         * 
233
         * @return y value
234
         */
235
        public int getY() {
236
                return y;
237
        }
238
        
239
        /**
240
         * Return Z value that is stored as long integer. The corresponding
241
         * Z scale from the public header block change this long integer to
242
         * true floating point value. The corresponding offset value can
243
         * also be used for projections with very large numbers.
244
         * 
245
         * the coordinate = (Z-OrgZ)/Units
246
         * 
247
         * @return z value
248
         */
249
        public int getZ() {
250
                return z;
251
        }
252
        
253
        /**
254
         * Get the intensity value as the integer representation of the pulse 
255
         * return magnitude. This value is optional and system specific
256
         * 
257
         * @return intensity value
258
         */
259
        public int getIntensity() {
260
                return intensity;
261
        }
262
        
263
        /**
264
         * Get The echo information of BIN is the pulse return number for
265
         * a given output pulse.
266
         * 
267
         * 0 Only echo 
268
         * 1 First of many echo 
269
         * 2 Intermediate echo 
270
         * 3 Last if many echo 
271
         * 
272
         * @return echo information
273
         */
274
        public byte getEchoInformation() {
275
                return echoInformation;
276
        }
277
        
278
        /**
279
         * Get flight line number
280
         * 
281
         * @return flight line number
282
         */
283
        public char getFlightLine() {
284
                return flightLine;
285
        }
286
        
287
        /**
288
         * Get a given classification during filter processing.
289
         * 
290
         * @return classification
291
         */
292
        public char getClassification() {        
293
                return classification;
294
        }
295
        
296
        /**
297
         * Get a bit size of point format
298
         * 
299
         * @return sizeFormat
300
         */
301
        public int getSizeFormat() {
302
                return sizeFormat;
303
        }
304
        
305
        // SET METHODS
306
        
307
        /**
308
         * Set GPS time as integer.
309
         */
310
        public void setTime(int t) {
311
                time=t;
312
        }
313
        
314
        /**
315
         * Set Color RGB
316
         * 
317
         * @param c this array contains 4 chars for represents the RGBI
318
         */
319
        public void setcolor(char[] c) {
320
                if(c.length == 4)
321
                        color = c;
322
        }
323
        
324
        /**
325
         * set X value that is stored as long integer.
326
         * 
327
         * @param newx new value of x
328
         */ 
329
        public void setX(int newx) {
330
                x = newx;
331
        }
332

    
333
        /**
334
         * set Y value that is stored as long integer.
335
         * 
336
         * @param newy new value of y
337
         */  
338
        public void setY(int newy) {
339
                y = newy;
340
        }
341
        
342
        /**
343
         * set Z value that is stored as long integer.
344
         * 
345
         * @param newz new value of z
346
         */ 
347
        public void setZ(int newz) {
348
                z = newz;
349
        }
350
        
351
        /**
352
         * Set the intensity value as the integer representation of the pulse 
353
         * return magnitude. This value is optional and system specific
354
         * 
355
         * @param inten new intensity
356
         */
357
        public void setIntensity(int inten) {
358
                
359
                try{
360
                        // intensity is formed by 14 bits, 16383 represents (2^14)-1
361
                        if(inten >=0 && inten <= 16383) 
362
                                intensity = inten;
363
                        else
364
                                throw new OutOfRangeLidarException("Out of range of intensity");
365
                        
366
                } catch(OutOfRangeLidarException e) {
367
                        
368
                        e.printStackTrace();
369
                }
370
        }
371
        
372
        /**
373
         * Set the echo information of BIN is the pulse return number for
374
         * a given output pulse.
375
         * 
376
         * 0 Only echo 
377
         * 1 First of many echo 
378
         * 2 Intermediate echo 
379
         * 3 Last if many echo 
380
         * 
381
         * @param echo new echo information
382
         */
383
        public void setEchoInformation(byte echo) {
384
                
385
                try{
386
                        if(echo >=0 && echo <= 3)
387
                                echoInformation = echo;
388
                        else
389
                                throw new OutOfRangeLidarException("Out of range of echo information");
390
                        
391
                } catch(OutOfRangeLidarException e) {
392
                        
393
                        e.printStackTrace();
394
                }
395
        }
396
        
397
        /**
398
         * Get flight line number
399
         * 
400
         * @param fl new flight line number
401
         */
402
        public void setFlightLine(char fl) {
403
                
404
                try{
405
                        if(fl>=0 && fl<=255)
406
                                flightLine = fl;
407
                        else
408
                                throw new OutOfRangeLidarException("Out of range of flight line");
409
                        
410
                } catch(OutOfRangeLidarException e) {
411
                        
412
                        e.printStackTrace();
413
                }
414
        }
415
        
416
        /**
417
         * Set a given classification during filter processing.
418
         * 
419
         * @return c new classification
420
         */
421
        public void setClassification(char c) {        
422
                
423
                try{
424
                        if(c>=0 && c<=255)
425
                                classification = c;
426
                        else
427
                                throw new OutOfRangeLidarException("Out of range of classification");
428
                        
429
                } catch(OutOfRangeLidarException e) {
430
                        
431
                        e.printStackTrace();
432
                }
433
        }
434
        
435
        /**
436
         * Read a point of BIN file
437
         * 
438
         * @param input input file to read
439
         * @param Offset Offset to data
440
         * @param index index of points to read
441
         * @return true if success else return false 
442
         */
443
        public void readPoint(BigByteBuffer2 input, LidarHeader hdr, long index) {
444
                
445
                try{
446
                        if(index>hdr.getNumPointsRecord() || index < 0) {
447
                                throw new UnexpectedPointException("Out of Index"); 
448
                        }
449
                
450
                        int auxIndex;
451
                        byte[] punto = new byte[getSizeFormat()];
452
                        byte[] aux = new byte[2];
453
                        
454
                        input.position(hdr.getOffsetData()+getSizeFormat()*index);
455
                    input.get(punto);
456
                    
457
                    setClassification((char)(punto[0] & 0xFF)); 
458
                    setFlightLine((char)(punto[1] & 0xFF));
459
                    
460
                    aux[0] = punto[2];
461
                    aux[1] = (byte)(punto[3] & 0X3F);
462
                        setIntensity(ByteUtilities.arr2Unsignedshort(aux, 0));  // bits de 0-13
463
                        setEchoInformation((byte)((punto[3] & 0xC0) >> 2)); // bits 14 y 15
464
                        
465
                        setX(ByteUtilities.arr2Int(punto, 4));
466
                        setY(ByteUtilities.arr2Int(punto, 8));
467
                        setZ(ByteUtilities.arr2Int(punto, 12));
468
                        
469
                        auxIndex = 16;
470
                        
471
                        // si hay gps leelo
472
                        if(isTimeGPS) {
473
                                setTime(ByteUtilities.arr2Int(punto, auxIndex));
474
                                auxIndex+=4;
475
                        }
476
                        
477
                        // si hay color leelo
478
                        if(isColor) {
479
                                
480
                                char[] c = new char[4];
481
                                c[0] = (char)(punto[auxIndex] & 0xFF);
482
                                c[1] = (char)(punto[auxIndex+1] & 0xFF);
483
                                c[2] = (char)(punto[auxIndex+2] & 0xFF);
484
                                c[3] = (char)(punto[auxIndex+3] & 0xFF);
485
                                setcolor(c);
486
                        }
487
                        
488
                } catch (UnexpectedPointException e) {
489
                        e.printStackTrace();
490
                }
491
        }
492
        
493
        /**
494
         * Read x and y in point of BIN file
495
         * 
496
         * @param input input buffer to read
497
         * @param Offset Offset to data
498
         * @param index index of points to read
499
         * @return true if success else return false 
500
         */
501
        public Point2D.Double readPoint2D(BigByteBuffer2 input, LidarHeader hdr,  long index) {
502
                
503
                byte[] punto = new byte[12];
504
                    
505
                input.position((hdr.getOffsetData()+getSizeFormat()*index)+4);
506
                input.get(punto);
507
                
508
                setX(ByteUtilities.arr2Int(punto, 4));
509
                setY(ByteUtilities.arr2Int(punto, 8)); 
510
                
511
                return new Point2D.Double((getX()-hdr.getXOffset())/hdr.getXScale(), (getY()-hdr.getYOffset())/hdr.getYScale());
512
        }
513
        
514
        /**
515
         * Read a x, y and z in point of LAS file
516
         * 
517
         * @param input input buffer to read
518
         * @param Offset Offset to data
519
         * @param index index of points to read
520
         * @return true if success else return false 
521
         */
522
        public void readPoint3D(BigByteBuffer2 input, LidarHeader hdr, long index) {
523
        
524
                byte[] punto = new byte[16];
525
                
526
            input.position((hdr.getOffsetData()+getSizeFormat()*index)+4);
527
                input.get(punto);
528
                
529
                setX(ByteUtilities.arr2Int(punto, 4));
530
                setY(ByteUtilities.arr2Int(punto, 8));
531
                setZ(ByteUtilities.arr2Int(punto, 12));
532
        }
533
        
534
        /**
535
         * get field value by index:
536
         * 
537
         * 0 return X
538
         * 1 return Y
539
         * 2 return Z
540
         * 3 return intensity
541
         * 4 return classification
542
         * 5 return Line
543
         * 6 return echo information
544
         * 7-11 Time and Color RGBI
545
         * 
546
         * @param bb byte buffer of data 
547
          * @param indexField index of field
548
         * @param hdr LiDAR header
549
         * @param index asked point index. (row)
550
         * @return Value of row and column indicated
551
         */        
552
        public Value getFieldValueByIndex(BigByteBuffer2 bb, int indexField,
553
                        LidarHeader hdr, long index) {
554
                
555
                readPoint(bb, hdr, index);
556
                
557
                switch(indexField) {
558
                
559
                        case 0:
560
                                return ValueFactory.createValue((getX()-hdr.getXOffset())/hdr.getXScale());
561
                                
562
                        case 1: 
563
                                return ValueFactory.createValue((getY()-hdr.getYOffset())/hdr.getYScale());
564
                                
565
                        case 2:
566
                                return ValueFactory.createValue((getZ()-hdr.getZOffset())/hdr.getZScale());
567
                                
568
                        case 3:
569
                                return ValueFactory.createValue(getIntensity());
570
                                
571
                        case 4:
572
                                return ValueFactory.createValue(getClassification());
573
                                
574
                        case 5:
575
                                return ValueFactory.createValue(getFlightLine());
576
                                
577
                        case 6:
578
                                return ValueFactory.createValue(getEchoInformation());
579
                                
580
                        case 7:
581
                                
582
                                if(isTimeGPS)
583
                                        return ValueFactory.createValue(getTime());
584
                                else if(isColor)
585
                                        return ValueFactory.createValue(getR());
586
                                
587
                        case 8:
588
                                
589
                                if(isTimeGPS)
590
                                        return ValueFactory.createValue(getR());
591
                                else if(isColor)
592
                                        return ValueFactory.createValue(getG());
593
                        
594
                        case 9:
595
                                
596
                                if(isTimeGPS)
597
                                        return ValueFactory.createValue(getG());
598
                                else if(isColor)
599
                                        return ValueFactory.createValue(getB());
600
                                
601
                        case 10:
602
                                
603
                                if(isTimeGPS)
604
                                        return ValueFactory.createValue(getB());
605
                                else if(isColor)
606
                                        return ValueFactory.createValue(getI());
607

    
608
                        case 11:
609
                                if(isTimeGPS)
610
                                        return ValueFactory.createValue(getI());
611
                }
612
                
613
                return null;
614
        }
615

    
616
        public Value getFieldValueByName(BigByteBuffer2 bb, String nameField, LidarHeader hdr,
617
                        long index) {
618
                
619
                readPoint(bb, hdr, index);
620
                
621
                if(nameField.equalsIgnoreCase("X"))
622
                        return ValueFactory.createValue((getX()-hdr.getXOffset())/hdr.getXScale());
623
                else if(nameField.equalsIgnoreCase("Y"))
624
                        return ValueFactory.createValue((getY()-hdr.getYOffset())/hdr.getYScale());
625
                else if(nameField.equalsIgnoreCase("Z"))
626
                        return ValueFactory.createValue((getZ()-hdr.getZOffset())/hdr.getZScale());
627
                else if(nameField.equalsIgnoreCase("Intensity"))
628
                        return ValueFactory.createValue(getIntensity());
629
                else if(nameField.equalsIgnoreCase("Classification"))
630
                        return ValueFactory.createValue(getClassification());
631
                else if(nameField.equalsIgnoreCase("Line"))
632
                        return ValueFactory.createValue(getFlightLine());
633
                else if(nameField.equalsIgnoreCase("Echo"))
634
                        return ValueFactory.createValue(getEchoInformation());
635
                else if(nameField.equalsIgnoreCase("Time"))
636
                        return ValueFactory.createValue(getTime());
637
                else if(nameField.equalsIgnoreCase("R"))
638
                        return ValueFactory.createValue(getR());
639
                else if(nameField.equalsIgnoreCase("G"))
640
                        return ValueFactory.createValue(getG());
641
                else if(nameField.equalsIgnoreCase("B"))
642
                        return ValueFactory.createValue(getB());
643
                else if(nameField.equalsIgnoreCase("I"))
644
                        return ValueFactory.createValue(getI());
645
                                
646
                return null;
647
        }
648

    
649
        public FieldDescription[] getFieldDescription() {
650
                
651
                FieldDescription fieldDesc;
652
                FieldDescription[] fields;
653
                int index;
654
                int fieldsAddByColor, fieldsAddByTime;
655
                
656
                if(isColor)
657
                        fieldsAddByColor = 4;
658
                else
659
                        fieldsAddByColor = 0;
660
                
661
                if(isTimeGPS)
662
                        fieldsAddByTime = 1;
663
                else
664
                        fieldsAddByTime = 0;
665
                
666
                fields = new FieldDescription[7+fieldsAddByColor+fieldsAddByTime];
667

    
668
                fieldDesc = new FieldDescription();
669
                fieldDesc.setFieldName("X");
670
                fieldDesc.setFieldType(Types.DOUBLE);
671
                fieldDesc.setFieldLength(20);
672
                fieldDesc.setFieldDecimalCount(3);
673
                fields[0] = fieldDesc;
674

    
675
                fieldDesc = new FieldDescription();
676
                fieldDesc.setFieldName("Y");
677
                fieldDesc.setFieldType(Types.DOUBLE);
678
                fieldDesc.setFieldLength(20);
679
                fieldDesc.setFieldDecimalCount(3);
680
                fields[1] = fieldDesc;
681

    
682
                fieldDesc = new FieldDescription();
683
                fieldDesc.setFieldName("Z");
684
                fieldDesc.setFieldType(Types.DOUBLE);
685
                fieldDesc.setFieldLength(20);
686
                fieldDesc.setFieldDecimalCount(3);
687
                fields[2] = fieldDesc;
688

    
689
                fieldDesc = new FieldDescription();
690
                fieldDesc.setFieldName("Intensity");
691
                fieldDesc.setFieldType(Types.INTEGER);
692
                fieldDesc.setFieldLength(5);
693
                fieldDesc.setFieldDecimalCount(0);
694
                fields[3] = fieldDesc;
695

    
696
                fieldDesc = new FieldDescription();
697
                fieldDesc.setFieldName("Classification");
698
                fieldDesc.setFieldType(Types.INTEGER);
699
                fieldDesc.setFieldLength(3);
700
                fieldDesc.setFieldDecimalCount(0);
701
                fields[4] = fieldDesc;
702
                
703
                fieldDesc = new FieldDescription();
704
                fieldDesc.setFieldName("Line");
705
                fieldDesc.setFieldType(Types.INTEGER);
706
                fieldDesc.setFieldLength(3);
707
                fieldDesc.setFieldDecimalCount(0);
708
                fields[5] = fieldDesc;
709
                
710
                fieldDesc = new FieldDescription();
711
                fieldDesc.setFieldName("Echo");
712
                fieldDesc.setFieldType(Types.INTEGER);
713
                fieldDesc.setFieldLength(2);
714
                fieldDesc.setFieldDecimalCount(0);
715
                fields[6] = fieldDesc;
716
                
717
                index = 7;
718
                
719
                if(isTimeGPS) {
720
                        
721
                        fieldDesc = new FieldDescription();
722
                        fieldDesc.setFieldName("Time");
723
                        fieldDesc.setFieldType(Types.INTEGER);
724
                        fieldDesc.setFieldLength(20);
725
                        fieldDesc.setFieldDecimalCount(0);
726
                        fields[index] = fieldDesc;
727
                        index++;
728
                }
729
                
730
                if(isColor) {
731
                        
732
                        fieldDesc = new FieldDescription();
733
                        fieldDesc.setFieldName("R");
734
                        fieldDesc.setFieldType(Types.INTEGER);
735
                        fieldDesc.setFieldLength(3);
736
                        fieldDesc.setFieldDecimalCount(0);
737
                        fields[index] = fieldDesc;
738
                        
739
                        fieldDesc = new FieldDescription();
740
                        fieldDesc.setFieldName("G");
741
                        fieldDesc.setFieldType(Types.INTEGER);
742
                        fieldDesc.setFieldLength(3);
743
                        fieldDesc.setFieldDecimalCount(0);
744
                        fields[index+1] = fieldDesc;
745
                        
746
                        fieldDesc = new FieldDescription();
747
                        fieldDesc.setFieldName("B");
748
                        fieldDesc.setFieldType(Types.INTEGER);
749
                        fieldDesc.setFieldLength(3);
750
                        fieldDesc.setFieldDecimalCount(0);
751
                        fields[index+2] = fieldDesc;
752
                        
753
                        fieldDesc = new FieldDescription();
754
                        fieldDesc.setFieldName("I");
755
                        fieldDesc.setFieldType(Types.INTEGER);
756
                        fieldDesc.setFieldLength(3);
757
                        fieldDesc.setFieldDecimalCount(0);
758
                        fields[index+3] = fieldDesc;
759
                        
760
                        index+=4;
761
                }
762
                
763
                return fields;
764
        }
765

    
766
        public int getFieldType(int i) {
767
                
768
                FieldDescription[] fields;
769
                fields = getFieldDescription();
770
                return fields[i].getFieldType();
771
        }
772

    
773
        public void WritePoint(ByteBuffer bb) {
774
                
775
                byte[] punto = new byte[getSizeFormat()];
776
                
777
                // byte 1
778
                punto[0] = (byte) (getClassification() & 0xFF);
779
                
780
                // byte 2
781
                punto[1] = (byte) (getFlightLine() & 0xFF);
782
                
783
                // byte 3-4
784
                ByteUtilities.unsignedShort2Arr(getIntensity(), punto, 2);
785
                
786
                // bits 7 y 8 del byte 4
787
                punto[3] >>= 2;
788
                punto[3]+=getEchoInformation();
789
                
790
                // bytes 4-8
791
                ByteUtilities.int2Arr(getX(), punto, 4);
792
                
793

    
794
                // bytes 8-12
795
                ByteUtilities.int2Arr(getY(), punto, 8);        
796
                
797
                // bytes 12-16
798
                ByteUtilities.int2Arr(getZ(), punto, 12);
799
                
800
                // si hay gps leelo
801
                if(isTimeGPS) {
802
                        
803
                        // bytes 16-20
804
                        ByteUtilities.int2Arr(time, punto, 16);
805
                        
806
                        if(isColor) {
807
                                // bytes 20-24
808
                                punto[20]= (byte) (color[0] & 0xFF);
809
                                punto[21] = (byte) (color[1] & 0xFF);
810
                                punto[22] = (byte) (color[2] & 0xFF);
811
                                punto[23] = (byte) (color[3] & 0xFF);
812
                        }
813
                } else {
814
                
815
                        // si hay color leelo
816
                        if(isColor) {
817
                                
818
                                // bytes 16-20
819
                                punto[16]= (byte) (color[0] & 0xFF);
820
                                punto[17] = (byte) (color[1] & 0xFF);
821
                                punto[18] = (byte) (color[2] & 0xFF);
822
                                punto[19] = (byte) (color[3] & 0xFF);
823
                        }
824
                }
825
                
826
                bb.put(punto);
827
                
828
                return;
829
        }
830

    
831
        /*
832
         * Set Point from a row
833
         * @see com.dielmo.gvsig.lidar.LidarPoint#setPoint(com.hardcode.gdbms.engine.values.Value[], com.dielmo.gvsig.lidar.LidarHeader)
834
         */
835
        public void setPoint(Value[] row, LidarHeader hdr) {
836
                
837
                double auxX = ((DoubleValue)(row[0])).getValue();
838
                double auxY = ((DoubleValue)(row[1])).getValue();
839
                double auxZ = ((DoubleValue)(row[2])).getValue();
840
                
841
                setX((int) (auxX * (hdr.getXScale()) + hdr.getXOffset())); 
842
                setY((int) (auxY * (hdr.getYScale()) + hdr.getYOffset()));
843
                setZ((int) (auxZ * (hdr.getZScale()) + hdr.getZOffset()));
844
                
845
                setIntensity(((IntValue)(row[3])).getValue());
846
                setClassification((char) (((IntValue)(row[4])).byteValue() & 0xFF));
847
                setFlightLine((char) (((IntValue)(row[5])).byteValue() & 0xFF));
848
                setEchoInformation(((IntValue)(row[6])).byteValue()); 
849
                
850
                if(hdr instanceof BINHeader) {
851
                        
852
                        BINHeader hdrBin = (BINHeader) hdr;
853
                        if(hdrBin.getTime()>0) {
854
                                
855
                                setTime(((IntValue)(row[7])).getValue());
856
                                
857
                                if(hdrBin.getColor()>0) {
858
                                        
859
                                        color[0] = (char) (((IntValue)(row[8])).byteValue() & 0xFF);
860
                                        color[1] = (char) (((IntValue)(row[9])).byteValue() & 0xFF);
861
                                        color[2] = (char) (char) (((IntValue)(row[10])).byteValue() & 0xFF);
862
                                        color[3] = (char) (((IntValue)(row[11])).byteValue() & 0xFF);
863
                                }
864
                        } else {
865
                                
866
                                if(hdrBin.getColor()>0) {
867
                                        
868
                                        color[0] = (char) (((IntValue)(row[7])).byteValue() & 0xFF);
869
                                        color[1] = (char) (((IntValue)(row[8])).byteValue() & 0xFF);
870
                                        color[2] = (char) (((IntValue)(row[9])).byteValue() & 0xFF);
871
                                        color[3] = (char) (((IntValue)(row[10])).byteValue() & 0xFF);
872
                                }
873
                        }
874
                }
875
        }
876

    
877
}