-
April 9th, 2009, 01:46 PM
#1
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 01:49 PM.
Reason: oops
-
April 9th, 2009, 01:49 PM
#2
Re: Complicated growable array
Have you considered using std::vector?
-
April 9th, 2009, 01:50 PM
#3
Re: Complicated growable array
Code:
struct Point
{
float x, y;
};
std::vector< std::pair<Point, Point> > growablearray;
-
April 9th, 2009, 01:51 PM
#4
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
-
April 9th, 2009, 01:52 PM
#5
Re: Complicated growable array
Originally Posted by Lindley
Code:
struct Point
{
float x, y;
};
std::vector< std::pair<Point, Point> > growablearray;
holy wow! going to try this method out.
-
April 9th, 2009, 02:26 PM
#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)
-
April 9th, 2009, 02:30 PM
#7
Re: Complicated growable array
Okay, before talking about an array, what is the class definition of the objects that you plan to store?
-
April 9th, 2009, 03:02 PM
#8
Re: Complicated growable array
they are either doubles or CvRect if they would work
-
April 9th, 2009, 03:10 PM
#9
Re: Complicated growable array
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.
-
April 9th, 2009, 03:25 PM
#10
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
-
April 9th, 2009, 07:19 PM
#11
Re: Complicated growable array
Originally Posted by breakerbyte
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|