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

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

Don't pollute namespace with using directives in headers, also prefer using
std:: prefix to 'using namespace std' in implementation files.

  • Property svn:eol-style set to native
File size: 3.3 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    m_fprog = LoadCgSourceProgram(g_context, "one_plane.cg", CG_PROFILE_FP30,
43        NULL);
44    m_data_param = cgGetNamedParameter(m_fprog, "data");
45    m_tf_param = cgGetNamedParameter(m_fprog, "tf");
46    m_render_param = cgGetNamedParameter(m_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(m_data_param, plane[index]->id);
112    cgGLSetTextureParameter(m_tf_param, tf[index]->id());
113    cgGLEnableTextureParameter(m_data_param);
114    cgGLEnableTextureParameter(m_tf_param);
115
116    cgGLSetParameter4f(m_render_param, 0., 0., 0., 0.);
117
118    cgGLBindProgram(m_fprog);
119    cgGLEnableProfile(CG_PROFILE_FP30);
120}
121
122void
123PlaneRenderer::deactivate_shader()
124{
125    cgGLDisableProfile(CG_PROFILE_FP30);
126    cgGLDisableTextureParameter(m_data_param);
127    cgGLDisableTextureParameter(m_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.