[cig-commits] r9289 - cs/benchmark/cigma/trunk/src

luis at geodynamics.org luis at geodynamics.org
Wed Feb 13 01:51:08 PST 2008


Author: luis
Date: 2008-02-13 01:51:08 -0800 (Wed, 13 Feb 2008)
New Revision: 9289

Modified:
   cs/benchmark/cigma/trunk/src/Points.cpp
   cs/benchmark/cigma/trunk/src/Points.h
Log:
Use locator to find the nearest point contained in Points instance

Modified: cs/benchmark/cigma/trunk/src/Points.cpp
===================================================================
--- cs/benchmark/cigma/trunk/src/Points.cpp	2008-02-13 09:51:06 UTC (rev 9288)
+++ cs/benchmark/cigma/trunk/src/Points.cpp	2008-02-13 09:51:08 UTC (rev 9289)
@@ -1,4 +1,5 @@
 #include "Points.h"
+#include <limits>
 
 // ---------------------------------------------------------------------------
 
@@ -31,3 +32,54 @@
 
 
 // ---------------------------------------------------------------------------
+
+bool cigma::Points::find_ann_index(double *globalPoint, int *annIndex)
+{
+
+    *annIndex = -1;
+
+    if (locator != 0)
+    {
+        locator->search(globalPoint);
+        *annIndex = locator->idx(0);
+        return true;
+    }
+
+    /* Calculate distance to each point one-by-one? */
+    int i,j;
+    double r2 = 0;
+
+    int i_min;
+    double r2_min;
+
+    i_min = -1;
+    r2_min = std::numeric_limits<double>::infinity();
+    for (i = 0; i < num; i++)
+    {
+        double *pt = &data[dim*i];
+
+        r2 = 0;
+        for (j = 0; j < dim; j++)
+        {
+            double dx[dim];
+            dx[j] = globalPoint[j] - pt[j];
+            r2 += dx[j] * dx[j];
+        }
+
+        if (r2 < r2_min)
+        {
+            i_min = i;
+            r2_min = r2;
+        }
+    }
+    if (i_min < 0)
+    {
+        return false;
+    }
+
+    *annIndex = i_min;
+    return true;
+}
+
+
+// ---------------------------------------------------------------------------

Modified: cs/benchmark/cigma/trunk/src/Points.h
===================================================================
--- cs/benchmark/cigma/trunk/src/Points.h	2008-02-13 09:51:06 UTC (rev 9288)
+++ cs/benchmark/cigma/trunk/src/Points.h	2008-02-13 09:51:08 UTC (rev 9289)
@@ -40,6 +40,7 @@
 
 public:
     Locator *locator;
+    bool find_ann_index(double *globalPoint, int *annIndex);
 };
 
 // ---------------------------------------------------------------------------



More information about the cig-commits mailing list