Loading...
Searching...
No Matches
Rips_contraction.cpp
/* This file is part of the Gudhi Library - https://gudhi.inria.fr/ - which is released under MIT.
* See file LICENSE or go to https://gudhi.inria.fr/licensing/ for full license details.
* Author(s): David Salinas
*
* Copyright (C) 2014 Inria
*
* Modification(s):
* - YYYY/MM Author: Description of the modification
*/
#include <gudhi/Edge_contraction.h>
#include <gudhi/Skeleton_blocker.h>
#include <gudhi/Off_reader.h>
#include <gudhi/Point.h>
#include <gudhi/Clock.h>
#include <iostream>
struct Geometry_trait {
typedef Point_d Point;
};
using Profile = Gudhi::contraction::Edge_profile<Complex>;
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_without_blockers(*p, *q);
}
}
int main(int argc, char *argv[]) {
if (argc != 3) {
std::cerr << "Usage " << argv[0] << " ../../data/points/tore3D_1307.off 0.3 to load the file " <<
"../../data/points/tore3D_1307.off and contract the Rips complex built with parameter 0.3.\n";
return -1;
}
Complex complex;
// load only the points
if (!off_reader.is_valid()) {
std::cerr << "Unable to read file:" << argv[1] << std::endl;
return EXIT_FAILURE;
}
std::clog << "Build the Rips complex with " << complex.num_vertices() << " vertices" << std::endl;
build_rips(complex, atof(argv[2]));
Gudhi::Clock contraction_chrono("Time to simplify and enumerate simplices");
std::clog << "Initial complex has " <<
complex.num_vertices() << " vertices and " <<
complex.num_edges() << " edges" << std::endl;
Complex_contractor contractor(complex,
Gudhi::contraction::make_first_vertex_placement<Profile>(),
Gudhi::contraction::make_link_valid_contraction<Profile>(),
Gudhi::contraction::make_remove_popable_blockers_visitor<Profile>());
contractor.contract_edges();
std::clog << "Counting final number of simplices \n";
unsigned num_simplices = std::distance(complex.complex_simplex_range().begin(), complex.complex_simplex_range().end());
std::clog << "Final complex has " <<
complex.num_vertices() << " vertices, " <<
complex.num_edges() << " edges, " <<
complex.num_blockers() << " blockers and " <<
num_simplices << " simplices" << std::endl;
std::clog << contraction_chrono;
return EXIT_SUCCESS;
}
return a cost corresponding to the squared length of the edge
Definition: Edge_length_cost.h:24
Class that allows to contract iteratively edges of a simplicial complex.
Definition: Skeleton_blocker_contractor.h:98
Complex_simplex_range complex_simplex_range() const
Returns a Complex_simplex_range over all the simplices of the complex.
Definition: Skeleton_blocker_complex.h:1429
Class that represents a geometric complex that can be simplified. The class allows access to points o...
Definition: Skeleton_blocker_geometric_complex.h:29
Class that allows to load a Skeleton_blocker_complex from an off file.
Definition: Skeleton_blocker_off_io.h:108