[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 | |
---|
[4617] | 35 | #define NANOVIS_VERSION "1.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 PlaneRenderer; |
---|
| 54 | class VelocityArrowsSlice; |
---|
| 55 | class NvLIC; |
---|
| 56 | class PointSet; |
---|
| 57 | class Texture2D; |
---|
| 58 | class HeightMap; |
---|
| 59 | class Grid; |
---|
| 60 | class NvCamera; |
---|
| 61 | class TransferFunction; |
---|
| 62 | class Volume; |
---|
[4612] | 63 | class Flow; |
---|
[1370] | 64 | |
---|
[2822] | 65 | class NanoVis |
---|
| 66 | { |
---|
[2831] | 67 | public: |
---|
[3492] | 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 | |
---|
[2831] | 77 | enum NanoVisFlags { |
---|
| 78 | REDRAW_PENDING = (1 << 0), |
---|
[3492] | 79 | MAP_FLOWS = (1 << 1) |
---|
[2831] | 80 | }; |
---|
[2822] | 81 | |
---|
[3567] | 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; |
---|
[4612] | 88 | typedef std::tr1::unordered_map<FlowId, Flow *> FlowHashmap; |
---|
[3567] | 89 | typedef std::tr1::unordered_map<HeightMapId, HeightMap *> HeightMapHashmap; |
---|
| 90 | |
---|
[3452] | 91 | static void processCommands(); |
---|
[2831] | 92 | static void init(const char *path); |
---|
| 93 | static void initGL(); |
---|
[2877] | 94 | static void initOffscreenBuffer(); |
---|
| 95 | static void resizeOffscreenBuffer(int w, int h); |
---|
[3478] | 96 | static void setBgColor(float color[3]); |
---|
[3497] | 97 | static void render(); |
---|
[2951] | 98 | static void draw3dAxis(); |
---|
[2847] | 99 | static void idle(); |
---|
| 100 | static void update(); |
---|
[2951] | 101 | static void removeAllData(); |
---|
[2930] | 102 | |
---|
[3362] | 103 | static const NvCamera *getCamera() |
---|
| 104 | { |
---|
| 105 | return cam; |
---|
| 106 | } |
---|
[2847] | 107 | static void pan(float dx, float dy); |
---|
| 108 | static void zoom(float z); |
---|
[3492] | 109 | static void resetCamera(bool resetOrientation = false); |
---|
[1299] | 110 | |
---|
[2877] | 111 | static void eventuallyRedraw(unsigned int flag = 0); |
---|
[2847] | 112 | |
---|
[2877] | 113 | static void setVolumeRanges(); |
---|
| 114 | static void setHeightmapRanges(); |
---|
[3362] | 115 | |
---|
| 116 | #ifdef KEEPSTATS |
---|
[3377] | 117 | static int getStatsFile(Tcl_Obj *objPtr); |
---|
| 118 | static int writeToStatsFile(int f, const char *s, size_t length); |
---|
[2951] | 119 | #endif |
---|
[2877] | 120 | static void ppmWrite(const char *prefix); |
---|
[1295] | 121 | static void sendDataToClient(const char *command, const char *data, |
---|
[2831] | 122 | size_t dlen); |
---|
[2877] | 123 | static void bmpWrite(const char *prefix); |
---|
| 124 | static void bmpWriteToFile(int frame_number, const char* directory_name); |
---|
[2847] | 125 | |
---|
[3567] | 126 | static TransferFunction *getTransferFunction(const TransferFunctionId& id); |
---|
| 127 | static TransferFunction *defineTransferFunction(const TransferFunctionId& id, |
---|
[2847] | 128 | size_t n, float *data); |
---|
| 129 | |
---|
[2877] | 130 | static int renderLegend(TransferFunction *tf, double min, double max, |
---|
| 131 | int width, int height, const char *volArg); |
---|
[2847] | 132 | |
---|
[2877] | 133 | static Volume *loadVolume(const char *tag, int width, int height, int depth, |
---|
[4612] | 134 | int numComponents, float *data, double vmin, double vmax, |
---|
[2877] | 135 | double nonZeroMin); |
---|
[1156] | 136 | |
---|
[4612] | 137 | static void removeVolume(Volume *volume); |
---|
[2877] | 138 | |
---|
| 139 | static void readScreen() |
---|
[2822] | 140 | { |
---|
[2877] | 141 | glReadPixels(0, 0, winWidth, winHeight, GL_RGB, GL_UNSIGNED_BYTE, |
---|
| 142 | screenBuffer); |
---|
[1028] | 143 | } |
---|
[2930] | 144 | static void bindOffscreenBuffer() |
---|
[2822] | 145 | { |
---|
[2877] | 146 | glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, _finalFbo); |
---|
[1028] | 147 | } |
---|
[1431] | 148 | |
---|
[4612] | 149 | static Flow *getFlow(const char *name); |
---|
| 150 | static Flow *createFlow(Tcl_Interp *interp, const char *name); |
---|
[3567] | 151 | static void deleteFlow(const char *name); |
---|
[3566] | 152 | static void deleteFlows(Tcl_Interp *interp); |
---|
| 153 | static bool mapFlows(); |
---|
| 154 | static void getFlowBounds(vrmath::Vector3f& min, |
---|
[3492] | 155 | vrmath::Vector3f& max, |
---|
| 156 | bool onlyVisible = false); |
---|
[3566] | 157 | static void renderFlows(); |
---|
| 158 | static void resetFlows(); |
---|
| 159 | static bool updateFlows(); |
---|
| 160 | static void advectFlows(); |
---|
[2831] | 161 | |
---|
[2846] | 162 | static FILE *stdin, *logfile, *recfile; |
---|
[3376] | 163 | static int statsFile; |
---|
[2846] | 164 | static unsigned int flags; |
---|
[2877] | 165 | static bool debugFlag; |
---|
| 166 | static bool axisOn; |
---|
[3567] | 167 | static struct timeval startTime; ///< Start of elapsed time. |
---|
| 168 | |
---|
| 169 | static int winWidth; ///< Width of the render window |
---|
| 170 | static int winHeight; ///< Height of the render window |
---|
| 171 | static int renderWindow; //< GLUT handle for the render window |
---|
[2877] | 172 | static unsigned char *screenBuffer; |
---|
[2951] | 173 | static Texture2D *legendTexture; |
---|
[2846] | 174 | static Grid *grid; |
---|
[3463] | 175 | static nv::util::Fonts *fonts; |
---|
[2846] | 176 | static int updir; |
---|
| 177 | static NvCamera *cam; |
---|
[3463] | 178 | static nv::graphics::RenderContext *renderContext; |
---|
[2846] | 179 | |
---|
[3567] | 180 | static TransferFunctionHashmap tfTable; ///< maps transfunc name to TransferFunction object |
---|
| 181 | static VolumeHashmap volumeTable; |
---|
| 182 | static FlowHashmap flowTable; |
---|
| 183 | static HeightMapHashmap heightMapTable; |
---|
[2846] | 184 | |
---|
| 185 | static double magMin, magMax; |
---|
| 186 | static float xMin, xMax, yMin, yMax, zMin, zMax, wMin, wMax; |
---|
[3492] | 187 | static vrmath::Vector3f sceneMin, sceneMax; |
---|
[2846] | 188 | |
---|
[2877] | 189 | static VolumeRenderer *volRenderer; |
---|
[2846] | 190 | static VelocityArrowsSlice *velocityArrowsSlice; |
---|
| 191 | static NvLIC *licRenderer; |
---|
[2877] | 192 | static PlaneRenderer *planeRenderer; |
---|
[3568] | 193 | |
---|
[2846] | 194 | #ifdef USE_POINTSET_RENDERER |
---|
[2877] | 195 | static PointSetRenderer *pointSetRenderer; |
---|
[2846] | 196 | static std::vector<PointSet *> pointSet; |
---|
| 197 | #endif |
---|
| 198 | |
---|
| 199 | static Tcl_Interp *interp; |
---|
[3567] | 200 | |
---|
[2831] | 201 | private: |
---|
[3492] | 202 | static void collectBounds(bool onlyVisible = false); |
---|
| 203 | |
---|
[3362] | 204 | static float _licSlice; ///< Slice position [0,1] |
---|
| 205 | static int _licAxis; ///< Slice axis: 0:x, 1:y, 2:z |
---|
[2877] | 206 | |
---|
[2831] | 207 | //frame buffer for final rendering |
---|
[2877] | 208 | static GLuint _finalFbo, _finalColorTex, _finalDepthRb; |
---|
[835] | 209 | }; |
---|
[851] | 210 | |
---|
[2831] | 211 | #endif |
---|