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

paulmthompson / WhiskerToolbox / 15865657612

25 Jun 2025 01:50AM UTC coverage: 69.485% (+0.9%) from 68.538%
15865657612

push

github

paulmthompson
add principal axis data transform

371 of 383 new or added lines in 3 files covered. (96.87%)

139 existing lines in 4 files now uncovered.

10058 of 14475 relevant lines covered (69.49%)

1210.31 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_principal_axis.hpp"
18
#include "transforms/Masks/mask_skeletonize.hpp"
19
#include "transforms/Masks/mask_to_line.hpp"
20

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

29

UNCOV
30
TransformRegistry::TransformRegistry() {
×
31

UNCOV
32
    std::cout << "Initializing Operation Registry..." << std::endl;
×
33

34
    _registerOperation(std::make_unique<MaskAreaOperation>());
×
35
    _registerOperation(std::make_unique<MaskCentroidOperation>());
×
NEW
36
    _registerOperation(std::make_unique<MaskPrincipalAxisOperation>());
×
37
    _registerOperation(std::make_unique<MaskToLineOperation>());
×
38
    _registerOperation(std::make_unique<MaskSkeletonizeOperation>());
×
39
    _registerOperation(std::make_unique<EventThresholdOperation>());
×
40
    _registerOperation(std::make_unique<IntervalThresholdOperation>());
×
41
    _registerOperation(std::make_unique<HilbertPhaseOperation>());
×
42
    _registerOperation(std::make_unique<AnalogScalingOperation>());
×
43
    _registerOperation(std::make_unique<LineAngleOperation>());
×
44
    _registerOperation(std::make_unique<LineMinPointDistOperation>());
×
45
    _registerOperation(std::make_unique<LineResampleOperation>());
×
46
    _registerOperation(std::make_unique<LineCurvatureOperation>());
×
47
    _registerOperation(std::make_unique<LineSubsegmentOperation>());
×
48
    _registerOperation(std::make_unique<LinePointExtractionOperation>());
×
UNCOV
49
    _registerOperation(std::make_unique<LineClipOperation>());
×
50
    _registerOperation(std::make_unique<GroupOperation>());
×
51

52
    _computeApplicableOperations();
×
UNCOV
53
    std::cout << "Operation Registry Initialized." << std::endl;
×
54
}
×
55

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

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

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

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

98
void TransformRegistry::_computeApplicableOperations() {
×
UNCOV
99
    std::cout << "Computing applicable operations based on registered operations..." << std::endl;
×
100
    type_index_to_op_names_.clear();// Start fresh
×
101

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

109
        // Add this operation's name to the list for its target type index
UNCOV
110
        type_index_to_op_names_[target_type_index].push_back(op_name);
×
111
    }
×
112

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