[vtkusers] clip one vtkPolyData with another?
Alle Meije Wink
alle_meije at yahoo.co.uk
Sun Feb 26 15:13:31 EST 2006
Hi David and others,
Thanks for your many hints and tips. I tried vtkSelectPolyData,
vtkStencil, and vtkImplicitLoop, but at the moment nothing works.
(the subdivision thing did not work, because the triangles of the cut
surface -the clipcow way- differed orders of magnitude in size)
>>I can't see how I should do this. From the test code for
>>vtkImplicitSelectionLoop I saw that you can use it to extract a piece of
>>a surface (such as the isosurface), but what I would need is a piece of
>>the cut-plane
>
> I was thinking you would cut your isosurface to get a polyline (after a
> pass through vtkStripper?). This polyline would be the 'loop' which is then
> used to clip the cut planes with vtkImplicitSelectionLoop.
My script is below, the (MRI) data is still at www.wbic.cam.ac.uk/~amw71
I thought that this code would clip the cut surface, i.e. remove the
part of the cut surface outside the brain iso-surface (defined by
isoNormals).
Instead, the cut surface still extends outside the brain (to the extent
of the bounding box). There are cuts out of the cut surface *inside* the
brain. I have captured the latest result in
http://www.wbic.cam.ac.uk/~amw71/SurfaceCut3.png
(grey value tresholded:http://www.wbic.cam.ac.uk/~amw71/SurfaceCut.png,
plain clipped plane: http://www.wbic.cam.ac.uk/~amw71/SurfaceCut2.png)
I am still trying to find a way to show the cut planes with the grey
values inside, but with the planes cut so that only the part inside the
surface is shown.
Does this output make any sense (to anybody)?
Thanks!
Alle Meije
attached: script to show isosurface and saggital cut-plane
===========================================================
############################################################
# Prepare the GUI
catch {load vtktcl}
source vtkInt.tcl
source colors.tcl
############################################################
# Load the brain data
vtkImageReader anatomyReader
anatomyReader SetFileName "BrainTemplate.vtk"
anatomyReader SetFileDimensionality 3
anatomyReader SetHeaderSize 215
anatomyReader SetDataSpacing 1 1 1
anatomyReader SetDataExtent 0 90 0 108 0 90
anatomyReader SetDataScalarTypeToUnsignedChar
############################################################
# generate the isosurface from the ICBM template
vtkMarchingCubes BrainIso
BrainIso SetInput [anatomyReader GetOutput]
BrainIso SetValue 0 70
vtkSmoothPolyDataFilter smooth
smooth SetInput [BrainIso GetOutput]
smooth SetNumberOfIterations 20
vtkTriangleFilter triangulate
triangulate SetInput [smooth GetOutput]
############################################################
# clip the brain
vtkPoints points
points InsertPoint 0 50.3 58.0 36.0
points InsertPoint 1 50.3 58.0 36.0
points InsertPoint 2 50.3 58.0 36.0
vtkFloatArray normals
normals SetNumberOfComponents 3
normals SetNumberOfTuples 3
normals SetTuple3 0 1.0 0.0 0.0
normals SetTuple3 1 0.0 -1.0 0.0
normals SetTuple3 2 0.0 0.0 -1.0
vtkPlanes clipplanes
clipplanes SetPoints points
clipplanes SetNormals normals
vtkClipPolyData clipper
clipper SetInput [triangulate GetOutput]
clipper SetClipFunction clipplanes
vtkPolyDataMapper BrainIsoMapper
BrainIsoMapper SetInput [clipper GetOutput]
BrainIsoMapper ScalarVisibilityOff
vtkActor BrainIsoActor
BrainIsoActor SetMapper BrainIsoMapper
eval [BrainIsoActor GetProperty] SetColor .6 .3 .3
eval [BrainIsoActor GetProperty] SetOpacity 1
# set origins at centres of volumes
BrainIsoActor SetOrigin 46 55 46
############################################################
# generate the slices at the clipping position
############################################################
# cutplane: Sag
# cut the volume (make cut-plane with grey values)
vtkPlane planeSag
planeSag SetOrigin 50.3 58.0 36.0
planeSag SetNormal -1 0 0
vtkCutter cutSag
cutSag SetInput [anatomyReader GetOutput]
cutSag SetCutFunction planeSag
# cut the isosurface (make a contour+normals of the cut)
vtkPolyDataNormals isoNormals
isoNormals SetInput [smooth GetOutput]
vtkCutter cutEdgesSag;
cutEdgesSag SetInput [isoNormals GetOutput]
cutEdgesSag SetCutFunction planeSag
vtkStripper cutStripsSag;
cutStripsSag SetInput [cutEdgesSag GetOutput]
cutStripsSag Update
vtkImplicitSelectionLoop cutLoopSag
cutLoopSag SetLoop [[cutEdgesSag GetOutput] GetPoints]
vtkClipPolyData clippedCutSag
clippedCutSag SetInput [cutSag GetOutput]
clippedCutSag SetClipFunction cutLoopSag
# make the actor for the saggittal cutplane
vtkPolyDataMapper cutPlaneMapperSag
cutPlaneMapperSag SetInput [clippedCutSag GetOutput]
vtkActor actorSag
actorSag SetMapper cutPlaneMapperSag
############################################################
# Create the RenderWindow, Renderer and add Actors
# Create the camera
vtkCamera camera
camera SetFocalPoint 46 55 46
camera SetPosition -80 -40 -50
camera Azimuth 180
camera Roll 270
# add the actors
vtkRenderer renWindow
renWindow SetActiveCamera camera
renWindow AddActor BrainIsoActor
renWindow AddActor actorSag
renWindow SetBackground .5 .5 .5
# Use the camera in the renderwindow
vtkRenderWindow renWin
renWin AddRenderer renWindow
renWin SetSize 512 512
vtkRenderWindowInteractor RenderControl
RenderControl SetRenderWindow renWin
RenderControl Initialize
############################################################
# Define custom interaction.
vtkRenderWindowInteractor iren
iren SetInteractorStyle ""
iren SetRenderWindow renWin
iren AddObserver KeyPressEvent Keypress
############################################################
# write out files in other formats
file delete -force Cover.wrl
vtkVRMLExporter vrml
vrml SetInput renWin
vrml SetFileName Cover.wrl
vrml Write
# prevent the tk window from showing up, then start the event loop
wm withdraw .
___________________________________________________________
To help you stay safe and secure online, we've developed the all new Yahoo! Security Centre. http://uk.security.yahoo.com
More information about the vtkusers
mailing list