source: nanovis/branches/1.1/PCASplit.h @ 5406

Last change on this file since 5406 was 4890, checked in by ldelgass, 9 years ago

merge r3627:3628 from trunk

  • Property svn:eol-style set to native
File size: 3.5 KB
RevLine 
[2798]1/* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */
[3502]2/*
3 * Copyright (c) 2004-2013  HUBzero Foundation, LLC
4 *
5 */
[4889]6#ifndef PCA_PCASPLIT_H
7#define PCA_PCASPLIT_H
[835]8
[846]9#include <memory.h>
[2832]10
[3492]11#include <vrmath/Vector3f.h>
[4890]12#include <vrmath/Color4f.h>
[846]13
14namespace PCA {
15
[2832]16class Point
17{
18public:
19    Point() :
20        size(1.0f),
21        value(0.0f)
22    {}
23
[3492]24    vrmath::Vector3f position;
[4890]25    vrmath::Color4f color;
[2832]26    float size;
[846]27    float value;
28};
29
[2832]30class Cluster
31{
32public:
33    Cluster() :
[2844]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),
[2832]38        numOfPoints(0),
[2844]39        points(NULL),
40        children(NULL),
41        vbo(0),
42        level(0)
[2832]43    {
44    }
[846]45
[2832]46    void setChildren(Cluster *children, int count)
47    {
48        this->children = children;
49        numOfChildren = count;
50    }
[2844]51
[2832]52    void setPoints(Point *points, int count)
53    {
54        this->points = points;
55        numOfPoints = count;
56    }
[846]57
[3492]58    vrmath::Vector3f centroid;
[4890]59    vrmath::Color4f color;
[2832]60    float scale;
[846]61
[2832]62    int numOfChildren;
63    int numOfPoints;
64    Point *points;
65    Cluster *children;
66    unsigned int vbo;
67    int level;
68};
[846]69
[2832]70class ClusterAccel
71{
72public:
[2844]73    ClusterAccel(int maxlevel) :
74        root(NULL),
75        maxLevel(maxlevel)
[2832]76    {
77        startPointerCluster = new Cluster *[maxLevel];
78        numOfClusters = new int[maxLevel];
[2844]79        vbo = new unsigned int[maxLevel];
80        memset(vbo, 0, sizeof(unsigned int) * maxLevel);
[2832]81    }
[846]82
[2832]83    Cluster *root;
84    int maxLevel;
85    Cluster **startPointerCluster;
86    int *numOfClusters;
[2844]87    unsigned int *vbo;
[846]88};
89
[2832]90class Cluster_t
91{
92public:
93    Cluster_t() :
94        numOfPoints_t(0),
95        scale_t(0.0f),
96        points_t(0)
97    {}
98
[3492]99    vrmath::Vector3f centroid_t;
[2832]100    int numOfPoints_t;
101    float scale_t;
102    Point *points_t;
[846]103};
104
[2832]105class ClusterListNode
106{
107public:
108    ClusterListNode(Cluster_t *d, ClusterListNode *n) :
109        data(d),
110        next(n)
111    {}
[846]112
[2832]113    ClusterListNode() :
114        data(NULL),
115        next(NULL)
116    {}
117
118    Cluster_t *data;
119    ClusterListNode *next;
[846]120};
121
[2832]122class PCASplit
123{
124public:
125    enum {
126        MAX_INDEX = 8000000
127    };
[846]128
[2832]129    PCASplit();
[846]130
[2832]131    ~PCASplit();
[846]132
[2832]133    ClusterAccel *doIt(Point *data, int count);
[846]134
[2832]135    void setMinDistance(float minDistance)
136    {
137        _minDistance = minDistance;
138    }
[846]139
[2832]140    void setMaxLevel(int maxLevel)
141    {
142        _maxLevel = maxLevel;
143    }
[846]144
[3492]145    static void computeDistortion(Point *data, int count, const vrmath::Vector3f& mean, float& distortion, float& maxSize);
[846]146
[3492]147    static void computeCentroid(Point *data, int count, vrmath::Vector3f& mean);
[846]148
[3492]149    static void computeCovariant(Point *data, int count, const vrmath::Vector3f& mean, float *m);
[846]150
[2832]151private:
152    void init();
[846]153
[2832]154    void analyze(ClusterListNode *cluster, Cluster *parent, int level, float limit);
[846]155
[2832]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
[934]184}
[846]185
186#endif
187
Note: See TracBrowser for help on using the repository browser.