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

Last change on this file since 1489 was 1478, checked in by gah, 15 years ago

Fix volume management routines to handle deletion

File size: 3.3 KB
Line 
1
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    /*empty*/
36}
37
38//initialize the render shader
39void
40PlaneRenderer::init_shaders()
41{
42    //plane rendering shader
43    m_fprog = LoadCgSourceProgram(g_context, "one_plane.cg", CG_PROFILE_FP30,
44        NULL);
45    m_data_param = cgGetNamedParameter(m_fprog, "data");
46    m_tf_param = cgGetNamedParameter(m_fprog, "tf");
47    m_render_param = cgGetNamedParameter(m_fprog, "render_param");
48}
49
50
51int
52PlaneRenderer::add_plane(Texture2D* _p, TransferFunction* _tf)
53{
54    int ret = n_planes;
55
56    plane.push_back(_p);
57    tf.push_back(_tf);
58
59    if(ret==0)
60        active_plane = ret;
61
62    n_planes++;
63    return ret;
64}
65
66void
67PlaneRenderer::remove_plane(int index) {
68    vector<Texture2D*>::iterator piter = plane.begin()+index;
69    vector<TransferFunction*>::iterator tfiter = tf.begin()+index;
70
71    plane.erase(piter);
72    tf.erase(tfiter);
73
74    n_planes--;
75}
76
77
78void
79PlaneRenderer::render()
80{
81    if (n_planes == 0)
82        return;
83
84    glEnable(GL_TEXTURE_2D);
85    glEnable(GL_BLEND);
86
87    glViewport(0, 0, render_width, render_height);
88    glMatrixMode(GL_PROJECTION);
89    glLoadIdentity();
90    gluOrtho2D(0, render_width, 0, render_height);
91    glMatrixMode(GL_MODELVIEW);
92    glLoadIdentity();
93
94    //glColor3f(1.,1.,1.);         //MUST HAVE THIS LINE!!!
95
96    //if no active plane
97    if(active_plane == -1)
98        return;
99
100    activate_shader(active_plane);
101    glBegin(GL_QUADS);
102    glTexCoord2f(0, 0); glVertex2f(0, 0);
103    glTexCoord2f(1, 0); glVertex2f(render_width, 0);
104    glTexCoord2f(1, 1); glVertex2f(render_width, render_height);
105    glTexCoord2f(0, 1); glVertex2f(0, render_height);
106    glEnd();
107    deactivate_shader();
108
109}
110
111void
112PlaneRenderer::activate_shader(int index)
113{
114
115    cgGLSetTextureParameter(m_data_param, plane[index]->id);
116    cgGLSetTextureParameter(m_tf_param, tf[index]->id);
117    cgGLEnableTextureParameter(m_data_param);
118    cgGLEnableTextureParameter(m_tf_param);
119
120    cgGLSetParameter4f(m_render_param, 0., 0., 0., 0.);
121
122    Trace("activate_shader: binding ");
123    cgGLBindProgram(m_fprog);
124    Trace("activate_shader: done binding");
125    cgGLEnableProfile(CG_PROFILE_FP30);
126}
127
128
129void
130PlaneRenderer::deactivate_shader()
131{
132    cgGLDisableProfile(CG_PROFILE_FP30);
133    cgGLDisableTextureParameter(m_data_param);
134    cgGLDisableTextureParameter(m_tf_param);
135}
136
137void
138PlaneRenderer::set_active_plane(int index)
139{
140    active_plane = index;
141}
142
143void
144PlaneRenderer::set_screen_size(int w, int h)
145{
146    render_width = w;
147    render_height = h;
148}
Note: See TracBrowser for help on using the repository browser.