svn-gvsig-desktop / branches / v10 / libraries / libLidar / src / com / dielmo / lidar / LASPoint11F1.java @ 25423
History | View | Annotate | Download (14.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.nio.ByteBuffer; |
53 |
import java.sql.Types; |
54 |
|
55 |
import com.hardcode.gdbms.engine.values.DoubleValue; |
56 |
import com.hardcode.gdbms.engine.values.IntValue; |
57 |
import com.hardcode.gdbms.engine.values.Value; |
58 |
import com.hardcode.gdbms.engine.values.ValueFactory; |
59 |
import com.iver.cit.gvsig.fmap.drivers.FieldDescription; |
60 |
import com.iver.utiles.bigfile.BigByteBuffer2; |
61 |
|
62 |
|
63 |
/**
|
64 |
* LAS point that implement the LAS point data version LAS1.0
|
65 |
* in format 1
|
66 |
*
|
67 |
* @author Oscar Garcia
|
68 |
*/
|
69 |
public class LASPoint11F1 extends LASPoint11F0{ |
70 |
|
71 |
/**
|
72 |
* The GPS time is the double floating point time tag value at which
|
73 |
* the point was acquired.
|
74 |
*/
|
75 |
private double timeGPS; |
76 |
|
77 |
/**
|
78 |
* Default constructor, without arguments.
|
79 |
* Initializes all components to zero.
|
80 |
*/
|
81 |
public LASPoint11F1() {
|
82 |
super();
|
83 |
timeGPS = 0;
|
84 |
sizeFormat = 28;
|
85 |
} |
86 |
|
87 |
/**
|
88 |
* Get GPS time as double floating point time tag value at which
|
89 |
* the point was acquired.
|
90 |
*/
|
91 |
public double getTimeGPS() { |
92 |
return timeGPS;
|
93 |
} |
94 |
|
95 |
/**
|
96 |
* Set GPS time to double floating point time tag value at which
|
97 |
* the point was acquired.
|
98 |
*/
|
99 |
public void setTimeGPS(double tGPS) { |
100 |
timeGPS = tGPS; |
101 |
} |
102 |
|
103 |
/**
|
104 |
* Read a point of LAS file
|
105 |
*
|
106 |
* @param input input buffer to read
|
107 |
* @param Offset Offset to data
|
108 |
* @param index index of points to read
|
109 |
* @return true if success else return false
|
110 |
*/
|
111 |
public void readPoint(BigByteBuffer2 input, LidarHeader hdr, long index) { |
112 |
|
113 |
try{
|
114 |
if(index>hdr.getNumPointsRecord() || index < 0) { |
115 |
throw new UnexpectedPointException("Out of index"); |
116 |
} |
117 |
|
118 |
byte[] punto = new byte[getSizeFormat()]; |
119 |
|
120 |
input.position(hdr.getOffsetData()+getSizeFormat()*index); |
121 |
input.get(punto); |
122 |
|
123 |
setX(ByteUtilities.arr2Int(punto, 0));
|
124 |
setY(ByteUtilities.arr2Int(punto, 4));
|
125 |
setZ(ByteUtilities.arr2Int(punto, 8));
|
126 |
setIntensity(ByteUtilities.arr2Unsignedshort(punto, 12));
|
127 |
|
128 |
setReturnNumber((byte)(punto[14] & 0x07)); // 3 primeros bits del byte 14 |
129 |
setNumberOfReturn((byte)((punto[14] & 0x38) >> 3)); // 3 siguintes bits |
130 |
setScanDirectionFlag((byte)((punto[14] & 0x40) >> 6)); // 1 bit |
131 |
setEdgeOfFlightLine((byte)((punto[14] & 0x80) >> 7)); // 1 bit |
132 |
|
133 |
setClassification((char)(punto[15] & 0X1F)); // 5 bits del byte 15 |
134 |
setSynthetic((byte)((punto[15] & 0X20) >> 5 )); // 1 bit |
135 |
setKeyPoint((byte)((punto[15] & 0X40) >> 6 )); // 1 bit |
136 |
setWithheld((byte)((punto[15] & 0X80) >> 7 )); // 1 bit |
137 |
|
138 |
setScanAngleRank(punto[16]);
|
139 |
setUserData((char)(punto[17] & 0XFF)); |
140 |
setPointSourceID(ByteUtilities.arr2Unsignedshort(punto, 18));
|
141 |
setTimeGPS(ByteUtilities.arr2Double(punto, 20));
|
142 |
|
143 |
} catch (UnexpectedPointException e) {
|
144 |
// TODO Auto-generated catch block
|
145 |
e.printStackTrace(); |
146 |
} |
147 |
} |
148 |
|
149 |
/**
|
150 |
* get by field the Value:
|
151 |
*
|
152 |
* 0 return X
|
153 |
* 1 return Y
|
154 |
* 2 return Z
|
155 |
* 3 return intensity
|
156 |
* 4 return returnNumber
|
157 |
* 5 return numberOfReturn
|
158 |
* 6 return scanDirectionFlag
|
159 |
* 7 return edgeOfFlightLine
|
160 |
* 8 return classification
|
161 |
* 9 return synthetic
|
162 |
* 10 return keyPoint
|
163 |
* 11 return withheld
|
164 |
* 12 return scanAngleRank
|
165 |
* 13 return userData
|
166 |
* 14 return pointSourceID
|
167 |
* 15 return Time GPS
|
168 |
*
|
169 |
* @param bb byte buffer of data
|
170 |
* @param indexField index of field
|
171 |
* @param hdr LiDAR header
|
172 |
* @param index asked point index. (row)
|
173 |
* @return Value of row and column indicated
|
174 |
*/
|
175 |
public Value getFieldValueByIndex(BigByteBuffer2 bb, int indexField, |
176 |
LidarHeader hdr, long index) {
|
177 |
|
178 |
readPoint(bb, hdr, index); |
179 |
|
180 |
switch(indexField) {
|
181 |
|
182 |
case 0: |
183 |
return ValueFactory.createValue(getX()*hdr.getXScale()+hdr.getXOffset());
|
184 |
|
185 |
case 1: |
186 |
return ValueFactory.createValue(getY()*hdr.getYScale()+hdr.getYOffset());
|
187 |
|
188 |
case 2: |
189 |
return ValueFactory.createValue(getZ()*hdr.getZScale()+hdr.getZOffset());
|
190 |
|
191 |
case 3: |
192 |
return ValueFactory.createValue(getIntensity());
|
193 |
|
194 |
case 4: |
195 |
return ValueFactory.createValue(getReturnNumber());
|
196 |
|
197 |
case 5: |
198 |
return ValueFactory.createValue(getNumberOfReturn());
|
199 |
|
200 |
case 6: |
201 |
return ValueFactory.createValue(getScanDirectionFlag());
|
202 |
|
203 |
case 7: |
204 |
return ValueFactory.createValue(getEdgeOfFlightLine());
|
205 |
|
206 |
case 8: |
207 |
return ValueFactory.createValue(getClassification());
|
208 |
|
209 |
case 9: |
210 |
return ValueFactory.createValue(getSynthetic());
|
211 |
|
212 |
case 10: |
213 |
return ValueFactory.createValue(getKeyPoint());
|
214 |
|
215 |
case 11: |
216 |
return ValueFactory.createValue(getWithheld());
|
217 |
|
218 |
case 12: |
219 |
return ValueFactory.createValue(getScanAngleRank());
|
220 |
|
221 |
case 13: |
222 |
return ValueFactory.createValue(getUserData());
|
223 |
|
224 |
case 14: |
225 |
return ValueFactory.createValue(getPointSourceID());
|
226 |
|
227 |
case 15: |
228 |
return ValueFactory.createValue(getTimeGPS());
|
229 |
} |
230 |
|
231 |
return null; |
232 |
} |
233 |
|
234 |
public Value getFieldValueByName(BigByteBuffer2 bb, String nameField, LidarHeader hdr, |
235 |
long index) {
|
236 |
|
237 |
readPoint(bb, hdr, index); |
238 |
|
239 |
if(nameField.equalsIgnoreCase("X")) |
240 |
return ValueFactory.createValue(getX()*hdr.getXScale()+hdr.getXOffset());
|
241 |
else if(nameField.equalsIgnoreCase("Y")) |
242 |
return ValueFactory.createValue(getY()*hdr.getYScale()+hdr.getYOffset());
|
243 |
else if(nameField.equalsIgnoreCase("Z")) |
244 |
return ValueFactory.createValue(getZ()*hdr.getZScale()+hdr.getZOffset());
|
245 |
else if(nameField.equalsIgnoreCase("Intensity")) |
246 |
return ValueFactory.createValue(getIntensity());
|
247 |
else if(nameField.equalsIgnoreCase("Return_Number")) |
248 |
return ValueFactory.createValue(getReturnNumber());
|
249 |
else if(nameField.equalsIgnoreCase("Number_of_Returns")) |
250 |
return ValueFactory.createValue(getNumberOfReturn());
|
251 |
else if(nameField.equalsIgnoreCase("Scan_Direction_Flag")) |
252 |
return ValueFactory.createValue(getScanDirectionFlag());
|
253 |
else if(nameField.equalsIgnoreCase("Edge_of_Flight_Line")) |
254 |
return ValueFactory.createValue(getEdgeOfFlightLine());
|
255 |
else if(nameField.equalsIgnoreCase("Classification")) |
256 |
return ValueFactory.createValue(getClassification());
|
257 |
else if(nameField.equalsIgnoreCase("Synthetic")) |
258 |
return ValueFactory.createValue(getSynthetic());
|
259 |
else if(nameField.equalsIgnoreCase("Key_Point")) |
260 |
return ValueFactory.createValue(getKeyPoint());
|
261 |
else if(nameField.equalsIgnoreCase("Withheld")) |
262 |
return ValueFactory.createValue(getWithheld());
|
263 |
else if(nameField.equalsIgnoreCase("Scan_Angle_Rank")) |
264 |
return ValueFactory.createValue(getScanAngleRank());
|
265 |
else if(nameField.equalsIgnoreCase("User_Data")) |
266 |
return ValueFactory.createValue(getUserData());
|
267 |
else if(nameField.equalsIgnoreCase("Point_Source_ID")) |
268 |
return ValueFactory.createValue(getPointSourceID());
|
269 |
else if(nameField.equalsIgnoreCase("GPS_Time")) |
270 |
return ValueFactory.createValue(getTimeGPS());
|
271 |
|
272 |
return null; |
273 |
} |
274 |
|
275 |
public FieldDescription[] getFieldDescription() { |
276 |
FieldDescription fieldDesc; |
277 |
FieldDescription[] fields;
|
278 |
|
279 |
fields = new FieldDescription[16]; |
280 |
|
281 |
fieldDesc = new FieldDescription();
|
282 |
fieldDesc.setFieldName("X");
|
283 |
fieldDesc.setFieldType(Types.DOUBLE);
|
284 |
fieldDesc.setFieldLength(20);
|
285 |
fieldDesc.setFieldDecimalCount(3);
|
286 |
fields[0] = fieldDesc;
|
287 |
|
288 |
fieldDesc = new FieldDescription();
|
289 |
fieldDesc.setFieldName("Y");
|
290 |
fieldDesc.setFieldType(Types.DOUBLE);
|
291 |
fieldDesc.setFieldLength(20);
|
292 |
fieldDesc.setFieldDecimalCount(3);
|
293 |
fields[1] = fieldDesc;
|
294 |
|
295 |
fieldDesc = new FieldDescription();
|
296 |
fieldDesc.setFieldName("Z");
|
297 |
fieldDesc.setFieldType(Types.DOUBLE);
|
298 |
fieldDesc.setFieldLength(20);
|
299 |
fieldDesc.setFieldDecimalCount(3);
|
300 |
fields[2] = fieldDesc;
|
301 |
|
302 |
fieldDesc = new FieldDescription();
|
303 |
fieldDesc.setFieldName("Intensity");
|
304 |
fieldDesc.setFieldType(Types.INTEGER);
|
305 |
fieldDesc.setFieldLength(5);
|
306 |
fieldDesc.setFieldDecimalCount(0);
|
307 |
fields[3] = fieldDesc;
|
308 |
|
309 |
fieldDesc = new FieldDescription();
|
310 |
fieldDesc.setFieldName("Return_Number");
|
311 |
fieldDesc.setFieldType(Types.INTEGER);
|
312 |
fieldDesc.setFieldLength(1);
|
313 |
fieldDesc.setFieldDecimalCount(0);
|
314 |
fields[4] = fieldDesc;
|
315 |
|
316 |
fieldDesc = new FieldDescription();
|
317 |
fieldDesc.setFieldName("Number_of_Returns");
|
318 |
fieldDesc.setFieldType(Types.INTEGER);
|
319 |
fieldDesc.setFieldLength(1);
|
320 |
fieldDesc.setFieldDecimalCount(0);
|
321 |
fields[5] = fieldDesc;
|
322 |
|
323 |
fieldDesc = new FieldDescription();
|
324 |
fieldDesc.setFieldName("Scan_Direction_Flag");
|
325 |
fieldDesc.setFieldType(Types.INTEGER);
|
326 |
fieldDesc.setFieldLength(1);
|
327 |
fieldDesc.setFieldDecimalCount(0);
|
328 |
fields[6] = fieldDesc;
|
329 |
|
330 |
fieldDesc = new FieldDescription();
|
331 |
fieldDesc.setFieldName("Edge_of_Flight_Line");
|
332 |
fieldDesc.setFieldType(Types.INTEGER);
|
333 |
fieldDesc.setFieldLength(1);
|
334 |
fieldDesc.setFieldDecimalCount(0);
|
335 |
fields[7] = fieldDesc;
|
336 |
|
337 |
fieldDesc = new FieldDescription();
|
338 |
fieldDesc.setFieldName("Classification");
|
339 |
fieldDesc.setFieldType(Types.INTEGER);
|
340 |
fieldDesc.setFieldLength(3);
|
341 |
fieldDesc.setFieldDecimalCount(0);
|
342 |
fields[8] = fieldDesc;
|
343 |
|
344 |
fieldDesc = new FieldDescription();
|
345 |
fieldDesc.setFieldName("Synthetic");
|
346 |
fieldDesc.setFieldType(Types.INTEGER);
|
347 |
fieldDesc.setFieldLength(1);
|
348 |
fieldDesc.setFieldDecimalCount(0);
|
349 |
fields[9] = fieldDesc;
|
350 |
|
351 |
fieldDesc = new FieldDescription();
|
352 |
fieldDesc.setFieldName("Key_Point");
|
353 |
fieldDesc.setFieldType(Types.INTEGER);
|
354 |
fieldDesc.setFieldLength(1);
|
355 |
fieldDesc.setFieldDecimalCount(0);
|
356 |
fields[10] = fieldDesc;
|
357 |
|
358 |
fieldDesc = new FieldDescription();
|
359 |
fieldDesc.setFieldName("Withheld");
|
360 |
fieldDesc.setFieldType(Types.INTEGER);
|
361 |
fieldDesc.setFieldLength(1);
|
362 |
fieldDesc.setFieldDecimalCount(0);
|
363 |
fields[11] = fieldDesc;
|
364 |
|
365 |
fieldDesc = new FieldDescription();
|
366 |
fieldDesc.setFieldName("Scan_Angle_Rank");
|
367 |
fieldDesc.setFieldType(Types.INTEGER);
|
368 |
fieldDesc.setFieldLength(3);
|
369 |
fieldDesc.setFieldDecimalCount(0);
|
370 |
fields[12] = fieldDesc;
|
371 |
|
372 |
fieldDesc = new FieldDescription();
|
373 |
fieldDesc.setFieldName("User_Data");
|
374 |
fieldDesc.setFieldType(Types.INTEGER);
|
375 |
fieldDesc.setFieldLength(3);
|
376 |
fieldDesc.setFieldDecimalCount(0);
|
377 |
fields[13] = fieldDesc;
|
378 |
|
379 |
fieldDesc = new FieldDescription();
|
380 |
fieldDesc.setFieldName("Point_Source_ID");
|
381 |
fieldDesc.setFieldType(Types.INTEGER);
|
382 |
fieldDesc.setFieldLength(10);
|
383 |
fieldDesc.setFieldDecimalCount(0);
|
384 |
fields[14] = fieldDesc;
|
385 |
|
386 |
fieldDesc = new FieldDescription();
|
387 |
fieldDesc.setFieldName("GPS_Time");
|
388 |
fieldDesc.setFieldType(Types.DOUBLE);
|
389 |
fieldDesc.setFieldLength(20);
|
390 |
fieldDesc.setFieldDecimalCount(5);
|
391 |
fields[15] = fieldDesc;
|
392 |
|
393 |
return fields;
|
394 |
} |
395 |
|
396 |
public void WritePoint(ByteBuffer bb) { |
397 |
|
398 |
byte auxByte;
|
399 |
byte[] punto = new byte[getSizeFormat()]; |
400 |
|
401 |
// X bytes 0-4
|
402 |
ByteUtilities.int2Arr(getX(), punto, 0);
|
403 |
|
404 |
// Y bytes 4-8
|
405 |
ByteUtilities.int2Arr(getY(), punto, 4);
|
406 |
|
407 |
// bytes 8-12
|
408 |
ByteUtilities.int2Arr(getZ(), punto, 8);
|
409 |
|
410 |
// bytes 12-14
|
411 |
ByteUtilities.unsignedShort2Arr(getIntensity(), punto, 12);
|
412 |
|
413 |
// byte 14
|
414 |
auxByte = getReturnNumber(); |
415 |
auxByte |= (byte)((getNumberOfReturn()) << 3); |
416 |
auxByte |= (byte)((getScanDirectionFlag()) << 6); |
417 |
auxByte |= (byte)((getEdgeOfFlightLine()) << 7); |
418 |
punto[14] = auxByte;
|
419 |
|
420 |
// byte 15
|
421 |
auxByte = (byte)(getClassification());
|
422 |
auxByte |= (byte)((getSynthetic()) << 5); |
423 |
auxByte |= (byte)((getKeyPoint()) << 6); |
424 |
auxByte |= (byte)((getWithheld()) << 7); |
425 |
punto[15] = auxByte;
|
426 |
|
427 |
// byte 16
|
428 |
punto[16] = (byte)((getScanAngleRank() & 0xFF)); |
429 |
|
430 |
// byte 17
|
431 |
punto[17] = (byte)((getUserData() & 0xFF)); |
432 |
|
433 |
// bytes 18-20
|
434 |
ByteUtilities.unsignedShort2Arr(getPointSourceID(), punto, 18);
|
435 |
|
436 |
// bytes 20-28
|
437 |
ByteUtilities.double2Arr(getTimeGPS(), punto, 18);
|
438 |
|
439 |
bb.put(punto); |
440 |
} |
441 |
|
442 |
/*
|
443 |
* Set Point from a row
|
444 |
* @see com.dielmo.gvsig.lidar.LidarPoint#setPoint(com.hardcode.gdbms.engine.values.Value[], com.dielmo.gvsig.lidar.LidarHeader)
|
445 |
*/
|
446 |
public void setPoint(Value[] row, LidarHeader hdr) { |
447 |
double auxX = ((DoubleValue)(row[0])).getValue(); |
448 |
double auxY = ((DoubleValue)(row[1])).getValue(); |
449 |
double auxZ = ((DoubleValue)(row[2])).getValue(); |
450 |
|
451 |
setX((int) ((auxX-hdr.getXOffset())/hdr.getXScale()));
|
452 |
setY((int) ((auxY-hdr.getYOffset())/hdr.getYScale()));
|
453 |
setZ((int) ((auxZ-hdr.getZOffset())/hdr.getZScale()));
|
454 |
|
455 |
setIntensity(((IntValue)(row[3])).getValue());
|
456 |
setReturnNumber(((IntValue)(row[4])).byteValue());
|
457 |
setNumberOfReturn(((IntValue)(row[5])).byteValue());
|
458 |
setScanDirectionFlag(((IntValue)(row[6])).byteValue());
|
459 |
setEdgeOfFlightLine(((IntValue)(row[7])).byteValue());
|
460 |
setClassification((char) (((IntValue)(row[8])).byteValue() & 0xFF)); |
461 |
|
462 |
setSynthetic((byte) (((IntValue)(row[9])).byteValue())); |
463 |
setKeyPoint((byte) (((IntValue)(row[10])).byteValue())); |
464 |
setWithheld((byte) (((IntValue)(row[11])).byteValue())); |
465 |
|
466 |
setScanAngleRank(((IntValue)(row[12])).byteValue());
|
467 |
setUserData((char) (((IntValue)(row[13])).byteValue() & 0xFF)); |
468 |
setPointSourceID(((IntValue)(row[14])).getValue());
|
469 |
|
470 |
setTimeGPS(((DoubleValue)(row[15])).getValue());
|
471 |
} |
472 |
} |