1 #ifndef CANDIDATE_HEADER
2 #define CANDIDATE_HEADER
70 return (m_lowerBound + m_upperBound) / 2.f;
86 template <
class ScoreVisitorT>
89 ScoreVisitorT& scoreVisitor,
93 size_t minPoints = 500);
94 template <
class ScoreVisitorT>
97 ScoreVisitorT& scoreVisitor,
101 float bitmapEpsilon);
104 size_t mergedSubsets,
110 float bitmapEpsilon);
112 template <
class ScoreVisitorT>
114 float WeightedScore(
const PointCloud&
pc,
float epsilon,
float normalThresh)
const;
115 void ConnectedComponent(
const PointCloud&
pc,
float bitmapEpsilon,
float* borderRatio = 0);
116 template <
class ScoreVisitorT>
117 float GlobalWeightedScore(ScoreVisitorT& scoreVisitor,
122 float bitmapEpsilon);
134 return m_indices->size();
138 inline void GetBounds(
size_t sampledPoints,
size_t totalPoints);
139 inline void Induct(
double totalSize,
141 double totalCorrectSize,
144 inline void Deduct(
double totalSize,
146 double totalCorrectSize,
150 void GetScore(
const PointCloud&
pc,
float bitmapEpsilon,
bool doFiltering);
151 void GetScoreMaxCCSize(
const PointCloud&
pc,
float bitmapEpsilon,
bool doFiltering);
152 void GetScoreMaxCCMinBorder(
const PointCloud&
pc,
float bitmapEpsilon,
bool doFiltering);
164 bool m_hasConnectedComponent;
195 c->m_shape = m_shape->
Clone();
196 c->m_shape->Release();
197 c->m_subset = m_subset;
198 c->m_lowerBound = m_lowerBound;
199 c->m_upperBound = m_upperBound;
201 c->m_indices->Release();
202 c->m_level = m_level;
204 c->m_hasConnectedComponent = m_hasConnectedComponent;
205 c->m_score = m_score;
209 Candidate::GetBounds(
size_t sampledPoints,
size_t totalPoints)
212 (
double)totalPoints, (
double)sampledPoints, (
double)m_score, &m_lowerBound, &m_upperBound);
213 m_lowerBound =
std::max(0.f, m_lowerBound);
217 Candidate::Induct(
double totalSize,
219 double totalCorrectSize,
223 Deduct(-2.0 - sampleSize, -2.0 - totalSize, -1.0 - totalCorrectSize, lower, upper);
224 *lower = -1.f - *lower;
225 *upper = -1.f - *upper;
229 Candidate::Deduct(
double totalSize,
231 double totalCorrectSize,
235 double nI = sampleSize * totalCorrectSize;
236 double denom = nI * (totalSize - sampleSize) * (totalSize - totalCorrectSize);
237 double frac = denom / (totalSize - 1);
239 *lower =
float((nI - dev) / totalSize);
240 *upper =
float((nI + dev) / totalSize);
243 template <
class ScoreVisitorT>
247 ScoreVisitorT& scoreVisitor,
253 if (m_subset >= maxSubset)
257 if (m_subset >= octrees.
size())
262 size_t sampledPoints = 0;
263 for (
size_t i = 0; i < m_subset; ++i)
265 sampledPoints += octrees[i]->
size();
268 size_t newlySampledPoints = 0;
269 scoreVisitor.SetIndices(m_indices);
272 scoreVisitor.SetOctree(*octrees[m_subset]);
273 m_shape->
Visit(&scoreVisitor);
274 newlySampledPoints += octrees[m_subset]->
size();
275 sampledPoints += octrees[m_subset]->
size();
277 }
while (m_subset < octrees.
size() && newlySampledPoints < minPoints);
279 m_score = m_indices->
size();
280 GetBounds(sampledPoints, currentSize);
287 if (m_hasConnectedComponent ||
288 (2.f * (m_upperBound - (m_lowerBound / .7f)) / (m_upperBound + (m_lowerBound / .7f))) < .3f)
290 if (!m_hasConnectedComponent && m_indices->
size() < 2)
294 m_hasConnectedComponent =
true;
296 pc, (4 << ((octrees.
size() - m_subset) / 2)) * bitmapEpsilon, m_indices,
false);
297 m_indices->
resize(m_score);
298 if (m_subset >= octrees.
size())
300 GetScore(
pc, bitmapEpsilon,
true);
301 m_upperBound = m_lowerBound = m_score;
304 GetScore(
pc, (2 << ((octrees.
size() - m_subset) / 2)) * bitmapEpsilon,
false);
306 GetBounds(sampledPoints, currentSize);
311 template <
class ScoreVisitorT>
315 ScoreVisitorT& scoreVisitor,
323 size_t indicesSize = m_indices->
size();
324 for (
size_t i = 0; i < indicesSize;)
326 if (shapeIndex[(*m_indices)[i]] != -1)
329 std::swap((*m_indices)[i], (*m_indices)[indicesSize]);
337 m_score = indicesSize;
339 if (m_hasConnectedComponent)
341 if (m_indices->
size() != indicesSize)
343 if ((
float)indicesSize / m_indices->
size() > 0.95)
345 m_indices->
resize(indicesSize);
348 m_subset >= octrees.
size()
350 : (4 << ((octrees.
size() - m_subset) / 2)) * bitmapEpsilon,
351 m_subset >= octrees.
size());
353 if (m_subset >= octrees.
size())
355 m_upperBound = m_lowerBound = (
float)m_indices->
size();
363 m_hasConnectedComponent =
false;
366 ImproveBounds(octrees,
pc, scoreVisitor, currentSize, bitmapEpsilon, 1);
370 else if (m_subset > octrees.
size())
378 m_indices->
resize(indicesSize);
379 m_score = m_indices->
size();
381 size_t sampledPoints = 0, endi =
std::min(m_subset, octrees.
size());
382 for (
size_t i = 0; i < endi; ++i)
384 sampledPoints += octrees[i]->
size();
387 GetBounds(sampledPoints, currentSize);
390 template <
class ScoreVisitorT>
395 scoreVisitor.SetOctree(oct);
396 scoreVisitor.SetIndices(m_indices);
397 m_shape->
Visit(&scoreVisitor);
398 m_lowerBound = m_upperBound = (
float)m_indices->
size();
401 template <
class ScoreVisitorT>