Jump to content

Recommended Posts

Andrew Kant    0

I'm still a novice in Houdini. Help me understand how to swap the rows and columns of primitive indices. It is necessary that I can rotate the indexes, as shown in blue.

Снимок.JPG

Share this post


Link to post
Share on other sites
Atom    516

Try dropping down a Sort node and place it in Shift mode. Then you can offset primitives with the slider.

Edited by Atom

Share this post


Link to post
Share on other sites
Andrew Kant    0
1 hour ago, Atom said:

Try dropping down a Sort node and place it in Shift mode. Then you can offset primitives with the slider.

Sort Node gives the wrong result. I do not need to shift the indexes, but rotate them 90 degrees. Node Sort works well with Grid, you can specify which axis to build columns, but for the torus it does not fit. I think that this can be implemented in the VOP. But I do not know.
Edited by Andrew Kant

Share this post


Link to post
Share on other sites
f1480187    454

Compute index attribute:

// Primitive wrangle.
int rows = chi("../torus1/rows");
int cols = chi("../torus1/cols");
i@index = @primnum % cols * rows + @primnum / cols;

Then Sort by attribute:

swap_rows_cols.png.87eafc35a9004283057455a563339bd0.png

swap_rows_cols.hipnc

 

By the way, this is reshape and transposition. Not 90 degree rotation:

| 0  1  2  3  4  5|
| 6  7  8  9 10 11|
|12 13 14 15 16 17|

| 0  3  6  9 12 15|
| 1  4  7 10 13 16|
| 2  5  8 11 14 17|

 

Edited by f1480187
  • Like 1
  • Thanks 1

Share this post


Link to post
Share on other sites
Andrew Kant    0
1 hour ago, f1480187 said:

Compute index attribute:


// Primitive wrangle.
int rows = chi("../torus1/rows");
int cols = chi("../torus1/cols");
i@index = @primnum % cols * rows + @primnum / cols;

Then Sort by attribute:

swap_rows_cols.png.87eafc35a9004283057455a563339bd0.png

swap_rows_cols.hipnc

 

By the way, this is reshape and transposition. Not 90 degree rotation:


| 0  1  2  3  4  5|
| 6  7  8  9 10 11|
|12 13 14 15 16 17|

| 0  3  6  9 12 15|
| 1  4  7 10 13 16|
| 2  5  8 11 14 17|

 

Many thanks! That's exactly what I wanted. I was also advised to use the Transpose node. Can you know how you can apply it for this task?

Share this post


Link to post
Share on other sites
f1480187    454

It's limited to Houdini's native 2×2, 3×3 and 4×4 matrices, and it probably used for shading and 3D transformation tasks. We can't really use it to transpose r×c matrix. Simple numerical algorithm in VEX did the job too.

 

For the sake of completeness, to work with arbitrary-sized matrices in Houdini use numpy:

import numpy as np

rows = hou.evalParm('../torus1/rows')
cols = hou.evalParm('../torus1/cols')

# Make initial matrix representation.
old_sort = np.arange(rows * cols).reshape(rows, cols)

# Reshape and transpose.
new_sort = old_sort.reshape(cols, rows).T

# Make index attribute.
node = hou.pwd()
geo = node.geometry()
geo.addAttrib(hou.attribType.Prim, 'index', -1)
geo.setPrimIntAttribValues('index', new_sort.ravel())

 

swap_rows_cols_python.hipnc

  • Thanks 1

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×