[Closed] Mini-challenge. Get ordered poly edge loops
i don’t think it’s correct at all…
check the setup:
delete objects
obj = converttopoly (plane width:100 length:100 widthsegs:4 lengthsegs:4)
polyop.setedgeselection obj #all
t1 = timestamp()
global loop_edge = #()
global loop_vert = #()
closed = #()
findLoops obj &loop_edge &loop_vert &closed
t2 = timestamp(); format "Time= %
" (t2-t1)
it makes ONE loop. which is absolutely impossible for this setup
loop is a sequence of points where every one is connected to only one, and it has to keep the same rule in backward direction…
what you make is more like a tree… where the ‘backward rule’ doesn’t work
Please, DenisT, before saying that the routine is not correct, read its conditions: “it’s only valid for unconnected loops, closed or not”
In your example, all is connected and there is more than one solution for it. It’s not a case that my routine cares about.
My routine can be usefull, for example, when you slice a mesh and you need to have the new verts ordered for each ‘sliced section’ of the mesh.
hmm… it changes the rule of the original challenge…
the original task was to find all loops in ANY edge selection…
definitely you can organize your algorithm the way to process ‘isolated loops’ first. but it’s just a step of the solution
I see … I did not quite understand your requirements.
But my routine seems to work fine and fast for its purpose!
I really still don’t understand what do you need…
How many loops should you get in this schema?
- 2 closed unconnected loops? (then 2 valid solutions and 4 edges not used)
- 4 closed loops sharing 1 edge? (then using 4 edges twice in different loops)
And in this other one?
You will need to leave unused edges or share them in different loops.
for picture #1 there two loops minimum…
the algorithm mostly has to solve these loops:
There are two loops on my picture
The algorithm I proposed does solve these cases perfectly. It even gives you the two possible solutions, bridged and unbridged paths
And, if the code is optimized, it is very fast.
I get these results using a modified (fixed) version of the code I posted earlier:
Bridged Paths
#(60, 62, 63, 49, 61, 74, 75, 77, 79, 81, 82, 69, 55, 67, 68, 70)
#(36, 38, 40, 41, 28, 11, 26, 39, 52)
Unbridged Paths
#(60, 61, 49, 63, 62, 74, 75, 77, 79, 81, 82, 68, 67, 55, 69, 70)
#(36, 38, 39, 26, 11, 28, 41, 40, 52)
Here is one of the many “hard cases” to solve. It can be solved, but I can’t figure out a logic for a 1 or 2 passes solution for it.
The challenging part is to pick the correct edge to start.
(
delete objects
obj = converttopoly (plane pos:[0,0,1] length:100 width:100 lengthsegs:6 widthsegs:6 wirecolor:yellow isselected:on)
obj.selectededges = #{8, 11, 23..25, 27..29, 35..37, 39, 41..43, 51..53, 63..64, 66..67}
max modify mode
subobjectlevel = 2
)
If you pick the correct edge to start, then the algorithm I proposed will work it out just perfectly.
I’m not sure, but:
- If I’m not wrong, you do the calculation of ‘neigthbors edges’ for each edge. Perhaps you can do it once at the beginning for all the edges and store the result in an array (you can use some sort of dictionnary, as I’ve done in my routine).
- In your ‘FindHeadTail’ routine, if there aren’t pure ‘tail edges’, chose those with 2 neigthbors in one side.
- Start with one of them, in the opposite direction of this intersection.
- Add a final function for ‘gluing’ loops in these intersection points if needed.
The code I posted is much worse than that, trust me It is just a sketch as proof of concept. But the algorithm does work.
So, the code has many bugs, is redundant, and of course not optimized. Even the algorithm misses a few things, which I’ve found later when working with different scenes. But I think I’ve solved them.
The problem I face is not how to solve it, but how to do it quickly. For example, if the loop is as one of the torus test, we can pick any random edge and that will be fine. But maybe it can’t be done the way I would like and it needs to be analyzed differently. Sometime things are just like that. I haven’t put too much work on it, so I am still not sure whether there is a better/simple approach.
Hi Jorge.
No, the first item wasn’t an improvement of your code (I’m not able to do that), it’s just a way to pre-store neigthbors so you can search for edges that have just 2 connections in one side.
Ah, I misunderstood the comment.
Yes, for figuring out if there are intersections, I just go thru all the edges and if a vertex appears more than twice we have an intersection.