diff --git a/CMakeLists.txt b/CMakeLists.txt index bcbd89a..d726bf7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,4 @@ -# Copyright 2012-2023 Ronald Römer +# Copyright 2012-2024 Ronald Römer # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/README.md b/README.md index 9707b15..7caf064 100644 --- a/README.md +++ b/README.md @@ -202,10 +202,6 @@ from vtkbool.vtkBool import vtkPolyDataBooleanFilter ## Errors and their meaning -- *First/Second input does not contain any supported cells.* - - What it says. Look at the Features. - - *Bad shaped cells detected.* At least one cell has a bad shape. For a cell with more than three points: not all points lie on the plane defined by the calculated surface normal. @@ -239,7 +235,7 @@ from vtkbool.vtkBool import vtkPolyDataBooleanFilter ## Copyright -2012-2023 Ronald Römer +2012-2024 Ronald Römer ## License diff --git a/Utilities.cxx b/Utilities.cxx index 2284d4c..76650e4 100644 --- a/Utilities.cxx +++ b/Utilities.cxx @@ -1,5 +1,5 @@ /* -Copyright 2012-2023 Ronald Römer +Copyright 2012-2024 Ronald Römer Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -27,7 +27,7 @@ limitations under the License. #include -void ComputeNormal (vtkPoints *pts, double *n, vtkIdType num, const vtkIdType *poly) { +double ComputeNormal (vtkPoints *pts, double *n, vtkIdType num, const vtkIdType *poly) { n[0] = 0; n[1] = 0; n[2] = 0; if (num == 3) { @@ -59,7 +59,7 @@ void ComputeNormal (vtkPoints *pts, double *n, vtkIdType num, const vtkIdType *p } } - vtkMath::Normalize(n); + return vtkMath::Normalize(n); } bool CheckNormal (vtkPoints *pts, vtkIdType num, const vtkIdType *poly, const double *n, double d) { @@ -173,7 +173,7 @@ void BackTransform (const double *in, double *out, const Base &base) { out[2] = z; } -void ComputeNormal (const Poly &poly, double *n) { +double ComputeNormal (const Poly &poly, double *n) { n[0] = 0; n[1] = 0; n[2] = 0; Poly::const_iterator itrA, itrB; @@ -193,7 +193,7 @@ void ComputeNormal (const Poly &poly, double *n) { n[2] += (ptA.x-ptB.x)*(ptA.y+ptB.y); } - vtkMath::Normalize(n); + return vtkMath::Normalize(n); } bool PointInPoly (const Poly &poly, const Point3d &p) { diff --git a/Utilities.h b/Utilities.h index f1aea66..45b6f11 100644 --- a/Utilities.h +++ b/Utilities.h @@ -1,5 +1,5 @@ /* -Copyright 2012-2023 Ronald Römer +Copyright 2012-2024 Ronald Römer Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -36,7 +36,7 @@ limitations under the License. double GetAngle (const double *vA, const double *vB, const double *n); /* VTK */ -void ComputeNormal (vtkPoints *pts, double *n, vtkIdType num, const vtkIdType *poly); +double ComputeNormal (vtkPoints *pts, double *n, vtkIdType num, const vtkIdType *poly); bool CheckNormal (vtkPoints *pts, vtkIdType num, const vtkIdType *poly, const double *n, double d); void FindPoints (vtkKdTreePointLocator *pl, const double *pt, vtkIdList *pts, double tol = 1e-6); @@ -127,7 +127,7 @@ std::ostream& operator<< (typename std::enable_if::value, std::o typedef std::vector Poly; typedef std::vector PolysType; -void ComputeNormal (const Poly &poly, double *n); +double ComputeNormal (const Poly &poly, double *n); bool PointInPoly (const Poly &poly, const Point3d &p); void WritePolys (const char *name, const PolysType &polys); diff --git a/testing/generate_frieze.py b/testing/generate_frieze.py index 842ce84..af50e2d 100755 --- a/testing/generate_frieze.py +++ b/testing/generate_frieze.py @@ -1,7 +1,7 @@ #!/usr/bin/env python # *-* coding: UTF-8 *-* -# Copyright 2012-2023 Ronald Römer +# Copyright 2012-2024 Ronald Römer # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/testing/test_filter.py b/testing/test_filter.py index 8526117..e53313b 100755 --- a/testing/test_filter.py +++ b/testing/test_filter.py @@ -1,7 +1,7 @@ #!/usr/bin/env python # *-* coding: UTF-8 *-* -# Copyright 2012-2023 Ronald Römer +# Copyright 2012-2024 Ronald Römer # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/testing/test_merger.cxx b/testing/test_merger.cxx index c4b5c99..a20c60e 100644 --- a/testing/test_merger.cxx +++ b/testing/test_merger.cxx @@ -1,5 +1,5 @@ /* -Copyright 2012-2023 Ronald Römer +Copyright 2012-2024 Ronald Römer Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/testing/test_python.py b/testing/test_python.py index bad2904..c8435c6 100755 --- a/testing/test_python.py +++ b/testing/test_python.py @@ -1,7 +1,7 @@ #!/usr/bin/env python # *-* coding: UTF-8 *-* -# Copyright 2012-2023 Ronald Römer +# Copyright 2012-2024 Ronald Römer # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/vtkPolyDataBooleanFilter.cxx b/vtkPolyDataBooleanFilter.cxx index 4d88f77..200d91c 100644 --- a/vtkPolyDataBooleanFilter.cxx +++ b/vtkPolyDataBooleanFilter.cxx @@ -1,5 +1,5 @@ /* -Copyright 2012-2023 Ronald Römer +Copyright 2012-2024 Ronald Römer Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -1831,7 +1831,7 @@ void vtkPolyDataBooleanFilter::RestoreOrigPoints (vtkPolyData *pd, PolyStripsTyp std::cout << "RestoreOrigPoints()" << std::endl; #endif - pd->BuildLinks(); + pd->DeleteLinks(); pd->BuildLinks(); vtkKdTreePointLocator *loc = vtkKdTreePointLocator::New(); loc->SetDataSet(pd); @@ -1873,7 +1873,7 @@ void vtkPolyDataBooleanFilter::DisjoinPolys (vtkPolyData *pd, PolyStripsType &po std::cout << "DisjoinPolys()" << std::endl; #endif - pd->BuildLinks(); + pd->DeleteLinks(); pd->BuildLinks(); vtkKdTreePointLocator *loc = vtkKdTreePointLocator::New(); loc->SetDataSet(pd); @@ -2093,7 +2093,7 @@ void vtkPolyDataBooleanFilter::AddAdjacentPoints (vtkPolyData *pd, vtkIdTypeArra std::cout << "AddAdjacentPoints()" << std::endl; #endif - pd->BuildLinks(); + pd->DeleteLinks(); pd->BuildLinks(); vtkIdTypeArray *origCellIds = vtkIdTypeArray::SafeDownCast(pd->GetCellData()->GetScalars("OrigCellIds")); @@ -2282,9 +2282,9 @@ void vtkPolyDataBooleanFilter::MergePoints (vtkPolyData *pd, PolyStripsType &pol #endif pd->BuildCells(); - pd->BuildLinks(); + pd->DeleteLinks(); pd->BuildLinks(); - contLines->BuildLinks(); + contLines->DeleteLinks(); contLines->BuildLinks(); auto loc = vtkSmartPointer::New(); loc->SetDataSet(pd); @@ -2739,8 +2739,8 @@ bool vtkPolyDataBooleanFilter::CombineRegions () { plB->SetDataSet(pdB); plB->BuildLocator(); - pdA->BuildLinks(); - pdB->BuildLinks(); + pdA->DeleteLinks(); pdA->BuildLinks(); + pdB->DeleteLinks(); pdB->BuildLinks(); vtkIdTypeArray *scalarsA = vtkIdTypeArray::SafeDownCast(pdA->GetPointData()->GetScalars()); vtkIdTypeArray *scalarsB = vtkIdTypeArray::SafeDownCast(pdB->GetPointData()->GetScalars()); diff --git a/vtkPolyDataBooleanFilter.h b/vtkPolyDataBooleanFilter.h index 7676316..50560f3 100644 --- a/vtkPolyDataBooleanFilter.h +++ b/vtkPolyDataBooleanFilter.h @@ -1,5 +1,5 @@ /* -Copyright 2012-2023 Ronald Römer +Copyright 2012-2024 Ronald Römer Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/vtkPolyDataContactFilter.cxx b/vtkPolyDataContactFilter.cxx index 7720dd5..bc651da 100644 --- a/vtkPolyDataContactFilter.cxx +++ b/vtkPolyDataContactFilter.cxx @@ -1,5 +1,5 @@ /* -Copyright 2012-2023 Ronald Römer +Copyright 2012-2024 Ronald Römer Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -33,15 +33,12 @@ limitations under the License. #include #include #include -#include #include #include #include -#include #include #include #include - #include #include "vtkPolyDataContactFilter.h" @@ -52,29 +49,6 @@ limitations under the License. vtkStandardNewMacro(vtkPolyDataContactFilter); vtkPolyDataContactFilter::vtkPolyDataContactFilter () { - - contLines = vtkPolyData::New(); - contLines->Allocate(1000); - - contPts = vtkPoints::New(); - contPts->SetDataTypeToDouble(); - contLines->SetPoints(contPts); - - contA = vtkIdTypeArray::New(); - contB = vtkIdTypeArray::New(); - - contA->SetName("cA"); - contB->SetName("cB"); - - sourcesA = vtkIdTypeArray::New(); - sourcesA->SetNumberOfComponents(2); - - sourcesB = vtkIdTypeArray::New(); - sourcesB->SetNumberOfComponents(2); - - sourcesA->SetName("sourcesA"); - sourcesB->SetName("sourcesB"); - SetNumberOfInputPorts(2); SetNumberOfOutputPorts(3); @@ -85,14 +59,7 @@ vtkPolyDataContactFilter::vtkPolyDataContactFilter () { } vtkPolyDataContactFilter::~vtkPolyDataContactFilter () { - sourcesB->Delete(); - sourcesA->Delete(); - - contB->Delete(); - contA->Delete(); - - contPts->Delete(); - contLines->Delete(); + // nix mehr } int vtkPolyDataContactFilter::RequestData (vtkInformation *request, vtkInformationVector **inputVector, vtkInformationVector *outputVector) { @@ -113,56 +80,69 @@ int vtkPolyDataContactFilter::RequestData (vtkInformation *request, vtkInformati vtkPolyData *resultB = vtkPolyData::SafeDownCast(outInfoB->Get(vtkDataObject::DATA_OBJECT())); vtkPolyData *resultC = vtkPolyData::SafeDownCast(outInfoC->Get(vtkDataObject::DATA_OBJECT())); - // durchführung der aufgabe + // contLines anlegen - pdA = vtkPolyData::New(); - pdA->DeepCopy(_pdA); + contLines = vtkSmartPointer::New(); + contLines->Allocate(1000); - pdB = vtkPolyData::New(); - pdB->DeepCopy(_pdB); + auto contPts = vtkSmartPointer::New(); + contPts->SetDataTypeToDouble(); - PreparePolyData(pdA); - PreparePolyData(pdB); + contLines->SetPoints(contPts); - if (pdA->GetNumberOfCells() == 0) { - vtkErrorMacro("First input does not contain any supported cells."); - return 1; - } + contA = vtkSmartPointer::New(); + contB = vtkSmartPointer::New(); - if (pdB->GetNumberOfCells() == 0) { - vtkErrorMacro("Second input does not contain any supported cells."); - return 1; - } + contA->Allocate(1000); + contB->Allocate(1000); + + contA->SetName("cA"); + contB->SetName("cB"); + + sourcesA = vtkSmartPointer::New(); + sourcesB = vtkSmartPointer::New(); + + sourcesA->Allocate(1000); + sourcesB->Allocate(1000); + + sourcesA->SetNumberOfComponents(2); + sourcesB->SetNumberOfComponents(2); + + sourcesA->SetName("sourcesA"); + sourcesB->SetName("sourcesB"); - origCellIdsA = vtkIdTypeArray::SafeDownCast(pdA->GetCellData()->GetScalars("OrigCellIds")); - origCellIdsB = vtkIdTypeArray::SafeDownCast(pdB->GetCellData()->GetScalars("OrigCellIds")); + // durchführung der aufgabe + + newPdA = vtkSmartPointer::New(); + newPdB = vtkSmartPointer::New(); - GetInvalidEdges(pdA, edgesA); - GetInvalidEdges(pdB, edgesB); + CopyPolyData(_pdA, newPdA); + CopyPolyData(_pdB, newPdB); - // anlegen der obb-trees + GetInvalidEdges(newPdA, edgesA); + GetInvalidEdges(newPdB, edgesB); - vtkOBBTree *obbA = vtkOBBTree::New(); - obbA->SetDataSet(pdA); - obbA->SetNumberOfCellsPerNode(1); + auto obbA = vtkSmartPointer::New(); + obbA->SetDataSet(newPdA); + obbA->SetNumberOfCellsPerNode(10); obbA->BuildLocator(); - vtkOBBTree *obbB = vtkOBBTree::New(); - obbB->SetDataSet(pdB); - obbB->SetNumberOfCellsPerNode(1); + auto obbB = vtkSmartPointer::New(); + obbB->SetDataSet(newPdB); + obbB->SetNumberOfCellsPerNode(10); obbB->BuildLocator(); - vtkMatrix4x4 *mat = vtkMatrix4x4::New(); + auto mat = vtkSmartPointer::New(); obbA->IntersectWithOBBTree(obbB, mat, InterOBBNodes, this); - if (aborted) { - vtkErrorMacro("Bad shaped cells detected."); + if (contLines->GetNumberOfCells() == 0) { + vtkErrorMacro("There is no contact."); return 1; } - if (contLines->GetNumberOfCells() == 0) { - vtkErrorMacro("There is no contact."); + if (aborted) { + vtkErrorMacro("Bad shaped cells detected."); return 1; } @@ -184,7 +164,9 @@ int vtkPolyDataContactFilter::RequestData (vtkInformation *request, vtkInformati contLines->RemoveDeletedCells(); - vtkCleanPolyData *clean = vtkCleanPolyData::New(); + contLines->Squeeze(); + + auto clean = vtkSmartPointer::New(); clean->SetInputData(contLines); clean->ToleranceIsAbsoluteOn(); clean->SetAbsoluteTolerance(1e-5); @@ -202,127 +184,117 @@ int vtkPolyDataContactFilter::RequestData (vtkInformation *request, vtkInformati resultA->RemoveDeletedCells(); - clean->Delete(); - mat->Delete(); - obbB->Delete(); - obbA->Delete(); - - resultB->DeepCopy(pdA); - resultC->DeepCopy(pdB); - - pdB->Delete(); - pdA->Delete(); - + resultB->DeepCopy(newPdA); + resultC->DeepCopy(newPdB); } return 1; } -void vtkPolyDataContactFilter::PreparePolyData (vtkPolyData *pd) { +void vtkPolyDataContactFilter::CopyPolyData (vtkPolyData *pd, vtkPolyData *newPd) { + auto newPoints = vtkSmartPointer::New(); - pd->GetCellData()->Initialize(); - pd->GetPointData()->Initialize(); + newPoints->SetDataType(pd->GetPoints()->GetDataType()); + newPoints->DeepCopy(pd->GetPoints()); - vtkIdTypeArray *cellIds = vtkIdTypeArray::New(); + newPd->SetPoints(newPoints); - vtkCellIterator *cellItr = pd->NewCellIterator(); - for (cellItr->InitTraversal(); !cellItr->IsDoneWithTraversal(); cellItr->GoToNextCell()) { - cellIds->InsertNextValue(cellItr->GetCellId()); - } + auto newPolys = vtkSmartPointer::New(); - vtkIdType cellId; + newPolys->Allocate(pd->GetNumberOfPolys()); - for (cellItr->InitTraversal(); !cellItr->IsDoneWithTraversal(); cellItr->GoToNextCell()) { - cellId = cellItr->GetCellId(); + newPd->SetPolys(newPolys); + + auto cellIds = vtkSmartPointer::New(); + cellIds->Allocate(pd->GetNumberOfPolys()); - if (cellItr->GetCellType() == VTK_QUAD) { - vtkIdList *ptIds = cellItr->GetPointIds(); + vtkCellIterator *cellItr = pd->NewCellIterator(); - vtkPoints *pts = cellItr->GetPoints(); + vtkIdType cellId; + vtkIdList *ptIds; - double n[3]; + double p0[3], p1[3], p2[3], p3[3]; - ComputeNormal(pd->GetPoints(), n, 4, ptIds->GetPointer(0)); + double n[3], d; - double dA = vtkMath::Dot(n, pts->GetPoint(0)), - dB = vtkMath::Dot(n, pts->GetPoint(1))-dA; + double dA, dB; - if (std::abs(dB) > 1e-6) { - // nur wenn nicht auf einer ebene + for (cellItr->InitTraversal(); !cellItr->IsDoneWithTraversal(); cellItr->GoToNextCell()) { + cellId = cellItr->GetCellId(); + ptIds = cellItr->GetPointIds(); - dA = vtkMath::Distance2BetweenPoints(pts->GetPoint(0), pts->GetPoint(2)); - dB = vtkMath::Distance2BetweenPoints(pts->GetPoint(1), pts->GetPoint(3)); + if (cellItr->GetCellType() == VTK_TRIANGLE || cellItr->GetCellType() == VTK_POLYGON) { + newPd->InsertNextCell(cellItr->GetCellType(), ptIds); - auto newCellA = vtkSmartPointer::New(); - auto newCellB = vtkSmartPointer::New(); + cellIds->InsertNextValue(cellId); - newCellA->SetNumberOfIds(3); - newCellB->SetNumberOfIds(3); + } else if (cellItr->GetCellType() == VTK_TRIANGLE_STRIP) { + auto cells = vtkSmartPointer::New(); - if (dA < dB) { - newCellA->SetId(0, ptIds->GetId(1)); - newCellA->SetId(1, ptIds->GetId(2)); - newCellA->SetId(2, ptIds->GetId(3)); + vtkTriangleStrip::DecomposeStrip(cellItr->GetNumberOfPoints(), ptIds->GetPointer(0), cells); - newCellB->SetId(0, ptIds->GetId(3)); - newCellB->SetId(1, ptIds->GetId(0)); - newCellB->SetId(2, ptIds->GetId(1)); - } else { - newCellA->SetId(0, ptIds->GetId(0)); - newCellA->SetId(1, ptIds->GetId(1)); - newCellA->SetId(2, ptIds->GetId(2)); + vtkIdType n; + const vtkIdType *pts; - newCellB->SetId(0, ptIds->GetId(2)); - newCellB->SetId(1, ptIds->GetId(3)); - newCellB->SetId(2, ptIds->GetId(0)); + for (cells->InitTraversal(); cells->GetNextCell(n, pts);) { + if (pts[0] != pts[1] && pts[1] != pts[2] && pts[2] != pts[0]) { + newPd->InsertNextCell(VTK_TRIANGLE, n, pts); + cellIds->InsertNextValue(cellId); } + } - pd->InsertNextCell(VTK_TRIANGLE, newCellA); - cellIds->InsertNextValue(cellId); + } else if (cellItr->GetCellType() == VTK_QUAD) { - pd->InsertNextCell(VTK_TRIANGLE, newCellB); - cellIds->InsertNextValue(cellId); + newPoints->GetPoint(ptIds->GetId(0), p0); + newPoints->GetPoint(ptIds->GetId(1), p1); + newPoints->GetPoint(ptIds->GetId(2), p2); + newPoints->GetPoint(ptIds->GetId(3), p3); - pd->DeleteCell(cellId); - } + ComputeNormal(newPoints, n, 4, ptIds->GetPointer(0)); - } else if (cellItr->GetCellType() == VTK_TRIANGLE_STRIP) { - vtkIdList *ptIds = cellItr->GetPointIds(); + d = vtkMath::Dot(n, p0); - vtkCellArray *cells = vtkCellArray::New(); + if (CheckNormal(newPoints, 4, ptIds->GetPointer(0), n, d)) { + newPd->InsertNextCell(VTK_POLYGON, ptIds); + cellIds->InsertNextValue(cellId); - vtkTriangleStrip::DecomposeStrip(cellItr->GetNumberOfPoints(), ptIds->GetPointer(0), cells); + } else { + dA = vtkMath::Distance2BetweenPoints(p0, p2); + dB = vtkMath::Distance2BetweenPoints(p1, p3); - vtkIdType n; - const vtkIdType *pts; + if (dA < dB) { + // 0, 2 + const vtkIdType cellA[] = {ptIds->GetId(0), ptIds->GetId(1), ptIds->GetId(2)}; + const vtkIdType cellB[] = {ptIds->GetId(2), ptIds->GetId(3), ptIds->GetId(0)}; - for (cells->InitTraversal(); cells->GetNextCell(n, pts);) { - if (pts[0] != pts[1] && pts[1] != pts[2] && pts[2] != pts[0]) { - pd->InsertNextCell(VTK_TRIANGLE, n, pts); + newPd->InsertNextCell(VTK_TRIANGLE, 3, cellA); cellIds->InsertNextValue(cellId); - } - } + newPd->InsertNextCell(VTK_TRIANGLE, 3, cellB); + cellIds->InsertNextValue(cellId); - cells->Delete(); + } else { + // 1, 3 + const vtkIdType cellA[] = {ptIds->GetId(1), ptIds->GetId(2), ptIds->GetId(3)}; + const vtkIdType cellB[] = {ptIds->GetId(3), ptIds->GetId(0), ptIds->GetId(1)}; - pd->DeleteCell(cellId); + newPd->InsertNextCell(VTK_TRIANGLE, 3, cellA); + cellIds->InsertNextValue(cellId); - } else if (cellItr->GetCellType() != VTK_TRIANGLE && cellItr->GetCellType() != VTK_POLYGON) { - pd->DeleteCell(cellId); + newPd->InsertNextCell(VTK_TRIANGLE, 3, cellB); + cellIds->InsertNextValue(cellId); + } + } } } cellItr->Delete(); cellIds->SetName("OrigCellIds"); - pd->GetCellData()->SetScalars(cellIds); - - cellIds->Delete(); + newPd->GetCellData()->SetScalars(cellIds); - pd->RemoveDeletedCells(); - pd->BuildLinks(); + newPd->Squeeze(); } @@ -675,6 +647,12 @@ bool vtkPolyDataContactFilter::InterPolyLine (InterPtsType &interPts, vtkPolyDat _interPts.insert(_interPts.end(), pts.begin(), pts.end()); } + // probe, ob die schnittpunkte auf den kanten liegen + + if (!vtkPolyDataContactFilter::CheckInters(_interPts, pd)) { + return false; + } + interPts.swap(_interPts); return true; @@ -690,28 +668,28 @@ void vtkPolyDataContactFilter::InterPolys (vtkIdType idA, vtkIdType idB) { vtkIdType numA, numB; const vtkIdType *polyA, *polyB; - pdA->GetCellPoints(idA, numA, polyA); - pdB->GetCellPoints(idB, numB, polyB); + newPdA->GetCellPoints(idA, numA, polyA); + newPdB->GetCellPoints(idB, numB, polyB); // ebenen aufstellen double nA[3], nB[3], ptA[3], ptB[3], dA, dB; - ComputeNormal(pdA->GetPoints(), nA, numA, polyA); - ComputeNormal(pdB->GetPoints(), nB, numB, polyB); + ComputeNormal(newPdA->GetPoints(), nA, numA, polyA); + ComputeNormal(newPdB->GetPoints(), nB, numB, polyB); - pdA->GetPoint(polyA[0], ptA); - pdB->GetPoint(polyB[0], ptB); + newPdA->GetPoint(polyA[0], ptA); + newPdB->GetPoint(polyB[0], ptB); dA = vtkMath::Dot(nA, ptA); dB = vtkMath::Dot(nB, ptB); - if (!CheckNormal(pdA->GetPoints(), numA, polyA, nA, dA)) { + if (!CheckNormal(newPdA->GetPoints(), numA, polyA, nA, dA)) { aborted = true; return; } - if (!CheckNormal(pdB->GetPoints(), numB, polyB, nB, dB)) { + if (!CheckNormal(newPdB->GetPoints(), numB, polyB, nB, dB)) { aborted = true; return; } @@ -765,14 +743,12 @@ void vtkPolyDataContactFilter::InterPolys (vtkIdType idA, vtkIdType idB) { InterPtsType intersA, intersB; - // probe, ob die schnittpunkte auf den kanten liegen - - if (!vtkPolyDataContactFilter::InterPolyLine(intersA, pdA, numA, polyA, r, s, Src::A, nA) || !vtkPolyDataContactFilter::CheckInters(intersA, pdA)) { + if (!vtkPolyDataContactFilter::InterPolyLine(intersA, newPdA, numA, polyA, r, s, Src::A, nA)) { aborted = true; return; } - if (!vtkPolyDataContactFilter::InterPolyLine(intersB, pdB, numB, polyB, r, s, Src::B, nB) || !vtkPolyDataContactFilter::CheckInters(intersB, pdB)) { + if (!vtkPolyDataContactFilter::InterPolyLine(intersB, newPdB, numB, polyB, r, s, Src::B, nB)) { aborted = true; return; } @@ -872,8 +848,8 @@ void vtkPolyDataContactFilter::AddContactLines (InterPtsType &intersA, InterPtsT vtkIdList *linePts = vtkIdList::New(); - linePts->InsertNextId(contPts->InsertNextPoint(f.pt)); - linePts->InsertNextId(contPts->InsertNextPoint(s.pt)); + linePts->InsertNextId(contLines->GetPoints()->InsertNextPoint(f.pt)); + linePts->InsertNextId(contLines->GetPoints()->InsertNextPoint(s.pt)); contLines->InsertNextCell(VTK_LINE, linePts); diff --git a/vtkPolyDataContactFilter.h b/vtkPolyDataContactFilter.h index 891a347..c59d7b1 100644 --- a/vtkPolyDataContactFilter.h +++ b/vtkPolyDataContactFilter.h @@ -1,5 +1,5 @@ /* -Copyright 2012-2023 Ronald Römer +Copyright 2012-2024 Ronald Römer Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -94,7 +94,7 @@ typedef std::set InvalidEdgesType; class VTK_EXPORT vtkPolyDataContactFilter : public vtkPolyDataAlgorithm { - void PreparePolyData (vtkPolyData *pd); + void CopyPolyData (vtkPolyData *pd, vtkPolyData *newPd); static void InterEdgeLine (InterPtsType &interPts, vtkPolyData *pd, vtkIdType idA, vtkIdType idB, const double *r, const double *pt, Src src); static bool InterPolyLine (InterPtsType &interPts, vtkPolyData *pd, vtkIdType num, const vtkIdType *poly, const double *r, const double *pt, Src src, const double *n); @@ -104,20 +104,14 @@ class VTK_EXPORT vtkPolyDataContactFilter : public vtkPolyDataAlgorithm { static bool CheckInters (InterPtsType &interPts, vtkPolyData *pd); - vtkIdTypeArray *contA, *contB; + vtkSmartPointer newPdA, newPdB; - vtkPolyData *contLines; - vtkPoints *contPts; - - vtkPolyData *pdA, *pdB; - - vtkIdTypeArray *sourcesA, *sourcesB; + vtkSmartPointer contLines; + vtkSmartPointer contA, contB, sourcesA, sourcesB; bool invalidA, invalidB; InvalidEdgesType edgesA, edgesB; - vtkIdTypeArray *origCellIdsA, *origCellIdsB; - void GetInvalidEdges (vtkPolyData *pd, InvalidEdgesType &edges); bool aborted;