1 Attachment(s)
limits for drawing a QwtPlotCurve
Hello,
I'm drawing some curves onto the spectrogram and want to adapt/limit the bounds of curve to the bounds of spectrogram. As you can see in the attached image, the bound for x2 in spectrogram is 4, but the curve has bigger x2 values than 4, thus the image is not nice, because the plot should be only filled with spectrogramdata ( without grey areas) and on it there should be curves, which should respect the bounds of spectrogram. How to do the limitations?
best regards,
Vitali
I set the curve data with this class:
Code:
{
// The x values depend on its index and the y values
// can be calculated from the corresponding x value.
// So we don't need to store the values.
// Such an implementation is slower because every point
// has to be recalculated for every replot, but it demonstrates how
// QwtData can be used.
public:
SimpleData( double (*b)(double), double rang1[2], double step)
{
constraintFunc = b;
_step = step;
rangeX[0]= rang1[0]; rangeX[1] = rang1[1];
range = (rang1[1] - rang1[0])/step;
if(range<0){
range = range *(-1);
}
d_size = size_t(range);
}
{
return new SimpleData(*this);
}
virtual size_t size() const
{
return d_size;
}
virtual double x(size_t i) const
{
if(rangeX[0]<0){
return (-(range- i) + i)/ range;
}
else
return ((range + i) + i)/ range;
}
virtual double y(size_t i) const
{
return (*constraintFunc)(x(i));
}
private:
size_t d_size;
double range;
double _step;
double (*constraintFunc)(double); // function pointer for constraint function
double rangeX[2];
};
Re: limits for drawing a QwtPlotCurve
ok, I solved it myself by "if" and "else if" conditions:
Code:
{
// The x values depend on its index and the y values
// can be calculated from the corresponding x value.
// So we don't need to store the values.
// Such an implementation is slower because every point
// has to be recalculated for every replot, but it demonstrates how
// QwtData can be used.
public:
SimpleData( double (*b)(double), double rang1[2], double rang2[2], double step)
{
constraintFunc = b;
_step = step;
rangeX[0]= rang1[0]; rangeX[1] = rang1[1];
rangeY[0]= rang2[0]; rangeY[1] = rang2[1];
range = (rang1[1] - rang1[0])/step;
if(range<0){
range = range *(-1);
}
d_size = size_t(range);
}
{
return new SimpleData(*this);
}
virtual size_t size() const
{
return d_size;
}
virtual double x(size_t i) const
{
if(rangeX[0]<0){
return (-(range- i) + i)/ range;
}
else
return ((range + i) + i)/ range;
}
virtual double y(size_t i) const
{
if((*constraintFunc)(x(i)) > rangeY[1]){
return rangeY[1];
}
else if((*constraintFunc)(x(i)) < rangeY[0]){
return rangeY[0];
}
else return (*constraintFunc)(x(i));
}
private:
size_t d_size;
double range;
double _step;
double (*constraintFunc)(double); // function pointer for constraint function
double rangeX[2];
double rangeY[2];
};