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