Fixed Vineyard to preserve the vine addresses after we add a new dimension vine (was a major bug)
--- a/include/topology/vineyard.h Fri Feb 29 15:46:12 2008 -0500
+++ b/include/topology/vineyard.h Fri Feb 29 19:43:11 2008 -0500
@@ -35,7 +35,8 @@
typedef Vine<Simplex> Vine;
typedef Knee<Simplex> Knee;
typedef std::list<Vine> VineList;
- typedef std::vector<VineList> VineListVector;
+ typedef std::list<VineList> VineListList;
+ typedef std::vector<typename VineListList::iterator> VineListVector;
typedef typename FiltrationSimplex::Cycle Cycle;
typedef typename FiltrationSimplex::Index Index;
@@ -61,7 +62,8 @@
void start_vine(Index i);
private:
- VineListVector vines;
+ VineListList vines; // stores vine lists
+ VineListVector vines_vector; // stores pointers (iterators) to vine lists
Evaluator* evaluator;
};
@@ -117,10 +119,14 @@
public:
typedef S Simplex;
typedef Knee<Simplex> Knee;
- typedef std::list<Knee> VineRepresentation;
+ typedef std::list<Knee> VineRepresentation;
typedef typename VineRepresentation::const_iterator const_knee_iterator;
Vine() {}
+ Vine(const Vine& other):
+ VineRepresentation(other) {}
+ Vine(const VineRepresentation& other):
+ VineRepresentation(other) {}
Vine(const Knee& k) { add(k); }
void add(RealType b, RealType d, RealType t) { push_back(Knee(b,d,t)); }
--- a/include/topology/vineyard.hpp Fri Feb 29 15:46:12 2008 -0500
+++ b/include/topology/vineyard.hpp Fri Feb 29 19:43:11 2008 -0500
@@ -23,7 +23,8 @@
if (dim >= vines.size())
{
AssertMsg(dim == vines.size(), "New dimension has to be contiguous");
- vines.push_back(std::list<Vine>());
+ vines.push_back(VineList());
+ vines_vector.push_back(boost::prior(vines.end()));
}
start_vine(cur);
@@ -60,8 +61,8 @@
AssertMsg(i->sign(), "Can only start vines for positive simplices");
Dimension dim = i->dimension();
- vines[dim].push_back(Vine());
- i->set_vine(&vines[dim].back());
+ vines_vector[dim]->push_back(Vine());
+ i->set_vine(&vines_vector[dim]->back());
i->pair()->set_vine(i->vine());
}
@@ -88,12 +89,12 @@
Vineyard<FS>::
save_edges(const std::string& filename) const
{
- for (unsigned int i = 0; i < vines.size(); ++i)
+ for (unsigned int i = 0; i < vines_vector.size(); ++i)
{
std::ostringstream os; os << i;
std::string fn = filename + os.str() + ".edg";
std::ofstream out(fn.c_str());
- for (typename VineList::const_iterator vi = vines[i].begin(); vi != vines[i].end(); ++vi)
+ for (typename VineList::const_iterator vi = vines_vector[i]->begin(); vi != vines_vector[i]->end(); ++vi)
for (typename Vine::const_iterator ki = vi->begin(), kiprev = ki++; ki != vi->end(); kiprev = ki++)
{
if (kiprev->is_infinite() || ki->is_infinite()) continue;