source: trunk/vizservers/nanovis/PointSet.cpp @ 884

Last change on this file since 884 was 827, checked in by vrinside, 16 years ago

Added color blending with point sprite texture

File size: 2.0 KB
Line 
1#include "PointSet.h"
2#include "PCASplit.h"
3#include <stdlib.h>
4#include <stdio.h>
5
6PointSet::PointSet()
7: _visible(false), _cluster(0), _sortLevel(4), _min(0.0f), _max(1.0f)
8{
9}
10
11PointSet::~PointSet()
12{
13    if (_cluster)
14    {
15        delete _cluster;
16    }
17}
18
19void PointSet::initialize(Vector4* values, const unsigned int count, const Vector3& scale, const Vector3& origin, float min, float max)
20{
21    PCA::PCASplit pcaSplit;
22
23    _scale = scale;
24    _origin = origin;
25    _min = min;
26    _max = max;
27
28    PCA::Point* points = (PCA::Point*) malloc(sizeof(PCA::Point) * count);
29    for (unsigned int i = 0; i < count; ++i)
30    {
31        points[i].position.set(values[i].x, values[i].y, values[i].z);
32        points[i].color.set(1.0f, 1.0f, 1.0f, 0.2f);
33        points[i].value = values[i].w;
34        points[i].size = 0.001;
35    }
36
37    if (_cluster != 0)
38    {
39        delete _cluster;
40    }
41   
42    pcaSplit.setMinDistance(scale.length() / 3.0f);
43    _cluster = pcaSplit.doIt(points, count);
44}
45
46void PointSet::updateColor(float* color,  int colorCount)
47{
48        if (_cluster == 0) return;
49
50    int level = 4;
51
52        PCA::Cluster* cluster = _cluster->startPointerCluster[level - 1];
53        PCA::Cluster* c = &(cluster[0]);
54        PCA::Cluster* end = &(cluster[_cluster->numOfClusters[level - 1] - 1]);
55
56        Vector3 pos;
57       
58    PCA::Point* points;
59    Vector4* colors = (Vector4*) color;
60        int numOfPoints;
61    int index;
62    float d = _max - _min;
63        for (; c <= end; c = (PCA::Cluster*) ((int) c + sizeof(PCA::Cluster)))
64        {
65        points = c->points;
66        numOfPoints = c->numOfPoints;
67
68        for (int i = 0; i < numOfPoints; ++i)
69        {
70            index = (points[i].value - _min) / d  * (colorCount - 1);
71            if (index >= colorCount) index = colorCount - 1;
72            //printf("TEST %f %d/%d -> %d (%f %f %f)\n", points[i].value, i, numOfPoints, index,
73            //                                    colors[index].x, colors[index].y, colors[index].z);
74            //fflush(stdout);
75            points[i].color = colors[index];
76        }
77
78        }
79}
80
Note: See TracBrowser for help on using the repository browser.