From 2e582f5a617ed7a4faaafa8930ae7291146a4543 Mon Sep 17 00:00:00 2001 From: vrouvrea Date: Tue, 6 Oct 2015 13:44:03 +0000 Subject: GUDHIConfig.cmake and GUDHIVersion.cmake generation generate_version.sh modification to take into account these new files git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/trunk@830 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 54d3d4f963fb29c9a142be1c28458ce05215ec79 --- src/CMakeLists.txt | 72 ++++++++++++++++++++++++++++++++++++++++++------ src/GUDHIConfig.cmake.in | 15 ++++++++++ 2 files changed, 78 insertions(+), 9 deletions(-) create mode 100644 src/GUDHIConfig.cmake.in (limited to 'src') diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 3e21870f..e8297aa8 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,16 +1,12 @@ cmake_minimum_required(VERSION 2.6) project(GUDHI) -# Do not forget to version number. -set (GUDHI_MAJOR_VERSION 1) -set (GUDHI_MINOR_VERSION 2) -set (GUDHI_PATCH_VERSION 0) +include("CMakeGUDHIVersion.txt") list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/modules/") find_package(Boost REQUIRED COMPONENTS system filesystem program_options chrono timer REQUIRED) - if (NOT CMAKE_BUILD_TYPE) set(CMAKE_BUILD_TYPE "Release") endif() @@ -40,9 +36,35 @@ else() add_definitions(-DBOOST_ALL_NO_LIB) INCLUDE_DIRECTORIES(${Boost_INCLUDE_DIRS}) - LINK_DIRECTORIES(${Boost_LIBRARY_DIRS}) - include_directories(include/) - + LINK_DIRECTORIES(${Boost_LIBRARY_DIRS}) + + #--------------------------------------------------------------------------------------- + # GUDHIConfig.cmake 1st part + + # Offer the user the choice of overriding the installation directories - i.e. "cmake -DGUDHI_DIR=~/gudhi/GUDHI_1.2.0 ." + set(INSTALL_LIB_DIR lib CACHE PATH "Installation directory for libraries") + set(INSTALL_BIN_DIR bin CACHE PATH "Installation directory for executables") + set(INSTALL_INCLUDE_DIR include CACHE PATH "Installation directory for header files") + if(WIN32 AND NOT CYGWIN) + set(DEF_INSTALL_CMAKE_DIR CMake) + else() + set(DEF_INSTALL_CMAKE_DIR lib/CMake/GUDHI) + endif() + set(INSTALL_CMAKE_DIR ${DEF_INSTALL_CMAKE_DIR} CACHE PATH "Installation directory for CMake files") + + # Make relative paths absolute (needed later on) + foreach(p LIB BIN INCLUDE CMAKE) + set(var INSTALL_${p}_DIR) + if(NOT IS_ABSOLUTE "${${var}}") + set(${var} "${CMAKE_INSTALL_PREFIX}/${${var}}") + endif() + endforeach() + #--------------------------------------------------------------------------------------- + + #--------------------------------------------------------------------------------------- + # Gudhi compilation part + include_directories(include) + add_subdirectory(example/Simplex_tree) add_subdirectory(example/Persistent_cohomology) add_subdirectory(example/Skeleton_blocker) @@ -55,7 +77,39 @@ else() # data points generator add_subdirectory(data/points/generator) + #--------------------------------------------------------------------------------------- + + #--------------------------------------------------------------------------------------- + # GUDHIConfig.cmake 2nd part + # Export the package for use from the build-tree + # (this registers the build-tree with a global CMake-registry) + export(PACKAGE GUDHI) + + # Create the GUDHIConfig.cmake and GUDHIConfigVersion files + file(RELATIVE_PATH REL_INCLUDE_DIR "${INSTALL_CMAKE_DIR}" "${INSTALL_INCLUDE_DIR}") + # ... for the build tree + set(CONF_INCLUDE_DIRS "${PROJECT_SOURCE_DIR}/include" "${PROJECT_BINARY_DIR}/include") + configure_file(GUDHIConfig.cmake.in "${PROJECT_BINARY_DIR}/GUDHIConfig.cmake" @ONLY) + # ... for the install tree + set(CONF_INCLUDE_DIRS "\${GUDHI_CMAKE_DIR}/${REL_INCLUDE_DIR}") + configure_file(GUDHIConfig.cmake.in "${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/GUDHIConfig.cmake" @ONLY) + # ... for both + configure_file(GUDHIConfigVersion.cmake.in "${PROJECT_BINARY_DIR}/GUDHIConfigVersion.cmake" @ONLY) + + configure_file(GUDHIVersion.cmake.in "${PROJECT_BINARY_DIR}/GUDHIVersion.cmake" @ONLY) + + # Install the GUDHIConfig.cmake and GUDHIConfigVersion.cmake + install(FILES + "${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/GUDHIConfig.cmake" + "${PROJECT_BINARY_DIR}/GUDHIConfigVersion.cmake" + DESTINATION "${INSTALL_CMAKE_DIR}" COMPONENT dev) + #--------------------------------------------------------------------------------------- + + #--------------------------------------------------------------------------------------- + # Gudhi installation part - install (DIRECTORY include/gudhi DESTINATION include) + # install the include file on "make install" + install(DIRECTORY include/gudhi DESTINATION include) + #--------------------------------------------------------------------------------------- endif() diff --git a/src/GUDHIConfig.cmake.in b/src/GUDHIConfig.cmake.in new file mode 100644 index 00000000..83aa61e7 --- /dev/null +++ b/src/GUDHIConfig.cmake.in @@ -0,0 +1,15 @@ +# - Config file for the GUDHI package +# It defines the following variables +# GUDHI_INCLUDE_DIRS - include directories for GUDHI +# GUDHI_LIBRARIES - libraries to link against +# GUDHI_EXECUTABLE - the executables + +# Compute paths +get_filename_component(GUDHI_CMAKE_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH) +set(GUDHI_INCLUDE_DIRS "@CONF_INCLUDE_DIRS@") + +# Our library dependencies (contains definitions for IMPORTED targets) +include("${GUDHI_CMAKE_DIR}/GUDHITargets.cmake") + +# These are IMPORTED targets created by GUDHITargets.cmake +set(GUDHI_EXECUTABLE mini_simplex_tree) -- cgit v1.2.3 From 5f62ba7ffa4322a16c811f59fbf206a3b41ff7f7 Mon Sep 17 00:00:00 2001 From: vrouvrea Date: Tue, 6 Oct 2015 15:33:33 +0000 Subject: Cmake fixes git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/trunk@834 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: b11aad4d7984b2f156fac8df298516c7780b0df4 --- scripts/generate_version.sh | 1 + src/CMakeLists.txt | 44 +++++++---------------------------------- src/GUDHIConfig.cmake.in | 8 -------- src/GUDHIConfigVersion.cmake.in | 11 +++++++++++ 4 files changed, 19 insertions(+), 45 deletions(-) create mode 100644 src/GUDHIConfigVersion.cmake.in (limited to 'src') diff --git a/scripts/generate_version.sh b/scripts/generate_version.sh index 533f51ed..43a54c1c 100755 --- a/scripts/generate_version.sh +++ b/scripts/generate_version.sh @@ -55,6 +55,7 @@ cp $ROOT_DIR/src/Doxyfile $VERSION_DIR cp -R $ROOT_DIR/biblio $VERSION_DIR cp $ROOT_DIR/src/GUDHIConfigVersion.cmake.in $VERSION_DIR cp $ROOT_DIR/src/GUDHIConfig.cmake.in $VERSION_DIR +cp $ROOT_DIR/GUDHIVersion.cmake.in $VERSION_DIR # PACKAGE LEVEL COPY PACKAGE_INC_DIR="/include" diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index e8297aa8..010bd995 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -38,29 +38,6 @@ else() INCLUDE_DIRECTORIES(${Boost_INCLUDE_DIRS}) LINK_DIRECTORIES(${Boost_LIBRARY_DIRS}) - #--------------------------------------------------------------------------------------- - # GUDHIConfig.cmake 1st part - - # Offer the user the choice of overriding the installation directories - i.e. "cmake -DGUDHI_DIR=~/gudhi/GUDHI_1.2.0 ." - set(INSTALL_LIB_DIR lib CACHE PATH "Installation directory for libraries") - set(INSTALL_BIN_DIR bin CACHE PATH "Installation directory for executables") - set(INSTALL_INCLUDE_DIR include CACHE PATH "Installation directory for header files") - if(WIN32 AND NOT CYGWIN) - set(DEF_INSTALL_CMAKE_DIR CMake) - else() - set(DEF_INSTALL_CMAKE_DIR lib/CMake/GUDHI) - endif() - set(INSTALL_CMAKE_DIR ${DEF_INSTALL_CMAKE_DIR} CACHE PATH "Installation directory for CMake files") - - # Make relative paths absolute (needed later on) - foreach(p LIB BIN INCLUDE CMAKE) - set(var INSTALL_${p}_DIR) - if(NOT IS_ABSOLUTE "${${var}}") - set(${var} "${CMAKE_INSTALL_PREFIX}/${${var}}") - endif() - endforeach() - #--------------------------------------------------------------------------------------- - #--------------------------------------------------------------------------------------- # Gudhi compilation part include_directories(include) @@ -80,33 +57,26 @@ else() #--------------------------------------------------------------------------------------- #--------------------------------------------------------------------------------------- - # GUDHIConfig.cmake 2nd part + # GUDHIConfig.cmake # Export the package for use from the build-tree # (this registers the build-tree with a global CMake-registry) export(PACKAGE GUDHI) # Create the GUDHIConfig.cmake and GUDHIConfigVersion files - file(RELATIVE_PATH REL_INCLUDE_DIR "${INSTALL_CMAKE_DIR}" "${INSTALL_INCLUDE_DIR}") - # ... for the build tree - set(CONF_INCLUDE_DIRS "${PROJECT_SOURCE_DIR}/include" "${PROJECT_BINARY_DIR}/include") + set(CONF_INCLUDE_DIRS "${PROJECT_SOURCE_DIR}/include") configure_file(GUDHIConfig.cmake.in "${PROJECT_BINARY_DIR}/GUDHIConfig.cmake" @ONLY) - # ... for the install tree - set(CONF_INCLUDE_DIRS "\${GUDHI_CMAKE_DIR}/${REL_INCLUDE_DIR}") - configure_file(GUDHIConfig.cmake.in "${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/GUDHIConfig.cmake" @ONLY) - # ... for both configure_file(GUDHIConfigVersion.cmake.in "${PROJECT_BINARY_DIR}/GUDHIConfigVersion.cmake" @ONLY) - configure_file(GUDHIVersion.cmake.in "${PROJECT_BINARY_DIR}/GUDHIVersion.cmake" @ONLY) + #--------------------------------------------------------------------------------------- + + #--------------------------------------------------------------------------------------- + # Gudhi installation part # Install the GUDHIConfig.cmake and GUDHIConfigVersion.cmake install(FILES "${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/GUDHIConfig.cmake" "${PROJECT_BINARY_DIR}/GUDHIConfigVersion.cmake" - DESTINATION "${INSTALL_CMAKE_DIR}" COMPONENT dev) - #--------------------------------------------------------------------------------------- - - #--------------------------------------------------------------------------------------- - # Gudhi installation part + DESTINATION share/gudhi) # install the include file on "make install" install(DIRECTORY include/gudhi DESTINATION include) diff --git a/src/GUDHIConfig.cmake.in b/src/GUDHIConfig.cmake.in index 83aa61e7..02b540dc 100644 --- a/src/GUDHIConfig.cmake.in +++ b/src/GUDHIConfig.cmake.in @@ -1,15 +1,7 @@ # - Config file for the GUDHI package # It defines the following variables # GUDHI_INCLUDE_DIRS - include directories for GUDHI -# GUDHI_LIBRARIES - libraries to link against -# GUDHI_EXECUTABLE - the executables # Compute paths -get_filename_component(GUDHI_CMAKE_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH) set(GUDHI_INCLUDE_DIRS "@CONF_INCLUDE_DIRS@") -# Our library dependencies (contains definitions for IMPORTED targets) -include("${GUDHI_CMAKE_DIR}/GUDHITargets.cmake") - -# These are IMPORTED targets created by GUDHITargets.cmake -set(GUDHI_EXECUTABLE mini_simplex_tree) diff --git a/src/GUDHIConfigVersion.cmake.in b/src/GUDHIConfigVersion.cmake.in new file mode 100644 index 00000000..6d443ef6 --- /dev/null +++ b/src/GUDHIConfigVersion.cmake.in @@ -0,0 +1,11 @@ +set(PACKAGE_VERSION "@GUDHI_VERSION@") + +# Check whether the requested PACKAGE_FIND_VERSION is compatible +if("${PACKAGE_VERSION}" VERSION_LESS "${PACKAGE_FIND_VERSION}") + set(PACKAGE_VERSION_COMPATIBLE FALSE) +else() + set(PACKAGE_VERSION_COMPATIBLE TRUE) + if ("${PACKAGE_VERSION}" VERSION_EQUAL "${PACKAGE_FIND_VERSION}") + set(PACKAGE_VERSION_EXACT TRUE) + endif() +endif() -- cgit v1.2.3 From 044d0496773d6df57bf49a6bbf49bdc0cc2642d2 Mon Sep 17 00:00:00 2001 From: vrouvrea Date: Wed, 7 Oct 2015 06:28:31 +0000 Subject: Enable test suite for user version. git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/trunk@835 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 87f06171990fe2b5e93515e7c6d3f8553a461f49 --- src/CMakeLists.txt | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src') diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 010bd995..5be629f7 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -3,6 +3,8 @@ project(GUDHI) include("CMakeGUDHIVersion.txt") +enable_testing() + list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/modules/") find_package(Boost REQUIRED COMPONENTS system filesystem program_options chrono timer REQUIRED) -- cgit v1.2.3 From 384343575eee5fc99440f1f42258b7cb43a3c3a7 Mon Sep 17 00:00:00 2001 From: vrouvrea Date: Wed, 7 Oct 2015 07:32:02 +0000 Subject: Let GudhUI in last compilation position as QT is known for modifying CMAKE_CXX_FLAGS git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/trunk@836 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: f3bbe579d98a098b4adc89349e619983ceba225b --- CMakeLists.txt | 7 ++++--- src/CMakeLists.txt | 7 ++++--- 2 files changed, 8 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/CMakeLists.txt b/CMakeLists.txt index 91030185..76e55d43 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -79,12 +79,13 @@ else() add_subdirectory(src/Bottleneck/example) add_subdirectory(src/Bottleneck/test) - # GudhUI - add_subdirectory(src/GudhUI) - # data points generator add_subdirectory(data/points/generator) + # Please let GudhUI in last compilation position as QT is known to modify CMAKE_CXX_FLAGS + # GudhUI + add_subdirectory(src/GudhUI) + endif() diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 5be629f7..b782b9f3 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -51,11 +51,12 @@ else() add_subdirectory(example/Hasse_complex) add_subdirectory(example/Bottleneck) - # GudhUI - add_subdirectory(GudhUI) - # data points generator add_subdirectory(data/points/generator) + + # Please let GudhUI in last compilation position as QT is known to modify CMAKE_CXX_FLAGS + # GudhUI + add_subdirectory(GudhUI) #--------------------------------------------------------------------------------------- #--------------------------------------------------------------------------------------- -- cgit v1.2.3 From 13909da1c16c05550c440c8bf22c4a5bfc4fcdf9 Mon Sep 17 00:00:00 2001 From: vrouvrea Date: Wed, 7 Oct 2015 10:45:09 +0000 Subject: cpplint fixes on contraction + Eigen3 cmake find modules git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/trunk@837 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 9f2afcb6bc8721680442c97d5297528d41c9d9b0 --- .../CGAL_queue/Modifiable_priority_queue.h | 120 +-- .../include/gudhi/Contraction/Edge_profile.h | 199 ++-- src/Contraction/include/gudhi/Edge_contraction.h | 36 +- .../include/gudhi/Skeleton_blocker_contractor.h | 1009 ++++++++++---------- src/cmake/modules/FindEigen3.cmake | 86 ++ src/cmake/modules/UseEigen3.cmake | 9 + 6 files changed, 760 insertions(+), 699 deletions(-) create mode 100644 src/cmake/modules/FindEigen3.cmake create mode 100644 src/cmake/modules/UseEigen3.cmake (limited to 'src') diff --git a/src/Contraction/include/gudhi/Contraction/CGAL_queue/Modifiable_priority_queue.h b/src/Contraction/include/gudhi/Contraction/CGAL_queue/Modifiable_priority_queue.h index 10b89e13..f4eb59fd 100644 --- a/src/Contraction/include/gudhi/Contraction/CGAL_queue/Modifiable_priority_queue.h +++ b/src/Contraction/include/gudhi/Contraction/CGAL_queue/Modifiable_priority_queue.h @@ -16,8 +16,8 @@ // // Author(s) : Fernando Cacciola // -#ifndef CGAL_MODIFIABLE_PRIORITY_QUEUE_H -#define CGAL_MODIFIABLE_PRIORITY_QUEUE_H +#ifndef CONTRACTION_CGAL_MODIFIABLE_PRIORITY_QUEUE_H +#define CONTRACTION_CGAL_MODIFIABLE_PRIORITY_QUEUE_H #define CGAL_SURFACE_MESH_SIMPLIFICATION_USE_RELAXED_HEAP @@ -27,65 +27,73 @@ namespace CGAL { -template - ,class ID_ = boost::identity_property_map - > -class Modifiable_priority_queue -{ -public: - +template , class ID_ = boost::identity_property_map> +class Modifiable_priority_queue { + public: typedef Modifiable_priority_queue Self; - - typedef IndexedType_ IndexedType ; - typedef Compare_ Compare; - typedef ID_ ID ; - - typedef boost::relaxed_heap Heap; + + typedef IndexedType_ IndexedType; + typedef Compare_ Compare; + typedef ID_ ID; + + typedef boost::relaxed_heap Heap; typedef typename Heap::value_type value_type; - typedef typename Heap::size_type size_type; - - typedef bool handle ; - -public: - - Modifiable_priority_queue( size_type largest_ID, Compare const& c, ID const& id ) : mHeap(largest_ID,c,id) {} - - handle push ( value_type const& v ) { mHeap.push(v) ; return handle(true) ; } - - handle update ( value_type const& v, handle h ) { mHeap.update(v); return h ; } - - handle erase ( value_type const& v, handle ) { mHeap.remove(v); return null_handle() ; } - - value_type top() const { return mHeap.top() ; } - - void pop() { mHeap.pop(); } - - bool empty() const { return mHeap.empty() ; } - - bool contains ( value_type const& v ) { return mHeap.contains(v) ; } - - boost::optional extract_top() - { - boost::optional r ; - if ( !empty() ) - { + typedef typename Heap::size_type size_type; + + typedef bool handle; + + public: + Modifiable_priority_queue(size_type largest_ID, Compare const& c, ID const& id) : mHeap(largest_ID, c, id) { } + + handle push(value_type const& v) { + mHeap.push(v); + return handle(true); + } + + handle update(value_type const& v, handle h) { + mHeap.update(v); + return h; + } + + handle erase(value_type const& v, handle) { + mHeap.remove(v); + return null_handle(); + } + + value_type top() const { + return mHeap.top(); + } + + void pop() { + mHeap.pop(); + } + + bool empty() const { + return mHeap.empty(); + } + + bool contains(value_type const& v) { + return mHeap.contains(v); + } + + boost::optional extract_top() { + boost::optional r; + if (!empty()) { value_type v = top(); pop(); - r = boost::optional(v) ; - } - return r ; + r = boost::optional(v); + } + return r; + } + + static handle null_handle() { + return handle(false); } - - static handle null_handle() { return handle(false); } - -private: - Heap mHeap ; - -} ; + private: + Heap mHeap; +}; -} //namespace CGAL +} //namespace CGAL -#endif - +#endif // CONTRACTION_CGAL_MODIFIABLE_PRIORITY_QUEUE_H diff --git a/src/Contraction/include/gudhi/Contraction/Edge_profile.h b/src/Contraction/include/gudhi/Contraction/Edge_profile.h index f90bd71a..b6dfd63b 100644 --- a/src/Contraction/include/gudhi/Contraction/Edge_profile.h +++ b/src/Contraction/include/gudhi/Contraction/Edge_profile.h @@ -1,130 +1,129 @@ - /* 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-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 - * 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 . - */ - -#ifndef GUDHI_EDGE_PROFILE_H_ -#define GUDHI_EDGE_PROFILE_H_ -//#include "combinatorics/Skeleton_blocker/Simplex.h" - - -namespace Gudhi{ +/* 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-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 + * 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 . + */ + +#ifndef CONTRACTION_EDGE_PROFILE_H_ +#define CONTRACTION_EDGE_PROFILE_H_ + +namespace Gudhi { namespace contraction { -template class Edge_profile{ -public: - typedef GeometricSimplifiableComplex Complex; - typedef typename Complex::GT GT; +template class Edge_profile { + public: + typedef GeometricSimplifiableComplex Complex; + typedef typename Complex::GT GT; - typedef typename GeometricSimplifiableComplex::Vertex_handle Vertex_handle; - typedef typename GeometricSimplifiableComplex::Root_vertex_handle Root_vertex_handle; + typedef typename GeometricSimplifiableComplex::Vertex_handle Vertex_handle; + typedef typename GeometricSimplifiableComplex::Root_vertex_handle Root_vertex_handle; - typedef typename GeometricSimplifiableComplex::Edge_handle Edge_handle; - typedef typename GeometricSimplifiableComplex::Graph_vertex Graph_vertex; - typedef typename GeometricSimplifiableComplex::Graph_edge Graph_edge; - typedef typename GeometricSimplifiableComplex::Point Point; + typedef typename GeometricSimplifiableComplex::Edge_handle Edge_handle; + typedef typename GeometricSimplifiableComplex::Graph_vertex Graph_vertex; + typedef typename GeometricSimplifiableComplex::Graph_edge Graph_edge; + typedef typename GeometricSimplifiableComplex::Point Point; + Edge_profile(GeometricSimplifiableComplex& complex, Edge_handle edge) : complex_(complex), edge_handle_(edge), + v0_(complex_.first_vertex(edge_handle_)), v1_(complex_.second_vertex(edge_handle_)) { + assert(complex_.get_address(complex_[edge_handle_].first())); + assert(complex_.get_address(complex_[edge_handle_].second())); + assert(complex_.contains_edge(v0_handle(), v1_handle())); + assert(v0_handle() != v1_handle()); + } + virtual ~Edge_profile() { } + GeometricSimplifiableComplex& complex() const { + return complex_; + } - Edge_profile( GeometricSimplifiableComplex& complex,Edge_handle edge):complex_(complex),edge_handle_(edge), - v0_(complex_.first_vertex(edge_handle_)),v1_(complex_.second_vertex(edge_handle_)) -{ - assert(complex_.get_address(complex_[edge_handle_].first())); - assert(complex_.get_address(complex_[edge_handle_].second())); - assert(complex_.contains_edge(v0_handle(),v1_handle())); - assert(v0_handle() != v1_handle()); -} + Edge_handle edge_handle() const { + return edge_handle_; + } - virtual ~Edge_profile(){ } + Graph_edge& edge() const { + return complex_[edge_handle_]; + } + Graph_vertex& v0() const { + return complex_[v0_handle()]; + } - GeometricSimplifiableComplex& complex() const { - return complex_; - } + Graph_vertex& v1() const { + return complex_[v1_handle()]; + } - Edge_handle edge_handle() const{ - return edge_handle_; - } + Vertex_handle v0_handle() const { + return v0_; + // Root_vertex_handle root = complex_[edge_handle_].first(); + // assert(complex_.get_address(root)); + // return *complex_.get_address(root); + } - Graph_edge& edge() const{ - return complex_[edge_handle_]; - } + Vertex_handle v1_handle() const { + return v1_; + // Root_vertex_handle root = complex_[edge_handle_].second(); + // assert(complex_.get_address(root)); + // return *complex_.get_address(root); + } + const Point& p0() const { + return complex_.point(v0_handle()); + } - Graph_vertex& v0() const{return complex_[v0_handle()];} - Graph_vertex& v1() const{return complex_[v1_handle()];} + const Point& p1() const { + return complex_.point(v1_handle()); + } + friend std::ostream& operator<<(std::ostream& o, const Edge_profile & v) { + o << "v0:" << v.v0_handle() << " v1:" << v.v1_handle(); + return o; + } - Vertex_handle v0_handle() const{ - return v0_; -// Root_vertex_handle root = complex_[edge_handle_].first(); -// assert(complex_.get_address(root)); -// return *complex_.get_address(root); - } + private: + GeometricSimplifiableComplex& complex_; - Vertex_handle v1_handle() const{ - return v1_; -// Root_vertex_handle root = complex_[edge_handle_].second(); -// assert(complex_.get_address(root)); -// return *complex_.get_address(root); - } + Edge_handle edge_handle_; - const Point& p0() const {return complex_.point(v0_handle());} + Vertex_handle v0_; - const Point& p1() const {return complex_.point(v1_handle());} - - friend std::ostream& operator << (std::ostream& o, const Edge_profile & v){ - o << "v0:"< class Edge_profile_factory { + public: + typedef typename EdgeProfile::Edge_handle Edge_handle_; + typedef typename EdgeProfile::Complex Complex_; -}; + virtual EdgeProfile make_profile( + Complex_& complex, + Edge_handle_ edge) const { + return EdgeProfile(complex, edge); + } -template class Edge_profile_factory{ -public: - typedef typename EdgeProfile::Edge_handle Edge_handle_; - typedef typename EdgeProfile::Complex Complex_; - virtual EdgeProfile make_profile( - Complex_& complex, - Edge_handle_ edge) const{ - return EdgeProfile(complex,edge); - } - - virtual ~Edge_profile_factory(){}; + virtual ~Edge_profile_factory() { } }; - } // namespace contraction -} // namespace GUDHI +} // namespace Gudhi -#endif /* GUDHI_EDGE_PROFILE_H_ */ +#endif // CONTRACTION_EDGE_PROFILE_H_ diff --git a/src/Contraction/include/gudhi/Edge_contraction.h b/src/Contraction/include/gudhi/Edge_contraction.h index 2c254710..dfce8d1b 100644 --- a/src/Contraction/include/gudhi/Edge_contraction.h +++ b/src/Contraction/include/gudhi/Edge_contraction.h @@ -20,21 +20,21 @@ * along with this program. If not, see . */ -#ifndef GUDHI_EDGE_CONTRACTION_H_ -#define GUDHI_EDGE_CONTRACTION_H_ +#ifndef EDGE_CONTRACTION_H_ +#define EDGE_CONTRACTION_H_ -#include "gudhi/Skeleton_blocker_contractor.h" -#include "gudhi/Contraction/policies/Edge_length_cost.h" -#include "gudhi/Contraction/policies/First_vertex_placement.h" -#include "gudhi/Contraction/policies/Valid_contraction_policy.h" -#include "gudhi/Contraction/policies/Dummy_valid_contraction.h" -#include "gudhi/Contraction/policies/Link_condition_valid_contraction.h" -#include "gudhi/Utils.h" +#include +#include +#include +#include +#include +#include +#include +namespace Gudhi { -namespace Gudhi{ -namespace contraction{ +namespace contraction { /** \defgroup contr Contraction @@ -120,9 +120,9 @@ while ensuring its homotopy type is preserved during the contraction (edge are c \code{.cpp} #include #include -#include "gudhi/Edge_contraction.h" -#include "gudhi/Skeleton_blocker.h" -#include "gudhi/Off_reader.h" +#include +#include +#include using namespace std; @@ -228,9 +228,9 @@ Time to simplify and enumerate simplices: \copyright GNU General Public License v3. \verbatim Contact: David Salinas, david.salinas@inria.fr \endverbatim */ -/** @} */ // end defgroup +/** @} */ // end defgroup +} // namespace contraction -} -} +} // namespace Gudhi -#endif /* GUDHI_EDGE_CONTRACTION_H_ */ +#endif // EDGE_CONTRACTION_H_ diff --git a/src/Contraction/include/gudhi/Skeleton_blocker_contractor.h b/src/Contraction/include/gudhi/Skeleton_blocker_contractor.h index dcc05c22..2759b540 100644 --- a/src/Contraction/include/gudhi/Skeleton_blocker_contractor.h +++ b/src/Contraction/include/gudhi/Skeleton_blocker_contractor.h @@ -20,80 +20,69 @@ * along with this program. If not, see . */ -#ifndef GUDHI_SKELETON_BLOCKER_CONTRACTOR_H_ -#define GUDHI_SKELETON_BLOCKER_CONTRACTOR_H_ - -#include -#include +#ifndef SKELETON_BLOCKER_CONTRACTOR_H_ +#define SKELETON_BLOCKER_CONTRACTOR_H_ // todo remove the queue to be independent from cgald -#include "gudhi/Contraction/CGAL_queue/Modifiable_priority_queue.h" +#include +#include +#include +#include +#include +#include +#include +#include // xxx remove +#include // xxx remove +#include -#include -#include -#include +#include +#include -#include "gudhi/Contraction/Edge_profile.h" -#include "gudhi/Contraction/policies/Cost_policy.h" -#include "gudhi/Contraction/policies/Edge_length_cost.h" -#include "gudhi/Contraction/policies/Placement_policy.h" -#include "gudhi/Contraction/policies/First_vertex_placement.h" - -#include "gudhi/Contraction/policies/Valid_contraction_policy.h" -#include "gudhi/Contraction/policies/Dummy_valid_contraction.h" //xxx remove -#include "gudhi/Contraction/policies/Link_condition_valid_contraction.h" //xxx remove - -#include "gudhi/Contraction/policies/Contraction_visitor.h" - -#include "gudhi/Skeleton_blocker/Skeleton_blocker_complex_visitor.h" +#include +#include -#include "gudhi/Utils.h" +#include +#include +#include +#include // for pair +#include -namespace Gudhi{ +namespace Gudhi { namespace contraction { - - - template -Placement_policy* make_first_vertex_placement(){ - return new First_vertex_placement(); +Placement_policy* make_first_vertex_placement() { + return new First_vertex_placement(); } template -Valid_contraction_policy* make_link_valid_contraction(){ - return new Link_condition_valid_contraction(); +Valid_contraction_policy* make_link_valid_contraction() { + return new Link_condition_valid_contraction(); } - /** -*@brief Visitor to remove popable blockers after an edge contraction. -*/ + *@brief Visitor to remove popable blockers after an edge contraction. + */ template -class Contraction_visitor_remove_popable : public Contraction_visitor{ -public: - typedef typename Profile::Point Point; - typedef typename Profile::Complex Complex; - typedef typename Complex::Vertex_handle Vertex_handle; - - void on_contracted(const Profile &profile, boost::optional< Point > placement) override{ - profile.complex().remove_all_popable_blockers(profile.v0_handle()); - } +class Contraction_visitor_remove_popable : public Contraction_visitor { + public: + typedef typename Profile::Point Point; + typedef typename Profile::Complex Complex; + typedef typename Complex::Vertex_handle Vertex_handle; + + void on_contracted(const Profile &profile, boost::optional< Point > placement) override { + profile.complex().remove_all_popable_blockers(profile.v0_handle()); + } }; template -Contraction_visitor* make_remove_popable_blockers_visitor(){ - return new Contraction_visitor_remove_popable(); +Contraction_visitor* make_remove_popable_blockers_visitor() { + return new Contraction_visitor_remove_popable(); } - - - - - /** *@class Skeleton_blocker_contractor *@brief Class that allows to contract iteratively edges of a simplicial complex. @@ -110,519 +99,489 @@ Contraction_visitor* make_remove_popable_blockers_visitor(){ * a topological condition (link condition) or a geometrical condition (normals messed up). * */ -template< -class GeometricSimplifiableComplex, -class EdgeProfile = Edge_profile -> -class Skeleton_blocker_contractor : private skbl::Dummy_complex_visitor{ - - GeometricSimplifiableComplex& complex_; - -public: - typedef typename GeometricSimplifiableComplex::Graph_vertex Graph_vertex; - typedef typename GeometricSimplifiableComplex::Vertex_handle Vertex_handle; - typedef typename GeometricSimplifiableComplex::Simplex_handle Simplex_handle; - typedef typename GeometricSimplifiableComplex::Simplex_handle_iterator Simplex_handle_iterator; - - - - typedef typename GeometricSimplifiableComplex::Root_vertex_handle Root_vertex_handle; - - typedef typename GeometricSimplifiableComplex::Graph_edge Graph_edge; - typedef typename GeometricSimplifiableComplex::Edge_handle Edge_handle; - typedef typename GeometricSimplifiableComplex::Point Point; - - typedef EdgeProfile Profile; - - - typedef Cost_policy Cost_policy_; - typedef Placement_policy Placement_policy_; - typedef Valid_contraction_policy Valid_contraction_policy_; - typedef Contraction_visitor Contraction_visitor_; - typedef Edge_profile_factory Edge_profile_factory_; +template> +class Skeleton_blocker_contractor : private skbl::Dummy_complex_visitor< +typename GeometricSimplifiableComplex::Vertex_handle> { + GeometricSimplifiableComplex& complex_; + public: + typedef typename GeometricSimplifiableComplex::Graph_vertex Graph_vertex; + typedef typename GeometricSimplifiableComplex::Vertex_handle Vertex_handle; + typedef typename GeometricSimplifiableComplex::Simplex_handle Simplex_handle; + typedef typename GeometricSimplifiableComplex::Simplex_handle_iterator Simplex_handle_iterator; - typedef boost::optional Cost_type; - typedef boost::optional Placement_type ; - typedef size_t size_type; + typedef typename GeometricSimplifiableComplex::Root_vertex_handle Root_vertex_handle; - typedef Skeleton_blocker_contractor Self ; + typedef typename GeometricSimplifiableComplex::Graph_edge Graph_edge; + typedef typename GeometricSimplifiableComplex::Edge_handle Edge_handle; + typedef typename GeometricSimplifiableComplex::Point Point; + typedef EdgeProfile Profile; -private: + typedef Cost_policy Cost_policy_; + typedef Placement_policy Placement_policy_; + typedef Valid_contraction_policy Valid_contraction_policy_; + typedef Contraction_visitor Contraction_visitor_; + typedef Edge_profile_factory Edge_profile_factory_; - struct Compare_id - { - Compare_id() : algorithm_(0) {} - Compare_id( Self const* aAlgorithm ) : algorithm_(aAlgorithm) {} - bool operator() ( Edge_handle a, Edge_handle b ) const - { - return algorithm_->get_undirected_edge_id(a) < algorithm_->get_undirected_edge_id(b); - } + typedef boost::optional Cost_type; + typedef boost::optional Placement_type; - Self const* algorithm_ ; - } ; + typedef size_t size_type; - struct Compare_cost - { - Compare_cost() : algorithm_(0) { - } + typedef Skeleton_blocker_contractor Self; - Compare_cost( Self const* aAlgorithm ) : algorithm_(aAlgorithm) { - } + private: + struct Compare_id { + Compare_id() : algorithm_(0) { } - bool operator() ( Edge_handle a, Edge_handle b ) const - { - // NOTE: A cost is an optional<> value. - // Absent optionals are ordered first; that is, "none < T" and "T > none" for any defined T != none. - // In consequence, edges with undefined costs will be promoted to the top of the priority queue and poped out first. - return algorithm_->get_data(a).cost() < algorithm_->get_data(b).cost(); - } + Compare_id(Self const* aAlgorithm) : algorithm_(aAlgorithm) { } - Self const* algorithm_ ; + bool operator()(Edge_handle a, Edge_handle b) const { + return algorithm_->get_undirected_edge_id(a) < algorithm_->get_undirected_edge_id(b); + } - } ; + Self const* algorithm_; + }; - struct Undirected_edge_id : boost::put_get_helper - { - typedef boost::readable_property_map_tag category; - typedef size_type value_type; - typedef size_type reference; - typedef Edge_handle key_type; + struct Compare_cost { + Compare_cost() : algorithm_(0) { } - Undirected_edge_id() : algorithm_(0) {} + Compare_cost(Self const* aAlgorithm) : algorithm_(aAlgorithm) { } - Undirected_edge_id( Self const* aAlgorithm ) : algorithm_(aAlgorithm) {} + bool operator()(Edge_handle a, Edge_handle b) const { + // NOTE: A cost is an optional<> value. + // Absent optionals are ordered first; that is, "none < T" and "T > none" for any defined T != none. + // In consequence, edges with undefined costs will be promoted to the top of the priority queue and popped out + // first. + return algorithm_->get_data(a).cost() < algorithm_->get_data(b).cost(); + } - size_type operator[] ( Edge_handle e ) const { return algorithm_->get_undirected_edge_id(e); } + Self const* algorithm_; + }; - Self const* algorithm_ ; - } ; + struct Undirected_edge_id : boost::put_get_helper { + typedef boost::readable_property_map_tag category; + typedef size_type value_type; + typedef size_type reference; + typedef Edge_handle key_type; - typedef CGAL::Modifiable_priority_queue PQ ; - typedef typename PQ::handle pq_handle ; + Undirected_edge_id() : algorithm_(0) { } + Undirected_edge_id(Self const* aAlgorithm) : algorithm_(aAlgorithm) { } - // An Edge_data is associated with EVERY edge in the complex (collapsible or not). - // It relates the edge with the PQ-handle needed to update the priority queue - // It also relates the edge with a policy-based cache - class Edge_data - { - public : + size_type operator[](Edge_handle e) const { + return algorithm_->get_undirected_edge_id(e); + } - Edge_data() : PQHandle_(),cost_() {} + Self const* algorithm_; + }; - Cost_type const& cost() const { return cost_ ; } - Cost_type & cost() { return cost_ ; } + typedef CGAL::Modifiable_priority_queue PQ; + typedef typename PQ::handle pq_handle; - pq_handle PQ_handle() const { return PQHandle_ ;} - bool is_in_PQ() const { return PQHandle_ != PQ::null_handle() ; } + // An Edge_data is associated with EVERY edge in the complex (collapsible or not). + // It relates the edge with the PQ-handle needed to update the priority queue + // It also relates the edge with a policy-based cache - void set_PQ_handle( pq_handle h ) { PQHandle_ = h ; } + class Edge_data { + public: + Edge_data() : PQHandle_(), cost_() { } - void reset_PQ_handle() { PQHandle_ = PQ::null_handle() ; } + Cost_type const& cost() const { + return cost_; + } - private: - pq_handle PQHandle_ ; - Cost_type cost_ ; + Cost_type & cost() { + return cost_; + } - } ; - typedef Edge_data* Edge_data_ptr ; - typedef boost::scoped_array Edge_data_array ; + pq_handle PQ_handle() const { + return PQHandle_; + } + bool is_in_PQ() const { + return PQHandle_ != PQ::null_handle(); + } - int get_undirected_edge_id ( Edge_handle edge ) const { - return complex_[edge].index() ; - } + void set_PQ_handle(pq_handle h) { + PQHandle_ = h; + } + void reset_PQ_handle() { + PQHandle_ = PQ::null_handle(); + } - const Edge_data& get_data ( Edge_handle edge ) const - { - return edge_data_array_[get_undirected_edge_id(edge)]; - } - - - Edge_data& get_data ( Edge_handle edge ) - { - return edge_data_array_[get_undirected_edge_id(edge)]; - } - - Cost_type get_cost(const Profile & profile) const{ - return (*cost_policy_)(profile,get_placement(profile)); - } - - Profile create_profile(Edge_handle edge) const{ - if(edge_profile_factory_) - return edge_profile_factory_->make_profile(complex_,edge); - else - return Profile(complex_,edge); - } - - - void insert_in_PQ( Edge_handle edge, Edge_data& data ) - { - data.set_PQ_handle(heap_PQ_->push(edge)); - ++current_num_edges_heap_; - } - - void update_in_PQ( Edge_handle edge, Edge_data& data ) - { - data.set_PQ_handle(heap_PQ_->update(edge,data.PQ_handle())) ; - } - - void remove_from_PQ( Edge_handle edge, Edge_data& data ) - { - data.set_PQ_handle(heap_PQ_->erase(edge,data.PQ_handle())); - --current_num_edges_heap_; - } - - boost::optional pop_from_PQ() { - boost::optional edge = heap_PQ_->extract_top(); - if ( edge ) - get_data(*edge).reset_PQ_handle(); - return edge ; - } - - - -private: - - /** - * @brief Collect edges. - * - * Iterates over all edges of the simplicial complex and - * 1) inserts them in the priority queue sorted according to the Cost policy. - * 2) set the id() field of each edge - */ - void collect_edges(){ - // - // Loop over all the edges in the complex in the heap - // - size_type size = complex_.num_edges(); - DBG("Collecting edges ..."); - DBGMSG("num edges :",size); - - edge_data_array_.reset( new Edge_data[size] ) ; - - heap_PQ_.reset( new PQ (size, Compare_cost(this), Undirected_edge_id(this) ) ) ; - - std::size_t id = 0 ; - - //xxx do a parralel for - for(auto edge : complex_.edge_range()){ - complex_[edge].index() = id++; - Profile const& profile = create_profile(edge); - Edge_data& data = get_data(edge); - data.cost() = get_cost(profile) ; - ++initial_num_edges_heap_; - insert_in_PQ(edge,data); - if(contraction_visitor_) contraction_visitor_->on_collected(profile,data.cost()); - } - - DBG("Edges collected."); - - } - - bool should_stop(double lCost,const Profile &profile) const{ - return false; - } - - boost::optional get_placement(const Profile& profile) const{ - return (*placement_policy_)(profile); - } - - bool is_contraction_valid( Profile const& profile, Placement_type placement ) const{ - if(!valid_contraction_policy_) return true; - return (*valid_contraction_policy_)(profile,placement); - } - - -public: - /** - * \brief Contract edges. - * - * While the heap is not empty, it extracts the edge with the minimum - * cost in the heap then try to contract it. - * It stops when the Stop policy says so or when the number of contractions - * given by 'num_max_contractions' is reached (if this number is positive). - */ - void contract_edges(int num_max_contractions=-1){ - - DBG("\n\nContract edges"); - int num_contraction = 0 ; - - bool unspecified_num_contractions = (num_max_contractions == -1); - // - // Pops and processes each edge from the PQ - // - boost::optional edge ; - while ( (edge = pop_from_PQ())&& ((num_contractionon_selected(profile,cost,0,0); - - DBGMSG("\n\n---- Pop edge - num vertices :",complex_.num_vertices()); - - if (cost){ - DBGMSG("sqrt(cost):",std::sqrt(*cost)); - if (should_stop(*cost,profile) ) - { - if(contraction_visitor_) contraction_visitor_->on_stop_condition_reached(); - DBG("should_stop"); - break ; - } - Placement_type placement = get_placement(profile); - if ( is_contraction_valid(profile,placement) && placement ) - { - DBG("contraction_valid"); - contract_edge(profile,placement); - ++ num_contraction; - } - else - { - DBG("contraction not valid"); - if(contraction_visitor_) contraction_visitor_->on_non_valid(profile); - } - } - else - DBG("uncomputable cost"); - } - if(contraction_visitor_) contraction_visitor_->on_stop_condition_reached(); - } - - - bool is_in_heap(Edge_handle edge) const{ - if(heap_PQ_->empty()) return false; - else{ - return edge_data_array_[get_undirected_edge_id(edge)].is_in_PQ(); - } - } - - bool is_heap_empty() const{ - return heap_PQ_->empty(); - } - - - /** - * @brief Returns an Edge_handle and a Placement_type. This pair consists in - * the edge with the lowest cost in the heap together with its placement. - * The returned value is initialized iff the heap is non-empty. - */ - boost::optional > top_edge(){ - boost::optional > res; - - if(!heap_PQ_->empty()) { - auto edge = heap_PQ_->top(); - Profile const& profile = create_profile(edge); - Placement_type placement = get_placement(profile); - res = make_pair(edge,placement); - DBGMSG("top edge:",complex_[edge]); - - } - return res; - } - - - /** - * @brief Constructor with default policies. - * - * @details The default cost, placement, valid and visitor policies - * are respectively : the edge length, the first point, the link condition - */ - Skeleton_blocker_contractor(GeometricSimplifiableComplex& complex) - :complex_(complex), - cost_policy_(new Edge_length_cost), - placement_policy_(new First_vertex_placement), - valid_contraction_policy_(new Link_condition_valid_contraction), - contraction_visitor_(new Contraction_visitor_()), - edge_profile_factory_(0), - initial_num_edges_heap_(0), - current_num_edges_heap_(0) - { - complex_.set_visitor(this); - if(contraction_visitor_) contraction_visitor_->on_started(complex); - collect_edges(); - } - - /** - * @brief Constructor with customed policies. - * @remark Policies destruction is handle by the class with smart pointers. - */ - Skeleton_blocker_contractor(GeometricSimplifiableComplex& complex, - Cost_policy_ *cost_policy, - Placement_policy_ * placement_policy = new First_vertex_placement, - Valid_contraction_policy_ * valid_contraction_policy = new Link_condition_valid_contraction, - Contraction_visitor_* contraction_visitor = new Contraction_visitor_(), - Edge_profile_factory_* edge_profile_factory = NULL - ): - complex_(complex), - cost_policy_(cost_policy), - placement_policy_(placement_policy), - valid_contraction_policy_(valid_contraction_policy), - contraction_visitor_(contraction_visitor), - edge_profile_factory_(edge_profile_factory), - initial_num_edges_heap_(0), - current_num_edges_heap_(0) - { - complex_.set_visitor(this); - if(contraction_visitor) contraction_visitor->on_started(complex); - collect_edges(); - } - - - ~Skeleton_blocker_contractor(){ - complex_.set_visitor(0); - } - -private: - - - void contract_edge(const Profile& profile, Placement_type placement ) { - if(contraction_visitor_) contraction_visitor_->on_contracting(profile,placement); - - assert(complex_.contains_vertex(profile.v0_handle())); - assert(complex_.contains_vertex(profile.v1_handle())); - assert(placement); - - profile.complex().point(profile.v0_handle()) = *placement; - - // remark : this is not necessary since v1 will be deactivated - // profile.complex().point(profile.v1_handle()) = *placement; - - complex_.contract_edge(profile.v0_handle(),profile.v1_handle()); - - assert(complex_.contains_vertex(profile.v0_handle())); - assert(!complex_.contains_vertex(profile.v1_handle())); - - update_changed_edges(); - - // the visitor could do something as complex_.remove_popable_blockers(); - if(contraction_visitor_) contraction_visitor_->on_contracted(profile,placement); - } - -private: - - // every time the visitor's method on_changed_edge is called, it adds an - // edge to changed_edges_ - std::vector< Edge_handle > changed_edges_; - - /** - * @brief we update the cost and the position in the heap of an edge that has - * been changed - */ - inline void on_changed_edge(Vertex_handle a,Vertex_handle b) override{ - boost::optional ab(complex_[std::make_pair(a,b)]); - assert(ab); - changed_edges_.push_back(*ab); - } - - void update_changed_edges(){ - //xxx do a parralel for - - DBG("update edges"); - - // sequential loop - for(auto ab : changed_edges_){ - //1-get the Edge_handle corresponding to ab - //2-change the data in mEdgeArray[ab.id()] - //3-update the heap - Edge_data& data = get_data(ab); - Profile const& profile = create_profile(ab); - data.cost() = get_cost(profile) ; - if ( data.is_in_PQ()){ - update_in_PQ(ab,data); - } - else{ - insert_in_PQ(ab,data); - } - } - changed_edges_.clear(); - } - - -private: - void on_remove_edge(Vertex_handle a,Vertex_handle b) override{ - - boost::optional ab((complex_[std::make_pair(a,b)])); - assert(ab); - Edge_data& lData = get_data(*ab) ; - if ( lData.is_in_PQ() ) - { - remove_from_PQ(*ab,lData) ; - } - } -private: - /** - * @brief Called when the edge 'ax' has been added while the edge 'bx' - * is still there but will be removed on next instruction. - * We assign the index of 'bx' to the edge index of 'ax' - */ - void on_swaped_edge(Vertex_handle a,Vertex_handle b,Vertex_handle x) override{ - boost::optional ax(complex_[std::make_pair(a,x)]); - boost::optional bx(complex_[std::make_pair(b,x)]); - assert(ax&& bx); - complex_[*ax].index() =complex_[*bx].index(); - } -private: - /** - * @brief Called when a blocker is removed. - * All the edges that passes through the blocker may be edge-contractible - * again and are thus reinserted in the heap. - */ - void on_delete_blocker(const Simplex_handle * blocker) override{ - // we go for all pairs xy that belongs to the blocker - // note that such pairs xy are necessarily edges of the complex - // by definition of a blocker - - // todo uniqument utile pour la link condition - // laisser à l'utilisateur? booleen update_heap_on_removed_blocker? - Simplex_handle blocker_copy(*blocker); - for (auto x = blocker_copy.begin(); x!= blocker_copy.end(); ++x){ - for(auto y=x ; ++y != blocker_copy.end(); ){ - auto edge_descr(complex_[std::make_pair(*x,*y)]); - assert(edge_descr); - Edge_data& data = get_data(*edge_descr); - Profile const& profile = create_profile(*edge_descr); - data.cost() = get_cost(profile) ; - - // If the edge is already in the heap - // its priority has not changed. - // If the edge is not present, we reinsert it - // remark : we could also reinsert the edge - // only if it is valid - if ( !data.is_in_PQ() ){ - insert_in_PQ(*edge_descr,data); - } - } - } - } - - -private: - std::shared_ptr cost_policy_; - std::shared_ptr placement_policy_; - std::shared_ptr valid_contraction_policy_; - std::shared_ptr contraction_visitor_; - - //in case the user wants to do something special when the edge profile - //are created (for instance add some info) - std::shared_ptr edge_profile_factory_; - Edge_data_array edge_data_array_ ; - - boost::scoped_ptr heap_PQ_ ; - int initial_num_edges_heap_; - int current_num_edges_heap_; - + private: + pq_handle PQHandle_; + Cost_type cost_; + }; + typedef Edge_data* Edge_data_ptr; + typedef boost::scoped_array Edge_data_array; + + int get_undirected_edge_id(Edge_handle edge) const { + return complex_[edge].index(); + } + + const Edge_data& get_data(Edge_handle edge) const { + return edge_data_array_[get_undirected_edge_id(edge)]; + } + + Edge_data& get_data(Edge_handle edge) { + return edge_data_array_[get_undirected_edge_id(edge)]; + } + + Cost_type get_cost(const Profile & profile) const { + return (*cost_policy_)(profile, get_placement(profile)); + } + + Profile create_profile(Edge_handle edge) const { + if (edge_profile_factory_) + return edge_profile_factory_->make_profile(complex_, edge); + else + return Profile(complex_, edge); + } + + void insert_in_PQ(Edge_handle edge, Edge_data& data) { + data.set_PQ_handle(heap_PQ_->push(edge)); + ++current_num_edges_heap_; + } + + void update_in_PQ(Edge_handle edge, Edge_data& data) { + data.set_PQ_handle(heap_PQ_->update(edge, data.PQ_handle())); + } + + void remove_from_PQ(Edge_handle edge, Edge_data& data) { + data.set_PQ_handle(heap_PQ_->erase(edge, data.PQ_handle())); + --current_num_edges_heap_; + } + + boost::optional pop_from_PQ() { + boost::optional edge = heap_PQ_->extract_top(); + if (edge) + get_data(*edge).reset_PQ_handle(); + return edge; + } + + private: + /** + * @brief Collect edges. + * + * Iterates over all edges of the simplicial complex and + * 1) inserts them in the priority queue sorted according to the Cost policy. + * 2) set the id() field of each edge + */ + void collect_edges() { + // + // Loop over all the edges in the complex in the heap + // + size_type size = complex_.num_edges(); + DBG("Collecting edges ..."); + DBGMSG("num edges :", size); + + edge_data_array_.reset(new Edge_data[size]); + + heap_PQ_.reset(new PQ(size, Compare_cost(this), Undirected_edge_id(this))); + + std::size_t id = 0; + + // xxx do a parralel for + for (auto edge : complex_.edge_range()) { + complex_[edge].index() = id++; + Profile const& profile = create_profile(edge); + Edge_data& data = get_data(edge); + data.cost() = get_cost(profile); + ++initial_num_edges_heap_; + insert_in_PQ(edge, data); + if (contraction_visitor_) contraction_visitor_->on_collected(profile, data.cost()); + } + + DBG("Edges collected."); + } + + bool should_stop(double lCost, const Profile &profile) const { + return false; + } + + boost::optional get_placement(const Profile& profile) const { + return (*placement_policy_)(profile); + } + + bool is_contraction_valid(Profile const& profile, Placement_type placement) const { + if (!valid_contraction_policy_) return true; + return (*valid_contraction_policy_)(profile, placement); + } + + + public: + /** + * \brief Contract edges. + * + * While the heap is not empty, it extracts the edge with the minimum + * cost in the heap then try to contract it. + * It stops when the Stop policy says so or when the number of contractions + * given by 'num_max_contractions' is reached (if this number is positive). + */ + void contract_edges(int num_max_contractions = -1) { + DBG("\n\nContract edges"); + int num_contraction = 0; + + bool unspecified_num_contractions = (num_max_contractions == -1); + // + // Pops and processes each edge from the PQ + // + boost::optional edge; + while ((edge = pop_from_PQ()) && ((num_contraction < num_max_contractions) || (unspecified_num_contractions))) { + Profile const& profile = create_profile(*edge); + Cost_type cost(get_data(*edge).cost()); + if (contraction_visitor_) contraction_visitor_->on_selected(profile, cost, 0, 0); + + DBGMSG("\n\n---- Pop edge - num vertices :", complex_.num_vertices()); + + if (cost) { + DBGMSG("sqrt(cost):", std::sqrt(*cost)); + if (should_stop(*cost, profile)) { + if (contraction_visitor_) contraction_visitor_->on_stop_condition_reached(); + DBG("should_stop"); + break; + } + Placement_type placement = get_placement(profile); + if (is_contraction_valid(profile, placement) && placement) { + DBG("contraction_valid"); + contract_edge(profile, placement); + ++num_contraction; + } else { + DBG("contraction not valid"); + if (contraction_visitor_) contraction_visitor_->on_non_valid(profile); + } + } else { + DBG("uncomputable cost"); + } + } + if (contraction_visitor_) contraction_visitor_->on_stop_condition_reached(); + } + + bool is_in_heap(Edge_handle edge) const { + if (heap_PQ_->empty()) { + return false; + } else { + return edge_data_array_[get_undirected_edge_id(edge)].is_in_PQ(); + } + } + + bool is_heap_empty() const { + return heap_PQ_->empty(); + } + + /** + * @brief Returns an Edge_handle and a Placement_type. This pair consists in + * the edge with the lowest cost in the heap together with its placement. + * The returned value is initialized iff the heap is non-empty. + */ + boost::optional > top_edge() { + boost::optional > res; + + if (!heap_PQ_->empty()) { + auto edge = heap_PQ_->top(); + Profile const& profile = create_profile(edge); + Placement_type placement = get_placement(profile); + res = std::make_pair(edge, placement); + DBGMSG("top edge:", complex_[edge]); + } + return res; + } + + /** + * @brief Constructor with default policies. + * + * @details The default cost, placement, valid and visitor policies + * are respectively : the edge length, the first point, the link condition + */ + Skeleton_blocker_contractor(GeometricSimplifiableComplex& complex) + : complex_(complex), + cost_policy_(new Edge_length_cost), + placement_policy_(new First_vertex_placement), + valid_contraction_policy_(new Link_condition_valid_contraction), + contraction_visitor_(new Contraction_visitor_()), + edge_profile_factory_(0), + initial_num_edges_heap_(0), + current_num_edges_heap_(0) { + complex_.set_visitor(this); + if (contraction_visitor_) contraction_visitor_->on_started(complex); + collect_edges(); + } + + /** + * @brief Constructor with customed policies. + * @remark Policies destruction is handle by the class with smart pointers. + */ + Skeleton_blocker_contractor(GeometricSimplifiableComplex& complex, + Cost_policy_ *cost_policy, + Placement_policy_ * placement_policy = new First_vertex_placement, + Valid_contraction_policy_ * valid_contraction_policy = + new Link_condition_valid_contraction, + Contraction_visitor_* contraction_visitor = new Contraction_visitor_(), + Edge_profile_factory_* edge_profile_factory = NULL) : + complex_(complex), + cost_policy_(cost_policy), + placement_policy_(placement_policy), + valid_contraction_policy_(valid_contraction_policy), + contraction_visitor_(contraction_visitor), + edge_profile_factory_(edge_profile_factory), + initial_num_edges_heap_(0), + current_num_edges_heap_(0) { + complex_.set_visitor(this); + if (contraction_visitor) contraction_visitor->on_started(complex); + collect_edges(); + } + + ~Skeleton_blocker_contractor() { + complex_.set_visitor(0); + } + + private: + void contract_edge(const Profile& profile, Placement_type placement) { + if (contraction_visitor_) contraction_visitor_->on_contracting(profile, placement); + + assert(complex_.contains_vertex(profile.v0_handle())); + assert(complex_.contains_vertex(profile.v1_handle())); + assert(placement); + + profile.complex().point(profile.v0_handle()) = *placement; + + // remark : this is not necessary since v1 will be deactivated + // profile.complex().point(profile.v1_handle()) = *placement; + + complex_.contract_edge(profile.v0_handle(), profile.v1_handle()); + + assert(complex_.contains_vertex(profile.v0_handle())); + assert(!complex_.contains_vertex(profile.v1_handle())); + + update_changed_edges(); + + // the visitor could do something as complex_.remove_popable_blockers(); + if (contraction_visitor_) contraction_visitor_->on_contracted(profile, placement); + } + + private: + // every time the visitor's method on_changed_edge is called, it adds an + // edge to changed_edges_ + std::vector< Edge_handle > changed_edges_; + + /** + * @brief we update the cost and the position in the heap of an edge that has + * been changed + */ + inline void on_changed_edge(Vertex_handle a, Vertex_handle b) override { + boost::optional ab(complex_[std::make_pair(a, b)]); + assert(ab); + changed_edges_.push_back(*ab); + } + + void update_changed_edges() { + // xxx do a parralel for + DBG("update edges"); + + // sequential loop + for (auto ab : changed_edges_) { + // 1-get the Edge_handle corresponding to ab + // 2-change the data in mEdgeArray[ab.id()] + // 3-update the heap + Edge_data& data = get_data(ab); + Profile const& profile = create_profile(ab); + data.cost() = get_cost(profile); + if (data.is_in_PQ()) { + update_in_PQ(ab, data); + } else { + insert_in_PQ(ab, data); + } + } + changed_edges_.clear(); + } + + + private: + void on_remove_edge(Vertex_handle a, Vertex_handle b) override { + boost::optional ab((complex_[std::make_pair(a, b)])); + assert(ab); + Edge_data& lData = get_data(*ab); + if (lData.is_in_PQ()) { + remove_from_PQ(*ab, lData); + } + } + + private: + /** + * @brief Called when the edge 'ax' has been added while the edge 'bx' + * is still there but will be removed on next instruction. + * We assign the index of 'bx' to the edge index of 'ax' + */ + void on_swaped_edge(Vertex_handle a, Vertex_handle b, Vertex_handle x) override { + boost::optional ax(complex_[std::make_pair(a, x)]); + boost::optional bx(complex_[std::make_pair(b, x)]); + assert(ax && bx); + complex_[*ax].index() = complex_[*bx].index(); + } + + private: + /** + * @brief Called when a blocker is removed. + * All the edges that passes through the blocker may be edge-contractible + * again and are thus reinserted in the heap. + */ + void on_delete_blocker(const Simplex_handle * blocker) override { + // we go for all pairs xy that belongs to the blocker + // note that such pairs xy are necessarily edges of the complex + // by definition of a blocker + + // todo uniqument utile pour la link condition + // laisser a l'utilisateur ? booleen update_heap_on_removed_blocker? + Simplex_handle blocker_copy(*blocker); + for (auto x = blocker_copy.begin(); x != blocker_copy.end(); ++x) { + for (auto y = x; ++y != blocker_copy.end();) { + auto edge_descr(complex_[std::make_pair(*x, *y)]); + assert(edge_descr); + Edge_data& data = get_data(*edge_descr); + Profile const& profile = create_profile(*edge_descr); + data.cost() = get_cost(profile); + + // If the edge is already in the heap + // its priority has not changed. + // If the edge is not present, we reinsert it + // remark : we could also reinsert the edge + // only if it is valid + if (!data.is_in_PQ()) { + insert_in_PQ(*edge_descr, data); + } + } + } + } + + + private: + std::shared_ptr cost_policy_; + std::shared_ptr placement_policy_; + std::shared_ptr valid_contraction_policy_; + std::shared_ptr contraction_visitor_; + + // in case the user wants to do something special when the edge profile + // are created (for instance add some info) + std::shared_ptr edge_profile_factory_; + Edge_data_array edge_data_array_; + + boost::scoped_ptr heap_PQ_; + int initial_num_edges_heap_; + int current_num_edges_heap_; }; } // namespace contraction -} // namespace GUDHI -#endif /* GUDHI_SKELETON_BLOCKER_CONTRACTOR_H_ */ +} // namespace Gudhi + +#endif // SKELETON_BLOCKER_CONTRACTOR_H_ diff --git a/src/cmake/modules/FindEigen3.cmake b/src/cmake/modules/FindEigen3.cmake new file mode 100644 index 00000000..70c07dfb --- /dev/null +++ b/src/cmake/modules/FindEigen3.cmake @@ -0,0 +1,86 @@ +# - Try to find Eigen3 lib +# +# This module supports requiring a minimum version, e.g. you can do +# find_package(Eigen3 3.1.2) +# to require version 3.1.2 or newer of Eigen3. +# +# Once done this will define +# +# EIGEN3_FOUND - system has eigen lib with correct version +# EIGEN3_INCLUDE_DIR - the eigen include directory +# EIGEN3_VERSION - eigen version + +# Copyright (c) 2006, 2007 Montel Laurent, +# Copyright (c) 2008, 2009 Gael Guennebaud, +# Copyright (c) 2009 Benoit Jacob +# Redistribution and use is allowed according to the terms of the 2-clause BSD license. + +include(FindPackageHandleStandardArgs) + +if(NOT Eigen3_FIND_VERSION) + if(NOT Eigen3_FIND_VERSION_MAJOR) + set(Eigen3_FIND_VERSION_MAJOR 2) + endif(NOT Eigen3_FIND_VERSION_MAJOR) + if(NOT Eigen3_FIND_VERSION_MINOR) + set(Eigen3_FIND_VERSION_MINOR 91) + endif(NOT Eigen3_FIND_VERSION_MINOR) + if(NOT Eigen3_FIND_VERSION_PATCH) + set(Eigen3_FIND_VERSION_PATCH 0) + endif(NOT Eigen3_FIND_VERSION_PATCH) + + set(Eigen3_FIND_VERSION "${Eigen3_FIND_VERSION_MAJOR}.${Eigen3_FIND_VERSION_MINOR}.${Eigen3_FIND_VERSION_PATCH}") +endif(NOT Eigen3_FIND_VERSION) + +macro(_eigen3_get_version) + file(READ "${EIGEN3_INCLUDE_DIR}/Eigen/src/Core/util/Macros.h" _eigen3_version_header) + + string(REGEX MATCH "define[ \t]+EIGEN_WORLD_VERSION[ \t]+([0-9]+)" _eigen3_world_version_match "${_eigen3_version_header}") + set(EIGEN3_WORLD_VERSION "${CMAKE_MATCH_1}") + string(REGEX MATCH "define[ \t]+EIGEN_MAJOR_VERSION[ \t]+([0-9]+)" _eigen3_major_version_match "${_eigen3_version_header}") + set(EIGEN3_MAJOR_VERSION "${CMAKE_MATCH_1}") + string(REGEX MATCH "define[ \t]+EIGEN_MINOR_VERSION[ \t]+([0-9]+)" _eigen3_minor_version_match "${_eigen3_version_header}") + set(EIGEN3_MINOR_VERSION "${CMAKE_MATCH_1}") + + set(EIGEN3_VERSION ${EIGEN3_WORLD_VERSION}.${EIGEN3_MAJOR_VERSION}.${EIGEN3_MINOR_VERSION}) +endmacro(_eigen3_get_version) + +set(EIGEN3_USE_FILE "UseEigen3") + +if (EIGEN3_INCLUDE_DIR) + + if (EXISTS ${EIGEN3_INCLUDE_DIR}/signature_of_eigen3_matrix_library) + # in cache already and valid + _eigen3_get_version() + set(EIGEN3_FOUND ${EIGEN3_VERSION_OK}) + + find_package_handle_standard_args(Eigen3 + REQUIRED_VARS EIGEN3_INCLUDE_DIR + VERSION_VAR EIGEN3_VERSION) + + else() + message(STATUS "Eigen3 path specified in cmake variable EIGEN3_INCLUDE_DIR is " + "set to ${EIGEN3_INCLUDE_DIR}, but that path does not contains the file " + "signature_of_eigen3_matrix_library and is considered as invalid.") + endif() + + + +else (EIGEN3_INCLUDE_DIR) + + find_path(EIGEN3_INCLUDE_DIR NAMES signature_of_eigen3_matrix_library + HINTS ENV EIGEN3_INC_DIR + ENV EIGEN3_DIR + PATHS ${KDE4_INCLUDE_DIR} + PATH_SUFFIXES include eigen3 eigen + DOC "Directory containing the Eigen3 header files" + ) + + if(EIGEN3_INCLUDE_DIR) + _eigen3_get_version() + endif(EIGEN3_INCLUDE_DIR) + + find_package_handle_standard_args(Eigen3 + REQUIRED_VARS EIGEN3_INCLUDE_DIR + VERSION_VAR EIGEN3_VERSION) + +endif(EIGEN3_INCLUDE_DIR) diff --git a/src/cmake/modules/UseEigen3.cmake b/src/cmake/modules/UseEigen3.cmake new file mode 100644 index 00000000..e3ed18be --- /dev/null +++ b/src/cmake/modules/UseEigen3.cmake @@ -0,0 +1,9 @@ +# This module setups the compiler for using Eigen v3 library. +# It assumes that find_package(Eigen3) was already called. + + +include_directories( SYSTEM ${EIGEN3_INCLUDE_DIR} ) + +add_definitions(-DCGAL_EIGEN3_ENABLED) + +set (EIGEN3_SETUP TRUE) -- cgit v1.2.3 From 6dd03d72142c98c4348e1b95d538de3b184bbc59 Mon Sep 17 00:00:00 2001 From: vrouvrea Date: Thu, 8 Oct 2015 14:09:30 +0000 Subject: 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 --- CMakeLists.txt | 3 - src/CMakeLists.txt | 2 - .../CGAL_queue/Modifiable_priority_queue.h | 6 +- .../Contraction/policies/Contraction_visitor.h | 164 +++++------ .../gudhi/Contraction/policies/Cost_policy.h | 76 ++--- .../Contraction/policies/Dummy_valid_contraction.h | 84 +++--- .../gudhi/Contraction/policies/Edge_length_cost.h | 90 +++--- .../Contraction/policies/First_vertex_placement.h | 81 +++--- .../policies/Link_condition_valid_contraction.h | 96 +++--- .../gudhi/Contraction/policies/Middle_placement.h | 87 +++--- .../gudhi/Contraction/policies/Placement_policy.h | 76 ++--- .../policies/Valid_contraction_policy.h | 80 ++--- src/Hasse_complex/example/CMakeLists.txt | 5 - .../example/hasse_complex_from_simplex_tree.cpp | 124 -------- src/Hasse_complex/include/gudhi/Hasse_complex.h | 323 +++++++++++---------- src/Simplex_tree/test/simplex_tree_unit_test.cpp | 3 + .../test/TestSkeletonBlockerComplex.cpp | 2 +- src/common/include/gudhi/Off_reader.h | 2 +- 18 files changed, 598 insertions(+), 706 deletions(-) delete mode 100644 src/Hasse_complex/example/CMakeLists.txt delete mode 100644 src/Hasse_complex/example/hasse_complex_from_simplex_tree.cpp (limited to 'src') diff --git a/CMakeLists.txt b/CMakeLists.txt index 76e55d43..ae089562 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -75,9 +75,6 @@ else() add_subdirectory(src/Skeleton_blocker/test) add_subdirectory(src/Skeleton_blocker/example) add_subdirectory(src/Contraction/example) - add_subdirectory(src/Hasse_complex/example) - add_subdirectory(src/Bottleneck/example) - add_subdirectory(src/Bottleneck/test) # data points generator add_subdirectory(data/points/generator) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index b782b9f3..a84090e9 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -48,8 +48,6 @@ else() add_subdirectory(example/Persistent_cohomology) add_subdirectory(example/Skeleton_blocker) add_subdirectory(example/Contraction) - add_subdirectory(example/Hasse_complex) - add_subdirectory(example/Bottleneck) # data points generator add_subdirectory(data/points/generator) diff --git a/src/Contraction/include/gudhi/Contraction/CGAL_queue/Modifiable_priority_queue.h b/src/Contraction/include/gudhi/Contraction/CGAL_queue/Modifiable_priority_queue.h index f4eb59fd..28ae535d 100644 --- a/src/Contraction/include/gudhi/Contraction/CGAL_queue/Modifiable_priority_queue.h +++ b/src/Contraction/include/gudhi/Contraction/CGAL_queue/Modifiable_priority_queue.h @@ -21,10 +21,12 @@ #define CGAL_SURFACE_MESH_SIMPLIFICATION_USE_RELAXED_HEAP -#include // Neeeded by the following Boost header for CHAR_BIT. #include #include +#include // Neeeded by the following Boost header for CHAR_BIT. +#include // for less + namespace CGAL { template , class ID_ = boost::identity_property_map> @@ -94,6 +96,6 @@ class Modifiable_priority_queue { Heap mHeap; }; -} //namespace CGAL +} // namespace CGAL #endif // CONTRACTION_CGAL_MODIFIABLE_PRIORITY_QUEUE_H diff --git a/src/Contraction/include/gudhi/Contraction/policies/Contraction_visitor.h b/src/Contraction/include/gudhi/Contraction/policies/Contraction_visitor.h index b8b1e87a..7ee05aad 100644 --- a/src/Contraction/include/gudhi/Contraction/policies/Contraction_visitor.h +++ b/src/Contraction/include/gudhi/Contraction/policies/Contraction_visitor.h @@ -1,32 +1,32 @@ - /* 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-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 - * 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 . - */ - -#ifndef GUDHI_CONTRACTION_VISITOR_H_ -#define GUDHI_CONTRACTION_VISITOR_H_ - -#include "gudhi/Contraction/Edge_profile.h" -#include "boost/optional.hpp" - -namespace Gudhi{ +/* 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-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 + * 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 . + */ + +#ifndef CONTRACTION_POLICIES_CONTRACTION_VISITOR_H_ +#define CONTRACTION_POLICIES_CONTRACTION_VISITOR_H_ + +#include +#include + +namespace Gudhi { namespace contraction { @@ -36,66 +36,56 @@ namespace contraction { *@ingroup contr */ template -class Contraction_visitor {//: public Dummy_complex_visitor { -public: - //typedef typename ComplexType::GeometryTrait GT; - typedef EdgeProfile Profile; - typedef double FT; - typedef typename Profile::Complex Complex; - typedef Complex ComplexType; - typedef typename ComplexType::Point Point; - - - virtual ~Contraction_visitor(){}; - - /** - * @brief Called before the edge contraction process starts. - */ - virtual void on_started (ComplexType & complex){} - - /** - * @brief Called when the algorithm stops. - */ - virtual void on_stop_condition_reached (){} - - - /** - * @brief Called during the collecting phase (when a cost is assigned to the edges), for each edge collected. - */ - virtual void on_collected (const Profile &profile, boost::optional< FT > cost){} - - /** - * @brief Called during the processing phase (when edges are contracted), for each edge that is selected. - */ - virtual void on_selected (const Profile &profile, boost::optional< FT > cost, int initial_count, int current_count){} - - - /** - * @brief Called when an edge is about to be contracted and replaced by a vertex whose position is *placement. - */ - virtual void on_contracting(const Profile &profile, boost::optional< Point > placement){ - } - - - - /** - * @brief Called when after an edge has been contracted onto a new point placement. - * A possibility would to remove popable blockers at this point for instance. - */ - virtual void on_contracted(const Profile &profile, boost::optional< Point > placement){ - - } - - - /** - * @brief Called for each selected edge which cannot be contracted because the ValidContractionPredicate is false - */ - virtual void on_non_valid(const Profile &profile){} - +class Contraction_visitor { // : public Dummy_complex_visitor { + public: + // typedef typename ComplexType::GeometryTrait GT; + typedef EdgeProfile Profile; + typedef double FT; + typedef typename Profile::Complex Complex; + typedef Complex ComplexType; + typedef typename ComplexType::Point Point; + + virtual ~Contraction_visitor() { } + + /** + * @brief Called before the edge contraction process starts. + */ + virtual void on_started(ComplexType & complex) { } + + /** + * @brief Called when the algorithm stops. + */ + virtual void on_stop_condition_reached() { } + + /** + * @brief Called during the collecting phase (when a cost is assigned to the edges), for each edge collected. + */ + virtual void on_collected(const Profile &profile, boost::optional< FT > cost) { } + + /** + * @brief Called during the processing phase (when edges are contracted), for each edge that is selected. + */ + virtual void on_selected(const Profile &profile, boost::optional< FT > cost, int initial_count, int current_count) { } + + /** + * @brief Called when an edge is about to be contracted and replaced by a vertex whose position is *placement. + */ + virtual void on_contracting(const Profile &profile, boost::optional< Point > placement) { } + + /** + * @brief Called when after an edge has been contracted onto a new point placement. + * A possibility would to remove popable blockers at this point for instance. + */ + virtual void on_contracted(const Profile &profile, boost::optional< Point > placement) { } + + /** + * @brief Called for each selected edge which cannot be contracted because the ValidContractionPredicate is false + */ + virtual void on_non_valid(const Profile &profile) { } }; } // namespace contraction -} // namespace GUDHI +} // namespace Gudhi -#endif /* GUDHI_CONTRACTION_VISITOR_H_ */ +#endif // CONTRACTION_POLICIES_CONTRACTION_VISITOR_H_ diff --git a/src/Contraction/include/gudhi/Contraction/policies/Cost_policy.h b/src/Contraction/include/gudhi/Contraction/policies/Cost_policy.h index 3cb18c86..f4d343ec 100644 --- a/src/Contraction/include/gudhi/Contraction/policies/Cost_policy.h +++ b/src/Contraction/include/gudhi/Contraction/policies/Cost_policy.h @@ -1,51 +1,53 @@ - /* 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-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 - * 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 . - */ - -#ifndef GUDHI_COST_POLICY_H_ -#define GUDHI_COST_POLICY_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): David Salinas + * + * 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 + * 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 . + */ + +#ifndef CONTRACTION_POLICIES_COST_POLICY_H_ +#define CONTRACTION_POLICIES_COST_POLICY_H_ #include -namespace Gudhi{ +namespace Gudhi { namespace contraction { /** -*@brief Policy to specify the cost of contracting an edge. + *@brief Policy to specify the cost of contracting an edge. *@ingroup contr -*/ -template< typename EdgeProfile> class Cost_policy{ -public: - typedef typename EdgeProfile::Point Point; - typedef typename EdgeProfile::Graph_vertex Graph_vertex; + */ +template< typename EdgeProfile> +class Cost_policy { + public: + typedef typename EdgeProfile::Point Point; + typedef typename EdgeProfile::Graph_vertex Graph_vertex; - typedef boost::optional Cost_type; + typedef boost::optional Cost_type; - virtual Cost_type operator()(const EdgeProfile& profile, const boost::optional& placement) const =0; - virtual ~Cost_policy(){ - }; + virtual Cost_type operator()(const EdgeProfile& profile, const boost::optional& placement) const = 0; + + virtual ~Cost_policy() { } }; } // namespace contraction -} // namespace GUDHI -#endif /* GUDHI_COST_POLICY_H_ */ +} // namespace Gudhi + +#endif // CONTRACTION_POLICIES_COST_POLICY_H_ diff --git a/src/Contraction/include/gudhi/Contraction/policies/Dummy_valid_contraction.h b/src/Contraction/include/gudhi/Contraction/policies/Dummy_valid_contraction.h index de473944..5d329496 100644 --- a/src/Contraction/include/gudhi/Contraction/policies/Dummy_valid_contraction.h +++ b/src/Contraction/include/gudhi/Contraction/policies/Dummy_valid_contraction.h @@ -1,51 +1,49 @@ - /* 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-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 - * 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 . - */ - -#ifndef GUDHI_DUMMY_VALID_CONTRACTION_H_ -#define GUDHI_DUMMY_VALID_CONTRACTION_H_ - -#include "Valid_contraction_policy.h" - -namespace Gudhi{ +/* 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-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 + * 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 . + */ + +#ifndef CONTRACTION_POLICIES_DUMMY_VALID_CONTRACTION_H_ +#define CONTRACTION_POLICIES_DUMMY_VALID_CONTRACTION_H_ + +#include + +namespace Gudhi { namespace contraction { - - - /** - *@brief Policy that accept all edge contraction. - */ -template< typename EdgeProfile> class Dummy_valid_contraction : public Valid_contraction_policy{ -public: - typedef typename EdgeProfile::Point Point; - bool operator()(const EdgeProfile& profile,const boost::optional& placement){ - return true; - } +/** + *@brief Policy that accept all edge contraction. + */ +template< typename EdgeProfile> +class Dummy_valid_contraction : public Valid_contraction_policy { + public: + typedef typename EdgeProfile::Point Point; + + bool operator()(const EdgeProfile& profile, const boost::optional& placement) { + return true; + } }; } // namespace contraction -} // namespace GUDHI - - +} // namespace Gudhi -#endif /* GUDHI_DUMMY_VALID_CONTRACTION_H_ */ +#endif // CONTRACTION_POLICIES_DUMMY_VALID_CONTRACTION_H_ diff --git a/src/Contraction/include/gudhi/Contraction/policies/Edge_length_cost.h b/src/Contraction/include/gudhi/Contraction/policies/Edge_length_cost.h index b22ada0d..e4beb220 100644 --- a/src/Contraction/include/gudhi/Contraction/policies/Edge_length_cost.h +++ b/src/Contraction/include/gudhi/Contraction/policies/Edge_length_cost.h @@ -1,56 +1,56 @@ - /* 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-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 - * 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 . - */ - -#ifndef GUDHI_EDGE_LENGTH_COST_H_ -#define GUDHI_EDGE_LENGTH_COST_H_ - -#include "Cost_policy.h" - -namespace Gudhi{ +/* 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-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 + * 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 . + */ -namespace contraction { +#ifndef CONTRACTION_POLICIES_DUMMY_EDGE_LENGTH_COST_H_ +#define CONTRACTION_POLICIES_DUMMY_EDGE_LENGTH_COST_H_ + +#include +namespace Gudhi { + +namespace contraction { /** * @brief return a cost corresponding to the squared length of the edge */ -template< typename EdgeProfile> class Edge_length_cost : public Cost_policy{ -public: - typedef typename Cost_policy::Cost_type Cost_type; - typedef typename EdgeProfile::Point Point; - Cost_type operator()(const EdgeProfile& profile, const boost::optional& placement) const override{ - double res = 0; - auto p0_coord = profile.p0().begin(); - auto p1_coord = profile.p1().begin(); - for(; p0_coord != profile.p0().end(); p0_coord++, p1_coord++){ - res += (*p0_coord - *p1_coord) * (*p0_coord - *p1_coord); - } - return res; - } - +template< typename EdgeProfile> +class Edge_length_cost : public Cost_policy { + public: + typedef typename Cost_policy::Cost_type Cost_type; + typedef typename EdgeProfile::Point Point; + + Cost_type operator()(const EdgeProfile& profile, const boost::optional& placement) const override { + double res = 0; + auto p0_coord = profile.p0().begin(); + auto p1_coord = profile.p1().begin(); + for (; p0_coord != profile.p0().end(); p0_coord++, p1_coord++) { + res += (*p0_coord - *p1_coord) * (*p0_coord - *p1_coord); + } + return res; + } }; } // namespace contraction -} // namespace GUDHI +} // namespace Gudhi -#endif /* GUDHI_EDGE_LENGTH_COST_H_ */ +#endif // CONTRACTION_POLICIES_DUMMY_EDGE_LENGTH_COST_H_ diff --git a/src/Contraction/include/gudhi/Contraction/policies/First_vertex_placement.h b/src/Contraction/include/gudhi/Contraction/policies/First_vertex_placement.h index 93abac35..1f68db0d 100644 --- a/src/Contraction/include/gudhi/Contraction/policies/First_vertex_placement.h +++ b/src/Contraction/include/gudhi/Contraction/policies/First_vertex_placement.h @@ -1,53 +1,52 @@ - /* 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-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 - * 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 . - */ - -#ifndef GUDHI_FIRST_VERTEX_PLACEMENT_H_ -#define GUDHI_FIRST_VERTEX_PLACEMENT_H_ - -#include "Placement_policy.h" - -namespace Gudhi{ +/* 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-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 + * 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 . + */ -namespace contraction { +#ifndef CONTRACTION_POLICIES_FIRST_VERTEX_PLACEMENT_H_ +#define CONTRACTION_POLICIES_FIRST_VERTEX_PLACEMENT_H_ + +#include + +namespace Gudhi { +namespace contraction { /** * @brief Places the contracted point onto the first point of the edge */ -template< typename EdgeProfile> class First_vertex_placement : public Placement_policy{ - -public: - typedef typename EdgeProfile::Point Point; - typedef typename EdgeProfile::Edge_handle Edge_handle; +template< typename EdgeProfile> +class First_vertex_placement : public Placement_policy { + public: + typedef typename EdgeProfile::Point Point; + typedef typename EdgeProfile::Edge_handle Edge_handle; - typedef typename Placement_policy::Placement_type Placement_type; + typedef typename Placement_policy::Placement_type Placement_type; - Placement_type operator()(const EdgeProfile& profile) const override{ - return Placement_type(profile.p0()); - } + Placement_type operator()(const EdgeProfile& profile) const override { + return Placement_type(profile.p0()); + } }; -} // namespace contraction -} // namespace GUDHI +} // namespace contraction +} // namespace Gudhi -#endif /* GUDHI_FIRST_VERTEX_PLACEMENT_H_ */ +#endif // CONTRACTION_POLICIES_FIRST_VERTEX_PLACEMENT_H_ diff --git a/src/Contraction/include/gudhi/Contraction/policies/Link_condition_valid_contraction.h b/src/Contraction/include/gudhi/Contraction/policies/Link_condition_valid_contraction.h index c901e629..919df243 100644 --- a/src/Contraction/include/gudhi/Contraction/policies/Link_condition_valid_contraction.h +++ b/src/Contraction/include/gudhi/Contraction/policies/Link_condition_valid_contraction.h @@ -1,54 +1,56 @@ - /* 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-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 - * 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 . - */ - -#ifndef GUDHI_LINK_CONDITION_VALID_CONTRACTION_H_ -#define GUDHI_LINK_CONDITION_VALID_CONTRACTION_H_ - -#include "gudhi/Utils.h" -#include "Valid_contraction_policy.h" - - -namespace Gudhi{ +/* 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-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 + * 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 . + */ + +#ifndef CONTRACTION_POLICIES_LINK_CONDITION_VALID_CONTRACTION_H_ +#define CONTRACTION_POLICIES_LINK_CONDITION_VALID_CONTRACTION_H_ + +#include +#include + + +namespace Gudhi { namespace contraction { - - /** - *@brief Policy that only accept edges verifying the link condition (and therefore whose contraction preserving homotopy type). - *@ingroup contr - */ -template< typename EdgeProfile> class Link_condition_valid_contraction : public Valid_contraction_policy{ -public: - typedef typename EdgeProfile::Edge_handle Edge_handle; - typedef typename EdgeProfile::Point Point; - //typedef typename EdgeProfile::Edge_handle Edge_handle; - bool operator()(const EdgeProfile& profile,const boost::optional& placement) const override{ - Edge_handle edge(profile.edge_handle()); - DBGMSG("Link_condition_valid_contraction:",profile.complex().link_condition(edge)); - return profile.complex().link_condition(edge); - } +/** + *@brief Policy that only accept edges verifying the link condition (and therefore whose contraction preserving homotopy type). + *@ingroup contr + */ +template< typename EdgeProfile> +class Link_condition_valid_contraction : public Valid_contraction_policy { + public: + typedef typename EdgeProfile::Edge_handle Edge_handle; + typedef typename EdgeProfile::Point Point; + // typedef typename EdgeProfile::Edge_handle Edge_handle; + + bool operator()(const EdgeProfile& profile, const boost::optional& placement) const override { + Edge_handle edge(profile.edge_handle()); + DBGMSG("Link_condition_valid_contraction:", profile.complex().link_condition(edge)); + return profile.complex().link_condition(edge); + } }; + } // namespace contraction -} // namespace GUDHI +} // namespace Gudhi -#endif /* GUDHI_LINK_CONDITION_VALID_CONTRACTION_H_ */ +#endif // CONTRACTION_POLICIES_LINK_CONDITION_VALID_CONTRACTION_H_ diff --git a/src/Contraction/include/gudhi/Contraction/policies/Middle_placement.h b/src/Contraction/include/gudhi/Contraction/policies/Middle_placement.h index 30f0a570..4b59f1b5 100644 --- a/src/Contraction/include/gudhi/Contraction/policies/Middle_placement.h +++ b/src/Contraction/include/gudhi/Contraction/policies/Middle_placement.h @@ -1,52 +1,51 @@ - /* 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-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 - * 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 . - */ - -#ifndef GUDHI_MIDDLE_PLACEMENT_H_ -#define GUDHI_MIDDLE_PLACEMENT_H_ - -#include "Placement_policy.h" - - -namespace Gudhi{ +/* 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-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 + * 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 . + */ + +#ifndef CONTRACTION_POLICIES_MIDDLE_PLACEMENT_H_ +#define CONTRACTION_POLICIES_MIDDLE_PLACEMENT_H_ + +#include + +namespace Gudhi { namespace contraction { +template< typename EdgeProfile> +class Middle_placement : public Placement_policy { + public: + typedef typename EdgeProfile::Point Point; + typedef typename EdgeProfile::Edge_handle Edge_handle; + typedef typename EdgeProfile::Graph_vertex Graph_vertex; - -template< typename EdgeProfile> class Middle_placement : public Placement_policy{ + typedef typename Placement_policy::Placement_type Placement_type; -public: - typedef typename EdgeProfile::Point Point; - typedef typename EdgeProfile::Edge_handle Edge_handle; - typedef typename EdgeProfile::Graph_vertex Graph_vertex; - - typedef typename Placement_policy::Placement_type Placement_type; - - Placement_type operator()(const EdgeProfile& profile) const override{ - //todo compute the middle - return Placement_type(profile.p0()); - } + Placement_type operator()(const EdgeProfile& profile) const override { + // todo compute the middle + return Placement_type(profile.p0()); + } }; + } // namespace contraction -} // namespace GUDHI -#endif /* GUDHI_MIDDLE_PLACEMENT_H_ */ +} // namespace Gudhi + +#endif // CONTRACTION_POLICIES_MIDDLE_PLACEMENT_H_ diff --git a/src/Contraction/include/gudhi/Contraction/policies/Placement_policy.h b/src/Contraction/include/gudhi/Contraction/policies/Placement_policy.h index 3a804cf0..34ffa49f 100644 --- a/src/Contraction/include/gudhi/Contraction/policies/Placement_policy.h +++ b/src/Contraction/include/gudhi/Contraction/policies/Placement_policy.h @@ -1,49 +1,51 @@ - /* 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-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 - * 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 . - */ - -#ifndef GUDHI_PLACEMENT_POLICY_H_ -#define GUDHI_PLACEMENT_POLICY_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): David Salinas + * + * 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 + * 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 . + */ + +#ifndef CONTRACTION_POLICIES_PLACEMENT_POLICY_H_ +#define CONTRACTION_POLICIES_PLACEMENT_POLICY_H_ #include namespace Gudhi { + namespace contraction { +/** + *@brief Policy to specify where the merged point had to be placed after an edge contraction. + *@ingroup contr + */ +template< typename EdgeProfile> +class Placement_policy { + public: + typedef typename EdgeProfile::Point Point; + typedef boost::optional Placement_type; - /** - *@brief Policy to specify where the merged point had to be placed after an edge contraction. - *@ingroup contr - */ -template< typename EdgeProfile> class Placement_policy{ -public: - typedef typename EdgeProfile::Point Point; - typedef boost::optional Placement_type; + virtual Placement_type operator()(const EdgeProfile& profile) const = 0; - virtual Placement_type operator()(const EdgeProfile& profile) const=0; - virtual ~Placement_policy(){}; + virtual ~Placement_policy() { } }; - } // namespace contraction -} // namespace GUDHI -#endif /* GUDHI_PLACEMENT_POLICY_H_ */ +} // namespace Gudhi + +#endif // CONTRACTION_POLICIES_PLACEMENT_POLICY_H_ diff --git a/src/Contraction/include/gudhi/Contraction/policies/Valid_contraction_policy.h b/src/Contraction/include/gudhi/Contraction/policies/Valid_contraction_policy.h index bee2ecd7..78d61173 100644 --- a/src/Contraction/include/gudhi/Contraction/policies/Valid_contraction_policy.h +++ b/src/Contraction/include/gudhi/Contraction/policies/Valid_contraction_policy.h @@ -1,47 +1,51 @@ - /* 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-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 - * 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 . - */ - -#ifndef GUDHI_VALID_CONTRACTION_POLICY_H_ -#define GUDHI_VALID_CONTRACTION_POLICY_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): David Salinas + * + * 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 + * 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 . + */ + +#ifndef CONTRACTION_POLICIES_VALID_CONTRACTION_POLICY_H_ +#define CONTRACTION_POLICIES_VALID_CONTRACTION_POLICY_H_ namespace Gudhi { + namespace contraction { - /** - *@brief Policy to specify if an edge contraction is valid or not. - *@ingroup contr - */ -template< typename EdgeProfile> class Valid_contraction_policy{ -public: - typedef typename EdgeProfile::Point Point; - typedef typename EdgeProfile::Edge_handle Edge_handle; - typedef typename EdgeProfile::Graph_vertex Graph_vertex; - - virtual bool operator()(const EdgeProfile& profile,const boost::optional& placement) const =0; - virtual ~Valid_contraction_policy(){}; +/** + *@brief Policy to specify if an edge contraction is valid or not. + *@ingroup contr + */ +template< typename EdgeProfile> +class Valid_contraction_policy { + public: + typedef typename EdgeProfile::Point Point; + typedef typename EdgeProfile::Edge_handle Edge_handle; + typedef typename EdgeProfile::Graph_vertex Graph_vertex; + + virtual bool operator()(const EdgeProfile& profile, const boost::optional& placement) const = 0; + + virtual ~Valid_contraction_policy() { } }; } // namespace contraction -} // namespace GUDHI + +} // namespace Gudhi -#endif /* GUDHI_VALID_CONTRACTION_POLICY_H_ */ +#endif // CONTRACTION_POLICIES_VALID_CONTRACTION_POLICY_H_ 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 . - */ - -#include -#include -#include "gudhi/graph_simplicial_complex.h" -#include "gudhi/Simplex_tree.h" - -using namespace Gudhi; - -typedef std::vector< Vertex_handle > typeVectorVertex; -typedef std::pair 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 . - */ - -#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 . + */ + +#ifndef HASSE_COMPLEX_H_ +#define HASSE_COMPLEX_H_ -#include #include -namespace Gudhi{ +#include + +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 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 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_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_range; - - typedef typename std::vector< Simplex_handle >::iterator Boundary_simplex_iterator; - typedef boost::iterator_range 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_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_range; + + typedef typename std::vector< Simplex_handle >::iterator Boundary_simplex_iterator; + typedef boost::iterator_range 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 endpoints( Simplex_handle sh ) - { return std::pair( complex_[sh].boundary_[0] - , complex_[sh].boundary_[1] ) ;} + std::pair endpoints(Simplex_handle sh) { + return std::pair(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 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::Simplex_key > boundary; - typename Hasse_complex::Filtration_value fil; - typename Hasse_complex::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::Simplex_key > boundary; + typename Hasse_complex::Filtration_value fil; + typename Hasse_complex::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 >(key,fil,boundary)); + // insert every simplex in the simplex tree + hcpx.complex_.push_back(Hasse_simplex< Hasse_complex >(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_ diff --git a/src/Simplex_tree/test/simplex_tree_unit_test.cpp b/src/Simplex_tree/test/simplex_tree_unit_test.cpp index 1539ad2b..fff00d77 100644 --- a/src/Simplex_tree/test/simplex_tree_unit_test.cpp +++ b/src/Simplex_tree/test/simplex_tree_unit_test.cpp @@ -108,6 +108,7 @@ BOOST_AUTO_TEST_CASE(simplex_tree_from_file) { // Size of simplex int size = 0; for (auto vertex : st.simplex_vertex_range(f_simplex)) { + // Remove warning (void) vertex; size++; } @@ -164,6 +165,8 @@ void set_and_test_simplex_tree_dim_fil(typeST& simplexTree, int vectorSize, cons // Another way to count simplices: size_t num_simp = 0; for (auto f_simplex : simplexTree.complex_simplex_range()) { + // Remove warning + (void) f_simplex; num_simp++; } diff --git a/src/Skeleton_blocker/test/TestSkeletonBlockerComplex.cpp b/src/Skeleton_blocker/test/TestSkeletonBlockerComplex.cpp index 3dc38572..319e3c43 100644 --- a/src/Skeleton_blocker/test/TestSkeletonBlockerComplex.cpp +++ b/src/Skeleton_blocker/test/TestSkeletonBlockerComplex.cpp @@ -343,7 +343,7 @@ bool test_iterator_simplices3(){ bool test_iterator_simplices4(){ Complex empty_complex; for(auto v : empty_complex.vertex_range()){ - v; + (void) v; } for(auto e : empty_complex.edge_range()){ empty_complex[e]; diff --git a/src/common/include/gudhi/Off_reader.h b/src/common/include/gudhi/Off_reader.h index b70e7897..81b9e634 100644 --- a/src/common/include/gudhi/Off_reader.h +++ b/src/common/include/gudhi/Off_reader.h @@ -166,7 +166,7 @@ class Off_reader { iss >> num_face_vertices; std::vector face; face.assign(std::istream_iterator(iss), std::istream_iterator()); - if (!face.size() == off_info_.num_vertices) return false; + if (face.size() != off_info_.dim) return false; visitor.maximal_face(face); } return true; -- cgit v1.2.3 From 58e633f51ffa06aa219231cd1c08eab59457a12f Mon Sep 17 00:00:00 2001 From: vrouvrea Date: Thu, 8 Oct 2015 15:24:27 +0000 Subject: Fix cpplint on examples. Bug fix on persistence_from_simple_simplex_tree. Add persistence examples tests. git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/trunk@843 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 9b7b73abb4a5d6bb110376deb689247bfdae035c --- src/Contraction/example/Garland_heckbert.cpp | 36 ++- .../example/Garland_heckbert/Error_quadric.h | 324 +++++++++++---------- src/Contraction/example/Rips_contraction.cpp | 99 ++++--- src/Persistent_cohomology/example/CMakeLists.txt | 1 + .../example/alpha_shapes_persistence.cpp | 230 +++++++-------- .../example/performance_rips_persistence.cpp | 168 +++++------ .../example/persistence_from_file.cpp | 239 +++++++-------- .../persistence_from_simple_simplex_tree.cpp | 135 ++++----- .../example/rips_multifield_persistence.cpp | 234 +++++++-------- .../example/rips_persistence.cpp | 222 +++++++------- src/Skeleton_blocker/example/CMakeLists.txt | 6 +- .../example/Skeleton_blocker_from_simplices.cpp | 112 ++++--- .../example/Skeleton_blocker_iteration.cpp | 131 +++++---- .../example/Skeleton_blocker_link.cpp | 92 +++--- .../Skeleton_blocker_simple_traits.h | 2 +- 15 files changed, 1008 insertions(+), 1023 deletions(-) (limited to 'src') diff --git a/src/Contraction/example/Garland_heckbert.cpp b/src/Contraction/example/Garland_heckbert.cpp index a41f65aa..70f29b6a 100644 --- a/src/Contraction/example/Garland_heckbert.cpp +++ b/src/Contraction/example/Garland_heckbert.cpp @@ -1,7 +1,4 @@ -/* - * Garland_heckbert.h - * Created on: Feb 10, 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. * @@ -28,12 +25,13 @@ #ifndef GARLAND_HECKBERT_H_ #define GARLAND_HECKBERT_H_ +#include +#include +#include +#include + #include #include -#include "gudhi/Point.h" -#include "gudhi/Edge_contraction.h" -#include "gudhi/Skeleton_blocker.h" -#include "gudhi/Off_reader.h" #include "Garland_heckbert/Error_quadric.h" @@ -51,7 +49,6 @@ struct Geometry_trait { */ struct Garland_heckbert_traits : public Skeleton_blocker_simple_geometric_traits { public: - struct Garland_heckbert_vertex : public Simple_geometric_vertex { Error_quadric quadric; }; @@ -68,6 +65,7 @@ typedef Skeleton_blocker_contractor Complex_contractor; */ class GH_placement : public Gudhi::contraction::Placement_policy { Complex& complex_; + public: typedef Gudhi::contraction::Placement_policy::Placement_type Placement_type; @@ -91,8 +89,8 @@ class GH_placement : public Gudhi::contraction::Placement_policy { */ class GH_cost : public Gudhi::contraction::Cost_policy { Complex& complex_; - public: + public: typedef Gudhi::contraction::Cost_policy::Cost_type Cost_type; GH_cost(Complex& complex) : complex_(complex) { } @@ -115,13 +113,13 @@ class GH_cost : public Gudhi::contraction::Cost_policy { */ class GH_visitor : public Gudhi::contraction::Contraction_visitor { Complex& complex_; - public: + public: GH_visitor(Complex& complex) : complex_(complex) { } - //Compute quadrics for every vertex v - //The quadric of v consists in the sum of quadric - //of every triangles passing through v weighted by its area + // Compute quadrics for every vertex v + // The quadric of v consists in the sum of quadric + // of every triangles passing through v weighted by its area void on_started(Complex & complex) override { for (auto v : complex.vertex_range()) { @@ -147,7 +145,8 @@ class GH_visitor : public Gudhi::contraction::Contraction_visitor { int main(int argc, char *argv[]) { if (argc != 4) { - std::cerr << "Usage " << argv[0] << " input.off output.off N to load the file input.off, contract N edges and save the result to output.off.\n"; + std::cerr << "Usage " << argv[0] << " input.off output.off N to load the file input.off, contract N edges and save " + << "the result to output.off.\n"; return EXIT_FAILURE; } @@ -172,8 +171,7 @@ int main(int argc, char *argv[]) { new GH_cost(complex), new GH_placement(complex), contraction::make_link_valid_contraction(), - new GH_visitor(complex) - ); + new GH_visitor(complex)); std::cout << "Contract " << num_contractions << " edges" << std::endl; contractor.contract_edges(num_contractions); @@ -183,7 +181,7 @@ int main(int argc, char *argv[]) { complex.num_edges() << " edges and" << complex.num_triangles() << " triangles." << std::endl; - //write simplified complex + // write simplified complex Skeleton_blocker_off_writer off_writer(argv[2], complex); return EXIT_SUCCESS; @@ -191,4 +189,4 @@ int main(int argc, char *argv[]) { -#endif /* GARLAND_HECKBERT_H_ */ +#endif // GARLAND_HECKBERT_H_ diff --git a/src/Contraction/example/Garland_heckbert/Error_quadric.h b/src/Contraction/example/Garland_heckbert/Error_quadric.h index 72134c9d..a033aa00 100644 --- a/src/Contraction/example/Garland_heckbert/Error_quadric.h +++ b/src/Contraction/example/Garland_heckbert/Error_quadric.h @@ -1,164 +1,182 @@ -/* - * Error_quadric.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. * - * Created on: 24 janv. 2014 - * Author: dsalinas + * 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 . + * */ #ifndef ERROR_QUADRIC_H_ #define ERROR_QUADRIC_H_ -#include -#include #include +#include +#include -template class Error_quadric{ -private : - double coeff[10]; - -public : - Error_quadric(){ - clear(); - } - - /** - * Quadric corresponding to the L2 distance to the plane. - * - * According to the notation of Garland Heckbert, they - * denote a quadric symetric matrix as : - * Q = [ q11 q12 q13 q14] - * [ q12 q22 q23 q24] - * [ q13 q23 q33 q34] - * [ q14 q24 q34 q44] - * - * which is represented by a vector with 10 elts that - * are denoted ci for clarity with : - * Q = [ c0 c1 c2 c3 ] - * [ c1 c4 c5 c6 ] - * [ c2 c5 c7 c8 ] - * [ c3 c6 c8 c9 ] - * - * The constructor return the quadrics that represents - * the squared distance to the plane defined by triangle p0,p1,p2 - * times the area of triangle p0,p1,p2. - */ - Error_quadric(const Point & p0,const Point & p1,const Point & p2){ - - Point normal(unit_normal(p0,p1,p2)); - double a=normal[0]; - double b=normal[1]; - double c=normal[2]; - double d= -a*p0[0]-b*p0[1]-c*p0[2]; - coeff[0] = a*a ; - coeff[1] = a*b ; - coeff[2] = a*c ; - coeff[3] = a*d ; - coeff[4] = b*b ; - coeff[5] = b*c ; - coeff[6] = b*d ; - coeff[7] = c*c ; - coeff[8] = c*d ; - coeff[9] = d*d ; - - double area_p0p1p2 = std::sqrt(squared_area(p0,p1,p2)); - for(auto& x : coeff) - x*= area_p0p1p2; - } - - - inline double squared_area(const Point& p0,const Point& p1,const Point& p2) { - //if (x1,x2,x3) = p1-p0 and (y1,y2,y3) = p2-p0 - //then the squared area is = (u^2+v^2+w^2)/4 - //with: u = x2 * y3 - x3 * y2; - // v = x3 * y1 - x1 * y3; - // w = x1 * y2 - x2 * y1; - Point p0p1(p1-p0); - Point p0p2(p2-p0); - double A = p0p1[1] * p0p2[2] - p0p1[2] * p0p2[1]; - double B = p0p1[2] * p0p2[0] - p0p1[0] * p0p2[2]; - double C = p0p1[0] * p0p2[1] - p0p1[1] * p0p2[0]; - return 1./4. * (A*A+B*B+C*C); - } - - - void clear(){ - for(auto& x:coeff) - x=0; - } - - Error_quadric& operator+=(const Error_quadric& other){ - if(this!=&other) - for(int i = 0 ; i < 10; ++i) - coeff[i] += other.coeff[i]; - return *this; - } - - /** - * @return The quadric quost defined by the scalar product v^T Q v where Q is the quadratic form of Garland/Heckbert - */ - inline double cost(const Point& point) const{ - double cost = - coeff[0]*point.x()*point.x()+coeff[4]*point.y()*point.y()+coeff[7]*point.z()*point.z() - +2*(coeff[1]*point.x()*point.y()+coeff[5]*point.y()*point.z()+coeff[2]*point.z()*point.x()) - +2*(coeff[3]*point.x()+coeff[6]*point.y()+coeff[8]*point.z()) - +coeff[9]; - if(cost<0) return 0; - else { - return cost; - } - } - - inline double grad_determinant() const{ - return - coeff[0] * coeff[4] * coeff[7] - - coeff[0] * coeff[5] * coeff[5] - - coeff[1] * coeff[1] * coeff[7] - +2*coeff[1] * coeff[5] * coeff[2] - - coeff[4] * coeff[2] * coeff[2]; - } - - /** - * Return the point such that it minimizes the gradient of the quadric. - * Det must be passed with the determinant value of the gradient (should be non zero). - */ - inline Point solve_linear_gradient(double det) const{ - return Point({ - (-coeff[1]*coeff[5]*coeff[8]+coeff[1]*coeff[7]*coeff[6]+coeff[2]*coeff[8]*coeff[4]-coeff[2]*coeff[5]*coeff[6]-coeff[3]*coeff[4]*coeff[7]+coeff[3]*coeff[5]*coeff[5])/ det, - (coeff[0]*coeff[5]*coeff[8]-coeff[0]*coeff[7]*coeff[6]-coeff[5]*coeff[2]*coeff[3]-coeff[1]*coeff[2]*coeff[8]+coeff[6]*coeff[2]*coeff[2]+coeff[1]*coeff[3]*coeff[7])/det, - (-coeff[8]*coeff[0]*coeff[4]+coeff[8]*coeff[1]*coeff[1]+coeff[2]*coeff[3]*coeff[4]+coeff[5]*coeff[0]*coeff[6]-coeff[5]*coeff[1]*coeff[3]-coeff[1]*coeff[2]*coeff[6])/det - }); - } - - - /** - * returns the point that minimizes the quadric. - * It inverses the quadric if its determinant is higher that a given threshold . - * If the determinant is lower than this value the returned value is uninitialized. - */ - boost::optional min_cost(double scale=1) const{ - // const double min_determinant = 1e-4 * scale*scale; - const double min_determinant = 1e-5; - boost::optional pt_res; - double det = grad_determinant(); - if (std::abs(det)>min_determinant) - pt_res = solve_linear_gradient(det); - return pt_res; - } - - friend std::ostream& operator<< (std::ostream& stream, const Error_quadric& quadric) { - stream << "\n[ "< class Error_quadric { + private: + double coeff[10]; + + public: + Error_quadric() { + clear(); + } + + /** + * Quadric corresponding to the L2 distance to the plane. + * + * According to the notation of Garland Heckbert, they + * denote a quadric symetric matrix as : + * Q = [ q11 q12 q13 q14] + * [ q12 q22 q23 q24] + * [ q13 q23 q33 q34] + * [ q14 q24 q34 q44] + * + * which is represented by a vector with 10 elts that + * are denoted ci for clarity with : + * Q = [ c0 c1 c2 c3 ] + * [ c1 c4 c5 c6 ] + * [ c2 c5 c7 c8 ] + * [ c3 c6 c8 c9 ] + * + * The constructor return the quadrics that represents + * the squared distance to the plane defined by triangle p0,p1,p2 + * times the area of triangle p0,p1,p2. + */ + Error_quadric(const Point & p0, const Point & p1, const Point & p2) { + Point normal(unit_normal(p0, p1, p2)); + double a = normal[0]; + double b = normal[1]; + double c = normal[2]; + double d = -a * p0[0] - b * p0[1] - c * p0[2]; + coeff[0] = a*a; + coeff[1] = a*b; + coeff[2] = a*c; + coeff[3] = a*d; + coeff[4] = b*b; + coeff[5] = b*c; + coeff[6] = b*d; + coeff[7] = c*c; + coeff[8] = c*d; + coeff[9] = d*d; + + double area_p0p1p2 = std::sqrt(squared_area(p0, p1, p2)); + for (auto& x : coeff) + x *= area_p0p1p2; + } + + inline double squared_area(const Point& p0, const Point& p1, const Point& p2) { + // if (x1,x2,x3) = p1-p0 and (y1,y2,y3) = p2-p0 + // then the squared area is = (u^2+v^2+w^2)/4 + // with: u = x2 * y3 - x3 * y2; + // v = x3 * y1 - x1 * y3; + // w = x1 * y2 - x2 * y1; + Point p0p1(p1 - p0); + Point p0p2(p2 - p0); + double A = p0p1[1] * p0p2[2] - p0p1[2] * p0p2[1]; + double B = p0p1[2] * p0p2[0] - p0p1[0] * p0p2[2]; + double C = p0p1[0] * p0p2[1] - p0p1[1] * p0p2[0]; + return 1. / 4. * (A * A + B * B + C * C); + } + + void clear() { + for (auto& x : coeff) + x = 0; + } + + Error_quadric& operator+=(const Error_quadric& other) { + if (this != &other) { + for (int i = 0; i < 10; ++i) + coeff[i] += other.coeff[i]; + } + return *this; + } + + /** + * @return The quadric quost defined by the scalar product v^T Q v where Q is the quadratic form of Garland/Heckbert + */ + inline double cost(const Point& point) const { + double cost = + coeff[0] * point.x() * point.x() + coeff[4] * point.y() * point.y() + coeff[7] * point.z() * point.z() + + 2 * (coeff[1] * point.x() * point.y() + coeff[5] * point.y() * point.z() + coeff[2] * point.z() * point.x()) + + 2 * (coeff[3] * point.x() + coeff[6] * point.y() + coeff[8] * point.z()) + + coeff[9]; + if (cost < 0) { + return 0; + } else { + return cost; + } + } + + inline double grad_determinant() const { + return + coeff[0] * coeff[4] * coeff[7] + - coeff[0] * coeff[5] * coeff[5] + - coeff[1] * coeff[1] * coeff[7] + + 2 * coeff[1] * coeff[5] * coeff[2] + - coeff[4] * coeff[2] * coeff[2]; + } + + /** + * Return the point such that it minimizes the gradient of the quadric. + * Det must be passed with the determinant value of the gradient (should be non zero). + */ + inline Point solve_linear_gradient(double det) const { + return Point({ + (-coeff[1] * coeff[5] * coeff[8] + coeff[1] * coeff[7] * coeff[6] + coeff[2] * coeff[8] * coeff[4] - + coeff[2] * coeff[5] * coeff[6] - coeff[3] * coeff[4] * coeff[7] + coeff[3] * coeff[5] * coeff[5]) + / det, + (coeff[0] * coeff[5] * coeff[8] - coeff[0] * coeff[7] * coeff[6] - coeff[5] * coeff[2] * coeff[3] - + coeff[1] * coeff[2] * coeff[8] + coeff[6] * coeff[2] * coeff[2] + coeff[1] * coeff[3] * coeff[7]) + / det, + (-coeff[8] * coeff[0] * coeff[4] + coeff[8] * coeff[1] * coeff[1] + coeff[2] * coeff[3] * coeff[4] + + coeff[5] * coeff[0] * coeff[6] - coeff[5] * coeff[1] * coeff[3] - coeff[1] * coeff[2] * coeff[6]) + / det + }); + } + + /** + * returns the point that minimizes the quadric. + * It inverses the quadric if its determinant is higher that a given threshold . + * If the determinant is lower than this value the returned value is uninitialized. + */ + boost::optional min_cost(double scale = 1) const { + // const double min_determinant = 1e-4 * scale*scale; + const double min_determinant = 1e-5; + boost::optional pt_res; + double det = grad_determinant(); + if (std::abs(det) > min_determinant) + pt_res = solve_linear_gradient(det); + return pt_res; + } + + friend std::ostream& operator<<(std::ostream& stream, const Error_quadric& quadric) { + stream << "\n[ " << quadric.coeff[0] << "," << quadric.coeff[1] << "," << quadric.coeff[2] << "," << + quadric.coeff[3] << ";\n"; + stream << " " << quadric.coeff[1] << "," << quadric.coeff[4] << "," << quadric.coeff[5] << "," << + quadric.coeff[6] << ";\n"; + stream << " " << quadric.coeff[2] << "," << quadric.coeff[5] << "," << quadric.coeff[7] << "," << + quadric.coeff[8] << ";\n"; + stream << " " << quadric.coeff[3] << "," << quadric.coeff[6] << "," << quadric.coeff[8] << "," << + quadric.coeff[9] << "]"; + return stream; + } }; - - - -#endif /* ERROR_QUADRIC_H_ */ - +#endif // ERROR_QUADRIC_H_ diff --git a/src/Contraction/example/Rips_contraction.cpp b/src/Contraction/example/Rips_contraction.cpp index bd0a8b8c..d21246ed 100644 --- a/src/Contraction/example/Rips_contraction.cpp +++ b/src/Contraction/example/Rips_contraction.cpp @@ -19,24 +19,23 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ +#include +#include +#include +#include + #include #include -#include "gudhi/Edge_contraction.h" -#include "gudhi/Skeleton_blocker.h" -#include "gudhi/Off_reader.h" -#include "gudhi/Point.h" using namespace std; using namespace Gudhi; using namespace skbl; using namespace contraction; - -struct Geometry_trait{ - typedef Point_d Point; +struct Geometry_trait { + typedef Point_d Point; }; - typedef Geometry_trait::Point Point; typedef Skeleton_blocker_simple_geometric_traits Complex_geometric_traits; typedef Skeleton_blocker_geometric_complex< Complex_geometric_traits > Complex; @@ -44,62 +43,62 @@ typedef Edge_profile Profile; typedef Skeleton_blocker_contractor Complex_contractor; template -void build_rips(ComplexType& complex, double offset){ - if (offset<=0) return; - auto vertices = complex.vertex_range(); - for (auto p = vertices.begin(); p != vertices.end(); ++p) - for (auto q = p; ++q != vertices.end(); /**/){ - if ( squared_dist(complex.point(*p), complex.point(*q)) < 4 * offset * offset) - complex.add_edge(*p,*q); - } +void build_rips(ComplexType& complex, double offset) { + if (offset <= 0) return; + auto vertices = complex.vertex_range(); + for (auto p = vertices.begin(); p != vertices.end(); ++p) + for (auto q = p; ++q != vertices.end(); /**/) { + if (squared_dist(complex.point(*p), complex.point(*q)) < 4 * offset * offset) + complex.add_edge(*p, *q); + } } -int main (int argc, char *argv[]) -{ - if (argc!=3){ - std::cerr << "Usage "< off_reader(argv[1],complex,true); - if(!off_reader.is_valid()){ - std::cerr << "Unable to read file:"< off_reader(argv[1], complex, true); + if (!off_reader.is_valid()) { + std::cerr << "Unable to read file:" << argv[1] << std::endl; + return EXIT_FAILURE; + } - std::cout << "Build the Rips complex with "<, - contraction::make_first_vertex_placement(), - contraction::make_link_valid_contraction(), - contraction::make_remove_popable_blockers_visitor()); - contractor.contract_edges(); + Complex_contractor contractor(complex, + new Edge_length_cost, + contraction::make_first_vertex_placement(), + contraction::make_link_valid_contraction(), + contraction::make_remove_popable_blockers_visitor()); + contractor.contract_edges(); - std::cout << "Counting final number of simplices \n"; - unsigned num_simplices = std::distance(complex.simplex_range().begin(),complex.simplex_range().end()); + std::cout << "Counting final number of simplices \n"; + unsigned num_simplices = std::distance(complex.simplex_range().begin(), complex.simplex_range().end()); - std::cout << "Final complex has "<< - complex.num_vertices()<<" vertices, "<< - complex.num_edges()<<" edges, "<< - complex.num_blockers()<<" blockers and "<< - num_simplices<<" simplices"<. - */ +/* 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 . + */ + +#include +#include +#include +#include #include #include @@ -27,36 +32,37 @@ #include #include - -#include "gudhi/graph_simplicial_complex.h" -#include "gudhi/Simplex_tree.h" -#include "gudhi/Persistent_cohomology.h" -#include +#include +#include +#include +#include +#include +#include using namespace Gudhi; using namespace Gudhi::persistent_cohomology; // Alpha_shape_3 templates type definitions typedef CGAL::Exact_predicates_inexact_constructions_kernel Kernel; -typedef CGAL::Alpha_shape_vertex_base_3 Vb; -typedef CGAL::Alpha_shape_cell_base_3 Fb; -typedef CGAL::Triangulation_data_structure_3 Tds; -typedef CGAL::Delaunay_triangulation_3 Triangulation_3; -typedef CGAL::Alpha_shape_3 Alpha_shape_3; +typedef CGAL::Alpha_shape_vertex_base_3 Vb; +typedef CGAL::Alpha_shape_cell_base_3 Fb; +typedef CGAL::Triangulation_data_structure_3 Tds; +typedef CGAL::Delaunay_triangulation_3 Triangulation_3; +typedef CGAL::Alpha_shape_3 Alpha_shape_3; // From file type definition -typedef Kernel::Point_3 Point_3; +typedef Kernel::Point_3 Point_3; // filtration with alpha values needed type definition typedef Alpha_shape_3::FT Alpha_value_type; -typedef CGAL::Object Object; +typedef CGAL::Object Object; typedef CGAL::Dispatch_output_iterator< - CGAL::cpp11::tuple, - CGAL::cpp11::tuple >, std::back_insert_iterator< std::vector > - > > Dispatch; -typedef Alpha_shape_3::Cell_handle Cell_handle; -typedef Alpha_shape_3::Facet Facet; -typedef Alpha_shape_3::Edge Edge_3; +CGAL::cpp11::tuple, +CGAL::cpp11::tuple >, + std::back_insert_iterator< std::vector > > > Dispatch; +typedef Alpha_shape_3::Cell_handle Cell_handle; +typedef Alpha_shape_3::Facet Facet; +typedef Alpha_shape_3::Edge Edge_3; typedef std::list Vertex_list; // gudhi type definition @@ -65,70 +71,60 @@ typedef std::map Alpha_shape typedef std::pair Alpha_shape_simplex_tree_pair; typedef std::vector< Simplex_tree_vertex > Simplex_tree_vector_vertex; -//#define DEBUG_TRACES - -Vertex_list from (const Cell_handle& ch) -{ +Vertex_list from(const Cell_handle& ch) { Vertex_list the_list; - for (auto i = 0; i < 4; i++) - { + for (auto i = 0; i < 4; i++) { #ifdef DEBUG_TRACES std::cout << "from cell[" << i << "]=" << ch->vertex(i)->point() << std::endl; -#endif // DEBUG_TRACES +#endif // DEBUG_TRACES the_list.push_back(ch->vertex(i)); } return the_list; } -Vertex_list from (const Facet& fct) -{ + +Vertex_list from(const Facet& fct) { Vertex_list the_list; - for (auto i = 0; i < 4; i++) - { - if (fct.second != i) - { + for (auto i = 0; i < 4; i++) { + if (fct.second != i) { #ifdef DEBUG_TRACES std::cout << "from facet=[" << i << "]" << fct.first->vertex(i)->point() << std::endl; -#endif // DEBUG_TRACES +#endif // DEBUG_TRACES the_list.push_back(fct.first->vertex(i)); } } return the_list; } -Vertex_list from (const Edge_3& edg) -{ + +Vertex_list from(const Edge_3& edg) { Vertex_list the_list; - for (auto i = 0; i < 4; i++) - { - if ((edg.second == i) ||(edg.third == i)) - { + for (auto i = 0; i < 4; i++) { + if ((edg.second == i) || (edg.third == i)) { #ifdef DEBUG_TRACES std::cout << "from edge[" << i << "]=" << edg.first->vertex(i)->point() << std::endl; -#endif // DEBUG_TRACES +#endif // DEBUG_TRACES the_list.push_back(edg.first->vertex(i)); } } return the_list; } -Vertex_list from (const Alpha_shape_3::Vertex_handle& vh) -{ + +Vertex_list from(const Alpha_shape_3::Vertex_handle& vh) { Vertex_list the_list; #ifdef DEBUG_TRACES std::cout << "from vertex=" << vh->point() << std::endl; -#endif // DEBUG_TRACES +#endif // DEBUG_TRACES the_list.push_back(vh); return the_list; } -void usage(char * const progName) -{ - std::cerr << "Usage: " << progName << " path_to_file_graph coeff_field_characteristic[integer > 0] min_persistence[float >= -1.0]\n"; - exit(-1); // ----- >> +void usage(char * const progName) { + std::cerr << "Usage: " << progName << + " path_to_file_graph coeff_field_characteristic[integer > 0] min_persistence[float >= -1.0]\n"; + exit(-1); } -int main (int argc, char * const argv[]) -{ - - int coeff_field_characteristic=0; +int main(int argc, char * const argv[]) { + int coeff_field_characteristic = 0; int returnedScanValue = sscanf(argv[2], "%d", &coeff_field_characteristic); if ((returnedScanValue == EOF) || (coeff_field_characteristic <= 0)) { std::cerr << "Error: " << argv[2] << " is not correct\n"; @@ -149,102 +145,96 @@ int main (int argc, char * const argv[]) } // Read points from file - std::string filegraph = argv[1]; + std::string filegraph = argv[1]; std::list lp; std::ifstream is(filegraph.c_str()); int n; is >> n; #ifdef DEBUG_TRACES std::cout << "Reading " << n << " points " << std::endl; -#endif // DEBUG_TRACES +#endif // DEBUG_TRACES Point_3 p; - for( ; n>0 ; n--) { + for (; n > 0; n--) { is >> p; lp.push_back(p); } // alpha shape construction from points. CGAL has a strange behavior in REGULARIZED mode. - Alpha_shape_3 as(lp.begin(),lp.end(),0,Alpha_shape_3::GENERAL); + Alpha_shape_3 as(lp.begin(), lp.end(), 0, Alpha_shape_3::GENERAL); #ifdef DEBUG_TRACES std::cout << "Alpha shape computed in GENERAL mode" << std::endl; -#endif // DEBUG_TRACES +#endif // DEBUG_TRACES // filtration with alpha values from alpha shape std::vector the_objects; std::vector the_alpha_values; - Dispatch disp = CGAL::dispatch_output( std::back_inserter(the_objects), std::back_inserter(the_alpha_values)); + Dispatch disp = CGAL::dispatch_output(std::back_inserter(the_objects), + std::back_inserter(the_alpha_values)); as.filtration_with_alpha_values(disp); #ifdef DEBUG_TRACES std::cout << "filtration_with_alpha_values returns : " << the_objects.size() << " objects" << std::endl; -#endif // DEBUG_TRACES +#endif // DEBUG_TRACES Alpha_shape_3::size_type count_vertices = 0; - Alpha_shape_3::size_type count_edges = 0; - Alpha_shape_3::size_type count_facets = 0; - Alpha_shape_3::size_type count_cells = 0; + Alpha_shape_3::size_type count_edges = 0; + Alpha_shape_3::size_type count_facets = 0; + Alpha_shape_3::size_type count_cells = 0; // Loop on objects vector Vertex_list vertex_list; Simplex_tree<> simplex_tree; Alpha_shape_simplex_tree_map map_cgal_simplex_tree; std::vector::iterator the_alpha_value_iterator = the_alpha_values.begin(); - int dim_max=0; - Filtration_value filtration_max=0.0; - for(auto object_iterator: the_objects) - { + int dim_max = 0; + Filtration_value filtration_max = 0.0; + for (auto object_iterator : the_objects) { // Retrieve Alpha shape vertex list from object - if (const Cell_handle* cell = CGAL::object_cast(&object_iterator)) - { + if (const Cell_handle * cell = CGAL::object_cast(&object_iterator)) { vertex_list = from(*cell); count_cells++; if (dim_max < 3) { - dim_max=3; // Cell is of dim 3 + // Cell is of dim 3 + dim_max = 3; } - } - else if (const Facet* facet = CGAL::object_cast(&object_iterator)) - { + } else if (const Facet * facet = CGAL::object_cast(&object_iterator)) { vertex_list = from(*facet); count_facets++; if (dim_max < 2) { - dim_max=2; // Facet is of dim 2 + // Facet is of dim 2 + dim_max = 2; } - } - else if (const Edge_3* edge = CGAL::object_cast(&object_iterator)) - { + } else if (const Edge_3 * edge = CGAL::object_cast(&object_iterator)) { vertex_list = from(*edge); count_edges++; if (dim_max < 1) { - dim_max=1; // Edge_3 is of dim 1 + // Edge_3 is of dim 1 + dim_max = 1; } - } - else if (const Alpha_shape_3::Vertex_handle* vertex = CGAL::object_cast(&object_iterator)) - { + } else if (const Alpha_shape_3::Vertex_handle * vertex = + CGAL::object_cast(&object_iterator)) { count_vertices++; vertex_list = from(*vertex); } // Construction of the vector of simplex_tree vertex from list of alpha_shapes vertex Simplex_tree_vector_vertex the_simplex_tree; - for (auto the_alpha_shape_vertex:vertex_list) - { + for (auto the_alpha_shape_vertex : vertex_list) { Alpha_shape_simplex_tree_map::iterator the_map_iterator = map_cgal_simplex_tree.find(the_alpha_shape_vertex); - if (the_map_iterator == map_cgal_simplex_tree.end()) - { + if (the_map_iterator == map_cgal_simplex_tree.end()) { // alpha shape not found Simplex_tree_vertex vertex = map_cgal_simplex_tree.size(); #ifdef DEBUG_TRACES std::cout << "vertex [" << the_alpha_shape_vertex->point() << "] not found - insert " << vertex << std::endl; -#endif // DEBUG_TRACES +#endif // DEBUG_TRACES the_simplex_tree.push_back(vertex); - map_cgal_simplex_tree.insert(Alpha_shape_simplex_tree_pair(the_alpha_shape_vertex,vertex)); - } else - { + map_cgal_simplex_tree.insert(Alpha_shape_simplex_tree_pair(the_alpha_shape_vertex, vertex)); + } else { // alpha shape found Simplex_tree_vertex vertex = the_map_iterator->second; #ifdef DEBUG_TRACES std::cout << "vertex [" << the_alpha_shape_vertex->point() << "] found in " << vertex << std::endl; -#endif // DEBUG_TRACES +#endif // DEBUG_TRACES the_simplex_tree.push_back(vertex); } } @@ -252,7 +242,7 @@ int main (int argc, char * const argv[]) Filtration_value filtr = std::sqrt(*the_alpha_value_iterator); #ifdef DEBUG_TRACES std::cout << "filtration = " << filtr << std::endl; -#endif // DEBUG_TRACES +#endif // DEBUG_TRACES if (filtr > filtration_max) { filtration_max = filtr; } @@ -267,9 +257,9 @@ int main (int argc, char * const argv[]) #ifdef DEBUG_TRACES std::cout << "vertices \t\t" << count_vertices << std::endl; - std::cout << "edges \t\t" << count_edges << std::endl; - std::cout << "facets \t\t" << count_facets << std::endl; - std::cout << "cells \t\t" << count_cells << std::endl; + std::cout << "edges \t\t" << count_edges << std::endl; + std::cout << "facets \t\t" << count_facets << std::endl; + std::cout << "cells \t\t" << count_cells << std::endl; std::cout << "Information of the Simplex Tree: " << std::endl; @@ -277,23 +267,25 @@ int main (int argc, char * const argv[]) std::cout << " Number of simplices = " << simplex_tree.num_simplices() << std::endl << std::endl; std::cout << " Dimension = " << simplex_tree.dimension() << " "; std::cout << " filtration = " << simplex_tree.filtration() << std::endl << std::endl; -#endif // DEBUG_TRACES +#endif // DEBUG_TRACES #ifdef DEBUG_TRACES std::cout << "Iterator on vertices: " << std::endl; - for( auto vertex : simplex_tree.complex_vertex_range() ) - { std::cout << vertex << " "; } -#endif // DEBUG_TRACES + for (auto vertex : simplex_tree.complex_vertex_range()) { + std::cout << vertex << " "; + } +#endif // DEBUG_TRACES // Sort the simplices in the order of the filtration simplex_tree.initialize_filtration(); std::cout << "Simplex_tree dim: " << simplex_tree.dimension() << std::endl; // Compute the persistence diagram of the complex - Persistent_cohomology< Simplex_tree<>, Field_Zp > pcoh( simplex_tree ); - pcoh.init_coefficients( coeff_field_characteristic ); //initializes the coefficient field for homology + Persistent_cohomology< Simplex_tree<>, Field_Zp > pcoh(simplex_tree); + // initializes the coefficient field for homology + pcoh.init_coefficients(coeff_field_characteristic); - pcoh.compute_persistent_cohomology( min_persistence ); + pcoh.compute_persistent_cohomology(min_persistence); pcoh.output_diagram(); diff --git a/src/Persistent_cohomology/example/performance_rips_persistence.cpp b/src/Persistent_cohomology/example/performance_rips_persistence.cpp index 077c2b07..0e912d57 100644 --- a/src/Persistent_cohomology/example/performance_rips_persistence.cpp +++ b/src/Persistent_cohomology/example/performance_rips_persistence.cpp @@ -1,49 +1,51 @@ - /* 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 . - */ - -#include "gudhi/reader_utils.h" -#include "gudhi/graph_simplicial_complex.h" -#include "gudhi/distance_functions.h" -#include "gudhi/Simplex_tree.h" -#include "gudhi/Persistent_cohomology.h" -#include "gudhi/Persistent_cohomology/Multi_field.h" -#include "gudhi/Hasse_complex.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 . + */ + +#include +#include +#include +#include +#include +#include +#include #include +#include +#include using namespace Gudhi; using namespace Gudhi::persistent_cohomology; /* Compute the persistent homology of the complex cpx with coefficients in Z/pZ. */ template< typename FilteredComplex> -void timing_persistence( FilteredComplex & cpx - , int p ); +void timing_persistence(FilteredComplex & cpx + , int p); /* Compute multi-field persistent homology of the complex cpx with coefficients in * Z/rZ for all prime number r in [p;q].*/ template< typename FilteredComplex> -void timing_persistence( FilteredComplex & cpx - , int p - , int q ); +void timing_persistence(FilteredComplex & cpx + , int p + , int q); /* Timings for the computation of persistent homology with different * representations of a Rips complex and different coefficient fields. The @@ -59,111 +61,111 @@ void timing_persistence( FilteredComplex & cpx * We present also timings for the computation of multi-field persistent * homology in all fields Z/rZ for r prime between 2 and 1223. */ -int main (int argc, char * argv[]) -{ +int main(int argc, char * argv[]) { std::chrono::time_point start, end; int enlapsed_sec; - std::string filepoints = "../examples/Kl.txt"; - Filtration_value threshold = 0.3; - int dim_max = 3; - int p = 2; - int q = 1223; + std::string filepoints = "../examples/Kl.txt"; + Filtration_value threshold = 0.3; + int dim_max = 3; + int p = 2; + int q = 1223; -// Extract the points from the file filepoints + // Extract the points from the file filepoints typedef std::vector Point_t; std::vector< Point_t > points; - read_points( filepoints, points ); + read_points(filepoints, points); -// Compute the proximity graph of the points + // Compute the proximity graph of the points start = std::chrono::system_clock::now(); - Graph_t prox_graph = compute_proximity_graph( points, threshold - , euclidean_distance ); + Graph_t prox_graph = compute_proximity_graph(points, threshold + , euclidean_distance); end = std::chrono::system_clock::now(); - enlapsed_sec = std::chrono::duration_cast(end-start).count(); + enlapsed_sec = std::chrono::duration_cast(end - start).count(); std::cout << "Compute Rips graph in " << enlapsed_sec << " sec.\n"; -// Construct the Rips complex in a Simplex Tree - Simplex_tree<> st; + // Construct the Rips complex in a Simplex Tree + Simplex_tree<> st; start = std::chrono::system_clock::now(); - st.insert_graph(prox_graph); // insert the proximity graph in the simplex tree - st.expansion( dim_max ); // expand the graph until dimension dim_max + // insert the proximity graph in the simplex tree + st.insert_graph(prox_graph); + // expand the graph until dimension dim_max + st.expansion(dim_max); end = std::chrono::system_clock::now(); - enlapsed_sec = std::chrono::duration_cast(end-start).count(); + enlapsed_sec = std::chrono::duration_cast(end - start).count(); std::cout << "Compute Rips complex in " << enlapsed_sec << " sec.\n"; std::cout << " - dimension = " << st.dimension() << std::endl; std::cout << " - number of simplices = " << st.num_simplices() << std::endl; -// Sort the simplices in the order of the filtration + // Sort the simplices in the order of the filtration start = std::chrono::system_clock::now(); st.initialize_filtration(); end = std::chrono::system_clock::now(); - enlapsed_sec = std::chrono::duration_cast(end-start).count(); + enlapsed_sec = std::chrono::duration_cast(end - start).count(); std::cout << "Order the simplices of the filtration in " << enlapsed_sec << " sec.\n"; -// Convert the simplex tree into a hasse diagram + // Convert the simplex tree into a hasse diagram start = std::chrono::system_clock::now(); Hasse_complex<> hcpx(st); end = std::chrono::system_clock::now(); - enlapsed_sec = std::chrono::duration_cast(end-start).count(); + enlapsed_sec = std::chrono::duration_cast(end - start).count(); std::cout << "Convert the simplex tree into a Hasse diagram in " << enlapsed_sec << " sec.\n"; std::cout << "Timings when using a simplex tree: \n"; - timing_persistence(st,p); - timing_persistence(st,q); - timing_persistence(st,p,q); + timing_persistence(st, p); + timing_persistence(st, q); + timing_persistence(st, p, q); std::cout << "Timings when using a Hasse complex: \n"; - timing_persistence(hcpx,p); - timing_persistence(hcpx,q); - timing_persistence(hcpx,p,q); + timing_persistence(hcpx, p); + timing_persistence(hcpx, q); + timing_persistence(hcpx, p, q); return 0; } - template< typename FilteredComplex> void -timing_persistence( FilteredComplex & cpx - , int p ) -{ +timing_persistence(FilteredComplex & cpx + , int p) { std::chrono::time_point start, end; int enlapsed_sec; - Persistent_cohomology< FilteredComplex, Field_Zp > pcoh (cpx); - pcoh.init_coefficients( p ); //initilizes the coefficient field for homology - + Persistent_cohomology< FilteredComplex, Field_Zp > pcoh(cpx); + // initializes the coefficient field for homology + pcoh.init_coefficients(p); + start = std::chrono::system_clock::now(); - - pcoh.compute_persistent_cohomology( INFINITY ); - + + pcoh.compute_persistent_cohomology(INFINITY); + end = std::chrono::system_clock::now(); - enlapsed_sec = std::chrono::duration_cast(end-start).count(); - std::cout << " Compute persistent homology in Z/"<(end - start).count(); + std::cout << " Compute persistent homology in Z/" << p << "Z in " << enlapsed_sec << " sec.\n"; } template< typename FilteredComplex> void -timing_persistence( FilteredComplex & cpx - , int p - , int q ) -{ +timing_persistence(FilteredComplex & cpx + , int p + , int q) { std::chrono::time_point start, end; int enlapsed_sec; - Persistent_cohomology< FilteredComplex, Multi_field > pcoh (cpx); - pcoh.init_coefficients( p, q ); //initilizes the coefficient field for homology + Persistent_cohomology< FilteredComplex, Multi_field > pcoh(cpx); + // initializes the coefficient field for homology + pcoh.init_coefficients(p, q); // compute persistent homology, disgarding persistent features of life shorter than min_persistence start = std::chrono::system_clock::now(); - pcoh.compute_persistent_cohomology( INFINITY ); + pcoh.compute_persistent_cohomology(INFINITY); end = std::chrono::system_clock::now(); - enlapsed_sec = std::chrono::duration_cast(end-start).count(); + enlapsed_sec = std::chrono::duration_cast(end - start).count(); std::cout << " Compute multi-field persistent homology in all coefficient fields Z/pZ " - << "with p in ["<. - */ - -#include "gudhi/reader_utils.h" -#include "gudhi/graph_simplicial_complex.h" -#include "gudhi/distance_functions.h" -#include "gudhi/Simplex_tree.h" -#include "gudhi/Persistent_cohomology.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): 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 . + */ + +#include +#include +#include +#include +#include #include +#include + using namespace Gudhi; using namespace Gudhi::persistent_cohomology; -typedef int Vertex_handle; -typedef double Filtration_value; - -void program_options( int argc, char * argv[] - , std::string & simplex_tree_file - , std::string & output_file - , int & p - , Filtration_value & min_persistence ); - -int main (int argc, char * argv[]) -{ - std::string simplex_tree_file; - std::string output_file ; - int p ; - Filtration_value min_persistence; - - program_options(argc,argv,simplex_tree_file,output_file,p,min_persistence); - - std::cout << "Simplex_tree from file=" << simplex_tree_file.c_str() << " - output_file=" << output_file.c_str() << std::endl; - std::cout << " - p=" << p << " - min_persistence=" << min_persistence << std::endl; - - // Construct the Rips complex in a Simplex Tree - Simplex_tree<> simplex_tree; - - std::ifstream simplex_tree_stream(simplex_tree_file); - simplex_tree_stream >> simplex_tree; - - std::cout << "The complex contains " << simplex_tree.num_simplices() << " simplices" << std::endl; - std::cout << " - dimension " << simplex_tree.dimension() << " - filtration " << simplex_tree.filtration() << std::endl; - - /* - std::cout << std::endl << std::endl << "Iterator on Simplices in the filtration, with [filtration value]:" << std::endl; - for( auto f_simplex : simplex_tree.filtration_simplex_range() ) - { std::cout << " " << "[" << simplex_tree.filtration(f_simplex) << "] "; - for( auto vertex : simplex_tree.simplex_vertex_range(f_simplex) ) - { std::cout << vertex << " "; } - std::cout << std::endl; - }*/ - - // Sort the simplices in the order of the filtration - simplex_tree.initialize_filtration(); - - // Compute the persistence diagram of the complex - Persistent_cohomology< Simplex_tree<>, Field_Zp > pcoh( simplex_tree ); - pcoh.init_coefficients( p ); //initilizes the coefficient field for homology - - pcoh.compute_persistent_cohomology( min_persistence ); - - // Output the diagram in output_file - if(output_file.empty()) { pcoh.output_diagram(); } - else { - std::ofstream out(output_file); - pcoh.output_diagram(out); - out.close(); } +typedef int Vertex_handle; +typedef double Filtration_value; + +void program_options(int argc, char * argv[] + , std::string & simplex_tree_file + , std::string & output_file + , int & p + , Filtration_value & min_persistence); + +int main(int argc, char * argv[]) { + std::string simplex_tree_file; + std::string output_file; + int p; + Filtration_value min_persistence; + + program_options(argc, argv, simplex_tree_file, output_file, p, min_persistence); + + std::cout << "Simplex_tree from file=" << simplex_tree_file.c_str() << " - output_file=" << output_file.c_str() + << std::endl; + std::cout << " - p=" << p << " - min_persistence=" << min_persistence << std::endl; + + // Construct the Rips complex in a Simplex Tree + Simplex_tree<> simplex_tree; + + std::ifstream simplex_tree_stream(simplex_tree_file); + simplex_tree_stream >> simplex_tree; + + std::cout << "The complex contains " << simplex_tree.num_simplices() << " simplices" << std::endl; + std::cout << " - dimension " << simplex_tree.dimension() << " - filtration " << simplex_tree.filtration() + << std::endl; + + /* + std::cout << std::endl << std::endl << "Iterator on Simplices in the filtration, with [filtration value]:" << std::endl; + for( auto f_simplex : simplex_tree.filtration_simplex_range() ) + { std::cout << " " << "[" << simplex_tree.filtration(f_simplex) << "] "; + for( auto vertex : simplex_tree.simplex_vertex_range(f_simplex) ) + { std::cout << vertex << " "; } + std::cout << std::endl; + }*/ + + // Sort the simplices in the order of the filtration + simplex_tree.initialize_filtration(); + + // Compute the persistence diagram of the complex + Persistent_cohomology< Simplex_tree<>, Field_Zp > pcoh(simplex_tree); + // initializes the coefficient field for homology + pcoh.init_coefficients(p); + + pcoh.compute_persistent_cohomology(min_persistence); + + // Output the diagram in output_file + if (output_file.empty()) { + pcoh.output_diagram(); + } else { + std::ofstream out(output_file); + pcoh.output_diagram(out); + out.close(); + } - return 0; + return 0; } - - -void program_options( int argc, char * argv[] - , std::string & simplex_tree_file - , std::string & output_file - , int & p - , Filtration_value & min_persistence ) -{ +void program_options(int argc, char * argv[] + , std::string & simplex_tree_file + , std::string & output_file + , int & p + , Filtration_value & min_persistence) { namespace po = boost::program_options; - po::options_description hidden("Hidden options"); + po::options_description hidden("Hidden options"); hidden.add_options() - ("input-file", po::value(&simplex_tree_file), - "Name of file containing a simplex set. Format is one simplex per line (cf. reader_utils.h - read_simplex): Dim1 X11 X12 ... X1d Fil1 "); - + ("input-file", po::value(&simplex_tree_file), + "Name of file containing a simplex set. Format is one simplex per line (cf. reader_utils.h - read_simplex): Dim1 X11 X12 ... X1d Fil1 "); + po::options_description visible("Allowed options", 100); visible.add_options() - ("help,h", "produce help message") - ("output-file,o", po::value(&output_file)->default_value(std::string()), - "Name of file in which the persistence diagram is written. Default print in std::cout") - ("field-charac,p", po::value(&p)->default_value(11), - "Characteristic p of the coefficient field Z/pZ for computing homology.") - ("min-persistence,m", po::value(&min_persistence), - "Minimal lifetime of homology feature to be recorded. Default is 0"); + ("help,h", "produce help message") + ("output-file,o", po::value(&output_file)->default_value(std::string()), + "Name of file in which the persistence diagram is written. Default print in std::cout") + ("field-charac,p", po::value(&p)->default_value(11), + "Characteristic p of the coefficient field Z/pZ for computing homology.") + ("min-persistence,m", po::value(&min_persistence), + "Minimal lifetime of homology feature to be recorded. Default is 0"); po::positional_options_description pos; pos.add("input-file", 1); - - po::options_description all; all.add(visible).add(hidden); + + po::options_description all; + all.add(visible).add(hidden); po::variables_map vm; po::store(po::command_line_parser(argc, argv). - options(all).positional(pos).run(), vm); + options(all).positional(pos).run(), vm); po::notify(vm); - if (vm.count("help") || !vm.count("input-file")) - { - std::cout << std::endl; - std::cout << "Compute the persistent homology with coefficient field Z/pZ \n"; - std::cout << "of a Rips complex defined on a set of input points.\n \n"; - std::cout << "The output diagram contains one bar per line, written with the convention: \n"; - std::cout << " p dim b d \n"; - std::cout << "where dim is the dimension of the homological feature,\n"; - std::cout << "b and d are respectively the birth and death of the feature and \n"; - std::cout << "p is the characteristic of the field Z/pZ used for homology coefficients." << std::endl << std::endl; - - std::cout << "Usage: " << argv[0] << " [options] input-file" << std::endl << std::endl; - std::cout << visible << std::endl; - std::abort(); + if (vm.count("help") || !vm.count("input-file")) { + std::cout << std::endl; + std::cout << "Compute the persistent homology with coefficient field Z/pZ \n"; + std::cout << "of a Rips complex defined on a set of input points.\n \n"; + std::cout << "The output diagram contains one bar per line, written with the convention: \n"; + std::cout << " p dim b d \n"; + std::cout << "where dim is the dimension of the homological feature,\n"; + std::cout << "b and d are respectively the birth and death of the feature and \n"; + std::cout << "p is the characteristic of the field Z/pZ used for homology coefficients." << std::endl << std::endl; + + std::cout << "Usage: " << argv[0] << " [options] input-file" << std::endl << std::endl; + std::cout << visible << std::endl; + std::abort(); } } diff --git a/src/Persistent_cohomology/example/persistence_from_simple_simplex_tree.cpp b/src/Persistent_cohomology/example/persistence_from_simple_simplex_tree.cpp index ba82e4e6..ba772f04 100644 --- a/src/Persistent_cohomology/example/persistence_from_simple_simplex_tree.cpp +++ b/src/Persistent_cohomology/example/persistence_from_simple_simplex_tree.cpp @@ -20,11 +20,14 @@ * along with this program. If not, see . */ +#include +#include +#include + #include #include -#include "gudhi/graph_simplicial_complex.h" -#include "gudhi/Simplex_tree.h" -#include "gudhi/Persistent_cohomology.h" +#include +#include using namespace Gudhi; using namespace Gudhi::persistent_cohomology; @@ -34,15 +37,19 @@ typedef std::pair typeSimplex; typedef std::pair< Simplex_tree<>::Simplex_handle, bool > typePairSimplexBool; typedef Simplex_tree<> typeST; -void usage(char * const progName) -{ +void usage(char * const progName) { std::cerr << "Usage: " << progName << " coeff_field_characteristic[integer > 0] min_persistence[float >= -1.0]\n"; - exit(-1); // ----- >> + exit(-1); } -int main (int argc, char * const argv[]) -{ - int coeff_field_characteristic=0; +int main(int argc, char * const argv[]) { + // program args management + if (argc != 3) { + std::cerr << "Error: Number of arguments (" << argc << ") is not correct\n"; + usage(argv[0]); + } + + int coeff_field_characteristic = 0; int returnedScanValue = sscanf(argv[1], "%d", &coeff_field_characteristic); if ((returnedScanValue == EOF) || (coeff_field_characteristic <= 0)) { std::cerr << "Error: " << argv[1] << " is not correct\n"; @@ -56,101 +63,65 @@ int main (int argc, char * const argv[]) usage(argv[0]); } - // program args management - if (argc != 3) { - std::cerr << "Error: Number of arguments (" << argc << ") is not correct\n"; - usage(argv[0]); - } - // 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); + std::cout << " - INSERT (0,1,2)" << std::endl; + typeVectorVertex SimplexVector = {0, 1, 2}; + st.insert_simplex_and_subfaces(SimplexVector, 0.3); // ++ SECOND std::cout << " - INSERT 3" << std::endl; - typeVectorVertex SimplexVector2; - SimplexVector2.push_back(3); - st.insert_simplex_and_subfaces ( SimplexVector2, 0.1); + SimplexVector = {3}; + st.insert_simplex_and_subfaces(SimplexVector, 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); + SimplexVector = {0, 3}; + st.insert_simplex_and_subfaces(SimplexVector, 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); + std::cout << " - INSERT (0,1) (already inserted)" << std::endl; + SimplexVector = {0, 1}; + st.insert_simplex_and_subfaces(SimplexVector, 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); + SimplexVector = {3, 4, 5}; + st.insert_simplex_and_subfaces(SimplexVector, 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); + SimplexVector = {0, 1, 6, 7}; + st.insert_simplex_and_subfaces(SimplexVector, 0.4); // ++ SEVENTH std::cout << " - INSERT (4,5,8,9)" << std::endl; - typeVectorVertex SimplexVector7; - SimplexVector7.push_back(4); - SimplexVector7.push_back(5); - SimplexVector7.push_back(8); - SimplexVector7.push_back(9); - st.insert_simplex_and_subfaces ( SimplexVector7, 0.4); + SimplexVector = {4, 5, 8, 9}; + st.insert_simplex_and_subfaces(SimplexVector, 0.4); // ++ EIGHTH std::cout << " - INSERT (9,10,11)" << std::endl; - typeVectorVertex SimplexVector8; - SimplexVector8.push_back(9); - SimplexVector8.push_back(10); - SimplexVector8.push_back(11); - st.insert_simplex_and_subfaces ( SimplexVector8, 0.3); - + SimplexVector = {9, 10, 11}; + st.insert_simplex_and_subfaces(SimplexVector, 0.3); + // ++ NINETH std::cout << " - INSERT (2,10,12)" << std::endl; - typeVectorVertex SimplexVector9; - SimplexVector9.push_back(2); - SimplexVector9.push_back(10); - SimplexVector9.push_back(12); - st.insert_simplex_and_subfaces ( SimplexVector9, 0.3); - + SimplexVector = {2, 10, 12}; + st.insert_simplex_and_subfaces(SimplexVector, 0.3); + // ++ TENTH std::cout << " - INSERT (11,6)" << std::endl; - typeVectorVertex SimplexVector10; - SimplexVector10.push_back(11); - SimplexVector10.push_back(6); - st.insert_simplex_and_subfaces ( SimplexVector10, 0.2); + SimplexVector = {6, 11}; + st.insert_simplex_and_subfaces(SimplexVector, 0.2); // ++ ELEVENTH std::cout << " - INSERT (13,14,15)" << std::endl; - typeVectorVertex SimplexVector11; - SimplexVector11.push_back(13); - SimplexVector11.push_back(14); - SimplexVector11.push_back(15); - st.insert_simplex_and_subfaces ( SimplexVector11, 0.25); + SimplexVector = {13, 14, 15}; + st.insert_simplex_and_subfaces(SimplexVector, 0.25); /* Inserted simplex: */ /* 1 6 */ @@ -175,33 +146,31 @@ int main (int argc, char * const argv[]) st.set_dimension(2); st.set_filtration(0.4); - std::cout << "The complex contains " << st.num_simplices() << " simplices - " << st.num_vertices() << " vertices " << std::endl; + 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 << std::endl << "Iterator on Simplices in the filtration, with [filtration value]:" + << std::endl; std::cout << "**************************************************************" << std::endl; std::cout << "strict graph G { " << std::endl; - for( auto f_simplex : st.filtration_simplex_range() ) - { + 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 << " -- "; + for (auto vertex : st.simplex_vertex_range(f_simplex)) { + std::cout << static_cast(vertex) << " -- "; } std::cout << ";" << std::endl; } std::cout << "}" << std::endl; - //std::cout << "**************************************************************" << std::endl; - //st.print_hasse(std::cout); std::cout << "**************************************************************" << std::endl; - // Compute the persistence diagram of the complex persistent_cohomology::Persistent_cohomology< Simplex_tree<>, Field_Zp > pcoh(st); - pcoh.init_coefficients( coeff_field_characteristic ); //initiliazes the coefficient field for homology + // initializes the coefficient field for homology + pcoh.init_coefficients(coeff_field_characteristic); - pcoh.compute_persistent_cohomology( min_persistence ); + pcoh.compute_persistent_cohomology(min_persistence); // Output the diagram in filediag pcoh.output_diagram(); diff --git a/src/Persistent_cohomology/example/rips_multifield_persistence.cpp b/src/Persistent_cohomology/example/rips_multifield_persistence.cpp index 297a8f98..5277bf7a 100644 --- a/src/Persistent_cohomology/example/rips_multifield_persistence.cpp +++ b/src/Persistent_cohomology/example/rips_multifield_persistence.cpp @@ -1,153 +1,157 @@ - /* 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 . - */ - -#include "gudhi/reader_utils.h" -#include "gudhi/graph_simplicial_complex.h" -#include "gudhi/distance_functions.h" -#include "gudhi/Simplex_tree.h" -#include "gudhi/Persistent_cohomology.h" -#include "gudhi/Persistent_cohomology/Multi_field.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 . + */ + +#include +#include +#include +#include +#include +#include #include +#include +#include + using namespace Gudhi; using namespace Gudhi::persistent_cohomology; -typedef int Vertex_handle; +typedef int Vertex_handle; typedef double Filtration_value; -void program_options( int argc, char * argv[] - , std::string & filepoints - , std::string & filediag - , Filtration_value & threshold - , int & dim_max - , int & min_p - , int & max_p - , Filtration_value & min_persistence ); - -int main (int argc, char * argv[]) -{ - std::string filepoints; - std::string filediag; +void program_options(int argc, char * argv[] + , std::string & filepoints + , std::string & filediag + , Filtration_value & threshold + , int & dim_max + , int & min_p + , int & max_p + , Filtration_value & min_persistence); + +int main(int argc, char * argv[]) { + std::string filepoints; + std::string filediag; Filtration_value threshold; - int dim_max; - int min_p; - int max_p; + int dim_max; + int min_p; + int max_p; Filtration_value min_persistence; - program_options(argc,argv,filepoints,filediag,threshold,dim_max,min_p,max_p,min_persistence); + program_options(argc, argv, filepoints, filediag, threshold, dim_max, min_p, max_p, min_persistence); -// Extract the points from the file filepoints + // Extract the points from the file filepoints typedef std::vector Point_t; std::vector< Point_t > points; - read_points( filepoints, points ); + read_points(filepoints, points); -// Compute the proximity graph of the points - Graph_t prox_graph = compute_proximity_graph( points, threshold - , euclidean_distance ); + // Compute the proximity graph of the points + Graph_t prox_graph = compute_proximity_graph(points, threshold + , euclidean_distance); -// Construct the Rips complex in a Simplex Tree - Simplex_tree<> st; - st.insert_graph(prox_graph); // insert the proximity graph in the simplex tree - st.expansion( dim_max ); // expand the graph until dimension dim_max + // Construct the Rips complex in a Simplex Tree + Simplex_tree<> st; + // insert the proximity graph in the simplex tree + st.insert_graph(prox_graph); + // expand the graph until dimension dim_max + st.expansion(dim_max); -// Sort the simplices in the order of the filtration + // Sort the simplices in the order of the filtration st.initialize_filtration(); -// Compute the persistence diagram of the complex - Persistent_cohomology< Simplex_tree<>, Multi_field > pcoh( st ); - pcoh.init_coefficients( min_p, max_p ); //initilizes the coefficient field for homology + // Compute the persistence diagram of the complex + Persistent_cohomology< Simplex_tree<>, Multi_field > pcoh(st); + // initializes the coefficient field for homology + pcoh.init_coefficients(min_p, max_p); // compute persistent homology, disgarding persistent features of life shorter than min_persistence - pcoh.compute_persistent_cohomology( min_persistence ); - -// Output the diagram in filediag - if(filediag.empty()) { pcoh.output_diagram(); } - else { - std::ofstream out(filediag); - pcoh.output_diagram(out); - out.close(); } + pcoh.compute_persistent_cohomology(min_persistence); + + // Output the diagram in filediag + if (filediag.empty()) { + pcoh.output_diagram(); + } else { + std::ofstream out(filediag); + pcoh.output_diagram(out); + out.close(); + } return 0; } - - -void program_options( int argc, char * argv[] - , std::string & filepoints - , std::string & filediag - , Filtration_value & threshold - , int & dim_max - , int & min_p - , int & max_p - , Filtration_value & min_persistence ) -{ +void program_options(int argc, char * argv[] + , std::string & filepoints + , std::string & filediag + , Filtration_value & threshold + , int & dim_max + , int & min_p + , int & max_p + , Filtration_value & min_persistence) { namespace po = boost::program_options; - po::options_description hidden("Hidden options"); + po::options_description hidden("Hidden options"); hidden.add_options() - ("input-file", po::value(&filepoints), - "Name of file containing a point set. Format is one point per line: X1 ... Xd \n"); - + ("input-file", po::value(&filepoints), + "Name of file containing a point set. Format is one point per line: X1 ... Xd \n"); + po::options_description visible("Allowed options"); visible.add_options() - ("help,h", "produce help message") - ("output-file,o", po::value(&filediag)->default_value(std::string()), - "Name of file in which the persistence diagram is written. Default print in std::cout") - ("max-edge-length,r", po::value(&threshold)->default_value(0), - "Maximal length of an edge for the Rips complex construction.") - ("cpx-dimension,d", po::value(&dim_max)->default_value(1), - "Maximal dimension of the Rips complex we want to compute.") - ("min-field-charac,p", po::value(&min_p)->default_value(2), - "Minimal characteristic p of the coefficient field Z/pZ.") - ("max-field-charac,q", po::value(&max_p)->default_value(1223), - "Minimial characteristic q of the coefficient field Z/pZ.") - ("min-persistence,m", po::value(&min_persistence), - "Minimal lifetime of homology feature to be recorded. Default is 0"); + ("help,h", "produce help message") + ("output-file,o", po::value(&filediag)->default_value(std::string()), + "Name of file in which the persistence diagram is written. Default print in std::cout") + ("max-edge-length,r", po::value(&threshold)->default_value(0), + "Maximal length of an edge for the Rips complex construction.") + ("cpx-dimension,d", po::value(&dim_max)->default_value(1), + "Maximal dimension of the Rips complex we want to compute.") + ("min-field-charac,p", po::value(&min_p)->default_value(2), + "Minimal characteristic p of the coefficient field Z/pZ.") + ("max-field-charac,q", po::value(&max_p)->default_value(1223), + "Minimial characteristic q of the coefficient field Z/pZ.") + ("min-persistence,m", po::value(&min_persistence), + "Minimal lifetime of homology feature to be recorded. Default is 0"); po::positional_options_description pos; pos.add("input-file", 1); - - po::options_description all; all.add(visible).add(hidden); + + po::options_description all; + all.add(visible).add(hidden); po::variables_map vm; po::store(po::command_line_parser(argc, argv). - options(all).positional(pos).run(), vm); + options(all).positional(pos).run(), vm); po::notify(vm); - if (vm.count("help") || !vm.count("input-file")) - { - std::cout << std::endl; - std::cout << "Compute the persistent homology with various coefficient fields \n"; - std::cout << "of a Rips complex defined on a set of input points. The coefficient \n"; - std::cout << "fields are all the Z/rZ for a prime number r contained in the \n"; - std::cout << "specified range [p,q]\n \n"; - std::cout << "The output diagram contains one bar per line, written with the convention: \n"; - std::cout << " p1*...*pr dim b d \n"; - std::cout << "where dim is the dimension of the homological feature,\n"; - std::cout << "b and d are respectively the birth and death of the feature and \n"; - std::cout << "p1*...*pr is the product of prime numbers pi such that the homology \n"; - std::cout << "feature exists in homology with Z/piZ coefficients."<< std::endl << std::endl; - - std::cout << "Usage: " << argv[0] << " [options] input-file" << std::endl << std::endl; - std::cout << visible << std::endl; - std::abort(); + if (vm.count("help") || !vm.count("input-file")) { + std::cout << std::endl; + std::cout << "Compute the persistent homology with various coefficient fields \n"; + std::cout << "of a Rips complex defined on a set of input points. The coefficient \n"; + std::cout << "fields are all the Z/rZ for a prime number r contained in the \n"; + std::cout << "specified range [p,q]\n \n"; + std::cout << "The output diagram contains one bar per line, written with the convention: \n"; + std::cout << " p1*...*pr dim b d \n"; + std::cout << "where dim is the dimension of the homological feature,\n"; + std::cout << "b and d are respectively the birth and death of the feature and \n"; + std::cout << "p1*...*pr is the product of prime numbers pi such that the homology \n"; + std::cout << "feature exists in homology with Z/piZ coefficients." << std::endl << std::endl; + + std::cout << "Usage: " << argv[0] << " [options] input-file" << std::endl << std::endl; + std::cout << visible << std::endl; + std::abort(); } } diff --git a/src/Persistent_cohomology/example/rips_persistence.cpp b/src/Persistent_cohomology/example/rips_persistence.cpp index 4253def9..9b1ef42f 100644 --- a/src/Persistent_cohomology/example/rips_persistence.cpp +++ b/src/Persistent_cohomology/example/rips_persistence.cpp @@ -1,147 +1,151 @@ - /* 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 . - */ - -#include "gudhi/reader_utils.h" -#include "gudhi/graph_simplicial_complex.h" -#include "gudhi/distance_functions.h" -#include "gudhi/Simplex_tree.h" -#include "gudhi/Persistent_cohomology.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 . + */ + +#include +#include +#include +#include +#include #include +#include +#include + using namespace Gudhi; using namespace Gudhi::persistent_cohomology; -typedef int Vertex_handle; -typedef double Filtration_value; - -void program_options( int argc, char * argv[] - , std::string & filepoints - , std::string & filediag - , Filtration_value & threshold - , int & dim_max - , int & p - , Filtration_value & min_persistence ); - -int main (int argc, char * argv[]) -{ - std::string filepoints; - std::string filediag ; - Filtration_value threshold ; - int dim_max ; - int p ; +typedef int Vertex_handle; +typedef double Filtration_value; + +void program_options(int argc, char * argv[] + , std::string & filepoints + , std::string & filediag + , Filtration_value & threshold + , int & dim_max + , int & p + , Filtration_value & min_persistence); + +int main(int argc, char * argv[]) { + std::string filepoints; + std::string filediag; + Filtration_value threshold; + int dim_max; + int p; Filtration_value min_persistence; - program_options(argc,argv,filepoints,filediag,threshold,dim_max,p,min_persistence); + program_options(argc, argv, filepoints, filediag, threshold, dim_max, p, min_persistence); -// Extract the points from the file filepoints + // Extract the points from the file filepoints typedef std::vector Point_t; std::vector< Point_t > points; - read_points( filepoints, points ); + read_points(filepoints, points); -// Compute the proximity graph of the points - Graph_t prox_graph = compute_proximity_graph( points, threshold - , euclidean_distance ); + // Compute the proximity graph of the points + Graph_t prox_graph = compute_proximity_graph(points, threshold + , euclidean_distance); -// Construct the Rips complex in a Simplex Tree - Simplex_tree<> st; - st.insert_graph(prox_graph); // insert the proximity graph in the simplex tree - st.expansion( dim_max ); // expand the graph until dimension dim_max + // Construct the Rips complex in a Simplex Tree + Simplex_tree<> st; + // insert the proximity graph in the simplex tree + st.insert_graph(prox_graph); + // expand the graph until dimension dim_max + st.expansion(dim_max); std::cout << "The complex contains " << st.num_simplices() << " simplices \n"; std::cout << " and has dimension " << st.dimension() << " \n"; -// Sort the simplices in the order of the filtration + // Sort the simplices in the order of the filtration st.initialize_filtration(); -// Compute the persistence diagram of the complex + // Compute the persistence diagram of the complex persistent_cohomology::Persistent_cohomology< Simplex_tree<>, Field_Zp > pcoh(st); - pcoh.init_coefficients( p ); //initilizes the coefficient field for homology - - pcoh.compute_persistent_cohomology( min_persistence ); - -// Output the diagram in filediag - if(filediag.empty()) { pcoh.output_diagram(); } - else { - std::ofstream out(filediag); - pcoh.output_diagram(out); - out.close(); } + // initializes the coefficient field for homology + pcoh.init_coefficients(p); + + pcoh.compute_persistent_cohomology(min_persistence); + + // Output the diagram in filediag + if (filediag.empty()) { + pcoh.output_diagram(); + } else { + std::ofstream out(filediag); + pcoh.output_diagram(out); + out.close(); + } return 0; } - - -void program_options( int argc, char * argv[] - , std::string & filepoints - , std::string & filediag - , Filtration_value & threshold - , int & dim_max - , int & p - , Filtration_value & min_persistence ) -{ +void program_options(int argc, char * argv[] + , std::string & filepoints + , std::string & filediag + , Filtration_value & threshold + , int & dim_max + , int & p + , Filtration_value & min_persistence) { namespace po = boost::program_options; - po::options_description hidden("Hidden options"); + po::options_description hidden("Hidden options"); hidden.add_options() - ("input-file", po::value(&filepoints), - "Name of file containing a point set. Format is one point per line: X1 ... Xd "); - + ("input-file", po::value(&filepoints), + "Name of file containing a point set. Format is one point per line: X1 ... Xd "); + po::options_description visible("Allowed options", 100); visible.add_options() - ("help,h", "produce help message") - ("output-file,o", po::value(&filediag)->default_value(std::string()), - "Name of file in which the persistence diagram is written. Default print in std::cout") - ("max-edge-length,r", po::value(&threshold)->default_value(0), - "Maximal length of an edge for the Rips complex construction.") - ("cpx-dimension,d", po::value(&dim_max)->default_value(1), - "Maximal dimension of the Rips complex we want to compute.") - ("field-charac,p", po::value(&p)->default_value(11), - "Characteristic p of the coefficient field Z/pZ for computing homology.") - ("min-persistence,m", po::value(&min_persistence), - "Minimal lifetime of homology feature to be recorded. Default is 0. Enter a negative value to see zero length intervals"); + ("help,h", "produce help message") + ("output-file,o", po::value(&filediag)->default_value(std::string()), + "Name of file in which the persistence diagram is written. Default print in std::cout") + ("max-edge-length,r", po::value(&threshold)->default_value(0), + "Maximal length of an edge for the Rips complex construction.") + ("cpx-dimension,d", po::value(&dim_max)->default_value(1), + "Maximal dimension of the Rips complex we want to compute.") + ("field-charac,p", po::value(&p)->default_value(11), + "Characteristic p of the coefficient field Z/pZ for computing homology.") + ("min-persistence,m", po::value(&min_persistence), + "Minimal lifetime of homology feature to be recorded. Default is 0. Enter a negative value to see zero length intervals"); po::positional_options_description pos; pos.add("input-file", 1); - - po::options_description all; all.add(visible).add(hidden); + + po::options_description all; + all.add(visible).add(hidden); po::variables_map vm; po::store(po::command_line_parser(argc, argv). - options(all).positional(pos).run(), vm); + options(all).positional(pos).run(), vm); po::notify(vm); - if (vm.count("help") || !vm.count("input-file")) - { - std::cout << std::endl; - std::cout << "Compute the persistent homology with coefficient field Z/pZ \n"; - std::cout << "of a Rips complex defined on a set of input points.\n \n"; - std::cout << "The output diagram contains one bar per line, written with the convention: \n"; - std::cout << " p dim b d \n"; - std::cout << "where dim is the dimension of the homological feature,\n"; - std::cout << "b and d are respectively the birth and death of the feature and \n"; - std::cout << "p is the characteristic of the field Z/pZ used for homology coefficients." << std::endl << std::endl; - - std::cout << "Usage: " << argv[0] << " [options] input-file" << std::endl << std::endl; - std::cout << visible << std::endl; - std::abort(); + if (vm.count("help") || !vm.count("input-file")) { + std::cout << std::endl; + std::cout << "Compute the persistent homology with coefficient field Z/pZ \n"; + std::cout << "of a Rips complex defined on a set of input points.\n \n"; + std::cout << "The output diagram contains one bar per line, written with the convention: \n"; + std::cout << " p dim b d \n"; + std::cout << "where dim is the dimension of the homological feature,\n"; + std::cout << "b and d are respectively the birth and death of the feature and \n"; + std::cout << "p is the characteristic of the field Z/pZ used for homology coefficients." << std::endl << std::endl; + + std::cout << "Usage: " << argv[0] << " [options] input-file" << std::endl << std::endl; + std::cout << visible << std::endl; + std::abort(); } } diff --git a/src/Skeleton_blocker/example/CMakeLists.txt b/src/Skeleton_blocker/example/CMakeLists.txt index d1228526..de0c7bba 100644 --- a/src/Skeleton_blocker/example/CMakeLists.txt +++ b/src/Skeleton_blocker/example/CMakeLists.txt @@ -1,10 +1,12 @@ cmake_minimum_required(VERSION 2.6) project(GUDHIskbl) - add_executable(SkeletonBlockerFromSimplices Skeleton_blocker_from_simplices.cpp) add_executable(SkeletonBlockerIteration Skeleton_blocker_iteration.cpp) add_executable(SkeletonBlockerLink Skeleton_blocker_link.cpp) +target_link_libraries(SkeletonBlockerIteration ${Boost_TIMER_LIBRARY} ${Boost_SYSTEM_LIBRARY}) -target_link_libraries(SkeletonBlockerIteration ${Boost_TIMER_LIBRARY} ${Boost_SYSTEM_LIBRARY}) +add_test(SkeletonBlockerFromSimplices ${CMAKE_CURRENT_BINARY_DIR}/SkeletonBlockerFromSimplices) +add_test(SkeletonBlockerIteration ${CMAKE_CURRENT_BINARY_DIR}/SkeletonBlockerIteration) +add_test(SkeletonBlockerLink ${CMAKE_CURRENT_BINARY_DIR}/SkeletonBlockerLink) diff --git a/src/Skeleton_blocker/example/Skeleton_blocker_from_simplices.cpp b/src/Skeleton_blocker/example/Skeleton_blocker_from_simplices.cpp index 9f9b3d52..2738c01c 100644 --- a/src/Skeleton_blocker/example/Skeleton_blocker_from_simplices.cpp +++ b/src/Skeleton_blocker/example/Skeleton_blocker_from_simplices.cpp @@ -1,34 +1,33 @@ - /* 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-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 - * 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 . - */ - +/* 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-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 + * 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 . + */ + +#include #include #include #include #include #include - - -#include "gudhi/Skeleton_blocker.h" +#include using namespace std; using namespace Gudhi; @@ -39,45 +38,44 @@ typedef Complex::Vertex_handle Vertex_handle; typedef Complex::Simplex_handle Simplex_handle; typedef Complex::Simplex_handle Simplex; -int main (int argc, char *argv[]){ - std::vector simplices; +int main(int argc, char *argv[]) { + std::vector simplices; - //add 4 triangles of a tetrahedron 0123 - simplices.push_back(Simplex_handle(Vertex_handle(0),Vertex_handle(1),Vertex_handle(2))); - simplices.push_back(Simplex_handle(Vertex_handle(1),Vertex_handle(2),Vertex_handle(3))); - simplices.push_back(Simplex_handle(Vertex_handle(3),Vertex_handle(0),Vertex_handle(2))); - simplices.push_back(Simplex_handle(Vertex_handle(3),Vertex_handle(0),Vertex_handle(1))); + // add 4 triangles of a tetrahedron 0123 + simplices.push_back(Simplex_handle(Vertex_handle(0), Vertex_handle(1), Vertex_handle(2))); + simplices.push_back(Simplex_handle(Vertex_handle(1), Vertex_handle(2), Vertex_handle(3))); + simplices.push_back(Simplex_handle(Vertex_handle(3), Vertex_handle(0), Vertex_handle(2))); + simplices.push_back(Simplex_handle(Vertex_handle(3), Vertex_handle(0), Vertex_handle(1))); - //get complex from top faces - Complex complex(make_complex_from_top_faces(simplices.begin(),simplices.end())); + // get complex from top faces + Complex complex(make_complex_from_top_faces(simplices.begin(), simplices.end())); - std::cout << "Simplices:"<. - */ +/* 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-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 + * 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 . + */ + +#include #include @@ -29,8 +31,6 @@ #include -#include "gudhi/Skeleton_blocker.h" - using namespace std; using namespace Gudhi; using namespace skbl; @@ -39,54 +39,53 @@ typedef Skeleton_blocker_complex Complex; typedef Complex::Vertex_handle Vertex_handle; typedef Complex::Simplex_handle Simplex; - -Complex build_complete_complex(int n){ - // build a full complex with n vertices and 2^n-1 simplices - Complex complex; - for(int i=0;i. - */ +/* 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-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 + * 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 . + */ +#include #include #include @@ -27,9 +28,6 @@ #include #include - -#include "gudhi/Skeleton_blocker.h" - using namespace std; using namespace Gudhi; using namespace skbl; @@ -39,33 +37,31 @@ typedef Complex::Vertex_handle Vertex_handle; typedef Complex::Root_vertex_handle Root_vertex_handle; typedef Complex::Simplex_handle Simplex; +int main(int argc, char *argv[]) { + // build a full complex with 4 vertices and 2^4-1 simplices + // Initial vertices are (0,1,2,3,4) + Simplex tetrahedron(Vertex_handle(0), Vertex_handle(1), Vertex_handle(2), Vertex_handle(3)); + Complex complex; + complex.add_simplex(tetrahedron); -int main (int argc, char *argv[]){ - // build a full complex with 4 vertices and 2^4-1 simplices - // Initial vertices are (0,1,2,3,4) - Simplex tetrahedron(Vertex_handle(0),Vertex_handle(1),Vertex_handle(2),Vertex_handle(3)); - Complex complex; - complex.add_simplex(tetrahedron); + cout << "complex:" << complex.to_string() << endl; - cout<<"complex:"< Date: Thu, 8 Oct 2015 21:15:51 +0000 Subject: 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 --- data/points/generator/hypergenerator.cpp | 7 +- src/GudhUI/gui/MainWindow.cpp | 385 +++++++-------- src/GudhUI/gui/MainWindow.h | 140 +++--- src/GudhUI/gui/Menu_edge_contraction.cpp | 118 ++--- src/GudhUI/gui/Menu_edge_contraction.h | 73 +-- src/GudhUI/gui/Menu_k_nearest_neighbors.cpp | 82 ++-- src/GudhUI/gui/Menu_k_nearest_neighbors.h | 58 ++- src/GudhUI/gui/Menu_persistence.cpp | 45 +- src/GudhUI/gui/Menu_persistence.h | 42 +- src/GudhUI/gui/Menu_uniform_neighbors.cpp | 87 ++-- src/GudhUI/gui/Menu_uniform_neighbors.h | 57 ++- src/GudhUI/gui/Viewer.cpp | 0 src/GudhUI/gui/Viewer_instructor.cpp | 0 src/GudhUI/gui/gudhui.cpp | 35 +- src/GudhUI/model/Complex_typedefs.h | 48 +- src/GudhUI/model/Model.h | 650 +++++++++++++------------- src/GudhUI/utils/Critical_points.h | 203 ++++---- src/GudhUI/utils/Edge_collapsor.h | 156 ++++--- src/GudhUI/utils/Edge_contractor.h | 156 ++++--- src/GudhUI/utils/Furthest_point_epsilon_net.h | 244 +++++----- src/GudhUI/utils/Is_manifold.h | 117 +++-- src/GudhUI/utils/K_nearest_builder.h | 143 +++--- src/GudhUI/utils/Lloyd_builder.h | 133 +++--- src/GudhUI/utils/MClock.h | 109 +++-- src/GudhUI/utils/Persistence_compute.h | 138 +++--- src/GudhUI/utils/Rips_builder.h | 99 ++-- src/GudhUI/utils/UI_utils.h | 43 +- src/GudhUI/utils/Vertex_collapsor.h | 138 +++--- src/GudhUI/view/Color.h | 42 +- src/GudhUI/view/FirstCoordProjector.h | 44 +- src/GudhUI/view/Projector3D.h | 47 +- src/GudhUI/view/View_parameter.h | 264 ++++++----- src/GudhUI/view/Viewer.cpp | 303 ++++++------ src/GudhUI/view/Viewer.h | 129 ++--- src/GudhUI/view/Viewer_instructor.cpp | 272 +++++------ src/GudhUI/view/Viewer_instructor.h | 149 +++--- 36 files changed, 2492 insertions(+), 2264 deletions(-) delete mode 100644 src/GudhUI/gui/Viewer.cpp delete mode 100644 src/GudhUI/gui/Viewer_instructor.cpp (limited to 'src') diff --git a/data/points/generator/hypergenerator.cpp b/data/points/generator/hypergenerator.cpp index 32ef450d..60890b44 100644 --- a/data/points/generator/hypergenerator.cpp +++ b/data/points/generator/hypergenerator.cpp @@ -35,8 +35,9 @@ typedef CGAL::Epick_d< CGAL::Dynamic_dimension_tag > K; typedef K::Point_d Point; void usage(char * const progName) { - std::cerr << "Usage: " << progName << " in|on sphere|cube off_file_name points_number[integer > 0] dimension[integer > 1] radius[double > 0.0 | default = 1.0]" << std::endl; - exit(-1); // ----- >> + std::cerr << "Usage: " << progName << " in|on sphere|cube off_file_name points_number[integer > 0] " << + "dimension[integer > 1] radius[double > 0.0 | default = 1.0]" << std::endl; + exit(-1); } int main(int argc, char **argv) { @@ -119,7 +120,7 @@ int main(int argc, char **argv) { for (auto thePoint : points) { int i = 0; - for (;i < dimension - 1; i++) { + for (; i < dimension - 1; i++) { diagram_out << thePoint[i] << " "; } diagram_out << thePoint[i] << std::endl; // last point + Carriage Return diff --git a/src/GudhUI/gui/MainWindow.cpp b/src/GudhUI/gui/MainWindow.cpp index e41b15ba..779ccd33 100644 --- a/src/GudhUI/gui/MainWindow.cpp +++ b/src/GudhUI/gui/MainWindow.cpp @@ -1,3 +1,25 @@ +/* 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-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 + * 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 . + */ + #include "MainWindow.h" #include @@ -6,292 +28,271 @@ #include - #include "gui/Menu_k_nearest_neighbors.h" #include "gui/Menu_uniform_neighbors.h" #include "gui/Menu_edge_contraction.h" #include "gui/Menu_persistence.h" +MainWindow::MainWindow(QWidget* parent) : + menu_k_nearest_neighbors_(new Menu_k_nearest_neighbors(this)), + menu_uniform_neighbors_(new Menu_uniform_neighbors(this)), + menu_edge_contraction_(new Menu_edge_contraction(this, model_)), + menu_persistence_(new Menu_persistence(this)) { + // #ifndef NDEBUG // catch nan + // feenableexcept(FE_DIVBYZERO | FE_INVALID | FE_OVERFLOW); + // #endif -MainWindow::MainWindow(QWidget* parent): -menu_k_nearest_neighbors_(new Menu_k_nearest_neighbors(this)), -menu_uniform_neighbors_(new Menu_uniform_neighbors(this)), -menu_edge_contraction_(new Menu_edge_contraction(this,model_)), -menu_persistence_(new Menu_persistence(this)) -{ -//#ifndef NDEBUG // catch nan -//feenableexcept(FE_DIVBYZERO | FE_INVALID | FE_OVERFLOW); -//#endif + setupUi(this); - setupUi(this); + viewer_instructor_ = new Viewer_instructor( + this, + this->viewer, + model_.complex_); - viewer_instructor_ = new Viewer_instructor( - this, - this->viewer, - model_.complex_ - ); + connectActions(); - connectActions(); - - update_view(); + update_view(); } -void -MainWindow::closeEvent(QCloseEvent *event){ - exit(0); +void +MainWindow::closeEvent(QCloseEvent *event) { + exit(0); } - -void -MainWindow::connectActions(){ - QObject::connect(this->actionLoad_complex, SIGNAL(triggered()), this, - SLOT(off_file_open())); - QObject::connect(this->actionLoad_points, SIGNAL(triggered()), this, - SLOT(off_points_open())); - QObject::connect(this->actionSave_complex, SIGNAL(triggered()), this, - SLOT(off_file_save())); - QObject::connect(this->actionSave_points, SIGNAL(triggered()), this, - SLOT(off_points_save())); - - QObject::connect(this->actionShow_graph_stats, SIGNAL(triggered()), this, - SLOT(show_graph_stats())); - QObject::connect(this->actionShow_complex_stats, SIGNAL(triggered()), this, - SLOT(show_complex_stats())); - QObject::connect(this->actionShow_complex_dimension, SIGNAL(triggered()), this, - SLOT(show_complex_dimension())); - - QObject::connect(this->actionUniform_proximity_graph, SIGNAL(triggered()), this, - SLOT(build_rips_menu())); - QObject::connect(this->actionK_nearest_neighbors_graph, SIGNAL(triggered()), this, - SLOT(build_k_nearest_neighbors_menu())); - - - QObject::connect(this->actionContract_edges, SIGNAL(triggered()), this, - SLOT(contract_edge_menu())); - - QObject::connect(this->actionCollapse_vertices, SIGNAL(triggered()), this, - SLOT(collapse_vertices())); - - QObject::connect(this->actionCollapse_edges, SIGNAL(triggered()), this, - SLOT(collapse_edges())); - - QObject::connect(this->actionNoise, SIGNAL(triggered()), this, - SLOT(uniform_noise())); - QObject::connect(this->actionLloyd, SIGNAL(triggered()), this, - SLOT(lloyd())); - - - //view - QObject::connect(this->actionPoints, SIGNAL(triggered()), this->viewer_instructor_, - SLOT(change_draw_vertices())); - QObject::connect(this->actionEdges, SIGNAL(triggered()), this->viewer_instructor_, - SLOT(change_draw_edges())); - QObject::connect(this->actionTriangles, SIGNAL(triggered()), this->viewer_instructor_, - SLOT(change_draw_triangles())); - - //topology - QObject::connect(this->actionShow_homology_group, SIGNAL(triggered()), this, - SLOT(show_homology_group())); - QObject::connect(this->actionEuler_characteristic, SIGNAL(triggered()), this, - SLOT(show_euler_characteristic())); - QObject::connect(this->actionPersistence, SIGNAL(triggered()), this, - 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())); - +void +MainWindow::connectActions() { + QObject::connect(this->actionLoad_complex, SIGNAL(triggered()), this, + SLOT(off_file_open())); + QObject::connect(this->actionLoad_points, SIGNAL(triggered()), this, + SLOT(off_points_open())); + QObject::connect(this->actionSave_complex, SIGNAL(triggered()), this, + SLOT(off_file_save())); + QObject::connect(this->actionSave_points, SIGNAL(triggered()), this, + SLOT(off_points_save())); + + QObject::connect(this->actionShow_graph_stats, SIGNAL(triggered()), this, + SLOT(show_graph_stats())); + QObject::connect(this->actionShow_complex_stats, SIGNAL(triggered()), this, + SLOT(show_complex_stats())); + QObject::connect(this->actionShow_complex_dimension, SIGNAL(triggered()), this, + SLOT(show_complex_dimension())); + + QObject::connect(this->actionUniform_proximity_graph, SIGNAL(triggered()), this, + SLOT(build_rips_menu())); + QObject::connect(this->actionK_nearest_neighbors_graph, SIGNAL(triggered()), this, + SLOT(build_k_nearest_neighbors_menu())); + + + QObject::connect(this->actionContract_edges, SIGNAL(triggered()), this, + SLOT(contract_edge_menu())); + + QObject::connect(this->actionCollapse_vertices, SIGNAL(triggered()), this, + SLOT(collapse_vertices())); + + QObject::connect(this->actionCollapse_edges, SIGNAL(triggered()), this, + SLOT(collapse_edges())); + + QObject::connect(this->actionNoise, SIGNAL(triggered()), this, + SLOT(uniform_noise())); + QObject::connect(this->actionLloyd, SIGNAL(triggered()), this, + SLOT(lloyd())); + + + // view + QObject::connect(this->actionPoints, SIGNAL(triggered()), this->viewer_instructor_, + SLOT(change_draw_vertices())); + QObject::connect(this->actionEdges, SIGNAL(triggered()), this->viewer_instructor_, + SLOT(change_draw_edges())); + QObject::connect(this->actionTriangles, SIGNAL(triggered()), this->viewer_instructor_, + SLOT(change_draw_triangles())); + + // topology + QObject::connect(this->actionShow_homology_group, SIGNAL(triggered()), this, + SLOT(show_homology_group())); + QObject::connect(this->actionEuler_characteristic, SIGNAL(triggered()), this, + SLOT(show_euler_characteristic())); + QObject::connect(this->actionPersistence, SIGNAL(triggered()), this, + 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())); } void -MainWindow::init_view() const{ - viewer_instructor_->initialize_bounding_box(); - viewer_instructor_->show_entire_scene(); - update_view(); +MainWindow::init_view() const { + viewer_instructor_->initialize_bounding_box(); + viewer_instructor_->show_entire_scene(); + update_view(); } - void -MainWindow::update_view() const{ - emit (sceneChanged()); +MainWindow::update_view() const { + emit(sceneChanged()); } - - /** * open a file chooser to choose an off to load */ -void -MainWindow::off_file_open(){ - QString fileName = QFileDialog::getOpenFileName(this, tr("Open off File"), - "~/", tr("off files (*.off)")); - if (!fileName.isEmpty()){ - model_.off_file_open(fileName.toStdString()); - init_view(); - } +void +MainWindow::off_file_open() { + QString fileName = QFileDialog::getOpenFileName(this, tr("Open off File"), + "~/", tr("off files (*.off)")); + if (!fileName.isEmpty()) { + model_.off_file_open(fileName.toStdString()); + init_view(); + } } void -MainWindow::off_points_open(){ - QString fileName = QFileDialog::getOpenFileName(this, tr("Open points in a off file"), - "~/", tr("off files (*.off)")); - if (!fileName.isEmpty()){ - model_.off_points_open(fileName.toStdString()); - init_view(); - } +MainWindow::off_points_open() { + QString fileName = QFileDialog::getOpenFileName(this, tr("Open points in a off file"), + "~/", tr("off files (*.off)")); + if (!fileName.isEmpty()) { + model_.off_points_open(fileName.toStdString()); + init_view(); + } } - /** * open a file chooser to choose an off to save */ -void -MainWindow::off_file_save(){ - QString fileName = QFileDialog::getOpenFileName(this, tr("Save to off File"), - "~/", tr("off files (*.off)")); - if (!fileName.isEmpty()) - { - model_.off_file_save(fileName.toStdString()); - } +void +MainWindow::off_file_save() { + QString fileName = QFileDialog::getOpenFileName(this, tr("Save to off File"), + "~/", tr("off files (*.off)")); + if (!fileName.isEmpty()) { + model_.off_file_save(fileName.toStdString()); + } } /** * open a file chooser to choose an off to save */ void -MainWindow::off_points_save(){ - QString fileName = QFileDialog::getOpenFileName(this, tr("Save to off File"), - "~/", tr("off files (*.off)")); - if (!fileName.isEmpty()) - { - model_.off_points_save(fileName.toStdString()); - } +MainWindow::off_points_save() { + QString fileName = QFileDialog::getOpenFileName(this, tr("Save to off File"), + "~/", tr("off files (*.off)")); + if (!fileName.isEmpty()) { + model_.off_points_save(fileName.toStdString()); + } } - void -MainWindow::show_graph_stats(){ - model_.show_graph_stats(); +MainWindow::show_graph_stats() { + model_.show_graph_stats(); } void -MainWindow::show_complex_stats(){ - model_.show_complex_stats(); +MainWindow::show_complex_stats() { + model_.show_complex_stats(); } -void -MainWindow::show_complex_dimension(){ - model_.show_complex_dimension(); +void +MainWindow::show_complex_dimension() { + model_.show_complex_dimension(); } - void -MainWindow::build_rips_menu(){ - menu_uniform_neighbors_->show(); +MainWindow::build_rips_menu() { + menu_uniform_neighbors_->show(); } void -MainWindow::build_rips(double alpha){ - model_.build_rips(alpha); - update_view(); +MainWindow::build_rips(double alpha) { + model_.build_rips(alpha); + update_view(); } void -MainWindow::build_k_nearest_neighbors_menu(){ - menu_k_nearest_neighbors_->show(); +MainWindow::build_k_nearest_neighbors_menu() { + menu_k_nearest_neighbors_->show(); } void -MainWindow::build_k_nearest_neighbors(unsigned k){ - model_.build_k_nearest_neighbors(k); - update_view(); +MainWindow::build_k_nearest_neighbors(unsigned k) { + model_.build_k_nearest_neighbors(k); + update_view(); } void -MainWindow::contract_edge_menu(){ - menu_edge_contraction_->show(); +MainWindow::contract_edge_menu() { + menu_edge_contraction_->show(); } void -MainWindow::contract_edges(unsigned num_collapses){ - std::cerr <<"Collapse "<show(); +MainWindow::persistence_menu() { + menu_persistence_->show(); } void -MainWindow::compute_persistence(int p,double threshold,int max_dim,double min_pers){ - model_.show_persistence(p,threshold,max_dim,min_pers); +MainWindow::compute_persistence(int p, double threshold, int max_dim, double min_pers) { + model_.show_persistence(p, threshold, max_dim, min_pers); } void -MainWindow::critical_points_menu(){ - bool ok; - double max_length = QInputDialog::getDouble(this, tr("Maximal edge length for the Rips"), - tr("Maximal edge length:"), 0, 0, 10000, 3, &ok); - if (ok) - model_.show_critical_points(max_length); +MainWindow::critical_points_menu() { + bool ok; + double max_length = QInputDialog::getDouble(this, tr("Maximal edge length for the Rips"), + tr("Maximal edge length:"), 0, 0, 10000, 3, &ok); + if (ok) + model_.show_critical_points(max_length); } void -MainWindow::is_manifold_menu(){ - model_.show_is_manifold(); +MainWindow::is_manifold_menu() { + model_.show_is_manifold(); } diff --git a/src/GudhUI/gui/MainWindow.h b/src/GudhUI/gui/MainWindow.h index e46b72a3..c8c3fcf6 100644 --- a/src/GudhUI/gui/MainWindow.h +++ b/src/GudhUI/gui/MainWindow.h @@ -1,5 +1,27 @@ -#ifndef MAIN_WINDOW_H -#define MAIN_WINDOW_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): David Salinas + * + * 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 + * 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 . + */ + +#ifndef GUI_MAINWINDOW_H_ +#define GUI_MAINWINDOW_H_ // Workaround for moc-qt4 not parsing boost headers #include @@ -15,86 +37,82 @@ class Menu_uniform_neighbors; class Menu_edge_contraction; class Menu_persistence; -class MainWindow : public QMainWindow,public Ui::MainWindow{ - Q_OBJECT +class MainWindow : public QMainWindow, public Ui::MainWindow { + Q_OBJECT -private: - Model model_; - Viewer_instructor* viewer_instructor_; - Menu_k_nearest_neighbors* menu_k_nearest_neighbors_; - Menu_uniform_neighbors* menu_uniform_neighbors_; - Menu_edge_contraction* menu_edge_contraction_; - Menu_persistence* menu_persistence_; + private: + Model model_; + Viewer_instructor* viewer_instructor_; + Menu_k_nearest_neighbors* menu_k_nearest_neighbors_; + Menu_uniform_neighbors* menu_uniform_neighbors_; + Menu_edge_contraction* menu_edge_contraction_; + Menu_persistence* menu_persistence_; -public: - MainWindow(QWidget* parent = 0); - void connectActions(); + public: + MainWindow(QWidget* parent = 0); + void connectActions(); - /** - * compute the bounding box and calls update view - */ - void init_view() const; - void update_view() const; + /** + * compute the bounding box and calls update view + */ + void init_view() const; + void update_view() const; -protected: - void closeEvent(QCloseEvent *event); - void keyPressEvent(QKeyEvent *event){} + protected: + void closeEvent(QCloseEvent *event); -public: + void keyPressEvent(QKeyEvent *event) { } - public slots: + public: + public slots: + /** + * open a file chooser to choose an off to load + */ + void off_file_open(); + void off_points_open(); - /** - * open a file chooser to choose an off to load - */ - void off_file_open(); + /** + * open a file chooser to choose an off to save + */ + void off_file_save(); + void off_points_save(); - void off_points_open(); + void show_graph_stats(); + void show_complex_stats(); + void show_complex_dimension(); - /** - * open a file chooser to choose an off to save - */ - void off_file_save(); - void off_points_save(); - void show_graph_stats(); - void show_complex_stats(); - void show_complex_dimension(); + void build_rips_menu(); + void build_rips(double alpha); + void build_k_nearest_neighbors_menu(); + void build_k_nearest_neighbors(unsigned k); - void build_rips_menu(); - void build_rips(double alpha); - void build_k_nearest_neighbors_menu(); - void build_k_nearest_neighbors(unsigned k); + void contract_edge_menu(); + void contract_edges(unsigned num_collapses); - void contract_edge_menu(); - void contract_edges(unsigned num_collapses); + void collapse_vertices(); + void collapse_edges(); - void collapse_vertices(); - void collapse_edges(); + void uniform_noise(); + void lloyd(); + void show_homology_group(); + void show_euler_characteristic(); + void persistence_menu(); + void compute_persistence(int p, double threshold, int max_dim, double min_pers); + void critical_points_menu(); + void is_manifold_menu(); - void uniform_noise(); - void lloyd(); - - void show_homology_group(); - void show_euler_characteristic(); - 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: - signals: - void sceneChanged() const; - + public: + signals: + void sceneChanged() const; }; -#endif +#endif // GUI_MAINWINDOW_H_ diff --git a/src/GudhUI/gui/Menu_edge_contraction.cpp b/src/GudhUI/gui/Menu_edge_contraction.cpp index dd2621be..a679b0bf 100644 --- a/src/GudhUI/gui/Menu_edge_contraction.cpp +++ b/src/GudhUI/gui/Menu_edge_contraction.cpp @@ -1,91 +1,97 @@ -/* - * Menu_edge_contraction.cpp +/* This file is part of the Gudhi Library. The Gudhi library + * (Geometric Understanding in Higher Dimensions) is a generic C++ + * library for computational topology. * - * Created on: Sep 11, 2014 - * Author: dsalinas + * Author(s): David Salinas + * + * 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 + * 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 . */ -#ifndef MENU_EDGE_CONTRACTION_CPP_ -#define MENU_EDGE_CONTRACTION_CPP_ - +#ifndef GUI_MENU_EDGE_CONTRACTION_CPP_ +#define GUI_MENU_EDGE_CONTRACTION_CPP_ #include "Menu_edge_contraction.h" -Menu_edge_contraction::Menu_edge_contraction(MainWindow* parent,const Model& model): -parent_(parent),model_(model) -{ - setupUi(this); - connectActions(parent_); +Menu_edge_contraction::Menu_edge_contraction(MainWindow* parent, const Model& model) : + parent_(parent), model_(model) { + setupUi(this); + connectActions(parent_); } -void Menu_edge_contraction::connectActions(MainWindow* parent) -{ - QObject::connect( - this->horizontalSlider, - SIGNAL(valueChanged(int)), - this, - SLOT(slider_value_changed(int)) - ); +void Menu_edge_contraction::connectActions(MainWindow* parent) { + QObject::connect( + this->horizontalSlider, + SIGNAL(valueChanged(int)), + this, + SLOT(slider_value_changed(int))); - QObject::connect(this, SIGNAL(contract_edges(unsigned)), parent, SLOT(contract_edges(unsigned))); - - QObject::connect(this->pushButton_collapse, SIGNAL(clicked()), this, SLOT(send_contract_edges())); + QObject::connect(this, SIGNAL(contract_edges(unsigned)), parent, SLOT(contract_edges(unsigned))); + QObject::connect(this->pushButton_collapse, SIGNAL(clicked()), this, SLOT(send_contract_edges())); } -void Menu_edge_contraction::slider_value_changed(int new_slider_value){ - int num_collapses = - (horizontalSlider->value()==1)? 1 : horizontalSlider->value() * model_.num_vertices() / 100 ; - this->txt_nb_vertices->setNum((int)model_.num_vertices()); - this->txt_nb_collapses->setNum(num_collapses); - this->spinBox_nb_remaining_vertices->setValue(model_.num_vertices()-num_collapses); +void Menu_edge_contraction::slider_value_changed(int new_slider_value) { + int num_collapses = + (horizontalSlider->value() == 1) ? 1 : horizontalSlider->value() * model_.num_vertices() / 100; + this->txt_nb_vertices->setNum(static_cast(model_.num_vertices())); + this->txt_nb_collapses->setNum(num_collapses); + this->spinBox_nb_remaining_vertices->setValue(model_.num_vertices() - num_collapses); } - void -Menu_edge_contraction::update_slider_value(){ - int num_vertices = model_.num_vertices(); - int num_collapses = (horizontalSlider->value()==1)? 1 : horizontalSlider->value() * num_vertices / 100 ; - int horizontal_slider_position = num_vertices>0? num_collapses/(double)num_vertices * 100 : 1 ; - horizontalSlider->setValue(horizontal_slider_position); +Menu_edge_contraction::update_slider_value() { + int num_vertices = model_.num_vertices(); + int num_collapses = (horizontalSlider->value() == 1) ? 1 : horizontalSlider->value() * num_vertices / 100; + int horizontal_slider_position = num_vertices > 0 ? num_collapses / static_cast(num_vertices * 100) : 1; + horizontalSlider->setValue(horizontal_slider_position); } - void -Menu_edge_contraction::update_gui_numbers(){ - update_slider_value(); - bool ok; - int num_collapses = this->txt_nb_collapses->text().toInt(&ok,10); - if(!ok) return; - this->txt_nb_vertices->setNum((int)model_.num_vertices()); - this->txt_nb_collapses->setNum(num_collapses); - this->spinBox_nb_remaining_vertices->setValue(model_.num_vertices()-num_collapses); +Menu_edge_contraction::update_gui_numbers() { + update_slider_value(); + bool ok; + int num_collapses = this->txt_nb_collapses->text().toInt(&ok, 10); + if (!ok) return; + this->txt_nb_vertices->setNum(static_cast(model_.num_vertices())); + this->txt_nb_collapses->setNum(num_collapses); + this->spinBox_nb_remaining_vertices->setValue(model_.num_vertices() - num_collapses); } void -Menu_edge_contraction::update_gui_numbers(int new_value){ - update_gui_numbers(); +Menu_edge_contraction::update_gui_numbers(int new_value) { + update_gui_numbers(); } - void -Menu_edge_contraction::send_contract_edges(){ - emit(contract_edges(num_collapses())); - update_gui_numbers(); +Menu_edge_contraction::send_contract_edges() { + emit(contract_edges(num_collapses())); + update_gui_numbers(); } unsigned -Menu_edge_contraction::num_vertices(){ - return model_.num_vertices(); +Menu_edge_contraction::num_vertices() { + return model_.num_vertices(); } unsigned -Menu_edge_contraction::num_collapses(){ - return (horizontalSlider->value()==1)? 1 : horizontalSlider->value() * num_vertices() / 100 ; +Menu_edge_contraction::num_collapses() { + return (horizontalSlider->value() == 1) ? 1 : horizontalSlider->value() * num_vertices() / 100; } - #include "Menu_edge_contraction.moc" -#endif /* MENU_EDGE_CONTRACTION_CPP_ */ +#endif // GUI_MENU_EDGE_CONTRACTION_CPP_ diff --git a/src/GudhUI/gui/Menu_edge_contraction.h b/src/GudhUI/gui/Menu_edge_contraction.h index 81d37bd8..08f0bf67 100644 --- a/src/GudhUI/gui/Menu_edge_contraction.h +++ b/src/GudhUI/gui/Menu_edge_contraction.h @@ -1,12 +1,27 @@ -/* - * Menu_edge_contraction.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. * - * Created on: Sep 11, 2014 - * Author: dsalinas + * Author(s): David Salinas + * + * 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 + * 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 . */ -#ifndef MENU_EDGE_CONTRACTION_H_ -#define MENU_EDGE_CONTRACTION_H_ +#ifndef GUI_MENU_EDGE_CONTRACTION_H_ +#define GUI_MENU_EDGE_CONTRACTION_H_ // Workaround for moc-qt4 not parsing boost headers #include @@ -16,39 +31,33 @@ #include "model/Model.h" +class Menu_edge_contraction : public QDialog, public Ui::MenuEdgeContraction { + Q_OBJECT -class Menu_edge_contraction : public QDialog,public Ui::MenuEdgeContraction{ - Q_OBJECT -private: - MainWindow* parent_; - const Model& model_; - + private: + MainWindow* parent_; + const Model& model_; - void update_slider_value(); -public: + void update_slider_value(); - Menu_edge_contraction(MainWindow* parent,const Model& model); + public: + Menu_edge_contraction(MainWindow* parent, const Model& model); - void connectActions(MainWindow* parent); + void connectActions(MainWindow* parent); + private: + unsigned num_vertices(); + unsigned num_collapses(); -private: - unsigned num_vertices(); - unsigned num_collapses(); + public slots: + void slider_value_changed(int new_slider_value); + void update_gui_numbers(); + void update_gui_numbers(int gui_numbers); - public slots: - - void slider_value_changed(int new_slider_value); - void update_gui_numbers(); - void update_gui_numbers(int); - - void send_contract_edges(); - signals: - - void contract_edges(unsigned num_collapses); + void send_contract_edges(); + signals: + void contract_edges(unsigned num_collapses); }; - - -#endif /* MENU_EDGE_CONTRACTION_H_ */ +#endif // GUI_MENU_EDGE_CONTRACTION_H_ diff --git a/src/GudhUI/gui/Menu_k_nearest_neighbors.cpp b/src/GudhUI/gui/Menu_k_nearest_neighbors.cpp index 21c67b2a..e24865f2 100644 --- a/src/GudhUI/gui/Menu_k_nearest_neighbors.cpp +++ b/src/GudhUI/gui/Menu_k_nearest_neighbors.cpp @@ -1,55 +1,59 @@ -/* - * Menu_k_nearest_neighbors.cpp +/* This file is part of the Gudhi Library. The Gudhi library + * (Geometric Understanding in Higher Dimensions) is a generic C++ + * library for computational topology. * - * Created on: Sep 11, 2014 - * Author: dsalinas + * Author(s): David Salinas + * + * 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 + * 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 . */ - #include "Menu_k_nearest_neighbors.h" -Menu_k_nearest_neighbors::Menu_k_nearest_neighbors(QMainWindow* parent_): -parent(parent_) -{ - setupUi(this); - connectActions(parent_); +Menu_k_nearest_neighbors::Menu_k_nearest_neighbors(QMainWindow* parent_) + : parent(parent_) { + setupUi(this); + connectActions(parent_); } -void Menu_k_nearest_neighbors::connectActions(QMainWindow* parent){ - - QObject::connect( - this->pushButtonCompute, - SIGNAL(clicked()), - this, - SLOT(send_compute_k_nearest_neighbors()) - ); - QObject::connect( - this->spinBoxK, - SIGNAL(valueChanged(int)), - this, - SLOT(update_k(int)) - ); - QObject::connect( - this, - SIGNAL(compute_k_nearest_neighbors(unsigned)), - parent, - SLOT(build_k_nearest_neighbors(unsigned)) - ); - +void Menu_k_nearest_neighbors::connectActions(QMainWindow* parent) { + QObject::connect(this->pushButtonCompute, + SIGNAL(clicked()), + this, + SLOT(send_compute_k_nearest_neighbors())); + QObject::connect(this->spinBoxK, + SIGNAL(valueChanged(int)), + this, + SLOT(update_k(int))); + QObject::connect(this, + SIGNAL(compute_k_nearest_neighbors(unsigned)), + parent, + SLOT(build_k_nearest_neighbors(unsigned))); } -void Menu_k_nearest_neighbors::send_compute_k_nearest_neighbors(){ - emit(compute_k_nearest_neighbors((unsigned)spinBoxK->value())); +void Menu_k_nearest_neighbors::send_compute_k_nearest_neighbors() { + emit(compute_k_nearest_neighbors((unsigned) spinBoxK->value())); } -void Menu_k_nearest_neighbors::accept(){ - send_compute_k_nearest_neighbors(); +void Menu_k_nearest_neighbors::accept() { + send_compute_k_nearest_neighbors(); } -void Menu_k_nearest_neighbors::update_k(int new_k_value){ - if(checkBoxAutoUpdate->isChecked()) - emit(compute_k_nearest_neighbors((unsigned)spinBoxK->value())); +void Menu_k_nearest_neighbors::update_k(int new_k_value) { + if (checkBoxAutoUpdate->isChecked()) + emit(compute_k_nearest_neighbors((unsigned) spinBoxK->value())); } - #include "Menu_k_nearest_neighbors.moc" diff --git a/src/GudhUI/gui/Menu_k_nearest_neighbors.h b/src/GudhUI/gui/Menu_k_nearest_neighbors.h index d72b0074..8088b768 100644 --- a/src/GudhUI/gui/Menu_k_nearest_neighbors.h +++ b/src/GudhUI/gui/Menu_k_nearest_neighbors.h @@ -1,39 +1,51 @@ -/* - * Menu_k_nearest_neighbors.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. * - * Created on: Sep 11, 2014 - * Author: dsalinas + * Author(s): David Salinas + * + * 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 + * 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 . */ -#ifndef MENU_K_NEAREST_NEIGHBORS_H_ -#define MENU_K_NEAREST_NEIGHBORS_H_ +#ifndef GUI_MENU_K_NEAREST_NEIGHBORS_H_ +#define GUI_MENU_K_NEAREST_NEIGHBORS_H_ #include #include "gui/ui_KNearestNeighborsMenu.h" class QWidget; +class Menu_k_nearest_neighbors : public QDialog, public Ui::KNearestNeighborsMenu { + Q_OBJECT -class Menu_k_nearest_neighbors : public QDialog,public Ui::KNearestNeighborsMenu{ - Q_OBJECT -private: - QMainWindow* parent; + private: + QMainWindow* parent; -public: + public: + Menu_k_nearest_neighbors(QMainWindow* parent_); - Menu_k_nearest_neighbors(QMainWindow* parent_); + void connectActions(QMainWindow* parent); - void connectActions(QMainWindow* parent); - - public slots: - void send_compute_k_nearest_neighbors(); - void update_k(int); - void accept(); - - signals: - void compute_k_nearest_neighbors(unsigned k); + public slots: + void send_compute_k_nearest_neighbors(); + void update_k(int k); + void accept(); + signals: + void compute_k_nearest_neighbors(unsigned k); }; - -#endif /* MENU_K_NEAREST_NEIGHBORS_H_ */ +#endif // GUI_MENU_K_NEAREST_NEIGHBORS_H_ diff --git a/src/GudhUI/gui/Menu_persistence.cpp b/src/GudhUI/gui/Menu_persistence.cpp index fae3a0e6..016c076b 100644 --- a/src/GudhUI/gui/Menu_persistence.cpp +++ b/src/GudhUI/gui/Menu_persistence.cpp @@ -1,13 +1,10 @@ -/* - * Menu_persistence.cpp - * 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 @@ -27,34 +24,30 @@ #include "Menu_persistence.h" -Menu_persistence::Menu_persistence(QMainWindow* parent_):parent(parent_) -{ - setupUi(this); - connectActions(parent_); +Menu_persistence::Menu_persistence(QMainWindow* parent_) : parent(parent_) { + setupUi(this); + connectActions(parent_); } -void Menu_persistence::connectActions(QMainWindow* parent){ - QObject::connect( - this, - SIGNAL(compute_persistence(int,double,int,double)), - parent, - SLOT(compute_persistence(int,double,int,double)) - ); +void Menu_persistence::connectActions(QMainWindow* parent) { + QObject::connect(this, + SIGNAL(compute_persistence(int, double, int, double)), + parent, + SLOT(compute_persistence(int, double, int, double))); } -void Menu_persistence::send_compute_persistence(){ - emit(compute_persistence(p_spinBox->value(),threshold_doubleSpinBox->value(), - maxdimension_spinBox->value(),minpersistence_doubleSpinBox->value())); +void Menu_persistence::send_compute_persistence() { + emit(compute_persistence(p_spinBox->value(), threshold_doubleSpinBox->value(), + maxdimension_spinBox->value(), minpersistence_doubleSpinBox->value())); } -void Menu_persistence::accept(){ - send_compute_persistence(); +void Menu_persistence::accept() { + send_compute_persistence(); } -//void Menu_persistence::compute_persistence(int p_fied,double threshold,int dim_max,double min_persistence){ -//// if(checkBoxAutoUpdate->isChecked()) -//// emit(compute_k_nearest_neighbors((unsigned)spinBoxK->value())); -//} - +// void Menu_persistence::compute_persistence(int p_fied,double threshold,int dim_max,double min_persistence) { +// if(checkBoxAutoUpdate->isChecked()) +// emit(compute_k_nearest_neighbors((unsigned)spinBoxK->value())); +// } #include "Menu_persistence.moc" diff --git a/src/GudhUI/gui/Menu_persistence.h b/src/GudhUI/gui/Menu_persistence.h index 67b64afa..8c4df158 100644 --- a/src/GudhUI/gui/Menu_persistence.h +++ b/src/GudhUI/gui/Menu_persistence.h @@ -1,13 +1,10 @@ -/* - * Menu_persistence.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,36 +21,31 @@ * */ - -#ifndef MENU_PERSISTENCE_H_ -#define MENU_PERSISTENCE_H_ - +#ifndef GUI_MENU_PERSISTENCE_H_ +#define GUI_MENU_PERSISTENCE_H_ #include #include "gui/ui_PersistenceMenu.h" class QWidget; +class Menu_persistence : public QDialog, public Ui::PersistenceMenu { + Q_OBJECT -class Menu_persistence : public QDialog,public Ui::PersistenceMenu{ - Q_OBJECT -private: - QMainWindow* parent; - -public: + private: + QMainWindow* parent; - Menu_persistence(QMainWindow* parent_); + public: + Menu_persistence(QMainWindow* parent_); - void connectActions(QMainWindow* parent); + void connectActions(QMainWindow* parent); - public slots: - void send_compute_persistence(); - void accept(); - signals: - void compute_persistence(int p_fied,double threshold,int dim_max,double min_persistence); + public slots: + void send_compute_persistence(); + void accept(); + signals: + void compute_persistence(int p_fied, double threshold, int dim_max, double min_persistence); }; - - -#endif /* MENU_PERSISTENCE_H_ */ +#endif // GUI_MENU_PERSISTENCE_H_ diff --git a/src/GudhUI/gui/Menu_uniform_neighbors.cpp b/src/GudhUI/gui/Menu_uniform_neighbors.cpp index 86e2593e..20e4f98f 100644 --- a/src/GudhUI/gui/Menu_uniform_neighbors.cpp +++ b/src/GudhUI/gui/Menu_uniform_neighbors.cpp @@ -1,59 +1,60 @@ -/* - * Menu_uniform_neighbors.cpp +/* This file is part of the Gudhi Library. The Gudhi library + * (Geometric Understanding in Higher Dimensions) is a generic C++ + * library for computational topology. * - * Created on: Sep 11, 2014 - * Author: dsalinas + * Author(s): David Salinas + * + * 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 + * 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 . + * */ - - - - #include "Menu_uniform_neighbors.h" -Menu_uniform_neighbors::Menu_uniform_neighbors(QMainWindow* parent_): -parent(parent_) -{ - setupUi(this); - connectActions(parent_); +Menu_uniform_neighbors::Menu_uniform_neighbors(QMainWindow* parent_) : + parent(parent_) { + setupUi(this); + connectActions(parent_); } -void Menu_uniform_neighbors::connectActions(QMainWindow* parent){ - - QObject::connect( - this->pushButtonCompute, - SIGNAL(clicked()), - this, - SLOT(send_compute_uniform_neighbors()) - ); - QObject::connect( - this->doubleSpinBoxAlpha, - SIGNAL(valueChanged(double)), - this, - SLOT(update_alpha(double)) - ); - QObject::connect( - this, - SIGNAL(compute_uniform_neighbors(double)), - parent, - SLOT(build_rips(double)) - ); - +void Menu_uniform_neighbors::connectActions(QMainWindow* parent) { + QObject::connect(this->pushButtonCompute, + SIGNAL(clicked()), + this, + SLOT(send_compute_uniform_neighbors())); + QObject::connect(this->doubleSpinBoxAlpha, + SIGNAL(valueChanged(double)), + this, + SLOT(update_alpha(double))); + QObject::connect(this, + SIGNAL(compute_uniform_neighbors(double)), + parent, + SLOT(build_rips(double))); } -void Menu_uniform_neighbors::send_compute_uniform_neighbors(){ - emit(compute_uniform_neighbors(doubleSpinBoxAlpha->value())); +void Menu_uniform_neighbors::send_compute_uniform_neighbors() { + emit(compute_uniform_neighbors(doubleSpinBoxAlpha->value())); } -void Menu_uniform_neighbors::accept(){ - send_compute_uniform_neighbors(); +void Menu_uniform_neighbors::accept() { + send_compute_uniform_neighbors(); } -void Menu_uniform_neighbors::update_alpha(double alpha){ - if(checkBoxAutoUpdate->isChecked()) - emit(compute_uniform_neighbors(doubleSpinBoxAlpha->value())); +void Menu_uniform_neighbors::update_alpha(double alpha) { + if (checkBoxAutoUpdate->isChecked()) + emit(compute_uniform_neighbors(doubleSpinBoxAlpha->value())); } - - #include "Menu_uniform_neighbors.moc" diff --git a/src/GudhUI/gui/Menu_uniform_neighbors.h b/src/GudhUI/gui/Menu_uniform_neighbors.h index cb90cc88..0b6f65fe 100644 --- a/src/GudhUI/gui/Menu_uniform_neighbors.h +++ b/src/GudhUI/gui/Menu_uniform_neighbors.h @@ -1,36 +1,51 @@ -/* - * Menu_uniform_neighbors.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. * - * Created on: Sep 11, 2014 - * Author: dsalinas + * Author(s): David Salinas + * + * 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 + * 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 . + * */ -#ifndef MENU_UNIFORM_NEIGHBORS_H_ -#define MENU_UNIFORM_NEIGHBORS_H_ +#ifndef GUI_MENU_UNIFORM_NEIGHBORS_H_ +#define GUI_MENU_UNIFORM_NEIGHBORS_H_ #include #include "gui/ui_UniformNeighborsMenu.h" -class Menu_uniform_neighbors : public QDialog,public Ui::UniformMenu { - Q_OBJECT -private: - QMainWindow* parent; - -public: +class Menu_uniform_neighbors : public QDialog, public Ui::UniformMenu { + Q_OBJECT - Menu_uniform_neighbors(QMainWindow* parent_); + private: + QMainWindow* parent; - void connectActions(QMainWindow* parent); + public: + Menu_uniform_neighbors(QMainWindow* parent_); - public slots: - void send_compute_uniform_neighbors(); - void update_alpha(double); - void accept(); + void connectActions(QMainWindow* parent); - signals: - void compute_uniform_neighbors(double alpha); + public slots: + void send_compute_uniform_neighbors(); + void update_alpha(double alpha); + void accept(); + signals: + void compute_uniform_neighbors(double alpha); }; -#endif /* MENU_UNIFORM_NEIGHBORS_H_ */ +#endif // GUI_MENU_UNIFORM_NEIGHBORS_H_ diff --git a/src/GudhUI/gui/Viewer.cpp b/src/GudhUI/gui/Viewer.cpp deleted file mode 100644 index e69de29b..00000000 diff --git a/src/GudhUI/gui/Viewer_instructor.cpp b/src/GudhUI/gui/Viewer_instructor.cpp deleted file mode 100644 index e69de29b..00000000 diff --git a/src/GudhUI/gui/gudhui.cpp b/src/GudhUI/gui/gudhui.cpp index 8d90270f..377cd2f2 100644 --- a/src/GudhUI/gui/gudhui.cpp +++ b/src/GudhUI/gui/gudhui.cpp @@ -1,15 +1,36 @@ +/* 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-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 + * 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 . + * + */ + #include "MainWindow.h" #include #include +int main(int argc, char** argv) { + QApplication application(argc, argv); + application.setOrganizationDomain("inria.fr"); + application.setOrganizationName("INRIA"); + application.setApplicationName("GudhUI"); -int main(int argc, char** argv) -{ - QApplication application(argc,argv); - application.setOrganizationDomain("inria.fr"); - application.setOrganizationName("INRIA"); - application.setApplicationName("GudhUI"); - MainWindow mw; application.setQuitOnLastWindowClosed(false); mw.show(); diff --git a/src/GudhUI/model/Complex_typedefs.h b/src/GudhUI/model/Complex_typedefs.h index b6404d62..c310d4a6 100644 --- a/src/GudhUI/model/Complex_typedefs.h +++ b/src/GudhUI/model/Complex_typedefs.h @@ -1,39 +1,49 @@ -/* - * Complex_typedefs.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. * - * Created on: Aug 26, 2014 - * Author: dsalinas + * Author(s): David Salinas + * + * 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 + * 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 . + * */ -#ifndef COMPLEX_TYPEDEFS_H_ -#define COMPLEX_TYPEDEFS_H_ - +#ifndef MODEL_COMPLEX_TYPEDEFS_H_ +#define MODEL_COMPLEX_TYPEDEFS_H_ - -#include "gudhi/Skeleton_blocker/Skeleton_blocker_simple_geometric_traits.h" -#include "gudhi/Skeleton_blocker_geometric_complex.h" +#include +#include #include - #include #include - struct Geometry_trait : public CGAL::Cartesian_d { - typedef CGAL::Cartesian::Point_3 Point_3; - typedef CGAL::Cartesian::Vector_3 Vector_3; - typedef CGAL::Point_d> Point; - typedef CGAL::Vector_d> Vector; + typedef CGAL::Cartesian::Point_3 Point_3; + typedef CGAL::Cartesian::Vector_3 Vector_3; + typedef CGAL::Point_d> Point; + typedef CGAL::Vector_d> Vector; }; typedef Geometry_trait::Point Point; - using namespace Gudhi; using namespace Gudhi::skbl; typedef Skeleton_blocker_simple_geometric_traits Complex_geometric_traits; typedef Skeleton_blocker_geometric_complex< Complex_geometric_traits > Complex; - -#endif /* COMPLEX_TYPEDEFS_H_ */ +#endif // MODEL_COMPLEX_TYPEDEFS_H_ diff --git a/src/GudhUI/model/Model.h b/src/GudhUI/model/Model.h index 17a7d278..d78cbad9 100644 --- a/src/GudhUI/model/Model.h +++ b/src/GudhUI/model/Model.h @@ -1,16 +1,41 @@ -/* - * Model.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. * - * Created on: Aug 25, 2014 - * Author: david + * Author(s): David Salinas + * + * 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 + * 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 . + * */ -#ifndef MODEL_H_ -#define MODEL_H_ +#ifndef MODEL_MODEL_H_ +#define MODEL_MODEL_H_ + +#include +#include +#include +#include + +#include #include #include -#include "gudhi/Clock.h" +#include +#include + #include "utils/UI_utils.h" #include "utils/Lloyd_builder.h" #include "utils/Rips_builder.h" @@ -22,328 +47,309 @@ #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" - -#include "gudhi/Off_reader.h" - #include "Complex_typedefs.h" - -#include - - template -class CGAL_geometric_flag_complex_wrapper{ - Complex& complex_; - typedef typename Complex::Vertex_handle Vertex_handle; - typedef typename Complex::Point Point; - - const bool load_only_points_; - -public: - CGAL_geometric_flag_complex_wrapper(Complex& complex,bool load_only_points = false): - complex_(complex), - load_only_points_(load_only_points){ - } - - void init(int dim,int num_vertices,int num_max_faces,int num_edges) const{ - } - - void point(const std::vector& coords){ - Point p(coords.size(),coords.begin(),coords.end()); - complex_.add_vertex(p); - } - - void maximal_face(std::vector vertices){ - if (!load_only_points_){ - std::cout<<"size:"<& coords) { + Point p(coords.size(), coords.begin(), coords.end()); + complex_.add_vertex(p); + } + + void maximal_face(std::vector vertices) { + if (!load_only_points_) { + 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])); + } + } + + void done() const { } }; - -class Model{ - -public: - Complex complex_; - typedef Complex::Vertex_handle Vertex_handle; - - Model():complex_(){ - } - -public: - void off_file_open(const std::string& name_file){ - UIDBGMSG("load off file",name_file); - complex_.clear(); - CGAL_geometric_flag_complex_wrapper 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 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< new_point(point.dimension()); - for(int i = 0 ; i < point.dimension();++i){ - new_point[i] = point[i] + (rand() % 2 - .5) * amplitude; - } - return Point(point.dimension(), new_point.begin(),new_point.end()); - } - -public: - - void lloyd(int num_iterations,int num_closest_neighbors){ - UIDBG("lloyd"); - Lloyd_builder lloyd_builder(complex_,1); - } - - double squared_eucl_distance(const Point& p1,const Point& p2) const{ - return Geometry_trait::Squared_distance_d()(p1,p2); - } - - // complex operations from points - void build_rips(double alpha){ - UIDBG("build_rips"); - Rips_builder rips_builder(complex_,alpha); - } - - void build_k_nearest_neighbors(unsigned k){ - UIDBG("build_k_nearest"); - complex_.keep_only_vertices(); - K_nearest_builder k_nearest_builder(complex_,k); - } - - void build_delaunay(){ - UIDBG("build_delaunay"); - complex_.keep_only_vertices(); - } - - - - void contract_edges(unsigned num_contractions){ - Clock c; - Edge_contractor contractor(complex_,num_contractions); - std::cout<<"Time to simplify: "< collapsor(complex_,complex_.num_vertices()); - UIDBGMSG("num vertices collapsed:",old_num_vertices - complex_.num_vertices()); - } - - void collapse_edges(unsigned num_collapses){ - Edge_collapsor collapsor(complex_,num_collapses); - } - - - void show_graph_stats(){ - std::cout << "++++++ Graph stats +++++++"<< std::endl; - std::cout << "Num vertices : " << complex_.num_vertices()<::max)(); - for(auto v : complex_.vertex_range()) - res= (std::min)(res,complex_.degree(v)); - return res; - } - - int max_degree() const{ - int res = 0; - for(auto v : complex_.vertex_range()) - res= (std::max)(res,complex_.degree(v)); - return res; - } - - int avg_degree() const{ - int res = 0; - for(auto v : complex_.vertex_range()) - res+= complex_.degree(v); - return res / complex_.num_vertices(); - } - -public: - - - - void show_complex_stats(){ - std::cout << "++++++ Mesh stats +++++++"<< std::endl; - std::cout << "Num vertices : " << complex_.num_vertices()< 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 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 + void uniform_noise(double amplitude) { + UIDBG("unif noise"); + for (auto v : complex_.vertex_range()) + complex_.point(v) = add_uniform_noise(complex_.point(v), amplitude); + } + + private: + Point add_uniform_noise(const Point& point, double amplitude) { + std::vector new_point(point.dimension()); + for (int i = 0; i < point.dimension(); ++i) { + new_point[i] = point[i] + (rand() % 2 - .5) * amplitude; + } + return Point(point.dimension(), new_point.begin(), new_point.end()); + } + + public: + void lloyd(int num_iterations, int num_closest_neighbors) { + UIDBG("lloyd"); + Lloyd_builder lloyd_builder(complex_, 1); + } + + double squared_eucl_distance(const Point& p1, const Point& p2) const { + return Geometry_trait::Squared_distance_d()(p1, p2); + } + + // complex operations from points + + void build_rips(double alpha) { + UIDBG("build_rips"); + Rips_builder rips_builder(complex_, alpha); + } + + void build_k_nearest_neighbors(unsigned k) { + UIDBG("build_k_nearest"); + complex_.keep_only_vertices(); + K_nearest_builder k_nearest_builder(complex_, k); + } + + void build_delaunay() { + UIDBG("build_delaunay"); + complex_.keep_only_vertices(); + } + + void contract_edges(unsigned num_contractions) { + Clock c; + Edge_contractor contractor(complex_, num_contractions); + std::cout << "Time to simplify: " << c.num_seconds() << "s" << std::endl; + } + + void collapse_vertices(unsigned num_collapses) { + auto old_num_vertices = complex_.num_vertices(); + Vertex_collapsor collapsor(complex_, complex_.num_vertices()); + UIDBGMSG("num vertices collapsed:", old_num_vertices - complex_.num_vertices()); + } + + void collapse_edges(unsigned num_collapses) { + Edge_collapsor collapsor(complex_, num_collapses); + } + + void show_graph_stats() { + std::cout << "++++++ Graph stats +++++++" << std::endl; + std::cout << "Num vertices : " << complex_.num_vertices() << std::endl; + std::cout << "Num edges : " << complex_.num_edges() << std::endl; + std::cout << "Num connected components : " << complex_.num_connected_components() << std::endl; + std::cout << "Min/avg/max degree : " << min_degree() << "/" << avg_degree() << "/" << max_degree() << std::endl; + std::cout << "Num connected components : " << complex_.num_connected_components() << std::endl; + std::cout << "Num connected components : " << complex_.num_connected_components() << std::endl; + std::cout << "+++++++++++++++++++++++++" << std::endl; + } + + private: + int min_degree() const { + int res = (std::numeric_limits::max)(); + for (auto v : complex_.vertex_range()) + res = (std::min)(res, complex_.degree(v)); + return res; + } + + int max_degree() const { + int res = 0; + for (auto v : complex_.vertex_range()) + res = (std::max)(res, complex_.degree(v)); + return res; + } + + int avg_degree() const { + int res = 0; + for (auto v : complex_.vertex_range()) + res += complex_.degree(v); + return res / complex_.num_vertices(); + } + + public: + void show_complex_stats() { + std::cout << "++++++ Mesh stats +++++++" << std::endl; + std::cout << "Num vertices : " << complex_.num_vertices() << std::endl; + std::cout << "Num edges : " << complex_.num_edges() << std::endl; + std::cout << "Num connected components : " << complex_.num_connected_components() << std::endl; + std::cout << "+++++++++++++++++++++++++" << std::endl; + } + + void show_complex_dimension() { + unsigned num_simplices = 0; + int euler = 0; + int dimension = 0; + Clock clock; + for (const auto &s : complex_.simplex_range()) { + num_simplices++; + dimension = (std::max)(s.dimension(), dimension); + if (s.dimension() % 2 == 0) + euler += 1; + else + euler -= 1; + } + clock.end(); + std::cout << "++++++ Mesh dimension +++++++" << std::endl; + std::cout << "Dimension : " << dimension << std::endl; + std::cout << "Euler characteristic : " << euler << std::endl; + std::cout << "Num simplices : " << num_simplices << std::endl; + std::cout << "Total time: " << clock << std::endl; + std::cout << "Time per simplex: " << clock.num_seconds() / num_simplices << " s" << std::endl; + std::cout << "+++++++++++++++++++++++++" << std::endl; + } + + void show_homology_group() { #ifdef _WIN32 - std::cout << "Works only on linux x64 for the moment\n"; + std::cout << "Works only on linux x64 for the moment\n"; #else - Clock clock; - run_chomp(); - clock.end(); + Clock clock; + run_chomp(); + clock.end(); #endif - } - - void show_euler_characteristic(){ - unsigned num_simplices = 0; - int euler = 0; - int dimension = 0; - for(const auto &s : complex_.simplex_range()){ - num_simplices++; - dimension = (std::max)(s.dimension(),dimension); - if(s.dimension()%2==0) - euler+=1; - else - euler-=1; - } - std::cout << "Saw "< persistence(complex_,std::cout,Persistence_params(p,threshold,max_dim,min_pers)); - } - - void show_critical_points(double max_distance){ - Critical_points critical_points(complex_,std::cout,max_distance); - } - - void show_is_manifold(){ - unsigned dim; - bool is_manifold; - Is_manifold test_manifold(complex_,dim,is_manifold); - - if(is_manifold) std::cout << "The complex is a "<=4 and may or may not be a manifold\n"; - } - - -private: - void run_chomp(){ - save_complex_in_file_for_chomp(); - std::cout << "Call CHOMP library\n"; - int returnValue = system("utils/homsimpl chomp.sim"); - std::cout << "CHOMP returns" << returnValue << std::endl; - } - - void save_complex_in_file_for_chomp(){ - std::ofstream file; - file.open("chomp.sim"); - for(const auto &s : complex_.simplex_range()){ - bool first = true; - file<<"("; - for(auto x : s){ - if(first) first = false; - else file<<","; - file << x; - } - file<<")\n"; - } - } -public: - - - unsigned num_vertices() const{ - return complex_.num_vertices(); - } - - unsigned num_edges() const{ - return complex_.num_edges(); - } - + } + + void show_euler_characteristic() { + unsigned num_simplices = 0; + int euler = 0; + int dimension = 0; + for (const auto &s : complex_.simplex_range()) { + num_simplices++; + dimension = (std::max)(s.dimension(), dimension); + if (s.dimension() % 2 == 0) + euler += 1; + else + euler -= 1; + } + std::cout << "Saw " << num_simplices << " simplices with maximum dimension " << dimension << std::endl; + std::cout << "The euler characteristic is : " << euler << std::endl; + } + + void show_persistence(int p, double threshold, int max_dim, double min_pers) { + Persistence_compute persistence(complex_, std::cout, Persistence_params(p, threshold, max_dim, min_pers)); + } + + void show_critical_points(double max_distance) { + Critical_points critical_points(complex_, std::cout, max_distance); + } + + void show_is_manifold() { + unsigned dim; + bool is_manifold; + Is_manifold 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() { + save_complex_in_file_for_chomp(); + std::cout << "Call CHOMP library\n"; + int returnValue = system("utils/homsimpl chomp.sim"); + std::cout << "CHOMP returns" << returnValue << std::endl; + } + + void save_complex_in_file_for_chomp() { + std::ofstream file; + file.open("chomp.sim"); + for (const auto &s : complex_.simplex_range()) { + bool first = true; + file << "("; + for (auto x : s) { + if (first) + first = false; + else + file << ","; + file << x; + } + file << ")\n"; + } + } + + public: + unsigned num_vertices() const { + return complex_.num_vertices(); + } + + unsigned num_edges() const { + return complex_.num_edges(); + } }; -#endif /* MODEL_H_ */ +#endif // MODEL_MODEL_H_ 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 +#include // for pair<> +#include // for sort + #include "utils/Edge_contractor.h" /** @@ -37,101 +36,97 @@ * * todo do a sparsification with some parameter eps while growing */ -template 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 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 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& edges){ - unsigned pos = 0; - for(Edge e : edges){ - std::cout<<"edge "< 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 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 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 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 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& 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 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_ diff --git a/src/GudhUI/utils/Edge_collapsor.h b/src/GudhUI/utils/Edge_collapsor.h index 4dcd18ac..fcf2a248 100644 --- a/src/GudhUI/utils/Edge_collapsor.h +++ b/src/GudhUI/utils/Edge_collapsor.h @@ -1,12 +1,28 @@ -/* - * Collapsor.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. * - * Created on: Sep 25, 2014 - * Author: dsalinas + * Author(s): David Salinas + * + * 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 + * 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 . + * */ -#ifndef COLLAPSOR_H_ -#define COLLAPSOR_H_ +#ifndef UTILS_COLLAPSOR_H_ +#define UTILS_COLLAPSOR_H_ #include #include "utils/Edge_contractor.h" @@ -15,71 +31,67 @@ /** * Iteratively puts every vertex at the center of its neighbors */ -template class Edge_collapsor{ -private: - SkBlComplex& complex_; - unsigned num_collapses_; -public: - typedef typename SkBlComplex::Vertex_handle Vertex_handle; - typedef typename SkBlComplex::Edge_handle Edge_handle; - - /** - * @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) - { - std::list edges; - edges.insert(edges.begin(),complex_.edge_range().begin(),complex_.edge_range().end()); - - edges.sort( - [&](Edge_handle e1,Edge_handle e2){ - return squared_edge_length(e1) < squared_edge_length(e2); - }); - - collapse_edges(edges); - - } - -private: - - void collapse_edges(std::list& edges){ - while(!edges.empty() && num_collapses_--){ - Edge_handle current_edge = edges.front(); - edges.pop_front(); - if(is_link_reducible(current_edge)) - complex_.remove_edge(current_edge); - } - - } - - bool is_link_reducible(Edge_handle e){ - auto link = complex_.link(e); - - if(link.empty()) return false; - - if(link.is_cone()) return true; - - if(link.num_connected_components()>1) return false; - - Edge_contractor contractor(link,link.num_vertices()-1); - - return (link.num_vertices()==1); - } - - - double squared_edge_length(Edge_handle e) const{ - return squared_eucl_distance(complex_.point(complex_.first_vertex(e)),complex_.point(complex_.second_vertex(e))); - } - - double squared_eucl_distance(const Point& p1,const Point& p2) const{ - return Geometry_trait::Squared_distance_d()(p1,p2); - } - +template class Edge_collapsor { + private: + SkBlComplex& complex_; + unsigned num_collapses_; + + public: + typedef typename SkBlComplex::Vertex_handle Vertex_handle; + typedef typename SkBlComplex::Edge_handle Edge_handle; + + /** + * @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) { + std::list edges; + edges.insert(edges.begin(), complex_.edge_range().begin(), complex_.edge_range().end()); + + edges.sort( + [&](Edge_handle e1, Edge_handle e2) { + return squared_edge_length(e1) < squared_edge_length(e2); + }); + + collapse_edges(edges); + } + + private: + void collapse_edges(std::list& edges) { + while (!edges.empty() && num_collapses_--) { + Edge_handle current_edge = edges.front(); + edges.pop_front(); + if (is_link_reducible(current_edge)) + complex_.remove_edge(current_edge); + } + } + + bool is_link_reducible(Edge_handle e) { + auto link = complex_.link(e); + + if (link.empty()) + return false; + + if (link.is_cone()) + return true; + + if (link.num_connected_components() > 1) + return false; + + Edge_contractor contractor(link, link.num_vertices() - 1); + + return (link.num_vertices() == 1); + } + + double squared_edge_length(Edge_handle e) const { + return squared_eucl_distance(complex_.point(complex_.first_vertex(e)), complex_.point(complex_.second_vertex(e))); + } + + double squared_eucl_distance(const Point& p1, const Point& p2) const { + return Geometry_trait::Squared_distance_d()(p1, p2); + } }; - - -#endif /* COLLAPSOR_H_ */ +#endif // UTILS_COLLAPSOR_H_ diff --git a/src/GudhUI/utils/Edge_contractor.h b/src/GudhUI/utils/Edge_contractor.h index d0a1f866..053aac04 100644 --- a/src/GudhUI/utils/Edge_contractor.h +++ b/src/GudhUI/utils/Edge_contractor.h @@ -1,85 +1,97 @@ -/* - * Contractor.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. * - * Created on: Sep 25, 2014 - * Author: dsalinas + * Author(s): David Salinas + * + * 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 + * 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 . + * */ -#ifndef EDGE_CONTRACTOR_H_ -#define EDGE_CONTRACTOR_H_ +#ifndef UTILS_EDGE_CONTRACTOR_H_ +#define UTILS_EDGE_CONTRACTOR_H_ -#include "gudhi/Skeleton_blocker_contractor.h" - -#include "gudhi/Contraction/Edge_profile.h" -#include "gudhi/Contraction/policies/Cost_policy.h" +#include +#include +#include +#include /** * Iteratively puts every vertex at the center of its neighbors */ -template class Edge_contractor{ -private: - SkBlComplex& complex_; - unsigned num_contractions_; - - /** - * @brief return a cost corresponding to the squared length of the edge - */ - template< typename EdgeProfile> class Length_cost : public contraction::Cost_policy{ - public: - typedef typename contraction::Cost_policy::Cost_type Cost_type; - typedef typename EdgeProfile::Point Point; - Cost_type operator()(const EdgeProfile& profile, const boost::optional& placement) const override{ - Cost_type res; - if(!placement) return res; - return Geometry_trait::Squared_distance_d()(profile.p0(),profile.p1()); //not working?? - } - }; - - - /** - * @brief return a cost corresponding to the squared length of the edge - */ - template< typename EdgeProfile> class Middle_placement : public contraction::Placement_policy{ - public: - typedef typename contraction::Placement_policy::Placement_type Placement_type; - typedef typename EdgeProfile::Point Point; - Placement_type operator()(const EdgeProfile& profile) const override{ - std::vector mid_coords(profile.p0().dimension(),0); - for (size_t 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()); - } - }; - - public: - typedef typename SkBlComplex::Vertex_handle Vertex_handle; - typedef typename SkBlComplex::Edge_handle Edge_handle; - - /** - * @brief Modify complex to be the expansion of the k-nearest neighbor - * symetric graph. - */ - Edge_contractor(SkBlComplex& complex,unsigned num_contractions): - complex_(complex),num_contractions_(num_contractions) - { - typedef typename contraction::Edge_profile Profile; - num_contractions = (std::min)((int)num_contractions,(int)(complex_.num_vertices()-1)); - contraction::Skeleton_blocker_contractor contractor( - complex_, - new Length_cost>(), - new Middle_placement>(), - contraction::make_link_valid_contraction(), - contraction::make_remove_popable_blockers_visitor() - ); - contractor.contract_edges(num_contractions); - } - - +template class Edge_contractor { + private: + SkBlComplex& complex_; + unsigned num_contractions_; + + /** + * @brief return a cost corresponding to the squared length of the edge + */ + template< typename EdgeProfile> class Length_cost : public contraction::Cost_policy { + public: + typedef typename contraction::Cost_policy::Cost_type Cost_type; + typedef typename EdgeProfile::Point Point; + + Cost_type operator()(const EdgeProfile& profile, const boost::optional& placement) const override { + Cost_type res; + if (!placement) + return res; + return Geometry_trait::Squared_distance_d()(profile.p0(), profile.p1()); // not working?? + } + }; + + /** + * @brief return a cost corresponding to the squared length of the edge + */ + template< typename EdgeProfile> class Middle_placement : public contraction::Placement_policy { + public: + typedef typename contraction::Placement_policy::Placement_type Placement_type; + typedef typename EdgeProfile::Point Point; + + Placement_type operator()(const EdgeProfile& profile) const override { + std::vector mid_coords(profile.p0().dimension(), 0); + for (size_t 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()); + } + }; + + public: + typedef typename SkBlComplex::Vertex_handle Vertex_handle; + typedef typename SkBlComplex::Edge_handle Edge_handle; + + /** + * @brief Modify complex to be the expansion of the k-nearest neighbor + * symetric graph. + */ + Edge_contractor(SkBlComplex& complex, unsigned num_contractions) : + complex_(complex), num_contractions_(num_contractions) { + typedef typename contraction::Edge_profile Profile; + num_contractions = (std::min)(static_cast(num_contractions), static_cast(complex_.num_vertices() - 1)); + typedef typename contraction::Skeleton_blocker_contractor Contractor; + Contractor contractor(complex_, + new Length_cost> (), + new Middle_placement> (), + contraction::make_link_valid_contraction(), + contraction::make_remove_popable_blockers_visitor()); + contractor.contract_edges(num_contractions); + } }; - - #endif /* EDGE_CONTRACTOR_H_ */ diff --git a/src/GudhUI/utils/Furthest_point_epsilon_net.h b/src/GudhUI/utils/Furthest_point_epsilon_net.h index 590b65c4..f2a216f6 100644 --- a/src/GudhUI/utils/Furthest_point_epsilon_net.h +++ b/src/GudhUI/utils/Furthest_point_epsilon_net.h @@ -1,134 +1,132 @@ -/* - * Furthest_point_epsilon_net.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. * - * Created on: Sep 26, 2014 - * Author: dsalinas + * Author(s): David Salinas + * + * 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 + * 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 . + * */ -#ifndef FURTHEST_POINT_EPSILON_NET_H_ -#define FURTHEST_POINT_EPSILON_NET_H_ +#ifndef UTILS_FURTHEST_POINT_EPSILON_NET_H_ +#define UTILS_FURTHEST_POINT_EPSILON_NET_H_ -#include "utils/UI_utils.h" #include +#include // for sort + +#include "utils/UI_utils.h" /** * Computes an epsilon net with furthest point strategy. */ -template class Furthest_point_epsilon_net{ -private: - SkBlComplex& complex_; - typedef typename SkBlComplex::Vertex_handle Vertex_handle; - typedef typename SkBlComplex::Edge_handle Edge_handle; - - /** - * Let V be the set of vertices. - * Initially v0 is one arbitrarly vertex and the set V0 is {v0}. - * Then Vk is computed as follows. - * First we compute the vertex pk that is the furthest from Vk - * then Vk = Vk \cup pk. - * The radius of pk is its distance to Vk and its meeting vertex - * is the vertex of Vk for which this distance is achieved. - */ - struct Net_filtration_vertex{ - Vertex_handle vertex_handle; - Vertex_handle meeting_vertex; - double radius; - - - Net_filtration_vertex( - Vertex_handle vertex_handle_, - Vertex_handle meeting_vertex_, - double radius_): - vertex_handle(vertex_handle_),meeting_vertex(meeting_vertex_),radius(radius_) - {} - - bool operator<(const Net_filtration_vertex& other ) const{ - return radius < other.radius; - } - - }; - -public: - - - std::vector net_filtration_; - - /** - * @brief Modify complex to be the expansion of the k-nearest neighbor - * symetric graph. - */ - Furthest_point_epsilon_net(SkBlComplex& complex): - complex_(complex) - { - if(!complex.empty()){ - init_filtration(); - for(int k = 2; k < net_filtration_.size(); ++k){ - update_radius_value(k); - } - } - } - - //xxx does not work if complex not full - double radius(Vertex_handle v){ - return net_filtration_[v.vertex].radius; - } - - - - -private: - - void init_filtration(){ - Vertex_handle v0 = *(complex_.vertex_range().begin()); - net_filtration_.reserve(complex_.num_vertices()); - for(auto v : complex_.vertex_range()){ - if(v != v0) - net_filtration_.push_back( - Net_filtration_vertex(v, - Vertex_handle(-1), - squared_eucl_distance(v,v0)) - ); - } - net_filtration_.push_back(Net_filtration_vertex(v0,Vertex_handle(-1),1e10)); - auto n = net_filtration_.size(); - sort_filtration(n-1); - } - - void update_radius_value(int k){ - int n = net_filtration_.size(); - int index_to_update = n-k; - for(int i = 0; i< index_to_update; ++i){ - net_filtration_[i].radius = (std::min)(net_filtration_[i].radius , - squared_eucl_distance( - net_filtration_[i].vertex_handle, - net_filtration_[index_to_update].vertex_handle - ) - ); - } - sort_filtration(n-k); - } - - /** - * sort all i first elements. - */ - void sort_filtration(int i){ - std::sort(net_filtration_.begin(),net_filtration_.begin()+ i); - } - - double squared_eucl_distance(Vertex_handle v1,Vertex_handle v2) const{ - return std::sqrt(Geometry_trait::Squared_distance_d()( - complex_.point(v1),complex_.point(v2)) - ); - } - - void print_filtration() const{ - for(auto v : net_filtration_){ - std::cerr <<"v="< d="< class Furthest_point_epsilon_net { + private: + SkBlComplex& complex_; + typedef typename SkBlComplex::Vertex_handle Vertex_handle; + typedef typename SkBlComplex::Edge_handle Edge_handle; + + /** + * Let V be the set of vertices. + * Initially v0 is one arbitrarly vertex and the set V0 is {v0}. + * Then Vk is computed as follows. + * First we compute the vertex pk that is the furthest from Vk + * then Vk = Vk \cup pk. + * The radius of pk is its distance to Vk and its meeting vertex + * is the vertex of Vk for which this distance is achieved. + */ + struct Net_filtration_vertex { + Vertex_handle vertex_handle; + Vertex_handle meeting_vertex; + double radius; + + Net_filtration_vertex(Vertex_handle vertex_handle_, + Vertex_handle meeting_vertex_, + double radius_) : + vertex_handle(vertex_handle_), meeting_vertex(meeting_vertex_), radius(radius_) { } + + bool operator<(const Net_filtration_vertex& other) const { + return radius < other.radius; + } + }; + + public: + std::vector net_filtration_; + + /** + * @brief Modify complex to be the expansion of the k-nearest neighbor + * symetric graph. + */ + Furthest_point_epsilon_net(SkBlComplex& complex) : + complex_(complex) { + if (!complex.empty()) { + init_filtration(); + for (int k = 2; k < net_filtration_.size(); ++k) { + update_radius_value(k); + } + } + } + + // xxx does not work if complex not full + + double radius(Vertex_handle v) { + return net_filtration_[v.vertex].radius; + } + + private: + void init_filtration() { + Vertex_handle v0 = *(complex_.vertex_range().begin()); + net_filtration_.reserve(complex_.num_vertices()); + for (auto v : complex_.vertex_range()) { + if (v != v0) + net_filtration_.push_back(Net_filtration_vertex(v, + Vertex_handle(-1), + squared_eucl_distance(v, v0))); + } + net_filtration_.push_back(Net_filtration_vertex(v0, Vertex_handle(-1), 1e10)); + auto n = net_filtration_.size(); + sort_filtration(n - 1); + } + + void update_radius_value(int k) { + int n = net_filtration_.size(); + int index_to_update = n - k; + for (int i = 0; i < index_to_update; ++i) { + net_filtration_[i].radius = (std::min)(net_filtration_[i].radius, + squared_eucl_distance(net_filtration_[i].vertex_handle, + net_filtration_[index_to_update].vertex_handle)); + } + sort_filtration(n - k); + } + + /** + * sort all i first elements. + */ + void sort_filtration(int i) { + std::sort(net_filtration_.begin(), net_filtration_.begin() + i); + } + + double squared_eucl_distance(Vertex_handle v1, Vertex_handle v2) const { + return std::sqrt(Geometry_trait::Squared_distance_d()(complex_.point(v1), complex_.point(v2))); + } + + void print_filtration() const { + for (auto v : net_filtration_) { + std::cerr << "v=" << v.vertex_handle << "-> d=" << v.radius << std::endl; + } + } }; - - -#endif /* FURTHEST_POINT_EPSILON_NET_H_ */ +#endif // UTILS_FURTHEST_POINT_EPSILON_NET_H_ diff --git a/src/GudhUI/utils/Is_manifold.h b/src/GudhUI/utils/Is_manifold.h index e708a6a4..1b25df34 100644 --- a/src/GudhUI/utils/Is_manifold.h +++ b/src/GudhUI/utils/Is_manifold.h @@ -7,7 +7,7 @@ * * 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 @@ -25,11 +25,10 @@ */ -#ifndef IS_MANIFOLD_H_ -#define IS_MANIFOLD_H_ +#ifndef UTILS_IS_MANIFOLD_H_ +#define UTILS_IS_MANIFOLD_H_ #include "utils/UI_utils.h" - #include "utils/Edge_contractor.h" /** @@ -38,67 +37,67 @@ * * todo do a sparsification with some parameter eps while growing */ -template class Is_manifold{ -private: - const SkBlComplex& input_complex_; - typedef typename SkBlComplex::Vertex_handle Vertex_handle; +template 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; + } + } + } + } -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; + } -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 contractor(link, link.num_vertices() - 1); + return (is_sphere_simplex(link) == k); + } - bool is_k_sphere(Vertex_handle v,int k){ - auto link = input_complex_.link(v); - Edge_contractor 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 - // 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 - int is_sphere_simplex(const SubComplex& complex){ - if(complex.empty()) return -1; - if(complex.num_blockers()!=1) return -2; + template + 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()); + //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); - } + if (first_blocker->dimension() + 1 != complex.num_vertices()) + return -2; + else + return (first_blocker->dimension() - 1); + } }; -#endif /* IS_MANIFOLD_H_ */ +#endif // UTILS_IS_MANIFOLD_H_ diff --git a/src/GudhUI/utils/K_nearest_builder.h b/src/GudhUI/utils/K_nearest_builder.h index b65a79e0..cab24b7c 100644 --- a/src/GudhUI/utils/K_nearest_builder.h +++ b/src/GudhUI/utils/K_nearest_builder.h @@ -1,81 +1,92 @@ -/* - * K_nearest_builder.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. * - * Created on: Sep 10, 2014 - * Author: dsalinas + * Author(s): David Salinas + * + * 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 + * 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 . + * */ -#ifndef K_NEAREST_BUILDER_H_ -#define K_NEAREST_BUILDER_H_ +#ifndef UTILS_K_NEAREST_BUILDER_H_ +#define UTILS_K_NEAREST_BUILDER_H_ -#include -#include #include #include #include #include -#include +#include +#include #include +#include +#include +#include + #include "utils/UI_utils.h" #include "model/Complex_typedefs.h" - - -template class K_nearest_builder{ -private: - - typedef Geometry_trait Kernel; - typedef Point Point_d; - typedef boost::tuple Point_d_with_id; - typedef CGAL::Search_traits_d Traits_base; - typedef CGAL::Search_traits_adapter, Traits_base> Traits; - typedef CGAL::Orthogonal_k_neighbor_search Neighbor_search; - typedef Neighbor_search::Tree Tree; - typedef Neighbor_search::Distance Distance; - - SkBlComplex& complex_; -public: - - /** - * @brief Modify complex to be the expansion of the k-nearest neighbor - * symetric graph. - */ - K_nearest_builder(SkBlComplex& complex,unsigned k):complex_(complex){ - complex.keep_only_vertices(); - compute_edges(k); - } - -private: - - - - double squared_eucl_distance(const Point& p1,const Point& p2) const{ - return Geometry_trait::Squared_distance_d()(p1,p2); - } - - void compute_edges(unsigned k){ - - std::list points_with_id; - for(auto v: complex_.vertex_range()){ - Point_d_with_id point_v(complex_.point(v),v.vertex); - points_with_id.push_back(point_v); - } - - Tree tree(points_with_id.begin(),points_with_id.end()); - - typedef typename SkBlComplex::Vertex_handle Vertex_handle; - 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)); - if (p != q && complex_.contains_vertex(p) && complex_.contains_vertex(q)) - complex_.add_edge(p,q); - } - } - } - - +template class K_nearest_builder { + private: + typedef Geometry_trait Kernel; + typedef Point Point_d; + typedef boost::tuple Point_d_with_id; + typedef CGAL::Search_traits_d Traits_base; + typedef CGAL::Search_traits_adapter, + Traits_base> Traits; + typedef CGAL::Orthogonal_k_neighbor_search Neighbor_search; + typedef Neighbor_search::Tree Tree; + typedef Neighbor_search::Distance Distance; + + SkBlComplex& complex_; + + public: + /** + * @brief Modify complex to be the expansion of the k-nearest neighbor + * symetric graph. + */ + K_nearest_builder(SkBlComplex& complex, unsigned k) : complex_(complex) { + complex.keep_only_vertices(); + compute_edges(k); + } + + private: + double squared_eucl_distance(const Point& p1, const Point& p2) const { + return Geometry_trait::Squared_distance_d()(p1, p2); + } + + void compute_edges(unsigned k) { + std::list points_with_id; + for (auto v : complex_.vertex_range()) { + Point_d_with_id point_v(complex_.point(v), v.vertex); + points_with_id.push_back(point_v); + } + + Tree tree(points_with_id.begin(), points_with_id.end()); + + typedef typename SkBlComplex::Vertex_handle Vertex_handle; + 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)); + if (p != q && complex_.contains_vertex(p) && complex_.contains_vertex(q)) + complex_.add_edge(p, q); + } + } + } }; -#endif /* K_NEAREST_BUILDER_H_ */ +#endif // UTILS_K_NEAREST_BUILDER_H_ diff --git a/src/GudhUI/utils/Lloyd_builder.h b/src/GudhUI/utils/Lloyd_builder.h index db2a7973..18ec9fac 100644 --- a/src/GudhUI/utils/Lloyd_builder.h +++ b/src/GudhUI/utils/Lloyd_builder.h @@ -1,78 +1,91 @@ -/* - * Lloyd.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. * - * Created on: Sep 25, 2014 - * Author: dsalinas + * Author(s): David Salinas + * + * 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 + * 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 . + * */ -#ifndef LLOYD_H_ -#define LLOYD_H_ - +#ifndef UTILS_LLOYD_BUILDER_H_ +#define UTILS_LLOYD_BUILDER_H_ #include +#include /** * Iteratively puts every vertex at the center of its neighbors */ -template class Lloyd_builder{ -private: - SkBlComplex& complex_; - int dim; -public: - typedef typename SkBlComplex::Vertex_handle Vertex_handle; - /** - * @brief Modify complex to be the expansion of the k-nearest neighbor - * symetric graph. - */ - Lloyd_builder(SkBlComplex& complex,unsigned num_iterations):complex_(complex),dim(-1){ - if(!complex_.empty()){ - dim = get_dimension(); - while(num_iterations--){ - std::list new_points; - for(auto v : complex.vertex_range()) - new_points.push_back(barycenter_neighbors(v)); - - auto new_points_it = new_points.begin(); - for(auto v : complex.vertex_range()) - complex_.point(v) = *(new_points_it++); - } - } - } +template class Lloyd_builder { + private: + SkBlComplex& complex_; + int dim; -private: + public: + typedef typename SkBlComplex::Vertex_handle Vertex_handle; - int get_dimension(){ - assert(!complex_.empty()); - for(auto v : complex_.vertex_range()) - return complex_.point(v).dimension(); - return -1; - } + /** + * @brief Modify complex to be the expansion of the k-nearest neighbor + * symetric graph. + */ + Lloyd_builder(SkBlComplex& complex, unsigned num_iterations) : complex_(complex), dim(-1) { + if (!complex_.empty()) { + dim = get_dimension(); + while (num_iterations--) { + std::list new_points; + for (auto v : complex.vertex_range()) + new_points.push_back(barycenter_neighbors(v)); - Point barycenter_neighbors(Vertex_handle v) const{ - if(complex_.degree(v)==0) - return complex_.point(v); + auto new_points_it = new_points.begin(); + for (auto v : complex.vertex_range()) + complex_.point(v) = *(new_points_it++); + } + } + } - std::vector res(dim,0); - unsigned num_points = 0; - for(auto nv : complex_.vertex_range(v)){ - ++num_points; - const Point& point = complex_.point(nv); - assert(point.dimension() == dim); - for(int i = 0; i < point.dimension() ; ++i) - res[i] += point[i]; - } - for(auto& x : res) - x/= num_points; - return Point(dim,res.begin(),res.end()); - } + private: + int get_dimension() { + assert(!complex_.empty()); + for (auto v : complex_.vertex_range()) + return complex_.point(v).dimension(); + return -1; + } + Point barycenter_neighbors(Vertex_handle v) const { + if (complex_.degree(v) == 0) + return complex_.point(v); + std::vector res(dim, 0); + unsigned num_points = 0; + for (auto nv : complex_.vertex_range(v)) { + ++num_points; + const Point& point = complex_.point(nv); + assert(point.dimension() == dim); + for (int i = 0; i < point.dimension(); ++i) + res[i] += point[i]; + } + for (auto& x : res) + x /= num_points; + return Point(dim, res.begin(), res.end()); + } - double squared_eucl_distance(const Point& p1,const Point& p2) const{ - return Geometry_trait::Squared_distance_d()(p1,p2); - } - + double squared_eucl_distance(const Point& p1, const Point& p2) const { + return Geometry_trait::Squared_distance_d()(p1, p2); + } }; - -#endif /* LLOYD_H_ */ +#endif // UTILS_LLOYD_BUILDER_H_ diff --git a/src/GudhUI/utils/MClock.h b/src/GudhUI/utils/MClock.h index b5c7d191..e8d8918a 100644 --- a/src/GudhUI/utils/MClock.h +++ b/src/GudhUI/utils/MClock.h @@ -1,57 +1,70 @@ -/* - * Clock.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. * - * Created on: Jun 17, 2014 - * Author: dsalinas + * Author(s): David Salinas + * + * 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 + * 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 . + * */ -#ifndef CLOCK_H_ -#define CLOCK_H_ +#ifndef UTILS_MCLOCK_H_ +#define UTILS_MCLOCK_H_ #include +class MClock { + public: + MClock() { + end_called = false; + begin(); + } -class MClock{ - -public: - MClock(){ - end_called = false; - begin(); - } - - void begin() const{ - end_called = false; - gettimeofday(&startTime, NULL); - } - - void end() const{ - end_called = true; - gettimeofday(&endTime, NULL); - } - - friend std::ostream& operator<< (std::ostream& stream,const MClock& clock){ - // if(!clock.end_called) clock.end(); - if(!clock.end_called) stream << "end not called"; - else{ - long totalTime = (clock.endTime.tv_sec - clock.startTime.tv_sec) * 1000000L; - totalTime += (clock.endTime.tv_usec - clock.startTime.tv_usec); - stream << clock.num_seconds() <<"s"; - } - return stream; - - } - - double num_seconds() const{ - if(!end_called) end(); - long totalTime = (endTime.tv_sec - startTime.tv_sec) * 1000000L; - totalTime += (endTime.tv_usec - startTime.tv_usec); - return (totalTime / 1000L)/(double) 1000; - } - -private: - mutable struct timeval startTime, endTime; - mutable bool end_called; -}; + void begin() const { + end_called = false; + gettimeofday(&startTime, NULL); + } + void end() const { + end_called = true; + gettimeofday(&endTime, NULL); + } + + friend std::ostream& operator<<(std::ostream& stream, const MClock& clock) { + // if(!clock.end_called) clock.end(); + if (!clock.end_called) { + stream << "end not called"; + } else { + long totalTime = (clock.endTime.tv_sec - clock.startTime.tv_sec) * 1000000L; + totalTime += (clock.endTime.tv_usec - clock.startTime.tv_usec); + stream << clock.num_seconds() << "s"; + } + return stream; + } + + double num_seconds() const { + if (!end_called) end(); + long totalTime = (endTime.tv_sec - startTime.tv_sec) * 1000000L; + totalTime += (endTime.tv_usec - startTime.tv_usec); + return (totalTime / 1000L) / static_cast(1000); + } + + private: + mutable struct timeval startTime, endTime; + mutable bool end_called; +}; -#endif /* CLOCK_H_ */ +#endif // UTILS_MCLOCK_H_ diff --git a/src/GudhUI/utils/Persistence_compute.h b/src/GudhUI/utils/Persistence_compute.h index 50d340b8..0b9961d3 100644 --- a/src/GudhUI/utils/Persistence_compute.h +++ b/src/GudhUI/utils/Persistence_compute.h @@ -1,13 +1,10 @@ -/* - * Persistence_compute.h - * Created on: Jan 26, 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 @@ -25,83 +22,76 @@ */ -#ifndef PERSISTENCE_COMPUTE_H_ -#define PERSISTENCE_COMPUTE_H_ +#ifndef UTILS_PERSISTENCE_COMPUTE_H_ +#define UTILS_PERSISTENCE_COMPUTE_H_ +#include +#include +#include +#include -#include "gudhi/graph_simplicial_complex.h" -#include "gudhi/Simplex_tree.h" -#include "gudhi/distance_functions.h" -#include "gudhi/Persistent_cohomology.h" +#include +struct Persistence_params { + int p; + double threshold; + int max_dim; + double min_pers; -struct Persistence_params{ - int p; - double threshold; - int max_dim; - double min_pers; - - Persistence_params(int p_,double th_,int max_dim_=10,double min_pers_=0) - :p(p_),threshold(th_),max_dim(max_dim_),min_pers(min_pers_){} + Persistence_params(int p_, double th_, int max_dim_ = 10, double min_pers_ = 0) + : p(p_), threshold(th_), max_dim(max_dim_), min_pers(min_pers_) { } }; - /** * Show persistence into output stream */ -template class Persistence_compute{ -private: - SkBlComplex& complex_; - std::ostream& stream_; -public: - typedef typename SkBlComplex::Vertex_handle Vertex_handle; - typedef typename SkBlComplex::Edge_handle Edge_handle; - - /** - * @brief Compute persistence - * parameters : - * unsigned dim_max - * 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){ - - //for now everything is copied, todo boost adapt iterators to points of SkBlComplex instead of copying to an intial vector - typedef std::vector Point_t; - std::vector< Point_t > points; - points.reserve(complex.num_vertices()); - for(auto v : complex.vertex_range()){ - const auto & pt = complex.point(v); - Point_t pt_to_add(pt.cartesian_begin(),pt.cartesian_end()); - points.emplace_back(std::move(pt_to_add)); - } - - - Graph_t prox_graph = compute_proximity_graph( points, params.threshold, euclidean_distance ); - Gudhi::Simplex_tree<> st; - st.insert_graph(prox_graph); - st.expansion( params.max_dim ); - - Gudhi::persistent_cohomology::Persistent_cohomology< Gudhi::Simplex_tree<>,Gudhi::persistent_cohomology::Field_Zp > pcoh (st); - pcoh.init_coefficients( params.p ); //initilizes the coefficient field for homology - pcoh.compute_persistent_cohomology( params.min_pers ); //put params.min_pers - stream_<<"persistence: \n"; - stream_<<"p dimension birth death: \n"; - - pcoh.output_diagram(stream_); - } - -private: - - +template class Persistence_compute { + private: + SkBlComplex& complex_; + std::ostream& stream_; + + public: + typedef typename SkBlComplex::Vertex_handle Vertex_handle; + typedef typename SkBlComplex::Edge_handle Edge_handle; + + /** + * @brief Compute persistence + * parameters : + * unsigned dim_max + * 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) { + // for now everything is copied, todo boost adapt iterators to points of SkBlComplex instead of copying to an + // initial vector + typedef std::vector Point_t; + std::vector< Point_t > points; + points.reserve(complex.num_vertices()); + for (auto v : complex.vertex_range()) { + const auto & pt = complex.point(v); + Point_t pt_to_add(pt.cartesian_begin(), pt.cartesian_end()); + points.emplace_back(std::move(pt_to_add)); + } + + + Graph_t prox_graph = compute_proximity_graph(points, params.threshold, euclidean_distance); + Gudhi::Simplex_tree<> st; + st.insert_graph(prox_graph); + st.expansion(params.max_dim); + + Gudhi::persistent_cohomology::Persistent_cohomology< Gudhi::Simplex_tree<>, + Gudhi::persistent_cohomology::Field_Zp > pcoh(st); + // initializes the coefficient field for homology + 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"; + + pcoh.output_diagram(stream_); + } }; - - - - - -#endif /* PERSISTENCE_COMPUTE_H_ */ +#endif // UTILS_PERSISTENCE_COMPUTE_H_ diff --git a/src/GudhUI/utils/Rips_builder.h b/src/GudhUI/utils/Rips_builder.h index 9484f9ab..b22f4db6 100644 --- a/src/GudhUI/utils/Rips_builder.h +++ b/src/GudhUI/utils/Rips_builder.h @@ -1,56 +1,69 @@ -/* - * Rips_builder.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. * - * Created on: Sep 10, 2014 - * Author: dsalinas + * Author(s): David Salinas + * + * 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 + * 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 . + * */ -#ifndef RIPS_BUILDER_H_ -#define RIPS_BUILDER_H_ +#ifndef UTILS_RIPS_BUILDER_H_ +#define UTILS_RIPS_BUILDER_H_ #include -#include "utils/UI_utils.h" -#include "model/Complex_typedefs.h" #include - #include #include -template class Rips_builder{ -private: - SkBlComplex& complex_; -public: - - /** - * @brief Modify complex to be the Rips complex - * of its points with offset alpha. - */ - Rips_builder(SkBlComplex& complex,double alpha):complex_(complex){ - complex.keep_only_vertices(); - if (alpha<=0) return; - compute_edges(alpha); - } - -private: - - - double squared_eucl_distance(const Point& p1,const Point& p2) const{ - return Geometry_trait::Squared_distance_d()(p1,p2); - } - - void compute_edges(double alpha){ - auto vertices = complex_.vertex_range(); - for(auto p = vertices.begin(); p!= vertices.end(); ++p){ - std::cout << *p << " "; std::cout.flush(); - for (auto q = p; ++q != vertices.end(); /**/) - if (squared_eucl_distance(complex_.point(*p),complex_.point(*q)) < 4*alpha*alpha) - complex_.add_edge(*p,*q); - } - std::cout << std::endl; - } +#include "utils/UI_utils.h" +#include "model/Complex_typedefs.h" -}; +template class Rips_builder { + private: + SkBlComplex& complex_; + public: + /** + * @brief Modify complex to be the Rips complex + * of its points with offset alpha. + */ + Rips_builder(SkBlComplex& complex, double alpha) : complex_(complex) { + complex.keep_only_vertices(); + if (alpha <= 0) return; + compute_edges(alpha); + } + + private: + double squared_eucl_distance(const Point& p1, const Point& p2) const { + return Geometry_trait::Squared_distance_d()(p1, p2); + } + + void compute_edges(double alpha) { + auto vertices = complex_.vertex_range(); + for (auto p = vertices.begin(); p != vertices.end(); ++p) { + std::cout << *p << " "; + std::cout.flush(); + for (auto q = p; ++q != vertices.end(); /**/) + if (squared_eucl_distance(complex_.point(*p), complex_.point(*q)) < 4 * alpha * alpha) + complex_.add_edge(*p, *q); + } + std::cout << std::endl; + } +}; -#endif /* RIPS_BUILDER_H_ */ +#endif // UTILS_RIPS_BUILDER_H_ diff --git a/src/GudhUI/utils/UI_utils.h b/src/GudhUI/utils/UI_utils.h index 4ade4b98..9cc209d3 100644 --- a/src/GudhUI/utils/UI_utils.h +++ b/src/GudhUI/utils/UI_utils.h @@ -1,30 +1,45 @@ -/* - * UI_utils.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. * - * Created on: Aug 25, 2014 - * Author: david + * Author(s): David Salinas + * + * 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 + * 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 . + * */ -#ifndef UI_UTILS_H_ -#define UI_UTILS_H_ +#ifndef UTILS_UI_UTILS_H_ +#define UTILS_UI_UTILS_H_ #define UIDBG_VERBOSE #ifdef UIDBG_VERBOSE -#define UIDBG(a) std::cerr << "UIDBG: " << (a)< "; for(auto x:a) std::cerr<< x << ","; std::cerr< "; for (auto x : a) std::cerr << x << ","; std::cerr << std::endl } #else // #define DBG(a) a -// #define DBGMSG(a,b) b +// #define DBGMSG(a, b) b // #define DBGVALUE(a) a // #define DBGCONT(a) a #define UIDBG(a) -#define UIDBGMSG(a,b) +#define UIDBGMSG(a, b) #define UIDBGVALUE(a) #define UIDBGCONT(a) #endif - -#endif // UI_UTILS_H_ +#endif // UTILS_UI_UTILS_H_ diff --git a/src/GudhUI/utils/Vertex_collapsor.h b/src/GudhUI/utils/Vertex_collapsor.h index d4911a35..be03c765 100644 --- a/src/GudhUI/utils/Vertex_collapsor.h +++ b/src/GudhUI/utils/Vertex_collapsor.h @@ -1,76 +1,86 @@ -/* - * Vertex_collapsor.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. * - * Created on: Sep 25, 2014 - * Author: dsalinas + * Author(s): David Salinas + * + * 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 + * 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 . + * */ -#ifndef VERTEX_COLLAPSOR_H_ -#define VERTEX_COLLAPSOR_H_ +#ifndef UTILS_VERTEX_COLLAPSOR_H_ +#define UTILS_VERTEX_COLLAPSOR_H_ #include "utils/Edge_contractor.h" #include "utils/Furthest_point_epsilon_net.h" #include "utils/UI_utils.h" + /** * Iteratively puts every vertex at the center of its neighbors */ -template class Vertex_collapsor{ -private: - SkBlComplex& complex_; - size_t num_collapses_; -public: - typedef typename SkBlComplex::Vertex_handle Vertex_handle; - typedef typename SkBlComplex::Edge_handle Edge_handle; - - /** - * @brief Modify complex to be the expansion of the k-nearest neighbor - * symetric graph. - */ - Vertex_collapsor(SkBlComplex& complex, size_t num_collapses) : - complex_(complex),num_collapses_(num_collapses) - { -// std::list vertices; -// vertices.insert(vertices.begin(),complex_.vertex_range().begin(),complex_.vertex_range().end()); -// UIDBG("Collapse vertices"); -// collapse_vertices(vertices); - - std::list vertices; - - UIDBG("Compute eps net"); - Furthest_point_epsilon_net eps_net(complex_); - - for(auto vh : eps_net.net_filtration_) - vertices.push_back(vh.vertex_handle); - - UIDBG("Collapse vertices"); - collapse_vertices(vertices); - - - - } - -private: - - - void collapse_vertices(std::list& vertices){ - while(!vertices.empty() && num_collapses_--){ - Vertex_handle current_vertex = vertices.front(); - vertices.pop_front(); - if(is_link_reducible(current_vertex)) - complex_.remove_vertex(current_vertex); - } - } - - bool is_link_reducible(Vertex_handle v){ - auto link = complex_.link(v); - if(link.empty()) return false; - if(link.is_cone()) return true; - if(link.num_connected_components()>1) return false; - Edge_contractor contractor(link,link.num_vertices()-1); - return (link.num_vertices()==1); - } - +template class Vertex_collapsor { + private: + SkBlComplex& complex_; + size_t num_collapses_; + + public: + typedef typename SkBlComplex::Vertex_handle Vertex_handle; + typedef typename SkBlComplex::Edge_handle Edge_handle; + + /** + * @brief Modify complex to be the expansion of the k-nearest neighbor + * symetric graph. + */ + Vertex_collapsor(SkBlComplex& complex, size_t num_collapses) : + complex_(complex), num_collapses_(num_collapses) { + // std::list vertices; + // vertices.insert(vertices.begin(),complex_.vertex_range().begin(),complex_.vertex_range().end()); + // UIDBG("Collapse vertices"); + // collapse_vertices(vertices); + + std::list vertices; + + UIDBG("Compute eps net"); + Furthest_point_epsilon_net eps_net(complex_); + + for (auto vh : eps_net.net_filtration_) + vertices.push_back(vh.vertex_handle); + + UIDBG("Collapse vertices"); + collapse_vertices(vertices); + } + + private: + void collapse_vertices(std::list& vertices) { + while (!vertices.empty() && num_collapses_--) { + Vertex_handle current_vertex = vertices.front(); + vertices.pop_front(); + if (is_link_reducible(current_vertex)) + complex_.remove_vertex(current_vertex); + } + } + + bool is_link_reducible(Vertex_handle v) { + auto link = complex_.link(v); + if (link.empty()) return false; + if (link.is_cone()) return true; + if (link.num_connected_components() > 1) return false; + Edge_contractor contractor(link, link.num_vertices() - 1); + return (link.num_vertices() == 1); + } }; - -#endif /* VERTEX_COLLAPSOR_H_ */ +#endif // UTILS_VERTEX_COLLAPSOR_H_ diff --git a/src/GudhUI/view/Color.h b/src/GudhUI/view/Color.h index a63456cb..ba0592e1 100644 --- a/src/GudhUI/view/Color.h +++ b/src/GudhUI/view/Color.h @@ -1,21 +1,35 @@ -/* - * Color.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. * - * Created on: Aug 26, 2014 - * Author: dsalinas + * Author(s): David Salinas + * + * 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 + * 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 . + * */ -#ifndef COLOR_H_ -#define COLOR_H_ - +#ifndef VIEW_COLOR_H_ +#define VIEW_COLOR_H_ +struct Color { + double r; + double g; + double b; -struct Color{ - double r; - double g; - double b; - Color(double r_,double g_,double b_):r(r_),g(g_),b(b_){} + Color(double r_, double g_, double b_) : r(r_), g(g_), b(b_) { } }; - -#endif /* COLOR_H_ */ +#endif // VIEW_COLOR_H_ diff --git a/src/GudhUI/view/FirstCoordProjector.h b/src/GudhUI/view/FirstCoordProjector.h index 2659eef1..529d2d42 100644 --- a/src/GudhUI/view/FirstCoordProjector.h +++ b/src/GudhUI/view/FirstCoordProjector.h @@ -1,24 +1,40 @@ -/* - * FirstCoordProjector.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. * - * Created on: Aug 27, 2014 - * Author: dsalinas + * Author(s): David Salinas + * + * 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 + * 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 . + * */ -#ifndef FIRSTCOORDPROJECTOR_H_ -#define FIRSTCOORDPROJECTOR_H_ +#ifndef VIEW_FIRSTCOORDPROJECTOR_H_ +#define VIEW_FIRSTCOORDPROJECTOR_H_ #include "utils/UI_utils.h" #include "Projector3D.h" -class FirstCoordProjector3D : public Projector3D{ - typedef Projector3D::Point Point; - typedef Projector3D::Point_3 Point_3; +class FirstCoordProjector3D : public Projector3D { + typedef Projector3D::Point Point; + typedef Projector3D::Point_3 Point_3; - Point_3 operator()(const Point& p) const{ - assert(p.dimension()>=3); - return Point_3(p.x(),p.y(),p.z()); - } + Point_3 operator()(const Point& p) const { + assert(p.dimension() >= 3); + return Point_3(p.x(), p.y(), p.z()); + } }; -#endif /* FIRSTCOORDPROJECTOR_H_ */ +#endif // VIEW_FIRSTCOORDPROJECTOR_H_ diff --git a/src/GudhUI/view/Projector3D.h b/src/GudhUI/view/Projector3D.h index 503b35c5..2a756541 100644 --- a/src/GudhUI/view/Projector3D.h +++ b/src/GudhUI/view/Projector3D.h @@ -1,28 +1,39 @@ -/* - * Projector.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. * - * Created on: Aug 27, 2014 - * Author: dsalinas + * Author(s): David Salinas + * + * 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 + * 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 . + * */ -#ifndef PROJECTOR3D_H_ -#define PROJECTOR3D_H_ +#ifndef VIEW_PROJECTOR3D_H_ +#define VIEW_PROJECTOR3D_H_ #include "model/Complex_typedefs.h" +class Projector3D { + public: + typedef Geometry_trait::Point Point; + typedef Geometry_trait::Point_3 Point_3; -class Projector3D{ -public: - typedef Geometry_trait::Point Point; - typedef Geometry_trait::Point_3 Point_3; - - virtual Point_3 operator()(const Point&) const = 0; - - virtual ~Projector3D(){ - } + virtual Point_3 operator()(const Point&) const = 0; + virtual ~Projector3D() { } }; - - -#endif /* PROJECTOR3D_H_ */ +#endif // VIEW_PROJECTOR3D_H_ diff --git a/src/GudhUI/view/View_parameter.h b/src/GudhUI/view/View_parameter.h index 39c5d7dd..9805abc2 100644 --- a/src/GudhUI/view/View_parameter.h +++ b/src/GudhUI/view/View_parameter.h @@ -1,13 +1,28 @@ -/* - * View_parameter.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. * - * Created on: Mar 10, 2014 - * Author: David Salinas - * Copyright 2013 INRIA. All rights reserved + * Author(s): David Salinas + * + * 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 + * 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 . + * */ -#ifndef VIEW_PARAMETER_H_ -#define VIEW_PARAMETER_H_ +#ifndef VIEW_VIEW_PARAMETER_H_ +#define VIEW_VIEW_PARAMETER_H_ #include @@ -15,123 +30,122 @@ * Different parameters for the view such as the camera angle, * the light, options for vertices/edges/triangles. */ -class View_parameter{ -public: - bool light; - bool relative_light; - - double size_vertices; - double size_edges; - double light_edges; // in 0-1 - double light_triangles;// in 0-1 - - /** - * light angle - */ - double theta; - double phi; - - enum VERTEX_MODE{ V_NONE,V_SIMPLE,V_COUNT}; - enum EDGE_MODE{ E_NONE,E_SIMPLE,E_COUNT}; - enum TRIANGLE_MODE{ T_NONE,T_SIMPLE,T_COUNT}; - - - - - VERTEX_MODE vertex_mode; - EDGE_MODE edge_mode; - TRIANGLE_MODE triangle_mode; - - void change_vertex_mode(){ - int current_value = vertex_mode; - vertex_mode = static_cast(++current_value % V_COUNT); - std::cout<<"Vertex mode : "; - switch (vertex_mode) { - case V_NONE: - std::cout<<"empty\n"; - break; - case V_SIMPLE: - std::cout<<"simple\n"; - break; - default: - break; - } - } - - void change_vertex_mode(int new_mode){ - vertex_mode = static_cast(new_mode % V_COUNT); - } - - void change_edge_mode(){ - int current_value = edge_mode; - edge_mode = static_cast(++current_value % E_COUNT); - } - - void change_edge_mode(int new_mode){ - edge_mode = static_cast(new_mode % E_COUNT); - } - - - void change_triangle_mode(){ - int current_value = triangle_mode; - triangle_mode = static_cast(++current_value % T_COUNT); - } - - - - - - View_parameter(){ - light = true; - relative_light = true; - vertex_mode = V_SIMPLE; - edge_mode = E_SIMPLE; - triangle_mode = T_NONE; - - size_vertices = 3; - size_edges = 2; - - light_edges = 0.3; - light_triangles = 0.85; - theta = 0; - phi = 0; - } - - friend std::ostream& operator<<(std::ostream& stream, const View_parameter& param){ - stream << param.light<< " "; - stream << param.relative_light<< " "; - stream << param.vertex_mode<< " "; - stream << param.edge_mode<< " "; - stream << param.triangle_mode<< " "; - stream << param.size_vertices<< " "; - stream << param.size_edges<< " "; - stream << param.light_edges<< " "; - stream << param.light_triangles<< " "; - stream << param.theta<< " "; - stream << param.phi<< " "; - return stream; - } - - friend std::istream& operator>>(std::istream& stream, View_parameter& param){ - stream >> param.light; - stream >> param.relative_light; - int a; - stream>>a; - param.vertex_mode = static_cast(a % V_COUNT); - stream>>a; - param.edge_mode = static_cast(a % E_COUNT); - stream>>a; - param.triangle_mode = static_cast(a % T_COUNT); - stream>>a; - stream >> param.size_vertices; - stream >> param.size_edges; - stream >> param.light_edges; - stream >> param.light_triangles; - stream >> param.theta; - stream >> param.phi; - return stream; - } - +class View_parameter { + public: + bool light; + bool relative_light; + + double size_vertices; + double size_edges; + double light_edges; // in 0-1 + double light_triangles; // in 0-1 + + /** + * light angle + */ + double theta; + double phi; + + enum VERTEX_MODE { + V_NONE, V_SIMPLE, V_COUNT + }; + + enum EDGE_MODE { + E_NONE, E_SIMPLE, E_COUNT + }; + + enum TRIANGLE_MODE { + T_NONE, T_SIMPLE, T_COUNT + }; + + VERTEX_MODE vertex_mode; + EDGE_MODE edge_mode; + TRIANGLE_MODE triangle_mode; + + void change_vertex_mode() { + int current_value = vertex_mode; + vertex_mode = static_cast (++current_value % V_COUNT); + std::cout << "Vertex mode : "; + switch (vertex_mode) { + case V_NONE: + std::cout << "empty\n"; + break; + case V_SIMPLE: + std::cout << "simple\n"; + break; + default: + break; + } + } + + void change_vertex_mode(int new_mode) { + vertex_mode = static_cast (new_mode % V_COUNT); + } + + void change_edge_mode() { + int current_value = edge_mode; + edge_mode = static_cast (++current_value % E_COUNT); + } + + void change_edge_mode(int new_mode) { + edge_mode = static_cast (new_mode % E_COUNT); + } + + void change_triangle_mode() { + int current_value = triangle_mode; + triangle_mode = static_cast (++current_value % T_COUNT); + } + + View_parameter() { + light = true; + relative_light = true; + vertex_mode = V_SIMPLE; + edge_mode = E_SIMPLE; + triangle_mode = T_NONE; + + size_vertices = 3; + size_edges = 2; + + light_edges = 0.3; + light_triangles = 0.85; + theta = 0; + phi = 0; + } + + friend std::ostream& operator<<(std::ostream& stream, const View_parameter& param) { + stream << param.light << " "; + stream << param.relative_light << " "; + stream << param.vertex_mode << " "; + stream << param.edge_mode << " "; + stream << param.triangle_mode << " "; + stream << param.size_vertices << " "; + stream << param.size_edges << " "; + stream << param.light_edges << " "; + stream << param.light_triangles << " "; + stream << param.theta << " "; + stream << param.phi << " "; + return stream; + } + + friend std::istream& operator>>(std::istream& stream, View_parameter& param) { + stream >> param.light; + stream >> param.relative_light; + int a; + stream >> a; + param.vertex_mode = static_cast (a % V_COUNT); + stream >> a; + param.edge_mode = static_cast (a % E_COUNT); + stream >> a; + param.triangle_mode = static_cast (a % T_COUNT); + stream >> a; + stream >> param.size_vertices; + stream >> param.size_edges; + stream >> param.light_edges; + stream >> param.light_triangles; + stream >> param.theta; + stream >> param.phi; + return stream; + } }; -#endif /* VIEW_PARAMETER_H_ */ +#endif // VIEW_VIEW_PARAMETER_H_ diff --git a/src/GudhUI/view/Viewer.cpp b/src/GudhUI/view/Viewer.cpp index d8a35faf..c6c2b345 100644 --- a/src/GudhUI/view/Viewer.cpp +++ b/src/GudhUI/view/Viewer.cpp @@ -1,197 +1,186 @@ -/* - * Viewer.cpp +/* This file is part of the Gudhi Library. The Gudhi library + * (Geometric Understanding in Higher Dimensions) is a generic C++ + * library for computational topology. * - * Created on: Aug 26, 2014 - * Author: dsalinas + * Author(s): David Salinas + * + * 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 + * 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 . + * */ #include "Viewer.h" #include "utils/UI_utils.h" -Viewer::Viewer(QWidget* parent): QGLViewer(QGLFormat(QGL::SampleBuffers),parent),instructor(0),theta(0),phi(0){ -} +Viewer::Viewer(QWidget* parent) : QGLViewer(QGLFormat(QGL::SampleBuffers), parent), instructor(0), theta(0), phi(0) { } -void -Viewer::set_instructor(Viewer_instructor* instructor_){ - instructor = instructor_; +void Viewer::set_instructor(Viewer_instructor* instructor_) { + instructor = instructor_; } -void -Viewer::show_entire_scene(){ - this->showEntireScene(); +void Viewer::show_entire_scene() { + this->showEntireScene(); } -void -Viewer::draw(){ - instructor->give_instructions(); +void Viewer::draw() { + instructor->give_instructions(); } - -void -Viewer::set_bounding_box(const Point_3 & lower_left,const Point_3 & upper_right){ - this->camera()->setSceneBoundingBox( - qglviewer::Vec(lower_left[0], lower_left[1], lower_left[2]), - qglviewer::Vec(upper_right[0], upper_right[1], upper_right[2]) - ); +void Viewer::set_bounding_box(const Point_3 & lower_left, const Point_3 & upper_right) { + this->camera()->setSceneBoundingBox(qglviewer::Vec(lower_left[0], lower_left[1], lower_left[2]), + qglviewer::Vec(upper_right[0], upper_right[1], upper_right[2])); } -void -Viewer::update_GL(){ - this->updateGL(); - +void Viewer::update_GL() { + this->updateGL(); } -void -Viewer::init_scene(){ - this->setBackgroundColor(Qt::white); - ::glEnable(GL_LINE_SMOOTH); - init_light(); +void Viewer::init_scene() { + this->setBackgroundColor(Qt::white); + ::glEnable(GL_LINE_SMOOTH); + init_light(); } -void -Viewer::init_light(){ - ::glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE); +void Viewer::init_light() { + ::glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE); } -void -Viewer::set_light(){ - if(theta>=0 && phi >=0){ - const GLfloat pos[4] = {(float)(sin(phi)*cos(theta)),(float)(sin(phi)*sin(theta)),(float)(cos(phi)),0.}; - glLightfv(GL_LIGHT0, GL_POSITION, pos); - } +void Viewer::set_light() { + if (theta >= 0 && phi >= 0) { + const GLfloat pos[4] = {static_cast (sin(phi) * cos(theta)), + static_cast (sin(phi) * sin(theta)), + static_cast (cos(phi)), 0.}; + glLightfv(GL_LIGHT0, GL_POSITION, pos); + } } -void -Viewer::set_light_direction(double theta_,double phi_){ - theta = theta_; - phi = phi_; +void Viewer::set_light_direction(double theta_, double phi_) { + theta = theta_; + phi = phi_; } /** * set the light in the direction of the observer */ -void -Viewer::set_light_direction(){ - theta = -1; - phi = -1; +void Viewer::set_light_direction() { + theta = -1; + phi = -1; } +void Viewer::postSelection(const QPoint& point) { + bool found; -void -Viewer::postSelection(const QPoint& point){ - bool found; + auto vec = this->camera()->pointUnderPixel(point, found); - auto vec = this->camera()->pointUnderPixel(point,found); - - if(found){ - Point_3 position(vec[0],vec[1],vec[2]); - emit(click(position)); - } + if (found) { + Point_3 position(vec[0], vec[1], vec[2]); + emit(click(position)); + } } //////////////////////// // draw //////////////////////// -void -Viewer::set_size_point(double size_points){ - ::glPointSize(size_points); -} - -void -Viewer::draw_point(const Point_3& p,const Color& color,double size_points){ - ::glColor3f(color.r,color.g,color.b); - ::glDisable(GL_LIGHTING); - ::glEnable(GL_POINT_SMOOTH); - ::glPointSize(size_points); - ::glBegin(GL_POINTS); - ::glVertex3d(p.x(), p.y(), p.z()); - ::glEnd(); - ::glDisable(GL_POINT_SMOOTH); -} - -void -Viewer::begin_draw_points(double size,bool light){ - light?glEnable(GL_LIGHTING):glDisable(GL_LIGHTING); - ::glEnable(GL_POINT_SMOOTH); - ::glPointSize(size); - ::glBegin(GL_POINTS); -} - -void -Viewer::set_color(const Color& color){ - ::glColor3f(color.r,color.g,color.b); -} - -void -Viewer::draw_points(const Point_3 & point){ - ::glVertex3d(point.x(),point.y(),point.z()); -} - -void -Viewer::end_draw_points(){ - ::glEnd(); - ::glDisable(GL_POINT_SMOOTH); -} - -void -Viewer::draw_edge(const Point_3 &a,const Point_3 &b,const Color& color,double size){ - ::glColor3f(color.r,color.g,color.b); - ::glPointSize(3.0); - ::glLineWidth(size); - ::glBegin(GL_LINES); - ::glVertex3f(a.x(),a.y(),a.z()); - ::glVertex3f(b.x(),b.y(),b.z()); - ::glEnd(); -} - -void -Viewer::begin_draw_edges(double size,bool light){ - ::glLineWidth(size); - ::glPolygonMode(GL_FRONT_AND_BACK,GL_LINE); - ::glEnable(GL_POLYGON_OFFSET_LINE); - ::glPolygonOffset(3.0f,-3.0f); - light?glEnable(GL_LIGHTING):glDisable(GL_LIGHTING); - ::glBegin(GL_LINES); -} - -void -Viewer::draw_edges(const Point_3 &a,const Point_3 &b){ - ::glVertex3f(a.x(),a.y(),a.z()); - ::glVertex3f(b.x(),b.y(),b.z()); -} - -void -Viewer::end_draw_edges(){ - ::glEnd(); -} - -void -Viewer::begin_draw_triangles(double size,bool light,bool transparent){ - if(transparent){ - ::glEnable (GL_BLEND); - ::glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - } - ::glPolygonMode(GL_FRONT_AND_BACK,GL_FILL); - ::glEnable(GL_POLYGON_OFFSET_FILL); - ::glPolygonOffset(3.0f,-3.0f); - light?glEnable(GL_LIGHTING):glDisable(GL_LIGHTING); - ::glBegin(GL_TRIANGLES); -} - -void -Viewer::draw_triangles(const Point_3& p1,const Point_3& p2,const Point_3& p3){ - if(!CGAL::collinear(p1,p2,p3)){ - auto triangle_normal = CGAL::unit_normal(p1,p2,p3); - ::glNormal3d(triangle_normal.x(),triangle_normal.y(),triangle_normal.z()); - ::glVertex3d(p1.x(),p1.y(),p1.z()); - ::glVertex3d(p2.x(),p2.y(),p2.z()); - ::glVertex3d(p3.x(),p3.y(),p3.z()); - } -} - -void -Viewer::end_draw_triangles(){ - ::glEnd(); + +void Viewer::set_size_point(double size_points) { + ::glPointSize(size_points); +} + +void Viewer::draw_point(const Point_3& p, const Color& color, double size_points) { + ::glColor3f(color.r, color.g, color.b); + ::glDisable(GL_LIGHTING); + ::glEnable(GL_POINT_SMOOTH); + ::glPointSize(size_points); + ::glBegin(GL_POINTS); + ::glVertex3d(p.x(), p.y(), p.z()); + ::glEnd(); + ::glDisable(GL_POINT_SMOOTH); +} + +void Viewer::begin_draw_points(double size, bool light) { + light ? glEnable(GL_LIGHTING) : glDisable(GL_LIGHTING); + ::glEnable(GL_POINT_SMOOTH); + ::glPointSize(size); + ::glBegin(GL_POINTS); +} + +void Viewer::set_color(const Color& color) { + ::glColor3f(color.r, color.g, color.b); +} + +void Viewer::draw_points(const Point_3 & point) { + ::glVertex3d(point.x(), point.y(), point.z()); +} + +void Viewer::end_draw_points() { + ::glEnd(); + ::glDisable(GL_POINT_SMOOTH); +} + +void Viewer::draw_edge(const Point_3 &a, const Point_3 &b, const Color& color, double size) { + ::glColor3f(color.r, color.g, color.b); + ::glPointSize(3.0); + ::glLineWidth(size); + ::glBegin(GL_LINES); + ::glVertex3f(a.x(), a.y(), a.z()); + ::glVertex3f(b.x(), b.y(), b.z()); + ::glEnd(); +} + +void Viewer::begin_draw_edges(double size, bool light) { + ::glLineWidth(size); + ::glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); + ::glEnable(GL_POLYGON_OFFSET_LINE); + ::glPolygonOffset(3.0f, -3.0f); + light ? glEnable(GL_LIGHTING) : glDisable(GL_LIGHTING); + ::glBegin(GL_LINES); +} + +void Viewer::draw_edges(const Point_3 &a, const Point_3 &b) { + ::glVertex3f(a.x(), a.y(), a.z()); + ::glVertex3f(b.x(), b.y(), b.z()); +} + +void Viewer::end_draw_edges() { + ::glEnd(); +} + +void Viewer::begin_draw_triangles(double size, bool light, bool transparent) { + if (transparent) { + ::glEnable(GL_BLEND); + ::glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + } + ::glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); + ::glEnable(GL_POLYGON_OFFSET_FILL); + ::glPolygonOffset(3.0f, -3.0f); + light ? glEnable(GL_LIGHTING) : glDisable(GL_LIGHTING); + ::glBegin(GL_TRIANGLES); +} + +void Viewer::draw_triangles(const Point_3& p1, const Point_3& p2, const Point_3& p3) { + if (!CGAL::collinear(p1, p2, p3)) { + auto triangle_normal = CGAL::unit_normal(p1, p2, p3); + ::glNormal3d(triangle_normal.x(), triangle_normal.y(), triangle_normal.z()); + ::glVertex3d(p1.x(), p1.y(), p1.z()); + ::glVertex3d(p2.x(), p2.y(), p2.z()); + ::glVertex3d(p3.x(), p3.y(), p3.z()); + } +} + +void Viewer::end_draw_triangles() { + ::glEnd(); } #include "Viewer.moc" diff --git a/src/GudhUI/view/Viewer.h b/src/GudhUI/view/Viewer.h index 00f9b245..99bd63e4 100644 --- a/src/GudhUI/view/Viewer.h +++ b/src/GudhUI/view/Viewer.h @@ -1,10 +1,36 @@ -#ifndef VIEWER_H -#define VIEWER_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): David Salinas + * + * 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 + * 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 . + * + */ + +#ifndef VIEW_VIEWER_H +#define VIEW_VIEWER_H // Workaround for moc-qt4 not parsing boost headers #include #include + +#include + #include "View_parameter.h" #include "model/Complex_typedefs.h" #include "Color.h" @@ -13,87 +39,82 @@ class Viewer_instructor; class Viewer : public QGLViewer { - Q_OBJECT - - Viewer_instructor * instructor; - - /** - * light angles - */ - double theta,phi; - typedef Complex::GT Gudhi_kernel; - typedef Gudhi_kernel::Point_3 Point_3; -public: - Viewer(QWidget* parent); + Q_OBJECT - void set_instructor(Viewer_instructor* instructor_); + Viewer_instructor * instructor; - void show_entire_scene(); + /** + * light angles + */ + double theta, phi; + typedef Complex::GT Gudhi_kernel; + typedef Gudhi_kernel::Point_3 Point_3; - void draw(); + public: + Viewer(QWidget* parent); + void set_instructor(Viewer_instructor* instructor_); - void set_bounding_box(const Point_3 & lower_left,const Point_3 & upper_right); + void show_entire_scene(); - void update_GL(); + void draw(); - void init_scene(); + void set_bounding_box(const Point_3 & lower_left, const Point_3 & upper_right); - void init_light(); + void update_GL(); - void set_light(); + void init_scene(); - void set_light_direction(double theta,double phi); + void init_light(); - /** - * set the light in the direction of the observer - */ - void set_light_direction(); + void set_light(); + void set_light_direction(double theta, double phi); -protected: - virtual void postSelection(const QPoint& point); + /** + * set the light in the direction of the observer + */ + void set_light_direction(); + protected: + virtual void postSelection(const QPoint& point); -public: + public: + //////////////////////// + // draw + //////////////////////// + void set_size_point(double size_points); - //////////////////////// - // draw - //////////////////////// - void set_size_point(double size_points); + void set_color(const Color& color); - void set_color(const Color& color); + void draw_point(const Point_3& p, const Color& color, double size_points); - void draw_point(const Point_3& p,const Color& color,double size_points); + void begin_draw_points(double size, bool light = false); - void begin_draw_points(double size,bool light=false); + void draw_points(const Point_3 & point); - void draw_points(const Point_3 & point); + void end_draw_points(); - void end_draw_points(); + void draw_edge(const Point_3 &a, const Point_3 &b, const Color& color, double size); - void draw_edge(const Point_3 &a,const Point_3 &b,const Color& color,double size); + void begin_draw_edges(double size, bool light = false); - void begin_draw_edges(double size,bool light=false); + void draw_edges(const Point_3 &a, const Point_3 &b); - void draw_edges(const Point_3 &a,const Point_3 &b); + void end_draw_edges(); - void end_draw_edges(); + void begin_draw_triangles(double size, bool light, bool transparent = false); - void begin_draw_triangles(double size,bool light,bool transparent = false); + void draw_triangles(const Point_3& p1, const Point_3& p2, const Point_3& p3); - void draw_triangles(const Point_3& p1,const Point_3& p2,const Point_3& p3); + // todo remove + void draw_triangles(const std::vector& points); - //todo remove - void draw_triangles(const std::vector& points); + void end_draw_triangles(); - void end_draw_triangles(); - - signals: - void click(const Point_3& position); + signals: + void click(const Point_3& position); }; - - -#endif +#endif // VIEW_VIEWER_H diff --git a/src/GudhUI/view/Viewer_instructor.cpp b/src/GudhUI/view/Viewer_instructor.cpp index 3cb8f152..4446d209 100644 --- a/src/GudhUI/view/Viewer_instructor.cpp +++ b/src/GudhUI/view/Viewer_instructor.cpp @@ -1,206 +1,192 @@ -/* - * Viewer_instructor.cpp +/* This file is part of the Gudhi Library. The Gudhi library + * (Geometric Understanding in Higher Dimensions) is a generic C++ + * library for computational topology. * - * Created on: Aug 26, 2014 - * Author: dsalinas + * Author(s): David Salinas + * + * 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 + * 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 . + * */ #include + #include "Viewer_instructor.h" #include "utils/UI_utils.h" #include "FirstCoordProjector.h" - Viewer_instructor::Viewer_instructor(QWidget* parent, - Viewer* viewer, - const Complex& mesh -):viewer_(viewer),mesh_(mesh),projector_(new FirstCoordProjector3D()){ - viewer_->set_instructor(this); + Viewer* viewer, + const Complex& mesh + ) + : viewer_(viewer), mesh_(mesh), projector_(new FirstCoordProjector3D()) { + viewer_->set_instructor(this); +} + +void Viewer_instructor::initialize_bounding_box() { + auto pair_bounding_box = compute_bounding_box_corners(); + viewer_->set_bounding_box(proj(pair_bounding_box.first), proj(pair_bounding_box.second)); + viewer_->init_scene(); } +std::pair Viewer_instructor::compute_bounding_box_corners() { + if (mesh_.empty()) { + return std::make_pair(Point(-1, -1, -1, 1), Point(1, 1, 1, 1)); + } else { + double x_min = 1e10; + double y_min = 1e10; + double z_min = 1e10; + double x_max = -1e10; + double y_max = -1e10; + double z_max = -1e10; + for (auto vi : mesh_.vertex_range()) { + auto pt = proj(mesh_.point(vi)); + x_min = (std::min)(x_min, pt.x()); + y_min = (std::min)(y_min, pt.y()); + z_min = (std::min)(z_min, pt.z()); -void -Viewer_instructor::initialize_bounding_box(){ - auto pair_bounding_box = compute_bounding_box_corners(); - viewer_->set_bounding_box(proj(pair_bounding_box.first),proj(pair_bounding_box.second)); - viewer_->init_scene(); -} - -std::pair -Viewer_instructor::compute_bounding_box_corners(){ - if(mesh_.empty()){ - return std::make_pair(Point(-1,-1,-1,1),Point(1,1,1,1)); - } - else{ - double x_min = 1e10; - double y_min = 1e10; - double z_min = 1e10; - double x_max = -1e10; - double y_max = -1e10; - double z_max = -1e10; - for( auto vi : mesh_.vertex_range()) - { - auto pt = proj(mesh_.point(vi)); - x_min = (std::min)(x_min,pt.x()); - y_min = (std::min)(y_min,pt.y()); - z_min = (std::min)(z_min,pt.z()); - - x_max = (std::max)(x_max,pt.x()); - y_max = (std::max)(y_max,pt.y()); - z_max = (std::max)(z_max,pt.z()); - - } - return std::make_pair( - Point(x_min,y_min,z_min,1.), - Point(x_max,y_max,z_max,1.) - ); - } + x_max = (std::max)(x_max, pt.x()); + y_max = (std::max)(y_max, pt.y()); + z_max = (std::max)(z_max, pt.z()); + } + return std::make_pair(Point(x_min, y_min, z_min, 1.), + Point(x_max, y_max, z_max, 1.)); + } } -void -Viewer_instructor::show_entire_scene(){ - viewer_->show_entire_scene(); +void Viewer_instructor::show_entire_scene() { + viewer_->show_entire_scene(); } -const qglviewer::Camera* -Viewer_instructor::camera() const{ - return viewer_->camera(); +const qglviewer::Camera* Viewer_instructor::camera() const { + return viewer_->camera(); } int -Viewer_instructor::width() const{ - return viewer_->width(); +Viewer_instructor::width() const { + return viewer_->width(); } + int -Viewer_instructor::height() const{ - return viewer_->height(); +Viewer_instructor::height() const { + return viewer_->height(); } /** * to change display parameters */ -View_parameter& -Viewer_instructor::view_params(){ - return view_params_; +View_parameter& Viewer_instructor::view_params() { + return view_params_; } - void -Viewer_instructor::give_instructions(){ - if(view_params_.relative_light) - viewer_->set_light_direction(); - else - viewer_->set_light_direction(view_params_.theta,view_params_.phi); - viewer_->set_light(); - - if (view_params_.edge_mode) draw_edges(); - if (view_params_.triangle_mode) draw_triangles(); - if (view_params_.vertex_mode) draw_points(); +Viewer_instructor::give_instructions() { + if (view_params_.relative_light) + viewer_->set_light_direction(); + else + viewer_->set_light_direction(view_params_.theta, view_params_.phi); + viewer_->set_light(); + if (view_params_.edge_mode) draw_edges(); + if (view_params_.triangle_mode) draw_triangles(); + if (view_params_.vertex_mode) draw_points(); } -void -Viewer_instructor::draw_edges(){ - viewer_->begin_draw_edges(view_params_.size_edges,false); +void Viewer_instructor::draw_edges() { + viewer_->begin_draw_edges(view_params_.size_edges, false); - for(auto edge : mesh_.edge_range()){ - set_color_edge(edge); - const Point& a = mesh_.point(mesh_.first_vertex(edge)); - const Point& b = mesh_.point(mesh_.second_vertex(edge)) ; - viewer_->draw_edges(proj(a),proj(b)); - } + for (auto edge : mesh_.edge_range()) { + set_color_edge(edge); + const Point& a = mesh_.point(mesh_.first_vertex(edge)); + const Point& b = mesh_.point(mesh_.second_vertex(edge)); + viewer_->draw_edges(proj(a), proj(b)); + } - viewer_->end_draw_edges(); + viewer_->end_draw_edges(); } -void -Viewer_instructor::draw_triangles(){ - const double size_triangles = 1.0; - viewer_->begin_draw_triangles(size_triangles,view_params_.light); - - for(const auto& fit : mesh_.triangle_range()) { - set_color_triangle(fit); - if(view_params_.triangle_mode){ - auto fit_it = fit.begin(); - const Point& p1 = mesh_.point(*fit_it); - const Point& p2 = mesh_.point(*(++fit_it)); - const Point& p3 = mesh_.point(*(++fit_it)); - viewer_->draw_triangles(proj(p1),proj(p2),proj(p3)); - } - } - viewer_->end_draw_triangles(); -} +void Viewer_instructor::draw_triangles() { + const double size_triangles = 1.0; + viewer_->begin_draw_triangles(size_triangles, view_params_.light); -void -Viewer_instructor::draw_points(){ - viewer_->begin_draw_points( view_params_.size_vertices); - for( auto vi : mesh_.vertex_range()) - { - viewer_->set_size_point(view_params_.size_vertices); - set_color_vertex(vi); - viewer_->draw_points(proj(mesh_.point(vi))); - } - viewer_->end_draw_points(); + for (const auto& fit : mesh_.triangle_range()) { + set_color_triangle(fit); + if (view_params_.triangle_mode) { + auto fit_it = fit.begin(); + const Point& p1 = mesh_.point(*fit_it); + const Point& p2 = mesh_.point(*(++fit_it)); + const Point& p3 = mesh_.point(*(++fit_it)); + viewer_->draw_triangles(proj(p1), proj(p2), proj(p3)); + } + } + viewer_->end_draw_triangles(); } - -void -Viewer_instructor::draw_edge(const Point&,const Point&){ - +void Viewer_instructor::draw_points() { + viewer_->begin_draw_points(view_params_.size_vertices); + for (auto vi : mesh_.vertex_range()) { + viewer_->set_size_point(view_params_.size_vertices); + set_color_vertex(vi); + viewer_->draw_points(proj(mesh_.point(vi))); + } + viewer_->end_draw_points(); } -void -Viewer_instructor::draw_point(const Point&){ - -} +void Viewer_instructor::draw_edge(const Point&, const Point&) { } +void Viewer_instructor::draw_point(const Point&) { } /** * set the right color of vertex/edge/triangle considering the view_params choice */ -void -Viewer_instructor::set_color_vertex(Vertex_handle vh){ - viewer_->set_color(Color(view_params_.light_edges,view_params_.light_edges,view_params_.light_edges)); +void Viewer_instructor::set_color_vertex(Vertex_handle vh) { + viewer_->set_color(Color(view_params_.light_edges, view_params_.light_edges, view_params_.light_edges)); } -void -Viewer_instructor::set_color_edge(Edge_handle eh) { - viewer_->set_color(Color(view_params_.light_edges,view_params_.light_edges,view_params_.light_edges)); +void Viewer_instructor::set_color_edge(Edge_handle eh) { + viewer_->set_color(Color(view_params_.light_edges, view_params_.light_edges, view_params_.light_edges)); } -void -Viewer_instructor::set_color_triangle(const Simplex_handle& triangle){ - viewer_->set_color(Color(view_params_.light_triangles,view_params_.light_triangles,view_params_.light_triangles)); +void Viewer_instructor::set_color_triangle(const Simplex_handle& triangle) { + viewer_->set_color(Color(view_params_.light_triangles, view_params_.light_triangles, view_params_.light_triangles)); } - Viewer_instructor::Point_3 -Viewer_instructor::proj(const Point& p) const{ - return (*projector_)(p); +Viewer_instructor::proj(const Point& p) const { + return (*projector_)(p); } - -void -Viewer_instructor::sceneChanged(){ - UIDBG("sceneChanged"); - viewer_->update_GL(); +void Viewer_instructor::sceneChanged() { + UIDBG("sceneChanged"); + viewer_->update_GL(); } -void -Viewer_instructor::change_draw_vertices(){ - view_params_.change_vertex_mode(); +void Viewer_instructor::change_draw_vertices() { + view_params_.change_vertex_mode(); } -void -Viewer_instructor::change_draw_edges(){ - view_params_.change_edge_mode(); + +void Viewer_instructor::change_draw_edges() { + view_params_.change_edge_mode(); } -void -Viewer_instructor::change_draw_triangles(){ - view_params_.change_triangle_mode(); + +void Viewer_instructor::change_draw_triangles() { + view_params_.change_triangle_mode(); } -void -Viewer_instructor::change_light(){ - view_params_.light =! view_params_.light ; + +void Viewer_instructor::change_light() { + view_params_.light = !view_params_.light; } #include "Viewer_instructor.moc" diff --git a/src/GudhUI/view/Viewer_instructor.h b/src/GudhUI/view/Viewer_instructor.h index 62b3755e..e1c6af8b 100644 --- a/src/GudhUI/view/Viewer_instructor.h +++ b/src/GudhUI/view/Viewer_instructor.h @@ -1,17 +1,40 @@ -#ifndef VIEWER_INSTRUCTOR_H -#define VIEWER_INSTRUCTOR_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): David Salinas + * + * 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 + * 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 . + * + */ + +#ifndef VIEW_VIEWER_INSTRUCTOR_H +#define VIEW_VIEWER_INSTRUCTOR_H // todo do a viewer instructor that have directely a pointer to a QGLviewer and buffer ot not triangles // Workaround for moc-qt4 not parsing boost headers #include -#include - #include #include #include +#include +#include // for pair<> #include "model/Complex_typedefs.h" @@ -22,89 +45,73 @@ class Viewer; class Viewer_parameter; -class Viewer_instructor : public QWidget{ - Q_OBJECT - - typedef Geometry_trait::Point_3 Point_3; - typedef Complex::Point Point; - typedef Complex::Vertex_handle Vertex_handle; - typedef Complex::Edge_handle Edge_handle; - typedef Complex::Simplex_handle Simplex_handle; - - - Viewer* viewer_; - View_parameter view_params_; - const Complex& mesh_; - std::unique_ptr projector_; - - -public: - - Viewer_instructor(QWidget* parent, - Viewer* viewer, - const Complex& mesh - ); - - - void initialize_bounding_box(); - - std::pair compute_bounding_box_corners(); - - void show_entire_scene(); - - const qglviewer::Camera* camera() const; - - int width() const; - int height() const; - - /** - * to change display parameters - */ - View_parameter& view_params(); +class Viewer_instructor : public QWidget { + Q_OBJECT + typedef Geometry_trait::Point_3 Point_3; + typedef Complex::Point Point; + typedef Complex::Vertex_handle Vertex_handle; + typedef Complex::Edge_handle Edge_handle; + typedef Complex::Simplex_handle Simplex_handle; -public: + Viewer* viewer_; + View_parameter view_params_; + const Complex& mesh_; + std::unique_ptr projector_; - /** - * gives instructions to the viewer - */ - void give_instructions(); + public: + Viewer_instructor(QWidget* parent, Viewer* viewer, const Complex& mesh); - void draw_edges(); - void draw_triangles(); - void draw_points(); + void initialize_bounding_box(); + std::pair compute_bounding_box_corners(); - void draw_edge(const Point&,const Point&); + void show_entire_scene(); - void draw_point(const Point&); + const qglviewer::Camera* camera() const; + int width() const; + int height() const; - /** - * set the right color of vertex/edge/triangle considering the view_params choice - */ - void set_color_vertex(Vertex_handle vh); - void set_color_edge(Edge_handle eh); + /** + * to change display parameters + */ + View_parameter& view_params(); - void set_color_triangle(const Simplex_handle& triangle); + public: + /** + * gives instructions to the viewer + */ + void give_instructions(); -private: - /** - * Projection to 3D needed for the viewer. - */ - Point_3 proj(const Point& p) const; + void draw_edges(); + void draw_triangles(); + void draw_points(); - public slots : + void draw_edge(const Point&, const Point&); - void sceneChanged(); + void draw_point(const Point&); - void change_draw_vertices(); - void change_draw_edges(); - void change_draw_triangles(); - void change_light(); + /** + * set the right color of vertex/edge/triangle considering the view_params choice + */ + void set_color_vertex(Vertex_handle vh); + void set_color_edge(Edge_handle eh); + void set_color_triangle(const Simplex_handle& triangle); + private: + /** + * Projection to 3D needed for the viewer. + */ + Point_3 proj(const Point& p) const; + public slots: + void sceneChanged(); + void change_draw_vertices(); + void change_draw_edges(); + void change_draw_triangles(); + void change_light(); }; -#endif //VIEWER_INSTRUCTOR_H +#endif // VIEW_VIEWER_INSTRUCTOR_H -- cgit v1.2.3 From 376c2a0dbde0decffb3f37146071368ccb3836a7 Mon Sep 17 00:00:00 2001 From: vrouvrea Date: Thu, 8 Oct 2015 21:48:10 +0000 Subject: cpplint fixes git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/trunk@845 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 8b15f0805527b494f3a57625de5c69d836b287dd --- .../CGAL_queue/Modifiable_priority_queue.h | 6 +++--- .../gudhi/Contraction/policies/Edge_length_cost.h | 6 +++--- src/GudhUI/utils/Edge_collapsor.h | 6 +++--- src/GudhUI/utils/Edge_contractor.h | 2 +- src/GudhUI/utils/Is_manifold.h | 4 ++-- src/GudhUI/utils/Vertex_collapsor.h | 2 ++ src/GudhUI/view/Viewer.h | 6 +++--- src/GudhUI/view/Viewer_instructor.h | 6 +++--- src/Hasse_complex/include/gudhi/Hasse_complex.h | 9 +++++---- .../include/gudhi/Persistent_cohomology.h | 20 +++++++++++--------- .../include/gudhi/Persistent_cohomology/Field_Zp.h | 6 +++--- .../gudhi/Persistent_cohomology/Multi_field.h | 6 +++--- .../Persistent_cohomology_column.h | 6 +++--- src/Simplex_tree/include/gudhi/Simplex_tree.h | 13 ++++++++----- .../gudhi/Simplex_tree/Simplex_tree_iterators.h | 6 +++--- .../Simplex_tree_node_explicit_storage.h | 6 +++--- .../gudhi/Simplex_tree/Simplex_tree_siblings.h | 6 +++--- .../include/gudhi/Simplex_tree/indexing_tag.h | 6 +++--- .../gudhi/Skeleton_blocker_simplifiable_complex.h | 6 +++--- src/common/include/gudhi/graph_simplicial_complex.h | 6 +++++- 20 files changed, 73 insertions(+), 61 deletions(-) (limited to 'src') diff --git a/src/Contraction/include/gudhi/Contraction/CGAL_queue/Modifiable_priority_queue.h b/src/Contraction/include/gudhi/Contraction/CGAL_queue/Modifiable_priority_queue.h index 28ae535d..5a55c513 100644 --- a/src/Contraction/include/gudhi/Contraction/CGAL_queue/Modifiable_priority_queue.h +++ b/src/Contraction/include/gudhi/Contraction/CGAL_queue/Modifiable_priority_queue.h @@ -16,8 +16,8 @@ // // Author(s) : Fernando Cacciola // -#ifndef CONTRACTION_CGAL_MODIFIABLE_PRIORITY_QUEUE_H -#define CONTRACTION_CGAL_MODIFIABLE_PRIORITY_QUEUE_H +#ifndef CONTRACTION_CGAL_QUEUE_MODIFIABLE_PRIORITY_QUEUE_H_ +#define CONTRACTION_CGAL_QUEUE_MODIFIABLE_PRIORITY_QUEUE_H_ #define CGAL_SURFACE_MESH_SIMPLIFICATION_USE_RELAXED_HEAP @@ -98,4 +98,4 @@ class Modifiable_priority_queue { } // namespace CGAL -#endif // CONTRACTION_CGAL_MODIFIABLE_PRIORITY_QUEUE_H +#endif // CONTRACTION_CGAL_QUEUE_MODIFIABLE_PRIORITY_QUEUE_H_ diff --git a/src/Contraction/include/gudhi/Contraction/policies/Edge_length_cost.h b/src/Contraction/include/gudhi/Contraction/policies/Edge_length_cost.h index e4beb220..dac2d448 100644 --- a/src/Contraction/include/gudhi/Contraction/policies/Edge_length_cost.h +++ b/src/Contraction/include/gudhi/Contraction/policies/Edge_length_cost.h @@ -20,8 +20,8 @@ * along with this program. If not, see . */ -#ifndef CONTRACTION_POLICIES_DUMMY_EDGE_LENGTH_COST_H_ -#define CONTRACTION_POLICIES_DUMMY_EDGE_LENGTH_COST_H_ +#ifndef CONTRACTION_POLICIES_EDGE_LENGTH_COST_H_ +#define CONTRACTION_POLICIES_EDGE_LENGTH_COST_H_ #include @@ -53,4 +53,4 @@ class Edge_length_cost : public Cost_policy { } // namespace Gudhi -#endif // CONTRACTION_POLICIES_DUMMY_EDGE_LENGTH_COST_H_ +#endif // CONTRACTION_POLICIES_EDGE_LENGTH_COST_H_ diff --git a/src/GudhUI/utils/Edge_collapsor.h b/src/GudhUI/utils/Edge_collapsor.h index fcf2a248..151e9b01 100644 --- a/src/GudhUI/utils/Edge_collapsor.h +++ b/src/GudhUI/utils/Edge_collapsor.h @@ -21,8 +21,8 @@ * */ -#ifndef UTILS_COLLAPSOR_H_ -#define UTILS_COLLAPSOR_H_ +#ifndef UTILS_EDGE_COLLAPSOR_H_ +#define UTILS_EDGE_COLLAPSOR_H_ #include #include "utils/Edge_contractor.h" @@ -94,4 +94,4 @@ template class Edge_collapsor { } }; -#endif // UTILS_COLLAPSOR_H_ +#endif // UTILS_EDGE_COLLAPSOR_H_ diff --git a/src/GudhUI/utils/Edge_contractor.h b/src/GudhUI/utils/Edge_contractor.h index 053aac04..45079a40 100644 --- a/src/GudhUI/utils/Edge_contractor.h +++ b/src/GudhUI/utils/Edge_contractor.h @@ -94,4 +94,4 @@ template class Edge_contractor { } }; -#endif /* EDGE_CONTRACTOR_H_ */ +#endif // UTILS_EDGE_CONTRACTOR_H_ diff --git a/src/GudhUI/utils/Is_manifold.h b/src/GudhUI/utils/Is_manifold.h index 1b25df34..b6b19ee0 100644 --- a/src/GudhUI/utils/Is_manifold.h +++ b/src/GudhUI/utils/Is_manifold.h @@ -56,7 +56,7 @@ template class Is_manifold { dim = local_dimension(v); break; } - //check that the link of every vertex is a dim-1 sphere + // 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; @@ -90,7 +90,7 @@ template class Is_manifold { 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 + // 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()) diff --git a/src/GudhUI/utils/Vertex_collapsor.h b/src/GudhUI/utils/Vertex_collapsor.h index be03c765..2b36cb3a 100644 --- a/src/GudhUI/utils/Vertex_collapsor.h +++ b/src/GudhUI/utils/Vertex_collapsor.h @@ -24,6 +24,8 @@ #ifndef UTILS_VERTEX_COLLAPSOR_H_ #define UTILS_VERTEX_COLLAPSOR_H_ +#include + #include "utils/Edge_contractor.h" #include "utils/Furthest_point_epsilon_net.h" #include "utils/UI_utils.h" diff --git a/src/GudhUI/view/Viewer.h b/src/GudhUI/view/Viewer.h index 99bd63e4..276ccd3c 100644 --- a/src/GudhUI/view/Viewer.h +++ b/src/GudhUI/view/Viewer.h @@ -21,8 +21,8 @@ * */ -#ifndef VIEW_VIEWER_H -#define VIEW_VIEWER_H +#ifndef VIEW_VIEWER_H_ +#define VIEW_VIEWER_H_ // Workaround for moc-qt4 not parsing boost headers #include @@ -117,4 +117,4 @@ class Viewer : public QGLViewer { void click(const Point_3& position); }; -#endif // VIEW_VIEWER_H +#endif // VIEW_VIEWER_H_ diff --git a/src/GudhUI/view/Viewer_instructor.h b/src/GudhUI/view/Viewer_instructor.h index e1c6af8b..31a1d273 100644 --- a/src/GudhUI/view/Viewer_instructor.h +++ b/src/GudhUI/view/Viewer_instructor.h @@ -21,8 +21,8 @@ * */ -#ifndef VIEW_VIEWER_INSTRUCTOR_H -#define VIEW_VIEWER_INSTRUCTOR_H +#ifndef VIEW_VIEWER_INSTRUCTOR_H_ +#define VIEW_VIEWER_INSTRUCTOR_H_ // todo do a viewer instructor that have directely a pointer to a QGLviewer and buffer ot not triangles @@ -114,4 +114,4 @@ class Viewer_instructor : public QWidget { void change_light(); }; -#endif // VIEW_VIEWER_INSTRUCTOR_H +#endif // VIEW_VIEWER_INSTRUCTOR_H_ diff --git a/src/Hasse_complex/include/gudhi/Hasse_complex.h b/src/Hasse_complex/include/gudhi/Hasse_complex.h index c3a84c02..67079687 100644 --- a/src/Hasse_complex/include/gudhi/Hasse_complex.h +++ b/src/Hasse_complex/include/gudhi/Hasse_complex.h @@ -26,6 +26,8 @@ #include #include +#include // for pair +#include namespace Gudhi { @@ -71,11 +73,10 @@ template < typename FiltrationValue = double > class Hasse_complex { public: - typedef Hasse_simplex Hasse_simp; typedef FiltrationValue Filtration_value; typedef SimplexKey Simplex_key; - typedef int Simplex_handle; //index in vector complex_ + typedef int Simplex_handle; // index in vector complex_ typedef boost::counting_iterator< Simplex_handle > Filtration_simplex_iterator; typedef boost::iterator_range Filtration_simplex_range; @@ -214,8 +215,8 @@ std::istream& operator>>(std::istream & is typename Hasse_complex::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 - { + // read all simplices in the file as a list of vertices + while (read_hasse_simplex(is, boundary, fil)) { // insert every simplex in the simplex tree hcpx.complex_.push_back(Hasse_simplex< Hasse_complex >(key, fil, boundary)); diff --git a/src/Persistent_cohomology/include/gudhi/Persistent_cohomology.h b/src/Persistent_cohomology/include/gudhi/Persistent_cohomology.h index 8c614e96..d096792f 100644 --- a/src/Persistent_cohomology/include/gudhi/Persistent_cohomology.h +++ b/src/Persistent_cohomology/include/gudhi/Persistent_cohomology.h @@ -20,8 +20,8 @@ * along with this program. If not, see . */ -#ifndef SRC_PERSISTENT_COHOMOLOGY_INCLUDE_GUDHI_PERSISTENT_COHOMOLOGY_H_ -#define SRC_PERSISTENT_COHOMOLOGY_INCLUDE_GUDHI_PERSISTENT_COHOMOLOGY_H_ +#ifndef PERSISTENT_COHOMOLOGY_H_ +#define PERSISTENT_COHOMOLOGY_H_ #include #include @@ -38,6 +38,10 @@ #include #include #include // std::ofstream +#include // for numeric_limits<> +#include +#include +#include namespace Gudhi { @@ -709,13 +713,11 @@ class Persistent_cohomology { } } - void write_output_diagram(std::string diagram_name) - { - std::ofstream diagram_out(diagram_name.c_str()); - cmp_intervals_by_length cmp( cpx_ ); + void write_output_diagram(std::string diagram_name) { + std::ofstream diagram_out(diagram_name.c_str()); + cmp_intervals_by_length cmp(cpx_); std::sort(std::begin(persistent_pairs_), std::end(persistent_pairs_), cmp); - for(auto pair : persistent_pairs_) - { + for (auto pair : persistent_pairs_) { diagram_out << cpx_->dimension(get<0>(pair)) << " " << cpx_->filtration(get<0>(pair)) << " " << cpx_->filtration(get<1>(pair)) << std::endl; @@ -774,4 +776,4 @@ class Persistent_cohomology { } // namespace Gudhi -#endif // SRC_PERSISTENT_COHOMOLOGY_INCLUDE_GUDHI_PERSISTENT_COHOMOLOGY_H_ +#endif // PERSISTENT_COHOMOLOGY_H_ diff --git a/src/Persistent_cohomology/include/gudhi/Persistent_cohomology/Field_Zp.h b/src/Persistent_cohomology/include/gudhi/Persistent_cohomology/Field_Zp.h index a12019f8..6db16e69 100644 --- a/src/Persistent_cohomology/include/gudhi/Persistent_cohomology/Field_Zp.h +++ b/src/Persistent_cohomology/include/gudhi/Persistent_cohomology/Field_Zp.h @@ -20,8 +20,8 @@ * along with this program. If not, see . */ -#ifndef SRC_PERSISTENT_COHOMOLOGY_INCLUDE_GUDHI_PERSISTENT_COHOMOLOGY_FIELD_ZP_H_ -#define SRC_PERSISTENT_COHOMOLOGY_INCLUDE_GUDHI_PERSISTENT_COHOMOLOGY_FIELD_ZP_H_ +#ifndef PERSISTENT_COHOMOLOGY_FIELD_ZP_H_ +#define PERSISTENT_COHOMOLOGY_FIELD_ZP_H_ #include #include @@ -113,4 +113,4 @@ class Field_Zp { } // namespace Gudhi -#endif // SRC_PERSISTENT_COHOMOLOGY_INCLUDE_GUDHI_PERSISTENT_COHOMOLOGY_FIELD_ZP_H_ +#endif // PERSISTENT_COHOMOLOGY_FIELD_ZP_H_ diff --git a/src/Persistent_cohomology/include/gudhi/Persistent_cohomology/Multi_field.h b/src/Persistent_cohomology/include/gudhi/Persistent_cohomology/Multi_field.h index 555d696f..0591fc95 100644 --- a/src/Persistent_cohomology/include/gudhi/Persistent_cohomology/Multi_field.h +++ b/src/Persistent_cohomology/include/gudhi/Persistent_cohomology/Multi_field.h @@ -20,8 +20,8 @@ * along with this program. If not, see . */ -#ifndef SRC_PERSISTENT_COHOMOLOGY_INCLUDE_GUDHI_PERSISTENT_COHOMOLOGY_MULTI_FIELD_H_ -#define SRC_PERSISTENT_COHOMOLOGY_INCLUDE_GUDHI_PERSISTENT_COHOMOLOGY_MULTI_FIELD_H_ +#ifndef PERSISTENT_COHOMOLOGY_MULTI_FIELD_H_ +#define PERSISTENT_COHOMOLOGY_MULTI_FIELD_H_ #include @@ -183,4 +183,4 @@ class Multi_field { } // namespace Gudhi -#endif // SRC_PERSISTENT_COHOMOLOGY_INCLUDE_GUDHI_PERSISTENT_COHOMOLOGY_MULTI_FIELD_H_ +#endif // PERSISTENT_COHOMOLOGY_MULTI_FIELD_H_ diff --git a/src/Persistent_cohomology/include/gudhi/Persistent_cohomology/Persistent_cohomology_column.h b/src/Persistent_cohomology/include/gudhi/Persistent_cohomology/Persistent_cohomology_column.h index 568f24df..612658e6 100644 --- a/src/Persistent_cohomology/include/gudhi/Persistent_cohomology/Persistent_cohomology_column.h +++ b/src/Persistent_cohomology/include/gudhi/Persistent_cohomology/Persistent_cohomology_column.h @@ -20,8 +20,8 @@ * along with this program. If not, see . */ -#ifndef SRC_PERSISTENT_COHOMOLOGY_INCLUDE_GUDHI_PERSISTENT_COHOMOLOGY_PERSISTENT_COHOMOLOGY_COLUMN_H_ -#define SRC_PERSISTENT_COHOMOLOGY_INCLUDE_GUDHI_PERSISTENT_COHOMOLOGY_PERSISTENT_COHOMOLOGY_COLUMN_H_ +#ifndef PERSISTENT_COHOMOLOGY_PERSISTENT_COHOMOLOGY_COLUMN_H_ +#define PERSISTENT_COHOMOLOGY_PERSISTENT_COHOMOLOGY_COLUMN_H_ #include #include @@ -138,4 +138,4 @@ class Persistent_cohomology_column : public boost::intrusive::set_base_hook< } // namespace Gudhi -#endif // SRC_PERSISTENT_COHOMOLOGY_INCLUDE_GUDHI_PERSISTENT_COHOMOLOGY_PERSISTENT_COHOMOLOGY_COLUMN_H_ +#endif // PERSISTENT_COHOMOLOGY_PERSISTENT_COHOMOLOGY_COLUMN_H_ diff --git a/src/Simplex_tree/include/gudhi/Simplex_tree.h b/src/Simplex_tree/include/gudhi/Simplex_tree.h index 96565ff1..6e51d107 100644 --- a/src/Simplex_tree/include/gudhi/Simplex_tree.h +++ b/src/Simplex_tree/include/gudhi/Simplex_tree.h @@ -120,7 +120,9 @@ class Simplex_tree { /* Type of node in the simplex tree. */ typedef Simplex_tree_node_explicit_storage Node; /* Type of dictionary Vertex_handle -> Node for traversing the simplex tree. */ - // Note: this wastes space when Vertex_handle is 32 bits and Node is aligned on 64 bits. It would be better to use a flat_set (with our own comparator) where we can control the layout of the struct (put Vertex_handle and Simplex_key next to each other). + // Note: this wastes space when Vertex_handle is 32 bits and Node is aligned on 64 bits. It would be better to use a + // flat_set (with our own comparator) where we can control the layout of the struct (put Vertex_handle and + // Simplex_key next to each other). typedef typename boost::container::flat_map Dictionary; /* \brief Set of nodes sharing a same parent in the simplex tree. */ @@ -131,7 +133,7 @@ class Simplex_tree { Key_simplex_base_real() : key_(-1) {} void assign_key(Simplex_key k) { key_ = k; } Simplex_key key() const { return key_; } - private: + private: Simplex_key key_; }; struct Key_simplex_base_dummy { @@ -145,7 +147,7 @@ class Simplex_tree { Filtration_simplex_base_real() : filt_(0) {} void assign_filtration(Filtration_value f) { filt_ = f; } Filtration_value filtration() const { return filt_; } - private: + private: Filtration_value filt_; }; struct Filtration_simplex_base_dummy { @@ -153,7 +155,8 @@ class Simplex_tree { void assign_filtration(Filtration_value f) { assert(f == 0); } Filtration_value filtration() const { return 0; } }; - typedef typename std::conditional::type Filtration_simplex_base; + typedef typename std::conditional::type Filtration_simplex_base; public: /** \brief Handle type to a simplex contained in the simplicial complex represented @@ -271,7 +274,7 @@ class Simplex_tree { * The filtration must be valid. If the filtration has not been initialized yet, the * method initializes it (i.e. order the simplices). If the complex has changed since the last time the filtration * was initialized, please call `initialize_filtration()` to recompute it. */ - Filtration_simplex_range const& filtration_simplex_range(Indexing_tag=Indexing_tag()) { + Filtration_simplex_range const& filtration_simplex_range(Indexing_tag = Indexing_tag()) { if (filtration_vect_.empty()) { initialize_filtration(); } diff --git a/src/Simplex_tree/include/gudhi/Simplex_tree/Simplex_tree_iterators.h b/src/Simplex_tree/include/gudhi/Simplex_tree/Simplex_tree_iterators.h index f83f5ea8..372ef329 100644 --- a/src/Simplex_tree/include/gudhi/Simplex_tree/Simplex_tree_iterators.h +++ b/src/Simplex_tree/include/gudhi/Simplex_tree/Simplex_tree_iterators.h @@ -20,8 +20,8 @@ * along with this program. If not, see . */ -#ifndef SIMPLEX_TREE_ITERATORS_H_ -#define SIMPLEX_TREE_ITERATORS_H_ +#ifndef SIMPLEX_TREE_SIMPLEX_TREE_ITERATORS_H_ +#define SIMPLEX_TREE_SIMPLEX_TREE_ITERATORS_H_ #include #include @@ -315,4 +315,4 @@ class Simplex_tree_skeleton_simplex_iterator : public boost::iterator_facade< /* @} */ // end addtogroup simplex_tree } // namespace Gudhi -#endif // SIMPLEX_TREE_ITERATORS_H_ +#endif // SIMPLEX_TREE_SIMPLEX_TREE_ITERATORS_H_ diff --git a/src/Simplex_tree/include/gudhi/Simplex_tree/Simplex_tree_node_explicit_storage.h b/src/Simplex_tree/include/gudhi/Simplex_tree/Simplex_tree_node_explicit_storage.h index 7f735b7e..25d4888a 100644 --- a/src/Simplex_tree/include/gudhi/Simplex_tree/Simplex_tree_node_explicit_storage.h +++ b/src/Simplex_tree/include/gudhi/Simplex_tree/Simplex_tree_node_explicit_storage.h @@ -20,8 +20,8 @@ * along with this program. If not, see . */ -#ifndef SIMPLEX_TREE_NODE_EXPLICIT_STORAGE_H_ -#define SIMPLEX_TREE_NODE_EXPLICIT_STORAGE_H_ +#ifndef SIMPLEX_TREE_SIMPLEX_TREE_NODE_EXPLICIT_STORAGE_H_ +#define SIMPLEX_TREE_SIMPLEX_TREE_NODE_EXPLICIT_STORAGE_H_ #include @@ -69,4 +69,4 @@ struct Simplex_tree_node_explicit_storage : SimplexTree::Filtration_simplex_base /* @} */ // end addtogroup simplex_tree } // namespace Gudhi -#endif // SIMPLEX_TREE_NODE_EXPLICIT_STORAGE_H_ +#endif // SIMPLEX_TREE_SIMPLEX_TREE_NODE_EXPLICIT_STORAGE_H_ diff --git a/src/Simplex_tree/include/gudhi/Simplex_tree/Simplex_tree_siblings.h b/src/Simplex_tree/include/gudhi/Simplex_tree/Simplex_tree_siblings.h index 9cdda967..158ee1f7 100644 --- a/src/Simplex_tree/include/gudhi/Simplex_tree/Simplex_tree_siblings.h +++ b/src/Simplex_tree/include/gudhi/Simplex_tree/Simplex_tree_siblings.h @@ -20,8 +20,8 @@ * along with this program. If not, see . */ -#ifndef SIMPLEX_TREE_SIBLINGS_H_ -#define SIMPLEX_TREE_SIBLINGS_H_ +#ifndef SIMPLEX_TREE_SIMPLEX_TREE_SIBLINGS_H_ +#define SIMPLEX_TREE_SIMPLEX_TREE_SIBLINGS_H_ #include @@ -124,4 +124,4 @@ class Simplex_tree_siblings { /* @} */ // end addtogroup simplex_tree } // namespace Gudhi -#endif // SIMPLEX_TREE_SIBLINGS_H_ +#endif // SIMPLEX_TREE_SIMPLEX_TREE_SIBLINGS_H_ diff --git a/src/Simplex_tree/include/gudhi/Simplex_tree/indexing_tag.h b/src/Simplex_tree/include/gudhi/Simplex_tree/indexing_tag.h index a00dac27..0adeb46d 100644 --- a/src/Simplex_tree/include/gudhi/Simplex_tree/indexing_tag.h +++ b/src/Simplex_tree/include/gudhi/Simplex_tree/indexing_tag.h @@ -20,8 +20,8 @@ * along with this program. If not, see . */ -#ifndef INDEXING_TAG_H_ -#define INDEXING_TAG_H_ +#ifndef SIMPLEX_TREE_INDEXING_TAG_H_ +#define SIMPLEX_TREE_INDEXING_TAG_H_ namespace Gudhi { @@ -36,4 +36,4 @@ struct linear_indexing_tag { // struct zigzag_indexing_tag {}; } // namespace Gudhi -#endif // INDEXING_TAG_H_ +#endif // SIMPLEX_TREE_INDEXING_TAG_H_ diff --git a/src/Skeleton_blocker/include/gudhi/Skeleton_blocker_simplifiable_complex.h b/src/Skeleton_blocker/include/gudhi/Skeleton_blocker_simplifiable_complex.h index 705c78bb..17a237a7 100644 --- a/src/Skeleton_blocker/include/gudhi/Skeleton_blocker_simplifiable_complex.h +++ b/src/Skeleton_blocker/include/gudhi/Skeleton_blocker_simplifiable_complex.h @@ -22,12 +22,12 @@ #ifndef SKELETON_BLOCKER_SIMPLIFIABLE_COMPLEX_H_ #define SKELETON_BLOCKER_SIMPLIFIABLE_COMPLEX_H_ +#include + #include #include #include -#include - namespace Gudhi { namespace skbl { @@ -340,7 +340,7 @@ Skeleton_blocker_complex::contract_edge(Vertex_handle a, Vert assert(this->contains_vertex(a)); assert(this->contains_vertex(b)); - if(this->contains_edge(a, b)) + if (this->contains_edge(a, b)) this->add_edge(a, b); // if some blockers passes through 'ab', we need to remove them. diff --git a/src/common/include/gudhi/graph_simplicial_complex.h b/src/common/include/gudhi/graph_simplicial_complex.h index 859504b2..042ef516 100644 --- a/src/common/include/gudhi/graph_simplicial_complex.h +++ b/src/common/include/gudhi/graph_simplicial_complex.h @@ -25,6 +25,10 @@ #include +#include // for pair<> +#include +#include + /* Edge tag for Boost PropertyGraph. */ struct edge_filtration_t { typedef boost::edge_property_tag kind; @@ -79,7 +83,7 @@ Graph_t compute_proximity_graph(PointCloud &points Graph_t skel_graph(edges.begin() , edges.end() , edges_fil.begin() - , idx_u); //number of points labeled from 0 to idx_u-1 + , idx_u); // number of points labeled from 0 to idx_u-1 auto vertex_prop = boost::get(vertex_filtration_t(), skel_graph); -- cgit v1.2.3 From 79b1219d1d6d1547c977050b28e7f4e12a7cc937 Mon Sep 17 00:00:00 2001 From: vrouvrea Date: Fri, 9 Oct 2015 12:41:05 +0000 Subject: Fix clang compile failure - must include iostream to redefine operator<< git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/trunk@846 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: c3c719704415bcd8660123212817eb9ce42c5d2a --- src/Contraction/include/gudhi/Contraction/Edge_profile.h | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/Contraction/include/gudhi/Contraction/Edge_profile.h b/src/Contraction/include/gudhi/Contraction/Edge_profile.h index b6dfd63b..90ca6cdf 100644 --- a/src/Contraction/include/gudhi/Contraction/Edge_profile.h +++ b/src/Contraction/include/gudhi/Contraction/Edge_profile.h @@ -23,6 +23,8 @@ #ifndef CONTRACTION_EDGE_PROFILE_H_ #define CONTRACTION_EDGE_PROFILE_H_ +#include + namespace Gudhi { namespace contraction { @@ -93,9 +95,8 @@ template class Edge_profile { return complex_.point(v1_handle()); } - friend std::ostream& operator<<(std::ostream& o, const Edge_profile & v) { - o << "v0:" << v.v0_handle() << " v1:" << v.v1_handle(); - return o; + friend std::ostream& operator<<(std::ostream& o, const Edge_profile& v) { + return o << "v0:" << v.v0_handle() << " v1:" << v.v1_handle(); } private: -- cgit v1.2.3 From e448c1916b0f01e926f5bd65be24d1866cf910f1 Mon Sep 17 00:00:00 2001 From: vrouvrea Date: Fri, 9 Oct 2015 15:56:10 +0000 Subject: osteram is sufficient enough - iostream before git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/trunk@847 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 53ea9daa092a111b843535bad27f6a03cd6ce55a --- src/Contraction/include/gudhi/Contraction/Edge_profile.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/Contraction/include/gudhi/Contraction/Edge_profile.h b/src/Contraction/include/gudhi/Contraction/Edge_profile.h index 90ca6cdf..e4910b27 100644 --- a/src/Contraction/include/gudhi/Contraction/Edge_profile.h +++ b/src/Contraction/include/gudhi/Contraction/Edge_profile.h @@ -23,7 +23,7 @@ #ifndef CONTRACTION_EDGE_PROFILE_H_ #define CONTRACTION_EDGE_PROFILE_H_ -#include +#include namespace Gudhi { -- cgit v1.2.3 From 53c5df01a52987c5d2ea75a3de9523acc076d8a7 Mon Sep 17 00:00:00 2001 From: vrouvrea Date: Mon, 12 Oct 2015 11:41:05 +0000 Subject: Workaround for include(${CGAL_USE_FILE}) in GudhUI and hypergenerator Fix make test issue when cmake in a build directory for SimplexTreeUT and skbl TestGeometricComplex git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/trunk@849 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: d6b35ba4b697c7ee61fcd39b998a0fd717a3716a --- data/points/generator/CMakeLists.txt | 15 +++++++++++++++ src/GudhUI/CMakeLists.txt | 27 +++++++++++++++------------ src/Simplex_tree/test/CMakeLists.txt | 3 +++ src/Skeleton_blocker/test/CMakeLists.txt | 4 ++++ 4 files changed, 37 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/data/points/generator/CMakeLists.txt b/data/points/generator/CMakeLists.txt index 0d045450..26b44446 100644 --- a/data/points/generator/CMakeLists.txt +++ b/data/points/generator/CMakeLists.txt @@ -4,7 +4,22 @@ project(GUDHIPointsGenerator) if(CGAL_FOUND) if (NOT CGAL_VERSION VERSION_LESS 4.6.0) message(STATUS "CGAL version: ${CGAL_VERSION}.") + include( ${CGAL_USE_FILE} ) + # In CMakeLists.txt, when include(${CGAL_USE_FILE}), CXX_FLAGS are overwritten. + # cf. http://doc.cgal.org/latest/Manual/installation.html#title40 + # A workaround is to add "-std=c++11" again. + # A fix would be to use https://cmake.org/cmake/help/v3.1/prop_gbl/CMAKE_CXX_KNOWN_FEATURES.html + # or even better https://cmake.org/cmake/help/v3.1/variable/CMAKE_CXX_STANDARD.html + # but it implies to use cmake version 3.1 at least. + if(NOT MSVC) + include(CheckCXXCompilerFlag) + CHECK_CXX_COMPILER_FLAG(-std=c++11 COMPILER_SUPPORTS_CXX11) + if(COMPILER_SUPPORTS_CXX11) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") + endif() + endif() + # - End of workaround find_package(Eigen3 3.1.0) if (EIGEN3_FOUND) diff --git a/src/GudhUI/CMakeLists.txt b/src/GudhUI/CMakeLists.txt index e896f42c..71f4fd1a 100644 --- a/src/GudhUI/CMakeLists.txt +++ b/src/GudhUI/CMakeLists.txt @@ -18,20 +18,23 @@ if ( CGAL_FOUND AND QT4_FOUND AND OPENGL_FOUND AND QGLVIEWER_FOUND ) LINK_DIRECTORIES(${Boost_LIBRARY_DIRS}) include(${QT_USE_FILE}) - include(${CGAL_USE_FILE}) -if(MSVC) - # Turn off some VC++ warnings - SET (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4267 /wd4668 /wd4311 /wd4800 /wd4820 /wd4503 /wd4244 /wd4345 /wd4996 /wd4396 /wd4018") -else() - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O2 -std=c++11 -Wall -Wpedantic -Wsign-compare") - set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -ggdb -O0") - set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}") -endif() + include(${CGAL_USE_FILE}) + # In CMakeLists.txt, when include(${CGAL_USE_FILE}), CXX_FLAGS are overwritten. + # cf. http://doc.cgal.org/latest/Manual/installation.html#title40 + # A workaround is to add "-std=c++11" again. + # A fix would be to use https://cmake.org/cmake/help/v3.1/prop_gbl/CMAKE_CXX_KNOWN_FEATURES.html + # or even better https://cmake.org/cmake/help/v3.1/variable/CMAKE_CXX_STANDARD.html + # but it implies to use cmake version 3.1 at least. + if(NOT MSVC) + include(CheckCXXCompilerFlag) + CHECK_CXX_COMPILER_FLAG(-std=c++11 COMPILER_SUPPORTS_CXX11) + if(COMPILER_SUPPORTS_CXX11) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") + endif() + endif() + # - End of workaround -message("CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS}") -message("CMAKE_CXX_FLAGS_DEBUG ${CMAKE_CXX_FLAGS_DEBUG}") -message("CMAKE_CXX_FLAGS_RELEASE ${CMAKE_CXX_FLAGS_RELEASE}") include_directories (${QGLVIEWER_INCLUDE_DIR}) include_directories(.) diff --git a/src/Simplex_tree/test/CMakeLists.txt b/src/Simplex_tree/test/CMakeLists.txt index b6a1c0b6..c9eae163 100644 --- a/src/Simplex_tree/test/CMakeLists.txt +++ b/src/Simplex_tree/test/CMakeLists.txt @@ -17,6 +17,9 @@ endif() add_executable ( SimplexTreeUT simplex_tree_unit_test.cpp ) target_link_libraries(SimplexTreeUT ${Boost_SYSTEM_LIBRARY} ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY}) +# Do not forget to copy test files in current binary dir +file(COPY "simplex_tree_for_unit_test.txt" DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/) + # Unitary tests add_test(NAME SimplexTreeUT COMMAND ${CMAKE_CURRENT_BINARY_DIR}/SimplexTreeUT diff --git a/src/Skeleton_blocker/test/CMakeLists.txt b/src/Skeleton_blocker/test/CMakeLists.txt index e62600a2..8b6fb672 100644 --- a/src/Skeleton_blocker/test/CMakeLists.txt +++ b/src/Skeleton_blocker/test/CMakeLists.txt @@ -18,6 +18,10 @@ add_executable(TestSkeletonBlockerComplex TestSkeletonBlockerComplex.cpp) add_executable(TestSimplifiable TestSimplifiable.cpp) add_executable(TestGeometricComplex TestGeometricComplex.cpp) +# Do not forget to copy test files in current binary dir +file(COPY "test.off" DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/) +file(COPY "test2.off" DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/) + add_test(TestSkeletonBlockerComplex ${CMAKE_CURRENT_BINARY_DIR}/TestSkeletonBlockerComplex) add_test(TestSimplifiable ${CMAKE_CURRENT_BINARY_DIR}/TestSimplifiable) add_test(TestGeometricComplex ${CMAKE_CURRENT_BINARY_DIR}/TestGeometricComplex) -- cgit v1.2.3 From 6fd64ffb734f09eeb40aade1efa2e03666eb65b9 Mon Sep 17 00:00:00 2001 From: vrouvrea Date: Mon, 12 Oct 2015 14:57:19 +0000 Subject: Fix program_options issue with MSVC git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/trunk@850 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: b2a90b0c494f0eae1da67e23527946733d501643 --- src/Persistent_cohomology/example/CMakeLists.txt | 66 ++++++++++++------------ 1 file changed, 33 insertions(+), 33 deletions(-) (limited to 'src') diff --git a/src/Persistent_cohomology/example/CMakeLists.txt b/src/Persistent_cohomology/example/CMakeLists.txt index 435d2f58..ea69352e 100644 --- a/src/Persistent_cohomology/example/CMakeLists.txt +++ b/src/Persistent_cohomology/example/CMakeLists.txt @@ -2,43 +2,43 @@ cmake_minimum_required(VERSION 2.6) project(GUDHIExPersCohom) # problem with Visual Studio link on Boost program_options -if (NOT MSVC) - add_executable(persistence_from_simple_simplex_tree persistence_from_simple_simplex_tree.cpp) - target_link_libraries(persistence_from_simple_simplex_tree ${Boost_SYSTEM_LIBRARY}) - add_test(persistence_from_simple_simplex_tree ${CMAKE_CURRENT_BINARY_DIR}/persistence_from_simple_simplex_tree 1 0) +add_definitions( -DBOOST_ALL_NO_LIB ) +add_definitions( -DBOOST_ALL_DYN_LINK ) - add_executable(rips_persistence rips_persistence.cpp) - target_link_libraries(rips_persistence ${Boost_SYSTEM_LIBRARY} ${Boost_PROGRAM_OPTIONS_LIBRARY}) - - add_test(rips_persistence_3 ${CMAKE_CURRENT_BINARY_DIR}/rips_persistence ${CMAKE_SOURCE_DIR}/data/points/Kl.txt -r 0.25 -d 3 -p 3 -m 100) - - add_executable(persistence_from_file persistence_from_file.cpp) - target_link_libraries(persistence_from_file ${Boost_SYSTEM_LIBRARY} ${Boost_PROGRAM_OPTIONS_LIBRARY}) - add_test(persistence_from_file_3_2_0 ${CMAKE_CURRENT_BINARY_DIR}/persistence_from_file ${CMAKE_SOURCE_DIR}/data/points/bunny_5000.st -p 2 -m 0) - add_test(persistence_from_file_3_3_100 ${CMAKE_CURRENT_BINARY_DIR}/persistence_from_file ${CMAKE_SOURCE_DIR}/data/points/bunny_5000.st -p 3 -m 100) - - if(GMPXX_FOUND AND GMP_FOUND) - message("GMPXX_LIBRARIES = ${GMPXX_LIBRARIES}") - message("GMP_LIBRARIES = ${GMP_LIBRARIES}") +add_executable(persistence_from_simple_simplex_tree persistence_from_simple_simplex_tree.cpp) +target_link_libraries(persistence_from_simple_simplex_tree ${Boost_SYSTEM_LIBRARY}) +add_test(persistence_from_simple_simplex_tree ${CMAKE_CURRENT_BINARY_DIR}/persistence_from_simple_simplex_tree 1 0) + +add_executable(rips_persistence rips_persistence.cpp) +target_link_libraries(rips_persistence ${Boost_SYSTEM_LIBRARY} ${Boost_PROGRAM_OPTIONS_LIBRARY}) - add_executable(rips_multifield_persistence rips_multifield_persistence.cpp ) - target_link_libraries(rips_multifield_persistence ${Boost_SYSTEM_LIBRARY} ${Boost_PROGRAM_OPTIONS_LIBRARY} ${GMPXX_LIBRARIES} ${GMP_LIBRARIES}) - add_test(rips_multifield_persistence_2_71 ${CMAKE_CURRENT_BINARY_DIR}/rips_multifield_persistence ${CMAKE_SOURCE_DIR}/data/points/Kl.txt -r 0.25 -d 3 -p 2 -q 71 -m 100) +add_test(rips_persistence_3 ${CMAKE_CURRENT_BINARY_DIR}/rips_persistence ${CMAKE_SOURCE_DIR}/data/points/Kl.txt -r 0.25 -d 3 -p 3 -m 100) - add_executable ( performance_rips_persistence performance_rips_persistence.cpp ) - target_link_libraries(performance_rips_persistence ${Boost_SYSTEM_LIBRARY} ${Boost_PROGRAM_OPTIONS_LIBRARY} ${GMPXX_LIBRARIES} ${GMP_LIBRARIES}) +add_executable(persistence_from_file persistence_from_file.cpp) +target_link_libraries(persistence_from_file ${Boost_SYSTEM_LIBRARY} ${Boost_PROGRAM_OPTIONS_LIBRARY}) +add_test(persistence_from_file_3_2_0 ${CMAKE_CURRENT_BINARY_DIR}/persistence_from_file ${CMAKE_SOURCE_DIR}/data/points/bunny_5000.st -p 2 -m 0) +add_test(persistence_from_file_3_3_100 ${CMAKE_CURRENT_BINARY_DIR}/persistence_from_file ${CMAKE_SOURCE_DIR}/data/points/bunny_5000.st -p 3 -m 100) - if(CGAL_FOUND) - if (CMAKE_BUILD_TYPE MATCHES Debug) - # For programs to be more verbose - add_definitions(-DDEBUG_TRACES) - endif() +if(GMPXX_FOUND AND GMP_FOUND) + message("GMPXX_LIBRARIES = ${GMPXX_LIBRARIES}") + message("GMP_LIBRARIES = ${GMP_LIBRARIES}") - add_executable(alpha_shapes_persistence alpha_shapes_persistence.cpp) - target_link_libraries(alpha_shapes_persistence ${Boost_SYSTEM_LIBRARY} ${GMPXX_LIBRARIES} ${GMP_LIBRARIES} ${CGAL_LIBRARY}) - add_test(alpha_shapes_persistence_2_0_5 ${CMAKE_CURRENT_BINARY_DIR}/alpha_shapes_persistence ${CMAKE_SOURCE_DIR}/data/points/bunny_5000 2 0.5) - #add_test(alpha_shapes_persistence_3_3_100 ${CMAKE_CURRENT_BINARY_DIR}/alpha_shapes_persistence ${CMAKE_SOURCE_DIR}/data/points/bunny_5000.st -p 3 -m 100) - endif() - + add_executable(rips_multifield_persistence rips_multifield_persistence.cpp ) + target_link_libraries(rips_multifield_persistence ${Boost_SYSTEM_LIBRARY} ${Boost_PROGRAM_OPTIONS_LIBRARY} ${GMPXX_LIBRARIES} ${GMP_LIBRARIES}) + add_test(rips_multifield_persistence_2_71 ${CMAKE_CURRENT_BINARY_DIR}/rips_multifield_persistence ${CMAKE_SOURCE_DIR}/data/points/Kl.txt -r 0.25 -d 3 -p 2 -q 71 -m 100) + + add_executable ( performance_rips_persistence performance_rips_persistence.cpp ) + target_link_libraries(performance_rips_persistence ${Boost_SYSTEM_LIBRARY} ${Boost_PROGRAM_OPTIONS_LIBRARY} ${GMPXX_LIBRARIES} ${GMP_LIBRARIES}) + + if(CGAL_FOUND) + if (CMAKE_BUILD_TYPE MATCHES Debug) + # For programs to be more verbose + add_definitions(-DDEBUG_TRACES) + endif() + add_executable(alpha_shapes_persistence alpha_shapes_persistence.cpp) + target_link_libraries(alpha_shapes_persistence ${Boost_SYSTEM_LIBRARY} ${GMPXX_LIBRARIES} ${GMP_LIBRARIES} ${CGAL_LIBRARY}) + add_test(alpha_shapes_persistence_2_0_5 ${CMAKE_CURRENT_BINARY_DIR}/alpha_shapes_persistence ${CMAKE_SOURCE_DIR}/data/points/bunny_5000 2 0.5) + #add_test(alpha_shapes_persistence_3_3_100 ${CMAKE_CURRENT_BINARY_DIR}/alpha_shapes_persistence ${CMAKE_SOURCE_DIR}/data/points/bunny_5000.st -p 3 -m 100) endif() + endif() -- cgit v1.2.3 From d0938e30da46a8ef0ad2e58ca57ab8df64454831 Mon Sep 17 00:00:00 2001 From: glisse Date: Wed, 14 Oct 2015 11:19:12 +0000 Subject: Update old comment about stable_sort. git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/trunk@856 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 20773a87a3a40113ad8a051be7972289144cd1d7 --- src/Simplex_tree/include/gudhi/Simplex_tree.h | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/Simplex_tree/include/gudhi/Simplex_tree.h b/src/Simplex_tree/include/gudhi/Simplex_tree.h index 6e51d107..4c6a95e8 100644 --- a/src/Simplex_tree/include/gudhi/Simplex_tree.h +++ b/src/Simplex_tree/include/gudhi/Simplex_tree.h @@ -771,12 +771,6 @@ class Simplex_tree { * assigned a Simplex_key corresponding to its order in the filtration (from 0 to m-1 for a * simplicial complex with m simplices). * - * The use of a depth-first traversal of the simplex tree, provided by - * complex_simplex_range(), combined with - * a stable sort is meant to optimize the order of simplices with same - * filtration value. The heuristic consists in inserting the cofaces of a - * simplex as soon as possible. - * * Will be automatically called when calling filtration_simplex_range() * if the filtration has never been initialized yet. */ void initialize_filtration() { @@ -785,7 +779,15 @@ class Simplex_tree { for (Simplex_handle sh : complex_simplex_range()) filtration_vect_.push_back(sh); - // the stable sort ensures the ordering heuristic + /* We use stable_sort here because with libstdc++ it is faster than sort. + * is_before_in_filtration is now a total order, but we used to call + * stable_sort for the following heuristic: + * The use of a depth-first traversal of the simplex tree, provided by + * complex_simplex_range(), combined with a stable sort is meant to + * optimize the order of simplices with same filtration value. The + * heuristic consists in inserting the cofaces of a simplex as soon as + * possible. + */ std::stable_sort(filtration_vect_.begin(), filtration_vect_.end(), is_before_in_filtration(this)); } -- cgit v1.2.3