source: nanovis/trunk/PCASplit.h @ 4890

Last change on this file since 4890 was 3627, checked in by ldelgass, 11 years ago

Use vrmath::Color4f for color where appropriate

  • Property svn:eol-style set to native
File size: 3.5 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#ifndef PCA_PCASPLIT_H
7#define PCA_PCASPLIT_H
8
9#include <memory.h>
10
11#include <vrmath/Vector3f.h>
12#include <vrmath/Color4f.h>
13
14namespace PCA {
15
16class Point
17{
18public:
19    Point() :
20        size(1.0f),
21        value(0.0f)
22    {}
23
24    vrmath::Vector3f position;
25    vrmath::Color4f color;
26    float size;
27    float value;
28};
29
30class Cluster
31{
32public:
33    Cluster() :
34        centroid(0.0f, 0.0f, 0.0f),
35        color(1.0f, 1.0f, 1.0f, 1.0f),
36        scale(0.0f),
37        numOfChildren(0),
38        numOfPoints(0),
39        points(NULL),
40        children(NULL),
41        vbo(0),
42        level(0)
43    {
44    }
45
46    void setChildren(Cluster *children, int count)
47    {
48        this->children = children;
49        numOfChildren = count;
50    }
51
52    void setPoints(Point *points, int count)
53    {
54        this->points = points;
55        numOfPoints = count;
56    }
57
58    vrmath::Vector3f centroid;
59    vrmath::Color4f color;
60    float scale;
61
62    int numOfChildren;
63    int numOfPoints;
64    Point *points;
65    Cluster *children;
66    unsigned int vbo;
67    int level;
68};
69
70class ClusterAccel
71{
72public:
73    ClusterAccel(int maxlevel) :
74        root(NULL),
75        maxLevel(maxlevel)
76    {
77        startPointerCluster = new Cluster *[maxLevel];
78        numOfClusters = new int[maxLevel];
79        vbo = new unsigned int[maxLevel];
80        memset(vbo, 0, sizeof(unsigned int) * maxLevel);
81    }
82
83    Cluster *root;
84    int maxLevel;
85    Cluster **startPointerCluster;
86    int *numOfClusters;
87    unsigned int *vbo;
88};
89
90class Cluster_t
91{
92public:
93    Cluster_t() :
94        numOfPoints_t(0),
95        scale_t(0.0f),
96        points_t(0)
97    {}
98
99    vrmath::Vector3f centroid_t;
100    int numOfPoints_t;
101    float scale_t;
102    Point *points_t;
103};
104
105class ClusterListNode
106{
107public:
108    ClusterListNode(Cluster_t *d, ClusterListNode *n) :
109        data(d),
110        next(n)
111    {}
112
113    ClusterListNode() :
114        data(NULL),
115        next(NULL)
116    {}
117
118    Cluster_t *data;
119    ClusterListNode *next;
120};
121
122class PCASplit
123{
124public:
125    enum {
126        MAX_INDEX = 8000000
127    };
128
129    PCASplit();
130
131    ~PCASplit();
132
133    ClusterAccel *doIt(Point *data, int count);
134
135    void setMinDistance(float minDistance)
136    {
137        _minDistance = minDistance;
138    }
139
140    void setMaxLevel(int maxLevel)
141    {
142        _maxLevel = maxLevel;
143    }
144
145    static void computeDistortion(Point *data, int count, const vrmath::Vector3f& mean, float& distortion, float& maxSize);
146
147    static void computeCentroid(Point *data, int count, vrmath::Vector3f& mean);
148
149    static void computeCovariant(Point *data, int count, const vrmath::Vector3f& mean, float *m);
150
151private:
152    void init();
153
154    void analyze(ClusterListNode *cluster, Cluster *parent, int level, float limit);
155
156    void addLeafCluster(Cluster_t *cluster);
157
158    Cluster *createClusterBlock(ClusterListNode *clusterList, int count, int level);
159
160    void split(Point *data, int count, float maxDistortion);
161
162    float getMaxDistortionSquare(ClusterListNode *clusterList, int count);
163
164    ClusterAccel *_clusterHeader;
165
166    ClusterListNode *_curClusterNode;
167    ClusterListNode *_memClusterChunk1;
168    ClusterListNode *_memClusterChunk2;
169    ClusterListNode *_curMemClusterChunk;
170
171    int _memClusterChunkIndex;
172
173    Cluster *_curRoot;
174
175    int _curClusterCount;
176    int _maxLevel;
177    float _minDistance;
178    float _distanceScale;
179    unsigned int *_indices;
180    int _indexCount;
181    int _finalMaxLevel;
182};     
183
184}
185
186#endif
187
Note: See TracBrowser for help on using the repository browser.