Ignore:
Timestamp:
Dec 13, 2007 7:24:01 PM (16 years ago)
Author:
vrinside
Message:

Added color blending with point sprite texture

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/vizservers/nanovis/PointSet.cpp

    r825 r827  
    22#include "PCASplit.h"
    33#include <stdlib.h>
     4#include <stdio.h>
    45
    56PointSet::PointSet()
    6 : _visible(false), _cluster(0), _sortLevel(4)
     7: _visible(false), _cluster(0), _sortLevel(4), _min(0.0f), _max(1.0f)
    78{
    89}
     
    1617}
    1718
    18 void PointSet::initialize(Vector4* values, const unsigned int count)
     19void PointSet::initialize(Vector4* values, const unsigned int count, const Vector3& scale, const Vector3& origin, float min, float max)
    1920{
    2021    PCA::PCASplit pcaSplit;
     22
     23    _scale = scale;
     24    _origin = origin;
     25    _min = min;
     26    _max = max;
    2127
    2228    PCA::Point* points = (PCA::Point*) malloc(sizeof(PCA::Point) * count);
     
    2430    {
    2531        points[i].position.set(values[i].x, values[i].y, values[i].z);
    26 
    27         // TBD
    2832        points[i].color.set(1.0f, 1.0f, 1.0f, 0.2f);
    29 
    3033        points[i].value = values[i].w;
     34        points[i].size = 0.001;
    3135    }
    3236
     
    3539        delete _cluster;
    3640    }
    37 
    3841   
     42    pcaSplit.setMinDistance(scale.length() / 3.0f);
    3943    _cluster = pcaSplit.doIt(points, count);
    4044}
    4145
    42 void PointSet::updateColor()
     46void PointSet::updateColor(float* color,  int colorCount)
    4347{
    44    
     48        if (_cluster == 0) return;
     49
     50    int level = 4;
     51
     52        PCA::Cluster* cluster = _cluster->startPointerCluster[level - 1];
     53        PCA::Cluster* c = &(cluster[0]);
     54        PCA::Cluster* end = &(cluster[_cluster->numOfClusters[level - 1] - 1]);
     55
     56        Vector3 pos;
     57       
     58    PCA::Point* points;
     59    Vector4* colors = (Vector4*) color;
     60        int numOfPoints;
     61    int index;
     62    float d = _max - _min;
     63        for (; c <= end; c = (PCA::Cluster*) ((int) c + sizeof(PCA::Cluster)))
     64        {
     65        points = c->points;
     66        numOfPoints = c->numOfPoints;
     67
     68        for (int i = 0; i < numOfPoints; ++i)
     69        {
     70            index = (points[i].value - _min) / d  * (colorCount - 1);
     71            if (index >= colorCount) index = colorCount - 1;
     72            //printf("TEST %f %d/%d -> %d (%f %f %f)\n", points[i].value, i, numOfPoints, index,
     73            //                                    colors[index].x, colors[index].y, colors[index].z);
     74            //fflush(stdout);
     75            points[i].color = colors[index];
     76        }
     77
     78        }
    4579}
    4680
Note: See TracChangeset for help on using the changeset viewer.