create the primitive only if the propagation was successful

This commit is contained in:
Sébastien Loriot 2023-01-31 11:49:29 +01:00
parent 464f5a0d46
commit 331323ea44
1 changed files with 3 additions and 8 deletions

View File

@ -223,14 +223,13 @@ namespace Shape_detection {
// Try to grow a new region from the index of the seed item.
if (!get(m_visited, seed)) {
typename Region_type::Primitive primitive = m_region_type.primitive();
const bool is_success = propagate(seed, region, primitive);
const bool is_success = propagate(seed, region);
// Check global conditions.
if (!is_success || !m_region_type.is_valid_region(region)) {
revert(region);
} else {
*(region_out++) = std::pair<typename RegionType::Primitive, Region>(primitive, region);
*(region_out++) = std::pair<typename RegionType::Primitive, Region>(m_region_type.primitive(), region);
fill_region_map(m_nb_regions++, region);
}
}
@ -336,7 +335,7 @@ namespace Shape_detection {
}
}
bool propagate(const Item &seed, Region& region, typename RegionType::Primitive &primitive) {
bool propagate(const Item &seed, Region& region) {
region.clear();
// Use two queues, while running on this queue, push to the other queue;
@ -352,7 +351,6 @@ namespace Shape_detection {
// Update internal properties of the region.
const bool is_well_created = m_region_type.update(region);
primitive = m_region_type.primitive();
if (!is_well_created) return false;
bool grown = true;
@ -423,9 +421,6 @@ namespace Shape_detection {
return true;
}
// If it fits, update the primitive.
primitive = m_region_type.primitive();
// Try to continue growing the region by considering formerly rejected elements.
for (const std::pair<const Item, const Item>& p : rejected) {
if (m_region_type.is_part_of_region(p.first, p.second, region)) {