Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: ngscopeclient/scopehal-apps
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 2aec92137e2b
Choose a base ref
...
head repository: ngscopeclient/scopehal-apps
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: f66d6f5c4195
Choose a head ref
  • 2 commits
  • 1 file changed
  • 1 contributor

Commits on Feb 13, 2020

  1. Copy the full SHA
    7b2df76 View commit details

Commits on Feb 14, 2020

  1. Copy the full SHA
    f66d6f5 View commit details
Showing with 121 additions and 55 deletions.
  1. +121 −55 glscopeclient/WaveformArea_rendering.cpp
176 changes: 121 additions & 55 deletions glscopeclient/WaveformArea_rendering.cpp
Original file line number Diff line number Diff line change
@@ -68,84 +68,152 @@ bool WaveformArea::PrepareGeometry()
return false;

//Create the geometry
size_t waveform_size = count * 12; //3 points * 2 triangles * 2 coordinates
m_traceBuffer.resize(waveform_size);
double radius = 1;
double offset = m_channel->GetOffset();
m_xoff = (pdat->m_triggerPhase - m_group->m_timeOffset) * m_group->m_pixelsPerPicosecond;
double xscale = pdat->m_timescale * m_group->m_pixelsPerPicosecond;
bool dbscale = IsFFT();
#pragma omp parallel for num_threads(8)
for(size_t j=0; j<(count-1); j++)
{
//Actual X/Y start/end point of the data
float xleft = data.GetSampleStart(j) * xscale;
float xright = data.GetSampleStart(j+1) * xscale;

float yleft;
float yright;

//log scale
if(dbscale)
//Use old code path for FFT traces, for now
if(IsFFT())
{
size_t waveform_size = count * 12; //3 points * 2 triangles * 2 coordinates
m_traceBuffer.resize(waveform_size);
m_waveformLength = count;
#pragma omp parallel for num_threads(8)
for(size_t j=0; j<(count-1); j++)
{
//Actual X/Y start/end point of the data
float xleft = data.GetSampleStart(j) * xscale;
float xright = data.GetSampleStart(j+1) * xscale;

double db1 = 20 * log10(data[j]);
double db2 = 20 * log10(data[j+1]);

db1 = -70 - db1; //todo: dont hard code plot limit
db2 = -70 - db2;

yleft = DbToYPosition(db1);
yright = DbToYPosition(db2);
float yleft = DbToYPosition(db1);
float yright = DbToYPosition(db2);

//Find the normal vector (swap x and y components)
float dy = xright - xleft;
float dx = yright - yleft;

//Normalize
float scale = radius / sqrt(dy*dy + dx*dx);
dx = dx * scale;
dy = dy * scale;

//Calculate final coordinates
float x1 = xleft - dx;
float y1 = yleft - dy;

float x2 = xleft + dx;
float y2 = yleft + dy;

float x3 = xright + dx;
float y3 = yright + dy;

float x4 = xright - dx;
float y4 = yright - dy;

//and emit the vertexes
size_t base = j*12;
m_traceBuffer[base+0] = x2;
m_traceBuffer[base+1] = y2;

m_traceBuffer[base+2] = x1;
m_traceBuffer[base+3] = y1;

m_traceBuffer[base+4] = x3;
m_traceBuffer[base+5] = y3;

m_traceBuffer[base+6] = x1;
m_traceBuffer[base+7] = y1;

m_traceBuffer[base+8] = x3;
m_traceBuffer[base+9] = y3;

m_traceBuffer[base+10] = x4;
m_traceBuffer[base+11] = y4;
}
}

//normal linear scale
else
else
{
size_t waveform_size = count * 12; //3 points * 2 triangles * 2 coordinates
m_traceBuffer.resize(waveform_size);
m_waveformLength = count;

for(size_t j=0; j<(count-1); j++)
{
yleft = m_pixelsPerVolt * (data[j] + offset);
yright = m_pixelsPerVolt * (data[j+1] + offset);
}
float xleft = data.GetSampleStart(j) * xscale;
float xright = xleft + 1;
if(xscale > 1)
xright = xleft + xscale;

float ymid = m_pixelsPerVolt * (data[j] + offset);
float nextymid = m_pixelsPerVolt * (data[j+1] + offset);

float ybot = std::min(ymid, nextymid) - 1;
float ytop = std::max(ymid, nextymid) + 1;

//Find the normal vector (swap x and y components
float dy = xright - xleft;
float dx = yright - yleft;
float x1 = xleft;
float y1 = ybot;

//Normalize
float scale = radius / sqrt(dy*dy + dx*dx);
dx = dx * scale;
dy = dy * scale;
float x2 = xright;
float y2 = ybot;

//Calculate final coordinates
float x1 = xleft - dx;
float y1 = yleft - dy;
float x3 = xright;
float y3 = ytop;

float x2 = xleft + dx;
float y2 = yleft + dy;
float x4 = xleft;
float y4 = ytop;

float x3 = xright + dx;
float y3 = yright + dy;
/*
If we stop here, we just get ugly looking boxes when zoomed in.
float x4 = xright - dx;
float y4 = yright - dy;
At higher zooms, we need to move the corners a bit.
Find the average of our starting Y coordinates and the previous box's end,
then move both to that point.
*/
if( (xscale > 1) && (j > 0) )
{
size_t oldbase = (j-1)*12;

float oldtop = m_traceBuffer[oldbase + 9];
float oldbot = m_traceBuffer[oldbase + 1];

y4 = (oldtop + ytop) / 2;
y1 = (oldbot + ybot) / 2;

//Patch up the old points
m_traceBuffer[oldbase + 5] = y4;
m_traceBuffer[oldbase + 9] = y4;

//and emit the vertexes
size_t base = j*12;
m_traceBuffer[base+0] = x2;
m_traceBuffer[base+1] = y2;
m_traceBuffer[oldbase + 1] = y1;
}

//and emit the vertexes
size_t base = j*12;
m_traceBuffer[base+0] = x2;
m_traceBuffer[base+1] = y2;

m_traceBuffer[base+2] = x1;
m_traceBuffer[base+3] = y1;
m_traceBuffer[base+2] = x1;
m_traceBuffer[base+3] = y1;

m_traceBuffer[base+4] = x3;
m_traceBuffer[base+5] = y3;
m_traceBuffer[base+4] = x3;
m_traceBuffer[base+5] = y3;

m_traceBuffer[base+6] = x1;
m_traceBuffer[base+7] = y1;
m_traceBuffer[base+6] = x1;
m_traceBuffer[base+7] = y1;

m_traceBuffer[base+8] = x3;
m_traceBuffer[base+9] = y3;
m_traceBuffer[base+8] = x3;
m_traceBuffer[base+9] = y3;

m_traceBuffer[base+10] = x4;
m_traceBuffer[base+11] = y4;
m_traceBuffer[base+10] = x4;
m_traceBuffer[base+11] = y4;
}
}

double dt = GetTime() - start;
@@ -154,16 +222,14 @@ bool WaveformArea::PrepareGeometry()

//Download waveform data
m_traceVBOs[0]->Bind();
glBufferData(GL_ARRAY_BUFFER, 0, NULL, GL_DYNAMIC_DRAW);
glBufferData(GL_ARRAY_BUFFER, sizeof(float) * m_traceBuffer.size(), &m_traceBuffer[0], GL_DYNAMIC_DRAW);
glInvalidateBufferData(GL_ARRAY_BUFFER);
glBufferData(GL_ARRAY_BUFFER, sizeof(float) * m_traceBuffer.size(), &m_traceBuffer[0], GL_STREAM_DRAW);

//Configure vertex array settings
m_traceVAOs[0]->Bind();
m_waveformProgram.EnableVertexArray("vert");
m_waveformProgram.SetVertexAttribPointer("vert", 2, 0);

m_waveformLength = count;

dt = GetTime() - start;
m_downloadTime += dt;