summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsalinasd <salinasd@636b058d-ea47-450e-bf9e-a15bfbe3eedb>2015-01-29 09:09:18 +0000
committersalinasd <salinasd@636b058d-ea47-450e-bf9e-a15bfbe3eedb>2015-01-29 09:09:18 +0000
commit52bca1c4334e8abe965d616e1ef8a92280013a9b (patch)
treeb4a62dcb5e8224330cb821d4308db62d509397d2
parentc01198fed2d886c45e007b5532c56403fc465c78 (diff)
test is manifold
git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/trunk@437 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: a515b3216d21c8a5736744842fdcf09644f5c7b1
-rw-r--r--src/GudhUI/gui/MainWindow.cpp11
-rw-r--r--src/GudhUI/gui/MainWindow.h1
-rw-r--r--src/GudhUI/gui/main_window.ui6
-rw-r--r--src/GudhUI/model/Model.h59
-rw-r--r--src/GudhUI/utils/Critical_points.h137
-rw-r--r--src/GudhUI/utils/Edge_collapsor.h9
-rw-r--r--src/GudhUI/utils/Is_manifold.h104
7 files changed, 316 insertions, 11 deletions
diff --git a/src/GudhUI/gui/MainWindow.cpp b/src/GudhUI/gui/MainWindow.cpp
index f5abfffc..e41b15ba 100644
--- a/src/GudhUI/gui/MainWindow.cpp
+++ b/src/GudhUI/gui/MainWindow.cpp
@@ -98,6 +98,9 @@ MainWindow::connectActions(){
SLOT(persistence_menu()));
QObject::connect(this->actionEstimate_topological_changes, SIGNAL(triggered()), this,
SLOT(critical_points_menu()));
+ QObject::connect(this->actionIs_manifold, SIGNAL(triggered()), this,
+ SLOT(is_manifold_menu()));
+
QObject::connect(this, SIGNAL(sceneChanged()), this->viewer_instructor_,
SLOT(sceneChanged()));
@@ -223,8 +226,7 @@ MainWindow::contract_edges(unsigned num_collapses){
void
MainWindow::collapse_edges(){
- std::cerr <<"Collapse "<<100<< " edges\n";
- model_.collapse_edges(100);
+ model_.collapse_edges(model_.num_edges());
update_view();
}
@@ -287,5 +289,10 @@ MainWindow::critical_points_menu(){
model_.show_critical_points(max_length);
}
+void
+MainWindow::is_manifold_menu(){
+ model_.show_is_manifold();
+}
+
#include "MainWindow.moc"
diff --git a/src/GudhUI/gui/MainWindow.h b/src/GudhUI/gui/MainWindow.h
index 506a1f3a..587f1c6f 100644
--- a/src/GudhUI/gui/MainWindow.h
+++ b/src/GudhUI/gui/MainWindow.h
@@ -84,6 +84,7 @@ public:
void persistence_menu();
void compute_persistence(int p,double threshold,int max_dim,double min_pers);
void critical_points_menu();
+ void is_manifold_menu();
public:
diff --git a/src/GudhUI/gui/main_window.ui b/src/GudhUI/gui/main_window.ui
index 8a7ad7da..312480b6 100644
--- a/src/GudhUI/gui/main_window.ui
+++ b/src/GudhUI/gui/main_window.ui
@@ -90,6 +90,7 @@
<addaction name="actionShow_homology_group"/>
<addaction name="actionPersistence"/>
<addaction name="actionEstimate_topological_changes"/>
+ <addaction name="actionIs_manifold"/>
</widget>
<addaction name="menuFile"/>
<addaction name="menuPoints"/>
@@ -236,6 +237,11 @@
<bool>false</bool>
</property>
</action>
+ <action name="actionIs_manifold">
+ <property name="text">
+ <string>Is manifold</string>
+ </property>
+ </action>
</widget>
<customwidgets>
<customwidget>
diff --git a/src/GudhUI/model/Model.h b/src/GudhUI/model/Model.h
index 39bbd9d8..6ac971d0 100644
--- a/src/GudhUI/model/Model.h
+++ b/src/GudhUI/model/Model.h
@@ -20,6 +20,7 @@
#include "utils/Edge_contractor.h"
#include "utils/Persistence_compute.h"
#include "utils/Critical_points.h"
+#include "utils/Is_manifold.h"
#include "gudhi/Skeleton_blocker/Skeleton_blocker_simple_geometric_traits.h"
#include "gudhi/Skeleton_blocker_geometric_complex.h"
@@ -56,8 +57,9 @@ public:
void maximal_face(std::vector<int> vertices){
if (!load_only_points_){
- for (int i = 0; i<vertices.size()-1 ; ++i)
- for (int j = i+1; j<vertices.size()-1 ; ++j)
+ std::cout<<"size:"<<vertices.size()<<std::endl;
+ for (int i = 0; i<vertices.size() ; ++i)
+ for (int j = i+1; j<vertices.size() ; ++j)
complex_.add_edge(Vertex_handle(vertices[i]),Vertex_handle(vertices[j]));
}
}
@@ -80,23 +82,54 @@ public:
void off_file_open(const std::string& name_file){
UIDBGMSG("load off file",name_file);
complex_.clear();
- CGAL_geometric_flag_complex_wrapper<Complex> read_wraper(complex_);
+ CGAL_geometric_flag_complex_wrapper<Complex> read_wraper(complex_,false);
Gudhi::read_off(name_file,read_wraper);
}
void off_points_open(const std::string& name_file){
UIDBGMSG("load off points",name_file);
complex_.clear();
- CGAL_geometric_flag_complex_wrapper<Complex> read_wraper(complex_);
+ CGAL_geometric_flag_complex_wrapper<Complex> read_wraper(complex_,true);
Gudhi::read_off(name_file,read_wraper);
}
void off_file_save(const std::string& name_file){
UIDBG("save off file");
+ UIDBG("save off off_points_save");
+ std::ofstream file(name_file);
+ if(file.is_open()){
+ file<<"OFF\n";
+ file<<complex_.num_vertices()<<" "<<complex_.num_edges()<<" 0\n";
+ for(auto v : complex_.vertex_range()){
+ const auto& pt(complex_.point(v));
+ for(auto it = pt.cartesian_begin();it!=pt.cartesian_end();++it)
+ file<<*it<<" ";
+ file<<std::endl;
+ }
+ for(auto e : complex_.edge_range())
+ file<<"2 "<<complex_.first_vertex(e)<<" "<<complex_.second_vertex(e)<<"\n";
+ file.close();
+ }
+ else std::cerr << "Could not open file "<<name_file<<std::endl;
+
}
void off_points_save(const std::string& name_file){
UIDBG("save off off_points_save");
+ std::ofstream file(name_file);
+ if(file.is_open()){
+ file<<"OFF\n";
+ file<<complex_.num_vertices()<<" 0 0\n";
+ for(auto v : complex_.vertex_range()){
+ const auto& pt(complex_.point(v));
+ for(auto it = pt.cartesian_begin();it!=pt.cartesian_end();++it)
+ file<<*it<<" ";
+ file<<std::endl;
+ }
+ file.close();
+ }
+ else std::cerr << "Could not open file "<<name_file<<std::endl;
+
}
// point sets operations
@@ -160,7 +193,7 @@ public:
}
void collapse_edges(unsigned num_collapses){
- Edge_collapsor<Complex> collapsor(complex_,complex_.num_edges());
+ Edge_collapsor<Complex> collapsor(complex_,num_collapses);
}
@@ -268,6 +301,17 @@ public:
Critical_points<Complex> critical_points(complex_,std::cout,max_distance);
}
+ void show_is_manifold(){
+ unsigned dim;
+ bool is_manifold;
+ Is_manifold<Complex> test_manifold(complex_,dim,is_manifold);
+
+ if(is_manifold) std::cout << "The complex is a "<<dim<<"-manifold\n";
+ else
+ if(dim<4) std::cout << "The complex has dimension greater than "<<dim<<" and is not a manifold\n";
+ else std::cout << "The complex has dimension>=4 and may or may not be a manifold\n";
+ }
+
private:
void run_chomp(){
@@ -296,6 +340,11 @@ public:
unsigned num_vertices() const{
return complex_.num_vertices();
}
+
+ unsigned num_edges() const{
+ return complex_.num_edges();
+ }
+
};
#endif /* MODEL_H_ */
diff --git a/src/GudhUI/utils/Critical_points.h b/src/GudhUI/utils/Critical_points.h
new file mode 100644
index 00000000..92392d4a
--- /dev/null
+++ b/src/GudhUI/utils/Critical_points.h
@@ -0,0 +1,137 @@
+/*
+ * Critical_points.h
+ * Created on: Jan 27, 2015
+ * 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)
+ *
+ * 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
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+
+#ifndef CRITICAL_POINTS_H_
+#define CRITICAL_POINTS_H_
+
+#include <deque>
+#include "utils/Edge_contractor.h"
+
+/**
+ * Iteratively tries to anticollapse smallest edge non added so far.
+ * If its link is contractible then no topological change and else possible topological change.
+ *
+ * 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));
+ }
+
+
+
+};
+
+
+
+
+
+#endif /* CRITICAL_POINTS_H_ */
diff --git a/src/GudhUI/utils/Edge_collapsor.h b/src/GudhUI/utils/Edge_collapsor.h
index 9cf880e0..4dcd18ac 100644
--- a/src/GudhUI/utils/Edge_collapsor.h
+++ b/src/GudhUI/utils/Edge_collapsor.h
@@ -10,6 +10,7 @@
#include <list>
#include "utils/Edge_contractor.h"
+#include "utils/UI_utils.h"
/**
* Iteratively puts every vertex at the center of its neighbors
@@ -23,8 +24,9 @@ public:
typedef typename SkBlComplex::Edge_handle Edge_handle;
/**
- * @brief Modify complex to be the expansion of the k-nearest neighbor
- * symetric graph.
+ * @brief Collapse num_collapses edges. If num_collapses<0 then it collapses all possible edges.
+ * Largest edges are collapsed first.
+ *
*/
Edge_collapsor(SkBlComplex& complex,unsigned num_collapses):
complex_(complex),num_collapses_(num_collapses)
@@ -43,7 +45,6 @@ public:
private:
-
void collapse_edges(std::list<Edge_handle>& edges){
while(!edges.empty() && num_collapses_--){
Edge_handle current_edge = edges.front();
@@ -63,7 +64,7 @@ private:
if(link.num_connected_components()>1) return false;
- Edge_contractor<Complex> contractor(link,link.num_vertices()-1);
+ Edge_contractor<SkBlComplex> contractor(link,link.num_vertices()-1);
return (link.num_vertices()==1);
}
diff --git a/src/GudhUI/utils/Is_manifold.h b/src/GudhUI/utils/Is_manifold.h
new file mode 100644
index 00000000..e708a6a4
--- /dev/null
+++ b/src/GudhUI/utils/Is_manifold.h
@@ -0,0 +1,104 @@
+/*
+ * Is_manifold.h
+ * Created on: Jan 28, 2015
+ * 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)
+ *
+ * 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
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+
+#ifndef IS_MANIFOLD_H_
+#define IS_MANIFOLD_H_
+
+#include "utils/UI_utils.h"
+
+#include "utils/Edge_contractor.h"
+
+/**
+ * Iteratively tries to anticollapse smallest edge non added so far.
+ * If its link is contractible then no topological change and else possible topological change.
+ *
+ * todo do a sparsification with some parameter eps while growing
+ */
+template<typename SkBlComplex> class Is_manifold{
+private:
+ const SkBlComplex& input_complex_;
+ typedef typename SkBlComplex::Vertex_handle Vertex_handle;
+
+
+public:
+ /*
+ * return dim the maximum dimension around one simplex and res which is true if the complex is a manifold.
+ * If the complex has dimension <= 3 then if res is false, the complex is not a manifold.
+ * For d-manifold with d>=4, res may be false while the complex is a manifold.
+ */
+ Is_manifold(const SkBlComplex& input_complex,unsigned& dim,bool & res):input_complex_(input_complex){
+ res = true;
+ dim = -1;
+ if(!input_complex_.empty()){
+ for(auto v : input_complex_.vertex_range()){
+ dim = local_dimension(v);
+ break;
+ }
+ //check that the link of every vertex is a dim-1 sphere
+ for(auto v : input_complex_.vertex_range()){
+ if(!is_k_sphere(v,dim-1)) {
+ res = false;
+ break;
+ }
+ }
+ }
+ }
+
+private:
+ unsigned local_dimension(Vertex_handle v){
+ unsigned dim = 0;
+ for(const auto& s: input_complex_.simplex_range(v))
+ dim = (std::max)(dim,(unsigned)s.dimension());
+ return dim;
+ }
+
+ bool is_k_sphere(Vertex_handle v,int k){
+ auto link = input_complex_.link(v);
+ Edge_contractor<Complex> contractor(link,link.num_vertices()-1);
+ return (is_sphere_simplex(link)==k);
+ }
+
+ // A minimal sphere is a complex that contains vertices v1...vn and all faces
+ // made upon this set except the face {v1,...,vn}
+ // return -2 if not a minimal sphere
+ // and d otherwise if complex is a d minimal sphere
+ template<typename SubComplex>
+ int is_sphere_simplex(const SubComplex& complex){
+ if(complex.empty()) return -1;
+ if(complex.num_blockers()!=1) return -2;
+
+ //necessary and sufficient condition : there exists a unique blocker that passes through all vertices
+ auto first_blocker = *(complex.const_blocker_range().begin());
+
+ if (first_blocker->dimension()+1 != complex.num_vertices())
+ return -2;
+ else
+ return (first_blocker->dimension()-1);
+ }
+};
+
+#endif /* IS_MANIFOLD_H_ */