[vtkusers] Need to pick a cell and it's neighbors

tasnim hanene-jeder at hotmail.fr
Tue Aug 7 16:48:43 EDT 2012


David Doria-2-3 wrote
> 
> Please provide the smallest possible, self-contained, compilable code that
> demonstrates your problem.
> 
> David
> 
this is the part of the code that i modify it in the OnLeftButtonDown():
    

      int* pos = this->GetInteractor()->GetEventPosition();
 
      vtkSmartPointer<vtkCellPicker> picker =
vtkSmartPointer<vtkCellPicker>::New();
      picker->SetTolerance(0.0005);
 
      // Pick from this location.
      picker->Pick(pos[0], pos[1], 0, this->GetDefaultRenderer());
 
      double* worldPosition = picker->GetPickPosition();
      std::cout << "Cell id is: " << picker->GetCellId() << std::endl;
	  picker->GetCellId();
 
        vtkSmartPointer<vtkIdTypeArray> ids =
vtkSmartPointer<vtkIdTypeArray>::New();
        ids->SetNumberOfComponents(1);
        ids->InsertNextValue(picker->GetCellId());
 
        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();

        extractSelection->SetInput(0, this->Data);
        extractSelection->SetInput(1, selection);

        extractSelection->Update();
 
        // In selection
        vtkSmartPointer<vtkUnstructuredGrid> selected =
          vtkSmartPointer<vtkUnstructuredGrid>::New();
        selected->ShallowCopy(extractSelection->GetOutput());
 
        selectedMapper->SetInputConnection(selected->GetProducerPort());
 vtkSmartPointer<vtkPolyData> newdata = vtkSmartPointer<vtkPolyData>::New();
            newdata->SetPoints(selected->GetPoints());

			 // copy the cells
             newdata->SetPolys(selected->GetCells());
            vtkIdType cellId=picker->GetCellId();
            vtkSmartPointer< vtkTriangleFilter > triangleFilter =
           	vtkSmartPointer<vtkTriangleFilter>::New();
			
           triangleFilter->SetInputConnection(newdata->GetProducerPort());
           triangleFilter->Update();
		   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));
 
    //get the neighbors of the cell
    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;
  



--
View this message in context: http://vtk.1045678.n5.nabble.com/Need-to-pick-a-cell-and-its-neighbors-tp5715057p5715152.html
Sent from the VTK - Users mailing list archive at Nabble.com.



More information about the vtkusers mailing list