[vtkusers] create a vtkpolyData from selected cells!!

tasnim hanene-jeder at hotmail.fr
Sat Aug 25 06:27:55 EDT 2012


Good morning,
I created a program which allows me to pick a cell from a mesh and retrieve
its PointsNeighbors. After retrieving them, i tried to create a PolyData
from it ( in order to apply the subdivision filter on it ), but when i build
the program, i got this message:
*ERROR: In C:\vtk-download\vtk source\Filtering\vtkExecutive.cxx, line 756
vtkStreamingDemandDrivenPipeline (00992A68): Algorithm
vtkExtractSelection(00291DC0) returned failure for request: vtkInformation
(009A50C8) Debug: Off Modified Time: 2999 Reference Count: 1 Registered
Events: (none) Request: REQUEST_DATA_OBJECT FORWARD_DIRECTION: 0
ALGORITHM_AFTER_FORWARD: 1 FROM_OUTPUT_PORT: 0*

I thought that my code is correct, but something is wrong. Anybody can tell
me what is wrong please:


      picker->Pick(pos[0], pos[1], 0, this->GetDefaultRenderer());// // Pick
from this location.
 
      double* worldPosition = picker->GetPickPosition();
	  vtkIdType cellId=picker->GetCellId();

	  vtkSmartPointer<vtkIdList> cellPointIds =
    vtkSmartPointer<vtkIdList>::New();
  triangleFilter->GetOutput()->GetCellPoints(cellId, cellPointIds);
 
  std::list<vtkIdType> neighbors;
 
  for(vtkIdType i = 0; i < cellPointIds->GetNumberOfIds(); i++)
    {
    vtkSmartPointer<vtkIdList> idList =
      vtkSmartPointer<vtkIdList>::New();
    idList->InsertNextId(cellPointIds->GetId(i));
    
    vtkSmartPointer<vtkIdList> neighborCellIds =
      vtkSmartPointer<vtkIdList>::New();
 
    triangleFilter->GetOutput()->GetCellNeighbors(cellId, idList,
neighborCellIds);
 
    for(vtkIdType j = 0; j < neighborCellIds->GetNumberOfIds(); j++)
      {
      neighbors.push_back(neighborCellIds->GetId(j));
      }
    }
  std::cout << "Point neighbor ids are: " << std::endl;
 
  for(std::list<vtkIdType>::iterator it1 = neighbors.begin(); it1 !=
neighbors.end(); it1++)
    {
    std::cout << " " << *it1;
    }
  std::cout << std::endl;
 
 
  vtkSmartPointer<vtkDataSetMapper> sphereMapper =
    vtkSmartPointer<vtkDataSetMapper>::New();
  sphereMapper->SetInputConnection(sphere->GetOutputPort());
  vtkSmartPointer<vtkActor> sphereActor =
    vtkSmartPointer<vtkActor>::New();
  sphereActor->SetMapper(sphereMapper);
  sphereActor->GetProperty()->SetEdgeColor(0, 0, 0);
  sphereActor->GetProperty()->EdgeVisibilityOn();
 
  vtkSmartPointer<vtkDataSetMapper> mainCellMapper =
    vtkSmartPointer<vtkDataSetMapper>::New();
 
  vtkSmartPointer<vtkDataSetMapper> neighborCellsMapper =
    vtkSmartPointer<vtkDataSetMapper>::New();

  // Create a dataset with the neighbor cells
  {
    vtkSmartPointer<vtkIdTypeArray> ids =
        vtkSmartPointer<vtkIdTypeArray>::New();
    ids->SetNumberOfComponents(1);
	ids->InsertNextValue(cellId);
    for(std::list<vtkIdType>::iterator it1 = neighbors.begin(); it1 !=
neighbors.end(); it1++)
      {
		 
      ids->InsertNextValue(*it1);
      }
 
    vtkSmartPointer<vtkSelectionNode> selectionNode =
      vtkSmartPointer<vtkSelectionNode>::New();
    selectionNode->SetFieldType(vtkSelectionNode::CELL);
    selectionNode->SetContentType(vtkSelectionNode::INDICES);
    selectionNode->SetSelectionList(ids);
 
    vtkSmartPointer<vtkSelection> selection =
        vtkSmartPointer<vtkSelection>::New();
    selection->AddNode(selectionNode);
 
    vtkSmartPointer<vtkExtractSelection> extractSelection =
        vtkSmartPointer<vtkExtractSelection>::New();

	#if VTK_MAJOR_VERSION <= 5
        extractSelection->SetInput(0, this->Data);
        extractSelection->SetInput(1, selection);
#else
        extractSelection->SetInputData(0, this->Data);
        extractSelection->SetInputData(1, selection);
#endif

    extractSelection->Update();
 
   
neighborCellsMapper->SetInputConnection(extractSelection->GetOutputPort());
	// In selection
        vtkSmartPointer<vtkUnstructuredGrid> selected =
          vtkSmartPointer<vtkUnstructuredGrid>::New();
        selected->ShallowCopy(extractSelection->GetOutput());

#if VTK_MAJOR_VERSION <= 5
        selectedMapper->SetInputConnection(
          selected->GetProducerPort());
#else
        selectedMapper->SetInputData(selected);
#endif
 vtkSmartPointer<vtkPolyData> newdata =
                vtkSmartPointer<vtkPolyData>::New();
            newdata->SetPoints(selected->GetPoints());

			 // copy the cells        

            newdata->SetPolys(selected->GetCells());
            
            vtkSmartPointer< vtkTriangleFilter > triangleFilter =
           	vtkSmartPointer<vtkTriangleFilter>::New();
           triangleFilter->SetInputConnection(newdata->GetProducerPort());
           triangleFilter->Update();

		    int numberOfSubdivisions = 2;

            vtkSmartPointer< vtkLoopSubdivisionFilter > subdivisionFilter =
                vtkSmartPointer<vtkLoopSubdivisionFilter>::New();
           
subdivisionFilter->SetNumberOfSubdivisions(numberOfSubdivisions);
           
           
subdivisionFilter->SetInputConnection(triangleFilter->GetOutputPort());

            subdivisionFilter->Update(); // not necessary
            // show the subdivsions
           
selectedMapper->SetInputConnection(subdivisionFilter->GetOutputPort());

thanks,




--
View this message in context: http://vtk.1045678.n5.nabble.com/create-a-vtkpolyData-from-selected-cells-tp5715553.html
Sent from the VTK - Users mailing list archive at Nabble.com.



More information about the vtkusers mailing list