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

paulmthompson / WhiskerToolbox / 15885645409

25 Jun 2025 07:37PM UTC coverage: 71.644% (+2.2%) from 69.485%
15885645409

push

github

paulmthompson
add median filter for masks

250 of 260 new or added lines in 3 files covered. (96.15%)

49 existing lines in 2 files now uncovered.

11170 of 15591 relevant lines covered (71.64%)

1148.54 hits per line

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

0.0
/src/WhiskerToolbox/DataManager/transforms/TransformRegistry.cpp
1
#include "TransformRegistry.hpp"
2

3
#include "transforms/AnalogTimeSeries/analog_event_threshold.hpp"
4
#include "transforms/AnalogTimeSeries/analog_hilbert_phase.hpp"
5
#include "transforms/AnalogTimeSeries/analog_interval_threshold.hpp"
6
#include "transforms/AnalogTimeSeries/analog_scaling.hpp"
7
#include "transforms/DigitalIntervalSeries/digital_interval_group.hpp"
8
#include "transforms/Lines/line_angle.hpp"
9
#include "transforms/Lines/line_clip.hpp"
10
#include "transforms/Lines/line_curvature.hpp"
11
#include "transforms/Lines/line_min_point_dist.hpp"
12
#include "transforms/Lines/line_point_extraction.hpp"
13
#include "transforms/Lines/line_resample.hpp"
14
#include "transforms/Lines/line_subsegment.hpp"
15
#include "transforms/Masks/mask_area.hpp"
16
#include "transforms/Masks/mask_centroid.hpp"
17
#include "transforms/Masks/mask_connected_component.hpp"
18
#include "transforms/Masks/mask_hole_filling.hpp"
19
#include "transforms/Masks/mask_median_filter.hpp"
20
#include "transforms/Masks/mask_principal_axis.hpp"
21
#include "transforms/Masks/mask_skeletonize.hpp"
22
#include "transforms/Masks/mask_to_line.hpp"
23

24
#include <iostream>// For init messages
25
#include <map>
26
#include <memory>// unique_ptr
27
#include <string>
28
#include <typeindex>
29
#include <variant>// Needed for the public interface
30
#include <vector>
31

32

33
TransformRegistry::TransformRegistry() {
×
34

35
    std::cout << "Initializing Operation Registry..." << std::endl;
×
36

37
    _registerOperation(std::make_unique<MaskAreaOperation>());
×
38
    _registerOperation(std::make_unique<MaskCentroidOperation>());
×
39
    _registerOperation(std::make_unique<MaskConnectedComponentOperation>());
×
40
    _registerOperation(std::make_unique<MaskHoleFillingOperation>());
×
NEW
41
    _registerOperation(std::make_unique<MaskMedianFilterOperation>());
×
42
    _registerOperation(std::make_unique<MaskPrincipalAxisOperation>());
×
43
    _registerOperation(std::make_unique<MaskToLineOperation>());
×
44
    _registerOperation(std::make_unique<MaskSkeletonizeOperation>());
×
45
    _registerOperation(std::make_unique<EventThresholdOperation>());
×
46
    _registerOperation(std::make_unique<IntervalThresholdOperation>());
×
47
    _registerOperation(std::make_unique<HilbertPhaseOperation>());
×
48
    _registerOperation(std::make_unique<AnalogScalingOperation>());
×
49
    _registerOperation(std::make_unique<LineAngleOperation>());
×
50
    _registerOperation(std::make_unique<LineMinPointDistOperation>());
×
51
    _registerOperation(std::make_unique<LineResampleOperation>());
×
52
    _registerOperation(std::make_unique<LineCurvatureOperation>());
×
UNCOV
53
    _registerOperation(std::make_unique<LineSubsegmentOperation>());
×
54
    _registerOperation(std::make_unique<LinePointExtractionOperation>());
×
55
    _registerOperation(std::make_unique<LineClipOperation>());
×
56
    _registerOperation(std::make_unique<GroupOperation>());
×
57

58
    _computeApplicableOperations();
×
UNCOV
59
    std::cout << "Operation Registry Initialized." << std::endl;
×
UNCOV
60
}
×
61

UNCOV
62
std::vector<std::string> TransformRegistry::getOperationNamesForVariant(DataTypeVariant const & dataVariant) const {
×
63
    // Get the type_index of the type currently stored in the variant.
64
    // Note: std::variant::type() returns the type_index of the *alternative*,
65
    // which in our case IS the std::shared_ptr<T>. This matches what
66
    // getTargetInputTypeIndex() should return.
67
    auto current_type_index = std::visit([](auto & v) -> std::type_index { return typeid(v); }, dataVariant);
×
68

69
    // Look up the type index in the pre-computed map
UNCOV
70
    auto it = type_index_to_op_names_.find(current_type_index);
×
UNCOV
71
    if (it != type_index_to_op_names_.end()) {
×
72
        return it->second;// Return the pre-computed list of names
×
73
    } else {
74
        // No registered operation targets this specific type_index.
75
        // This is normal if a data type has no operations defined for it.
76
        return {};// Return empty vector
×
77
    }
78
}
79

UNCOV
80
TransformOperation * TransformRegistry::findOperationByName(std::string const & operation_name) const {
×
UNCOV
81
    auto it = name_to_operation_.find(operation_name);
×
82
    if (it != name_to_operation_.end()) {
×
UNCOV
83
        return it->second;
×
84
    } else {
85
        // std::cerr << "Warning: Requested operation name not found: '" << operation_name << "'" << std::endl;
86
        return nullptr;
×
87
    }
88
}
89

90
void TransformRegistry::_registerOperation(std::unique_ptr<TransformOperation> op) {
×
91
    if (!op) return;
×
UNCOV
92
    std::string op_name = op->getName();
×
UNCOV
93
    if (name_to_operation_.count(op_name)) {
×
94
        std::cerr << "Warning: Operation with name '" << op_name << "' already registered." << std::endl;
×
95
        return;
×
96
    }
97
    std::cout << "Registering operation: " << op_name
98
              << " (Targets type index: " << op->getTargetInputTypeIndex().name() << ")"// Debug info
×
UNCOV
99
              << std::endl;
×
100
    name_to_operation_[op_name] = op.get();
×
101
    all_operations_.push_back(std::move(op));
×
102
}
×
103

104
void TransformRegistry::_computeApplicableOperations() {
×
105
    std::cout << "Computing applicable operations based on registered operations..." << std::endl;
×
UNCOV
106
    type_index_to_op_names_.clear();// Start fresh
×
107

UNCOV
108
    for (auto const & op_ptr: all_operations_) {
×
109
        if (!op_ptr) continue;
×
110
        // Get the type index this operation says it targets
UNCOV
111
        std::type_index target_type_index = op_ptr->getTargetInputTypeIndex();
×
112
        // Get the user-facing name of the operation
113
        std::string op_name = op_ptr->getName();
×
114

115
        // Add this operation's name to the list for its target type index
UNCOV
116
        type_index_to_op_names_[target_type_index].push_back(op_name);
×
UNCOV
117
    }
×
118

119
    std::cout << "Finished computing applicable operations." << std::endl;
×
120
// Debug print (optional): shows mangled names for type_index keys internally
121
#ifndef NDEBUG// Example: Only print in debug builds
122
    for (auto const & pair: type_index_to_op_names_) {
×
UNCOV
123
        std::cout << "  TypeIndex Hash(" << pair.first.hash_code()
×
UNCOV
124
                  << ", Name=" << pair.first.name() << ") supports: ";
×
125
        for (auto const & name: pair.second) std::cout << "'" << name << "' ";
×
UNCOV
126
        std::cout << std::endl;
×
127
    }
128
#endif
UNCOV
129
}
×
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