diff --git a/src/main.cc b/src/main.cc index 5e2107b..3d30b6a 100644 --- a/src/main.cc +++ b/src/main.cc @@ -44,10 +44,10 @@ int main(int argc, char **argv) { vtkNew dihedralAnglesFilter; dihedralAnglesFilter->SetInputConnection(tetMeshReader->GetOutputPort()); - // vtkNew polyMeshReader; - // polyMeshReader->SetFileName(argv[2]); - vtkNew polyMeshReader; + vtkNew polyMeshReader; polyMeshReader->SetFileName(argv[2]); + // vtkNew polyMeshReader; + // polyMeshReader->SetFileName(argv[2]); vtkNew removeExternalCellsFilter; removeExternalCellsFilter->SetInputConnection(0, diff --git a/src/remove_external_cells_filter.cc b/src/remove_external_cells_filter.cc index f3a2455..55dafa2 100644 --- a/src/remove_external_cells_filter.cc +++ b/src/remove_external_cells_filter.cc @@ -1,6 +1,7 @@ #include "remove_external_cells_filter.h" #include "point_tris_dist.h" +#include #include #include #include @@ -8,6 +9,7 @@ #include #include #include +#include vtkStandardNewMacro(RemoveExternalCellsFilter); @@ -29,81 +31,6 @@ int RemoveExternalCellsFilter::FillInputPortInformation( } -// static bool isSurfaceCell(vtkUnstructuredGrid *tetMesh, vtkIdType cellId) { -// vtkNew facePoints; -// vtkNew sharedCells; -// for (vtkIdType faceId = 0; faceId < 4; faceId++) { -// facePoints->InsertNextId((faceId + 0) % 4); -// facePoints->InsertNextId((faceId + 1) % 4); -// facePoints->InsertNextId((faceId + 2) % 4); -// tetMesh->GetCellNeighbors(cellId, facePoints, sharedCells); -// if (sharedCells->GetNumberOfIds() == 1) { // Surface cell. -// return true; -// } -// facePoints->Reset(); -// sharedCells->Reset(); -// } -// return false; -// } - - -// static void closestTri(vtkPolyData *polyMesh, -// vtkKdTree *kdTree, -// vtkStaticCellLinks *polyMeshLinks, -// double *point, -// double *closestTriDist, -// double *closestTriDirection) { -// vtkIdType closestPoint; -// { -// double dummy; -// closestPoint = kdTree->FindClosestPoint(point, dummy); -// } -// vtkIdType *triIds = polyMeshLinks->GetCells(closestPoint); -// vtkIdType nTris = polyMeshLinks->GetNcells(closestPoint); - -// *closestTriDist = std::numeric_limits::infinity(); -// for (vtkIdType j = 0; j < nTris; j++) { -// vtkIdType cellId = triIds[j]; -// double direction[3]; -// double dist = pointTriangleDistance(point, polyMesh->GetCell(cellId), -// direction); -// if (dist < *closestTriDist) { -// *closestTriDist = dist; -// closestTriDirection[0] = direction[0]; -// closestTriDirection[1] = direction[1]; -// closestTriDirection[2] = direction[2]; -// } -// } -// } - - -// static bool isExternalCell(vtkUnstructuredGrid *tetMesh, -// vtkPolyData *polyMesh, -// vtkStaticCellLinks *polyMeshLinks, -// vtkKdTree *kdTree, -// vtkIdType cellId) { -// vtkNew pointIds; -// tetMesh->GetCellPoints(cellId, pointIds); -// double a[3], b[3], c[3]; -// tetMesh->GetPoint(pointIds->GetId(0), a); -// tetMesh->GetPoint(pointIds->GetId(1), b); -// tetMesh->GetPoint(pointIds->GetId(2), c); - -// double aDist, bDist, cDist; -// double aDirection[3], bDirection[3], cDirection[3]; -// closestTri(polyMesh, kdTree, polyMeshLinks, a, -// &aDist, aDirection); -// closestTri(polyMesh, kdTree, polyMeshLinks, b, -// &bDist, bDirection); -// closestTri(polyMesh, kdTree, polyMeshLinks, c, -// &cDist, cDirection); -// if (aDist > 0 && bDist > 0 && cDist > 0) { -// return true; -// } -// return false; -// } - - vtkTypeBool RemoveExternalCellsFilter::RequestData( vtkInformation *request, vtkInformationVector **inputVector, @@ -112,43 +39,29 @@ vtkTypeBool RemoveExternalCellsFilter::RequestData( vtkUnstructuredGrid* tetMesh = vtkUnstructuredGrid::GetData(inputVector[0]); vtkPolyData *polyMesh = vtkPolyData::GetData(inputVector[1]); vtkUnstructuredGrid* output = vtkUnstructuredGrid::GetData(outputVector); - // output->CopyStructure(tetMesh); - // output->GetPointData()->PassData(tetMesh->GetPointData()); - // output->GetCellData()->PassData(tetMesh->GetCellData()); vtkNew selectEnclosedPoints; selectEnclosedPoints->SetInputDataObject(0, tetMesh); selectEnclosedPoints->SetInputDataObject(1, polyMesh); selectEnclosedPoints->Update(); - unsigned char *enclosedPoints = (unsigned char *) - selectEnclosedPoints->GetOutput()->GetPointData() - ->GetArray("SelectedPoints")->GetVoidPointer(0); - vtkNew outPoints; - vtkNew outPointIds; - vtkIdType outPointId = 0; - outPointIds->SetNumberOfIds(4); - output->Allocate(); + vtkUnsignedCharArray *enclosedPoints = + vtkUnsignedCharArray::SafeDownCast( + selectEnclosedPoints->GetOutput() + ->GetPointData()->GetArray("SelectedPoints")); + + vtkNew outCells; auto it = tetMesh->NewCellIterator(); - for (it->InitTraversal(); - !it->IsDoneWithTraversal(); - it->GoToNextCell()) { + for (it->InitTraversal(); !it->IsDoneWithTraversal(); it->GoToNextCell()) { vtkIdList *pointIds = it->GetPointIds(); - if (!enclosedPoints[pointIds->GetId(0)] - && !enclosedPoints[pointIds->GetId(1)] - && !enclosedPoints[pointIds->GetId(2)] - && !enclosedPoints[pointIds->GetId(3)]) { - outPointIds->SetId(0, outPointId + 0); - outPointIds->SetId(1, outPointId + 1); - outPointIds->SetId(2, outPointId + 2); - outPointIds->SetId(3, outPointId + 3); - outPointId += 4; - outPoints->InsertPoints(outPointIds, pointIds, - tetMesh->GetPoints()); - output->InsertNextCell(it->GetCellType(), outPointIds); + if (enclosedPoints->GetValue(pointIds->GetId(0)) + || enclosedPoints->GetValue(pointIds->GetId(1)) + || enclosedPoints->GetValue(pointIds->GetId(2)) + || enclosedPoints->GetValue(pointIds->GetId(3))) { + outCells->InsertNextCell(it->GetPointIds()); } } - outPoints->SetNumberOfPoints(outPointId + 3); - output->SetPoints(outPoints); + output->SetCells(VTK_TETRA, outCells); + output->SetPoints(tetMesh->GetPoints()); return true; }