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

Last change on this file since 4819 was 3502, checked in by ldelgass, 11 years ago

Add basic VTK structured points reader to nanovis, update copyright dates.

  • Property svn:eol-style set to native
File size: 1.0 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 "BucketSort.h"
8
9using namespace PCA;
10
11#include <vrmath/Vector3f.h>
12#include <vrmath/Matrix4x4d.h>
13
14void
15BucketSort::init()
16{
17    _count = 0;
18    memset(_buffer, 0, sizeof(ClusterList*) * _size);
19}
20
21void
22BucketSort::sort(ClusterAccel* clusterAccel, const Matrix4x4d& cameraMat, int level)
23{
24    if (clusterAccel == 0) {
25        return;
26    }
27    Cluster* cluster = clusterAccel->startPointerCluster[level - 1];
28    Cluster* c = &(cluster[0]);
29    Cluster* end = &(cluster[clusterAccel->numOfClusters[level - 1] - 1]);
30
31    Vector3f pos;
32    for (; c <= end; c = (Cluster*) ((char *)c + sizeof(Cluster))) {
33        pos = cameraMat.transform(c->centroid);
34        addBucket(c, pos.length()*_invMaxLength);
35    }
36}       
37
38void
39BucketSort::addBucket(Cluster* cluster, float ratio)
40{
41    int index = (int) (ratio * _size);
42    ClusterList* c = &(_memChunck[_count++]);
43    c->data = cluster;
44    c->next =_buffer[index];
45    _buffer[index] = c;
46}
47
Note: See TracBrowser for help on using the repository browser.