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  bool diff(const SectionLevel& other) const;
86 };
87 
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) const;
107  bool operator==(const MitochondriaPointLevel& other) const;
108  bool operator!=(const MitochondriaPointLevel& other) const;
109 };
110 
113  std::vector<Section::Type> _sections;
114  std::map<int, std::vector<unsigned int>> _children;
115 
116  bool diff(const MitochondriaSectionLevel& other) const;
117  bool operator==(const MitochondriaSectionLevel& other) const;
118  bool operator!=(const MitochondriaSectionLevel& other) const;
119 };
120 
122 namespace DendriticSpine {
123 
124 using SectionId_t = int32_t;
125 using SegmentId_t = int32_t;
126 using Offset_t = floatType;
127 
129  SectionId_t sectionId;
130  SegmentId_t segmentId;
131  Offset_t offset;
132 };
133 
134 struct Level {
135  std::vector<PostSynapticDensity> _post_synaptic_density;
136 };
137 
138 } // namespace DendriticSpine
139 
145  std::vector<uint32_t> _sectionIndices;
146  std::vector<morphio::floatType> _volumes;
147  std::vector<morphio::floatType> _surfaceAreas;
148  std::vector<uint32_t> _filamentCounts;
149 };
150 
152 struct Annotation {
153  Annotation(AnnotationType type,
154  uint32_t sectionId,
155  PointLevel points,
156  std::string details,
157  int32_t lineNumber)
158  : _type(type)
159  , _sectionId(sectionId)
160  , _points(std::move(points))
161  , _details(std::move(details))
162  , _lineNumber(lineNumber) {}
163 
164  AnnotationType _type;
165  uint32_t _sectionId;
166  PointLevel _points;
167  std::string _details;
168  int32_t _lineNumber;
169 };
170 
171 
176 struct Marker {
177  PointLevel _pointLevel;
178  std::string _label;
179  int32_t _sectionId;
180 };
181 
186 struct CellLevel {
187  MorphologyVersion _version = {"undefined", 0, 0};
188  morphio::CellFamily _cellFamily = NEURON;
189  SomaType _somaType = SOMA_UNDEFINED;
190  std::vector<Annotation> _annotations;
191  std::vector<Marker> _markers;
192 
193  bool diff(const CellLevel& other) const;
194  bool operator==(const CellLevel& other) const;
195  bool operator!=(const CellLevel& other) const;
196 
197  std::string fileFormat() const {
198  return std::get<0>(_version);
199  }
200  uint32_t majorVersion() {
201  return std::get<1>(_version);
202  }
203  uint32_t minorVersion() {
204  return std::get<2>(_version);
205  }
206 };
207 
209 struct Properties {
210  PointLevel _pointLevel;
211  SectionLevel _sectionLevel;
212  CellLevel _cellLevel;
213  PointLevel _somaLevel;
214 
215  MitochondriaPointLevel _mitochondriaPointLevel;
216  MitochondriaSectionLevel _mitochondriaSectionLevel;
217 
218  EndoplasmicReticulumLevel _endoplasmicReticulumLevel;
219 
220  DendriticSpine::Level _dendriticSpineLevel;
221 
222  template <typename T>
223  std::vector<typename T::Type>& get_mut() noexcept;
224 
225  template <typename T>
226  const std::vector<typename T::Type>& get() const noexcept;
227 
228  const morphio::MorphologyVersion& version() const noexcept {
229  return _cellLevel._version;
230  }
231  const morphio::CellFamily& cellFamily() const noexcept {
232  return _cellLevel._cellFamily;
233  }
234  const morphio::SomaType& somaType() const noexcept {
235  return _cellLevel._somaType;
236  }
237  template <typename T>
238  const std::map<int32_t, std::vector<uint32_t>>& children() const noexcept;
239 };
240 
241 
242 std::ostream& operator<<(std::ostream& os, const Properties& properties);
243 std::ostream& operator<<(std::ostream& os, const PointLevel& pointLevel);
244 
245 #define INSTANTIATE_TEMPLATE_GET(T, M) \
246  template <> \
247  inline std::vector<T::Type>& Properties::get_mut<T>() noexcept { \
248  return M; \
249  } \
250  template <> \
251  inline const std::vector<T::Type>& Properties::get<T>() const noexcept { \
252  return M; \
253  }
254 
255 INSTANTIATE_TEMPLATE_GET(Point, _pointLevel._points)
256 INSTANTIATE_TEMPLATE_GET(Perimeter, _pointLevel._perimeters)
257 INSTANTIATE_TEMPLATE_GET(Diameter, _pointLevel._diameters)
258 INSTANTIATE_TEMPLATE_GET(MitoSection, _mitochondriaSectionLevel._sections)
259 INSTANTIATE_TEMPLATE_GET(MitoPathLength, _mitochondriaPointLevel._relativePathLengths)
260 INSTANTIATE_TEMPLATE_GET(MitoNeuriteSectionId, _mitochondriaPointLevel._sectionIds)
261 INSTANTIATE_TEMPLATE_GET(MitoDiameter, _mitochondriaPointLevel._diameters)
262 INSTANTIATE_TEMPLATE_GET(Section, _sectionLevel._sections)
263 INSTANTIATE_TEMPLATE_GET(SectionType, _sectionLevel._sectionTypes)
264 
265 #undef INSTANTIATE_TEMPLATE_GET
266 
267 template <>
268 inline const std::map<int32_t, std::vector<uint32_t>>& Properties::children<Section>() const
269  noexcept {
270  return _sectionLevel._children;
271 }
272 
273 template <>
274 inline const std::map<int32_t, std::vector<uint32_t>>& Properties::children<MitoSection>() const
275  noexcept {
276  return _mitochondriaSectionLevel._children;
277 }
278 
279 } // namespace Property
280 } // namespace morphio
morphio::Property::Properties
Definition: properties.h:209
morphio::enums::SomaType
SomaType
Definition: enums.h:61
morphio::enums::SectionType
SectionType
Definition: enums.h:71
morphio::Property::EndoplasmicReticulumLevel
Definition: properties.h:144
morphio::Property::MitochondriaPointLevel
Definition: properties.h:92
morphio::enums::NEURON
@ NEURON
Neuron.
Definition: enums.h:55
morphio::Property::SectionType
Definition: properties.h:37
morphio::Property::MitoDiameter
Definition: properties.h:53
morphio::Property::Annotation
Definition: properties.h:152
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:54
morphio::enums::SOMA_UNDEFINED
@ SOMA_UNDEFINED
Undefined soma.
Definition: enums.h:62
morphio::Property::CellLevel
Definition: properties.h:186
morphio::Property::Perimeter
Definition: properties.h:41
morphio::DendriticSpine
Definition: dendritic_spine.h:17
morphio::Property::Marker
Definition: properties.h:176
morphio::Property::MitoSection
Definition: properties.h:28
morphio::Property::MitoPathLength
Definition: properties.h:49
morphio::Property::DendriticSpine::Level
Definition: properties.h:134
morphio::Property::DendriticSpine::PostSynapticDensity
Definition: properties.h:128
morphio::Property::Diameter
Definition: properties.h:45
morphio::Property::MitochondriaSectionLevel
Definition: properties.h:112
morphio::Property::Marker::_sectionId
int32_t _sectionId
id of section that contains the marker
Definition: properties.h:179
morphio::Property::PointLevel
Definition: properties.h:62