[cig-commits] r13181 - in cs/cigma/trunk: . src tests tests/libcigma
luis at geodynamics.org
luis at geodynamics.org
Wed Oct 29 15:12:04 PDT 2008
Author: luis
Date: 2008-10-29 15:12:03 -0700 (Wed, 29 Oct 2008)
New Revision: 13181
Added:
cs/cigma/trunk/tests/libcigma/LocatorTest.cpp
cs/cigma/trunk/tests/libcigma/LocatorTest.h
Modified:
cs/cigma/trunk/Makefile.am
cs/cigma/trunk/src/AnnLocator.cpp
cs/cigma/trunk/src/AnnLocator.h
cs/cigma/trunk/src/Locator.h
cs/cigma/trunk/src/py_Locator.cpp
cs/cigma/trunk/src/py_Locator.h
cs/cigma/trunk/src/py_cigma_setup.py
cs/cigma/trunk/tests/test_registry.cpp
Log:
Updates to cigma::AnnLocator
Added initialization routine when given a mesh. Updated
python bindings, added a test fixture, and changed
makefile and setup.py script so they use the libann.a
static library.
Modified: cs/cigma/trunk/Makefile.am
===================================================================
--- cs/cigma/trunk/Makefile.am 2008-10-29 22:12:01 UTC (rev 13180)
+++ cs/cigma/trunk/Makefile.am 2008-10-29 22:12:03 UTC (rev 13181)
@@ -168,7 +168,7 @@
cigma_LDADD =
cigma_LDADD += libcigma.a
-#cigma_LDADD += libann.a
+cigma_LDADD += libann.a
#cigma_LDADD += $(HDF5_LIBS) -lhdf5_cpp # XXX: fix this flag
#cigma_LDADD += $(VTK_LIBS)
#cigma_LDADD += $(BOOST_FILESYSTEM_LIBS)
@@ -222,6 +222,7 @@
_cigma_so_LDADD =
_cigma_so_LDADD += libcigma.a
+_cigma_so_LDADD += libann.a
# XXX: add header files to this variable
_cigma_so_SOURCES = \
@@ -262,12 +263,14 @@
cigma_test_CXXFLAGS =
cigma_test_CXXFLAGS += @CPPUNIT_CFLAGS@
+cigma_test_CXXFLAGS += $(ANN_FLAGS)
cigma_test_CXXFLAGS += -I$(top_srcdir)/src
cigma_test_CXXFLAGS += -I$(top_srcdir)/tests
cigma_test_LDADD =
cigma_test_LDADD += @CPPUNIT_LIBS@
cigma_test_LDADD += libcigma.a
+cigma_test_LDADD += libann.a
cigma_test_LDADD += $(BOOST_FILESYSTEM_LIB)
cigma_test_SOURCES = \
@@ -287,6 +290,8 @@
tests/libcigma/ElementBlockTest.cpp \
tests/libcigma/MeshPartTest.h \
tests/libcigma/MeshPartTest.cpp \
+ tests/libcigma/LocatorTest.h \
+ tests/libcigma/LocatorTest.cpp \
tests/libcigma/DofHandlerTest.h \
tests/libcigma/DofHandlerTest.cpp \
tests/libcigma/FunctionTest.h \
Modified: cs/cigma/trunk/src/AnnLocator.cpp
===================================================================
--- cs/cigma/trunk/src/AnnLocator.cpp 2008-10-29 22:12:01 UTC (rev 13180)
+++ cs/cigma/trunk/src/AnnLocator.cpp 2008-10-29 22:12:03 UTC (rev 13181)
@@ -1,15 +1,13 @@
#include "AnnLocator.h"
#include <cassert>
#include <iostream>
+#include <boost/shared_ptr.hpp>
using namespace cigma;
-// ----------------------------------------------------------------------------
-
AnnLocator::AnnLocator()
{
- std::cout << "Calling AnnLocator()" << std::endl;
-
+ //std::cout << "Calling AnnLocator()" << std::endl;
nnk = 8;
epsilon = 0;
@@ -17,20 +15,19 @@
ndim = 0;
ndim2 = 0;
-/*
dataPoints = 0;
kdtree = 0;
nnIdx = 0;
nnDists = 0;
-*/
- locatorType = NONE_TYPE;
+
+ // Indicate that object is not initialized
+ this->locatorType = AnnLocator::NONE_TYPE;
}
AnnLocator::~AnnLocator()
{
- std::cout << "Calling ~AnnLocator()" << std::endl;
- /*
+ //std::cout << "Calling ~AnnLocator()" << std::endl;
if (kdtree != 0)
{
delete kdtree;
@@ -54,24 +51,65 @@
delete [] nnDists;
nnDists = 0;
}
- */
}
-// ----------------------------------------------------------------------------
+void AnnLocator::init(const MeshPart& mesh)
+{
+ assert(nnk > 0);
-//void AnnLocator::initialize(boost::shared_ptr<MeshPart>& meshPart) {}
+ npts = mesh.connect->n_cells();
+ ndim = mesh.coords->n_dim();
+ ndim2 = ndim * 2;
-//void AnnLocator::search_bbox(double *point)
+ 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());
+ assert(cell->cell_type() != Cell::NONE);
+
+ for (i = 0; i < npts; i++)
+ {
+ ANNpoint pt = dataPoints[i];
+ //mesh.selectCell(i); // XXX: use iterator
+ mesh.getCell(i, *cell);
+ mesh.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] = point[i];
- queryPoint[ndim*1 + i] = point[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];
+ }
+}
+
Modified: cs/cigma/trunk/src/AnnLocator.h
===================================================================
--- cs/cigma/trunk/src/AnnLocator.h 2008-10-29 22:12:01 UTC (rev 13180)
+++ cs/cigma/trunk/src/AnnLocator.h 2008-10-29 22:12:03 UTC (rev 13181)
@@ -1,8 +1,9 @@
#ifndef __CIGMA_ANN_LOCATOR_H__
#define __CIGMA_ANN_LOCATOR_H__
+#include <cassert>
#include "Locator.h"
-//#include "MeshPart.h"
+#include "MeshPart.h"
//#include "Points.h"
#include "ANN/ANN.h"
@@ -18,14 +19,11 @@
AnnLocator();
~AnnLocator();
- //void initialize(MeshPart *meshPart);
- //void initialize(Points *points);
-
- //void search_bbox(double *point);
- //void search_point(double *point);
+ void init(const MeshPart& mesh);
+ //void init(const Points& points);
- //void initialize(boost::shared_ptr<MeshPart>& meshPart);
void searchBoundingBox(double *bbox);
+ void searchPoint(double *point);
int n_dim() const;
int n_idx() const;
@@ -46,15 +44,13 @@
AnnLocatorType locatorType;
-/*
private:
- ANNpointArray dataPoints;
+ 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
-*/
};
// ----------------------------------------------------------------------------
@@ -71,10 +67,8 @@
inline int cigma::AnnLocator::idx(int i) const
{
- //assert(0 <= i);
- //assert(i < nnk);
- //return nnIdx[i];
- return 0; //XXX: FIXME!!
+ assert((0 <= i) && (i < nnk));
+ return nnIdx[i];
}
// ----------------------------------------------------------------------------
Modified: cs/cigma/trunk/src/Locator.h
===================================================================
--- cs/cigma/trunk/src/Locator.h 2008-10-29 22:12:01 UTC (rev 13180)
+++ cs/cigma/trunk/src/Locator.h 2008-10-29 22:12:03 UTC (rev 13181)
@@ -13,6 +13,7 @@
virtual ~Locator();
virtual void searchBoundingBox(double *bbox) = 0;
+ virtual void searchPoint(double *point) = 0;
virtual int n_dim() const = 0;
virtual int n_idx() const = 0;
Modified: cs/cigma/trunk/src/py_Locator.cpp
===================================================================
--- cs/cigma/trunk/src/py_Locator.cpp 2008-10-29 22:12:01 UTC (rev 13180)
+++ cs/cigma/trunk/src/py_Locator.cpp 2008-10-29 22:12:03 UTC (rev 13181)
@@ -23,6 +23,11 @@
this->get_override("searchBoundingBox")(bbox);
}
+void pyLocator::searchPoint(double *point)
+{
+ this->get_override("searchPoint")(point);
+}
+
/*
bool pyLocator::check_idx(int i) const
{
Modified: cs/cigma/trunk/src/py_Locator.h
===================================================================
--- cs/cigma/trunk/src/py_Locator.h 2008-10-29 22:12:01 UTC (rev 13180)
+++ cs/cigma/trunk/src/py_Locator.h 2008-10-29 22:12:03 UTC (rev 13181)
@@ -11,6 +11,7 @@
int n_idx() const;
int idx(int i) const;
void searchBoundingBox(double *bbox);
+ void searchPoint(double *point);
};
#endif
Modified: cs/cigma/trunk/src/py_cigma_setup.py
===================================================================
--- cs/cigma/trunk/src/py_cigma_setup.py 2008-10-29 22:12:01 UTC (rev 13180)
+++ cs/cigma/trunk/src/py_cigma_setup.py 2008-10-29 22:12:03 UTC (rev 13181)
@@ -44,6 +44,6 @@
Extension("_cigma", [('src/%s' % f) for f in sources],
define_macros=defines,
libraries=libs,
- extra_objects=['libcigma.a'])
+ extra_objects=['libcigma.a','libann.a'])
]
)
Added: cs/cigma/trunk/tests/libcigma/LocatorTest.cpp
===================================================================
--- cs/cigma/trunk/tests/libcigma/LocatorTest.cpp (rev 0)
+++ cs/cigma/trunk/tests/libcigma/LocatorTest.cpp 2008-10-29 22:12:03 UTC (rev 13181)
@@ -0,0 +1,14 @@
+#include "LocatorTest.h"
+using namespace libcigma;
+
+#include "AnnLocator.h"
+using namespace cigma;
+
+#include <boost/shared_ptr.hpp>
+using boost::shared_ptr;
+
+void LocatorTest::test_something()
+{
+ shared_ptr<AnnLocator> locator(new AnnLocator);
+}
+
Added: cs/cigma/trunk/tests/libcigma/LocatorTest.h
===================================================================
--- cs/cigma/trunk/tests/libcigma/LocatorTest.h (rev 0)
+++ cs/cigma/trunk/tests/libcigma/LocatorTest.h 2008-10-29 22:12:03 UTC (rev 13181)
@@ -0,0 +1,23 @@
+#ifndef __LOCATOR_TEST_H__
+#define __LOCATOR_TEST_H__
+
+#include <cppunit/TestFixture.h>
+#include <cppunit/extensions/HelperMacros.h>
+
+
+namespace libcigma
+{
+ class LocatorTest : public CPPUNIT_NS::TestFixture
+ {
+ CPPUNIT_TEST_SUITE(LocatorTest);
+ CPPUNIT_TEST(test_something);
+ CPPUNIT_TEST_SUITE_END();
+
+ public:
+ LocatorTest() {}
+ ~LocatorTest() {}
+ void test_something();
+ };
+};
+
+#endif
Modified: cs/cigma/trunk/tests/test_registry.cpp
===================================================================
--- cs/cigma/trunk/tests/test_registry.cpp 2008-10-29 22:12:01 UTC (rev 13180)
+++ cs/cigma/trunk/tests/test_registry.cpp 2008-10-29 22:12:03 UTC (rev 13181)
@@ -27,6 +27,9 @@
#include <libcigma/MeshPartTest.h>
CPPUNIT_TEST_SUITE_REGISTRATION(libcigma::MeshPartTest);
+#include <libcigma/LocatorTest.h>
+CPPUNIT_TEST_SUITE_REGISTRATION(libcigma::LocatorTest);
+
#include <libcigma/DofHandlerTest.h>
CPPUNIT_TEST_SUITE_REGISTRATION(libcigma::DofHandlerTest);
More information about the CIG-COMMITS
mailing list