rockinfresh
20th January 2014, 15:23
Hi all,
I am a newbie in QWT. Just wish to ask how can I plot data from a vector. The code below shows what I have done so far. Basically, the data I am storing into the vector are pixel values of an image along the axis. After that, I proceed to plot them, but there is always an error. I am not sure how to exactly do them either:/ I been trying to plot for almost 2 weeks plus already. But to no avail. I am still confused over the curve as well, why is there another vector needed for the setSamples() of curve?
vector<byte> v_char; //values of pixels taken from y-axis //tried double and int as well.
//store pixel values into v_char
v_char.reserve(image.rows * image.cols);
for (int i = 0; i < image.rows; i++)
{
int segment_start = *(uchar*)image.data + i * image.step;
v_char.insert(v_char.end(), segment_start, segment_start + image.cols);
}
//plotting of v_char vector
QwtPlot *plota=new QwtPlot(); //Create plot widget
plota->setTitle( "Plot Analysis" ); //Name the plot
plota->setCanvasBackground( Qt::black ); //Set the Background colour
plota->setAxisScale( QwtPlot::yLeft, 0, 1000000 ); //Scale the y-axis
plota->setAxisScale(QwtPlot::xBottom,0,image.rows); //Scale the x-axis
plota->insertLegend(new QwtLegend()); //Insert a legend
//attach curve to plota
QwtPlotCurve *curvea = new QwtPlotCurve(); // Create a curve
// curvea->setTitle("Count"); //Name the curve
curvea->setPen( Qt::white, 2);//Set colour and thickness for drawing the curve
//Use Antialiasing to improve plot render quality
curvea->setRenderHint( QwtPlotItem::RenderAntialiased, true );
QPolygonF points;
for( int h = 0; h < v_char.size(); ++h)
{
float bin_value = v_char[h];
points << QPointF((float)h, bin_value);
}
curvea->setSamples(points); //pass points to be drawn on the curve
curvea->attach( plota ); // Attach curve to the plot
plota->resize( 600, 400 ); //Resize the plot
//plot.replot();
plota->show(); //Show plot
If anybody do know, please please do help, I already at my wits end. I can't seem to find an example or tutorial online for QWT plots. I already tried lots of things... Is there a problem with my code? Or my whole programming flow is wrong? Please help. Thanks.
I am a newbie in QWT. Just wish to ask how can I plot data from a vector. The code below shows what I have done so far. Basically, the data I am storing into the vector are pixel values of an image along the axis. After that, I proceed to plot them, but there is always an error. I am not sure how to exactly do them either:/ I been trying to plot for almost 2 weeks plus already. But to no avail. I am still confused over the curve as well, why is there another vector needed for the setSamples() of curve?
vector<byte> v_char; //values of pixels taken from y-axis //tried double and int as well.
//store pixel values into v_char
v_char.reserve(image.rows * image.cols);
for (int i = 0; i < image.rows; i++)
{
int segment_start = *(uchar*)image.data + i * image.step;
v_char.insert(v_char.end(), segment_start, segment_start + image.cols);
}
//plotting of v_char vector
QwtPlot *plota=new QwtPlot(); //Create plot widget
plota->setTitle( "Plot Analysis" ); //Name the plot
plota->setCanvasBackground( Qt::black ); //Set the Background colour
plota->setAxisScale( QwtPlot::yLeft, 0, 1000000 ); //Scale the y-axis
plota->setAxisScale(QwtPlot::xBottom,0,image.rows); //Scale the x-axis
plota->insertLegend(new QwtLegend()); //Insert a legend
//attach curve to plota
QwtPlotCurve *curvea = new QwtPlotCurve(); // Create a curve
// curvea->setTitle("Count"); //Name the curve
curvea->setPen( Qt::white, 2);//Set colour and thickness for drawing the curve
//Use Antialiasing to improve plot render quality
curvea->setRenderHint( QwtPlotItem::RenderAntialiased, true );
QPolygonF points;
for( int h = 0; h < v_char.size(); ++h)
{
float bin_value = v_char[h];
points << QPointF((float)h, bin_value);
}
curvea->setSamples(points); //pass points to be drawn on the curve
curvea->attach( plota ); // Attach curve to the plot
plota->resize( 600, 400 ); //Resize the plot
//plot.replot();
plota->show(); //Show plot
If anybody do know, please please do help, I already at my wits end. I can't seem to find an example or tutorial online for QWT plots. I already tried lots of things... Is there a problem with my code? Or my whole programming flow is wrong? Please help. Thanks.