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