25 i = l; j = r; mi = (l + r)/2;
29 while(itemIndices[i] < m) i++;
30 while(m < itemIndices[j]) j--;
33 k = itemIndices[i]; itemIndices[i] = itemIndices[j]; itemIndices[j] = k;
38 if (l < j) quick_sort(itemIndices, l, j);
39 if (i < r) quick_sort(itemIndices, i, r);
48 if (itemIndices.size() == 0)
return;
51 quick_sort(itemIndices, 0, itemIndices.size() - 1);
55 while (i < (
int)itemIndices.size()) {
57 while (j < (
int)itemIndices.size() && itemIndices[i] == itemIndices[j]) {
58 itemIndices[j] = -1; j++;
65 while (i < (
int)itemIndices.size()) {
66 if (itemIndices[i] < 0) {
67 itemIndices[i] = itemIndices[itemIndices.size()-1];
68 itemIndices.pop_back();
78 set_grid_spacing(
float spacing) {
81 _invSpacing = 1.0f / spacing;
100 add(
const NxBounds3 &bounds,
int itemIndex) {
106 cell_coord_of(bounds.min, x1, y1, z1);
107 cell_coord_of(bounds.max, x2, y2, z2);
110 entry.itemIndex = itemIndex;
112 for (x = x1; x <= x2; x++) {
113 for (y = y1; y <= y2; y++) {
114 for (z = z1; z <= z2; z++) {
116 int h = hash_function(x, y, z);
117 MeshHashRoot &r = _hashIndex[h];
118 int n = _entries.size();
120 if (r.timeStamp != _time || r.first < 0)
123 entry.next = r.first;
128 _entries.push_back(entry);
138 add(
const NxVec3 &pos,
int itemIndex) {
142 cell_coord_of(pos, x, y, z);
145 entry.itemIndex = itemIndex;
147 int h = hash_function(x, y, z);
148 MeshHashRoot &r = _hashIndex[h];
149 int n = _entries.size();
151 if (r.timeStamp != _time || r.first < 0)
154 entry.next = r.first;
159 _entries.push_back(entry);
166 query(
const NxBounds3 &bounds,
pvector<int> &itemIndices,
int maxIndices) {
172 cell_coord_of(bounds.min, x1, y1, z1);
173 cell_coord_of(bounds.max, x2, y2, z2);
177 for (x=x1; x<=x2; x++) {
178 for (y=y1; y<=y2; y++) {
179 for (z=z1; z<=z2; z++) {
181 int h = hash_function(x, y, z);
183 MeshHashRoot &r = _hashIndex[h];
184 if (r.timeStamp != _time)
continue;
188 MeshHashEntry &entry = _entries[i];
189 itemIndices.push_back(entry.itemIndex);
190 if (maxIndices >= 0 && (
int)itemIndices.size() >= maxIndices)
return;
202 query_unique(
const NxBounds3 &bounds,
pvector<int> &itemIndices,
int maxIndices) {
204 query(bounds, itemIndices, maxIndices);
205 compress_indices(itemIndices);
212 query(
const NxVec3 &pos,
pvector<int> &itemIndices,
int maxIndices) {
216 cell_coord_of(pos, x, y, z);
220 int h = hash_function(x, y, z);
221 MeshHashRoot &r = _hashIndex[h];
222 if (r.timeStamp != _time)
return;
226 MeshHashEntry &entry = _entries[i];
227 itemIndices.push_back(entry.itemIndex);
228 if (maxIndices >= 0 && (
int)itemIndices.size() >= maxIndices)
return;
237 query_unique(
const NxVec3 &pos,
pvector<int> &itemIndices,
int maxIndices) {
239 query(pos, itemIndices, maxIndices);
240 compress_indices(itemIndices);
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.