From e64def921ca78c9fb77655729f4a12d60b648ac7 Mon Sep 17 00:00:00 2001 From: Florian Maurin <florian@coreform.com> Date: Thu, 22 Apr 2021 20:57:59 +0200 Subject: [PATCH] Provide a cache for the weights in GetInterpolatedPointId For nonlinear elements with nonlinear subdivision > 1, the surface is triangulated and GetInterpolatedPointId is called for each triangle corner. This function was before allocating each time a vector for the weights. We now move this allocation outside of this function, such that the allocation is done only once per unstructured grid. So the weight is now part of that function argument list. The old function has been marked as VTK_DEPRECATED_IN_9_1_0 --- .../vtkDataSetRegionSurfaceFilter.cxx | 7 ++-- Filters/Geometry/vtkDataSetSurfaceFilter.cxx | 38 ++++++++++++------- Filters/Geometry/vtkDataSetSurfaceFilter.h | 9 ++++- 3 files changed, 36 insertions(+), 18 deletions(-) diff --git a/Filters/Geometry/vtkDataSetRegionSurfaceFilter.cxx b/Filters/Geometry/vtkDataSetRegionSurfaceFilter.cxx index 04a1bcf6259..f69a804604b 100644 --- a/Filters/Geometry/vtkDataSetRegionSurfaceFilter.cxx +++ b/Filters/Geometry/vtkDataSetRegionSurfaceFilter.cxx @@ -614,6 +614,7 @@ int vtkDataSetRegionSurfaceFilter::UnstructuredGridExecute( if (this->NonlinearSubdivisionLevel > 1) { // We are going to need parametric coordinates to further subdivide. + std::vector<double> weights(cell->GetNumberOfPoints()); double* pc = cell->GetParametricCoords(); parametricCoords->Reset(); parametricCoords->SetNumberOfComponents(3); @@ -655,8 +656,8 @@ int vtkDataSetRegionSurfaceFilter::UnstructuredGridExecute( inParamCoords[k][0] = 0.5 * (inParamCoords[pt1][0] + inParamCoords[pt2][0]); inParamCoords[k][1] = 0.5 * (inParamCoords[pt1][1] + inParamCoords[pt2][1]); inParamCoords[k][2] = 0.5 * (inParamCoords[pt1][2] + inParamCoords[pt2][2]); - inPts[k] = GetInterpolatedPointId( - inPts[pt1], inPts[pt2], input, cell, inParamCoords[k], newPts, outputPD); + inPts[k] = GetInterpolatedPointId(inPts[pt1], inPts[pt2], input, cell, + inParamCoords[k], weights.data(), newPts, outputPD); } // * 0 // / \ Use the 6 points recorded @@ -666,7 +667,7 @@ int vtkDataSetRegionSurfaceFilter::UnstructuredGridExecute( // / \ / \ . // *-----*-----* // 1 4 2 - const int subtriangles[12] = { 0, 3, 5, 3, 1, 4, 3, 4, 5, 5, 4, 2 }; + static const int subtriangles[12] = { 0, 3, 5, 3, 1, 4, 3, 4, 5, 5, 4, 2 }; for (k = 0; k < 12; k++) { int localId = subtriangles[k]; diff --git a/Filters/Geometry/vtkDataSetSurfaceFilter.cxx b/Filters/Geometry/vtkDataSetSurfaceFilter.cxx index ee5c728c0a2..c1aba920c8d 100644 --- a/Filters/Geometry/vtkDataSetSurfaceFilter.cxx +++ b/Filters/Geometry/vtkDataSetSurfaceFilter.cxx @@ -1605,6 +1605,7 @@ int vtkDataSetSurfaceFilter::UnstructuredGridExecuteInternal(vtkUnstructuredGrid } else { + weights.resize(cell->GetNumberOfPoints()); double paramCoordDelta = 1. / (numCellPtsAfterSubdivision - 1); cellIter->GetCell(cell); double inParamCoords[3]; @@ -1614,7 +1615,8 @@ int vtkDataSetSurfaceFilter::UnstructuredGridExecuteInternal(vtkUnstructuredGrid for (j = 0; j < numDeltaPtsAfterSubdivision - 1; j++) { inParamCoords[0] = paramCoordDelta * (numDeltaPtsAfterSubdivision * i + j + 1); - outPtId = GetInterpolatedPointId(input, cell, inParamCoords, newPts, outputPD); + outPtId = GetInterpolatedPointId( + input, cell, inParamCoords, weights.data(), newPts, outputPD); newLines->InsertCellPoint(outPtId); } if (i < numCellPts - 2) @@ -1648,6 +1650,7 @@ int vtkDataSetSurfaceFilter::UnstructuredGridExecuteInternal(vtkUnstructuredGrid { cellIter->GetCell(cell); input->SetCellOrderAndRationalWeights(cellId, cell); + weights.resize(cell->GetNumberOfPoints()); int numCellPtsAfterSubdivision = std::pow(2, this->NonlinearSubdivisionLevel - 1) * (numCellPts - 1) + 1; newLines->InsertNextCell(numCellPtsAfterSubdivision); @@ -1657,7 +1660,8 @@ int vtkDataSetSurfaceFilter::UnstructuredGridExecuteInternal(vtkUnstructuredGrid for (i = 0; i < numCellPtsAfterSubdivision; i++) { inParamCoords[0] = paramCoordDelta * i; - outPtId = GetInterpolatedPointId(input, cell, inParamCoords, newPts, outputPD); + outPtId = + GetInterpolatedPointId(input, cell, inParamCoords, weights.data(), newPts, outputPD); newLines->InsertCellPoint(outPtId); } } @@ -2085,8 +2089,8 @@ int vtkDataSetSurfaceFilter::UnstructuredGridExecuteInternal(vtkUnstructuredGrid inParamCoords[k][0] = 0.5 * (inParamCoords[pt1][0] + inParamCoords[pt2][0]); inParamCoords[k][1] = 0.5 * (inParamCoords[pt1][1] + inParamCoords[pt2][1]); inParamCoords[k][2] = 0.5 * (inParamCoords[pt1][2] + inParamCoords[pt2][2]); - inPts[k] = GetInterpolatedPointId( - inPts[pt1], inPts[pt2], input, cell, inParamCoords[k], newPts, outputPD); + inPts[k] = GetInterpolatedPointId(inPts[pt1], inPts[pt2], input, cell, + inParamCoords[k], weights.data(), newPts, outputPD); } // * 0 // / \ Use the 6 points recorded @@ -2096,7 +2100,7 @@ int vtkDataSetSurfaceFilter::UnstructuredGridExecuteInternal(vtkUnstructuredGrid // / \ / \ . // *-----*-----* // 1 4 2 - const int subtriangles[12] = { 0, 3, 5, 3, 1, 4, 3, 4, 5, 5, 4, 2 }; + static const int subtriangles[12] = { 0, 3, 5, 3, 1, 4, 3, 4, 5, 5, 4, 2 }; for (k = 0; k < 12; k++) { int localId = subtriangles[k]; @@ -2685,31 +2689,39 @@ vtkIdType vtkDataSetSurfaceFilter::GetOutputPointIdAndInterpolate(vtkIdType inPt //------------------------------------------------------------------------------ vtkIdType vtkDataSetSurfaceFilter::GetInterpolatedPointId(vtkIdType edgePtA, vtkIdType edgePtB, vtkDataSet* input, vtkCell* cell, double pcoords[3], vtkPoints* outPts, vtkPointData* outPD) +{ + std::vector<double> weights(cell->GetNumberOfPoints()); + return this->GetInterpolatedPointId( + edgePtA, edgePtB, input, cell, pcoords, weights.data(), outPts, outPD); +} + +//------------------------------------------------------------------------------ +vtkIdType vtkDataSetSurfaceFilter::GetInterpolatedPointId(vtkIdType edgePtA, vtkIdType edgePtB, + vtkDataSet* input, vtkCell* cell, double pcoords[3], double* weights, vtkPoints* outPts, + vtkPointData* outPD) { vtkIdType outPtId = this->EdgeMap->FindEdge(edgePtA, edgePtB); if (outPtId == -1) { int subId = -1; double wcoords[3]; - std::vector<double> weights(cell->GetNumberOfPoints()); - cell->EvaluateLocation(subId, pcoords, wcoords, weights.data()); + cell->EvaluateLocation(subId, pcoords, wcoords, weights); outPtId = outPts->InsertNextPoint(wcoords); - outPD->InterpolatePoint(input->GetPointData(), outPtId, cell->GetPointIds(), weights.data()); + outPD->InterpolatePoint(input->GetPointData(), outPtId, cell->GetPointIds(), weights); this->RecordOrigPointId(outPtId, -1); this->EdgeMap->AddEdge(edgePtA, edgePtB, outPtId); } return outPtId; } -vtkIdType vtkDataSetSurfaceFilter::GetInterpolatedPointId( - vtkDataSet* input, vtkCell* cell, double pcoords[3], vtkPoints* outPts, vtkPointData* outPD) +vtkIdType vtkDataSetSurfaceFilter::GetInterpolatedPointId(vtkDataSet* input, vtkCell* cell, + double pcoords[3], double* weights, vtkPoints* outPts, vtkPointData* outPD) { int subId = -1; double wcoords[3]; - std::vector<double> weights(cell->GetNumberOfPoints()); - cell->EvaluateLocation(subId, pcoords, wcoords, weights.data()); + cell->EvaluateLocation(subId, pcoords, wcoords, weights); vtkIdType outPtId = outPts->InsertNextPoint(wcoords); - outPD->InterpolatePoint(input->GetPointData(), outPtId, cell->GetPointIds(), weights.data()); + outPD->InterpolatePoint(input->GetPointData(), outPtId, cell->GetPointIds(), weights); this->RecordOrigPointId(outPtId, -1); return outPtId; } diff --git a/Filters/Geometry/vtkDataSetSurfaceFilter.h b/Filters/Geometry/vtkDataSetSurfaceFilter.h index e157a6fe019..4d1f49f4b0c 100644 --- a/Filters/Geometry/vtkDataSetSurfaceFilter.h +++ b/Filters/Geometry/vtkDataSetSurfaceFilter.h @@ -320,10 +320,15 @@ protected: class vtkEdgeInterpolationMap; vtkEdgeInterpolationMap* EdgeMap; + VTK_DEPRECATED_IN_9_1_0( + "Use GetInterpolatedPointId(vtkIdType edgePtA, vtkIdType edgePtB, vtkDataSet* input, vtkCell* " + "cell, double pcoords[3], double* weights, vtkPoints* outPts, vtkPointData* outPD) instead") vtkIdType GetInterpolatedPointId(vtkIdType edgePtA, vtkIdType edgePtB, vtkDataSet* input, vtkCell* cell, double pcoords[3], vtkPoints* outPts, vtkPointData* outPD); - vtkIdType GetInterpolatedPointId( - vtkDataSet* input, vtkCell* cell, double pcoords[3], vtkPoints* outPts, vtkPointData* outPD); + vtkIdType GetInterpolatedPointId(vtkIdType edgePtA, vtkIdType edgePtB, vtkDataSet* input, + vtkCell* cell, double pcoords[3], double* weights, vtkPoints* outPts, vtkPointData* outPD); + vtkIdType GetInterpolatedPointId(vtkDataSet* input, vtkCell* cell, double pcoords[3], + double* weights, vtkPoints* outPts, vtkPointData* outPD); vtkIdType NumberOfNewCells; // Better memory allocation for faces (hash) -- GitLab