source: nanovis/branches/1.1/nanovis.h @ 4889

Last change on this file since 4889 was 4889, checked in by ldelgass, 5 years ago

Merge r3611:3618 from trunk

  • Property svn:eol-style set to native
File size: 5.5 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
31//defines for the image based flow visualization
32#define NMESH 256       //resolution of flow mesh
33#define NPIX  512       //display size
34
35namespace nv {
36namespace graphics {
37    class RenderContext;
38}
39namespace util {
40    class Fonts;
41}
42
43class Camera;
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    enum AxisDirections { 
59        X_POS = 1,
60        Y_POS = 2,
61        Z_POS = 3,
62        X_NEG = -1,
63        Y_NEG = -2,
64        Z_NEG = -3
65    };
66
67    enum NanoVisFlags { 
68        REDRAW_PENDING = (1 << 0), 
69        MAP_FLOWS = (1 << 1)
70    };
71
72    typedef std::string TransferFunctionId;
73    typedef std::string VolumeId;
74    typedef std::string FlowId;
75    typedef std::string HeightMapId;
76    typedef std::tr1::unordered_map<TransferFunctionId, TransferFunction *> TransferFunctionHashmap;
77    typedef std::tr1::unordered_map<VolumeId, Volume *> VolumeHashmap;
78    typedef std::tr1::unordered_map<FlowId, Flow *> FlowHashmap;
79    typedef std::tr1::unordered_map<HeightMapId, HeightMap *> HeightMapHashmap;
80
81    static bool init(const char *path);
82    static bool initGL();
83    static bool initOffscreenBuffer();
84    static bool resizeOffscreenBuffer(int w, int h);
85    static void setBgColor(float color[3]);
86    static void render();
87    static void draw3dAxis();
88    static void update();
89    static void removeAllData();
90
91    static const Camera *getCamera()
92    {
93        return cam;
94    }
95    static void pan(float dx, float dy);
96    static void zoom(float z);
97    static void resetCamera(bool resetOrientation = false);
98
99    static void eventuallyRedraw(unsigned int flag = 0);
100
101    static void ppmWrite(const char *prefix);
102    static void bmpWrite(const char *prefix);
103    static void bmpWriteToFile(int frameNum, const char* dirName);
104 
105    static TransferFunction *getTransferFunction(const TransferFunctionId& id);
106    static TransferFunction *defineTransferFunction(const TransferFunctionId& id, 
107                                                    size_t n, float *data);
108
109    static int renderLegend(TransferFunction *tf, double min, double max, 
110                            int width, int height, const char *volArg);
111
112    static Volume *loadVolume(const char *tag, int width, int height, int depth,
113                              int numComponents, float *data, double vmin, double vmax, 
114                              double nonZeroMin);
115
116    static void removeVolume(Volume *volume);
117
118    static void readScreen()
119    {
120        //glPixelStorei(GL_PACK_ALIGNMENT, 1);
121        glReadPixels(0, 0, winWidth, winHeight, GL_RGB, GL_UNSIGNED_BYTE, 
122                     screenBuffer);
123    }
124    static void bindOffscreenBuffer()
125    {
126        glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, _finalFbo);
127    }
128
129    static void setVolumeRanges();
130    static void setHeightmapRanges();
131
132    static Flow *getFlow(const char *name);
133    static Flow *createFlow(Tcl_Interp *interp, const char *name);
134    static void deleteFlows(Tcl_Interp *interp);
135    static void deleteFlow(const char *name);
136    static bool mapFlows();
137    static void getFlowBounds(vrmath::Vector3f& min,
138                              vrmath::Vector3f& max,
139                              bool onlyVisible = false);
140    static void renderFlows();
141    static void resetFlows();
142    static bool updateFlows();
143    static void advectFlows();
144
145    static Tcl_Interp *interp;
146
147    static unsigned int flags;
148    static bool debugFlag;
149    static bool axisOn;
150
151    static int winWidth;        ///< Width of the render window
152    static int winHeight;       ///< Height of the render window
153    static int renderWindow;    ///< GLUT handle for the render window
154    static unsigned char *screenBuffer;
155    static Texture2D *legendTexture;
156    static util::Fonts *fonts;
157    static int updir;
158    static Camera *cam;
159    static graphics::RenderContext *renderContext;
160
161    static TransferFunctionHashmap tfTable; ///< maps transfunc name to TransferFunction object
162    static VolumeHashmap volumeTable;
163    static FlowHashmap flowTable;
164    static HeightMapHashmap heightMapTable;
165
166    static double magMin, magMax;
167    static float xMin, xMax, yMin, yMax, zMin, zMax, wMin, wMax;
168    static vrmath::Vector3f sceneMin, sceneMax;
169
170    static VolumeRenderer *volRenderer;
171    static VelocityArrowsSlice *velocityArrowsSlice;
172    static LIC *licRenderer;
173    static PlaneRenderer *planeRenderer;
174    static Grid *grid;
175
176private:
177    static void collectBounds(bool onlyVisible = false);
178
179    static float _licSlice;  ///< Slice position [0,1]
180    static int _licAxis;     ///< Slice axis: 0:x, 1:y, 2:z
181
182    //frame buffer for final rendering
183    static GLuint _finalFbo, _finalColorTex, _finalDepthRb;
184};
185
186}
187
188#endif
Note: See TracBrowser for help on using the repository browser.