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

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

merge r3597 from trunk

  • Property svn:eol-style set to native
File size: 6.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 NANOVIS_H
17#define NANOVIS_H
18
19#include <tcl.h>
20#include <md5.h>
21#include <GL/glew.h>
22
23#include <math.h>
24#include <stddef.h> // For size_t
25#include <stdio.h>
26
27#include <vector>
28#include <iostream>
29#include <tr1/unordered_map>
30
31#include <vrmath/Vector3f.h>
32
33#include "config.h"
34
35#define NANOVIS_VERSION         "1.1"
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 VolumeRenderer;
51class PointSetRenderer;
52class NvParticleRenderer;
53class PlaneRenderer;
54class VelocityArrowsSlice;
55class NvLIC;
56class PointSet;
57class Texture2D;
58class HeightMap;
59class Grid;
60class NvCamera;
61class TransferFunction;
62class Volume;
63class Flow;
64
65class NanoVis
66{
67public:
68    enum AxisDirections { 
69        X_POS = 1,
70        Y_POS = 2,
71        Z_POS = 3,
72        X_NEG = -1,
73        Y_NEG = -2,
74        Z_NEG = -3
75    };
76
77    enum NanoVisFlags { 
78        REDRAW_PENDING = (1 << 0), 
79        MAP_FLOWS = (1 << 1)
80    };
81
82    typedef std::string TransferFunctionId;
83    typedef std::string VolumeId;
84    typedef std::string FlowId;
85    typedef std::string HeightMapId;
86    typedef std::tr1::unordered_map<TransferFunctionId, TransferFunction *> TransferFunctionHashmap;
87    typedef std::tr1::unordered_map<VolumeId, Volume *> VolumeHashmap;
88    typedef std::tr1::unordered_map<FlowId, Flow *> FlowHashmap;
89    typedef std::tr1::unordered_map<HeightMapId, HeightMap *> HeightMapHashmap;
90
91    static void processCommands();
92    static void init(const char *path);
93    static void initGL();
94    static void initOffscreenBuffer();
95    static void resizeOffscreenBuffer(int w, int h);
96    static void setBgColor(float color[3]);
97    static void render();
98    static void draw3dAxis();
99    static void idle();
100    static void update();
101    static void removeAllData();
102
103    static const NvCamera *getCamera()
104    {
105        return cam;
106    }
107    static void pan(float dx, float dy);
108    static void zoom(float z);
109    static void resetCamera(bool resetOrientation = false);
110
111    static void eventuallyRedraw(unsigned int flag = 0);
112
113    static void setVolumeRanges();
114    static void setHeightmapRanges();
115
116#ifdef KEEPSTATS
117    static int getStatsFile(Tcl_Obj *objPtr);
118    static int writeToStatsFile(int f, const char *s, size_t length);
119#endif
120    static void ppmWrite(const char *prefix);
121    static void sendDataToClient(const char *command, const char *data,
122                                 size_t dlen);
123    static void bmpWrite(const char *prefix);
124    static void bmpWriteToFile(int frame_number, const char* directory_name);
125 
126    static TransferFunction *getTransferFunction(const TransferFunctionId& id);
127    static TransferFunction *defineTransferFunction(const TransferFunctionId& id, 
128                                                    size_t n, float *data);
129
130    static int renderLegend(TransferFunction *tf, double min, double max, 
131                            int width, int height, const char *volArg);
132
133    static Volume *loadVolume(const char *tag, int width, int height, int depth,
134                              int numComponents, float *data, double vmin, double vmax, 
135                              double nonZeroMin);
136
137    static void removeVolume(Volume *volume);
138
139    static void readScreen()
140    {
141        glReadPixels(0, 0, winWidth, winHeight, GL_RGB, GL_UNSIGNED_BYTE, 
142                     screenBuffer);
143    }
144    static void bindOffscreenBuffer()
145    {
146        glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, _finalFbo);
147    }
148
149    static Flow *getFlow(const char *name);
150    static Flow *createFlow(Tcl_Interp *interp, const char *name);
151    static void deleteFlow(const char *name);
152    static void deleteFlows(Tcl_Interp *interp);
153    static bool mapFlows();
154    static void getFlowBounds(vrmath::Vector3f& min,
155                              vrmath::Vector3f& max,
156                              bool onlyVisible = false);
157    static void renderFlows();
158    static void resetFlows();
159    static bool updateFlows();
160    static void advectFlows();
161
162    static FILE *stdin, *logfile, *recfile;
163    static int statsFile;
164    static unsigned int flags;
165    static bool debugFlag;
166    static bool axisOn;
167    static struct timeval startTime;       ///< Start of elapsed time.
168
169    static int winWidth;        ///< Width of the render window
170    static int winHeight;       ///< Height of the render window
171    static int renderWindow;    //< GLUT handle for the render window
172    static unsigned char *screenBuffer;
173    static Texture2D *legendTexture;
174    static Grid *grid;
175    static nv::util::Fonts *fonts;
176    static int updir;
177    static NvCamera *cam;
178    static nv::graphics::RenderContext *renderContext;
179
180    static TransferFunctionHashmap tfTable; ///< maps transfunc name to TransferFunction object
181    static VolumeHashmap volumeTable;
182    static FlowHashmap flowTable;
183    static HeightMapHashmap heightMapTable;
184
185    static double magMin, magMax;
186    static float xMin, xMax, yMin, yMax, zMin, zMax, wMin, wMax;
187    static vrmath::Vector3f sceneMin, sceneMax;
188
189    static VolumeRenderer *volRenderer;
190    static VelocityArrowsSlice *velocityArrowsSlice;
191    static NvLIC *licRenderer;
192    static PlaneRenderer *planeRenderer;
193
194#ifdef USE_POINTSET_RENDERER
195    static PointSetRenderer *pointSetRenderer;
196    static std::vector<PointSet *> pointSet;
197#endif
198
199    static Tcl_Interp *interp;
200
201private:
202    static void collectBounds(bool onlyVisible = false);
203
204    static float _licSlice;  ///< Slice position [0,1]
205    static int _licAxis;     ///< Slice axis: 0:x, 1:y, 2:z
206
207    //frame buffer for final rendering
208    static GLuint _finalFbo, _finalColorTex, _finalDepthRb;
209};
210
211#endif
Note: See TracBrowser for help on using the repository browser.