source: trunk/packages/vizservers/nanovis/PointSet.cpp @ 2844

Last change on this file since 2844 was 2844, checked in by ldelgass, 8 years ago

Cleanups, no functional changes

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