source: nanovis/trunk/nanovis.h

Last change on this file was 5717, checked in by ldelgass, 4 years ago

Downsample volume if dims exceed hardware limits

  • Property svn:eol-style set to native
File size: 5.0 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 NV_NANOVIS_H
17#define NV_NANOVIS_H
18
19#include <cstddef> // For size_t
20#include <string>
21#include <tr1/unordered_map>
22
23#include <tcl.h>
24
25#include <GL/glew.h>
26
27#include <vrmath/BBox.h>
28#include <vrmath/Vector3f.h>
29
30#include "config.h"
31#include "Camera.h"
32
33//defines for the image based flow visualization
34#define NMESH 256       //resolution of flow mesh
35#define NPIX  512       //display size
36
37namespace nv {
38namespace graphics {
39    class RenderContext;
40}
41namespace util {
42    class Fonts;
43}
44
45class Flow;
46class Grid;
47class HeightMap;
48class LIC;
49class OrientationIndicator;
50class PlaneRenderer;
51class Texture2D;
52class TransferFunction;
53class VelocityArrowsSlice;
54class Volume;
55class VolumeRenderer;
56
57class NanoVis
58{
59public:
60    typedef std::string TransferFunctionId;
61    typedef std::string VolumeId;
62    typedef std::string FlowId;
63    typedef std::string HeightMapId;
64    typedef std::tr1::unordered_map<TransferFunctionId, TransferFunction *> TransferFunctionHashmap;
65    typedef std::tr1::unordered_map<VolumeId, Volume *> VolumeHashmap;
66    typedef std::tr1::unordered_map<FlowId, Flow *> FlowHashmap;
67    typedef std::tr1::unordered_map<HeightMapId, HeightMap *> HeightMapHashmap;
68
69    static bool init(const char *path);
70    static bool initGL();
71    static bool initOffscreenBuffer();
72    static bool resizeOffscreenBuffer(int w, int h);
73    static void setBgColor(float color[3]);
74    static void render();
75    static void update();
76    static void removeAllData();
77
78    static const Camera *getCamera()
79    {
80        return _camera;
81    }
82    static void panCamera(float dx, float dy);
83    static void zoomCamera(float z);
84    static void orientCamera(double *quat);
85    static void setCameraPosition(vrmath::Vector3f pos);
86    static void setCameraUpdir(Camera::AxisDirection dir);
87    static void resetCamera(bool resetOrientation = false);
88
89    static void eventuallyRedraw();
90
91    static TransferFunction *getTransferFunction(const TransferFunctionId& id);
92    static TransferFunction *defineTransferFunction(const TransferFunctionId& id, 
93                                                    size_t n, float *data);
94
95    static int renderLegend(TransferFunction *tf, double min, double max, 
96                            int width, int height, const char *tag);
97
98    static Volume *loadVolume(const char *tag, int width, int height, int depth,
99                              int numComponents, float *data, double vmin, double vmax, 
100                              double nonZeroMin);
101
102    static void removeVolume(Volume *volume);
103
104    static void readScreen()
105    {
106        glPixelStorei(GL_PACK_ALIGNMENT, 1);
107        glReadPixels(0, 0, winWidth, winHeight, GL_RGB, GL_UNSIGNED_BYTE, 
108                     screenBuffer);
109    }
110    static void bindOffscreenBuffer()
111    {
112        glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, _finalFbo);
113    }
114
115    static void setVolumeRanges();
116    static void setHeightmapRanges();
117    static bool setFlowRanges();
118
119    static Flow *getFlow(const char *name);
120    static Flow *createFlow(Tcl_Interp *interp, const char *name);
121    static void deleteFlows(Tcl_Interp *interp);
122    static void deleteFlow(const char *name);
123
124    static void renderFlows();
125    static void resetFlows();
126    static bool updateFlows();
127    static void advectFlows();
128
129    static Tcl_Interp *interp;
130
131    static bool redrawPending;
132    static bool debugFlag;
133
134    static int winWidth;        ///< Width of the render window
135    static int winHeight;       ///< Height of the render window
136    static int renderWindow;    ///< GLUT handle for the render window
137    static unsigned char *screenBuffer;
138    static Texture2D *legendTexture;
139    static util::Fonts *fonts;
140    static graphics::RenderContext *renderContext;
141    static GLint max3dTextureSize;
142
143    static TransferFunctionHashmap tfTable; ///< maps transfunc name to TransferFunction object
144    static VolumeHashmap volumeTable;
145    static FlowHashmap flowTable;
146    static HeightMapHashmap heightMapTable;
147
148    static vrmath::BBox sceneBounds;
149
150    static VolumeRenderer *volRenderer;
151    static VelocityArrowsSlice *velocityArrowsSlice;
152    static LIC *licRenderer;
153    static PlaneRenderer *planeRenderer;
154    static OrientationIndicator *orientationIndicator;
155    static Grid *grid;
156
157private:
158    static void collectBounds(bool onlyVisible = false);
159
160    static Camera *_camera;
161
162    //frame buffer for final rendering
163    static GLuint _finalFbo, _finalColorTex, _finalDepthRb;
164};
165
166}
167
168#endif
Note: See TracBrowser for help on using the repository browser.