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

Last change on this file since 953 was 953, checked in by gah, 16 years ago

remove warnings from compile

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