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 <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 | //defines for the image based flow visualization |
---|
39 | #define NMESH 256 //resolution of flow mesh |
---|
40 | #define NPIX 512 //display size |
---|
41 | |
---|
42 | namespace nv { |
---|
43 | namespace graphics { |
---|
44 | class RenderContext; |
---|
45 | } |
---|
46 | namespace util { |
---|
47 | class Fonts; |
---|
48 | } |
---|
49 | |
---|
50 | class Camera; |
---|
51 | class Flow; |
---|
52 | class Grid; |
---|
53 | class HeightMap; |
---|
54 | class LIC; |
---|
55 | class OrientationIndicator; |
---|
56 | class PlaneRenderer; |
---|
57 | class Texture2D; |
---|
58 | class TransferFunction; |
---|
59 | class VelocityArrowsSlice; |
---|
60 | class Volume; |
---|
61 | class VolumeRenderer; |
---|
62 | |
---|
63 | class NanoVis |
---|
64 | { |
---|
65 | public: |
---|
66 | enum AxisDirections { |
---|
67 | X_POS = 1, |
---|
68 | Y_POS = 2, |
---|
69 | Z_POS = 3, |
---|
70 | X_NEG = -1, |
---|
71 | Y_NEG = -2, |
---|
72 | Z_NEG = -3 |
---|
73 | }; |
---|
74 | |
---|
75 | enum NanoVisFlags { |
---|
76 | REDRAW_PENDING = (1 << 0), |
---|
77 | MAP_FLOWS = (1 << 1) |
---|
78 | }; |
---|
79 | |
---|
80 | typedef std::string TransferFunctionId; |
---|
81 | typedef std::string VolumeId; |
---|
82 | typedef std::string FlowId; |
---|
83 | typedef std::string HeightMapId; |
---|
84 | typedef std::tr1::unordered_map<TransferFunctionId, TransferFunction *> TransferFunctionHashmap; |
---|
85 | typedef std::tr1::unordered_map<VolumeId, Volume *> VolumeHashmap; |
---|
86 | typedef std::tr1::unordered_map<FlowId, Flow *> FlowHashmap; |
---|
87 | typedef std::tr1::unordered_map<HeightMapId, HeightMap *> HeightMapHashmap; |
---|
88 | |
---|
89 | static bool init(const char *path); |
---|
90 | static bool initGL(); |
---|
91 | static bool initOffscreenBuffer(); |
---|
92 | static bool resizeOffscreenBuffer(int w, int h); |
---|
93 | static void setBgColor(float color[3]); |
---|
94 | static void render(); |
---|
95 | static void draw3dAxis(); |
---|
96 | static void update(); |
---|
97 | static void removeAllData(); |
---|
98 | |
---|
99 | static const Camera *getCamera() |
---|
100 | { |
---|
101 | return cam; |
---|
102 | } |
---|
103 | static void pan(float dx, float dy); |
---|
104 | static void zoom(float z); |
---|
105 | static void resetCamera(bool resetOrientation = false); |
---|
106 | |
---|
107 | static void eventuallyRedraw(unsigned int flag = 0); |
---|
108 | |
---|
109 | static void setVolumeRanges(); |
---|
110 | static void setHeightmapRanges(); |
---|
111 | |
---|
112 | static TransferFunction *getTransferFunction(const TransferFunctionId& id); |
---|
113 | static TransferFunction *defineTransferFunction(const TransferFunctionId& id, |
---|
114 | size_t n, float *data); |
---|
115 | |
---|
116 | static int renderLegend(TransferFunction *tf, double min, double max, |
---|
117 | int width, int height, const char *volArg); |
---|
118 | |
---|
119 | static Volume *loadVolume(const char *tag, int width, int height, int depth, |
---|
120 | int numComponents, float *data, double vmin, double vmax, |
---|
121 | double nonZeroMin); |
---|
122 | |
---|
123 | static void removeVolume(Volume *volume); |
---|
124 | |
---|
125 | static void readScreen() |
---|
126 | { |
---|
127 | glPixelStorei(GL_PACK_ALIGNMENT, 1); |
---|
128 | glReadPixels(0, 0, winWidth, winHeight, GL_RGB, GL_UNSIGNED_BYTE, |
---|
129 | screenBuffer); |
---|
130 | } |
---|
131 | static void bindOffscreenBuffer() |
---|
132 | { |
---|
133 | glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, _finalFbo); |
---|
134 | } |
---|
135 | |
---|
136 | static Flow *getFlow(const char *name); |
---|
137 | static Flow *createFlow(Tcl_Interp *interp, const char *name); |
---|
138 | static void deleteFlows(Tcl_Interp *interp); |
---|
139 | static void deleteFlow(const char *name); |
---|
140 | static bool mapFlows(); |
---|
141 | static void getFlowBounds(vrmath::Vector3f& min, |
---|
142 | vrmath::Vector3f& max, |
---|
143 | bool onlyVisible = false); |
---|
144 | static void renderFlows(); |
---|
145 | static void resetFlows(); |
---|
146 | static bool updateFlows(); |
---|
147 | static void advectFlows(); |
---|
148 | |
---|
149 | static Tcl_Interp *interp; |
---|
150 | |
---|
151 | static unsigned int flags; |
---|
152 | static bool debugFlag; |
---|
153 | |
---|
154 | static int winWidth; ///< Width of the render window |
---|
155 | static int winHeight; ///< Height of the render window |
---|
156 | static int renderWindow; //< GLUT handle for the render window |
---|
157 | static unsigned char *screenBuffer; |
---|
158 | static Texture2D *legendTexture; |
---|
159 | static util::Fonts *fonts; |
---|
160 | static int updir; |
---|
161 | static Camera *cam; |
---|
162 | static graphics::RenderContext *renderContext; |
---|
163 | |
---|
164 | static TransferFunctionHashmap tfTable; ///< maps transfunc name to TransferFunction object |
---|
165 | static VolumeHashmap volumeTable; |
---|
166 | static FlowHashmap flowTable; |
---|
167 | static HeightMapHashmap heightMapTable; |
---|
168 | |
---|
169 | static double magMin, magMax; |
---|
170 | static float xMin, xMax, yMin, yMax, zMin, zMax, wMin, wMax; |
---|
171 | static vrmath::Vector3f sceneMin, sceneMax; |
---|
172 | |
---|
173 | static VolumeRenderer *volRenderer; |
---|
174 | static VelocityArrowsSlice *velocityArrowsSlice; |
---|
175 | static LIC *licRenderer; |
---|
176 | static PlaneRenderer *planeRenderer; |
---|
177 | static OrientationIndicator *orientationIndicator; |
---|
178 | static Grid *grid; |
---|
179 | |
---|
180 | private: |
---|
181 | static void collectBounds(bool onlyVisible = false); |
---|
182 | |
---|
183 | static float _licSlice; ///< Slice position [0,1] |
---|
184 | static int _licAxis; ///< Slice axis: 0:x, 1:y, 2:z |
---|
185 | |
---|
186 | //frame buffer for final rendering |
---|
187 | static GLuint _finalFbo, _finalColorTex, _finalDepthRb; |
---|
188 | }; |
---|
189 | |
---|
190 | } |
---|
191 | |
---|
192 | #endif |
---|