<div class="gmail_quote">On Fri, May 18, 2012 at 6:19 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">
Good Morning,<br>
Since my last post was without a title( i forget to set a title), I will<br>
post my little problem again. I have a program which create a<br>
vtkspheresource and pick a cell.I tryed to create a vtkPolyData from the<br>
selected cell, in order to apply the subdivisionFilter on it. But it didn&#39;t<br>
work.Any Help please!!!! here is my code:<br>
//////////////////////////////<br>
#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>
<br>
/// pour la selection d&#39;un triangle<br>
#include &lt;vtkVersion.h&gt;<br>
#include &lt;vtkRendererCollection.h&gt;<br>
#include &lt;vtkDataSetMapper.h&gt;<br>
#include &lt;vtkIdTypeArray.h&gt;<br>
#include &lt;vtkTriangleFilter.h&gt;<br>
#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>
<br>
#include &lt;vtkGenericCell.h&gt;<br>
#include &lt;vtkLoopSubdivisionFilter.h&gt;<br>
#include &lt;vtkSphereSource.h&gt;<br>
<br>
<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>
<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>
<br>
<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>
<br>
        // In selection<br>
        vtkSmartPointer&lt;vtkUnstructuredGrid&gt; selected =<br>
          vtkSmartPointer&lt;vtkUnstructuredGrid&gt;::New();<br>
        selected-&gt;ShallowCopy(extractSelection-&gt;GetOutput());<br>
<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>
                /////////////////////<br>
<br>
                 // 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>
<br>
<br>
                /////////////:<br>
                 vtkSmartPointer&lt;vtkIdTypeArray&gt; id =<br>
      vtkSmartPointer&lt;vtkIdTypeArray&gt;::New();<br>
  id-&gt;SetNumberOfComponents(1);<br>
<br>
  // Set values<br>
  for(unsigned int i = 10; i &lt; 20; i++)<br>
    {<br>
    ids-&gt;InsertNextValue(i);<br>
    }<br>
<br>
<br>
                ///////////////<br>
<br>
<br>
#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>
<br>
int main(int, char *[])<br>
{<br>
 vtkSmartPointer&lt;vtkSphereSource&gt; sphereSource =<br>
    vtkSmartPointer&lt;vtkSphereSource&gt;::New();<br>
  sphereSource-&gt;Update();<br>
<br>
  // filtre de triangle<br>
   vtkSmartPointer&lt;vtkTriangleFilter&gt; triangleFilter =<br>
    vtkSmartPointer&lt;vtkTriangleFilter&gt;::New();<br>
   triangleFilter-&gt;SetInputConnection(sphereSource-&gt;GetOutputPort());<br>
  triangleFilter-&gt;Update();<br>
<br>
<br>
  // Visualize<br>
  vtkSmartPointer&lt;vtkPolyDataMapper&gt; mapper =<br>
    vtkSmartPointer&lt;vtkPolyDataMapper&gt;::New();<br>
  mapper-&gt;SetInputConnection(triangleFilter-&gt;GetOutputPort());<br>
<br>
  vtkSmartPointer&lt;vtkActor&gt; actor =<br>
    vtkSmartPointer&lt;vtkActor&gt;::New();<br>
  actor-&gt;SetMapper(mapper);<br>
<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>
<br>
  vtkSmartPointer&lt;vtkRenderWindowInteractor&gt; renderWindowInteractor =<br>
    vtkSmartPointer&lt;vtkRenderWindowInteractor&gt;::New();<br>
  renderWindowInteractor-&gt;SetRenderWindow(renderWindow);<br>
  renderWindowInteractor-&gt;Initialize();<br>
<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>
  style-&gt;Data = triangleFilter-&gt;GetOutput();<br>
   renderWindowInteractor-&gt;SetInteractorStyle(style);<br>
<br>
<br>
  renderer-&gt;AddActor(actor);<br>
  renderer-&gt;ResetCamera();<br>
  renderer-&gt;SetBackground(0,0,1); // Blue<br>
  //renderer-&gt;SetBackground(.3, .6, .3); // Background color green<br>
<br>
  renderWindow-&gt;Render();<br>
  renderWindowInteractor-&gt;Start();<br>
<br>
  return EXIT_SUCCESS;<br>
}<br>
<br>
i&#39;d like to apply the loopSubdivisionFilter on my  selected cell.But one i<br>
pick on a cell, it shows me his error message:<br>
vtkLoopSubdivisionFilter (009D6CD0): vtkLoopSubdivisionFilter only operates<br>
on triangles, but this data set has no triangles to operate on.<br>
Any Help please, and  thanks fo all<br></blockquote><div><br></div>That code is much too long to troubleshoot (though you definitely need a vtkTriangleFilter before the LoopSubdivisionFilter in this case). I suggest you make a very minimal (compilable) example of the part of the code that is causing the problem.<br clear="all">
<br><div>David </div></div>