properties.h
1 
20 #pragma once
21 
22 #include <map>
23 #include <morphio/types.h>
24 
25 namespace morphio {
26 namespace Property {
27 
28 struct Section {
29  // (offset, parent index)
30  using Type = std::array<int, 2>;
31 };
32 
33 struct MitoSection {
34  // (offset, parent index)
35  using Type = std::array<int, 2>;
36 };
37 
38 struct Point {
39  using Type = morphio::Point;
40 };
41 
42 struct SectionType {
43  using Type = morphio::SectionType;
44 };
45 
46 struct Perimeter {
47  using Type = floatType;
48 };
49 
50 struct Diameter {
51  using Type = floatType;
52 };
53 
55  using Type = floatType;
56 };
57 
58 struct MitoDiameter {
59  using Type = floatType;
60 };
61 
63  using Type = uint32_t;
64 };
65 
66 struct PointLevel {
67  std::vector<Point::Type> _points;
68  std::vector<Diameter::Type> _diameters;
69  std::vector<Perimeter::Type> _perimeters;
70 
71  PointLevel() = default;
72  PointLevel(std::vector<Point::Type> points,
73  std::vector<Diameter::Type> diameters,
74  std::vector<Perimeter::Type> perimeters = {});
75  PointLevel(const PointLevel& data);
76  PointLevel(const PointLevel& data, SectionRange range);
77  PointLevel& operator=(const PointLevel& other);
78 };
79 
80 struct SectionLevel {
81  std::vector<Section::Type> _sections;
82  std::vector<SectionType::Type> _sectionTypes;
83  std::map<int, std::vector<unsigned int>> _children;
84 
85  bool operator==(const SectionLevel& other) const;
86  bool operator!=(const SectionLevel& other) const;
87 
88  // Like operator!= but with logLevel argument
89  bool diff(const SectionLevel& other, LogLevel logLevel) const;
90 };
91 
93  std::vector<MitoNeuriteSectionId::Type> _sectionIds;
94  std::vector<MitoPathLength::Type> _relativePathLengths;
95  std::vector<MitoDiameter::Type> _diameters;
96 
97  MitochondriaPointLevel() = default;
98  MitochondriaPointLevel(const MitochondriaPointLevel& data, const SectionRange& range);
99 
100  MitochondriaPointLevel(std::vector<uint32_t> sectionId,
101  // relative pathlength between the current points
102  // and the start of the neuronal section
103  std::vector<MitoPathLength::Type> relativePathLengths,
104  std::vector<MitoDiameter::Type> diameters);
105 
106  bool diff(const MitochondriaPointLevel& other, LogLevel logLevel) const;
107  bool operator==(const MitochondriaPointLevel& other) const;
108  bool operator!=(const MitochondriaPointLevel& other) const;
109 };
110 
112  std::vector<Section::Type> _sections;
113  std::map<int, std::vector<unsigned int>> _children;
114 
115  bool diff(const MitochondriaSectionLevel& other, LogLevel logLevel) const;
116  bool operator==(const MitochondriaSectionLevel& other) const;
117  bool operator!=(const MitochondriaSectionLevel& other) const;
118 };
119 
121  std::vector<uint32_t> _sectionIndices;
122  std::vector<morphio::floatType> _volumes;
123  std::vector<morphio::floatType> _surfaceAreas;
124  std::vector<uint32_t> _filamentCounts;
125 };
126 
127 struct Annotation {
128  Annotation(AnnotationType type,
129  uint32_t sectionId,
130  PointLevel points,
131  std::string details,
132  int32_t lineNumber)
133  : _type(type)
134  , _sectionId(sectionId)
135  , _points(std::move(points))
136  , _details(std::move(details))
137  , _lineNumber(lineNumber) {}
138 
139  AnnotationType _type;
140  uint32_t _sectionId;
141  PointLevel _points;
142  std::string _details;
143  int32_t _lineNumber;
144 };
145 
146 struct Marker {
147  PointLevel _pointLevel;
148  std::string _label;
149  int32_t _sectionId; // id of section that contains the marker
150 };
151 
152 struct CellLevel {
153  MorphologyVersion _version = {"undefined", 0, 0};
154  morphio::CellFamily _cellFamily = NEURON;
155  SomaType _somaType = SOMA_UNDEFINED;
156  std::vector<Annotation> _annotations;
157  std::vector<Marker> _markers;
158 
159  bool diff(const CellLevel& other, LogLevel logLevel) const;
160  bool operator==(const CellLevel& other) const;
161  bool operator!=(const CellLevel& other) const;
162  std::string fileFormat() const;
163  uint32_t majorVersion();
164  uint32_t minorVersion();
165 };
166 
167 // The lowest level data blob
168 struct Properties {
169  PointLevel _pointLevel;
170  SectionLevel _sectionLevel;
171  CellLevel _cellLevel;
172  PointLevel _somaLevel;
173 
174  MitochondriaPointLevel _mitochondriaPointLevel;
175  MitochondriaSectionLevel _mitochondriaSectionLevel;
176 
177  EndoplasmicReticulumLevel _endoplasmicReticulumLevel;
178 
179  template <typename T>
180  std::vector<typename T::Type>& get_mut() noexcept;
181 
182  template <typename T>
183  const std::vector<typename T::Type>& get() const noexcept;
184 
185  const morphio::MorphologyVersion& version() const noexcept {
186  return _cellLevel._version;
187  }
188  const morphio::CellFamily& cellFamily() const noexcept {
189  return _cellLevel._cellFamily;
190  }
191  const morphio::SomaType& somaType() const noexcept {
192  return _cellLevel._somaType;
193  }
194  template <typename T>
195  const std::map<int32_t, std::vector<uint32_t>>& children() const noexcept;
196 };
197 
198 std::ostream& operator<<(std::ostream& os, const Properties& properties);
199 std::ostream& operator<<(std::ostream& os, const PointLevel& pointLevel);
200 
201 #define INSTANTIATE_TEMPLATE_GET(T, M) \
202  template <> \
203  inline std::vector<T::Type>& Properties::get_mut<T>() noexcept { \
204  return M; \
205  } \
206  template <> \
207  inline const std::vector<T::Type>& Properties::get<T>() const noexcept { \
208  return M; \
209  }
210 
211 INSTANTIATE_TEMPLATE_GET(Point, _pointLevel._points)
212 INSTANTIATE_TEMPLATE_GET(Perimeter, _pointLevel._perimeters)
213 INSTANTIATE_TEMPLATE_GET(Diameter, _pointLevel._diameters)
214 INSTANTIATE_TEMPLATE_GET(MitoSection, _mitochondriaSectionLevel._sections)
215 INSTANTIATE_TEMPLATE_GET(MitoPathLength, _mitochondriaPointLevel._relativePathLengths)
216 INSTANTIATE_TEMPLATE_GET(MitoNeuriteSectionId, _mitochondriaPointLevel._sectionIds)
217 INSTANTIATE_TEMPLATE_GET(MitoDiameter, _mitochondriaPointLevel._diameters)
218 INSTANTIATE_TEMPLATE_GET(Section, _sectionLevel._sections)
219 INSTANTIATE_TEMPLATE_GET(SectionType, _sectionLevel._sectionTypes)
220 
221 #undef INSTANTIATE_TEMPLATE_GET
222 
223 template <>
224 inline const std::map<int32_t, std::vector<uint32_t>>& Properties::children<Section>() const
225  noexcept {
226  return _sectionLevel._children;
227 }
228 
229 template <>
230 inline const std::map<int32_t, std::vector<uint32_t>>& Properties::children<MitoSection>() const
231  noexcept {
232  return _mitochondriaSectionLevel._children;
233 }
234 
235 } // namespace Property
236 } // namespace morphio
Definition: endoplasmic_reticulum.h:5
Definition: properties.h:127
Definition: properties.h:152
Definition: properties.h:50
Definition: properties.h:146
Definition: properties.h:58
Definition: properties.h:62
Definition: properties.h:54
Definition: properties.h:33
Definition: properties.h:46
Definition: properties.h:38
Definition: properties.h:66
Definition: properties.h:168
Definition: properties.h:28
Definition: properties.h:80
Definition: properties.h:42