source: nanovis/branches/1.1/BucketSort.cpp @ 4923

Last change on this file since 4923 was 4889, checked in by ldelgass, 5 years ago

Merge r3611:3618 from trunk

  • Property svn:eol-style set to native
File size: 1.1 KB
Line 
1/* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2/*
3 * Copyright (c) 2004-2013  HUBzero Foundation, LLC
4 *
5 */
6
7#include <vrmath/Vector3f.h>
8#include <vrmath/Matrix4x4d.h>
9
10#include "BucketSort.h"
11
12using namespace PCA;
13using namespace vrmath;
14
15void 
16BucketSort::init()
17{
18    _count = 0;
19    memset(_buffer, 0, sizeof(ClusterList*) * _size);
20}
21
22void 
23BucketSort::sort(ClusterAccel* clusterAccel, const Matrix4x4d& cameraMat, int level)
24{
25    if (clusterAccel == 0) {
26        return;
27    }
28    Cluster* cluster = clusterAccel->startPointerCluster[level - 1];
29    Cluster* c = &(cluster[0]);
30    Cluster* end = &(cluster[clusterAccel->numOfClusters[level - 1] - 1]);
31
32    for (; c <= end; c = (Cluster*) ((char *)c + sizeof(Cluster))) {
33        Vector4f pt = cameraMat.transform(Vector4f(c->centroid, 1));
34        Vector3f pos(pt.x, pt.y, pt.z);
35        addBucket(c, pos.length()*_invMaxLength);
36    }
37}       
38
39void 
40BucketSort::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.