properties.h
1 /* Copyright (c) 2013-2023, EPFL/Blue Brain Project
2  *
3  * SPDX-License-Identifier: Apache-2.0
4  */
5 #pragma once
6 
7 #include <map>
8 #include <string> // std::string
9 #include <vector> // std::vector
10 
11 #include <morphio/types.h>
12 
13 namespace morphio {
14 namespace vasculature {
15 namespace property {
16 
17 struct VascSection {
18  // offset
19  // refers to the index in the points vector from which the section begins
20  using Type = unsigned int;
21 };
22 
23 struct Point {
24  using Type = morphio::Point;
25 };
26 
27 struct SectionType {
29 };
30 
31 struct Diameter {
32  using Type = floatType;
33 };
34 
39 struct Connection {
40  using Type = std::array<unsigned int, 2>;
41 };
42 
45  std::vector<Point::Type> _points;
46  std::vector<Diameter::Type> _diameters;
47 
48  VascPointLevel() = default;
49  VascPointLevel(const std::vector<Point::Type>& points,
50  const std::vector<Diameter::Type>& diameters);
51  VascPointLevel(const VascPointLevel& data);
52  VascPointLevel(const VascPointLevel& data, SectionRange range);
53  VascPointLevel& operator=(const VascPointLevel&) = default;
54 };
55 
57 struct VascEdgeLevel {
58  std::vector<morphio::floatType> leakiness;
59 };
60 
63  std::vector<VascSection::Type> _sections;
64  std::vector<SectionType::Type> _sectionTypes;
65  std::map<uint32_t, std::vector<uint32_t>> _predecessors;
66  std::map<uint32_t, std::vector<uint32_t>> _successors;
67  bool operator==(const VascSectionLevel& other) const;
68  bool operator!=(const VascSectionLevel& other) const;
69 
70  // Like operator!= but with logLevel argument
71  bool diff(const VascSectionLevel& other, LogLevel logLevel) const;
72 };
73 
75 struct Properties {
76  VascPointLevel _pointLevel;
77  VascEdgeLevel _edgeLevel;
78  VascSectionLevel _sectionLevel;
79  std::vector<Connection::Type> _connectivity;
80 
81  template <typename T>
82  std::vector<typename T::Type>& get_mut() noexcept;
83 
84  template <typename T>
85  const std::vector<typename T::Type>& get() const noexcept;
86 
87  const std::map<uint32_t, std::vector<uint32_t>>& predecessors() const noexcept {
88  return _sectionLevel._predecessors;
89  }
90  const std::map<uint32_t, std::vector<uint32_t>>& successors() const noexcept {
91  return _sectionLevel._successors;
92  }
93 };
94 
95 std::ostream& operator<<(std::ostream& os, const Properties& properties);
96 std::ostream& operator<<(std::ostream& os, const VascPointLevel& pointLevel);
97 
98 #define INSTANTIATE_TEMPLATE_GET(T, M) \
99  template <> \
100  inline std::vector<T::Type>& Properties::get_mut<T>() noexcept { \
101  return M; \
102  } \
103  template <> \
104  inline const std::vector<T::Type>& Properties::get<T>() const noexcept { \
105  return M; \
106  }
107 
108 INSTANTIATE_TEMPLATE_GET(VascSection, _sectionLevel._sections)
109 INSTANTIATE_TEMPLATE_GET(Point, _pointLevel._points)
110 INSTANTIATE_TEMPLATE_GET(Connection, _connectivity)
111 INSTANTIATE_TEMPLATE_GET(SectionType, _sectionLevel._sectionTypes)
112 INSTANTIATE_TEMPLATE_GET(Diameter, _pointLevel._diameters)
113 
114 #undef INSTANTIATE_TEMPLATE_GET
115 
116 
117 } // namespace property
118 } // namespace vasculature
119 } // namespace morphio
morphio::vasculature::property::Point
Definition: properties.h:23
morphio::vasculature::property::Properties
Definition: properties.h:75
morphio::vasculature::property::Diameter
Definition: properties.h:31
morphio::vasculature::property::VascPointLevel
Definition: properties.h:44
morphio::vasculature::property::VascEdgeLevel
Definition: properties.h:57
morphio::vasculature::property::VascSectionLevel
Definition: properties.h:62
morphio::vasculature::property::Connection
Definition: properties.h:39
morphio::vasculature::property::VascSection
Definition: properties.h:17
morphio::enums::VascularSectionType
VascularSectionType
Definition: enums.h:121
morphio::vasculature::property::SectionType
Definition: properties.h:27