From 1b06786e63e91cde4d229ea86f442516a59a486b Mon Sep 17 00:00:00 2001 From: Guilhem Lavaux Date: Mon, 4 Mar 2013 22:48:13 -0500 Subject: [PATCH] Started work to support periodic boundaries in KDTree --- src/mykdtree.hpp | 2 ++ src/mykdtree.tcc | 17 +++++++++++++++-- src/replicateGenerator.hpp | 37 +++++++++++++++++++++++++++++++++++++ 3 files changed, 54 insertions(+), 2 deletions(-) create mode 100644 src/replicateGenerator.hpp diff --git a/src/mykdtree.hpp b/src/mykdtree.hpp index 1a691c6..9d2c63c 100644 --- a/src/mykdtree.hpp +++ b/src/mykdtree.hpp @@ -184,6 +184,8 @@ namespace CosmoTool { Cell **sortingHelper; Cell *base_cell; + bool periodic; + Node *buildTree(Cell **cell0, uint32_t NumCells, uint32_t depth, diff --git a/src/mykdtree.tcc b/src/mykdtree.tcc index a5e3abb..27ea18b 100644 --- a/src/mykdtree.tcc +++ b/src/mykdtree.tcc @@ -31,7 +31,8 @@ namespace CosmoTool { template KDTree::KDTree(Cell *cells, uint32_t Ncells) { - + periodic = false; + base_cell = cells; numNodes = Ncells; nodes = new Node[numNodes]; @@ -365,7 +366,19 @@ namespace CosmoTool { CoordType R2 = INFINITY; Cell *best = 0; - recursiveNearest(root, 0, x, R2, best); + recursiveNearest(root, 0, x, R2, best); + if (periodic) + { +#if 0 + ReplicateGenerator replicate(x); + + do + { + recursiveNearest(root, 0, replicate.getPosition(), R2, best); + } + while (replicate.next()); +#endif + } return best; } diff --git a/src/replicateGenerator.hpp b/src/replicateGenerator.hpp new file mode 100644 index 0000000..270640f --- /dev/null +++ b/src/replicateGenerator.hpp @@ -0,0 +1,37 @@ +#ifndef __REPLICATE_GENERATOR_HPP +#define __REPLICATE_GENERATOR_HPP + +namespace CosmoTool +{ + + template + class ReplicateGenerator + { + public: + ReplicateGenerator(const Coord x[N]) + { + face = 0; + } + + bool next() + { + if (face == (2*N)) + return false; + + face++; + + } + + Coord getPosition() + { + return x_shifted; + } + + private: + Coord x_shifted[N]; + int face; + }; + +}; + +#endif