src/WhiskerToolbox/Whisker_Widget/WhiskerWidgetState.hpp
src/WhiskerToolbox/Whisker_Widget/WhiskerWidgetState.hpp
State class for Whisker_Widget. More…
Classes
| Name | |
|---|---|
| struct | WhiskerWidgetStateData Serializable data structure for WhiskerWidgetState. |
| class | WhiskerWidgetState State class for Whisker_Widget. |
Types
| Name | |
|---|---|
| enum class | FaceOrientation { Top = 0, Bottom = 1, Left = 2, Right = 3} Enumeration for face orientation. |
Detailed Description
State class for Whisker_Widget.
See:
- EditorState for base class documentation
- Whisker_Widget for the widget implementation
WhiskerWidgetState manages the serializable state for the Whisker_Widget, enabling workspace save/restore and integration with the EditorRegistry system.
State tracked:
- Face orientation (top, bottom, left, right)
- Number of whiskers to track
- Length threshold
- Clip length
- Linking tolerance
- Whisker pad key and position
- Mask mode settings
Types Documentation
enum FaceOrientation
| Enumerator | Value | Description |
|---|---|---|
| Top | 0 | |
| Bottom | 1 | |
| Left | 2 | |
| Right | 3 |
Enumeration for face orientation.
Source code
#ifndef WHISKER_WIDGET_STATE_HPP
#define WHISKER_WIDGET_STATE_HPP
#include "EditorState/EditorState.hpp"
#include "EditorState/StrongTypes.hpp" // Must be before any TimePosition usage in signals
#include "TimeFrame/TimeFrame.hpp"
#include <rfl.hpp>
#include <rfl/json.hpp>
#include <string>
enum class FaceOrientation {
Top = 0,
Bottom = 1,
Left = 2,
Right = 3
};
struct WhiskerWidgetStateData {
std::string instance_id;
std::string display_name = "Whisker Tracking";
// Tracking parameters
int face_orientation = 0;
int num_whiskers_to_track = 0;
double length_threshold = 30.0;
int clip_length = 0;
float linking_tolerance = 20.0f;
// Whisker pad settings
std::string whisker_pad_key;
float whisker_pad_x = 0.0f;
float whisker_pad_y = 0.0f;
// Mask mode settings
bool use_mask_mode = false;
std::string selected_mask_key;
// Current whisker selection
int current_whisker = 0;
// Auto DL mode
bool auto_dl = false;
};
class WhiskerWidgetState : public EditorState {
Q_OBJECT
public:
explicit WhiskerWidgetState(QObject * parent = nullptr);
~WhiskerWidgetState() override = default;
// === Type Identification ===
[[nodiscard]] QString getTypeName() const override { return QStringLiteral("WhiskerWidget"); }
[[nodiscard]] QString getDisplayName() const override;
void setDisplayName(QString const & name) override;
// === Transient Runtime State ===
// (NOT serialized - just runtime)
TimePosition current_position;
// === Serialization ===
[[nodiscard]] std::string toJson() const override;
bool fromJson(std::string const & json) override;
// === State Properties - Getters ===
[[nodiscard]] FaceOrientation faceOrientation() const;
[[nodiscard]] int numWhiskersToTrack() const;
[[nodiscard]] double lengthThreshold() const;
[[nodiscard]] int clipLength() const;
[[nodiscard]] float linkingTolerance() const;
[[nodiscard]] std::string const & whiskerPadKey() const;
[[nodiscard]] float whiskerPadX() const;
[[nodiscard]] float whiskerPadY() const;
[[nodiscard]] bool useMaskMode() const;
[[nodiscard]] std::string const & selectedMaskKey() const;
[[nodiscard]] int currentWhisker() const;
[[nodiscard]] bool autoDL() const;
// === State Properties - Setters ===
void setFaceOrientation(FaceOrientation orientation);
void setNumWhiskersToTrack(int num);
void setLengthThreshold(double threshold);
void setClipLength(int length);
void setLinkingTolerance(float tolerance);
void setWhiskerPadKey(std::string const & key);
void setWhiskerPadPosition(float x, float y);
void setUseMaskMode(bool use_mask);
void setSelectedMaskKey(std::string const & key);
void setCurrentWhisker(int whisker);
void setAutoDL(bool auto_dl);
signals:
void faceOrientationChanged(FaceOrientation orientation);
void numWhiskersToTrackChanged(int num);
void lengthThresholdChanged(double threshold);
void clipLengthChanged(int length);
void linkingToleranceChanged(float tolerance);
void whiskerPadKeyChanged(std::string const & key);
void whiskerPadPositionChanged(float x, float y);
void useMaskModeChanged(bool use_mask);
void selectedMaskKeyChanged(std::string const & key);
void currentWhiskerChanged(int whisker);
void autoDLChanged(bool auto_dl);
private:
WhiskerWidgetStateData _data;
};
#endif // WHISKER_WIDGET_STATE_HPPUpdated on 2026-11-13 at 20:25:46 +0000