Skip to content

Commit 9bc0252

Browse files
committed
fixed laz support and las/laz header update
1 parent a7218df commit 9bc0252

8 files changed

+56
-27
lines changed

PotreeConverter/include/LASPointReader.h

+13
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,19 @@ class LIBLASReader{
4343
stream.close();
4444
}
4545

46+
AABB getAABB(){
47+
AABB aabb;
48+
49+
const liblas::Header &header = reader.GetHeader();
50+
51+
Vector3<double> min = Vector3<double>(header.GetMinX(), header.GetMinY(), header.GetMinZ());
52+
Vector3<double> max = Vector3<double>(header.GetMaxX(), header.GetMaxY(), header.GetMaxZ());
53+
aabb.update(min);
54+
aabb.update(max);
55+
56+
return aabb;
57+
}
58+
4659
};
4760

4861

PotreeConverter/include/LASPointWriter.hpp

+19-6
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,15 @@
77
#include <fstream>
88

99
#include "liblas\liblas.hpp"
10+
#include <boost/algorithm/string/predicate.hpp>
1011

1112
#include "AABB.h"
1213
#include "PointWriter.hpp"
1314

1415
using std::string;
1516
using std::fstream;
1617
using std::ios;
18+
using boost::algorithm::iends_with;
1719

1820
class LASPointWriter : public PointWriter{
1921

@@ -35,9 +37,14 @@ class LASPointWriter : public PointWriter{
3537
header->SetMin(aabb.min.x, aabb.min.y, aabb.min.z);
3638
header->SetMax(aabb.max.x, aabb.max.y, aabb.max.z);
3739
header->SetScale(0.01, 0.01, 0.01);
40+
header->SetPointRecordsCount(53);
41+
42+
if(iends_with(file, ".laz")){
43+
header->SetCompressed(true);
44+
}
3845

3946
stream = new fstream(file, ios::out | ios::binary);
40-
writer = new liblas::Writer(*stream, *header);
47+
writer = new liblas::Writer(*stream, *header);
4148

4249

4350
//LASheader header;
@@ -63,16 +70,22 @@ class LASPointWriter : public PointWriter{
6370
void write(const Point &point);
6471

6572
void close(){
66-
header->SetPointRecordsCount(numPoints);
67-
68-
writer->SetHeader(*header);
69-
writer->WriteHeader();
7073

71-
stream->close();
74+
// close stream
7275
delete writer;
76+
stream->close();
7377
delete stream;
7478
writer = NULL;
7579
stream = NULL;
80+
81+
// update point count
82+
stream = new fstream(file, ios::out | ios::binary | ios::in );
83+
stream->seekp(107);
84+
stream->write(reinterpret_cast<const char*>(&numPoints), 4);
85+
stream->close();
86+
delete stream;
87+
stream = NULL;
88+
7689
}
7790

7891
};

PotreeConverter/src/LASPointReader.cpp

+7-11
Original file line numberDiff line numberDiff line change
@@ -44,17 +44,13 @@ LASPointReader::LASPointReader(string path){
4444
for(int i = 0; i < files.size(); i++){
4545
string file = files[i];
4646

47-
reader = new LIBLASReader(file);
47+
LIBLASReader aabbReader(file);
48+
AABB lAABB = aabbReader.getAABB();
49+
50+
aabb.update(lAABB.min);
51+
aabb.update(lAABB.max);
4852

49-
liblas::Header header = reader->reader.GetHeader();
50-
51-
Vector3<double> min = Vector3<double>(header.GetMinX(), header.GetMinY(), header.GetMinZ());
52-
Vector3<double> max = Vector3<double>(header.GetMaxX(), header.GetMaxY(), header.GetMaxZ());
53-
aabb.update(min);
54-
aabb.update(max);
55-
56-
reader->close();
57-
delete reader;
53+
aabbReader.close();
5854
}
5955

6056
// open first file
@@ -99,7 +95,7 @@ bool LASPointReader::readNextPoint(){
9995
}
10096

10197
Point LASPointReader::getPoint(){
102-
liblas::Point lp = reader->reader.GetPoint();
98+
const liblas::Point &lp = reader->reader.GetPoint();
10399
Point p(lp.GetX(), lp.GetY(), lp.GetZ());
104100

105101
p.intensity = lp.GetIntensity();

PotreeConverter/src/LASPointWriter.cpp

+6-6
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ using std::vector;
88

99
void LASPointWriter::write(const Point &point){
1010
liblas::Point lp;
11+
lp.SetHeader(header);
1112

12-
lp.SetX(point.x / header->GetScaleX());
13-
lp.SetY(point.y / header->GetScaleY());
14-
lp.SetZ(point.z / header->GetScaleZ());
13+
lp.SetX(point.x);
14+
lp.SetY(point.y);
15+
lp.SetZ(point.z);
1516

16-
1717
vector<uint8_t> &data = lp.GetData();
1818

1919
unsigned short pr = point.r * 256;
@@ -25,10 +25,10 @@ void LASPointWriter::write(const Point &point){
2525
{ // TODO lp.SetColor did not work, do this instead. check for bugs?
2626
data[20] = reinterpret_cast<unsigned char*>(&pr)[0];
2727
data[21] = reinterpret_cast<unsigned char*>(&pr)[1];
28-
28+
2929
data[22] = reinterpret_cast<unsigned char*>(&pg)[0];
3030
data[23] = reinterpret_cast<unsigned char*>(&pg)[1];
31-
31+
3232
data[24] = reinterpret_cast<unsigned char*>(&pb)[0];
3333
data[25] = reinterpret_cast<unsigned char*>(&pb)[1];
3434
}

PotreeConverter/src/PotreeConverter.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ void PotreeConverter::convert(){
162162
auto end = high_resolution_clock::now();
163163
long duration = duration_cast<milliseconds>(end-start).count();
164164
cout << "duration: " << (duration / 1000.0f) << "s" << endl;
165-
165+
//return;
166166
}
167167
}
168168
writer.flush();

build/PotreeConverter/PotreeConverter.vcxproj

+2-2
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@
141141
</PropertyGroup>
142142
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
143143
<ClCompile>
144-
<AdditionalIncludeDirectories>$(SolutionDir)/../PotreeConverter/include;C:/dev/lib/boost_1_55_0;$(LASLIB_INCLUDE_DIR);$(LASZIP_INCLUDE_DIR);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
144+
<AdditionalIncludeDirectories>$(SolutionDir)/../PotreeConverter/include;C:/dev/lib/boost_1_55_0;C:\dev\lib\liblas\libLAS-1.7.0\include;$(LASZIP_INCLUDE_DIR);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
145145
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
146146
<CompileAs>CompileAsCpp</CompileAs>
147147
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
@@ -171,7 +171,7 @@
171171
</Midl>
172172
<Link>
173173
<AdditionalOptions> /machine:x64 /debug %(AdditionalOptions)</AdditionalOptions>
174-
<AdditionalDependencies>kernel32.lib;user32.lib;gdi32.lib;winspool.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;comdlg32.lib;advapi32.lib;C:\Boost\lib\libboost_system-vc110-mt-gd-1_55.lib;C:\Boost\lib\libboost_thread-vc110-mt-gd-1_55.lib;C:\Boost\lib\libboost_filesystem-vc110-mt-gd-1_55.lib;C:\Boost\lib\libboost_program_options-vc110-mt-gd-1_55.lib;C:\dev\lib\lastools\x64\DebugDLL\laslib.lib</AdditionalDependencies>
174+
<AdditionalDependencies>kernel32.lib;user32.lib;gdi32.lib;winspool.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;comdlg32.lib;advapi32.lib;C:\Boost\lib\libboost_system-vc110-mt-gd-1_55.lib;C:\Boost\lib\libboost_thread-vc110-mt-gd-1_55.lib;C:\Boost\lib\libboost_filesystem-vc110-mt-gd-1_55.lib;C:\Boost\lib\libboost_program_options-vc110-mt-gd-1_55.lib;$(LASLIB_LIBRARY_DIR)\laslib.lib;C:\dev\lib\liblas\libLAS-1.7.0\build\bin\Debug\liblas.lib</AdditionalDependencies>
175175
<AdditionalLibraryDirectories>%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
176176
<GenerateDebugInformation>true</GenerateDebugInformation>
177177
<ImportLibrary>C:/dev/workspaces/PotreeConverter/PotreeConverter_develop/build/PotreeConverter/Debug/PotreeConverter.lib</ImportLibrary>

build/PotreeConverter/PotreeConverter.vcxproj.user

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
33
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
4-
<LocalDebuggerCommandArguments>C:\dev\pointclouds\mschuetz\lion_takanawa.las -s 0.5 -l 1</LocalDebuggerCommandArguments>
4+
<LocalDebuggerCommandArguments>C:\dev\pointclouds\mschuetz\lion_takanawa.las -s 0.3 -l 3 --output-format LAZ</LocalDebuggerCommandArguments>
55
<LocalDebuggerWorkingDirectory>$(TargetDir)</LocalDebuggerWorkingDirectory>
66
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
77
</PropertyGroup>

testcases.txt

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
.\PotreeConverter.exe C:\dev\pointclouds\mschuetz\lion_takanawa.las -o C:\dev\pointclouds\test\lion\las_bin -s 0.15 -l 3 --output-format BINARY
2+
.\PotreeConverter.exe C:\dev\pointclouds\mschuetz\lion_takanawa.las -o C:\dev\pointclouds\test\lion\las_las -s 0.15 -l 3 --output-format LAS
3+
.\PotreeConverter.exe C:\dev\pointclouds\mschuetz\lion_takanawa.las -o C:\dev\pointclouds\test\lion\las_laz -s 0.15 -l 3 --output-format LAZ
4+
5+
.\PotreeConverter.exe C:\dev\pointclouds\mschuetz\lion_takanawa.ply -o C:\dev\pointclouds\test\lion\ply_bin -s 0.15 -l 3 --output-format BINARY
6+
.\PotreeConverter.exe C:\dev\pointclouds\mschuetz\lion_takanawa.ply -o C:\dev\pointclouds\test\lion\ply_las -s 0.15 -l 3 --output-format LAS
7+
.\PotreeConverter.exe C:\dev\pointclouds\mschuetz\lion_takanawa.ply -o C:\dev\pointclouds\test\lion\ply_laz -s 0.15 -l 3 --output-format LAZ

0 commit comments

Comments
 (0)