41 Transformation3d tTrafo;
42 tTrafo.rotation = Math3d::unit_mat;
43 tTrafo.translation = Math3d::zero_vec;
44 std::vector<Transformation3d> aTransformations;
45 aTransformations.resize(aHypotheses.size());
47 for (
size_t i = 0; i < aTransformations.size(); i++)
49 aTransformations.at(i) = tTrafo;
57 std::vector<Transformation3d> aEstimatedTransformations,
60 std::vector<std::vector<CHypothesisPoint*>> aPointClouds;
61 aPointClouds.resize(aHypotheses.size());
63 for (
size_t i = 0; i < aHypotheses.size(); i++)
65 aPointClouds.at(i).resize(aHypotheses.at(i)->aConfirmedPoints.size());
67 for (
size_t j = 0; j < aHypotheses.at(i)->aConfirmedPoints.size(); j++)
69 aPointClouds.at(i).at(j) = aHypotheses.at(i)->aConfirmedPoints.at(j);
73 FusePointClouds(aPointClouds, aEstimatedTransformations, pFusedHypothesis);
80 Transformation3d tTrafo;
81 tTrafo.rotation = Math3d::unit_mat;
82 tTrafo.translation = Math3d::zero_vec;
83 std::vector<Transformation3d> aTransformations;
84 aTransformations.resize(aHypothesisPoints.size());
86 for (
size_t i = 0; i < aTransformations.size(); i++)
88 aTransformations.at(i) = tTrafo;
97 std::vector<Transformation3d> aEstimatedTransformations,
100 bool bPairwiseFusion =
true;
102 if (aHypothesisPoints.size() < 2)
108 timeval tStart, tEnd;
109 gettimeofday(&tStart, 0);
112 Transformation3d tAccumulatedTransform, tInverseTransform;
113 tAccumulatedTransform.rotation = Math3d::unit_mat;
114 tAccumulatedTransform.translation = Math3d::zero_vec;
116 for (
size_t i = 0; i < aHypothesisPoints.size() - 1; i++)
118 Math3d::MulMatMat(aEstimatedTransformations.at(i).rotation,
119 tAccumulatedTransform.rotation,
120 tAccumulatedTransform.rotation);
121 Math3d::MulMatVec(aEstimatedTransformations.at(i).rotation,
122 tAccumulatedTransform.translation,
123 aEstimatedTransformations.at(i).translation,
124 tAccumulatedTransform.translation);
125 Math3d::Transpose(tAccumulatedTransform.rotation, tInverseTransform.rotation);
126 Math3d::MulMatVec(tInverseTransform.rotation,
127 tAccumulatedTransform.translation,
128 tInverseTransform.translation);
129 Math3d::MulVecScalar(tInverseTransform.translation, -1, tInverseTransform.translation);
131 for (
size_t j = 0; j < aHypothesisPoints.at(i).size(); j++)
133 Math3d::MulMatVec(tInverseTransform.rotation,
134 aHypothesisPoints.at(i).at(j)->vPosition,
135 tInverseTransform.translation,
136 aHypothesisPoints.at(i).at(j)->vPosition);
141 std::vector<std::vector<CColorICP::CPointXYZRGBI>> aPointClouds;
142 aPointClouds.resize(aHypothesisPoints.size());
144 for (
size_t i = 0; i < aHypothesisPoints.size(); i++)
146 aPointClouds.at(i).resize(aHypothesisPoints.at(i).size());
148 for (
size_t j = 0; j < aHypothesisPoints.at(i).size(); j++)
150 aPointClouds.at(i).at(j) =
156 const int nNumDifferentInitializations = 7;
157 std::vector<Mat3d> aRotations;
158 aRotations.resize(nNumDifferentInitializations);
159 const float fAngle =
M_PI / 6.0f;
160 Math3d::SetMat(aRotations.at(0), Math3d::unit_mat);
161 Math3d::SetRotationMatX(aRotations.at(1), fAngle);
162 Math3d::SetRotationMatX(aRotations.at(2), -fAngle);
163 Math3d::SetRotationMatY(aRotations.at(3), fAngle);
164 Math3d::SetRotationMatY(aRotations.at(4), -fAngle);
165 Math3d::SetRotationMatZ(aRotations.at(5), fAngle);
166 Math3d::SetRotationMatZ(aRotations.at(6), -fAngle);
170 const int nParallelityFactor = omp_get_num_procs();
171 omp_set_num_threads(nParallelityFactor);
174 for (
int i = 0; i < nParallelityFactor; i++)
182 int nFusionResultIndex = -1;
188 nFusionResultIndex = 0;
189 std::vector<Transformation3d> aPairwiseTransformations;
190 aPairwiseTransformations.resize(aPointClouds.size() - 1);
191 std::vector<float> aMinDistances;
192 aMinDistances.resize(aPointClouds.size() - 1);
194 for (
size_t i = 0; i < aPointClouds.size() - 1; i++)
196 aPairwiseTransformations.at(i).rotation = Math3d::unit_mat;
197 aPairwiseTransformations.at(i).translation = Math3d::zero_vec;
198 aMinDistances.at(i) = FLT_MAX;
203 #pragma omp parallel for schedule(static, 1)
204 for (
int k = 0; k < nNumDifferentInitializations * ((int)aPointClouds.size() - 1); k++)
206 const int n = k / nNumDifferentInitializations;
207 const int i = k % nNumDifferentInitializations;
208 const int nThreadNumber = omp_get_thread_num();
214 std::vector<CColorICP::CPointXYZRGBI> aRotatedPointCloud;
215 aRotatedPointCloud.resize(aPointClouds.at(n).size());
217 for (
size_t j = 0; j < aPointClouds.at(n).size(); j++)
219 aRotatedPointCloud.at(j) = aPointClouds.at(n).at(j);
221 aRotatedPointCloud.at(j), aRotations.at(i), Math3d::zero_vec);
226 float fDist = pColorICPInstances[nThreadNumber]->
SearchObject(
227 aRotatedPointCloud, mRotation, vTranslation);
230 if (fDist < aMinDistances.at(n))
233 mRotation, aRotations.at(i), aPairwiseTransformations.at(n).rotation);
234 Math3d::SetVec(aPairwiseTransformations.at(n).translation, vTranslation);
235 aMinDistances.at(n) = fDist;
240 int nOverallNumberOfPoints = 0;
241 int nIndexOffset = aPointClouds.at(0).size();
243 for (
size_t i = 0; i < aPointClouds.size(); i++)
245 nOverallNumberOfPoints += aPointClouds.at(i).size();
248 aPointClouds.at(nFusionResultIndex).resize(nOverallNumberOfPoints);
249 tAccumulatedTransform.rotation = Math3d::unit_mat;
250 tAccumulatedTransform.translation = Math3d::zero_vec;
252 for (
size_t i = 0; i < aPointClouds.size() - 1; i++)
254 Math3d::MulMatMat(aPairwiseTransformations.at(i).rotation,
255 tAccumulatedTransform.rotation,
256 tAccumulatedTransform.rotation);
257 Math3d::MulMatVec(aPairwiseTransformations.at(i).rotation,
258 tAccumulatedTransform.translation,
259 aPairwiseTransformations.at(i).translation,
260 tAccumulatedTransform.translation);
261 Math3d::Transpose(tAccumulatedTransform.rotation, tInverseTransform.rotation);
262 Math3d::MulMatVec(tInverseTransform.rotation,
263 tAccumulatedTransform.translation,
264 tInverseTransform.translation);
265 Math3d::MulVecScalar(
266 tInverseTransform.translation, -1, tInverseTransform.translation);
268 #pragma omp parallel for schedule(static, 100)
269 for (
size_t j = 0; j < aPointClouds.at(i + 1).size(); j++)
272 tInverseTransform.rotation,
273 tInverseTransform.translation);
274 aPointClouds.at(nFusionResultIndex).at(nIndexOffset + j) =
275 aPointClouds.at(i + 1).at(j);
280 nIndexOffset += aPointClouds.at(i).size();
286 const int nStartIndex = aHypothesisPoints.size() / 2;
287 nFusionResultIndex = nStartIndex;
288 int nLowIndex = nStartIndex - 1;
289 int nHighIndex = nStartIndex + 1;
292 while (nLowIndex >= 0 || nHighIndex < (
int)aHypothesisPoints.size())
295 for (
int i = 0; i < nParallelityFactor; i++)
303 Mat3d mBestRotation = Math3d::unit_mat;
304 Vec3d vBestTranslation = Math3d::zero_vec;
305 float fMinDist = FLT_MAX;
307 #pragma omp parallel for schedule(static, 1)
308 for (
int i = 0; i < nNumDifferentInitializations; i++)
310 const int nThreadNumber = omp_get_thread_num();
313 std::vector<CColorICP::CPointXYZRGBI> aRotatedPointCloud;
314 aRotatedPointCloud.resize(aPointClouds.at(nLowIndex).size());
316 for (
size_t j = 0; j < aPointClouds.at(nLowIndex).size(); j++)
318 aRotatedPointCloud.at(j) = aPointClouds.at(nLowIndex).at(j);
320 aRotatedPointCloud.at(j), aRotations.at(i), Math3d::zero_vec);
325 float fDist = pColorICPInstances[nThreadNumber]->
SearchObject(
326 aRotatedPointCloud, mRotation, vTranslation);
329 if (fDist < fMinDist)
331 Math3d::MulMatMat(mRotation, aRotations.at(i), mBestRotation);
332 Math3d::SetVec(vBestTranslation, vTranslation);
339 for (
size_t i = 0; i < aPointClouds.at(nLowIndex).size(); i++)
342 aPointClouds.at(nLowIndex).at(i), mBestRotation, vBestTranslation);
343 aPointClouds.at(nStartIndex).push_back(aPointClouds.at(nLowIndex).at(i));
350 if (nHighIndex < (
int)aHypothesisPoints.size())
352 Mat3d mBestRotation = Math3d::unit_mat;
353 Vec3d vBestTranslation = Math3d::zero_vec;
354 float fMinDist = FLT_MAX;
356 #pragma omp parallel for schedule(static, 1)
357 for (
int i = 0; i < nNumDifferentInitializations; i++)
359 const int nThreadNumber = omp_get_thread_num();
362 std::vector<CColorICP::CPointXYZRGBI> aRotatedPointCloud;
363 aRotatedPointCloud.resize(aPointClouds.at(nHighIndex).size());
365 for (
size_t j = 0; j < aPointClouds.at(nHighIndex).size(); j++)
367 aRotatedPointCloud.at(j) = aPointClouds.at(nHighIndex).at(j);
369 aRotatedPointCloud.at(j), aRotations.at(i), Math3d::zero_vec);
374 float fDist = pColorICPInstances[nThreadNumber]->
SearchObject(
375 aRotatedPointCloud, mRotation, vTranslation);
378 if (fDist < fMinDist)
380 Math3d::MulMatMat(mRotation, aRotations.at(i), mBestRotation);
381 Math3d::SetVec(vBestTranslation, vTranslation);
388 for (
size_t i = 0; i < aPointClouds.at(nHighIndex).size(); i++)
391 aPointClouds.at(nHighIndex).at(i), mBestRotation, vBestTranslation);
392 aPointClouds.at(nStartIndex).push_back(aPointClouds.at(nHighIndex).at(i));
404 if (!pFusedHypothesis)
411 pFusedHypothesis->
aConfirmedPoints.resize(aPointClouds.at(nFusionResultIndex).size());
414 aPointClouds.at(nFusionResultIndex).size());
416 for (
size_t i = 0; i < aPointClouds.at(nFusionResultIndex).size(); i++)
429 for (
int i = 0; i < nParallelityFactor; i++)
431 delete pColorICPInstances[i];
434 gettimeofday(&tEnd, 0);
435 long tTimeDiff = (1000 * tEnd.tv_sec + tEnd.tv_usec / 1000) -
436 (1000 * tStart.tv_sec + tStart.tv_usec / 1000);