source: trunk/vizservers/nanovis/PointSetRenderer.cpp @ 825

Last change on this file since 825 was 825, checked in by vrinside, 14 years ago

Image Loader initialization

  • Add BMP loader in Nv.cpp

Point Renderer code added..

  • Put a data container and manage the containters with std::vector
  • Renderer 1) scale factor part should be taken into account
File size: 2.7 KB
Line 
1#include "Nv.h"
2#include <GL/gl.h>
3#include "PointSetRenderer.h"
4#include <PCASplit.h>
5#include <imgLoaders/Image.h>
6#include <imgLoaders/ImageLoaderFactory.h>
7#include <imgLoaders/ImageLoader.h>
8#include <stdio.h>
9#include <R2/R2FilePath.h>
10
11PointSetRenderer::PointSetRenderer()
12{
13    _shader = new PointShader();
14    R2string path = R2FilePath::getInstance()->getPath("particle2.bmp");
15    if (path.getLength() == 0)
16    {
17        printf("ERROR : file not found - %s\n", (const char*) path);
18        fflush(stdout);
19        return;
20    }
21   
22    ImageLoader* loader = ImageLoaderFactory::getInstance()->createLoader("bmp");
23    Image* image = loader->load(path, Image::IMG_RGBA);
24
25    if (image)
26    {
27        _pointTexture = new Texture2D(image->getWidth(), image->getHeight(), GL_UNSIGNED_BYTE, GL_LINEAR,   
28                                4, (float*) image->getImageBuffer());
29    }
30    else
31    {
32        printf("fail to load image [%s]\n", "particles2.bmp");
33    }
34
35    delete loader;
36
37    _bucketSort = new PCA::BucketSort(1024);
38}
39
40void PointSetRenderer::renderPoints(PCA::Point* points, int length)
41{
42    PCA::Point* p = points;
43    for (int i = 0; i < length; ++i)
44    {
45        glColor4f(p->color.x, p->color.y, p->color.z, p->color.w);
46        glVertex3f(p->position.x, p->position.y, p->position.z);
47   
48        ++p;
49    }
50}
51
52void PointSetRenderer::renderCluster(PCA::ClusterList** bucket, int size, int level)
53{
54    float quadratic[] = { 1.0f, 0.0f, 0.01f };
55
56
57    glPointParameterfvARB(GL_POINT_DISTANCE_ATTENUATION_ARB, quadratic);
58    glPointParameterfARB(GL_POINT_FADE_THRESHOLD_SIZE_ARB, 60.0f);
59    glPointParameterfARB(GL_POINT_SIZE_MIN_ARB, 1.0f);
60    glPointParameterfARB(GL_POINT_SIZE_MAX_ARB, 100);
61    glTexEnvf(GL_POINT_SPRITE_ARB, GL_COORD_REPLACE_ARB, GL_TRUE);
62
63    glEnable(GL_POINT_SPRITE_ARB);
64
65    bool setSize = false;
66    glBegin(GL_POINTS);
67
68    PCA::ClusterList* p;
69    for (int i = size - 1; i >= 0; --i)
70    {
71        p = bucket[i];
72        if (p)
73        {
74            if (!setSize)
75            {
76                _shader->setScale(p->data->points[0].size);
77                setSize = true;
78            }
79        }
80
81        while (p)
82        {
83            renderPoints(p->data->points, p->data->numOfPoints);
84
85            p = p->next;
86        }
87       
88    }
89
90    glEnd();
91
92    glDisable(GL_POINT_SPRITE_ARB);
93
94}
95
96void PointSetRenderer::render(PCA::ClusterAccel* cluster, const Mat4x4& mat, int sortLevel)
97{
98    _bucketSort->init();
99    _bucketSort->sort(cluster, mat, sortLevel);
100
101    _pointTexture->activate();
102    _shader->bind();
103    glPushMatrix();
104        glTranslatef(-0.5f, -0.5f, -0.5f);
105        renderCluster(_bucketSort->getBucket(), _bucketSort->getSize(), 4);
106    glPopMatrix();
107
108    _shader->unbind();
109    _pointTexture->deactivate();
110}
111
Note: See TracBrowser for help on using the repository browser.