source: nanovis/tags/1.2.0/nanovis.h @ 5724

Last change on this file since 5724 was 4937, checked in by ldelgass, 9 years ago

merge threading

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