source: trunk/packages/vizservers/nanovis/nanovis.h @ 3884

Last change on this file since 3884 was 3630, checked in by ldelgass, 11 years ago

Nanovis refactoring to fix problems with scaling and multiple results.
Do rendering in world space to properly place and scale multiple data sets.
Also fix flows to reduce resets of animations. More work toward removing
Cg dependency. Fix panning to convert viewport coords to world coords.

  • Property svn:eol-style set to native
File size: 5.2 KB
Line 
1/* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2/*
3 * ----------------------------------------------------------------------
4 *  nanovis.h: package header
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#ifndef NV_NANOVIS_H
17#define NV_NANOVIS_H
18
19#include <math.h>
20#include <stddef.h> // For size_t
21#include <stdio.h>
22#include <sys/time.h>
23#include <sys/types.h> // For pid_t
24
25#include <tcl.h>
26
27#include <GL/glew.h>
28
29#include <vector>
30#include <iostream>
31#include <tr1/unordered_map>
32
33#include <vrmath/BBox.h>
34#include <vrmath/Vector3f.h>
35
36#include "config.h"
37#include "Camera.h"
38#include "FlowTypes.h"
39#include "md5.h"
40
41//defines for the image based flow visualization
42#define NMESH 256       //resolution of flow mesh
43#define NPIX  512       //display size
44
45namespace nv {
46namespace graphics {
47    class RenderContext;
48}
49namespace util {
50    class Fonts;
51}
52
53class Flow;
54class Grid;
55class HeightMap;
56class LIC;
57class OrientationIndicator;
58class PlaneRenderer;
59class Texture2D;
60class TransferFunction;
61class VelocityArrowsSlice;
62class Volume;
63class VolumeRenderer;
64
65class NanoVis
66{
67public:
68    typedef std::string TransferFunctionId;
69    typedef std::string VolumeId;
70    typedef std::string FlowId;
71    typedef std::string HeightMapId;
72    typedef std::tr1::unordered_map<TransferFunctionId, TransferFunction *> TransferFunctionHashmap;
73    typedef std::tr1::unordered_map<VolumeId, Volume *> VolumeHashmap;
74    typedef std::tr1::unordered_map<FlowId, Flow *> FlowHashmap;
75    typedef std::tr1::unordered_map<HeightMapId, HeightMap *> HeightMapHashmap;
76
77    static bool init(const char *path);
78    static bool initGL();
79    static bool initOffscreenBuffer();
80    static bool resizeOffscreenBuffer(int w, int h);
81    static void setBgColor(float color[3]);
82    static void render();
83    static void update();
84    static void removeAllData();
85
86    static const Camera *getCamera()
87    {
88        return _camera;
89    }
90    static void panCamera(float dx, float dy);
91    static void zoomCamera(float z);
92    static void orientCamera(double *quat);
93    static void setCameraPosition(vrmath::Vector3f pos);
94    static void setCameraUpdir(Camera::AxisDirection dir);
95    static void resetCamera(bool resetOrientation = false);
96
97    static void eventuallyRedraw();
98 
99    static TransferFunction *getTransferFunction(const TransferFunctionId& id);
100    static TransferFunction *defineTransferFunction(const TransferFunctionId& id,
101                                                    size_t n, float *data);
102
103    static int renderLegend(TransferFunction *tf, double min, double max,
104                            int width, int height, const char *volArg);
105
106    static Volume *loadVolume(const char *tag, int width, int height, int depth,
107                              int numComponents, float *data, double vmin, double vmax,
108                              double nonZeroMin);
109
110    static void removeVolume(Volume *volume);
111
112    static void readScreen()
113    {
114        glPixelStorei(GL_PACK_ALIGNMENT, 1);
115        glReadPixels(0, 0, winWidth, winHeight, GL_RGB, GL_UNSIGNED_BYTE,
116                     screenBuffer);
117    }
118    static void bindOffscreenBuffer()
119    {
120        glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, _finalFbo);
121    }
122
123    static void setVolumeRanges();
124    static void setHeightmapRanges();
125    static bool mapFlows();
126
127    static Flow *getFlow(const char *name);
128    static Flow *createFlow(Tcl_Interp *interp, const char *name);
129    static void deleteFlows(Tcl_Interp *interp);
130    static void deleteFlow(const char *name);
131    static void getFlowBounds(vrmath::Vector3f& min,
132                              vrmath::Vector3f& max,
133                              bool onlyVisible = false);
134    static void renderFlows();
135    static void resetFlows();
136    static bool updateFlows();
137    static void advectFlows();
138
139    static Tcl_Interp *interp;
140
141    static bool redrawPending;
142    static bool debugFlag;
143
144    static int winWidth;        ///< Width of the render window
145    static int winHeight;       ///< Height of the render window
146    static int renderWindow;    ///< GLUT handle for the render window
147    static unsigned char *screenBuffer;
148    static Texture2D *legendTexture;
149    static util::Fonts *fonts;
150    static graphics::RenderContext *renderContext;
151
152    static TransferFunctionHashmap tfTable; ///< maps transfunc name to TransferFunction object
153    static VolumeHashmap volumeTable;
154    static FlowHashmap flowTable;
155    static HeightMapHashmap heightMapTable;
156
157    static vrmath::BBox sceneBounds;
158
159    static VolumeRenderer *volRenderer;
160    static VelocityArrowsSlice *velocityArrowsSlice;
161    static LIC *licRenderer;
162    static PlaneRenderer *planeRenderer;
163    static OrientationIndicator *orientationIndicator;
164    static Grid *grid;
165
166private:
167    static void collectBounds(bool onlyVisible = false);
168
169    static Camera *_camera;
170
171    //frame buffer for final rendering
172    static GLuint _finalFbo, _finalColorTex, _finalDepthRb;
173};
174
175}
176
177#endif
Note: See TracBrowser for help on using the repository browser.