1 #ifndef CANDIDATE_HEADER
2 #define CANDIDATE_HEADER
53 return (m_lowerBound + m_upperBound) / 2.f;
64 template<
class ScoreVisitorT >
67 size_t currentSize,
float bitmapEpsilon,
68 size_t maxSubset,
size_t minPoints = 500);
69 template<
class ScoreVisitorT >
71 const PointCloud&
pc, ScoreVisitorT& scoreVisitor,
size_t currentSize,
72 float epsilon,
float normalThresh,
float bitmapEpsilon);
76 float normalThresh,
float bitmapEpsilon);
78 template<
class ScoreVisitorT >
79 void GlobalScore(ScoreVisitorT& scoreVisitor,
82 float normalThresh)
const;
83 void ConnectedComponent(
const PointCloud&
pc,
float bitmapEpsilon,
float* borderRatio = 0);
84 template<
class ScoreVisitorT >
85 float GlobalWeightedScore(ScoreVisitorT& scoreVisitor,
const IndexedOctreeType& oct,
94 float epsilon,
float normalThresh)
const;
97 return m_indices->size();
101 inline void GetBounds(
size_t sampledPoints,
size_t totalPoints);
102 inline void Induct(
double totalSize,
double sampleSize,
103 double totalCorrectSize,
float* lower,
float* upper)
const;
104 inline void Deduct(
double totalSize,
double sampleSize,
105 double totalCorrectSize,
float* lower,
float* upper)
const;
107 void GetScore(
const PointCloud&
pc,
float bitmapEpsilon,
bool doFiltering);
108 void GetScoreMaxCCSize(
const PointCloud&
pc,
float bitmapEpsilon,
bool doFiltering);
109 void GetScoreMaxCCMinBorder(
const PointCloud&
pc,
float bitmapEpsilon,
bool doFiltering);
121 bool m_hasConnectedComponent;
147 c->m_shape = m_shape->
Clone();
148 c->m_shape->Release();
149 c->m_subset = m_subset;
150 c->m_lowerBound = m_lowerBound;
151 c->m_upperBound = m_upperBound;
153 c->m_indices->Release();
154 c->m_level = m_level;;
155 c->m_hasConnectedComponent = m_hasConnectedComponent;
156 c->m_score = m_score;
159 void Candidate::GetBounds(
size_t sampledPoints,
size_t totalPoints)
161 Induct((
double)totalPoints, (
double)sampledPoints, (
double)m_score, &m_lowerBound,
163 m_lowerBound =
std::max(0.f, m_lowerBound);
166 void Candidate::Induct(
double totalSize,
double sampleSize,
167 double totalCorrectSize,
float* lower,
float* upper)
const
169 Deduct(-2.0 - sampleSize, -2.0 - totalSize, -1.0 - totalCorrectSize,
171 *lower = -1.f - *lower;
172 *upper = -1.f - *upper;
175 void Candidate::Deduct(
double totalSize,
double sampleSize,
176 double totalCorrectSize,
float* lower,
float* upper)
const
178 double nI = sampleSize * totalCorrectSize;
179 double denom = nI * (totalSize - sampleSize) *
180 (totalSize - totalCorrectSize);
181 double frac = denom / (totalSize - 1);
183 *lower =
float((nI - dev) / totalSize);
184 *upper =
float((nI + dev) / totalSize);
187 template<
class ScoreVisitorT >
190 size_t currentSize,
float bitmapEpsilon,
191 size_t maxSubset,
size_t minPoints)
193 if (m_subset >= maxSubset)
197 if (m_subset >= octrees.
size())
202 size_t sampledPoints = 0;
203 for (
size_t i = 0; i < m_subset; ++i)
205 sampledPoints += octrees[i]->
size();
208 size_t newlySampledPoints = 0;
209 scoreVisitor.SetIndices(m_indices);
212 scoreVisitor.SetOctree(*octrees[m_subset]);
213 m_shape->
Visit(&scoreVisitor);
214 newlySampledPoints += octrees[m_subset]->
size();
215 sampledPoints += octrees[m_subset]->
size();
218 while (m_subset < octrees.
size() && newlySampledPoints < minPoints);
220 m_score = m_indices->
size();
221 GetBounds(sampledPoints, currentSize);
228 if (m_hasConnectedComponent ||
229 (2.f * (m_upperBound - (m_lowerBound / .7f)) /
230 (m_upperBound + (m_lowerBound / .7f))) < .3f)
232 if (!m_hasConnectedComponent && m_indices->
size() < 2)
236 m_hasConnectedComponent =
true;
238 (4 << ((octrees.
size() - m_subset) / 2)) * bitmapEpsilon,
240 m_indices->
resize(m_score);
241 if (m_subset >= octrees.
size())
243 GetScore(
pc, bitmapEpsilon,
true);
244 m_upperBound = m_lowerBound = m_score;
247 GetScore(
pc, (2 << ((octrees.
size() - m_subset) / 2)) * bitmapEpsilon,
false);
249 GetBounds(sampledPoints, currentSize);
254 template<
class ScoreVisitorT >
256 const PointCloud&
pc, ScoreVisitorT& scoreVisitor,
size_t currentSize,
257 float epsilon,
float normalThresh,
float bitmapEpsilon)
261 size_t indicesSize = m_indices->
size();
262 for (
size_t i = 0; i < indicesSize;)
264 if (shapeIndex[(*m_indices)[i]] != -1)
267 std::swap((*m_indices)[i], (*m_indices)[indicesSize]);
275 m_score = indicesSize;
277 if (m_hasConnectedComponent)
279 if (m_indices->
size() != indicesSize)
281 if ((
float)indicesSize / m_indices->
size() > 0.95)
283 m_indices->
resize(indicesSize);
285 GetScore(
pc, m_subset >= octrees.
size() ? bitmapEpsilon :
286 (4 << ((octrees.
size() - m_subset) / 2)) * bitmapEpsilon,
287 m_subset >= octrees.
size());
289 if (m_subset >= octrees.
size())
291 m_upperBound = m_lowerBound = (
float)m_indices->
size();
299 m_hasConnectedComponent =
false;
303 currentSize, bitmapEpsilon, 1);
307 else if (m_subset > octrees.
size())
315 m_indices->
resize(indicesSize);
316 m_score = m_indices->
size();
318 size_t sampledPoints = 0,
320 for (
size_t i = 0; i < endi; ++i)
322 sampledPoints += octrees[i]->
size();
325 GetBounds(sampledPoints, currentSize);
328 template<
class ScoreVisitorT >
333 scoreVisitor.SetOctree(oct);
334 scoreVisitor.SetIndices(m_indices);
335 m_shape->
Visit(&scoreVisitor);
336 m_lowerBound = m_upperBound = (
float)m_indices->
size();
339 template<
class ScoreVisitorT >
341 const PointCloud&
pc,
float epsilon,
float normalThresh,