It is currently 22 Oct 2014, 09:56

All times are UTC + 1 hour [ DST ]




Post new topic Reply to topic  [ 9 posts ] 
Author Message
 Post subject: Hitting a wall: Sort Sets?
PostPosted: 15 Dec 2013, 04:06 
Offline
User avatar

Joined: 17 Apr 2013, 11:52
Posts: 106
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.


Attachments:
ArrayOfArrays.png
ArrayOfArrays.png [ 179.34 KiB | Viewed 722 times ]
Top
 Profile  
 
 Post subject: Re: Hitting a wall: Sort Sets?
PostPosted: 17 Dec 2013, 01:11 
Offline
User avatar

Joined: 17 Apr 2013, 11:52
Posts: 106
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:

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


Top
 Profile  
 
 Post subject: Re: Hitting a wall: Sort Sets?
PostPosted: 18 Dec 2013, 05:02 
Offline
User avatar

Joined: 17 Apr 2013, 11:52
Posts: 106
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


Attachments:
RandomPolygonIndexSet.png
RandomPolygonIndexSet.png [ 150.01 KiB | Viewed 630 times ]
Top
 Profile  
 
 Post subject: Re: Hitting a wall: Sort Sets?
PostPosted: 18 Dec 2013, 06:18 
Offline
Moderator

Joined: 24 May 2012, 09:44
Posts: 1550
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?


Top
 Profile  
 
 Post subject: Re: Hitting a wall: Sort Sets?
PostPosted: 18 Dec 2013, 17:07 
Offline

Joined: 22 Mar 2010, 18:43
Posts: 411
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


Top
 Profile  
 
 Post subject: Re: Hitting a wall: Sort Sets?
PostPosted: 25 Dec 2013, 08:31 
Offline
User avatar

Joined: 17 Apr 2013, 11:52
Posts: 106
@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


Attachments:
pb_RandomPolygonIndexSet.0.1.xsicompound [26 KiB]
Downloaded 25 times
pb_RandomUniValueSet.0.1.xsicompound [5.06 KiB]
Downloaded 24 times


Last edited by probiner on 26 Dec 2013, 10:08, edited 1 time in total.
Top
 Profile  
 
 Post subject: Re: Hitting a wall: Sort Sets?
PostPosted: 25 Dec 2013, 20:01 
Offline

Joined: 22 Mar 2010, 18:43
Posts: 411
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.

Quote:
- 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.


Top
 Profile  
 
 Post subject: Re: Hitting a wall: Sort Sets?
PostPosted: 25 Dec 2013, 20:12 
Offline

Joined: 22 Mar 2010, 18:43
Posts: 411
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.


Top
 Profile  
 
 Post subject: Re: Hitting a wall: Sort Sets?
PostPosted: 17 Jan 2014, 10:48 
Offline
User avatar

Joined: 17 Apr 2013, 11:52
Posts: 106
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


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 9 posts ] 

All times are UTC + 1 hour [ DST ]


Who is online

Users browsing this forum: No registered users and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group