[cig-commits] r14094 - in cs/cigma/trunk: src tests/libcigma
luis at geodynamics.org
luis at geodynamics.org
Wed Feb 18 08:14:59 PST 2009
Author: luis
Date: 2009-02-18 08:14:58 -0800 (Wed, 18 Feb 2009)
New Revision: 14094
Modified:
cs/cigma/trunk/src/Locator.cpp
cs/cigma/trunk/src/Locator.h
cs/cigma/trunk/src/MeshPart.cpp
cs/cigma/trunk/src/core_readers.cpp
cs/cigma/trunk/src/io_hdf5_reader.cpp
cs/cigma/trunk/src/io_vtk_reader.cpp
cs/cigma/trunk/src/loc_bbox.cpp
cs/cigma/trunk/src/loc_bbox.h
cs/cigma/trunk/src/loc_kdtree.cpp
cs/cigma/trunk/src/loc_kdtree.h
cs/cigma/trunk/tests/libcigma/LocatorTest.cpp
Log:
Updated Locator interface.
This change should allow us to dynamically alter the size of the
search list (number of nearest neighbors to search).
Modified: cs/cigma/trunk/src/Locator.cpp
===================================================================
--- cs/cigma/trunk/src/Locator.cpp 2009-02-18 16:14:54 UTC (rev 14093)
+++ cs/cigma/trunk/src/Locator.cpp 2009-02-18 16:14:58 UTC (rev 14094)
@@ -1,8 +1,40 @@
#include "Locator.h"
#include "tri_logger.hpp"
+#include "loc_bbox.h"
+#include "loc_kdtree.h"
+using namespace std;
using namespace cigma;
+Locator::LocatorType Locator::string2type(const string& name)
+{
+ if (name == "bbox")
+ {
+ return Locator::BoundingBoxType;
+ }
+ else if (name == "kdtree")
+ {
+ return Locator::KdtreeType;
+ }
+ return Locator::BruteForceType;
+}
+
+boost::shared_ptr<Locator> Locator::New(Locator::LocatorType loc_type)
+{
+ boost::shared_ptr<Locator> loc;
+ switch (loc_type)
+ {
+ case Locator::BoundingBoxType:
+ loc.reset(new BoundingBoxLocator);
+ break;
+
+ case Locator::KdtreeType:
+ loc.reset(new KdtreeLocator);
+ break;
+ }
+ return loc;
+}
+
Locator::Locator()
{
TRI_LOG_STR("Locator::Locator()");
Modified: cs/cigma/trunk/src/Locator.h
===================================================================
--- cs/cigma/trunk/src/Locator.h 2009-02-18 16:14:54 UTC (rev 14093)
+++ cs/cigma/trunk/src/Locator.h 2009-02-18 16:14:58 UTC (rev 14094)
@@ -1,9 +1,12 @@
#ifndef CIGMA_LOCATOR_H
#define CIGMA_LOCATOR_H
+#include <boost/shared_ptr.hpp>
+
namespace cigma
{
class Locator;
+ class MeshPart;
}
class cigma::Locator
@@ -12,12 +15,15 @@
Locator();
virtual ~Locator();
- virtual int n_dim() const = 0;
- virtual void search(double *point) = 0;
+ virtual void init(MeshPart& mesh) = 0;
+ virtual void setMaxNeighbors(int k) = 0;
virtual int n_idx() const = 0;
virtual int idx(int i) const = 0;
+ virtual int n_dim() const = 0;
+ virtual void search(double *point) = 0;
+
enum LocatorType {
BruteForceType,
BoundingBoxType,
@@ -27,6 +33,11 @@
};
virtual LocatorType getType() const = 0;
+ static LocatorType string2type(const std::string& name);
+
+ /* static factory method */
+ static boost::shared_ptr<Locator> New(LocatorType loc_type);
+
};
#endif
Modified: cs/cigma/trunk/src/MeshPart.cpp
===================================================================
--- cs/cigma/trunk/src/MeshPart.cpp 2009-02-18 16:14:54 UTC (rev 14093)
+++ cs/cigma/trunk/src/MeshPart.cpp 2009-02-18 16:14:58 UTC (rev 14094)
@@ -53,8 +53,8 @@
void MeshPart::setLocator(const shared_ptr<Locator>& loc)
{
assert(loc);
- assert(loc->n_dim() > 0);
- this->locator = loc;
+ locator = loc;
+ locator->init(*this);
}
void MeshPart::setLocator()
@@ -63,20 +63,18 @@
const int ncells = this->n_cells();
if (ndim == 3)
{
- if (ncells > BoundingBoxLocator::nnk)
+ if (ncells > BoundingBoxLocator::default_nnk)
{
- shared_ptr<BoundingBoxLocator> loc(new BoundingBoxLocator);
- loc->init(*this);
- this->locator = loc;
+ locator = Locator::New(Locator::BoundingBoxType);
+ locator->init(*this);
}
}
else
{
- if (ncells > KdtreeLocator::nnk)
+ if (ncells > KdtreeLocator::default_nnk)
{
- shared_ptr<KdtreeLocator> loc(new KdtreeLocator);
- loc->init(*this);
- this->locator = loc;
+ locator = Locator::New(Locator::KdtreeType);
+ locator->init(*this);
}
}
}
Modified: cs/cigma/trunk/src/core_readers.cpp
===================================================================
--- cs/cigma/trunk/src/core_readers.cpp 2009-02-18 16:14:54 UTC (rev 14093)
+++ cs/cigma/trunk/src/core_readers.cpp 2009-02-18 16:14:58 UTC (rev 14094)
@@ -175,15 +175,6 @@
if (mesh && mesh_info.use_locator)
{
mesh->setLocator();
-
- //if (mesh->n_cells() > KdtreeLocator::nnk)
- //{
- // // XXX: is there a better way to initialize? inheritance on MeshPart perhaps?
- // //shared_ptr<BoundingBoxLocator> locator(new BoundingBoxLocator);
- // shared_ptr<KdtreeLocator> locator(new KdtreeLocator);
- // locator->init(*mesh);
- // mesh->setLocator(locator);
- //}
}
return mesh;
Modified: cs/cigma/trunk/src/io_hdf5_reader.cpp
===================================================================
--- cs/cigma/trunk/src/io_hdf5_reader.cpp 2009-02-18 16:14:54 UTC (rev 14093)
+++ cs/cigma/trunk/src/io_hdf5_reader.cpp 2009-02-18 16:14:58 UTC (rev 14094)
@@ -239,18 +239,6 @@
}
mesh->setLocator();
-
- //if (true)
- //{
- // if (mesh->n_cells() > KdtreeLocator::nnk)
- // {
- // // XXX: move this to a method in MeshPart
- // //shared_ptr<BoundingBoxLocator> locator(new BoundingBoxLocator);
- // shared_ptr<KdtreeLocator> locator(new KdtreeLocator);
- // locator->init(*mesh);
- // mesh->setLocator(locator);
- // }
- //}
}
else
{
Modified: cs/cigma/trunk/src/io_vtk_reader.cpp
===================================================================
--- cs/cigma/trunk/src/io_vtk_reader.cpp 2009-02-18 16:14:54 UTC (rev 14093)
+++ cs/cigma/trunk/src/io_vtk_reader.cpp 2009-02-18 16:14:58 UTC (rev 14094)
@@ -289,18 +289,6 @@
mesh->setLocator();
- // XXX: move following block to a method in MeshPart
- //if (true)
- //{
- // if (mesh->n_cells() > KdtreeLocator::nnk)
- // {
- // //shared_ptr<BoundingBoxLocator> locator(new BoundingBoxLocator);
- // shared_ptr<KdtreeLocator> locator(new KdtreeLocator);
- // locator->init(*mesh);
- // mesh->setLocator(locator);
- // }
- //}
-
return mesh;
}
Modified: cs/cigma/trunk/src/loc_bbox.cpp
===================================================================
--- cs/cigma/trunk/src/loc_bbox.cpp 2009-02-18 16:14:54 UTC (rev 14093)
+++ cs/cigma/trunk/src/loc_bbox.cpp 2009-02-18 16:14:58 UTC (rev 14094)
@@ -7,15 +7,12 @@
using namespace cigma;
using boost::shared_ptr;
-int BoundingBoxLocator::nnk = 10;
+int BoundingBoxLocator::default_nnk = 10;
BoundingBoxLocator::BoundingBoxLocator()
{
TRI_LOG_STR("BoundingBoxLocator::BoundingBoxLocator()");
- //nnk = 8;
- //nnk = 20;
-
epsilon = 0;
npts = 0;
@@ -26,6 +23,7 @@
kdtree = 0;
queryPoint = 0;
+ nnk = BoundingBoxLocator::default_nnk;
nnIdx = 0;
nnDists = 0;
@@ -68,7 +66,7 @@
}
}
-void BoundingBoxLocator::init(const MeshPart& mesh)
+void BoundingBoxLocator::init(MeshPart& mesh)
{
TRI_LOG_STR("BoundingBoxLocator::init()");
@@ -84,9 +82,7 @@
dataPoints = annAllocPts(npts, ndim2);
queryPoint = annAllocPt(ndim2);
- assert(nnk > 0);
- nnIdx = new ANNidx[nnk];
- nnDists = new ANNdist[nnk];
+ this->setMaxNeighbors(BoundingBoxLocator::default_nnk);
int i,j;
double minpt[ndim];
@@ -125,6 +121,18 @@
TRI_LOG(epsilon);
}
+void BoundingBoxLocator::setMaxNeighbors(int k)
+{
+ assert(k > 0);
+
+ if (nnIdx != 0) { delete [] nnIdx; }
+ if (nnDists != 0) { delete [] nnDists; }
+
+ nnk = k;
+ nnIdx = new ANNidx[nnk];
+ nnDists = new ANNdist[nnk];
+}
+
void BoundingBoxLocator::search(double *point)
{
/*
Modified: cs/cigma/trunk/src/loc_bbox.h
===================================================================
--- cs/cigma/trunk/src/loc_bbox.h 2009-02-18 16:14:54 UTC (rev 14093)
+++ cs/cigma/trunk/src/loc_bbox.h 2009-02-18 16:14:58 UTC (rev 14094)
@@ -17,28 +17,32 @@
~BoundingBoxLocator();
LocatorType getType() const { return BoundingBoxType; }
- void init(const MeshPart& mesh);
+ void init(MeshPart& mesh);
+ void setMaxNeighbors(int k);
- int n_dim() const;
- void search(double *point);
int n_idx() const;
int idx(int i) const;
+ int n_dim() const;
+ void search(double *point);
+
public:
- static int nnk; /// number of nearest neighbors
+ static int default_nnk;
private:
- int npts; /// number of "points" (bounding boxes)
- int ndim; /// dimension of single point
- int ndim2; /// dimension of bounding box
- double epsilon; /// tolerance (in bbox space)
+ int npts; /// number of "points" (bounding boxes)
+ int ndim; /// dimension of single point
+ int ndim2; /// dimension of bounding box
+ double epsilon; /// tolerance (in bbox space)
private:
ANNpointArray dataPoints; // XXX: can we reuse the data in nc_array directly?
ANNkd_tree *kdtree;
+ ANNpoint queryPoint; /// query point for search routine
- ANNpoint queryPoint; /// query point for search routine
+private:
+ int nnk; /// number of nearest neighbors
ANNidxArray nnIdx; /// near neighbor indices
ANNdistArray nnDists; /// near neighbor distances
};
Modified: cs/cigma/trunk/src/loc_kdtree.cpp
===================================================================
--- cs/cigma/trunk/src/loc_kdtree.cpp 2009-02-18 16:14:54 UTC (rev 14093)
+++ cs/cigma/trunk/src/loc_kdtree.cpp 2009-02-18 16:14:58 UTC (rev 14094)
@@ -7,7 +7,7 @@
using namespace cigma;
using boost::shared_ptr;
-int KdtreeLocator::nnk = 10;
+int KdtreeLocator::default_nnk = 10;
KdtreeLocator::KdtreeLocator()
{
@@ -21,7 +21,7 @@
queryPoint = 0;
searchRadius = 0;
- //nnk = 8;
+ nnk = KdtreeLocator::default_nnk;
nnIdx = 0;
nnDists = 0;
}
@@ -63,6 +63,8 @@
dataPoints = annAllocPts(npts, ndim);
queryPoint = annAllocPt(ndim);
+ this->setMaxNeighbors(KdtreeLocator::default_nnk);
+
if (mesh.centroid.size() == 0)
{
mesh.computeCellCentroids();
@@ -79,9 +81,6 @@
kdtree = new ANNkd_tree(dataPoints, npts, ndim);
- nnIdx.resize(nnk);
- nnDists.resize(nnk);
-
searchRadius = 3 * mesh.getMaxCellDiameter();
TRI_LOG(npts);
@@ -90,6 +89,14 @@
TRI_LOG(searchRadius);
}
+void KdtreeLocator::setMaxNeighbors(int k)
+{
+ assert(k > 0);
+ nnk = k;
+ nnIdx.resize(nnk);
+ nnDists.resize(nnk);
+}
+
void KdtreeLocator::search(double *point)
{
for (int j = 0; j < ndim; j++)
Modified: cs/cigma/trunk/src/loc_kdtree.h
===================================================================
--- cs/cigma/trunk/src/loc_kdtree.h 2009-02-18 16:14:54 UTC (rev 14093)
+++ cs/cigma/trunk/src/loc_kdtree.h 2009-02-18 16:14:58 UTC (rev 14094)
@@ -19,6 +19,7 @@
LocatorType getType() const { return Locator::KdtreeType; }
void init(MeshPart& mesh);
+ void setMaxNeighbors(int k);
int n_dim() const;
void search(double *point);
@@ -27,7 +28,7 @@
int idx(int i) const;
public:
- static int nnk; /// number of nearest neighbors
+ static int default_nnk;
private:
int npts; /// number of points
@@ -41,6 +42,7 @@
ANNpoint queryPoint; /// query point for search routine
public:
+ int nnk; /// number of nearest neighbors
std::valarray<ANNidx> nnIdx; /// near neighbor indices
std::valarray<ANNdist> nnDists; /// near neighbor distances
};
Modified: cs/cigma/trunk/tests/libcigma/LocatorTest.cpp
===================================================================
--- cs/cigma/trunk/tests/libcigma/LocatorTest.cpp 2009-02-18 16:14:54 UTC (rev 14093)
+++ cs/cigma/trunk/tests/libcigma/LocatorTest.cpp 2009-02-18 16:14:58 UTC (rev 14094)
@@ -42,14 +42,11 @@
// Initialize Locator
//
shared_ptr<BoundingBoxLocator> locator(new BoundingBoxLocator);
- locator->init(*mesh);
-
-
- //
- // Finish mesh initialization
- // XXX: is there a better way? perhaps inheritance..
- //
mesh->setLocator(locator);
+ if (mesh->locator)
+ {
+ mesh->locator->setMaxNeighbors(8);
+ }
//
// Test locator
More information about the CIG-COMMITS
mailing list