mitochondria.h
1 /* Copyright (c) 2013-2023, EPFL/Blue Brain Project
2  *
3  * SPDX-License-Identifier: Apache-2.0
4  */
5 #pragma once
6 
7 #include <map>
8 #include <memory>
9 
10 #include <morphio/mito_section.h>
11 #include <morphio/properties.h>
12 #include <morphio/types.h>
13 
14 #include <morphio/mut/mito_section.h>
15 
16 namespace morphio {
17 namespace mut {
18 
19 using mito_upstream_iterator = morphio::upstream_iterator_t<std::shared_ptr<MitoSection>>;
20 using mito_breadth_iterator =
22 using mito_depth_iterator = morphio::depth_iterator_t<std::shared_ptr<MitoSection>, Mitochondria>;
23 
26 {
27  using MitoSectionP = std::shared_ptr<MitoSection>;
28 
29  public:
30  Mitochondria() = default;
31 
33  const std::vector<MitoSectionP>& children(const MitoSectionP&) const;
34 
40  const MitoSectionP& section(uint32_t id) const;
41 
43  const std::map<uint32_t, MitoSectionP>& sections() const noexcept;
44 
51  mito_depth_iterator depth_begin(const MitoSectionP& section) const;
52  mito_depth_iterator depth_end() const;
53 
61  mito_breadth_iterator breadth_begin(const MitoSectionP& section) const;
62  mito_breadth_iterator breadth_end() const;
63 
71  mito_upstream_iterator upstream_begin(const MitoSectionP& section) const;
72  mito_upstream_iterator upstream_end() const;
73 
77  const MitoSectionP& parent(const MitoSectionP& parent) const;
78 
82  bool isRoot(const MitoSectionP& section) const;
83 
88  const std::vector<MitoSectionP>& rootSections() const noexcept;
89 
93  MitoSectionP appendRootSection(const Property::MitochondriaPointLevel& pointProperties);
94 
101  MitoSectionP appendRootSection(const morphio::MitoSection&, bool recursive = false);
102  MitoSectionP appendRootSection(const MitoSectionP&, bool recursive = false);
103 
104  const MitoSectionP& mitoSection(uint32_t id) const;
105 
109  void _buildMitochondria(Property::Properties& properties) const;
110 
111  private:
112  friend class MitoSection;
113 
114  uint32_t _register(const MitoSectionP& section);
115 
116  uint32_t _counter = 0;
117  std::map<uint32_t, std::vector<MitoSectionP>> children_;
118  std::map<uint32_t, uint32_t> parent_;
119  std::vector<MitoSectionP> root_sections_;
120  std::map<uint32_t, MitoSectionP> sections_;
121 };
122 
123 inline const std::map<uint32_t, Mitochondria::MitoSectionP>& Mitochondria::sections() const
124  noexcept {
125  return sections_;
126 }
127 
128 inline const std::vector<Mitochondria::MitoSectionP>& Mitochondria::rootSections() const noexcept {
129  return root_sections_;
130 }
131 
132 } // namespace mut
133 } // namespace morphio
morphio::mut::Mitochondria::rootSections
const std::vector< MitoSectionP > & rootSections() const noexcept
Definition: mitochondria.h:128
morphio::Property::Properties
Definition: properties.h:210
morphio::depth_iterator_t
Definition: section_iterators.hpp:82
morphio::mut::Mitochondria::upstream_begin
mito_upstream_iterator upstream_begin() const
morphio::MitoSection
Definition: mito_section.h:21
morphio::Property::MitochondriaPointLevel
Definition: properties.h:93
morphio::mut::Mitochondria::depth_begin
mito_depth_iterator depth_begin() const
morphio::mut::Mitochondria::section
const MitoSectionP & section(uint32_t id) const
morphio::mut::Mitochondria::isRoot
bool isRoot(const MitoSectionP &section) const
morphio::mut::Mitochondria::parent
const MitoSectionP & parent(const MitoSectionP &parent) const
morphio::mut::Mitochondria::_buildMitochondria
void _buildMitochondria(Property::Properties &properties) const
morphio::upstream_iterator_t
Definition: section_iterators.hpp:111
morphio::mut::Mitochondria::sections
const std::map< uint32_t, MitoSectionP > & sections() const noexcept
Returns the dictionary id -> Section for this tree.
Definition: mitochondria.h:123
morphio::mut::Mitochondria::breadth_begin
mito_breadth_iterator breadth_begin() const
morphio::mut::Mitochondria
Definition: mitochondria.h:25
morphio::mut::Mitochondria::children
const std::vector< MitoSectionP > & children(const MitoSectionP &) const
Get the Section children.
morphio::breadth_iterator_t
Definition: section_iterators.hpp:53
morphio::mut::MitoSection
Definition: mito_section.h:17
morphio::mut::Mitochondria::appendRootSection
MitoSectionP appendRootSection(const Property::MitochondriaPointLevel &pointProperties)