Package: pycaster
Backgroundpycasteris a simple single-module package (module also calledpycaster) which contains arayCasterclass. This class allows
for ray-casting operations to be performed on any mesh represented by a
‘vtkPolyData’ object.TherayCasterclass acts as a wrapper of thevtkOBBTreeclass
and uses perform ray-casting. It can calculate the coordinates of the
entry/exit points between the ray and the surface. It can in addition
calculate the distance a ray travels within the closed section of the
surface, i.e., within the solid.The class features a static method ‘fromSTL’ which allows for it to be
initialized directly from an STL file which it loads and extracts the
polydata from initializing the ray-caster.DocumentationNo extensive documentation ofpycasterwas written due to its
simplicity.Examples: IPython NotebooksTwo IPython Notebooks were written demonstrating the usage ofpycasteron STL models:A notebook demonstrating the usage ofpycasteron the STL model
of a hollow sphere can be foundhere(with the STL file being availablehere).A very similar notebook to the above, with the sole exception being
operating on the STL model of a human skull extracted from CT data
can be foundherewhile the corresponding STL file is availablehere.Usage ExampleIn a nutshell usingpycasterit would go as such:from pycaster import pycaster

# Create a new rayCaster object through the 'fromSTL' static-method thus loading
# the STL file 'sphereHollow.stl' and creating a new rayCaster under 'caster'
caster = pycaster.rayCaster.fromSTL("sphereHollow.stl", scale=1.0)

# Set the source and target coordinate of the ray
pSource = [-50.0, 0.0, 0.0]
pTarget = [50.0, 0.0, 0.0]

# Use the 'castRay' method of the 'rayCaster' class to intersect a ray/line with
# the surface and return a list of coordinates, i.e., the intersection points
pointsIntersection = caster.castRay(pSource, pTarget)

# Use the calcDistanceInSolid to calculate the distance the ray 'travels' within
# the surface
caster.calcDistanceInSolid(pSource, pTarget)Requirementsvtk >= 5.10.1 nose >= 1.3.3Python 3.x SupportAt the time of writingpycastercannot function with Python 3.x as
the VTK Python bindings have not been ported to Python 3.x. However,pycasterhas been extensively tested with different Python 2.7.x
versions.InstallationThis package is already hosted on PyPIhereand can be easily
installed through pip as such:pip install pycasteror straight from the source-code usingsetuptoolsas such:python setup.py installHowever, given thevtkrequirement ofpycasterwhich doesn’t
always build easy with pip I strongly suggest the following:Use an Anaconda python distro. I’ve written a blog post about the
advantages it offershere.Install the dependencies withconda(see the aforementioned post)Installpycasterwithpipwhile skipping the dependencies as
such:pip install pycaster --no-depsTesting & CIpycastercomes with tests written withunittestand
batch-executed withnose. The distribution also comes with several
.stl files used for testing the different aspects of the package. After
installation you can easily run those tests from within a python session
with the following code:from pycaster.test import test_all
test_all.runTests()Every commit ofpycasteris being built and tested on theWerckerCI system. The application is public
and can be accessed through either clicking on the wercker badge at the
top of this page or throughthislink.