ngscopeclient 0.1-dev+51fbda87c
EyeMask.h
Go to the documentation of this file.
1/***********************************************************************************************************************
2* *
3* libscopehal *
4* *
5* Copyright (c) 2012-2024 Andrew D. Zonenberg and contributors *
6* All rights reserved. *
7* *
8* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the *
9* following conditions are met: *
10* *
11* * Redistributions of source code must retain the above copyright notice, this list of conditions, and the *
12* following disclaimer. *
13* *
14* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the *
15* following disclaimer in the documentation and/or other materials provided with the distribution. *
16* *
17* * Neither the name of the author nor the names of any contributors may be used to endorse or promote products *
18* derived from this software without specific prior written permission. *
19* *
20* THIS SOFTWARE IS PROVIDED BY THE AUTHORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
21* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL *
22* THE AUTHORS BE HELD LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES *
23* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR *
24* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT *
25* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE *
26* POSSIBILITY OF SUCH DAMAGE. *
27* *
28***********************************************************************************************************************/
29
37#ifndef EyeMask_h
38#define EyeMask_h
39
40#include "../canvas_ity/src/canvas_ity.hpp"
41
42class EyeDecoder2;
43class EyeWaveform;
44
50{
51public:
52
55 : m_time(0)
56 , m_voltage(0)
57 {}
58
65 EyeMaskPoint(float t, float v)
66 : m_time(t)
67 , m_voltage(v)
68 {}
69
75 float m_time;
76
78 float m_voltage;
79};
80
86{
87public:
88
90 std::vector<EyeMaskPoint> m_points;
91};
92
98{
99
100public:
101 EyeMask();
102 virtual ~EyeMask();
103
104 bool Load(std::string path);
105 bool Load(const YAML::Node& node);
106
108 std::string GetFileName() const
109 { return m_fname; }
110
112 std::string GetMaskName() const
113 { return m_maskname; }
114
120 float GetAllowedHitRate() const
121 { return m_hitrate; }
122
124 EyeWaveform* waveform,
125 float xscale,
126 float xoff,
127 float yscale,
128 float yoff,
129 float height) const;
130
131 float CalculateHitRate(
132 EyeWaveform* cap,
133 size_t width,
134 size_t height,
135 float fullscalerange,
136 float xscale,
137 float xoff);
138
140 bool empty() const
141 { return m_polygons.empty(); }
142
145 { return m_timebaseIsRelative; }
146
148 const std::vector<EyeMaskPolygon>& GetPolygons() const
149 { return m_polygons; }
150
152 size_t GetWidth()
153 { return m_width; }
154
156 size_t GetHeight()
157 { return m_height; }
158
159 //Helpers for unit testing
160public:
161
167 void GetPixels(std::vector<uint8_t>& pixels)
168 {
169 pixels.resize(m_width * m_height * 4);
170 m_canvas->get_image_data(pixels.data(), m_width, m_height, m_width*4, 0,0);
171 }
172
173protected:
174
176 std::string m_fname;
177
179 std::vector<EyeMaskPolygon> m_polygons;
180
183
186
188 std::string m_maskname;
189
191 std::unique_ptr< canvas_ity::canvas > m_canvas;
192
194 size_t m_width;
195
197 size_t m_height;
198};
199
200#endif
A single point within an EyeMaskPolygon.
Definition: EyeMask.h:50
EyeMaskPoint(float t, float v)
Initialize a point from a timestamp and voltage.
Definition: EyeMask.h:65
EyeMaskPoint()
Default constructor.
Definition: EyeMask.h:54
float m_time
X axis position of the point.
Definition: EyeMask.h:75
float m_voltage
Y axis position of the point.
Definition: EyeMask.h:78
A single polygon within an EyeMask.
Definition: EyeMask.h:86
std::vector< EyeMaskPoint > m_points
Set of vertices within the polygon.
Definition: EyeMask.h:90
A mask used for checking eye patterns.
Definition: EyeMask.h:98
bool empty() const
Return true if there are no polygons in the mask.
Definition: EyeMask.h:140
size_t GetHeight()
Get the rendered height of the mask.
Definition: EyeMask.h:156
size_t m_width
Current width.
Definition: EyeMask.h:194
void RenderForAnalysis(EyeWaveform *waveform, float xscale, float xoff, float yscale, float yoff, float height) const
Renders the mask to an offscreen buffer we can use for hit testing.
Definition: EyeMask.cpp:186
void GetPixels(std::vector< uint8_t > &pixels)
Get the raw image data as RGBA32.
Definition: EyeMask.h:167
size_t m_height
Current height.
Definition: EyeMask.h:197
const std::vector< EyeMaskPolygon > & GetPolygons() const
Return the set of polygons in the mask.
Definition: EyeMask.h:148
std::string GetMaskName() const
Get the display name of the eye pattern mask.
Definition: EyeMask.h:112
std::string m_maskname
Human readable name of the mask (e.g. "XFI")
Definition: EyeMask.h:188
float GetAllowedHitRate() const
Get the allowed mask hit rate.
Definition: EyeMask.h:120
EyeMask()
Initialize an empty mask.
Definition: EyeMask.cpp:55
std::vector< EyeMaskPolygon > m_polygons
Set of polygons in the mask.
Definition: EyeMask.h:179
bool IsTimebaseRelative()
Returns true if the timebase is in relative units (UI) and false if absolute (time)
Definition: EyeMask.h:144
std::string m_fname
Filename of the mask.
Definition: EyeMask.h:176
bool m_timebaseIsRelative
true = time measured in UIs || false = time measured in ps
Definition: EyeMask.h:185
std::string GetFileName() const
Get the filename of the mask.
Definition: EyeMask.h:108
float CalculateHitRate(EyeWaveform *cap, size_t width, size_t height, float fullscalerange, float xscale, float xoff)
Checks a raw eye pattern dataset against the mask.
Definition: EyeMask.cpp:226
float m_hitrate
Most recent hit rate.
Definition: EyeMask.h:182
size_t GetWidth()
Get the rendered width of the mask.
Definition: EyeMask.h:152
std::unique_ptr< canvas_ity::canvas > m_canvas
Canvas for rasterizing the mask.
Definition: EyeMask.h:191
An eye-pattern waveform.
Definition: EyeWaveform.h:58
Base class for all electronic load drivers.
Definition: Load.h:45