------------------------------------------------------------------------------
| 967 | |
| 968 | //------------------------------------------------------------------------------ |
| 969 | void vtkExtractSelection::ExtractSelectedPoints( |
| 970 | vtkDataSet* input, vtkUnstructuredGrid* output, vtkSignedCharArray* pointInside, bool extractAll) |
| 971 | { |
| 972 | vtkIdType numPts = input->GetNumberOfPoints(); |
| 973 | |
| 974 | vtkPointData* pd = input->GetPointData(); |
| 975 | vtkPointData* outputPD = output->GetPointData(); |
| 976 | |
| 977 | // To copy points in a type agnostic way later |
| 978 | auto pointSet = vtkPointSet::SafeDownCast(input); |
| 979 | |
| 980 | outputPD->SetCopyGlobalIds(1); |
| 981 | outputPD->CopyFieldOff("vtkOriginalPointIds"); |
| 982 | outputPD->CopyAllocate(pd); |
| 983 | |
| 984 | vtkNew<vtkIdTypeArray> originalPointIds; |
| 985 | originalPointIds->SetNumberOfComponents(1); |
| 986 | originalPointIds->SetName("vtkOriginalPointIds"); |
| 987 | outputPD->AddArray(originalPointIds); |
| 988 | |
| 989 | vtkNew<vtkPoints> newPts; |
| 990 | if (!extractAll) |
| 991 | { |
| 992 | if (pointSet) |
| 993 | { |
| 994 | newPts->SetDataType(pointSet->GetPoints()->GetDataType()); |
| 995 | } |
| 996 | vtkNew<vtkIdList> ids; |
| 997 | ids->Allocate(numPts); |
| 998 | vtkUnsignedCharArray* ghostArray = input->GetPointGhostArray(); |
| 999 | for (vtkIdType cc = 0; cc < numPts; ++cc) |
| 1000 | { |
| 1001 | if (ghostArray && ghostArray->GetValue(cc) == vtkDataSetAttributes::HIDDENPOINT) |
| 1002 | { |
| 1003 | // skip this point |
| 1004 | continue; |
| 1005 | } |
| 1006 | if (pointInside->GetValue(cc) != 0) |
| 1007 | { |
| 1008 | ids->InsertNextId(cc); |
| 1009 | } |
| 1010 | } |
| 1011 | const vtkIdType numNewPts = ids->GetNumberOfIds(); |
| 1012 | // copy points |
| 1013 | newPts->SetNumberOfPoints(numNewPts); |
| 1014 | vtkSMPTools::For(0, numNewPts, |
| 1015 | [&](vtkIdType begin, vtkIdType end) |
| 1016 | { |
| 1017 | double point[3]; |
| 1018 | auto idsPtr = ids->GetPointer(0); |
| 1019 | for (vtkIdType ptId = begin; ptId < end; ++ptId) |
| 1020 | { |
| 1021 | input->GetPoint(idsPtr[ptId], point); |
| 1022 | newPts->SetPoint(ptId, point); |
| 1023 | } |
| 1024 | }); |
| 1025 | // copy point data |
| 1026 | outputPD->SetNumberOfTuples(numNewPts); |
no test coverage detected