------------------------------------------------------------------------------
| 65 | |
| 66 | //------------------------------------------------------------------------------ |
| 67 | void vtkDistancePolyDataFilter::GetPolyDataDistance(vtkPolyData* mesh, vtkPolyData* src) |
| 68 | { |
| 69 | vtkDebugMacro(<< "Start vtkDistancePolyDataFilter::GetPolyDataDistance"); |
| 70 | |
| 71 | if (mesh->GetNumberOfCells() == 0 || mesh->GetNumberOfPoints() == 0) |
| 72 | { |
| 73 | vtkErrorMacro(<< "No points/cells to operate on"); |
| 74 | return; |
| 75 | } |
| 76 | |
| 77 | if (src->GetNumberOfPolys() == 0 || src->GetNumberOfPoints() == 0) |
| 78 | { |
| 79 | vtkErrorMacro(<< "No points/cells to difference from"); |
| 80 | return; |
| 81 | } |
| 82 | |
| 83 | vtkNew<vtkImplicitPolyDataDistance> imp; |
| 84 | imp->SetInput(src); |
| 85 | |
| 86 | // Calculate distance from points. |
| 87 | const vtkIdType numPts = mesh->GetNumberOfPoints(); |
| 88 | |
| 89 | vtkNew<vtkDoubleArray> pointArray; |
| 90 | pointArray->SetName("Distance"); |
| 91 | pointArray->SetNumberOfComponents(1); |
| 92 | pointArray->SetNumberOfTuples(numPts); |
| 93 | |
| 94 | vtkNew<vtkDoubleArray> directionArray; |
| 95 | if (this->ComputeDirection) |
| 96 | { |
| 97 | directionArray->SetName("Direction"); |
| 98 | directionArray->SetNumberOfComponents(3); |
| 99 | directionArray->SetNumberOfTuples(numPts); |
| 100 | } |
| 101 | |
| 102 | auto DistanceWithSign = [&](const double& val) |
| 103 | // NOLINTNEXTLINE(readability-avoid-nested-conditional-operator) |
| 104 | { return this->SignedDistance ? (this->NegateDistance ? -val : val) : std::abs(val); }; |
| 105 | |
| 106 | vtkSMPTools::For(0, numPts, |
| 107 | [&](vtkIdType begin, vtkIdType end) |
| 108 | { |
| 109 | double pt[3]; |
| 110 | for (vtkIdType ptId = begin; ptId < end; ptId++) |
| 111 | { |
| 112 | mesh->GetPoint(ptId, pt); |
| 113 | if (this->ComputeDirection) |
| 114 | { |
| 115 | double closestPoint[3]; |
| 116 | double direction[3]; |
| 117 | double val = imp->EvaluateFunctionAndGetClosestPoint(pt, closestPoint); |
| 118 | double dist = DistanceWithSign(val); |
| 119 | vtkMath::Subtract(closestPoint, pt, direction); |
| 120 | vtkMath::Normalize(direction); |
| 121 | pointArray->SetValue(ptId, dist); |
| 122 | directionArray->SetTuple(ptId, direction); |
| 123 | } |
| 124 | else |
no test coverage detected