Implement a volume function for extruded bitmaps (EBM)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 difficult to compute.

References:

  • http://en.wikipedia.org/wiki/Volume
  • http://mathworld.wolfram.com/
  • http://www.dtic.mil/cgi-bin/GetTRDoc?AD=AD0274936
  • include/raytrace.h: See ft_volume callback defined in rt_functab structure

Code:

  • src/librt/primitives/ebm/ebm.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 the volume (units are mm^3). There are numerous examples in our code where we compute volume 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
ebm-volume.patch1.8 KBDecember 02 2013 07:56 UTC
ebm-volume2.patch3.2 KBDecember 05 2013 06:57 UTC
Comments
Matthewon November 25 2013 23:54 UTC

Hi, I might be interested in this task, but I'm still trying to familiarize myself with the code. Where can I find more information on things like the "rt_functlab" struct? (besides the source)

agkphysicson December 1 2013 09:12 UTCTask Claimed

I would like to work on this task.

Gauravjeet Singh on December 1 2013 12:31 UTCTask Assigned

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

agkphysicson December 2 2013 05:50 UTCTransformation Matrix

To calculate the volume it should be sufficient to multiply the number of cells by the extrude depth, because each cell is one mm^2.


But the ebm object has a member called 'mat' which is a 4x4 matrix that can transform the ebm object, like rotate it and scale it.


Acoording to a lecture here, the volume change is equal to the determinant of the upper right 3x3 part of this transform matrix, but only if the bottom row is 0, 0, 0, 1. Playing around in MGED I've found that putting arbitrary values in the bottom row of this matrix often causes it to display incorrectly or disappear. I've written a function which calculates the volume only if the bottom row is 0, 0, 0, 1, and produces a warning otherwise, which I am testing now.


Is that matrix likely to take on other values that we have to take into account? And also, if it is unable to calculate the volume correctly, what should be placed in the volume argument?

agkphysicson December 2 2013 07:57 UTCReady for review

The work on this task is ready to be reviewed.

agkphysicson December 2 2013 08:01 UTCTesting

I have tested this function with basic shapes such as circles and squares, and it seems to be giving correct results, even when the transform matrix is modified for shears and scales etc. If the bottom row of the matrix is not 0 0 0 1, the volume returns -1.0 and an error is printed to the MGED console.

Sean on December 3 2013 07:12 UTChomogenous matrices

agkphysics, you can't assume the bottom row is 0 0 0 1.  Element [15] (the last one) is often used to encode a uniform scaling factor.  But hope is not lost!  We have a function that calculates the determinant of a given 4x4 matrix: bn_mat_determinant().


You're definitely on the right track, excellent sleuthing.


The information from that presentation wasn't to imply that it only works with a 3x3.  That was just to keep the explanation simple.  You can use the 4x4 determinant.  Give it a try and compare with your current solution.  You'll probably just need to make sure the determinant is not zero and use it's absolute value (in case it's mirrored).


 

Sean on December 3 2013 07:12 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 3 2013 07:12 UTCDeadline extended

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

agkphysicson December 3 2013 07:48 UTCIncorrect Values

I used the 4x4 determinant, but it gives incorrect results when the bottom row is modifed. For example, when the matrix is a diagonal of all 2's, the shape appears to be the same size in the graphics window yet the volume is 16 times the correct value becuase the determinant is 16.


Similarly when only element 15 is increased the shape decreases in size yet the volume increases.

Daniel Rossberg on December 3 2013 08:11 UTCPerspective projection

The 4x4 matrix describes in fact a transformation with homogenious coordinates.  The map into the real 3-space is done by the "homogeneous divide" (e.g. see here: https://en.wikipedia.org/wiki/Transformation_matrix#Perspective_projection).  This explanes your observations when modifying the bottom row.

agkphysicson December 3 2013 09:41 UTCYes, but...

I realise this, but I am still trying to find a way to correctly calculate the volume even when the bottom row is modifed.


Is it possible to 'undo' the effect of changing the bottom, row, because otherwise I don't see how to correctly calculate the volume in all situations where someone puts arbitrary values in that matrix?


Anyway, I will keep researching the problem.

Daniel Rossberg on December 3 2013 11:34 UTCI'm afraid there is no easy solution

First of all: There is no factor for the volume.  It depends on where you are in space (e.g. the distance of the ebm to the projection center).


Next you could try is to transform the cuboids into pyramid stumps and compute their volume.  But what happens if the 4th homogenious coordinate w becomes 0 inside one of these stumps? (Probable: then the ebm is degenerated anyway.)

agkphysicson December 5 2013 06:57 UTCReady for review

The work on this task is ready to be reviewed.

agkphysicson December 5 2013 07:04 UTCSorry for the late reply

Sorry for the late reply but I have been sick for the past 24 hours, so haven't been able to work on this task.


But I think I have a solution. It makes use of the fact that each cell is essentially a distorted cube, so using a formula from here, it calculates the co-ordinates of the eight vertices of each cell and calculates the volume of each cell, and a cumulative total is returned as the volume.


Testing this looks like it's working for basic shapes, and g_qa gives similar results for heavly distorted shapes.

Melange on December 6 2013 05:58 UTCNo more Work can be submitted

Melange has detected that the deadline has passed and no more work can be submitted. The submitted work should be reviewed.

Sean on December 6 2013 06:02 UTCTask Closed

Congratulations, this task has been completed successfully.

Sean on December 6 2013 06:04 UTCeither way, excellent work

Whether it's right or not, this is outstanding work.  You've gone above and beyond by comparing to gqa, so please do try and claim the ebm volume function follow-on tasks as they're posted.  There will probably be one to enable it in analyze output and another to validate a specific test case or two (which you've already done).


Outstanding.