section.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 <morphio/properties.h>
8 #include <morphio/section.h>
9 #include <morphio/types.h>
10 
11 #include <morphio/section_iterators.hpp>
12 
13 namespace morphio {
14 namespace mut {
15 
17 using breadth_iterator = morphio::breadth_iterator_t<std::shared_ptr<Section>, Morphology>;
18 using depth_iterator = morphio::depth_iterator_t<std::shared_ptr<Section>, Morphology>;
19 
21 class Section: public std::enable_shared_from_this<Section>
22 {
23  public:
24  ~Section() = default;
25 
29  inline uint32_t id() const noexcept;
30 
34  inline SectionType& type() noexcept;
35  inline const SectionType& type() const noexcept;
41  inline std::vector<Point>& points() noexcept;
42  inline const std::vector<Point>& points() const noexcept;
48  inline std::vector<morphio::floatType>& diameters() noexcept;
49  inline const std::vector<morphio::floatType>& diameters() const noexcept;
55  inline std::vector<morphio::floatType>& perimeters() noexcept;
56  inline const std::vector<morphio::floatType>& perimeters() const noexcept;
62  inline Property::PointLevel& properties() noexcept;
63  inline const Property::PointLevel& properties() const noexcept;
65  //
67  // Methods that were previously in mut::Morphology
68  //
70 
76  const std::shared_ptr<Section>& parent() const;
77 
81  bool isRoot() const;
82 
87  bool isHeterogeneous(bool downstream = true) const;
88 
92  bool hasSameShape(const Section& other) const noexcept;
93 
97  const std::vector<std::shared_ptr<Section>>& children() const;
98 
99  depth_iterator depth_begin() const;
100  depth_iterator depth_end() const;
101 
102  breadth_iterator breadth_begin() const;
103  breadth_iterator breadth_end() const;
104 
105  upstream_iterator upstream_begin() const;
106  upstream_iterator upstream_end() const;
107 
108  std::shared_ptr<Section> appendSection(const morphio::Section&, bool recursive = false);
109 
110  std::shared_ptr<Section> appendSection(std::shared_ptr<Section> original_section,
111  bool recursive = false);
112 
113  std::shared_ptr<Section> appendSection(
114  const Property::PointLevel&, SectionType sectionType = SectionType::SECTION_UNDEFINED);
115 
116  private:
117  friend class Morphology;
118 
119  Section(Morphology*, unsigned int id, SectionType type, const Property::PointLevel&);
120  Section(Morphology*, unsigned int id, const morphio::Section& section);
121  Section(Morphology*, unsigned int id, const Section&);
122 
123 
127  void throwIfNoOwningMorphology() const;
128 
132  Morphology* getOwningMorphologyOrThrow() const;
133 
134  void emitWarning(std::shared_ptr<WarningMessage>);
135 
136  Morphology* morphology_;
137  Property::PointLevel point_properties_;
138  uint32_t id_;
139  SectionType section_type_;
140 };
141 
142 std::ostream& operator<<(std::ostream&, const std::shared_ptr<Section>&);
143 
144 inline uint32_t Section::id() const noexcept {
145  return id_;
146 }
147 
148 inline SectionType& Section::type() noexcept {
149  return section_type_;
150 }
151 
152 inline const SectionType& Section::type() const noexcept {
153  return section_type_;
154 }
155 
156 inline std::vector<Point>& Section::points() noexcept {
157  return point_properties_._points;
158 }
159 
160 inline const std::vector<Point>& Section::points() const noexcept {
161  return point_properties_._points;
162 }
163 
164 inline std::vector<morphio::floatType>& Section::diameters() noexcept {
165  return point_properties_._diameters;
166 }
167 
168 inline const std::vector<morphio::floatType>& Section::diameters() const noexcept {
169  return point_properties_._diameters;
170 }
171 
172 inline std::vector<morphio::floatType>& Section::perimeters() noexcept {
173  return point_properties_._perimeters;
174 }
175 
176 inline const std::vector<morphio::floatType>& Section::perimeters() const noexcept {
177  return point_properties_._perimeters;
178 }
179 
181  return point_properties_;
182 }
183 
184 inline const Property::PointLevel& Section::properties() const noexcept {
185  return point_properties_;
186 }
187 
188 } // namespace mut
189 } // namespace morphio
190 
191 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:82
morphio::enums::SectionType
SectionType
Definition: enums.h:69
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:144
morphio::mut::Section::points
std::vector< Point > & points() noexcept
Definition: section.h:156
morphio::mut::Section::isHeterogeneous
bool isHeterogeneous(bool downstream=true) const
morphio::upstream_iterator_t
Definition: section_iterators.hpp:111
morphio::mut::Section::properties
Property::PointLevel & properties() noexcept
Definition: section.h:180
morphio::mut::Section::diameters
std::vector< morphio::floatType > & diameters() noexcept
Definition: section.h:164
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:32
morphio::mut::Section::type
SectionType & type() noexcept
Definition: section.h:148
morphio::mut::Section::hasSameShape
bool hasSameShape(const Section &other) const noexcept
morphio::mut::Section
Definition: section.h:21
morphio::Property::PointLevel
Definition: properties.h:62
morphio::mut::Section::perimeters
std::vector< morphio::floatType > & perimeters() noexcept
Definition: section.h:172