Sorry if this has come up before. I searched, but did find a previous thread on the topic.
I'm looking for a VOP or instructions for building a VOP network (or something) to provide the unit vector/slope of a best fit line for a local point cloud.
Basically, a linear regression for a set of local points, on a per point basis.
Is there something like this already? If not, could someone help me build it? My math isn't strong enough to build it myself. I found this: http://en.m.wikipedi…Line_Regression [en.m.wikipedi]
If it was even just boiled down into pseudo code, I could probably build the network, but I just don't know how to translate calculus or linear algebra into simple algebra to turn it into code. Any help would be appreciated :-)
Thanks!
3d line fitting for local point cloud
8218 5 2- ben-andersen
- Member
- 47 posts
- Joined: Jan. 2014
- Offline
- animatrix_
- Member
- 4495 posts
- Joined: Feb. 2012
- Offline
I needed the exact thing back when H13 was released. Thanks to SESI for adding numpy, I wrote a Best Fit Line SOP pretty quickly. It works great, but be wary of using it on millions of points as numpy's svd consumes a lot of memory for some reason. I don't think it's a bug though.
I should upload it on Orbolt so it's a one click solution. Here is the code:
import numpy as np
node = hou.pwd()
geo = node.geometry()
p =
for pt in geo.points ( ):
p.append ( pt.position ( ) )
c = np.mean ( p, axis = 0, dtype = np.float64 )
u, s, v = np.linalg.svd ( p - c, full_matrices = False )
geo.addAttrib ( hou.attribType.Global, “bNormal”, v )
geo.addAttrib ( hou.attribType.Global, “bCenter”, c )
Paste it inside a Python SOP, and then reference the normal and center attributes anywhere you want.
I also have one to calculate the Best Fit Plane on Orbolt if you ever need that:
https://www.orbolt.com/asset/animatrix::bestFitPlane::1.00 [orbolt.com]
This one is written in VEX and can run through millions of points without any issues or performance penalties and hardly uses any memory. It uses a different technique though, which is why the difference.
Just recently I used it to have a boat react to the waves of a sea. Using Align SOP is very jittery, especially if the sea is not calm. Getting the Best Fit Plane of the sea bbox'ed by the boat and reorienting the boat worked really well. Just an unusual usage I thought I would mention in the hopes that SESI might add similar functionality to H14. They are very welcome to add mines too if they are feeling tired
I should upload it on Orbolt so it's a one click solution. Here is the code:
import numpy as np
node = hou.pwd()
geo = node.geometry()
p =
for pt in geo.points ( ):
p.append ( pt.position ( ) )
c = np.mean ( p, axis = 0, dtype = np.float64 )
u, s, v = np.linalg.svd ( p - c, full_matrices = False )
geo.addAttrib ( hou.attribType.Global, “bNormal”, v )
geo.addAttrib ( hou.attribType.Global, “bCenter”, c )
Paste it inside a Python SOP, and then reference the normal and center attributes anywhere you want.
I also have one to calculate the Best Fit Plane on Orbolt if you ever need that:
https://www.orbolt.com/asset/animatrix::bestFitPlane::1.00 [orbolt.com]
This one is written in VEX and can run through millions of points without any issues or performance penalties and hardly uses any memory. It uses a different technique though, which is why the difference.
Just recently I used it to have a boat react to the waves of a sea. Using Align SOP is very jittery, especially if the sea is not calm. Getting the Best Fit Plane of the sea bbox'ed by the boat and reorienting the boat worked really well. Just an unusual usage I thought I would mention in the hopes that SESI might add similar functionality to H14. They are very welcome to add mines too if they are feeling tired
Senior FX TD @ Industrial Light & Magic
Get to the NEXT level in Houdini & VEX with Pragmatic VEX! [www.pragmatic-vfx.com]
youtube.com/@pragmaticvfx | patreon.com/animatrix | animatrix2k7.gumroad.com
Get to the NEXT level in Houdini & VEX with Pragmatic VEX! [www.pragmatic-vfx.com]
youtube.com/@pragmaticvfx | patreon.com/animatrix | animatrix2k7.gumroad.com
- ben-andersen
- Member
- 47 posts
- Joined: Jan. 2014
- Offline
This is terrific. Thanks so much! I'll try it out when I get home in a few days :-)
The plane looks like what I need, but does it provide multiple local planes, if the point cloud search radius is smaller than the entire cloud? Is that what those smaller planes in one of your images are?
Thanks again. I really appreciate it.
The plane looks like what I need, but does it provide multiple local planes, if the point cloud search radius is smaller than the entire cloud? Is that what those smaller planes in one of your images are?
Thanks again. I really appreciate it.
- animatrix_
- Member
- 4495 posts
- Joined: Feb. 2012
- Offline
Actually I am not using point cloud functions It uses all points in the input. So if you specify a subset of those using the Group parameter, then it will find the best fit plane of only those points.
Senior FX TD @ Industrial Light & Magic
Get to the NEXT level in Houdini & VEX with Pragmatic VEX! [www.pragmatic-vfx.com]
youtube.com/@pragmaticvfx | patreon.com/animatrix | animatrix2k7.gumroad.com
Get to the NEXT level in Houdini & VEX with Pragmatic VEX! [www.pragmatic-vfx.com]
youtube.com/@pragmaticvfx | patreon.com/animatrix | animatrix2k7.gumroad.com
- edward
- Member
- 7710 posts
- Joined: July 2005
- Offline
- Michael Battcock
- Member
- 30 posts
- Joined: Aug. 2013
- Offline
-
- Quick Links