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

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

merge r3596 from trunk

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