<html>
  <head>
    <meta content="text/html; charset=ISO-8859-1"
      http-equiv="Content-Type">
  </head>
  <body text="#000000" bgcolor="#FFFFFF">
    <div class="moz-cite-prefix">I want to reach a jpg file because I
      have to process the image afterwards.<br>
      It works fine for the circle so I expect it should also work for
      my polydata.<br>
      <br>
      But yes I have tried it with a *.mhd file.<br>
      When I display it with a vtkImageViewer2 and move the mouse I get
      a white square, but this is not my expected slice.<br>
      If I render my slice in 3D ("circle" object) it shows it
      correctly.<br>
      <br>
      Best regards<br>
      Marc<br>
      <br>
      Am 5/10/2013 1:25 AM, schrieb Alex Malyushytskyy:<br>
    </div>
    <blockquote
cite="mid:CAHR9pJ02gTgsFum5U8EPWFA-Z0=BQOVZhpQhLM9r8J9c05aO3w@mail.gmail.com"
      type="cite">
      <div dir="ltr">
        <div>
          <div>Have you tried to use <font color="#006600">vtkMetaImageWriter</font><br>
          </div>
          to write data for your code, so you can stop questioning&nbsp; if
          problem is with the way you write jpg?<br>
          <br>
        </div>
        Alex<br>
        <div>
          <div><br>
            <br>
          </div>
        </div>
      </div>
      <div class="gmail_extra"><br>
        <br>
        <div class="gmail_quote">On Thu, May 9, 2013 at 11:35 AM, Marc
          Huber <span dir="ltr">&lt;<a moz-do-not-send="true"
              href="mailto:marchuber.hft@gmx.de" target="_blank">marchuber.hft@gmx.de</a>&gt;</span>
          wrote:<br>
          <blockquote class="gmail_quote" style="margin:0 0 0
            .8ex;border-left:1px #ccc solid;padding-left:1ex">
            <div 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 moz-do-not-send="true"
href="http://www.vtk.org/Wiki/VTK/Examples/Cxx/PolyData/PolyDataContourToImageData"
                target="_blank">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>
                &nbsp;&nbsp;&nbsp; //vtkSmartPointer&lt;vtkSphereSource&gt;
                sphereSource =
                vtkSmartPointer&lt;vtkSphereSource&gt;::New();<br>
                &nbsp;&nbsp;&nbsp; //&nbsp;&nbsp;&nbsp; sphereSource-&gt;SetPhiResolution(30);<br>
                &nbsp;&nbsp;&nbsp; //&nbsp;&nbsp;&nbsp; sphereSource-&gt;SetThetaResolution(30);<br>
                &nbsp;&nbsp;&nbsp; //&nbsp;&nbsp;&nbsp; sphereSource-&gt;SetCenter(40, 40, 0);<br>
                &nbsp;&nbsp;&nbsp; //&nbsp;&nbsp;&nbsp; sphereSource-&gt;SetRadius(20);</font><br>
              <br>
              <font color="#ff0000">&nbsp;&nbsp;&nbsp; //MY CODE<br>
                &nbsp;&nbsp;&nbsp; vtkSmartPointer&lt;vtkPolyData&gt; polydata =
                vtkSmartPointer&lt;vtkPolyData&gt;::New();&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br>
                &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
polydata-&gt;ShallowCopy(stlActor-&gt;GetMapper()-&gt;GetInputAsDataSet());</font><br>
              &nbsp;&nbsp;&nbsp; <br>
              &nbsp;&nbsp;&nbsp; vtkSmartPointer&lt;vtkCutter&gt; circleCutter =
              vtkSmartPointer&lt;vtkCutter&gt;::New();<br>
              <font color="#006600">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
                //circleCutter-&gt;SetInputConnection(sphereSource-&gt;GetOutputPort());&nbsp;

                //ORIGINAL</font><br>
              &nbsp;&nbsp;&nbsp; &nbsp;<font color="#ff0000">&nbsp;&nbsp;
                circleCutter-&gt;SetInputConnection(polydata-&gt;GetProducerPort());
                //MY CODE</font><br>
              &nbsp;&nbsp;&nbsp; vtkSmartPointer&lt;vtkPlane&gt; cutPlane =
              vtkSmartPointer&lt;vtkPlane&gt;::New();<br>
              <font color="#006600">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
                //cutPlane-&gt;SetOrigin(sphereSource-&gt;GetCenter());
                //ORIGINAL</font><br>
              &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;<font color="#ff0000">&nbsp;
                cutPlane-&gt;SetOrigin(polydata-&gt;GetCenter()); //MY
                CODE</font><br>
              &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; cutPlane-&gt;SetNormal(0, 0, 1);<br>
              &nbsp;&nbsp;&nbsp; circleCutter-&gt;SetCutFunction(cutPlane);<br>
              &nbsp;&nbsp;&nbsp; vtkSmartPointer&lt;vtkStripper&gt; stripper =
              vtkSmartPointer&lt;vtkStripper&gt;::New();<br>
              &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
              stripper-&gt;SetInputConnection(circleCutter-&gt;GetOutputPort());
              // valid circle<br>
              &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; stripper-&gt;Update();<br>
              &nbsp;&nbsp;&nbsp; // that's our circle<br>
              &nbsp;&nbsp;&nbsp; vtkSmartPointer&lt;vtkPolyData&gt; circle =
              stripper-&gt;GetOutput();<br>
              &nbsp;<br>
              &nbsp;&nbsp;&nbsp; // write circle out<br>
              &nbsp;&nbsp;&nbsp; vtkSmartPointer&lt;vtkXMLPolyDataWriter&gt;
              polyDataWriter =
              vtkSmartPointer&lt;vtkXMLPolyDataWriter&gt;::New();<br>
              &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; polyDataWriter-&gt;SetInput(circle);<br>
              &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; polyDataWriter-&gt;SetFileName("circle.vtp");<br>
              &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; polyDataWriter-&gt;SetCompressorTypeToNone();<br>
              &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; polyDataWriter-&gt;SetDataModeToAscii();<br>
              &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; polyDataWriter-&gt;Write();<br>
              &nbsp;<br>
              &nbsp;&nbsp;&nbsp; // prepare the binary image's voxel grid&nbsp;&nbsp;&nbsp; <br>
              &nbsp;&nbsp;&nbsp; double bounds[6];<br>
              &nbsp;&nbsp;&nbsp; circle-&gt;GetBounds(bounds);<br>
              &nbsp;&nbsp;&nbsp; double spacing[3]; // desired volume spacing<br>
              &nbsp;&nbsp;&nbsp; spacing[0] = 0.5;<br>
              &nbsp;&nbsp;&nbsp; spacing[1] = 0.5;<br>
              &nbsp;&nbsp;&nbsp; spacing[2] = 0.5;<br>
              &nbsp;&nbsp;&nbsp; vtkSmartPointer&lt;vtkImageData&gt; whiteImage =
              vtkSmartPointer&lt;vtkImageData&gt;::New();<br>
              &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; whiteImage-&gt;SetSpacing(spacing);<br>
              &nbsp;<br>
              &nbsp;&nbsp;&nbsp; // compute dimensions<br>
              &nbsp;&nbsp;&nbsp; int dim[3];<br>
              &nbsp;&nbsp;&nbsp; for (int i = 0; i &lt; 3; i++)<br>
              &nbsp;&nbsp;&nbsp; {<br>
              &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; dim[i] = static_cast&lt;int&gt;(ceil((bounds[i * 2
              + 1] - bounds[i * 2]) /spacing[i])) + 1;<br>
              &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if (dim[i] &lt; 1){ dim[i] = 1;}<br>
              &nbsp;&nbsp;&nbsp; }<br>
              &nbsp;&nbsp;&nbsp; whiteImage-&gt;SetDimensions(dim);<br>
              &nbsp;&nbsp;&nbsp; whiteImage-&gt;SetExtent(0, dim[0] - 1, 0, dim[1] - 1,
              0, dim[2] - 1);<br>
              &nbsp;&nbsp;&nbsp; double origin[3];<br>
              &nbsp;&nbsp;&nbsp; // NOTE: I am not sure whether or not we had to add
              some offset!<br>
              &nbsp;&nbsp;&nbsp; origin[0] = bounds[0];// + spacing[0] / 2;<br>
              &nbsp;&nbsp;&nbsp; origin[1] = bounds[2];// + spacing[1] / 2;<br>
              &nbsp;&nbsp;&nbsp; origin[2] = bounds[4];// + spacing[2] / 2;<br>
              &nbsp;&nbsp;&nbsp; whiteImage-&gt;SetOrigin(origin);<br>
              &nbsp;&nbsp;&nbsp; whiteImage-&gt;SetScalarTypeToUnsignedChar();<br>
              &nbsp;&nbsp;&nbsp; whiteImage-&gt;AllocateScalars();<br>
              &nbsp;&nbsp;&nbsp; // fill the image with foreground voxels:<br>
              &nbsp;&nbsp;&nbsp; unsigned char inval = 255;<br>
              &nbsp;&nbsp;&nbsp; unsigned char outval = 0;<br>
              &nbsp;&nbsp;&nbsp; vtkIdType count = whiteImage-&gt;GetNumberOfPoints();<br>
              &nbsp;&nbsp;&nbsp; for (vtkIdType i = 0; i &lt; count; ++i)<br>
              &nbsp;&nbsp;&nbsp; {<br>
              &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
              whiteImage-&gt;GetPointData()-&gt;GetScalars()-&gt;SetTuple1(i,
              inval);<br>
              &nbsp;&nbsp;&nbsp; }<br>
              &nbsp;<br>
              &nbsp;&nbsp;&nbsp; // sweep polygonal data (this is the important thing
              with contours!)<br>
              &nbsp;&nbsp;&nbsp; vtkSmartPointer&lt;vtkLinearExtrusionFilter&gt;
              extruder =<br>
              &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
              vtkSmartPointer&lt;vtkLinearExtrusionFilter&gt;::New();<br>
              &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; extruder-&gt;SetInput(circle);<br>
              &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; extruder-&gt;SetScaleFactor(1.);<br>
              &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; extruder-&gt;SetExtrusionTypeToNormalExtrusion();<br>
              &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; extruder-&gt;SetVector(0, 0, 1);<br>
              &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; extruder-&gt;Update();<br>
              &nbsp;<br>
              &nbsp;&nbsp;&nbsp; // polygonal data --&gt; image stencil:<br>
              &nbsp;&nbsp;&nbsp; vtkSmartPointer&lt;vtkPolyDataToImageStencil&gt;
              pol2stenc =
              vtkSmartPointer&lt;vtkPolyDataToImageStencil&gt;::New();<br>
              &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; pol2stenc-&gt;SetTolerance(0); // important if
              extruder-&gt;SetVector(0, 0, 1) !!!<br>
              &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
              pol2stenc-&gt;SetInputConnection(extruder-&gt;GetOutputPort());<br>
              &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; pol2stenc-&gt;SetOutputOrigin(origin);<br>
              &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; pol2stenc-&gt;SetOutputSpacing(spacing);<br>
              &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
              pol2stenc-&gt;SetOutputWholeExtent(whiteImage-&gt;GetExtent());<br>
              &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; pol2stenc-&gt;Update();<br>
              &nbsp;<br>
              &nbsp;&nbsp;&nbsp; // cut the corresponding white image and set the
              background:<br>
              &nbsp;&nbsp;&nbsp; vtkSmartPointer&lt;vtkImageStencil&gt; imgstenc =
              vtkSmartPointer&lt;vtkImageStencil&gt;::New();<br>
              &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; imgstenc-&gt;SetInput(whiteImage);<br>
              &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
              imgstenc-&gt;SetStencil(pol2stenc-&gt;GetOutput());<br>
              &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; imgstenc-&gt;ReverseStencilOff();<br>
              &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; imgstenc-&gt;SetBackgroundValue(outval);<br>
              &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; imgstenc-&gt;Update();<br>
              &nbsp;<br>
              <font color="#006600">&nbsp;&nbsp;&nbsp; //ORIGINAL CODE<br>
                &nbsp;&nbsp;&nbsp; //vtkSmartPointer&lt;vtkMetaImageWriter&gt;
                imageWriter =<br>
                &nbsp;&nbsp;&nbsp; //&nbsp;
                vtkSmartPointer&lt;vtkMetaImageWriter&gt;::New();<br>
                &nbsp;&nbsp;&nbsp; //imageWriter-&gt;SetFileName("labelImage.mhd");<br>
                &nbsp;&nbsp;&nbsp;
                //imageWriter-&gt;SetInputConnection(imgstenc-&gt;GetOutputPort());<br>
                &nbsp;&nbsp;&nbsp; //imageWriter-&gt;Write();</font><br>
              &nbsp;<br>
              <font color="#ff0000">&nbsp;&nbsp;&nbsp; //MY CODE<br>
                &nbsp; &nbsp;&nbsp;&nbsp; vtkSmartPointer&lt;vtkJPEGWriter&gt; cutWriter =
                vtkSmartPointer&lt;vtkJPEGWriter&gt;::New();<br>
                &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; cutWriter-&gt;SetFileName("cut1.jpg");<br>
                &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
                cutWriter-&gt;SetInputConnection(imgstenc-&gt;GetOutputPort());<br>
                &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; cutWriter-&gt;Write(); </font><br>
              <span class="HOEnZb"><font color="#888888">
                  <pre cols="72">
</pre>
                </font></span></div>
            <br>
            _______________________________________________<br>
            Powered by <a moz-do-not-send="true"
              href="http://www.kitware.com" target="_blank">www.kitware.com</a><br>
            <br>
            Visit other Kitware open-source projects at <a
              moz-do-not-send="true"
              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
              moz-do-not-send="true"
              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 moz-do-not-send="true"
              href="http://www.vtk.org/mailman/listinfo/vtkusers"
              target="_blank">http://www.vtk.org/mailman/listinfo/vtkusers</a><br>
            <br>
          </blockquote>
        </div>
        <br>
      </div>
    </blockquote>
    <br>
    <br>
  </body>
</html>