First if the code has not been compiled to an executable, do that now:
> gcc stlwrite.c -o stlwrite.exe -lm
This program truncates a stereolithography (stl) file using its associated airway centerline skeleton data file, so these files need be in the same directory as your executable and labeled Lung.stl and Lung_skeleton.dat respectively. The third file needed is truncation.txt and it follows a simple format, which is sampled below:
> more truncation.txt
3 2
0 0.9 1.5
1 0.9 1.5
2 0.9 2
The first line contains 2 integers: the first is the stop generation that will be used to set the final boundary, and the second is a variable “boundaryerror” that can be set to 2 for a standard run, or 1 or 0 for troubleshooting modes. It is important to note that the generation numbering is setup with the trachea representing the 0th generation, so setting it to 3 as seen above will result in generations 0, 1, and 2 being output. Also note that setting boundaryerror=2 will tell the program to output generations 0 to 2 and planar pressure boundary set at the start of generation 3. If boundaryerror=1 was set instead, the program will run identically as before except in the stl output that the faces adjacent to the final boundary will be marked as the boundary and not the last generation. Setting boundaryerror=0 will be very similar to the previous case except that no boundary or pressure faces will be output; only the generations desired.
Save the above to truncation.txt and run the executable:
> ./stlwrite.exe
Note that if this script is run again, it will overwrite the previous files, so your outputted test.stl will not be saved unless you rename or move it between runs. Modify the boundaryerror mode defined in truncation.txt to 1 and rename test.stl to test_be2.stl before running the executable again; repeat this again by renaming the previous output to test_be1.stl and setting boundarerror mode to 0. Rename this final output to test_be0.stl. Open software capable of viewing a stl (such as Icem, Harpoon, Ensight, or Paraview) and compare the differences between files. Below are screenshots of selected pressure boundaries that were created while using the above truncation.txt and having boundary error set to 2, 1, and 0 respectively.
boundaryerror=2
boundaryerror=1
boundaryerror=0
Panning out further, an overlay of the stl generated by setting boundaryerror=1 above can be seen, along with an image of it overlayed the original lung stl file, and a further panned out view of that.
just boundaryerror=1
boundaryerror=1 overlayed on original lung stl
further panned out view of boundaryerror=1 overlayed on original lung stl