[cig-commits] r14072 - cs/cigma/trunk/src
luis at geodynamics.org
luis at geodynamics.org
Wed Feb 18 08:14:17 PST 2009
Author: luis
Date: 2009-02-18 08:14:17 -0800 (Wed, 18 Feb 2009)
New Revision: 14072
Added:
cs/cigma/trunk/src/loc_bbox.cpp
cs/cigma/trunk/src/loc_bbox.h
Removed:
cs/cigma/trunk/src/AnnLocator.cpp
cs/cigma/trunk/src/AnnLocator.h
Log:
Moved AnnLocator code to BoundingBoxLocator
Deleted: cs/cigma/trunk/src/AnnLocator.cpp
===================================================================
--- cs/cigma/trunk/src/AnnLocator.cpp 2009-02-18 16:14:14 UTC (rev 14071)
+++ cs/cigma/trunk/src/AnnLocator.cpp 2009-02-18 16:14:17 UTC (rev 14072)
@@ -1,117 +0,0 @@
-#include "AnnLocator.h"
-#include <cassert>
-#include <iostream>
-#include <boost/shared_ptr.hpp>
-
-using namespace cigma;
-using boost::shared_ptr;
-
-AnnLocator::AnnLocator()
-{
- //std::cout << "Calling AnnLocator()" << std::endl;
- nnk = 8;
- epsilon = 0;
-
- npts = 0;
- ndim = 0;
- ndim2 = 0;
-
- dataPoints = 0;
- kdtree = 0;
-
- nnIdx = 0;
- nnDists = 0;
-
- // Indicate that object is not initialized
- this->locatorType = AnnLocator::NONE_TYPE;
-}
-
-AnnLocator::~AnnLocator()
-{
- //std::cout << "Calling ~AnnLocator()" << std::endl;
- if (kdtree != 0)
- {
- delete kdtree;
- kdtree = 0;
- }
-
- if (dataPoints != 0)
- {
- annDeallocPts(dataPoints);
- dataPoints = 0;
- }
-
- if (nnIdx != 0)
- {
- delete [] nnIdx;
- nnIdx = 0;
- }
-
- if (nnDists != 0)
- {
- delete [] nnDists;
- nnDists = 0;
- }
-}
-
-void AnnLocator::init(const MeshPart& mesh)
-{
- TRI_LOG_STR("AnnLocator::init()");
- assert(nnk > 0);
-
- npts = mesh.connect->n_cells();
- ndim = mesh.coords->n_dim();
- ndim2 = ndim * 2;
-
- assert(npts > 0);
- assert(ndim > 0);
-
- dataPoints = annAllocPts(npts, ndim2);
- queryPoint = annAllocPt(ndim2);
-
- nnIdx = new ANNidx[nnk];
- nnDists = new ANNdist[nnk];
-
- int i,j;
- double minpt[ndim];
- double maxpt[ndim];
-
- //boost::shared_ptr<Cell> cell = Cell::New(mesh.cell->cell_type());
- shared_ptr<Cell> cell = Cell::New(mesh.cell_type);
- assert(cell->cell_type() != Cell::NONE);
-
- for (i = 0; i < npts; i++)
- {
- ANNpoint pt = dataPoints[i];
- mesh.getCell(i, *cell);
- cell->bbox(minpt, maxpt);
- for (j = 0; j < ndim; j++)
- {
- pt[ndim*0 + j] = minpt[j];
- pt[ndim*1 + j] = maxpt[j];
- }
- }
-
- kdtree = new ANNkd_tree(dataPoints, npts, ndim2);
-
- this->locatorType = AnnLocator::CELL_TYPE;
-}
-
-void AnnLocator::searchBoundingBox(double *bbox)
-{
- for (int i = 0; i < ndim; i++)
- {
- queryPoint[ndim*0 + i] = bbox[i];
- queryPoint[ndim*1 + i] = bbox[i];
- }
- kdtree->annkSearch(queryPoint, nnk, nnIdx, nnDists, epsilon);
-}
-
-void AnnLocator::searchPoint(double *point)
-{
- for (int i = 0; i < ndim; i++)
- {
- queryPoint[i] = point[i];
- }
-}
-
Deleted: cs/cigma/trunk/src/AnnLocator.h
===================================================================
--- cs/cigma/trunk/src/AnnLocator.h 2009-02-18 16:14:14 UTC (rev 14071)
+++ cs/cigma/trunk/src/AnnLocator.h 2009-02-18 16:14:17 UTC (rev 14072)
@@ -1,76 +0,0 @@
-#ifndef __CIGMA_ANN_LOCATOR_H__
-#define __CIGMA_ANN_LOCATOR_H__
-
-#include <cassert>
-#include "Locator.h"
-#include "MeshPart.h"
-//#include "Points.h"
-#include "ANN/ANN.h"
-
-namespace cigma
-{
- class AnnLocator;
-}
-
-class cigma::AnnLocator : public cigma::Locator
-{
-public:
-
- AnnLocator();
- ~AnnLocator();
-
- void init(const MeshPart& mesh);
- //void init(const Points& points);
-
- void searchBoundingBox(double *bbox);
- void searchPoint(double *point);
-
- int n_dim() const;
- int n_idx() const;
- int idx(int i) const;
-
-public:
- int nnk; /// number of nearest neighbors
- int npts; /// number of "points" (bounding boxes)
- int ndim; /// dimension of single point
- int ndim2; /// dimension of bounding box (ndim * 2)
- double epsilon; /// tolerance (in bbox space)
-
- typedef enum {
- NONE_TYPE,
- POINT_TYPE,
- CELL_TYPE
- } AnnLocatorType;
-
- AnnLocatorType locatorType;
-
-private:
- ANNpointArray dataPoints; // XXX: can we reuse the data in nc_array directly?
- ANNkd_tree *kdtree;
-
- ANNpoint queryPoint; /// query point for search routine
- ANNidxArray nnIdx; /// near neighbor indices
- ANNdistArray nnDists; /// near neighbor distances
-};
-
-// ----------------------------------------------------------------------------
-
-inline int cigma::AnnLocator::n_dim() const
-{
- return ndim;
-}
-
-inline int cigma::AnnLocator::n_idx() const
-{
- return nnk;
-}
-
-inline int cigma::AnnLocator::idx(int i) const
-{
- //assert((0 <= i) && (i < nnk));
- return nnIdx[i];
-}
-
-// ----------------------------------------------------------------------------
-
-#endif
Copied: cs/cigma/trunk/src/loc_bbox.cpp (from rev 14071, cs/cigma/trunk/src/AnnLocator.cpp)
===================================================================
--- cs/cigma/trunk/src/loc_bbox.cpp (rev 0)
+++ cs/cigma/trunk/src/loc_bbox.cpp 2009-02-18 16:14:17 UTC (rev 14072)
@@ -0,0 +1,146 @@
+#include "loc_bbox.h"
+#include "tri_logger.hpp"
+#include <cassert>
+#include <iostream>
+#include <boost/shared_ptr.hpp>
+
+using namespace cigma;
+using boost::shared_ptr;
+
+BoundingBoxLocator::BoundingBoxLocator()
+{
+ TRI_LOG_STR("BoundingBoxLocator::BoundingBoxLocator()");
+
+ //nnk = 8;
+ nnk = 10;
+ //nnk = 20;
+
+ epsilon = 0;
+
+ npts = 0;
+ ndim = 0;
+ ndim2 = 0;
+
+ dataPoints = 0;
+ kdtree = 0;
+
+ queryPoint = 0;
+ nnIdx = 0;
+ nnDists = 0;
+
+ // Object is not initialized yet...
+ // Owner needs to call init() method
+}
+
+BoundingBoxLocator::~BoundingBoxLocator()
+{
+ TRI_LOG_STR("BoundingBoxLocator::~BoundingBoxLocator()");
+
+ if (kdtree != 0)
+ {
+ delete kdtree;
+ kdtree = 0;
+ }
+
+ if (dataPoints != 0)
+ {
+ annDeallocPts(dataPoints);
+ dataPoints = 0;
+ }
+
+ if (queryPoint != 0)
+ {
+ annDeallocPt(queryPoint);
+ queryPoint = 0;
+ }
+
+ if (nnIdx != 0)
+ {
+ delete [] nnIdx;
+ nnIdx = 0;
+ }
+
+ if (nnDists != 0)
+ {
+ delete [] nnDists;
+ nnDists = 0;
+ }
+}
+
+void BoundingBoxLocator::init(const MeshPart& mesh)
+{
+ TRI_LOG_STR("BoundingBoxLocator::init()");
+
+ npts = mesh.connect->n_cells();
+ ndim = mesh.coords->n_dim();
+ //ndim2 = ndim * 2;
+ ndim2 = 6;
+
+ assert(npts > 0);
+ assert(ndim > 0);
+ assert((ndim == 3) || (ndim == 2));
+
+ dataPoints = annAllocPts(npts, ndim2);
+ queryPoint = annAllocPt(ndim2);
+
+ assert(nnk > 0);
+ nnIdx = new ANNidx[nnk];
+ nnDists = new ANNdist[nnk];
+
+ int i,j;
+ double minpt[ndim];
+ double maxpt[ndim];
+
+ shared_ptr<Cell> cell = mesh.getCell();
+ assert(cell->cell_type() != Cell::NONE);
+
+ for (i = 0; i < npts; i++)
+ {
+ ANNpoint pt = dataPoints[i];
+ mesh.getCell(i, *cell);
+ cell->bbox(minpt, maxpt);
+
+ /*
+ for (j = 0; j < ndim; j++)
+ {
+ pt[ndim*0 + j] = minpt[j];
+ pt[ndim*1 + j] = maxpt[j];
+ } // */
+
+ pt[0] = minpt[0];
+ pt[1] = minpt[1];
+ pt[2] = (ndim == 3) ? minpt[2] : 1.0;
+
+ pt[3] = maxpt[0];
+ pt[4] = maxpt[1];
+ pt[5] = (ndim == 3) ? maxpt[2] : 1.0;
+ }
+
+ kdtree = new ANNkd_tree(dataPoints, npts, ndim2);
+
+ TRI_LOG(npts);
+ TRI_LOG(ndim);
+ TRI_LOG(nnk);
+ TRI_LOG(epsilon);
+}
+
+void BoundingBoxLocator::search(double *point)
+{
+ /*
+ for (int i = 0; i < ndim; i++)
+ {
+ queryPoint[ndim*0 + i] = bbox[i];
+ queryPoint[ndim*1 + i] = bbox[i];
+ } // */
+
+ queryPoint[0] = point[0];
+ queryPoint[1] = point[1];
+ queryPoint[2] = (ndim == 3) ? point[2] : 1.0;
+
+ queryPoint[3] = point[0];
+ queryPoint[4] = point[1];
+ queryPoint[5] = (ndim == 3) ? point[2] : 1.0;
+
+ kdtree->annkSearch(queryPoint, nnk, nnIdx, nnDists, epsilon);
+}
+
Copied: cs/cigma/trunk/src/loc_bbox.h (from rev 14071, cs/cigma/trunk/src/AnnLocator.h)
===================================================================
--- cs/cigma/trunk/src/loc_bbox.h (rev 0)
+++ cs/cigma/trunk/src/loc_bbox.h 2009-02-18 16:14:17 UTC (rev 14072)
@@ -0,0 +1,65 @@
+#ifndef CIGMA_BOUNDING_BOX_LOCATOR_H
+#define CIGMA_BOUNDING_BOX_LOCATOR_H
+
+#include "Locator.h"
+#include "MeshPart.h"
+#include "ANN/ANN.h"
+
+namespace cigma
+{
+ class BoundingBoxLocator;
+}
+
+class cigma::BoundingBoxLocator : public cigma::Locator
+{
+public:
+ BoundingBoxLocator();
+ ~BoundingBoxLocator();
+ LocatorType getType() const { return BoundingBoxType; }
+
+ void init(const MeshPart& mesh);
+
+ int n_dim() const;
+ void search(double *point);
+
+ int n_idx() const;
+ int idx(int i) const;
+
+
+public:
+ int nnk; /// number of nearest neighbors
+ 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
+ ANNidxArray nnIdx; /// near neighbor indices
+ ANNdistArray nnDists; /// near neighbor distances
+};
+
+// ----------------------------------------------------------------------------
+
+inline int cigma::BoundingBoxLocator::n_dim() const
+{
+ return ndim;
+}
+
+inline int cigma::BoundingBoxLocator::n_idx() const
+{
+ return nnk;
+}
+
+inline int cigma::BoundingBoxLocator::idx(int i) const
+{
+ //cigma_assert((0 <= i) && (i < nnk));
+ return nnIdx[i];
+}
+
+// ----------------------------------------------------------------------------
+
+#endif
More information about the CIG-COMMITS
mailing list