PDA

View Full Version : Infinite filling area curve



SandyEmerald
4th October 2013, 09:22
Hi all. I'm using qwt 5.2.2. I'm trying to make kind of filling area between two lines. Lines can be infinite in horizontal. I'm using DBL_MIN and DBL_MAX.
Lines are inherit from QwtPlotMarker. If my lines are infinite, I create them using setYValue(double), if not - setValue(double, double).
Code for my filling area:


QwtPlotCurve* fillingAreaCurve = new QwtPlotCurve;

fillingAreaCurve->setItemAttribute(QwtPlotItem::Legend, false);
fillingAreaCurve->setStyle(QwtPlotCurve::Lines);
fillingAreaCurve->setPen(QPen(Qt::gray, 1, Qt::SolidLine));
fillingAreaCurve->setBrush(QBrush(QColor(150, 150, 150, 127),Qt::SolidPattern));
fillingAreaCurve->setBaseline(baseline);
fillingAreaCurve->setData(xData, yData, 2);

Where xData is array, xData[0] = DBL_MIN, xData[1] = DBL_MAX. After that, i do attach(plot) and replot().
The problem is that my program freeze. I tried to separate them to two areas - from DBL_MIN to 0 and from 0 to DBL_MAX - nothing changed.
Any ideas?

P.S.: Sorry for my horrible English.

Uwe
4th October 2013, 10:19
Hi all. I'm using qwt 5.2.2. I'm trying to make kind of filling area between two lines.
Upgrade to Qwt 6.x and use QwtPlotIntervalCurve.

Uwe

SandyEmerald
4th October 2013, 11:53
I can't do it. It does not depend on me.

Uwe
4th October 2013, 13:01
Then tell the guys where it depends on, that I have said, that implementing this feature with Qwt 5.x will be a pain.

Uwe

AidenBlake
8th October 2013, 13:39
So, could you please help to do the same thing with QwtPlotMarker? My idea is in using pen with semitransparent color. How i can draw ending line with QwtPlotMarker?
I coded:



QwtPlotMarker *marker = new QwtPlotMarker();
QPen pen;
pen.setColor(QColor(150, 150, 150, 127));
marker->setLineStyle(QwtPlotMarker::HLine);


So, now, if i'd want to draw infinite filling area, i could calculate pen width and use


pen.setWidthF(width);
marker->setLinePen(pen);
setYValue(y);


and what about ending line? help please

NoLJustS
24th March 2014, 13:06
Problem of the code posted in first message is that qwt tries to calculate scales steps and other staff and can't do it correctly when min showed value is DBL_MIN and max = DBL_MAX. Anyway you most likely dont want your plot autoscaled to [DBL_MIN, DBL_MAX].
I can suggest next solution - make your own data for curve:

InfiniteData(const QwtPlot* plot, double left, double right, double y):
m_plot(plot), m_boundingCurve(boundingCurve), m_left(left), m_right(right), m_y(y)
{
}

virtual QwtData* copy () const
{
return new InfiniteData(m_plot, m_left, m_right, m_y);
}

virtual size_t size() const
{
return 2;
}

virtual double x(size_t i) const
{
const double x = (i == 0) ? m_left : m_right;
const QwtScaleDiv* xScale = m_plot->axisScaleDiv(QwtPlot::xBottom);

if(std::fabs(x - DBL_MIN) < std::numeric_limits<double>::epsilon())
return xScale->lowerBound() - xScale->range();

if(std::fabs(DBL_MAX - x) < std::numeric_limits<double>::epsilon())
return xScale->upperBound() + xScale->range();

return x;
}

virtual double y(size_t i) const
{
return m_y;
}

virtual QwtDoubleRect boundingRect() const
{
return QwtDoubleRect(); //But your plot will always replot in such way to contain [0, 0] point. You can change it as you need
}

private:
const QwtPlot* m_plot;
const double m_left;
const double m_right;
const double m_y;
};

And then use it like:
QwtPlotCurve* fillingAreaCurve = new QwtPlotCurve;
fillingAreaCurve->setItemAttribute(QwtPlotItem::Legend, false);
fillingAreaCurve->setStyle(QwtPlotCurve::Lines);
fillingAreaCurve->setPen(QPen(Qt::gray, 1, Qt::SolidLine));
fillingAreaCurve->setBrush(QBrush(QColor(150, 150, 150, 127),Qt::SolidPattern));
fillingAreaCurve->setBaseline(firstYValue);
fillingAreaCurve->setData(InfiniteData(plot, DBL_MIN, DBL_MAX, secondYValue));

And happiness will come!