Edge_contractor.h
1/* This file is part of the Gudhi Library - https://gudhi.inria.fr/ - which is released under MIT.
2 * See file LICENSE or go to https://gudhi.inria.fr/licensing/ for full license details.
3 * Author(s): David Salinas
4 *
5 * Copyright (C) 2014 Inria
6 *
7 * Modification(s):
8 * - YYYY/MM Author: Description of the modification
9 */
10
11#ifndef UTILS_EDGE_CONTRACTOR_H_
12#define UTILS_EDGE_CONTRACTOR_H_
13
14
15#include <gudhi/Skeleton_blocker_contractor.h>
16#include <gudhi/Contraction/Edge_profile.h>
17#include <gudhi/Contraction/policies/Cost_policy.h>
18
19#include <vector>
20
24template<typename SkBlComplex> class Edge_contractor {
25 private:
26 SkBlComplex& complex_;
27 unsigned num_contractions_;
28
32 template< typename EdgeProfile> class Length_cost : public contraction::Cost_policy<EdgeProfile> {
33 public:
34 typedef typename contraction::Cost_policy<EdgeProfile>::Cost_type Cost_type;
35 typedef typename EdgeProfile::Point Point;
36
37 Cost_type operator()(const EdgeProfile& profile, const boost::optional<Point>& placement) const override {
38 Cost_type res;
39 if (!placement)
40 return res;
41 return Geometry_trait::Squared_distance_d()(profile.p0(), profile.p1()); // not working??
42 }
43 };
44
48 template< typename EdgeProfile> class Middle_placement : public contraction::Placement_policy<EdgeProfile> {
49 public:
50 typedef typename contraction::Placement_policy<EdgeProfile>::Placement_type Placement_type;
51 typedef typename EdgeProfile::Point Point;
52
53 Placement_type operator()(const EdgeProfile& profile) const override {
54 std::vector<double> mid_coords(profile.p0().dimension(), 0);
55 for (int i = 0; i < profile.p0().dimension(); ++i) {
56 mid_coords[i] = (profile.p0()[i] + profile.p1()[i]) / 2.;
57 }
58 return Point(profile.p0().dimension(), mid_coords.begin(), mid_coords.end());
59 }
60 };
61
62 public:
63 typedef typename SkBlComplex::Vertex_handle Vertex_handle;
64 typedef typename SkBlComplex::Edge_handle Edge_handle;
65
70 Edge_contractor(SkBlComplex& complex, unsigned num_contractions) :
71 complex_(complex), num_contractions_(num_contractions) {
72 typedef typename contraction::Edge_profile<Complex> Profile;
73 num_contractions = (std::min)(static_cast<int>(num_contractions), static_cast<int>(complex_.num_vertices() - 1));
74 typedef typename contraction::Skeleton_blocker_contractor<Complex> Contractor;
75 Contractor contractor(complex_,
76 new Length_cost<contraction::Edge_profile < Complex >> (),
77 new Middle_placement<contraction::Edge_profile < Complex >> (),
78 contraction::make_link_valid_contraction<Profile>(),
79 contraction::make_remove_popable_blockers_visitor<Profile>());
80 contractor.contract_edges(num_contractions);
81 }
82};
83
84#endif // UTILS_EDGE_CONTRACTOR_H_
Definition: Edge_contractor.h:24
Edge_contractor(SkBlComplex &complex, unsigned num_contractions)
Modify complex to be the expansion of the k-nearest neighbor symetric graph.
Definition: Edge_contractor.h:70
GUDHIdev  Version 3.5.0  - C++ library for Topological Data Analysis (TDA) and Higher Dimensional Geometry Understanding.  - Copyright : MIT Generated on Tue Aug 16 2022 14:01:50 for GUDHIdev by Doxygen 1.9.4