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

Last change on this file since 5040 was 4889, checked in by ldelgass, 9 years ago

Merge r3611:3618 from trunk

  • Property svn:eol-style set to native
File size: 1.1 KB
RevLine 
[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
12using namespace PCA;
[4889]13using namespace vrmath;
[953]14
15void
16BucketSort::init()
17{
18    _count = 0;
19    memset(_buffer, 0, sizeof(ClusterList*) * _size);
20}
21
22void
[3492]23BucketSort::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
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.