svn-gvsig-desktop / branches / v10 / libraries / libLidar / src / com / dielmo / lidar / LASVariableLengthRecord_1X.java @ 25423
History | View | Annotate | Download (7.86 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.io.InputStream; |
53 |
import java.nio.ByteBuffer; |
54 |
|
55 |
|
56 |
public abstract class LASVariableLengthRecord_1X { |
57 |
|
58 |
|
59 |
/**
|
60 |
* data after the variable length record.
|
61 |
*
|
62 |
* Make sure that maximum size is 65536 bytes
|
63 |
*/
|
64 |
protected byte[] data; |
65 |
|
66 |
/**
|
67 |
* The userID field is ASCII character data that identifies the
|
68 |
* user which created the variable length record.
|
69 |
*/
|
70 |
protected char[] userID = new char[16]; |
71 |
|
72 |
/**
|
73 |
* Record ID is dependent upon the User ID. There can be 0 to 65535
|
74 |
* record Ids for every UserID. The ASPRS standard will manage its own record Ids (User Ids owned by the
|
75 |
* specification), otherwise record Ids will be managed by the owner of the given User ID. So each
|
76 |
* User ID is allowed to assign 0 to 65535 record Ids as they wish. Publicizing the meaning of a
|
77 |
* given record ID will be left to the owner of the given User ID. Unknown User ID/Record ID
|
78 |
* combinations should be ignored.
|
79 |
*/
|
80 |
protected int recordID; |
81 |
|
82 |
/**
|
83 |
* The record length is the number of bytes for the record after the
|
84 |
* end of the standard part of the header.
|
85 |
*/
|
86 |
protected int RecordLengthAfterHeader; |
87 |
|
88 |
/**
|
89 |
* Optional null terminated text description of the data.
|
90 |
*/
|
91 |
protected char[] description = new char[32]; |
92 |
|
93 |
|
94 |
/**
|
95 |
* Default constructor, without arguments.
|
96 |
* Initializes all components to zero.
|
97 |
*/
|
98 |
public LASVariableLengthRecord_1X() {
|
99 |
int i;
|
100 |
|
101 |
for(i=0;i<16;i++) |
102 |
userID[i] = 0;
|
103 |
|
104 |
recordID = 0;
|
105 |
RecordLengthAfterHeader=0;
|
106 |
|
107 |
for(i=0;i<32;i++) |
108 |
description[i] = 0;
|
109 |
} |
110 |
|
111 |
|
112 |
/**
|
113 |
* Return the userID field as string that identifies the
|
114 |
* user which created the variable length record.
|
115 |
*
|
116 |
* @return user ID
|
117 |
*/
|
118 |
public String getUserID() { |
119 |
String s;
|
120 |
char[] G = new char[16]; |
121 |
int i;
|
122 |
for(i=0;i<16;i++) |
123 |
{ |
124 |
if(userID[i]!=0) |
125 |
G[i] = userID[i]; |
126 |
else
|
127 |
G[i] = ' ';
|
128 |
} |
129 |
|
130 |
s = new String(G); |
131 |
return s;
|
132 |
} |
133 |
|
134 |
/**
|
135 |
* set the userID field as string that identifies the
|
136 |
* user which created the variable length record.
|
137 |
*
|
138 |
* Only accept 16 characters
|
139 |
*
|
140 |
* @param u new userID
|
141 |
*/
|
142 |
public void setUserID(String u) { |
143 |
|
144 |
int i;
|
145 |
for(i=0;i<16 && i<u.length() ;i++){ |
146 |
|
147 |
userID[i] = u.charAt(i); |
148 |
} |
149 |
|
150 |
// put to zero.
|
151 |
while(i<16){ |
152 |
|
153 |
userID[i] = 0;
|
154 |
i++; |
155 |
} |
156 |
} |
157 |
|
158 |
/**
|
159 |
* Return record ID.
|
160 |
*
|
161 |
* Record ID is dependent upon the User ID. There can be 0 to 65535
|
162 |
* record Ids for every UserID. The ASPRS standard will manage its own
|
163 |
* record Ids (User Ids owned by the specification), otherwise record
|
164 |
* Ids will be managed by the owner of the given User ID. So each User
|
165 |
* ID is allowed to assign 0 to 65535 record Ids as they wish.
|
166 |
* Publicizing the meaning of a given record ID will be left to the
|
167 |
* owner of the given User ID. Unknown User ID/Record ID combinations
|
168 |
* should be ignored.
|
169 |
*
|
170 |
* @return record ID
|
171 |
*/
|
172 |
public int getRecordID() { |
173 |
return recordID;
|
174 |
} |
175 |
|
176 |
/**
|
177 |
* set record ID.
|
178 |
*
|
179 |
* Record ID is dependent upon the User ID. There can be 0 to 65535
|
180 |
* record Ids for every UserID. The ASPRS standard will manage its own
|
181 |
* record Ids (User Ids owned by the specification), otherwise record
|
182 |
* Ids will be managed by the owner of the given User ID. So each User
|
183 |
* ID is allowed to assign 0 to 65535 record Ids as they wish.
|
184 |
* Publicizing the meaning of a given record ID will be left to the
|
185 |
* owner of the given User ID. Unknown User ID/Record ID combinations
|
186 |
* should be ignored.
|
187 |
*
|
188 |
* @param r new record ID
|
189 |
*/
|
190 |
public void setRecordID( int r) { |
191 |
|
192 |
try{
|
193 |
if(r>=0 && r<=LidarHeader.UNSIGNED_SHORT_MAX) |
194 |
recordID=r; |
195 |
else
|
196 |
throw new OutOfRangeLidarException("Out of range of record ID (Variable Length Record)"); |
197 |
|
198 |
} catch(OutOfRangeLidarException e) {
|
199 |
|
200 |
e.printStackTrace(); |
201 |
} |
202 |
|
203 |
} |
204 |
|
205 |
/**
|
206 |
* Return record length after header. This is the number of bytes
|
207 |
* for the record after the end of the standard part of the header.
|
208 |
*
|
209 |
* @return record length after header
|
210 |
*/
|
211 |
public int getRecordLengthAfterHeader() { |
212 |
return RecordLengthAfterHeader;
|
213 |
} |
214 |
|
215 |
/**
|
216 |
* set record length after header. This is the number of bytes
|
217 |
* for the record after the end of the standard part of the header.
|
218 |
*
|
219 |
* @param r new record length after header
|
220 |
*/
|
221 |
public void setRecordLengthAfterHeader(int r) { |
222 |
|
223 |
try{
|
224 |
if(r>=0 && r<=LidarHeader.UNSIGNED_SHORT_MAX) |
225 |
RecordLengthAfterHeader = r; |
226 |
else
|
227 |
throw new OutOfRangeLidarException("Out of range of record length after header (Variable Length Record)"); |
228 |
|
229 |
} catch(OutOfRangeLidarException e) {
|
230 |
|
231 |
e.printStackTrace(); |
232 |
} |
233 |
} |
234 |
|
235 |
/**
|
236 |
* Return the text description of the data.
|
237 |
*
|
238 |
* @return description
|
239 |
*/
|
240 |
public String getDescription() { |
241 |
String s;
|
242 |
char[] D = new char[32]; |
243 |
int i;
|
244 |
for(i=0;i<32;i++) { |
245 |
if(description[i]!=0) |
246 |
D[i] = description[i]; |
247 |
else
|
248 |
D[i] = ' ';
|
249 |
} |
250 |
|
251 |
s = new String(D); |
252 |
return s;
|
253 |
} |
254 |
|
255 |
/**
|
256 |
* set the text description of the data.
|
257 |
* Only accept 32 characters
|
258 |
*
|
259 |
* @param d new description
|
260 |
*/
|
261 |
public void setDescription(String d) { |
262 |
int i;
|
263 |
for(i=0;i<32 && i<d.length();i++) { |
264 |
|
265 |
description[i] = d.charAt(i); |
266 |
} |
267 |
|
268 |
// put to zero.
|
269 |
while(i<32){ |
270 |
|
271 |
description[i] = 0;
|
272 |
i++; |
273 |
} |
274 |
} |
275 |
|
276 |
/**
|
277 |
* Read the collection of bytes of variable length record
|
278 |
*
|
279 |
* @param input input file to read
|
280 |
* @param VarLengthRecord buffer into which the data is read
|
281 |
* @return true if success else return false
|
282 |
*/
|
283 |
protected abstract boolean readVarLegthRecordData(InputStream input); |
284 |
|
285 |
/**
|
286 |
* Read the Variable length record header of LAS file
|
287 |
*
|
288 |
* @param input input file to read
|
289 |
* @return true if success else return false
|
290 |
*/
|
291 |
public abstract boolean readVarLegthRecord(InputStream input); |
292 |
|
293 |
/**
|
294 |
* Write the Variable length record header of LAS file
|
295 |
*
|
296 |
* @param bb byte buffer to write
|
297 |
* @return true if success else return false
|
298 |
*/
|
299 |
public abstract boolean writeVarLegthRecord(ByteBuffer bb); |
300 |
|
301 |
|
302 |
/**
|
303 |
* return data after the variable length record.
|
304 |
*
|
305 |
* maximum size is 65536 bytes
|
306 |
*
|
307 |
* @return data after variable length record.
|
308 |
*/
|
309 |
public byte[] getData() { |
310 |
return data;
|
311 |
} |
312 |
|
313 |
|
314 |
/**
|
315 |
* set data after the variable length record.
|
316 |
*
|
317 |
* Make sure that maximum size is 65536 bytes
|
318 |
*
|
319 |
* @return data after variable length record.
|
320 |
*/
|
321 |
public void setData(byte[] data) { |
322 |
this.data = data;
|
323 |
} |
324 |
} |