Results 1 to 20 of 22

Thread: QVectos to multidimensional array

Hybrid View

Previous Post Previous Post   Next Post Next Post
  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

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
  •  
Qt is a trademark of The Qt Company.