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

Last change on this file since 3492 was 3492, checked in by ldelgass, 6 years ago

Fix camera reset for nanovis. Includes refactoring of vector/matrix classes
in nanovis to consolidate into vrmath library. Also add preliminary canonical
view control to clients for testing.

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