[vtkusers] Problems with vtkClipPolyData and vtkSurfaceReconstructionFilter

Øystein Skotheim oystein+vtk at edge.no
Thu Nov 17 11:03:00 EST 2005


Hello. Can anybody tell me if there is something wrong with the included 
TCL code? I am using it to 1) clip a point cloud by pressing "i" to 
activate the box widget and "C" to clip away what is outside the box and 
later 2) to construct a surface on the point cloud (keypress "S") by using 
vtkSurfaceReconstructionFilter

The problem is that the program crashes in around 50% of the cases
(segmentation fault in the wish interpreter) I experience similar 
symptoms on MS Windows and MacOSX platforms.

Am I doing something wrong, or is there something wrong with the filters?

If I connect the "unclipped" pointcloud to vtkSurfaceReconstructionFilter 
I do not experience any crashes.

(By the way I am using VTK from the 5.0 branch in CVS)

--cut--

package require vtk
package require vtkinteraction

###############
## CALLBACKS ##
###############

proc keyPressed {} {
     global reslicer iren clipPlanes clipper renWin ren1
     global surfaceActor pointActor

     # CLIP
     if { [ iren GetKeyCode ] == "C"} {
 	boxWidget GetPlanes clipPlanes
 	clipper Update
 	[ clipper GetClippedOutput ] Print
 	renWin Render
     }

     # MAKE SURFACE
     if { [ iren GetKeyCode ] == "S"} {
 	surf Update
 	ren1 RemoveActor pointActor
 	ren1 AddActor surfaceActor
 	renWin Render
     }

}


if { [ expr $argc < 1 ] } {
     puts "Syntax: wish pcstudio.tcl <filename.xyz>"
     exit
}

vtkPoints points
vtkCellArray cells
vtkPolyData cloud

puts "Reading points from file $argv"
set file [open [lindex $argv 0]]

set no_coords 0
while { [gets $file line] != -1 } {
     scan $line "%f %f %f" x y z
     points InsertPoint $no_coords $x $y $z
     incr no_coords
}

cells InsertNextCell $no_coords
for { set i 0 } { $i < $no_coords } { incr i } {
     cells InsertCellPoint $i
}

cloud SetPoints points
cloud SetVerts  cells

##############
## CLIPPING ##
##############

vtkPlanes clipPlanes

vtkClipPolyData clipper
clipper SetInput cloud
clipper SetClipFunction clipPlanes
clipper GenerateClippedOutputOn
clipper SetValue 0.5

vtkPolyDataMapper pointMapper
pointMapper SetInput [ clipper GetClippedOutput ]
pointMapper ScalarVisibilityOff

vtkActor pointActor
pointActor SetMapper pointMapper
[pointActor GetProperty] SetRepresentationToPoints
[pointActor GetProperty] SetColor 0 0 1.0

######################
## SURFACE CREATION ##
######################

# Construct the surface and create isosurface.
#
vtkSurfaceReconstructionFilter surf
surf SetInput [ clipper GetClippedOutput ]

vtkContourFilter cf
cf SetInputConnection [surf GetOutputPort]
cf SetValue 0 0.0

# Sometimes the contouring algorithm can create a volume whose gradient
# vector and ordering of polygon (using the right hand rule) are 
# inconsistent. vtkReverseSense cures this problem.
vtkReverseSense reverse
reverse SetInputConnection [cf GetOutputPort]
reverse ReverseCellsOn
reverse ReverseNormalsOn

vtkPolyDataMapper surfaceMapper
surfaceMapper SetInputConnection [reverse GetOutputPort]
surfaceMapper ScalarVisibilityOff

vtkActor surfaceActor
surfaceActor SetMapper surfaceMapper
[surfaceActor GetProperty] SetDiffuseColor 1.0000 0.3882 0.2784
[surfaceActor GetProperty] SetSpecularColor 1 1 1
[surfaceActor GetProperty] SetSpecular .4
[surfaceActor GetProperty] SetSpecularPower 50

# Create the RenderWindow, Renderer and both Actors

vtkRenderer ren1
vtkRenderWindow renWin
renWin AddRenderer ren1

vtkInteractorStyleTrackballCamera style

vtkRenderWindowInteractor iren
iren SetRenderWindow renWin 
iren SetInteractorStyle style

################
## BOX WIDGET ##
################

vtkBoxWidget boxWidget
boxWidget SetInteractor iren
boxWidget SetInput cloud
boxWidget SetPlaceFactor 1.0
boxWidget PlaceWidget
boxWidget GetPlanes clipPlanes

# Add the actors to the renderer, set the background and size
# ren1 AddActor surfaceActor
ren1 AddActor pointActor
ren1 SetBackground 0 0 0

renWin SetSize 400 400
ren1 ResetCamera
ren1 ResetCameraClippingRange

# render the image
#
iren AddObserver UserEvent {wm deiconify .vtkInteract}
iren AddObserver KeyPressEvent keyPressed

renWin Render

# prevent the tk window from showing up then start the event loop
wm withdraw .

---cut---

Øystein Skotheim, Research Scientist
Dept. of Optical Measurement Systems and Data Analysis
SINTEF ICT, N-7465 Trondheim, Norway


More information about the vtkusers mailing list