[vtkusers] How to reorganized a VtkStripper?

Francois Lasson francois.lasson at institutmaupertuis.fr
Fri Jun 5 05:20:28 EDT 2015


Hello,

I'm trying to reorganize a vtkstripper , in other words modify index of 
lines.
I have a vtkStripper, I get his cells, reorganize them and I try to
put back cells in my vtkStripper.
Does anyone have a solution?
Thanks,
François.


My function :

bool Routing::compareByIndex(vtkSmartPointer<vtkStripper> &stripper){

     //Pair vector with cells (lines) and index
std::vector<std::pair<double,vtkSmartPointer<vtkIdList> > > lines;
     //Get lines
     vtkIdType numberOfLines = stripper->GetOutput()->GetNumberOfLines();
     vtkPoints *points = stripper->GetOutput()->GetPoints();
     vtkCellArray *cells = stripper->GetOutput()->GetLines();
     vtkIdType *indices;
     vtkIdType numberOfPoints;
     unsigned int lineCount = 0;
     //For all lines
     for (cells->InitTraversal(); cells->GetNextCell(numberOfPoints, 
indices); lineCount++) // Next line
     {
         //Get index (distance with a dot product)
         double start_point[3];
         points->GetPoint(indices[0],start_point);
         Eigen::Vector3f 
vector_point(start_point[0],start_point[1],start_point[2]);
         float dist = this->vector_dir_.dot(vector_point); //In order to 
get distance between (0,0,0) and first point of each lines
         //Get cell
         vtkSmartPointer<vtkIdList> cell = 
vtkSmartPointer<vtkIdList>::New();
         cells->GetCell(lineCount,cell);

         //Push back to vector
         lines.push_back(std::make_pair(dist,cell));
     }
     // Sort the array
     std::sort(lines.begin(), lines.end(), sortFunction);
     //modify stripper
     vtkSmartPointer<vtkCellArray> cellArray = 
vtkSmartPointer<vtkCellArray>::New();
     for(int i=0; i<lines.size();i++)
        cellArray->InsertNextCell(lines[i].second);

     vtkSmartPointer<vtkStripper> stripper_temp = 
vtkSmartPointer<vtkStripper>::New();
     stripper_temp->GetOutput()->SetLines(cellArray);
     std::cout<<" Number of lines in stripper : 
"<<stripper_temp->GetOutput()->GetNumberOfLines()<<std::endl;
     stripper_temp->Update();
stripper->GetOutput()->ShallowCopy(stripper_temp->GetOutput());
     stripper->Update();
     return true;
}


More information about the vtkusers mailing list