Commit 8618030b authored by Praetorius, Simon's avatar Praetorius, Simon

backgroundmesh and kdtree updated

parent 7e87c6ed
......@@ -217,7 +217,7 @@ namespace experimental {
void Box::init()
{
int maxNr = 1.0;
int maxNr = 1;
for (size_t i = 0; i < DOW; i++)
maxNr *= N[i];
boxData.resize(maxNr);
......@@ -370,4 +370,4 @@ namespace experimental {
boxData[nr].push_back(data);
}
}
\ No newline at end of file
}
......@@ -36,6 +36,7 @@
#include <iostream>
#include "AMDiS.h"
#include "ElementFunction.h"
using namespace nanoflann;
using namespace AMDiS;
......@@ -66,10 +67,12 @@ typedef std::vector<DataType> VectorOfDataType;
typename index_type = DegreeOfFreedom >
struct KDTreeMeshAdaptor
{
typedef KDTreeMeshAdaptor< VectorOfPointsType_,
typedef KDTreeMeshAdaptor< VectorOfPointsType_,
VectorOfDataType_,
value_type,
DIM,
Distance > self_t;
Distance,
index_type > self_t;
typedef typename Distance::template traits<value_type, self_t>::distance_t metric_t;
typedef KDTreeSingleIndexAdaptor< metric_t,
self_t,
......@@ -77,11 +80,12 @@ typedef std::vector<DataType> VectorOfDataType;
index_type > index_t;
index_t* index; //! The kd-tree index for the user to call its methods as usual with any other FLANN index.
Mesh* mesh;
/// Constructor: takes a const ref to the vector of vectors object with the data points
KDTreeVectorOfWorldVectorsAdaptor(const int dimensionality,
Mesh* mesh_,
const int leaf_max_size = 10)
KDTreeMeshAdaptor(const int dimensionality,
Mesh* mesh_,
const int leaf_max_size = 10)
: mesh(mesh_)
{
const size_t dims = Global::getGeo(WORLD);
......@@ -98,7 +102,7 @@ typedef std::vector<DataType> VectorOfDataType;
index->buildIndex();
}
~KDTreeVectorOfWorldVectorsAdaptor() {
~KDTreeMeshAdaptor() {
delete index;
}
......@@ -138,8 +142,8 @@ typedef std::vector<DataType> VectorOfDataType;
index->buildIndex();
}
VectorOfPointsType_ &m_points;
VectorOfDataType_ &m_data;
VectorOfPointsType_ m_points;
VectorOfDataType_ m_data;
/** Query for the \a num_closest closest points to a given point (entered as query_point[0:dim-1]).
* Note that this is a short-cut method for index->findNeighbors().
......@@ -169,7 +173,7 @@ typedef std::vector<DataType> VectorOfDataType;
// Must return the number of data points
inline size_t kdtree_get_point_count() const {
return m_points.getUsedSize();
return m_points.size();
}
// Returns the distance between the vector "p1[0:size-1]" and the data point with index "idx_p2" stored in the class:
......@@ -249,24 +253,24 @@ typedef std::vector<DataType> VectorOfDataType;
}; // end of KDTreeMeshAdaptor
typedef KDTreeMeshAdaptor< VectorOfPointsType, VectorOfDataType, double > KD_Tree;
static std::map<const FiniteElemSpace*, std::pair<int, KD_Tree*> > kdtreeMap;
typedef KDTreeMeshAdaptor< VectorOfPointsType, VectorOfDataType, double > KD_Tree_M;
static std::map<const FiniteElemSpace*, std::pair<int, KD_Tree_M*> > kdtreeMap_M;
inline KD_Tree* provideKDTree(const FiniteElemSpace* feSpace)
inline KD_Tree_M* provideKDTree(const FiniteElemSpace* feSpace)
{
if (kdtreeMap.find(feSpace) != kdtreeMap.end()) {
if (kdtreeMap[feSpace].first != feSpace->getMesh()->getChangeIndex()) {
kdtreeMap[feSpace].second->reinit();
kdtreeMap[feSpace].first = feSpace->getMesh()->getChangeIndex();
if (kdtreeMap_M.find(feSpace) != kdtreeMap_M.end()) {
if (kdtreeMap_M[feSpace].first != feSpace->getMesh()->getChangeIndex()) {
kdtreeMap_M[feSpace].second->reinit();
kdtreeMap_M[feSpace].first = feSpace->getMesh()->getChangeIndex();
}
} else {
KD_Tree* kdtree = new KD_Tree(Global::getGeo(WORLD), feSpace->getMesh());
kdtreeMap[feSpace] = std::make_pair(feSpace->getMesh()->getChangeIndex(), kdtree);
KD_Tree_M* kdtree = new KD_Tree_M(Global::getGeo(WORLD), feSpace->getMesh());
kdtreeMap_M[feSpace] = std::make_pair(feSpace->getMesh()->getChangeIndex(), kdtree);
}
return kdtreeMap[feSpace].second;
return kdtreeMap_M[feSpace].second;
}
} // end namespace
} // end namespace experimental
#endif
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment