fix point to triangle distance computation

This commit is contained in:
papush! 2022-03-02 14:46:01 +01:00
parent 13a582b20b
commit fee21c7a34
3 changed files with 39 additions and 30 deletions

View File

@ -121,16 +121,23 @@ int main(int argc, char **argv) {
profile->SetPoints(points);
profile->SetStrips(strips);
vtkTriangle *cell = vtkTriangle::SafeDownCast(profile->GetCell(0));
vtkCell *cell = profile->GetCell(0);
// vtkTriangle *triangle = vtkTriangle::SafeDownCast(cell);
// vtkTriangle *triangle = (vtkTriangle *) cell;
double direction[3] = {0, 0, 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";
std::cout << "[" << point[0]
<< ", " << point[1]
<< ", " << point[2]
<< "] (" << d << ")"
<< "[" << direction[0]
<< ", " << direction[1]
<< ", " << direction[2] << "]\n";
#ifdef USE_VIEWER
/* Volume rendering properties */

View File

@ -1,19 +1,20 @@
#include "point_tris_dist.h"
#include <vtkPoints.h>
#include <vtkTriangle.h>
#include <vtkMath.h>
double pointSegmentDistance(double *p, double *a, double *b, double* normal) {
double pointSegmentDistance(double *p, double *a, double *b, double* direction) {
double segSqrLength = vtkMath::Distance2BetweenPoints(a, b);
double ap[3]; vtkMath::Subtract(p, a, ap);
double ab[3]; vtkMath::Subtract(b, a, ab);
if(segSqrLength <= 0) {
normal[0] = ap[0];
normal[1] = ap[1];
normal[2] = ap[2];
vtkMath::Normalize(normal);
direction[0] = ap[0];
direction[1] = ap[1];
direction[2] = ap[2];
vtkMath::Normalize(direction);
return vtkMath::Norm(ap, 3);
}
@ -22,14 +23,14 @@ double pointSegmentDistance(double *p, double *a, double *b, double* normal) {
vtkMath::MultiplyScalar(ab, h);
double v[3]; vtkMath::Subtract(ap, ab, v);
normal[0] = v[0];
normal[1] = v[1];
normal[2] = v[2];
vtkMath::Normalize(normal);
direction[0] = v[0];
direction[1] = v[1];
direction[2] = v[2];
vtkMath::Normalize(direction);
return vtkMath::Norm(v);
}
double pointTriangleDistance(double *p, vtkTriangle *triangle, double *normal) {
double pointTriangleDistance(double *p, vtkCell *triangle, double *direction) {
double a[3]; triangle->GetPoints()->GetPoint(0, a);
double b[3]; triangle->GetPoints()->GetPoint(1, b);
double c[3]; triangle->GetPoints()->GetPoint(2, c);
@ -64,7 +65,7 @@ double pointTriangleDistance(double *p, vtkTriangle *triangle, double *normal) {
n[2] * p[2],
};
double t[3]; vtkMath::Subtract(na, np, t);
double t[3]; vtkMath::Subtract(np, na, t);
double nt[3] = {
n[0] * t[0],
@ -73,10 +74,10 @@ double pointTriangleDistance(double *p, vtkTriangle *triangle, double *normal) {
};
normal[0] = nt[0];
normal[1] = nt[1];
normal[2] = nt[2];
vtkMath::Normalize(normal);
direction[0] = nt[0];
direction[1] = nt[1];
direction[2] = nt[2];
vtkMath::Normalize(direction);
return vtkMath::Norm(nt);
} else {
@ -91,17 +92,17 @@ double pointTriangleDistance(double *p, vtkTriangle *triangle, double *normal) {
double min = vtkMath::Min(lab, vtkMath::Min(lbc, lca));
if(min == lab) {
normal[0] = normalA[0];
normal[1] = normalA[1];
normal[2] = normalA[2];
direction[0] = normalA[0];
direction[1] = normalA[1];
direction[2] = normalA[2];
} else if(min == lbc) {
normal[0] = normalB[0];
normal[1] = normalB[1];
normal[2] = normalB[2];
direction[0] = normalB[0];
direction[1] = normalB[1];
direction[2] = normalB[2];
} else {
normal[0] = normalC[0];
normal[1] = normalC[1];
normal[2] = normalC[2];
direction[0] = normalC[0];
direction[1] = normalC[1];
direction[2] = normalC[2];
}
return min;

View File

@ -1,9 +1,10 @@
#ifndef POINT_TRIS_DIST_H
#define POINT_TRIS_DIST_H
#include <vtkTriangle.h>
/* #include <vtkTriangle.h> */
#include <vtkCell.h>
#include <utility>
double pointTriangleDistance(double *point, vtkTriangle *triangle, double *normal);
double pointTriangleDistance(double *point, vtkCell *triangle, double *direction);
#endif