source: trunk/packages/vizservers/nanovis/PCASplit.h @ 3362

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

Cleanups, no functional changes

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