FastLED 3.9.15
Loading...
Searching...
No Matches
screenmap.h
Go to the documentation of this file.
1#pragma once
2
3
4#include "fl/stl/flat_map.h" // Required: fl_map is a template alias, cannot be forward declared
5#include "fl/stl/shared_ptr.h"
6#include "fl/stl/int.h"
7#include "fl/stl/noexcept.h"
8/* Screenmap maps strip indexes to x,y coordinates. This is used for FastLED Web
9 * to map the 1D strip to a 2D screen. Note that the strip can have arbitrary
10 * size. this was first motivated by the effort to port theChromancer project to
11 * FastLED for the browser.
12 */
13
14namespace fl {
15
16// Forward declarations - full definitions only needed in .cpp
17class string;
18class json;
19template<typename Signature> class function;
20
21// Forward declare geometry types
22template<typename T> struct vec2;
23using vec2f = vec2<float>;
24
25// Forward declare XYMap for optional source storage
26class XYMap;
27
28// Forward declare LUT types and smart pointers
29template<typename T> class LUT;
31template<typename T> class shared_ptr; // IWYU pragma: keep
34
35// ScreenMap screen map maps strip indexes to x,y coordinates for a ui
36// canvas in float format.
37// This class is cheap to copy as it uses smart pointers for shared data.
38class ScreenMap {
39 public:
40 static ScreenMap Circle(int numLeds, float cm_between_leds = 1.5f,
41 float cm_led_diameter = 0.5f,
42 float completion = 1.0f) FL_NOEXCEPT;
43
44 static ScreenMap DefaultStrip(int numLeds, float cm_between_leds = 1.5f,
45 float cm_led_diameter = 0.2f,
46 float completion = .9f) FL_NOEXCEPT;
47
48 // Constructors and destructor - implemented in .cpp for proper smart_ptr handling
51
52 // is_reverse is false by default for linear layout
53 ScreenMap(u32 length, float mDiameter = -1.0f) FL_NOEXCEPT;
54
55 ScreenMap(const vec2f *lut, u32 length, float diameter = -1.0) FL_NOEXCEPT;
56
57 template <u32 N>
58 ScreenMap(const vec2f (&lut)[N], float diameter = -1.0) FL_NOEXCEPT
59 : ScreenMap(lut, N, diameter) {}
60
61 // Constructor with functor to fill in values
62 ScreenMap(int count, float diameter, fl::function<void(int, vec2f& pt_out)> func) FL_NOEXCEPT;
63
64 ScreenMap(const ScreenMap &other) FL_NOEXCEPT;
66
67 const vec2f &operator[](u32 x) const FL_NOEXCEPT;
68
69 void set(u16 index, const vec2f &p) FL_NOEXCEPT;
70
71 void addOffset(const vec2f &p) FL_NOEXCEPT;
74
76
77 // TODO: change this name to setDiameterLed. Default should be .5f
78 // for 5 mm ws lense.
79 void setDiameter(float diameter) FL_NOEXCEPT;
80
81 // define the assignment operator
84
85 vec2f mapToIndex(u32 x) const FL_NOEXCEPT;
86
87 u32 getLength() const FL_NOEXCEPT;
88 // The diameter each point represents.
89 float getDiameter() const FL_NOEXCEPT;
90
91 // Get the bounding box of all points in the screen map
93
94 static bool ParseJson(const char *jsonStrScreenMap,
95 fl::flat_map<string, ScreenMap> *segmentMaps,
96 string *err = nullptr) FL_NOEXCEPT;
97
98 static bool ParseJson(const char *jsonStrScreenMap,
99 const char *screenMapName, ScreenMap *screenmap,
100 string *err = nullptr) FL_NOEXCEPT;
101
102 static void toJsonStr(const fl::flat_map<string, ScreenMap> &,
103 string *jsonBuffer) FL_NOEXCEPT;
104 static void toJson(const fl::flat_map<string, ScreenMap> &, fl::json *doc) FL_NOEXCEPT;
105
109
113
116 const XYMap* getXYMap() const FL_NOEXCEPT;
117
120 bool hasSourceXYMap() const FL_NOEXCEPT;
121
122 private:
123 static const vec2f &empty() FL_NOEXCEPT;
124 u32 length = 0;
125 float mDiameter = -1.0f; // Only serialized if it's not > 0.0f.
127 XYMapPtr mSourceXYMap; // Optional: source XYMap for encoding pipeline
128};
129
130} // namespace fl
XYMap xymap
fl::ScreenMap screenmap
Definition lut.h:35
u32 getLength() const FL_NOEXCEPT
static void toJson(const fl::flat_map< string, ScreenMap > &, fl::json *doc) FL_NOEXCEPT
static ScreenMap DefaultStrip(int numLeds, float cm_between_leds=1.5f, float cm_led_diameter=0.2f, float completion=.9f) FL_NOEXCEPT
float mDiameter
Definition screenmap.h:125
void setSourceXYMap(const fl::shared_ptr< XYMap > &xymap) FL_NOEXCEPT
Set the source XYMap (used for pixel transformation during encoding)
static void toJsonStr(const fl::flat_map< string, ScreenMap > &, string *jsonBuffer) FL_NOEXCEPT
const XYMapPtr & getSourceXYMapPtr() const FL_NOEXCEPT
Get the source XYMap shared pointer if available.
static const vec2f & empty() FL_NOEXCEPT
ScreenMap() FL_NOEXCEPT
void setDiameter(float diameter) FL_NOEXCEPT
vec2f getBounds() const FL_NOEXCEPT
const XYMap * getXYMap() const FL_NOEXCEPT
Get the source XYMap as a raw const pointer.
LUTXYFLOATPtr mLookUpTable
Definition screenmap.h:126
static bool ParseJson(const char *jsonStrScreenMap, fl::flat_map< string, ScreenMap > *segmentMaps, string *err=nullptr) FL_NOEXCEPT
bool hasSourceXYMap() const FL_NOEXCEPT
Check if source XYMap is available.
void addOffset(const vec2f &p) FL_NOEXCEPT
ScreenMap & addOffsetY(float y) FL_NOEXCEPT
void set(u16 index, const vec2f &p) FL_NOEXCEPT
float getDiameter() const FL_NOEXCEPT
XYMapPtr mSourceXYMap
Definition screenmap.h:127
vec2f mapToIndex(u32 x) const FL_NOEXCEPT
ScreenMap & operator=(const ScreenMap &other) FL_NOEXCEPT
ScreenMap & addOffsetX(float x) FL_NOEXCEPT
static ScreenMap Circle(int numLeds, float cm_between_leds=1.5f, float cm_led_diameter=0.5f, float completion=1.0f) FL_NOEXCEPT
const vec2f & operator[](u32 x) const FL_NOEXCEPT
shared_ptr< LUTXYFLOAT > LUTXYFLOATPtr
Definition screenmap.h:32
vec2< float > vec2f
Definition geometry.h:333
shared_ptr< XYMap > XYMapPtr
Definition screenmap.h:33
LUT< vec2f > LUTXYFLOAT
Definition lut.h:26
Base definition for an LED controller.
Definition crgb.hpp:179
#define FL_NOEXCEPT