From 13a582b20b4516db39466448d9a862d38289886f Mon Sep 17 00:00:00 2001 From: CookieKastanie Date: Wed, 2 Mar 2022 14:07:13 +0100 Subject: [PATCH] OUCH --- src/main.cc | 29 +++++++++++++++++++++++++++++ src/point_tris_dist.cc | 10 +++++----- 2 files changed, 34 insertions(+), 5 deletions(-) diff --git a/src/main.cc b/src/main.cc index 8efe320..c7afaf9 100644 --- a/src/main.cc +++ b/src/main.cc @@ -4,11 +4,14 @@ #include "external_points_filter.h" #include "mesh_fit_filter.h" +#include "point_tris_dist.h" #include #include #include #include +#include +#include #ifdef USE_VIEWER #include @@ -103,6 +106,32 @@ int main(int argc, char **argv) { writer->Write(); + vtkNew points; + points->InsertPoint(0, 0., 0., 0.); + points->InsertPoint(1, 1., 0., 0.); + points->InsertPoint(2, 1., 1., 0.); + + vtkNew strips; + strips->InsertNextCell(3); + strips->InsertCellPoint(0); + strips->InsertCellPoint(1); + strips->InsertCellPoint(2); + + vtkNew profile; + profile->SetPoints(points); + profile->SetStrips(strips); + + vtkTriangle *cell = vtkTriangle::SafeDownCast(profile->GetCell(0)); + + double direction[3] = {0, 0, 0}; + double point[3] = {0, 1, 0}; + + double d = pointTriangleDistance(point, cell, direction); + //double d = 5; + + std::cout << "[" << point[0] << ", " << point[1] << ", " << point[2] << "] (" << d << ")" + << "[" << direction[0] << ", " << direction[1] << ", " << direction[2] << "]\n"; + #ifdef USE_VIEWER /* Volume rendering properties */ vtkNew volumeMapper; diff --git a/src/point_tris_dist.cc b/src/point_tris_dist.cc index 555edda..aaef56a 100644 --- a/src/point_tris_dist.cc +++ b/src/point_tris_dist.cc @@ -31,8 +31,8 @@ double pointSegmentDistance(double *p, double *a, double *b, double* normal) { double pointTriangleDistance(double *p, vtkTriangle *triangle, double *normal) { double a[3]; triangle->GetPoints()->GetPoint(0, a); - double b[3]; triangle->GetPoints()->GetPoint(0, b); - double c[3]; triangle->GetPoints()->GetPoint(0, c); + double b[3]; triangle->GetPoints()->GetPoint(1, b); + double c[3]; triangle->GetPoints()->GetPoint(2, c); double ab[3]; vtkMath::Subtract(b, a, ab); double bc[3]; vtkMath::Subtract(c, b, bc); @@ -73,9 +73,9 @@ double pointTriangleDistance(double *p, vtkTriangle *triangle, double *normal) { }; - normal[0] = np[0]; - normal[1] = np[1]; - normal[2] = np[2]; + normal[0] = nt[0]; + normal[1] = nt[1]; + normal[2] = nt[2]; vtkMath::Normalize(normal); return vtkMath::Norm(nt);