summaryrefslogtreecommitdiff
path: root/src/Cech_complex/include/gudhi/Cech_complex_blocker.h
blob: d718b56e138c6e6b1ee61268be4946cd649d61ab (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
/*    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) 2018 Inria
 *
 *    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 CECH_COMPLEX_BLOCKER_H_
#define CECH_COMPLEX_BLOCKER_H_

#include <gudhi/Cech_complex.h>        // Cech_blocker is using a pointer on Gudhi::cech_complex::Cech_complex
#include <gudhi/distance_functions.h>  // for Gudhi::Squared_radius

#include <iostream>
#include <vector>
#include <cmath>  // for std::sqrt

namespace Gudhi {

namespace cech_complex {

// Just declaring Cech_complex class because used and not yet defined.
template<typename SimplicialComplexForCechComplex, typename ForwardPointRange>
class Cech_complex;

/** \internal
 * \class Cech_blocker
 * \brief Cech complex blocker.
 *
 * \ingroup cech_complex
 *
 * \details
 * Cech blocker is an oracle constructed from a Cech_complex and a simplicial complex.
 *
 * \tparam SimplicialComplexForProximityGraph furnishes `Simplex_handle` and `Filtration_value` type definition,
 * `simplex_vertex_range(Simplex_handle sh)`and `assign_filtration(Simplex_handle sh, Filtration_value filt)` methods.
 *
 * \tparam ForwardPointRange is required by the pointer on Chech_complex for type definition.
 */
template <typename SimplicialComplexForCech, typename ForwardPointRange>
class Cech_blocker {
 private:
  using Point = std::vector<double>;
  using Point_cloud = std::vector<Point>;
  using Simplex_handle = typename SimplicialComplexForCech::Simplex_handle;
  using Filtration_value = typename SimplicialComplexForCech::Filtration_value;
  using Cech_complex = Gudhi::cech_complex::Cech_complex<SimplicialComplexForCech, ForwardPointRange>;

 public:
  /** \internal \brief Cech complex blocker operator() - the oracle - assigns the filtration value from the simplex
   * radius and returns if the simplex expansion must be blocked.
   *  \param[in] sh The Simplex_handle.
   *  \return true if the simplex radius is greater than the Cech_complex max_radius*/
  bool operator()(Simplex_handle sh) {
    Point_cloud points;
    for (auto vertex : simplicial_complex_.simplex_vertex_range(sh)) {
      points.push_back(Point(cc_ptr_->point_iterator(vertex)->begin(),
                             cc_ptr_->point_iterator(vertex)->end()));
#ifdef DEBUG_TRACES
      std::cout << "#(" << vertex << ")#";
#endif  // DEBUG_TRACES
    }
    Filtration_value squared_radius = Gudhi::Radius_distance()(points);
#ifdef DEBUG_TRACES
    std::cout << "squared_radius = " << squared_radius << " - " << (squared_radius > cc_ptr_->max_radius()) << std::endl;
#endif  // DEBUG_TRACES
    simplicial_complex_.assign_filtration(sh, squared_radius);
    return (squared_radius > cc_ptr_->max_radius());
  }

  /** \internal \brief Cech complex blocker constructor. */
  Cech_blocker(SimplicialComplexForCech& simplicial_complex, Cech_complex* cc_ptr)
    : simplicial_complex_(simplicial_complex),
      cc_ptr_(cc_ptr) {
  }
 private:
  SimplicialComplexForCech simplicial_complex_;
  Cech_complex* cc_ptr_;
};

}  // namespace cech_complex

}  // namespace Gudhi

#endif  // CECH_COMPLEX_BLOCKER_H_