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

Last change on this file since 3611 was 3611, checked in by ldelgass, 11 years ago

Use nv namespace for classes in nanovis rather than prefixing class names with
Nv (still need to convert shader classes).

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