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

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

cleanup includes

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