Here is my code as simple as possible, also i applied your last suggestions but despite i got segmentation fault. Please help.
- Plot.h
#ifndef PLOT_DATA_H
#define PLOT_DATA_H
#include "qwt_raster_data.h"
{
private:
double ** d_DataArray;
public:
plot_data();
~plot_data();
virtual double value(double x, double y) const;
void setData();
};
#endif // PLOT_DATA_H
#ifndef PLOT_DATA_H
#define PLOT_DATA_H
#include "qwt_raster_data.h"
class plot_data: public QwtRasterData
{
private:
double ** d_DataArray;
public:
plot_data();
~plot_data();
virtual QwtRasterData *copy() const;
virtual QwtDoubleInterval range() const;
virtual double value(double x, double y) const;
void setData();
};
#endif // PLOT_DATA_H
To copy to clipboard, switch view to plain text mode
- Plot.cpp
#include "plot_data.h"
#include <QDebug>
#include <cmath>
plot_data::plot_data():
{
d_DataArray = NULL;
}
plot_data::~plot_data()
{
if (d_DataArray != NULL ){
for(int i = 0; i < 10; i ++)
{
delete [] d_DataArray[i];
}
delete [] d_DataArray;
}
}
{
}
{
plot_data *clone = new plot_data();
return clone;
}
double plot_data::value(double x, double y) const
{
int xpos = qRound(x);
int ypos = qRound(y);
if (xpos >= 0 || xpos < 10 || ypos >= 0 || ypos < 10 )
{
//here is still segmentation fault;
return d_DataArray[xpos][ypos];
}
qDebug() << "it happened";
return 0.0;
}
void plot_data::setData()
{
//here i'm generating some test data.
//help values to random data;
int XMin = 0, XMax = 10, size = 100;
if (d_DataArray != NULL )
{
for(int i = 0; i < 10; i ++)
{
delete [] d_DataArray[i];
}
delete [] d_DataArray;
qDebug()<< "Deleted";
}
d_DataArray = new double* [10];
if (d_DataArray == NULL)
{
qDebug() << "BAd initialization";
}
for(int i = 0; i < 10; i ++)
{
d_DataArray[i] = new double [10];
if (d_DataArray[i] == NULL)
qDebug() << "Something Wrong with allocation";
}
for(int x = 0; x < 10; x ++)
for(int y = 0; y < 10; y ++){
d_DataArray[x][y] = XMin + rand() * (XMax - XMin) / RAND_MAX;
//qDebug() << d_DataArray[0][9] << "\n";
//WHEN I CALL HERE SOMETHING LIKE THIS IT ALSO YELDS SEGFAULT
}
}
#include "plot_data.h"
#include <QDebug>
#include <cmath>
plot_data::plot_data():
QwtRasterData(QwtDoubleRect(0., 0., 9.0, 9.0))
{
d_DataArray = NULL;
}
plot_data::~plot_data()
{
if (d_DataArray != NULL ){
for(int i = 0; i < 10; i ++)
{
delete [] d_DataArray[i];
}
delete [] d_DataArray;
}
}
QwtDoubleInterval plot_data::range() const
{
return QwtDoubleInterval(0., 10);
}
QwtRasterData* plot_data::copy() const
{
plot_data *clone = new plot_data();
return clone;
}
double plot_data::value(double x, double y) const
{
int xpos = qRound(x);
int ypos = qRound(y);
if (xpos >= 0 || xpos < 10 || ypos >= 0 || ypos < 10 )
{
//here is still segmentation fault;
return d_DataArray[xpos][ypos];
}
qDebug() << "it happened";
return 0.0;
}
void plot_data::setData()
{
//here i'm generating some test data.
//help values to random data;
int XMin = 0, XMax = 10, size = 100;
if (d_DataArray != NULL )
{
for(int i = 0; i < 10; i ++)
{
delete [] d_DataArray[i];
}
delete [] d_DataArray;
qDebug()<< "Deleted";
}
d_DataArray = new double* [10];
if (d_DataArray == NULL)
{
qDebug() << "BAd initialization";
}
for(int i = 0; i < 10; i ++)
{
d_DataArray[i] = new double [10];
if (d_DataArray[i] == NULL)
qDebug() << "Something Wrong with allocation";
}
for(int x = 0; x < 10; x ++)
for(int y = 0; y < 10; y ++){
d_DataArray[x][y] = XMin + rand() * (XMax - XMin) / RAND_MAX;
//qDebug() << d_DataArray[0][9] << "\n";
//WHEN I CALL HERE SOMETHING LIKE THIS IT ALSO YELDS SEGFAULT
}
}
To copy to clipboard, switch view to plain text mode
Regarding the way how i would like to use the SpectrogramPlot. I'm working on 2 dimmensional Lattice boltzman method, and i want to visualise my results using SpectrogramPlot. It is simulation of fluid over discrete space. Results are values of speed in each cell of space. So i want to represent the data in 2D array. I think it's natural
Bookmarks