Hello Paul, instead of using vtkExtractSelection, you can use vtkExtractSelectedPolydataIds.  Here is a code example you can use.<div>And you will have a polydata as a result instead of an UG .<br><div><br></div><div><br></div>

<div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><span class="Apple-tab-span" style="white-space:pre">        </span>vtkSmartPointer&lt;vtkIdTypeArray&gt; ids = vtkSmartPointer&lt;vtkIdTypeArray&gt;::New();<br>

<span class="Apple-tab-span" style="white-space:pre">        </span>ids-&gt;SetNumberOfComponents(1);<br></blockquote><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">

 </blockquote><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><span class="Apple-tab-span" style="white-space:pre">        </span>  // Set values<br>

</blockquote><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">        std::vector&lt;int&gt; idsForNewPolydata ;</blockquote>

<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">         //Put ids you want into  idsForNewPolydata</blockquote>

<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><br></blockquote><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">

<span class="Apple-tab-span" style="white-space:pre">        </span>std::vector&lt;int&gt;::iterator it;<br><span class="Apple-tab-span" style="white-space:pre">        </span>for (it = idsForNewPolydata.begin(); it != idsForNewPolydata.end(); it++)  // idsForNewPolydata in your case should be id&#39;s from 0 to <span style="background-color:rgb(255,255,255);color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px">nCellsNum</span>/2</blockquote>

<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><span class="Apple-tab-span" style="white-space:pre">        </span>{<br>

<span class="Apple-tab-span" style="white-space:pre">                </span>int currentIndice = *it;<br><span class="Apple-tab-span" style="white-space:pre">                </span>ids-&gt;InsertNextValue(currentIndice);<br><span class="Apple-tab-span" style="white-space:pre">        </span>}<br>

<span class="Apple-tab-span" style="white-space:pre"></span></blockquote><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">

 </blockquote><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><span class="Apple-tab-span" style="white-space:pre">        </span>vtkSmartPointer&lt;vtkSelectionNode&gt; selectionNode = vtkSmartPointer&lt;vtkSelectionNode&gt;::New();<br>

<span class="Apple-tab-span" style="white-space:pre">        </span>selectionNode-&gt;SetFieldType(vtkSelectionNode::CELL);<br><span class="Apple-tab-span" style="white-space:pre">        </span>selectionNode-&gt;SetContentType(vtkSelectionNode::INDICES);<br>

<span class="Apple-tab-span" style="white-space:pre">        </span>selectionNode-&gt;SetSelectionList(ids);<br></blockquote><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">

 </blockquote><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><span class="Apple-tab-span" style="white-space:pre">        </span>vtkSmartPointer&lt;vtkSelection&gt; selection = vtkSmartPointer&lt;vtkSelection&gt;::New();<br>

<span class="Apple-tab-span" style="white-space:pre">        </span>selection-&gt;AddNode(selectionNode);<br><span class="Apple-tab-span" style="white-space:pre"></span></blockquote><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">

 </blockquote><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><span class="Apple-tab-span" style="white-space:pre">        </span>vtkSmartPointer&lt;vtkExtractSelectedPolyDataIds&gt; extractSelectedIds =<span class="Apple-tab-span" style="white-space:pre">        </span>vtkSmartPointer&lt;vtkExtractSelectedPolyDataIds&gt;::New();<br>

<span class="Apple-tab-span" style="white-space:pre">        </span>extractSelectedIds-&gt;SetInput(0, polydata);<br><span class="Apple-tab-span" style="white-space:pre">        </span>extractSelectedIds-&gt;SetInput(1, selection);<br>

<span class="Apple-tab-span" style="white-space:pre">        </span>extractSelectedIds-&gt;Update();<br></blockquote><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">

 </blockquote><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><span class="Apple-tab-span" style="white-space:pre">        </span>vtkPolyData* finalPolyData = extractSelectedIds-&gt;GetOutput();</blockquote>

</div><div><br></div><div><br>Cheers, </div><div>Gonzalo..</div><div><br></div><div><br><div class="gmail_quote">2012/8/13 Paul McIntosh <span dir="ltr">&lt;<a href="mailto:paul.mcintosh@internetscooter.com" target="_blank">paul.mcintosh@internetscooter.com</a>&gt;</span><br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi David,<br>
<br>
Thanks for your response - attached is a stl generated from a sphere source<br>
and program the output from using this example.<br>
<br>
The input polydata has &quot;Number Of Cells: 96&quot; (so is read ok) - I select half<br>
of those cells and it appears to be correct as following reports &quot;48&quot; :<br>
<div class="im">&quot;cout &lt;&lt; &quot;Selected Cells: &quot; &lt;&lt;<br>
cellSelection-&gt;GetNode(0)-&gt;GetSelectionList()-&gt;GetNumberOfTuples()<br>
<br>
</div>However the output polydata is missing the cells.<br>
<br>
  Number Of Points: 35<br>
  Number Of Cells: 0<br>
<br>
I am probably just missing an setting that brings the cells but I have been<br>
banging my head against this for a while and not making much headway.<br>
<br>
Any help much appreciated and I am also happy to add this to the vtk<br>
examples once it is working.<br>
<br>
Cheers,<br>
<br>
Paul<br>
<div><div class="h5"><br>
-----Original Message-----<br>
From: David Doria [mailto:<a href="mailto:daviddoria@gmail.com">daviddoria@gmail.com</a>]<br>
Sent: Sunday, 12 August 2012 11:07 PM<br>
To: Paul McIntosh<br>
Cc: <a href="mailto:vtkusers@vtk.org">vtkusers@vtk.org</a><br>
Subject: Re: [vtkusers] vtkPolyData and extracted selections<br>
<br>
On Sun, Aug 12, 2012 at 7:44 AM, Paul McIntosh<br>
&lt;<a href="mailto:paul.mcintosh@internetscooter.com">paul.mcintosh@internetscooter.com</a>&gt; wrote:<br>
&gt; Hi,<br>
&gt;<br>
&gt; I am creating a utility that will calculate the frontal area of a<br>
&gt; mesh. The first thing I am trying is extracting cells from a mesh by<br>
&gt; their id&#39;s (later I will change this to select cells that are visible<br>
&gt; from a particular direction). I am getting stuck though creating a new<br>
&gt; polydata object which is a subset of the original, using the<br>
&gt; selection. The VTK examples use an unstructuredgrid, but the same code<br>
&gt; doesn&#39;t work with polydata - can anyone see what I am doing wrong?<br>
&gt;<br>
&gt; Paul<br>
&gt;<br>
&gt;<br>
&gt; #include &lt;vtkPolyData.h&gt;<br>
&gt; #include &lt;vtkSTLWriter.h&gt;<br>
&gt; #include &lt;vtkSTLReader.h&gt;<br>
&gt; #include &lt;vtkTransform.h&gt;<br>
&gt; #include &lt;vtkTransformFilter.h&gt;<br>
&gt; #include &lt;vtkTriangle.h&gt;<br>
&gt; #include &lt;vtkSphereSource.h&gt;<br>
&gt; #include &lt;vtkSmartPointer.h&gt;<br>
&gt; #include &lt;vtkPolyDataMapper.h&gt;<br>
&gt; #include &lt;vtkIdTypeArray.h&gt;<br>
&gt; #include &lt;vtkSelectionNode.h&gt;<br>
&gt; #include &lt;vtkActor.h&gt;<br>
&gt; #include &lt;vtkRenderWindow.h&gt;<br>
&gt; #include &lt;vtkRenderer.h&gt;<br>
&gt; #include &lt;vtkRenderWindowInteractor.h&gt; #include<br>
&gt; &lt;vtkHardwareSelector.h&gt; #include &lt;vtkInteractorStyleTrackballCamera.h&gt;<br>
&gt; #include &lt;vtkRendererCollection.h&gt;<br>
&gt; #include &lt;vtkSelection.h&gt;<br>
&gt; #include &lt;vtkExtractSelection.h&gt;<br>
&gt; #include &lt;vtkDataSetMapper.h&gt;<br>
&gt; #include &lt;vtkProperty.h&gt;<br>
&gt; #include &lt;vtkObjectFactory.h&gt;<br>
&gt; #include &lt;vtkCellArray.h&gt;<br>
&gt; #include &lt;vtkCell.h&gt;<br>
&gt; #include &lt;vtkInformation.h&gt;<br>
&gt; #include &lt;vtkUnstructuredGrid.h&gt;<br>
&gt;<br>
&gt; // C++<br>
&gt; #include &lt;list&gt;<br>
&gt; #include &lt;iostream&gt;<br>
&gt; #include &lt;fstream&gt;<br>
&gt;<br>
&gt; using namespace std;<br>
&gt;<br>
&gt; int main(int argc, char *argv[])<br>
&gt; {<br>
&gt;         // check and get the stl input file provided<br>
&gt;     if ( argc != 2 )<br>
&gt;     {<br>
&gt;         cout &lt;&lt; &quot;Required parameters: Filename&quot; &lt;&lt; endl;<br>
&gt;         return EXIT_FAILURE;<br>
&gt;     }<br>
&gt;     std::string inputfile = argv[1];<br>
&gt;<br>
&gt;     // read STL and print out some info<br>
&gt;     std::cout &lt;&lt; &quot;Reading: &quot; &lt;&lt; inputfile &lt;&lt; std::endl;<br>
&gt;     vtkSmartPointer&lt;vtkSTLReader&gt; stlReader =<br>
&gt; vtkSmartPointer&lt;vtkSTLReader&gt;::New();<br>
&gt;     stlReader-&gt;SetFileName(inputfile.c_str());<br>
&gt;     vtkSmartPointer&lt;vtkPolyData&gt; polydata =<br>
&gt; vtkSmartPointer&lt;vtkPolyData&gt;::New();<br>
&gt;     polydata = stlReader-&gt;GetOutput();<br>
&gt;     polydata-&gt;Update();<br>
&gt;     cout &lt;&lt; &quot;Cells: &quot; &lt;&lt; polydata-&gt;GetNumberOfCells() &lt;&lt; endl;<br>
&gt;     cout &lt;&lt; &quot;Points: &quot; &lt;&lt; polydata-&gt;GetNumberOfPoints() &lt;&lt; endl;<br>
&gt;     cout &lt;&lt; &quot;Polys: &quot; &lt;&lt; polydata-&gt;GetNumberOfPolys() &lt;&lt; endl;<br>
&gt;     cout &lt;&lt; &quot;Verts: &quot; &lt;&lt; polydata-&gt;GetNumberOfVerts() &lt;&lt; endl;<br>
&gt;         polydata-&gt;Print(cout);<br>
&gt;<br>
&gt;         // select cells of interest<br>
&gt;         // ref: <a href="http://www.kitware.com/media/html/SelectionsInVTK.html" target="_blank">http://www.kitware.com/media/html/SelectionsInVTK.html</a><br>
&gt;     vtkSmartPointer&lt;vtkSelectionNode&gt; cellSelectionNode =<br>
&gt; vtkSmartPointer&lt;vtkSelectionNode&gt;::New();<br>
&gt;         cellSelectionNode-&gt;SetFieldType(vtkSelectionNode::CELL);<br>
&gt;         cellSelectionNode-&gt;SetContentType(vtkSelectionNode::INDICES);<br>
&gt;<br>
&gt;     vtkSmartPointer&lt;vtkIdTypeArray&gt; ids =<br>
&gt; vtkSmartPointer&lt;vtkIdTypeArray&gt;::New();<br>
&gt;     ids-&gt;SetNumberOfComponents(1);<br>
&gt;<br>
&gt;         int nCellsNum = polydata-&gt;GetNumberOfCells();<br>
&gt;         for (int nCellID = 0; nCellID &lt; nCellsNum/2; nCellID++)<br>
&gt;         {<br>
&gt;                 vtkCell* cell;<br>
&gt;                 cell = polydata-&gt;GetCell(nCellID);<br>
&gt;                 ids-&gt;InsertNextValue(nCellID);<br>
&gt;         }<br>
&gt;         cellSelectionNode-&gt;SetSelectionList(ids);<br>
&gt;         vtkSmartPointer&lt;vtkSelection&gt; cellSelection =<br>
&gt; vtkSmartPointer&lt;vtkSelection&gt;::New();<br>
&gt;       cellSelection-&gt;AddNode(cellSelectionNode);<br>
&gt;         cout &lt;&lt; &quot;Selected Cells: &quot; &lt;&lt;<br>
&gt; cellSelection-&gt;GetNode(0)-&gt;GetSelectionList()-&gt;GetNumberOfTuples() &lt;&lt;<br>
</div></div>&gt; cellSelection-&gt;endl;<br>
<div class="HOEnZb"><div class="h5">&gt;         //cellSelection-&gt;Print(cout);<br>
&gt;<br>
&gt;         // Extract Selection<br>
&gt;         vtkSmartPointer&lt;vtkExtractSelection&gt; extractSelection =<br>
&gt; vtkSmartPointer&lt;vtkExtractSelection&gt;::New();<br>
&gt;         extractSelection-&gt;SetInput(0, polydata);                // The<br>
&gt; dataset is given on its first input port<br>
&gt;         extractSelection-&gt;SetInput(1, cellSelection);   // The subset is<br>
&gt; described by the contents of the vtkSelection on its second input port<br>
&gt;         extractSelection-&gt;Update();<br>
&gt;         extractSelection-&gt;Print(cout);<br>
&gt;<br>
&gt;         vtkSmartPointer&lt;vtkPolyData&gt; selectedPolydata =<br>
&gt; vtkSmartPointer&lt;vtkPolyData&gt;::New();<br>
&gt;         selectedPolydata-&gt;ShallowCopy(extractSelection-&gt;GetOutput());<br>
&gt;         selectedPolydata-&gt;Print(cout);<br>
&gt;<br>
&gt;     // Visualise<br>
&gt;     vtkSmartPointer&lt;vtkPolyDataMapper&gt; selectedPolydataMapper =<br>
&gt; vtkSmartPointer&lt;vtkPolyDataMapper&gt;::New();<br>
&gt;         selectedPolydataMapper-&gt;SetInput(selectedPolydata);<br>
&gt;      vtkSmartPointer&lt;vtkActor&gt; actor = vtkSmartPointer&lt;vtkActor&gt;::New();<br>
&gt;      //actor-&gt;SetMapper(mapper);<br>
&gt;      actor-&gt;SetMapper(selectedPolydataMapper);<br>
&gt;<br>
&gt;      vtkSmartPointer&lt;vtkRenderer&gt; renderer =<br>
&gt; vtkSmartPointer&lt;vtkRenderer&gt;::New();<br>
&gt;      vtkSmartPointer&lt;vtkRenderWindow&gt; renderWindow =<br>
&gt; vtkSmartPointer&lt;vtkRenderWindow&gt;::New();<br>
&gt;      renderWindow-&gt;AddRenderer(renderer);<br>
&gt;      vtkSmartPointer&lt;vtkRenderWindowInteractor&gt; renderWindowInteractor<br>
&gt; = vtkSmartPointer&lt;vtkRenderWindowInteractor&gt;::New();<br>
&gt;      renderWindowInteractor-&gt;SetRenderWindow(renderWindow);<br>
&gt;<br>
&gt;      renderer-&gt;AddActor(actor);<br>
&gt;      renderer-&gt;SetBackground(.3, .6, .3); // Background color green<br>
&gt;<br>
&gt;      renderWindow-&gt;Render();<br>
&gt;      renderWindowInteractor-&gt;Start();<br>
&gt;<br>
&gt;     return EXIT_SUCCESS;<br>
&gt; }<br>
&gt;<br>
&gt; Cheers,<br>
&gt;<br>
&gt; Paul<br>
<br>
What do you mean &quot;doesn&#39;t work&quot;? What is the error? Please make your example<br>
self-contained (i.e. generate data (perhaps vtkSphereSource) instead of<br>
reading it from a file, etc) so it is easier for us to take a look.<br>
<br>
David<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>--------<br>Gonzalo Amadio<br><br>
</div></div>