Page 1 of 1

Hitting a wall: Sort Sets?

Posted: 15 Dec 2013, 03:06
by probiner
Trying to randomize a mesh PolygonIndex, freeze it and export to another app. I now understand that the underlying problem in this task is something that hits me many times. Really want to nail this one.

Trying to use Create Topo node to basically copy the mesh I want to scramble, just with a different Polygonal Description. PolygonToVertices gives me a set of arrays of each polygon's point order. So I though it would be easy, just had to randomize the order of the Set. But there's how Sort Set with Key like there is to Arrays...
So, Build Array from Set. But this flattens my arrays, from a set:

(0)triangle: [2 3 1]
(1)quad: [2 6 4 3]
(3)pentagon: [1 3 4 0 5]

I get a flatten list:

Object: [2 3 1 2 6 4 3 1 3 4 0 5]

I can't sort this while keeping the indices grouped by polygon. I usually don't have this problem when randomizing the indices themselves, but that's because they are a single values, no grouping involved.

What I want is an array of arrays like:

Object: [[2 3 1] [2 6 4 3] [1 3 4 0 5]]


I looked into 2D Arrays but they look more like Array + Markers and not automatically generated. Still not sortable.

That split string (still single values though) looks more like into what I wanted the array to be.

The image also shows a hand-typed String linked to Create Topo node, but with a new Polygonal Description. It effectively makes the new Topo's PolygonIndex 1 2 0 instead of 0 1 2. I've put it there just to show that It's something that is possible and makes sense. I'm just missing the middle section...

How would you guys do it? I guess I'm lacking some comprehension of Sets, Arrays and how to manipulate them. Or maybe I hit an ICE limitation wall.

Thanks in advance.

Re: Hitting a wall: Sort Sets?

Posted: 17 Dec 2013, 00:11
by probiner
Not very python savy but using the last image as an example made a little thing that basically picks a polygon at random from the the PolygonToVertices list and places it in a new list and then gives me a flat string I can plug on "Create Topo" Node Polygon Description to have my new mesh with new PolygonIndex
Hard for me to believe this is not something straight forward to do in ICE. Well, I'm learning.

I just don't know how to use it inside of Softimage or how to get PolygonsToVertices out of Softimage.

Cheers

Code: Select all


import random

PolyToVertsList=[[2, 3, 1], [2, 6, 4 ,3], [1, 3, 4, 0, 5]] ##PolygonToVertices
RandPolyToVertsList=[]

while (len(PolyToVertsList)>0):
    i=random.randrange(0,len(PolyToVertsList))
    PolyToVertsList[i].append(-1)  ##-1 to close polygon on Create Topo node
    RandPolyToVertsList.extend(PolyToVertsList[i])
    del PolyToVertsList[i]

PoygonalDescriptionString=" ".join(str(x) for x in RandPolyToVertsList) ##String

print PoygonalDescriptionString

Running on repl.it

Re: Hitting a wall: Sort Sets?

Posted: 18 Dec 2013, 04:02
by probiner
Nailed it!
Writing the python code definitely helped to think about it and cook the recipe. Kudos to Guillaume Laforge for insights and tip on Repeat node.
So basically pick from a pile at random and put it on another pile.

Cheers

Re: Hitting a wall: Sort Sets?

Posted: 18 Dec 2013, 05:18
by Bullit
So you wanted the poly ID blocks remained defined by blocks while mixing up the poly IDs. Sort of moving people(poly IDs) around rooms without flattening the rooms as way to still getting them by the room IDs?

But i don't get that from the icetree. In viewport it seems you have 5 groups(rooms) , is this correct?

Re: Hitting a wall: Sort Sets?

Posted: 18 Dec 2013, 16:07
by Chris_TC
I'm almost 100% sure this can be done without a Repeat node because I've built something similar before. To figure out which part of the Polygonal Description you need to read, you can use multiple Select SubArray in Array nodes.

Quick example without having tried it:
ARRAY A: 0,5,4,-2,3,9,8,12,-2,15,16,13,-2 (mesh consists of a triangle, a square, and another triangle)

You would have another array that contains: Get self.PolygonToVertices->Get Array Size->Add "1"->Build Array From Set:
ARRAY B: 4,5,4 (first polygon contains 3 vertices, second one contains 4 vertices, third one contains 3 vertices, and we added 1 to every value).

Now lets say you need to read the third polygon's description. You select the subarray from Array B from index 0 to index 1:
4,5
You build the array sum:
9
You now read array A from index 9 to index 9 + 4 (+4 because the third value in array B is 4):
15,16,13,-2

Re: Hitting a wall: Sort Sets?

Posted: 25 Dec 2013, 07:31
by probiner
@Bullit
It's basically what you said. I wanted to scramble the rooms's door number, not the their contents. Since it's not something set'able in ICE I just make a new polymesh in a new order.
Compounds attached.


@Chris_TC
Thanks for chiming in.
I've had previously wondered of your method and I faced it as working ok to crystallize data and access it later. Seems to me that it's basically what 2D Arrays do. A flat array for the contents and an array bookmarking the index of the last element of the "group". Never tried produce it, though ,because:
- To access n element you alway have to make a sum first of 0 to n elements. Don't know the big O notation here, but I wonder if that won't slow one down when dealing with thousands of polygons.
- For this particular case I would still have to use the Repeat node no? I Have to cycle the sequence of unique random integers to, 1 by 1 copy an array bit, into the new array no? 1 2 3 -2 Repeat, different random polygon, 5 8 7 2 -2. Etc...

I've had no issues randomizing Sets that are composed of Unique elements with the following (pb_RandomizeUniValueSet):
Image
Problems arise when the set is composed of arrays and it's manipulated like a flat array. Also here to add up I wanted to freeze and export them mesh to LightWave; I usually just set data as a ICE attribute and call it when I need.

Cheers

Re: Hitting a wall: Sort Sets?

Posted: 25 Dec 2013, 19:01
by Chris_TC
probiner wrote:- To access n element you alway have to make a sum first of 0 to n elements. Don't know the big O notation here, but I wonder if that won't slow one down when dealing with thousands of polygons.
From what I recall the speed is excellent even on huge meshes. Unfortunately I don't have access to Soft or to my compounds right now, so I can't dig out the one I'm thinking of.
- For this particular case I would still have to use the Repeat node no? I Have to cycle the sequence of unique random integers to, 1 by 1 copy on array bit, into the new array no? 1 2 3 -2 Repeat, different random polygon, 5 8 7 2 -2. Etc...
I can't try this right now, but I think that the Select Subarray in Array accepts array inputs in every port. So you'd just have to build an array of random polygon indexes with Random Value, then feed that into the Select Subarray using the logic I posted.
If that doesn't work, then there should at least be a way to call the Select Subarray in a per-polygon context. I'm pretty sure I've done all this before, and it annoys me that I can't check.

Re: Hitting a wall: Sort Sets?

Posted: 25 Dec 2013, 19:12
by Chris_TC
Chris_TC wrote:there should at least be a way to call the Select Subarray in a per-polygon context.
Just to explain a little more. I would build an array of random polygon indexes, e.g.:
5,2,3,0,4,1

Then I'd do Get self.PolygonIndex -> Find in Array
For example, polygon number 0 would find itself at index 3 in the above array. Then plug this into the Select Subarray. The output of the Select Subarray will be per-polygon, which can then be turned into an array via Build Array From Set. And everything should be good to go without any Repeats.

Re: Hitting a wall: Sort Sets?

Posted: 17 Jan 2014, 09:48
by probiner
Hi Chris I gave this thing another shot to try to do it your way. Here's what I did with what I understood you told me.

Have an object Alike the previous, a tri, a quad and a ngon glued like a cube. It's "PolygonToVertices" (PTV) looks like 415, 2513, 45260. Ok so I "Push on Array" -2 and get: 415-2, 2513-2, 45260-2 (PTV-2)

Now if I want to go the "Select Sub-Array in Array" path, to find the End Index path I PTV-2 > "Build Array from Set" and "Find in Array" -2 and get the array: 3,8,14 . To find the Start Index I subtract the End Index by PTV-2 > "Get Array Size" > minus 1 (3, 4, 5), giving me the Start Index: 0, 4, 9. Randomizing these single value arrays with the same seed will solve the Order bit of the problem.
Now, the problem is that when I plug those 2 arrays End and Start Index on the "Select Sub-Array in Array" it tells me that only takes Integer not Array of Integer.

Image

And I can't seem to find a node that would allow me to use these range Integer Arrays to return a single flat array with new order, because, of course its preventing that the output would have to be an Array of arrays :P
"Find in Array" also doesn't allow Arrays on "Value" input.

Image

So you see I fail to understand how to put that into practice. Are you joined with your SI now to check those things you done previously?

I'm also doing this on a new empty object I assume your posts were though for doing things within the same object, correct?
I think and Array to String node would help, crystallizing the array into a single value, then re-oder it at will and then use the current String to Array. Or more nodes to handle sets like arrays as they sure seem to use an Oder, it just seems that there's no access. "Select in Set" thingy?

Cheers