VTK re-compile (for Python) with PowerCrust algorithm support

The following was performed with VTK 5.8 and Python 2.7.8 on Debian Wheezy x86_64.

  1. Get the VTK source-code: http://vtk.org/VTK/resources/software.html
  2. Get the Tim Hutton’s PowerCrust C++ source-code: https://github.com/timhutton/vtkpowercrust
  3. Unzip both archives
  4. Copy the C++ files (.cxx & .h) into VTK/Hybrid
  5. Edit VTK/Hybrib/CMakeLists.txt and add the PowerCrust .cxx file
  6. cd VTK; mkdir build; cd build; ccmake ..
  7. Set desired installation directory
  8. Turn on BUILD_SHARED_LIBS, VTK_USE_RENDERING, VTK_WRAP_PYTHON
  9. While on ccmake first configured [c] and then generate [g]
  10. make && make install
  11. cd Wrapping/Python; python setup.py install
  12. Assuming all go well export the VTK libraries: export LD_LIBRARY_PATH=/<installation_path>/lib/vtk-5.8

VTK export JPG from DICOM

Exporting .jpg image copy from .dcm input using VTK in Python.

# Iterate through .dcm files and export to .jpg
for image in os.listdir(PathDicom):
if (image.endswith(".dcm")):
reader.SetFileName(image)
reader.Update()

# Need to cast before writing to .jpg
castFilter = vtk.vtkImageCast()
castFilter.SetOutputScalarTypeToUnsignedChar()
castFilter.SetInputConnection(reader.GetOutputPort())
castFilter.Update()

# .jpg file write
writer = vtk.vtkJPEGWriter()
writer.SetInputConnection(castFilter.GetOutputPort())
jpg_filename = image.replace(“.dcm”, “.jpg”)
writer.SetFileName(“{0}”.format(jpg_filename))
writer.Write()