section.h
1 #pragma once
2 
3 #include <functional>
4 
5 #include <morphio/properties.h>
6 #include <morphio/section.h>
7 #include <morphio/types.h>
8 
9 #include <morphio/section_iterators.hpp>
10 
11 namespace morphio {
12 namespace mut {
13 
15 using breadth_iterator = morphio::breadth_iterator_t<std::shared_ptr<Section>, Morphology>;
16 using depth_iterator = morphio::depth_iterator_t<std::shared_ptr<Section>, Morphology>;
17 
18 class Section: public std::enable_shared_from_this<Section>
19 {
20  public:
21  ~Section() = default;
22 
26  inline uint32_t id() const noexcept;
27 
31  inline SectionType& type() noexcept;
32  inline const SectionType& type() const noexcept;
38  inline std::vector<Point>& points() noexcept;
39  inline const std::vector<Point>& points() const noexcept;
45  inline std::vector<morphio::floatType>& diameters() noexcept;
46  inline const std::vector<morphio::floatType>& diameters() const noexcept;
52  inline std::vector<morphio::floatType>& perimeters() noexcept;
53  inline const std::vector<morphio::floatType>& perimeters() const noexcept;
59  inline Property::PointLevel& properties() noexcept;
60  inline const Property::PointLevel& properties() const noexcept;
63  //
64  // Methods that were previously in mut::Morphology
65  //
67 
73  const std::shared_ptr<Section>& parent() const;
74 
78  bool isRoot() const;
79 
83  const std::vector<std::shared_ptr<Section>>& children() const;
84 
85  depth_iterator depth_begin() const;
86  depth_iterator depth_end() const;
87 
88  breadth_iterator breadth_begin() const;
89  breadth_iterator breadth_end() const;
90 
91  upstream_iterator upstream_begin() const;
92  upstream_iterator upstream_end() const;
93 
94  std::shared_ptr<Section> appendSection(const morphio::Section&, bool recursive = false);
95 
96  std::shared_ptr<Section> appendSection(std::shared_ptr<Section> original_section,
97  bool recursive = false);
98 
99  std::shared_ptr<Section> appendSection(
100  const Property::PointLevel&, SectionType sectionType = SectionType::SECTION_UNDEFINED);
101 
102  private:
103  friend class Morphology;
104 
105  Section(Morphology*, unsigned int id, SectionType type, const Property::PointLevel&);
106  Section(Morphology*, unsigned int id, const morphio::Section& section);
107  Section(Morphology*, unsigned int id, const Section&);
108 
109 
113  void throwIfNoOwningMorphology() const;
114 
118  Morphology* getOwningMorphologyOrThrow() const;
119 
120  Morphology* _morphology;
121  Property::PointLevel _pointProperties;
122  uint32_t _id;
123  SectionType _sectionType;
124 };
125 
126 std::ostream& operator<<(std::ostream&, const std::shared_ptr<Section>&);
127 
128 inline uint32_t Section::id() const noexcept {
129  return _id;
130 }
131 
132 inline SectionType& Section::type() noexcept {
133  return _sectionType;
134 }
135 
136 inline const SectionType& Section::type() const noexcept {
137  return _sectionType;
138 }
139 
140 inline std::vector<Point>& Section::points() noexcept {
141  return _pointProperties._points;
142 }
143 
144 inline const std::vector<Point>& Section::points() const noexcept {
145  return _pointProperties._points;
146 }
147 
148 inline std::vector<morphio::floatType>& Section::diameters() noexcept {
149  return _pointProperties._diameters;
150 }
151 
152 inline const std::vector<morphio::floatType>& Section::diameters() const noexcept {
153  return _pointProperties._diameters;
154 }
155 
156 inline std::vector<morphio::floatType>& Section::perimeters() noexcept {
157  return _pointProperties._perimeters;
158 }
159 
160 inline const std::vector<morphio::floatType>& Section::perimeters() const noexcept {
161  return _pointProperties._perimeters;
162 }
163 
165  return _pointProperties;
166 }
167 
168 inline const Property::PointLevel& Section::properties() const noexcept {
169  return _pointProperties;
170 }
171 
172 } // namespace mut
173 } // namespace morphio
174 
175 std::ostream& operator<<(std::ostream&, const morphio::mut::Section&);
Definition: section.h:37
Definition: section_iterators.hpp:54
Definition: section_iterators.hpp:82
Definition: morphology.h:27
Definition: section.h:19
const std::vector< std::shared_ptr< Section > > & children() const
std::vector< morphio::floatType > & perimeters() noexcept
Definition: section.h:156
SectionType & type() noexcept
Definition: section.h:132
Property::PointLevel & properties() noexcept
Definition: section.h:164
uint32_t id() const noexcept
Definition: section.h:128
std::vector< Point > & points() noexcept
Definition: section.h:140
std::vector< morphio::floatType > & diameters() noexcept
Definition: section.h:148
const std::shared_ptr< Section > & parent() const
Definition: section_iterators.hpp:110
Definition: endoplasmic_reticulum.h:5
upstream_iterator_t< Section > upstream_iterator
Definition: section.h:32
Definition: properties.h:66