summaryrefslogtreecommitdiff
path: root/src/Hasse_complex
diff options
context:
space:
mode:
authorvrouvrea <vrouvrea@636b058d-ea47-450e-bf9e-a15bfbe3eedb>2015-10-08 14:09:30 +0000
committervrouvrea <vrouvrea@636b058d-ea47-450e-bf9e-a15bfbe3eedb>2015-10-08 14:09:30 +0000
commit6dd03d72142c98c4348e1b95d538de3b184bbc59 (patch)
treef4879bd329b6f6d0b449c3f7ca3ad338fe937348 /src/Hasse_complex
parent13909da1c16c05550c440c8bf22c4a5bfc4fcdf9 (diff)
cpplint fixes on Contraction + warning fixes + Hide Hasse complex for Gudhi version 1.2.0
git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/trunk@841 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: ed7bf90a9ae0b000b995c6ae4bbdaedbb1a65dd5
Diffstat (limited to 'src/Hasse_complex')
-rw-r--r--src/Hasse_complex/example/CMakeLists.txt5
-rw-r--r--src/Hasse_complex/example/hasse_complex_from_simplex_tree.cpp124
-rw-r--r--src/Hasse_complex/include/gudhi/Hasse_complex.h323
3 files changed, 174 insertions, 278 deletions
diff --git a/src/Hasse_complex/example/CMakeLists.txt b/src/Hasse_complex/example/CMakeLists.txt
deleted file mode 100644
index 564df49d..00000000
--- a/src/Hasse_complex/example/CMakeLists.txt
+++ /dev/null
@@ -1,5 +0,0 @@
-cmake_minimum_required(VERSION 2.6)
-project(GUDHIHasseComplexExample)
-
-add_executable ( hasse_complex_from_simplex_tree hasse_complex_from_simplex_tree.cpp )
-add_test(hasse_complex_from_simplex_tree ${CMAKE_CURRENT_BINARY_DIR}/hasse_complex_from_simplex_tree)
diff --git a/src/Hasse_complex/example/hasse_complex_from_simplex_tree.cpp b/src/Hasse_complex/example/hasse_complex_from_simplex_tree.cpp
deleted file mode 100644
index 1de43ab7..00000000
--- a/src/Hasse_complex/example/hasse_complex_from_simplex_tree.cpp
+++ /dev/null
@@ -1,124 +0,0 @@
-/* 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): Vincent Rouvreau
- *
- * Copyright (C) 2014 INRIA Saclay (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/>.
- */
-
-#include <iostream>
-#include <ctime>
-#include "gudhi/graph_simplicial_complex.h"
-#include "gudhi/Simplex_tree.h"
-
-using namespace Gudhi;
-
-typedef std::vector< Vertex_handle > typeVectorVertex;
-typedef std::pair<typeVectorVertex, Filtration_value> typeSimplex;
-typedef std::pair< Simplex_tree<>::Simplex_handle, bool > typePairSimplexBool;
-typedef Simplex_tree<> typeST;
-
-int main(int argc, char * const argv[]) {
- // TEST OF INSERTION
- std::cout << "********************************************************************" << std::endl;
- std::cout << "TEST OF INSERTION" << std::endl;
- typeST st;
-
- // ++ FIRST
- std::cout << " - INSERT (2,1,0)" << std::endl;
- typeVectorVertex SimplexVector1;
- SimplexVector1.push_back(2);
- SimplexVector1.push_back(1);
- SimplexVector1.push_back(0);
- st.insert_simplex_and_subfaces(SimplexVector1, 0.3);
-
- // ++ SECOND
- std::cout << " - INSERT 3" << std::endl;
- typeVectorVertex SimplexVector2;
- SimplexVector2.push_back(3);
- st.insert_simplex_and_subfaces(SimplexVector2, 0.1);
-
- // ++ THIRD
- std::cout << " - INSERT (0,3)" << std::endl;
- typeVectorVertex SimplexVector3;
- SimplexVector3.push_back(3);
- SimplexVector3.push_back(0);
- st.insert_simplex_and_subfaces(SimplexVector3, 0.2);
-
- // ++ FOURTH
- std::cout << " - INSERT (1,0) (already inserted)" << std::endl;
- typeVectorVertex SimplexVector4;
- SimplexVector4.push_back(1);
- SimplexVector4.push_back(0);
- st.insert_simplex_and_subfaces(SimplexVector4, 0.2);
-
- // ++ FIFTH
- std::cout << " - INSERT (3,4,5)" << std::endl;
- typeVectorVertex SimplexVector5;
- SimplexVector5.push_back(3);
- SimplexVector5.push_back(4);
- SimplexVector5.push_back(5);
- st.insert_simplex_and_subfaces(SimplexVector5, 0.3);
-
- // ++ SIXTH
- std::cout << " - INSERT (0,1,6,7)" << std::endl;
- typeVectorVertex SimplexVector6;
- SimplexVector6.push_back(0);
- SimplexVector6.push_back(1);
- SimplexVector6.push_back(6);
- SimplexVector6.push_back(7);
- st.insert_simplex_and_subfaces(SimplexVector6, 0.4);
-
- /* Inserted simplex: */
- /* 1 6 */
- /* o---o */
- /* /X\7/ 4 */
- /* o---o---o---o */
- /* 2 0 3\X/ */
- /* o */
- /* 5 */
-
- /* In other words: */
- /* A facet [2,1,0] */
- /* An edge [0,3] */
- /* A facet [3,4,5] */
- /* A cell [0,1,6,7] */
- /* A cell [4,5,8,9] */
- /* A facet [9,10,11] */
- /* An edge [11,6] */
- /* An edge [10,12,2] */
-
- // ++ GENERAL VARIABLE SET
- st.set_filtration(0.4); // Max filtration value
- st.set_dimension(3); // Max dimension = 3 -> (0,1,6,7)
-
- std::cout << "The complex contains " << st.num_simplices() << " simplices - " << st.num_vertices() << " vertices " << std::endl;
- std::cout << " - dimension " << st.dimension() << " - filtration " << st.filtration() << std::endl;
- std::cout << std::endl << std::endl << "Iterator on Simplices in the filtration, with [filtration value]:" << std::endl;
- std::cout << "**************************************************************" << std::endl;
-
- for( auto f_simplex : st.filtration_simplex_range() )
- {
- std::cout << " " << "[" << st.filtration(f_simplex) << "] ";
- for( auto vertex : st.simplex_vertex_range(f_simplex) )
- {
- std::cout << (int)vertex;
- }
- }
-
- return 0;
-}
diff --git a/src/Hasse_complex/include/gudhi/Hasse_complex.h b/src/Hasse_complex/include/gudhi/Hasse_complex.h
index 427d9916..c3a84c02 100644
--- a/src/Hasse_complex/include/gudhi/Hasse_complex.h
+++ b/src/Hasse_complex/include/gudhi/Hasse_complex.h
@@ -1,208 +1,233 @@
- /* 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): Clément Maria
- *
- * 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 GUDHI_HASSE_DIAGRAM_H
-#define GUDHI_HASSE_DIAGRAM_H
+/* 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): Clément Maria
+ *
+ * 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 HASSE_COMPLEX_H_
+#define HASSE_COMPLEX_H_
-#include <algorithm>
#include <boost/iterator/counting_iterator.hpp>
-namespace Gudhi{
+#include <algorithm>
+
+namespace Gudhi {
template < class HasseCpx >
-struct Hasse_simplex
-{
-//Complex_ds must verify that cpx->key(sh) is the order of sh in the filtration
+struct Hasse_simplex {
+ // Complex_ds must verify that cpx->key(sh) is the order of sh in the filtration
+
template< class Complex_ds >
- Hasse_simplex ( Complex_ds & cpx
- , typename Complex_ds::Simplex_handle sh )
- : key_(cpx.key(sh))
- , filtration_(cpx.filtration(sh))
- , boundary_()
- {
- boundary_.reserve(cpx.dimension(sh)+1);
- for( auto b_sh : cpx.boundary_simplex_range(sh) )
- { boundary_.push_back( cpx.key(b_sh) ); }
+ Hasse_simplex(Complex_ds & cpx
+ , typename Complex_ds::Simplex_handle sh)
+ : key_(cpx.key(sh))
+ , filtration_(cpx.filtration(sh))
+ , boundary_() {
+ boundary_.reserve(cpx.dimension(sh) + 1);
+ for (auto b_sh : cpx.boundary_simplex_range(sh)) {
+ boundary_.push_back(cpx.key(b_sh));
+ }
}
- Hasse_simplex ( typename HasseCpx::Simplex_key key
+ Hasse_simplex(typename HasseCpx::Simplex_key key
, typename HasseCpx::Filtration_value fil
, std::vector<typename HasseCpx::Simplex_handle> boundary)
- : key_(key)
- , filtration_(fil)
- , boundary_(boundary) {}
+ : key_(key)
+ , filtration_(fil)
+ , boundary_(boundary) { }
- typename HasseCpx::Simplex_key key_;
- typename HasseCpx::Filtration_value filtration_;
+ typename HasseCpx::Simplex_key key_;
+ typename HasseCpx::Filtration_value filtration_;
std::vector<typename HasseCpx::Simplex_handle> boundary_;
};
-
-
-/** \brief Data structure representing a Hasse diagram, i.e.
- * a complex where all codimension 1 incidence
- * relations are explicitly encoded.
- *
- * \implements FilteredComplex
- * \ingroup simplex_tree
- */
-template < typename FiltrationValue = double
- , typename SimplexKey = int
- , typename VertexHandle = int
- >
-class Hasse_complex
-{
-public:
-
- typedef Hasse_simplex<Hasse_complex> Hasse_simp;
- typedef FiltrationValue Filtration_value;
- typedef SimplexKey Simplex_key;
- typedef int Simplex_handle; //index in vector complex_
-
- typedef boost::counting_iterator< Simplex_handle > Filtration_simplex_iterator;
- typedef boost::iterator_range<Filtration_simplex_iterator> Filtration_simplex_range;
-
- typedef typename std::vector< Simplex_handle >::iterator Boundary_simplex_iterator;
- typedef boost::iterator_range<Boundary_simplex_iterator> Boundary_simplex_range;
-
- typedef typename std::vector< Simplex_handle >::iterator Skeleton_simplex_iterator;
- typedef boost::iterator_range< Skeleton_simplex_iterator > Skeleton_simplex_range;
-
-
-/* only dimension 0 skeleton_simplex_range(...) */
- Skeleton_simplex_range skeleton_simplex_range( int dim = 0 ) {
- if(dim != 0) { std::cerr << "Dimension must be 0 \n"; }
- return Skeleton_simplex_range(vertices_.begin(),vertices_.end());
+/** \private
+ * \brief Data structure representing a Hasse diagram, i.e.
+ * a complex where all codimension 1 incidence
+ * relations are explicitly encoded.
+ *
+ * \implements FilteredComplex
+ * \ingroup simplex_tree
+ */
+template < typename FiltrationValue = double
+, typename SimplexKey = int
+, typename VertexHandle = int
+>
+class Hasse_complex {
+ public:
+
+ typedef Hasse_simplex<Hasse_complex> Hasse_simp;
+ typedef FiltrationValue Filtration_value;
+ typedef SimplexKey Simplex_key;
+ typedef int Simplex_handle; //index in vector complex_
+
+ typedef boost::counting_iterator< Simplex_handle > Filtration_simplex_iterator;
+ typedef boost::iterator_range<Filtration_simplex_iterator> Filtration_simplex_range;
+
+ typedef typename std::vector< Simplex_handle >::iterator Boundary_simplex_iterator;
+ typedef boost::iterator_range<Boundary_simplex_iterator> Boundary_simplex_range;
+
+ typedef typename std::vector< Simplex_handle >::iterator Skeleton_simplex_iterator;
+ typedef boost::iterator_range< Skeleton_simplex_iterator > Skeleton_simplex_range;
+
+ /* only dimension 0 skeleton_simplex_range(...) */
+ Skeleton_simplex_range skeleton_simplex_range(int dim = 0) {
+ if (dim != 0) {
+ std::cerr << "Dimension must be 0 \n";
+ }
+ return Skeleton_simplex_range(vertices_.begin(), vertices_.end());
}
template < class Complex_ds >
Hasse_complex(Complex_ds & cpx)
- : complex_()
- , vertices_()
- , threshold_(cpx.filtration())
- , num_vertices_()
- , dim_max_(cpx.dimension())
- {
+ : complex_()
+ , vertices_()
+ , threshold_(cpx.filtration())
+ , num_vertices_()
+ , dim_max_(cpx.dimension()) {
complex_.reserve(cpx.num_simplices());
int idx = 0;
- for(auto cpx_sh : cpx.filtration_simplex_range())
- {
- complex_.push_back(Hasse_simp(cpx,cpx_sh));
- if(dimension(idx) == 0) { vertices_.push_back(idx); }
- ++idx;
+ for (auto cpx_sh : cpx.filtration_simplex_range()) {
+ complex_.push_back(Hasse_simp(cpx, cpx_sh));
+ if (dimension(idx) == 0) {
+ vertices_.push_back(idx);
+ }
+ ++idx;
}
}
Hasse_complex()
- : complex_()
- , vertices_()
- , threshold_(0)
- , num_vertices_(0)
- , dim_max_(-1) {}
-
- size_t num_simplices() { return complex_.size(); }
+ : complex_()
+ , vertices_()
+ , threshold_(0)
+ , num_vertices_(0)
+ , dim_max_(-1) { }
+
+ size_t num_simplices() {
+ return complex_.size();
+ }
- Filtration_simplex_range filtration_simplex_range()
- { return Filtration_simplex_range( Filtration_simplex_iterator(0)
- , Filtration_simplex_iterator(complex_.size()) ); }
+ Filtration_simplex_range filtration_simplex_range() {
+ return Filtration_simplex_range(Filtration_simplex_iterator(0)
+ , Filtration_simplex_iterator(complex_.size()));
+ }
- Simplex_key key( Simplex_handle sh ) { return complex_[sh].key_; }
+ Simplex_key key(Simplex_handle sh) {
+ return complex_[sh].key_;
+ }
- Simplex_key null_key() { return -1; }
+ Simplex_key null_key() {
+ return -1;
+ }
- Simplex_handle simplex( Simplex_key key )
- {
- if(key == null_key()) return null_simplex();
+ Simplex_handle simplex(Simplex_key key) {
+ if (key == null_key()) return null_simplex();
return key;
}
- Simplex_handle null_simplex() { return -1; }
+ Simplex_handle null_simplex() {
+ return -1;
+ }
- Filtration_value filtration( Simplex_handle sh ) {
- if( sh == null_simplex() ) { return filtration(); }
+ Filtration_value filtration(Simplex_handle sh) {
+ if (sh == null_simplex()) {
+ return filtration();
+ }
return complex_[sh].filtration_;
}
- Filtration_value filtration() { return threshold_; }
+ Filtration_value filtration() {
+ return threshold_;
+ }
+
+ int dimension(Simplex_handle sh) {
+ if (complex_[sh].boundary_.empty()) return 0;
+ return complex_[sh].boundary_.size() - 1;
+ }
- int dimension ( Simplex_handle sh ) {
- if(complex_[sh].boundary_.empty()) return 0;
- return complex_[sh].boundary_.size()-1;
+ int dimension() {
+ return dim_max_;
}
- int dimension () { return dim_max_; }
- std::pair<Simplex_handle,Simplex_handle> endpoints( Simplex_handle sh )
- { return std::pair<Simplex_handle,Simplex_handle>( complex_[sh].boundary_[0]
- , complex_[sh].boundary_[1] ) ;}
+ std::pair<Simplex_handle, Simplex_handle> endpoints(Simplex_handle sh) {
+ return std::pair<Simplex_handle, Simplex_handle>(complex_[sh].boundary_[0]
+ , complex_[sh].boundary_[1]);
+ }
- void assign_key( Simplex_handle sh, Simplex_key key) { complex_[sh].key_ = key; }
+ void assign_key(Simplex_handle sh, Simplex_key key) {
+ complex_[sh].key_ = key;
+ }
- Boundary_simplex_range boundary_simplex_range ( Simplex_handle sh )
- { return Boundary_simplex_range( complex_[sh].boundary_.begin()
- , complex_[sh].boundary_.end() ); }
+ Boundary_simplex_range boundary_simplex_range(Simplex_handle sh) {
+ return Boundary_simplex_range(complex_[sh].boundary_.begin()
+ , complex_[sh].boundary_.end());
+ }
- void display_simplex(Simplex_handle sh)
- {
+ void display_simplex(Simplex_handle sh) {
std::cout << dimension(sh) << " ";
- for(auto sh_b : boundary_simplex_range(sh)) std::cout << sh_b << " ";
+ for (auto sh_b : boundary_simplex_range(sh)) std::cout << sh_b << " ";
std::cout << " " << filtration(sh) << " key=" << key(sh);
}
- void initialize_filtration()
- {
+ void initialize_filtration() {
Simplex_key key = 0;
- for(auto & h_simp : complex_) { h_simp.key_ = key; ++key; }
+ for (auto & h_simp : complex_) {
+ h_simp.key_ = key;
+ ++key;
+ }
}
- std::vector< Hasse_simp > complex_;
+ std::vector< Hasse_simp > complex_;
std::vector<Simplex_handle> vertices_;
- Filtration_value threshold_;
- size_t num_vertices_;
- int dim_max_;
+ Filtration_value threshold_;
+ size_t num_vertices_;
+ int dim_max_;
};
template< typename T1, typename T2, typename T3 >
-std::istream& operator>> ( std::istream & is
- , Hasse_complex< T1, T2, T3 > & hcpx )
-{
+std::istream& operator>>(std::istream & is
+ , Hasse_complex< T1, T2, T3 > & hcpx) {
assert(hcpx.num_simplices() == 0);
size_t num_simp;
is >> num_simp;
- hcpx.complex_.reserve(num_simp);
-
- std::vector< typename Hasse_complex<T1,T2,T3>::Simplex_key > boundary;
- typename Hasse_complex<T1,T2,T3>::Filtration_value fil;
- typename Hasse_complex<T1,T2,T3>::Filtration_value max_fil = 0 ;
- int max_dim = -1;
- int key = 0 ;
- while(read_hasse_simplex( is, boundary, fil )) //read all simplices in the file as a list of vertices
+ hcpx.complex_.reserve(num_simp);
+
+ std::vector< typename Hasse_complex<T1, T2, T3>::Simplex_key > boundary;
+ typename Hasse_complex<T1, T2, T3>::Filtration_value fil;
+ typename Hasse_complex<T1, T2, T3>::Filtration_value max_fil = 0;
+ int max_dim = -1;
+ int key = 0;
+ while (read_hasse_simplex(is, boundary, fil)) //read all simplices in the file as a list of vertices
{
- //insert every simplex in the simplex tree
- hcpx.complex_.push_back( Hasse_simplex< Hasse_complex<T1,T2,T3> >(key,fil,boundary));
+ // insert every simplex in the simplex tree
+ hcpx.complex_.push_back(Hasse_simplex< Hasse_complex<T1, T2, T3> >(key, fil, boundary));
- if(max_dim < hcpx.dimension(key)) { max_dim = hcpx.dimension(key); }
- if(hcpx.dimension(key) == 0) { hcpx.vertices_.push_back(key); }
- if(max_fil < fil) { max_fil = fil; }
+ if (max_dim < hcpx.dimension(key)) {
+ max_dim = hcpx.dimension(key);
+ }
+ if (hcpx.dimension(key) == 0) {
+ hcpx.vertices_.push_back(key);
+ }
+ if (max_fil < fil) {
+ max_fil = fil;
+ }
++key;
boundary.clear();
@@ -214,6 +239,6 @@ std::istream& operator>> ( std::istream & is
return is;
}
-} // namespace GUDHI
+} // namespace Gudhi
-#endif // GUDHI_HASSE_DIAGRAM_H
+#endif // HASSE_COMPLEX_H_