void init( Visitor& visitor, Scalar dmax ) { myNodes.clear(); Node node; while ( ! visitor.finished() ) { node = visitor.current(); myNodes.push_back( node ); if ( node.second > dmax ) break; visitor.expand(); } }
void testBreadthFirstPropagation() { typedef Z2i::Point Point; typedef Z2i::Domain Domain; typedef Z2i::DigitalSet DigitalSet; typedef Z2i::Object4_8 Object; BOOST_CONCEPT_ASSERT(( CUndirectedSimpleGraph<Z2i::Object4_8> )); Point p1( -41, -36 ); Point p2( 18, 18 ); Domain domain( p1, p2 ); Point c1( -2, -1 ); Point c2( -14, 5 ); Point c3( -30, -15 ); Point c4( -10, -20 ); Point c5( 12, -1 ); DigitalSet shape_set( domain ); Shapes<Domain>::addNorm2Ball( shape_set, c1, 9 ); Shapes<Domain>::addNorm1Ball( shape_set, c2, 9 ); Shapes<Domain>::addNorm1Ball( shape_set, c3, 10 ); Shapes<Domain>::addNorm2Ball( shape_set, c4, 12 ); Shapes<Domain>::addNorm1Ball( shape_set, c5, 4 ); Object obj(Z2i::dt4_8, shape_set); GradientColorMap<int> cmap_grad( 0, 52); cmap_grad.addColor( Color( 0, 0, 255 ) ); cmap_grad.addColor( Color( 0, 255, 0 ) ); cmap_grad.addColor( Color( 255, 0, 0 ) ); Board2D board; board << SetMode( domain.className(), "Paving" ) << domain << SetMode( p1.className(), "Paving" ); Image image = ImageFromSet<Image>::create(shape_set, 1); typedef BreadthFirstVisitor<Object, set<Point> > Visitor; BOOST_CONCEPT_ASSERT(( CGraphVisitor< Visitor > )); Visitor bfv (obj, c1); while( !bfv.finished() ) { image.setValue(bfv.current().first, bfv.current().second); bfv.expand(); } string specificStyle = p1.className() + "/Paving"; for ( DigitalSet::ConstIterator it = shape_set.begin(); it != shape_set.end(); ++it ) { if( image(*it) == 0) { board << CustomStyle( specificStyle, new CustomColors( Color::Black, Color::Red ) ) << *it; } else { if( image(*it) > 0 ) { board << CustomStyle( specificStyle, new CustomColors( Color::Black, cmap_grad( image(*it) ) ) ) << *it; } else { board << CustomStyle( specificStyle, new CustomColors( Color::Black, cmap_grad( 0 ) ) ) << *it; } } } board.saveEPS("testBreadthFirstPropagation.eps"); }
void StaticPersistence<D, CT, OT, E, Cmp>:: pair_simplices(iterator bg, iterator end, bool store_negative, const Visitor& visitor) { #if LOGGING typename ContainerTraits::OutputMap outmap(order_); #endif // FIXME: need sane output for logging rLog(rlPersistence, "Entered: pair_simplices"); for (iterator j = bg; j != end; ++j) { visitor.init(j); rLog(rlPersistence, "Simplex %s", outmap(j).c_str()); Cycle z; swap_cycle(j, z); rLog(rlPersistence, " has boundary: %s", z.tostring(outmap).c_str()); // Sparsify the cycle by removing the negative elements if (!store_negative) { typename OrderElement::Cycle zz; BOOST_FOREACH(OrderIndex i, z) if (i->sign()) // positive zz.push_back(i); z.swap(zz); } // -------------------------- CountNum(cPersistencePairBoundaries, z.size()); #ifdef COUNTERS Count(cPersistencePair); #endif // COUNTERS while(!z.empty()) { OrderIndex i = z.top(ocmp_); // take the youngest element with respect to the OrderComparison rLog(rlPersistence, " %s: %s", outmap(i).c_str(), outmap(i->pair).c_str()); // TODO: is this even a meaningful assert? AssertMsg(!ocmp_(i, index(j)), "Simplices in the cycle must precede current simplex: (%s in cycle of %s)", outmap(i).c_str(), outmap(j).c_str()); // i is not paired, so we pair j with i if (iterator_to(i->pair) == iterator_to(i)) { rLog(rlPersistence, " Pairing %s and %s with cycle %s", outmap(i).c_str(), outmap(j).c_str(), z.tostring(outmap).c_str()); set_pair(i, j); swap_cycle(j, z); set_pair(j, i); CountNum(cPersistencePairCycleLength, j->cycle.size()); CountBy (cPersistencePairCycleLength, j->cycle.size()); break; } // update element z.add(i->pair->cycle, ocmp_); visitor.update(j, iterator_to(i)); rLog(rlPersistence, " new cycle: %s", z.tostring(outmap).c_str()); } // if z was empty, so is (already) j->cycle, so nothing to do visitor.finished(j); rLog(rlPersistence, "Finished with %s: %s", outmap(j).c_str(), outmap(j->pair).c_str()); }