Jump to content

Primitive group center positions


pak

Recommended Posts

there is an actual vex function for this :D

http://www.sidefx.com/docs/houdini16.0/vex/functions/getbbox_center

you can give it a group as input.

running the following code in a wrangle (Run Over: Detail (only once))

string grps[] = detailintrinsic(0, "primitivegroups");
foreach(string grp; grps)
{
    int groupCenterPt = addpoint(0,getbbox_center(0, grp));
}


should do the trick for you

  • Like 3
Link to comment
Share on other sites

problem i see with bbox is it is flawed that it's not always truely 'centre'....ie. for a 'quad'...the centre is same as bbox centre...easy...but say you are dealing with the 2 tris making up that quad...the centre of each tri is somewhere inside the tri...not at the centre of its bbox.

here's the illustration....group shape resembles a triangle...its centre should be inside that triangle...not on its hypotenuse/bbox centre

bboxflaw.hipnc

Edited by Noobini
Link to comment
Share on other sites

3 hours ago, violalyu said:

One way I've used before is scale it to 0 on a per primitive basis and then fuse all the points, so that you get the center point of each one. Hope it helps :-)

That would solve for "primitives" - but I'm looking for "prim group centers" ~ I believe this method wouldn't work in that case?

Link to comment
Share on other sites

@pak yes sorry I wasn't reading the title carefully! I went from @jon3de 's file and added a (very roundabout) way to get the group name as an attribute on the newly created centroid points, I'm sure there are better ways, but I'll just post it here in case this could be of any inspiration :-)

pointsOnPrimitiveGroups_viola.hipnc

Link to comment
Share on other sites

Hi @pak, I didn't have the error message, but it is basically the same for me, it might be Houdini version difference? I'm using Houdini16.0.633, something might changed from 15.5 to 16? 
Also it seems you need the group attribute on the points for some later operation? Maybe there are other ways to directly achieve that, like instead of using group name as the "marker", there might be other attributes that could be used? 

Link to comment
Share on other sites

mmm...still wrong to me...because everyone's using BBox logic...if my prim groups are 'triangles' like these in the corners...their prim group center....well...they don't look very centered do they ?

However if all your prim groups are 'rectangular'...well ignore me...all's fine and dandy...

 

BBoxFlaw.jpg

Edited by Noobini
Link to comment
Share on other sites

here's my take on things...look at the classic case in the top left corner, a piece that is a triangular shape, imagine if BBox logic was applied to get the 'center'...it would have been ON the hypotenuse (right angle triangle, basic trig)....WRONG !!!

But with my simple CoM logic (I won't claim it's foolproof, I'm wondering how it works on an L shape)..it's on the inside of the tri itself...

CoM.jpg

vu_CoM.hipnc

Edited by Noobini
  • Like 3
Link to comment
Share on other sites

FYI, if you load the sample file CentroidPoints, you'll get this Detail Wrangle:

int nprims = nprimitives(1);
for(int i = 0; i < nprims; ++i)
{
    int nvtx = primintrinsic(1, "vertexcount", i);
    vector pos = { 0, 0, 0 };
    if(nvtx > 0)
    {
        for(int j = 0; j < nvtx; ++j)
        {
            int ptidx = vertexpoint(1, vertexindex(1, i, j));
            pos += point(1, "P", ptidx);
        }
        pos /= nvtx;
    }
    int pt = addpoint(geoself(), pos);
}

which was my initial idea to solve this problem...while it would work fine if your prim verts were 'evenly' distributed...it falls down when the verts distribution is skewed. so if your prim (or prim group) has this vert distribution, using the wrangle above you'd get the center incorrectly pulled to the highest vert concentration...so I decided to use scatter to even out my sample size so I don't care how 'dodgy' the orig geometry is...

BiasedTri.jpg

WrongCentre.jpg

CorrectCentre.jpg

Link to comment
Share on other sites

That's such a clever way to work @Noobini, thank you for this detailed step by step share!

@violalyu I am on 16.0.705 - maybe it's a version difference.. However, I don't have the option "transfer groups" anywhere in that node. Here, check out this brand new assemble node I've placed.

Edit: Just checked help for the node through right click menu, indeed in H16, there is no "transfer groups" option in assemble node. Maybe that's why.

 

assemble.png

Edited by pak
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...