Gudhi  1.1.0
 All Classes Functions Typedefs Friends Groups Pages
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 Sophia Antipolis-Méditerranée (France)
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 SRC_SIMPLEX_TREE_INCLUDE_GUDHI_SIMPLEX_TREE_SIMPLEX_TREE_SIBLINGS_H_
24 #define SRC_SIMPLEX_TREE_INCLUDE_GUDHI_SIMPLEX_TREE_SIMPLEX_TREE_SIBLINGS_H_
25 
26 #include "boost/container/flat_map.hpp"
27 #include "Simplex_tree_node_explicit_storage.h"
28 
29 #include <utility>
30 #include <vector>
31 
32 namespace Gudhi {
33 
34 /* \addtogroup simplex_tree
35  * Represents a set of node of a Simplex_tree that share the same parent.
36  * @{
37  */
38 
39 /* \brief Data structure to store a set of nodes in a SimplexTree sharing
40  * the same parent node.*/
41 template<class SimplexTree, class MapContainer>
42 class Simplex_tree_siblings {
43 // private:
44 // friend SimplexTree;
45  public:
46  template<class T> friend class Simplex_tree_simplex_vertex_iterator;
47  template<class T> friend class Simplex_tree_boundary_simplex_iterator;
48  template<class T> friend class Simplex_tree_complex_simplex_iterator;
49  template<class T> friend class Simplex_tree_skeleton_simplex_iterator;
50 
51  typedef typename SimplexTree::Vertex_handle Vertex_handle;
52  typedef typename SimplexTree::Filtration_value Filtration_value;
53  typedef typename SimplexTree::Node Node;
54  typedef MapContainer Dictionary;
55  typedef typename MapContainer::iterator Dictionary_it;
56 
57  /* Default constructor.*/
58  Simplex_tree_siblings()
59  : oncles_(NULL),
60  parent_(-1),
61  members_() {
62  }
63 
64  /* Constructor with values.*/
65  Simplex_tree_siblings(Simplex_tree_siblings * oncles, Vertex_handle parent)
66  : oncles_(oncles),
67  parent_(parent),
68  members_() {
69  }
70 
71  /* \brief Constructor with initialized set of members.
72  *
73  * 'members' must be sorted and unique.*/
74  Simplex_tree_siblings(Simplex_tree_siblings * oncles, Vertex_handle parent,
75  const std::vector<std::pair<Vertex_handle, Node> > & members)
76  : oncles_(oncles),
77  parent_(parent),
78  members_(boost::container::ordered_unique_range, members.begin(),
79  members.end()) {
80  for (auto map_it = members_.begin(); map_it != members_.end(); map_it++) {
81  map_it->second.assign_children(this);
82  }
83  }
84 
85  /*
86  * \brief Inserts a Node in the set of siblings nodes.
87  *
88  * If already present, assigns the minimal filtration value
89  * between input filtration_value and the value already
90  * present in the node.
91  */
92  void insert(Vertex_handle v, Filtration_value filtration_value) {
93  typename Dictionary::iterator sh = members_.find(v);
94  if (sh != members_.end() && sh->second.filtration() > filtration_value) {
95  sh->second.assign_filtration(filtration_value);
96  return;
97  }
98  if (sh == members_.end()) {
99  members_.insert(
100  std::pair<Vertex_handle, Node>(v, Node(this, filtration_value)));
101  return;
102  }
103  }
104 
105  typename Dictionary::iterator find(Vertex_handle v) {
106  return members_.find(v);
107  }
108 
109  Simplex_tree_siblings * oncles() {
110  return oncles_;
111  }
112 
113  Vertex_handle parent() {
114  return parent_;
115  }
116 
117  Dictionary & members() {
118  return members_;
119  }
120 
121  size_t size() {
122  return members_.size();
123  }
124 
125  Simplex_tree_siblings * oncles_;
126  Vertex_handle parent_;
127  Dictionary members_;
128 };
129 
130 /* @} */ // end addtogroup simplex_tree
131 } // namespace Gudhi
132 
133 #endif // SRC_SIMPLEX_TREE_INCLUDE_GUDHI_SIMPLEX_TREE_SIMPLEX_TREE_SIBLINGS_H_