svn-gvsig-desktop / branches / v10 / libraries / libDielmoOpenLidar / src / com / dielmo / lidar / LASPoint12F3.java @ 26423
History | View | Annotate | Download (9.41 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 |
|
54 |
import com.dielmo.lidar.fieldsDescription.ColumnDescription; |
55 |
import com.dielmo.lidar.fieldsDescription.ContainerColumnDescription; |
56 |
|
57 |
|
58 |
/**
|
59 |
* LAS point that implement the LAS point data version LAS1.0
|
60 |
* in format 1
|
61 |
*
|
62 |
* @author Oscar Garcia
|
63 |
*/
|
64 |
public class LASPoint12F3 extends LASPoint11F1{ |
65 |
|
66 |
/**
|
67 |
* The Red image channel value associated with this point
|
68 |
*/
|
69 |
protected int red; |
70 |
|
71 |
/**
|
72 |
* The green image channel value associated with this point
|
73 |
*/
|
74 |
protected int green; |
75 |
|
76 |
/**
|
77 |
* The blue image channel value associated with this point
|
78 |
*/
|
79 |
protected int blue; |
80 |
|
81 |
/**
|
82 |
* Default constructor, without arguments.
|
83 |
* Initializes all components to zero.
|
84 |
*/
|
85 |
public LASPoint12F3() {
|
86 |
super();
|
87 |
sizeFormat = 34;
|
88 |
red = 0;
|
89 |
green = 0;
|
90 |
blue = 0;
|
91 |
lasIndex=-1;
|
92 |
} |
93 |
|
94 |
// GET METHOD
|
95 |
/**
|
96 |
* The red image channel value associated with this point
|
97 |
*
|
98 |
* @return red color value
|
99 |
*/
|
100 |
public int getRed() { |
101 |
return red;
|
102 |
} |
103 |
|
104 |
/**
|
105 |
* The green image channel value associated with this point
|
106 |
*
|
107 |
* @return green color value
|
108 |
*/
|
109 |
public int getGreen() { |
110 |
return green;
|
111 |
} |
112 |
|
113 |
/**
|
114 |
* The red image channel value associated with this point
|
115 |
*
|
116 |
* @return blue color value
|
117 |
*/
|
118 |
public int getBlue() { |
119 |
return blue;
|
120 |
} |
121 |
|
122 |
// SET METHOD
|
123 |
/**
|
124 |
* Set the Red image channel value associated with this point
|
125 |
*
|
126 |
* @param r new red value
|
127 |
*/
|
128 |
public void setRed(int r) { |
129 |
|
130 |
try{
|
131 |
if(r >=0 && r <= UNSIGNED_SHORT_MAX) |
132 |
red = r; |
133 |
else
|
134 |
throw new OutOfRangeLidarException("Out of range of red value"); |
135 |
|
136 |
} catch(OutOfRangeLidarException e) {
|
137 |
|
138 |
e.printStackTrace(); |
139 |
} |
140 |
} |
141 |
|
142 |
/**
|
143 |
* Set the Red image channel value associated with this point
|
144 |
*
|
145 |
* @param g new green value
|
146 |
*/
|
147 |
public void setGreen(int g) { |
148 |
|
149 |
try{
|
150 |
if(g >=0 && g <= UNSIGNED_SHORT_MAX) |
151 |
green = g; |
152 |
else
|
153 |
throw new OutOfRangeLidarException("Out of range of green value"); |
154 |
|
155 |
} catch(OutOfRangeLidarException e) {
|
156 |
|
157 |
e.printStackTrace(); |
158 |
} |
159 |
} |
160 |
|
161 |
/**
|
162 |
* Set the Blue image channel value associated with this point
|
163 |
*
|
164 |
* @param b new green value
|
165 |
*/
|
166 |
public void setBlue(int b) { |
167 |
|
168 |
try{
|
169 |
if(b >=0 && b <= UNSIGNED_SHORT_MAX) |
170 |
blue = b; |
171 |
else
|
172 |
throw new OutOfRangeLidarException("Out of range of blue value"); |
173 |
|
174 |
} catch(OutOfRangeLidarException e) {
|
175 |
|
176 |
e.printStackTrace(); |
177 |
} |
178 |
} |
179 |
|
180 |
/**
|
181 |
* Read a point of LAS file
|
182 |
*
|
183 |
* @param input input buffer to read
|
184 |
* @param Offset Offset to data
|
185 |
* @param index index of points to read
|
186 |
* @return true if success else return false
|
187 |
*/
|
188 |
public void readPoint(BigByteBuffer2 input, LidarHeader hdr, long index) { |
189 |
|
190 |
try{
|
191 |
if(index>hdr.getNumPointsRecord() || index < 0) { |
192 |
throw new UnexpectedPointException("Out of index"); |
193 |
} |
194 |
|
195 |
if(index==lasIndex)
|
196 |
return;
|
197 |
else
|
198 |
lasIndex=index; |
199 |
|
200 |
byte[] punto = new byte[getSizeFormat()]; |
201 |
|
202 |
input.position(hdr.getOffsetData()+getSizeFormat()*index); |
203 |
input.get(punto); |
204 |
|
205 |
setX(ByteUtilities.arr2Int(punto, 0));
|
206 |
setY(ByteUtilities.arr2Int(punto, 4));
|
207 |
setZ(ByteUtilities.arr2Int(punto, 8));
|
208 |
setIntensity(ByteUtilities.arr2Unsignedshort(punto, 12));
|
209 |
|
210 |
setReturnNumber((byte)(punto[14] & 0x07)); // 3 primeros bits del byte 14 |
211 |
setNumberOfReturn((byte)((punto[14] & 0x38) >> 3)); // 3 siguintes bits |
212 |
setScanDirectionFlag((byte)((punto[14] & 0x40) >> 6)); // 1 bit |
213 |
setEdgeOfFlightLine((byte)((punto[14] & 0x80) >> 7)); // 1 bit |
214 |
|
215 |
setClassification((char)(punto[15] & 0X1F)); // 5 bits del byte 15 |
216 |
setSynthetic((byte)((punto[15] & 0X20) >> 5 )); // 1 bit |
217 |
setKeyPoint((byte)((punto[15] & 0X40) >> 6 )); // 1 bit |
218 |
setWithheld((byte)((punto[15] & 0X80) >> 7 )); // 1 bit |
219 |
|
220 |
setScanAngleRank(punto[16]);
|
221 |
setUserData((char)(punto[17] & 0XFF)); |
222 |
setPointSourceID(ByteUtilities.arr2Unsignedshort(punto, 18));
|
223 |
setTimeGPS(ByteUtilities.arr2Double(punto, 20));
|
224 |
|
225 |
setRed(ByteUtilities.arr2Unsignedshort(punto, 28));
|
226 |
setGreen(ByteUtilities.arr2Unsignedshort(punto, 30));
|
227 |
setBlue(ByteUtilities.arr2Unsignedshort(punto, 32));
|
228 |
|
229 |
} catch (UnexpectedPointException e) {
|
230 |
// TODO Auto-generated catch block
|
231 |
e.printStackTrace(); |
232 |
} |
233 |
} |
234 |
|
235 |
/**
|
236 |
* get by field the Value:
|
237 |
*
|
238 |
* 0 return X
|
239 |
* 1 return Y
|
240 |
* 2 return Z
|
241 |
* 3 return intensity
|
242 |
* 4 return returnNumber
|
243 |
* 5 return numberOfReturn
|
244 |
* 6 return scanDirectionFlag
|
245 |
* 7 return edgeOfFlightLine
|
246 |
* 8 return classification
|
247 |
* 9 return synthetic
|
248 |
* 10 return keyPoint
|
249 |
* 11 return withheld
|
250 |
* 12 return scanAngleRank
|
251 |
* 13 return userData
|
252 |
* 14 return pointSourceID
|
253 |
* 15 return Time GPS
|
254 |
* 16 return R
|
255 |
* 17 return G
|
256 |
* 18 return B
|
257 |
*
|
258 |
* @param bb byte buffer of data
|
259 |
* @param indexField index of field
|
260 |
* @param hdr LiDAR header
|
261 |
* @param index asked point index. (row)
|
262 |
* @return Object of row and column indicated
|
263 |
*/
|
264 |
public Object getFieldValueByIndex(BigByteBuffer2 bb, int indexField, |
265 |
LidarHeader hdr, long index) {
|
266 |
|
267 |
if (indexField >= 15) { |
268 |
readPoint(bb, hdr, index); |
269 |
if(indexField == 15) |
270 |
return getTimeGPS();
|
271 |
if(indexField == 16) |
272 |
return getRed();
|
273 |
else if(indexField == 17) |
274 |
return getGreen();
|
275 |
else if(indexField == 18) |
276 |
return getBlue();
|
277 |
} |
278 |
return super.getFieldValueByIndex(bb, indexField, hdr, index); |
279 |
} |
280 |
|
281 |
|
282 |
public Object getFieldValueByName(BigByteBuffer2 bb, String nameField, LidarHeader hdr, |
283 |
long index) {
|
284 |
|
285 |
if(nameField.equalsIgnoreCase("GPS_Time")){ |
286 |
readPoint(bb, hdr, index); |
287 |
return getTimeGPS();
|
288 |
} else if (nameField.equalsIgnoreCase("R")) { |
289 |
readPoint(bb, hdr, index); |
290 |
return getRed();
|
291 |
} else if (nameField.equalsIgnoreCase("G")) { |
292 |
readPoint(bb, hdr, index); |
293 |
return getGreen();
|
294 |
} else if (nameField.equalsIgnoreCase("B")) { |
295 |
readPoint(bb, hdr, index); |
296 |
return getBlue();
|
297 |
} |
298 |
return super.getFieldValueByName(bb, nameField, hdr, index); |
299 |
} |
300 |
|
301 |
public ContainerColumnDescription getColumnsDescription(ContainerColumnDescription fields) {
|
302 |
|
303 |
super.getColumnsDescription(fields);
|
304 |
fields.add("GPS_Time", ColumnDescription.DOUBLE, 20, 5, 0.0); |
305 |
fields.add("R", ColumnDescription.INT, 10, 0, 0); |
306 |
fields.add("G", ColumnDescription.INT, 10, 0, 0); |
307 |
fields.add("B", ColumnDescription.INT, 10, 0, 0); |
308 |
|
309 |
return fields;
|
310 |
} |
311 |
|
312 |
public void WritePoint(ByteBuffer bb) { |
313 |
|
314 |
byte auxByte;
|
315 |
byte[] punto = new byte[getSizeFormat()]; |
316 |
|
317 |
// X bytes 0-4
|
318 |
ByteUtilities.int2Arr(getX(), punto, 0);
|
319 |
|
320 |
// Y bytes 4-8
|
321 |
ByteUtilities.int2Arr(getY(), punto, 4);
|
322 |
|
323 |
// bytes 8-12
|
324 |
ByteUtilities.int2Arr(getZ(), punto, 8);
|
325 |
|
326 |
// bytes 12-14
|
327 |
ByteUtilities.unsignedShort2Arr(getIntensity(), punto, 12);
|
328 |
|
329 |
// byte 14
|
330 |
auxByte = getReturnNumber(); |
331 |
auxByte |= (byte)((getNumberOfReturn()) << 3); |
332 |
auxByte |= (byte)((getScanDirectionFlag()) << 6); |
333 |
auxByte |= (byte)((getEdgeOfFlightLine()) << 7); |
334 |
punto[14] = auxByte;
|
335 |
|
336 |
// byte 15
|
337 |
auxByte = (byte)(getClassification());
|
338 |
auxByte |= (byte)((getSynthetic()) << 5); |
339 |
auxByte |= (byte)((getKeyPoint()) << 6); |
340 |
auxByte |= (byte)((getWithheld()) << 7); |
341 |
punto[15] = auxByte;
|
342 |
|
343 |
// byte 16
|
344 |
punto[16] = (byte)((getScanAngleRank() & 0xFF)); |
345 |
|
346 |
// byte 17
|
347 |
punto[17] = (byte)((getUserData() & 0xFF)); |
348 |
|
349 |
// bytes 18-20
|
350 |
ByteUtilities.unsignedShort2Arr(getPointSourceID(), punto, 18);
|
351 |
|
352 |
// bytes 20-28
|
353 |
ByteUtilities.double2Arr(getTimeGPS(), punto, 18);
|
354 |
|
355 |
// bytes 28-30
|
356 |
ByteUtilities.unsignedShort2Arr(getRed(), punto, 28);
|
357 |
|
358 |
// bytes 30-32
|
359 |
ByteUtilities.unsignedShort2Arr(getRed(), punto, 30);
|
360 |
|
361 |
// bytes 32-34
|
362 |
ByteUtilities.unsignedShort2Arr(getRed(), punto, 32);
|
363 |
|
364 |
bb.put(punto); |
365 |
} |
366 |
|
367 |
/*
|
368 |
* Set Point from a row
|
369 |
*/
|
370 |
public void setPoint(Object[] row, LidarHeader hdr) { |
371 |
|
372 |
super.setPoint(row, hdr);
|
373 |
|
374 |
setTimeGPS(((Double)(row[15]))); |
375 |
setRed(((Integer)(row[16]))); |
376 |
setGreen(((Integer)(row[17]))); |
377 |
setBlue(((Integer)(row[18]))); |
378 |
} |
379 |
} |