PDA

View Full Version : How to use a curve with values other than Double?



TEAmerc
26th October 2015, 19:41
I have a server that I'm reading different signal data off of and I want to plot the data using a qwtPlotCurve as it comes in. My problem is that some of the data comes in as an unsigned type (Uint64_t, ulongong, ushort, etc) but setRawSamples only supports arrays of double, so my data gets misinterpreted and comes out as really funny numbers except for the signals that are of signed types.

I had a similar problem with displaying my data in a table, but since the data is stored as a QVariant all I had to do was make a large switch block and cast the data as I updated it, and make a custom delegate for displaying it.

However, since setRawSamples only supports signed types I can't do this and was wondering if there was another way around it so that i could have curves being plotted of both signed and unsigned types.

My code for updating the plot as it is now is below for reference:



void TableViewWindow::UpdateTrendViewDocks(uint64_t **storedData)
{
//If this ViewWindow has been closed do nothing
if (this->isHidden())
return;

QList<QDockWidget *> allDockWidgets = findChildren<QDockWidget *>();

for (QDockWidget * eachDock : allDockWidgets)
{
//Only update docks that are visible
if (!eachDock->isHidden())
{
TableDock *thisTableDock = static_cast<TableDock *>(eachDock);
// Check if the dock contains a trendview before attempting to update
if (thisTableDock->GetViewType() == TableDock::TrendView)
{
QwtPlot *theTrendView = static_cast<QwtPlot *>(thisTableDock->widget());
for (TableDock::CurvePair *curvePair : thisTableDock->curveHolder)
{
curvePair->curve->setRawSamples(xAxisCounter
, (double *)storedData[curvePair->sigNumber]
, historyCount);
double ** demoContainer= (double **)storedData;

std::cerr << std::dec << "SignNum " << curvePair->sigNumber
<< " Should = " << *((uint64_t * )&demoContainer[curvePair->sigNumber][2999])
<< " double Value = " << *((double * )&demoContainer[curvePair->sigNumber][2999])
<< std::endl;
}
theTrendView->replot();
}
}
}
}


With a sample output line from this using a signal where the only difference is whether it's interpreted as signed or unsigned being:



SignNum 0 Should = 6693 double Value = 3.30678e-320


Note that storedData is of type uint64_t **
Also note the letsPretend variable and cerr print statement was for proof of concept and isn't actually going to be in the final run as it does nothing but show the error I'm getting

Uwe
27th October 2015, 07:31
If you don't want to convert and copy the samples to a 2nd buffer you can write a data bridge deriving from QwtSeriesData<QPointF> using your original samples. If the values in xAxisCounter are somehow related to the sample index you could avoid to have this array too.

But of course you can't simply cast a pointer for an uint64_t * to double * and expect to happen something useful.

Uwe

TEAmerc
27th October 2015, 16:14
After some experimentation I got a data bridge derived from QwtSeriesData<QPointF> like you suggested working on the plot similarly to my delegate class for the table side.

Also the xAxisCounter was literally just an array of incrementing values for a counter along the x-Axis so this method also did let me get rid of that too which was nice.

Thanks!