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

Last change on this file since 3596 was 3502, checked in by ldelgass, 11 years ago

Add basic VTK structured points reader to nanovis, update copyright dates.

  • Property svn:eol-style set to native
File size: 2.7 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-2013  HUBzero Foundation, LLC
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 <GL/glew.h>
18
19#include "PlaneRenderer.h"
20#include "Trace.h"
21
22PlaneRenderer::PlaneRenderer(int width, int height) :
23    _activePlane(-1),
24    _numPlanes(0),
25    _renderWidth(width),
26    _renderHeight(height),
27    _shader(new NvColorTableShader())
28{
29    _plane.clear();
30    _tf.clear();
31}
32
33PlaneRenderer::~PlaneRenderer()
34{
35    delete _shader;
36}
37
38int
39PlaneRenderer::addPlane(Texture2D *p, TransferFunction *tfPtr)
40{
41    int ret = _numPlanes;
42
43    _plane.push_back(p);
44    _tf.push_back(tfPtr);
45
46    if (ret == 0)
47        _activePlane = ret;
48
49    _numPlanes++;
50    return ret;
51}
52
53void
54PlaneRenderer::removePlane(int index)
55{
56    std::vector<Texture2D *>::iterator piter = _plane.begin()+index;
57    std::vector<TransferFunction *>::iterator tfiter = _tf.begin()+index;
58
59    _plane.erase(piter);
60    _tf.erase(tfiter);
61
62    _numPlanes--;
63}
64
65void
66PlaneRenderer::render()
67{
68    if (_numPlanes == 0)
69        return;
70
71    glPushAttrib(GL_VIEWPORT_BIT | GL_ENABLE_BIT);
72
73    glEnable(GL_TEXTURE_2D);
74    glEnable(GL_BLEND);
75
76    glViewport(0, 0, _renderWidth, _renderHeight);
77    glMatrixMode(GL_PROJECTION);
78    glPushMatrix();
79    glLoadIdentity();
80    gluOrtho2D(0, _renderWidth, 0, _renderHeight);
81    glMatrixMode(GL_MODELVIEW);
82    glPushMatrix();
83    glLoadIdentity();
84
85    //glColor3f(1., 1., 1.);         //MUST HAVE THIS LINE!!!
86
87    //if no active plane
88    if (_activePlane == -1)
89        return;
90
91    _shader->bind(_plane[_activePlane], _tf[_activePlane]);
92    glBegin(GL_QUADS);
93    glTexCoord2f(0, 0); glVertex2f(0, 0);
94    glTexCoord2f(1, 0); glVertex2f(_renderWidth, 0);
95    glTexCoord2f(1, 1); glVertex2f(_renderWidth, _renderHeight);
96    glTexCoord2f(0, 1); glVertex2f(0, _renderHeight);
97    glEnd();
98    _shader->unbind();
99
100    glMatrixMode(GL_PROJECTION);
101    glPopMatrix();
102
103    glMatrixMode(GL_MODELVIEW);
104    glPopMatrix();
105
106    glPopAttrib();
107}
108
109void
110PlaneRenderer::setActivePlane(int index)
111{
112    _activePlane = index;
113}
114
115void
116PlaneRenderer::setScreenSize(int w, int h)
117{
118    _renderWidth = w;
119    _renderHeight = h;
120}
Note: See TracBrowser for help on using the repository browser.