Homework 7: Volume carving & marching cubes

Due date: Friday, May 30th, 11:59pm

In this homework you will build a volume representation of your object and run a marching cubes algorithm on it to get your final watertight model.
We decided to spare you the programming effort, given the fact that acquiring, processing and aligning enough views to get a good coverage of the object is enough work.

First, you need to apply a transformation to the aligned views, so that all the points fall inside the carving volume (the cube (x=0..1, y=0..1, z=0..1) ). In order to do this, run the program
~emilp/volcarve/fit2vol (on ugcs).
It takes a single argument, the name of the file that lists all your aligned views. This program will save your .params files under .params.old and will create new .params files. The only parameter that is modified is malign, which is composed with a uniform scale and a translation. Fit2vol will also check for consistency between the .params and .range files. It will complain if they do not match. They match if all the points in the .range file are along the "funny ray" generated by the grid structure that was described in class (the ray given by the intersection of the horizontal plane given by the camera row and the vertical plane given by the projector column). In other words, if the grid cell (i,j) contains coordinates (x,y,z), then the y coordinate in pixels of (x,y,z) projected onto the camera plane should be i+rngy0, and the x coordinate in pixels of (x,y,z) projected on the projector plane should be j+rngx0. You will get warning messages for all the points that do not comply. The program will go on, however.

The next step is to obtain the volume. Run ~emilp/volcarve/volcarve giving it as argument the same file that lists all your views. Press R (refine) a couple of times - until you get to the resolution of 128^3. (you need to be inside the Inventor window when you press keys, and the cursor must be the little arrow, not the hand -> to switch between them, press ESC). If there are pieces of uncarved volume floating around your object, you may edit them out, either by selected connected components, or with the cutting tool (best way!).
To get the cutting tool, press C (in the Edit mode: arrow cursor). You can rotate the plane around by clicking on a point inside the 3 circles and dragging it. (the circles will turn yellow while you rotate)
You can move the plane along its normal by clicking and dragging a point of the plane that is not inside the sphere generated by the 3 circles. To move the whole scene (object+plane), use the hand cursor (ESC to switch). When you are done, press D (in the arrow cursor). All the voxels that are on the red side of the plane will be deleted. To get rid of the cutting tool, press C again. Refining will also remove the tool.
To delete stuff by connected components, click on the piece you want to delete (the cursor must be the little arrow and the cutting plane should not be visible). The text window from which you started volcarve should say 'Finding connected component. Starting from ...' (if it doesn't, you didn't click on the right thing). Wait until you get the message 'Press F to revert to full volume. Press D to delete the piece'. You should see in the Inventor window just the piece of unwanted volume. If you can still see your object, bad luck ... the piece of garbage was connected to your object and you cannot delete it. You need more views to separate them (or you need to use a plane behind the object).
You can edit stuff out at any resolution. If you edit something out by connected component and then refine the volume you might see small pieces floating at the borders of the big chunk you just deleted. This happens because what you see on the screen are the voxels marked as FULL, and the ones you don't see might be either EMPTY or BOUNDARY. When you refine, the BOUNDARY voxels might split up into FULL smaller voxels. Deleting a piece gets rid of all the FULL voxels in the piece and of <one layer> of boundary. If your boundary is thicker, you get full voxels again at the next finer resolution.
Pressing V will save out your volume in the format needed for marching cubes: a bunch of slice.xx files will appear in the current directory. For 128 resolution, they take up 4 Megs. For 256, 32 Megs. The size gets multiplied by 8 for each refinement step. Since you cannot do much with these slice files, except build the final mesh, it's a good ideea to delete them after you run VTK. If you want to save your editing work, press S to save the run-length encoded volume (much smaller), which you can load later with volcarve (to do additional editing or to use additional views).

The third step is to get a surface from your volume. Run ~emilp/volcarve/marchCubes giving it as a parameter the resolution of your volume. After VTK is finished running, you should find a volume.iv in the current directory.
marchCubes is just a small shell script that sets a couple of variables and then runs the VTK Tcl script that does all the data processing. The Tcl script itself has a lot more more functionality and is very well explained at http://www.crd.ge.com/~lorensen/seg12/segemented16.html. I encourage you to take a look at it (you don't need to know Tcl)
You may want to play a bit with the parameters of the script, particularly with the standard deviation of the Gaussian filter, the value for the isosurface and the smoothing factor. If you raise the standard deviation or the isosurface value, you might be able to get rid of small islands of unwanted volume, without editing it out in volcarve, but you might also generate holes in the thin parts of your object (you object will shrink a bit, too). A higher smoothing factor might kill the high-frequency details in your object, a lower smoothing factor might produce a rugged appearance.

The sources for VTK are in /ug/space/ee148/vtk. Here is the VTK homepage.
The sources for fit2vol & volcarve are in ~emilp/volcarve/src. Please email me any bug reports.

What to turn in

On your web page, put a link to the best complete model of your object that you can get. You will have to do an in-class presentation, too.