<div dir="ltr">You need a vtkPlane, not a vtkPlaneSource to do the cutting. The vtkPlaceSource produces polydata. The vtkPlane is an implicit function. vtkCutter uses implicit functions to cut the data.<div><br></div><div>
<br></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Thu, Aug 1, 2013 at 11:46 AM, Daniël Lacko <span dir="ltr"><<a href="mailto:lacko.daniel@outlook.com" target="_blank">lacko.daniel@outlook.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div><div dir="ltr">Hi all,<br><br>I'm trying to calculate the circumference of the human head in 3D. I'm using VTK 5.10.1 and Python 2.7 64-bit. I want to calculate the intersection of a plane passing through certain point on the head. I then want to extract the boundary and calculate the length of this polyline. First, I want to visualize the boundary to make sure the extraction is working as expected.<br>
<br>As far as I understand, I can use vtkCutter to cut a slice from the original image. When I modify the vtkCutter ClipCow.py example, I can use vtkFeatureExtract to extract the boundary and write it to a .vtk file for visualization:<br>
<br> # Here we are cutting the cow. Cutting creates lines where the cut<br> # function intersects the model. (Clipping removes a portion of the<br> # model but the dimension of the data does not change.)<br> #<br>
# The reason we are cutting is to generate a closed polygon at the<br> # boundary of the clipping process. The cutter generates line<br> # segments, the stripper then puts them together into polylines. We<br> # then pull a trick and define polygons using the closed line<br>
# segments that the stripper created.<br> cutEdges = vtk.vtkCutter()<br> cutEdges.SetInputConnection(cow.GetOutputPort())<br> cutEdges.SetCutFunction(plane)<br> cutEdges.GenerateCutScalarsOn()<br> cutEdges.SetValue(0, 0.5)<br>
cutStrips = vtk.vtkStripper()<br> cutStrips.SetInputConnection(cutEdges.GetOutputPort())<br> cutStrips.Update()<br> cutPoly = vtk.vtkPolyData()<br> cutPoly.SetPoints(cutStrips.GetOutput().GetPoints())<br> cutPoly.SetPolys(cutStrips.GetOutput().GetLines())<br>
<br> # Extract boundary from cutPoly<br> cutBoundary = vtk.vtkFeatureEdges()<br> cutBoundary.SetInput(cutPoly)<br> cutBoundary.Update()<br> # Write cut line to .vtk file<br> polyWriter = vtk.vtkPolyDataWriter()<br>
polyWriter.SetInput(cutBoundary.GetOutput())<br> polyWriter.SetFileName("cutPoly.vtk")<br> polyWriter.Write()<br><br>The code works as intended. However, if I try using it with my own code, it won't read the surface data correctly:<br>
<br> # Circumference plane (used to cut)<br> circPlaneSource = vtk.vtkPlaneSource()<br> circPlaneSource.SetOrigin(G - <br> 150*self.midSagittalPlaneNormal)<br> circPlaneSource.SetPoint1(Op -<br> 150*self.midSagittalPlaneNormal)<br>
circPlaneSource.SetPoint2(G +<br> 150*self.midSagittalPlaneNormal)<br> circPlaneSource.SetResolution(15, 15)<br> circPlaneSource.Update()<br><br> surface = vtk.vtkSTLReader()<br> surface.SetFileName(fileName)<br>
<br> # Cut a slice out of the surface and convert it to a PolyData object<br> cutEdges = vtk.vtkCutter()<br> cutEdges.SetInputConnection(surface.GetOutputPort())<br> cutEdges.SetCutFunction(circPlaneSource.GetOutput())<br>
cutEdges.GenerateCutScalarsOn()<br> cutEdges.SetValue(0, 0.5)<br> cutStrips = vtk.vtkStripper()<br> cutStrips.SetInputConnection(cutEdges.GetOutputPort())<br> cutStrips.Update()<br> cutPoly = vtk.vtkPolyData()<br>
cutPoly.SetPoints(cutStrips.GetOutput().GetPoints())<br> cutPoly.SetPolys(cutStrips.GetOutput().GetLines())<br> <br> # Extract boundary from cutPoly<br> cutBoundary = vtk.vtkFeatureEdges()<br> cutBoundary.SetInput(cutPoly)<br>
cutBoundary.Update()<br><br> # Write cut line to .vtk file<br> polyWriter = vtk.vtkPolyDataWriter()<br> polyWriter.SetInput(cutBoundary.GetOutput())<br> polyWriter.SetFileName("test.vtk")<br> polyWriter.Write()<br>
<br>I don't get an error message, the code just hangs at the cutEdges.SetInputConnection(...). The only significant difference as far as I can tell is that I'm using an .stl file instead of a .g file. Shouldn't the outputport data from vtkSTLReader and vtkBYUReader be the same (a vtkAlgorithm object in this case)? <br>
<br>Though I've been using bits and pieces of vtk code over the past year, I'm still very unexperienced in VTK (and image processing in general). Am I supposed to extract the data from vtkSTLReader in a different way? Any help would be greatly appreciated.<br>
<br>Kind regards,<br><br>Daniel<br>                                            </div></div>
<br>_______________________________________________<br>
Powered by <a href="http://www.kitware.com" target="_blank">www.kitware.com</a><br>
<br>
Visit other Kitware open-source projects at <a href="http://www.kitware.com/opensource/opensource.html" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
<br>
Please keep messages on-topic and check the VTK FAQ at: <a href="http://www.vtk.org/Wiki/VTK_FAQ" target="_blank">http://www.vtk.org/Wiki/VTK_FAQ</a><br>
<br>
Follow this link to subscribe/unsubscribe:<br>
<a href="http://www.vtk.org/mailman/listinfo/vtkusers" target="_blank">http://www.vtk.org/mailman/listinfo/vtkusers</a><br>
<br></blockquote></div><br><br clear="all"><div><br></div>-- <br>Unpaid intern in BillsBasement at noware dot com<br>
</div>