Sort expressions

   11834   8   1
User Avatar
Member
519 posts
Joined:
Offline
I have broken up a curve of polygons into single polygons. In this process the order of the polygons got mixed up (curve starts with primitive 0, then 5, then 2 etc.). I added a connectivity sop so the curves now have in the proper order the $CLASS attribute/variable. How can I use it in a sort SOP? I didn't find any Hscript commands to set the primitive number and the sort expression slider seems strange for adding expressions…(why is there a slider and not just a blank line for the expression?)


Pagefan
User Avatar
Member
665 posts
Joined: July 2005
Offline
The Sort SOP should contain a drop down menu with a Sort by Expression field…

In the Expression field you can enter in $CLASS and the sop should use that as a reference to order your prims.
User Avatar
Member
519 posts
Joined:
Offline
Well seems that trick didn't work. I opened the spreadsheet on the connectivity SOP and it did add the class-attribute but in such a way that sort can't do anything with it
primitive class
0 0
1 1
2 2
3 3
etc…

My primitives are ordered like this 0 4 1 5 2 6 3 7 (aka it's a real mess). So when adding the $CLASS in the sort SOP the primitive order stays the same. I was hoping the connectivity SOP would number the polys in sequential order of “connectedness”.

I guess I am missing something very obvious here, knowing Houdini there must be a very simple way to get this done…
User Avatar
Member
7709 posts
Joined: July 2005
Offline
In your Connectivity SOP, make sure that you're creating a primitive attribute. This is not the default. Then in the Sort SOP, make sure you're sorting by primitives and not points.
User Avatar
Member
519 posts
Joined:
Offline
I am sorry but maybe I didn't explain properly. I made a little DA that cuts up a polygon curve in single polygons (add SOP in one branch and a delete + add SOP in another branch then both branches are wired into a merge SOP).

During this process the order of the primitive numbering changes. In the single add branch I get, for example, polygons 0 till 5, in the del+add-branch I get another set of polygons 0-6. In the merge SOP you now have 12 polygons but their order is like 0 5 1 6 2 7 etc. Now I add a connectivity SOP and it does add the class-attribute (and makes the variable class, mapped to $CLASS) but the value of class is the same as the unsorted primitive number. When you use a sort SOP then it will probably do something but the result is nil, my primitive numbering is still messy.

I hope this makes things a bit more clear. If not I can post the file tomorrow.

Pagefan
User Avatar
Member
7709 posts
Joined: July 2005
Offline
Ok, so you don't need/want a Connectivity SOP at all. My first thought is that if you were careful in how you ordered the inputs of the Merge SOP in the first place, then the primitive ordering would probably work fine without any fancy sorting.

In anycase, let's suppose you were given such geometry, had no control over how it was generated, and needed to sort them by point number. Then here's one way you can do it:
- Append an AttribCreate SOP. Name = ptnum, Value = $PT
- Append an AttribPromote SOP. Original Name = ptnum, New Class = Primitive, Promotion Method = Minimum.
- Append a Sort SOP. Primitive Sort = By Expression, Expression = $PTNUM

There might be easier ways but that's the first one that came to my mind.
User Avatar
Member
7709 posts
Joined: July 2005
Offline
Pagefan
I made a little DA that cuts up a polygon curve in single polygons (add SOP in one branch and a delete + add SOP in another branch then both branches are wired into a merge SOP).

BTW, I'm not sure if need anything more than just 1 Add SOP and 1 Facet SOP to do this if you have a polygon curve primitive. In the Add SOP, first turn on Delete Geometry But Keep the Points on the first parameter tab. Then in the second parameter tab, create say 12 primitives. For each primitive you do something like: 0-5, 5-10, 10-14, etc. Then you append a Facet SOP with Unique Points turned on to separate each curve primitive. And there's no sorting needed either.
User Avatar
Member
321 posts
Joined: July 2005
Offline
Pagefan
My primitives are ordered like this: 0 4 1 5 2 6 3 7 (aka it's a real mess). So when adding the $CLASS in the sort SOP the primitive order stays the same. I was hoping the connectivity SOP would number the polys in sequential order of “connectedness”.
Well, your primitives are actually ordered 0 1 2 3 4 5, but they're *positioned* 0 4 1 5 … Connectivity (iirc) doesn't really pay attention to position, it just goes down the list and sees if current element is connected to previous element. So if you want to reorder them so that they're join'able, you need to figure out how to convert the position information back into order-in-list information. For example, sort-by-x assumes they're all sequential on the X axis, and sorts by that. But if your original curve goes all over the place, there's no way to leverage that.

However, given that your curve is cut up into pieces, I see two choices: 1) pre-set an attribute *before* you cut them up, thereby encoding the original order into the cut-up data and then key off of that in your sort, or 2) assuming that when you cut them up that the ends are still near each other, use a facet sop to consolidate points, increasing the radius until common ends are joined. At that point, the other response regarding addAttribute and attributePromote should work.
– Antoine
Antoine Durr
Floq FX
antoine@floqfx.com
_________________
User Avatar
Member
519 posts
Joined:
Offline
thanks for the all the tips. The attribcreate trick did it and works like a charm . No need for the attribpromote sop though. I included the file.

Did try the add-facet SOP approach but that didn't produce the result I wanted; the add SOP doesn't lend itself for much scripting and since I want to make a DA, I don't know beforehand how many polygons I need to create.

Pagefan

Attachments:
polyzap.hipnc (165.6 KB)

  • Quick Links