SDRAngel  4.11.5
Developer docs for <a href="https://github.com/f4exb/sdrangel">SDRangel<\a>, an Open Source Qt5 / OpenGL 3.0+ SDR and signal analyzer frontend to various hardware.
scopevisxy.cpp
Go to the documentation of this file.
1 // Copyright (C) 2018 F4EXB //
3 // written by Edouard Griffiths //
4 // //
5 // This program is free software; you can redistribute it and/or modify //
6 // it under the terms of the GNU General Public License as published by //
7 // the Free Software Foundation as version 3 of the License, or //
8 // (at your option) any later version. //
9 // //
10 // This program is distributed in the hope that it will be useful, //
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of //
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
13 // GNU General Public License V3 for more details. //
14 // //
15 // You should have received a copy of the GNU General Public License //
16 // along with this program. If not, see <http://www.gnu.org/licenses/>. //
18 
19 #include <chrono>
20 #include <thread>
21 
22 #include "scopevisxy.h"
23 #include "gui/tvscreen.h"
24 
26  m_tvScreen(tvScreen),
27  m_scale(1.0),
28  m_cols(0),
29  m_rows(0),
30  m_pixelsPerFrame(480),
31  m_pixelCount(0),
32  m_alphaTrace(128),
33  m_alphaReset(128),
34  m_plotRGB(qRgb(0, 255, 0)),
35  m_gridRGB(qRgb(255, 255 ,255))
36 {
37  setObjectName("ScopeVisXY");
40 }
41 
43 {
44 }
45 
46 void ScopeVisXY::setPixelsPerFrame(int pixelsPerFrame)
47 {
48  m_pixelsPerFrame = pixelsPerFrame;
49  m_pixelCount = 0;
51 }
52 
53 void ScopeVisXY::feed(const SampleVector::const_iterator& cbegin, const SampleVector::const_iterator& end, bool positiveOnly)
54 {
55  (void) positiveOnly;
56  SampleVector::const_iterator begin(cbegin);
57 
58  while (begin < end)
59  {
60  float x = m_scale * (begin->m_real/SDR_RX_SCALEF);
61  float y = m_scale * (begin->m_imag/SDR_RX_SCALEF);
62 
63  int row = m_rows * ((1.0 - y) / 2.0);
64  int col = m_cols * ((1.0 + x) / 2.0);
65 
66  row = row < 0 ? 0 : row >= m_rows ? m_rows-1 : row;
67  col = col < 0 ? 0 : col >= m_cols ? m_cols-1 : col;
68 
69  m_tvScreen->selectRow(row);
70  m_tvScreen->setDataColor(col, qRed(m_plotRGB), qGreen(m_plotRGB), qBlue(m_plotRGB), m_alphaTrace);
71 
72  ++begin;
73  m_pixelCount++;
74 
76  {
77  int rows, cols;
78  m_tvScreen->getSize(rows, cols);
79 
80  if ((rows != m_rows) || (cols != m_cols))
81  {
82  calculateGraticule(rows, cols);
83  m_rows = rows;
84  m_cols = cols;
85  }
86 
88  m_tvScreen->update();
89  std::this_thread::sleep_for(std::chrono::microseconds(5000));
91  drawGraticule();
92  m_pixelCount = 0;
93  }
94  }
95 }
96 
98 {
99 }
100 
102 {
103 }
104 
105 bool ScopeVisXY::handleMessage(const Message& message)
106 {
107  (void) message;
108  return false;
109 }
110 
111 void ScopeVisXY::addGraticulePoint(const std::complex<float>& z) {
112  m_graticule.push_back(z);
113 }
114 
116  m_graticule.clear();
117 }
118 
119 void ScopeVisXY::calculateGraticule(int rows, int cols)
120 {
121  m_graticuleRows.clear();
122  m_graticuleCols.clear();
123 
124  std::vector<std::complex<float> >::const_iterator grIt = m_graticule.begin();
125 
126  for (; grIt != m_graticule.end(); ++grIt)
127  {
128  int y = rows * ((1.0 - grIt->imag()) / 2.0);
129  int x = cols * ((1.0 + grIt->real()) / 2.0);
130 
131  for (int d = -4; d <= 4; ++d)
132  {
133  m_graticuleRows.push_back(y+d);
134  m_graticuleCols.push_back(x);
135  m_graticuleRows.push_back(y);
136  m_graticuleCols.push_back(x+d);
137  }
138  }
139 }
140 
142 {
143  std::vector<int>::const_iterator rowIt = m_graticuleRows.begin();
144  std::vector<int>::const_iterator colIt = m_graticuleCols.begin();
145 
146  for(; (rowIt != m_graticuleRows.end()) && (colIt != m_graticuleCols.end()); ++rowIt, ++colIt)
147  {
148  m_tvScreen->selectRow(*rowIt);
149  m_tvScreen->setDataColor(*colIt, qRed(m_gridRGB), qGreen(m_gridRGB), qBlue(m_gridRGB));
150  }
151 }
152 
void drawGraticule()
Definition: scopevisxy.cpp:141
bool setDataColor(int intCol, int intRed, int intGreen, int intBlue)
Definition: tvscreen.cpp:224
void resetImage()
Definition: tvscreen.cpp:76
virtual bool handleMessage(const Message &message)
Processing of a message. Returns true if message has actually been processed.
Definition: scopevisxy.cpp:105
TVScreen * m_tvScreen
Definition: scopevisxy.h:57
std::vector< int > m_graticuleCols
Definition: scopevisxy.h:69
void setAlphaBlend(bool blnAlphaBlend)
Definition: tvscreen.h:59
virtual void start()
Definition: scopevisxy.cpp:97
QRgb m_gridRGB
Definition: scopevisxy.h:66
void renderImage(unsigned char *objData)
Definition: tvscreen.cpp:70
int m_pixelCount
Definition: scopevisxy.h:62
void clearGraticule()
Definition: scopevisxy.cpp:115
std::vector< std::complex< float > > m_graticule
Definition: scopevisxy.h:67
void getSize(int &intCols, int &intRows) const
Definition: tvscreen.cpp:95
float m_scale
Definition: scopevisxy.h:58
ScopeVisXY(TVScreen *tvScreen)
Definition: scopevisxy.cpp:25
int m_pixelsPerFrame
Definition: scopevisxy.h:61
#define SDR_RX_SCALEF
Definition: dsptypes.h:33
QRgb m_plotRGB
Definition: scopevisxy.h:65
int m_alphaReset
alpha channel of screen blanking (blackening) is 255 minus decay value [0:255]
Definition: scopevisxy.h:64
virtual void stop()
Definition: scopevisxy.cpp:101
int m_cols
Definition: scopevisxy.h:59
void setPixelsPerFrame(int pixelsPerFrame)
Definition: scopevisxy.cpp:46
std::vector< int > m_graticuleRows
Definition: scopevisxy.h:68
int m_alphaTrace
this is the stroke value [0:255]
Definition: scopevisxy.h:63
int m_rows
Definition: scopevisxy.h:60
void setAlphaReset()
Definition: tvscreen.h:60
virtual void feed(const SampleVector::const_iterator &begin, const SampleVector::const_iterator &end, bool positiveOnly)
Definition: scopevisxy.cpp:53
virtual ~ScopeVisXY()
Definition: scopevisxy.cpp:42
void addGraticulePoint(const std::complex< float > &z)
Definition: scopevisxy.cpp:111
void calculateGraticule(int rows, int cols)
Definition: scopevisxy.cpp:119
bool selectRow(int intLine)
Definition: tvscreen.cpp:212