Loop Selections

Become a member of the CGSociety

Connect, Share, and Learn with our Large Growing CG Art Community. It's Free!

Thread Tools Search this Thread Display Modes
  07 July 2014
Loop Selections

I'm looking for code that shows how to do loop selections in C++.
I code mostly for Cinema4D. But I think I can convert code that's in Maya or other apps format.

The main problem I'm having is that polygons don't follow a static set of shared edges. They are often spun randomly.
For example. The b-c edge on one polygon is not always the shared a-b edge in the neighboring polygon. They don't always follow as set pattern. So I can't just simply select all of the a-b edges to get a loop selection from it.

Is there a standard loop selection type of code that all of the 3D programs use?
This seems like something that all graphics programmers would have in their tool box. But I can't seem to find one with Google.

My Gallery
  07 July 2014
There are many ways to do it, and what results you get depends on how you want to deal with fringe cases, how diminutive or extensive you want them to be and so on.
In every app you can see loops selecting somewhat differently when they reach poles and so on, and that's because they use different rule-sets and handle fringes and termination differently.

The absolute simplest way to do loops is to treat your edges as directional vectors (normalized) and use a dot product on the neighbourhood, and pick the most parallel one, and keep doing it until the original edge is met in the neighbourhood look-up (loop is closed).
For simple topologies this will work just fine, say loops around a cylinder, but with no additional handling for some perfectly legal topos a skewed angle will send it crawling all over the mesh.

Ultimately the principle is the same, look up connected edges, apply rule, move on until terminal condition (first edge met, boundary met, non manifold spot, whatever you decide the terminator to be).

Other rules to bias the pick of the next edge could be to weigh the fan, so if two edges come very close in parallel value but one is in the middle of the fanned neighbourhood projected on the current point's normal you will pick the one with better bisecting index (in the middle of a fan of N connected elements).

You can also choose to use boundaries as terminators, or to given them very high weight if your originator is also a boundary (this way the edgeloop tool becomes a hole/boundary selection tool as well) and so on.

Arbitrarily connected topologies don't have any parametric qualities to them, so there is no best or universally accepted way to do edge loops, only many different ways to interpret the connectivity and heuristically (guesswork) get decent coherence out of it.
Come, Join the Cult http://www.cultofrig.com - Rigging from First Principles
  07 July 2014
Actually the simplest method is simply to do a ring selection then pick a side and use that for your loop selection, fewer calculations all round, and the result is a guaranteed loop without deviation due to direction (a parallel edge is not a guarantee of parallel flow), points often have multiple edges emanating, but edges typically belong to only one or two polygons.

It's a fairly trivial task in Cinema (ignoring the inbuilt functions that already give you this), simply pick your edge, get the next edge along in the polygon (perpendicular), this is your first ring edge, then calculate the ring by stepping to the opposite (left or right depending on the previous loop edge shared point), use the Neighbor class to get the next polygon from the edge, rinse and repeat till you either run out of opposite edges or hit an edge that's already been used. The algorithm will work in any 3D application, although not all apps have equivalents of the neighbor class built in to their API's in which case you will need to create your own lookup maps.
The Third Party | Homepage | My Reel
"You need to know what you're doing before you start, and to start because you need what you're doing."
  07 July 2014
It's not trivial for me.
I can't figure out the proper questions to ask. And how to solve them in my code.
All I really want is to be able to select the neighboring point (right,left,up,or down) from the currently selected point/points. And so on ...every time I run the code.
I basically need a clamped edge loop that stops when it finds the first neighboring point along an edge in a specific direction.
Basically, taking edge loop code and adding a break to it's loop.

So far I've done it two ways which are not working very good.
I used angles and point distances to find the closest points. Then select the point if it falls with a range.
This is horribly complicated and I'm still not getting the proper results from it.

I use the neighbor class in C4D on the selected polygons to get the neighboring polygons.
This class has a function called GetPolyInfo() which lets me select the neighboring polygons.
There's an option in it which lets me grab the right[2], left[1], up[0], down[3] neighbor polygon.
It's really nice because it selects the same edge even if the polygons are spun in various ways.
And then I get the point I want to select (a,b,c,d) from that neighbor polygon I selected.
This works fairly well. And I can make a loop selection by running the code multiple times(which is how I want it to work).
But there's a problem with this...I don't want to have to select a polygon. I want to select a point and then get it's neighbor (right, left,top bottom) every time I run it. Resulting in a point loop selection.

I can get the neighboring points, edges, and polygons.
But I don't know how to filter them to get the specific ones so that I can create a loop selection in a specific direction if I keep executing the code.

The reason I want this is because I'd like to grow select in points mode in only one direction. And C4D doesn't have that option.
The grow select tool selects the neighboring points in all directions.

My Gallery
  07 July 2014
If you're talking the specifics of the C4D API, then you will also find the Neighbor class offers GetEdgePolys, GetNeighbor (the manifold opposite edge to the passed poly along the passed edge) and GetPointPolys, but it does not have GetPointEdges. For you to calculate the edges radiating from a point you must then call GetPointPolys, iterate through the passed array of polygons, find the edges that contain your point and do whatever you need to with them.

However, you do not need to do that if you use the edge ring method. In that instance you simply use the GetNeighbor or GetEdgePolys functions to return the opposite polygon to the edge that you're on, then use the NGon functions to retrieve the full NGon index (as the Neighbor class standard functions deal with the simplified quads and tri's), increase the edge index in the polygon + 2 (or -2 depending on the side being used), and rinse and repeat. You can then determine how you wish to handle poles. The side + or - 2 is always onwards, rather than backwards, you only need to calculate for yourself which side of the ring edge the loop is on to make sure you carry on in the right direction, and that's just a matter of comparing the point indexes.
The Third Party | Homepage | My Reel
"You need to know what you're doing before you start, and to start because you need what you're doing."
  07 July 2014
I might be misunderstanding what you're saying. But I'd rather not use the edge ring method.

I'm able to get the polygons that the point belongs to. Using the GetPointPolys() function. And also with my own custom code that I dreamed up too.
But I just can't figure out how to select the neighboring point in a specific direction. It's frustrating to know how to use all of this code and still be stuck on something that seems like it should be very simple to do.
I was hoping that if I saw some loop selection code. Any code, in any language, in any app. That it might show me what I'm missing.

My Gallery

Last edited by Scott Ayers : 07 July 2014 at 11:39 PM.
reply share thread

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Society of Digital Artists

Powered by vBulletin
Copyright 2000 - 2006,
Jelsoft Enterprises Ltd.
Minimize Ads
Forum Jump

All times are GMT. The time now is 05:04 PM.

Powered by vBulletin
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.