source: trunk/packages/vizservers/nanovis/nanovis.h @ 3567

Last change on this file since 3567 was 3567, checked in by ldelgass, 9 years ago

Refactor and cleanups in nanovis, mainly to switch to using STL hash tables
(TR1 required) instead of Tcl hash tables, split out Flow particles and boxes
to separate implementation files. The goal is to achieve better separation of
Tcl command parsing and the core graphics rendering objects and code.

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