finish implementing RemoveExternalCellsFilter

This commit is contained in:
papush! 2022-03-08 14:02:40 +01:00
parent 151522fa57
commit 61d1f67b06
2 changed files with 19 additions and 106 deletions

View File

@ -44,10 +44,10 @@ int main(int argc, char **argv) {
vtkNew<DihedralAnglesFilter> dihedralAnglesFilter; vtkNew<DihedralAnglesFilter> dihedralAnglesFilter;
dihedralAnglesFilter->SetInputConnection(tetMeshReader->GetOutputPort()); dihedralAnglesFilter->SetInputConnection(tetMeshReader->GetOutputPort());
// vtkNew<vtkXMLPolyDataReader> polyMeshReader; vtkNew<vtkXMLPolyDataReader> polyMeshReader;
// polyMeshReader->SetFileName(argv[2]);
vtkNew<vtkOBJReader> polyMeshReader;
polyMeshReader->SetFileName(argv[2]); polyMeshReader->SetFileName(argv[2]);
// vtkNew<vtkOBJReader> polyMeshReader;
// polyMeshReader->SetFileName(argv[2]);
vtkNew<RemoveExternalCellsFilter> removeExternalCellsFilter; vtkNew<RemoveExternalCellsFilter> removeExternalCellsFilter;
removeExternalCellsFilter->SetInputConnection(0, removeExternalCellsFilter->SetInputConnection(0,

View File

@ -1,6 +1,7 @@
#include "remove_external_cells_filter.h" #include "remove_external_cells_filter.h"
#include "point_tris_dist.h" #include "point_tris_dist.h"
#include <vtkCellType.h>
#include <vtkUnstructuredGrid.h> #include <vtkUnstructuredGrid.h>
#include <vtkDataObject.h> #include <vtkDataObject.h>
#include <vtkPolyData.h> #include <vtkPolyData.h>
@ -8,6 +9,7 @@
#include <vtkCellData.h> #include <vtkCellData.h>
#include <vtkCellIterator.h> #include <vtkCellIterator.h>
#include <vtkSelectEnclosedPoints.h> #include <vtkSelectEnclosedPoints.h>
#include <vtkUnsignedCharArray.h>
vtkStandardNewMacro(RemoveExternalCellsFilter); vtkStandardNewMacro(RemoveExternalCellsFilter);
@ -29,81 +31,6 @@ int RemoveExternalCellsFilter::FillInputPortInformation(
} }
// static bool isSurfaceCell(vtkUnstructuredGrid *tetMesh, vtkIdType cellId) {
// vtkNew<vtkIdList> facePoints;
// vtkNew<vtkIdList> 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<double>::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<vtkIdList> 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( vtkTypeBool RemoveExternalCellsFilter::RequestData(
vtkInformation *request, vtkInformation *request,
vtkInformationVector **inputVector, vtkInformationVector **inputVector,
@ -112,43 +39,29 @@ vtkTypeBool RemoveExternalCellsFilter::RequestData(
vtkUnstructuredGrid* tetMesh = vtkUnstructuredGrid::GetData(inputVector[0]); vtkUnstructuredGrid* tetMesh = vtkUnstructuredGrid::GetData(inputVector[0]);
vtkPolyData *polyMesh = vtkPolyData::GetData(inputVector[1]); vtkPolyData *polyMesh = vtkPolyData::GetData(inputVector[1]);
vtkUnstructuredGrid* output = vtkUnstructuredGrid::GetData(outputVector); vtkUnstructuredGrid* output = vtkUnstructuredGrid::GetData(outputVector);
// output->CopyStructure(tetMesh);
// output->GetPointData()->PassData(tetMesh->GetPointData());
// output->GetCellData()->PassData(tetMesh->GetCellData());
vtkNew<vtkSelectEnclosedPoints> selectEnclosedPoints; vtkNew<vtkSelectEnclosedPoints> selectEnclosedPoints;
selectEnclosedPoints->SetInputDataObject(0, tetMesh); selectEnclosedPoints->SetInputDataObject(0, tetMesh);
selectEnclosedPoints->SetInputDataObject(1, polyMesh); selectEnclosedPoints->SetInputDataObject(1, polyMesh);
selectEnclosedPoints->Update(); selectEnclosedPoints->Update();
unsigned char *enclosedPoints = (unsigned char *) vtkUnsignedCharArray *enclosedPoints =
selectEnclosedPoints->GetOutput()->GetPointData() vtkUnsignedCharArray::SafeDownCast(
->GetArray("SelectedPoints")->GetVoidPointer(0); selectEnclosedPoints->GetOutput()
vtkNew<vtkPoints> outPoints; ->GetPointData()->GetArray("SelectedPoints"));
vtkNew<vtkIdList> outPointIds;
vtkIdType outPointId = 0; vtkNew<vtkCellArray> outCells;
outPointIds->SetNumberOfIds(4);
output->Allocate();
auto it = tetMesh->NewCellIterator(); auto it = tetMesh->NewCellIterator();
for (it->InitTraversal(); for (it->InitTraversal(); !it->IsDoneWithTraversal(); it->GoToNextCell()) {
!it->IsDoneWithTraversal();
it->GoToNextCell()) {
vtkIdList *pointIds = it->GetPointIds(); vtkIdList *pointIds = it->GetPointIds();
if (!enclosedPoints[pointIds->GetId(0)] if (enclosedPoints->GetValue(pointIds->GetId(0))
&& !enclosedPoints[pointIds->GetId(1)] || enclosedPoints->GetValue(pointIds->GetId(1))
&& !enclosedPoints[pointIds->GetId(2)] || enclosedPoints->GetValue(pointIds->GetId(2))
&& !enclosedPoints[pointIds->GetId(3)]) { || enclosedPoints->GetValue(pointIds->GetId(3))) {
outPointIds->SetId(0, outPointId + 0); outCells->InsertNextCell(it->GetPointIds());
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);
} }
} }
outPoints->SetNumberOfPoints(outPointId + 3); output->SetCells(VTK_TETRA, outCells);
output->SetPoints(outPoints); output->SetPoints(tetMesh->GetPoints());
return true; return true;
} }