From 62bc5963ffc693d04dd4a32d902d1312ff593fb6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jacob=20St=C3=B8ren?= Date: Sun, 30 Aug 2015 21:27:53 +0200 Subject: [PATCH] (#397) Added line triangle intersection direction to intersection method Preparing for Well Log Extraction --- ApplicationCode/ReservoirDataModel/cvfGeometryTools.cpp | 9 +++++++-- ApplicationCode/ReservoirDataModel/cvfGeometryTools.h | 3 ++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/ApplicationCode/ReservoirDataModel/cvfGeometryTools.cpp b/ApplicationCode/ReservoirDataModel/cvfGeometryTools.cpp index 664f80af5b..1a5d47012d 100644 --- a/ApplicationCode/ReservoirDataModel/cvfGeometryTools.cpp +++ b/ApplicationCode/ReservoirDataModel/cvfGeometryTools.cpp @@ -374,9 +374,11 @@ double GeometryTools::linePointSquareDist(const cvf::Vec3d& p1, const cvf::Vec3d int GeometryTools::intersectLineSegmentTriangle( const cvf::Vec3d p0, const cvf::Vec3d p1, const cvf::Vec3d t0, const cvf::Vec3d t1, const cvf::Vec3d t2, - cvf::Vec3d* intersectionPoint ) + cvf::Vec3d* intersectionPoint , bool * isLineDirDotNormalNegative) { - CVF_ASSERT(intersectionPoint != NULL); + CVF_TIGHT_ASSERT(intersectionPoint != NULL); + CVF_TIGHT_ASSERT(isLineDirDotNormalNegative != NULL); + cvf::Vec3d u, v, n; // triangle vectors cvf::Vec3d dir, w0, w; // ray vectors double r, a, b; // params to calc ray-plane intersect @@ -392,6 +394,9 @@ int GeometryTools::intersectLineSegmentTriangle( const cvf::Vec3d p0, const cvf: w0 = p0 - t0; a = -dot(n, w0); b = dot(n, dir); + + (*isLineDirDotNormalNegative) = (b < 0.0); + if (fabs(b) < SMALL_NUM) { // ray is parallel to triangle plane if (a == 0) // ray lies in triangle plane return 2; diff --git a/ApplicationCode/ReservoirDataModel/cvfGeometryTools.h b/ApplicationCode/ReservoirDataModel/cvfGeometryTools.h index 2c9e2a58a6..2c1478a983 100644 --- a/ApplicationCode/ReservoirDataModel/cvfGeometryTools.h +++ b/ApplicationCode/ReservoirDataModel/cvfGeometryTools.h @@ -39,7 +39,8 @@ public: static double linePointSquareDist(const cvf::Vec3d& p1, const cvf::Vec3d& p2, const cvf::Vec3d& p3); static int intersectLineSegmentTriangle( const cvf::Vec3d p0, const cvf::Vec3d p1, const cvf::Vec3d t0, const cvf::Vec3d t1, const cvf::Vec3d t2, - cvf::Vec3d* intersectionPoint ); + cvf::Vec3d* intersectionPoint, + bool * isLineDirDotNormalNegative); static cvf::Vec3d barycentricCoords(const cvf::Vec3d& t0, const cvf::Vec3d& t1, const cvf::Vec3d& t2, const cvf::Vec3d& p); static cvf::Vec4d barycentricCoords(const cvf::Vec3d& v0, const cvf::Vec3d& v1, const cvf::Vec3d& v2, const cvf::Vec3d& v3, const cvf::Vec3d& p); static double interpolateQuad(const cvf::Vec3d& v1, double s1,