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