[vtkusers] vtkUnstructuredGrid, Connectivity and Locations are nullptr after setting them with SetCells

"Michał Kotowicz" M.Kotowicz at ichip.pw.edu.pl
Sun Dec 6 05:32:03 EST 2015


 Dear vtk-users, vtk-developers
I'm trying to write parallel visualizer with vtkUnstructuredGrid, code sample
(cellArray is std::shared_ptr of tbb::concurrent_vector<unsigned> 
(it contains 8*numCells Id's of points of mesh) 
and Grids is 
std::map<std::string, vtkSmartPointer<vtkCPUnstructuredGridBuilder>>) :


> Grids[name] = vtkSmartPointer<vtkCPUnstructuredGridBuilder>::New();
> 
>  vtkSmartPointer<vtkPoints> TmpPoints = vtkSmartPointer<vtkPoints>::New();
>  TmpPoints->SetNumberOfPoints(numPts);
> 
>  tbb::blocked_range<vtkIdType> PtsRange(0, numPts, 10000);
>  tbb::parallel_for(PtsRange, [&](const tbb::blocked_range<vtkIdType>& r) {
>  vtkIdType Offset{3*r.begin()};
>  for(vtkIdType i = r.begin() ; i < r.end(); ++i, Offset += 3)
>  {
>  TmpPoints->SetPoint(i, coords[Offset], coords[Offset+1], coords[Offset+2]);
>  }
>  });
> 
>  Grids[name]->SetPoints(TmpPoints.Get());
> 
>  vtkSmartPointer<vtkCellArray> CellsArray =
>  vtkSmartPointer<vtkCellArray>::New();
>  CellsArray->SetNumberOfCells(cellArray->size()/8);
> 
>  vtkIdTypeArray* IdArray = CellsArray->GetData();
>  IdArray->SetNumberOfComponents(8);
>  IdArray->SetNumberOfTuples(cellArray->size()/8);
> 
>  vtkSmartPointer<vtkIdTypeArray> CellsLocations =
>  vtkSmartPointer<vtkIdTypeArray>::New();
>  CellsLocations->SetNumberOfComponents(1);
>  CellsLocations->SetNumberOfTuples(cellArray->size()/8);
> 
>  vtkSmartPointer<vtkUnsignedCharArray> CellsTypes =
>  vtkSmartPointer<vtkUnsignedCharArray>::New();
>  CellsTypes->SetNumberOfComponents(1);
>  CellsTypes->SetNumberOfTuples(cellArray->size()/8);
> 
>  tbb::blocked_range<unsigned> CellsRange(0, cellArray->size(),
>  HUGE_NUMBER); // I test it in sequential manner
>  tbb::parallel_for(CellsRange, [&](const tbb::blocked_range<unsigned>& r) {
>  for(auto offset = r.begin() ; offset < r.end(); offset += 8)
>  {
> 
>  vtkIdType IdList[] {
>  cellArray->operator[](offset),
>  cellArray->operator[](offset + 1),
>  cellArray->operator[](offset + 2),
>  cellArray->operator[](offset + 3),
>  cellArray->operator[](offset + 4),
>  cellArray->operator[](offset + 5),
>  cellArray->operator[](offset + 6),
>  cellArray->operator[](offset + 7)
>  };
>  
> // Grids[name]->InsertNextCell(12, 8, IdList); // OK, but not parallelizable.
> // Grids[name]->GetUnstructuredGrid()->InsertNextCell(12, 8, IdList); // OK, but not parallelizable.
> 
>  IdArray->SetTupleValue(offset/8, IdList);
>  vtkIdType TmpTab[] {offset};
>  CellsLocations->SetTupleValue(offset/8, TmpTab);
>  CellsTypes->SetTuple1(offset/8, 12);
>  }
>  });
> // I tested CellsLocations and CellsArray and they contain proper numbers (printed with program and during
> // GDB session)
> 
>  Grids[name]->GetUnstructuredGrid()->SetCells(CellsTypes.GetPointer(),
>  CellsLocations.GetPointer(), CellsArray.GetPointer());
> 
> // Returns nullptr 0oa
>  vtkIdTypeArray* Tmp = Grids[name]->GetUnstructuredGrid()->GetCellLocationsArray();
> // Returns nullptr 0oa
>  vtkCellArray* TmpCell = Grids[name]->GetUnstructuredGrid()->GetCells(); 
> }
> 

So after setting Connectivity and Locations I'm still having empty these members, and when I use
vtkXMLUnstructuredGridWriter, only Points, and CellTypes are contained in .vtu file. (connectivity is empty, and
locations contains rubish numbers). This function works when I use InsertNextCell but this is not parallelizable.
Is it solvable? Thank you for any hint.
Best Regards,
Kotu
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20151206/bb037d34/attachment.html>


More information about the vtkusers mailing list