Commit 8ef90e57 authored by Praetorius, Simon's avatar Praetorius, Simon
Browse files

backgroundmesh and views

parent cf9f88fd
...@@ -64,7 +64,7 @@ namespace experimental { ...@@ -64,7 +64,7 @@ namespace experimental {
} }
bool Box::inBox(PointType& x) bool Box::inBox(const PointType& x)
{ {
for (size_t i = 0; i < DOW; i++) for (size_t i = 0; i < DOW; i++)
if (min_corner[i] > x[i] || max_corner[i] < x[i]) if (min_corner[i] > x[i] || max_corner[i] < x[i])
...@@ -82,7 +82,7 @@ namespace experimental { ...@@ -82,7 +82,7 @@ namespace experimental {
* | 0 | 1 | 2 | 3 | * | 0 | 1 | 2 | 3 |
* -----------------> Nx=4 * -----------------> Nx=4
**/ **/
int Box::getBox(PointType& x) int Box::getBox(const PointType& x)
{ {
std::vector<int> idx(DOW); std::vector<int> idx(DOW);
for (size_t i = 0; i < DOW; i++) for (size_t i = 0; i < DOW; i++)
...@@ -92,7 +92,7 @@ namespace experimental { ...@@ -92,7 +92,7 @@ namespace experimental {
} }
bool Box::getNearestData(PointType& x, DataType& data) bool Box::getNearestData(const PointType& x, DataType& data)
{ {
if (!inBox(x)) if (!inBox(x))
return false; return false;
...@@ -120,7 +120,7 @@ namespace experimental { ...@@ -120,7 +120,7 @@ namespace experimental {
} }
bool Box::getNearestData(PointType& x, std::vector<DataType>& data, int nData) bool Box::getNearestData(const PointType& x, std::vector<DataType>& data, int nData)
{ {
if (!inBox(x)) if (!inBox(x))
return false; return false;
...@@ -346,7 +346,7 @@ namespace experimental { ...@@ -346,7 +346,7 @@ namespace experimental {
/// berechne die minimale Entfernung der Ränder der Box zu x /// berechne die minimale Entfernung der Ränder der Box zu x
double Box::getBoxBoundaryDist(int nr, PointType& x) double Box::getBoxBoundaryDist(int nr, const PointType& x)
{ {
std::vector<int> idx; std::vector<int> idx;
nr2idx(nr, idx); nr2idx(nr, idx);
......
...@@ -19,7 +19,7 @@ namespace experimental { ...@@ -19,7 +19,7 @@ namespace experimental {
typedef WorldVector<double> PointType; typedef WorldVector<double> PointType;
inline double distance(PointType &x, PointType &y, unsigned int n) inline double distance(const PointType &x, const PointType &y, unsigned int n)
{ {
double d = 0.0; double d = 0.0;
for (unsigned int i = 0; i < n; i++) for (unsigned int i = 0; i < n; i++)
...@@ -27,7 +27,7 @@ namespace experimental { ...@@ -27,7 +27,7 @@ namespace experimental {
return sqrt(d); return sqrt(d);
} }
inline double distance2(PointType &x, PointType &y, unsigned int n) inline double distance2(const PointType &x, const PointType &y, unsigned int n)
{ {
double d = 0.0; double d = 0.0;
for (unsigned int i = 0; i < n; i++) for (unsigned int i = 0; i < n; i++)
...@@ -49,11 +49,11 @@ namespace experimental { ...@@ -49,11 +49,11 @@ namespace experimental {
int getMaxBoxSize(); int getMaxBoxSize();
bool inBox(PointType& x); bool inBox(const PointType& x);
int getBox(PointType& x); int getBox(const PointType& x);
bool getNearestData(PointType& x, DataType& data); bool getNearestData(const PointType& x, DataType& data);
bool getNearestData(PointType& x, std::vector<DataType>& data, int nData); bool getNearestData(const PointType& x, std::vector<DataType>& data, int nData);
/** /**
* strategies: * strategies:
...@@ -63,7 +63,7 @@ namespace experimental { ...@@ -63,7 +63,7 @@ namespace experimental {
* 3 .. get n nearest points, calc weighted regression plane and eval at x * 3 .. get n nearest points, calc weighted regression plane and eval at x
**/ **/
template<typename T> template<typename T>
T evalAtPoint(DOFVector<T>& vec, PointType& x, int strategy = 0, int nrOfPoints = -1); T evalAtPoint(const DOFVector<T>& vec, const PointType& x, int strategy = 0, int nrOfPoints = -1);
static Box* provideBackgroundMesh(const FiniteElemSpace* feSpace); static Box* provideBackgroundMesh(const FiniteElemSpace* feSpace);
static void delete_all(); static void delete_all();
...@@ -73,16 +73,16 @@ namespace experimental { ...@@ -73,16 +73,16 @@ namespace experimental {
protected: protected:
template<typename T> template<typename T>
T evalAtPoint_simple(DOFVector<T>& vec, PointType& x); T evalAtPoint_simple(const DOFVector<T>& vec, const PointType& x);
template<typename T> template<typename T>
T evalAtPoint_weighted_sum(DOFVector<T>& vec, PointType& x, int nrOfPoints); T evalAtPoint_weighted_sum(const DOFVector<T>& vec, const PointType& x, int nrOfPoints);
template<typename T> template<typename T>
T evalAtPoint_regression(DOFVector<T>& vec, PointType& x, int nrOfPoints); T evalAtPoint_regression(const DOFVector<T>& vec, const PointType& x, int nrOfPoints);
template<typename T> template<typename T>
T evalAtPoint_weighted_regression(DOFVector<T>& vec, PointType& x, int nrOfPoints); T evalAtPoint_weighted_regression(const DOFVector<T>& vec, const PointType& x, int nrOfPoints);
inline int idx2nr(std::vector<int>& idx); inline int idx2nr(std::vector<int>& idx);
...@@ -94,7 +94,7 @@ namespace experimental { ...@@ -94,7 +94,7 @@ namespace experimental {
void getSurroundingBoxes(std::set<int> &nrs, std::set<int> &surrounding_nrs); void getSurroundingBoxes(std::set<int> &nrs, std::set<int> &surrounding_nrs);
/// berechne die minimale Entfernung der Ränder der Box zu x /// berechne die minimale Entfernung der Ränder der Box zu x
double getBoxBoundaryDist(int nr, PointType& x); double getBoxBoundaryDist(int nr, const PointType& x);
static std::map<const FiniteElemSpace*, std::pair<int, Box*> > boxMap; static std::map<const FiniteElemSpace*, std::pair<int, Box*> > boxMap;
......
...@@ -10,7 +10,7 @@ namespace experimental { ...@@ -10,7 +10,7 @@ namespace experimental {
* 3 .. get n nearest points, calc weighted regression plane and eval at x * 3 .. get n nearest points, calc weighted regression plane and eval at x
**/ **/
template<typename T> template<typename T>
T Box::evalAtPoint(DOFVector<T>& vec, PointType& x, int strategy, int nrOfPoints) T Box::evalAtPoint(const DOFVector<T>& vec, const PointType& x, int strategy, int nrOfPoints)
{ {
T value; T value;
switch (strategy) { switch (strategy) {
...@@ -35,7 +35,7 @@ namespace experimental { ...@@ -35,7 +35,7 @@ namespace experimental {
template<typename T> template<typename T>
T Box::evalAtPoint_simple(DOFVector<T>& vec, PointType& x) T Box::evalAtPoint_simple(const DOFVector<T>& vec, const PointType& x)
{ {
DataType dof; DataType dof;
T value; nullify(value); T value; nullify(value);
...@@ -46,7 +46,7 @@ namespace experimental { ...@@ -46,7 +46,7 @@ namespace experimental {
template<typename T> template<typename T>
T Box::evalAtPoint_weighted_sum(DOFVector<T>& vec, PointType& x, int nrOfPoints) T Box::evalAtPoint_weighted_sum(const DOFVector<T>& vec, const PointType& x, int nrOfPoints)
{ {
T value; nullify(value); T value; nullify(value);
...@@ -76,7 +76,7 @@ namespace experimental { ...@@ -76,7 +76,7 @@ namespace experimental {
template<typename T> template<typename T>
T Box::evalAtPoint_regression(DOFVector<T>& vec, PointType& x, int nrOfPoints) T Box::evalAtPoint_regression(const DOFVector<T>& vec, const PointType& x, int nrOfPoints)
{ {
T value; nullify(value); T value; nullify(value);
...@@ -102,7 +102,7 @@ namespace experimental { ...@@ -102,7 +102,7 @@ namespace experimental {
template<typename T> template<typename T>
T Box::evalAtPoint_weighted_regression(DOFVector<T>& vec, PointType& x, int nrOfPoints) T Box::evalAtPoint_weighted_regression(const DOFVector<T>& vec, const PointType& x, int nrOfPoints)
{ {
T value; nullify(value); T value; nullify(value);
......
...@@ -19,7 +19,7 @@ void Helpers::interpolOverLine(const Container &vec, ...@@ -19,7 +19,7 @@ void Helpers::interpolOverLine(const Container &vec,
p[0] = lambda*x2 + (1.0-lambda)*x1; p[0] = lambda*x2 + (1.0-lambda)*x1;
p[1] = lambda*y2 + (1.0-lambda)*y1; p[1] = lambda*y2 + (1.0-lambda)*y1;
double value = vec.evalAtPoint(p); double value = evalAtPoint(vec, p);
x.push_back(p); x.push_back(p);
y.push_back(value); y.push_back(value);
} }
......
...@@ -159,7 +159,7 @@ struct DOFView : public DOFVector<T> { ...@@ -159,7 +159,7 @@ struct DOFView : public DOFVector<T> {
bool use_kdtree = false; bool use_kdtree = false;
Parameters::get("KD-Tree->enabled",use_kdtree); Parameters::get("KD-Tree->enabled",use_kdtree);
if (use_kdtree) { if (use_kdtree) {
KD_Tree* tree = provideKDTree(feSpace); KD_Tree_Dof* tree = provideKDTree(feSpace);
T value = tree->evalAtPoint(*vector, x_); T value = tree->evalAtPoint(*vector, x_);
return value; return value;
} }
...@@ -384,7 +384,7 @@ inline T evalAtPoint(const DOFVector<T> &obj, WorldVector<double> &p, ElInfo* ol ...@@ -384,7 +384,7 @@ inline T evalAtPoint(const DOFVector<T> &obj, WorldVector<double> &p, ElInfo* ol
bool use_kdtree = false; bool use_kdtree = false;
Parameters::get("KD-Tree->enabled",use_kdtree); Parameters::get("KD-Tree->enabled",use_kdtree);
if (use_kdtree) { if (use_kdtree) {
KD_Tree* tree = provideKDTree(feSpace); KD_Tree_Dof* tree = provideKDTree(feSpace);
T value = tree->evalAtPoint(obj, p); T value = tree->evalAtPoint(obj, p);
return value; return value;
} }
......
...@@ -44,7 +44,7 @@ namespace experimental { ...@@ -44,7 +44,7 @@ namespace experimental {
// ===================================================================================== // =====================================================================================
typedef WorldVector<double> PointType; typedef WorldVector<double> PointType;
typedef DOFVector<PointType> my_vector_of_vectors_t; typedef DOFVector<PointType> VectorOfVectors_Dof;
// ===================================================================================== // =====================================================================================
...@@ -61,12 +61,13 @@ typedef DOFVector<PointType> my_vector_of_vectors_t; ...@@ -61,12 +61,13 @@ typedef DOFVector<PointType> my_vector_of_vectors_t;
int DIM = -1, int DIM = -1,
class Distance = nanoflann::metric_L2_Simple, class Distance = nanoflann::metric_L2_Simple,
typename index_type = DegreeOfFreedom > typename index_type = DegreeOfFreedom >
struct KDTreeVectorOfWorldVectorsAdaptor struct KDTreeDOFVectorOfWorldVectorsAdaptor
{ {
typedef KDTreeVectorOfWorldVectorsAdaptor< VectorOfVectorsType, typedef KDTreeDOFVectorOfWorldVectorsAdaptor< VectorOfVectorsType,
value_type, value_type,
DIM, DIM,
Distance > self_t; Distance,
index_type > self_t;
typedef typename Distance::template traits<value_type, self_t>::distance_t metric_t; typedef typename Distance::template traits<value_type, self_t>::distance_t metric_t;
typedef KDTreeSingleIndexAdaptor< metric_t, typedef KDTreeSingleIndexAdaptor< metric_t,
self_t, self_t,
...@@ -76,7 +77,7 @@ typedef DOFVector<PointType> my_vector_of_vectors_t; ...@@ -76,7 +77,7 @@ typedef DOFVector<PointType> my_vector_of_vectors_t;
index_t* index; //! The kd-tree index for the user to call its methods as usual with any other FLANN index. index_t* index; //! The kd-tree index for the user to call its methods as usual with any other FLANN index.
/// Constructor: takes a const ref to the vector of vectors object with the data points /// Constructor: takes a const ref to the vector of vectors object with the data points
KDTreeVectorOfWorldVectorsAdaptor(const int dimensionality, KDTreeDOFVectorOfWorldVectorsAdaptor(const int dimensionality,
VectorOfVectorsType &mat, VectorOfVectorsType &mat,
const int leaf_max_size = 10) : m_data(mat) const int leaf_max_size = 10) : m_data(mat)
{ {
...@@ -88,7 +89,7 @@ typedef DOFVector<PointType> my_vector_of_vectors_t; ...@@ -88,7 +89,7 @@ typedef DOFVector<PointType> my_vector_of_vectors_t;
index->buildIndex(); index->buildIndex();
} }
~KDTreeVectorOfWorldVectorsAdaptor() { ~KDTreeDOFVectorOfWorldVectorsAdaptor() {
delete index; delete index;
} }
...@@ -167,7 +168,7 @@ typedef DOFVector<PointType> my_vector_of_vectors_t; ...@@ -167,7 +168,7 @@ typedef DOFVector<PointType> my_vector_of_vectors_t;
* == evalAtPoint_simple * == evalAtPoint_simple
**/ **/
template<typename T> template<typename T>
T evalAtPoint(DOFVector<T>& vec, PointType& x, int strategy = 0, int nrOfPoints = -1) T evalAtPoint(const DOFVector<T>& vec, const PointType& x, int strategy = 0, int nrOfPoints = -1)
{ {
const size_t nnp = 1; const size_t nnp = 1;
std::vector<DegreeOfFreedom> ret_indexes(nnp); std::vector<DegreeOfFreedom> ret_indexes(nnp);
...@@ -184,28 +185,28 @@ typedef DOFVector<PointType> my_vector_of_vectors_t; ...@@ -184,28 +185,28 @@ typedef DOFVector<PointType> my_vector_of_vectors_t;
return value; return value;
} }
}; // end of KDTreeVectorOfVectorsAdaptor }; // end of KDTreeDOFVectorOfWorldVectorsAdaptor
typedef KDTreeVectorOfWorldVectorsAdaptor< my_vector_of_vectors_t, double > KD_Tree; typedef KDTreeDOFVectorOfWorldVectorsAdaptor< VectorOfVectors_Dof, double > KD_Tree_Dof;
static std::map<const FiniteElemSpace*, std::pair<int, KD_Tree*> > kdtreeMap; static std::map<const FiniteElemSpace*, std::pair<int, KD_Tree_Dof*> > kdtreeMap_Dof;
inline KD_Tree* provideKDTree(const FiniteElemSpace* feSpace) inline KD_Tree_Dof* provideKDTree(const FiniteElemSpace* feSpace)
{ {
if (kdtreeMap.find(feSpace) != kdtreeMap.end()) { if (kdtreeMap_Dof.find(feSpace) != kdtreeMap_Dof.end()) {
if (kdtreeMap[feSpace].first != feSpace->getMesh()->getChangeIndex()) { if (kdtreeMap_Dof[feSpace].first != feSpace->getMesh()->getChangeIndex()) {
feSpace->getMesh()->getDofIndexCoords(feSpace, kdtreeMap[feSpace].second->m_data); feSpace->getMesh()->getDofIndexCoords(feSpace, kdtreeMap_Dof[feSpace].second->m_data);
kdtreeMap[feSpace].second->reinit(); kdtreeMap_Dof[feSpace].second->reinit();
kdtreeMap[feSpace].first = feSpace->getMesh()->getChangeIndex(); kdtreeMap_Dof[feSpace].first = feSpace->getMesh()->getChangeIndex();
} }
} else { } else {
DOFVector<WorldVector<double> >* coords = new DOFVector<WorldVector<double> >(feSpace, "coords"); DOFVector<WorldVector<double> >* coords = new DOFVector<WorldVector<double> >(feSpace, "coords");
feSpace->getMesh()->getDofIndexCoords(feSpace, *coords); feSpace->getMesh()->getDofIndexCoords(feSpace, *coords);
KD_Tree* kdtree = new KD_Tree(Global::getGeo(WORLD), *coords); KD_Tree_Dof* kdtree = new KD_Tree_Dof(Global::getGeo(WORLD), *coords);
kdtreeMap[feSpace] = std::make_pair(feSpace->getMesh()->getChangeIndex(), kdtree); kdtreeMap_Dof[feSpace] = std::make_pair(feSpace->getMesh()->getChangeIndex(), kdtree);
} }
return kdtreeMap[feSpace].second; return kdtreeMap_Dof[feSpace].second;
} }
} // end namespace } // end namespace
......
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