FastLED 3.10.6
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#include "fl/stl/vector.h"
9/* Screenmap maps strip indexes to x,y coordinates. This is used for FastLED Web
10 * to map the 1D strip to a 2D screen. Note that the strip can have arbitrary
11 * size. this was first motivated by the effort to port theChromancer project to
12 * FastLED for the browser.
13 */
14
15namespace fl {
16
17// Forward declarations - full definitions only needed in .cpp
18class string;
19class json;
20template<typename Signature> class function;
21
22// Forward declare geometry types
23template<typename T> struct vec2;
24using vec2f = vec2<float>;
25
26// Forward declare XYMap for optional source storage
27class XYMap;
28
29// Forward declare LUT types and smart pointers
30template<typename T> class LUT;
32template<typename T> class shared_ptr; // IWYU pragma: keep
35
36// ScreenMap screen map maps strip indexes to x,y coordinates for a ui
37// canvas in float format.
38// This class is cheap to copy as it uses smart pointers for shared data.
39class ScreenMap {
40 public:
41 struct Shape {
44 float thickness = 0.0f;
45 };
46 static ScreenMap Circle(int numLeds, float cm_between_leds = 1.5f,
47 float cm_led_diameter = 0.5f,
48 float completion = 1.0f) FL_NO_EXCEPT;
49
50 static ScreenMap DefaultStrip(int numLeds, float cm_between_leds = 1.5f,
51 float cm_led_diameter = 0.2f,
52 float completion = .9f) FL_NO_EXCEPT;
53
54 // Constructors and destructor - implemented in .cpp for proper smart_ptr handling
57
58 // is_reverse is false by default for linear layout
59 ScreenMap(u32 length, float mDiameter = -1.0f) FL_NO_EXCEPT;
60
61 ScreenMap(const vec2f *lut, u32 length, float diameter = -1.0) FL_NO_EXCEPT;
62
63 template <u32 N>
64 ScreenMap(const vec2f (&lut)[N], float diameter = -1.0) FL_NO_EXCEPT
65 : ScreenMap(lut, N, diameter) {}
66
67 // Constructor with functor to fill in values
68 ScreenMap(int count, float diameter, fl::function<void(int, vec2f& pt_out)> func) FL_NO_EXCEPT;
69
70 ScreenMap(const ScreenMap &other) FL_NO_EXCEPT;
72
73 const vec2f &operator[](u32 x) const FL_NO_EXCEPT;
74
75 void set(u16 index, const vec2f &p) FL_NO_EXCEPT;
76
77 void addOffset(const vec2f &p) FL_NO_EXCEPT;
80
82
83 // TODO: change this name to setDiameterLed. Default should be .5f
84 // for 5 mm ws lense.
85 void setDiameter(float diameter) FL_NO_EXCEPT;
86
87 // define the assignment operator
90
91 vec2f mapToIndex(u32 x) const FL_NO_EXCEPT;
92
93 u32 getLength() const FL_NO_EXCEPT;
94 // The diameter each point represents.
95 float getDiameter() const FL_NO_EXCEPT;
96
97 // Get the bounding box of all points in the screen map
99
100 void setShape(u32 index, Shape::Type type, const vec2f *vertices, u32 count,
101 float thickness = 0.0f) FL_NO_EXCEPT;
102 bool hasShapes() const FL_NO_EXCEPT;
103 u32 getShapeCount() const FL_NO_EXCEPT;
104 const Shape &getShape(u32 index) const FL_NO_EXCEPT;
105
106 static bool ParseJson(const char *jsonStrScreenMap,
107 fl::flat_map<string, ScreenMap> *segmentMaps,
108 string *err = nullptr) FL_NO_EXCEPT;
109
110 static bool ParseJson(const char *jsonStrScreenMap,
111 const char *screenMapName, ScreenMap *screenmap,
112 string *err = nullptr) FL_NO_EXCEPT;
113
114 static void toJsonStr(const fl::flat_map<string, ScreenMap> &,
115 string *jsonBuffer) FL_NO_EXCEPT;
116 static void toJson(const fl::flat_map<string, ScreenMap> &, fl::json *doc) FL_NO_EXCEPT;
117
121
125
128 const XYMap* getXYMap() const FL_NO_EXCEPT;
129
132 bool hasSourceXYMap() const FL_NO_EXCEPT;
133
134 private:
135 static const vec2f &empty() FL_NO_EXCEPT;
136 u32 length = 0;
137 // -1 is the sentinel for "unset", and is not serialized: a negative
138 // diameter is not a size, and the parser reads an absent key back as -1.
139 // The constructors and `setDiameter` fold every non-positive value to
140 // it, so this holds either a real size or the sentinel and never a
141 // third thing a round trip would have to change.
142 float mDiameter = -1.0f;
144 XYMapPtr mSourceXYMap; // Optional: source XYMap for encoding pipeline
146};
147
148} // namespace fl
XYMap xymap
fl::ScreenMap screenmap
Definition lut.h:35
void addOffset(const vec2f &p) FL_NO_EXCEPT
float mDiameter
Definition screenmap.h:142
static void toJsonStr(const fl::flat_map< string, ScreenMap > &, string *jsonBuffer) FL_NO_EXCEPT
static ScreenMap DefaultStrip(int numLeds, float cm_between_leds=1.5f, float cm_led_diameter=0.2f, float completion=.9f) FL_NO_EXCEPT
static ScreenMap Circle(int numLeds, float cm_between_leds=1.5f, float cm_led_diameter=0.5f, float completion=1.0f) FL_NO_EXCEPT
bool hasShapes() const FL_NO_EXCEPT
void setSourceXYMap(const fl::shared_ptr< XYMap > &xymap) FL_NO_EXCEPT
Set the source XYMap (used for pixel transformation during encoding)
const XYMap * getXYMap() const FL_NO_EXCEPT
Get the source XYMap as a raw const pointer.
ScreenMap & addOffsetY(float y) FL_NO_EXCEPT
ScreenMap & addOffsetX(float x) FL_NO_EXCEPT
fl::vector< Shape > mShapes
Definition screenmap.h:145
ScreenMap() FL_NO_EXCEPT
const vec2f & operator[](u32 x) const FL_NO_EXCEPT
void setShape(u32 index, Shape::Type type, const vec2f *vertices, u32 count, float thickness=0.0f) FL_NO_EXCEPT
static bool ParseJson(const char *jsonStrScreenMap, fl::flat_map< string, ScreenMap > *segmentMaps, string *err=nullptr) FL_NO_EXCEPT
ScreenMap & operator=(const ScreenMap &other) FL_NO_EXCEPT
float getDiameter() const FL_NO_EXCEPT
LUTXYFLOATPtr mLookUpTable
Definition screenmap.h:143
vec2f mapToIndex(u32 x) const FL_NO_EXCEPT
static const vec2f & empty() FL_NO_EXCEPT
u32 getShapeCount() const FL_NO_EXCEPT
void setDiameter(float diameter) FL_NO_EXCEPT
bool hasSourceXYMap() const FL_NO_EXCEPT
Check if source XYMap is available.
void set(u16 index, const vec2f &p) FL_NO_EXCEPT
u32 getLength() const FL_NO_EXCEPT
XYMapPtr mSourceXYMap
Definition screenmap.h:144
vec2f getBounds() const FL_NO_EXCEPT
static void toJson(const fl::flat_map< string, ScreenMap > &, fl::json *doc) FL_NO_EXCEPT
const XYMapPtr & getSourceXYMapPtr() const FL_NO_EXCEPT
Get the source XYMap shared pointer if available.
fl::XYPathPtr getShape(int which)
Definition Downscale.h:54
shared_ptr< LUTXYFLOAT > LUTXYFLOATPtr
Definition screenmap.h:33
vec2< float > vec2f
Definition geometry.h:333
shared_ptr< XYMap > XYMapPtr
Definition screenmap.h:34
LUT< vec2f > LUTXYFLOAT
Definition lut.h:26
InputGamut g FL_NO_EXCEPT
Definition rgbw.h:121
Base definition for an LED controller.
Definition crgb.hpp:179
fl::vector< vec2f > vertices
Definition screenmap.h:43