any better solution than making a list of list of lists for my problem ?

Hey forum :)

I´m working on the following problem:
I have a 2D <bool> array, where 1 means the cell is solid and 0 it is liquid, so the domain can consist of one large area, or several smaller ones.
Now I have to find the outline of these areas. For this I already wrote the code, and all border elements of one domain are stored in a list.

Now, since there can be one area or many areas in the domain, I need to separate my list of border elements and would therefore get a list for each area. And each area list element has its own list of all the border elements that enclose this area.

But this is not the end yet, because whats the real goal is to calculate the outline of all these areas, with variable accuracy (first order, second, third, maybe even higher). Therefore I have to separate the border of one area again into several parts, so I can then make an approximation of the length for each part.

And since the number of parts depends on the shape of the area, it again means I need a list, thus ending in a list of list of lists.

(And since the real problem is a 3D surface and this 2D simplification is just the first step, this means a list of list of list of lists for the real case).

Of course, an array of lists would also work, but I think lists offer more flexibility than a c++ array.

if any1 has a better idea, I´m glad to take it :)

thanks in advance,

Chris
Last edited on
I think you should merge some steps. That would reduce the need of containers (although i did't understand why you think you need so much)

For example (simplified, not too much i hope):
Level 1 : you could have an array of int instead of bool. You browse all the points in your array. When you find a 1 that touches a 0, you assign it a new "island" number >1.
Level 2 : When you find a new island, you could use recursion to follow the other 1s that touch your new island number and a 0, and give them the island number. At the end of this recursion, the complete island sides would be identified
Level3 :At each new point of your island, you would add the distance to it's previous contiguous point to a vector (not a list, so that you can have constant time access to a random position instead of linear time access) at a position corresponding to the island number
When level 1 would be finished, all islands would be identified and their perimeters calculated
Thanks for your ideas, and you are right, I dont need so many layers.

The "island" idea is very helpfull, but I´ll stick with the <bool> array because I need to save memory.
recursion is a bad idea in this case I think, because it eats memory away too quickly, so its lists and vectors.

Thanks again for your time and input, I´ve made a class concept now which looks quite useful :)
Topic archived. No new replies allowed.