Count number of edges

   6592   6   2
User Avatar
Member
126 posts
Joined: Aug. 2010
Offline
Hi, I'm trying to calculate the Euler Characteristic of my mesh. I need to figure the Genus of my mesh, to check if it is a torus or disk.

To to this I just need to count the number of vertexs (points), faces (primitives) and edges..

Points and prims are easy, but how can I count the number of edges?

https://en.wikipedia.org/wiki/Euler_characteristic [en.wikipedia.org]
Edited by aeaeaeae - June 24, 2016 10:44:36
User Avatar
Member
4523 posts
Joined: Feb. 2012
Offline
len(hou.Geometry.globEdges("*"))

but it will be slow for high res models.
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 | pragmaticvfx.gumroad.com
User Avatar
Member
182 posts
Joined: April 2009
Offline
Python is indeed very slow when you have to deal with millions of polygons.

But there is another way using vex

You run an attrib wrangle over primitives and for each primitive you look at its half edges.
hedge_equivcount() will give you the number of half edges that are equivalent to your current half edge.
If it has only one equivalent, then it's an unshared edge.
If it has more, then you know it's a shared edge and it contributes by ( 1 / hedge_equivcount ) to the total count.
An edge between two primitives thus equals 1, because each prim's half edge contributes 0.5.
Last but not least you promote the count to a detail attribute to get the total sum.

This might sound more complicated, but it is faster because most of it is running multithreaded in the wrangle sop.



Edited by blackpixel - June 24, 2016 17:11:32

Attachments:
halfedges.gif (218.2 KB)
halfedges.hip (82.8 KB)

User Avatar
Member
670 posts
Joined: Sept. 2013
Online
Not very elegant, but you could set carve node to
U = 0 and V = 1
Breakpoints -> Cut Breakpoints

and count prims.
https://procegen.konstantinmagnus.de/ [procegen.konstantinmagnus.de]
User Avatar
Member
182 posts
Joined: April 2009
Offline
Konstantin Magnus
Not very elegant, but you could set carve node to
U = 0 and V = 1
Breakpoints -> Cut Breakpoints

and count prims.

Doesn't carve return multiple lines along shared edges ? That would give you a wrong number.
User Avatar
Member
402 posts
Joined: June 2014
Offline
There's also a hedge_isprimary() vex function which only returns true for one in every set of shared half edges, you can make a wrangle to “Run Over: Detail” and iterate over the half edges testing for primary:
int numedges = 0;

int i = 0;

while(hedge_isvalid(0, i)){
if(hedge_isprimary(geoself(), i))
numedges++;
i++;
}

i@count = numedges;

EDIT: although I think there's more magic to @blackpixel's solution
Edited by friedasparagus - June 27, 2016 13:06:36
Henry Dean
User Avatar
Member
182 posts
Joined: April 2009
Offline
nice one friedasparagus! It's a bit slower than running over prims, but still miles ahead of python
  • Quick Links