PDA

View Full Version : Spectogram related



KosyakOFF
24th April 2009, 11:37
Hi everyone.

I have plot with curves and Spectogram on it. Then I replot this plot (in order to apply changes in curves data) spectogram goes something like blank or it's rasterdata values are all equal to zero.

I have found only one way - to setData to spectogram for every replot. Can I use more advance solution?

VERY big thanks for your answers beforehand.

Uwe
24th April 2009, 13:24
Without showing more informations you can't expect any useful answer. At least you have to post the implementation of your raster data object.

Uwe

KosyakOFF
28th April 2009, 10:46
Impl:

class SpectrogramData: public QwtRasterData
{
public:

double min,max,width,height,pixWidth,pixHeight;
ap::real_2d_array* grid;
mPoints mainStringBeg;
mPoints mainStringEnd;
double xMast,yMast;
double currX,x0,x1,y0,y1,x,y,tmpEn0,tmpEn1;

SpectrogramData(double tmax, double tmin, double twidth, double theight,double tpixWidth, double tpixHeight, ap::real_2d_array* a)
: QwtRasterData(QwtDoubleRect(0, 0,twidth,theight))
{
max=tmax;
min=tmin;
width=twidth;
height=theight;
//this->setBoundingRect(QwtDoubleRect(0,0,width,height));
grid=a;
pixWidth=tpixWidth;
pixHeight=tpixHeight;
xMast=width/pixWidth;
yMast=height/pixHeight;
SETMAINSTRINGS(0);
}

void setParams(double tmin,double tmax,int twidth,int theight)
{
min=tmin; max=tmax;
width=twidth; height=theight;
this->setBoundingRect(QwtDoubleRect(0,0,width,height));
}
void setGrid( ap::real_2d_array* a /*vector <tmpPoint> *a*/)
{
grid=a;
}

virtual QwtRasterData *copy() const
{
return new SpectrogramData(max,min,width,height,pixWidth,pixH eight,grid);
}

virtual QwtDoubleInterval range() const
{
if (min==-1 && max==-1)
return QwtDoubleInterval(0.0, 10.0);

return QwtDoubleInterval(0, max);

}

virtual double value(double tx, double ty) const
{

if (int(tx)<width && int(tx)>=0 && int(ty)<height-1 && int(ty)>=0)
{
if (min!=-1 || max!=-1)
{
if (ty<mainStringBeg.y)
return 0;
if ( ty>mainStringEnd.y)
{
if (int(mainStringEnd.y)+1<height)
SETMAINSTRINGS( int(mainStringEnd.y) );
else return 0;
}
if (ty==mainStringBeg.y)
{
SEARCHVALUEONLINE(mainStringBeg,tx)
return y;
}
if(ty>mainStringBeg.y && ty<mainStringEnd.y)
{
SEARCHVALUE(tx,ty)
return y;
}
if (ty==mainStringEnd.y)
{
SEARCHVALUEONLINE(mainStringEnd,tx)
return y;
}
else
return 0;
}
}
return 0;

}
};


macros like SEARCHVALUE are used to perform an interpolation.

Uwe
29th April 2009, 07:24
Your raster data object has a pointer to the values (grid) only. Did you check what's going on with this array later ?

Uwe

KosyakOFF
29th April 2009, 11:29
Well i performed such test: in place of setData() function I set cerr<< value of some random grid cells and they are correct, so my app don't clear grids before reploting. But if I cerr<< rasterData.value() on some random values they are all zero.

I don't know internal work of rasterData class. Maybe I should observe Implementation of rasterData copy() function.

Maybe in some situations it gets wrong parameters (width,hight,resolution) so value() function will return zero on every pixel (My value impl. return zero in case if value() can't calculate real value).

Then I setData to spectogram I use temp. QwtRasterData like: d_spectogram->setData(SpectogramData(<data constructor>));

Maybe I should create pointer to spectogramData, allocate memory and create new spectogramData and then set it to spectogram?

As far as I discovered setData() function makes copy of rasterData as we give her as a parameter. So there is no point too put huge grids in rasterData, it is better to store pointers to this grid. But I stiil don't know why spectogram turns blank.

I've tested another thing - if I use setData, then replot the spectrPlot ones it's drawing right picture. but if will replot twice spectroGram will turn blank =|

KosyakOFF
29th April 2009, 14:51
I think I've got it.

Then Spectogram copies user defined spectogram data (child class of basic QwtRasterData) it convert this data to basic QwtRasterData with prededined value() method.

This must be a problem. So maybe I should overload spectogram Private data?

Uwe
30th April 2009, 06:59
The spectrogram item clones your raster data object using your virtual copy method - the one you have posted looks o.k. to me.
But note, that you might need to reassign your data object ( create a new clone ) whenever you change its attributes.

F.e. calling setGrid for your object will have no effect until you reassign it.

Uwe