Complicated growable array
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 11 of 11

Thread: Complicated growable array

  1. #1
    Join Date
    Apr 2009
    Posts
    6

    Complicated growable array

    Hi codeguru users!

    I am basically looking to make a growable array thats basically as follows:


    { [ ((PT1.X,PT1.Y,PT2.X,PT3.X),(PT1.X,PT1.Y,PT2.X,PT3.X),(PT1.X,PT1.Y,PT2.X,PT3.X) )] }

    the arrays size grows a lot.
    (pt1.x/y are points i am using via opencv)
    the larger picture ie the outside "()" represent an object
    the second set of "()" represent the iterations
    and the individual elements of the iterations (the points) are points

    if you help me i will love you forever

    EDIT: the array increases by each of the above (marked with "[]")
    Last edited by breakerbyte; April 9th, 2009 at 02:49 PM. Reason: oops

  2. #2
    Join Date
    Jan 2006
    Location
    Singapore
    Posts
    6,391

    Re: Complicated growable array

    Have you considered using std::vector?
    C + C++ Compiler: MinGW port of GCC
    Build + Version Control System: SCons + Bazaar

    Look up a C/C++ Reference and learn How To Ask Questions The Smart Way
    Kindly rate my posts if you found them useful

  3. #3
    Lindley is offline Elite Member Power Poster
    Join Date
    Oct 2007
    Location
    Fairfax, VA
    Posts
    10,891

    Re: Complicated growable array

    Code:
    struct Point
    {
        float x, y;
    };
    
    std::vector< std::pair<Point, Point> > growablearray;

  4. #4
    Join Date
    Apr 2009
    Posts
    6

    Re: Complicated growable array

    yeah, but apparently Its hard for me to find/understand exactly what is happening.

    would it be:

    vector<vector<vector<double>>> detection_points;

    not sure how I would set the sizes or anything.

    or how to use the push_back function correctly for it

  5. #5
    Join Date
    Apr 2009
    Posts
    6

    Re: Complicated growable array

    Quote Originally Posted by Lindley View Post
    Code:
    struct Point
    {
        float x, y;
    };
    
    std::vector< std::pair<Point, Point> > growablearray;
    holy wow! going to try this method out.

  6. #6
    Join Date
    Apr 2009
    Posts
    6

    Re: Complicated growable array

    not working :/

    could I combine both methods and store each "Point"
    lets say that (Point(iteration 0),Point(iteration 1),Point(iteration 2) is the equivalence of object

    (object,object,object)

  7. #7
    Join Date
    Jan 2006
    Location
    Singapore
    Posts
    6,391

    Re: Complicated growable array

    Okay, before talking about an array, what is the class definition of the objects that you plan to store?
    C + C++ Compiler: MinGW port of GCC
    Build + Version Control System: SCons + Bazaar

    Look up a C/C++ Reference and learn How To Ask Questions The Smart Way
    Kindly rate my posts if you found them useful

  8. #8
    Join Date
    Apr 2009
    Posts
    6

    Re: Complicated growable array

    they are either doubles or CvRect if they would work

  9. #9
    Join Date
    Jan 2006
    Location
    Singapore
    Posts
    6,391

    Re: Complicated growable array

    Quote Originally Posted by breakerbyte
    they are either doubles or CvRect if they would work
    Well, I don't really understand you, actually. I felt that Lindley made a good stab at an answer, but it seems like there is a communication breakdown somewhere. Let's do this step by step.

    Firstly, instead of dumping this:
    Code:
    { [ ((PT1.X,PT1.Y,PT2.X,PT3.X),(PT1.X,PT1.Y,PT2.X,PT3.X),(PT1.X,PT1.Y,PT2.X,PT3.X) )] }
    Do a breakdown of it. You say that "pt1.x/y are points i am using via opencv". What do you mean by "the second set of "()" represent the iterations"? Perhaps you want to create a class here, and then objects of this class would then be members of another class, and then the dynamic array would contain objects of this second class?

    Also, you should state how does Lindley's example not work.
    C + C++ Compiler: MinGW port of GCC
    Build + Version Control System: SCons + Bazaar

    Look up a C/C++ Reference and learn How To Ask Questions The Smart Way
    Kindly rate my posts if you found them useful

  10. #10
    Join Date
    Apr 2009
    Posts
    6

    Re: Complicated growable array

    Sorry bout the confusion.

    <vector<vector<CvRect>>foo;
    Changing everything to CvRect.

    need foo to grow 5 rows and 1 column on demand. thats the real issue

  11. #11
    Join Date
    Apr 1999
    Posts
    27,446

    Re: Complicated growable array

    Quote Originally Posted by breakerbyte View Post
    Sorry bout the confusion.

    <vector<vector<CvRect>>foo;
    Changing everything to CvRect.

    need foo to grow 5 rows and 1 column on demand. thats the real issue
    It's easier if you use typedef.
    Code:
    #include <vector>
    typedef std::vector<CvRect> CvRectArray;
    typedef std::vector<CvRectArray> CvRectArray2D;
    //...
    int main()
    {
        // Assuming that CVRect is default constructible.
        CVRectArray2D foo(5, CVRectArray(10));  A 5x10 array of CVRect
    
        // resize to 10x20
    
        // first, resize the existing rows
        for (CVRectArray2D::size_type i = 0; i < foo.size(); ++i )
            foo[i].resize(20);
    
        // now add on new rows 
        foo.resize(10, CVRectArray(20));
    }
    Regards,

    Paul McKenzie

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center