<div><div class="gmail_quote">On Fri, May 18, 2012 at 8:55 AM, tasnim <span dir="ltr">&lt;<a href="mailto:hanene-jeder@hotmail.fr" target="_blank">hanene-jeder@hotmail.fr</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Hi David,<br>
thanks for your answer.Ok, this is my new code with some modifications:<br>
<div class="im">#include &lt;vtkSmartPointer.h&gt;<br>
#include &lt;vtkPolyDataMapper.h&gt;<br>
#include &lt;vtkActor.h&gt;<br>
#include &lt;vtkRenderWindow.h&gt;<br>
#include &lt;vtkRenderer.h&gt;<br>
#include &lt;vtkRenderWindowInteractor.h&gt;<br>
#include &lt;vtkOBJReader.h&gt;<br>
#include &lt;vtkUnstructuredGrid.h&gt;<br>
#include &lt;vtkCell.h&gt;<br>
#include &lt;vtkCellArray.h&gt;<br>
#include &lt;vtkIdList.h&gt;<br>
#include &lt;vtkUnsignedCharArray.h&gt;<br>
#include &lt;vtkPointData.h&gt;<br>
#include &lt;string&gt;<br>
</div><div class="im">#include &lt;vtkVersion.h&gt;<br>
#include &lt;vtkRendererCollection.h&gt;<br>
#include &lt;vtkDataSetMapper.h&gt;<br>
#include &lt;vtkIdTypeArray.h&gt;<br>
</div><div><div class="h5">#include &lt;vtkCommand.h&gt;<br>
#include &lt;vtkPolyData.h&gt;<br>
#include &lt;vtkPoints.h&gt;<br>
#include &lt;vtkCellPicker.h&gt;<br>
#include &lt;vtkInteractorStyleTrackballCamera.h&gt;<br>
#include &lt;vtkProperty.h&gt;<br>
#include &lt;vtkSelectionNode.h&gt;<br>
#include &lt;vtkSelection.h&gt;<br>
#include &lt;vtkExtractSelection.h&gt;<br>
#include &lt;vtkObjectFactory.h&gt;<br>
#include &lt;vtkGenericCell.h&gt;<br>
#include &lt;vtkLoopSubdivisionFilter.h&gt;<br>
#include &lt;vtkSphereSource.h&gt;<br>
// Catch mouse events<br>
class MouseInteractorStyle : public vtkInteractorStyleTrackballCamera<br>
{<br>
  public:<br>
  static MouseInteractorStyle* New();<br>
<br>
  MouseInteractorStyle()<br>
  {<br>
    selectedMapper = vtkSmartPointer&lt;vtkDataSetMapper&gt;::New();<br>
    selectedActor = vtkSmartPointer&lt;vtkActor&gt;::New();<br>
  }<br>
<br>
    virtual void OnLeftButtonDown()<br>
    {<br>
      // Get the location of the click (in window coordinates)<br>
      int* pos = this-&gt;GetInteractor()-&gt;GetEventPosition();<br>
<br>
      vtkSmartPointer&lt;vtkCellPicker&gt; picker =<br>
        vtkSmartPointer&lt;vtkCellPicker&gt;::New();<br>
      picker-&gt;SetTolerance(0.0005);<br>
       // Pick from this location.<br>
      picker-&gt;Pick(pos[0], pos[1], 0, this-&gt;GetDefaultRenderer());<br>
<br>
      double* worldPosition = picker-&gt;GetPickPosition();<br>
      std::cout &lt;&lt; &quot;Cell id is: &quot; &lt;&lt; picker-&gt;GetCellId() &lt;&lt; std::endl;<br>
<br>
      if(picker-&gt;GetCellId() != -1)<br>
        {<br>
<br>
        std::cout &lt;&lt; &quot;Pick position is: &quot; &lt;&lt; worldPosition[0] &lt;&lt; &quot; &quot; &lt;&lt;<br>
worldPosition[1]<br>
                  &lt;&lt; &quot; &quot; &lt;&lt; worldPosition[2] &lt;&lt; endl;<br>
<br>
        vtkSmartPointer&lt;vtkIdTypeArray&gt; ids =<br>
          vtkSmartPointer&lt;vtkIdTypeArray&gt;::New();<br>
        ids-&gt;SetNumberOfComponents(1);<br>
        ids-&gt;InsertNextValue(picker-&gt;GetCellId());<br>
<br>
        vtkSmartPointer&lt;vtkSelectionNode&gt; selectionNode =<br>
          vtkSmartPointer&lt;vtkSelectionNode&gt;::New();<br>
        selectionNode-&gt;SetFieldType(vtkSelectionNode::CELL);<br>
        selectionNode-&gt;SetContentType(vtkSelectionNode::INDICES);<br>
        selectionNode-&gt;SetSelectionList(ids);<br>
        vtkSmartPointer&lt;vtkSelection&gt; selection =<br>
          vtkSmartPointer&lt;vtkSelection&gt;::New();<br>
        selection-&gt;AddNode(selectionNode);<br>
<br>
        vtkSmartPointer&lt;vtkExtractSelection&gt; extractSelection =<br>
          vtkSmartPointer&lt;vtkExtractSelection&gt;::New();<br>
#if VTK_MAJOR_VERSION &lt;= 5<br>
        extractSelection-&gt;SetInput(0, this-&gt;Data);<br>
        extractSelection-&gt;SetInput(1, selection);<br>
#else<br>
        extractSelection-&gt;SetInputData(0, this-&gt;Data);<br>
        extractSelection-&gt;SetInputData(1, selection);<br>
#endif<br>
        extractSelection-&gt;Update();<br>
         // In selection<br>
        vtkSmartPointer&lt;vtkUnstructuredGrid&gt; selected =<br>
          vtkSmartPointer&lt;vtkUnstructuredGrid&gt;::New();<br>
        selected-&gt;ShallowCopy(extractSelection-&gt;GetOutput());<br>
         std::cout &lt;&lt; &quot;There are &quot; &lt;&lt; selected-&gt;GetNumberOfPoints()<br>
                  &lt;&lt; &quot; points in the selection.&quot; &lt;&lt; std::endl;<br>
        std::cout &lt;&lt; &quot;There are &quot; &lt;&lt; selected-&gt;GetNumberOfCells()<br>
                  &lt;&lt; &quot; cells in the selection.&quot; &lt;&lt; std::endl;<br>
</div></div><div class="im">                 // Create a polydata object<br>
  vtkSmartPointer&lt;vtkPolyData&gt; newdata =<br>
    vtkSmartPointer&lt;vtkPolyData&gt;::New();<br>
<br>
                vtkPoints* cellPoints = selected-&gt;GetPoints();<br>
        newdata-&gt;SetPoints(cellPoints);<br>
<br>
                int numberOfSubdivisions = 2;<br>
                vtkSmartPointer&lt;vtkPolyDataAlgorithm&gt; subdivisionFilter;<br>
                 subdivisionFilter =  vtkSmartPointer&lt;vtkLoopSubdivisionFilter&gt;::New();<br>
        dynamic_cast&lt;vtkLoopSubdivisionFilter *&gt;<br>
(subdivisionFilter.GetPointer())-&gt;SetNumberOfSubdivisions(numberOfSubdivisions);<br>
#if VTK_MAJOR_VERSION &lt;= 5<br>
                subdivisionFilter-&gt;SetInputConnection(newdata-&gt;GetProducerPort());<br>
#else<br>
    subdivisionFilter-&gt;SetInputData(newdata);<br>
#endif<br>
    subdivisionFilter-&gt;Update();<br>
</div><div class="im">                 vtkSmartPointer&lt;vtkIdTypeArray&gt; id =<br>
      vtkSmartPointer&lt;vtkIdTypeArray&gt;::New();<br>
  id-&gt;SetNumberOfComponents(1);<br>
   // Set values<br>
  for(unsigned int i = 10; i &lt; 20; i++)<br>
    {<br>
    ids-&gt;InsertNextValue(i);<br>
    }<br>
<br>
</div><div class="im">#if VTK_MAJOR_VERSION &lt;= 5<br>
        selectedMapper-&gt;SetInputConnection(<br>
          selected-&gt;GetProducerPort());<br>
#else<br>
        selectedMapper-&gt;SetInputData(selected);<br>
#endif<br>
<br>
        selectedActor-&gt;SetMapper(selectedMapper);<br>
        selectedActor-&gt;GetProperty()-&gt;EdgeVisibilityOn();<br>
        selectedActor-&gt;GetProperty()-&gt;SetEdgeColor(1,0,0);<br>
        selectedActor-&gt;GetProperty()-&gt;SetLineWidth(3);<br>
<br>
<br>
this-&gt;Interactor-&gt;GetRenderWindow()-&gt;GetRenderers()-&gt;GetFirstRenderer()-&gt;AddActor(selectedActor);<br>
<br>
        }<br>
      // Forward events<br>
      vtkInteractorStyleTrackballCamera::OnLeftButtonDown();<br>
    }<br>
<br>
    vtkSmartPointer&lt;vtkPolyData&gt; Data;<br>
    vtkSmartPointer&lt;vtkDataSetMapper&gt; selectedMapper;<br>
    vtkSmartPointer&lt;vtkActor&gt; selectedActor;<br>
<br>
};<br>
<br>
vtkStandardNewMacro(MouseInteractorStyle);<br>
<br>
int main(int, char *[])<br>
{<br>
 vtkSmartPointer&lt;vtkSphereSource&gt; sphereSource =<br>
    vtkSmartPointer&lt;vtkSphereSource&gt;::New();<br>
  sphereSource-&gt;Update();<br>
</div><div class="im">     // Visualize<br>
  vtkSmartPointer&lt;vtkPolyDataMapper&gt; mapper =<br>
    vtkSmartPointer&lt;vtkPolyDataMapper&gt;::New();<br>
</div>  mapper-&gt;SetInputConnection(sphereSource-&gt;GetOutputPort());<br>
<div class="im">    vtkSmartPointer&lt;vtkActor&gt; actor =<br>
    vtkSmartPointer&lt;vtkActor&gt;::New();<br>
  actor-&gt;SetMapper(mapper);<br>
   vtkSmartPointer&lt;vtkRenderer&gt; renderer =<br>
    vtkSmartPointer&lt;vtkRenderer&gt;::New();<br>
  vtkSmartPointer&lt;vtkRenderWindow&gt; renderWindow =<br>
    vtkSmartPointer&lt;vtkRenderWindow&gt;::New();<br>
  renderWindow-&gt;AddRenderer(renderer);<br>
  vtkSmartPointer&lt;vtkRenderWindowInteractor&gt; renderWindowInteractor =<br>
    vtkSmartPointer&lt;vtkRenderWindowInteractor&gt;::New();<br>
  renderWindowInteractor-&gt;SetRenderWindow(renderWindow);<br>
  renderWindowInteractor-&gt;Initialize();<br>
   // Set the custom stype to use for interaction.<br>
  vtkSmartPointer&lt;MouseInteractorStyle&gt; style =<br>
    vtkSmartPointer&lt;MouseInteractorStyle&gt;::New();<br>
  style-&gt;SetDefaultRenderer(renderer);<br>
</div>  style-&gt;Data = sphereSource-&gt;GetOutput();<br>
<div class="im">   renderWindowInteractor-&gt;SetInteractorStyle(style);<br>
   renderer-&gt;AddActor(actor);<br>
  renderer-&gt;ResetCamera();<br>
  renderer-&gt;SetBackground(0,0,1); // Blue<br>
</div><div class="im">   renderWindow-&gt;Render();<br>
  renderWindowInteractor-&gt;Start();<br>
   return EXIT_SUCCESS;<br>
}<br>
</div>I think the error is in these lines:<br>
<div class="im"> // Create a polydata object<br>
  vtkSmartPointer&lt;vtkPolyData&gt; newdata =<br>
    vtkSmartPointer&lt;vtkPolyData&gt;::New();<br>
<br>
                vtkPoints* cellPoints = selected-&gt;GetPoints();<br>
        newdata-&gt;SetPoints(cellPoints);<br>
<br>
                int numberOfSubdivisions = 2;<br>
                vtkSmartPointer&lt;vtkPolyDataAlgorithm&gt; subdivisionFilter;<br>
                 subdivisionFilter =  vtkSmartPointer&lt;vtkLoopSubdivisionFilter&gt;::New();<br>
        dynamic_cast&lt;vtkLoopSubdivisionFilter *&gt;<br>
(subdivisionFilter.GetPointer())-&gt;SetNumberOfSubdivisions(numberOfSubdivisions);<br>
#if VTK_MAJOR_VERSION &lt;= 5<br>
                subdivisionFilter-&gt;SetInputConnection(newdata-&gt;GetProducerPort());<br>
#else<br>
    subdivisionFilter-&gt;SetInputData(newdata);<br>
#endif<br>
    subdivisionFilter-&gt;Update();<br>
</div>The message error says:<br>
Warning: In C:\vtk\Graphics\vtkLoopSubdivisionFilter.cxx, line 363<br>
vtkLoopSubdivisionFilter (01AEAA80): vtkLoopSubdivisionFilter only operates<br>
<div class="im">on triangles, but this data set has no triangles to operate on.<br>
<br>
</div>ERROR: In C:\vtk\Filtering\vtkExecutive.cxx, line 756<br>
vtkStreamingDemandDrivenPipeline (01AE4A48): Algorithm<br>
vtkLoopSubdivisionFilter(01AEAA80) returned failure for request:<br>
vtkInformation (01AE7E28)<br></blockquote><div><br></div>A few things:<div><br></div><div>1) You still didn&#39;t use a TriangleFilter</div><div><br></div><div>2) There is no need for all of the visualization code to demonstrate this problem. It is just polluting the problem.</div>
<div><br></div><div>3)  Why are you doing this?</div><div><span style>           vtkSmartPointer&lt;</span><span style>vtkPolyDataAlgorithm&gt; subdivisionFilter;</span></div><div><span style>                subdivisionFilter =  vtkSmartPointer&lt;</span><span style>vtkLoopSubdivisionFilter&gt;::</span><span style>New();</span><br style>
<span style>       dynamic_cast&lt;</span><span style>vtkLoopSubdivisionFilter *&gt;</span><br style><span style>(subdivisionFilter.GetPointer(</span><span style>))-&gt;SetNumberOfSubdivisions(</span><span style>numberOfSubdivisions);</span><br style>
<font color="#500050" face="arial, sans-serif"><br></font></div><div><font color="#500050" face="arial, sans-serif">instead of just </font></div><div><font color="#500050" face="arial, sans-serif"><br></font></div><div><div>
<span style>vtkSmartPointer&lt;</span>
<span style>vtkLoopSubdivisionFilter</span> <span style>&gt; subdivisionFilter</span><span style> =  vtkSmartPointer&lt;</span><span style>vtkLoopSubdivisionFilter&gt;::</span><span style>New();</span></div><div><span style>subdivisionFilter</span><span style>-&gt;SetNumberOfSubdivisions(</span><span style>numberOfSubdivisions);</span><br style>
</div></div><div><span style><br></span></div><div><span style>?</span></div><div><span style><br></span></div><div>David </div></div></div>