properties.h
1 #pragma once
2 
3 #include <cstdint> // uint32_t
4 
5 #include <array>
6 #include <map>
7 #include <vector>
8 
9 #include <morphio/types.h>
10 #include <morphio/vector_types.h>
11 #include <morphio/version.h>
12 
13 namespace morphio {
21 namespace Property {
22 
23 struct Section {
24  // (offset, parent index)
25  using Type = std::array<int, 2>;
26 };
27 
28 struct MitoSection {
29  // (offset, parent index)
30  using Type = std::array<int, 2>;
31 };
32 
33 struct Point {
34  using Type = morphio::Point;
35 };
36 
37 struct SectionType {
38  using Type = morphio::SectionType;
39 };
40 
41 struct Perimeter {
42  using Type = floatType;
43 };
44 
45 struct Diameter {
46  using Type = floatType;
47 };
48 
50  using Type = floatType;
51 };
52 
53 struct MitoDiameter {
54  using Type = floatType;
55 };
56 
58  using Type = uint32_t;
59 };
60 
62 struct PointLevel {
63  std::vector<Point::Type> _points;
64  std::vector<Diameter::Type> _diameters;
65  std::vector<Perimeter::Type> _perimeters;
66 
67  PointLevel() = default;
68  PointLevel(std::vector<Point::Type> points,
69  std::vector<Diameter::Type> diameters,
70  std::vector<Perimeter::Type> perimeters = {});
71  PointLevel(const PointLevel& data);
72  PointLevel(const PointLevel& data, SectionRange range);
73  PointLevel& operator=(const PointLevel& other);
74 };
75 
77 struct SectionLevel {
78  std::vector<Section::Type> _sections;
79  std::vector<SectionType::Type> _sectionTypes;
80  std::map<int, std::vector<unsigned int>> _children;
81 
82  bool operator==(const SectionLevel& other) const;
83  bool operator!=(const SectionLevel& other) const;
84 
85  // Like operator!= but with logLevel argument
86  bool diff(const SectionLevel& other, LogLevel logLevel) const;
87 };
88 
94  std::vector<MitoNeuriteSectionId::Type> _sectionIds;
95  std::vector<MitoPathLength::Type> _relativePathLengths;
96  std::vector<MitoDiameter::Type> _diameters;
97 
98  MitochondriaPointLevel() = default;
99  MitochondriaPointLevel(const MitochondriaPointLevel& data, const SectionRange& range);
100 
101  MitochondriaPointLevel(std::vector<uint32_t> sectionId,
102  // relative pathlength between the current points
103  // and the start of the neuronal section
104  std::vector<MitoPathLength::Type> relativePathLengths,
105  std::vector<MitoDiameter::Type> diameters);
106 
107  bool diff(const MitochondriaPointLevel& other, LogLevel logLevel) const;
108  bool operator==(const MitochondriaPointLevel& other) const;
109  bool operator!=(const MitochondriaPointLevel& other) const;
110 };
111 
114  std::vector<Section::Type> _sections;
115  std::map<int, std::vector<unsigned int>> _children;
116 
117  bool diff(const MitochondriaSectionLevel& other, LogLevel logLevel) const;
118  bool operator==(const MitochondriaSectionLevel& other) const;
119  bool operator!=(const MitochondriaSectionLevel& other) const;
120 };
121 
123 namespace DendriticSpine {
124 
125 using SectionId_t = int32_t;
126 using SegmentId_t = int32_t;
127 using Offset_t = floatType;
128 
130  SectionId_t sectionId;
131  SegmentId_t segmentId;
132  Offset_t offset;
133 };
134 
135 struct Level {
136  std::vector<PostSynapticDensity> _post_synaptic_density;
137 };
138 
139 } // namespace DendriticSpine
140 
146  std::vector<uint32_t> _sectionIndices;
147  std::vector<morphio::floatType> _volumes;
148  std::vector<morphio::floatType> _surfaceAreas;
149  std::vector<uint32_t> _filamentCounts;
150 };
151 
153 struct Annotation {
154  Annotation(AnnotationType type,
155  uint32_t sectionId,
156  PointLevel points,
157  std::string details,
158  int32_t lineNumber)
159  : _type(type)
160  , _sectionId(sectionId)
161  , _points(std::move(points))
162  , _details(std::move(details))
163  , _lineNumber(lineNumber) {}
164 
165  AnnotationType _type;
166  uint32_t _sectionId;
167  PointLevel _points;
168  std::string _details;
169  int32_t _lineNumber;
170 };
171 
172 
177 struct Marker {
178  PointLevel _pointLevel;
179  std::string _label;
180  int32_t _sectionId;
181 };
182 
187 struct CellLevel {
188  MorphologyVersion _version = {"undefined", 0, 0};
189  morphio::CellFamily _cellFamily = NEURON;
190  SomaType _somaType = SOMA_UNDEFINED;
191  std::vector<Annotation> _annotations;
192  std::vector<Marker> _markers;
193 
194  bool diff(const CellLevel& other, LogLevel logLevel) const;
195  bool operator==(const CellLevel& other) const;
196  bool operator!=(const CellLevel& other) const;
197 
198  std::string fileFormat() const {
199  return std::get<0>(_version);
200  }
201  uint32_t majorVersion() {
202  return std::get<1>(_version);
203  }
204  uint32_t minorVersion() {
205  return std::get<2>(_version);
206  }
207 };
208 
210 struct Properties {
211  PointLevel _pointLevel;
212  SectionLevel _sectionLevel;
213  CellLevel _cellLevel;
214  PointLevel _somaLevel;
215 
216  MitochondriaPointLevel _mitochondriaPointLevel;
217  MitochondriaSectionLevel _mitochondriaSectionLevel;
218 
219  EndoplasmicReticulumLevel _endoplasmicReticulumLevel;
220 
221  DendriticSpine::Level _dendriticSpineLevel;
222 
223  template <typename T>
224  std::vector<typename T::Type>& get_mut() noexcept;
225 
226  template <typename T>
227  const std::vector<typename T::Type>& get() const noexcept;
228 
229  const morphio::MorphologyVersion& version() const noexcept {
230  return _cellLevel._version;
231  }
232  const morphio::CellFamily& cellFamily() const noexcept {
233  return _cellLevel._cellFamily;
234  }
235  const morphio::SomaType& somaType() const noexcept {
236  return _cellLevel._somaType;
237  }
238  template <typename T>
239  const std::map<int32_t, std::vector<uint32_t>>& children() const noexcept;
240 };
241 
242 
243 std::ostream& operator<<(std::ostream& os, const Properties& properties);
244 std::ostream& operator<<(std::ostream& os, const PointLevel& pointLevel);
245 
246 #define INSTANTIATE_TEMPLATE_GET(T, M) \
247  template <> \
248  inline std::vector<T::Type>& Properties::get_mut<T>() noexcept { \
249  return M; \
250  } \
251  template <> \
252  inline const std::vector<T::Type>& Properties::get<T>() const noexcept { \
253  return M; \
254  }
255 
256 INSTANTIATE_TEMPLATE_GET(Point, _pointLevel._points)
257 INSTANTIATE_TEMPLATE_GET(Perimeter, _pointLevel._perimeters)
258 INSTANTIATE_TEMPLATE_GET(Diameter, _pointLevel._diameters)
259 INSTANTIATE_TEMPLATE_GET(MitoSection, _mitochondriaSectionLevel._sections)
260 INSTANTIATE_TEMPLATE_GET(MitoPathLength, _mitochondriaPointLevel._relativePathLengths)
261 INSTANTIATE_TEMPLATE_GET(MitoNeuriteSectionId, _mitochondriaPointLevel._sectionIds)
262 INSTANTIATE_TEMPLATE_GET(MitoDiameter, _mitochondriaPointLevel._diameters)
263 INSTANTIATE_TEMPLATE_GET(Section, _sectionLevel._sections)
264 INSTANTIATE_TEMPLATE_GET(SectionType, _sectionLevel._sectionTypes)
265 
266 #undef INSTANTIATE_TEMPLATE_GET
267 
268 template <>
269 inline const std::map<int32_t, std::vector<uint32_t>>& Properties::children<Section>() const
270  noexcept {
271  return _sectionLevel._children;
272 }
273 
274 template <>
275 inline const std::map<int32_t, std::vector<uint32_t>>& Properties::children<MitoSection>() const
276  noexcept {
277  return _mitochondriaSectionLevel._children;
278 }
279 
280 } // namespace Property
281 } // namespace morphio
morphio::Property::Properties
Definition: properties.h:210
morphio::enums::SomaType
SomaType
Definition: enums.h:59
morphio::enums::SectionType
SectionType
Definition: enums.h:69
morphio::Property::EndoplasmicReticulumLevel
Definition: properties.h:145
morphio::Property::MitochondriaPointLevel
Definition: properties.h:93
morphio::enums::NEURON
@ NEURON
Neuron.
Definition: enums.h:53
morphio::Property::SectionType
Definition: properties.h:37
morphio::Property::MitoDiameter
Definition: properties.h:53
morphio::Property::Annotation
Definition: properties.h:153
morphio::Property::SectionLevel
Definition: properties.h:77
morphio::Property::MitoNeuriteSectionId
Definition: properties.h:57
morphio::Property::Section
Definition: properties.h:23
morphio::Property::Point
Definition: properties.h:33
morphio::enums::CellFamily
CellFamily
Definition: enums.h:52
morphio::enums::SOMA_UNDEFINED
@ SOMA_UNDEFINED
Undefined soma.
Definition: enums.h:60
morphio::Property::CellLevel
Definition: properties.h:187
morphio::Property::Perimeter
Definition: properties.h:41
morphio::DendriticSpine
Definition: dendritic_spine.h:17
morphio::Property::Marker
Definition: properties.h:177
morphio::Property::MitoSection
Definition: properties.h:28
morphio::Property::MitoPathLength
Definition: properties.h:49
morphio::Property::DendriticSpine::Level
Definition: properties.h:135
morphio::Property::DendriticSpine::PostSynapticDensity
Definition: properties.h:129
morphio::Property::Diameter
Definition: properties.h:45
morphio::Property::MitochondriaSectionLevel
Definition: properties.h:113
morphio::Property::Marker::_sectionId
int32_t _sectionId
id of section that contains the marker
Definition: properties.h:180
morphio::Property::PointLevel
Definition: properties.h:62