Page 1 of 2 12 LastLast
Results 1 to 20 of 22

Thread: QVectos to multidimensional array

  1. #1
    Join Date
    Jan 2007
    Posts
    95
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Windows

    Angry QVectos to multidimensional array

    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:
    Qt Code:
    1. GLuint GLWidget::makeSurf(const GLfloat *reflectance,QVector<float> x,QVector<float> y,QVector<float> z)
    2. {
    3. float ***points;
    4. int dimx=x.size();
    5. int dimy=y.size();
    6.  
    7. points= new float **[dimx];
    8. for (int i=0;i<dimx;i++){
    9. points[i]=new float *[dimy];
    10. for (int j=0;j<dimy;j++){
    11. points[i][j]=new float[3];
    12. }
    13. }
    14. int cont=0;
    15. for (int ix=0; ix<dimx; ix++){
    16. for (int iy=0; iy<dimy; iy++){
    17. cont++;
    18. points[ix][iy][0]=x[cont];
    19. points[ix][iy][1]=y[cont];
    20. points[ix][iy][2]=z[cont];
    21. }
    22. }
    23.  
    24.  
    25. or this way:
    26.  
    27. points = new float **[dimx];
    28. for(int i=0;i<dimx;i++) {
    29. *(points+i) = new float *[dimy];
    30. for(int j=0;j<dimy;j++){
    31. *(*(points+i)+j) = new float[3];
    32. }
    33. }
    34. int cont=0;
    35. for(int i=0;i<dimx;i++) {
    36. for(int j=0;j<dimy;j++) {
    37. *(*(*(points+i)+j)+0) = x[cont];
    38. *(*(*(points+i)+j)+1) = y[cont];
    39. *(*(*(points+i)+j)+2) = z[cont];
    40. cont++;
    41. }
    42. }
    43. ..........
    44. }
    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

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QVectos to multidimensional array

    It is definetly an idex problem.
    I suggest you do a core dump, or - instert qDebug() along the code, and play with it untill you get to the line that is crashing, then add a debug information befor that line that will dump all the index values.

  3. #3
    Join Date
    Jan 2007
    Posts
    95
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QVectos to multidimensional array

    i can see now whats the problem. If i have for example 6 points (6 for x, 6 for y and 6 for z) i cannot programm a double for loop to define the points of the surface, because this code are trying to save 6*6 points, and i only have 6 points (with 3 coordenates each point).

    But, can anybody tell me how to make a surface (with opengl or glunurbs) if a have a collection of coordenates (x,y,z)?

  4. #4
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QVectos to multidimensional array

    If i have for example 6 points (6 for x, 6 for y and 6 for z)
    But isn'T a point made of x,y and z?
    like: point1(x,y,z) point2(x,y,z)?

  5. #5
    Join Date
    Jan 2007
    Posts
    95
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QVectos to multidimensional array

    These are the points:

    ( x[0] , y[0] , z[0] )
    ( x[1] , y[1] , z[1] )
    ( x[2] , y[2] , z[2] )
    ...
    ( x[n] , y[n] , z[n] )

    But i save all x in one qvector, all y in other qvector and all z in other qvector.

  6. #6
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QVectos to multidimensional array

    so what do you mean by :
    If i have for example 6 points (6 for x, 6 for y and 6 for z)
    ?

  7. #7
    Join Date
    Jan 2007
    Posts
    95
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QVectos to multidimensional array

    I have 6 points (for example) but i dont have dimx=6 * dimy=6 points, and when i use this code:

    Qt Code:
    1. int cont=0;
    2. for (int ix=0; ix<dimx; ix++){
    3. for (int iy=0; iy<dimy; iy++){
    4. cont++;
    5. points[ix][iy][0]=x[cont];
    6. points[ix][iy][1]=y[cont];
    7. points[ix][iy][2]=z[cont];
    8. }
    9. }
    To copy to clipboard, switch view to plain text mode 

    i'm trying to alocate 6x6 points, and this is the error, cont=0,1,.....,36, and x[0,..,6] y[0,...,6] and z[0,...,6].
    The definition of the pointer (***points) is ok, but the initialization of the pointer is bad.
    This code works if i make only a for loop like this:

    Qt Code:
    1. for (int i=0; i<dimx; i++){
    2. points[i][i][0]=x[i];
    3. points[i][i][1]=y[i];
    4. points[i][i][2]=z[i];
    5. }
    To copy to clipboard, switch view to plain text mode 

    But this is not what i want for making a surface, because i have a lots of points in the array with no initialization.

    So, i make this question: how construct a surface if i have n points (x,y,z) with evaluators (opengl) or nurbs (glut), or another way...?

  8. #8
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QVectos to multidimensional array

    I don't see any problem with the array initialization.
    Your array has dimx*dimy*3 dimensions.
    So if your x vector is size 6, and your y vector is size 6 then your array is
    6*6*3.
    Where any combination of: points[0-5][0-5][0-2] is valid.
    The only problem (now that I looked a bit more carefully) is this the count.
    But I need to think it over.
    I am confuses.
    Do you have 6 (for example) given poitns which have x,y,z values, OR - you have 6 x value, 6 y values and 6 z values that you want to asign to any possible combination of the tree vectors?
    Last edited by high_flyer; 15th March 2007 at 12:57.

  9. #9
    Join Date
    Jan 2007
    Posts
    95
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QVectos to multidimensional array

    No, I have 6 (for examples) points, only 6 point whoose x values are save in a qvector, y coordinates in a qvector and z coordinates in a qvector. But i dont want to the combination of these values. The points are:

    ( x[0] , y[0] , z[0] )
    ( x[1] , y[1] , z[1] )
    ( x[2] , y[2] , z[2] )
    ( x[3] , y[3] , z[3] )
    ( x[4] , y[4] , z[4] )
    ( x[5] , y[5] , z[5] )

    but not the combination of theese values. For example, this is not a valid point for me: ( x[1] , y[2] , z[3] ).

    Sorry for my bad english.

  10. #10
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QVectos to multidimensional array

    it that case you dont need a multi dimensional array the way you did it.
    You need one dimensional array of points, where each point has x,y,z values.
    I still don't know how you want to use this data.
    Whats wrong with having the coordinated in 3 vectors?
    What are you trying to acheave by having all the infomration in one entity?
    Is doing:
    Qt Code:
    1. valx = x[i];
    2. valy = y[i];
    3. valz = z[i];
    To copy to clipboard, switch view to plain text mode 

    not good?

    If you must have each point as entity you can do:
    Qt Code:
    1. typedef struct {
    2. float x;
    3. float y;
    4. float z;
    5. } point;
    6.  
    7. QVector<point> vpoints;
    8. point temp;
    9. for(int i=0; i<x.size(); ++i)
    10. {
    11. temp.x = x[i];
    12. temp.y = y[i];
    13. temp.z = z[i];
    14. vpoints.push_back(temp);
    15. }
    To copy to clipboard, switch view to plain text mode 

  11. #11
    Join Date
    Jan 2007
    Posts
    95
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QVectos to multidimensional array

    Yes, but i need a multidimensional array because opengl functions to evaluate surfaces (glMap2f, GlEvalMesh2,...) needs points in that way, like multidimensional array, and glut functions for NURBS surfaces need it too. Thats the reason why i need multidimensional array.
    If you know other way to do this (paint in opengl a surface with n points), please tell me how?

    Thanks

  12. #12
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QVectos to multidimensional array

    Yes, but you are mixing and confusing things.
    You have QVector.size() points.
    So the index of the x,y and z vectors is not their location in the 3D world, but their joint values are, yet you are using the vector index as a position:
    points[ix][iy][0]=x[cont];
    what (maybe) you are looking for is:
    Qt Code:
    1. for(int i=0: i<x.size(); i++)
    2. points[x[i]][y[i]][z[i]] = somevalue;
    To copy to clipboard, switch view to plain text mode 
    but what 'somevalue' is, I don't know, its not visible in your code, maybe reflectance[i]?

  13. #13
    Join Date
    Jan 2007
    Posts
    95
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QVectos to multidimensional array

    So the index of the x,y and z vectors is not their location in the 3D world, but their joint values are, yet you are using the vector index as a position:
    Yes, you are right about confusing.

    but what 'somevalue' is, I don't know, its not visible in your code, maybe reflectance[i]?
    No, in qvector x, y and z are the coordinates in a real 3D space of the points of the surface.

  14. #14
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QVectos to multidimensional array

    No, in qvector x, y and z are the coordinates in a real 3D space of the points of the surface.
    Which is exactly what my last suggestion does.
    The 3D array should hold some point values, right?
    The vectors hold the x,y,z position and.... where is the value?

  15. #15
    Join Date
    Jan 2007
    Posts
    95
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QVectos to multidimensional array

    With a fortran programm i generate a grid of points who contents x,y,z,value then i select wich points has a value between l1 and l2 ( l1=value-delta, l2=value+delta), this made me a points collection with the same value of the function (this is a contour). I want to print in open gl this contour (points(x,y,z) with the same value of the function) and construct a surface with theese points. Im trying this (x,y,z) be my control points to construct the surface. I know i can joint this points with lines, triangles,... but this is not a smooth surface, so im trying to use opengl evaluators or glutnurbs where my points are the control points of the evaluator or nurbs.

    I hope you understand me.

  16. #16
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QVectos to multidimensional array

    I hope you understand me.
    Well, yes and no...

    Ok, so you have the values for each point calculated by some external function.
    Good.
    So where is the problem?
    You can use the code I suggested (with your original 3D array initialization)
    Qt Code:
    1. for(int i=0: i<x.size(); i++)
    2. points[x[i]][y[i]][z[i]] = somevalue;
    To copy to clipboard, switch view to plain text mode 

    Where 'somevalue' is the value you calculated with your fortran program.
    And you can feed this 3D array then to opengl.

  17. #17
    Join Date
    Jan 2007
    Posts
    95
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QVectos to multidimensional array

    After all, thanks a lot for your patient and for your suggestions.

    I cant see why this code works because x[i], y[i] and z[i] are floating values. And I dont know why theese points are the control points of my surface in opengl.

    Nevertheless, im going to try this....

    As I thought, compiler says me that x[i]... are not integral values. And no compile the program.
    Last edited by zorro68; 16th March 2007 at 11:31.

  18. #18
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QVectos to multidimensional array

    I cant see why this code works because x[i], y[i] and z[i] are floating values.
    You are right, I forgot these are floats.
    But then something does not add up with the information you are giving.
    What kind of a multi dimenssional array does openGL expects?
    What kind of infomation the array should have?
    The only way I see is to map the vector values to ints - otherwise you can't use them as indexes in an array.

  19. #19
    Join Date
    Feb 2007
    Posts
    49
    Thanks
    4
    Thanked 6 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QVectos to multidimensional array

    To help this discussion...

    This is what OpenGL expects. gluNurbsSurface.

  20. #20
    Join Date
    Jan 2007
    Posts
    95
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QVectos to multidimensional array

    Im trying to do something like this with my points:

    http://pgrafica.webideas4all.com/evaluators.html

    but in this way i need n*m control points, and i have not this n*m control points. I have lots of points in a 3Dspace, and i need a surface that contains all theese points.
    Im thinking of generate the n*m points with my points and interpolate (splines,bsplines,....or any suggestion) the other points. If i have the n*m control points i can construct the surface with evaluators.

Similar Threads

  1. How to create QPixmap from unsigned character array?
    By rashidbutt in forum Qt Programming
    Replies: 4
    Last Post: 16th May 2006, 18:25
  2. Creating a global array in my code???
    By therealjag in forum General Programming
    Replies: 5
    Last Post: 13th March 2006, 11:13
  3. QSettings again ... how to remove array elements
    By Mike in forum Qt Programming
    Replies: 4
    Last Post: 11th January 2006, 08:58
  4. loading array values directly
    By jamadagni in forum General Programming
    Replies: 5
    Last Post: 8th January 2006, 17:50

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.