Rev | Line | |
---|
[2798] | 1 | /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */ |
---|
[3502] | 2 | /* |
---|
| 3 | * Copyright (c) 2004-2013 HUBzero Foundation, LLC |
---|
| 4 | * |
---|
| 5 | */ |
---|
| 6 | |
---|
[4889] | 7 | #include <vrmath/Vector3f.h> |
---|
| 8 | #include <vrmath/Matrix4x4d.h> |
---|
| 9 | |
---|
[953] | 10 | #include "BucketSort.h" |
---|
| 11 | |
---|
| 12 | using namespace PCA; |
---|
[4889] | 13 | using namespace vrmath; |
---|
[953] | 14 | |
---|
| 15 | void |
---|
| 16 | BucketSort::init() |
---|
| 17 | { |
---|
| 18 | _count = 0; |
---|
| 19 | memset(_buffer, 0, sizeof(ClusterList*) * _size); |
---|
| 20 | } |
---|
| 21 | |
---|
| 22 | void |
---|
[3492] | 23 | BucketSort::sort(ClusterAccel* clusterAccel, const Matrix4x4d& cameraMat, int level) |
---|
[953] | 24 | { |
---|
| 25 | if (clusterAccel == 0) { |
---|
[4889] | 26 | return; |
---|
[953] | 27 | } |
---|
| 28 | Cluster* cluster = clusterAccel->startPointerCluster[level - 1]; |
---|
| 29 | Cluster* c = &(cluster[0]); |
---|
| 30 | Cluster* end = &(cluster[clusterAccel->numOfClusters[level - 1] - 1]); |
---|
| 31 | |
---|
[1170] | 32 | for (; c <= end; c = (Cluster*) ((char *)c + sizeof(Cluster))) { |
---|
[4889] | 33 | Vector4f pt = cameraMat.transform(Vector4f(c->centroid, 1)); |
---|
| 34 | Vector3f pos(pt.x, pt.y, pt.z); |
---|
| 35 | addBucket(c, pos.length()*_invMaxLength); |
---|
[953] | 36 | } |
---|
| 37 | } |
---|
| 38 | |
---|
| 39 | void |
---|
| 40 | BucketSort::addBucket(Cluster* cluster, float ratio) |
---|
| 41 | { |
---|
| 42 | int index = (int) (ratio * _size); |
---|
| 43 | ClusterList* c = &(_memChunck[_count++]); |
---|
| 44 | c->data = cluster; |
---|
| 45 | c->next =_buffer[index]; |
---|
| 46 | _buffer[index] = c; |
---|
| 47 | } |
---|
| 48 | |
---|
Note: See
TracBrowser
for help on using the repository browser.