Hi, I'm trying to program a surface with opengl evaluators or glunurbs, but this two functions needs a multidimensional array (three dimension) for points. I have my points in three Qvector (one for x, one for y and one for z). When I trying to convert this qvectors to a array i have an error, but i dont know what. The compiler says ok all, but when i run the program, the program exit with no warning. This is the code:
GLuint GLWidget::makeSurf(const GLfloat *reflectance,QVector<float> x,QVector<float> y,QVector<float> z)
{
float ***points;
int dimx=x.size();
int dimy=y.size();
points= new float **[dimx];
for (int i=0;i<dimx;i++){
points[i]=new float *[dimy];
for (int j=0;j<dimy;j++){
points[i][j]=new float[3];
}
}
int cont=0;
for (int ix=0; ix<dimx; ix++){
for (int iy=0; iy<dimy; iy++){
cont++;
points[ix][iy][0]=x[cont];
points[ix][iy][1]=y[cont];
points[ix][iy][2]=z[cont];
}
}
or this way:
points = new float **[dimx];
for(int i=0;i<dimx;i++) {
*(points+i) = new float *[dimy];
for(int j=0;j<dimy;j++){
*(*(points+i)+j) = new float[3];
}
}
int cont=0;
for(int i=0;i<dimx;i++) {
for(int j=0;j<dimy;j++) {
*(*(*(points+i)+j)+0) = x[cont];
*(*(*(points+i)+j)+1) = y[cont];
*(*(*(points+i)+j)+2) = z[cont];
cont++;
}
}
..........
}
GLuint GLWidget::makeSurf(const GLfloat *reflectance,QVector<float> x,QVector<float> y,QVector<float> z)
{
float ***points;
int dimx=x.size();
int dimy=y.size();
points= new float **[dimx];
for (int i=0;i<dimx;i++){
points[i]=new float *[dimy];
for (int j=0;j<dimy;j++){
points[i][j]=new float[3];
}
}
int cont=0;
for (int ix=0; ix<dimx; ix++){
for (int iy=0; iy<dimy; iy++){
cont++;
points[ix][iy][0]=x[cont];
points[ix][iy][1]=y[cont];
points[ix][iy][2]=z[cont];
}
}
or this way:
points = new float **[dimx];
for(int i=0;i<dimx;i++) {
*(points+i) = new float *[dimy];
for(int j=0;j<dimy;j++){
*(*(points+i)+j) = new float[3];
}
}
int cont=0;
for(int i=0;i<dimx;i++) {
for(int j=0;j<dimy;j++) {
*(*(*(points+i)+j)+0) = x[cont];
*(*(*(points+i)+j)+1) = y[cont];
*(*(*(points+i)+j)+2) = z[cont];
cont++;
}
}
..........
}
To copy to clipboard, switch view to plain text mode
Both samples crash. I have check dimension of qvectors and are ok. But exit the programm with no warning.
Need help please.
Thanks
Bookmarks