Implement a surface area function for super ellipsoids (SUPERELL)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/Surface_area
  • http://mathworld.wolfram.com/
  • http://www.dtic.mil/cgi-bin/GetTRDoc?AD=AD0274936
  • include/raytrace.h: See ft_surf_area callback defined in the rt_functab structure

Code:

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

This task involves writing a new callback function that takes an rt_db_internal object and calculates the surface area (units are mm^2). There are numerous examples in our code where we compute surface area for other primitives. 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
superell_surface_area.diff3.3 KBJanuary 02 2014 04:21 UTC
Comments
Peter Amidonon December 4 2013 16:52 UTCTask Claimed

I would like to work on this task.

Mandeep Kaur on December 4 2013 16:57 UTCTask Assigned

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

Peter Amidonon December 5 2013 00:11 UTCNo general formula for ellipsoid

Hi,


I cannot find any general formula for the surface area of the ellipsoid, and as far as I can tell, even if it was derived at some point it would have to contain elliptical integrals. Can you please advise?

Peter Amidonon December 5 2013 20:38 UTCClaim Removed

The claim on this task has been removed, someone else can claim it now.

Sean on December 31 2013 06:28 UTCcomment on mailing list

This is a hint I posted to the brlcad-devel mailing list on this task that might help someone make progress:


This is a difficult one.  I don't know of a way to directly evaluate the surface area, but you could converge to a definably accurate estimate by sampling surface points.

For example, you could iterate over the x(u,v) y(u,v) and z(u,v) parametric representation described on Wikipedia, incrementing by maybe PI/4 for starters, and using the surface points as defining a surface tessellation.  You can sample the u,v in a way that creates quadrilateral patches (rectangles), which you can sum up easily.  You then recalculate with PI/(4+N) or PI/(4*N), for example PI/8 then PI/16 then PI/32 .. etc, and stop when the area summation converges to a solution within some defined tolerance (like 0.005).

Alternatively for that task, you could implement any one of the special cases A) e=0,n=0 or e=2,n=0 (boxes); B) e=0,n=1 or e=2,n=1 (four cylinder sections); C) e=0,n=2 or e=2,n=2 (prisms); D) e=1,n=0 or e=1,n=2 (a cylinder/cone); or E) e=1,n=1 (a sphere).  They're all individually pretty simple (and an opportunity to complete five different tasks). 

Peter Amidonon December 31 2013 06:59 UTCTask Claimed

I would like to work on this task.

Sean on December 31 2013 07:18 UTCTask Assigned

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

Peter Amidonon January 2 2014 04:27 UTCMore work in a follow on task?

While this algorithm is fairly slow, I have spent probably ~6hrs trying to optimize it (profiling says that a __signbitl linux function is taking the majority of the time); to do this, I have written a small tester program that has a geometry written in it and runs the algorithm on it. This version of the algorithm is very slow with precisions 1024; however, it returned an area less than 2 away from the correct area for all of the shapes that I tested it on. I would not mind doing a follow-on task to attempt to optimize it further; I would also like to do a follow on that involves writing tests for it.

Peter Amidonon January 2 2014 04:28 UTCReady for review

The work on this task is ready to be reviewed.

Sean on January 2 2014 05:31 UTCTask Closed

Congratulations, this task has been completed successfully.

Sean on January 2 2014 06:06 UTCcertainly

There were several issues with this patch, but I marked it complete because this is easily one of the hardest tasks in our list and your implementation looks functionally okay (though possibly some major bugs).  Here are some of the issues noted that you can fix on commit:



  • _rt_superell_surf_area_box() should be static

  • struct rt_superell_internal *sip should be const and passed as const in most places

  • _rt_superell_c() and _rt_superell_s() are cryptic names

  • sgn() is unnecessarily/unhelpfully truncated too

  • sgn() returns an int, which means _rt_superell_c() and _s() will be doing integer math which doesn't look like what you intended.  should return a fastf_t or be a cast in the caller.

  • can drop the _rt_ prefix for the static funcs -- use superell_ instead 

  • any numeric constants should be documented (what/why) briefly, for example:


    • _rt_superell_surf_area_general()'s two loops, why -pi to pi and -pi/2 to pi/2

    • rt_superell_surf_area() has three: the initial 64, the *=4, and 0.005.  Why not initial 128 or 3 or 823482?  Why not *=2 or *=8 or *=123? 


  • the 0.005 can probably be replaced with BN_TOL_DIST (which doesn't need a comment)

  • you left debugging print statements (bu_log and printf)


If you've tried different convergence parameters (the constants in rt_superell_surf_area()), it'd be good to also document their sensitivity and what makes them a good default or what other values might be useful to have.  Anything that'll help another developer trying to understand what it all means.

 

Follow-on tasks are definitely in order, no problems there.  I'll post a link when they're ready.

 

Sean on January 2 2014 06:12 UTCfollow-on

A follow-on task has been posted: http://www.google-melange.com/gci/task/view/google/gci2013/5895393510424576

Peter Amidonon January 2 2014 07:02 UTCCommitted

This was committed as r59250 with the changes that you suggested.