41 #include <boost/lexical_cast.hpp>
47 void setupArgs(
int argc,
char *argv[],
unsigned int& startId,
unsigned int& endId,
string& extension);
53 int main(
int argc,
char *argv[])
66 bool debugMode =
false;
74 std::shared_ptr<PM::Transformation> rigidTransform;
75 rigidTransform =
PM::get().TransformationRegistrar.create(
"RigidTransformation");
83 TP Tref = TP::Identity(4,4);
85 unsigned startingI = 0;
86 unsigned listSizeI = list.size();
87 unsigned listSizeJ = list.size();
90 startingI = boost::lexical_cast<unsigned>(argv[2]);
91 listSizeI = startingI + 1;
94 PM::Matrix overlapResults = PM::Matrix::Ones(listSizeJ, listSizeI);
96 for(
unsigned i = startingI; i < listSizeI; i++)
98 unsigned startingJ = i+1;
101 startingJ = boost::lexical_cast<unsigned>(argv[3]);
102 listSizeJ = startingJ + 1;
104 for(
unsigned j = startingJ; j < listSizeJ; j++)
110 cout <<
"Point cloud loaded" << endl;
113 if(list[i].groundTruthTransformation.rows() != 0)
115 Tread = list[i].groundTruthTransformation;
116 Tref = list[j].groundTruthTransformation;
120 cout <<
"ERROR: fields gTXX (i.e., ground truth matrix) is required" << endl;
129 std::shared_ptr<PM::DataPointsFilter> subSample =
130 PM::get().DataPointsFilterRegistrar.create(
131 "RandomSamplingDataPointsFilter",
135 std::shared_ptr<PM::DataPointsFilter> maxDensity =
136 PM::get().DataPointsFilterRegistrar.create(
137 "MaxDensityDataPointsFilter"
148 PM::get().DataPointsFilterRegistrar.create(
149 "SurfaceNormalDataPointsFilter",
152 {
"keepDensities",
"1"}
160 const Matrix inliersRead = Matrix::Zero(1,
reading.features.cols());
161 reading.addDescriptor(
"inliers", inliersRead);
167 reference.addDescriptor(
"inliers", inliersRef);
173 for(
int l = 0; l < 2; l++)
175 const int selfPtsCount =
self.features.cols();
176 const int targetPtsCount =
target.features.cols();
181 std::shared_ptr<PM::Matcher> matcherSelf =
182 PM::get().MatcherRegistrar.create(
187 std::shared_ptr<PM::Matcher> matcherTarget =
188 PM::get().MatcherRegistrar.create(
189 "KDTreeVarDistMatcher",
192 {
"maxDistField",
"maxSearchDist"}
196 matcherSelf->init(
self);
197 matcherTarget->init(
target);
200 selfMatches = matcherSelf->findClosests(
self);
202 const Matrix maxSearchDist = selfMatches.dists.colwise().maxCoeff().cwiseSqrt();
203 self.addDescriptor(
"maxSearchDist", maxSearchDist);
205 Matches targetMatches(knnAll, targetPtsCount);
206 targetMatches = matcherTarget->findClosests(
self);
208 BOOST_AUTO(inlierSelf,
self.getDescriptorViewByName(
"inliers"));
209 BOOST_AUTO(inlierTarget,
target.getDescriptorViewByName(
"inliers"));
210 for(
int i = 0; i < selfPtsCount; i++)
212 for(
int k = 0; k < knnAll; k++)
214 if (targetMatches.dists(k, i) != Matches::InvalidDist)
216 inlierSelf(0,i) = 1.0;
217 inlierTarget(0,targetMatches.ids(k, i)) = 1.0;
226 const BOOST_AUTO(finalInlierSelf,
self.getDescriptorViewByName(
"inliers"));
227 const BOOST_AUTO(finalInlierTarget,
target.getDescriptorViewByName(
"inliers"));
228 const double selfRatio = (finalInlierSelf.array() > 0).count()/(double)finalInlierSelf.cols();
229 const double targetRatio = (finalInlierTarget.array() > 0).count()/(double)finalInlierTarget.cols();
231 cout << i <<
" -> " << j <<
": " << selfRatio << endl;
232 cout << j <<
" -> " << i <<
": " << targetRatio << endl;
236 self.save(
"scan_i.vtk");
237 target.save(
"scan_j.vtk");
241 overlapResults(j,i) = selfRatio;
242 overlapResults(i,j) = targetRatio;
249 std::fstream outFile;
250 outFile.open(
"overlapResults.csv", fstream::out);
251 for(
int x=0;
x < overlapResults.rows();
x++)
253 for(
int y=0; y < overlapResults.cols(); y++)
255 outFile << overlapResults(
x, y) <<
", ";
268 if (!(argc == 2 || argc == 4))
271 cerr <<
" ERROR in command line" << endl << endl;
272 cerr <<
" Usage: " << argv[0] <<
" listOfFiles.csv <i j>" << endl;
273 cerr <<
" Note: 'i' and 'j' are optional arguments. If used, only compute the overlap for those 2 point cloud ids and dump VTK files for visual inspection." << endl;
275 cerr <<
" Example: " << endl;
276 cerr <<
" $ " << argv[0] <<
" ../example/data/carCloudList.csv" << endl;