<html>
  <head>

    <meta http-equiv="content-type" content="text/html; charset=ISO-8859-15">
  </head>
  <body text="#000000" bgcolor="#FFFFFF">
    Hi,<br>
    <br>
    I wanted to cut a polydata object in several slices<br>
    <br>
    When I apply this example it works all fine:<br>
<a class="moz-txt-link-freetext" href="http://www.vtk.org/Wiki/VTK/Examples/Cxx/PolyData/PolyDataContourToImageData">http://www.vtk.org/Wiki/VTK/Examples/Cxx/PolyData/PolyDataContourToImageData</a><br>
    <br>
    But I have a polydata object and no sphere and I want to produce a
    *.jpg file.<br>
    My result is just a black image and I'm wondering what the problem
    might be.<br>
    Has anyone an idea?<br>
    <br>
    Here is my code (Original code commented out and mine in red):<br>
    <br>
    <font color="#006600">//ORIGINAL CODE<br>
          //vtkSmartPointer&lt;vtkSphereSource&gt; sphereSource =
      vtkSmartPointer&lt;vtkSphereSource&gt;::New();<br>
          //    sphereSource-&gt;SetPhiResolution(30);<br>
          //    sphereSource-&gt;SetThetaResolution(30);<br>
          //    sphereSource-&gt;SetCenter(40, 40, 0);<br>
          //    sphereSource-&gt;SetRadius(20);</font><br>
    <br>
    <font color="#ff0000">    //MY CODE<br>
          vtkSmartPointer&lt;vtkPolyData&gt; polydata =
      vtkSmartPointer&lt;vtkPolyData&gt;::New();        <br>
             
polydata-&gt;ShallowCopy(stlActor-&gt;GetMapper()-&gt;GetInputAsDataSet());</font><br>
        <br>
        vtkSmartPointer&lt;vtkCutter&gt; circleCutter =
    vtkSmartPointer&lt;vtkCutter&gt;::New();<br>
    <font color="#006600">       
      //circleCutter-&gt;SetInputConnection(sphereSource-&gt;GetOutputPort()); 
      //ORIGINAL</font><br>
         <font color="#ff0000">  
      circleCutter-&gt;SetInputConnection(polydata-&gt;GetProducerPort());
      //MY CODE</font><br>
        vtkSmartPointer&lt;vtkPlane&gt; cutPlane =
    vtkSmartPointer&lt;vtkPlane&gt;::New();<br>
    <font color="#006600">       
      //cutPlane-&gt;SetOrigin(sphereSource-&gt;GetCenter()); //ORIGINAL</font><br>
          <font color="#ff0000"> 
      cutPlane-&gt;SetOrigin(polydata-&gt;GetCenter()); //MY CODE</font><br>
            cutPlane-&gt;SetNormal(0, 0, 1);<br>
        circleCutter-&gt;SetCutFunction(cutPlane);<br>
        vtkSmartPointer&lt;vtkStripper&gt; stripper =
    vtkSmartPointer&lt;vtkStripper&gt;::New();<br>
           
    stripper-&gt;SetInputConnection(circleCutter-&gt;GetOutputPort());
    // valid circle<br>
            stripper-&gt;Update();<br>
        // that's our circle<br>
        vtkSmartPointer&lt;vtkPolyData&gt; circle =
    stripper-&gt;GetOutput();<br>
     <br>
        // write circle out<br>
        vtkSmartPointer&lt;vtkXMLPolyDataWriter&gt; polyDataWriter =
    vtkSmartPointer&lt;vtkXMLPolyDataWriter&gt;::New();<br>
            polyDataWriter-&gt;SetInput(circle);<br>
            polyDataWriter-&gt;SetFileName("circle.vtp");<br>
            polyDataWriter-&gt;SetCompressorTypeToNone();<br>
            polyDataWriter-&gt;SetDataModeToAscii();<br>
            polyDataWriter-&gt;Write();<br>
     <br>
        // prepare the binary image's voxel grid    <br>
        double bounds[6];<br>
        circle-&gt;GetBounds(bounds);<br>
        double spacing[3]; // desired volume spacing<br>
        spacing[0] = 0.5;<br>
        spacing[1] = 0.5;<br>
        spacing[2] = 0.5;<br>
        vtkSmartPointer&lt;vtkImageData&gt; whiteImage =
    vtkSmartPointer&lt;vtkImageData&gt;::New();<br>
            whiteImage-&gt;SetSpacing(spacing);<br>
     <br>
        // compute dimensions<br>
        int dim[3];<br>
        for (int i = 0; i &lt; 3; i++)<br>
        {<br>
            dim[i] = static_cast&lt;int&gt;(ceil((bounds[i * 2 + 1] -
    bounds[i * 2]) /spacing[i])) + 1;<br>
            if (dim[i] &lt; 1){ dim[i] = 1;}<br>
        }<br>
        whiteImage-&gt;SetDimensions(dim);<br>
        whiteImage-&gt;SetExtent(0, dim[0] - 1, 0, dim[1] - 1, 0, dim[2]
    - 1);<br>
        double origin[3];<br>
        // NOTE: I am not sure whether or not we had to add some offset!<br>
        origin[0] = bounds[0];// + spacing[0] / 2;<br>
        origin[1] = bounds[2];// + spacing[1] / 2;<br>
        origin[2] = bounds[4];// + spacing[2] / 2;<br>
        whiteImage-&gt;SetOrigin(origin);<br>
        whiteImage-&gt;SetScalarTypeToUnsignedChar();<br>
        whiteImage-&gt;AllocateScalars();<br>
        // fill the image with foreground voxels:<br>
        unsigned char inval = 255;<br>
        unsigned char outval = 0;<br>
        vtkIdType count = whiteImage-&gt;GetNumberOfPoints();<br>
        for (vtkIdType i = 0; i &lt; count; ++i)<br>
        {<br>
           
    whiteImage-&gt;GetPointData()-&gt;GetScalars()-&gt;SetTuple1(i,
    inval);<br>
        }<br>
     <br>
        // sweep polygonal data (this is the important thing with
    contours!)<br>
        vtkSmartPointer&lt;vtkLinearExtrusionFilter&gt; extruder =<br>
            vtkSmartPointer&lt;vtkLinearExtrusionFilter&gt;::New();<br>
            extruder-&gt;SetInput(circle);<br>
            extruder-&gt;SetScaleFactor(1.);<br>
            extruder-&gt;SetExtrusionTypeToNormalExtrusion();<br>
            extruder-&gt;SetVector(0, 0, 1);<br>
            extruder-&gt;Update();<br>
     <br>
        // polygonal data --&gt; image stencil:<br>
        vtkSmartPointer&lt;vtkPolyDataToImageStencil&gt; pol2stenc =
    vtkSmartPointer&lt;vtkPolyDataToImageStencil&gt;::New();<br>
            pol2stenc-&gt;SetTolerance(0); // important if
    extruder-&gt;SetVector(0, 0, 1) !!!<br>
           
    pol2stenc-&gt;SetInputConnection(extruder-&gt;GetOutputPort());<br>
            pol2stenc-&gt;SetOutputOrigin(origin);<br>
            pol2stenc-&gt;SetOutputSpacing(spacing);<br>
           
    pol2stenc-&gt;SetOutputWholeExtent(whiteImage-&gt;GetExtent());<br>
            pol2stenc-&gt;Update();<br>
     <br>
        // cut the corresponding white image and set the background:<br>
        vtkSmartPointer&lt;vtkImageStencil&gt; imgstenc =
    vtkSmartPointer&lt;vtkImageStencil&gt;::New();<br>
            imgstenc-&gt;SetInput(whiteImage);<br>
            imgstenc-&gt;SetStencil(pol2stenc-&gt;GetOutput());<br>
            imgstenc-&gt;ReverseStencilOff();<br>
            imgstenc-&gt;SetBackgroundValue(outval);<br>
            imgstenc-&gt;Update();<br>
     <br>
    <font color="#006600">    //ORIGINAL CODE<br>
          //vtkSmartPointer&lt;vtkMetaImageWriter&gt; imageWriter =<br>
          //  vtkSmartPointer&lt;vtkMetaImageWriter&gt;::New();<br>
          //imageWriter-&gt;SetFileName("labelImage.mhd");<br>
         
      //imageWriter-&gt;SetInputConnection(imgstenc-&gt;GetOutputPort());<br>
          //imageWriter-&gt;Write();</font><br>
     <br>
    <font color="#ff0000">    //MY CODE<br>
            vtkSmartPointer&lt;vtkJPEGWriter&gt; cutWriter =
      vtkSmartPointer&lt;vtkJPEGWriter&gt;::New();<br>
              cutWriter-&gt;SetFileName("cut1.jpg");<br>
             
      cutWriter-&gt;SetInputConnection(imgstenc-&gt;GetOutputPort());<br>
              cutWriter-&gt;Write(); </font><br>
    <pre class="moz-signature" cols="72">-- 
Best regards / Mit freundlichen Grüßen
Marc Huber</pre>
  </body>
</html>