Implement a primitive centroid function ... for hyperboloids of one sheet (HYP)BRL-CAD
Status: ClosedTime to complete: 72 hrs Mentors: Sean, Matt S.Tags: C, C++, math, geometry, centroid

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.

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. The primitives that do not already have a centroid callback are itemized in following.

References:

Code:

  • src/librt/primitives/table.c
  • src/librt/primitives/hyp/hyp.c
Uploaded Work
File name/URLFile sizeDate submitted
table.c35.8 KBDecember 05 2012 23:19 UTC
hyp.c39.0 KBDecember 05 2012 23:20 UTC
hyp.c.diff400 bytesDecember 07 2012 05:15 UTC
table.c.diff198 bytesDecember 07 2012 05:15 UTC
new2.patch943 bytesDecember 07 2012 10:35 UTC
new3.patch987 bytesDecember 08 2012 03:41 UTC
new4.patch922 bytesDecember 08 2012 05:09 UTC
Comments
Aaron Keesingon December 5 2012 09:07 UTCTask Claimed

I would like to work on this task.

Daniel Rossberg on December 5 2012 09:31 UTCTask Assigned

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

Aaron Keesingon December 5 2012 23:18 UTChyp_Vi object already there

I see that there is a point_t object in the rt_hyp_internal structure whose description is "hyp vertex". Does this mean that all I have to do is make the centroid function replace *cent with hyp_Vi, like for rt_ell_centroid()?


I will upload that work but if you would like me to actually calculate the centroid within the function then I will see if I can do that.


 


Thanks


Aaron K

Aaron Keesingon December 6 2012 03:16 UTCReady for review

The work on this task is ready to be reviewed.

Daniel Rossberg on December 6 2012 13:13 UTCWe like the patch-files

Please provide us one.  Your subversion client should be able to generate it.

Daniel Rossberg on December 6 2012 13:13 UTCTask Needs More Work

One of the mentors has sent this task back for more work. Talk to the mentor(s) assigned to this task to satisfy the requirements needed to complete this task, submit your work again and mark the task as complete once you re-submit your work.

Aaron Keesingon December 7 2012 05:16 UTCReady for review

The work on this task is ready to be reviewed.

Sean on December 7 2012 06:10 UTCnot right

So a few problems.  First and foremost, it looks like the centroid is wrong.  It's not just the Vi point as that's on the base.


Next, the indentation is wrong in the hyp.c file.  See our HACKING file or other source files for details and examples.


The other issue is more practical, don't submit patches as separate files.  The changes to both files can be combined into a single patch file.  "svn diff file1.c file2.c ... my.patch" and similarly with the other GUI-based SVN tols too.

Sean on December 7 2012 06:10 UTCTask Needs More Work

One of the mentors has sent this task back for more work. Talk to the mentor(s) assigned to this task to satisfy the requirements needed to complete this task, submit your work again and mark the task as complete once you re-submit your work.

Aaron Keesingon December 7 2012 10:36 UTCReady for review

The work on this task is ready to be reviewed.

Aaron Keesingon December 7 2012 10:45 UTCCentroid Function

I only uploaded the patch file this time, so hyp.c and table.c are still my original ones. I think I have also fixed the indentation problem; I was using tabs instead of spaces.


Looking at the code already in hyp.c I believe the centroid has already been calculated somewhere. I believe it is in the hyp_internal_to_specific() function, where the full height vector is halved and added to the Vi point. This should give the center of the hyperboloid. I only used the two statements in that function that I needed and transferred them to the centroid function, to save unnecessary computation time.


If you want me to upload the newest hyp and table c files I will do that.


Thanks


Aaron K

Daniel Rossberg on December 7 2012 11:41 UTChyp.c breaks the build

[ 27%] Building C object src/librt/CMakeFiles/librt.dir/primitives/hyp/hyp.c.o


/home/rossberg/Devel/brlcad/src/librt/primitives/hyp/hyp.c: In function ‘rt_hyp_centroid’:


/home/rossberg/Devel/brlcad/src/librt/primitives/hyp/hyp.c:1370:5: error: ISO C90 forbids mixed declarations and code [-Werror=edantic]


cc1: all warnings being treated as errors


make[2]: *** [src/librt/CMakeFiles/librt.dir/primitives/hyp/hyp.c.o] Fehler 1


make[1]: *** [src/librt/CMakeFiles/librt.dir/all] Fehler 2


make: *** [all] Fehler 2

Daniel Rossberg on December 7 2012 11:41 UTCTask Needs More Work

One of the mentors has sent this task back for more work. Talk to the mentor(s) assigned to this task to satisfy the requirements needed to complete this task, submit your work again and mark the task as complete once you re-submit your work.

Sean on December 7 2012 19:31 UTClook again

Aaron, I suggest looking that function over again and noting the object types.  I may be mistaken as I only did a quick check, but I think you're confusing the V field on one struct with the Vi field on a different struct.  Make a hyp yourself and print out the value.  The "center" or "lookat" commands in mged will help.

Sean on December 7 2012 19:31 UTCDeadline extended

The deadline of the task has been extended with 1 days and 0 hours.

Aaron Keesingon December 8 2012 03:48 UTCReady for review

The work on this task is ready to be reviewed.

Aaron Keesingon December 8 2012 03:54 UTCQuestion

Sean, I'm not sure exactly what you mean when you suggest I might be confusing object types. I think I have solved the build crash issue as when I built it it did not come up with any hyp related errors (although I was building it on Windows). The description of hyp_V is "scaled vector to hyp origin". I interpreted that, after looking at the code, as being the center of the hyperboloid.


Regards


Aaron K

Sean on December 8 2012 04:08 UTCdifference

Aaron, so the distinction comes down to what fields are in a hyp_specific struct and which are in an rt_hyp_internal struct.  You do mimic another bit of code, which is probably what caused some misunderstanding earlier.  You add half the height vector to the hyp_Vi base center point, which indeed does give that center point.


The main issue remaining is that you don't actually need hyp_specific, it's superfluous.  You should be working entirely with just *cent (which isn't 'centroid' why?) or use a point_t instead.  The issues I see are:



  1. the comment is unnecessary/unhelpful (we're getting away from that convention)

  2. hyp_specific is not needed

  3. you don't make sure both args aren't null (could crash)

  4. function return type goes on a separate line (see our HACKING style guide)

Sean on December 8 2012 04:08 UTCTask Needs More Work

One of the mentors has sent this task back for more work. Talk to the mentor(s) assigned to this task to satisfy the requirements needed to complete this task, submit your work again and mark the task as complete once you re-submit your work.

Aaron Keesingon December 8 2012 05:10 UTCReady for review

The work on this task is ready to be reviewed.

Aaron Keesingon December 8 2012 05:12 UTCIssues

I think I have fixed all the issues you mentioned. I wasn't sure exactly how to implement the null checking, so I just made it return if either argument was NULL. If this is bad please let me know so I can fix it.


Thanks


Aaron K

Sean on December 8 2012 19:21 UTCnope, that's good

What you did looks good now.  Thanks for going through the revisions to get it fixed up!


 

Sean on December 8 2012 19:22 UTCTask Closed

Congratulations, this task has been completed successfully.

Sean on December 14 2012 14:25 UTCfollow-on task

A follow-on task has been created:


http://www.google-melange.com/gci/task/view/google/gci2012/8087202


 

Sean on December 14 2012 17:25 UTCcredited in AUTHORS

Aaron, your changes have been applied to our repository (r54062) and your name recorded in our authorship documentation.  You'll be credited with this publicly visible change in our next public release of BRL-CAD too. Thank you for your efforts!


 

Sean on January 14 2013 15:27 UTCthank you

As GCI comes to a close, we wanted to take the time to say THANK YOU for all your efforts.  This comment interface closes after GCI is over, so you're encouraged to join our mailing list where we'll be announcing contributions from GCI participants like yourelf over the upcoming months: 


https://lists.sourceforge.net/lists/listinfo/brlcad-news


If you've provided your full name, we'll be sure to credit you in our authorship documentation and you'll see your name in a future announcement.  If you contact us at devs@brlcad.org or via IRC, we'll even let you know when your work is integrated and follow up with updates.  You're welcome and encouraged to contact us any time, especially if you have a question about how to continue participating in Open Source after GCI is over, but even if just to keep in touch.  Note that ongoing participation in Open Source is one of the most impressive skills to have on your resumé.  Take care, be well, and thank you again!


I sincerely hope you continue to stay involved and contribute, given your abilities and background.  You tackled not just one but several of the hardest tasks we posted and did a fantastic job.  You'd be a welcome addition to our development team.