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) {}


20  };


21 


22 


23 


24  class Cluster {


25  public :


26  Vector3 centroid;


27  Vector4 color;


28  int level;


29  float scale;


30 


31  int numOfChildren;


32  int numOfPoints;


33  Point* points;


34  Cluster* children;


35  unsigned int vbo;


36  public :


37  void setChildren(Cluster* children, int count)


38  {


39  this>children = children;


40  numOfChildren = count;


41  }


42  void setPoints(Point* points, int count)


43  {


44  this>points = points;


45  numOfPoints = count;


46  }


47 


48  Cluster() : color(1.0f, 1.0f, 1.0f, 1.0f), numOfChildren(0), numOfPoints(0),


49  points(0), children(0), scale(0.0f), vbo(0)/*, minValue(0.0f), maxValue(0.0f)*/


50  , level(0)


51  {


52  }


53  };


54 


55  class ClusterAccel {


56  public :


57  Cluster* root;


58  int maxLevel;


59  Cluster** startPointerCluster;


60  int* numOfClusters;


61  unsigned int* _vbo;


62  public :


63  ClusterAccel(int maxlevel)


64  : root(0), maxLevel(maxlevel)


65  {


66  startPointerCluster = new Cluster*[maxLevel];


67  numOfClusters = new int[maxLevel];


68  _vbo = new unsigned int[maxLevel];


69  memset(_vbo, 0, sizeof(unsigned int) * maxLevel);


70  }


71  };


72 


73  class Cluster_t {


74  public :


75  Vector3 centroid_t;


76  int numOfPoints_t;


77  float scale_t;


78  Point* points_t;


79 


80  Cluster_t() : numOfPoints_t(0), scale_t(0.0f), points_t(0)


81  {}


82  };


83 


84  class ClusterListNode {


85  public :


86  Cluster_t* data;


87  ClusterListNode* next;


88  public :


89  ClusterListNode(Cluster_t* d, ClusterListNode* n)


90  : data(d), next(n)


91  {}


92 


93  ClusterListNode()


94  : data(0), next(0)


95  {}


96  };


97 


98 


99  class PCASplit {


100  enum {


101  MAX_INDEX =8000000


102  };


103  private :


104  ClusterListNode* _curClusterNode;


105  ClusterListNode* _memClusterChunk1;


106  ClusterListNode* _memClusterChunk2;


107  ClusterListNode* _curMemClusterChunk;


108 


109  int _memClusterChunkIndex;


110 


111  Cluster* _curRoot;


112 


113  int _curClusterCount;


114  int _maxLevel;


115  float _minDistance;


116  float _distanceScale;


117  unsigned int* _indices;


118  int _indexCount;


119  int _finalMaxLevel;


120 


121  ClusterAccel* _clusterHeader;


122  public :


123  PCASplit();


124  ~PCASplit();


125  public :


126  ClusterAccel* doIt(Point* data, int count);


127 


128  private :


129  void init();


130  void analyze(ClusterListNode* cluster, Cluster* parent, int level, float limit);


131  void addLeafCluster(Cluster_t* cluster);


132  Cluster* createClusterBlock(ClusterListNode* clusterList, int count, int level);


133  void split(Point* data, int count, float maxDistortion);


134  float getMaxDistortionSquare(ClusterListNode* clusterList, int count);


135  public :


136  static void computeDistortion(Point* data, int count, const Vector3& mean, float& distortion, float& maxSize);


137  static void computeCentroid(Point* data, int count, Vector3& mean);


138  static void computeCovariant(Point* data, int count, const Vector3& mean, float* m);


139  };


140 


141  };


142 


143  #endif


144 

