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

paulmthompson / WhiskerToolbox / 15566405961

10 Jun 2025 05:39PM UTC coverage: 62.158% (+6.9%) from 55.215%
15566405961

push

github

paulmthompson
add interface for interval grouping transformation

6851 of 11022 relevant lines covered (62.16%)

605.76 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_skeletonize.hpp"
17
#include "transforms/Masks/mask_to_line.hpp"
18

19
#include <iostream>// For init messages
20
#include <map>
21
#include <memory>// unique_ptr
22
#include <string>
23
#include <typeindex>
24
#include <variant>// Needed for the public interface
25
#include <vector>
26

27

28
TransformRegistry::TransformRegistry() {
×
29

30
    std::cout << "Initializing Operation Registry..." << std::endl;
×
31

32
    _registerOperation(std::make_unique<MaskAreaOperation>());
×
33
    _registerOperation(std::make_unique<MaskToLineOperation>());
×
34
    _registerOperation(std::make_unique<MaskSkeletonizeOperation>());
×
35
    _registerOperation(std::make_unique<EventThresholdOperation>());
×
36
    _registerOperation(std::make_unique<IntervalThresholdOperation>());
×
37
    _registerOperation(std::make_unique<HilbertPhaseOperation>());
×
38
    _registerOperation(std::make_unique<AnalogScalingOperation>());
×
39
    _registerOperation(std::make_unique<LineAngleOperation>());
×
40
    _registerOperation(std::make_unique<LineMinPointDistOperation>());
×
41
    _registerOperation(std::make_unique<LineResampleOperation>());
×
42
    _registerOperation(std::make_unique<LineCurvatureOperation>());
×
43
    _registerOperation(std::make_unique<LineSubsegmentOperation>());
×
44
    _registerOperation(std::make_unique<LinePointExtractionOperation>());
×
45
    _registerOperation(std::make_unique<LineClipOperation>());
×
46
    _registerOperation(std::make_unique<GroupOperation>());
×
47

48
    _computeApplicableOperations();
×
49
    std::cout << "Operation Registry Initialized." << std::endl;
×
50
}
×
51

52
std::vector<std::string> TransformRegistry::getOperationNamesForVariant(DataTypeVariant const & dataVariant) const {
×
53
    // Get the type_index of the type currently stored in the variant.
54
    // Note: std::variant::type() returns the type_index of the *alternative*,
55
    // which in our case IS the std::shared_ptr<T>. This matches what
56
    // getTargetInputTypeIndex() should return.
57
    auto current_type_index = std::visit([](auto & v) -> std::type_index { return typeid(v); }, dataVariant);
×
58

59
    // Look up the type index in the pre-computed map
60
    auto it = type_index_to_op_names_.find(current_type_index);
×
61
    if (it != type_index_to_op_names_.end()) {
×
62
        return it->second;// Return the pre-computed list of names
×
63
    } else {
64
        // No registered operation targets this specific type_index.
65
        // This is normal if a data type has no operations defined for it.
66
        return {};// Return empty vector
×
67
    }
68
}
69

70
TransformOperation * TransformRegistry::findOperationByName(std::string const & operation_name) const {
×
71
    auto it = name_to_operation_.find(operation_name);
×
72
    if (it != name_to_operation_.end()) {
×
73
        return it->second;
×
74
    } else {
75
        // std::cerr << "Warning: Requested operation name not found: '" << operation_name << "'" << std::endl;
76
        return nullptr;
×
77
    }
78
}
79

80
void TransformRegistry::_registerOperation(std::unique_ptr<TransformOperation> op) {
×
81
    if (!op) return;
×
82
    std::string op_name = op->getName();
×
83
    if (name_to_operation_.count(op_name)) {
×
84
        std::cerr << "Warning: Operation with name '" << op_name << "' already registered." << std::endl;
×
85
        return;
×
86
    }
87
    std::cout << "Registering operation: " << op_name
88
              << " (Targets type index: " << op->getTargetInputTypeIndex().name() << ")"// Debug info
×
89
              << std::endl;
×
90
    name_to_operation_[op_name] = op.get();
×
91
    all_operations_.push_back(std::move(op));
×
92
}
×
93

94
void TransformRegistry::_computeApplicableOperations() {
×
95
    std::cout << "Computing applicable operations based on registered operations..." << std::endl;
×
96
    type_index_to_op_names_.clear();// Start fresh
×
97

98
    for (auto const & op_ptr: all_operations_) {
×
99
        if (!op_ptr) continue;
×
100
        // Get the type index this operation says it targets
101
        std::type_index target_type_index = op_ptr->getTargetInputTypeIndex();
×
102
        // Get the user-facing name of the operation
103
        std::string op_name = op_ptr->getName();
×
104

105
        // Add this operation's name to the list for its target type index
106
        type_index_to_op_names_[target_type_index].push_back(op_name);
×
107
    }
×
108

109
    std::cout << "Finished computing applicable operations." << std::endl;
×
110
// Debug print (optional): shows mangled names for type_index keys internally
111
#ifndef NDEBUG// Example: Only print in debug builds
112
    for (auto const & pair: type_index_to_op_names_) {
×
113
        std::cout << "  TypeIndex Hash(" << pair.first.hash_code()
×
114
                  << ", Name=" << pair.first.name() << ") supports: ";
×
115
        for (auto const & name: pair.second) std::cout << "'" << name << "' ";
×
116
        std::cout << std::endl;
×
117
    }
118
#endif
119
}
×
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