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