41 #include <boost/format.hpp>
42 #include <boost/filesystem/path.hpp>
43 #include <boost/filesystem/operations.hpp>
44 #include <boost/lexical_cast.hpp>
50 void setupArgs(
int argc,
char *argv[],
unsigned int& startId,
unsigned int& endId,
string& extension);
60 int main(
int argc,
char *argv[])
67 typedef PM::DataPoints
DP;
71 const unsigned totalPointCount = boost::lexical_cast<unsigned>(argv[2]);
72 string outputFileName(argv[3]);
77 PM::DataPoints mapCloud;
79 PM::DataPoints lastCloud, newCloud;
80 TP T = TP::Identity(4,4);
83 std::shared_ptr<PM::Transformation> transformation;
84 transformation =
PM::get().REG(Transformation).create(
"RigidTransformation");
87 std::shared_ptr<PM::DataPointsFilter> removeScanner =
88 PM::get().DataPointsFilterRegistrar.create(
89 "MinDistDataPointsFilter",
94 std::shared_ptr<PM::DataPointsFilter> randSubsample =
95 PM::get().DataPointsFilterRegistrar.create(
96 "RandomSamplingDataPointsFilter",
102 std::shared_ptr<PM::DataPointsFilter> normalFilter =
103 PM::get().DataPointsFilterRegistrar.create(
104 "SurfaceNormalDataPointsFilter",
113 std::shared_ptr<PM::DataPointsFilter> densityFilter =
114 PM::get().DataPointsFilterRegistrar.create(
115 "SurfaceNormalDataPointsFilter",
119 {
"keepDensities",
"1"},
124 std::shared_ptr<PM::DataPointsFilter> observationDirectionFilter =
125 PM::get().DataPointsFilterRegistrar.create(
126 "ObservationDirectionDataPointsFilter"
129 std::shared_ptr<PM::DataPointsFilter> orientNormalFilter =
130 PM::get().DataPointsFilterRegistrar.create(
131 "OrientNormalsDataPointsFilter",
132 {{
"towardCenter",
"1"}}
135 std::shared_ptr<PM::DataPointsFilter> uniformSubsample =
136 PM::get().DataPointsFilterRegistrar.create(
137 "MaxDensityDataPointsFilter",
141 std::shared_ptr<PM::DataPointsFilter> shadowFilter =
142 PM::get().DataPointsFilterRegistrar.create(
143 "ShadowDataPointsFilter"
146 for(
unsigned i=0; i < list.size(); i++)
148 cout << endl <<
"-----------------------------" << endl;
149 cout <<
"Loading " << list[i].readingFileName;
150 newCloud =
DP::load(list[i].readingFileName);
152 cout <<
" found " << newCloud.getNbPoints() <<
" points. " << endl;
155 if(list[i].groundTruthTransformation.rows() != 0)
156 T = list[i].groundTruthTransformation;
159 cout <<
"ERROR: the field gTXX (ground truth) is required" << endl;
166 newCloud = removeScanner->filter(newCloud);
170 newCloud = randSubsample->filter(newCloud);
173 newCloud = normalFilter->filter(newCloud);
174 newCloud = observationDirectionFilter->filter(newCloud);
175 newCloud = orientNormalFilter->filter(newCloud);
176 newCloud = shadowFilter->filter(newCloud);
179 cout <<
"Transformation matrix: " << endl << T << endl;
180 newCloud = transformation->compute(newCloud, T);
188 mapCloud.concatenate(newCloud);
191 double probToKeep = totalPointCount/(double)mapCloud.features.cols();
195 mapCloud = densityFilter->filter(mapCloud);
196 mapCloud = uniformSubsample->filter(mapCloud);
198 probToKeep = totalPointCount/(double)mapCloud.features.cols();
202 cout <<
"Randomly keep " << probToKeep*100 <<
"\% points" << endl;
203 randSubsample =
PM::get().DataPointsFilterRegistrar.create(
204 "RandomSamplingDataPointsFilter",
205 {{
"prob",
toParam(probToKeep)}}
207 mapCloud = randSubsample->filter(mapCloud);
212 stringstream outputFileNameIter;
213 outputFileNameIter << boost::filesystem::path(outputFileName).stem().c_str() <<
"_" << i <<
".vtk";
215 mapCloud.save(outputFileNameIter.str());
218 mapCloud = densityFilter->filter(mapCloud);
219 mapCloud = uniformSubsample->filter(mapCloud);
221 mapCloud = densityFilter->filter(mapCloud);
224 cout <<
"-----------------------------" << endl;
225 cout <<
"-----------------------------" << endl;
226 cout <<
"Final number of points in the map: " << mapCloud.getNbPoints() << endl;
227 mapCloud.save(outputFileName);
238 cerr <<
"Error in command line, usage " << argv[0] <<
" listOfFiles.csv maxPoint outputFileName.{vtk,csv,ply}" << endl;
240 cerr <<
" example using file from example/data: " << endl;
241 cerr <<
" " << argv[0] <<
" carCloudList.csv 30000 test.vtk" << endl;
243 cerr <<
"Note: the file listOfFiles.csv need to include a serialize transformation matrix. For example:" << endl;
244 cerr <<
" fileName1.vtk, T00, T01, T02, T03, T10, T11, T12, T13, T20, T21, T22, T23, T30, T31, T32" << endl;
246 cerr <<
"Where Txy would be a 4x4 transformation matrix:" << endl;
247 cerr <<
" [T00 T01 T02 T03] " << endl;
248 cerr <<
" [T10 T11 T12 T13] " << endl;
249 cerr <<
" [T20 T21 T22 T23] " << endl;
250 cerr <<
" [T30 T31 T32 T33] (i.e., 0,0,0,1)" << endl;
252 cerr <<
"For more data visit:" << endl;
253 cerr <<
" http://projects.asl.ethz.ch/datasets/doku.php?id=laserregistration:laserregistration" << endl;