morphology.h
1 #pragma once
2 
3 #include <cstdint>
4 #include <iomanip>
5 #include <iostream>
6 #include <memory>
7 #include <ostream>
8 #include <unordered_map>
9 
10 #include <functional>
11 
12 #include <morphio/errorMessages.h>
13 #include <morphio/exceptions.h>
14 #include <morphio/mut/endoplasmic_reticulum.h>
15 #include <morphio/mut/mitochondria.h>
16 #include <morphio/mut/soma.h>
17 #include <morphio/properties.h>
18 #include <morphio/section.h>
19 #include <morphio/types.h>
20 
21 namespace morphio {
22 namespace mut {
23 bool _checkDuplicatePoint(const std::shared_ptr<Section>& parent,
24  const std::shared_ptr<Section>& current);
25 
27 {
28  public:
29  Morphology()
30  : _counter(0)
31  , _soma(std::make_shared<Soma>())
32  , _cellProperties(
33  std::make_shared<morphio::Property::CellLevel>(morphio::Property::CellLevel())) {}
34 
44  Morphology(const std::string& uri, unsigned int options = NO_MODIFIER);
45 
49  Morphology(const morphio::mut::Morphology& morphology, unsigned int options = NO_MODIFIER);
50 
54  Morphology(const morphio::Morphology& morphology, unsigned int options = NO_MODIFIER);
55 
56  virtual ~Morphology();
57 
61  inline const std::vector<std::shared_ptr<Section>>& rootSections() const noexcept;
62 
66  inline const std::map<uint32_t, std::shared_ptr<Section>>& sections() const noexcept;
67 
73  inline std::shared_ptr<Soma>& soma() noexcept;
74 
80  inline const std::shared_ptr<Soma>& soma() const noexcept;
81 
85  inline Mitochondria& mitochondria() noexcept;
89  inline const Mitochondria& mitochondria() const noexcept;
90 
94  inline EndoplasmicReticulum& endoplasmicReticulum() noexcept;
98  inline const EndoplasmicReticulum& endoplasmicReticulum() const noexcept;
99 
103  inline const std::vector<Property::Annotation>& annotations() const noexcept;
104 
108  inline const std::vector<Property::Marker>& markers() const noexcept;
109 
115  inline const std::shared_ptr<Section>& section(uint32_t id) const;
116 
123  depth_iterator depth_end() const;
124 
132  breadth_iterator breadth_end() const;
133 
135  //
136  // Tree manipulation methods
137  //
139 
148  void deleteSection(std::shared_ptr<Section> section, bool recursive = true);
149 
155  std::shared_ptr<Section> appendRootSection(const morphio::Section&, bool recursive = false);
156 
162  std::shared_ptr<Section> appendRootSection(const std::shared_ptr<Section>& section,
163  bool recursive = false);
164 
168  std::shared_ptr<Section> appendRootSection(const Property::PointLevel&,
169  SectionType sectionType);
170 
171  void applyModifiers(unsigned int modifierFlags);
172 
176  inline SomaType somaType() const noexcept;
177 
181  inline CellFamily cellFamily() const noexcept;
182 
186  inline MorphologyVersion version() const noexcept;
187 
191  void write(const std::string& filename);
192 
193  inline void addAnnotation(const morphio::Property::Annotation& annotation);
194  inline void addMarker(const morphio::Property::Marker& marker);
195 
199  Property::Properties buildReadOnly() const;
200 
206  std::unordered_map<int, std::vector<unsigned int>> connectivity();
207 
208 
214  void removeUnifurcations(const morphio::readers::DebugInfo& debugInfo);
215 
220 
221  public:
222  friend class Section;
223  friend void modifiers::nrn_order(morphio::mut::Morphology& morpho);
224  friend bool diff(const Morphology& left,
225  const Morphology& right,
226  morphio::enums::LogLevel verbose);
227  morphio::readers::ErrorMessages _err;
228 
229  uint32_t _register(const std::shared_ptr<Section>&);
230 
231  uint32_t _counter;
232  std::shared_ptr<Soma> _soma;
233  std::shared_ptr<morphio::Property::CellLevel> _cellProperties;
234  std::vector<std::shared_ptr<Section>> _rootSections;
235  std::map<uint32_t, std::shared_ptr<Section>> _sections;
236  Mitochondria _mitochondria;
237  EndoplasmicReticulum _endoplasmicReticulum;
238 
239  std::map<uint32_t, uint32_t> _parent;
240  std::map<uint32_t, std::vector<std::shared_ptr<Section>>> _children;
241 
242  private:
243  void eraseByValue(std::vector<std::shared_ptr<Section>>& vec,
244  const std::shared_ptr<Section> section);
245 };
246 
247 inline const std::vector<std::shared_ptr<Section>>& Morphology::rootSections() const noexcept {
248  return _rootSections;
249 }
250 
251 inline const std::map<uint32_t, std::shared_ptr<Section>>& Morphology::sections() const noexcept {
252  return _sections;
253 }
254 
255 inline std::shared_ptr<Soma>& Morphology::soma() noexcept {
256  return _soma;
257 }
258 
259 inline const std::shared_ptr<Soma>& Morphology::soma() const noexcept {
260  return _soma;
261 }
262 
264  return _mitochondria;
265 }
266 
267 inline const Mitochondria& Morphology::mitochondria() const noexcept {
268  return _mitochondria;
269 }
270 
272  return _endoplasmicReticulum;
273 }
274 
276  return _endoplasmicReticulum;
277 }
278 
279 inline const std::shared_ptr<Section>& Morphology::section(uint32_t id) const {
280  return _sections.at(id);
281 }
282 
283 inline SomaType Morphology::somaType() const noexcept {
284  return _soma->type();
285 }
286 
287 inline const std::vector<Property::Annotation>& Morphology::annotations() const noexcept {
288  return _cellProperties->_annotations;
289 }
290 
291 inline const std::vector<Property::Marker>& Morphology::markers() const noexcept {
292  return _cellProperties->_markers;
293 }
294 
295 inline CellFamily Morphology::cellFamily() const noexcept {
296  return _cellProperties->_cellFamily;
297 }
298 
299 inline MorphologyVersion Morphology::version() const noexcept {
300  return _cellProperties->_version;
301 }
302 
303 inline void Morphology::addAnnotation(const morphio::Property::Annotation& annotation) {
304  _cellProperties->_annotations.push_back(annotation);
305 }
306 
307 inline void Morphology::addMarker(const morphio::Property::Marker& marker) {
308  _cellProperties->_markers.push_back(marker);
309 }
310 
311 } // namespace mut
312 } // namespace morphio
Definition: morphology.h:22
Definition: section_iterators.hpp:54
Definition: section_iterators.hpp:82
Definition: endoplasmic_reticulum.h:14
Definition: mitochondria.h:29
Definition: morphology.h:27
void write(const std::string &filename)
friend bool diff(const Morphology &left, const Morphology &right, morphio::enums::LogLevel verbose)
breadth_iterator breadth_begin() const
std::shared_ptr< Soma > & soma() noexcept
Definition: morphology.h:255
const std::vector< Property::Marker > & markers() const noexcept
Definition: morphology.h:291
std::unordered_map< int, std::vector< unsigned int > > connectivity()
const std::shared_ptr< Section > & section(uint32_t id) const
Definition: morphology.h:279
Mitochondria & mitochondria() noexcept
Definition: morphology.h:263
std::shared_ptr< Section > appendRootSection(const morphio::Section &, bool recursive=false)
Morphology(const std::string &uri, unsigned int options=NO_MODIFIER)
void deleteSection(std::shared_ptr< Section > section, bool recursive=true)
CellFamily cellFamily() const noexcept
Definition: morphology.h:295
const std::map< uint32_t, std::shared_ptr< Section > > & sections() const noexcept
Definition: morphology.h:251
const std::vector< Property::Annotation > & annotations() const noexcept
Definition: morphology.h:287
SomaType somaType() const noexcept
Definition: morphology.h:283
depth_iterator depth_begin() const
Morphology(const morphio::Morphology &morphology, unsigned int options=NO_MODIFIER)
MorphologyVersion version() const noexcept
Definition: morphology.h:299
EndoplasmicReticulum & endoplasmicReticulum() noexcept
Definition: morphology.h:271
Morphology(const morphio::mut::Morphology &morphology, unsigned int options=NO_MODIFIER)
Property::Properties buildReadOnly() const
const std::vector< std::shared_ptr< Section > > & rootSections() const noexcept
Definition: morphology.h:247
Definition: section.h:19
Definition: soma.h:8
Definition: endoplasmic_reticulum.h:5
Definition: properties.h:127
Definition: properties.h:152
Definition: properties.h:146