Ignore:
Timestamp:
Mar 9, 2012 11:50:51 AM (12 years ago)
Author:
ldelgass
Message:

Formatting fixes

Location:
trunk/packages/vizservers/nanovis
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/packages/vizservers/nanovis/NvFlowVisRenderer.h

    r2817 r2832  
    2424
    2525class NvFlowVisRenderer {
    26     enum {
    27         MAX_PARTICLE_RENDERER = 4,
    28     };
    29 
    30     int _psys_width;
    31     int _psys_height;
    32     CGcontext context;
    33 
    34     std::map<std::string, NvVectorField*> _vectorFieldMap;
    35 
    36     bool _activated;
    37 
    38     //NvLIC* licRenderer[3];
    3926public:
    4027    NvFlowVisRenderer(int w, int h, CGcontext context);
     28
    4129    ~NvFlowVisRenderer();
    4230
    4331    void initialize();
     32
    4433    void initialize(const std::string& vfName);
     34
    4535    void advect();
     36
    4637    void reset();
     38
    4739    void render();
    4840
    49     void addVectorField(Volume* volPtr, const Vector3& ori, float scaleX,
    50                         float scaleY, float scaleZ, float max);
     41    void addVectorField(Volume *volPtr, const Vector3& ori, float scaleX,
     42                        float scaleY, float scaleZ, float max);
    5143
    52     void addVectorField(const std::string& vfName, Volume* volPtr, const Vector3& ori, float scaleX, float scaleY, float scaleZ, float max);
     44    void addVectorField(const std::string& vfName, Volume *volPtr, const Vector3& ori,
     45                        float scaleX, float scaleY, float scaleZ, float max);
     46
    5347    void removeVectorField(const std::string& vfName);
    5448
    5549    void addPlane(const std::string& vfName, const std::string& name);
     50
    5651    void removePlane(const std::string& vfName, const std::string& name);
    5752
     
    6661     */
    6762    void setPlanePos(const std::string& vfName, const std::string& name, float pos);
     63
    6864    void setParticleColor(const std::string& vfName, const std::string& name, const Vector4& color);
     65
    6966    void activatePlane(const std::string& vfName, const std::string& name);
     67
    7068    void deactivatePlane(const std::string& vfName, const std::string& name);
    7169
    7270    void activateVectorField(const std::string& vfName);
     71
    7372    void deactivateVectorField(const std::string& vfName);
    7473
     
    7675    // DEVICE SHAPE
    7776    void addDeviceShape(const std::string& vfName, const std::string& name, const NvDeviceShape& shape);
     77
    7878    void removeDeviceShape(const std::string& vfName, const std::string& name);
     79
    7980    void activateDeviceShape(const std::string& vfName);
     81
    8082    void deactivateDeviceShape(const std::string& vfName);
     83
    8184    void activateDeviceShape(const std::string& vfName, const std::string& name);
     85
    8286    void deactivateDeviceShape(const std::string& vfName, const std::string& name);
    83     bool active(void) {
     87
     88    bool active()
     89    {
    8490        return _activated;
    8591    }
    86     void active(bool state) {
     92
     93    void active(bool state)
     94    {
    8795        _activated = state;
    8896    }
     97
     98private:
     99    int _psys_width;
     100    int _psys_height;
     101    CGcontext context;
     102
     103    std::map<std::string, NvVectorField *> _vectorFieldMap;
     104
     105    bool _activated;
    89106};
    90107
  • trunk/packages/vizservers/nanovis/PCASplit.cpp

    r2822 r2832  
    11/* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */
    22#include <stdio.h>
    3 #include "PCASplit.h"
    43
    54#define WANT_STREAM                  // include.h will get stream fns
     
    109#include <newmatrc.h>
    1110
     11#include "PCASplit.h"
     12
    1213#ifdef use_namespace
    1314using namespace NEWMAT;              // access NEWMAT namespace
    1415#endif
    1516
    16 namespace PCA {
     17using namespace PCA;
    1718
    1819PCASplit::PCASplit() :
    19     _maxLevel(4), 
    20     _minDistance(0.5f), 
    21     _distanceScale(0.2f), 
    22     _indexCount(0), 
     20    _maxLevel(4),
     21    _minDistance(0.5f),
     22    _distanceScale(0.2f),
     23    _indexCount(0),
    2324    _finalMaxLevel(0)
    2425{
     
    3839
    3940void
    40 PCASplit::computeCentroid(Point* data, int count, Vector3& mean)
    41 {
    42     float sumx= 0, sumy = 0, sumz = 0;
     41PCASplit::computeCentroid(Point *data, int count, Vector3& mean)
     42{
     43    float sumx = 0, sumy = 0, sumz = 0;
    4344    float size = 0;
    4445    float sumsize = 0;
     
    5556
    5657void
    57 PCASplit::computeCovariant(Point* data, int count, const Vector3& mean,
    58                            float* m)
     58PCASplit::computeCovariant(Point *data, int count, const Vector3& mean,
     59                           float *m)
    5960{
    6061    memset(m, 0, sizeof(float) * 9);
     
    8283
    8384void
    84 PCASplit::computeDistortion(Point* data, int count, const Vector3& mean,
     85PCASplit::computeDistortion(Point *data, int count, const Vector3& mean,
    8586                            float& distortion, float& finalSize)
    8687{
     
    9192    float distance;
    9293    for (int i = 0; i < count; ++i) {
    93         // sum
    94         distance = mean.distanceSquare(data[i].position.x, data[i].position.y, data[i].position.z);
    95         distortion += distance;
    96        
    97         if (data[i].size > maxSize) {
    98             maxSize = data[i].size;
    99         }
    100        
    101         /*
    102           finalSize += data[i].size * sqrt(distance);
    103         */
    104         if (distance > finalSize) {
    105             finalSize = distance;
    106         }
     94        // sum
     95        distance = mean.distanceSquare(data[i].position.x, data[i].position.y, data[i].position.z);
     96        distortion += distance;
     97
     98        if (data[i].size > maxSize) {
     99            maxSize = data[i].size;
     100        }
     101
     102        /*
     103          finalSize += data[i].size * sqrt(distance);
     104        */
     105        if (distance > finalSize) {
     106            finalSize = distance;
     107        }
    107108    }
    108109    // equation 2
     
    110111    finalSize = sqrt (finalSize) + maxSize;
    111112}
    112        
     113     
    113114void
    114115PCASplit::init()
     
    118119}
    119120
    120 Cluster*
    121 PCASplit::createClusterBlock(ClusterListNode* clusterList, int count, int level)
     121Cluster *
     122PCASplit::createClusterBlock(ClusterListNode *clusterList, int count, int level)
    122123{
    123124    static int cc = 0;
    124125    cc += count;
    125     Cluster* clusterBlock = new Cluster[count];
     126    Cluster *clusterBlock = new Cluster[count];
    126127
    127128    _clusterHeader->numOfClusters[level - 1] = count;
     
    129130
    130131    TRACE("Cluster created %d [in level %d]:total %d\n", count, level, cc);
    131        
     132
    132133    int i = 0;
    133     ClusterListNode* clusterNode = clusterList;
     134    ClusterListNode *clusterNode = clusterList;
    134135    while (clusterNode) {
    135         clusterBlock[i].centroid = clusterList->data->centroid_t;
    136         clusterBlock[i].level = level;
    137         clusterBlock[i].scale = clusterList->data->scale_t;
    138        
    139         clusterNode = clusterNode->next;
    140         ++i;
     136        clusterBlock[i].centroid = clusterList->data->centroid_t;
     137        clusterBlock[i].level = level;
     138        clusterBlock[i].scale = clusterList->data->scale_t;
     139
     140        clusterNode = clusterNode->next;
     141        ++i;
    141142    }
    142143    if (count != i) {
    143         ERROR("Problem walking clusterList: count: %d, i: %d\n", count, i);
     144        ERROR("Problem walking clusterList: count: %d, i: %d\n", count, i);
    144145    }
    145146    return clusterBlock;
    146147}
    147148
    148 ClusterAccel* PCASplit::doIt(Point* data, int count)
     149ClusterAccel *
     150PCASplit::doIt(Point *data, int count)
    149151{
    150152    init();
    151153
    152154    _clusterHeader = new ClusterAccel(_maxLevel);
    153        
    154     Cluster* root = new Cluster;
    155     Cluster_t* cluster_t = new Cluster_t();
     155
     156    Cluster *root = new Cluster;
     157    Cluster_t *cluster_t = new Cluster_t();
    156158    cluster_t->points_t = data;
    157159    cluster_t->numOfPoints_t = count;
    158160    root->level = 1;
    159        
     161
    160162    _clusterHeader->root = root;
    161163    _clusterHeader->numOfClusters[0] = 1;
    162164    _clusterHeader->startPointerCluster[0] = root;
    163        
     165
    164166    Vector3 mean;
    165167    float distortion, scale;
    166        
     168
    167169    computeCentroid(cluster_t->points_t, cluster_t->numOfPoints_t, mean);
    168170    computeDistortion(cluster_t->points_t, cluster_t->numOfPoints_t, mean,
    169171                      distortion, scale);
    170        
     172
    171173    cluster_t->centroid_t = mean;
    172174    cluster_t->scale_t = scale;
    173        
     175
    174176    float mindistance = _minDistance;
    175177    int level = 2;
    176178
    177     ClusterListNode* clustNodeList = &(_memClusterChunk2[0]);
     179    ClusterListNode *clustNodeList = &(_memClusterChunk2[0]);
    178180    clustNodeList->data = cluster_t;
    179181    clustNodeList->next = 0;
    180        
     182
    181183    _curRoot = root;
    182184    do {
     
    192194
    193195        clustNodeList = _curClusterNode;
    194 
    195196    } while (level <= _maxLevel);
    196197
     
    199200
    200201void
    201 PCASplit::addLeafCluster(Cluster_t* cluster)
    202 {
    203     ClusterListNode* clusterNode =
    204         &_curMemClusterChunk[_memClusterChunkIndex++];
     202PCASplit::addLeafCluster(Cluster_t *cluster)
     203{
     204    ClusterListNode *clusterNode =
     205        &_curMemClusterChunk[_memClusterChunkIndex++];
    205206    clusterNode->data = cluster;
    206207    clusterNode->next = _curClusterNode;
     
    210211
    211212void
    212 PCASplit::split(Point* data, int count, float limit)
     213PCASplit::split(Point *data, int count, float limit)
    213214{
    214215    Vector3 mean;
     
    218219    float scale, distortion;
    219220    computeDistortion(data, count, mean, distortion, scale);
    220        
     221
    221222    //if (distortion < limit)
    222223    if (scale < limit) {
    223         Cluster_t* cluster_t = new Cluster_t();
     224        Cluster_t *cluster_t = new Cluster_t();
    224225        cluster_t->centroid_t = mean;
    225226        cluster_t->points_t = data;
     
    229230        return;
    230231    }
    231    
     232
    232233    computeCovariant(data, count, mean, m);
    233    
     234
    234235    SymmetricMatrix A(3);
    235236    for (int i = 1; i <= 3; ++i) {
     
    238239        }
    239240    }
    240        
    241     Matrix U; DiagonalMatrix D;
     241
     242    Matrix U;
     243    DiagonalMatrix D;
    242244    eigenvalues(A,D,U);
    243245    Vector3 emax(U(1, 3), U(2, 3), U(3, 3));
    244    
     246
    245247    int left = 0, right = count - 1;
    246    
     248
    247249    Point p;
    248250    for (;left < right;) {
    249         while (left < count && emax.dot(data[left].position - mean) >= 0.0f) {
    250             ++left;
    251         }
    252         while (right >= 0 && emax.dot(data[right].position - mean) < 0.0f) {
    253             --right;
    254         }
    255         if (left > right) {
    256             break;
    257         }
    258        
    259         p = data[left];
    260         data[left] = data[right];
    261         data[right] = p;
    262         ++left, --right;
    263        
    264     }
    265    
     251        while (left < count && emax.dot(data[left].position - mean) >= 0.0f) {
     252            ++left;
     253        }
     254        while (right >= 0 && emax.dot(data[right].position - mean) < 0.0f) {
     255            --right;
     256        }
     257        if (left > right) {
     258            break;
     259        }
     260
     261        p = data[left];
     262        data[left] = data[right];
     263        data[right] = p;
     264        ++left, --right;
     265    }
     266
    266267    if (left == 0 || right == count - 1) {
    267         TRACE("error\n");
    268         exit(1);
     268        TRACE("error\n");
     269        exit(1);
    269270    } else {
    270         split(data, left, limit);
    271         split(data + left, count - left, limit);
    272     }
    273 }
    274 
    275 void
    276 PCASplit::analyze(ClusterListNode* clusterNode, Cluster* parent, int level,
     271        split(data, left, limit);
     272        split(data + left, count - left, limit);
     273    }
     274}
     275
     276void
     277PCASplit::analyze(ClusterListNode *clusterNode, Cluster *parent, int level,
    277278                  float limit)
    278279{
    279280    if (level > _maxLevel) {
    280         return;
     281        return;
    281282    }
    282283    if (level > _finalMaxLevel) {
    283         _finalMaxLevel = level;
    284     }
    285        
     284        _finalMaxLevel = level;
     285    }
     286
    286287    init();
    287288
    288     ClusterListNode* clNode = clusterNode;
    289        
     289    ClusterListNode *clNode = clusterNode;
     290
    290291    // initialize the indexCount of indices
    291292    _indexCount = 0;
    292293    while (clNode) {
    293         if (clNode->data) {
    294             split(clNode->data->points_t, clNode->data->numOfPoints_t, limit);
    295             _indices[_indexCount++] = _curClusterCount;
    296         }
    297         clNode = clNode->next;
    298     }
    299        
     294        if (clNode->data) {
     295            split(clNode->data->points_t, clNode->data->numOfPoints_t, limit);
     296            _indices[_indexCount++] = _curClusterCount;
     297        }
     298        clNode = clNode->next;
     299    }
     300
    300301    //Vector3 mean;
    301302    //computeCentroid(cluster->points, cluster->numOfPoints, mean);
    302303
    303304    // the process values of split are in _curClusterNode and _curClusterCount
    304     ClusterListNode* curClusterNode = _curClusterNode;
     305    ClusterListNode *curClusterNode = _curClusterNode;
    305306    unsigned int curClusterNodeCount = _curClusterCount;
    306307
    307308    if (curClusterNodeCount) {
    308        
    309309        // create and init centroid
    310         Cluster* retClusterBlock =
    311             createClusterBlock(curClusterNode, curClusterNodeCount, level);
    312        
    313         _curRoot = retClusterBlock;
    314        
    315         if (level == _maxLevel) {
    316             ClusterListNode* node = curClusterNode;
    317             if (_indexCount > 0) {
    318                 // for parent
    319                 Point* points = new Point[curClusterNodeCount];
    320                
    321                 parent[0].setChildren(retClusterBlock, _indices[0]);
    322                 parent[0].setPoints(points, _indices[0]);
    323                
    324                 for (unsigned int i = 0, in = 0; i < curClusterNodeCount; ++i) {
    325                     if (i >= _indices[in]) {
    326                         in++;
    327                         parent[in].setChildren(retClusterBlock + _indices[in - 1], _indices[in] - _indices[in - 1]);
    328                         parent[in].setPoints(points + _indices[in - 1], _indices[in] - _indices[in - 1]);
    329                     }
    330                                        
    331                     retClusterBlock[i].scale = node->data->scale_t;
    332                     retClusterBlock[i].centroid = node->data->centroid_t;
    333                     retClusterBlock[i].points = node->data->points_t;
    334                     retClusterBlock[i].numOfPoints = node->data->numOfPoints_t;
    335                     retClusterBlock[i].color.set(float(rand()) / RAND_MAX,
    336                                                  float(rand()) / RAND_MAX,
    337                                                  float(rand()) / RAND_MAX,
    338                                                  0.2);
    339                    
    340                     points[i].position = node->data->centroid_t;
    341                     points[i].color.set(1.0f, 1.0f, 1.0f, 0.2f);
    342                     points[i].size = node->data->scale_t;
    343                    
    344                     node = node->next;
    345                 }
    346             }
    347         } else {
    348             Point* points = new Point[curClusterNodeCount];
    349             ClusterListNode* node = curClusterNode;
    350            
    351             if (_indexCount > 0) {
    352                 parent[0].setPoints(points, _indices[0]);
    353                 parent[0].setChildren(retClusterBlock, _indices[0]);
    354                 for (int k = 1; k < _indexCount; ++k) {
    355                     parent[k].setPoints(points + _indices[k - 1],
    356                                         _indices[k] - _indices[k - 1]);
    357                     parent[k].setChildren(retClusterBlock + _indices[k - 1],
    358                                           _indices[k] - _indices[k - 1]);
    359                 }
    360                                
    361                 // set points of sub-clusters
    362                 for (unsigned int i = 0; i < curClusterNodeCount; ++i) {
    363                     points[i].position = node->data->centroid_t;
    364                     points[i].color.set(1.0f, 1.0f, 1.0f, 0.2f);
    365                     points[i].size = node->data->scale_t;
    366                     node = node->next;
    367                 }
    368                
    369             }
    370         }
    371     }
    372 }
    373 
    374 } /*namespace PCA */
    375 
     310        Cluster *retClusterBlock =
     311            createClusterBlock(curClusterNode, curClusterNodeCount, level);
     312
     313        _curRoot = retClusterBlock;
     314
     315        if (level == _maxLevel) {
     316            ClusterListNode *node = curClusterNode;
     317            if (_indexCount > 0) {
     318                // for parent
     319                Point *points = new Point[curClusterNodeCount];
     320
     321                parent[0].setChildren(retClusterBlock, _indices[0]);
     322                parent[0].setPoints(points, _indices[0]);
     323
     324                for (unsigned int i = 0, in = 0; i < curClusterNodeCount; ++i) {
     325                    if (i >= _indices[in]) {
     326                        in++;
     327                        parent[in].setChildren(retClusterBlock + _indices[in - 1], _indices[in] - _indices[in - 1]);
     328                        parent[in].setPoints(points + _indices[in - 1], _indices[in] - _indices[in - 1]);
     329                    }
     330
     331                    retClusterBlock[i].scale = node->data->scale_t;
     332                    retClusterBlock[i].centroid = node->data->centroid_t;
     333                    retClusterBlock[i].points = node->data->points_t;
     334                    retClusterBlock[i].numOfPoints = node->data->numOfPoints_t;
     335                    retClusterBlock[i].color.set(float(rand()) / RAND_MAX,
     336                                                 float(rand()) / RAND_MAX,
     337                                                 float(rand()) / RAND_MAX,
     338                                                 0.2);
     339
     340                    points[i].position = node->data->centroid_t;
     341                    points[i].color.set(1.0f, 1.0f, 1.0f, 0.2f);
     342                    points[i].size = node->data->scale_t;
     343
     344                    node = node->next;
     345                }
     346            }
     347        } else {
     348            Point *points = new Point[curClusterNodeCount];
     349            ClusterListNode *node = curClusterNode;
     350
     351            if (_indexCount > 0) {
     352                parent[0].setPoints(points, _indices[0]);
     353                parent[0].setChildren(retClusterBlock, _indices[0]);
     354                for (int k = 1; k < _indexCount; ++k) {
     355                    parent[k].setPoints(points + _indices[k - 1],
     356                                        _indices[k] - _indices[k - 1]);
     357                    parent[k].setChildren(retClusterBlock + _indices[k - 1],
     358                                          _indices[k] - _indices[k - 1]);
     359                }
     360
     361                // set points of sub-clusters
     362                for (unsigned int i = 0; i < curClusterNodeCount; ++i) {
     363                    points[i].position = node->data->centroid_t;
     364                    points[i].color.set(1.0f, 1.0f, 1.0f, 0.2f);
     365                    points[i].size = node->data->scale_t;
     366                    node = node->next;
     367                }
     368            }
     369        }
     370    }
     371}
     372
  • trunk/packages/vizservers/nanovis/PCASplit.h

    r2798 r2832  
    11/* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */
    2 #ifndef __PCA_SPLIT_H__
    3 #define __PCA_SPLIT_H__
     2#ifndef PCA_SPLIT_H
     3#define PCA_SPLIT_H
    44
    55#include <memory.h>
     6
    67#include "Vector3.h"
    78#include "Vector4.h"
     
    910namespace PCA {
    1011
    11 class Point {
    12 public :
    13         Vector3 position;
    14         // histogram Index;
    15         //unsigned char color;
    16         Vector4 color;
    17         float size;
     12class Point
     13{
     14public:
     15    Point() :
     16        size(1.0f),
     17        value(0.0f)
     18    {}
     19
     20    Vector3 position;
     21    // histogram Index;
     22    //unsigned char color;
     23    Vector4 color;
     24    float size;
    1825    float value;
    19 public :
    20         Point() : size(1.0f), value(0.0f) {}
    2126};
    2227
     28class Cluster
     29{
     30public:
     31    Cluster() :
     32        color(1.0f, 1.0f, 1.0f, 1.0f),
     33        scale(0.0f),
     34        numOfChildren(0),
     35        numOfPoints(0),
     36        points(0),
     37        children(0),
     38        vbo(0)/*, minValue(0.0f), maxValue(0.0f)*/
     39        , level(0)
     40    {
     41    }
    2342
     43    void setChildren(Cluster *children, int count)
     44    {
     45        this->children = children;
     46        numOfChildren = count;
     47    }
     48    void setPoints(Point *points, int count)
     49    {
     50        this->points = points;
     51        numOfPoints = count;
     52    }
    2453
    25 class Cluster {
    26 public :
    27         Vector3 centroid;
    28         Vector4 color;
    29         float scale;
     54    Vector3 centroid;
     55    Vector4 color;
     56    float scale;
    3057
    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        
     58    int numOfChildren;
     59    int numOfPoints;
     60    Point *points;
     61    Cluster *children;
     62    unsigned int vbo;
     63    int level;
    6364};
    6465
    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         }
     66class ClusterAccel
     67{
     68public:
     69    ClusterAccel(int maxlevel)
     70        : root(0),
     71          maxLevel(maxlevel)
     72    {
     73        startPointerCluster = new Cluster *[maxLevel];
     74        numOfClusters = new int[maxLevel];
     75        _vbo = new unsigned int[maxLevel];
     76        memset(_vbo, 0, sizeof(unsigned int) * maxLevel);
     77    }
     78
     79    Cluster *root;
     80    int maxLevel;
     81    Cluster **startPointerCluster;
     82    int *numOfClusters;
     83    unsigned int *_vbo;
    8184};
    8285
    83 class Cluster_t {
    84 public :
    85         Vector3 centroid_t;
    86         int             numOfPoints_t;
    87         float   scale_t;
    88         Point*  points_t;
     86class Cluster_t
     87{
     88public:
     89    Cluster_t() :
     90        numOfPoints_t(0),
     91        scale_t(0.0f),
     92        points_t(0)
     93    {}
    8994
    90         Cluster_t() : numOfPoints_t(0), scale_t(0.0f), points_t(0)
    91                 {}
     95    Vector3 centroid_t;
     96    int numOfPoints_t;
     97    float scale_t;
     98    Point *points_t;
    9299};
    93100
    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         {}
     101class ClusterListNode
     102{
     103public:
     104    ClusterListNode(Cluster_t *d, ClusterListNode *n) :
     105        data(d),
     106        next(n)
     107    {}
    102108
    103         ClusterListNode()
    104                 : data(0), next(0)
    105         {}
     109    ClusterListNode() :
     110        data(NULL),
     111        next(NULL)
     112    {}
     113
     114    Cluster_t *data;
     115    ClusterListNode *next;
    106116};
    107117
     118class PCASplit
     119{
     120public:
     121    enum {
     122        MAX_INDEX = 8000000
     123    };
    108124
    109 class PCASplit {
    110         enum {
    111                 MAX_INDEX =8000000
    112         };
    113 private :
    114         ClusterListNode* _curClusterNode;
    115         ClusterListNode* _memClusterChunk1;
    116         ClusterListNode* _memClusterChunk2;
    117         ClusterListNode* _curMemClusterChunk;
     125    PCASplit();
    118126
    119         int _memClusterChunkIndex;
     127    ~PCASplit();
    120128
    121         Cluster* _curRoot;
     129    ClusterAccel *doIt(Point *data, int count);
    122130
    123         int _curClusterCount;
    124         int _maxLevel;
    125         float _minDistance;
    126         float _distanceScale;
    127         unsigned int* _indices;
    128         int _indexCount;
    129         int _finalMaxLevel;
     131    void setMinDistance(float minDistance)
     132    {
     133        _minDistance = minDistance;
     134    }
    130135
    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);
     136    void setMaxLevel(int maxLevel)
     137    {
     138        _maxLevel = maxLevel;
     139    }
    139140
    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);
     141    static void computeDistortion(Point *data, int count, const Vector3& mean, float& distortion, float& maxSize);
     142
     143    static void computeCentroid(Point *data, int count, Vector3& mean);
     144
     145    static void computeCovariant(Point *data, int count, const Vector3& mean, float *m);
     146
     147private:
     148    void init();
     149
     150    void analyze(ClusterListNode *cluster, Cluster *parent, int level, float limit);
     151
     152    void addLeafCluster(Cluster_t *cluster);
     153
     154    Cluster *createClusterBlock(ClusterListNode *clusterList, int count, int level);
     155
     156    void split(Point *data, int count, float maxDistortion);
     157
     158    float getMaxDistortionSquare(ClusterListNode *clusterList, int count);
     159
     160    ClusterAccel *_clusterHeader;
     161
     162    ClusterListNode *_curClusterNode;
     163    ClusterListNode *_memClusterChunk1;
     164    ClusterListNode *_memClusterChunk2;
     165    ClusterListNode *_curMemClusterChunk;
     166
     167    int _memClusterChunkIndex;
     168
     169    Cluster *_curRoot;
     170
     171    int _curClusterCount;
     172    int _maxLevel;
     173    float _minDistance;
     174    float _distanceScale;
     175    unsigned int *_indices;
     176    int _indexCount;
     177    int _finalMaxLevel;
    151178};     
    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 }
    162179
    163180}
Note: See TracChangeset for help on using the changeset viewer.