Matthias Pospiech | 16 Apr 15:49
Picon
Picon

Help with understanding QwtRasterData needed

This here is the example qwt delivers:

class SpectrogramData: public QwtRasterData

{

public:

    SpectrogramData(): QwtRasterData(QwtDoubleRect(-1.5, -1.5, 3.0, 3.0)) {}

virtual QwtRasterData *copy() const { return new SpectrogramData();}

virtual QwtDoubleInterval range() const { return QwtDoubleInterval(0.0, 
10.0);}

virtual double value(double x, double y) const{

const double c = 0.842;

const double v1 = x * x + (y-c) * (y+c);

const double v2 = x * (y+c) + x * (y+c);

return 1.0 / (v1 * v1 + v2 * v2);

}

};

In my problem the data however has to be delivered to the plot as a 
(Continue reading)

Matthias Pospiech | 16 Apr 18:09
Picon
Picon

Re: Help with understanding QwtRasterData needed

I now created my own SpectrogramData version. But in the end I found out 
that SpectrogramData fails to use my own values in the value function.
m_RangeX.min, m_RangeY.min are all unkown within
    virtual double value(double x, double y) const
(see definition below)

This problem is out of the scope of my c++ knowledge...

Matthias

--------------
class SpectrogramData: public QwtRasterData
{
private:
    double * m_Array;
    double m_minValue;
    double m_maxValue;
    struct structMinMax{
        double min;
        double max;
    };
    structMinMax m_RangeX;
    structMinMax m_RangeY;
    struct structXY{
        double x;
        double y;
    };
    structXY m_DataSize;
    structXY m_RealToArray;

(Continue reading)

Uwe Rathmann | 16 Apr 19:38
Picon

Re: Help with understanding QwtRasterData needed

On Wednesday 16 April 2008 18:09, Matthias Pospiech wrote:

> I now created my own SpectrogramData version. But in the end I found out
> that SpectrogramData fails to use my own values in the value function.

Your implementation of copy returns an uninitialized data object - not a 
clone. 

I recommend to use one of the Qt containers (f.e QVector or QList ) instead of 
the plain double arrays. These containers implicitely share your data, what 
makes copying an unexpensive operation and the handling of the memory is much 
easier. Especially if you don't feel comfortable with C/C++, you should use 
them.

Uwe

-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference 
Don't miss this year's exciting event. There's still time to save $100. 
Use priority code J8TL2D2. 
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
Matthias Pospiech | 16 Apr 20:09
Picon
Picon

Re: Help with understanding QwtRasterData needed

Uwe Rathmann schrieb:
> On Wednesday 16 April 2008 18:09, Matthias Pospiech wrote:
>
>   
>> I now created my own SpectrogramData version. But in the end I found out
>> that SpectrogramData fails to use my own values in the value function.
>>     
>
> Your implementation of copy returns an uninitialized data object - not a 
> clone. 
>
>   
It is the copy from the example code. I have no idea how to change it to 
be correct.
> I recommend to use one of the Qt containers (f.e QVector or QList ) instead of 
> the plain double arrays. These containers implicitely share your data, what 
> makes copying an unexpensive operation and the handling of the memory is much 
> easier. Especially if you don't feel comfortable with C/C++, you should use 
> them.
>   
I have to deal with no-Qt libaries, especially math libaries which 
require double arrays. Using QVector arrays would definetly be nicer, 
but would mean that I have to copy the array multiple times between each 
libary. The way I implemented it is how it works across the whole Code 
so far and I understand that part.

Matthias

-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference 
(Continue reading)

Uwe Rathmann | 16 Apr 21:08
Picon

Re: Help with understanding QwtRasterData needed

On Wednesday 16 April 2008 20:09, Matthias Pospiech wrote:

> It is the copy from the example code. I have no idea how to change it to
> be correct.

QwtRasterData *SpectrogramData::copy() const
{
        SpectrogramData *clone = new SpectrogramData();
        clone->setData(m_Array, m_DataSize.x, m_DataSize.y);
        ...
        return clone;
}

> I have to deal with no-Qt libaries, especially math libaries which
> require double arrays.
> Using QVector arrays would definetly be nicer, ...  

With QVector<double>::data() you have a double array.

> ... but would mean that I have to copy the array multiple times between each
> libary.

Your implementation of setData copies and each call of SpectrogramData::copy ( 
implicitely called by Qwt) would do another copy. If you would use a QVector 
inside of SpectrogramData you could write:

 void setData(double * Array, int sizex, int sizey)
 {
        ...
        m_Array.resize(size);
(Continue reading)

Uwe Rathmann | 16 Apr 18:29
Picon

Re: Help with understanding QwtRasterData needed

On Wednesday 16 April 2008 15:54, Matthias Pospiech wrote:

> In my problem the data however has to be delivered to the plot as a
> double array (2D Array).

QwtRasterData ( similar to QwtData ) is the link between the application data 
and the QwtRasterItem ( guess here a spectrogram ), that is responsible for 
displaying the data. 
When the raster item needs to render its image it calculates the position of 
each pixel and asks the raster data object for a value at this position. This 
value is mapped into a color using the value range, that is also provided by 
the data object. 

You need to implement a raster data object, that can access your 2d array:

a) YourRasterData::range()

If you have a color map from blue to red you also need to define which value 
means blue and which means red. Values above or below are mapped to the 
borders of the color map. Range is what we call "Wertebereich" in German.

b) YourRasterData::value()

Here you have to return the value at a specific position. Usually your 2D 
array will have a different raster, so you have to do some resampling here ( 
f.e. next neighbour ).

The following methods are optional, but might speedup the process of rendering 
a lot:

(Continue reading)

Matthias Pospiech | 17 Apr 09:47
Picon
Picon

Re: Help with understanding QwtRasterData needed

Using you hint about the clone function made the whole thing work:
    virtual QwtRasterData *copy() const
    {
        SpectrogramData *clone = new SpectrogramData();
        clone->setRangeX(m_RangeX.min, m_RangeX.max);
        clone->setRangeY(m_RangeY.min, m_RangeY.max);
        clone->setData(m_Array, m_DataSize.x, m_DataSize.y);
        return clone;
    }
It however requires to set the Range of the Data bevor setting the data 
which is not nice in term of the implementation.

I however still have the problem that the axis do not match the Data 
size (goes from -0.6 to 0.6 instead of 0-1024) and therefore no data is 
displayed since the value of alwyas 0.

Uwe Rathmann schrieb:
> a) YourRasterData::range()
>
> If you have a color map from blue to red you also need to define which value 
> means blue and which means red. Values above or below are mapped to the 
> borders of the color map. Range is what we call "Wertebereich" in German.
>   
That has been implmented as
    virtual QwtDoubleInterval range() const
    {
        return QwtDoubleInterval(m_minValue, m_maxValue);
    }

> b) YourRasterData::value()
(Continue reading)

Uwe Rathmann | 17 Apr 10:26
Picon

Re: Help with understanding QwtRasterData needed

On Thursday 17 April 2008 09:47, Matthias Pospiech wrote:

> It however requires to set the Range of the Data bevor setting the data
> which is not nice in term of the implementation.

Qwt has no setRange(). It is all your design and if you don't like something: 
change it.

The range should be related to your type of data - not to a specific set of 
samples. F.e. if you want to display temperature you might have a color map 
from blue to red, and a range from 0 to 100. 

Nice or not: it's not possible to map a value into a color, when the colors 
are related to nothing.

> I however still have the problem that the axis do not match the Data
> size (goes from -0.6 to 0.6 instead of 0-1024) and therefore no data is
> displayed since the value of alwyas 0.

In case of autoscaling the scales are calculated from the boundingRect. 
The values itsself have no meaning for the axes.

> It is defined as
>     void initRaster(const QwtDoubleRect &, const QSize &
> but I have no idea what I should do. 

If your array is already prepared for the following value() requests, then do 
nothing and don't reimplement this method.

> > d) YourRasterData::discardRaster()
(Continue reading)


Gmane