23 #ifndef WITNESS_COMPLEX_H_ 24 #define WITNESS_COMPLEX_H_ 26 #include <gudhi/Active_witness/Active_witness.h> 27 #include <gudhi/Witness_complex/all_faces_in.h> 36 namespace witness_complex {
49 template<
class Nearest_landmark_table_ >
52 typedef typename Nearest_landmark_table_::value_type Nearest_landmark_range;
53 typedef std::size_t Witness_id;
54 typedef std::size_t Landmark_id;
55 typedef std::pair<Landmark_id, double> Id_distance_pair;
56 typedef Active_witness<Id_distance_pair, Nearest_landmark_range> ActiveWitness;
57 typedef std::list< ActiveWitness > ActiveWitnessList;
58 typedef std::vector< Landmark_id > typeVectorVertex;
59 typedef std::vector<Nearest_landmark_range> Nearest_landmark_table_internal;
60 typedef Landmark_id Vertex_handle;
63 Nearest_landmark_table_internal nearest_landmark_table_;
85 : nearest_landmark_table_(std::begin(nearest_landmark_table), std::end(nearest_landmark_table)) {
97 template <
typename SimplicialComplexForWitness >
99 double max_alpha_square,
100 std::size_t limit_dimension = std::numeric_limits<std::size_t>::max())
const {
102 std::cerr <<
"Witness complex cannot create complex - complex is not empty.\n";
105 if (max_alpha_square < 0) {
106 std::cerr <<
"Witness complex cannot create complex - squared relaxation parameter must be non-negative.\n";
109 ActiveWitnessList active_witnesses;
111 for (
auto w : nearest_landmark_table_)
112 active_witnesses.push_back(ActiveWitness(w));
113 while (!active_witnesses.empty() && k <= limit_dimension) {
114 typename ActiveWitnessList::iterator aw_it = active_witnesses.begin();
115 std::vector<Landmark_id> simplex;
116 simplex.reserve(k+1);
117 while (aw_it != active_witnesses.end()) {
118 bool ok = add_all_faces_of_dimension(k,
120 std::numeric_limits<double>::infinity(),
125 assert(simplex.empty());
127 active_witnesses.erase(aw_it++);
145 template <
typename SimplicialComplexForWitness >
146 bool add_all_faces_of_dimension(
int dim,
148 double norelax_dist2,
149 typename ActiveWitness::iterator curr_l,
150 std::vector<Landmark_id>& simplex,
152 typename ActiveWitness::iterator end)
const {
155 bool will_be_active =
false;
156 typename ActiveWitness::iterator l_it = curr_l;
158 for (; l_it != end && l_it->second - alpha2 <= norelax_dist2; ++l_it) {
159 simplex.push_back(l_it->first);
161 typename ActiveWitness::iterator next_it = l_it;
162 will_be_active = add_all_faces_of_dimension(dim-1,
168 end) || will_be_active;
170 assert(!simplex.empty());
173 if (l_it->second <= norelax_dist2)
174 norelax_dist2 = l_it->second;
176 }
else if (dim == 0) {
177 for (; l_it != end && l_it->second - alpha2 <= norelax_dist2; ++l_it) {
178 simplex.push_back(l_it->first);
179 double filtration_value = 0;
181 if (l_it->second > norelax_dist2)
182 filtration_value = l_it->second - norelax_dist2;
183 if (all_faces_in(simplex, &filtration_value, sc)) {
184 will_be_active =
true;
187 assert(!simplex.empty());
190 if (l_it->second < norelax_dist2)
191 norelax_dist2 = l_it->second;
194 return will_be_active;
202 #endif // WITNESS_COMPLEX_H_ std::size_t num_vertices()
The concept SimplicialComplexForWitness describes the requirements for a type to implement a simplici...
Definition: SimplicialComplexForWitness.h:34
Simplex_handle null_simplex()
Returns a Simplex_hanlde that is different from all simplex handles of the simplices.
bool create_complex(SimplicialComplexForWitness &complex, double max_alpha_square, std::size_t limit_dimension=std::numeric_limits< std::size_t >::max()) const
Outputs the (weak) witness complex of relaxation 'max_alpha_square' in a simplicial complex data stru...
Definition: Witness_complex.h:98
Definition: SimplicialComplexForAlpha.h:26
Witness_complex(Nearest_landmark_table_ const &nearest_landmark_table)
Initializes member variables before constructing simplicial complex.
Definition: Witness_complex.h:84
Simplex_handle find(Input_vertex_range const &vertex_range)
Finds a simplex with vertices given by a range.
Constructs (weak) witness complex for a given table of nearest landmarks with respect to witnesses...
Definition: Witness_complex.h:50
Insertion_result_type insert_simplex(Input_vertex_range const &vertex_range, Filtration_value filtration)
Inserts a simplex with vertices from a given range 'vertex_range' in the simplicial complex...
void set_dimension(int dimension)
Sets the dimension of the simplicial complex to 'dimension'.