[2798] | 1 | /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */ |
---|
[3502] | 2 | /* |
---|
| 3 | * Copyright (c) 2004-2013 HUBzero Foundation, LLC |
---|
| 4 | * |
---|
| 5 | */ |
---|
[825] | 6 | #include <stdlib.h> |
---|
[827] | 7 | #include <stdio.h> |
---|
[825] | 8 | |
---|
[3492] | 9 | #include <vrmath/Vector3f.h> |
---|
| 10 | #include <vrmath/Vector4f.h> |
---|
[4890] | 11 | #include <vrmath/Color4f.h> |
---|
[3492] | 12 | |
---|
| 13 | #include "PointSet.h" |
---|
| 14 | #include "PCASplit.h" |
---|
| 15 | |
---|
[4889] | 16 | using namespace nv; |
---|
| 17 | |
---|
[1028] | 18 | void |
---|
[3492] | 19 | PointSet::initialize(vrmath::Vector4f *values, const unsigned int count, |
---|
| 20 | const vrmath::Vector3f& scale, const vrmath::Vector3f& origin, |
---|
[1028] | 21 | float min, float max) |
---|
[825] | 22 | { |
---|
| 23 | PCA::PCASplit pcaSplit; |
---|
| 24 | |
---|
[827] | 25 | _scale = scale; |
---|
| 26 | _origin = origin; |
---|
| 27 | _min = min; |
---|
| 28 | _max = max; |
---|
| 29 | |
---|
[2844] | 30 | PCA::Point *points = (PCA::Point *)malloc(sizeof(PCA::Point) * count); |
---|
[1028] | 31 | for (unsigned int i = 0; i < count; ++i) { |
---|
[825] | 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; |
---|
[827] | 35 | points[i].size = 0.001; |
---|
[825] | 36 | } |
---|
| 37 | |
---|
[1028] | 38 | if (_cluster != 0) { |
---|
[825] | 39 | delete _cluster; |
---|
| 40 | } |
---|
| 41 | |
---|
[827] | 42 | pcaSplit.setMinDistance(scale.length() / 3.0f); |
---|
[825] | 43 | _cluster = pcaSplit.doIt(points, count); |
---|
| 44 | } |
---|
| 45 | |
---|
[1028] | 46 | void |
---|
[2844] | 47 | PointSet::updateColor(float *color, int colorCount) |
---|
[825] | 48 | { |
---|
[1028] | 49 | if (_cluster == 0) { |
---|
| 50 | return; |
---|
| 51 | } |
---|
[827] | 52 | int level = 4; |
---|
| 53 | |
---|
[2844] | 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 | |
---|
[3492] | 58 | vrmath::Vector3f pos; |
---|
[2844] | 59 | |
---|
| 60 | PCA::Point *points; |
---|
[4890] | 61 | vrmath::Color4f *colors = (vrmath::Color4f *)color; |
---|
[1028] | 62 | int numOfPoints; |
---|
[827] | 63 | int index; |
---|
| 64 | float d = _max - _min; |
---|
[2844] | 65 | for (; c <= end; c = (PCA::Cluster *)((char *)c + sizeof(PCA::Cluster))) { |
---|
[827] | 66 | points = c->points; |
---|
| 67 | numOfPoints = c->numOfPoints; |
---|
[2814] | 68 | |
---|
[1028] | 69 | for (int i = 0; i < numOfPoints; ++i) { |
---|
[2814] | 70 | index = (int)((points[i].value - _min) / d * (colorCount - 1)); |
---|
[1028] | 71 | if (index >= colorCount) { |
---|
| 72 | index = colorCount - 1; |
---|
| 73 | } |
---|
[827] | 74 | points[i].color = colors[index]; |
---|
| 75 | } |
---|
[1028] | 76 | } |
---|
[825] | 77 | } |
---|