Implement a centroid function for solid polygonal meshes (NMG)BRL-CAD
Status: ClosedTime to complete: 72 hrs Mentors: SeanTags:

BRL-CAD provides more than two dozen types of geometry ''primitives'' such as ellipsoids, boxes, and cones. Every primitive is described by a collection of callback functions, for example rt_ell_bbox() returns the bounding box dimensions for an ellipsoid. Wikipedia, Wolfram Mathworld, and various other math sites (and research papers) around the web include the equations for most of our basic primitives while others are a little more tricky to compute.

References:

  • http://en.wikipedia.org/wiki/Centroid
  • http://mathworld.wolfram.com/
  • include/raytrace.h: See ft_centroid callback defined in the rt_functab structure

Code:

  • src/primitives/nmg/nmg.c (implement your function here)
  • src/librt/primitives/table.c (add a reference to your function here)

This task involves writing a new callback function that takes an rt_db_internal object and calculates its centroid (as a point_t 3D point). There are numerous examples in our code where we compute centroids for other primtiives. Submit a patch file the may be applied cleanly.

If you succeed, a follow-on task may be created to enable and validate your function.

Uploaded Work
File name/URLFile sizeDate submitted
nmg_centroid.patch6.7 KBNovember 28 2013 20:28 UTC
Comments
Johannes Schulteon November 28 2013 19:45 UTCTask Claimed

I would like to work on this task.

Daniel Rossberg on November 28 2013 19:56 UTCTask Assigned

This task has been assigned to Johannes Schulte. You have 72 hours to complete this task, good luck!

Johannes Schulteon November 28 2013 20:31 UTC

So, I went the way, we talked about the other day (http://ibot.rikers.org/%23brlcad/20131125.html.gz).


Links that might help, to understand my messy code a bit better are:


http://en.wikipedia.org/wiki/Centroid#Centroid_of_polygon


http://stackoverflow.com/questions/2792443/finding-the-centroid-of-a-polygon


http://stackoverflow.com/a/2360507


http://stackoverflow.com/questions/9325303/centroid-of-convex-polyhedron

Johannes Schulteon November 28 2013 20:31 UTCReady for review

The work on this task is ready to be reviewed.

Sean on November 29 2013 04:19 UTCon a roll

You, sir, are on a roll.  This is awesome work.


Patch applied in r58708 and looks nearly perfect.  Only issues are that you cannot use y0 or y1 as variable names but only due to shadow warnings, which you wouldn't necessarily know unless you attempted to compile on a Mac; and there's a couple places you could be using vmath macros more effectively, but nothing critical.


Glad to see that you're keeping your source tree up to date.  Please read over our HACKING file in its entirely if you have not done so already, but this time pay particular attention to the section entitled CONTRIBUTOR RESPONSIBILITIES.  I also invite you to join the brlcad-devel mailing list if you've not done so already.  Please let me know if you have any questions and keep up the great work.


 

Sean on November 29 2013 04:20 UTCTask Closed

Congratulations, this task has been completed successfully.