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

paulmthompson / WhiskerToolbox / 16036090729

02 Jul 2025 09:22PM UTC coverage: 72.408% (-0.06%) from 72.467%
16036090729

push

github

paulmthompson
remove obselete digitalintervalseries functions

7 of 15 new or added lines in 5 files covered. (46.67%)

74 existing lines in 8 files now uncovered.

11788 of 16280 relevant lines covered (72.41%)

1100.91 hits per line

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

70.43
/src/WhiskerToolbox/DataManager/Masks/Mask_Data.cpp
1
#include "Mask_Data.hpp"
2

3
#include "utils/map_timeseries.hpp"
4

5
#include <algorithm>
6
#include <cmath>
7
#include <iostream>
8

9
// ========== Constructors ==========
10

11
// ========== Setters ==========
12

13
bool MaskData::clearAtTime(TimeFrameIndex const time, bool notify) {
16✔
14
    if (clear_at_time(time, _data)) {
16✔
15
        if (notify) {
13✔
16
            notifyObservers();
3✔
17
        }
18
        return true;
13✔
19
    }
20
    return false;
3✔
21
}
22

UNCOV
23
bool MaskData::clearAtTime(TimeFrameIndex const time, size_t const index, bool notify) {
×
UNCOV
24
    if (clear_at_time(time, index, _data)) {
×
UNCOV
25
        if (notify) {
×
UNCOV
26
            notifyObservers();
×
27
        }
UNCOV
28
        return true;
×
29
    }
UNCOV
30
    return false;
×
31
}
32

33
void MaskData::addAtTime(TimeFrameIndex const time,
122✔
34
                             std::vector<uint32_t> const & x,
35
                             std::vector<uint32_t> const & y,
36
                             bool notify) {
37
    auto new_mask = create_mask(x, y);
122✔
38
    add_at_time(time, std::move(new_mask), _data);
122✔
39
    
40
    if (notify) {
122✔
41
        notifyObservers();
118✔
42
    }
43
}
244✔
44

45
void MaskData::addAtTime(TimeFrameIndex const time,
138✔
46
                             std::vector<Point2D<uint32_t>> mask,
47
                             bool notify) {
48
    add_at_time(time, std::move(mask), _data);
138✔
49
    
50
    if (notify) {
138✔
51
        notifyObservers();
72✔
52
    }
53
}
138✔
54
        
55
void MaskData::addAtTime(TimeFrameIndex const time,
×
56
                             std::vector<uint32_t> && x,
57
                             std::vector<uint32_t> && y,
58
                             bool notify) {
59
    // Create mask efficiently using move semantics
60
    auto new_mask = Mask2D{};
×
UNCOV
61
    new_mask.reserve(x.size());
×
62
    
63
    for (std::size_t i = 0; i < x.size(); i++) {
×
64
        //new_mask.emplace_back(x[i], y[i]);
65
        new_mask.push_back({x[i], y[i]});
×
66
    }
67

UNCOV
68
    _data[time].push_back(std::move(new_mask));
×
69
    
UNCOV
70
    if (notify) {
×
UNCOV
71
        notifyObservers();
×
72
    }
UNCOV
73
}
×
74

75
// ========== Getters ==========
76

77
std::vector<Mask2D> const & MaskData::getAtTime(TimeFrameIndex const time) const {
59✔
78
    return get_at_time(time, _data, _empty);
59✔
79
}
80

UNCOV
81
std::vector<Mask2D> const & MaskData::getAtTime(TimeFrameIndex const time, 
×
82
                                                TimeFrame const * source_timeframe,
83
                                                TimeFrame const * target_timeframe) const {
84

UNCOV
85
    return get_at_time(time, _data, _empty, source_timeframe, target_timeframe);
×
86
}
87

88
// ========== Image Size ==========
89

90
void MaskData::changeImageSize(ImageSize const & image_size) {
×
UNCOV
91
    if (_image_size.width == -1 || _image_size.height == -1) {
×
92
        std::cout << "No size set for current image. "
93
                  << " Please set a valid image size before trying to scale" << std::endl;
×
94
    }
95

UNCOV
96
    if (_image_size.width == image_size.width && _image_size.height == image_size.height) {
×
UNCOV
97
        std::cout << "Image size is the same. No need to scale" << std::endl;
×
98
        return;
×
99
    }
100

101
    float const scale_x = static_cast<float>(image_size.width) / static_cast<float>(_image_size.width);
×
102
    float const scale_y = static_cast<float>(image_size.height) / static_cast<float>(_image_size.height);
×
103

104
    for (auto & [time, masks] : _data) {
×
105
        for (auto & mask : masks) {
×
UNCOV
106
            for (auto & point : mask) {
×
UNCOV
107
                point.x = static_cast<uint32_t>(std::round(static_cast<float>(point.x) * scale_x));
×
UNCOV
108
                point.y = static_cast<uint32_t>(std::round(static_cast<float>(point.y) * scale_y));
×
109
            }
110
        }
111
    }
UNCOV
112
    _image_size = image_size;
×
113
}
114

115
// ========== Copy and Move ==========
116

117
std::size_t MaskData::copyTo(MaskData& target, TimeFrameInterval const & interval, bool notify) const {
9✔
118
    if (interval.start > interval.end) {
9✔
119
        std::cerr << "MaskData::copyTo: interval start (" << interval.start.getValue() 
1✔
120
                  << ") must be <= interval end (" << interval.end.getValue() << ")" << std::endl;
1✔
121
        return 0;
1✔
122
    }
123

124
    // Ensure target is not the same as source
125
    if (this == &target) {
8✔
126
        std::cerr << "MaskData::copyTo: Cannot copy to self" << std::endl;
1✔
127
        return 0;
1✔
128
    }
129

130
    std::size_t total_masks_copied = 0;
7✔
131

132
    // Iterate through all times in the source data within the interval
133
    for (auto const & [time, masks] : _data) {
21✔
134
        if (time >= interval.start && time <= interval.end && !masks.empty()) {
14✔
135
            for (auto const& mask : masks) {
16✔
136
                target.addAtTime(time, mask, false); // Don't notify for each operation
9✔
137
                total_masks_copied++;
9✔
138
            }
139
        }
140
    }
141

142
    // Notify observer only once at the end if requested
143
    if (notify && total_masks_copied > 0) {
7✔
144
        target.notifyObservers();
4✔
145
    }
146

147
    return total_masks_copied;
7✔
148
}
149

150
std::size_t MaskData::copyTo(MaskData& target, std::vector<TimeFrameIndex> const& times, bool notify) const {
2✔
151
    std::size_t total_masks_copied = 0;
2✔
152

153
    // Copy masks for each specified time
154
    for (TimeFrameIndex time : times) {
8✔
155
        auto it = _data.find(time);
6✔
156
        if (it != _data.end() && !it->second.empty()) {
6✔
157
            for (auto const& mask : it->second) {
10✔
158
                target.addAtTime(time, mask, false); // Don't notify for each operation
6✔
159
                total_masks_copied++;
6✔
160
            }
161
        }
162
    }
163

164
    // Notify observer only once at the end if requested
165
    if (notify && total_masks_copied > 0) {
2✔
166
        target.notifyObservers();
2✔
167
    }
168

169
    return total_masks_copied;
2✔
170
}
171

172
std::size_t MaskData::moveTo(MaskData& target, TimeFrameInterval const & interval, bool notify) {
5✔
173
    if (interval.start > interval.end) {
5✔
UNCOV
174
        std::cerr << "MaskData::moveTo: interval start (" << interval.start.getValue() 
×
UNCOV
175
                  << ") must be <= interval end (" << interval.end.getValue() << ")" << std::endl;
×
UNCOV
176
        return 0;
×
177
    }
178

179
    std::size_t total_masks_moved = 0;
5✔
180
    std::vector<TimeFrameIndex> times_to_clear;
5✔
181

182
    // First, copy all masks in the interval to target
183
    for (auto const & [time, masks] : _data) {
17✔
184
        if (time >= interval.start && time <= interval.end && !masks.empty()) {
12✔
185
            for (auto const& mask : masks) {
14✔
186
                target.addAtTime(time, mask, false); // Don't notify for each operation
8✔
187
                total_masks_moved++;
8✔
188
            }
189
            times_to_clear.push_back(time);
6✔
190
        }
191
    }
192

193
    // Then, clear all the times from source
194
    for (TimeFrameIndex time : times_to_clear) {
11✔
195
        clearAtTime(time, false); // Don't notify for each operation
6✔
196
    }
197

198
    // Notify observers only once at the end if requested
199
    if (notify && total_masks_moved > 0) {
5✔
200
        target.notifyObservers();
3✔
201
        notifyObservers();
3✔
202
    }
203

204
    return total_masks_moved;
5✔
205
}
5✔
206

207
std::size_t MaskData::moveTo(MaskData& target, std::vector<TimeFrameIndex> const& times, bool notify) {
2✔
208
    std::size_t total_masks_moved = 0;
2✔
209
    std::vector<TimeFrameIndex> times_to_clear;
2✔
210

211
    // First, copy masks for each specified time to target
212
    for (TimeFrameIndex time : times) {
8✔
213
        auto it = _data.find(time);
6✔
214
        if (it != _data.end() && !it->second.empty()) {
6✔
215
            for (auto const& mask : it->second) {
10✔
216
                target.addAtTime(time, mask, false); // Don't notify for each operation
6✔
217
                total_masks_moved++;
6✔
218
            }
219
            times_to_clear.push_back(time);
4✔
220
        }
221
    }
222

223
    // Then, clear all the times from source
224
    for (TimeFrameIndex time : times_to_clear) {
6✔
225
        clearAtTime(time, false); // Don't notify for each operation
4✔
226
    }
227

228
    // Notify observers only once at the end if requested
229
    if (notify && total_masks_moved > 0) {
2✔
230
        target.notifyObservers();
2✔
231
        notifyObservers();
2✔
232
    }
233

234
    return total_masks_moved;
2✔
235
}
2✔
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