Add diagram_point::get_persistence(order, func)
[libstick.git] / include / libstick / persistence.h
index 481d6480d2dd50821d82845672fdf0dd45873673..72b07b813944d758fe4927484d4fb03f96651926 100644 (file)
@@ -35,6 +35,34 @@ class persistence {
              * zero, the cycle never dies. Otherwise, 'death' is always larger
              * than 'birth'. */
             IT death;
+
+
+            /** Get the value of the birth index w.r.t. to a simplicial order o
+             * and a simplicial function f. Requires that o and f are defined
+             * on the same simplicial complex. */
+            template<class VT>
+            VT get_birth_value(const simplex_order &o, const simplicial_function<MAXDIM, IT, VT> &f) const {
+                assert(&f.get_complex() == &o.get_complex());
+                return f.get_value(o.order_to_complex(birth));
+            }
+
+            /** Get the value of the death index w.r.t. to a simplicial order o
+             * and a simplicial function f. Requires that o and f are defined
+             * on the same simplicial complex. */
+            template<class VT>
+            VT get_death_value(const simplex_order &o, const simplicial_function<MAXDIM, IT, VT> &f) const {
+                assert(&f.get_complex() == &o.get_complex());
+                return f.get_value(o.order_to_complex(death));
+            }
+
+            /** Get the persistence of this point w.r.t. to a simplicial order
+             * o and a simplicial function f. Requires that o and f are defined
+             * on the same simplicial complex. */
+            template<class VT>
+            VT get_persistence(const simplex_order &o, const simplicial_function<MAXDIM, IT, VT> &f) const {
+                assert(&f.get_complex() == &o.get_complex());
+                return get_death_value<VT>(o, f) - get_birth_value<VT>(o, f);
+            }
         };
 
         /** Save the births and deaths of simplices of a fixed dimension, say p. */
@@ -302,12 +330,8 @@ class persistence {
                     if (death > 0) {
                         os << birth << "\033[1;31m -> " << death << "\033[0;m";
 
-                        if (f != NULL) {
-                            const IT birth_idx = order.order_to_complex(birth);
-                            const IT death_idx = order.order_to_complex(death);
-                            const VT pers = f->get_value(death_idx) - f->get_value(birth_idx);
-                            os << " \tpers: " << pers;
-                        }
+                        if (f != NULL)
+                            os << " \tpers: " << dia.births[i].get_persistence(get_order(), *f);
                     } else {
                         os << "\033[1;32m" << birth << "\033[0;m";
                         if (f != NULL)