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 
19 class Section: public std::enable_shared_from_this<Section>
20 {
21  public:
22  ~Section() = default;
23 
27  inline uint32_t id() const noexcept;
28 
32  inline SectionType& type() noexcept;
33  inline const SectionType& type() const noexcept;
39  inline std::vector<Point>& points() noexcept;
40  inline const std::vector<Point>& points() const noexcept;
46  inline std::vector<morphio::floatType>& diameters() noexcept;
47  inline const std::vector<morphio::floatType>& diameters() const noexcept;
53  inline std::vector<morphio::floatType>& perimeters() noexcept;
54  inline const std::vector<morphio::floatType>& perimeters() const noexcept;
60  inline Property::PointLevel& properties() noexcept;
61  inline const Property::PointLevel& properties() const noexcept;
63  //
65  // Methods that were previously in mut::Morphology
66  //
68 
74  const std::shared_ptr<Section>& parent() const;
75 
79  bool isRoot() const;
80 
85  bool isHeterogeneous(bool downstream = true) const;
86 
90  bool hasSameShape(const Section& other) const noexcept;
91 
95  const std::vector<std::shared_ptr<Section>>& children() const;
96 
97  depth_iterator depth_begin() const;
98  depth_iterator depth_end() const;
99 
100  breadth_iterator breadth_begin() const;
101  breadth_iterator breadth_end() const;
102 
103  upstream_iterator upstream_begin() const;
104  upstream_iterator upstream_end() const;
105 
106  std::shared_ptr<Section> appendSection(const morphio::Section&, bool recursive = false);
107 
108  std::shared_ptr<Section> appendSection(std::shared_ptr<Section> original_section,
109  bool recursive = false);
110 
111  std::shared_ptr<Section> appendSection(
112  const Property::PointLevel&, SectionType sectionType = SectionType::SECTION_UNDEFINED);
113 
114  private:
115  friend class Morphology;
116 
117  Section(Morphology*, unsigned int id, SectionType type, const Property::PointLevel&);
118  Section(Morphology*, unsigned int id, const morphio::Section& section);
119  Section(Morphology*, unsigned int id, const Section&);
120 
121 
125  void throwIfNoOwningMorphology() const;
126 
130  Morphology* getOwningMorphologyOrThrow() const;
131 
132  Morphology* morphology_;
133  Property::PointLevel point_properties_;
134  uint32_t id_;
135  SectionType section_type_;
136 };
137 
138 std::ostream& operator<<(std::ostream&, const std::shared_ptr<Section>&);
139 
140 inline uint32_t Section::id() const noexcept {
141  return id_;
142 }
143 
144 inline SectionType& Section::type() noexcept {
145  return section_type_;
146 }
147 
148 inline const SectionType& Section::type() const noexcept {
149  return section_type_;
150 }
151 
152 inline std::vector<Point>& Section::points() noexcept {
153  return point_properties_._points;
154 }
155 
156 inline const std::vector<Point>& Section::points() const noexcept {
157  return point_properties_._points;
158 }
159 
160 inline std::vector<morphio::floatType>& Section::diameters() noexcept {
161  return point_properties_._diameters;
162 }
163 
164 inline const std::vector<morphio::floatType>& Section::diameters() const noexcept {
165  return point_properties_._diameters;
166 }
167 
168 inline std::vector<morphio::floatType>& Section::perimeters() noexcept {
169  return point_properties_._perimeters;
170 }
171 
172 inline const std::vector<morphio::floatType>& Section::perimeters() const noexcept {
173  return point_properties_._perimeters;
174 }
175 
177  return point_properties_;
178 }
179 
180 inline const Property::PointLevel& Section::properties() const noexcept {
181  return point_properties_;
182 }
183 
184 } // namespace mut
185 } // namespace morphio
186 
187 std::ostream& operator<<(std::ostream&, const morphio::mut::Section&);
morphio::mut::Section::parent
const std::shared_ptr< Section > & parent() const
morphio::depth_iterator_t
Definition: section_iterators.hpp:81
morphio::enums::SectionType
SectionType
Definition: enums.h:62
morphio::mut::Section::isRoot
bool isRoot() const
morphio::Section
Definition: section.h:36
morphio::mut::Section::id
uint32_t id() const noexcept
Definition: section.h:140
morphio::mut::Section::points
std::vector< Point > & points() noexcept
Definition: section.h:152
morphio::mut::Section::isHeterogeneous
bool isHeterogeneous(bool downstream=true) const
morphio::upstream_iterator_t
Definition: section_iterators.hpp:109
morphio::mut::Section::properties
Property::PointLevel & properties() noexcept
Definition: section.h:176
morphio::mut::Section::diameters
std::vector< morphio::floatType > & diameters() noexcept
Definition: section.h:160
morphio::mut::Section::children
const std::vector< std::shared_ptr< Section > > & children() const
morphio::breadth_iterator_t
Definition: section_iterators.hpp:53
morphio::mut::Morphology
Definition: morphology.h:24
morphio::mut::Section::type
SectionType & type() noexcept
Definition: section.h:144
morphio::mut::Section::hasSameShape
bool hasSameShape(const Section &other) const noexcept
morphio::mut::Section
Definition: section.h:19
morphio::Property::PointLevel
Definition: properties.h:62
morphio::mut::Section::perimeters
std::vector< morphio::floatType > & perimeters() noexcept
Definition: section.h:168