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

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

Stats log fixes, also bump version

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