Hey,
I have points with the following attributes values:
1,1,7,7,7,7,8,8,10.
I'd like to remap this values to start from 0 and increase by one as follow:
0,0,1,1,1,1,2,2,3
It looks to me like creating a loop which cycle 10 times and check if an attribute of the given iteration exists, if it does it creates new one with the value of the current counter. My question is what is the easiest way I can get that? Vex? Python? I can't get to any decent result in expresions or/and SOPs? Any idea will be really helpful.
thanks
kuba
remap attribute values
6468 6 3- kuba
- Member
- 345 posts
- Joined:
- Offline
- pbowmar
- Member
- 7028 posts
- Joined: July 2005
- Offline
- symek
- Member
- 1390 posts
- Joined: July 2005
- Offline
In python this would be like this:
points = hou.pwd().geometry().points()
for item in range(len(points)):
attr = points.attribValue(“attr”)
attr_p = points.attribValue(“attr”)
remapped = points.attribValue(“remapped”)
if attr != attr_p:
points.setAttribValue(“remapped”, remapped + 1)
else:
points.setAttribValue(“remapped”, remapped)
It assumes an existence of two point's attributes: attr and remapped. Remapped counts changes in attrs.
Theoretically this code is perfectly repeatable in VEX, but for me it doesn't work. Perhaps due to the SIMD nature, or I just did stupid mistake:
sop
remap()
{
float attr;
float attr_p;
float remapped;
import(“attr”, attr, 0);
import(“attr”, attr_p, 0, ptnum - 1);
import(“remapped”, remapped, 0, ptnum -1 );
if ( attr != attr_p ) {
addattribute(“remapped”, remapped + 1);
}
else {
addattribute(“remapped”, remapped);
}
}
hope this help,
sy.
points = hou.pwd().geometry().points()
for item in range(len(points)):
attr = points.attribValue(“attr”)
attr_p = points.attribValue(“attr”)
remapped = points.attribValue(“remapped”)
if attr != attr_p:
points.setAttribValue(“remapped”, remapped + 1)
else:
points.setAttribValue(“remapped”, remapped)
It assumes an existence of two point's attributes: attr and remapped. Remapped counts changes in attrs.
Theoretically this code is perfectly repeatable in VEX, but for me it doesn't work. Perhaps due to the SIMD nature, or I just did stupid mistake:
sop
remap()
{
float attr;
float attr_p;
float remapped;
import(“attr”, attr, 0);
import(“attr”, attr_p, 0, ptnum - 1);
import(“remapped”, remapped, 0, ptnum -1 );
if ( attr != attr_p ) {
addattribute(“remapped”, remapped + 1);
}
else {
addattribute(“remapped”, remapped);
}
}
hope this help,
sy.
- kuba
- Member
- 345 posts
- Joined:
- Offline
Hey there thanks and sorry for a delay,
Szymon, tried the python, I am probably doing something wrong, in python shell I am getting following error:
File “<console>”, line 8, in <module>
File “csidefx/HOUDIN~1.794/houdini/scripts/python\hou.py”, line 20059, in setAttribValue
return _hou.Point_setAttribValue(*args)
GeometryPermissionError: Geometry is read-only.
Don't understand what might be wrong with permission errors. Do you have any idea.
kuba
Szymon, tried the python, I am probably doing something wrong, in python shell I am getting following error:
File “<console>”, line 8, in <module>
File “csidefx/HOUDIN~1.794/houdini/scripts/python\hou.py”, line 20059, in setAttribValue
return _hou.Point_setAttribValue(*args)
GeometryPermissionError: Geometry is read-only.
Don't understand what might be wrong with permission errors. Do you have any idea.
kuba
- symek
- Member
- 1390 posts
- Joined: July 2005
- Offline
- kuba
- Member
- 345 posts
- Joined:
- Offline
- Antoine Durr
- Member
- 321 posts
- Joined: July 2005
- Offline
kuba
Hey,
I have points with the following attributes values:
1,1,7,7,7,7,8,8,10.
I'd like to remap this values to start from 0 and increase by one as follow:
0,0,1,1,1,1,2,2,3
It looks to me like creating a loop which cycle 10 times and check if an attribute of the given iteration exists, if it does it creates new one with the value of the current counter. My question is what is the easiest way I can get that? Vex? Python? I can't get to any decent result in expresions or/and SOPs? Any idea will be really helpful.
thanks
kuba
I've done this kind of thing with CHOPs. You need one expression CHOP, that given the input curve above, generates a 1 whenever the value changes, and 0 otherwise. Then run the output into the area CHOP, and you will have a new curve that increments every time the underlying data changes.
The expression CHOP needs a couple of ic() calls (or one of the variants – don't have Houdini in front of me) inside an if() function. You get the input value at the previous frame and compare it against the current frame, returning one or zero accordingly.
If you don't feel like messing with CHOPs, you could try the partition SOP, making a separate group for each batch. The group number then is your new incremental value. A foreach SOP could then delete everything but that group on each iteration, and reset another attribute value with the opdigits() of the group name.
– Antoine
-
- Quick Links