Skip to content
Snippets Groups Projects
Commit 188be593 authored by Utkarsh Ayachit's avatar Utkarsh Ayachit
Browse files

vtkExtractCells: shallow copy points, if possible

vtkExtractCells now shallow copies points, if possible thus avoiding
an expensive copy if input dataset is indeed a point-set.
parent dca352b7
No related branches found
No related tags found
No related merge requests found
......@@ -22,6 +22,7 @@
#include "vtkCell.h"
#include "vtkCellArray.h"
#include "vtkCellData.h"
#include "vtkDoubleArray.h"
#include "vtkIdTypeArray.h"
#include "vtkInformation.h"
#include "vtkNew.h"
......@@ -35,6 +36,7 @@
#include "vtkUnstructuredGrid.h"
#include <algorithm>
#include <iterator>
#include <numeric>
#include <vector>
......@@ -368,16 +370,34 @@ void vtkExtractCells::Copy(vtkDataSet* input, vtkUnstructuredGrid* output)
vtkIdType numPoints = input->GetNumberOfPoints();
vtkIdType numCells = input->GetNumberOfCells();
output->Allocate(numCells);
vtkNew<vtkPoints> pts;
pts->SetNumberOfPoints(numPoints);
output->SetPoints(pts);
for (vtkIdType i = 0; i < numPoints; i++)
if (auto inputPS = vtkPointSet::SafeDownCast(input))
{
vtkNew<vtkPoints> pts;
pts->ShallowCopy(inputPS->GetPoints());
output->SetPoints(pts);
}
else
{
pts->SetPoint(i, input->GetPoint(i));
vtkNew<vtkPoints> pts;
pts->SetDataTypeToDouble();
pts->SetNumberOfPoints(numPoints);
double temp[3];
pts->GetPoint(0, temp);
auto array = vtkDoubleArray::SafeDownCast(pts->GetData());
assert(array && array->GetNumberOfTuples() == numPoints);
vtkSMPTools::For(0, numPoints, [&array, &input](vtkIdType first, vtkIdType last) {
double coords[3];
for (vtkIdType cc = first; cc < last; ++cc)
{
input->GetPoint(cc, coords);
array->SetTypedTuple(cc, coords);
}
});
output->SetPoints(pts);
}
vtkNew<vtkIdList> cellPoints;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment