Compare commits

...

3 Commits

Author SHA1 Message Date
dcc99754b6 blbllblbl 2022-03-08 14:26:23 +01:00
5cb78e0881 remove trailing whitespace grrrrrrrrrrrrr 2022-03-08 14:26:08 +01:00
80a3172c77 refactor surface point filter 2022-03-08 14:25:59 +01:00
4 changed files with 27 additions and 23 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,
@ -55,12 +55,16 @@ int main(int argc, char **argv) {
removeExternalCellsFilter->SetInputConnection(1, removeExternalCellsFilter->SetInputConnection(1,
polyMeshReader->GetOutputPort()); polyMeshReader->GetOutputPort());
// vtkNew<ProjectSurfacePointsOnPoly> project; vtkNew<SurfacePointsFilter> surfacePointsFilter;
// project->SetInputConnection(0, removeExternalCellsFilter->GetOutputPort()); surfacePointsFilter->SetInputConnection(
// project->SetInputConnection(1, pdReader->GetOutputPort()); removeExternalCellsFilter->GetOutputPort());
vtkNew<ProjectSurfacePointsOnPoly> project;
project->SetInputConnection(0, surfacePointsFilter->GetOutputPort());
project->SetInputConnection(1, polyMeshReader->GetOutputPort());
vtkNew<vtkXMLUnstructuredGridWriter> writer; vtkNew<vtkXMLUnstructuredGridWriter> writer;
writer->SetInputConnection(removeExternalCellsFilter->GetOutputPort()); writer->SetInputConnection(project->GetOutputPort());
writer->SetDataModeToAscii(); writer->SetDataModeToAscii();
writer->SetFileName("out.vtu"); writer->SetFileName("out.vtu");
writer->Write(); writer->Write();

View File

@ -17,7 +17,7 @@ double pointSegmentDistance(double *p, double *a, double *b, double* direction)
vtkMath::Normalize(direction); vtkMath::Normalize(direction);
return vtkMath::Norm(ap, 3); return vtkMath::Norm(ap, 3);
} }
double h = vtkMath::ClampValue(vtkMath::Dot(ap, ab) / segSqrLength, 0., 1.); double h = vtkMath::ClampValue(vtkMath::Dot(ap, ab) / segSqrLength, 0., 1.);
vtkMath::MultiplyScalar(ab, h); vtkMath::MultiplyScalar(ab, h);

View File

@ -41,27 +41,27 @@ vtkTypeBool ProjectSurfacePointsOnPoly::RequestData(
vtkInformationVector **inputVector, vtkInformationVector **inputVector,
vtkInformationVector *outputVector) { vtkInformationVector *outputVector) {
(void) request; (void) request;
vtkUnstructuredGrid* us = vtkUnstructuredGrid::GetData(inputVector[0]); vtkUnstructuredGrid* tetMesh = vtkUnstructuredGrid::GetData(inputVector[0]);
vtkPolyData* pd = vtkPolyData::GetData(inputVector[1]); vtkPolyData* polyMesh = vtkPolyData::GetData(inputVector[1]);
vtkUnstructuredGrid* output = vtkUnstructuredGrid* output =
vtkUnstructuredGrid::GetData(outputVector); vtkUnstructuredGrid::GetData(outputVector);
output->CopyStructure(us); output->CopyStructure(tetMesh);
output->GetPointData()->PassData(us->GetPointData()); output->GetPointData()->PassData(tetMesh->GetPointData());
output->GetCellData()->PassData(us->GetCellData()); output->GetCellData()->PassData(tetMesh->GetCellData());
/* Generate cell links, these tell us which cell a point belongs to. */ /* Generate cell links, these tell us which cell a point belongs to. */
vtkNew<vtkStaticCellLinks> links; vtkNew<vtkStaticCellLinks> links;
links->BuildLinks(pd); links->BuildLinks(polyMesh);
vtkNew<vtkKdTree> kdTree; vtkNew<vtkKdTree> kdTree;
kdTree->BuildLocatorFromPoints(pd->GetPoints()); kdTree->BuildLocatorFromPoints(polyMesh->GetPoints());
vtkIdTypeArray *externalPoints = vtkIdTypeArray *surfacePoints =
vtkIdTypeArray::SafeDownCast(us->GetFieldData()->GetArray("external_points")); vtkIdTypeArray::SafeDownCast(tetMesh->GetFieldData()->GetArray("surface_points"));
for (vtkIdType i = 0; i < externalPoints->GetNumberOfTuples(); i++) { for (vtkIdType i = 0; i < surfacePoints->GetNumberOfTuples(); i++) {
double p[3]; double p[3];
us->GetPoint(externalPoints->GetTuple1(i), p); tetMesh->GetPoint(surfacePoints->GetTuple1(i), p);
double dist2; double dist2;
vtkIdType closest = kdTree->FindClosestPoint(p, dist2); vtkIdType closest = kdTree->FindClosestPoint(p, dist2);
vtkIdType *cellIds = links->GetCells(closest); vtkIdType *cellIds = links->GetCells(closest);
@ -73,7 +73,7 @@ vtkTypeBool ProjectSurfacePointsOnPoly::RequestData(
for (vtkIdType j = 0; j < nCells; j++) { for (vtkIdType j = 0; j < nCells; j++) {
vtkIdType cellId = cellIds[j]; vtkIdType cellId = cellIds[j];
double direction[3]; double direction[3];
double dist = pointTriangleDistance(p, pd->GetCell(cellId), direction); double dist = pointTriangleDistance(p, polyMesh->GetCell(cellId), direction);
/* Find the closest one. */ /* Find the closest one. */
if (dist < min_dist) { if (dist < min_dist) {
min_dist = dist; min_dist = dist;
@ -85,8 +85,8 @@ vtkTypeBool ProjectSurfacePointsOnPoly::RequestData(
vtkMath::MultiplyScalar(min_direction, min_dist); vtkMath::MultiplyScalar(min_direction, min_dist);
vtkMath::Subtract(p, min_direction, p); vtkMath::Subtract(p, min_direction, p);
us->GetPoints()->SetPoint(externalPoints->GetTuple1(i), p); tetMesh->GetPoints()->SetPoint(surfacePoints->GetTuple1(i), p);
us->Modified(); tetMesh->Modified();
} }
return true; return true;

View File

@ -52,7 +52,7 @@ vtkTypeBool SurfacePointsFilter::RequestData(
/* Create an array to store the IDs of external points. */ /* Create an array to store the IDs of external points. */
vtkNew<vtkIdTypeArray> externalPoints; vtkNew<vtkIdTypeArray> externalPoints;
externalPoints->SetName("external_points"); externalPoints->SetName("surface_points");
externalPoints->SetNumberOfComponents(1); externalPoints->SetNumberOfComponents(1);
vtkNew<vtkIntArray> isExternal; vtkNew<vtkIntArray> isExternal;
isExternal->SetName("bl"); isExternal->SetName("bl");