source: trunk/packages/vizservers/nanovis/PlaneRenderer.cpp @ 2835

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

Exclude unused file from build, misc. cleanups

  • Property svn:eol-style set to native
File size: 3.4 KB
Line 
1/* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2/*
3 * ----------------------------------------------------------------------
4 * PlaneRenderer.cpp : PlaneRenderer class for volume visualization
5 *
6 * ======================================================================
7 *  AUTHOR:  Wei Qiao <qiaow@purdue.edu>
8 *           Purdue Rendering and Perceptualization Lab (PURPL)
9 *
10 *  Copyright (c) 2004-2006  Purdue Research Foundation
11 *
12 *  See the file "license.terms" for information on usage and
13 *  redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
14 * ======================================================================
15 */
16
17#include "global.h"
18#include "PlaneRenderer.h"
19#include "Trace.h"
20
21PlaneRenderer::PlaneRenderer(CGcontext _context, int _width, int _height) :
22    _active_plane(-1),
23    _n_planes(0),
24    _render_width(_width),
25    _render_height(_height),
26    _g_context(_context)
27{
28    _plane.clear();
29    _tf.clear();
30    init_shaders();
31}
32
33PlaneRenderer::~PlaneRenderer()
34{
35}
36
37//initialize the render shader
38void
39PlaneRenderer::init_shaders()
40{
41    //plane rendering shader
42    _fprog = LoadCgSourceProgram(_g_context, "one_plane.cg", CG_PROFILE_FP30,
43                                 NULL);
44    _data_param = cgGetNamedParameter(_fprog, "data");
45    _tf_param = cgGetNamedParameter(_fprog, "tf");
46    _render_param = cgGetNamedParameter(_fprog, "render_param");
47}
48
49int
50PlaneRenderer::add_plane(Texture2D* _p, TransferFunction* tfPtr)
51{
52    int ret = _n_planes;
53
54    _plane.push_back(_p);
55    _tf.push_back(tfPtr);
56
57    if (ret == 0)
58        _active_plane = ret;
59
60    _n_planes++;
61    return ret;
62}
63
64void
65PlaneRenderer::remove_plane(int index) {
66    std::vector<Texture2D*>::iterator piter = _plane.begin()+index;
67    std::vector<TransferFunction*>::iterator tfiter = _tf.begin()+index;
68
69    _plane.erase(piter);
70    _tf.erase(tfiter);
71
72    _n_planes--;
73}
74
75void
76PlaneRenderer::render()
77{
78    if (_n_planes == 0)
79        return;
80
81    glEnable(GL_TEXTURE_2D);
82    glEnable(GL_BLEND);
83
84    glViewport(0, 0, _render_width, _render_height);
85    glMatrixMode(GL_PROJECTION);
86    glLoadIdentity();
87    gluOrtho2D(0, _render_width, 0, _render_height);
88    glMatrixMode(GL_MODELVIEW);
89    glLoadIdentity();
90
91    //glColor3f(1., 1., 1.);         //MUST HAVE THIS LINE!!!
92
93    //if no active plane
94    if (_active_plane == -1)
95        return;
96
97    activate_shader(_active_plane);
98    glBegin(GL_QUADS);
99    glTexCoord2f(0, 0); glVertex2f(0, 0);
100    glTexCoord2f(1, 0); glVertex2f(_render_width, 0);
101    glTexCoord2f(1, 1); glVertex2f(_render_width, _render_height);
102    glTexCoord2f(0, 1); glVertex2f(0, _render_height);
103    glEnd();
104    deactivate_shader();
105
106}
107
108void
109PlaneRenderer::activate_shader(int index)
110{
111    cgGLSetTextureParameter(_data_param, _plane[index]->id);
112    cgGLSetTextureParameter(_tf_param, _tf[index]->id());
113    cgGLEnableTextureParameter(_data_param);
114    cgGLEnableTextureParameter(_tf_param);
115
116    cgGLSetParameter4f(_render_param, 0., 0., 0., 0.);
117
118    cgGLBindProgram(_fprog);
119    cgGLEnableProfile(CG_PROFILE_FP30);
120}
121
122void
123PlaneRenderer::deactivate_shader()
124{
125    cgGLDisableProfile(CG_PROFILE_FP30);
126    cgGLDisableTextureParameter(_data_param);
127    cgGLDisableTextureParameter(_tf_param);
128}
129
130void
131PlaneRenderer::set_active_plane(int index)
132{
133    _active_plane = index;
134}
135
136void
137PlaneRenderer::set_screen_size(int w, int h)
138{
139    _render_width = w;
140    _render_height = h;
141}
Note: See TracBrowser for help on using the repository browser.