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