svn-gvsig-desktop / branches / v10 / libraries / libDielmoOpenLidar / src / com / dielmo / lidar / LASPoint11F0.java @ 26423
History | View | Annotate | Download (23.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 |
|
55 |
import com.dielmo.lidar.fieldsDescription.ColumnDescription; |
56 |
import com.dielmo.lidar.fieldsDescription.ContainerColumnDescription; |
57 |
|
58 |
/**
|
59 |
* LAS point that implement the LAS point data version LAS1.1
|
60 |
* in format 0
|
61 |
*
|
62 |
* @author Oscar Garcia
|
63 |
*/
|
64 |
public class LASPoint11F0 implements LidarPoint{ |
65 |
|
66 |
protected int sizeFormat; |
67 |
|
68 |
/**
|
69 |
* X value
|
70 |
*/
|
71 |
protected int x; |
72 |
|
73 |
/**
|
74 |
* Y value
|
75 |
*/
|
76 |
protected int y; |
77 |
|
78 |
/**
|
79 |
* Z value
|
80 |
*/
|
81 |
protected int z; |
82 |
|
83 |
/**
|
84 |
* The intensity value is the integer representation of the
|
85 |
* pulse return magnitude.
|
86 |
*/
|
87 |
protected int intensity; |
88 |
|
89 |
/**
|
90 |
* The return number is the pulse return number for a given output
|
91 |
* pulse.
|
92 |
*/
|
93 |
protected byte returnNumber; |
94 |
|
95 |
/**
|
96 |
* Total number of returns for a given pulse.
|
97 |
*/
|
98 |
protected byte numberOfReturn; |
99 |
|
100 |
/**
|
101 |
* direction at which the scanner mirror was traveling at the time
|
102 |
* of the output pulse.
|
103 |
*/
|
104 |
protected byte scanDirectionFlag; |
105 |
|
106 |
/**
|
107 |
* The edge of flight line data bit has a value of 1 only when
|
108 |
* the point is at the end of a scan. It is the last point on a
|
109 |
* given scan line before it changes direction.
|
110 |
*/
|
111 |
protected byte edgeOfFlightLine; |
112 |
|
113 |
/**
|
114 |
* The classification field is a number to signify a given
|
115 |
* classification during filter processing.
|
116 |
*/
|
117 |
protected char classification; |
118 |
|
119 |
/**
|
120 |
* If Synthetic is set, then this point was created by a technique
|
121 |
* other than LIDAR collection such as digitized from a photogrammetric
|
122 |
* stereo model.
|
123 |
*/
|
124 |
protected byte synthetic; |
125 |
|
126 |
/**
|
127 |
* If KeyPoint is set, this point is considered to be a model keypoint
|
128 |
* and thus generally should not be withheld in a thinning algorithm
|
129 |
*/
|
130 |
protected byte keyPoint; |
131 |
|
132 |
/**
|
133 |
* If Withheld is set, this point should not be included in
|
134 |
* processing (synonymous with Deleted).
|
135 |
*/
|
136 |
protected byte withheld; |
137 |
|
138 |
/**
|
139 |
* Angle at which the laser point was output from the laser system
|
140 |
* including the roll of the aircraft. The scan angle is within 1
|
141 |
* degree of accuracy from +90 to -90 degrees. The scan angle is an
|
142 |
* angle based on 0 degrees being NADIR, end -90 degrees to the left
|
143 |
* side of the aircraft in the direction of flight.
|
144 |
*/
|
145 |
protected byte scanAngleRank; |
146 |
|
147 |
/**
|
148 |
* This field may be used at the user's discretion.
|
149 |
*/
|
150 |
protected char userData; |
151 |
|
152 |
protected long lasIndex; |
153 |
|
154 |
/**
|
155 |
* This value indicates the file from which this point originated.
|
156 |
* Valid values for this field are 1 to 65,535 inclusive with zero
|
157 |
* being used for a special case discussed below. The numerical
|
158 |
* value corresponds to the File Source ID from which this point
|
159 |
* originated. Zero is reserved as a convenience to system implementers.
|
160 |
* A Point Source ID of zero implies that this point originated in this
|
161 |
* file. This implies that processing software should set the Point
|
162 |
* Source ID equal to the File Source ID of the file containing
|
163 |
* this point at some time during processing.
|
164 |
*/
|
165 |
protected int pointSourceID; |
166 |
|
167 |
/**
|
168 |
* Default constructor, without arguments.
|
169 |
* Initializes all components to zero.
|
170 |
*/
|
171 |
public LASPoint11F0() {
|
172 |
x = 0;
|
173 |
y = 0;
|
174 |
z = 0;
|
175 |
intensity = 0;
|
176 |
returnNumber = 0;
|
177 |
numberOfReturn = 0;
|
178 |
scanDirectionFlag = 0;
|
179 |
edgeOfFlightLine = 0;
|
180 |
classification = 0;
|
181 |
scanAngleRank = 0;
|
182 |
userData = 0;
|
183 |
pointSourceID = 0;
|
184 |
sizeFormat = 20;
|
185 |
lasIndex=-1;
|
186 |
} |
187 |
|
188 |
// GET METHODS
|
189 |
/**
|
190 |
* Return X value that is stored as long integer. The corresponding
|
191 |
* X scale from the public header block change this long integer to
|
192 |
* true floating point value. The corresponding offset value can
|
193 |
* also be used for projections with very large numbers.
|
194 |
*
|
195 |
* the coordinate = X*Xscale+Xoffset
|
196 |
*
|
197 |
* @return x value
|
198 |
*/
|
199 |
public int getX() { |
200 |
return x;
|
201 |
} |
202 |
|
203 |
/**
|
204 |
* Return Y value that is stored as long integer. The corresponding
|
205 |
* Y scale from the public header block change this long integer to
|
206 |
* true floating point value. The corresponding offset value can
|
207 |
* also be used for projections with very large numbers.
|
208 |
*
|
209 |
* the coordinate = Y*Yscale+Yoffset
|
210 |
*
|
211 |
* @return y value
|
212 |
*/
|
213 |
public int getY() { |
214 |
return y;
|
215 |
} |
216 |
|
217 |
/**
|
218 |
* Return Z value that is stored as long integer. The corresponding
|
219 |
* Z scale from the public header block change this long integer to
|
220 |
* true floating point value. The corresponding offset value can
|
221 |
* also be used for projections with very large numbers.
|
222 |
*
|
223 |
* the coordinate = Z*Zscale+Zoffset
|
224 |
*
|
225 |
* @return z value
|
226 |
*/
|
227 |
public int getZ() { |
228 |
return z;
|
229 |
} |
230 |
|
231 |
/**
|
232 |
* Get the intensity value as the integer representation of the pulse
|
233 |
* return magnitude. This value is optional and system specific
|
234 |
*
|
235 |
* @return intensity value
|
236 |
*/
|
237 |
public int getIntensity() { |
238 |
return intensity;
|
239 |
} |
240 |
|
241 |
/**
|
242 |
* Get the return number as the pulse return number for a given output
|
243 |
* pulse.
|
244 |
*
|
245 |
* @return pulse return number
|
246 |
*/
|
247 |
public byte getReturnNumber() { |
248 |
return returnNumber;
|
249 |
} |
250 |
|
251 |
/**
|
252 |
* Get total number of returns for a given pulse.
|
253 |
*
|
254 |
* @return number of return
|
255 |
*/
|
256 |
public byte getNumberOfReturn() { |
257 |
return numberOfReturn;
|
258 |
} |
259 |
|
260 |
/**
|
261 |
* Get direction at which the scanner mirror was traveling at the time
|
262 |
* of the output pulse.
|
263 |
*
|
264 |
* @return direction
|
265 |
*/
|
266 |
public byte getScanDirectionFlag() { |
267 |
return scanDirectionFlag;
|
268 |
} |
269 |
|
270 |
/**
|
271 |
* Get the edge of flight line data bit.
|
272 |
*
|
273 |
* @return edge of flight
|
274 |
*/
|
275 |
public byte getEdgeOfFlightLine() { |
276 |
return edgeOfFlightLine;
|
277 |
} |
278 |
|
279 |
/**
|
280 |
* Get a given classification during filter processing.
|
281 |
*
|
282 |
* @return classification
|
283 |
*/
|
284 |
public char getClassification() { |
285 |
return (char)(classification & 0x1F); |
286 |
} |
287 |
|
288 |
/**
|
289 |
* Get angle at which the laser point was output from the laser system
|
290 |
* including the roll of the aircraft. The scan angle is within 1
|
291 |
* degree of accuracy from +90 to 90 degrees. The scan angle is an
|
292 |
* angle based on 0 degrees being NADIR, end -90 degrees to the left
|
293 |
* side of the aircraft in the direction of flight.
|
294 |
*
|
295 |
* @return scan angle rank
|
296 |
*/
|
297 |
public byte getScanAngleRank() { |
298 |
return scanAngleRank;
|
299 |
} |
300 |
|
301 |
/**
|
302 |
* Get userData.
|
303 |
* This field may be used at the user's discretion.
|
304 |
*
|
305 |
* @return user data
|
306 |
*/
|
307 |
public char getUserData() { |
308 |
return userData;
|
309 |
} |
310 |
|
311 |
/**
|
312 |
* Get point source ID, this value indicates the file from which
|
313 |
* this point originated.
|
314 |
*
|
315 |
* @return user bit field
|
316 |
*/
|
317 |
public int getPointSourceID() { |
318 |
return pointSourceID;
|
319 |
} |
320 |
|
321 |
/**
|
322 |
* Get Synthetic. If synthetic is set, then this point was created by a
|
323 |
* technique other than LIDAR collection such as digitized from
|
324 |
* a photogrammetric stereo model.
|
325 |
*
|
326 |
* @return synthetic
|
327 |
*/
|
328 |
public byte getSynthetic() { |
329 |
return synthetic;
|
330 |
} |
331 |
|
332 |
/**
|
333 |
* Get keyPoint. If KeyPoint is set, this point is considered to be
|
334 |
* a model keypoint and thus generally should not be withheld in a
|
335 |
* thinning algorithm
|
336 |
*
|
337 |
* @return keyPoint
|
338 |
*/
|
339 |
public byte getKeyPoint() { |
340 |
return keyPoint;
|
341 |
} |
342 |
|
343 |
/**
|
344 |
* Get withheld. If Withheld is set, this point should not be
|
345 |
* included in processing (synonymous with Deleted).
|
346 |
*
|
347 |
* @return withheld
|
348 |
*/
|
349 |
public byte getWithheld() { |
350 |
return withheld;
|
351 |
} |
352 |
|
353 |
/**
|
354 |
* Get a bit size of point format
|
355 |
*
|
356 |
* @return sizeFormat
|
357 |
*/
|
358 |
public int getSizeFormat() { |
359 |
return sizeFormat;
|
360 |
} |
361 |
|
362 |
// SET METHODS
|
363 |
|
364 |
/**
|
365 |
* set X value that is stored as integer.
|
366 |
*
|
367 |
* @param newx new value of x
|
368 |
*/
|
369 |
public void setX(int newx) { |
370 |
x = newx; |
371 |
} |
372 |
|
373 |
/**
|
374 |
* set Y value that is stored as integer.
|
375 |
*
|
376 |
* @param newy new value of y
|
377 |
*/
|
378 |
public void setY(int newy) { |
379 |
y = newy; |
380 |
} |
381 |
|
382 |
/**
|
383 |
* set Z value that is stored as integer.
|
384 |
*
|
385 |
* @param newz new value of z
|
386 |
*/
|
387 |
public void setZ(int newz) { |
388 |
z = newz; |
389 |
} |
390 |
|
391 |
/**
|
392 |
* Set the intensity value as the integer representation of the pulse
|
393 |
* return magnitude. This value is optional and system specific
|
394 |
*
|
395 |
* @param inten new intensity
|
396 |
*/
|
397 |
public void setIntensity(int inten) { |
398 |
|
399 |
try{
|
400 |
if(inten >=0 && inten <= UNSIGNED_SHORT_MAX) |
401 |
intensity = inten; |
402 |
else
|
403 |
throw new OutOfRangeLidarException("Out of range of intensity"); |
404 |
|
405 |
} catch(OutOfRangeLidarException e) {
|
406 |
|
407 |
e.printStackTrace(); |
408 |
} |
409 |
} |
410 |
|
411 |
/**
|
412 |
* Set the return number.
|
413 |
*
|
414 |
* @param rn new pulse return number
|
415 |
*/
|
416 |
public void setReturnNumber(byte rn) { |
417 |
|
418 |
try{
|
419 |
if(rn>=0 && rn <= 7) |
420 |
returnNumber = rn; |
421 |
else
|
422 |
throw new OutOfRangeLidarException("Out of range of return number"); |
423 |
|
424 |
} catch(OutOfRangeLidarException e) {
|
425 |
|
426 |
e.printStackTrace(); |
427 |
} |
428 |
} |
429 |
|
430 |
/**
|
431 |
* Set total number of returns for a given pulse.
|
432 |
*
|
433 |
* @param nof new number of return
|
434 |
*/
|
435 |
public void setNumberOfReturn(byte nof) { |
436 |
|
437 |
try{
|
438 |
if(nof>=0 && nof <= 7) |
439 |
numberOfReturn = nof; |
440 |
else
|
441 |
throw new OutOfRangeLidarException("Out of range of number of return"); |
442 |
|
443 |
} catch(OutOfRangeLidarException e) {
|
444 |
|
445 |
e.printStackTrace(); |
446 |
} |
447 |
} |
448 |
|
449 |
/**
|
450 |
* Set direction at which the scanner mirror was traveling at the time
|
451 |
* of the output pulse.
|
452 |
*
|
453 |
* @param sdf new direction
|
454 |
*/
|
455 |
public void setScanDirectionFlag(byte sdf){ |
456 |
|
457 |
try{
|
458 |
if(sdf>=0 && sdf<=1) |
459 |
scanDirectionFlag = sdf; |
460 |
else
|
461 |
throw new OutOfRangeLidarException("Out of range of scan direction flag"); |
462 |
|
463 |
} catch(OutOfRangeLidarException e) {
|
464 |
|
465 |
e.printStackTrace(); |
466 |
} |
467 |
} |
468 |
|
469 |
/**
|
470 |
* Set the edge of flight line data bit.
|
471 |
*
|
472 |
* @param eofl new edge of flight
|
473 |
*/
|
474 |
public void setEdgeOfFlightLine(byte eofl) { |
475 |
|
476 |
try{
|
477 |
if(eofl>=0 && eofl <= 1) |
478 |
edgeOfFlightLine = eofl; |
479 |
else
|
480 |
throw new OutOfRangeLidarException("Out of range of flight line"); |
481 |
|
482 |
} catch(OutOfRangeLidarException e) {
|
483 |
|
484 |
e.printStackTrace(); |
485 |
} |
486 |
} |
487 |
|
488 |
/**
|
489 |
* Set a given classification during filter processing.
|
490 |
*
|
491 |
* @return c new classification
|
492 |
*/
|
493 |
public void setClassification(char c) { |
494 |
|
495 |
try{
|
496 |
if(c>=0 && c<=255) |
497 |
classification = c; |
498 |
else
|
499 |
throw new OutOfRangeLidarException("Out of range of classification"); |
500 |
|
501 |
} catch(OutOfRangeLidarException e) {
|
502 |
|
503 |
e.printStackTrace(); |
504 |
} |
505 |
} |
506 |
|
507 |
/**
|
508 |
* Set angle at which the laser point was output from the laser system
|
509 |
* including the roll of the aircraft.
|
510 |
*
|
511 |
* @param sar new scan angle rank
|
512 |
*/
|
513 |
public void setScanAngleRank(byte sar) { |
514 |
|
515 |
/* try{
|
516 |
if((int)sar>=-90 && (int)sar<=90)
|
517 |
*/ scanAngleRank = sar;
|
518 |
/* else
|
519 |
throw new OutOfRangeLidarException("Out of range of scan angle rank");
|
520 |
|
521 |
} catch(OutOfRangeLidarException e) {
|
522 |
|
523 |
e.printStackTrace();
|
524 |
}
|
525 |
*/ }
|
526 |
|
527 |
/**
|
528 |
* Set userData.
|
529 |
* This field may be used at the user's discretion.
|
530 |
*
|
531 |
* @param ud new user data
|
532 |
*/
|
533 |
public void setUserData(char ud) { |
534 |
|
535 |
try{
|
536 |
if(ud>=0 && ud<=255) |
537 |
userData = ud; |
538 |
else
|
539 |
throw new OutOfRangeLidarException("Out of range of user data"); |
540 |
|
541 |
} catch(OutOfRangeLidarException e) {
|
542 |
|
543 |
e.printStackTrace(); |
544 |
} |
545 |
} |
546 |
|
547 |
/**
|
548 |
* Set point source ID, this value indicates the file from which
|
549 |
* this point originated.
|
550 |
*
|
551 |
* @param psid user bit field
|
552 |
*/
|
553 |
public void setPointSourceID(int psid) { |
554 |
|
555 |
try{
|
556 |
if(psid >=0 && psid <= UNSIGNED_SHORT_MAX) |
557 |
pointSourceID = psid; |
558 |
else
|
559 |
throw new OutOfRangeLidarException("Out of range of point source ID"); |
560 |
|
561 |
} catch(OutOfRangeLidarException e) {
|
562 |
|
563 |
e.printStackTrace(); |
564 |
} |
565 |
} |
566 |
|
567 |
/**
|
568 |
* Set Synthetic. If synthetic is set, then this point was created by a
|
569 |
* technique other than LIDAR collection such as digitized from
|
570 |
* a photogrammetric stereo model.
|
571 |
*
|
572 |
* @param s new synthetic
|
573 |
*/
|
574 |
public void setSynthetic(byte s) { |
575 |
|
576 |
try{
|
577 |
if(s>=0 && s<=7) |
578 |
synthetic = s; |
579 |
else
|
580 |
throw new OutOfRangeLidarException("Out of range of synthetic"); |
581 |
|
582 |
} catch(OutOfRangeLidarException e) {
|
583 |
|
584 |
e.printStackTrace(); |
585 |
} |
586 |
} |
587 |
|
588 |
/**
|
589 |
* Set keyPoint. If KeyPoint is set, this point is considered to be
|
590 |
* a model keypoint and thus generally should not be withheld in a
|
591 |
* thinning algorithm
|
592 |
*
|
593 |
* @param k new keyPoint
|
594 |
*/
|
595 |
public void setKeyPoint(byte k) { |
596 |
|
597 |
try{
|
598 |
if(k>=0 && k<=7) |
599 |
keyPoint = k; |
600 |
else
|
601 |
throw new OutOfRangeLidarException("Out of range of key point"); |
602 |
|
603 |
} catch(OutOfRangeLidarException e) {
|
604 |
|
605 |
e.printStackTrace(); |
606 |
} |
607 |
} |
608 |
|
609 |
/**
|
610 |
* Set withheld. If Withheld is set, this point should not be
|
611 |
* included in processing (synonymous with Deleted).
|
612 |
*
|
613 |
* @param w new withheld
|
614 |
*/
|
615 |
public void setWithheld(byte w){ |
616 |
|
617 |
try{
|
618 |
if(w>=0 && w<=7) |
619 |
withheld = w; |
620 |
else
|
621 |
throw new OutOfRangeLidarException("Out of range of withheld"); |
622 |
|
623 |
} catch(OutOfRangeLidarException e) {
|
624 |
|
625 |
e.printStackTrace(); |
626 |
} |
627 |
} |
628 |
|
629 |
/**
|
630 |
* Read a point of LAS file
|
631 |
*
|
632 |
* @param input input buffer to read
|
633 |
* @param Offset Offset to data
|
634 |
* @param index index of points to read
|
635 |
* @return true if success else return false
|
636 |
*/
|
637 |
public void readPoint(BigByteBuffer2 input, LidarHeader hdr, long index) { |
638 |
|
639 |
try{
|
640 |
if(index>hdr.getNumPointsRecord() || index < 0) { |
641 |
throw new UnexpectedPointException("Out of index"); |
642 |
} |
643 |
|
644 |
if(index==lasIndex)
|
645 |
return;
|
646 |
else
|
647 |
lasIndex=index; |
648 |
|
649 |
byte[] punto = new byte[getSizeFormat()]; |
650 |
|
651 |
input.position(hdr.getOffsetData()+getSizeFormat()*index); |
652 |
input.get(punto); |
653 |
|
654 |
setX(ByteUtilities.arr2Int(punto, 0));
|
655 |
setY(ByteUtilities.arr2Int(punto, 4));
|
656 |
setZ(ByteUtilities.arr2Int(punto, 8));
|
657 |
setIntensity(ByteUtilities.arr2Unsignedshort(punto, 12));
|
658 |
|
659 |
setReturnNumber((byte)(punto[14] & 0x07)); // 3 primeros bits del byte 14 |
660 |
setNumberOfReturn((byte)((punto[14] & 0x38) >> 3)); // 3 siguintes bits |
661 |
setScanDirectionFlag((byte)((punto[14] & 0x40) >> 6)); // 1 bit |
662 |
setEdgeOfFlightLine((byte)((punto[14] & 0x80) >> 7)); // 1 bit |
663 |
|
664 |
setClassification((char)(punto[15] & 0X1F)); // 5 bits del byte 15 |
665 |
setSynthetic((byte)((punto[15] & 0X20) >> 5 )); // 1 bit |
666 |
setKeyPoint((byte)((punto[15] & 0X40) >> 6 )); // 1 bit |
667 |
setWithheld((byte)((punto[15] & 0X80) >> 7 )); // 1 bit |
668 |
|
669 |
setScanAngleRank(punto[16]);
|
670 |
setUserData((char)(punto[17] & 0XFF)); |
671 |
setPointSourceID(ByteUtilities.arr2Unsignedshort(punto, 18));
|
672 |
|
673 |
} catch (UnexpectedPointException e) {
|
674 |
// TODO Auto-generated catch block
|
675 |
e.printStackTrace(); |
676 |
} |
677 |
} |
678 |
|
679 |
/**
|
680 |
* Read a x and y in point of LAS file
|
681 |
*
|
682 |
* @param input input buffer to read
|
683 |
* @param Offset Offset to data
|
684 |
* @param index index of points to read
|
685 |
* @return true if success else return false
|
686 |
*/
|
687 |
public Point2D.Double readPoint2D(BigByteBuffer2 input, LidarHeader hdr, long index) { |
688 |
|
689 |
|
690 |
try{
|
691 |
|
692 |
if(index>hdr.getNumPointsRecord() || index < 0) { |
693 |
throw new UnexpectedPointException("Out of index"); |
694 |
} |
695 |
|
696 |
byte[] punto = new byte[8]; |
697 |
|
698 |
input.position(hdr.getOffsetData()+getSizeFormat()*index); |
699 |
input.get(punto); |
700 |
|
701 |
setX(ByteUtilities.arr2Int(punto, 0));
|
702 |
setY(ByteUtilities.arr2Int(punto, 4));
|
703 |
|
704 |
return new Point2D.Double(getX()*hdr.getXScale()+hdr.getXOffset(), getY()*hdr.getYScale()+hdr.getYOffset()); |
705 |
|
706 |
} catch (UnexpectedPointException e) {
|
707 |
// TODO Auto-generated catch block
|
708 |
e.printStackTrace(); |
709 |
} |
710 |
|
711 |
return null; |
712 |
} |
713 |
|
714 |
/**
|
715 |
* Read a x, y and z in point of LAS file
|
716 |
*
|
717 |
* @param input input buffer to read
|
718 |
* @param Offset Offset to data
|
719 |
* @param index index of points to read
|
720 |
* @return true if success else return false
|
721 |
*/
|
722 |
public void readPoint3D(BigByteBuffer2 input, LidarHeader hdr, long index) { |
723 |
|
724 |
try{
|
725 |
if(index>hdr.getNumPointsRecord() || index < 0) { |
726 |
throw new UnexpectedPointException("Out of index"); |
727 |
} |
728 |
|
729 |
byte[] punto = new byte[12]; |
730 |
|
731 |
input.position(hdr.getOffsetData()+getSizeFormat()*index); |
732 |
input.get(punto); |
733 |
|
734 |
setX(ByteUtilities.arr2Int(punto, 0));
|
735 |
setY(ByteUtilities.arr2Int(punto, 4));
|
736 |
setZ(ByteUtilities.arr2Int(punto, 8));
|
737 |
|
738 |
} catch (UnexpectedPointException e) {
|
739 |
// TODO Auto-generated catch block
|
740 |
e.printStackTrace(); |
741 |
} |
742 |
} |
743 |
|
744 |
/**
|
745 |
* get by field the Value:
|
746 |
*
|
747 |
* 0 return X
|
748 |
* 1 return Y
|
749 |
* 2 return Z
|
750 |
* 3 return intensity
|
751 |
* 4 return returnNumber
|
752 |
* 5 return numberOfReturn
|
753 |
* 6 return scanDirectionFlag
|
754 |
* 7 return edgeOfFlightLine
|
755 |
* 8 return classification
|
756 |
* 9 return synthetic
|
757 |
* 10 return keyPoint
|
758 |
* 11 return withheld
|
759 |
* 12 return scanAngleRank
|
760 |
* 13 return userData
|
761 |
* 14 return pointSourceID
|
762 |
*
|
763 |
* @param bb byte buffer of data
|
764 |
* @param indexField index of field
|
765 |
* @param hdr LiDAR header
|
766 |
* @param index asked point index. (row)
|
767 |
* @return Value of row and column indicated
|
768 |
*/
|
769 |
public Object getFieldValueByIndex(BigByteBuffer2 bb, int indexField, |
770 |
LidarHeader hdr, long index) {
|
771 |
|
772 |
readPoint(bb, hdr, index); |
773 |
|
774 |
switch(indexField) {
|
775 |
|
776 |
case 0: |
777 |
return getX() * hdr.getXScale() + hdr.getXOffset();
|
778 |
|
779 |
case 1: |
780 |
return getY() * hdr.getYScale() + hdr.getYOffset();
|
781 |
|
782 |
case 2: |
783 |
return getZ() * hdr.getZScale() + hdr.getZOffset();
|
784 |
|
785 |
case 3: |
786 |
return getIntensity();
|
787 |
|
788 |
case 4: |
789 |
return getReturnNumber();
|
790 |
|
791 |
case 5: |
792 |
return getNumberOfReturn();
|
793 |
|
794 |
case 6: |
795 |
return getScanDirectionFlag();
|
796 |
|
797 |
case 7: |
798 |
return getEdgeOfFlightLine();
|
799 |
|
800 |
case 8: |
801 |
return (byte)getClassification(); |
802 |
|
803 |
case 9: |
804 |
return getSynthetic();
|
805 |
|
806 |
case 10: |
807 |
return getKeyPoint();
|
808 |
|
809 |
case 11: |
810 |
return getWithheld();
|
811 |
|
812 |
case 12: |
813 |
return getScanAngleRank();
|
814 |
|
815 |
case 13: |
816 |
return (byte)getUserData(); |
817 |
|
818 |
case 14: |
819 |
return getPointSourceID();
|
820 |
} |
821 |
|
822 |
return null; |
823 |
} |
824 |
|
825 |
public Object getFieldValueByName(BigByteBuffer2 bb, String nameField, LidarHeader hdr, |
826 |
long index) {
|
827 |
|
828 |
readPoint(bb, hdr, index); |
829 |
|
830 |
if(nameField.equalsIgnoreCase("X")) |
831 |
return getX()*hdr.getXScale()+hdr.getXOffset();
|
832 |
else if(nameField.equalsIgnoreCase("Y")) |
833 |
return getY()*hdr.getYScale()+hdr.getYOffset();
|
834 |
else if(nameField.equalsIgnoreCase("Z")) |
835 |
return getZ()*hdr.getZScale()+hdr.getZOffset();
|
836 |
else if(nameField.equalsIgnoreCase("Intensity")) |
837 |
return getIntensity();
|
838 |
else if(nameField.equalsIgnoreCase("Return_Number")) |
839 |
return getReturnNumber();
|
840 |
else if(nameField.equalsIgnoreCase("Number_of_Returns")) |
841 |
return getNumberOfReturn();
|
842 |
else if(nameField.equalsIgnoreCase("Scan_Direction_Flag")) |
843 |
return getScanDirectionFlag();
|
844 |
else if(nameField.equalsIgnoreCase("Edge_of_Flight_Line")) |
845 |
return getEdgeOfFlightLine();
|
846 |
else if(nameField.equalsIgnoreCase("Classification")) |
847 |
return (byte)getClassification(); |
848 |
else if(nameField.equalsIgnoreCase("Synthetic")) |
849 |
return getSynthetic();
|
850 |
else if(nameField.equalsIgnoreCase("Key_Point")) |
851 |
return getKeyPoint();
|
852 |
else if(nameField.equalsIgnoreCase("Withheld")) |
853 |
return getWithheld();
|
854 |
else if(nameField.equalsIgnoreCase("Scan_Angle_Rank")) |
855 |
return getScanAngleRank();
|
856 |
else if(nameField.equalsIgnoreCase("User_Data")) |
857 |
return (byte)getUserData(); |
858 |
else if(nameField.equalsIgnoreCase("Point_Source_ID")) |
859 |
return getPointSourceID();
|
860 |
|
861 |
return null; |
862 |
} |
863 |
|
864 |
|
865 |
public ContainerColumnDescription getColumnsDescription(ContainerColumnDescription fields) {
|
866 |
|
867 |
fields.add("X", ColumnDescription.DOUBLE, 20, 3, 0.0); |
868 |
fields.add("Y", ColumnDescription.DOUBLE, 20, 3, 0.0); |
869 |
fields.add("Z", ColumnDescription.DOUBLE, 20, 3, 0.0); |
870 |
fields.add("Intensity", ColumnDescription.INT, 5, 0, 0); |
871 |
fields.add("Return_Number", ColumnDescription.BYTE, 1, 0, 0); |
872 |
fields.add("Number_of_Returns", ColumnDescription.BYTE, 1, 0, 0); |
873 |
fields.add("Scan_Direction_Flag", ColumnDescription.BYTE, 1, 0, 0); |
874 |
fields.add("Edge_of_Flight_Line", ColumnDescription.BYTE, 1, 0, 0); |
875 |
fields.add("Classification", ColumnDescription.BYTE, 1, 0, 0); |
876 |
fields.add("Synthetic", ColumnDescription.BYTE, 1, 0, 0); |
877 |
fields.add("Key_Point", ColumnDescription.BYTE, 1, 0, 0); |
878 |
fields.add("Withheld", ColumnDescription.BYTE, 1, 0, 0); |
879 |
fields.add("Scan_Angle_Rank", ColumnDescription.INT, 3, 0, 0); |
880 |
fields.add("User_Data", ColumnDescription.INT, 3, 0, 0); |
881 |
fields.add("Point_Source_ID", ColumnDescription.INT, 10, 0, 0); |
882 |
|
883 |
return fields;
|
884 |
} |
885 |
|
886 |
public void WritePoint(ByteBuffer bb) { |
887 |
|
888 |
byte auxByte;
|
889 |
byte[] punto = new byte[getSizeFormat()]; |
890 |
|
891 |
// X bytes 0-4
|
892 |
ByteUtilities.int2Arr(getX(), punto, 0);
|
893 |
|
894 |
// Y bytes 4-8
|
895 |
ByteUtilities.int2Arr(getY(), punto, 4);
|
896 |
|
897 |
// bytes 8-12
|
898 |
ByteUtilities.int2Arr(getZ(), punto, 8);
|
899 |
|
900 |
// bytes 12-14
|
901 |
ByteUtilities.unsignedShort2Arr(getIntensity(), punto, 12);
|
902 |
|
903 |
// byte 14
|
904 |
auxByte = getReturnNumber(); |
905 |
auxByte |= (byte)((getNumberOfReturn()) << 3); |
906 |
auxByte |= (byte)((getScanDirectionFlag()) << 6); |
907 |
auxByte |= (byte)((getEdgeOfFlightLine()) << 7); |
908 |
punto[14] = auxByte;
|
909 |
|
910 |
// byte 15
|
911 |
auxByte = (byte)(getClassification());
|
912 |
auxByte |= (byte)((getSynthetic()) << 5); |
913 |
auxByte |= (byte)((getKeyPoint()) << 6); |
914 |
auxByte |= (byte)((getWithheld()) << 7); |
915 |
punto[15] = auxByte;
|
916 |
|
917 |
// byte 16
|
918 |
punto[16] = (byte)((getScanAngleRank() & 0xFF)); |
919 |
|
920 |
// byte 17
|
921 |
punto[17] = (byte)((getUserData() & 0xFF)); |
922 |
|
923 |
// bytes 18-20
|
924 |
ByteUtilities.unsignedShort2Arr(getPointSourceID(), punto, 18);
|
925 |
|
926 |
bb.put(punto); |
927 |
} |
928 |
|
929 |
/*
|
930 |
* Set Point from a row
|
931 |
*/
|
932 |
public void setPoint(Object[] row, LidarHeader hdr) { |
933 |
|
934 |
double auxX = ((Double)(row[0])); |
935 |
double auxY = ((Double)(row[1])); |
936 |
double auxZ = ((Double)(row[2])); |
937 |
|
938 |
setX((int) ((auxX-hdr.getXOffset())/hdr.getXScale()));
|
939 |
setY((int) ((auxY-hdr.getYOffset())/hdr.getYScale()));
|
940 |
setZ((int) ((auxZ-hdr.getZOffset())/hdr.getZScale()));
|
941 |
|
942 |
setIntensity(((Integer)(row[3]))); |
943 |
setReturnNumber(((Integer)(row[4])).byteValue()); |
944 |
setNumberOfReturn(((Integer)(row[5])).byteValue()); |
945 |
setScanDirectionFlag(((Integer)(row[6])).byteValue()); |
946 |
setEdgeOfFlightLine(((Integer)(row[7])).byteValue()); |
947 |
setClassification((char) (((Integer)(row[8])).byteValue() & 0xFF)); |
948 |
|
949 |
setSynthetic((byte) (((Integer)(row[9])).byteValue())); |
950 |
setKeyPoint((byte) (((Integer)(row[10])).byteValue())); |
951 |
setWithheld((byte) (((Integer)(row[11])).byteValue())); |
952 |
|
953 |
setScanAngleRank( ((Integer)(row[12])).byteValue()); |
954 |
setUserData((char) (((Integer)(row[13])).byteValue() & 0xFF)); |
955 |
setPointSourceID(((Integer)(row[14]))); |
956 |
} |
957 |
} |