From e9b537adf29085ab10d3f1c4107c5890f93da09d Mon Sep 17 00:00:00 2001
From: graham <graham.macpherson@strath.ac.uk>
Date: Fri, 3 Oct 2008 19:22:57 +0100
Subject: [PATCH] Fixed small logic error in smoothEdges that meant that point
 groups at the start and end of the edge weren't handled properly.  Changed
 from compiling with FULLDEBUG.  Using the exact kernel because dualisation
 was causing CGAL to fail an assertion.  Going to examine the failing tets and
 try to check and intervene if possible so the inexact kernel can be used
 again.

---
 .../mesh/generation/CV3DMesher/CV3D.H         |  2 +-
 .../mesh/generation/CV3DMesher/Make/options   |  3 +-
 .../insertSurfaceNearestPointPairs.C          | 71 ++++++++++++++-----
 3 files changed, 56 insertions(+), 20 deletions(-)

diff --git a/applications/utilities/mesh/generation/CV3DMesher/CV3D.H b/applications/utilities/mesh/generation/CV3DMesher/CV3D.H
index 041e1e37145..784cf8db926 100644
--- a/applications/utilities/mesh/generation/CV3DMesher/CV3D.H
+++ b/applications/utilities/mesh/generation/CV3DMesher/CV3D.H
@@ -43,7 +43,7 @@ SourceFiles
 #ifndef CV3D_H
 #define CV3D_H
 
-#define CGAL_INEXACT
+//#define CGAL_INEXACT
 #define CGAL_HIERARCHY
 
 #include "CGALTriangulation3Ddefs.H"
diff --git a/applications/utilities/mesh/generation/CV3DMesher/Make/options b/applications/utilities/mesh/generation/CV3DMesher/Make/options
index ce0b8ecfec7..9042e2e9a51 100644
--- a/applications/utilities/mesh/generation/CV3DMesher/Make/options
+++ b/applications/utilities/mesh/generation/CV3DMesher/Make/options
@@ -1,5 +1,4 @@
-EXE_DEBUG = -DFULLDEBUG -g -O0
-//EXE_DEBUG = 
+//EXE_DEBUG = -DFULLDEBUG -g -O0
 
 include $(GENERAL_RULES)/CGAL
 FFLAGS = -DCGAL_FILES='"${CGAL_PATH}/CGAL/files"'
diff --git a/applications/utilities/mesh/generation/CV3DMesher/insertSurfaceNearestPointPairs.C b/applications/utilities/mesh/generation/CV3DMesher/insertSurfaceNearestPointPairs.C
index c9954dc55bc..730daa84052 100644
--- a/applications/utilities/mesh/generation/CV3DMesher/insertSurfaceNearestPointPairs.C
+++ b/applications/utilities/mesh/generation/CV3DMesher/insertSurfaceNearestPointPairs.C
@@ -286,6 +286,7 @@ void Foam::CV3D::smoothEdge
     // 3: adjust the spacing of remaining points on a pair by pair basis to
     //    remove excess points and add points to long uncontrolled spans.
 
+
     const edge& e(edges[edgeI]);
 
     const point& eStart(localPts[e.start()]);
@@ -328,7 +329,7 @@ void Foam::CV3D::smoothEdge
                 tempEdgePoints.append
                 (
                     eStart + (edgePoint - eStart)
-                        * tols_.featurePointGuard/edgeDist
+                    * tols_.featurePointGuard/edgeDist
                 );
 
                 startGuardPlaced = true;
@@ -350,7 +351,7 @@ void Foam::CV3D::smoothEdge
             else if
             (
                 edgeDist > tols_.featurePointGuard
-                && edgeDist < (edgeLength - tols_.featurePointGuard)
+             && edgeDist < (edgeLength - tols_.featurePointGuard)
             )
             {
                 tempEdgePoints.append(edgePoint);
@@ -377,15 +378,37 @@ void Foam::CV3D::smoothEdge
 
         point newEdgePoint(vector::zero);
 
-        if (edgePoints.size() == 1)
-        {
-            tempEdgePoints.append(edgePoints[0]);
+        // if (edgePoints.size() == 1)
+        // {
+        //     tempEdgePoints.append(edgePoints[0]);
+        // }
+        // else if
+        // (
+        //     (edgeDistances[1] - edgeDistances[0]) > tols_.edgeGroupSpacing
+        // )
+        // {
+        //     tempEdgePoints.append(edgePoints[0]);
+        // }
+
+        if (edgePoints.size() > 1)
+        {
+            if ((edgeDistances[1] - edgeDistances[0]) < tols_.edgeGroupSpacing)
+            {
+                // ...the first two points on the edge start a group
+
+                newEdgePoint += edgePoints[0];
+
+                groupSize++;
+            }
+            else
+            {
+                tempEdgePoints.append(edgePoints[0]);
+            }
         }
-        else if
-        (
-            (edgeDistances[1] - edgeDistances[0]) > tols_.edgeGroupSpacing
-        )
+        else
         {
+            // ...add the first point by default
+
             tempEdgePoints.append(edgePoints[0]);
         }
 
@@ -418,6 +441,16 @@ void Foam::CV3D::smoothEdge
             }
         }
 
+        if (groupSize > 0)
+        {
+            // A point group has been formed at the end of the edge and needs to
+            // be finished.
+
+            newEdgePoint /= groupSize;
+
+            tempEdgePoints.append(newEdgePoint);
+        }
+
         edgePoints.transfer(tempEdgePoints.shrink());
     }
 
@@ -794,7 +827,8 @@ void Foam::CV3D::insertSurfaceNearestPointPairs()
 
         for
         (
-            Triangulation::Finite_vertices_iterator vit = finite_vertices_begin();
+            Triangulation::Finite_vertices_iterator vit =
+            finite_vertices_begin();
             vit != finite_vertices_end();
             vit++
         )
@@ -852,14 +886,17 @@ void Foam::CV3D::insertSurfaceNearestPointPairs()
         edgePoints.shrink();
         edgeLabels.shrink();
 
-        smoothEdgePositions(edgePoints, edgeLabels);
+        if (edgePoints.size())
+        {
+            smoothEdgePositions(edgePoints, edgeLabels);
 
-        insertEdgePointGroups
-        (
-            edgePoints,
-            edgeLabels,
-            "surfaceNearestEdgePoints.obj"
-        );
+            insertEdgePointGroups
+            (
+                edgePoints,
+                edgeLabels,
+                "surfaceNearestEdgePoints.obj"
+            );
+        }
     }
 
     DynamicList<point> allNearSurfacePoints(nSurfacePointsEst);
-- 
GitLab