40 Transformation3d tTrafo;
41 tTrafo.rotation = Math3d::unit_mat;
42 tTrafo.translation = Math3d::zero_vec;
43 std::vector<Transformation3d> aTransformations;
44 aTransformations.resize(aHypotheses.size());
46 for (
size_t i = 0; i < aTransformations.size(); i++)
48 aTransformations.at(i) = tTrafo;
57 std::vector<std::vector<CHypothesisPoint*> > aPointClouds;
58 aPointClouds.resize(aHypotheses.size());
60 for (
size_t i = 0; i < aHypotheses.size(); i++)
62 aPointClouds.at(i).resize(aHypotheses.at(i)->aConfirmedPoints.size());
64 for (
size_t j = 0; j < aHypotheses.at(i)->aConfirmedPoints.size(); j++)
66 aPointClouds.at(i).at(j) = aHypotheses.at(i)->aConfirmedPoints.at(j);
70 FusePointClouds(aPointClouds, aEstimatedTransformations, pFusedHypothesis);
76 Transformation3d tTrafo;
77 tTrafo.rotation = Math3d::unit_mat;
78 tTrafo.translation = Math3d::zero_vec;
79 std::vector<Transformation3d> aTransformations;
80 aTransformations.resize(aHypothesisPoints.size());
82 for (
size_t i = 0; i < aTransformations.size(); i++)
84 aTransformations.at(i) = tTrafo;
91 void FusePointClouds(std::vector<std::vector<CHypothesisPoint*> > aHypothesisPoints, std::vector<Transformation3d> aEstimatedTransformations,
CObjectHypothesis*& pFusedHypothesis)
93 bool bPairwiseFusion =
true;
95 if (aHypothesisPoints.size() < 2)
101 timeval tStart, tEnd;
102 gettimeofday(&tStart, 0);
105 Transformation3d tAccumulatedTransform, tInverseTransform;
106 tAccumulatedTransform.rotation = Math3d::unit_mat;
107 tAccumulatedTransform.translation = Math3d::zero_vec;
109 for (
size_t i = 0; i < aHypothesisPoints.size() - 1; i++)
111 Math3d::MulMatMat(aEstimatedTransformations.at(i).rotation, tAccumulatedTransform.rotation, tAccumulatedTransform.rotation);
112 Math3d::MulMatVec(aEstimatedTransformations.at(i).rotation, tAccumulatedTransform.translation, aEstimatedTransformations.at(i).translation, tAccumulatedTransform.translation);
113 Math3d::Transpose(tAccumulatedTransform.rotation, tInverseTransform.rotation);
114 Math3d::MulMatVec(tInverseTransform.rotation, tAccumulatedTransform.translation, tInverseTransform.translation);
115 Math3d::MulVecScalar(tInverseTransform.translation, -1, tInverseTransform.translation);
117 for (
size_t j = 0; j < aHypothesisPoints.at(i).size(); j++)
119 Math3d::MulMatVec(tInverseTransform.rotation, aHypothesisPoints.at(i).at(j)->vPosition, tInverseTransform.translation, aHypothesisPoints.at(i).at(j)->vPosition);
124 std::vector<std::vector<CColorICP::CPointXYZRGBI> > aPointClouds;
125 aPointClouds.resize(aHypothesisPoints.size());
127 for (
size_t i = 0; i < aHypothesisPoints.size(); i++)
129 aPointClouds.at(i).resize(aHypothesisPoints.at(i).size());
131 for (
size_t j = 0; j < aHypothesisPoints.at(i).size(); j++)
138 const int nNumDifferentInitializations = 7;
139 std::vector<Mat3d> aRotations;
140 aRotations.resize(nNumDifferentInitializations);
141 const float fAngle =
M_PI / 6.0f;
142 Math3d::SetMat(aRotations.at(0), Math3d::unit_mat);
143 Math3d::SetRotationMatX(aRotations.at(1), fAngle);
144 Math3d::SetRotationMatX(aRotations.at(2), -fAngle);
145 Math3d::SetRotationMatY(aRotations.at(3), fAngle);
146 Math3d::SetRotationMatY(aRotations.at(4), -fAngle);
147 Math3d::SetRotationMatZ(aRotations.at(5), fAngle);
148 Math3d::SetRotationMatZ(aRotations.at(6), -fAngle);
153 const int nParallelityFactor = omp_get_num_procs();
154 omp_set_num_threads(nParallelityFactor);
157 for (
int i = 0; i < nParallelityFactor; i++)
164 int nFusionResultIndex = -1;
170 nFusionResultIndex = 0;
171 std::vector<Transformation3d> aPairwiseTransformations;
172 aPairwiseTransformations.resize(aPointClouds.size() - 1);
173 std::vector<float> aMinDistances;
174 aMinDistances.resize(aPointClouds.size() - 1);
176 for (
size_t i = 0; i < aPointClouds.size() - 1; i++)
178 aPairwiseTransformations.at(i).rotation = Math3d::unit_mat;
179 aPairwiseTransformations.at(i).translation = Math3d::zero_vec;
180 aMinDistances.at(i) = FLT_MAX;
185 #pragma omp parallel for schedule(static, 1)
186 for (
int k = 0; k < nNumDifferentInitializations * ((int)aPointClouds.size() - 1); k++)
188 const int n = k / nNumDifferentInitializations;
189 const int i = k % nNumDifferentInitializations;
190 const int nThreadNumber = omp_get_thread_num();
196 std::vector<CColorICP::CPointXYZRGBI> aRotatedPointCloud;
197 aRotatedPointCloud.resize(aPointClouds.at(n).size());
199 for (
size_t j = 0; j < aPointClouds.at(n).size(); j++)
201 aRotatedPointCloud.at(j) = aPointClouds.at(n).at(j);
207 float fDist = pColorICPInstances[nThreadNumber]->
SearchObject(aRotatedPointCloud, mRotation, vTranslation);
210 if (fDist < aMinDistances.at(n))
212 Math3d::MulMatMat(mRotation, aRotations.at(i), aPairwiseTransformations.at(n).rotation);
213 Math3d::SetVec(aPairwiseTransformations.at(n).translation, vTranslation);
214 aMinDistances.at(n) = fDist;
219 int nOverallNumberOfPoints = 0;
220 int nIndexOffset = aPointClouds.at(0).size();
222 for (
size_t i = 0; i < aPointClouds.size(); i++)
224 nOverallNumberOfPoints += aPointClouds.at(i).size();
227 aPointClouds.at(nFusionResultIndex).resize(nOverallNumberOfPoints);
228 tAccumulatedTransform.rotation = Math3d::unit_mat;
229 tAccumulatedTransform.translation = Math3d::zero_vec;
231 for (
size_t i = 0; i < aPointClouds.size() - 1; i++)
233 Math3d::MulMatMat(aPairwiseTransformations.at(i).rotation, tAccumulatedTransform.rotation, tAccumulatedTransform.rotation);
234 Math3d::MulMatVec(aPairwiseTransformations.at(i).rotation, tAccumulatedTransform.translation, aPairwiseTransformations.at(i).translation, tAccumulatedTransform.translation);
235 Math3d::Transpose(tAccumulatedTransform.rotation, tInverseTransform.rotation);
236 Math3d::MulMatVec(tInverseTransform.rotation, tAccumulatedTransform.translation, tInverseTransform.translation);
237 Math3d::MulVecScalar(tInverseTransform.translation, -1, tInverseTransform.translation);
239 #pragma omp parallel for schedule(static, 100)
240 for (
size_t j = 0; j < aPointClouds.at(i + 1).size(); j++)
243 aPointClouds.at(nFusionResultIndex).at(nIndexOffset + j) = aPointClouds.at(i + 1).at(j);
248 nIndexOffset += aPointClouds.at(i).size();
255 const int nStartIndex = aHypothesisPoints.size() / 2;
256 nFusionResultIndex = nStartIndex;
257 int nLowIndex = nStartIndex - 1;
258 int nHighIndex = nStartIndex + 1;
261 while (nLowIndex >= 0 || nHighIndex < (
int)aHypothesisPoints.size())
264 for (
int i = 0; i < nParallelityFactor; i++)
272 Mat3d mBestRotation = Math3d::unit_mat;
273 Vec3d vBestTranslation = Math3d::zero_vec;
274 float fMinDist = FLT_MAX;
276 #pragma omp parallel for schedule(static, 1)
277 for (
int i = 0; i < nNumDifferentInitializations; i++)
279 const int nThreadNumber = omp_get_thread_num();
282 std::vector<CColorICP::CPointXYZRGBI> aRotatedPointCloud;
283 aRotatedPointCloud.resize(aPointClouds.at(nLowIndex).size());
285 for (
size_t j = 0; j < aPointClouds.at(nLowIndex).size(); j++)
287 aRotatedPointCloud.at(j) = aPointClouds.at(nLowIndex).at(j);
293 float fDist = pColorICPInstances[nThreadNumber]->
SearchObject(aRotatedPointCloud, mRotation, vTranslation);
296 if (fDist < fMinDist)
298 Math3d::MulMatMat(mRotation, aRotations.at(i), mBestRotation);
299 Math3d::SetVec(vBestTranslation, vTranslation);
306 for (
size_t i = 0; i < aPointClouds.at(nLowIndex).size(); i++)
309 aPointClouds.at(nStartIndex).push_back(aPointClouds.at(nLowIndex).at(i));
316 if (nHighIndex < (
int)aHypothesisPoints.size())
318 Mat3d mBestRotation = Math3d::unit_mat;
319 Vec3d vBestTranslation = Math3d::zero_vec;
320 float fMinDist = FLT_MAX;
322 #pragma omp parallel for schedule(static, 1)
323 for (
int i = 0; i < nNumDifferentInitializations; i++)
325 const int nThreadNumber = omp_get_thread_num();
328 std::vector<CColorICP::CPointXYZRGBI> aRotatedPointCloud;
329 aRotatedPointCloud.resize(aPointClouds.at(nHighIndex).size());
331 for (
size_t j = 0; j < aPointClouds.at(nHighIndex).size(); j++)
333 aRotatedPointCloud.at(j) = aPointClouds.at(nHighIndex).at(j);
339 float fDist = pColorICPInstances[nThreadNumber]->
SearchObject(aRotatedPointCloud, mRotation, vTranslation);
342 if (fDist < fMinDist)
344 Math3d::MulMatMat(mRotation, aRotations.at(i), mBestRotation);
345 Math3d::SetVec(vBestTranslation, vTranslation);
352 for (
size_t i = 0; i < aPointClouds.at(nHighIndex).size(); i++)
355 aPointClouds.at(nStartIndex).push_back(aPointClouds.at(nHighIndex).at(i));
367 if (!pFusedHypothesis)
374 pFusedHypothesis->
aConfirmedPoints.resize(aPointClouds.at(nFusionResultIndex).size());
378 for (
size_t i = 0; i < aPointClouds.at(nFusionResultIndex).size(); i++)
387 for (
int i = 0; i < nParallelityFactor; i++)
389 delete pColorICPInstances[i];
392 gettimeofday(&tEnd, 0);
393 long tTimeDiff = (1000 * tEnd.tv_sec + tEnd.tv_usec / 1000) - (1000 * tStart.tv_sec + tStart.tv_usec / 1000);