[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 | |
---|
| 14 | namespace PCA { |
---|
| 15 | |
---|
[2832] | 16 | class Point |
---|
| 17 | { |
---|
| 18 | public: |
---|
| 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] | 30 | class Cluster |
---|
| 31 | { |
---|
| 32 | public: |
---|
| 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] | 70 | class ClusterAccel |
---|
| 71 | { |
---|
| 72 | public: |
---|
[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] | 90 | class Cluster_t |
---|
| 91 | { |
---|
| 92 | public: |
---|
| 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] | 105 | class ClusterListNode |
---|
| 106 | { |
---|
| 107 | public: |
---|
| 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] | 122 | class PCASplit |
---|
| 123 | { |
---|
| 124 | public: |
---|
| 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] | 151 | private: |
---|
| 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 | |
---|