------------------------------------------------------------------------------
| 960 | |
| 961 | //------------------------------------------------------------------------------ |
| 962 | vtkSmartPointer<vtkPolyData> vtkProbeLineFilter::CreateSamplingPolyLine( |
| 963 | vtkPoints* points, vtkIdList* pointIds, vtkDataObject* input, double tolerance) const |
| 964 | { |
| 965 | std::vector<vtkSmartPointer<vtkPolyData>> polylines; |
| 966 | double previousLength = 0.0; |
| 967 | vtkSmartPointer<vtkDataSetAttributes> defaultPD; |
| 968 | |
| 969 | for (vtkIdType i = 0; i < pointIds->GetNumberOfIds() - 1; ++i) |
| 970 | { |
| 971 | const vtkVector3d p1(points->GetPoint(pointIds->GetId(i))); |
| 972 | const vtkVector3d p2(points->GetPoint(pointIds->GetId(i + 1))); |
| 973 | vtkSmartPointer<vtkPolyData> current = (this->SamplingPattern == SAMPLE_LINE_UNIFORMLY) |
| 974 | ? this->SampleLineUniformly(p1, p2, input, tolerance) |
| 975 | : this->SampleLineAtEachCell(p1, p2, input, tolerance); |
| 976 | |
| 977 | if (!defaultPD) |
| 978 | { |
| 979 | defaultPD = current->GetPointData(); |
| 980 | } |
| 981 | |
| 982 | vtkDataArray* arclength = current->GetPointData()->GetArray("arc_length"); |
| 983 | if (arclength && current->GetNumberOfCells() == 1 && current->GetNumberOfPoints() > 1) |
| 984 | { |
| 985 | if (previousLength != 0.0) |
| 986 | { |
| 987 | auto range = vtk::DataArrayValueRange<1>(arclength); |
| 988 | vtkSMPTools::Transform(range.begin(), range.end(), range.begin(), |
| 989 | [previousLength](double x) { return x + previousLength; }); |
| 990 | } |
| 991 | previousLength = arclength->GetTuple1(arclength->GetNumberOfValues() - 1); |
| 992 | polylines.emplace_back(current); |
| 993 | } |
| 994 | } |
| 995 | |
| 996 | if (polylines.empty()) |
| 997 | { |
| 998 | auto res = vtkSmartPointer<vtkPolyData>::New(); |
| 999 | res->GetPointData()->ShallowCopy(defaultPD); |
| 1000 | return res; |
| 1001 | } |
| 1002 | else if (polylines.size() == 1) |
| 1003 | { |
| 1004 | return polylines[0]; |
| 1005 | } |
| 1006 | else |
| 1007 | { |
| 1008 | vtkNew<vtkAppendDataSets> appender; |
| 1009 | for (const auto& pl : polylines) |
| 1010 | { |
| 1011 | appender->AddInputData(0, pl); |
| 1012 | } |
| 1013 | appender->SetOutputDataSetType(VTK_POLY_DATA); |
| 1014 | appender->SetMergePoints(false); |
| 1015 | appender->Update(); |
| 1016 | return appender->GetPolyDataOutput(); |
| 1017 | } |
| 1018 | } |
| 1019 |
no test coverage detected