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

Last change on this file since 2824 was 2798, checked in by ldelgass, 12 years ago

Add emacs mode magic line in preparation for indentation cleanup

  • Property svn:eol-style set to native
File size: 3.1 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#include "Vector3.h"
7#include "Vector4.h"
8
9namespace PCA {
10
11class Point {
12public :
13        Vector3 position;
14        // histogram Index;
15        //unsigned char color;
16        Vector4 color;
17        float size;
18    float value;
19public :
20        Point() : size(1.0f), value(0.0f) {}
21};
22
23
24
25class Cluster {
26public :
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
38public :
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
65class ClusterAccel {
66public :
67        Cluster* root;
68        int maxLevel;
69        Cluster** startPointerCluster;
70        int* numOfClusters;
71        unsigned int* _vbo;
72public :
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
83class Cluster_t {
84public :
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
94class ClusterListNode {
95public :
96        Cluster_t* data;
97        ClusterListNode* next;
98public :
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
109class PCASplit {
110        enum {
111                MAX_INDEX =8000000
112        };
113private :
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;
132public :
133        PCASplit();
134        ~PCASplit();
135public :
136        ClusterAccel* doIt(Point* data, int count);
137    void setMinDistance(const float minDistance);
138    void setMaxLevel(int maxLevel);
139
140private :       
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);
147public :
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
153inline void PCASplit::setMinDistance(const float minDistance)
154{
155    _minDistance = minDistance;
156}
157
158inline void PCASplit::setMaxLevel(int maxLevel)
159{
160    _maxLevel = maxLevel;
161}
162
163}
164
165#endif
166
Note: See TracBrowser for help on using the repository browser.