[vtkusers] SphereSource as input to the TriangleFilter in a function!!!!!

tasnim hanene-jeder at hotmail.fr
Sun Aug 26 12:37:41 EDT 2012


Thanks , i resolved the problem, but when i tried to create a vtkPolyData
from these cells in order to apply a filter then, i got :
*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 
*Warning:* In C:\vtk-download\vtk
source\Graphics\vtkLoopSubdivisionFilter.cxx, line 363 
vtkLoopSubdivisionFilter (006465C0): vtkLoopSubdivisionFilter only operates
on triangles, but this data set has no triangles to operate on. 
I thought that my code is correct, but something is wrong. 

  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; 
  
  
  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()); 

            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()); 

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

thanks



--
View this message in context: http://vtk.1045678.n5.nabble.com/SphereSource-as-input-to-the-TriangleFilter-in-a-function-tp5715415p5715556.html
Sent from the VTK - Users mailing list archive at Nabble.com.



More information about the vtkusers mailing list