### Houdini attributes

9446   13   4
Member
10 posts
Joined: Aug. 2017
Offline
Hi guys..!
I'm new to Houdini so can anyone can help me
with my problems,
I'm getting confused in
1) what is float ?
2) what is integer ?
3) what is vector ?
vfx
Member
408 posts
Joined: July 2013
Offline
1. float is a number with a decimal portion
2. integer is a whole number without a decimal portion
3. vector is a structure comprised of 3 floats.
Houdini Indie
Redshift 3D
Member
74 posts
Joined: March 2016
Offline
I'd recommend you do the Algebra basics course on Khan Academy whilst learning Houdini. If only to refresh your mind on the stuff you learned at school.

And this course on Vector Match for 3d artists is really helpful too.

Vector Math for 3d Artists [chortle.ccsu.edu]
Edited by Jonathan Moore2 - Aug. 9, 2017 11:50:34
Member
1743 posts
Joined: March 2012
Offline
Expanding on Daryl Dunlap's nice quick response,

1) what is float ?
A “float” (or floating-point number) is any real number, but represented with finite precision (usually either 32 or 64 bits, though sometimes 16 bits). One thing to note about floats that surprises a lot of people is that many numbers that look simple in decimal, like 0.1, are not exactly that value when represented in floating-point, so you have to be careful when checking whether two float values are equal, to instead check if they're approximately equal. You might have to be careful about accumulating roundoff error in some cases, too.

2) what is integer ?
An integer is a counting number or the negative of one, so …, -3, -2, -1, 0, 1, 2, 3, … They are usually either 32 or 64 bits, so their range is limited, but that's usually not a big issue.

3) what is vector ?
In Houdini, a vector is 3 floats, usually representing values corresponding with x, y, and z, though there are often vectors whose values correspond with red, green, and blue colour components. It's all up to how the values are used.

One additional meaning of vector in Houdini is a little closer to a more mathematical view of vectors, namely a direction and magnitude: attributes that are marked as transforming like a vector, (you can set this in the Attribute Create SOP with the second drop-down next to Type), will be rotated and scaled, but not translated, when they're transformed. The velocity attribute, named `v`, is normally set to transform like a vector (noted by Vec in the middle-mouse-button dialog), whereas `P`is set to transform like positions (rotated, scaled, and translated; Pos in the middle-mouse-button dialog), `N`is set to transform like normals (rotated and inverse-scaled, then normalized; Nml in the middle-mouse-button dialog). Most other 3-float attributes, by default, are not transformed when transformations occur.
Writing code for fun and profit since... 2005? Wow, I'm getting old.
Staff
3452 posts
Joined: July 2005
Offline
ndickson
One thing to note about floats that surprises a lot of people is that many numbers that look simple in decimal, like 0.1, are not exactly that value when represented in floating-point

to add the what Neil said,
sometimes a parameter will have a value like this: 1.77636e-15
this is zero (0) in float
you can safely make these 0 manually.
Michael Goldfarb | www.odforce.net
SideFX
www.sidefx.com
Member
10 posts
Joined: Aug. 2017
Offline
Edited by deadpool111 - Aug. 12, 2017 01:36:55
vfx
Member
29 posts
Joined: June 2015
Offline
goldfarb
ndickson
One thing to note about floats that surprises a lot of people is that many numbers that look simple in decimal, like 0.1, are not exactly that value when represented in floating-point

to add the what Neil said,
sometimes a parameter will have a value like this: 1.77636e-15
this is zero (0) in float
you can safely make these 0 manually.

how?
Member
6790 posts
Joined: Sept. 2011
Offline
I'm not sure what @goldfarb meant. Maybe he meant that the values are small enough that they are zero for all intents and purposes.

Member
838 posts
Joined: Feb. 2016
Offline
goldfarb
ndickson
One thing to note about floats that surprises a lot of people is that many numbers that look simple in decimal, like 0.1, are not exactly that value when represented in floating-point

to add the what Neil said,
sometimes a parameter will have a value like this: 1.77636e-15
this is zero (0) in float
you can safely make these 0 manually.

let's pretend that that “weird” number is a value of point attribute @P.y

I then add a vex wrangle with the following ‘if statement’:
if (@P.y == 0) {removepoint(0, @ptnum);}

will the point with that weird number be removed?
Edited by Andr - Oct. 4, 2018 04:51:52
Member
838 posts
Joined: Feb. 2016
Offline
Talking about working with vectors, I noticed this strange thing:

v@myVector = set(1,2,3);
@N = @myVector; // @N is set correctly to (1,2,3). @N and @myVector are created in the same context (same wrangle)

Now add another wrangle to the one just created and re-assign @N to @myVector:
@N = @myVector; // @N is set now to (1,1,1) !! Only the first component is read.

Is Houdini no more aware that @myVector is a vector?
To fix that, you have to specify that it is a vector. @N = v@myVector; works indeed.

That took me a lot of time to figure out the first time, when I was going crazy with not being able to assign any vector attribute to N.

Is this a bug or is there any deeper reason on how Houdini works behind the scene that would explain this behavior?

I attached an example file
Cheers

Attachments:
Q_vectorAssignement.hiplc (49.1 KB)

Member
59 posts
Joined: April 2018
Offline
Andr
let's pretend that that “weird” number is a value of point attribute @P.y

I then add a vex wrangle with the following ‘if statement’:
if (@P.y == 0) {removepoint(0, @ptnum);}

will the point with that weird number be removed?
In this case, no. Generally, float comparisons can behave unintuitively because of rounding errors. The following approach is a reasonable solution for many cases, and will indeed work as expected in your example, by testing if the value is acceptably near zero:

```#define EPSILON 1e-8
if (abs(@P.y) < EPSILON) { removepoint(0, @ptnum); }
```

<math.h> also defines TOLERANCE to be 0.0001, which I guess may be being used in a similar way.

For more on this topic, this site [floating-point-gui.de] has very useful information.
Member
1743 posts
Joined: March 2012
Offline
Andr
v@myVector = set(1,2,3);
@N = @myVector; // @N is set correctly to (1,2,3). @N and @myVector are created in the same context (same wrangle)

Now add another wrangle to the one just created and re-assign @N to @myVector:
@N = @myVector; // @N is set now to (1,1,1) !! Only the first component is read.

Is Houdini no more aware that @myVector is a vector?
To fix that, you have to specify that it is a vector. @N = v@myVector; works indeed.
By default, if it's not specified in at least one place in the wrangle with a prefix or an explicit declaration like `vector @myVector;`Attribute Wrangle's VEX code will assume that attributes are single float values, except for a few hardcoded ones with different default assumptions, (for example, `@P, @N, @v, @Cd, @up,`will be assumed to be vector, `@id`will be assumed to be an integer, and `@orient`will be assumed to be a vector4, among others.) If you're not sure, it's always best to be on the safe side.

The reason that it can't just dynamically figure out attribute types as they come in is a bit technical, but in a nutshell, the VEX code needs to know what types it's dealing with before it actually receives any input data. When it eventually gets input data, if the types mismatch, it needs to convert to whatever type VEX already chose. In concept, it could recompile the VEX code if there are mismatched bindings, but that would be quite complicated to manage internally and would have behavioural/compatibility consequences that might not always be what people expect.
Writing code for fun and profit since... 2005? Wow, I'm getting old.
Member
1941 posts
Joined: Sept. 2015
Offline

let's pretend that that “weird” number is a value of point attribute @P.y

if (@P.y == 0) {removepoint(0, @ptnum);}

One way to do deal with it is to think about the context then adjust your logic of the code. In other words, how did this number come close to 0 but isn't quite there.

The question would be, do you need it at 0 or is it something that you want that might be close to 0.

Your code could deal with it a number of ways, depending on what you want(the below examples not neccesarily giving the same results):

`if (@P.y == 0) {removepoint(0, @ptnum);}orif (@P.y >= 0) {removepoint(0, @ptnum);}orif (@P.y >= 0) {removepoint(0, @ptnum);}orif( (@P.y !> 0) && (@P.y !< 0) )  {removepoint(0, @ptnum);}`
Edited by BabaJ - Oct. 4, 2018 13:22:06
Member
838 posts
Joined: Feb. 2016
Offline
forgot to say thanks to you all guys for the explaining and advising!

cheers