Jump to content
Masoud

How can I find the center of cluster points?

Recommended Posts

Hi;

As you can see in the image below, I scattered clusters of some points. How can I find the center of each cluster( each colony.)?

 

Thanks for helping.

CenterOfEachColoni_01.hip

Colony.jpg

Edited by Masoud

Share this post


Link to post
Share on other sites
13 minutes ago, Wooshum said:

You could use pcfilter to easily get an approximation of the center of the cluster. Within the if statement:


vector center = pcfilter(pcloud, "P")

see: https://www.sidefx.com/docs/houdini/vex/functions/pcfilter.html

Given the function weights according to the location of the search point it would not be an exact center.


I think it gives me only the position of each point.

Share this post


Link to post
Share on other sites

The pcfilter function will return the filtered (blurred, averaged, etc) positional value (or any attribute value you choose) of all of the points within the search radius and count. To demonstrate if you assign the center value to @P  and place the point wrangle within a sop solver you get a pseudo gravity sim. See attached HIP.

pseudo_gravity.hipnc

Edited by Wooshum
clarity

Share this post


Link to post
Share on other sites

Thank you "Milad", but I'm looking for the best way to calculate the center of those clusters.

Share this post


Link to post
Share on other sites

Here is another approach (similar to the previous).

rough ideas:

  • use pcfind() to get clusterpoints and add polylines (for connectivity)
  • remove points which are isolated
  • get connectivity classes
  • create dummy points (one for each class), which should be the center points later
  • each point should get all cluster points as vector array attribute (using for each is possible)
  • create average over all vector array for each point to get the center

Probably there are faster solutions.

CenterOfEachColoni_01.hipnc

 

faster equivalent (avoiding for each)...

 

CenterOfEachColoni_01B.hipnc

Edited by Aizatulin
  • Like 1

Share this post


Link to post
Share on other sites

Hi,

You can just average out all the points found in the point cloud lookup where you are coloring them, and either create new points at the computed center or store it as an attribute.

  • Like 1

Share this post


Link to post
Share on other sites

Also make sure to look at the cluster points node which even offers an "output: average points" function.

  • Like 1

Share this post


Link to post
Share on other sites
On 2/22/2020 at 9:13 PM, konstantin magnus said:

Also make sure to look at the cluster points node which even offers an "output: average points" function.

Do you mean avg() function?

Share this post


Link to post
Share on other sites

If you add a Cluster SOP after your Cluster Points SOP, it has a checkbox to output Cluster Centers.

image.png.97e632d0129cd08634f82eb3438dddab.png

 

-b

  • Like 1

Share this post


Link to post
Share on other sites

Thanks "Bonsak", good idea. But when I set "Output Attribute" to "Average Points", it shows some points that are not at the center of each cluster.

Edited by Masoud

Share this post


Link to post
Share on other sites

If you got the cluster from pcopen command, wouldn’t the centerpoint be @P? 
 

 

Share this post


Link to post
Share on other sites

Make sure you set the same number of clusters on both the Cluster Points SOP and Cluster SOP. The Cluster Points SOP has the Cluster SOP inside it. So you could use 2 Cluster Points SOPs if you want and set the second to Average Points. You still need to set the same number of clusters on both nodes though.

-b

image.png.bbadde900ef96e08524a7fcbebd35b41.png

cluster-centers.hip

Share this post


Link to post
Share on other sites
11 hours ago, ftaswin said:

If you got the cluster from pcopen command, wouldn’t the centerpoint be @P? 
 

 

but say you have found 2 points, just say left and right, and your hero point was slightly offcentre...then the centre of the cluster should be the centre of left/right points...not the orig slightly offcentre hero.

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

×