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;
dihedralAnglesFilter->SetInputConnection(tetMeshReader->GetOutputPort());
// vtkNew<vtkXMLPolyDataReader> polyMeshReader;
// polyMeshReader->SetFileName(argv[2]);
vtkNew<vtkOBJReader> polyMeshReader;
vtkNew<vtkXMLPolyDataReader> polyMeshReader;
polyMeshReader->SetFileName(argv[2]);
// vtkNew<vtkOBJReader> polyMeshReader;
// polyMeshReader->SetFileName(argv[2]);
vtkNew<RemoveExternalCellsFilter> removeExternalCellsFilter;
removeExternalCellsFilter->SetInputConnection(0,

View File

@ -1,6 +1,7 @@
#include "remove_external_cells_filter.h"
#include "point_tris_dist.h"
#include <vtkCellType.h>
#include <vtkUnstructuredGrid.h>
#include <vtkDataObject.h>
#include <vtkPolyData.h>
@ -8,6 +9,7 @@
#include <vtkCellData.h>
#include <vtkCellIterator.h>
#include <vtkSelectEnclosedPoints.h>
#include <vtkUnsignedCharArray.h>
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(
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<vtkSelectEnclosedPoints> selectEnclosedPoints;
selectEnclosedPoints->SetInputDataObject(0, tetMesh);
selectEnclosedPoints->SetInputDataObject(1, polyMesh);
selectEnclosedPoints->Update();
unsigned char *enclosedPoints = (unsigned char *)
selectEnclosedPoints->GetOutput()->GetPointData()
->GetArray("SelectedPoints")->GetVoidPointer(0);
vtkNew<vtkPoints> outPoints;
vtkNew<vtkIdList> outPointIds;
vtkIdType outPointId = 0;
outPointIds->SetNumberOfIds(4);
output->Allocate();
vtkUnsignedCharArray *enclosedPoints =
vtkUnsignedCharArray::SafeDownCast(
selectEnclosedPoints->GetOutput()
->GetPointData()->GetArray("SelectedPoints"));
vtkNew<vtkCellArray> 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;
}