VM2D 1.14
Vortex methods for 2D flows simulation
Loading...
Searching...
No Matches
VM2D::NeighborTree Class Reference

#include <cpuNeighborTree.h>

Collaboration diagram for VM2D::NeighborTree:

Public Member Functions

int LeafBegin (int leaf) const
int LeafEnd (int leaf) const
const NbBox & LeafBox (int leaf) const
template<typename F>
void Build (int n_, F getPos)
 Построение дерева; getPos(i) возвращает координаты i-й точки
void CollectLeaves (const NbBox &q, double R, std::vector< int > &leaves) const
 Список листьев, прямоугольники которых находятся на расстоянии меньше R от прямоугольника q.

Public Attributes

int n = 0
int nLeaves = 0
int firstLeaf = 1
 номер первого листа в неявном бинарном дереве (степень двойки)
std::vector< int > idx
 исходные номера точек в порядке сортировки
std::vector< Point2D > pos
 координаты точек в порядке сортировки
std::vector< NbBox > box
 прямоугольники узлов: корень 1, потомки узла k — 2k и 2k+1

Static Public Attributes

static const int leafSize = 32

Static Private Member Functions

static uint32_t Spread (uint32_t v)

Detailed Description

Definition at line 100 of file cpuNeighborTree.h.

Member Function Documentation

◆ Build()

template<typename F>
void VM2D::NeighborTree::Build ( int n_,
F getPos )
inline

Построение дерева; getPos(i) возвращает координаты i-й точки

Definition at line 119 of file cpuNeighborTree.h.

120 {
121 n = n_;
122 idx.resize(n);
123 pos.resize(n);
124
125 NbBox all;
126 all.SetEmpty();
127 for (int i = 0; i < n; ++i)
128 all.Add(getPos(i));
129
130 std::vector<uint64_t> keys(n), tmp(n);
131 const double scale = std::max(all.maxx - all.minx, all.maxy - all.miny);
132 const double iscale = (scale > 0.0) ? (65535.0 / scale) : 0.0;
133
134#pragma omp parallel for
135 for (int i = 0; i < n; ++i)
136 {
137 const Point2D& p = getPos(i);
138 const uint32_t ix = (uint32_t)((p[0] - all.minx) * iscale);
139 const uint32_t iy = (uint32_t)((p[1] - all.miny) * iscale);
140 keys[i] = ((uint64_t)((Spread(ix) << 1) | Spread(iy)) << 32) | (uint32_t)i;
141 }
142
143 //поразрядная сортировка по старшим 32 битам (мортоновский код)
144 for (int shift = 32; shift < 64; shift += 8)
145 {
146 size_t cnt[257] = { 0 };
147 for (int i = 0; i < n; ++i)
148 ++cnt[((keys[i] >> shift) & 0xFF) + 1];
149 for (int b = 0; b < 256; ++b)
150 cnt[b + 1] += cnt[b];
151 for (int i = 0; i < n; ++i)
152 tmp[cnt[(keys[i] >> shift) & 0xFF]++] = keys[i];
153 keys.swap(tmp);
154 }
155
156 for (int i = 0; i < n; ++i)
157 {
158 idx[i] = (int)(keys[i] & 0xFFFFFFFFu);
159 pos[i] = getPos(idx[i]);
160 }
161
162 nLeaves = (n + leafSize - 1) / leafSize;
163 firstLeaf = 1;
164 while (firstLeaf < std::max(nLeaves, 1))
165 firstLeaf <<= 1;
166
167 box.resize(2 * firstLeaf);
168#pragma omp parallel for
169 for (int l = 0; l < firstLeaf; ++l)
170 {
171 NbBox& b = box[firstLeaf + l];
172 b.SetEmpty();
173 if (l < nLeaves)
174 for (int k = LeafBegin(l); k < LeafEnd(l); ++k)
175 b.Add(pos[k]);
176 }
177 for (int k = firstLeaf - 1; k >= 1; --k)
178 {
179 box[k] = box[2 * k];
180 box[k].Add(box[2 * k + 1]);
181 }
182 }
std::vector< int > idx
исходные номера точек в порядке сортировки
int firstLeaf
номер первого листа в неявном бинарном дереве (степень двойки)
std::vector< NbBox > box
прямоугольники узлов: корень 1, потомки узла k — 2k и 2k+1
int LeafBegin(int leaf) const
int LeafEnd(int leaf) const
static const int leafSize
static uint32_t Spread(uint32_t v)
std::vector< Point2D > pos
координаты точек в порядке сортировки
Here is the call graph for this function:
Here is the caller graph for this function:

◆ CollectLeaves()

void VM2D::NeighborTree::CollectLeaves ( const NbBox & q,
double R,
std::vector< int > & leaves ) const
inline

Список листьев, прямоугольники которых находятся на расстоянии меньше R от прямоугольника q.

Definition at line 185 of file cpuNeighborTree.h.

186 {
187 leaves.clear();
188 if (nLeaves == 0)
189 return;
190 const double R2 = R * R;
191 int stack[64];
192 int top = 0;
193 stack[top++] = 1;
194 while (top > 0)
195 {
196 const int k = stack[--top];
197 if (box[k].Dist2(q) >= R2)
198 continue;
199 if (k >= firstLeaf)
200 leaves.push_back(k - firstLeaf);
201 else
202 {
203 stack[top++] = 2 * k + 1;
204 stack[top++] = 2 * k;
205 }
206 }
207 }
Here is the caller graph for this function:

◆ LeafBegin()

int VM2D::NeighborTree::LeafBegin ( int leaf) const
inline

Definition at line 113 of file cpuNeighborTree.h.

113{ return leaf * leafSize; }
Here is the caller graph for this function:

◆ LeafBox()

const NbBox & VM2D::NeighborTree::LeafBox ( int leaf) const
inline

Definition at line 115 of file cpuNeighborTree.h.

115{ return box[firstLeaf + leaf]; }
Here is the caller graph for this function:

◆ LeafEnd()

int VM2D::NeighborTree::LeafEnd ( int leaf) const
inline

Definition at line 114 of file cpuNeighborTree.h.

114{ return std::min(n, (leaf + 1) * leafSize); }
Here is the caller graph for this function:

◆ Spread()

uint32_t VM2D::NeighborTree::Spread ( uint32_t v)
inlinestaticprivate

Definition at line 210 of file cpuNeighborTree.h.

211 {
212 v &= 0x0000FFFF;
213 v = (v | (v << 8)) & 0x00FF00FF;
214 v = (v | (v << 4)) & 0x0F0F0F0F;
215 v = (v | (v << 2)) & 0x33333333;
216 v = (v | (v << 1)) & 0x55555555;
217 return v;
218 }
Here is the caller graph for this function:

Member Data Documentation

◆ box

std::vector<NbBox> VM2D::NeighborTree::box

прямоугольники узлов: корень 1, потомки узла k — 2k и 2k+1

Definition at line 111 of file cpuNeighborTree.h.

◆ firstLeaf

int VM2D::NeighborTree::firstLeaf = 1

номер первого листа в неявном бинарном дереве (степень двойки)

Definition at line 107 of file cpuNeighborTree.h.

◆ idx

std::vector<int> VM2D::NeighborTree::idx

исходные номера точек в порядке сортировки

Definition at line 109 of file cpuNeighborTree.h.

◆ leafSize

const int VM2D::NeighborTree::leafSize = 32
static

Definition at line 103 of file cpuNeighborTree.h.

◆ n

int VM2D::NeighborTree::n = 0

Definition at line 105 of file cpuNeighborTree.h.

◆ nLeaves

int VM2D::NeighborTree::nLeaves = 0

Definition at line 106 of file cpuNeighborTree.h.

◆ pos

std::vector<Point2D> VM2D::NeighborTree::pos

координаты точек в порядке сортировки

Definition at line 110 of file cpuNeighborTree.h.


The documentation for this class was generated from the following file: