[2798] | 1 | /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */ |
---|
[226] | 2 | /* |
---|
| 3 | * ---------------------------------------------------------------------- |
---|
| 4 | * nanovis.h: package header |
---|
| 5 | * |
---|
| 6 | * ====================================================================== |
---|
| 7 | * AUTHOR: Wei Qiao <qiaow@purdue.edu> |
---|
| 8 | * Purdue Rendering and Perceptualization Lab (PURPL) |
---|
| 9 | * |
---|
[3502] | 10 | * Copyright (c) 2004-2013 HUBzero Foundation, LLC |
---|
[226] | 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 | */ |
---|
[2831] | 16 | #ifndef NANOVIS_H |
---|
| 17 | #define NANOVIS_H |
---|
[259] | 18 | |
---|
[850] | 19 | #include <tcl.h> |
---|
[3377] | 20 | #include <md5.h> |
---|
[226] | 21 | #include <GL/glew.h> |
---|
[2831] | 22 | |
---|
[226] | 23 | #include <math.h> |
---|
[2831] | 24 | #include <stddef.h> // For size_t |
---|
[226] | 25 | #include <stdio.h> |
---|
| 26 | |
---|
[2831] | 27 | #include <vector> |
---|
| 28 | #include <iostream> |
---|
[3567] | 29 | #include <tr1/unordered_map> |
---|
[2831] | 30 | |
---|
[3492] | 31 | #include <vrmath/Vector3f.h> |
---|
[2818] | 32 | |
---|
[251] | 33 | #include "config.h" |
---|
[226] | 34 | |
---|
[3362] | 35 | #define NANOVIS_VERSION "1.1" |
---|
[251] | 36 | |
---|
[226] | 37 | //defines for the image based flow visualization |
---|
| 38 | #define NMESH 256 //resolution of flow mesh |
---|
| 39 | #define NPIX 512 //display size |
---|
| 40 | |
---|
[3463] | 41 | namespace nv { |
---|
[2831] | 42 | namespace graphics { |
---|
| 43 | class RenderContext; |
---|
| 44 | } |
---|
[3463] | 45 | namespace util { |
---|
| 46 | class Fonts; |
---|
| 47 | } |
---|
| 48 | } |
---|
[2831] | 49 | |
---|
| 50 | class VolumeRenderer; |
---|
| 51 | class PointSetRenderer; |
---|
| 52 | class NvParticleRenderer; |
---|
| 53 | class NvFlowVisRenderer; |
---|
| 54 | class PlaneRenderer; |
---|
| 55 | class VelocityArrowsSlice; |
---|
| 56 | class NvLIC; |
---|
| 57 | class PointSet; |
---|
| 58 | class Texture2D; |
---|
| 59 | class HeightMap; |
---|
[1370] | 60 | class NvVectorField; |
---|
[2831] | 61 | class Grid; |
---|
| 62 | class NvCamera; |
---|
| 63 | class TransferFunction; |
---|
| 64 | class Volume; |
---|
| 65 | class FlowCmd; |
---|
[1370] | 66 | |
---|
[2822] | 67 | class NanoVis |
---|
| 68 | { |
---|
[2831] | 69 | public: |
---|
[3492] | 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 | |
---|
[2831] | 79 | enum NanoVisFlags { |
---|
| 80 | REDRAW_PENDING = (1 << 0), |
---|
[3492] | 81 | MAP_FLOWS = (1 << 1) |
---|
[2831] | 82 | }; |
---|
[2822] | 83 | |
---|
[3567] | 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 | |
---|
[3452] | 93 | static void processCommands(); |
---|
[2831] | 94 | static void init(const char *path); |
---|
| 95 | static void initGL(); |
---|
[2877] | 96 | static void initOffscreenBuffer(); |
---|
| 97 | static void resizeOffscreenBuffer(int w, int h); |
---|
[3478] | 98 | static void setBgColor(float color[3]); |
---|
[3497] | 99 | static void render(); |
---|
[2951] | 100 | static void draw3dAxis(); |
---|
[2847] | 101 | static void idle(); |
---|
| 102 | static void update(); |
---|
[2951] | 103 | static void removeAllData(); |
---|
[2930] | 104 | |
---|
[3362] | 105 | static const NvCamera *getCamera() |
---|
| 106 | { |
---|
| 107 | return cam; |
---|
| 108 | } |
---|
[2847] | 109 | static void pan(float dx, float dy); |
---|
| 110 | static void zoom(float z); |
---|
[3492] | 111 | static void resetCamera(bool resetOrientation = false); |
---|
[1299] | 112 | |
---|
[2877] | 113 | static void eventuallyRedraw(unsigned int flag = 0); |
---|
[2847] | 114 | |
---|
[2877] | 115 | static void setVolumeRanges(); |
---|
| 116 | static void setHeightmapRanges(); |
---|
[3362] | 117 | |
---|
| 118 | #ifdef KEEPSTATS |
---|
[3377] | 119 | static int getStatsFile(Tcl_Obj *objPtr); |
---|
| 120 | static int writeToStatsFile(int f, const char *s, size_t length); |
---|
[2951] | 121 | #endif |
---|
[2877] | 122 | static void ppmWrite(const char *prefix); |
---|
[1295] | 123 | static void sendDataToClient(const char *command, const char *data, |
---|
[2831] | 124 | size_t dlen); |
---|
[2877] | 125 | static void bmpWrite(const char *prefix); |
---|
| 126 | static void bmpWriteToFile(int frame_number, const char* directory_name); |
---|
[2847] | 127 | |
---|
[3567] | 128 | static TransferFunction *getTransferFunction(const TransferFunctionId& id); |
---|
| 129 | static TransferFunction *defineTransferFunction(const TransferFunctionId& id, |
---|
[2847] | 130 | size_t n, float *data); |
---|
| 131 | |
---|
[2877] | 132 | static int renderLegend(TransferFunction *tf, double min, double max, |
---|
| 133 | int width, int height, const char *volArg); |
---|
[2847] | 134 | |
---|
[2877] | 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); |
---|
[1156] | 138 | |
---|
[2877] | 139 | static void removeVolume(Volume *volPtr); |
---|
| 140 | |
---|
| 141 | static void readScreen() |
---|
[2822] | 142 | { |
---|
[2877] | 143 | glReadPixels(0, 0, winWidth, winHeight, GL_RGB, GL_UNSIGNED_BYTE, |
---|
| 144 | screenBuffer); |
---|
[1028] | 145 | } |
---|
[2930] | 146 | static void bindOffscreenBuffer() |
---|
[2822] | 147 | { |
---|
[2877] | 148 | glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, _finalFbo); |
---|
[1028] | 149 | } |
---|
[1431] | 150 | |
---|
[3567] | 151 | static FlowCmd *getFlow(const char *name); |
---|
| 152 | static FlowCmd *createFlow(Tcl_Interp *interp, const char *name); |
---|
| 153 | static void deleteFlow(const char *name); |
---|
[3566] | 154 | static void deleteFlows(Tcl_Interp *interp); |
---|
| 155 | static bool mapFlows(); |
---|
| 156 | static void getFlowBounds(vrmath::Vector3f& min, |
---|
[3492] | 157 | vrmath::Vector3f& max, |
---|
| 158 | bool onlyVisible = false); |
---|
[3566] | 159 | static void renderFlows(); |
---|
| 160 | static void resetFlows(); |
---|
| 161 | static bool updateFlows(); |
---|
| 162 | static void advectFlows(); |
---|
[2831] | 163 | |
---|
[2846] | 164 | static FILE *stdin, *logfile, *recfile; |
---|
[3376] | 165 | static int statsFile; |
---|
[2846] | 166 | static unsigned int flags; |
---|
[2877] | 167 | static bool debugFlag; |
---|
| 168 | static bool axisOn; |
---|
[3567] | 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 |
---|
[2877] | 174 | static unsigned char *screenBuffer; |
---|
[2951] | 175 | static Texture2D *legendTexture; |
---|
[2846] | 176 | static Grid *grid; |
---|
[3463] | 177 | static nv::util::Fonts *fonts; |
---|
[2846] | 178 | static int updir; |
---|
| 179 | static NvCamera *cam; |
---|
[3463] | 180 | static nv::graphics::RenderContext *renderContext; |
---|
[2846] | 181 | |
---|
[3567] | 182 | static TransferFunctionHashmap tfTable; ///< maps transfunc name to TransferFunction object |
---|
| 183 | static VolumeHashmap volumeTable; |
---|
| 184 | static FlowHashmap flowTable; |
---|
| 185 | static HeightMapHashmap heightMapTable; |
---|
[2846] | 186 | |
---|
| 187 | static double magMin, magMax; |
---|
| 188 | static float xMin, xMax, yMin, yMax, zMin, zMax, wMin, wMax; |
---|
[3492] | 189 | static vrmath::Vector3f sceneMin, sceneMax; |
---|
[2846] | 190 | |
---|
[2877] | 191 | static VolumeRenderer *volRenderer; |
---|
[2951] | 192 | #ifdef notdef |
---|
[2846] | 193 | static NvFlowVisRenderer *flowVisRenderer; |
---|
[2951] | 194 | #endif |
---|
[2846] | 195 | static VelocityArrowsSlice *velocityArrowsSlice; |
---|
| 196 | static NvLIC *licRenderer; |
---|
[2877] | 197 | static PlaneRenderer *planeRenderer; |
---|
[3568] | 198 | |
---|
[2846] | 199 | #ifdef USE_POINTSET_RENDERER |
---|
[2877] | 200 | static PointSetRenderer *pointSetRenderer; |
---|
[2846] | 201 | static std::vector<PointSet *> pointSet; |
---|
| 202 | #endif |
---|
| 203 | |
---|
| 204 | static Tcl_Interp *interp; |
---|
[3567] | 205 | |
---|
[2831] | 206 | private: |
---|
[3492] | 207 | static void collectBounds(bool onlyVisible = false); |
---|
| 208 | |
---|
[3362] | 209 | static float _licSlice; ///< Slice position [0,1] |
---|
| 210 | static int _licAxis; ///< Slice axis: 0:x, 1:y, 2:z |
---|
[2877] | 211 | |
---|
[2831] | 212 | //frame buffer for final rendering |
---|
[2877] | 213 | static GLuint _finalFbo, _finalColorTex, _finalDepthRb; |
---|
[835] | 214 | }; |
---|
[851] | 215 | |
---|
[2831] | 216 | #endif |
---|