-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwolkencli.cpp
129 lines (128 loc) · 4.2 KB
/
wolkencli.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
/******************************************************/
/* */
/* wolkencli.cpp - main program for command-line */
/* */
/******************************************************/
/* Copyright 2019,2020 Pierre Abbat.
* This file is part of Wolkenbase.
*
* Wolkenbase is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Wolkenbase is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Wolkenbase. If not, see <http://www.gnu.org/licenses/>.
*/
/* This program cleans a point cloud as follows:
* 1. Read in the point cloud, storing it in a temporary file in blocks
* of RECORDS points and building an octree index.
* 2. Scan the point cloud's xy projection in Hilbert curve point sequences:
* 1 point, 4 points, 16 points, etc., looking at cylinders with radius
* 0.5 meter.
* 3. Find the lowest point near the axis of the cylinder and examine a sphere
* of radius 0.5 meter.
*/
#include <cmath>
#include <boost/program_options.hpp>
#include "las.h"
#include "threads.h"
#include "relprime.h"
#include "ldecimal.h"
#include "brevno.h"
#include "octree.h"
#include "freeram.h"
using namespace std;
namespace po=boost::program_options;
int main(int argc,char **argv)
{
LasPoint lPoint;
int i;
int nthreads=thread::hardware_concurrency();
size_t j;
vector<string> inputFiles;
vector<LasHeader> files;
vector<xyz> limits;
xyz center;
ofstream testFile("testfile");
ofstream dumpFile("dumpfile");
bool validArgs,validCmd=true;
po::options_description generic("Options");
po::options_description hidden("Hidden options");
po::options_description cmdline_options;
po::positional_options_description p;
po::variables_map vm;
if (nthreads<2)
nthreads=2;
hidden.add_options()
("input",po::value<vector<string> >(&inputFiles),"Input file");
p.add("input",-1);
cmdline_options.add(generic).add(hidden);
try
{
po::store(po::command_line_parser(argc,argv).options(cmdline_options).positional(p).run(),vm);
po::notify(vm);
}
catch (exception &e)
{
cerr<<e.what()<<endl;
validCmd=false;
}
files.resize(inputFiles.size());
for (i=0;i<inputFiles.size();i++)
files[i].openRead(inputFiles[i]);
for (i=0;i<files.size();i++)
{
int ver;
limits.push_back(files[i].minCorner());
limits.push_back(files[i].maxCorner());
ver=files[i].getVersion();
cout<<"Version "<<(ver>>8)<<'.'<<(ver&255)<<' ';
cout<<files[i].numberPoints()<<" points, format "<<files[i].getPointFormat()<<endl;
}
lowRam=freeRam()/7;
octRoot.sizeFit(limits);
center=octRoot.getCenter();
cout<<'('<<ldecimal(center.getx())<<','<<ldecimal(center.gety())<<','<<ldecimal(center.getz())<<")±";
cout<<octRoot.getSide()<<endl;
lPoint.location=xyz(M_PI,exp(1),sqrt(2));
for (i=0;i<RECORDS;i++)
lPoint.write(testFile);
if (nthreads<1)
nthreads=1;
octStore.open("store.oct",nthreads+relprime(nthreads));
octStore.resize(8*nthreads+1);
startThreads(nthreads);
waitForThreads(TH_READ);
for (i=0;i<files.size();i++)
{
for (j=0;j<files[i].numberPoints();j++)
{
lPoint=files[i].readPoint(j);
embufferPoint(lPoint,true);
if (j%987==0)
{
cout<<j<<" \r";
cout.flush();
writeBufLog();
}
}
cout<<files[i].numberPoints()<<" points, "<<pointBufferSize()<<" points in buffer\n";
cout<<octStore.getNumBuffers()<<" buffers, "<<octStore.getNumBlocks()<<" blocks\n";
}
waitForQueueEmpty();
cout<<"All points in octree\n";
cout<<alreadyInOctree.size()<<" duplicate points\n";
cout<<octStore.getNumBuffers()<<" buffers, "<<octStore.getNumBlocks()<<" blocks\n";
waitForThreads(TH_STOP);
cout<<"Dumping octree\n";
octStore.dump(dumpFile);
joinThreads();
writeBufLog();
return 0;
}