Simplex_tree_siblings.h
1 /* This file is part of the Gudhi Library. The Gudhi library
2  * (Geometric Understanding in Higher Dimensions) is a generic C++
3  * library for computational topology.
4  *
5  * Author(s): ClĂ©ment Maria
6  *
7  * Copyright (C) 2014 Inria
8  *
9  * This program is free software: you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation, either version 3 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program. If not, see <http://www.gnu.org/licenses/>.
21  */
22 
23 #ifndef SIMPLEX_TREE_SIMPLEX_TREE_SIBLINGS_H_
24 #define SIMPLEX_TREE_SIMPLEX_TREE_SIBLINGS_H_
25 
26 #include <gudhi/Simplex_tree/Simplex_tree_node_explicit_storage.h>
27 
28 #include <boost/container/flat_map.hpp>
29 
30 #include <utility>
31 #include <vector>
32 
33 namespace Gudhi {
34 
35 /* \addtogroup simplex_tree
36  * Represents a set of node of a Simplex_tree that share the same parent.
37  * @{
38  */
39 
40 /* \brief Data structure to store a set of nodes in a SimplexTree sharing
41  * the same parent node.*/
42 template<class SimplexTree, class MapContainer>
43 class Simplex_tree_siblings {
44 // private:
45 // friend SimplexTree;
46  public:
47  template<class T> friend class Simplex_tree_simplex_vertex_iterator;
48  template<class T> friend class Simplex_tree_boundary_simplex_iterator;
49  template<class T> friend class Simplex_tree_complex_simplex_iterator;
50  template<class T> friend class Simplex_tree_skeleton_simplex_iterator;
51 
52  typedef typename SimplexTree::Vertex_handle Vertex_handle;
54  typedef typename SimplexTree::Node Node;
55  typedef MapContainer Dictionary;
56  typedef typename MapContainer::iterator Dictionary_it;
57 
58  /* Default constructor.*/
59  Simplex_tree_siblings()
60  : oncles_(nullptr),
61  parent_(-1),
62  members_() {
63  }
64 
65  /* Constructor with values.*/
66  Simplex_tree_siblings(Simplex_tree_siblings * oncles, Vertex_handle parent)
67  : oncles_(oncles),
68  parent_(parent),
69  members_() {
70  }
71 
72  /* \brief Constructor with initialized set of members.
73  *
74  * 'members' must be sorted and unique.*/
75  template<typename RandomAccessVertexRange>
76  Simplex_tree_siblings(Simplex_tree_siblings * oncles, Vertex_handle parent, const RandomAccessVertexRange & members)
77  : oncles_(oncles),
78  parent_(parent),
79  members_(boost::container::ordered_unique_range, members.begin(),
80  members.end()) {
81  for (auto& map_el : members_) {
82  map_el.second.assign_children(this);
83  }
84  }
85 
86  /*
87  * \brief Inserts a Node in the set of siblings nodes.
88  *
89  * If already present, assigns the minimal filtration value
90  * between input filtration_value and the value already
91  * present in the node.
92  */
93  void insert(Vertex_handle v, Filtration_value filtration_value) {
94  auto ins = members_.emplace(v, Node(this, filtration_value));
95  if (!ins.second && filtration(ins.first) > filtration_value)
96  ins.first->second.assign_filtration(filtration_value);
97  }
98 
99  Dictionary_it find(Vertex_handle v) {
100  return members_.find(v);
101  }
102 
103  Simplex_tree_siblings * oncles() {
104  return oncles_;
105  }
106 
107  Vertex_handle parent() const {
108  return parent_;
109  }
110 
111  Dictionary & members() {
112  return members_;
113  }
114 
115  size_t size() const {
116  return members_.size();
117  }
118 
119  void erase(const Dictionary_it iterator) {
120  members_.erase(iterator);
121  }
122 
123  Simplex_tree_siblings * oncles_;
124  Vertex_handle parent_;
125  Dictionary members_;
126 };
127 
128 /* @} */ // end addtogroup simplex_tree
129 } // namespace Gudhi
130 
131 #endif // SIMPLEX_TREE_SIMPLEX_TREE_SIBLINGS_H_
Definition: SimplicialComplexForAlpha.h:26
Value type for a filtration function on a cell complex.
Definition: FiltrationValue.h:32
Handle type for the vertices of a cell complex.
Definition: VertexHandle.h:27
GUDHI  Version 2.2.0  - C++ library for Topological Data Analysis (TDA) and Higher Dimensional Geometry Understanding.  - Copyright : GPL v3 Generated on Fri Jun 22 2018 08:12:19 for GUDHI by Doxygen 1.8.13