• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

BlueBrain / MorphIO / 6533524408

16 Oct 2023 12:24PM UTC coverage: 76.051% (-0.02%) from 76.073%
6533524408

push

github

mgeplf
fix test_root_node_split

1972 of 2593 relevant lines covered (76.05%)

903.23 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

62.67
/src/mut/mitochondria.cpp
1
/* Copyright (c) 2013-2023, EPFL/Blue Brain Project
2
 *
3
 * SPDX-License-Identifier: Apache-2.0
4
 */
5
#include <queue>  // std::queue
6

7
#include <morphio/mut/mitochondria.h>
8

9

10
#include "../shared_utils.hpp"
11

12
namespace morphio {
13
namespace mut {
14

15
Mitochondria::MitoSectionP Mitochondria::appendRootSection(const morphio::MitoSection& section_,
44✔
16
                                                           bool recursive) {
17
    auto ptr = std::make_shared<MitoSection>(this, _counter, section_);
44✔
18
    _register(ptr);
44✔
19
    root_sections_.push_back(ptr);
44✔
20

21
    if (recursive) {
44✔
22
        for (const auto& child : section_.children()) {
66✔
23
            ptr->appendSection(child, true);
22✔
24
        }
25
    }
26

27
    return ptr;
44✔
28
}
29

30
Mitochondria::MitoSectionP Mitochondria::appendRootSection(const MitoSectionP& section_,
×
31
                                                           bool recursive) {
32
    auto section_copy = std::make_shared<MitoSection>(this, _counter, *section_);
×
33
    _register(section_copy);
×
34
    root_sections_.push_back(section_copy);
×
35

36
    if (recursive) {
×
37
        for (const auto& child : section_->children()) {
×
38
            section_copy->appendSection(child, true);
×
39
        }
40
    }
41

42
    return section_copy;
×
43
}
44

45
Mitochondria::MitoSectionP Mitochondria::appendRootSection(
×
46
    const Property::MitochondriaPointLevel& pointProperties) {
47
    auto ptr = std::make_shared<MitoSection>(this, _counter, pointProperties);
×
48
    _register(ptr);
×
49
    root_sections_.push_back(ptr);
×
50

51
    return ptr;
×
52
}
53

54
static void _appendMitoProperties(Property::MitochondriaPointLevel& to,
6✔
55
                                  const Property::MitochondriaPointLevel& from,
56
                                  int offset = 0) {
57
    _appendVector(to._sectionIds, from._sectionIds, offset);
6✔
58
    _appendVector(to._relativePathLengths, from._relativePathLengths, offset);
6✔
59
    _appendVector(to._diameters, from._diameters, offset);
6✔
60
}
6✔
61

62
const std::vector<Mitochondria::MitoSectionP>& Mitochondria::children(
6✔
63
    const MitoSectionP& section_) const {
64
    const auto it = children_.find(section_->id());
6✔
65
    if (it == children_.end()) {
6✔
66
        static std::vector<Mitochondria::MitoSectionP> empty;
4✔
67
        return empty;
4✔
68
    }
69
    return it->second;
2✔
70
}
71

72
const Mitochondria::MitoSectionP& Mitochondria::parent(const MitoSectionP& parent) const {
2✔
73
    return section(parent_.at(parent->id()));
2✔
74
}
75

76
bool Mitochondria::isRoot(const MitoSectionP& section_) const {
6✔
77
    return parent_.count(section_->id()) == 0;
6✔
78
}
79

80
const Mitochondria::MitoSectionP& Mitochondria::section(uint32_t id) const {
2✔
81
    return sections_.at(id);
2✔
82
}
83

84
void Mitochondria::_buildMitochondria(Property::Properties& properties) const {
110✔
85
    int32_t counter = 0;
110✔
86
    std::map<uint32_t, int32_t> newIds;
220✔
87

88
    for (const std::shared_ptr<MitoSection>& mitoStart : root_sections_) {
114✔
89
        std::queue<std::shared_ptr<MitoSection>> q;
8✔
90
        q.push(mitoStart);
4✔
91
        while (!q.empty()) {
10✔
92
            std::shared_ptr<MitoSection> section_ = q.front();
12✔
93
            q.pop();
6✔
94
            int32_t parentOnDisk = isRoot(section_) ? -1 : newIds[parent(section_)->id()];
6✔
95

96
            properties._mitochondriaSectionLevel._sections.push_back(
6✔
97
                {static_cast<int>(properties._mitochondriaPointLevel._diameters.size()),
6✔
98
                 parentOnDisk});
99
            _appendMitoProperties(properties._mitochondriaPointLevel, section_->_mitoPoints);
6✔
100

101
            newIds[section_->id()] = counter++;
6✔
102

103
            for (const auto& child : children(section_)) {
8✔
104
                q.push(child);
2✔
105
            }
106
        }
107
    }
108
}
110✔
109

110
const std::shared_ptr<MitoSection>& Mitochondria::mitoSection(uint32_t id) const {
×
111
    return sections_.at(id);
×
112
}
113

114
mito_depth_iterator Mitochondria::depth_begin(const MitoSectionP& section) const {
×
115
    return mito_depth_iterator(section);
×
116
}
117

118
mito_depth_iterator Mitochondria::depth_end() const {
×
119
    return mito_depth_iterator();
×
120
}
121

122
mito_breadth_iterator Mitochondria::breadth_begin(const MitoSectionP& section) const {
×
123
    return mito_breadth_iterator(section);
×
124
}
125

126
mito_breadth_iterator Mitochondria::breadth_end() const {
×
127
    return mito_breadth_iterator();
×
128
}
129

130
mito_upstream_iterator Mitochondria::upstream_begin(const MitoSectionP& section) const {
×
131
    return mito_upstream_iterator(section);
×
132
}
133

134
mito_upstream_iterator Mitochondria::upstream_end() const {
×
135
    return mito_upstream_iterator();
×
136
}
137

138
uint32_t Mitochondria::_register(const MitoSectionP& section) {
66✔
139
    if (sections_.count(section->id()) > 0) {
66✔
140
        throw SectionBuilderError("Section already exists");
×
141
    }
142
    _counter = std::max(_counter, section->id()) + 1;
66✔
143

144
    sections_[section->id()] = section;
66✔
145
    return section->id();
66✔
146
}
147

148
}  // namespace mut
149
}  // namespace morphio
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc