source: nanovis/trunk/PointSet.cpp @ 5064

Last change on this file since 5064 was 3627, checked in by ldelgass, 12 years ago

Use vrmath::Color4f for color where appropriate

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