svn-gvsig-desktop / branches / v10 / libraries / libLidar / src / com / dielmo / lidar / LASVariableLengthRecord_V10.java @ 25423
History | View | Annotate | Download (5.38 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.*; |
53 |
import java.nio.ByteBuffer; |
54 |
|
55 |
import javax.swing.JOptionPane; |
56 |
|
57 |
|
58 |
public class LASVariableLengthRecord_V10 extends LASVariableLengthRecord_1X { |
59 |
|
60 |
/**
|
61 |
* file Signature, must contain AABB (43707 in decimal) in version LAS1.0, while in version LAS1.1
|
62 |
* it is a reserved field.
|
63 |
*/
|
64 |
private int recordSignature; |
65 |
|
66 |
/**
|
67 |
* Default constructor, without arguments.
|
68 |
* Initializes all components to zero.
|
69 |
*/
|
70 |
public LASVariableLengthRecord_V10() {
|
71 |
super();
|
72 |
recordSignature = 43707; // 43707 decimal = AABB hexadecimal |
73 |
} |
74 |
|
75 |
/**
|
76 |
* Return record signature. This must be always "AABB" (43707 in decimal) in version LAS1.0
|
77 |
*
|
78 |
* @return record signature
|
79 |
*/
|
80 |
public int getRecordSignature() { |
81 |
return recordSignature;
|
82 |
} |
83 |
|
84 |
/**
|
85 |
* set record signature. This must be always "AABB" in version LAS1.0 (43707 in decimal)
|
86 |
*
|
87 |
* @param r new record signature
|
88 |
*/
|
89 |
public void setRecordSignature() { |
90 |
recordSignature = 43707;
|
91 |
} |
92 |
|
93 |
/**
|
94 |
* Read the variable length record data
|
95 |
*
|
96 |
* @param input input file to read
|
97 |
* @param VarLengthRecord buffer into which the data is read
|
98 |
* @return true if success else return false
|
99 |
*/
|
100 |
protected boolean readVarLegthRecordData(InputStream input) { |
101 |
if(RecordLengthAfterHeader <= 0) { |
102 |
return false; |
103 |
} |
104 |
|
105 |
try {
|
106 |
|
107 |
data = new byte[RecordLengthAfterHeader]; |
108 |
int offset=0,numRead=0; |
109 |
|
110 |
while (offset < RecordLengthAfterHeader && (numRead = input.read(data, offset, RecordLengthAfterHeader-offset) ) >= 0) { |
111 |
offset += numRead; |
112 |
} |
113 |
|
114 |
if (offset < RecordLengthAfterHeader) {
|
115 |
JOptionPane.showMessageDialog(null, "Bad input format"); |
116 |
return false; |
117 |
} |
118 |
|
119 |
} catch(IOException e) { |
120 |
e.printStackTrace(); |
121 |
return false; |
122 |
} |
123 |
|
124 |
return true; |
125 |
} |
126 |
|
127 |
/**
|
128 |
* Read the Variable length record header of LAS file
|
129 |
*
|
130 |
* @param input input file to read
|
131 |
* @return true if success else return false
|
132 |
*/
|
133 |
public boolean readVarLegthRecord(InputStream input) { |
134 |
|
135 |
int offset=0,numRead=0, j; |
136 |
byte[] VarLengthRecord = new byte[54]; |
137 |
|
138 |
//read VarLenhRecord
|
139 |
try {
|
140 |
|
141 |
while (offset < 54 && (numRead = input.read(VarLengthRecord, offset, VarLengthRecord.length-offset) ) >= 0) { |
142 |
offset += numRead; |
143 |
} |
144 |
|
145 |
if (offset < VarLengthRecord.length) {
|
146 |
JOptionPane.showMessageDialog(null, "Bad input format"); |
147 |
return false; |
148 |
} |
149 |
|
150 |
|
151 |
recordSignature = ByteUtilities.arr2Unsignedshort(VarLengthRecord, 0);
|
152 |
|
153 |
if(recordSignature != 43707) { |
154 |
return false; |
155 |
} |
156 |
|
157 |
|
158 |
for(j=0;j<16;j++) |
159 |
userID[j] = (char)(VarLengthRecord[j+2] & 0xFF); |
160 |
|
161 |
recordID = ByteUtilities.arr2Unsignedshort(VarLengthRecord, 18);
|
162 |
RecordLengthAfterHeader = ByteUtilities.arr2Unsignedshort(VarLengthRecord, 20);
|
163 |
|
164 |
for(j=0;j<32;j++) |
165 |
description[j] = (char)(VarLengthRecord[j+22] & 0xFF); |
166 |
|
167 |
readVarLegthRecordData(input); |
168 |
|
169 |
} catch (IOException e) { |
170 |
// TODO Auto-generated catch block
|
171 |
e.printStackTrace(); |
172 |
return false; |
173 |
} |
174 |
|
175 |
return true; |
176 |
} |
177 |
|
178 |
public boolean writeVarLegthRecord(ByteBuffer bb) { |
179 |
int i;
|
180 |
int index=0; |
181 |
byte[] VL_Buffer = new byte[54]; |
182 |
|
183 |
if(recordSignature != 43707) { |
184 |
return false; |
185 |
} |
186 |
|
187 |
// recordSignature bytes 0-2
|
188 |
ByteUtilities.unsignedShort2Arr(getRecordSignature(), VL_Buffer, 0);
|
189 |
|
190 |
// userID bytes 2-18
|
191 |
i = 0;
|
192 |
for(index=2;index<18;index++) { |
193 |
VL_Buffer[index] = ((byte)(userID[i] & 0XFF)); |
194 |
i++; |
195 |
} |
196 |
|
197 |
// recordID bytes 18-20
|
198 |
ByteUtilities.unsignedShort2Arr(getRecordID(), VL_Buffer, 18);
|
199 |
|
200 |
// RecordLengthAfterHeader bytes 20-22
|
201 |
ByteUtilities.unsignedShort2Arr(getRecordLengthAfterHeader(), VL_Buffer, 20);
|
202 |
|
203 |
// description bytes 22-54
|
204 |
i = 0;
|
205 |
for(index=22;index<54;index++) { |
206 |
VL_Buffer[index] = ((byte)(description[i] & 0XFF)); |
207 |
i++; |
208 |
} |
209 |
|
210 |
// write header VLR
|
211 |
bb.put(VL_Buffer); |
212 |
// write data VLR
|
213 |
bb.put(getData()); |
214 |
|
215 |
return true; |
216 |
} |
217 |
} |