summaryrefslogtreecommitdiff
path: root/src/GudhUI/utils/Critical_points.h
diff options
context:
space:
mode:
authorvrouvrea <vrouvrea@636b058d-ea47-450e-bf9e-a15bfbe3eedb>2015-10-08 21:15:51 +0000
committervrouvrea <vrouvrea@636b058d-ea47-450e-bf9e-a15bfbe3eedb>2015-10-08 21:15:51 +0000
commitcd2e83819689afd2cd1bc76810282111cf5cd59d (patch)
tree8cf97b1f5a8589fa160d03248ca3f429b436b814 /src/GudhUI/utils/Critical_points.h
parent58e633f51ffa06aa219231cd1c08eab59457a12f (diff)
cpplint fixes on GudhUI
git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/trunk@844 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 3acf1e789f3e4bded974f324ce3161bc1d1d2433
Diffstat (limited to 'src/GudhUI/utils/Critical_points.h')
-rw-r--r--src/GudhUI/utils/Critical_points.h203
1 files changed, 99 insertions, 104 deletions
diff --git a/src/GudhUI/utils/Critical_points.h b/src/GudhUI/utils/Critical_points.h
index 92392d4a..3021a5fe 100644
--- a/src/GudhUI/utils/Critical_points.h
+++ b/src/GudhUI/utils/Critical_points.h
@@ -1,13 +1,10 @@
-/*
- * Critical_points.h
- * Created on: Jan 27, 2015
- * This file is part of the Gudhi Library. The Gudhi library
+/* This file is part of the Gudhi Library. The Gudhi library
* (Geometric Understanding in Higher Dimensions) is a generic C++
* library for computational topology.
*
* Author(s): David Salinas
*
- * Copyright (C) 2014 INRIA Sophia Antipolis-Méditerranée (France)
+ * Copyright (C) 2014 INRIA Sophia Antipolis-Mediterranee (France)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -24,11 +21,13 @@
*
*/
-
-#ifndef CRITICAL_POINTS_H_
-#define CRITICAL_POINTS_H_
+#ifndef UTILS_CRITICAL_POINTS_H_
+#define UTILS_CRITICAL_POINTS_H_
#include <deque>
+#include <utility> // for pair<>
+#include <algorithm> // for sort
+
#include "utils/Edge_contractor.h"
/**
@@ -37,101 +36,97 @@
*
* todo do a sparsification with some parameter eps while growing
*/
-template<typename SkBlComplex> class Critical_points{
-private:
- SkBlComplex filled_complex_;
- const SkBlComplex& input_complex_;
- double max_length_;
- std::ostream& stream_;
-public:
- typedef typename SkBlComplex::Vertex_handle Vertex_handle;
- typedef typename SkBlComplex::Edge_handle Edge_handle;
- typedef typename std::pair<Vertex_handle,Vertex_handle> Edge;
-
- /**
- * @brief check all pair of points with length smaller than max_length
- */
- Critical_points(const SkBlComplex& input_complex,std::ostream& stream,double max_length):
- input_complex_(input_complex),max_length_(max_length),stream_(stream)
- {
-
- std::deque<Edge> edges;
- auto vertices = input_complex.vertex_range();
- for(auto p = vertices.begin(); p!= vertices.end(); ++p){
- filled_complex_.add_vertex(input_complex.point(*p));
- for (auto q = p; ++q != vertices.end(); /**/)
- if (squared_eucl_distance(input_complex.point(*p),input_complex.point(*q)) < max_length_*max_length_)
- edges.emplace_back(*p,*q);
- }
-
- std::sort(edges.begin(),edges.end(),
- [&](Edge e1,Edge e2){
- return squared_edge_length(e1) < squared_edge_length(e2);
- });
-
- anti_collapse_edges(edges);
-
- }
-
-private:
- double squared_eucl_distance(const Point& p1,const Point& p2) const{
- return Geometry_trait::Squared_distance_d()(p1,p2);
- }
-
-
- void anti_collapse_edges(const std::deque<Edge>& edges){
- unsigned pos = 0;
- for(Edge e : edges){
- std::cout<<"edge "<<pos++<<"/"<<edges.size()<<"\n";
- auto eh = filled_complex_.add_edge(e.first,e.second);
- int is_contractible(is_link_reducible(eh));
-
- switch (is_contractible) {
- case 0:
- stream_<<"alpha="<<std::sqrt(squared_edge_length(e))<< " topological change"<<std::endl;
- break;
- case 2:
- stream_<<"alpha="<<std::sqrt(squared_edge_length(e))<< " maybe a topological change"<<std::endl;
- break;
- default:
- break;
- }
- }
-
- }
-
-
- //0 -> not
- //1 -> yes
- //2 -> maybe
- int is_link_reducible(Edge_handle e){
- auto link = filled_complex_.link(e);
-
- if(link.empty()) return 0;
-
- Edge_contractor<Complex> contractor(link,link.num_vertices()-1);
-
- if(link.num_connected_components()>1) return 0; //one than more CC -> not contractible
-
- if (link.num_vertices()==1) return 1; //reduced to one point -> contractible
- else return 2; //we dont know
- }
-
-
- double squared_edge_length(Edge_handle e) const{
- return squared_eucl_distance(input_complex_.point(input_complex_.first_vertex(e)),input_complex_.point(input_complex_.second_vertex(e)));
- }
-
- double squared_edge_length(Edge e) const{
- return squared_eucl_distance(input_complex_.point(e.first),input_complex_.point(e.second));
- }
-
-
-
+template<typename SkBlComplex> class Critical_points {
+ private:
+ SkBlComplex filled_complex_;
+ const SkBlComplex& input_complex_;
+ double max_length_;
+ std::ostream& stream_;
+
+ public:
+ typedef typename SkBlComplex::Vertex_handle Vertex_handle;
+ typedef typename SkBlComplex::Edge_handle Edge_handle;
+ typedef typename std::pair<Vertex_handle, Vertex_handle> Edge;
+
+ /**
+ * @brief check all pair of points with length smaller than max_length
+ */
+ Critical_points(const SkBlComplex& input_complex, std::ostream& stream, double max_length) :
+ input_complex_(input_complex), max_length_(max_length), stream_(stream) {
+ std::deque<Edge> edges;
+ auto vertices = input_complex.vertex_range();
+ for (auto p = vertices.begin(); p != vertices.end(); ++p) {
+ filled_complex_.add_vertex(input_complex.point(*p));
+ for (auto q = p; ++q != vertices.end(); /**/)
+ if (squared_eucl_distance(input_complex.point(*p), input_complex.point(*q)) < max_length_ * max_length_)
+ edges.emplace_back(*p, *q);
+ }
+
+ std::sort(edges.begin(), edges.end(),
+ [&](Edge e1, Edge e2) {
+ return squared_edge_length(e1) < squared_edge_length(e2);
+ });
+
+ anti_collapse_edges(edges);
+ }
+
+ private:
+ double squared_eucl_distance(const Point& p1, const Point& p2) const {
+ return Geometry_trait::Squared_distance_d()(p1, p2);
+ }
+
+ void anti_collapse_edges(const std::deque<Edge>& edges) {
+ unsigned pos = 0;
+ for (Edge e : edges) {
+ std::cout << "edge " << pos++ << "/" << edges.size() << "\n";
+ auto eh = filled_complex_.add_edge(e.first, e.second);
+ int is_contractible(is_link_reducible(eh));
+
+ switch (is_contractible) {
+ case 0:
+ stream_ << "alpha=" << std::sqrt(squared_edge_length(e)) << " topological change" << std::endl;
+ break;
+ case 2:
+ stream_ << "alpha=" << std::sqrt(squared_edge_length(e)) << " maybe a topological change" << std::endl;
+ break;
+ default:
+ break;
+ }
+ }
+ }
+
+ // 0 -> not
+ // 1 -> yes
+ // 2 -> maybe
+
+ int is_link_reducible(Edge_handle e) {
+ auto link = filled_complex_.link(e);
+
+ if (link.empty())
+ return 0;
+
+ Edge_contractor<Complex> contractor(link, link.num_vertices() - 1);
+
+ if (link.num_connected_components() > 1)
+ // one than more CC -> not contractible
+ return 0;
+
+ if (link.num_vertices() == 1)
+ // reduced to one point -> contractible
+ return 1;
+ else
+ // we dont know
+ return 2;
+ }
+
+ double squared_edge_length(Edge_handle e) const {
+ return squared_eucl_distance(input_complex_.point(input_complex_.first_vertex(e)),
+ input_complex_.point(input_complex_.second_vertex(e)));
+ }
+
+ double squared_edge_length(Edge e) const {
+ return squared_eucl_distance(input_complex_.point(e.first), input_complex_.point(e.second));
+ }
};
-
-
-
-
-#endif /* CRITICAL_POINTS_H_ */
+#endif // UTILS_CRITICAL_POINTS_H_