source: branches/blt4/packages/vizservers/nanovis/PointSet.cpp @ 2742

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

64-bit fixes

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