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

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

Fixes for video generation

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