diff options
Diffstat (limited to 'src/GudhUI/utils')
-rw-r--r-- | src/GudhUI/utils/Bar_code_persistence.h | 90 | ||||
-rw-r--r-- | src/GudhUI/utils/Edge_contractor.h | 2 | ||||
-rw-r--r-- | src/GudhUI/utils/Furthest_point_epsilon_net.h | 2 | ||||
-rw-r--r-- | src/GudhUI/utils/Is_manifold.h | 2 | ||||
-rw-r--r-- | src/GudhUI/utils/K_nearest_builder.h | 10 | ||||
-rw-r--r-- | src/GudhUI/utils/Persistence_compute.h | 14 |
6 files changed, 101 insertions, 19 deletions
diff --git a/src/GudhUI/utils/Bar_code_persistence.h b/src/GudhUI/utils/Bar_code_persistence.h new file mode 100644 index 00000000..b527d684 --- /dev/null +++ b/src/GudhUI/utils/Bar_code_persistence.h @@ -0,0 +1,90 @@ +#include <math.h> // isfinite + +#include <QtGui/QApplication> + +#include <QGraphicsView> +#include <QGraphicsScene> +#include <QPointF> +#include <QVector> +#include <QGraphicsTextItem> + +#include <iostream> +#include <vector> +#include <limits> // NaN, infinity +#include <utility> // for pair +#include <string> + +#ifndef UTILS_BAR_CODE_PERSISTENCE_H_ +#define UTILS_BAR_CODE_PERSISTENCE_H_ + +class Bar_code_persistence { + private: + typedef std::vector<std::pair<double, double>> Persistence; + Persistence persistence_vector; + double min_birth; + double max_death; + + public: + Bar_code_persistence() + : min_birth(std::numeric_limits<double>::quiet_NaN()), + max_death(std::numeric_limits<double>::quiet_NaN()) { } + + void insert(double birth, double death) { + persistence_vector.push_back(std::make_pair(birth, death)); + if (std::isfinite(birth)) { + if ((birth < min_birth) || (std::isnan(min_birth))) + min_birth = birth; + if ((birth > max_death) || (std::isnan(max_death))) + max_death = birth; + } + if (std::isfinite(death)) + if ((death > max_death) || (std::isnan(max_death))) + max_death = death; + } + + void show(const std::string& window_title) { + // Create a view, put a scene in it + QGraphicsView * view = new QGraphicsView(); + QGraphicsScene * scene = new QGraphicsScene(); + view->setScene(scene); + double ratio = 600.0 / (max_death - min_birth); + // std::cout << "min_birth=" << min_birth << " - max_death=" << max_death << " - ratio=" << ratio << std::endl; + + double height = 0.0, birth = 0.0, death = 0.0; + int pers_num = 1; + for (auto& persistence : persistence_vector) { + height = 5.0 * pers_num; + // std::cout << "[" << pers_num << "] birth=" << persistence.first << " - death=" << persistence.second << std::endl; + if (std::isfinite(persistence.first)) + birth = ((persistence.first - min_birth) * ratio) + 50.0; + else + birth = 0.0; + + if (std::isfinite(persistence.second)) + death = ((persistence.second - min_birth) * ratio) + 50.0; + else + death = 700.0; + + scene->addLine(birth, height, death, height, QPen(Qt::blue, 2)); + pers_num++; + } + height += 10.0; + // scale line + scene->addLine(0, height, 700.0, height, QPen(Qt::black, 1)); + int modulo = 0; + for (double scale = 50.0; scale < 700.0; scale += 50.0) { + modulo++; + // scale small dash + scene->addLine(scale, height - 3.0, scale, height + 3.0, QPen(Qt::black, 1)); + // scale text + QString scale_value = QString::number(((scale - 50.0) / ratio) + min_birth); + QGraphicsTextItem* dimText = scene->addText(scale_value, QFont("Helvetica", 8)); + dimText->setPos(scale - (3.0 * scale_value.size()), height + 9.0 * (modulo % 2)); + } + view->setWindowTitle(window_title.c_str()); + // Show the view + view->show(); + } +}; + +#endif // UTILS_BAR_CODE_PERSISTENCE_H_ diff --git a/src/GudhUI/utils/Edge_contractor.h b/src/GudhUI/utils/Edge_contractor.h index 45079a40..8a29ff4b 100644 --- a/src/GudhUI/utils/Edge_contractor.h +++ b/src/GudhUI/utils/Edge_contractor.h @@ -65,7 +65,7 @@ template<typename SkBlComplex> class Edge_contractor { Placement_type operator()(const EdgeProfile& profile) const override { std::vector<double> mid_coords(profile.p0().dimension(), 0); - for (size_t i = 0; i < profile.p0().dimension(); ++i) { + for (int i = 0; i < profile.p0().dimension(); ++i) { mid_coords[i] = (profile.p0()[i] + profile.p1()[i]) / 2.; } return Point(profile.p0().dimension(), mid_coords.begin(), mid_coords.end()); diff --git a/src/GudhUI/utils/Furthest_point_epsilon_net.h b/src/GudhUI/utils/Furthest_point_epsilon_net.h index f2a216f6..98346daa 100644 --- a/src/GudhUI/utils/Furthest_point_epsilon_net.h +++ b/src/GudhUI/utils/Furthest_point_epsilon_net.h @@ -73,7 +73,7 @@ template<typename SkBlComplex> class Furthest_point_epsilon_net { complex_(complex) { if (!complex.empty()) { init_filtration(); - for (int k = 2; k < net_filtration_.size(); ++k) { + for (std::size_t k = 2; k < net_filtration_.size(); ++k) { update_radius_value(k); } } diff --git a/src/GudhUI/utils/Is_manifold.h b/src/GudhUI/utils/Is_manifold.h index b6b19ee0..0640ea47 100644 --- a/src/GudhUI/utils/Is_manifold.h +++ b/src/GudhUI/utils/Is_manifold.h @@ -69,7 +69,7 @@ template<typename SkBlComplex> class Is_manifold { private: unsigned local_dimension(Vertex_handle v) { unsigned dim = 0; - for (const auto& s : input_complex_.simplex_range(v)) + for (const auto& s : input_complex_.star_simplex_range(v)) dim = (std::max)(dim, (unsigned) s.dimension()); return dim; } diff --git a/src/GudhUI/utils/K_nearest_builder.h b/src/GudhUI/utils/K_nearest_builder.h index cab24b7c..7be0a4f4 100644 --- a/src/GudhUI/utils/K_nearest_builder.h +++ b/src/GudhUI/utils/K_nearest_builder.h @@ -29,12 +29,10 @@ #include <CGAL/Search_traits_d.h> #include <CGAL/Search_traits_adapter.h> #include <CGAL/property_map.h> -#include <boost/iterator/iterator_facade.hpp> -#include <boost/iterator/zip_iterator.hpp> #include <unordered_map> -#include <tuple> #include <list> +#include <utility> #include "utils/UI_utils.h" #include "model/Complex_typedefs.h" @@ -43,9 +41,9 @@ template<typename SkBlComplex> class K_nearest_builder { private: typedef Geometry_trait Kernel; typedef Point Point_d; - typedef boost::tuple<Point_d, unsigned> Point_d_with_id; + typedef std::pair<Point_d, unsigned> Point_d_with_id; typedef CGAL::Search_traits_d<Kernel> Traits_base; - typedef CGAL::Search_traits_adapter<Point_d_with_id, CGAL::Nth_of_tuple_property_map<0, Point_d_with_id>, + typedef CGAL::Search_traits_adapter<Point_d_with_id, CGAL::First_of_pair_property_map<Point_d_with_id>, Traits_base> Traits; typedef CGAL::Orthogonal_k_neighbor_search<Traits> Neighbor_search; typedef Neighbor_search::Tree Tree; @@ -81,7 +79,7 @@ template<typename SkBlComplex> class K_nearest_builder { for (auto p : complex_.vertex_range()) { Neighbor_search search(tree, complex_.point(p), k + 1); for (auto it = ++search.begin(); it != search.end(); ++it) { - Vertex_handle q(boost::get<1>(it->first)); + Vertex_handle q(std::get<1>(it->first)); if (p != q && complex_.contains_vertex(p) && complex_.contains_vertex(q)) complex_.add_edge(p, q); } diff --git a/src/GudhUI/utils/Persistence_compute.h b/src/GudhUI/utils/Persistence_compute.h index 0b9961d3..97165490 100644 --- a/src/GudhUI/utils/Persistence_compute.h +++ b/src/GudhUI/utils/Persistence_compute.h @@ -46,10 +46,6 @@ struct Persistence_params { * Show persistence into output stream */ template<typename SkBlComplex> class Persistence_compute { - private: - SkBlComplex& complex_; - std::ostream& stream_; - public: typedef typename SkBlComplex::Vertex_handle Vertex_handle; typedef typename SkBlComplex::Edge_handle Edge_handle; @@ -61,9 +57,7 @@ template<typename SkBlComplex> class Persistence_compute { * double threshold * int p for coefficient Z_p */ - Persistence_compute(SkBlComplex& complex, std::ostream& stream, const Persistence_params& params) : - // double threshold = 0.5,unsigned dim_max = 8): - complex_(complex), stream_(stream) { + Persistence_compute(SkBlComplex& complex, std::ostream& stream, const Persistence_params& params) { // for now everything is copied, todo boost adapt iterators to points of SkBlComplex instead of copying to an // initial vector typedef std::vector<double> Point_t; @@ -87,10 +81,10 @@ template<typename SkBlComplex> class Persistence_compute { pcoh.init_coefficients(params.p); // put params.min_pers pcoh.compute_persistent_cohomology(params.min_pers); - stream_ << "persistence: \n"; - stream_ << "p dimension birth death: \n"; + stream << "persistence: \n"; + stream << "p dimension birth death: \n"; - pcoh.output_diagram(stream_); + pcoh.output_diagram(stream); } }; |