diff options
132 files changed, 7033 insertions, 6739 deletions
diff --git a/CMakeGUDHIVersion.txt b/CMakeGUDHIVersion.txt new file mode 100644 index 00000000..19d10535 --- /dev/null +++ b/CMakeGUDHIVersion.txt @@ -0,0 +1,6 @@ +set (GUDHI_MAJOR_VERSION 1) +set (GUDHI_MINOR_VERSION 2) +set (GUDHI_PATCH_VERSION 0) +set(GUDHI_VERSION ${GUDHI_MAJOR_VERSION}.${GUDHI_MINOR_VERSION}.${GUDHI_PATCH_VERSION}) + +message(STATUS "GUDHI version : ${GUDHI_VERSION}") diff --git a/CMakeLists.txt b/CMakeLists.txt index bf01caeb..460196d7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,10 @@ cmake_minimum_required(VERSION 2.6) project(GUDHIdev) +include(CMakeGUDHIVersion.txt) +# Generate GUDHI official version file +configure_file(GUDHIVersion.cmake.in "${PROJECT_BINARY_DIR}/GUDHIVersion.cmake" @ONLY) + find_package(Boost REQUIRED COMPONENTS system filesystem unit_test_framework chrono timer program_options thread REQUIRED) set(CMAKE_PREFIX_PATH "${CMAKE_SOURCE_DIR}/src/cmake/modules/") @@ -79,18 +83,16 @@ 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/Alpha_complex/example) add_subdirectory(src/Alpha_complex/test) - 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/GUDHIVersion.cmake.in b/GUDHIVersion.cmake.in new file mode 100644 index 00000000..2f433c1c --- /dev/null +++ b/GUDHIVersion.cmake.in @@ -0,0 +1 @@ +@GUDHI_VERSION@ diff --git a/Version.txt b/Version.txt deleted file mode 100644 index 9084fa2f..00000000 --- a/Version.txt +++ /dev/null @@ -1 +0,0 @@ -1.1.0 diff --git a/data/points/generator/CMakeLists.txt b/data/points/generator/CMakeLists.txt index 0f2674c4..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) @@ -21,6 +36,6 @@ if(CGAL_FOUND) add_test(hypergenerator_in_cube_50000_2 ${CMAKE_CURRENT_BINARY_DIR}/hypergenerator in cube inCube.off 50000 3) endif() else() - message(WARNING "CGAL version: ${CGAL_VERSION} is too old to compile Alpha shapes feature. Version 4.6.0 is required.") + message(WARNING "CGAL version: ${CGAL_VERSION} is too old to compile hypergenerator. Version 4.6.0 is required.") endif () endif() 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/scripts/generate_version.sh b/scripts/generate_version.sh index e7575282..43a54c1c 100755 --- a/scripts/generate_version.sh +++ b/scripts/generate_version.sh @@ -4,19 +4,20 @@ #usage bash generate_version.sh -f DIR : generate even if svn is empty and save library in dir # # 23/06/2015 - Remove source, add biblio, and doc +# 06/10/2015 - Replace static Version.txt with generated GUDHIVersion.cmake file # VERSION CHECK ROOT_DIR=.. -VERSION_FILE="$ROOT_DIR/Version.txt" +VERSION_FILE="$ROOT_DIR/GUDHIVersion.cmake" if [ ! -f $VERSION_FILE ]; then - echo "File not found! : $VERSION_FILE" + echo "File not found! : $VERSION_FILE - Please launch cmake first to generate file" exit 1 fi # SVN STATUS CHECK OR IF FORCED BY USER if [ "$1" != "-f" ] then - SVN_STATUS=`svn status $ROOT_DIR` + SVN_STATUS=`svn status $ROOT_DIR | grep -v $VERSION_FILE` echo $SVN_STATUS fi @@ -44,6 +45,7 @@ mkdir "$VERSION_DIR" # TOP LEVEL FILE COPY cp $VERSION_FILE $VERSION_DIR +cp $ROOT_DIR/CMakeGUDHIVersion.txt $VERSION_DIR cp $ROOT_DIR/README $VERSION_DIR cp $ROOT_DIR/Conventions.txt $VERSION_DIR cp $ROOT_DIR/COPYING $VERSION_DIR @@ -51,6 +53,9 @@ cp -R $ROOT_DIR/data $VERSION_DIR cp $ROOT_DIR/src/CMakeLists.txt $VERSION_DIR 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/Alpha_complex/test/Alpha_complex_unit_test.cpp b/src/Alpha_complex/test/Alpha_complex_unit_test.cpp index b630e999..5633d2c7 100644 --- a/src/Alpha_complex/test/Alpha_complex_unit_test.cpp +++ b/src/Alpha_complex/test/Alpha_complex_unit_test.cpp @@ -46,7 +46,7 @@ BOOST_AUTO_TEST_CASE(ALPHA_DOC_OFF_file) { // Init of an alpha-complex from a OFF file // // ---------------------------------------------------------------------------- - std::string off_file_name("../../../data/points/alphacomplexdoc.off"); + std::string off_file_name("alphacomplexdoc.off"); double max_alpha_square_value = 60.0; std::cout << "========== OFF FILE NAME = " << off_file_name << " - alpha²=" << max_alpha_square_value << "==========" << std::endl; @@ -73,7 +73,7 @@ BOOST_AUTO_TEST_CASE(ALPHA_DOC_OFF_file_filtered) { // Init of an alpha-complex from a OFF file // // ---------------------------------------------------------------------------- - std::string off_file_name("../../../data/points/alphacomplexdoc.off"); + std::string off_file_name("alphacomplexdoc.off"); double max_alpha_square_value = 59.0; std::cout << "========== OFF FILE NAME = " << off_file_name << " - alpha²=" << max_alpha_square_value << "==========" << std::endl; diff --git a/src/Alpha_complex/test/CMakeLists.txt b/src/Alpha_complex/test/CMakeLists.txt index 87b05a3a..847581aa 100644 --- a/src/Alpha_complex/test/CMakeLists.txt +++ b/src/Alpha_complex/test/CMakeLists.txt @@ -21,6 +21,10 @@ if(CGAL_FOUND) add_executable ( AlphaComplexUT Alpha_complex_unit_test.cpp ) target_link_libraries(AlphaComplexUT ${Boost_SYSTEM_LIBRARY} ${CGAL_LIBRARY} ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY}) + + # Do not forget to copy test files in current binary dir + file(COPY "${CMAKE_SOURCE_DIR}/data/points/alphacomplexdoc.off" DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/) + add_test(AlphaComplexUT ${CMAKE_CURRENT_BINARY_DIR}/AlphaComplexUT # XML format for Jenkins xUnit plugin --log_format=XML --log_sink=${CMAKE_SOURCE_DIR}/AlphaComplexUT.xml --log_level=test_suite --report_level=no) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 172f9128..590ae373 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,11 +1,14 @@ cmake_minimum_required(VERSION 2.6) 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) - if (NOT CMAKE_BUILD_TYPE) set(CMAKE_BUILD_TYPE "Release") endif() @@ -35,22 +38,51 @@ else() add_definitions(-DBOOST_ALL_NO_LIB) INCLUDE_DIRECTORIES(${Boost_INCLUDE_DIRS}) - LINK_DIRECTORIES(${Boost_LIBRARY_DIRS}) - include_directories(include/) - - add_subdirectory(example/common) + LINK_DIRECTORIES(${Boost_LIBRARY_DIRS}) + + #--------------------------------------------------------------------------------------- + # Gudhi compilation part + include_directories(include) + + add_subdirectory(example/common) add_subdirectory(example/Simplex_tree) add_subdirectory(example/Persistent_cohomology) add_subdirectory(example/Skeleton_blocker) add_subdirectory(example/Contraction) - add_subdirectory(example/Hasse_complex) add_subdirectory(example/Alpha_complex) - add_subdirectory(example/Bottleneck) + # 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) + #--------------------------------------------------------------------------------------- - # data points generator - add_subdirectory(data/points/generator) + #--------------------------------------------------------------------------------------- + # 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 + set(CONF_INCLUDE_DIRS "${PROJECT_SOURCE_DIR}/include") + configure_file(GUDHIConfig.cmake.in "${PROJECT_BINARY_DIR}/GUDHIConfig.cmake" @ONLY) + configure_file(GUDHIConfigVersion.cmake.in "${PROJECT_BINARY_DIR}/GUDHIConfigVersion.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 share/gudhi) + + # install the include file on "make install" + install(DIRECTORY include/gudhi DESTINATION include) + #--------------------------------------------------------------------------------------- endif() 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 <gudhi/Point.h> +#include <gudhi/Edge_contraction.h> +#include <gudhi/Skeleton_blocker.h> +#include <gudhi/Off_reader.h> + #include <boost/timer/timer.hpp> #include <iostream> -#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<Geometry_trait> { public: - struct Garland_heckbert_vertex : public Simple_geometric_vertex { Error_quadric<Geometry_trait::Point> quadric; }; @@ -68,6 +65,7 @@ typedef Skeleton_blocker_contractor<Complex> Complex_contractor; */ class GH_placement : public Gudhi::contraction::Placement_policy<EdgeProfile> { Complex& complex_; + public: typedef Gudhi::contraction::Placement_policy<EdgeProfile>::Placement_type Placement_type; @@ -91,8 +89,8 @@ class GH_placement : public Gudhi::contraction::Placement_policy<EdgeProfile> { */ class GH_cost : public Gudhi::contraction::Cost_policy<EdgeProfile> { Complex& complex_; - public: + public: typedef Gudhi::contraction::Cost_policy<EdgeProfile>::Cost_type Cost_type; GH_cost(Complex& complex) : complex_(complex) { } @@ -115,13 +113,13 @@ class GH_cost : public Gudhi::contraction::Cost_policy<EdgeProfile> { */ class GH_visitor : public Gudhi::contraction::Contraction_visitor<EdgeProfile> { 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<EdgeProfile> { 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<EdgeProfile>(), - 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<Complex> 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 <http://www.gnu.org/licenses/>.
+ *
*/
#ifndef ERROR_QUADRIC_H_
#define ERROR_QUADRIC_H_
-#include <vector>
-#include <utility>
#include <boost/optional/optional.hpp>
+#include <vector>
+#include <utility>
-template <typename Point> 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<Point> min_cost(double scale=1) const{
- // const double min_determinant = 1e-4 * scale*scale;
- const double min_determinant = 1e-5;
- boost::optional<Point> 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;
- }
-
-
+template <typename Point> 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<Point> min_cost(double scale = 1) const {
+ // const double min_determinant = 1e-4 * scale*scale;
+ const double min_determinant = 1e-5;
+ boost::optional<Point> 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 <http://www.gnu.org/licenses/>. */ +#include <gudhi/Edge_contraction.h> +#include <gudhi/Skeleton_blocker.h> +#include <gudhi/Off_reader.h> +#include <gudhi/Point.h> + #include <boost/timer/timer.hpp> #include <iostream> -#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<Geometry_trait> Complex_geometric_traits; typedef Skeleton_blocker_geometric_complex< Complex_geometric_traits > Complex; @@ -44,62 +43,62 @@ typedef Edge_profile<Complex> Profile; typedef Skeleton_blocker_contractor<Complex> Complex_contractor; template<typename ComplexType> -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 "<<argv[0]<<" ../../../data/meshes/SO3_10000.off 0.3 to load the file ../../data/SO3_10000.off and contract the Rips complex built with paremeter 0.3.\n"; - return -1; - } +int main(int argc, char *argv[]) { + if (argc != 3) { + std::cerr << "Usage " << argv[0] << " ../../../data/meshes/SO3_10000.off 0.3 to load the file " << + "../../data/SO3_10000.off and contract the Rips complex built with paremeter 0.3.\n"; + return -1; + } - Complex complex; + Complex complex; - // load only the points - Skeleton_blocker_off_reader<Complex> off_reader(argv[1],complex,true); - if(!off_reader.is_valid()){ - std::cerr << "Unable to read file:"<<argv[1]<<std::endl; - return EXIT_FAILURE; - } + // load only the points + Skeleton_blocker_off_reader<Complex> 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 "<<complex.num_vertices()<<" vertices"<<std::endl; + std::cout << "Build the Rips complex with " << complex.num_vertices() << " vertices" << std::endl; - build_rips(complex,atof(argv[2])); + build_rips(complex, atof(argv[2])); - boost::timer::auto_cpu_timer t; + boost::timer::auto_cpu_timer t; - std::cout << "Initial complex has "<< - complex.num_vertices()<<" vertices and "<< - complex.num_edges()<<" edges"<<std::endl; + std::cout << "Initial complex has " << + complex.num_vertices() << " vertices and " << + complex.num_edges() << " edges" << std::endl; - Complex_contractor contractor(complex, - new Edge_length_cost<Profile>, - contraction::make_first_vertex_placement<Profile>(), - contraction::make_link_valid_contraction<Profile>(), - contraction::make_remove_popable_blockers_visitor<Profile>()); - contractor.contract_edges(); + Complex_contractor contractor(complex, + new Edge_length_cost<Profile>, + contraction::make_first_vertex_placement<Profile>(), + contraction::make_link_valid_contraction<Profile>(), + contraction::make_remove_popable_blockers_visitor<Profile>()); + 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"<<std::endl; + std::cout << "Final complex has " << + complex.num_vertices() << " vertices, " << + complex.num_edges() << " edges, " << + complex.num_blockers() << " blockers and " << + num_simplices << " simplices" << std::endl; - std::cout << "Time to simplify and enumerate simplices:\n"; + std::cout << "Time to simplify and enumerate simplices:\n"; - return EXIT_SUCCESS; + return EXIT_SUCCESS; } 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..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,76 +16,86 @@ // // Author(s) : Fernando Cacciola <fernando.cacciola@geometryfactory.com> // -#ifndef CGAL_MODIFIABLE_PRIORITY_QUEUE_H -#define 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 -#include <climits> // Neeeded by the following Boost header for CHAR_BIT. #include <boost/optional.hpp> #include <boost/pending/relaxed_heap.hpp> -namespace CGAL { +#include <climits> // Neeeded by the following Boost header for CHAR_BIT. +#include <functional> // for less -template <class IndexedType_ - ,class Compare_ = std::less<IndexedType_> - ,class ID_ = boost::identity_property_map - > -class Modifiable_priority_queue -{ -public: +namespace CGAL { +template <class IndexedType_, class Compare_ = std::less<IndexedType_>, 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<IndexedType,Compare,ID> Heap; + + typedef IndexedType_ IndexedType; + typedef Compare_ Compare; + typedef ID_ ID; + + typedef boost::relaxed_heap<IndexedType, Compare, ID> 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<value_type> extract_top() - { - boost::optional<value_type> 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<value_type> extract_top() { + boost::optional<value_type> r; + if (!empty()) { value_type v = top(); pop(); - r = boost::optional<value_type>(v) ; - } - return r ; + r = boost::optional<value_type>(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_QUEUE_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..e4910b27 100644 --- a/src/Contraction/include/gudhi/Contraction/Edge_profile.h +++ b/src/Contraction/include/gudhi/Contraction/Edge_profile.h @@ -1,130 +1,130 @@ - /* 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 <http://www.gnu.org/licenses/>. - */ - -#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 <http://www.gnu.org/licenses/>. + */ + +#ifndef CONTRACTION_EDGE_PROFILE_H_ +#define CONTRACTION_EDGE_PROFILE_H_ + +#include <ostream> + +namespace Gudhi { namespace contraction { -template<typename GeometricSimplifiableComplex> class Edge_profile{ -public: - typedef GeometricSimplifiableComplex Complex; - typedef typename Complex::GT GT; +template<typename GeometricSimplifiableComplex> 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) { + return o << "v0:" << v.v0_handle() << " v1:" << v.v1_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); - } + 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:"<<v.v0_handle() << " v1:"<<v.v1_handle(); - return o; - } -private: - - GeometricSimplifiableComplex& complex_; - - Edge_handle edge_handle_; - - Vertex_handle v0_; + Vertex_handle v1_; +}; - Vertex_handle v1_; +template<typename EdgeProfile> 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<typename EdgeProfile> 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/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 <http://www.gnu.org/licenses/>. - */ - -#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 <http://www.gnu.org/licenses/>. + */ + +#ifndef CONTRACTION_POLICIES_CONTRACTION_VISITOR_H_ +#define CONTRACTION_POLICIES_CONTRACTION_VISITOR_H_ + +#include <gudhi/Contraction/Edge_profile.h> +#include <boost/optional.hpp> + +namespace Gudhi { namespace contraction { @@ -36,66 +36,56 @@ namespace contraction { *@ingroup contr */ template <typename EdgeProfile> -class Contraction_visitor {//: public Dummy_complex_visitor<typename EdgeProfile::Vertex_handle> { -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<typename EdgeProfile::Vertex_handle> { + 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 <http://www.gnu.org/licenses/>. - */ - -#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 <http://www.gnu.org/licenses/>. + */ + +#ifndef CONTRACTION_POLICIES_COST_POLICY_H_ +#define CONTRACTION_POLICIES_COST_POLICY_H_ #include <boost/optional.hpp> -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<double> Cost_type; + typedef boost::optional<double> Cost_type; - virtual Cost_type operator()(const EdgeProfile& profile, const boost::optional<Point>& placement) const =0; - virtual ~Cost_policy(){ - }; + virtual Cost_type operator()(const EdgeProfile& profile, const boost::optional<Point>& 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 <http://www.gnu.org/licenses/>. - */ - -#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 <http://www.gnu.org/licenses/>. + */ + +#ifndef CONTRACTION_POLICIES_DUMMY_VALID_CONTRACTION_H_ +#define CONTRACTION_POLICIES_DUMMY_VALID_CONTRACTION_H_ + +#include <gudhi/Contraction/policies/Valid_contraction_policy.h> + +namespace Gudhi { namespace contraction { - - - /** - *@brief Policy that accept all edge contraction. - */ -template< typename EdgeProfile> class Dummy_valid_contraction : public Valid_contraction_policy<EdgeProfile>{ -public: - typedef typename EdgeProfile::Point Point; - bool operator()(const EdgeProfile& profile,const boost::optional<Point>& placement){ - return true; - } +/** + *@brief Policy that accept all edge contraction. + */ +template< typename EdgeProfile> +class Dummy_valid_contraction : public Valid_contraction_policy<EdgeProfile> { + public: + typedef typename EdgeProfile::Point Point; + + bool operator()(const EdgeProfile& profile, const boost::optional<Point>& 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..dac2d448 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 <http://www.gnu.org/licenses/>. - */ - -#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 <http://www.gnu.org/licenses/>. + */ -namespace contraction { +#ifndef CONTRACTION_POLICIES_EDGE_LENGTH_COST_H_ +#define CONTRACTION_POLICIES_EDGE_LENGTH_COST_H_ + +#include <gudhi/Contraction/policies/Cost_policy.h> +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<EdgeProfile>{ -public: - typedef typename Cost_policy<EdgeProfile>::Cost_type Cost_type; - typedef typename EdgeProfile::Point Point; - Cost_type operator()(const EdgeProfile& profile, const boost::optional<Point>& 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<EdgeProfile> { + public: + typedef typename Cost_policy<EdgeProfile>::Cost_type Cost_type; + typedef typename EdgeProfile::Point Point; + + Cost_type operator()(const EdgeProfile& profile, const boost::optional<Point>& 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_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 <http://www.gnu.org/licenses/>. - */ - -#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 <http://www.gnu.org/licenses/>. + */ -namespace contraction { +#ifndef CONTRACTION_POLICIES_FIRST_VERTEX_PLACEMENT_H_ +#define CONTRACTION_POLICIES_FIRST_VERTEX_PLACEMENT_H_ + +#include <gudhi/Contraction/policies/Placement_policy.h> + +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<EdgeProfile>{ - -public: - typedef typename EdgeProfile::Point Point; - typedef typename EdgeProfile::Edge_handle Edge_handle; +template< typename EdgeProfile> +class First_vertex_placement : public Placement_policy<EdgeProfile> { + public: + typedef typename EdgeProfile::Point Point; + typedef typename EdgeProfile::Edge_handle Edge_handle; - typedef typename Placement_policy<EdgeProfile>::Placement_type Placement_type; + typedef typename Placement_policy<EdgeProfile>::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 <http://www.gnu.org/licenses/>. - */ - -#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 <http://www.gnu.org/licenses/>. + */ + +#ifndef CONTRACTION_POLICIES_LINK_CONDITION_VALID_CONTRACTION_H_ +#define CONTRACTION_POLICIES_LINK_CONDITION_VALID_CONTRACTION_H_ + +#include <gudhi/Utils.h> +#include <gudhi/Contraction/policies/Valid_contraction_policy.h> + + +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<EdgeProfile>{ -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<Point>& 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<EdgeProfile> { + 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<Point>& 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 <http://www.gnu.org/licenses/>. - */ - -#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 <http://www.gnu.org/licenses/>. + */ + +#ifndef CONTRACTION_POLICIES_MIDDLE_PLACEMENT_H_ +#define CONTRACTION_POLICIES_MIDDLE_PLACEMENT_H_ + +#include <gudhi/Contraction/policies/Placement_policy.h> + +namespace Gudhi { namespace contraction { +template< typename EdgeProfile> +class Middle_placement : public Placement_policy<EdgeProfile> { + 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<EdgeProfile>{ + typedef typename Placement_policy<EdgeProfile>::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<EdgeProfile>::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 <http://www.gnu.org/licenses/>. - */ - -#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 <http://www.gnu.org/licenses/>. + */ + +#ifndef CONTRACTION_POLICIES_PLACEMENT_POLICY_H_ +#define CONTRACTION_POLICIES_PLACEMENT_POLICY_H_ #include <boost/optional.hpp> 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<Point> 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<Point> 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 <http://www.gnu.org/licenses/>. - */ - -#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 <http://www.gnu.org/licenses/>. + */ + +#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<Point>& 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<Point>& 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/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 <http://www.gnu.org/licenses/>. */ -#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 <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> +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 <boost/timer/timer.hpp> #include <iostream> -#include "gudhi/Edge_contraction.h" -#include "gudhi/Skeleton_blocker.h" -#include "gudhi/Off_reader.h" +#include <gudhi/Edge_contraction.h> +#include <gudhi/Skeleton_blocker.h> +#include <gudhi/Off_reader.h> 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 <http://www.gnu.org/licenses/>. */ -#ifndef GUDHI_SKELETON_BLOCKER_CONTRACTOR_H_ -#define GUDHI_SKELETON_BLOCKER_CONTRACTOR_H_ - -#include <memory> -#include <cassert> +#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 <gudhi/Contraction/CGAL_queue/Modifiable_priority_queue.h> +#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 <list> -#include <boost/scoped_array.hpp> -#include <boost/scoped_ptr.hpp> +#include <gudhi/Skeleton_blocker/Skeleton_blocker_complex_visitor.h> +#include <gudhi/Utils.h> -#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 <boost/scoped_array.hpp> +#include <boost/scoped_ptr.hpp> -#include "gudhi/Utils.h" +#include <memory> +#include <cassert> +#include <list> +#include <utility> // for pair +#include <vector> -namespace Gudhi{ +namespace Gudhi { namespace contraction { - - - template <class Profile> -Placement_policy<Profile>* make_first_vertex_placement(){ - return new First_vertex_placement<Profile>(); +Placement_policy<Profile>* make_first_vertex_placement() { + return new First_vertex_placement<Profile>(); } template <class Profile> -Valid_contraction_policy<Profile>* make_link_valid_contraction(){ - return new Link_condition_valid_contraction<Profile>(); +Valid_contraction_policy<Profile>* make_link_valid_contraction() { + return new Link_condition_valid_contraction<Profile>(); } - /** -*@brief Visitor to remove popable blockers after an edge contraction. -*/ + *@brief Visitor to remove popable blockers after an edge contraction. + */ template <class Profile> -class Contraction_visitor_remove_popable : public Contraction_visitor<Profile>{ -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<Profile> { + 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 <class Profile> -Contraction_visitor<Profile>* make_remove_popable_blockers_visitor(){ - return new Contraction_visitor_remove_popable<Profile>(); +Contraction_visitor<Profile>* make_remove_popable_blockers_visitor() { + return new Contraction_visitor_remove_popable<Profile>(); } - - - - - /** *@class Skeleton_blocker_contractor *@brief Class that allows to contract iteratively edges of a simplicial complex. @@ -110,519 +99,489 @@ Contraction_visitor<Profile>* make_remove_popable_blockers_visitor(){ * a topological condition (link condition) or a geometrical condition (normals messed up). * */ -template< -class GeometricSimplifiableComplex, -class EdgeProfile = Edge_profile<GeometricSimplifiableComplex> -> -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 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<Profile> Cost_policy_; - typedef Placement_policy<Profile> Placement_policy_; - typedef Valid_contraction_policy<Profile> Valid_contraction_policy_; - typedef Contraction_visitor<EdgeProfile> Contraction_visitor_; - typedef Edge_profile_factory<EdgeProfile> Edge_profile_factory_; +template<class GeometricSimplifiableComplex, class EdgeProfile = Edge_profile<GeometricSimplifiableComplex>> +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<double> Cost_type; - typedef boost::optional<Point> 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<Profile> Cost_policy_; + typedef Placement_policy<Profile> Placement_policy_; + typedef Valid_contraction_policy<Profile> Valid_contraction_policy_; + typedef Contraction_visitor<EdgeProfile> Contraction_visitor_; + typedef Edge_profile_factory<EdgeProfile> 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<double> Cost_type; + typedef boost::optional<Point> 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<size_type, Undirected_edge_id> - { - 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<size_type, Undirected_edge_id> { + 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<Edge_handle,Compare_cost,Undirected_edge_id> 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<Edge_handle, Compare_cost, Undirected_edge_id> 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> 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<Edge_handle> pop_from_PQ() { - boost::optional<Edge_handle> 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<Point> 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_handle> 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<std::pair<Edge_handle,Placement_type > > top_edge(){ - boost::optional<std::pair<Edge_handle,Placement_type > > 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<Profile>), - placement_policy_(new First_vertex_placement<Profile>), - valid_contraction_policy_(new Link_condition_valid_contraction<Profile>), - 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<Profile>, - Valid_contraction_policy_ * valid_contraction_policy = new Link_condition_valid_contraction<Profile>, - 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<Edge_handle> 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<Edge_handle> 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<Edge_handle> ax(complex_[std::make_pair(a,x)]); - boost::optional<Edge_handle> 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_> cost_policy_; - std::shared_ptr<Placement_policy_> placement_policy_; - std::shared_ptr<Valid_contraction_policy_> valid_contraction_policy_; - std::shared_ptr<Contraction_visitor_> 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_profile_factory_; - Edge_data_array edge_data_array_ ; - - boost::scoped_ptr<PQ> 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> 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<Edge_handle> pop_from_PQ() { + boost::optional<Edge_handle> 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<Point> 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_handle> 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<std::pair<Edge_handle, Placement_type > > top_edge() { + boost::optional<std::pair<Edge_handle, Placement_type > > 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<Profile>), + placement_policy_(new First_vertex_placement<Profile>), + valid_contraction_policy_(new Link_condition_valid_contraction<Profile>), + 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<Profile>, + Valid_contraction_policy_ * valid_contraction_policy = + new Link_condition_valid_contraction<Profile>, + 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<Edge_handle> 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<Edge_handle> 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<Edge_handle> ax(complex_[std::make_pair(a, x)]); + boost::optional<Edge_handle> 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_> cost_policy_; + std::shared_ptr<Placement_policy_> placement_policy_; + std::shared_ptr<Valid_contraction_policy_> valid_contraction_policy_; + std::shared_ptr<Contraction_visitor_> 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_profile_factory_; + Edge_data_array edge_data_array_; + + boost::scoped_ptr<PQ> 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/Doxyfile b/src/Doxyfile index 0724de1c..90884779 100644 --- a/src/Doxyfile +++ b/src/Doxyfile @@ -832,10 +832,16 @@ EXAMPLE_RECURSIVE = NO # that contain images that are to be included in the documentation (see the # \image command). +<<<<<<< .working IMAGE_PATH = doc/Skeleton_blocker/ \ doc/Alpha_complex/ \ doc/common/ \ doc/Contraction/ +======= +IMAGE_PATH = doc/Skeleton_blocker/ \ + doc/common/ \ + doc/Contraction/ +>>>>>>> .merge-right.r851 # The INPUT_FILTER tag can be used to specify a program that doxygen should diff --git a/src/GUDHIConfig.cmake.in b/src/GUDHIConfig.cmake.in new file mode 100644 index 00000000..02b540dc --- /dev/null +++ b/src/GUDHIConfig.cmake.in @@ -0,0 +1,7 @@ +# - Config file for the GUDHI package +# It defines the following variables +# GUDHI_INCLUDE_DIRS - include directories for GUDHI + +# Compute paths +set(GUDHI_INCLUDE_DIRS "@CONF_INCLUDE_DIRS@") + 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() diff --git a/src/GudhUI/CMakeLists.txt b/src/GudhUI/CMakeLists.txt index 9348868a..71f4fd1a 100644 --- a/src/GudhUI/CMakeLists.txt +++ b/src/GudhUI/CMakeLists.txt @@ -6,10 +6,6 @@ find_package(Qt4) find_package(QGLViewer) find_package(OpenGL) -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}") - if ( CGAL_FOUND AND QT4_FOUND AND OPENGL_FOUND AND QGLVIEWER_FOUND ) set( QT_USE_QTXML TRUE ) set( QT_USE_QTMAIN TRUE ) @@ -22,7 +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}) + # 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 + include_directories (${QGLVIEWER_INCLUDE_DIR}) include_directories(.) 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 <http://www.gnu.org/licenses/>. + */ + #include "MainWindow.h" #include <QWidget> @@ -6,292 +28,271 @@ #include <fenv.h> - #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 "<<num_collapses<< " vertices\n"; - model_.contract_edges(num_collapses); - update_view(); +MainWindow::contract_edges(unsigned num_collapses) { + std::cerr << "Collapse " << num_collapses << " vertices\n"; + model_.contract_edges(num_collapses); + update_view(); } - void -MainWindow::collapse_edges(){ - model_.collapse_edges(model_.num_edges()); - update_view(); +MainWindow::collapse_edges() { + model_.collapse_edges(model_.num_edges()); + update_view(); } - - void -MainWindow::collapse_vertices(){ - std::cerr <<"Collapse vertices edges\n"; - model_.collapse_vertices(0); - update_view(); +MainWindow::collapse_vertices() { + std::cerr << "Collapse vertices edges\n"; + model_.collapse_vertices(0); + update_view(); } - void -MainWindow::uniform_noise(){ - bool ok; - double amplitude = QInputDialog::getDouble(this, tr("Uniform noise"), - tr("Amplitude:"), 0, 0, 10000, 3, &ok); - srand(time(NULL)); - if (ok) - model_.uniform_noise(amplitude); +MainWindow::uniform_noise() { + bool ok; + double amplitude = QInputDialog::getDouble(this, tr("Uniform noise"), + tr("Amplitude:"), 0, 0, 10000, 3, &ok); + srand(time(NULL)); + if (ok) + model_.uniform_noise(amplitude); } - void -MainWindow::lloyd(){ - //todo 1 ask lloyd parameters - model_.lloyd(0,0); - update_view(); +MainWindow::lloyd() { + // todo 1 ask lloyd parameters + model_.lloyd(0, 0); + update_view(); } void -MainWindow::show_homology_group(){ - model_.show_homology_group(); +MainWindow::show_homology_group() { + model_.show_homology_group(); } void -MainWindow::show_euler_characteristic(){ - model_.show_euler_characteristic(); +MainWindow::show_euler_characteristic() { + model_.show_euler_characteristic(); } - - void -MainWindow::persistence_menu(){ - menu_persistence_->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 <http://www.gnu.org/licenses/>. + */ + +#ifndef GUI_MAINWINDOW_H_ +#define GUI_MAINWINDOW_H_ // Workaround for moc-qt4 not parsing boost headers #include <CGAL/config.h> @@ -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 <http://www.gnu.org/licenses/>. */ -#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<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::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<double>(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<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::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 <http://www.gnu.org/licenses/>. */ -#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 <CGAL/config.h> @@ -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 <http://www.gnu.org/licenses/>. */ - #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 <http://www.gnu.org/licenses/>. */ -#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 <QMainWindow> #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 <QMainWindow> #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 <http://www.gnu.org/licenses/>. + * */ - - - - #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 <http://www.gnu.org/licenses/>. + * */ -#ifndef MENU_UNIFORM_NEIGHBORS_H_ -#define MENU_UNIFORM_NEIGHBORS_H_ +#ifndef GUI_MENU_UNIFORM_NEIGHBORS_H_ +#define GUI_MENU_UNIFORM_NEIGHBORS_H_ #include <QMainWindow> #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 --- a/src/GudhUI/gui/Viewer.cpp +++ /dev/null diff --git a/src/GudhUI/gui/Viewer_instructor.cpp b/src/GudhUI/gui/Viewer_instructor.cpp deleted file mode 100644 index e69de29b..00000000 --- a/src/GudhUI/gui/Viewer_instructor.cpp +++ /dev/null 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 <http://www.gnu.org/licenses/>.
+ *
+ */
+
#include "MainWindow.h"
#include <QApplication>
#include <CGAL/Qt/resources.h>
+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 <http://www.gnu.org/licenses/>. + * */ -#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 <gudhi/Skeleton_blocker/Skeleton_blocker_simple_geometric_traits.h> +#include <gudhi/Skeleton_blocker_geometric_complex.h> #include <CGAL/Kernel_d/Point_d.h> - #include <CGAL/Cartesian.h> #include <CGAL/Cartesian_d.h> - struct Geometry_trait : public CGAL::Cartesian_d<double> { - typedef CGAL::Cartesian<double>::Point_3 Point_3; - typedef CGAL::Cartesian<double>::Vector_3 Vector_3; - typedef CGAL::Point_d<Cartesian_d<double>> Point; - typedef CGAL::Vector_d<Cartesian_d<double>> Vector; + typedef CGAL::Cartesian<double>::Point_3 Point_3; + typedef CGAL::Cartesian<double>::Vector_3 Vector_3; + typedef CGAL::Point_d<Cartesian_d<double>> Point; + typedef CGAL::Vector_d<Cartesian_d<double>> Vector; }; typedef Geometry_trait::Point Point; - using namespace Gudhi; using namespace Gudhi::skbl; typedef Skeleton_blocker_simple_geometric_traits<Geometry_trait> 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 <http://www.gnu.org/licenses/>. + * */ -#ifndef MODEL_H_ -#define MODEL_H_ +#ifndef MODEL_MODEL_H_ +#define MODEL_MODEL_H_ + +#include <gudhi/Clock.h> +#include <gudhi/Skeleton_blocker/Skeleton_blocker_simple_geometric_traits.h> +#include <gudhi/Skeleton_blocker_geometric_complex.h> +#include <gudhi/Off_reader.h> + +#include <CGAL/Euclidean_distance.h> #include <fstream> #include <limits> -#include "gudhi/Clock.h" +#include <string> +#include <vector> + #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 <CGAL/Euclidean_distance.h> - - template<typename Complex> -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<double>& coords){ - Point p(coords.size(),coords.begin(),coords.end()); - complex_.add_vertex(p); - } - - void maximal_face(std::vector<int> 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 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<double>& coords) { + Point p(coords.size(), coords.begin(), coords.end()); + complex_.add_vertex(p); + } + + void maximal_face(std::vector<int> 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<Complex> read_wraper(complex_,false); - Gudhi::read_off(name_file,read_wraper); - } - - void off_points_open(const std::string& name_file){ - UIDBGMSG("load off points",name_file); - complex_.clear(); - CGAL_geometric_flag_complex_wrapper<Complex> read_wraper(complex_,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<double> 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<Complex> 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<Complex> rips_builder(complex_,alpha); - } - - void build_k_nearest_neighbors(unsigned k){ - UIDBG("build_k_nearest"); - complex_.keep_only_vertices(); - K_nearest_builder<Complex> 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<Complex> 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<Complex> collapsor(complex_,complex_.num_vertices()); - UIDBGMSG("num vertices collapsed:",old_num_vertices - complex_.num_vertices()); - } - - void collapse_edges(unsigned num_collapses){ - Edge_collapsor<Complex> 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<int>::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(){ +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<Complex> read_wraper(complex_, false); + Gudhi::read_off(name_file, read_wraper); + } + + void off_points_open(const std::string& name_file) { + UIDBGMSG("load off points", name_file); + complex_.clear(); + CGAL_geometric_flag_complex_wrapper<Complex> read_wraper(complex_, 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<double> 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<Complex> 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<Complex> rips_builder(complex_, alpha); + } + + void build_k_nearest_neighbors(unsigned k) { + UIDBG("build_k_nearest"); + complex_.keep_only_vertices(); + K_nearest_builder<Complex> 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<Complex> 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<Complex> collapsor(complex_, complex_.num_vertices()); + UIDBGMSG("num vertices collapsed:", old_num_vertices - complex_.num_vertices()); + } + + void collapse_edges(unsigned num_collapses) { + Edge_collapsor<Complex> 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<int>::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 "<<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<Complex> persistence(complex_,std::cout,Persistence_params(p,threshold,max_dim,min_pers)); - } - - void show_critical_points(double max_distance){ - Critical_points<Complex> critical_points(complex_,std::cout,max_distance); - } - - void show_is_manifold(){ - unsigned dim; - bool is_manifold; - Is_manifold<Complex> test_manifold(complex_,dim,is_manifold); - - if(is_manifold) std::cout << "The complex is a "<<dim<<"-manifold\n"; - else - if(dim<4) std::cout << "The complex has dimension greater than "<<dim<<" and is not a manifold\n"; - else std::cout << "The complex has dimension>=4 and may or may not be a manifold\n"; - } - - -private: - void run_chomp(){ - 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<Complex> persistence(complex_, std::cout, Persistence_params(p, threshold, max_dim, min_pers)); + } + + void show_critical_points(double max_distance) { + Critical_points<Complex> critical_points(complex_, std::cout, max_distance); + } + + void show_is_manifold() { + unsigned dim; + bool is_manifold; + Is_manifold<Complex> test_manifold(complex_, dim, is_manifold); + + if (is_manifold) { + std::cout << "The complex is a " << dim << "-manifold\n"; + } else { + if (dim < 4) { + std::cout << "The complex has dimension greater than " << dim << " and is not a manifold\n"; + } else { + std::cout << "The complex has dimension>=4 and may or may not be a manifold\n"; + } + } + } + + private: + void run_chomp() { + 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 <deque> +#include <utility> // for pair<> +#include <algorithm> // for sort + #include "utils/Edge_contractor.h" /** @@ -37,101 +36,97 @@ * * todo do a sparsification with some parameter eps while growing */ -template<typename SkBlComplex> class Critical_points{ -private: - SkBlComplex filled_complex_; - const SkBlComplex& input_complex_; - double max_length_; - std::ostream& stream_; -public: - typedef typename SkBlComplex::Vertex_handle Vertex_handle; - typedef typename SkBlComplex::Edge_handle Edge_handle; - typedef typename std::pair<Vertex_handle,Vertex_handle> Edge; - - /** - * @brief check all pair of points with length smaller than max_length - */ - Critical_points(const SkBlComplex& input_complex,std::ostream& stream,double max_length): - input_complex_(input_complex),max_length_(max_length),stream_(stream) - { - - std::deque<Edge> edges; - auto vertices = input_complex.vertex_range(); - for(auto p = vertices.begin(); p!= vertices.end(); ++p){ - filled_complex_.add_vertex(input_complex.point(*p)); - for (auto q = p; ++q != vertices.end(); /**/) - if (squared_eucl_distance(input_complex.point(*p),input_complex.point(*q)) < max_length_*max_length_) - edges.emplace_back(*p,*q); - } - - std::sort(edges.begin(),edges.end(), - [&](Edge e1,Edge e2){ - return squared_edge_length(e1) < squared_edge_length(e2); - }); - - anti_collapse_edges(edges); - - } - -private: - double squared_eucl_distance(const Point& p1,const Point& p2) const{ - return Geometry_trait::Squared_distance_d()(p1,p2); - } - - - void anti_collapse_edges(const std::deque<Edge>& edges){ - unsigned pos = 0; - for(Edge e : edges){ - std::cout<<"edge "<<pos++<<"/"<<edges.size()<<"\n"; - auto eh = filled_complex_.add_edge(e.first,e.second); - int is_contractible(is_link_reducible(eh)); - - switch (is_contractible) { - case 0: - stream_<<"alpha="<<std::sqrt(squared_edge_length(e))<< " topological change"<<std::endl; - break; - case 2: - stream_<<"alpha="<<std::sqrt(squared_edge_length(e))<< " maybe a topological change"<<std::endl; - break; - default: - break; - } - } - - } - - - //0 -> not - //1 -> yes - //2 -> maybe - int is_link_reducible(Edge_handle e){ - auto link = filled_complex_.link(e); - - if(link.empty()) return 0; - - Edge_contractor<Complex> contractor(link,link.num_vertices()-1); - - if(link.num_connected_components()>1) return 0; //one than more CC -> not contractible - - if (link.num_vertices()==1) return 1; //reduced to one point -> contractible - else return 2; //we dont know - } - - - double squared_edge_length(Edge_handle e) const{ - return squared_eucl_distance(input_complex_.point(input_complex_.first_vertex(e)),input_complex_.point(input_complex_.second_vertex(e))); - } - - double squared_edge_length(Edge e) const{ - return squared_eucl_distance(input_complex_.point(e.first),input_complex_.point(e.second)); - } - - - +template<typename SkBlComplex> class Critical_points { + private: + SkBlComplex filled_complex_; + const SkBlComplex& input_complex_; + double max_length_; + std::ostream& stream_; + + public: + typedef typename SkBlComplex::Vertex_handle Vertex_handle; + typedef typename SkBlComplex::Edge_handle Edge_handle; + typedef typename std::pair<Vertex_handle, Vertex_handle> Edge; + + /** + * @brief check all pair of points with length smaller than max_length + */ + Critical_points(const SkBlComplex& input_complex, std::ostream& stream, double max_length) : + input_complex_(input_complex), max_length_(max_length), stream_(stream) { + std::deque<Edge> edges; + auto vertices = input_complex.vertex_range(); + for (auto p = vertices.begin(); p != vertices.end(); ++p) { + filled_complex_.add_vertex(input_complex.point(*p)); + for (auto q = p; ++q != vertices.end(); /**/) + if (squared_eucl_distance(input_complex.point(*p), input_complex.point(*q)) < max_length_ * max_length_) + edges.emplace_back(*p, *q); + } + + std::sort(edges.begin(), edges.end(), + [&](Edge e1, Edge e2) { + return squared_edge_length(e1) < squared_edge_length(e2); + }); + + anti_collapse_edges(edges); + } + + private: + double squared_eucl_distance(const Point& p1, const Point& p2) const { + return Geometry_trait::Squared_distance_d()(p1, p2); + } + + void anti_collapse_edges(const std::deque<Edge>& edges) { + unsigned pos = 0; + for (Edge e : edges) { + std::cout << "edge " << pos++ << "/" << edges.size() << "\n"; + auto eh = filled_complex_.add_edge(e.first, e.second); + int is_contractible(is_link_reducible(eh)); + + switch (is_contractible) { + case 0: + stream_ << "alpha=" << std::sqrt(squared_edge_length(e)) << " topological change" << std::endl; + break; + case 2: + stream_ << "alpha=" << std::sqrt(squared_edge_length(e)) << " maybe a topological change" << std::endl; + break; + default: + break; + } + } + } + + // 0 -> not + // 1 -> yes + // 2 -> maybe + + int is_link_reducible(Edge_handle e) { + auto link = filled_complex_.link(e); + + if (link.empty()) + return 0; + + Edge_contractor<Complex> contractor(link, link.num_vertices() - 1); + + if (link.num_connected_components() > 1) + // one than more CC -> not contractible + return 0; + + if (link.num_vertices() == 1) + // reduced to one point -> contractible + return 1; + else + // we dont know + return 2; + } + + double squared_edge_length(Edge_handle e) const { + return squared_eucl_distance(input_complex_.point(input_complex_.first_vertex(e)), + input_complex_.point(input_complex_.second_vertex(e))); + } + + double squared_edge_length(Edge e) const { + return squared_eucl_distance(input_complex_.point(e.first), input_complex_.point(e.second)); + } }; - - - - -#endif /* CRITICAL_POINTS_H_ */ +#endif // UTILS_CRITICAL_POINTS_H_ diff --git a/src/GudhUI/utils/Edge_collapsor.h b/src/GudhUI/utils/Edge_collapsor.h index 4dcd18ac..151e9b01 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 <http://www.gnu.org/licenses/>. + * */ -#ifndef COLLAPSOR_H_ -#define COLLAPSOR_H_ +#ifndef UTILS_EDGE_COLLAPSOR_H_ +#define UTILS_EDGE_COLLAPSOR_H_ #include <list> #include "utils/Edge_contractor.h" @@ -15,71 +31,67 @@ /** * Iteratively puts every vertex at the center of its neighbors */ -template<typename SkBlComplex> 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<Edge_handle> 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<Edge_handle>& 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<SkBlComplex> 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<typename SkBlComplex> 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<Edge_handle> 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<Edge_handle>& 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<SkBlComplex> 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_EDGE_COLLAPSOR_H_ diff --git a/src/GudhUI/utils/Edge_contractor.h b/src/GudhUI/utils/Edge_contractor.h index d0a1f866..45079a40 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 <http://www.gnu.org/licenses/>. + * */ -#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 <gudhi/Skeleton_blocker_contractor.h> +#include <gudhi/Contraction/Edge_profile.h> +#include <gudhi/Contraction/policies/Cost_policy.h> +#include <vector> /** * Iteratively puts every vertex at the center of its neighbors */ -template<typename SkBlComplex> 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<EdgeProfile>{ - public: - typedef typename contraction::Cost_policy<EdgeProfile>::Cost_type Cost_type; - typedef typename EdgeProfile::Point Point; - Cost_type operator()(const EdgeProfile& profile, const boost::optional<Point>& 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<EdgeProfile>{ - public: - typedef typename contraction::Placement_policy<EdgeProfile>::Placement_type Placement_type; - typedef typename EdgeProfile::Point Point; - Placement_type operator()(const EdgeProfile& profile) const override{ - std::vector<double> mid_coords(profile.p0().dimension(),0); - for (size_t i = 0; i < profile.p0().dimension(); ++i){ - 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<Complex> Profile; - num_contractions = (std::min)((int)num_contractions,(int)(complex_.num_vertices()-1)); - contraction::Skeleton_blocker_contractor<Complex> contractor( - complex_, - new Length_cost<contraction::Edge_profile<Complex>>(), - new Middle_placement<contraction::Edge_profile<Complex>>(), - contraction::make_link_valid_contraction<Profile>(), - contraction::make_remove_popable_blockers_visitor<Profile>() - ); - contractor.contract_edges(num_contractions); - } - - +template<typename SkBlComplex> 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<EdgeProfile> { + public: + typedef typename contraction::Cost_policy<EdgeProfile>::Cost_type Cost_type; + typedef typename EdgeProfile::Point Point; + + Cost_type operator()(const EdgeProfile& profile, const boost::optional<Point>& 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<EdgeProfile> { + public: + typedef typename contraction::Placement_policy<EdgeProfile>::Placement_type Placement_type; + typedef typename EdgeProfile::Point Point; + + Placement_type operator()(const EdgeProfile& profile) const override { + std::vector<double> mid_coords(profile.p0().dimension(), 0); + for (size_t i = 0; i < profile.p0().dimension(); ++i) { + 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<Complex> Profile; + num_contractions = (std::min)(static_cast<int>(num_contractions), static_cast<int>(complex_.num_vertices() - 1)); + typedef typename contraction::Skeleton_blocker_contractor<Complex> Contractor; + Contractor contractor(complex_, + new Length_cost<contraction::Edge_profile < Complex >> (), + new Middle_placement<contraction::Edge_profile < Complex >> (), + contraction::make_link_valid_contraction<Profile>(), + contraction::make_remove_popable_blockers_visitor<Profile>()); + contractor.contract_edges(num_contractions); + } }; - - -#endif /* EDGE_CONTRACTOR_H_ */ +#endif // UTILS_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 <http://www.gnu.org/licenses/>. + * */ -#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 <vector> +#include <algorithm> // for sort + +#include "utils/UI_utils.h" /** * Computes an epsilon net with furthest point strategy. */ -template<typename SkBlComplex> 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_vertex> 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; - } - } - +template<typename SkBlComplex> 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_vertex> 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..b6b19ee0 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<typename SkBlComplex> class Is_manifold{ -private: - const SkBlComplex& input_complex_; - typedef typename SkBlComplex::Vertex_handle Vertex_handle; +template<typename SkBlComplex> class Is_manifold { + private: + const SkBlComplex& input_complex_; + typedef typename SkBlComplex::Vertex_handle Vertex_handle; + public: + /* + * return dim the maximum dimension around one simplex and res which is true if the complex is a manifold. + * If the complex has dimension <= 3 then if res is false, the complex is not a manifold. + * For d-manifold with d>=4, res may be false while the complex is a manifold. + */ + Is_manifold(const SkBlComplex& input_complex, unsigned& dim, bool & res) : input_complex_(input_complex) { + res = true; + dim = -1; + if (!input_complex_.empty()) { + for (auto v : input_complex_.vertex_range()) { + dim = local_dimension(v); + break; + } + // check that the link of every vertex is a dim-1 sphere + for (auto v : input_complex_.vertex_range()) { + if (!is_k_sphere(v, dim - 1)) { + res = false; + break; + } + } + } + } -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<Complex> 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<Complex> contractor(link,link.num_vertices()-1); - return (is_sphere_simplex(link)==k); - } + // A minimal sphere is a complex that contains vertices v1...vn and all faces + // made upon this set except the face {v1,...,vn} + // return -2 if not a minimal sphere + // and d otherwise if complex is a d minimal sphere - // A minimal sphere is a complex that contains vertices v1...vn and all faces - // made upon this set except the face {v1,...,vn} - // return -2 if not a minimal sphere - // and d otherwise if complex is a d minimal sphere - template<typename SubComplex> - int is_sphere_simplex(const SubComplex& complex){ - if(complex.empty()) return -1; - if(complex.num_blockers()!=1) return -2; + template<typename SubComplex> + int is_sphere_simplex(const SubComplex& complex) { + if (complex.empty()) return -1; + if (complex.num_blockers() != 1) return -2; - //necessary and sufficient condition : there exists a unique blocker that passes through all vertices - auto first_blocker = *(complex.const_blocker_range().begin()); + // 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 <http://www.gnu.org/licenses/>. + * */ -#ifndef K_NEAREST_BUILDER_H_ -#define K_NEAREST_BUILDER_H_ +#ifndef UTILS_K_NEAREST_BUILDER_H_ +#define UTILS_K_NEAREST_BUILDER_H_ -#include <unordered_map> -#include <boost/iterator/iterator_facade.hpp> #include <CGAL/Euclidean_distance.h> #include <CGAL/Orthogonal_k_neighbor_search.h> #include <CGAL/Search_traits_d.h> #include <CGAL/Search_traits_adapter.h> -#include <CGAL/property_map.h>
+#include <CGAL/property_map.h> +#include <boost/iterator/iterator_facade.hpp> #include <boost/iterator/zip_iterator.hpp> +#include <unordered_map> +#include <tuple> +#include <list> + #include "utils/UI_utils.h" #include "model/Complex_typedefs.h" - - -template<typename SkBlComplex> class K_nearest_builder{ -private: - - typedef Geometry_trait Kernel; - typedef Point Point_d;
- typedef boost::tuple<Point_d, unsigned> Point_d_with_id;
- typedef CGAL::Search_traits_d<Kernel> Traits_base;
- typedef CGAL::Search_traits_adapter<Point_d_with_id, CGAL::Nth_of_tuple_property_map<0, Point_d_with_id>, Traits_base> Traits;
- typedef CGAL::Orthogonal_k_neighbor_search<Traits> 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<Point_d_with_id> 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<typename SkBlComplex> class K_nearest_builder { + private: + typedef Geometry_trait Kernel; + typedef Point Point_d; + typedef boost::tuple<Point_d, unsigned> Point_d_with_id; + typedef CGAL::Search_traits_d<Kernel> Traits_base; + typedef CGAL::Search_traits_adapter<Point_d_with_id, CGAL::Nth_of_tuple_property_map<0, Point_d_with_id>, + Traits_base> Traits; + typedef CGAL::Orthogonal_k_neighbor_search<Traits> 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<Point_d_with_id> 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 <http://www.gnu.org/licenses/>. + * */ -#ifndef LLOYD_H_ -#define LLOYD_H_ - +#ifndef UTILS_LLOYD_BUILDER_H_ +#define UTILS_LLOYD_BUILDER_H_ #include <vector> +#include <list> /** * Iteratively puts every vertex at the center of its neighbors */ -template<typename SkBlComplex> 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<Point> 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<typename SkBlComplex> 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<Point> 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<double> 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<double> 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 <http://www.gnu.org/licenses/>. + * */ -#ifndef CLOCK_H_ -#define CLOCK_H_ +#ifndef UTILS_MCLOCK_H_ +#define UTILS_MCLOCK_H_ #include <sys/time.h> +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<double>(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 <gudhi/graph_simplicial_complex.h> +#include <gudhi/Simplex_tree.h> +#include <gudhi/distance_functions.h> +#include <gudhi/Persistent_cohomology.h> -#include "gudhi/graph_simplicial_complex.h" -#include "gudhi/Simplex_tree.h" -#include "gudhi/distance_functions.h" -#include "gudhi/Persistent_cohomology.h" +#include <vector> +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<typename SkBlComplex> class Persistence_compute{ -private: - SkBlComplex& complex_; - std::ostream& stream_; -public: - typedef typename SkBlComplex::Vertex_handle Vertex_handle; - typedef typename SkBlComplex::Edge_handle Edge_handle; - - /** - * @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<double> 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<Point_t> ); - 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<typename SkBlComplex> class Persistence_compute { + private: + SkBlComplex& complex_; + std::ostream& stream_; + + public: + typedef typename SkBlComplex::Vertex_handle Vertex_handle; + typedef typename SkBlComplex::Edge_handle Edge_handle; + + /** + * @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<double> 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<Point_t>); + 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 <http://www.gnu.org/licenses/>. + * */ -#ifndef RIPS_BUILDER_H_ -#define RIPS_BUILDER_H_ +#ifndef UTILS_RIPS_BUILDER_H_ +#define UTILS_RIPS_BUILDER_H_ #include <boost/iterator/iterator_facade.hpp> -#include "utils/UI_utils.h" -#include "model/Complex_typedefs.h" #include <CGAL/Euclidean_distance.h> - #include <CGAL/Orthogonal_k_neighbor_search.h> #include <CGAL/Search_traits_d.h> -template<typename SkBlComplex> 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<typename SkBlComplex> 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 a7c0689f..9cc209d3 100644 --- a/src/GudhUI/utils/UI_utils.h +++ b/src/GudhUI/utils/UI_utils.h @@ -1,33 +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 <http://www.gnu.org/licenses/>. + * */ -#ifndef UI_UTILS_H_ -#define UI_UTILS_H_ - -#define PRINT(a) std::cerr << #a << ": " << (a) << " (DISP)"<<std::endl +#ifndef UTILS_UI_UTILS_H_ +#define UTILS_UI_UTILS_H_ #define UIDBG_VERBOSE - #ifdef UIDBG_VERBOSE -#define UIDBG(a) std::cerr << "UIDBG: " << (a)<<std::endl -#define UIDBGMSG(a,b) std::cerr << "UIDBG: " << a<<b<<std::endl -#define UIDBGVALUE(a) std::cerr << "UIDBG: " << #a << ": " << a<<std::endl -#define UIDBGCONT(a) std::cerr << "UIDBG: container "<< #a<<" -> "; for(auto x:a) std::cerr<< x << ","; std::cerr<<std::endl +#define UIDBG(a) std::cerr << "UIDBG: " << (a) << std::endl +#define UIDBGMSG(a, b) std::cerr << "UIDBG: " << a << b << std::endl +#define UIDBGVALUE(a) std::cerr << "UIDBG: " << #a << ": " << a << std::endl +#define UIDBGCONT(a) std::cerr << "UIDBG: container " << #a << " -> "; for (auto x : a) std::cerr << x << ","; std::cerr << std::endl } #else -//#define DBG(a) a -//#define DBGMSG(a,b) b -//#define DBGVALUE(a) a -//#define DBGCONT(a) a +// #define DBG(a) a +// #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..2b36cb3a 100644 --- a/src/GudhUI/utils/Vertex_collapsor.h +++ b/src/GudhUI/utils/Vertex_collapsor.h @@ -1,76 +1,88 @@ -/* - * 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 <http://www.gnu.org/licenses/>. + * */ -#ifndef VERTEX_COLLAPSOR_H_ -#define VERTEX_COLLAPSOR_H_ +#ifndef UTILS_VERTEX_COLLAPSOR_H_ +#define UTILS_VERTEX_COLLAPSOR_H_ + +#include <list> #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<typename SkBlComplex> 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<Vertex_handle> vertices; -// vertices.insert(vertices.begin(),complex_.vertex_range().begin(),complex_.vertex_range().end()); -// UIDBG("Collapse vertices"); -// collapse_vertices(vertices); - - std::list<Vertex_handle> vertices; - - UIDBG("Compute eps net"); - Furthest_point_epsilon_net<Complex> 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<Vertex_handle>& 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<Complex> contractor(link,link.num_vertices()-1); - return (link.num_vertices()==1); - } - +template<typename SkBlComplex> 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<Vertex_handle> vertices; + // vertices.insert(vertices.begin(),complex_.vertex_range().begin(),complex_.vertex_range().end()); + // UIDBG("Collapse vertices"); + // collapse_vertices(vertices); + + std::list<Vertex_handle> vertices; + + UIDBG("Compute eps net"); + Furthest_point_epsilon_net<Complex> 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<Vertex_handle>& 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<Complex> 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 <http://www.gnu.org/licenses/>. + * */ -#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 <http://www.gnu.org/licenses/>. + * */ -#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 <http://www.gnu.org/licenses/>. + * */ -#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 <http://www.gnu.org/licenses/>. + * */ -#ifndef VIEW_PARAMETER_H_ -#define VIEW_PARAMETER_H_ +#ifndef VIEW_VIEW_PARAMETER_H_ +#define VIEW_VIEW_PARAMETER_H_ #include <iostream> @@ -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<VERTEX_MODE>(++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<VERTEX_MODE>(new_mode % V_COUNT); - } - - void change_edge_mode(){ - int current_value = edge_mode; - edge_mode = static_cast<EDGE_MODE>(++current_value % E_COUNT); - } - - void change_edge_mode(int new_mode){ - edge_mode = static_cast<EDGE_MODE>(new_mode % E_COUNT); - } - - - void change_triangle_mode(){ - int current_value = triangle_mode; - triangle_mode = static_cast<TRIANGLE_MODE>(++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<VERTEX_MODE>(a % V_COUNT); - stream>>a; - param.edge_mode = static_cast<EDGE_MODE>(a % E_COUNT); - stream>>a; - param.triangle_mode = static_cast<TRIANGLE_MODE>(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<VERTEX_MODE> (++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<VERTEX_MODE> (new_mode % V_COUNT); + } + + void change_edge_mode() { + int current_value = edge_mode; + edge_mode = static_cast<EDGE_MODE> (++current_value % E_COUNT); + } + + void change_edge_mode(int new_mode) { + edge_mode = static_cast<EDGE_MODE> (new_mode % E_COUNT); + } + + void change_triangle_mode() { + int current_value = triangle_mode; + triangle_mode = static_cast<TRIANGLE_MODE> (++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<VERTEX_MODE> (a % V_COUNT); + stream >> a; + param.edge_mode = static_cast<EDGE_MODE> (a % E_COUNT); + stream >> a; + param.triangle_mode = static_cast<TRIANGLE_MODE> (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 <http://www.gnu.org/licenses/>. + * */ #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<float> (sin(phi) * cos(theta)), + static_cast<float> (sin(phi) * sin(theta)), + static_cast<float> (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..276ccd3c 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 <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#ifndef VIEW_VIEWER_H_
+#define VIEW_VIEWER_H_
// Workaround for moc-qt4 not parsing boost headers
#include <CGAL/config.h>
#include <QGLViewer/qglviewer.h>
+
+#include <vector>
+
#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<Point_3*>& points);
- //todo remove
- void draw_triangles(const std::vector<Point_3*>& 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 <http://www.gnu.org/licenses/>. + * */ #include <utility> + #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<Complex::Point, Complex::Point> 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<Complex::Point,Complex::Point> -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..31a1d273 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 <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#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 <CGAL/config.h>
-#include <memory>
-
#include <QFileDialog>
#include <QKeyEvent>
#include <QGLViewer/camera.h>
+#include <memory>
+#include <utility> // 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<Projector3D> projector_;
-
-
-public:
-
- Viewer_instructor(QWidget* parent,
- Viewer* viewer,
- const Complex& mesh
- );
-
-
- void initialize_bounding_box();
-
- std::pair<Point,Point> 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<Projector3D> 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<Point, Point> 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_
diff --git a/src/Hasse_complex/example/CMakeLists.txt b/src/Hasse_complex/example/CMakeLists.txt deleted file mode 100644 index 564df49d..00000000 --- a/src/Hasse_complex/example/CMakeLists.txt +++ /dev/null @@ -1,5 +0,0 @@ -cmake_minimum_required(VERSION 2.6) -project(GUDHIHasseComplexExample) - -add_executable ( hasse_complex_from_simplex_tree hasse_complex_from_simplex_tree.cpp ) -add_test(hasse_complex_from_simplex_tree ${CMAKE_CURRENT_BINARY_DIR}/hasse_complex_from_simplex_tree) diff --git a/src/Hasse_complex/example/hasse_complex_from_simplex_tree.cpp b/src/Hasse_complex/example/hasse_complex_from_simplex_tree.cpp deleted file mode 100644 index 1de43ab7..00000000 --- a/src/Hasse_complex/example/hasse_complex_from_simplex_tree.cpp +++ /dev/null @@ -1,124 +0,0 @@ -/* This file is part of the Gudhi Library. The Gudhi library - * (Geometric Understanding in Higher Dimensions) is a generic C++ - * library for computational topology. - * - * Author(s): Vincent Rouvreau - * - * Copyright (C) 2014 INRIA Saclay (France) - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#include <iostream> -#include <ctime> -#include "gudhi/graph_simplicial_complex.h" -#include "gudhi/Simplex_tree.h" - -using namespace Gudhi; - -typedef std::vector< Vertex_handle > typeVectorVertex; -typedef std::pair<typeVectorVertex, Filtration_value> typeSimplex; -typedef std::pair< Simplex_tree<>::Simplex_handle, bool > typePairSimplexBool; -typedef Simplex_tree<> typeST; - -int main(int argc, char * const argv[]) { - // TEST OF INSERTION - std::cout << "********************************************************************" << std::endl; - std::cout << "TEST OF INSERTION" << std::endl; - typeST st; - - // ++ FIRST - std::cout << " - INSERT (2,1,0)" << std::endl; - typeVectorVertex SimplexVector1; - SimplexVector1.push_back(2); - SimplexVector1.push_back(1); - SimplexVector1.push_back(0); - st.insert_simplex_and_subfaces(SimplexVector1, 0.3); - - // ++ SECOND - std::cout << " - INSERT 3" << std::endl; - typeVectorVertex SimplexVector2; - SimplexVector2.push_back(3); - st.insert_simplex_and_subfaces(SimplexVector2, 0.1); - - // ++ THIRD - std::cout << " - INSERT (0,3)" << std::endl; - typeVectorVertex SimplexVector3; - SimplexVector3.push_back(3); - SimplexVector3.push_back(0); - st.insert_simplex_and_subfaces(SimplexVector3, 0.2); - - // ++ FOURTH - std::cout << " - INSERT (1,0) (already inserted)" << std::endl; - typeVectorVertex SimplexVector4; - SimplexVector4.push_back(1); - SimplexVector4.push_back(0); - st.insert_simplex_and_subfaces(SimplexVector4, 0.2); - - // ++ FIFTH - std::cout << " - INSERT (3,4,5)" << std::endl; - typeVectorVertex SimplexVector5; - SimplexVector5.push_back(3); - SimplexVector5.push_back(4); - SimplexVector5.push_back(5); - st.insert_simplex_and_subfaces(SimplexVector5, 0.3); - - // ++ SIXTH - std::cout << " - INSERT (0,1,6,7)" << std::endl; - typeVectorVertex SimplexVector6; - SimplexVector6.push_back(0); - SimplexVector6.push_back(1); - SimplexVector6.push_back(6); - SimplexVector6.push_back(7); - st.insert_simplex_and_subfaces(SimplexVector6, 0.4); - - /* Inserted simplex: */ - /* 1 6 */ - /* o---o */ - /* /X\7/ 4 */ - /* o---o---o---o */ - /* 2 0 3\X/ */ - /* o */ - /* 5 */ - - /* In other words: */ - /* A facet [2,1,0] */ - /* An edge [0,3] */ - /* A facet [3,4,5] */ - /* A cell [0,1,6,7] */ - /* A cell [4,5,8,9] */ - /* A facet [9,10,11] */ - /* An edge [11,6] */ - /* An edge [10,12,2] */ - - // ++ GENERAL VARIABLE SET - st.set_filtration(0.4); // Max filtration value - st.set_dimension(3); // Max dimension = 3 -> (0,1,6,7) - - std::cout << "The complex contains " << st.num_simplices() << " simplices - " << st.num_vertices() << " vertices " << std::endl; - std::cout << " - dimension " << st.dimension() << " - filtration " << st.filtration() << std::endl; - std::cout << std::endl << std::endl << "Iterator on Simplices in the filtration, with [filtration value]:" << std::endl; - std::cout << "**************************************************************" << std::endl; - - for( auto f_simplex : st.filtration_simplex_range() ) - { - std::cout << " " << "[" << st.filtration(f_simplex) << "] "; - for( auto vertex : st.simplex_vertex_range(f_simplex) ) - { - std::cout << (int)vertex; - } - } - - return 0; -} diff --git a/src/Hasse_complex/include/gudhi/Hasse_complex.h b/src/Hasse_complex/include/gudhi/Hasse_complex.h index 427d9916..67079687 100644 --- a/src/Hasse_complex/include/gudhi/Hasse_complex.h +++ b/src/Hasse_complex/include/gudhi/Hasse_complex.h @@ -1,208 +1,234 @@ - /* This file is part of the Gudhi Library. The Gudhi library - * (Geometric Understanding in Higher Dimensions) is a generic C++ - * library for computational topology. - * - * Author(s): Clément Maria - * - * Copyright (C) 2014 INRIA Sophia Antipolis-Méditerranée (France) - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#ifndef GUDHI_HASSE_DIAGRAM_H -#define GUDHI_HASSE_DIAGRAM_H +/* This file is part of the Gudhi Library. The Gudhi library + * (Geometric Understanding in Higher Dimensions) is a generic C++ + * library for computational topology. + * + * Author(s): Clément Maria + * + * Copyright (C) 2014 INRIA Sophia Antipolis-Méditerranée (France) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#ifndef HASSE_COMPLEX_H_ +#define HASSE_COMPLEX_H_ -#include <algorithm> #include <boost/iterator/counting_iterator.hpp> -namespace Gudhi{ +#include <algorithm> +#include <utility> // for pair +#include <vector> + +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 ( typename HasseCpx::Simplex_key key + 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 , typename HasseCpx::Filtration_value fil , std::vector<typename HasseCpx::Simplex_handle> boundary) - : key_(key) - , filtration_(fil) - , boundary_(boundary) {} + : key_(key) + , filtration_(fil) + , boundary_(boundary) { } - typename HasseCpx::Simplex_key key_; - typename HasseCpx::Filtration_value filtration_; + typename HasseCpx::Simplex_key key_; + typename HasseCpx::Filtration_value filtration_; std::vector<typename HasseCpx::Simplex_handle> boundary_; }; - - -/** \brief Data structure representing a Hasse diagram, i.e. - * a complex where all codimension 1 incidence - * relations are explicitly encoded. - * - * \implements FilteredComplex - * \ingroup simplex_tree - */ -template < typename FiltrationValue = double - , typename SimplexKey = int - , typename VertexHandle = int - > -class Hasse_complex -{ -public: - - typedef Hasse_simplex<Hasse_complex> Hasse_simp; - typedef FiltrationValue Filtration_value; - typedef SimplexKey Simplex_key; - typedef int Simplex_handle; //index in vector complex_ - - typedef boost::counting_iterator< Simplex_handle > Filtration_simplex_iterator; - typedef boost::iterator_range<Filtration_simplex_iterator> Filtration_simplex_range; - - typedef typename std::vector< Simplex_handle >::iterator Boundary_simplex_iterator; - typedef boost::iterator_range<Boundary_simplex_iterator> Boundary_simplex_range; - - typedef typename std::vector< Simplex_handle >::iterator Skeleton_simplex_iterator; - typedef boost::iterator_range< Skeleton_simplex_iterator > Skeleton_simplex_range; - - -/* only dimension 0 skeleton_simplex_range(...) */ - Skeleton_simplex_range skeleton_simplex_range( int dim = 0 ) { - if(dim != 0) { std::cerr << "Dimension must be 0 \n"; } - return Skeleton_simplex_range(vertices_.begin(),vertices_.end()); +/** \private + * \brief Data structure representing a Hasse diagram, i.e. + * a complex where all codimension 1 incidence + * relations are explicitly encoded. + * + * \implements FilteredComplex + * \ingroup simplex_tree + */ +template < typename FiltrationValue = double +, typename SimplexKey = int +, typename VertexHandle = int +> +class Hasse_complex { + public: + typedef Hasse_simplex<Hasse_complex> Hasse_simp; + typedef FiltrationValue Filtration_value; + typedef SimplexKey Simplex_key; + typedef int Simplex_handle; // index in vector complex_ + + typedef boost::counting_iterator< Simplex_handle > Filtration_simplex_iterator; + typedef boost::iterator_range<Filtration_simplex_iterator> Filtration_simplex_range; + + typedef typename std::vector< Simplex_handle >::iterator Boundary_simplex_iterator; + typedef boost::iterator_range<Boundary_simplex_iterator> Boundary_simplex_range; + + typedef typename std::vector< Simplex_handle >::iterator Skeleton_simplex_iterator; + typedef boost::iterator_range< Skeleton_simplex_iterator > Skeleton_simplex_range; + + /* only dimension 0 skeleton_simplex_range(...) */ + Skeleton_simplex_range skeleton_simplex_range(int dim = 0) { + if (dim != 0) { + std::cerr << "Dimension must be 0 \n"; + } + return Skeleton_simplex_range(vertices_.begin(), vertices_.end()); } template < class Complex_ds > Hasse_complex(Complex_ds & cpx) - : complex_() - , vertices_() - , threshold_(cpx.filtration()) - , num_vertices_() - , dim_max_(cpx.dimension()) - { + : complex_() + , vertices_() + , threshold_(cpx.filtration()) + , num_vertices_() + , dim_max_(cpx.dimension()) { complex_.reserve(cpx.num_simplices()); int idx = 0; - for(auto cpx_sh : cpx.filtration_simplex_range()) - { - complex_.push_back(Hasse_simp(cpx,cpx_sh)); - if(dimension(idx) == 0) { vertices_.push_back(idx); } - ++idx; + for (auto cpx_sh : cpx.filtration_simplex_range()) { + complex_.push_back(Hasse_simp(cpx, cpx_sh)); + if (dimension(idx) == 0) { + vertices_.push_back(idx); + } + ++idx; } } Hasse_complex() - : complex_() - , vertices_() - , threshold_(0) - , num_vertices_(0) - , dim_max_(-1) {} - - size_t num_simplices() { return complex_.size(); } + : complex_() + , vertices_() + , threshold_(0) + , num_vertices_(0) + , dim_max_(-1) { } + + size_t num_simplices() { + return complex_.size(); + } - Filtration_simplex_range filtration_simplex_range() - { return Filtration_simplex_range( Filtration_simplex_iterator(0) - , Filtration_simplex_iterator(complex_.size()) ); } + Filtration_simplex_range filtration_simplex_range() { + return Filtration_simplex_range(Filtration_simplex_iterator(0) + , Filtration_simplex_iterator(complex_.size())); + } - Simplex_key key( Simplex_handle sh ) { return complex_[sh].key_; } + Simplex_key key(Simplex_handle sh) { + return complex_[sh].key_; + } - Simplex_key null_key() { return -1; } + Simplex_key null_key() { + return -1; + } - Simplex_handle simplex( Simplex_key key ) - { - if(key == null_key()) return null_simplex(); + Simplex_handle simplex(Simplex_key key) { + if (key == null_key()) return null_simplex(); return key; } - Simplex_handle null_simplex() { return -1; } + Simplex_handle null_simplex() { + return -1; + } - Filtration_value filtration( Simplex_handle sh ) { - if( sh == null_simplex() ) { return filtration(); } + Filtration_value filtration(Simplex_handle sh) { + if (sh == null_simplex()) { + return filtration(); + } return complex_[sh].filtration_; } - Filtration_value filtration() { return threshold_; } + Filtration_value filtration() { + return threshold_; + } + + int dimension(Simplex_handle sh) { + if (complex_[sh].boundary_.empty()) return 0; + return complex_[sh].boundary_.size() - 1; + } - int dimension ( Simplex_handle sh ) { - if(complex_[sh].boundary_.empty()) return 0; - return complex_[sh].boundary_.size()-1; + int dimension() { + return dim_max_; } - int dimension () { return dim_max_; } - std::pair<Simplex_handle,Simplex_handle> endpoints( Simplex_handle sh ) - { return std::pair<Simplex_handle,Simplex_handle>( complex_[sh].boundary_[0] - , complex_[sh].boundary_[1] ) ;} + std::pair<Simplex_handle, Simplex_handle> endpoints(Simplex_handle sh) { + return std::pair<Simplex_handle, Simplex_handle>(complex_[sh].boundary_[0] + , complex_[sh].boundary_[1]); + } - void assign_key( Simplex_handle sh, Simplex_key key) { complex_[sh].key_ = key; } + void assign_key(Simplex_handle sh, Simplex_key key) { + complex_[sh].key_ = key; + } - Boundary_simplex_range boundary_simplex_range ( Simplex_handle sh ) - { return Boundary_simplex_range( complex_[sh].boundary_.begin() - , complex_[sh].boundary_.end() ); } + Boundary_simplex_range boundary_simplex_range(Simplex_handle sh) { + return Boundary_simplex_range(complex_[sh].boundary_.begin() + , complex_[sh].boundary_.end()); + } - void display_simplex(Simplex_handle sh) - { + void display_simplex(Simplex_handle sh) { std::cout << dimension(sh) << " "; - for(auto sh_b : boundary_simplex_range(sh)) std::cout << sh_b << " "; + for (auto sh_b : boundary_simplex_range(sh)) std::cout << sh_b << " "; std::cout << " " << filtration(sh) << " key=" << key(sh); } - void initialize_filtration() - { + void initialize_filtration() { Simplex_key key = 0; - for(auto & h_simp : complex_) { h_simp.key_ = key; ++key; } + for (auto & h_simp : complex_) { + h_simp.key_ = key; + ++key; + } } - std::vector< Hasse_simp > complex_; + std::vector< Hasse_simp > complex_; std::vector<Simplex_handle> vertices_; - Filtration_value threshold_; - size_t num_vertices_; - int dim_max_; + Filtration_value threshold_; + size_t num_vertices_; + int dim_max_; }; template< typename T1, typename T2, typename T3 > -std::istream& operator>> ( std::istream & is - , Hasse_complex< T1, T2, T3 > & hcpx ) -{ +std::istream& operator>>(std::istream & is + , Hasse_complex< T1, T2, T3 > & hcpx) { assert(hcpx.num_simplices() == 0); size_t num_simp; is >> num_simp; - hcpx.complex_.reserve(num_simp); - - std::vector< typename Hasse_complex<T1,T2,T3>::Simplex_key > boundary; - typename Hasse_complex<T1,T2,T3>::Filtration_value fil; - typename Hasse_complex<T1,T2,T3>::Filtration_value max_fil = 0 ; - int max_dim = -1; - int key = 0 ; - while(read_hasse_simplex( is, boundary, fil )) //read all simplices in the file as a list of vertices - { - //insert every simplex in the simplex tree - hcpx.complex_.push_back( Hasse_simplex< Hasse_complex<T1,T2,T3> >(key,fil,boundary)); - - if(max_dim < hcpx.dimension(key)) { max_dim = hcpx.dimension(key); } - if(hcpx.dimension(key) == 0) { hcpx.vertices_.push_back(key); } - if(max_fil < fil) { max_fil = fil; } + hcpx.complex_.reserve(num_simp); + + std::vector< typename Hasse_complex<T1, T2, T3>::Simplex_key > boundary; + typename Hasse_complex<T1, T2, T3>::Filtration_value fil; + typename Hasse_complex<T1, T2, T3>::Filtration_value max_fil = 0; + int max_dim = -1; + int key = 0; + // 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<T1, T2, T3> >(key, fil, boundary)); + + if (max_dim < hcpx.dimension(key)) { + max_dim = hcpx.dimension(key); + } + if (hcpx.dimension(key) == 0) { + hcpx.vertices_.push_back(key); + } + if (max_fil < fil) { + max_fil = fil; + } ++key; boundary.clear(); @@ -214,6 +240,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/Persistent_cohomology/example/CMakeLists.txt b/src/Persistent_cohomology/example/CMakeLists.txt index 3276989d..ea69352e 100644 --- a/src/Persistent_cohomology/example/CMakeLists.txt +++ b/src/Persistent_cohomology/example/CMakeLists.txt @@ -2,42 +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_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() diff --git a/src/Persistent_cohomology/example/alpha_shapes_persistence.cpp b/src/Persistent_cohomology/example/alpha_shapes_persistence.cpp index 1e907040..6d5eebcf 100644 --- a/src/Persistent_cohomology/example/alpha_shapes_persistence.cpp +++ b/src/Persistent_cohomology/example/alpha_shapes_persistence.cpp @@ -1,24 +1,29 @@ - /* This file is part of the Gudhi Library. The Gudhi library - * (Geometric Understanding in Higher Dimensions) is a generic C++ - * library for computational topology. - * - * Author(s): Vincent Rouvreau - * - * Copyright (C) 2014 INRIA Saclay (France) - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ +/* This file is part of the Gudhi Library. The Gudhi library + * (Geometric Understanding in Higher Dimensions) is a generic C++ + * library for computational topology. + * + * Author(s): Vincent Rouvreau + * + * Copyright (C) 2014 INRIA Saclay (France) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#include <gudhi/graph_simplicial_complex.h> +#include <gudhi/Simplex_tree.h> +#include <gudhi/Persistent_cohomology.h> +#include <boost/variant.hpp> #include <CGAL/Exact_predicates_inexact_constructions_kernel.h> #include <CGAL/Delaunay_triangulation_3.h> @@ -27,36 +32,37 @@ #include <fstream> #include <cmath> - -#include "gudhi/graph_simplicial_complex.h" -#include "gudhi/Simplex_tree.h" -#include "gudhi/Persistent_cohomology.h" -#include <boost/variant.hpp> +#include <string> +#include <tuple> +#include <map> +#include <utility> +#include <list> +#include <vector> 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<Kernel> Vb; -typedef CGAL::Alpha_shape_cell_base_3<Kernel> Fb; -typedef CGAL::Triangulation_data_structure_3<Vb,Fb> Tds; -typedef CGAL::Delaunay_triangulation_3<Kernel,Tds> Triangulation_3; -typedef CGAL::Alpha_shape_3<Triangulation_3> Alpha_shape_3; +typedef CGAL::Alpha_shape_vertex_base_3<Kernel> Vb; +typedef CGAL::Alpha_shape_cell_base_3<Kernel> Fb; +typedef CGAL::Triangulation_data_structure_3<Vb, Fb> Tds; +typedef CGAL::Delaunay_triangulation_3<Kernel, Tds> Triangulation_3; +typedef CGAL::Alpha_shape_3<Triangulation_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<Object, Alpha_value_type>, - CGAL::cpp11::tuple<std::back_insert_iterator< std::vector<Object> >, std::back_insert_iterator< std::vector<Alpha_value_type> > - > > 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<Object, Alpha_value_type>, +CGAL::cpp11::tuple<std::back_insert_iterator< std::vector<Object> >, + std::back_insert_iterator< std::vector<Alpha_value_type> > > > 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<Alpha_shape_3::Vertex_handle> Vertex_list; // gudhi type definition @@ -65,70 +71,60 @@ typedef std::map<Alpha_shape_3::Vertex_handle, Simplex_tree_vertex > Alpha_shape typedef std::pair<Alpha_shape_3::Vertex_handle, Simplex_tree_vertex> 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<Point_3> 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<Object> the_objects; std::vector<Alpha_value_type> the_alpha_values; - Dispatch disp = CGAL::dispatch_output<Object, Alpha_value_type>( std::back_inserter(the_objects), std::back_inserter(the_alpha_values)); + Dispatch disp = CGAL::dispatch_output<Object, Alpha_value_type>(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<Alpha_value_type>::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<Cell_handle>(&object_iterator)) - { + if (const Cell_handle * cell = CGAL::object_cast<Cell_handle>(&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<Facet>(&object_iterator)) - { + } else if (const Facet * facet = CGAL::object_cast<Facet>(&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<Edge_3>(&object_iterator)) - { + } else if (const Edge_3 * edge = CGAL::object_cast<Edge_3>(&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<Alpha_shape_3::Vertex_handle>(&object_iterator)) - { + } else if (const Alpha_shape_3::Vertex_handle * vertex = + CGAL::object_cast<Alpha_shape_3::Vertex_handle>(&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 <http://www.gnu.org/licenses/>. - */ - -#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 <http://www.gnu.org/licenses/>. + */ + +#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> #include <chrono> +#include <string> +#include <vector> 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<std::chrono::system_clock> 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<double> 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<Point_t> ); + Graph_t prox_graph = compute_proximity_graph(points, threshold + , euclidean_distance<Point_t>); end = std::chrono::system_clock::now(); - enlapsed_sec = std::chrono::duration_cast<std::chrono::seconds>(end-start).count(); + enlapsed_sec = std::chrono::duration_cast<std::chrono::seconds>(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<std::chrono::seconds>(end-start).count(); + enlapsed_sec = std::chrono::duration_cast<std::chrono::seconds>(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<std::chrono::seconds>(end-start).count(); + enlapsed_sec = std::chrono::duration_cast<std::chrono::seconds>(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<std::chrono::seconds>(end-start).count(); + enlapsed_sec = std::chrono::duration_cast<std::chrono::seconds>(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<std::chrono::system_clock> 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<std::chrono::seconds>(end-start).count(); - std::cout << " Compute persistent homology in Z/"<<p<<"Z in " << enlapsed_sec << " sec.\n"; + enlapsed_sec = std::chrono::duration_cast<std::chrono::seconds>(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<std::chrono::system_clock> 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<std::chrono::seconds>(end-start).count(); + enlapsed_sec = std::chrono::duration_cast<std::chrono::seconds>(end - start).count(); std::cout << " Compute multi-field persistent homology in all coefficient fields Z/pZ " - << "with p in ["<<p<<";"<<q<<"] in " << enlapsed_sec << " sec.\n"; + << "with p in [" << p << ";" << q << "] in " << enlapsed_sec << " sec.\n"; } diff --git a/src/Persistent_cohomology/example/persistence_from_file.cpp b/src/Persistent_cohomology/example/persistence_from_file.cpp index e886aea7..8eb8d0f3 100644 --- a/src/Persistent_cohomology/example/persistence_from_file.cpp +++ b/src/Persistent_cohomology/example/persistence_from_file.cpp @@ -1,141 +1,144 @@ - /* This file is part of the Gudhi Library. The Gudhi library - * (Geometric Understanding in Higher Dimensions) is a generic C++ - * library for computational topology. - * - * Author(s): Vincent Rouvreau - * - * Copyright (C) 2014 INRIA Saclay (France) - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#include "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 <http://www.gnu.org/licenses/>. + */ + +#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 <boost/program_options.hpp> +#include <string> + 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<std::string>(&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<std::string>(&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<std::string>(&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<int>(&p)->default_value(11), - "Characteristic p of the coefficient field Z/pZ for computing homology.") - ("min-persistence,m", po::value<Filtration_value>(&min_persistence), - "Minimal lifetime of homology feature to be recorded. Default is 0"); + ("help,h", "produce help message") + ("output-file,o", po::value<std::string>(&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<int>(&p)->default_value(11), + "Characteristic p of the coefficient field Z/pZ for computing homology.") + ("min-persistence,m", po::value<Filtration_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 <http://www.gnu.org/licenses/>. */ +#include <gudhi/graph_simplicial_complex.h> +#include <gudhi/Simplex_tree.h> +#include <gudhi/Persistent_cohomology.h> + #include <iostream> #include <ctime> -#include "gudhi/graph_simplicial_complex.h" -#include "gudhi/Simplex_tree.h" -#include "gudhi/Persistent_cohomology.h" +#include <utility> +#include <vector> using namespace Gudhi; using namespace Gudhi::persistent_cohomology; @@ -34,15 +37,19 @@ typedef std::pair<typeVectorVertex, Filtration_value> 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<int>(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 <http://www.gnu.org/licenses/>. - */ - -#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 <http://www.gnu.org/licenses/>. + */ + +#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 <boost/program_options.hpp> +#include <string> +#include <vector> + 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<double> 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<Point_t> ); + // Compute the proximity graph of the points + Graph_t prox_graph = compute_proximity_graph(points, threshold + , euclidean_distance<Point_t>); -// 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<std::string>(&filepoints), - "Name of file containing a point set. Format is one point per line: X1 ... Xd \n"); - + ("input-file", po::value<std::string>(&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<std::string>(&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<Filtration_value>(&threshold)->default_value(0), - "Maximal length of an edge for the Rips complex construction.") - ("cpx-dimension,d", po::value<int>(&dim_max)->default_value(1), - "Maximal dimension of the Rips complex we want to compute.") - ("min-field-charac,p", po::value<int>(&min_p)->default_value(2), - "Minimal characteristic p of the coefficient field Z/pZ.") - ("max-field-charac,q", po::value<int>(&max_p)->default_value(1223), - "Minimial characteristic q of the coefficient field Z/pZ.") - ("min-persistence,m", po::value<Filtration_value>(&min_persistence), - "Minimal lifetime of homology feature to be recorded. Default is 0"); + ("help,h", "produce help message") + ("output-file,o", po::value<std::string>(&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<Filtration_value>(&threshold)->default_value(0), + "Maximal length of an edge for the Rips complex construction.") + ("cpx-dimension,d", po::value<int>(&dim_max)->default_value(1), + "Maximal dimension of the Rips complex we want to compute.") + ("min-field-charac,p", po::value<int>(&min_p)->default_value(2), + "Minimal characteristic p of the coefficient field Z/pZ.") + ("max-field-charac,q", po::value<int>(&max_p)->default_value(1223), + "Minimial characteristic q of the coefficient field Z/pZ.") + ("min-persistence,m", po::value<Filtration_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 <http://www.gnu.org/licenses/>. - */ - -#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 <http://www.gnu.org/licenses/>. + */ + +#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 <boost/program_options.hpp> +#include <string> +#include <vector> + 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<double> 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<Point_t> ); + // Compute the proximity graph of the points + Graph_t prox_graph = compute_proximity_graph(points, threshold + , euclidean_distance<Point_t>); -// 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<std::string>(&filepoints), - "Name of file containing a point set. Format is one point per line: X1 ... Xd "); - + ("input-file", po::value<std::string>(&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<std::string>(&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<Filtration_value>(&threshold)->default_value(0), - "Maximal length of an edge for the Rips complex construction.") - ("cpx-dimension,d", po::value<int>(&dim_max)->default_value(1), - "Maximal dimension of the Rips complex we want to compute.") - ("field-charac,p", po::value<int>(&p)->default_value(11), - "Characteristic p of the coefficient field Z/pZ for computing homology.") - ("min-persistence,m", po::value<Filtration_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<std::string>(&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<Filtration_value>(&threshold)->default_value(0), + "Maximal length of an edge for the Rips complex construction.") + ("cpx-dimension,d", po::value<int>(&dim_max)->default_value(1), + "Maximal dimension of the Rips complex we want to compute.") + ("field-charac,p", po::value<int>(&p)->default_value(11), + "Characteristic p of the coefficient field Z/pZ for computing homology.") + ("min-persistence,m", po::value<Filtration_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/Persistent_cohomology/include/gudhi/Persistent_cohomology.h b/src/Persistent_cohomology/include/gudhi/Persistent_cohomology.h index 5f399f1a..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 <http://www.gnu.org/licenses/>. */ -#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 <gudhi/Persistent_cohomology/Persistent_cohomology_column.h> #include <gudhi/Persistent_cohomology/Field_Zp.h> @@ -38,6 +38,10 @@ #include <vector> #include <set> #include <fstream> // std::ofstream +#include <limits> // for numeric_limits<> +#include <tuple> +#include <algorithm> +#include <string> namespace Gudhi { @@ -524,8 +528,8 @@ class Persistent_cohomology { Arith_element charac) { Simplex_key key = cpx_->key(sigma); // Create a column containing only one cell, - Column * new_col = column_pool_.construct(Column(key)); - Cell * new_cell = cell_pool_.construct(Cell(key, x, new_col)); + Column * new_col = column_pool_.construct(key); + Cell * new_cell = cell_pool_.construct(key, x, new_col); new_col->col_.push_back(*new_cell); // and insert it in the matrix, in constant time thanks to the hint cam_.end(). // Indeed *new_col has the biggest lexicographic value because key is the @@ -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 <http://www.gnu.org/licenses/>. */ -#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 <utility> #include <vector> @@ -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 <http://www.gnu.org/licenses/>. */ -#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 <gmpxx.h> @@ -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 5ffd1776..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,14 +20,14 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#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 <list> +#include <boost/tuple/tuple.hpp> +#include <boost/intrusive/set.hpp> +#include <boost/intrusive/list.hpp> -#include "boost/tuple/tuple.hpp" -#include "boost/intrusive/set.hpp" -#include "boost/intrusive/list.hpp" +#include <list> namespace Gudhi { @@ -80,13 +80,15 @@ class Persistent_cohomology_cell : public base_hook_cam_h, * The non-zero coefficients of the column are stored in a * boost::intrusive::list. Contains a hook to be stored in a * boost::intrusive::set. + * + * Movable but not Copyable. */ template<typename SimplexKey, typename ArithmeticElement> class Persistent_cohomology_column : public boost::intrusive::set_base_hook< boost::intrusive::link_mode<boost::intrusive::normal_link> > { - private: template<class T1, class T2> friend class Persistent_cohomology; + public: typedef Persistent_cohomology_cell<SimplexKey, ArithmeticElement> Cell; typedef boost::intrusive::list<Cell, boost::intrusive::constant_time_size<false>, @@ -96,13 +98,6 @@ class Persistent_cohomology_column : public boost::intrusive::set_base_hook< explicit Persistent_cohomology_column(SimplexKey key) : col_(), class_key_(key) {} - public: - /** Copy constructor.*/ - Persistent_cohomology_column(Persistent_cohomology_column const &other) - : col_(), - class_key_(other.class_key_) { - assert(other.col_.empty()); - } /** \brief Returns true iff the column is null.*/ bool is_null() const { @@ -143,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/example/CMakeLists.txt b/src/Simplex_tree/example/CMakeLists.txt index 2f924490..c70cfe35 100644 --- a/src/Simplex_tree/example/CMakeLists.txt +++ b/src/Simplex_tree/example/CMakeLists.txt @@ -1,9 +1,9 @@ cmake_minimum_required(VERSION 2.6) project(GUDHISimplexTreeFromFile) -add_executable ( simplex_tree_from_file simplex_tree_from_file.cpp ) -add_test(simplex_tree_from_file_2 ${CMAKE_CURRENT_BINARY_DIR}/simplex_tree_from_file ${CMAKE_SOURCE_DIR}/data/points/Klein_bottle_complex.txt 2) -add_test(simplex_tree_from_file_3 ${CMAKE_CURRENT_BINARY_DIR}/simplex_tree_from_file ${CMAKE_SOURCE_DIR}/data/points/Klein_bottle_complex.txt 3) +add_executable ( simplex_tree_from_cliques_of_graph simplex_tree_from_cliques_of_graph.cpp ) +add_test(simplex_tree_from_cliques_of_graph_2 ${CMAKE_CURRENT_BINARY_DIR}/simplex_tree_from_cliques_of_graph ${CMAKE_SOURCE_DIR}/data/points/Klein_bottle_complex.txt 2) +add_test(simplex_tree_from_cliques_of_graph_3 ${CMAKE_CURRENT_BINARY_DIR}/simplex_tree_from_cliques_of_graph ${CMAKE_SOURCE_DIR}/data/points/Klein_bottle_complex.txt 3) add_executable ( simple_simplex_tree simple_simplex_tree.cpp ) add_test(simple_simplex_tree ${CMAKE_CURRENT_BINARY_DIR}/simple_simplex_tree) diff --git a/src/Simplex_tree/example/mini_simplex_tree.cpp b/src/Simplex_tree/example/mini_simplex_tree.cpp index 08d626d3..7e48aaaf 100644 --- a/src/Simplex_tree/example/mini_simplex_tree.cpp +++ b/src/Simplex_tree/example/mini_simplex_tree.cpp @@ -58,11 +58,12 @@ int main() { auto edge02 = {0, 2}; ST::Simplex_handle e = st.find(edge02); - assert(st.filtration(e) == 0); // We are not using filtrations so everything has value 0 - for(ST::Simplex_handle t : st.cofaces_simplex_range(e, 1)) // Only coface is 012 - { - for(ST::Vertex_handle v : st.simplex_vertex_range(t)) // v in { 0, 1, 2 } + // We are not using filtrations so everything has value 0 + assert(st.filtration(e) == 0); + for (ST::Simplex_handle t : st.cofaces_simplex_range(e, 1)) { + // Only coface is 012 + for (ST::Vertex_handle v : st.simplex_vertex_range(t)) // v in { 0, 1, 2 } std::cout << v; std::cout << '\n'; - } + } } diff --git a/src/Simplex_tree/example/simple_simplex_tree.cpp b/src/Simplex_tree/example/simple_simplex_tree.cpp index a2e1f0e9..5146b906 100644 --- a/src/Simplex_tree/example/simple_simplex_tree.cpp +++ b/src/Simplex_tree/example/simple_simplex_tree.cpp @@ -20,9 +20,12 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ +#include <gudhi/graph_simplicial_complex.h> +#include <gudhi/Simplex_tree.h> + #include <iostream> -#include "gudhi/graph_simplicial_complex.h" -#include "gudhi/Simplex_tree.h" +#include <utility> // for pair +#include <vector> using namespace Gudhi; @@ -38,7 +41,7 @@ int main(int argc, char * const argv[]) { // TEST OF INSERTION std::cout << "********************************************************************" << std::endl; std::cout << "EXAMPLE OF SIMPLE INSERTION" << std::endl; - //Construct the Simplex Tree + // Construct the Simplex Tree Simplex_tree<> simplexTree; /* Simplex to be inserted: */ @@ -159,8 +162,8 @@ int main(int argc, char * const argv[]) { // ++ TENTH std::cout << " * INSERT 0 (already inserted)" << std::endl; typeVectorVertex tenthSimplexVector = { 0 }; - returnValue = - simplexTree.insert_simplex(tenthSimplexVector, Filtration_value(FOURTH_FILTRATION_VALUE)); // With a different filtration value + // With a different filtration value + returnValue = simplexTree.insert_simplex(tenthSimplexVector, Filtration_value(FOURTH_FILTRATION_VALUE)); if (returnValue.second == true) { std::cout << " + 0 INSERTED" << std::endl; @@ -181,18 +184,18 @@ int main(int argc, char * const argv[]) { } // ++ GENERAL VARIABLE SET - simplexTree.set_filtration(FOURTH_FILTRATION_VALUE); // Max filtration value - simplexTree.set_dimension(2); // Max dimension = 2 -> (2,1,0) + simplexTree.set_filtration(FOURTH_FILTRATION_VALUE); // Max filtration value + simplexTree.set_dimension(2); // Max dimension = 2 -> (2,1,0) - std::cout << "********************************************************************" << std::endl; + std::cout << "********************************************************************\n"; // Display the Simplex_tree - Can not be done in the middle of 2 inserts - std::cout << "* The complex contains " << simplexTree.num_simplices() << " simplices" << std::endl; - std::cout << " - dimension " << simplexTree.dimension() << " - filtration " << simplexTree.filtration() << std::endl; - std::cout << "* Iterator on Simplices in the filtration, with [filtration value]:" << std::endl; + std::cout << "* The complex contains " << simplexTree.num_simplices() << " simplices\n"; + std::cout << " - dimension " << simplexTree.dimension() << " - filtration " << simplexTree.filtration() << "\n"; + std::cout << "* Iterator on Simplices in the filtration, with [filtration value]:\n"; for (auto f_simplex : simplexTree.filtration_simplex_range()) { std::cout << " " << "[" << simplexTree.filtration(f_simplex) << "] "; for (auto vertex : simplexTree.simplex_vertex_range(f_simplex)) { - std::cout << (int) vertex << " "; + std::cout << static_cast<int>(vertex) << " "; } std::cout << std::endl; } diff --git a/src/Simplex_tree/example/simplex_tree_from_alpha_shapes_3.cpp b/src/Simplex_tree/example/simplex_tree_from_alpha_shapes_3.cpp index 5f797e93..45efe3ed 100644 --- a/src/Simplex_tree/example/simplex_tree_from_alpha_shapes_3.cpp +++ b/src/Simplex_tree/example/simplex_tree_from_alpha_shapes_3.cpp @@ -1,24 +1,28 @@ - /* This file is part of the Gudhi Library. The Gudhi library - * (Geometric Understanding in Higher Dimensions) is a generic C++ - * library for computational topology. - * - * Author(s): Vincent Rouvreau - * - * Copyright (C) 2014 INRIA Saclay (France) - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ +/* This file is part of the Gudhi Library. The Gudhi library + * (Geometric Understanding in Higher Dimensions) is a generic C++ + * library for computational topology. + * + * Author(s): Vincent Rouvreau + * + * Copyright (C) 2014 INRIA Saclay (France) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#include <gudhi/graph_simplicial_complex.h> +#include <gudhi/Simplex_tree.h> +#include <boost/variant.hpp> #include <CGAL/Exact_predicates_inexact_constructions_kernel.h> #include <CGAL/Delaunay_triangulation_3.h> @@ -27,32 +31,34 @@ #include <fstream> #include <cmath> - -#include "gudhi/graph_simplicial_complex.h" -#include "gudhi/Simplex_tree.h" -#include <boost/variant.hpp> +#include <string> +#include <tuple> // for tuple<> +#include <map> +#include <utility> // for pair<> +#include <list> +#include <vector> // Alpha_shape_3 templates type definitions typedef CGAL::Exact_predicates_inexact_constructions_kernel Kernel; -typedef CGAL::Alpha_shape_vertex_base_3<Kernel> Vb; -typedef CGAL::Alpha_shape_cell_base_3<Kernel> Fb; -typedef CGAL::Triangulation_data_structure_3<Vb,Fb> Tds; -typedef CGAL::Delaunay_triangulation_3<Kernel,Tds> Triangulation_3; -typedef CGAL::Alpha_shape_3<Triangulation_3> Alpha_shape_3; +typedef CGAL::Alpha_shape_vertex_base_3<Kernel> Vb; +typedef CGAL::Alpha_shape_cell_base_3<Kernel> Fb; +typedef CGAL::Triangulation_data_structure_3<Vb, Fb> Tds; +typedef CGAL::Delaunay_triangulation_3<Kernel, Tds> Triangulation_3; +typedef CGAL::Alpha_shape_3<Triangulation_3> Alpha_shape_3; // From file type definition -typedef Kernel::Point_3 Point; +typedef Kernel::Point_3 Point; // 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<Object, Alpha_value_type>, - CGAL::cpp11::tuple<std::back_insert_iterator< std::vector<Object> >, std::back_insert_iterator< std::vector<Alpha_value_type> > - > > Dispatch; -typedef Alpha_shape_3::Cell_handle Cell_handle; -typedef Alpha_shape_3::Facet Facet; -typedef Alpha_shape_3::Edge Edge; +CGAL::cpp11::tuple<Object, Alpha_value_type>, +CGAL::cpp11::tuple<std::back_insert_iterator< std::vector<Object> >, + std::back_insert_iterator< std::vector<Alpha_value_type> > > > Dispatch; +typedef Alpha_shape_3::Cell_handle Cell_handle; +typedef Alpha_shape_3::Facet Facet; +typedef Alpha_shape_3::Edge Edge; typedef std::list<Alpha_shape_3::Vertex_handle> Vertex_list; // gudhi type definition @@ -61,225 +67,209 @@ typedef std::map<Alpha_shape_3::Vertex_handle, Simplex_tree_vertex > Alpha_shape typedef std::pair<Alpha_shape_3::Vertex_handle, Simplex_tree_vertex> 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 the_list; - for (auto i = 0; i < 4; i++) - { +Vertex_list from(const Cell_handle& ch) { + Vertex_list the_list; + for (auto i = 0; i < 4; i++) { #ifdef DEBUG_TRACES - std::cout << "from cell[" << i << "]=" << ch->vertex(i)->point() << std::endl; -#endif // DEBUG_TRACES - the_list.push_back(ch->vertex(i)); - } - return the_list; + std::cout << "from cell[" << i << "]=" << ch->vertex(i)->point() << std::endl; +#endif // DEBUG_TRACES + the_list.push_back(ch->vertex(i)); + } + return the_list; } -Vertex_list from (const Facet& fct) -{ - Vertex_list the_list; - for (auto i = 0; i < 4; i++) - { - if (fct.second != i) - { + +Vertex_list from(const Facet& fct) { + Vertex_list the_list; + 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 - the_list.push_back(fct.first->vertex(i)); - } - } - return the_list; + std::cout << "from facet=[" << i << "]" << fct.first->vertex(i)->point() << std::endl; +#endif // DEBUG_TRACES + the_list.push_back(fct.first->vertex(i)); + } + } + return the_list; } -Vertex_list from (const Edge& edg) -{ - Vertex_list the_list; - for (auto i = 0; i < 4; i++) - { - if ((edg.second == i) ||(edg.third == i)) - { + +Vertex_list from(const Edge& edg) { + Vertex_list the_list; + 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 - the_list.push_back(edg.first->vertex(i)); - } - } - return the_list; + std::cout << "from edge[" << i << "]=" << edg.first->vertex(i)->point() << std::endl; +#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 the_list; + +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 - the_list.push_back(vh); - return the_list; + std::cout << "from vertex=" << vh->point() << std::endl; +#endif // DEBUG_TRACES + the_list.push_back(vh); + return the_list; } +int main(int argc, char * const argv[]) { + // program args management + if (argc != 2) { + std::cerr << "Usage: " << argv[0] + << " path_to_file_graph \n"; + return 0; + } -int main (int argc, char * const argv[]) -{ - // program args management - if (argc != 2) { - std::cerr << "Usage: " << argv[0] - << " path_to_file_graph \n"; - return 0; // ----- >> - } - - // Read points from file - std::string filegraph = argv[1]; - std::list<Point> lp; - std::ifstream is(filegraph.c_str()); - int n; - is >> n; + // Read points from file + std::string filegraph = argv[1]; + std::list<Point> lp; + std::ifstream is(filegraph.c_str()); + int n; + is >> n; #ifdef DEBUG_TRACES - std::cout << "Reading " << n << " points " << std::endl; -#endif // DEBUG_TRACES - Point p; - for( ; n>0 ; n--) { - is >> p; - lp.push_back(p); - } + std::cout << "Reading " << n << " points " << std::endl; +#endif // DEBUG_TRACES + Point p; + 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 construction from points. CGAL has a strange behavior in REGULARIZED mode. + 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 + std::cout << "Alpha shape computed in GENERAL mode" << std::endl; +#endif // DEBUG_TRACES - // filtration with alpha values from alpha shape - std::vector<Object> the_objects; - std::vector<Alpha_value_type> the_alpha_values; + // filtration with alpha values from alpha shape + std::vector<Object> the_objects; + std::vector<Alpha_value_type> the_alpha_values; - Dispatch disp = CGAL::dispatch_output<Object, Alpha_value_type>( std::back_inserter(the_objects), std::back_inserter(the_alpha_values)); + Dispatch disp = CGAL::dispatch_output<Object, Alpha_value_type>(std::back_inserter(the_objects), + std::back_inserter(the_alpha_values)); - as.filtration_with_alpha_values(disp); + 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 + std::cout << "filtration_with_alpha_values returns : " << the_objects.size() << " objects" << std::endl; +#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_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; - // Loop on objects vector - Vertex_list vertex_list; - Gudhi::Simplex_tree<> simplex_tree; - Alpha_shape_simplex_tree_map map_cgal_simplex_tree; - std::vector<Alpha_value_type>::iterator the_alpha_value_iterator = the_alpha_values.begin(); - for(auto object_iterator: the_objects) - { - // Retrieve Alpha shape vertex list from object - if (const Cell_handle* cell = CGAL::object_cast<Cell_handle>(&object_iterator)) - { - vertex_list = from(*cell); - count_cells++; - } - else if (const Facet* facet = CGAL::object_cast<Facet>(&object_iterator)) - { - vertex_list = from(*facet); - count_facets++; - } - else if (const Edge* edge = CGAL::object_cast<Edge>(&object_iterator)) - { - vertex_list = from(*edge); - count_edges++; - } - else if (const Alpha_shape_3::Vertex_handle* vertex = CGAL::object_cast<Alpha_shape_3::Vertex_handle>(&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) - { - 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()) - { - // alpha shape not found - Simplex_tree_vertex vertex = map_cgal_simplex_tree.size(); + // Loop on objects vector + Vertex_list vertex_list; + Gudhi::Simplex_tree<> simplex_tree; + Alpha_shape_simplex_tree_map map_cgal_simplex_tree; + std::vector<Alpha_value_type>::iterator the_alpha_value_iterator = the_alpha_values.begin(); + for (auto object_iterator : the_objects) { + // Retrieve Alpha shape vertex list from object + if (const Cell_handle * cell = CGAL::object_cast<Cell_handle>(&object_iterator)) { + vertex_list = from(*cell); + count_cells++; + } else if (const Facet * facet = CGAL::object_cast<Facet>(&object_iterator)) { + vertex_list = from(*facet); + count_facets++; + } else if (const Edge * edge = CGAL::object_cast<Edge>(&object_iterator)) { + vertex_list = from(*edge); + count_edges++; + } else if (const Alpha_shape_3::Vertex_handle * vertex = + CGAL::object_cast<Alpha_shape_3::Vertex_handle>(&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) { + 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()) { + // 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_simplex " << vertex << std::endl; -#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 - { - // alpha shape found - Simplex_tree_vertex vertex = the_map_iterator->second; + std::cout << "vertex [" << the_alpha_shape_vertex->point() << "] not found - insert_simplex " << vertex << "\n"; +#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 { + // 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 - the_simplex_tree.push_back(vertex); - } - } - // Construction of the simplex_tree + std::cout << "vertex [" << the_alpha_shape_vertex->point() << "] found in " << vertex << std::endl; +#endif // DEBUG_TRACES + the_simplex_tree.push_back(vertex); + } + } + // Construction of the simplex_tree #ifdef DEBUG_TRACES - std::cout << "filtration = " << *the_alpha_value_iterator << std::endl; -#endif // DEBUG_TRACES - simplex_tree.insert_simplex(the_simplex_tree, std::sqrt(*the_alpha_value_iterator)); - if (the_alpha_value_iterator != the_alpha_values.end()) - ++the_alpha_value_iterator; - else - std::cout << "This shall not happen" << std::endl; - } + std::cout << "filtration = " << *the_alpha_value_iterator << std::endl; +#endif // DEBUG_TRACES + simplex_tree.insert_simplex(the_simplex_tree, std::sqrt(*the_alpha_value_iterator)); + if (the_alpha_value_iterator != the_alpha_values.end()) + ++the_alpha_value_iterator; + else + std::cerr << "This shall not happen" << std::endl; + } #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 << "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 << "Information of the Simplex Tree: " << std::endl; - std::cout << " Number of vertices = " << simplex_tree.num_vertices() << " "; - std::cout << " Number of simplices = " << simplex_tree.num_simplices() << std::endl << std::endl; -#endif // DEBUG_TRACES + std::cout << "Information of the Simplex Tree:\n"; + std::cout << " Number of vertices = " << simplex_tree.num_vertices() << " "; + std::cout << " Number of simplices = " << simplex_tree.num_simplices() << std::endl << std::endl; +#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 + std::cout << "Iterator on vertices: \n"; + for (auto vertex : simplex_tree.complex_vertex_range()) { + std::cout << vertex << " "; + } +#endif // DEBUG_TRACES - std::cout << simplex_tree << std::endl; + std::cout << simplex_tree << std::endl; #ifdef DEBUG_TRACES - std::cout << std::endl << std::endl << "Iterator on simplices: " << std::endl; - for( auto simplex : simplex_tree.complex_simplex_range() ) - { - std::cout << " "; - for( auto vertex : simplex_tree.simplex_vertex_range(simplex) ) { std::cout << vertex << " "; } - std::cout << std::endl; - } -#endif // DEBUG_TRACES + std::cout << std::endl << std::endl << "Iterator on simplices:\n"; + for (auto simplex : simplex_tree.complex_simplex_range()) { + std::cout << " "; + for (auto vertex : simplex_tree.simplex_vertex_range(simplex)) { + std::cout << vertex << " "; + } + std::cout << std::endl; + } +#endif // DEBUG_TRACES #ifdef DEBUG_TRACES - 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; - } -#endif // DEBUG_TRACES + std::cout << std::endl << std::endl << "Iterator on Simplices in the filtration, with [filtration value]:\n"; + 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; + } +#endif // DEBUG_TRACES #ifdef DEBUG_TRACES - std::cout << std::endl << std::endl << "Iterator on Simplices in the filtration, and their boundary simplices:" << 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; + std::cout << std::endl << std::endl << "Iterator on Simplices in the filtration, and their boundary simplices:\n"; + 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; - for( auto b_simplex : simplex_tree.boundary_simplex_range(f_simplex) ) - { - std::cout << " " << "[" << simplex_tree.filtration(b_simplex) << "] "; - for( auto vertex : simplex_tree.simplex_vertex_range(b_simplex) ) - { std::cout << vertex << " "; } - std::cout << std::endl; - } - } -#endif // DEBUG_TRACES + for (auto b_simplex : simplex_tree.boundary_simplex_range(f_simplex)) { + std::cout << " " << "[" << simplex_tree.filtration(b_simplex) << "] "; + for (auto vertex : simplex_tree.simplex_vertex_range(b_simplex)) { + std::cout << vertex << " "; + } + std::cout << std::endl; + } + } +#endif // DEBUG_TRACES - return 0; + return 0; } diff --git a/src/Simplex_tree/example/simplex_tree_from_cliques_of_graph.cpp b/src/Simplex_tree/example/simplex_tree_from_cliques_of_graph.cpp new file mode 100644 index 00000000..58085014 --- /dev/null +++ b/src/Simplex_tree/example/simplex_tree_from_cliques_of_graph.cpp @@ -0,0 +1,114 @@ +/* This file is part of the Gudhi Library. The Gudhi library + * (Geometric Understanding in Higher Dimensions) is a generic C++ + * library for computational topology. + * + * Author(s): Clément Maria + * + * Copyright (C) 2014 INRIA Sophia Antipolis-Méditerranée (France) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#include <gudhi/reader_utils.h> +#include <gudhi/Simplex_tree.h> + +#include <iostream> +#include <ctime> +#include <string> + +using namespace Gudhi; + +int main(int argc, char * const argv[]) { + if (argc != 3) { + std::cerr << "Usage: " << argv[0] + << " path_to_file_graph max_dim \n"; + return 0; + } + std::string filegraph = argv[1]; + int max_dim = atoi(argv[2]); + + clock_t start, end; + // Construct the Simplex Tree + Simplex_tree<> st; + + start = clock(); + auto g = read_graph(filegraph); + // insert the graph in the simplex tree as 1-skeleton + st.insert_graph(g); + end = clock(); + std::cout << "Insert the 1-skeleton in the simplex tree in " + << static_cast<double>(end - start) / CLOCKS_PER_SEC << " s. \n"; + + start = clock(); + // expand the 1-skeleton until dimension max_dim + st.expansion(max_dim); + end = clock(); + std::cout << "max_dim = " << max_dim << "\n"; + std::cout << "Expand the simplex tree in " + << static_cast<double>(end - start) / CLOCKS_PER_SEC << " s. \n"; + + std::cout << "Information of the Simplex Tree: " << std::endl; + std::cout << " Number of vertices = " << st.num_vertices() << " "; + std::cout << " Number of simplices = " << st.num_simplices() << std::endl; + std::cout << std::endl << std::endl; + + std::cout << "Iterator on vertices: "; + for (auto vertex : st.complex_vertex_range()) { + std::cout << vertex << " "; + } + + std::cout << std::endl; + + std::cout << std::endl << std::endl; + + std::cout << "Iterator on simplices: " << std::endl; + for (auto simplex : st.complex_simplex_range()) { + std::cout << " "; + for (auto vertex : st.simplex_vertex_range(simplex)) { + std::cout << vertex << " "; + } + std::cout << std::endl; + } + + std::cout << std::endl << std::endl; + + std::cout << "Iterator on Simplices in the filtration, with [filtration value]:" << 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 << vertex << " "; + } + std::cout << std::endl; + } + + std::cout << std::endl << std::endl; + + std::cout << "Iterator on Simplices in the filtration, and their boundary simplices:" << 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 << vertex << " "; + } + std::cout << std::endl; + + for (auto b_simplex : st.boundary_simplex_range(f_simplex)) { + std::cout << " " << "[" << st.filtration(b_simplex) << "] "; + for (auto vertex : st.simplex_vertex_range(b_simplex)) { + std::cout << vertex << " "; + } + std::cout << std::endl; + } + } + return 0; +} diff --git a/src/Simplex_tree/example/simplex_tree_from_file.cpp b/src/Simplex_tree/example/simplex_tree_from_file.cpp deleted file mode 100644 index 20e8f067..00000000 --- a/src/Simplex_tree/example/simplex_tree_from_file.cpp +++ /dev/null @@ -1,104 +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): Clément Maria - * - * Copyright (C) 2014 INRIA Sophia Antipolis-Méditerranée (France) - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#include <iostream> -#include <ctime> -#include "gudhi/reader_utils.h" -#include "gudhi/Simplex_tree.h" - -using namespace Gudhi; - -int main (int argc, char * const argv[]) -{ - if (argc != 3) { - std::cerr << "Usage: " << argv[0] - << " path_to_file_graph max_dim \n"; - return 0; - } - std::string filegraph = argv[1]; - int max_dim = atoi(argv[2]); - - clock_t start, end; - //Construct the Simplex Tree - Simplex_tree<> st; - - start = clock(); - auto g = read_graph(filegraph); - st.insert_graph (g); //insert the graph in the simplex tree as 1-skeleton - end = clock(); - std::cout << "Insert the 1-skeleton in the simplex tree in " - << (double)(end-start)/CLOCKS_PER_SEC << " s. \n"; - - start = clock(); - st.expansion ( max_dim ); //expand the 1-skeleton until dimension max_dim - end = clock(); - std::cout << "max_dim = " << max_dim << "\n"; - std::cout << "Expand the simplex tree in " - << (double)(end-start)/CLOCKS_PER_SEC << " s. \n"; - - std::cout << "Information of the Simplex Tree: " << std::endl; - std::cout << " Number of vertices = " << st.num_vertices() << " "; - std::cout << " Number of simplices = " << st.num_simplices() << std::endl; - std::cout << std::endl << std::endl; - - std::cout << "Iterator on vertices: "; - for( auto vertex : st.complex_vertex_range() ) { std::cout << vertex << " "; } - - std::cout << std::endl; - - std::cout << std::endl << std::endl; - - std::cout << "Iterator on simplices: " << std::endl; - for( auto simplex : st.complex_simplex_range() ) - { - std::cout << " "; - for( auto vertex : st.simplex_vertex_range(simplex) ) { std::cout << vertex << " "; } - std::cout << std::endl; - } - - std::cout << std::endl << std::endl; - - std::cout << "Iterator on Simplices in the filtration, with [filtration value]:" << 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 << vertex << " "; } std::cout << std::endl; - } - - std::cout << std::endl << std::endl; - - std::cout << "Iterator on Simplices in the filtration, and their boundary simplices:" << 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 << vertex << " "; } std::cout << std::endl; - - for( auto b_simplex : st.boundary_simplex_range(f_simplex) ) - { - std::cout << " " << "[" << st.filtration(b_simplex) << "] "; - for( auto vertex : st.simplex_vertex_range(b_simplex) ) - { std::cout << vertex << " "; } std::cout << std::endl; - } - } - return 0; -} diff --git a/src/Simplex_tree/include/gudhi/Simplex_tree.h b/src/Simplex_tree/include/gudhi/Simplex_tree.h index 6a47083c..c7a0b5d5 100644 --- a/src/Simplex_tree/include/gudhi/Simplex_tree.h +++ b/src/Simplex_tree/include/gudhi/Simplex_tree.h @@ -119,7 +119,9 @@ class Simplex_tree { /* Type of node in the simplex tree. */ typedef Simplex_tree_node_explicit_storage<Simplex_tree> 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<Vertex_handle, Node> Dictionary; /* \brief Set of nodes sharing a same parent in the simplex tree. */ @@ -130,7 +132,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 { @@ -144,7 +146,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 { @@ -152,7 +154,8 @@ class Simplex_tree { void assign_filtration(Filtration_value f) { assert(f == 0); } Filtration_value filtration() const { return 0; } }; - typedef typename std::conditional<Options::store_filtration, Filtration_simplex_base_real, Filtration_simplex_base_dummy>::type Filtration_simplex_base; + typedef typename std::conditional<Options::store_filtration, Filtration_simplex_base_real, + Filtration_simplex_base_dummy>::type Filtration_simplex_base; public: /** \brief Handle type to a simplex contained in the simplicial complex represented @@ -270,7 +273,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 06462c88..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,10 +20,14 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#ifndef SRC_SIMPLEX_TREE_INCLUDE_GUDHI_SIMPLEX_TREE_SIMPLEX_TREE_ITERATORS_H_ -#define SRC_SIMPLEX_TREE_INCLUDE_GUDHI_SIMPLEX_TREE_SIMPLEX_TREE_ITERATORS_H_ +#ifndef SIMPLEX_TREE_SIMPLEX_TREE_ITERATORS_H_ +#define SIMPLEX_TREE_SIMPLEX_TREE_ITERATORS_H_ #include <boost/iterator/iterator_facade.hpp> +#include <boost/version.hpp> +#if BOOST_VERSION >= 105600 +# include <boost/container/static_vector.hpp> +#endif #include <vector> @@ -131,8 +135,7 @@ class Simplex_tree_boundary_simplex_iterator : public boost::iterator_facade< } Siblings * for_sib = sib_; - for (typename std::vector<Vertex_handle>::reverse_iterator rit = suffix_ - .rbegin(); rit != suffix_.rend(); ++rit) { + for (auto rit = suffix_.rbegin(); rit != suffix_.rend(); ++rit) { sh_ = for_sib->find(*rit); for_sib = sh_->second.children(); } @@ -142,9 +145,18 @@ class Simplex_tree_boundary_simplex_iterator : public boost::iterator_facade< sib_ = sib_->oncles(); } + // Most of the storage should be moved to the range, iterators should be light. Vertex_handle last_; // last vertex of the simplex Vertex_handle next_; // next vertex to push in suffix_ +#if BOOST_VERSION >= 105600 + // 40 seems a conservative bound on the dimension of a Simplex_tree for now, + // as it would not fit on the biggest hard-drive. + boost::container::static_vector<Vertex_handle, 40> suffix_; + // static_vector still has some overhead compared to a trivial hand-made + // version using std::aligned_storage, or compared to making suffix_ static. +#else std::vector<Vertex_handle> suffix_; +#endif Siblings * sib_; // where the next search will start from Simplex_handle sh_; // current Simplex_handle in the boundary SimplexTree * st_; // simplex containing the simplicial complex @@ -303,4 +315,4 @@ class Simplex_tree_skeleton_simplex_iterator : public boost::iterator_facade< /* @} */ // end addtogroup simplex_tree } // namespace Gudhi -#endif // SRC_SIMPLEX_TREE_INCLUDE_GUDHI_SIMPLEX_TREE_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 c49e30b9..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 <http://www.gnu.org/licenses/>. */ -#ifndef SRC_SIMPLEX_TREE_INCLUDE_GUDHI_SIMPLEX_TREE_SIMPLEX_TREE_NODE_EXPLICIT_STORAGE_H_ -#define SRC_SIMPLEX_TREE_INCLUDE_GUDHI_SIMPLEX_TREE_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 <vector> @@ -47,7 +47,7 @@ struct Simplex_tree_node_explicit_storage : SimplexTree::Filtration_simplex_base Simplex_tree_node_explicit_storage(Siblings * sib = nullptr, Filtration_value filtration = 0) : children_(sib) { - this->assign_filtration(filtration); + this->assign_filtration(filtration); } /* @@ -69,4 +69,4 @@ struct Simplex_tree_node_explicit_storage : SimplexTree::Filtration_simplex_base /* @} */ // end addtogroup simplex_tree } // namespace Gudhi -#endif // SRC_SIMPLEX_TREE_INCLUDE_GUDHI_SIMPLEX_TREE_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 d20a91d7..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,11 +20,12 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#ifndef SRC_SIMPLEX_TREE_INCLUDE_GUDHI_SIMPLEX_TREE_SIMPLEX_TREE_SIBLINGS_H_ -#define SRC_SIMPLEX_TREE_INCLUDE_GUDHI_SIMPLEX_TREE_SIMPLEX_TREE_SIBLINGS_H_ +#ifndef SIMPLEX_TREE_SIMPLEX_TREE_SIBLINGS_H_ +#define SIMPLEX_TREE_SIMPLEX_TREE_SIBLINGS_H_ -#include "boost/container/flat_map.hpp" -#include "Simplex_tree_node_explicit_storage.h" +#include <gudhi/Simplex_tree/Simplex_tree_node_explicit_storage.h> + +#include <boost/container/flat_map.hpp> #include <utility> #include <vector> @@ -79,7 +80,7 @@ class Simplex_tree_siblings { members.end()) { for (auto& map_el : members_) { map_el.second.assign_children(this); - } + } } /* @@ -123,4 +124,4 @@ class Simplex_tree_siblings { /* @} */ // end addtogroup simplex_tree } // namespace Gudhi -#endif // SRC_SIMPLEX_TREE_INCLUDE_GUDHI_SIMPLEX_TREE_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 69ffa44b..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 <http://www.gnu.org/licenses/>. */ -#ifndef SRC_SIMPLEX_TREE_INCLUDE_GUDHI_SIMPLEX_TREE_INDEXING_TAG_H_ -#define SRC_SIMPLEX_TREE_INCLUDE_GUDHI_SIMPLEX_TREE_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 // SRC_SIMPLEX_TREE_INCLUDE_GUDHI_SIMPLEX_TREE_INDEXING_TAG_H_ +#endif // SIMPLEX_TREE_INDEXING_TAG_H_ 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/Simplex_tree/test/simplex_tree_unit_test.cpp b/src/Simplex_tree/test/simplex_tree_unit_test.cpp index a4871cfd..00cf69bc 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/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 <http://www.gnu.org/licenses/>. - */ - +/* 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 <http://www.gnu.org/licenses/>. + */ + +#include <gudhi/Skeleton_blocker.h> #include <stdio.h> #include <stdlib.h> #include <string> #include <fstream> #include <sstream> - - -#include "gudhi/Skeleton_blocker.h" +#include <vector> 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<Simplex_handle> simplices; +int main(int argc, char *argv[]) { + std::vector<Simplex_handle> 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<Complex>(simplices.begin(),simplices.end())); + // get complex from top faces + Complex complex(make_complex_from_top_faces<Complex>(simplices.begin(), simplices.end())); - std::cout << "Simplices:"<<std::endl; - for(const Simplex & s : complex.simplex_range()) - std::cout << s << " "; - std::cout << std::endl; + std::cout << "Simplices:" << std::endl; + for (const Simplex & s : complex.simplex_range()) + std::cout << s << " "; + std::cout << std::endl; - //One blocker as simplex 0123 is not in the complex but all its proper faces are. - std::cout << "Blockers: "<<complex.blockers_to_string()<<std::endl; + // One blocker as simplex 0123 is not in the complex but all its proper faces are. + std::cout << "Blockers: " << complex.blockers_to_string() << std::endl; - //now build a complex from its full list of simplices - simplices.clear(); - simplices.push_back(Simplex_handle(Vertex_handle(0))); - simplices.push_back(Simplex_handle(Vertex_handle(1))); - simplices.push_back(Simplex_handle(Vertex_handle(2))); - simplices.push_back(Simplex_handle(Vertex_handle(0),Vertex_handle(1))); - simplices.push_back(Simplex_handle(Vertex_handle(1),Vertex_handle(2))); - simplices.push_back(Simplex_handle(Vertex_handle(2),Vertex_handle(0))); - complex = Complex(simplices.begin(),simplices.end()); + // now build a complex from its full list of simplices + simplices.clear(); + simplices.push_back(Simplex_handle(Vertex_handle(0))); + simplices.push_back(Simplex_handle(Vertex_handle(1))); + simplices.push_back(Simplex_handle(Vertex_handle(2))); + simplices.push_back(Simplex_handle(Vertex_handle(0), Vertex_handle(1))); + simplices.push_back(Simplex_handle(Vertex_handle(1), Vertex_handle(2))); + simplices.push_back(Simplex_handle(Vertex_handle(2), Vertex_handle(0))); + complex = Complex(simplices.begin(), simplices.end()); - std::cout << "Simplices:"<<std::endl; - for(const Simplex & s : complex.simplex_range()) - std::cout << s << " "; - std::cout << std::endl; + std::cout << "Simplices:" << std::endl; + for (const Simplex & s : complex.simplex_range()) + std::cout << s << " "; + std::cout << std::endl; - //One blocker as simplex 012 is not in the complex but all its proper faces are. - std::cout << "Blockers: "<<complex.blockers_to_string()<<std::endl; + // One blocker as simplex 012 is not in the complex but all its proper faces are. + std::cout << "Blockers: " << complex.blockers_to_string() << std::endl; - return EXIT_SUCCESS; + return EXIT_SUCCESS; } - diff --git a/src/Skeleton_blocker/example/Skeleton_blocker_iteration.cpp b/src/Skeleton_blocker/example/Skeleton_blocker_iteration.cpp index 126e32ec..69557694 100644 --- a/src/Skeleton_blocker/example/Skeleton_blocker_iteration.cpp +++ b/src/Skeleton_blocker/example/Skeleton_blocker_iteration.cpp @@ -1,24 +1,26 @@ - /* 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 <http://www.gnu.org/licenses/>. - */ +/* 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 <http://www.gnu.org/licenses/>. + */ + +#include <gudhi/Skeleton_blocker.h> #include <boost/timer/timer.hpp> @@ -29,8 +31,6 @@ #include <sstream> -#include "gudhi/Skeleton_blocker.h" - using namespace std; using namespace Gudhi; using namespace skbl; @@ -39,54 +39,53 @@ typedef Skeleton_blocker_complex<Skeleton_blocker_simple_traits> 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<n;i++) - complex.add_vertex(); - for(int i=0;i<n;i++) - for(int j=0;j<i;j++) - //note that add_edge, add the edge and all its cofaces - complex.add_edge(Vertex_handle(i),Vertex_handle(j)); - return complex; +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 < n; i++) + complex.add_vertex(); + for (int i = 0; i < n; i++) + for (int j = 0; j < i; j++) + // note that add_edge, add the edge and all its cofaces + complex.add_edge(Vertex_handle(i), Vertex_handle(j)); + return complex; } -int main (int argc, char *argv[]){ - boost::timer::auto_cpu_timer t; +int main(int argc, char *argv[]) { + boost::timer::auto_cpu_timer t; - const int n = 15; + const int n = 15; - // build a full complex with n vertices and 2^n-1 simplices - Complex complex(build_complete_complex(n)); + // build a full complex with n vertices and 2^n-1 simplices + Complex complex(build_complete_complex(n)); - // this is just to illustrate iterators, to count number of vertices - // or edges, complex.num_vertices() and complex.num_edges() are - // more appropriated! - unsigned num_vertices = 0; - for(auto v : complex.vertex_range()) { - std::cout << "Vertex " << v <<std::endl; - ++num_vertices; - } + // this is just to illustrate iterators, to count number of vertices + // or edges, complex.num_vertices() and complex.num_edges() are + // more appropriated! + unsigned num_vertices = 0; + for (auto v : complex.vertex_range()) { + std::cout << "Vertex " << v << std::endl; + ++num_vertices; + } - // such loop can also be done directly with distance as iterators are STL compliant - auto edges = complex.edge_range(); - unsigned num_edges = std::distance(edges.begin(), edges.end()); + // such loop can also be done directly with distance as iterators are STL compliant + auto edges = complex.edge_range(); + unsigned num_edges = std::distance(edges.begin(), edges.end()); - unsigned euler = 0; - unsigned num_simplices = 0; - // we use a reference to a simplex instead of a copy - // value here because a simplex is a set of integers - // and copying it cost time - for(const Simplex & s : complex.simplex_range()){ - ++num_simplices; - if(s.dimension()%2 == 0) - euler += 1; - else - euler -= 1; - } - std::cout << "Saw "<<num_vertices<<" vertices, "<<num_edges<<" edges and "<<num_simplices<<" simplices"<<std::endl; - std::cout << "The Euler Characteristic is "<<euler<<std::endl; - return EXIT_SUCCESS; + unsigned euler = 0; + unsigned num_simplices = 0; + // we use a reference to a simplex instead of a copy + // value here because a simplex is a set of integers + // and copying it cost time + for (const Simplex & s : complex.simplex_range()) { + ++num_simplices; + if (s.dimension() % 2 == 0) + euler += 1; + else + euler -= 1; + } + std::cout << "Saw " << num_vertices << " vertices, " << num_edges << " edges and " << num_simplices << " simplices" + << std::endl; + std::cout << "The Euler Characteristic is " << euler << std::endl; + return EXIT_SUCCESS; } - diff --git a/src/Skeleton_blocker/example/Skeleton_blocker_link.cpp b/src/Skeleton_blocker/example/Skeleton_blocker_link.cpp index 0987cc89..002cbc49 100644 --- a/src/Skeleton_blocker/example/Skeleton_blocker_link.cpp +++ b/src/Skeleton_blocker/example/Skeleton_blocker_link.cpp @@ -1,25 +1,26 @@ - /* 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 <http://www.gnu.org/licenses/>. - */ +/* 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 <http://www.gnu.org/licenses/>. + */ +#include <gudhi/Skeleton_blocker.h> #include <stdio.h> #include <stdlib.h> @@ -27,9 +28,6 @@ #include <fstream> #include <sstream> - -#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:"<<complex.to_string()<<endl; + // build the link of vertex 1, eg a triangle {0,2,3} + auto link = complex.link(Vertex_handle(1)); + cout << "link:" << link.to_string() << endl; - //build the link of vertex 1, eg a triangle {0,2,3} - auto link = complex.link(Vertex_handle(1)); - cout<<"link:"<<link.to_string()<<endl; + // Internally link is a subcomplex of 'complex' and its vertices are stored in a vector. + // They can be accessed via Vertex_handle(x) where x is an index of the vector. + // In that example, link has three vertices and thus it contains only + // Vertex_handle(0),Vertex_handle(1) and Vertex_handle(2) are). + for (int i = 0; i < 5; ++i) + cout << "link.contains_vertex(Vertex_handle(" << i << ")):" << link.contains_vertex(Vertex_handle(i)) << endl; + cout << endl; - //Internally link is a subcomplex of 'complex' and its vertices are stored in a vector. - //They can be accessed via Vertex_handle(x) where x is an index of the vector. - //In that example, link has three vertices and thus it contains only - // Vertex_handle(0),Vertex_handle(1) and Vertex_handle(2) are). - for(int i = 0; i<5; ++i) - cout << "link.contains_vertex(Vertex_handle("<<i<<")):"<<link.contains_vertex(Vertex_handle(i))<<endl; - cout<<endl; + // To access to the initial vertices eg (0,1,2,3,4), Root_vertex_handle must be used. + // For instance, to test if the link contains the vertex that was labeled i: + for (int i = 0; i < 5; ++i) + cout << "link.contains_vertex(Root_vertex_handle(" << i << ")):" << link.contains_vertex(Root_vertex_handle(i)) << endl; - //To access to the initial vertices eg (0,1,2,3,4), Root_vertex_handle must be used. - //For instance, to test if the link contains the vertex that was labeled i: - for(int i = 0; i<5; ++i) - cout << "link.contains_vertex(Root_vertex_handle("<<i<<")):"<<link.contains_vertex(Root_vertex_handle(i))<<endl; - - return EXIT_SUCCESS; + return EXIT_SUCCESS; } - diff --git a/src/Skeleton_blocker/include/gudhi/Skeleton_blocker.h b/src/Skeleton_blocker/include/gudhi/Skeleton_blocker.h index 289819b5..792a7994 100644 --- a/src/Skeleton_blocker/include/gudhi/Skeleton_blocker.h +++ b/src/Skeleton_blocker/include/gudhi/Skeleton_blocker.h @@ -19,23 +19,24 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#ifndef SRC_SKELETON_BLOCKER_INCLUDE_GUDHI_SKELETON_BLOCKER_H_ -#define SRC_SKELETON_BLOCKER_INCLUDE_GUDHI_SKELETON_BLOCKER_H_ -#include "gudhi/Skeleton_blocker_complex.h" -#include "gudhi/Skeleton_blocker_geometric_complex.h" -#include "gudhi/Skeleton_blocker_simplifiable_complex.h" -#include "gudhi/Skeleton_blocker/Skeleton_blocker_off_io.h" +#ifndef SKELETON_BLOCKER_H_ +#define SKELETON_BLOCKER_H_ -#include "gudhi/Skeleton_blocker/Skeleton_blocker_simple_traits.h" -#include "gudhi/Skeleton_blocker/Skeleton_blocker_simple_geometric_traits.h" +#include <gudhi/Skeleton_blocker_complex.h> +#include <gudhi/Skeleton_blocker_geometric_complex.h> +#include <gudhi/Skeleton_blocker_simplifiable_complex.h> +#include <gudhi/Skeleton_blocker/Skeleton_blocker_off_io.h> +#include <gudhi/Skeleton_blocker/Skeleton_blocker_simple_traits.h> +#include <gudhi/Skeleton_blocker/Skeleton_blocker_simple_geometric_traits.h> -#include "gudhi/Utils.h" // xxx - +#include <gudhi/Utils.h> // xxx namespace Gudhi { + namespace skbl { + /** \defgroup skbl Skeleton-Blocker \author David Salinas @@ -243,11 +244,9 @@ their collaboration to write the two initial papers \verbatim Contact: David Salinas, david.salinas@inria.fr \endverbatim */ /** @} */ // end defgroup -} // namespace skbl -} // namespace Gudhi - - -#endif // SRC_SKELETON_BLOCKER_INCLUDE_GUDHI_SKELETON_BLOCKER_H_ +} // namespace skbl +} // namespace Gudhi +#endif // SKELETON_BLOCKER_H_ diff --git a/src/Skeleton_blocker/include/gudhi/Skeleton_blocker/Skeleton_blocker_complex_visitor.h b/src/Skeleton_blocker/include/gudhi/Skeleton_blocker/Skeleton_blocker_complex_visitor.h index 829ab1e8..72bdf4c9 100644 --- a/src/Skeleton_blocker/include/gudhi/Skeleton_blocker/Skeleton_blocker_complex_visitor.h +++ b/src/Skeleton_blocker/include/gudhi/Skeleton_blocker/Skeleton_blocker_complex_visitor.h @@ -19,10 +19,10 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#ifndef SRC_SKELETON_BLOCKER_INCLUDE_GUDHI_SKELETON_BLOCKER_SKELETON_BLOCKER_COMPLEX_VISITOR_H_ -#define SRC_SKELETON_BLOCKER_INCLUDE_GUDHI_SKELETON_BLOCKER_SKELETON_BLOCKER_COMPLEX_VISITOR_H_ +#ifndef SKELETON_BLOCKER_SKELETON_BLOCKER_COMPLEX_VISITOR_H_ +#define SKELETON_BLOCKER_SKELETON_BLOCKER_COMPLEX_VISITOR_H_ -#include "gudhi/Skeleton_blocker/Skeleton_blocker_simplex.h" +#include <gudhi/Skeleton_blocker/Skeleton_blocker_simplex.h> namespace Gudhi { @@ -59,7 +59,7 @@ class Skeleton_blocker_complex_visitor { * remove_edge(b,x) */ virtual void on_swaped_edge(Vertex_handle a, Vertex_handle b, - Vertex_handle x)=0; + Vertex_handle x) = 0; virtual void on_add_blocker( const Skeleton_blocker_simplex<Vertex_handle>&) = 0; virtual void on_delete_blocker( @@ -132,4 +132,4 @@ class Print_complex_visitor : public Skeleton_blocker_complex_visitor< } // namespace Gudhi -#endif // SRC_SKELETON_BLOCKER_INCLUDE_GUDHI_SKELETON_BLOCKER_SKELETON_BLOCKER_COMPLEX_VISITOR_H_ +#endif // SKELETON_BLOCKER_SKELETON_BLOCKER_COMPLEX_VISITOR_H_ diff --git a/src/Skeleton_blocker/include/gudhi/Skeleton_blocker/Skeleton_blocker_link_superior.h b/src/Skeleton_blocker/include/gudhi/Skeleton_blocker/Skeleton_blocker_link_superior.h index 17d58956..d39fa9f3 100644 --- a/src/Skeleton_blocker/include/gudhi/Skeleton_blocker/Skeleton_blocker_link_superior.h +++ b/src/Skeleton_blocker/include/gudhi/Skeleton_blocker/Skeleton_blocker_link_superior.h @@ -19,10 +19,10 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#ifndef SRC_SKELETON_BLOCKER_INCLUDE_GUDHI_SKELETON_BLOCKER_SKELETON_BLOCKER_LINK_SUPERIOR_H_ -#define SRC_SKELETON_BLOCKER_INCLUDE_GUDHI_SKELETON_BLOCKER_SKELETON_BLOCKER_LINK_SUPERIOR_H_ +#ifndef SKELETON_BLOCKER_SKELETON_BLOCKER_LINK_SUPERIOR_H_ +#define SKELETON_BLOCKER_SKELETON_BLOCKER_LINK_SUPERIOR_H_ -#include "gudhi/Skeleton_blocker_link_complex.h" +#include <gudhi/Skeleton_blocker_link_complex.h> namespace Gudhi { @@ -74,4 +74,4 @@ class Skeleton_blocker_link_superior : public Skeleton_blocker_link_complex< } // namespace Gudhi -#endif // SRC_SKELETON_BLOCKER_INCLUDE_GUDHI_SKELETON_BLOCKER_SKELETON_BLOCKER_LINK_SUPERIOR_H_ +#endif // SKELETON_BLOCKER_SKELETON_BLOCKER_LINK_SUPERIOR_H_ diff --git a/src/Skeleton_blocker/include/gudhi/Skeleton_blocker/Skeleton_blocker_off_io.h b/src/Skeleton_blocker/include/gudhi/Skeleton_blocker/Skeleton_blocker_off_io.h index 6ad1fdd3..ec000986 100644 --- a/src/Skeleton_blocker/include/gudhi/Skeleton_blocker/Skeleton_blocker_off_io.h +++ b/src/Skeleton_blocker/include/gudhi/Skeleton_blocker/Skeleton_blocker_off_io.h @@ -19,15 +19,15 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#ifndef SRC_SKELETON_BLOCKER_INCLUDE_GUDHI_SKELETON_BLOCKER_SKELETON_BLOCKER_OFF_IO_H_ -#define SRC_SKELETON_BLOCKER_INCLUDE_GUDHI_SKELETON_BLOCKER_SKELETON_BLOCKER_OFF_IO_H_ +#ifndef SKELETON_BLOCKER_SKELETON_BLOCKER_OFF_IO_H_ +#define SKELETON_BLOCKER_SKELETON_BLOCKER_OFF_IO_H_ + +#include <gudhi/Off_reader.h> #include <string> #include <vector> #include <map> -#include "gudhi/Off_reader.h" - namespace Gudhi { namespace skbl { @@ -197,4 +197,4 @@ class Skeleton_blocker_off_writer { } // namespace Gudhi -#endif // SRC_SKELETON_BLOCKER_INCLUDE_GUDHI_SKELETON_BLOCKER_SKELETON_BLOCKER_OFF_IO_H_ +#endif // SKELETON_BLOCKER_SKELETON_BLOCKER_OFF_IO_H_ diff --git a/src/Skeleton_blocker/include/gudhi/Skeleton_blocker/Skeleton_blocker_simple_geometric_traits.h b/src/Skeleton_blocker/include/gudhi/Skeleton_blocker/Skeleton_blocker_simple_geometric_traits.h index d3a5b9d8..8508d9a5 100644 --- a/src/Skeleton_blocker/include/gudhi/Skeleton_blocker/Skeleton_blocker_simple_geometric_traits.h +++ b/src/Skeleton_blocker/include/gudhi/Skeleton_blocker/Skeleton_blocker_simple_geometric_traits.h @@ -19,14 +19,14 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#ifndef SRC_SKELETON_BLOCKER_INCLUDE_GUDHI_SKELETON_BLOCKER_SKELETON_BLOCKER_SIMPLE_GEOMETRIC_TRAITS_H_ -#define SRC_SKELETON_BLOCKER_INCLUDE_GUDHI_SKELETON_BLOCKER_SKELETON_BLOCKER_SIMPLE_GEOMETRIC_TRAITS_H_ +#ifndef SKELETON_BLOCKER_SKELETON_BLOCKER_SIMPLE_GEOMETRIC_TRAITS_H_ +#define SKELETON_BLOCKER_SKELETON_BLOCKER_SIMPLE_GEOMETRIC_TRAITS_H_ + +#include <gudhi/Skeleton_blocker/Skeleton_blocker_simple_traits.h> #include <string> #include <sstream> -#include "gudhi/Skeleton_blocker/Skeleton_blocker_simple_traits.h" - namespace Gudhi { namespace skbl { @@ -91,4 +91,4 @@ struct Skeleton_blocker_simple_geometric_traits : } // namespace Gudhi -#endif // SRC_SKELETON_BLOCKER_INCLUDE_GUDHI_SKELETON_BLOCKER_SKELETON_BLOCKER_SIMPLE_GEOMETRIC_TRAITS_H_ +#endif // SKELETON_BLOCKER_SKELETON_BLOCKER_SIMPLE_GEOMETRIC_TRAITS_H_ diff --git a/src/Skeleton_blocker/include/gudhi/Skeleton_blocker/Skeleton_blocker_simple_traits.h b/src/Skeleton_blocker/include/gudhi/Skeleton_blocker/Skeleton_blocker_simple_traits.h index 52e454ea..0d2de767 100644 --- a/src/Skeleton_blocker/include/gudhi/Skeleton_blocker/Skeleton_blocker_simple_traits.h +++ b/src/Skeleton_blocker/include/gudhi/Skeleton_blocker/Skeleton_blocker_simple_traits.h @@ -19,12 +19,13 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#ifndef SRC_SKELETON_BLOCKER_INCLUDE_GUDHI_SKELETON_BLOCKER_SKELETON_BLOCKER_SIMPLE_TRAITS_H_ -#define SRC_SKELETON_BLOCKER_INCLUDE_GUDHI_SKELETON_BLOCKER_SKELETON_BLOCKER_SIMPLE_TRAITS_H_ +#ifndef SKELETON_BLOCKER_SKELETON_BLOCKER_SIMPLE_TRAITS_H_ +#define SKELETON_BLOCKER_SKELETON_BLOCKER_SIMPLE_TRAITS_H_ + +#include <gudhi/Skeleton_blocker/Skeleton_blocker_simplex.h> #include <string> #include <sstream> -#include "Skeleton_blocker_simplex.h" namespace Gudhi { @@ -77,7 +78,7 @@ struct Skeleton_blocker_simple_traits { : vertex(val) { } - operator int() const { return (int)vertex; } + operator int() const { return static_cast<int>(vertex); } boost_vertex_handle vertex; @@ -178,4 +179,4 @@ struct Skeleton_blocker_simple_traits { } // namespace Gudhi -#endif // SRC_SKELETON_BLOCKER_INCLUDE_GUDHI_SKELETON_BLOCKER_SKELETON_BLOCKER_SIMPLE_TRAITS_H_ +#endif // SKELETON_BLOCKER_SKELETON_BLOCKER_SIMPLE_TRAITS_H_ diff --git a/src/Skeleton_blocker/include/gudhi/Skeleton_blocker/Skeleton_blocker_simplex.h b/src/Skeleton_blocker/include/gudhi/Skeleton_blocker/Skeleton_blocker_simplex.h index 0a2fcb9a..0d838d50 100644 --- a/src/Skeleton_blocker/include/gudhi/Skeleton_blocker/Skeleton_blocker_simplex.h +++ b/src/Skeleton_blocker/include/gudhi/Skeleton_blocker/Skeleton_blocker_simplex.h @@ -20,8 +20,8 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#ifndef SRC_SKELETON_BLOCKER_INCLUDE_GUDHI_SKELETON_BLOCKER_SKELETON_BLOCKER_SIMPLEX_H_ -#define SRC_SKELETON_BLOCKER_INCLUDE_GUDHI_SKELETON_BLOCKER_SKELETON_BLOCKER_SIMPLEX_H_ +#ifndef SKELETON_BLOCKER_SKELETON_BLOCKER_SIMPLEX_H_ +#define SKELETON_BLOCKER_SKELETON_BLOCKER_SIMPLEX_H_ #include <cassert> #include <iostream> @@ -371,5 +371,4 @@ class Skeleton_blocker_simplex { } // namespace Gudhi -#endif // SRC_SKELETON_BLOCKER_INCLUDE_GUDHI_SKELETON_BLOCKER_SKELETON_BLOCKER_SIMPLEX_H_ - +#endif // SKELETON_BLOCKER_SKELETON_BLOCKER_SIMPLEX_H_ diff --git a/src/Skeleton_blocker/include/gudhi/Skeleton_blocker/Skeleton_blocker_sub_complex.h b/src/Skeleton_blocker/include/gudhi/Skeleton_blocker/Skeleton_blocker_sub_complex.h index 40e26c68..b33b9606 100644 --- a/src/Skeleton_blocker/include/gudhi/Skeleton_blocker/Skeleton_blocker_sub_complex.h +++ b/src/Skeleton_blocker/include/gudhi/Skeleton_blocker/Skeleton_blocker_sub_complex.h @@ -20,16 +20,16 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#ifndef SRC_SKELETON_BLOCKER_INCLUDE_GUDHI_SKELETON_BLOCKER_SKELETON_BLOCKER_SUB_COMPLEX_H_ -#define SRC_SKELETON_BLOCKER_INCLUDE_GUDHI_SKELETON_BLOCKER_SKELETON_BLOCKER_SUB_COMPLEX_H_ +#ifndef SKELETON_BLOCKER_SKELETON_BLOCKER_SUB_COMPLEX_H_ +#define SKELETON_BLOCKER_SKELETON_BLOCKER_SUB_COMPLEX_H_ + +#include <gudhi/Skeleton_blocker_complex.h> +#include <gudhi/Skeleton_blocker/Skeleton_blocker_simplex.h> +#include <gudhi/Utils.h> #include <map> #include <vector> -#include "gudhi/Skeleton_blocker_complex.h" -#include "gudhi/Skeleton_blocker/Skeleton_blocker_simplex.h" -#include "gudhi/Utils.h" - namespace Gudhi { namespace skbl { @@ -75,7 +75,6 @@ class Skeleton_blocker_sub_complex : public ComplexType { typedef typename ComplexType::Root_simplex_handle Root_simplex_handle; protected: - /** * @brief Determines whether all proper faces of simplex 'sigma' belong to 'link1' \cup 'link2' * where 'link1' and 'link2' are subcomplexes of the same complex of type ComplexType @@ -287,5 +286,5 @@ bool proper_faces_in_union( } // namespace Gudhi -#endif // SRC_SKELETON_BLOCKER_INCLUDE_GUDHI_SKELETON_BLOCKER_SKELETON_BLOCKER_SUB_COMPLEX_H_ +#endif // SKELETON_BLOCKER_SKELETON_BLOCKER_SUB_COMPLEX_H_ diff --git a/src/Skeleton_blocker/include/gudhi/Skeleton_blocker/internal/Top_faces.h b/src/Skeleton_blocker/include/gudhi/Skeleton_blocker/internal/Top_faces.h index 32538f38..eb970195 100644 --- a/src/Skeleton_blocker/include/gudhi/Skeleton_blocker/internal/Top_faces.h +++ b/src/Skeleton_blocker/include/gudhi/Skeleton_blocker/internal/Top_faces.h @@ -1,67 +1,70 @@ - /* 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 <http://www.gnu.org/licenses/>. - */ -#ifndef TOP_FACES_H_ -#define TOP_FACES_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 <http://www.gnu.org/licenses/>. + */ +#ifndef SKELETON_BLOCKER_INTERNAL_TOP_FACES_H_ +#define SKELETON_BLOCKER_INTERNAL_TOP_FACES_H_ #include <list> #include <vector> #include <set> +namespace Gudhi { + +namespace skbl { + template<typename SimplexHandle> -std::list<SimplexHandle> subfaces(SimplexHandle top_face){ - std::list<SimplexHandle> res; - if(top_face.dimension()==-1) return res; - if(top_face.dimension()==0) { - res.push_back(top_face); - return res; - } - else{ - auto first_vertex = top_face.first_vertex(); - top_face.remove_vertex(first_vertex); - res = subfaces(top_face); - std::list<SimplexHandle> copy = res; - for(auto& simplex : copy){ - simplex.add_vertex(first_vertex); - } - res.push_back(SimplexHandle(first_vertex)); - res.splice(res.end(),copy); - return res; - } +std::list<SimplexHandle> subfaces(SimplexHandle top_face) { + std::list<SimplexHandle> res; + if (top_face.dimension() == -1) return res; + if (top_face.dimension() == 0) { + res.push_back(top_face); + return res; + } else { + auto first_vertex = top_face.first_vertex(); + top_face.remove_vertex(first_vertex); + res = subfaces(top_face); + std::list<SimplexHandle> copy = res; + for (auto& simplex : copy) { + simplex.add_vertex(first_vertex); + } + res.push_back(SimplexHandle(first_vertex)); + res.splice(res.end(), copy); + return res; + } } /** * add all faces of top_face in simplices_per_dimension */ template<typename SimplexHandle> -void register_faces( - std::vector< std::set<SimplexHandle> >& simplices_per_dimension, - const SimplexHandle& top_face){ - std::list<SimplexHandle> subfaces_list = subfaces(top_face); - for(auto& simplex : subfaces_list ){ - simplices_per_dimension[simplex.dimension()].insert(simplex); - } +void register_faces(std::vector< std::set<SimplexHandle> >& simplices_per_dimension, + const SimplexHandle& top_face) { + std::list<SimplexHandle> subfaces_list = subfaces(top_face); + for (auto& simplex : subfaces_list) { + simplices_per_dimension[simplex.dimension()].insert(simplex); + } } +} // namespace skbl +} // namespace Gudhi - -#endif /* TOP_FACES_H_ */ +#endif // SKELETON_BLOCKER_INTERNAL_TOP_FACES_H_ diff --git a/src/Skeleton_blocker/include/gudhi/Skeleton_blocker/internal/Trie.h b/src/Skeleton_blocker/include/gudhi/Skeleton_blocker/internal/Trie.h index f2a443dc..aa0416ef 100644 --- a/src/Skeleton_blocker/include/gudhi/Skeleton_blocker/internal/Trie.h +++ b/src/Skeleton_blocker/include/gudhi/Skeleton_blocker/internal/Trie.h @@ -1,13 +1,10 @@ -/* - * Trie.h - * Created on: Jan 29, 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-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 @@ -25,8 +22,8 @@ */ -#ifndef TRIE_H_ -#define TRIE_H_ +#ifndef SKELETON_BLOCKER_INTERNAL_TRIE_H_ +#define SKELETON_BLOCKER_INTERNAL_TRIE_H_ #include <memory> #include <vector> @@ -35,242 +32,237 @@ namespace Gudhi { - namespace skbl { - template<typename SimplexHandle> -struct Trie{ - typedef SimplexHandle Simplex_handle; - typedef typename SimplexHandle::Vertex_handle Vertex_handle; - - Vertex_handle v; - std::vector<std::shared_ptr<Trie> > childs; - //std::vector<std::unique_ptr<Trie> > childs; -> use of deleted function -private: - const Trie* parent_; -public: - Trie():parent_(0){} - Trie(Vertex_handle v_):v(v_),parent_(0){} - - Trie(Vertex_handle v_,Trie* parent):v(v_),parent_(parent){} - - - bool operator==(const Trie& other) const{ - return (v == other.v) ; - } - - void add_child(Trie* child){ - if(child){ - std::shared_ptr<Trie> ptr_to_add(child); - childs.push_back(ptr_to_add); - child->parent_ = this; - } - } - - typedef typename Simplex_handle::Simplex_vertex_const_iterator Simplex_vertex_const_iterator; - - - Trie* make_trie(Simplex_vertex_const_iterator s_it,Simplex_vertex_const_iterator s_end){ - if(s_it == s_end) return 0; - else{ - Trie* res = new Trie(*s_it); - Trie* child = make_trie(++s_it,s_end); - res->add_child(child); - return res; - } - } -private: - //go down recursively in the tree while advancing the simplex iterator. - //when it reaches a leaf, it inserts the remaining that is not present - void add_simplex_helper(Simplex_vertex_const_iterator s_it,Simplex_vertex_const_iterator s_end){ - assert(*s_it == v); - ++s_it; - if(s_it==s_end) return ; - if(!is_leaf()){ - for(auto child : childs){ - if(child->v == *s_it) - return child->add_simplex_helper(s_it,s_end); - } - //s_it is not found and needs to be inserted - } - //not leaf -> remaining of s needs to be inserted - Trie* son_with_what_remains_of_s(make_trie(s_it,s_end)); - add_child(son_with_what_remains_of_s); - return; - } - - void maximal_faces_helper(std::vector<Simplex_handle>& res) const{ - if(is_leaf()) res.push_back(simplex()); - else - for(auto child : childs) - child->maximal_faces_helper(res); - } - -public: - /** - * adds the simplex to the trie - */ - void add_simplex(const Simplex_handle& s){ - if(s.empty()) return; - assert(v==s.first_vertex()); - add_simplex_helper(s.begin(),s.end()); - } - - std::vector<Simplex_handle> maximal_faces() const{ - std::vector<Simplex_handle> res; - maximal_faces_helper(res); - return res; - } - - /** - * Goes to the root in the trie to consitute simplex - */ - void add_vertices_up_to_the_root(Simplex_handle& res) const{ - res.add_vertex(v); - if(parent_) - parent_->add_vertices_up_to_the_root(res); - } - - Simplex_handle simplex() const{ - Simplex_handle res; - add_vertices_up_to_the_root(res); - return res; - } - - bool is_leaf() const{ - return childs.empty(); - } - - bool is_root() const{ - return parent_==0; - } - - const Trie* parent() { - return parent_; - } - - void remove_leaf() { - assert(is_leaf); - if(!is_root()) - parent_->childs.erase(this); - } - - /** - * true iff the simplex corresponds to one node in the trie - */ - bool contains(const Simplex_handle& s) const{ - Trie const* current = this; - if(s.empty()) return true; - if(current->v != s.first_vertex()) return false; - auto s_pos = s.begin(); - ++s_pos; - while(s_pos != s.end() && current != 0){ - bool found = false; - for(const auto child : current->childs){ - if(child->v == *s_pos) { - ++s_pos; - current = child.get(); - found = true; - break; - } - } - if(!found) return false; - } - return current!=0; - } - - Trie* go_bottom_left(){ - if(is_leaf()) - return this; - else - return (*childs.begin())->go_bottom_left(); - } - - friend std::ostream& operator<<(std::ostream& stream, const Trie& trie){ - stream<< "T( "<< trie.v<< " "; - for(auto t : trie.childs) - stream << *t ; - stream<<")"; - return stream; - } +struct Trie { + typedef SimplexHandle Simplex_handle; + typedef typename SimplexHandle::Vertex_handle Vertex_handle; + + Vertex_handle v; + std::vector<std::shared_ptr<Trie> > childs; + // std::vector<std::unique_ptr<Trie> > childs; -> use of deleted function + private: + const Trie* parent_; + + public: + Trie() : parent_(0) { } + + Trie(Vertex_handle v_) : v(v_), parent_(0) { } + + Trie(Vertex_handle v_, Trie* parent) : v(v_), parent_(parent) { } + + bool operator==(const Trie& other) const { + return (v == other.v); + } + + void add_child(Trie* child) { + if (child) { + std::shared_ptr<Trie> ptr_to_add(child); + childs.push_back(ptr_to_add); + child->parent_ = this; + } + } + + typedef typename Simplex_handle::Simplex_vertex_const_iterator Simplex_vertex_const_iterator; + + Trie* make_trie(Simplex_vertex_const_iterator s_it, Simplex_vertex_const_iterator s_end) { + if (s_it == s_end) { + return 0; + } else { + Trie* res = new Trie(*s_it); + Trie* child = make_trie(++s_it, s_end); + res->add_child(child); + return res; + } + } + + private: + // go down recursively in the tree while advancing the simplex iterator. + // when it reaches a leaf, it inserts the remaining that is not present + void add_simplex_helper(Simplex_vertex_const_iterator s_it, Simplex_vertex_const_iterator s_end) { + assert(*s_it == v); + ++s_it; + if (s_it == s_end) return; + if (!is_leaf()) { + for (auto child : childs) { + if (child->v == *s_it) + return child->add_simplex_helper(s_it, s_end); + } + // s_it is not found and needs to be inserted + } + // not leaf -> remaining of s needs to be inserted + Trie * son_with_what_remains_of_s(make_trie(s_it, s_end)); + add_child(son_with_what_remains_of_s); + return; + } + + void maximal_faces_helper(std::vector<Simplex_handle>& res) const { + if (is_leaf()) res.push_back(simplex()); + else + for (auto child : childs) + child->maximal_faces_helper(res); + } + + public: + /** + * adds the simplex to the trie + */ + void add_simplex(const Simplex_handle& s) { + if (s.empty()) return; + assert(v == s.first_vertex()); + add_simplex_helper(s.begin(), s.end()); + } + + std::vector<Simplex_handle> maximal_faces() const { + std::vector<Simplex_handle> res; + maximal_faces_helper(res); + return res; + } + + /** + * Goes to the root in the trie to consitute simplex + */ + void add_vertices_up_to_the_root(Simplex_handle& res) const { + res.add_vertex(v); + if (parent_) + parent_->add_vertices_up_to_the_root(res); + } + + Simplex_handle simplex() const { + Simplex_handle res; + add_vertices_up_to_the_root(res); + return res; + } + + bool is_leaf() const { + return childs.empty(); + } + + bool is_root() const { + return parent_ == 0; + } + + const Trie* parent() { + return parent_; + } + + void remove_leaf() { + assert(is_leaf); + if (!is_root()) + parent_->childs.erase(this); + } + + /** + * true iff the simplex corresponds to one node in the trie + */ + bool contains(const Simplex_handle& s) const { + Trie const* current = this; + if (s.empty()) return true; + if (current->v != s.first_vertex()) return false; + auto s_pos = s.begin(); + ++s_pos; + while (s_pos != s.end() && current != 0) { + bool found = false; + for (const auto child : current->childs) { + if (child->v == *s_pos) { + ++s_pos; + current = child.get(); + found = true; + break; + } + } + if (!found) return false; + } + return current != 0; + } + + Trie* go_bottom_left() { + if (is_leaf()) + return this; + else + return (*childs.begin())->go_bottom_left(); + } + + friend std::ostream& operator<<(std::ostream& stream, const Trie& trie) { + stream << "T( " << trie.v << " "; + for (auto t : trie.childs) + stream << *t; + stream << ")"; + return stream; + } }; - template<typename SimplexHandle> -struct Tries{ - typedef typename SimplexHandle::Vertex_handle Vertex_handle; - typedef SimplexHandle Simplex_handle; - - typedef Trie<Simplex_handle> STrie; - - - template<typename SimpleHandleOutputIterator> - Tries(unsigned num_vertices,SimpleHandleOutputIterator simplex_begin, SimpleHandleOutputIterator simplex_end): - cofaces_(num_vertices,0){ - for (auto i = 0u; i < num_vertices; ++i) - cofaces_[i] = new STrie(Vertex_handle(i)); - for (auto s_it = simplex_begin; s_it != simplex_end; ++s_it) { - if (s_it->dimension() >= 1) - cofaces_[s_it->first_vertex()]->add_simplex(*s_it); - } - } - - ~Tries(){ - for(STrie* t : cofaces_) - delete t; - } - - //return a simplex that consists in all u such uv is an edge and u>v - Simplex_handle positive_neighbors(Vertex_handle v) const{ - Simplex_handle res; - for(auto child : cofaces_[v]->childs) - res.add_vertex(child->v); - return res; - } - - bool contains(const Simplex_handle& s) const{ - auto first_v = s.first_vertex(); - return cofaces_[first_v]->contains(s); - } - - friend std::ostream& operator<<(std::ostream& stream, const Tries& tries){ - for(auto trie : tries.cofaces_) - stream<<*trie<<std::endl; - return stream; - } - - //init_next_dimension must be called first - std::vector<Simplex_handle> next_dimension_simplices() const{ - std::vector<Simplex_handle> res; - while(!to_see_.empty() && to_see_.front()->simplex().dimension()==current_dimension_){ - res.emplace_back(to_see_.front()->simplex()); - for(auto child : to_see_.front()->childs) - to_see_.push_back(child.get()); - to_see_.pop_front(); - } - ++current_dimension_; - return res; - } - - void init_next_dimension() const{ - for(auto trie : cofaces_) - to_see_.push_back(trie); - } - -private: - mutable std::deque<STrie*> to_see_; - mutable unsigned current_dimension_=0; - - - std::vector<STrie*> cofaces_; - +struct Tries { + typedef typename SimplexHandle::Vertex_handle Vertex_handle; + typedef SimplexHandle Simplex_handle; + + typedef Trie<Simplex_handle> STrie; + + template<typename SimpleHandleOutputIterator> + Tries(unsigned num_vertices, SimpleHandleOutputIterator simplex_begin, SimpleHandleOutputIterator simplex_end) : + cofaces_(num_vertices, 0) { + for (auto i = 0u; i < num_vertices; ++i) + cofaces_[i] = new STrie(Vertex_handle(i)); + for (auto s_it = simplex_begin; s_it != simplex_end; ++s_it) { + if (s_it->dimension() >= 1) + cofaces_[s_it->first_vertex()]->add_simplex(*s_it); + } + } + + ~Tries() { + for (STrie* t : cofaces_) + delete t; + } + + // return a simplex that consists in all u such uv is an edge and u>v + + Simplex_handle positive_neighbors(Vertex_handle v) const { + Simplex_handle res; + for (auto child : cofaces_[v]->childs) + res.add_vertex(child->v); + return res; + } + + bool contains(const Simplex_handle& s) const { + auto first_v = s.first_vertex(); + return cofaces_[first_v]->contains(s); + } + + friend std::ostream& operator<<(std::ostream& stream, const Tries& tries) { + for (auto trie : tries.cofaces_) + stream << *trie << std::endl; + return stream; + } + + // init_next_dimension must be called first + + std::vector<Simplex_handle> next_dimension_simplices() const { + std::vector<Simplex_handle> res; + while (!to_see_.empty() && to_see_.front()->simplex().dimension() == current_dimension_) { + res.emplace_back(to_see_.front()->simplex()); + for (auto child : to_see_.front()->childs) + to_see_.push_back(child.get()); + to_see_.pop_front(); + } + ++current_dimension_; + return res; + } + + void init_next_dimension() const { + for (auto trie : cofaces_) + to_see_.push_back(trie); + } + + private: + mutable std::deque<STrie*> to_see_; + mutable unsigned current_dimension_ = 0; + std::vector<STrie*> cofaces_; }; +} // namespace skbl +} // namespace Gudhi -} - -} - -#endif /* TRIE_H_ */ +#endif // SKELETON_BLOCKER_INTERNAL_TRIE_H_ diff --git a/src/Skeleton_blocker/include/gudhi/Skeleton_blocker/iterators/Skeleton_blockers_blockers_iterators.h b/src/Skeleton_blocker/include/gudhi/Skeleton_blocker/iterators/Skeleton_blockers_blockers_iterators.h index f6f2c955..56a20a24 100644 --- a/src/Skeleton_blocker/include/gudhi/Skeleton_blocker/iterators/Skeleton_blockers_blockers_iterators.h +++ b/src/Skeleton_blocker/include/gudhi/Skeleton_blocker/iterators/Skeleton_blockers_blockers_iterators.h @@ -1,134 +1,131 @@ - /* 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 <http://www.gnu.org/licenses/>. - */ -#ifndef GUDHI_SKELETON_BLOCKERS_BLOCKERS_ITERATORS_H_ -#define GUDHI_SKELETON_BLOCKERS_BLOCKERS_ITERATORS_H_ - -#include "boost/iterator/iterator_facade.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 <http://www.gnu.org/licenses/>. + */ +#ifndef SKELETON_BLOCKER_ITERATORS_SKELETON_BLOCKERS_BLOCKERS_ITERATORS_H_ +#define SKELETON_BLOCKER_ITERATORS_SKELETON_BLOCKERS_BLOCKERS_ITERATORS_H_ + +#include <boost/iterator/iterator_facade.hpp> + +namespace Gudhi { namespace skbl { /** * @brief Iterator through the blockers of a vertex. - */ + */ // ReturnType = const Simplex_handle* or Simplex_handle* // MapIteratorType = BlockerMapConstIterator or BlockerMapIterator + template<typename MapIteratorType, typename ReturnType> class Blocker_iterator_internal : public boost::iterator_facade< - Blocker_iterator_internal<MapIteratorType,ReturnType>, - ReturnType, - boost::forward_traversal_tag, - ReturnType - >{ -private: - MapIteratorType current_position; - MapIteratorType end_of_map; -public: - - Blocker_iterator_internal():current_position(){} - - Blocker_iterator_internal(MapIteratorType position,MapIteratorType end_of_map_ ): - current_position(position), end_of_map(end_of_map_) - { } - - bool equal(const Blocker_iterator_internal& other) const{ - return current_position == other.current_position; - } - - void increment(){ - goto_next_blocker(); - } - - ReturnType dereference() const { - return(current_position->second); - } - -private: - /** - * Let the current pair be (v,sigma) where v is a vertex and sigma is a blocker. - * If v is not the first vertex of sigma then we already have seen sigma as a blocker - * and we look for the next one. - */ - void goto_next_blocker(){ - do { - ++current_position; - } while (!(current_position == end_of_map) && !first_time_blocker_is_seen()); - } - - bool first_time_blocker_is_seen() const{ - return current_position->first == current_position->second->first_vertex(); - } +Blocker_iterator_internal<MapIteratorType, ReturnType>, +ReturnType, +boost::forward_traversal_tag, +ReturnType +> { + private: + MapIteratorType current_position; + MapIteratorType end_of_map; + + public: + Blocker_iterator_internal() : current_position() { } + + Blocker_iterator_internal(MapIteratorType position, MapIteratorType end_of_map_) : + current_position(position), end_of_map(end_of_map_) { } + + bool equal(const Blocker_iterator_internal& other) const { + return current_position == other.current_position; + } + + void increment() { + goto_next_blocker(); + } + + ReturnType dereference() const { + return (current_position->second); + } + + private: + /** + * Let the current pair be (v,sigma) where v is a vertex and sigma is a blocker. + * If v is not the first vertex of sigma then we already have seen sigma as a blocker + * and we look for the next one. + */ + void goto_next_blocker() { + do { + ++current_position; + } while (!(current_position == end_of_map) && !first_time_blocker_is_seen()); + } + + bool first_time_blocker_is_seen() const { + return current_position->first == current_position->second->first_vertex(); + } }; - - /** * @brief Iterator through the blockers of a vertex */ // ReturnType = const Simplex_handle* or Simplex_handle* // MapIteratorType = BlockerMapConstIterator or BlockerMapIterator + template<typename MapIteratorType, typename ReturnType> class Blocker_iterator_around_vertex_internal : public boost::iterator_facade< - Blocker_iterator_around_vertex_internal<MapIteratorType,ReturnType>, - ReturnType, - boost::forward_traversal_tag, - ReturnType ->{ -private: - MapIteratorType current_position_; -public: - - Blocker_iterator_around_vertex_internal():current_position_(){} - - Blocker_iterator_around_vertex_internal(MapIteratorType position): - current_position_(position) - {} - - Blocker_iterator_around_vertex_internal& operator=(Blocker_iterator_around_vertex_internal other){ - this->current_position_ = other.current_position_; - return *this; - } - - bool equal(const Blocker_iterator_around_vertex_internal& other) const{ - return current_position_ == other.current_position_; - } - - void increment(){ - current_position_++; - } - - ReturnType dereference() const{ - return(current_position_->second); - } - - - MapIteratorType current_position(){ - return this->current_position_; - } +Blocker_iterator_around_vertex_internal<MapIteratorType, ReturnType>, +ReturnType, +boost::forward_traversal_tag, +ReturnType +> { + private: + MapIteratorType current_position_; + + public: + Blocker_iterator_around_vertex_internal() : current_position_() { } + + Blocker_iterator_around_vertex_internal(MapIteratorType position) : + current_position_(position) { } + + Blocker_iterator_around_vertex_internal& operator=(Blocker_iterator_around_vertex_internal other) { + this->current_position_ = other.current_position_; + return *this; + } + + bool equal(const Blocker_iterator_around_vertex_internal& other) const { + return current_position_ == other.current_position_; + } + + void increment() { + current_position_++; + } + + ReturnType dereference() const { + return (current_position_->second); + } + + MapIteratorType current_position() { + return this->current_position_; + } }; -} +} // namespace skbl -} // namespace GUDHI +} // namespace Gudhi -#endif /* GUDHI_SKELETON_BLOCKERS_BLOCKERS_ITERATORS_H_ */ +#endif // SKELETON_BLOCKER_ITERATORS_SKELETON_BLOCKERS_BLOCKERS_ITERATORS_H_ diff --git a/src/Skeleton_blocker/include/gudhi/Skeleton_blocker/iterators/Skeleton_blockers_edges_iterators.h b/src/Skeleton_blocker/include/gudhi/Skeleton_blocker/iterators/Skeleton_blockers_edges_iterators.h index 0be6c74d..ef4c7970 100644 --- a/src/Skeleton_blocker/include/gudhi/Skeleton_blocker/iterators/Skeleton_blockers_edges_iterators.h +++ b/src/Skeleton_blocker/include/gudhi/Skeleton_blocker/iterators/Skeleton_blockers_edges_iterators.h @@ -1,167 +1,144 @@ - /* 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 <http://www.gnu.org/licenses/>. - */ -#ifndef GUDHI_SKELETON_BLOCKERS_ITERATORS_EDGES_H_ -#define GUDHI_SKELETON_BLOCKERS_ITERATORS_EDGES_H_ - -#include "boost/iterator/iterator_facade.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 <http://www.gnu.org/licenses/>. + */ +#ifndef SKELETON_BLOCKER_ITERATORS_SKELETON_BLOCKERS_EDGES_ITERATORS_H_ +#define SKELETON_BLOCKER_ITERATORS_SKELETON_BLOCKERS_EDGES_ITERATORS_H_ + +#include <boost/iterator/iterator_facade.hpp> +#include <boost/graph/adjacency_list.hpp> + +#include <utility> // for pair<> + +namespace Gudhi { namespace skbl { template<typename SkeletonBlockerComplex> -class Edge_around_vertex_iterator : - public boost::iterator_facade < Edge_around_vertex_iterator<SkeletonBlockerComplex> - , typename SkeletonBlockerComplex::Edge_handle const - , boost::forward_traversal_tag - , typename SkeletonBlockerComplex::Edge_handle const - > -{ - friend class boost::iterator_core_access; - - typedef SkeletonBlockerComplex Complex; - typedef typename Complex::boost_adjacency_iterator boost_adjacency_iterator; - typedef typename Complex::Vertex_handle Vertex_handle; - typedef typename Complex::Edge_handle Edge_handle; - -private: - - const Complex* complex; - Vertex_handle v; - - boost_adjacency_iterator current_; - boost_adjacency_iterator end_; - -public: - - Edge_around_vertex_iterator():complex(NULL){ - } - - Edge_around_vertex_iterator(const Complex* complex_,Vertex_handle v_): - complex(complex_), - v(v_) - { - tie(current_,end_) = adjacent_vertices(v.vertex, complex->skeleton); - } - - /** - * returns an iterator to the end - */ - Edge_around_vertex_iterator(const Complex* complex_,Vertex_handle v_,int end): - complex(complex_), - v(v_) - { - tie(current_,end_) = adjacent_vertices(v.vertex, complex->skeleton); - set_end(); - } - - bool equal(const Edge_around_vertex_iterator& other) const{ - return (complex== other.complex) && (v == other.v) && (current_ == other.current_) && (end_ == other.end_); - } - - void increment(){ - if(current_ != end_) - ++current_; - } - - Edge_handle dereference() const{ - return *(*complex)[std::make_pair(v,static_cast<Vertex_handle>(*current_))]; - } - -private: - //remove this ugly hack - void set_end(){ - current_ = end_; - } +class Edge_around_vertex_iterator : public boost::iterator_facade <Edge_around_vertex_iterator<SkeletonBlockerComplex> +, typename SkeletonBlockerComplex::Edge_handle const, boost::forward_traversal_tag +, typename SkeletonBlockerComplex::Edge_handle const> { + friend class boost::iterator_core_access; + + typedef SkeletonBlockerComplex Complex; + typedef typename Complex::boost_adjacency_iterator boost_adjacency_iterator; + typedef typename Complex::Vertex_handle Vertex_handle; + typedef typename Complex::Edge_handle Edge_handle; + + private: + const Complex* complex; + Vertex_handle v; + + boost_adjacency_iterator current_; + boost_adjacency_iterator end_; + + public: + Edge_around_vertex_iterator() : complex(NULL) { } + + Edge_around_vertex_iterator(const Complex* complex_, Vertex_handle v_) : + complex(complex_), + v(v_) { + tie(current_, end_) = adjacent_vertices(v.vertex, complex->skeleton); + } + + /** + * returns an iterator to the end + */ + Edge_around_vertex_iterator(const Complex* complex_, Vertex_handle v_, int end) : + complex(complex_), + v(v_) { + tie(current_, end_) = adjacent_vertices(v.vertex, complex->skeleton); + set_end(); + } + + bool equal(const Edge_around_vertex_iterator& other) const { + return (complex == other.complex) && (v == other.v) && (current_ == other.current_) && (end_ == other.end_); + } + + void increment() { + if (current_ != end_) + ++current_; + } + + Edge_handle dereference() const { + return *(*complex)[std::make_pair(v, static_cast<Vertex_handle> (*current_))]; + } + + private: + // remove this ugly hack + void set_end() { + current_ = end_; + } }; - - /** *@brief Iterator on the edges of a simplicial complex. * */ template<typename SkeletonBlockerComplex> -class Edge_iterator : -public boost::iterator_facade < Edge_iterator<SkeletonBlockerComplex> +class Edge_iterator : public boost::iterator_facade <Edge_iterator<SkeletonBlockerComplex> , typename SkeletonBlockerComplex::Edge_handle const , boost::forward_traversal_tag -, typename SkeletonBlockerComplex::Edge_handle const -> - -{ - friend class boost::iterator_core_access; -public: - typedef SkeletonBlockerComplex Complex; - typedef typename Complex::boost_edge_iterator boost_edge_iterator; - typedef typename Complex::Edge_handle Edge_handle; - - - const Complex* complex; - std::pair<boost_edge_iterator,boost_edge_iterator> edge_iterator ; - - Edge_iterator():complex(NULL){ - } - - Edge_iterator(const SkeletonBlockerComplex* complex_): - complex(complex_), - edge_iterator(boost::edges(complex_->skeleton)) - { - } - - /** - * return an iterator to the end - */ - Edge_iterator(const SkeletonBlockerComplex* complex_,int end): - complex(complex_), - edge_iterator(boost::edges(complex_->skeleton)) - { - edge_iterator.first = edge_iterator.second; - } - - - bool equal(const Edge_iterator& other) const{ - return (complex == other.complex) && (edge_iterator == other.edge_iterator); - } - - void increment(){ - if(edge_iterator.first != edge_iterator.second){ - ++(edge_iterator.first); - } - } - - Edge_handle dereference() const{ - return(*(edge_iterator.first)); - } +, typename SkeletonBlockerComplex::Edge_handle const> { + friend class boost::iterator_core_access; + + public: + typedef SkeletonBlockerComplex Complex; + typedef typename Complex::boost_edge_iterator boost_edge_iterator; + typedef typename Complex::Edge_handle Edge_handle; + + const Complex* complex; + std::pair<boost_edge_iterator, boost_edge_iterator> edge_iterator; + + Edge_iterator() : complex(NULL) { } + + Edge_iterator(const SkeletonBlockerComplex* complex_) : + complex(complex_), + edge_iterator(boost::edges(complex_->skeleton)) { } + + /** + * return an iterator to the end + */ + Edge_iterator(const SkeletonBlockerComplex* complex_, int end) : + complex(complex_), + edge_iterator(boost::edges(complex_->skeleton)) { + edge_iterator.first = edge_iterator.second; + } + + bool equal(const Edge_iterator& other) const { + return (complex == other.complex) && (edge_iterator == other.edge_iterator); + } + + void increment() { + if (edge_iterator.first != edge_iterator.second) { + ++(edge_iterator.first); + } + } + + Edge_handle dereference() const { + return (*(edge_iterator.first)); + } }; +} // namespace skbl +} // namespace Gudhi -} - -} // namespace GUDHI - - -#endif /* GUDHI_SKELETON_BLOCKERS_ITERATORS_EDGES_H_ */ - - +#endif // SKELETON_BLOCKER_ITERATORS_SKELETON_BLOCKERS_EDGES_ITERATORS_H_ diff --git a/src/Skeleton_blocker/include/gudhi/Skeleton_blocker/iterators/Skeleton_blockers_iterators.h b/src/Skeleton_blocker/include/gudhi/Skeleton_blocker/iterators/Skeleton_blockers_iterators.h index 20a94734..cc3ed276 100644 --- a/src/Skeleton_blocker/include/gudhi/Skeleton_blocker/iterators/Skeleton_blockers_iterators.h +++ b/src/Skeleton_blocker/include/gudhi/Skeleton_blocker/iterators/Skeleton_blockers_iterators.h @@ -19,17 +19,14 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#ifndef GUDHI_SKELETON_BLOCKERS_ITERATORS_H_ -#define GUDHI_SKELETON_BLOCKERS_ITERATORS_H_ +#ifndef SKELETON_BLOCKER_ITERATORS_SKELETON_BLOCKERS_ITERATORS_H_ +#define SKELETON_BLOCKER_ITERATORS_SKELETON_BLOCKERS_ITERATORS_H_ -#include "Skeleton_blockers_vertices_iterators.h" -#include "Skeleton_blockers_edges_iterators.h" -#include "Skeleton_blockers_blockers_iterators.h" -#include "Skeleton_blockers_triangles_iterators.h" -#include "Skeleton_blockers_simplices_iterators.h" +#include <gudhi/Skeleton_blocker/iterators/Skeleton_blockers_vertices_iterators.h> +#include <gudhi/Skeleton_blocker/iterators/Skeleton_blockers_edges_iterators.h> +#include <gudhi/Skeleton_blocker/iterators/Skeleton_blockers_blockers_iterators.h> +#include <gudhi/Skeleton_blocker/iterators/Skeleton_blockers_triangles_iterators.h> +#include <gudhi/Skeleton_blocker/iterators/Skeleton_blockers_simplices_iterators.h> - - - -#endif /* GUDHI_SKELETON_BLOCKERS_ITERATORS_H_ */ +#endif // SKELETON_BLOCKER_ITERATORS_SKELETON_BLOCKERS_ITERATORS_H_ diff --git a/src/Skeleton_blocker/include/gudhi/Skeleton_blocker/iterators/Skeleton_blockers_simplices_iterators.h b/src/Skeleton_blocker/include/gudhi/Skeleton_blocker/iterators/Skeleton_blockers_simplices_iterators.h index f9d4d072..4d71b3f5 100644 --- a/src/Skeleton_blocker/include/gudhi/Skeleton_blocker/iterators/Skeleton_blockers_simplices_iterators.h +++ b/src/Skeleton_blocker/include/gudhi/Skeleton_blocker/iterators/Skeleton_blockers_simplices_iterators.h @@ -19,20 +19,20 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#ifndef GUDHI_SKELETON_BLOCKERS_SIMPLICES_ITERATORS_H_ -#define GUDHI_SKELETON_BLOCKERS_SIMPLICES_ITERATORS_H_ +#ifndef SKELETON_BLOCKER_ITERATORS_SKELETON_BLOCKERS_SIMPLICES_ITERATORS_H_ +#define SKELETON_BLOCKER_ITERATORS_SKELETON_BLOCKERS_SIMPLICES_ITERATORS_H_ -#include "boost/iterator/iterator_facade.hpp" +#include <gudhi/Skeleton_blocker_link_complex.h> +#include <gudhi/Skeleton_blocker/Skeleton_blocker_link_superior.h> +#include <gudhi/Skeleton_blocker/internal/Trie.h> +#include <gudhi/Utils.h> + +#include <boost/iterator/iterator_facade.hpp> #include <memory> #include <list> #include <iostream> -#include "gudhi/Skeleton_blocker_link_complex.h" -#include "gudhi/Skeleton_blocker/Skeleton_blocker_link_superior.h" -#include "gudhi/Skeleton_blocker/internal/Trie.h" -#include "gudhi/Utils.h" - namespace Gudhi { namespace skbl { @@ -68,7 +68,7 @@ public boost::iterator_facade < Simplex_around_vertex_iterator<SkeletonBlockerCo Vertex_handle v; std::shared_ptr<Link> link_v; std::shared_ptr<Trie> trie; - std::list<Trie*> nodes_to_be_seen; // todo deque + std::list<Trie*> nodes_to_be_seen; // todo deque public: Simplex_around_vertex_iterator() : complex(0) {} @@ -159,7 +159,7 @@ public boost::iterator_facade < Simplex_around_vertex_iterator<SkeletonBlockerCo bool both_non_empty = !nodes_to_be_seen.empty() && !other.nodes_to_be_seen.empty(); - if (!both_non_empty) return false; //one is empty the other is not + if (!both_non_empty) return false; // one is empty the other is not bool same_node = (**(nodes_to_be_seen.begin()) == **(other.nodes_to_be_seen.begin())); return same_node; @@ -174,7 +174,6 @@ public boost::iterator_facade < Simplex_around_vertex_iterator<SkeletonBlockerCo for (auto childs : first_node->childs) { nodes_to_be_seen.push_back(childs.get()); } - } Simplex_handle dereference() const { @@ -309,4 +308,4 @@ public boost::iterator_facade < Simplex_iterator<SkeletonBlockerComplex> } // namespace Gudhi -#endif // GUDHI_SKELETON_BLOCKERS_SIMPLICES_ITERATORS_H_ +#endif // SKELETON_BLOCKER_ITERATORS_SKELETON_BLOCKERS_SIMPLICES_ITERATORS_H_ diff --git a/src/Skeleton_blocker/include/gudhi/Skeleton_blocker/iterators/Skeleton_blockers_triangles_iterators.h b/src/Skeleton_blocker/include/gudhi/Skeleton_blocker/iterators/Skeleton_blockers_triangles_iterators.h index e137d1ea..28f5805d 100644 --- a/src/Skeleton_blocker/include/gudhi/Skeleton_blocker/iterators/Skeleton_blockers_triangles_iterators.h +++ b/src/Skeleton_blocker/include/gudhi/Skeleton_blocker/iterators/Skeleton_blockers_triangles_iterators.h @@ -1,117 +1,108 @@ - /* 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 <http://www.gnu.org/licenses/>. - */ -#ifndef GUDHI_SKELETON_BLOCKERS_TRIANGLES_ITERATORS_H_ -#define GUDHI_SKELETON_BLOCKERS_TRIANGLES_ITERATORS_H_ - -#include "boost/iterator/iterator_facade.hpp" +/* 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 <http://www.gnu.org/licenses/>. + */ +#ifndef SKELETON_BLOCKER_ITERATORS_SKELETON_BLOCKERS_TRIANGLES_ITERATORS_H_ +#define SKELETON_BLOCKER_ITERATORS_SKELETON_BLOCKERS_TRIANGLES_ITERATORS_H_ + +#include <boost/iterator/iterator_facade.hpp> #include <memory> -namespace Gudhi{ +namespace Gudhi { namespace skbl { -////////////////////////////////////////////////////////////////////// /** * \brief Iterator over the triangles that are * adjacent to a vertex of the simplicial complex. * \remark Will be removed soon -> dont look */ -template<typename Complex,typename LinkType> +template<typename Complex, typename LinkType> class Triangle_around_vertex_iterator : public boost::iterator_facade -< Triangle_around_vertex_iterator <Complex,LinkType> +< Triangle_around_vertex_iterator <Complex, LinkType> , typename Complex::Simplex_handle const , boost::forward_traversal_tag -, typename Complex::Simplex_handle const -> -{ - friend class boost::iterator_core_access; - template<typename T> friend class Triangle_iterator; -private: - typedef typename LinkType::Vertex_handle Vertex_handle; - typedef typename LinkType::Root_vertex_handle Root_vertex_handle; - typedef typename LinkType::Simplex_handle Simplex_handle; - typedef typename Complex::Complex_edge_iterator Complex_edge_iterator_; - - const Complex* complex_; - Vertex_handle v_; - std::shared_ptr<LinkType> link_; - Complex_edge_iterator_ current_edge_; - bool is_end_; -public: - Triangle_around_vertex_iterator(const Complex* complex,Vertex_handle v): - complex_(complex),v_(v),link_(new LinkType(*complex,v_)), - current_edge_(link_->edge_range().begin()), - is_end_(current_edge_ == link_->edge_range().end()){ - } - - /** - * @brief ugly hack to get an iterator to the end - */ - Triangle_around_vertex_iterator(const Complex* complex,Vertex_handle v,bool is_end): - complex_(complex),v_(v),link_(0),is_end_(true){ - } - - /** - * @brief ugly hack to get an iterator to the end - */ - Triangle_around_vertex_iterator(): - complex_(0),v_(-1),link_(0),is_end_(true){ - } - - - Triangle_around_vertex_iterator(const Triangle_around_vertex_iterator& other){ - v_ = other.v_; - complex_ = other.complex_; - is_end_ = other.is_end_; - - if(!is_end_){ - link_ = other.link_; - current_edge_= other.current_edge_; - } - } - - bool equal(const Triangle_around_vertex_iterator& other) const{ - return (complex_==other.complex_) && ((finished() &&other.finished()) || current_edge_ == other.current_edge_); - } - - Simplex_handle dereference() const{ - Root_vertex_handle v1 = (*link_)[*current_edge_].first(); - Root_vertex_handle v2 = (*link_)[*current_edge_].second(); - return Simplex_handle(v_,*(complex_->get_address(v1)),*(complex_->get_address(v2))); - } - - void increment(){ - ++current_edge_; - } - -private: - bool finished() const{ - return is_end_ || (current_edge_ == link_->edge_range().end()); - } - +, typename Complex::Simplex_handle const> { + friend class boost::iterator_core_access; + template<typename T> friend class Triangle_iterator; + private: + typedef typename LinkType::Vertex_handle Vertex_handle; + typedef typename LinkType::Root_vertex_handle Root_vertex_handle; + typedef typename LinkType::Simplex_handle Simplex_handle; + typedef typename Complex::Complex_edge_iterator Complex_edge_iterator_; + + const Complex* complex_; + Vertex_handle v_; + std::shared_ptr<LinkType> link_; + Complex_edge_iterator_ current_edge_; + bool is_end_; + + public: + Triangle_around_vertex_iterator(const Complex* complex, Vertex_handle v) : + complex_(complex), v_(v), link_(new LinkType(*complex, v_)), + current_edge_(link_->edge_range().begin()), + is_end_(current_edge_ == link_->edge_range().end()) { } + + /** + * @brief ugly hack to get an iterator to the end + */ + Triangle_around_vertex_iterator(const Complex* complex, Vertex_handle v, bool is_end) : + complex_(complex), v_(v), link_(0), is_end_(true) { } + + /** + * @brief ugly hack to get an iterator to the end + */ + Triangle_around_vertex_iterator() : + complex_(0), v_(-1), link_(0), is_end_(true) { } + + Triangle_around_vertex_iterator(const Triangle_around_vertex_iterator& other) { + v_ = other.v_; + complex_ = other.complex_; + is_end_ = other.is_end_; + + if (!is_end_) { + link_ = other.link_; + current_edge_ = other.current_edge_; + } + } + + bool equal(const Triangle_around_vertex_iterator& other) const { + return (complex_ == other.complex_) && ((finished() && other.finished()) || current_edge_ == other.current_edge_); + } + + Simplex_handle dereference() const { + Root_vertex_handle v1 = (*link_)[*current_edge_].first(); + Root_vertex_handle v2 = (*link_)[*current_edge_].second(); + return Simplex_handle(v_, *(complex_->get_address(v1)), *(complex_->get_address(v2))); + } + + void increment() { + ++current_edge_; + } + + private: + bool finished() const { + return is_end_ || (current_edge_ == link_->edge_range().end()); + } }; - - /** * \brief Iterator over the triangles of the * simplicial complex. @@ -119,121 +110,111 @@ private: * */ template<typename SkeletonBlockerComplex> -class Triangle_iterator : - public boost::iterator_facade< - Triangle_iterator <SkeletonBlockerComplex>, - typename SkeletonBlockerComplex::Simplex_handle const - , boost::forward_traversal_tag - , typename SkeletonBlockerComplex::Simplex_handle const - > -{ - friend class boost::iterator_core_access; -private: - typedef typename SkeletonBlockerComplex::Vertex_handle Vertex_handle; - typedef typename SkeletonBlockerComplex::Root_vertex_handle Root_vertex_handle; - typedef typename SkeletonBlockerComplex::Simplex_handle Simplex_handle; - typedef typename SkeletonBlockerComplex::Superior_triangle_around_vertex_iterator STAVI; - typedef typename SkeletonBlockerComplex::Complex_vertex_iterator Complex_vertex_iterator; - - const SkeletonBlockerComplex* complex_; - Complex_vertex_iterator current_vertex_; - STAVI current_triangle_; - bool is_end_; -public: - - /* - * @remark assume that the complex is non-empty - */ - Triangle_iterator(const SkeletonBlockerComplex* complex): - complex_(complex), - current_vertex_(complex->vertex_range().begin()), - current_triangle_(complex,*current_vertex_), // xxx this line is problematic is the complex is empty - is_end_(false){ - - assert(!complex->empty()); - gotoFirstTriangle(); - } - -private: - //goto to the first triangle or to the end if none - void gotoFirstTriangle(){ - if(!is_finished() && current_triangle_.finished()){ - goto_next_vertex(); - } - } -public: - - /** - * @brief ugly hack to get an iterator to the end - * @remark assume that the complex is non-empty - */ - Triangle_iterator(const SkeletonBlockerComplex* complex,bool is_end): - complex_(complex), - current_vertex_(complex->vertex_range().end()), - current_triangle_(), // xxx this line is problematic is the complex is empty - is_end_(true){ - } - - - Triangle_iterator& operator=(const Triangle_iterator & other){ - complex_ = other.complex_; - Complex_vertex_iterator current_vertex_; - STAVI current_triangle_; - return *this; - } - - - bool equal(const Triangle_iterator& other) const{ - bool both_are_finished = is_finished() && other.is_finished(); - bool both_arent_finished = !is_finished() && !other.is_finished(); - // if the two iterators are not finished, they must have the same state - return (complex_==other.complex_) && - (both_are_finished || - ( (both_arent_finished) && current_vertex_ == other.current_vertex_ && current_triangle_ == other.current_triangle_)); - - } - - Simplex_handle dereference() const{ - return *current_triangle_; - } - -private: - - // goto the next vertex that has a triangle pending or the - // end vertex iterator if none exists - void goto_next_vertex(){ - assert(current_triangle_.finished()); //we mush have consume all triangles passing through the vertex - assert(!is_finished()); // we must not be done - - ++current_vertex_; - - if(!is_finished()){ - current_triangle_ = STAVI(complex_, *current_vertex_); - if(current_triangle_.finished()) - goto_next_vertex(); - } - } -public: - void increment(){ - if(!current_triangle_.finished()){ - ++current_triangle_; // problem here - if(current_triangle_.finished()) - goto_next_vertex(); - } - else{ - assert(!is_finished()); - goto_next_vertex(); - } - } - -private: - bool is_finished() const{ - return is_end_ || current_vertex_ == complex_->vertex_range().end(); - } +class Triangle_iterator : public boost::iterator_facade< +Triangle_iterator <SkeletonBlockerComplex>, +typename SkeletonBlockerComplex::Simplex_handle const +, boost::forward_traversal_tag +, typename SkeletonBlockerComplex::Simplex_handle const> { + friend class boost::iterator_core_access; + private: + typedef typename SkeletonBlockerComplex::Vertex_handle Vertex_handle; + typedef typename SkeletonBlockerComplex::Root_vertex_handle Root_vertex_handle; + typedef typename SkeletonBlockerComplex::Simplex_handle Simplex_handle; + typedef typename SkeletonBlockerComplex::Superior_triangle_around_vertex_iterator STAVI; + typedef typename SkeletonBlockerComplex::Complex_vertex_iterator Complex_vertex_iterator; + + const SkeletonBlockerComplex* complex_; + Complex_vertex_iterator current_vertex_; + STAVI current_triangle_; + bool is_end_; + + public: + /* + * @remark assume that the complex is non-empty + */ + Triangle_iterator(const SkeletonBlockerComplex* complex) : + complex_(complex), + current_vertex_(complex->vertex_range().begin()), + current_triangle_(complex, *current_vertex_), // xxx this line is problematic is the complex is empty + is_end_(false) { + assert(!complex->empty()); + gotoFirstTriangle(); + } + + private: + // goto to the first triangle or to the end if none + void gotoFirstTriangle() { + if (!is_finished() && current_triangle_.finished()) { + goto_next_vertex(); + } + } + + public: + /** + * @brief ugly hack to get an iterator to the end + * @remark assume that the complex is non-empty + */ + Triangle_iterator(const SkeletonBlockerComplex* complex, bool is_end) : + complex_(complex), + current_vertex_(complex->vertex_range().end()), + current_triangle_(), // xxx this line is problematic is the complex is empty + is_end_(true) { } + + Triangle_iterator& operator=(const Triangle_iterator & other) { + complex_ = other.complex_; + Complex_vertex_iterator current_vertex_; + STAVI current_triangle_; + return *this; + } + + bool equal(const Triangle_iterator& other) const { + bool both_are_finished = is_finished() && other.is_finished(); + bool both_arent_finished = !is_finished() && !other.is_finished(); + // if the two iterators are not finished, they must have the same state + return (complex_ == other.complex_) && (both_are_finished || ((both_arent_finished) && + current_vertex_ == other.current_vertex_ && current_triangle_ == other.current_triangle_)); + } + + Simplex_handle dereference() const { + return *current_triangle_; + } + + private: + // goto the next vertex that has a triangle pending or the + // end vertex iterator if none exists + void goto_next_vertex() { + assert(current_triangle_.finished()); // we mush have consume all triangles passing through the vertex + assert(!is_finished()); // we must not be done + + ++current_vertex_; + + if (!is_finished()) { + current_triangle_ = STAVI(complex_, *current_vertex_); + if (current_triangle_.finished()) + goto_next_vertex(); + } + } + + public: + void increment() { + if (!current_triangle_.finished()) { + ++current_triangle_; // problem here + if (current_triangle_.finished()) + goto_next_vertex(); + } else { + assert(!is_finished()); + goto_next_vertex(); + } + } + + private: + bool is_finished() const { + return is_end_ || current_vertex_ == complex_->vertex_range().end(); + } }; -} +} // namespace skbl -} // namespace GUDHI +} // namespace Gudhi -#endif /* GUDHI_SKELETON_BLOCKERS_TRIANGLES_ITERATORS_H_ */ +#endif // SKELETON_BLOCKER_ITERATORS_SKELETON_BLOCKERS_TRIANGLES_ITERATORS_H_ diff --git a/src/Skeleton_blocker/include/gudhi/Skeleton_blocker/iterators/Skeleton_blockers_vertices_iterators.h b/src/Skeleton_blocker/include/gudhi/Skeleton_blocker/iterators/Skeleton_blockers_vertices_iterators.h index a9d4e373..14ae136a 100644 --- a/src/Skeleton_blocker/include/gudhi/Skeleton_blocker/iterators/Skeleton_blockers_vertices_iterators.h +++ b/src/Skeleton_blocker/include/gudhi/Skeleton_blocker/iterators/Skeleton_blockers_vertices_iterators.h @@ -1,31 +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 <http://www.gnu.org/licenses/>. - */ -#ifndef GUDHI_SKELETON_BLOCKERS_VERTICES_ITERATORS_H_ -#define GUDHI_SKELETON_BLOCKERS_VERTICES_ITERATORS_H_ - -#include "boost/iterator/iterator_facade.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 <http://www.gnu.org/licenses/>. + */ +#ifndef SKELETON_BLOCKER_ITERATORS_SKELETON_BLOCKERS_VERTICES_ITERATORS_H_ +#define SKELETON_BLOCKER_ITERATORS_SKELETON_BLOCKERS_VERTICES_ITERATORS_H_ + +#include <boost/iterator/iterator_facade.hpp> + +#include <utility> // for pair<> + +namespace Gudhi { namespace skbl { @@ -35,148 +36,137 @@ namespace skbl { *@remark Incrementation increases Vertex_handle. */ template<typename SkeletonBlockerComplex> -class Vertex_iterator : public boost::iterator_facade -< Vertex_iterator <SkeletonBlockerComplex> - , typename SkeletonBlockerComplex::Vertex_handle const - , boost::forward_traversal_tag - , typename SkeletonBlockerComplex::Vertex_handle const - > -{ - friend class boost::iterator_core_access; - - typedef typename SkeletonBlockerComplex::boost_vertex_iterator boost_vertex_iterator; - typedef typename SkeletonBlockerComplex::Vertex_handle Vertex_handle; -private: - const SkeletonBlockerComplex* complex; - std::pair<boost_vertex_iterator,boost_vertex_iterator> vertexIterator; - - -public: - Vertex_iterator():complex(NULL){ - } - - Vertex_iterator(const SkeletonBlockerComplex* complex_): - complex(complex_), - vertexIterator(vertices(complex_->skeleton)){ - if(!finished() && !is_active()) { - goto_next_valid(); - } - } - - /** - * return an iterator to the end. - */ - Vertex_iterator(const SkeletonBlockerComplex* complex_,int end): - complex(complex_),vertexIterator(vertices(complex_->skeleton)){ - vertexIterator.first = vertexIterator.second ; - } - -public: - void increment () {goto_next_valid();} - Vertex_handle dereference() const { - return(Vertex_handle(*(vertexIterator.first))); - } - - bool equal(const Vertex_iterator& other) const{ - return vertexIterator == other.vertexIterator && complex == other.complex; - } - - bool operator<(const Vertex_iterator& other) const{ - return dereference()<other.dereference(); - } - -private: - bool finished() const{ - return vertexIterator.first == vertexIterator.second; - } - - void goto_next_valid(){ - ++vertexIterator.first; - if(!finished() && !is_active()){ - goto_next_valid(); - } - } - - bool is_active() const{ - return ((*complex)[Vertex_handle(*vertexIterator.first)]).is_active(); - } - +class Vertex_iterator : public boost::iterator_facade< Vertex_iterator <SkeletonBlockerComplex> +, typename SkeletonBlockerComplex::Vertex_handle const +, boost::forward_traversal_tag +, typename SkeletonBlockerComplex::Vertex_handle const> { + friend class boost::iterator_core_access; + + typedef typename SkeletonBlockerComplex::boost_vertex_iterator boost_vertex_iterator; + typedef typename SkeletonBlockerComplex::Vertex_handle Vertex_handle; + private: + const SkeletonBlockerComplex* complex; + std::pair<boost_vertex_iterator, boost_vertex_iterator> vertexIterator; + + + public: + Vertex_iterator() : complex(NULL) { } + + Vertex_iterator(const SkeletonBlockerComplex* complex_) : + complex(complex_), + vertexIterator(vertices(complex_->skeleton)) { + if (!finished() && !is_active()) { + goto_next_valid(); + } + } + + /** + * return an iterator to the end. + */ + Vertex_iterator(const SkeletonBlockerComplex* complex_, int end) : + complex(complex_), vertexIterator(vertices(complex_->skeleton)) { + vertexIterator.first = vertexIterator.second; + } + + public: + void increment() { + goto_next_valid(); + } + + Vertex_handle dereference() const { + return (Vertex_handle(*(vertexIterator.first))); + } + + bool equal(const Vertex_iterator& other) const { + return vertexIterator == other.vertexIterator && complex == other.complex; + } + + bool operator<(const Vertex_iterator& other) const { + return dereference() < other.dereference(); + } + + private: + bool finished() const { + return vertexIterator.first == vertexIterator.second; + } + + void goto_next_valid() { + ++vertexIterator.first; + if (!finished() && !is_active()) { + goto_next_valid(); + } + } + + bool is_active() const { + return ((*complex)[Vertex_handle(*vertexIterator.first)]).is_active(); + } }; - - - template<typename SkeletonBlockerComplex> -class Neighbors_vertices_iterator -: public boost::iterator_facade < Neighbors_vertices_iterator<SkeletonBlockerComplex> - , typename SkeletonBlockerComplex::Vertex_handle const - , boost::forward_traversal_tag - , typename SkeletonBlockerComplex::Vertex_handle const - > -{ - friend class boost::iterator_core_access; - - typedef SkeletonBlockerComplex Complex; - typedef typename Complex::boost_adjacency_iterator boost_adjacency_iterator; - typedef typename Complex::Vertex_handle Vertex_handle; - typedef typename Complex::Edge_handle Edge_handle; - -private: - - const Complex* complex; - Vertex_handle v; - - boost_adjacency_iterator current_; - boost_adjacency_iterator end_; - -public: - // boost_adjacency_iterator ai, ai_end; - // for (tie(ai, ai_end) = adjacent_vertices(v.vertex, skeleton); ai != ai_end; ++ai){ - - Neighbors_vertices_iterator():complex(NULL){ - } - - Neighbors_vertices_iterator(const Complex* complex_,Vertex_handle v_): - complex(complex_), - v(v_){ - tie(current_,end_) = adjacent_vertices(v.vertex, complex->skeleton); - } - - /** - * returns an iterator to the end - */ - Neighbors_vertices_iterator(const Complex* complex_,Vertex_handle v_,int end): - complex(complex_), - v(v_){ - tie(current_,end_) = adjacent_vertices(v.vertex, complex->skeleton); - set_end(); - } - - - void increment () { - if(current_ != end_) - ++current_; - } - - Vertex_handle dereference() const { - return(Vertex_handle(*current_)); - } - - bool equal(const Neighbors_vertices_iterator& other) const{ - return (complex== other.complex) && (v == other.v) && (current_ == other.current_) && (end_ == other.end_); - } - -private: - //todo remove this ugly hack - void set_end(){ - current_ = end_; - } +class Neighbors_vertices_iterator: public boost::iterator_facade < Neighbors_vertices_iterator<SkeletonBlockerComplex> +, typename SkeletonBlockerComplex::Vertex_handle const +, boost::forward_traversal_tag +, typename SkeletonBlockerComplex::Vertex_handle const> { + friend class boost::iterator_core_access; + + typedef SkeletonBlockerComplex Complex; + typedef typename Complex::boost_adjacency_iterator boost_adjacency_iterator; + typedef typename Complex::Vertex_handle Vertex_handle; + typedef typename Complex::Edge_handle Edge_handle; + + private: + const Complex* complex; + Vertex_handle v; + + boost_adjacency_iterator current_; + boost_adjacency_iterator end_; + + public: + // boost_adjacency_iterator ai, ai_end; + // for (tie(ai, ai_end) = adjacent_vertices(v.vertex, skeleton); ai != ai_end; ++ai) { + + Neighbors_vertices_iterator() : complex(NULL) { } + + Neighbors_vertices_iterator(const Complex* complex_, Vertex_handle v_) : + complex(complex_), + v(v_) { + tie(current_, end_) = adjacent_vertices(v.vertex, complex->skeleton); + } + + /** + * returns an iterator to the end + */ + Neighbors_vertices_iterator(const Complex* complex_, Vertex_handle v_, int end) : + complex(complex_), + v(v_) { + tie(current_, end_) = adjacent_vertices(v.vertex, complex->skeleton); + set_end(); + } + + void increment() { + if (current_ != end_) + ++current_; + } + + Vertex_handle dereference() const { + return (Vertex_handle(*current_)); + } + + bool equal(const Neighbors_vertices_iterator& other) const { + return (complex == other.complex) && (v == other.v) && (current_ == other.current_) && (end_ == other.end_); + } + + private: + // todo remove this ugly hack + void set_end() { + current_ = end_; + } }; -} +} // namespace skbl -} // namespace GUDHI +} // namespace Gudhi -#endif /* GUDHI_SKELETON_BLOCKERS_VERTICES_ITERATORS_H_ */ +#endif // SKELETON_BLOCKER_ITERATORS_SKELETON_BLOCKERS_VERTICES_ITERATORS_H_ diff --git a/src/Skeleton_blocker/include/gudhi/Skeleton_blocker_complex.h b/src/Skeleton_blocker/include/gudhi/Skeleton_blocker_complex.h index 700830f2..07f371a2 100644 --- a/src/Skeleton_blocker/include/gudhi/Skeleton_blocker_complex.h +++ b/src/Skeleton_blocker/include/gudhi/Skeleton_blocker_complex.h @@ -20,8 +20,20 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#ifndef SRC_SKELETON_BLOCKER_INCLUDE_GUDHI_SKELETON_BLOCKER_COMPLEX_H_ -#define SRC_SKELETON_BLOCKER_INCLUDE_GUDHI_SKELETON_BLOCKER_COMPLEX_H_ +#ifndef SKELETON_BLOCKER_COMPLEX_H_ +#define SKELETON_BLOCKER_COMPLEX_H_ + +#include <gudhi/Skeleton_blocker/iterators/Skeleton_blockers_iterators.h> +#include <gudhi/Skeleton_blocker_link_complex.h> +#include <gudhi/Skeleton_blocker/Skeleton_blocker_link_superior.h> +#include <gudhi/Skeleton_blocker/Skeleton_blocker_sub_complex.h> +#include <gudhi/Skeleton_blocker/Skeleton_blocker_simplex.h> + +#include <gudhi/Skeleton_blocker/Skeleton_blocker_complex_visitor.h> +#include <gudhi/Skeleton_blocker/internal/Top_faces.h> +#include <gudhi/Skeleton_blocker/internal/Trie.h> + +#include <gudhi/Utils.h> #include <boost/graph/adjacency_list.hpp> #include <boost/graph/connected_components.hpp> @@ -40,18 +52,6 @@ #include <algorithm> #include <utility> -#include "gudhi/Skeleton_blocker/iterators/Skeleton_blockers_iterators.h" -#include "gudhi/Skeleton_blocker_link_complex.h" -#include "gudhi/Skeleton_blocker/Skeleton_blocker_link_superior.h" -#include "gudhi/Skeleton_blocker/Skeleton_blocker_sub_complex.h" -#include "gudhi/Skeleton_blocker/Skeleton_blocker_simplex.h" - -#include "gudhi/Skeleton_blocker/Skeleton_blocker_complex_visitor.h" -#include "gudhi/Skeleton_blocker/internal/Top_faces.h" -#include "gudhi/Skeleton_blocker/internal/Trie.h" - -#include "gudhi/Utils.h" - namespace Gudhi { namespace skbl { @@ -1406,7 +1406,8 @@ class Skeleton_blocker_complex { Const_complex_blocker_around_vertex_iterator; typedef boost::iterator_range <Complex_blocker_around_vertex_iterator> Complex_blocker_around_vertex_range; - typedef boost::iterator_range <Const_complex_blocker_around_vertex_iterator> Const_complex_blocker_around_vertex_range; + typedef boost::iterator_range <Const_complex_blocker_around_vertex_iterator> + Const_complex_blocker_around_vertex_range; public: /** @@ -1514,7 +1515,7 @@ class Skeleton_blocker_complex { * return the total number of simplices */ template<typename Complex, typename SimplexHandleIterator> -Complex make_complex_from_top_faces(SimplexHandleIterator simplex_begin, SimplexHandleIterator simplex_end, +Complex make_complex_from_top_faces(SimplexHandleIterator simplex_begin, SimplexHandleIterator simplex_end, bool is_flag_complex = false) { typedef typename Complex::Simplex_handle Simplex_handle; std::vector<Simplex_handle> simplices; @@ -1531,6 +1532,4 @@ Complex make_complex_from_top_faces(SimplexHandleIterator simplex_begin, Simplex #include "Skeleton_blocker_simplifiable_complex.h" - -#endif // SRC_SKELETON_BLOCKER_INCLUDE_GUDHI_SKELETON_BLOCKER_COMPLEX_H_ - +#endif // SKELETON_BLOCKER_COMPLEX_H_ diff --git a/src/Skeleton_blocker/include/gudhi/Skeleton_blocker_geometric_complex.h b/src/Skeleton_blocker/include/gudhi/Skeleton_blocker_geometric_complex.h index 3eff1ba3..b8395251 100644 --- a/src/Skeleton_blocker/include/gudhi/Skeleton_blocker_geometric_complex.h +++ b/src/Skeleton_blocker/include/gudhi/Skeleton_blocker_geometric_complex.h @@ -19,12 +19,12 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#ifndef SRC_SKELETON_BLOCKER_INCLUDE_GUDHI_SKELETON_BLOCKER_GEOMETRIC_COMPLEX_H_ -#define SRC_SKELETON_BLOCKER_INCLUDE_GUDHI_SKELETON_BLOCKER_GEOMETRIC_COMPLEX_H_ +#ifndef SKELETON_BLOCKER_GEOMETRIC_COMPLEX_H_ +#define SKELETON_BLOCKER_GEOMETRIC_COMPLEX_H_ -#include "gudhi/Utils.h" -#include "gudhi/Skeleton_blocker_complex.h" -#include "gudhi/Skeleton_blocker/Skeleton_blocker_sub_complex.h" +#include <gudhi/Utils.h> +#include <gudhi/Skeleton_blocker_complex.h> +#include <gudhi/Skeleton_blocker/Skeleton_blocker_sub_complex.h> namespace Gudhi { @@ -221,4 +221,4 @@ SkeletonBlockerGeometricComplex make_complex_from_top_faces( } // namespace Gudhi -#endif // SRC_SKELETON_BLOCKER_INCLUDE_GUDHI_SKELETON_BLOCKER_GEOMETRIC_COMPLEX_H_ +#endif // SKELETON_BLOCKER_GEOMETRIC_COMPLEX_H_ diff --git a/src/Skeleton_blocker/include/gudhi/Skeleton_blocker_link_complex.h b/src/Skeleton_blocker/include/gudhi/Skeleton_blocker_link_complex.h index 725ecce5..95d8fa97 100644 --- a/src/Skeleton_blocker/include/gudhi/Skeleton_blocker_link_complex.h +++ b/src/Skeleton_blocker/include/gudhi/Skeleton_blocker_link_complex.h @@ -19,11 +19,11 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#ifndef SRC_SKELETON_BLOCKER_INCLUDE_GUDHI_SKELETON_BLOCKER_LINK_COMPLEX_H_ -#define SRC_SKELETON_BLOCKER_INCLUDE_GUDHI_SKELETON_BLOCKER_LINK_COMPLEX_H_ +#ifndef SKELETON_BLOCKER_LINK_COMPLEX_H_ +#define SKELETON_BLOCKER_LINK_COMPLEX_H_ -#include "gudhi/Utils.h" -#include "gudhi/Skeleton_blocker_complex.h" +#include <gudhi/Utils.h> +#include <gudhi/Skeleton_blocker_complex.h> namespace Gudhi { @@ -297,4 +297,4 @@ class Skeleton_blocker_link_complex : public Skeleton_blocker_sub_complex< } // namespace Gudhi -#endif // SRC_SKELETON_BLOCKER_INCLUDE_GUDHI_SKELETON_BLOCKER_LINK_COMPLEX_H_ +#endif // SKELETON_BLOCKER_LINK_COMPLEX_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 57e1daf0..17a237a7 100644 --- a/src/Skeleton_blocker/include/gudhi/Skeleton_blocker_simplifiable_complex.h +++ b/src/Skeleton_blocker/include/gudhi/Skeleton_blocker_simplifiable_complex.h @@ -19,15 +19,15 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#ifndef SRC_SKELETON_BLOCKER_INCLUDE_GUDHI_SKELETON_BLOCKER_SIMPLIFIABLE_COMPLEX_H_ -#define SRC_SKELETON_BLOCKER_INCLUDE_GUDHI_SKELETON_BLOCKER_SIMPLIFIABLE_COMPLEX_H_ +#ifndef SKELETON_BLOCKER_SIMPLIFIABLE_COMPLEX_H_ +#define SKELETON_BLOCKER_SIMPLIFIABLE_COMPLEX_H_ + +#include <gudhi/Skeleton_blocker/Skeleton_blocker_sub_complex.h> #include <list> #include <vector> #include <set> -#include "gudhi/Skeleton_blocker/Skeleton_blocker_sub_complex.h" - namespace Gudhi { namespace skbl { @@ -340,7 +340,7 @@ Skeleton_blocker_complex<SkeletonBlockerDS>::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. @@ -447,4 +447,4 @@ Skeleton_blocker_complex<SkeletonBlockerDS>::notify_changed_edges(Vertex_handle } // namespace Gudhi -#endif // SRC_SKELETON_BLOCKER_INCLUDE_GUDHI_SKELETON_BLOCKER_SIMPLIFIABLE_COMPLEX_H_ +#endif // SKELETON_BLOCKER_SIMPLIFIABLE_COMPLEX_H_ 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) 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/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, <montel@kde.org> +# Copyright (c) 2008, 2009 Gael Guennebaud, <g.gael@free.fr> +# Copyright (c) 2009 Benoit Jacob <jacob.benoit.1@gmail.com> +# 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) diff --git a/src/common/example/CMakeLists.txt b/src/common/example/CMakeLists.txt index 4cb03dbe..d29e31e7 100644 --- a/src/common/example/CMakeLists.txt +++ b/src/common/example/CMakeLists.txt @@ -7,6 +7,20 @@ if(CGAL_FOUND) 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/common/include/gudhi/Clock.h b/src/common/include/gudhi/Clock.h index 08096c05..04c6ffb9 100644 --- a/src/common/include/gudhi/Clock.h +++ b/src/common/include/gudhi/Clock.h @@ -1,82 +1,79 @@ - /* 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 <http://www.gnu.org/licenses/>. - */ - -#ifndef GUDHI_CLOCK_H_ -#define GUDHI_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. + * + * 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 <http://www.gnu.org/licenses/>. + */ + +#ifndef CLOCK_H_ +#define CLOCK_H_ #include <boost/date_time/posix_time/posix_time.hpp> -class Clock{ - -public: - Clock():end_called(false){ - startTime = boost::posix_time::microsec_clock::local_time( ); - } - - Clock(const std::string& msg_){ - end_called = false; - begin(); - msg = msg_; - } - - - void begin() const{ - end_called = false; - startTime = boost::posix_time::microsec_clock::local_time( ); - } - - void end() const{ - end_called = true; - endTime = boost::posix_time::microsec_clock::local_time( ); - } - - void print() const{ - std::cout << *this << std::endl; - } - - friend std::ostream& operator<< (std::ostream& stream,const Clock& clock){ - if(!clock.end_called) - clock.end(); - - if(!clock.end_called) stream << "end not called"; - else{ - stream << clock.msg <<":"<<clock.num_seconds() <<"s"; - } - return stream; - - } - - double num_seconds() const{ - if(!end_called) return -1; - return (endTime-startTime).total_milliseconds()/1000.; - } - -private: - mutable boost::posix_time::ptime startTime, endTime; - mutable bool end_called; - std::string msg; - +#include <string> + +class Clock { + public: + Clock() : end_called(false) { + startTime = boost::posix_time::microsec_clock::local_time(); + } + + Clock(const std::string& msg_) { + end_called = false; + begin(); + msg = msg_; + } + + void begin() const { + end_called = false; + startTime = boost::posix_time::microsec_clock::local_time(); + } + + void end() const { + end_called = true; + endTime = boost::posix_time::microsec_clock::local_time(); + } + + void print() const { + std::cout << *this << std::endl; + } + + friend std::ostream& operator<<(std::ostream& stream, const Clock& clock) { + if (!clock.end_called) + clock.end(); + + if (!clock.end_called) { + stream << "end not called"; + } else { + stream << clock.msg << ":" << clock.num_seconds() << "s"; + } + return stream; + } + + double num_seconds() const { + if (!end_called) return -1; + return (endTime - startTime).total_milliseconds() / 1000.; + } + + private: + mutable boost::posix_time::ptime startTime, endTime; + mutable bool end_called; + std::string msg; }; - -#endif /* GUDHI_CLOCK_H_ */ +#endif // CLOCK_H_ diff --git a/src/common/include/gudhi/Off_reader.h b/src/common/include/gudhi/Off_reader.h index a8abb507..bba5a63a 100644 --- a/src/common/include/gudhi/Off_reader.h +++ b/src/common/include/gudhi/Off_reader.h @@ -1,13 +1,10 @@ -/* - * Off_reader.h - * Created on: Nov 28, 2014 - * 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,14 +22,15 @@ */ -#ifndef GUDHI_OFF_READER_H_ -#define GUDHI_OFF_READER_H_ +#ifndef OFF_READER_H_ +#define OFF_READER_H_ #include <sstream> #include <iostream> #include <iterator> - +#include <string> +#include <vector> namespace Gudhi { @@ -43,7 +41,6 @@ namespace Gudhi { */ class Off_reader { public: - Off_reader(std::ifstream& stream) : stream_(stream) { } ~Off_reader() { @@ -121,10 +118,11 @@ class Off_reader { std::cerr << "incorrect number of vertices/faces/edges\n"; return false; } - } else + } else { if (!(iss >> off_info_.dim >> off_info_.num_vertices >> off_info_.num_faces >> off_info_.num_edges)) { std::cerr << "incorrect number of vertices/faces/edges\n"; return false; + } } off_visitor.init(off_info_.dim, off_info_.num_vertices, off_info_.num_faces, off_info_.num_edges); @@ -147,7 +145,7 @@ class Off_reader { std::vector<double> point; std::istringstream iss(line); point.assign(std::istream_iterator<double>(iss), std::istream_iterator<double>()); - // if(point.size() != off_info_.dim) return false; + // if(point.size() != off_info_.dim) return false; visitor.point(point); } return true; @@ -162,7 +160,7 @@ class Off_reader { iss >> num_face_vertices; std::vector<int> face; face.assign(std::istream_iterator<int>(iss), std::istream_iterator<int>()); - if (!face.size() == off_info_.num_vertices) return false; + if (face.size() != off_info_.dim) return false; visitor.maximal_face(face); } return true; @@ -172,9 +170,9 @@ class Off_reader { template<typename OFFVisitor> void read_off(const std::string& name_file_off, OFFVisitor& vis) { std::ifstream stream(name_file_off); - if (!stream.is_open()) + if (!stream.is_open()) { std::cerr << "could not open file \n"; - else { + } else { Off_reader off_reader(stream); off_reader.read(vis); } @@ -182,4 +180,4 @@ void read_off(const std::string& name_file_off, OFFVisitor& vis) { } // namespace Gudhi -#endif // GUDHI_OFF_READER_H_ +#endif // OFF_READER_H_ diff --git a/src/common/include/gudhi/Point.h b/src/common/include/gudhi/Point.h index 4023445b..0479e71e 100644 --- a/src/common/include/gudhi/Point.h +++ b/src/common/include/gudhi/Point.h @@ -1,13 +1,10 @@ -/* - * Basic_geometry.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. * * 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,9 +21,8 @@ * */ - -#ifndef BASIC_GEOMETRY_H_ -#define BASIC_GEOMETRY_H_ +#ifndef POINT_H_ +#define POINT_H_ #include <cmath> #include <vector> @@ -34,143 +30,141 @@ #include <cstddef> #include <initializer_list> -class Point_d{ -public: - Point_d(size_t dim=3):coords_(dim,0){} - Point_d(const Point_d& other):coords_(other.coords_){} - Point_d(const std::initializer_list<double>& list):coords_(list) { - } - template<typename CoordsIt> - Point_d(CoordsIt begin,CoordsIt end):coords_(begin,end){} - - size_t dimension() const{ - return coords_.size(); - } - - double x() const{ - return coords_[0]; - } - - double y() const{ - return coords_[1]; - } - - double z() const{ - return coords_[2]; - } - - double& x(){ - return coords_[0]; - } - - double& y(){ - return coords_[1]; - } - - double& z(){ - return coords_[2]; - } - - std::vector<double>::const_iterator begin() const{ - return coords_.begin(); - } - - std::vector<double>::const_iterator end() const{ - return coords_.end(); - } - - double& operator[](unsigned i){ - return coords_[i]; - } - const double& operator[](unsigned i) const{ - return coords_[i]; - } - - double squared_norm() const{ - double res = 0; - for(auto x : coords_) - res+= x*x; - return res; - } - - friend double squared_dist(const Point_d& p1,const Point_d& p2){ - assert(p1.dimension()==p2.dimension()); - double res = 0; - for(unsigned i = 0; i < p1.coords_.size(); ++i) - res+= (p1[i]-p2[i])*(p1[i]-p2[i]); - return res; - } - - /** - * dot product - */ - double operator*(const Point_d& other) const{ - assert(dimension()==other.dimension()); - double res = 0; - for(unsigned i = 0; i < coords_.size(); ++i) - res+= coords_[i]*other[i]; - return res; - } - - /** - * only if points have dimension 3 - */ - Point_d cross_product(const Point_d& other){ - assert(dimension()==3 && other.dimension()==3); - Point_d res(3); - res[0] = (*this)[1] * other[2] - (*this)[2] * other[1]; - res[1] = (*this)[2] * other[0] - (*this)[0] * other[2]; - res[2] = (*this)[0] * other[1] - (*this)[1] * other[0]; - return res; - } - - Point_d operator+(const Point_d& other) const{ - assert(dimension()==other.dimension()); - Point_d res(dimension()); - for(unsigned i = 0; i < coords_.size(); ++i) - res[i] = (*this)[i] + other[i]; - return res; - } - - Point_d operator*(double lambda) const{ - Point_d res(dimension()); - for(unsigned i = 0; i < coords_.size(); ++i) - res[i] = (*this)[i] * lambda; - return res; - } - - Point_d operator/(double lambda) const{ - Point_d res(dimension()); - for(unsigned i = 0; i < coords_.size(); ++i) - res[i] = (*this)[i] / lambda; - return res; - } - - Point_d operator-(const Point_d& other) const{ - assert(dimension()==other.dimension()); - Point_d res(dimension()); - for(unsigned i = 0; i < coords_.size(); ++i) - res[i] = (*this)[i] - other[i]; - return res; - } - - friend Point_d unit_normal(const Point_d& p1,const Point_d& p2,const Point_d& p3){ - assert(p1.dimension()==3); - assert(p2.dimension()==3); - assert(p3.dimension()==3); - Point_d p1p2 = p2 - p1; - Point_d p1p3 = p3 - p1; - Point_d res(p1p2.cross_product(p1p3)); - return res / std::sqrt(res.squared_norm()); - } - - -private: - std::vector<double> coords_; +class Point_d { + public: + Point_d(size_t dim = 3) : coords_(dim, 0) { } + + Point_d(const Point_d& other) : coords_(other.coords_) { } + + Point_d(const std::initializer_list<double>& list) : coords_(list) { } + + template<typename CoordsIt> + Point_d(CoordsIt begin, CoordsIt end) : coords_(begin, end) { } + + size_t dimension() const { + return coords_.size(); + } + + double x() const { + return coords_[0]; + } + + double y() const { + return coords_[1]; + } + + double z() const { + return coords_[2]; + } + + double& x() { + return coords_[0]; + } + + double& y() { + return coords_[1]; + } + + double& z() { + return coords_[2]; + } + + std::vector<double>::const_iterator begin() const { + return coords_.begin(); + } + + std::vector<double>::const_iterator end() const { + return coords_.end(); + } + + double& operator[](unsigned i) { + return coords_[i]; + } + + const double& operator[](unsigned i) const { + return coords_[i]; + } + + double squared_norm() const { + double res = 0; + for (auto x : coords_) + res += x * x; + return res; + } + + friend double squared_dist(const Point_d& p1, const Point_d& p2) { + assert(p1.dimension() == p2.dimension()); + double res = 0; + for (unsigned i = 0; i < p1.coords_.size(); ++i) + res += (p1[i] - p2[i])*(p1[i] - p2[i]); + return res; + } + + /** + * dot product + */ + double operator*(const Point_d& other) const { + assert(dimension() == other.dimension()); + double res = 0; + for (unsigned i = 0; i < coords_.size(); ++i) + res += coords_[i] * other[i]; + return res; + } + + /** + * only if points have dimension 3 + */ + Point_d cross_product(const Point_d& other) { + assert(dimension() == 3 && other.dimension() == 3); + Point_d res(3); + res[0] = (*this)[1] * other[2] - (*this)[2] * other[1]; + res[1] = (*this)[2] * other[0] - (*this)[0] * other[2]; + res[2] = (*this)[0] * other[1] - (*this)[1] * other[0]; + return res; + } + + Point_d operator+(const Point_d& other) const { + assert(dimension() == other.dimension()); + Point_d res(dimension()); + for (unsigned i = 0; i < coords_.size(); ++i) + res[i] = (*this)[i] + other[i]; + return res; + } + + Point_d operator*(double lambda) const { + Point_d res(dimension()); + for (unsigned i = 0; i < coords_.size(); ++i) + res[i] = (*this)[i] * lambda; + return res; + } + + Point_d operator/(double lambda) const { + Point_d res(dimension()); + for (unsigned i = 0; i < coords_.size(); ++i) + res[i] = (*this)[i] / lambda; + return res; + } + + Point_d operator-(const Point_d& other) const { + assert(dimension() == other.dimension()); + Point_d res(dimension()); + for (unsigned i = 0; i < coords_.size(); ++i) + res[i] = (*this)[i] - other[i]; + return res; + } + + friend Point_d unit_normal(const Point_d& p1, const Point_d& p2, const Point_d& p3) { + assert(p1.dimension() == 3); + assert(p2.dimension() == 3); + assert(p3.dimension() == 3); + Point_d p1p2 = p2 - p1; + Point_d p1p3 = p3 - p1; + Point_d res(p1p2.cross_product(p1p3)); + return res / std::sqrt(res.squared_norm()); + } + + private: + std::vector<double> coords_; }; - - - - -#endif /* BASIC_GEOMETRY_H_ */ +#endif // POINT_H_ diff --git a/src/common/include/gudhi/Simple_object_pool.h b/src/common/include/gudhi/Simple_object_pool.h index fffcb2ef..fb9c8e23 100644 --- a/src/common/include/gudhi/Simple_object_pool.h +++ b/src/common/include/gudhi/Simple_object_pool.h @@ -20,45 +20,62 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ +#ifndef SIMPLE_OBJECT_POOL_H_ +#define SIMPLE_OBJECT_POOL_H_ + #include <boost/pool/pool.hpp> #include <utility> namespace Gudhi { - /** \private - * This is a simpler version of boost::object_pool, that requires - * that users explicitly destroy all objects. This lets the - * performance scale much better, see - * https://svn.boost.org/trac/boost/ticket/3789 . - */ + +/** \private + * This is a simpler version of boost::object_pool, that requires + * that users explicitly destroy all objects. This lets the + * performance scale much better, see + * https://svn.boost.org/trac/boost/ticket/3789 . + */ template <class T> -class Simple_object_pool : protected boost::pool<boost::default_user_allocator_malloc_free> -{ - protected: +class Simple_object_pool : protected boost::pool<boost::default_user_allocator_malloc_free> { + protected: typedef boost::pool<boost::default_user_allocator_malloc_free> Base; typedef T* pointer; - Base& base(){return *this;} - Base const& base()const{return *this;} - public: + + Base& base() { + return *this; + } + + Base const& base()const { + return *this; + } + + public: typedef T element_type; typedef boost::default_user_allocator_malloc_free user_allocator; typedef typename Base::size_type size_type; typedef typename Base::difference_type difference_type; + template<class...U> - Simple_object_pool(U&&...u) : Base(sizeof(T), std::forward<U>(u)...) {} + Simple_object_pool(U&&...u) : Base(sizeof (T), std::forward<U>(u)...) { } + template<class...U> - pointer construct(U&&...u){ - void* p=base().malloc BOOST_PREVENT_MACRO_SUBSTITUTION(); + pointer construct(U&&...u) { + void* p = base().malloc BOOST_PREVENT_MACRO_SUBSTITUTION(); assert(p); - try { new(p) T(std::forward<U>(u)...); } - catch(...) { + try { + new(p) T(std::forward<U>(u)...); + } catch (...) { base().free BOOST_PREVENT_MACRO_SUBSTITUTION(p); throw; } - return static_cast<pointer>(p); + return static_cast<pointer> (p); } - void destroy(pointer p){ + + void destroy(pointer p) { p->~T(); base().free BOOST_PREVENT_MACRO_SUBSTITUTION(p); } }; -} + +} // namespace Gudhi + +#endif // SIMPLE_OBJECT_POOL_H_ diff --git a/src/common/include/gudhi/Test.h b/src/common/include/gudhi/Test.h index 18b7ca82..6024c822 100644 --- a/src/common/include/gudhi/Test.h +++ b/src/common/include/gudhi/Test.h @@ -1,5 +1,28 @@ -#ifndef __TEST_H -#define __TEST_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 <http://www.gnu.org/licenses/>. + * + */ + +#ifndef TEST_H_ +#define TEST_H_ #include <list> #include <string> @@ -8,78 +31,75 @@ #include <iostream> -#define TEST(a) std::cout << "TEST: " << (a)<<std::endl -#define TESTMSG(a,b) std::cout << "TEST: " << a<<b<<std::endl -#define TESTVALUE(a) std::cout << "TEST: " << #a << ": " << a<<std::endl - +#define TEST(a) std::cout << "TEST: " << (a) << std::endl +#define TESTMSG(a, b) std::cout << "TEST: " << a << b << std::endl +#define TESTVALUE(a) std::cout << "TEST: " << #a << ": " << a << std::endl /** * Class to perform test */ -class Test -{ -private : - std::string name; - bool (*test)(); - - std::string separation() const{ - return "+++++++++++++++++++++++++++++++++++++++++++++++++\n"; - } - - std::string print_between_plus(std::string& s) const{ - std::stringstream res; - res << "+++++++++++++++++"<<s<<"+++++++++++++++++\n"; - return res.str(); - } - - -public: - Test(std::string name_,bool (*test_)()){ - name=name_; - test =test_; - } - - bool run(){ - std::cout << print_between_plus(name); - return test(); - } - std::string getName(){ - return name; - } +class Test { + private: + std::string name; + bool (*test)(); + + std::string separation() const { + return "+++++++++++++++++++++++++++++++++++++++++++++++++\n"; + } + + std::string print_between_plus(std::string& s) const { + std::stringstream res; + res << "+++++++++++++++++" << s << "+++++++++++++++++\n"; + return res.str(); + } + + public: + Test(std::string name_, bool (*test_)()) { + name = name_; + test = test_; + } + + bool run() { + std::cout << print_between_plus(name); + return test(); + } + + std::string getName() { + return name; + } }; - -class Tests -{ -private: - std::list<Test> tests; - -public: - void add(std::string name_,bool (*test_)()){ - Test test(name_,test_); - tests.push_back(test); - } - bool run(){ - bool tests_succesful(true); - std::vector<bool> res; - for (Test test : tests){ - res.push_back(test.run()); - } - std::cout << "\n\n results of tests : "<<std::endl; - int i=0; - for (Test t : tests){ - std::cout << "Test "<<i<< " \""<<t.getName()<<"\" --> "; - if (res[i++]) std::cout << "OK"<<std::endl; - else { - std::cout << "Fail"<<std::endl; - tests_succesful = false; - break; - } - } - return tests_succesful; - - } +class Tests { + private: + std::list<Test> tests; + + public: + void add(std::string name_, bool (*test_)()) { + Test test(name_, test_); + tests.push_back(test); + } + + bool run() { + bool tests_succesful(true); + std::vector<bool> res; + for (Test test : tests) { + res.push_back(test.run()); + } + std::cout << "\n\n results of tests : " << std::endl; + int i = 0; + for (Test t : tests) { + std::cout << "Test " << i << " \"" << t.getName() << "\" --> "; + if (res[i++]) { + std::cout << "OK" << std::endl; + } else { + std::cout << "Fail" << std::endl; + tests_succesful = false; + break; + } + } + return tests_succesful; + } }; -#endif +#endif // TEST_H_ diff --git a/src/common/include/gudhi/Utils.h b/src/common/include/gudhi/Utils.h index 7678685c..43916f11 100644 --- a/src/common/include/gudhi/Utils.h +++ b/src/common/include/gudhi/Utils.h @@ -1,48 +1,46 @@ - /* 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 <http://www.gnu.org/licenses/>. - */ -#ifndef GUDHI_UTILS_H_ -#define GUDHI_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. + * + * 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 <http://www.gnu.org/licenses/>. + */ +#ifndef UTILS_H_ +#define UTILS_H_ -#define PRINT(a) std::cerr << #a << ": " << (a) << " (DISP)"<<std::endl +#define PRINT(a) std::cerr << #a << ": " << (a) << " (DISP)" << std::endl -//#define DBG_VERBOSE +// #define DBG_VERBOSE #ifdef DBG_VERBOSE -#define DBG(a) std::cerr << "DBG: " << (a)<<std::endl -#define DBGMSG(a,b) std::cerr << "DBG: " << a<<b<<std::endl -#define DBGVALUE(a) std::cerr << "DBG: " << #a << ": " << a<<std::endl -#define DBGCONT(a) std::cerr << "DBG: container "<< #a<<" -> "; for(auto x:a) std::cerr<< x << ","; std::cerr<<std::endl +#define DBG(a) std::cerr << "DBG: " << (a) << std::endl +#define DBGMSG(a, b) std::cerr << "DBG: " << a << b << std::endl +#define DBGVALUE(a) std::cerr << "DBG: " << #a << ": " << a << std::endl +#define DBGCONT(a) std::cerr << "DBG: container " << #a << " -> "; for (auto x : a) std::cerr << x << ","; std::cerr << +std::endl #else -//#define DBG(a) a -//#define DBGMSG(a,b) b -//#define DBGVALUE(a) a -//#define DBGCONT(a) a +// #define DBG(a) a +// #define DBGMSG(a,b) b +// #define DBGVALUE(a) a +// #define DBGCONT(a) a #define DBG(a) -#define DBGMSG(a,b) +#define DBGMSG(a, b) #define DBGVALUE(a) #define DBGCONT(a) #endif - - - -#endif /* UTILS_H_ */ +#endif // UTILS_H_ diff --git a/src/common/include/gudhi/distance_functions.h b/src/common/include/gudhi/distance_functions.h index 7a2ab035..e5c79ded 100644 --- a/src/common/include/gudhi/distance_functions.h +++ b/src/common/include/gudhi/distance_functions.h @@ -1,37 +1,41 @@ - /* This file is part of the Gudhi Library. The Gudhi library - * (Geometric Understanding in Higher Dimensions) is a generic C++ - * library for computational topology. - * - * Author(s): Clément Maria - * - * Copyright (C) 2014 INRIA Sophia Antipolis-Méditerranée (France) - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ +/* This file is part of the Gudhi Library. The Gudhi library + * (Geometric Understanding in Higher Dimensions) is a generic C++ + * library for computational topology. + * + * Author(s): Clément Maria + * + * Copyright (C) 2014 INRIA Sophia Antipolis-Méditerranée (France) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#ifndef DISTANCE_FUNCTIONS_H_ +#define DISTANCE_FUNCTIONS_H_ /* Compute the Euclidean distance between two Points given * by a range of coordinates. The points are assumed to have * the same dimension. */ template< typename Point > -double euclidean_distance( Point &p1, Point &p2) -{ +double euclidean_distance(Point &p1, Point &p2) { double dist = 0.; - auto it1 = p1.begin(); auto it2 = p2.begin(); - for(; it1 != p1.end(); ++it1, ++it2) - { - double tmp = *it1 - *it2; - dist += tmp*tmp; - } - return sqrt(dist); + auto it1 = p1.begin(); + auto it2 = p2.begin(); + for (; it1 != p1.end(); ++it1, ++it2) { + double tmp = *it1 - *it2; + dist += tmp*tmp; + } + return sqrt(dist); } + +#endif // DISTANCE_FUNCTIONS_H_ diff --git a/src/common/include/gudhi/graph_simplicial_complex.h b/src/common/include/gudhi/graph_simplicial_complex.h index 1ad9dabd..042ef516 100644 --- a/src/common/include/gudhi/graph_simplicial_complex.h +++ b/src/common/include/gudhi/graph_simplicial_complex.h @@ -1,96 +1,99 @@ - /* This file is part of the Gudhi Library. The Gudhi library - * (Geometric Understanding in Higher Dimensions) is a generic C++ - * library for computational topology. - * - * Author(s): Clément Maria - * - * Copyright (C) 2014 INRIA Sophia Antipolis-Méditerranée (France) - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ +/* This file is part of the Gudhi Library. The Gudhi library + * (Geometric Understanding in Higher Dimensions) is a generic C++ + * library for computational topology. + * + * Author(s): Clément Maria + * + * Copyright (C) 2014 INRIA Sophia Antipolis-Méditerranée (France) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ -#ifndef GUDHI_GRAPH_SIMPLICIAL_COMPLEX_FILTRATION_TAG_H -#define GUDHI_GRAPH_SIMPLICIAL_COMPLEX_FILTRATION_TAG_H +#ifndef GRAPH_SIMPLICIAL_COMPLEX_H_ +#define GRAPH_SIMPLICIAL_COMPLEX_H_ #include <boost/graph/adjacency_list.hpp> +#include <utility> // for pair<> +#include <vector> +#include <map> + /* Edge tag for Boost PropertyGraph. */ struct edge_filtration_t { typedef boost::edge_property_tag kind; }; + /* Vertex tag for Boost PropertyGraph. */ struct vertex_filtration_t { typedef boost::vertex_property_tag kind; }; -typedef int Vertex_handle; -typedef double Filtration_value; +typedef int Vertex_handle; +typedef double Filtration_value; typedef boost::adjacency_list < boost::vecS, boost::vecS, boost::undirectedS - , boost::property < vertex_filtration_t, Filtration_value > - , boost::property < edge_filtration_t, Filtration_value > - > Graph_t; +, boost::property < vertex_filtration_t, Filtration_value > +, boost::property < edge_filtration_t, Filtration_value > +> Graph_t; typedef std::pair< Vertex_handle, Vertex_handle > Edge_t; /** \brief Output the proximity graph of the points. - * - * If points contains n elements, the proximity graph is the graph - * with n vertices, and an edge [u,v] iff the distance function between - * points u and v is smaller than threshold. - * - * The type PointCloud furnishes .begin() and .end() methods, that return - * iterators with value_type Point. - */ + * + * If points contains n elements, the proximity graph is the graph + * with n vertices, and an edge [u,v] iff the distance function between + * points u and v is smaller than threshold. + * + * The type PointCloud furnishes .begin() and .end() methods, that return + * iterators with value_type Point. + */ template< typename PointCloud - , typename Point > -Graph_t compute_proximity_graph( PointCloud &points - , Filtration_value threshold - , Filtration_value distance(Point p1, Point p2) ) -{ - std::vector< Edge_t > edges; - std::vector< Filtration_value > edges_fil; +, typename Point > +Graph_t compute_proximity_graph(PointCloud &points + , Filtration_value threshold + , Filtration_value distance(Point p1, Point p2)) { + std::vector< Edge_t > edges; + std::vector< Filtration_value > edges_fil; std::map< Vertex_handle, Filtration_value > vertices; Vertex_handle idx_u, idx_v; Filtration_value fil; idx_u = 0; - for(auto it_u = points.begin(); it_u != points.end(); ++it_u) - { - idx_v = idx_u+1; - for(auto it_v = it_u+1; it_v != points.end(); ++it_v, ++idx_v) - { - fil = distance(*it_u,*it_v); - if(fil <= threshold) { - edges.emplace_back(idx_u,idx_v); + for (auto it_u = points.begin(); it_u != points.end(); ++it_u) { + idx_v = idx_u + 1; + for (auto it_v = it_u + 1; it_v != points.end(); ++it_v, ++idx_v) { + fil = distance(*it_u, *it_v); + if (fil <= threshold) { + edges.emplace_back(idx_u, idx_v); edges_fil.push_back(fil); } } ++idx_u; } - Graph_t skel_graph( edges.begin() - , edges.end() - , edges_fil.begin() - , idx_u); //number of points labeled from 0 to idx_u-1 + Graph_t skel_graph(edges.begin() + , edges.end() + , edges_fil.begin() + , idx_u); // number of points labeled from 0 to idx_u-1 - auto vertex_prop = boost::get(vertex_filtration_t(),skel_graph); + auto vertex_prop = boost::get(vertex_filtration_t(), skel_graph); boost::graph_traits<Graph_t>::vertex_iterator vi, vi_end; - for ( std::tie(vi, vi_end) = boost::vertices(skel_graph); - vi != vi_end; ++vi ) - { boost::put(vertex_prop, *vi, 0.); } - + for (std::tie(vi, vi_end) = boost::vertices(skel_graph); + vi != vi_end; ++vi) { + boost::put(vertex_prop, *vi, 0.); + } + return skel_graph; } -#endif // GUDHI_GRAPH_SIMPLICIAL_COMPLEX_FILTRATION_TAG_H +#endif // GRAPH_SIMPLICIAL_COMPLEX_H_ diff --git a/src/common/include/gudhi/reader_utils.h b/src/common/include/gudhi/reader_utils.h index ab12c268..e05714c7 100644 --- a/src/common/include/gudhi/reader_utils.h +++ b/src/common/include/gudhi/reader_utils.h @@ -1,32 +1,38 @@ - /* This file is part of the Gudhi Library. The Gudhi library - * (Geometric Understanding in Higher Dimensions) is a generic C++ - * library for computational topology. - * - * Author(s): Clément Maria - * - * Copyright (C) 2014 INRIA Sophia Antipolis-Méditerranée (France) - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#ifndef GUDHI_READER_UTILS_H -#define GUDHI_READER_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. + * + * Author(s): Clément Maria + * + * Copyright (C) 2014 INRIA Sophia Antipolis-Méditerranée (France) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#ifndef READER_UTILS_H_ +#define READER_UTILS_H_ + +#include <gudhi/graph_simplicial_complex.h> + +#include <boost/graph/adjacency_list.hpp> #include <iostream> #include <fstream> -#include <boost/graph/adjacency_list.hpp> -#include "gudhi/graph_simplicial_complex.h" +#include <map> +#include <limits> // for numeric_limits<> +#include <string> +#include <vector> /** * \brief Read a set of points to turn it @@ -37,22 +43,21 @@ * X21 X22 ... X2d * etc */ -inline void -read_points ( std::string file_name - , std::vector< std::vector< double > > & points) -{ - std::ifstream in_file (file_name.c_str(),std::ios::in); - if(!in_file.is_open()) { +inline void read_points(std::string file_name, std::vector< std::vector< double > > & points) { + std::ifstream in_file(file_name.c_str(), std::ios::in); + if (!in_file.is_open()) { std::cerr << "Unable to open file " << file_name << std::endl; - return;} + return; + } std::string line; double x; - while( getline ( in_file , line ) ) - { + while (getline(in_file, line)) { std::vector< double > point; - std::istringstream iss( line ); - while(iss >> x) { point.push_back(x); } + std::istringstream iss(line); + while (iss >> x) { + point.push_back(x); + } points.push_back(point); } in_file.close(); @@ -70,53 +75,64 @@ read_points ( std::string file_name * Every simplex must appear exactly once. * Simplices of dimension more than 1 are ignored. */ -inline Graph_t -read_graph ( std::string file_name ) -{ - std::ifstream in_ (file_name.c_str(),std::ios::in); - if(!in_.is_open()) { std::cerr << "Unable to open file " << file_name << std::endl; } - - std::vector< Edge_t > edges; - std::vector< Filtration_value > edges_fil; +inline Graph_t read_graph(std::string file_name) { + std::ifstream in_(file_name.c_str(), std::ios::in); + if (!in_.is_open()) { + std::cerr << "Unable to open file " << file_name << std::endl; + } + + std::vector< Edge_t > edges; + std::vector< Filtration_value > edges_fil; std::map< Vertex_handle, Filtration_value > vertices; - - std::string line; - int dim; - Vertex_handle u,v,max_h = -1; + + std::string line; + int dim; + Vertex_handle u, v, max_h = -1; Filtration_value fil; - while( getline ( in_ , line ) ) - { - std::istringstream iss( line ); - while(iss >> dim) { - switch ( dim ) { - case 0 : { - iss >> u; iss >> fil; + while (getline(in_, line)) { + std::istringstream iss(line); + while (iss >> dim) { + switch (dim) { + case 0: + { + iss >> u; + iss >> fil; vertices[u] = fil; - if(max_h < u) { max_h = u; } + if (max_h < u) { + max_h = u; + } break; } - case 1 : { - iss >> u; iss >> v; iss >> fil; - edges.push_back(Edge_t(u,v)); + case 1: + { + iss >> u; + iss >> v; + iss >> fil; + edges.push_back(Edge_t(u, v)); edges_fil.push_back(fil); break; } - default: {break;} - } + default: + { + break; + } + } } } in_.close(); - if((size_t)(max_h+1) != vertices.size()) - { std::cerr << "Error: vertices must be labeled from 0 to n-1 \n"; } + if ((size_t) (max_h + 1) != vertices.size()) { + std::cerr << "Error: vertices must be labeled from 0 to n-1 \n"; + } - Graph_t skel_graph(edges.begin(),edges.end(),edges_fil.begin(),vertices.size()); - auto vertex_prop = boost::get(vertex_filtration_t(),skel_graph); + Graph_t skel_graph(edges.begin(), edges.end(), edges_fil.begin(), vertices.size()); + auto vertex_prop = boost::get(vertex_filtration_t(), skel_graph); boost::graph_traits<Graph_t>::vertex_iterator vi, vi_end; auto v_it = vertices.begin(); - for (std::tie(vi, vi_end) = boost::vertices(skel_graph); vi != vi_end; ++vi,++v_it) - { boost::put(vertex_prop, *vi, v_it->second); } + for (std::tie(vi, vi_end) = boost::vertices(skel_graph); vi != vi_end; ++vi, ++v_it) { + boost::put(vertex_prop, *vi, v_it->second); + } return skel_graph; } @@ -133,17 +149,15 @@ read_graph ( std::string file_name ) * Every simplex must appear exactly once. * Simplices of dimension more than 1 are ignored. */ -template< typename Vertex_handle - , typename Filtration_value > -bool read_simplex ( std::istream & in_ - , std::vector< Vertex_handle > & simplex - , Filtration_value & fil ) -{ - int dim=0; - if(!(in_ >> dim)) return false; +template< typename Vertex_handle, typename Filtration_value > +bool read_simplex(std::istream & in_, std::vector< Vertex_handle > & simplex, Filtration_value & fil) { + int dim = 0; + if (!(in_ >> dim)) return false; Vertex_handle v; - for(int i=0; i<dim+1; ++i) - { in_ >> v; simplex.push_back(v); } + for (int i = 0; i < dim + 1; ++i) { + in_ >> v; + simplex.push_back(v); + } in_ >> fil; in_.ignore((std::numeric_limits<std::streamsize>::max)(), '\n'); // ignore until the carriage return return true; @@ -162,20 +176,21 @@ bool read_simplex ( std::istream & in_ * Dimi ki1 ki2 ... kiDimi Fili means that the ith simplex in the * filtration has dimension Dimi, filtration value fil1 and simplices with * key ki1 ... kiDimi in its boundary.*/ -template< typename Simplex_key - , typename Filtration_value > -bool read_hasse_simplex ( std::istream & in_ - , std::vector< Simplex_key > & boundary - , Filtration_value & fil ) -{ +template< typename Simplex_key, typename Filtration_value > +bool read_hasse_simplex(std::istream & in_, std::vector< Simplex_key > & boundary, Filtration_value & fil) { int dim; - if(!(in_ >> dim)) return false; - if(dim == 0) {in_ >> fil; return true;} + if (!(in_ >> dim)) return false; + if (dim == 0) { + in_ >> fil; + return true; + } Simplex_key key; - for(int i=0; i<dim+1; ++i) - { in_ >> key; boundary.push_back(key); } + for (int i = 0; i < dim + 1; ++i) { + in_ >> key; + boundary.push_back(key); + } in_ >> fil; return true; } -#endif // GUDHI_READER_UTILS_H +#endif // READER_UTILS_H_ diff --git a/src/common/test/CMakeLists.txt b/src/common/test/CMakeLists.txt index 1b4dd6e0..a395338e 100644 --- a/src/common/test/CMakeLists.txt +++ b/src/common/test/CMakeLists.txt @@ -22,6 +22,11 @@ if(CGAL_FOUND) add_executable ( dtoffrw_UT dtoffrw_unit_test.cpp ) target_link_libraries(dtoffrw_UT ${Boost_SYSTEM_LIBRARY} ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY}) + # Do not forget to copy test files in current binary dir + file(COPY "dtoffrw_alphashapedoc_result.off" DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/) + # Do not forget to copy test files in current binary dir + file(COPY "${CMAKE_SOURCE_DIR}/data/points/alphacomplexdoc.off" DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/) + # Unitary tests add_test(dtoffrw_UT ${CMAKE_CURRENT_BINARY_DIR}/dtoffrw_UT # XML format for Jenkins xUnit plugin diff --git a/src/common/test/dtoffrw_unit_test.cpp b/src/common/test/dtoffrw_unit_test.cpp index ada218ac..cc6f283e 100644 --- a/src/common/test/dtoffrw_unit_test.cpp +++ b/src/common/test/dtoffrw_unit_test.cpp @@ -41,7 +41,7 @@ typedef CGAL::Delaunay_triangulation<K> T; BOOST_AUTO_TEST_CASE( Delaunay_triangulation_doc_test ) { // Read the OFF file (input file name given as parameter) and triangulates points - Gudhi::Delaunay_triangulation_off_reader<T> off_reader("../../../data/points/alphacomplexdoc.off"); + Gudhi::Delaunay_triangulation_off_reader<T> off_reader("alphacomplexdoc.off"); // Check the read operation was correct BOOST_CHECK(off_reader.is_valid()); @@ -73,7 +73,7 @@ BOOST_AUTO_TEST_CASE( Delaunay_triangulation_unexisting_file_read_test ) BOOST_AUTO_TEST_CASE( Delaunay_triangulation_unexisting_file_write_test ) { // Read the OFF file (input file name given as parameter) and triangulates points - Gudhi::Delaunay_triangulation_off_reader<T> off_reader("../../../data/points/alphacomplexdoc.off"); + Gudhi::Delaunay_triangulation_off_reader<T> off_reader("alphacomplexdoc.off"); // Retrieve the triangulation T* triangulation = off_reader.get_complex(); |