vop sop: getting the average of all points

   19249   13   2
User Avatar
Member
150 posts
Joined: Nov. 2013
Offline
so far I understand the average node computes an average of multiple inputs. every point with the input. what I need is the average of all points.

general speaking, how one would work on the whole set of components?
http://www.sekowfx.com [www.sekowfx.com]
User Avatar
Member
2722 posts
Joined: Feb. 2012
Offline
At the VOP level, you would have to loop yourself, and make sure to set Run Over to Detail mode.

Or easier to do it in VEX:

vector computeCenter ( )
{
int count = npoints ( 0 );
vector center = 0;
for ( int i = 0; i < count; ++i )
{
vector p = point ( 0, “P”, i );
center += p;
}
return center / count;
}

These will not be very fast though.


A better way IMO is to use Set Attribute VOP or setattrib function to add a detail attribute value (Merge Mode: Add).

Then using another SOP you would have to divide this value.
Senior FX TD @ Industrial Light & Magic

Get to the NEXT level in Houdini and VEX with Pragmatic VEX! [www.pragmatic-vfx.com]
patreon.com/animatrix | gumroad.com/animatrixx | vimeo.com/animatrix3d
User Avatar
Member
207 posts
Joined:
Offline
One thing I do kind of miss coming from ICE (having not found an equivalent in VEX) are the Statistics nodes (min/max/average/sum/product).

The AttribPromote Sop will easily compute the average of the entire point set if you promote the Point attribute to a Detail attribute, but design-wise it requires that you break your graph in to sections if you ever need to compute the average of the entire point-set in what would be the middle of a graph.

-T
User Avatar
Member
150 posts
Joined: Nov. 2013
Offline
thanks todd.
http://www.sekowfx.com [www.sekowfx.com]
User Avatar
Member
1744 posts
Joined: Oct. 2010
Offline
dependnig on what you are trying to do, it may be also useful to use the point cloud vop nodes.

http://www.sidefx.com/docs/houdini13.0/nodes/vop/pcopen [sidefx.com]

the advantage on these is that they are really fast if you only are looking for weighted average data withing a radius.
-G
User Avatar
Member
150 posts
Joined: Nov. 2013
Offline
grayOlorin
dependnig on what you are trying to do, it may be also useful to use the point cloud vop nodes.

http://www.sidefx.com/docs/houdini13.0/nodes/vop/pcopen [sidefx.com]

the advantage on these is that they are really fast if you only are looking for weighted average data withing a radius.

I'll check that one out, but it feels a bit to much for what I am trying to do.
I just want to add up all Positions and divide them by there ptnum.

In ICE you are able to work on the whole point set of an object.
So one can average (sum, min, max…) the whole point position set.
In vops yo are limited to just individual points, so it seems. Please correct me if I am wrong.
http://www.sekowfx.com [www.sekowfx.com]
User Avatar
Member
1744 posts
Joined: Oct. 2010
Offline
Yes, but it is that way foe an important reason, the vex/vop contexts run in a highly multithreaded single instruction multiple data (simd) archittexture, which is why is so fast. Its a very important advantage as it allows for processing of massive data (ie scan data) in a fraction of time

Fir doing operations on all points against each other (ie statistics), I feel in most cases regular operators (sops, pops, etc ) are better. You can also extend quite a bit with python nodes which even allow you to use snippets of inline cpp code (see inlinecpp module) numpy us also available with hou

For average of all points , you can also add a vector detail attribute and set each axis to this expression:

Centroid(“../youroperator”, D_X)
Centroid(“../youroperator”, D_Y)
Centroid(“../youroperator”, D_Z)

For things like sum, attribVOP is the way to go (since you can simd that). Check out the setAttribute VOP

For weighted averages or thongs of the sort, point cloud VOPs are awesome and fast

For other things , attribPromote and python operators (ie python snippets) are very easy

I guess the reason there is not a single node is that you would do each statistic operation in one way or another for speed and versatility but remember you can always make your own statistics digital asset for yourself (or share it in orbolt store). I have made my own l1 median it is important to remember that ICE == SOPS and VOPs, not just VOPS

Hopes this helps!





Centroid(
-G
User Avatar
Member
1744 posts
Joined: Oct. 2010
Offline
Oops centroid is lowercase c phone keyboard…
-G
User Avatar
Member
150 posts
Joined: Nov. 2013
Offline
This is helping a lot. Thanks for the comprehensive insight.
http://www.sekowfx.com [www.sekowfx.com]
User Avatar
Member
10584 posts
Joined: July 2005
Offline
FYI, you can AttribPromote SOP to a detail attribute to do this simply.
jason iversen, pipeline technology supervisor @ weta digital
also, http://www.odforce.net [www.odforce.net]
User Avatar
Member
1388 posts
Joined: July 2005
Offline
In Vops, use Bounding Box Vop, to compute centroid (centroid = min+(max-min)/2). Neither that nor centroid() expression will give an average of positions though. They both are center of bounding box, which is not the same thing.


edit: there is pointavg() [sidefx.com] expression also.
Edited by - April 27, 2014 08:15:13
User Avatar
Member
150 posts
Joined: Nov. 2013
Offline
i understand that i have to leave my comfort zone, having one tree setups.
thats the way houdini works, still looking for the benefit ;P.
I will get there, eventually.
http://www.sekowfx.com [www.sekowfx.com]
User Avatar
Member
1388 posts
Joined: July 2005
Offline
pusat
Or easier to do it in VEX:
vector computeCenter ( )
{
(…)
}

These will not be very fast though.

I would say this code has a good chance to have comparable performance with C++ node, but apparently not (it's ~x3.5 slower from AttributePromote in average mode, which is not bad, as it's still bellow a second for 5mil points, but still…).

Pure speculation here, but this is probably due to point()/import() functions which force atomic access to the attribute's array and per element compute (bye bye simd), unlike HDK which has these days very cache/simd friendly batch access to attributes. Looks like llvm/vex doesn't do its best here.

I think avg() on a big array of x, y, z's might be a way faster, but costs creating such an array doesn't make any sense. VEX functions like min(string attr)/max(string attr)/avg(string attr) would be helpful.
User Avatar
Member
2722 posts
Joined: Feb. 2012
Offline
SYmek
I would say this code has a good chance to have comparable performance with C++ node, but apparently not (it's ~x3.5 slower from AttributePromote in average mode, which is not bad, as it's still bellow a second for 5mil points, but still…).

Pure speculation here, but this is probably due to point()/import() functions which force atomic access to the attribute's array and per element compute (bye bye simd), unlike HDK which has these days very cache/simd friendly batch access to attributes. Looks like llvm/vex doesn't do its best here.

I think avg() on a big array of x, y, z's might be a way faster, but costs creating such an array doesn't make any sense. VEX functions like min(string attr)/max(string attr)/avg(string attr) would be helpful.

This is actually a case even Python have comparable performance to VEX. From what SESI told me the point() vex function is written expecting to be able to amortize setup time across many procs, and a function like point_many that let you fetch a batch of points at once, returning the result in a VEX array would make it a lot faster.

So if we have point_many, prim_many functions in addition to min(vector array), max(vector array), avg(vector array), etc it would be extremely useful.

Please submit an RFE if you would like to see this
Senior FX TD @ Industrial Light & Magic

Get to the NEXT level in Houdini and VEX with Pragmatic VEX! [www.pragmatic-vfx.com]
patreon.com/animatrix | gumroad.com/animatrixx | vimeo.com/animatrix3d
  • Quick Links