Previous

Section

<<<

Isosurface Generation Using VTK

Next

Section

>>>

VTK Basics

 

 

3.5.2. vtkContourFilter vs. vtkMarchingCubes

 

The best way to compare these two is to look at the same region of interest and see how they match up.  Below is the code to make the datasets render.

 

import Tkinter

import vtk

from vtk.tk.vtkTkRenderWindowInteractor import vtkTkRenderWindowInteractor

 

# Prepare to read the file

readerVolume = vtk.vtkImageReader()

readerVolume.SetDataScalarType( vtk.VTK_UNSIGNED_SHORT )

readerVolume.SetFileDimensionality( 3 )

readerVolume.SetDataExtent ( 0,255, 0,255, 0,576)

readerVolume.SetDataSpacing( 1,1,1 )

readerVolume.SetNumberOfScalarComponents( 1 )

readerVolume.SetDataByteOrderToBigEndian()

readerVolume.SetFileName( "./Female.raw" )

 

# Extract the region of interest

voiHead = vtk.vtkExtractVOI()

voiHead.SetInput( readerVolume.GetOutput() )

voiHead.SetVOI( 0,255, 60,255, 0,100 )

voiHead.SetSampleRate( 1,1,1 )

 

# Generate an isosurface

# UNCOMMENT THE FOLLOWING LINE FOR CONTOUR FILTER

# contourBoneHead = vtk.vtkContourFilter()

contourBoneHead = vtk.vtkMarchingCubes()

contourBoneHead.SetInput( voiHead.GetOutput() )

contourBoneHead.ComputeNormalsOn()

contourBoneHead.SetValue( 0, 1250 )  # Bone isovalue

 

# Take the isosurface data and create geometry

geoBoneMapper = vtk.vtkPolyDataMapper()

geoBoneMapper.SetInput( contourBoneHead.GetOutput() )

geoBoneMapper.ScalarVisibilityOff()

 

# Take the isosurface data and create geometry

actorBone = vtk.vtkLODActor()

actorBone.SetNumberOfCloudPoints( 1000000 )

actorBone.SetMapper( geoBoneMapper )

actorBone.GetProperty().SetColor( 1, 1, 1 )

 

# Create renderer

ren = vtk.vtkRenderer()

ren.SetBackground( 0.329412, 0.34902, 0.427451 ) #Paraview blue

ren.AddActor(actorBone)

 

# Create a window for the renderer of size 250x250

renWin = vtk.vtkRenderWindow()

renWin.AddRenderer(ren)

renWin.SetSize(250, 250)

 

# Set an user interface interactor for the render window

iren = vtk.vtkRenderWindowInteractor()

iren.SetRenderWindow(renWin)

 

# Start the initialization and rendering

iren.Initialize()

renWin.Render()

iren.Start()

 

Example 3.2: Code to generate compare the vtkMarchingCubes and vtkContourFilter

 

 

Below is a side-by-side comparison of the two. 

 

(a)

(b)

 

Figure 3.2: Renderings of the head section of the Visible Woman dataset using a bone isosurface value.  (a) vtkContourFilter, (b) vtkMarchingCubes

 

 

<<< Previous

Creating the Pipeline: vtkPolyDataMapper and vtkLODActor

 

 

Table of Contents

 

 

Next >>>

Trying Different Colors and Opacities