[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 | * |
---|
[3177] | 10 | * Copyright (c) 2004-2012 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> |
---|
| 29 | |
---|
[2818] | 30 | #include <rappture.h> |
---|
| 31 | |
---|
[251] | 32 | #include "config.h" |
---|
[226] | 33 | |
---|
[3362] | 34 | #define NANOVIS_VERSION "1.1" |
---|
[251] | 35 | |
---|
[226] | 36 | //defines for the image based flow visualization |
---|
| 37 | #define NMESH 256 //resolution of flow mesh |
---|
| 38 | #define NPIX 512 //display size |
---|
| 39 | |
---|
[2831] | 40 | namespace graphics { |
---|
| 41 | class RenderContext; |
---|
| 42 | } |
---|
| 43 | |
---|
| 44 | class VolumeRenderer; |
---|
| 45 | class PointSetRenderer; |
---|
| 46 | class NvParticleRenderer; |
---|
| 47 | class NvFlowVisRenderer; |
---|
| 48 | class PlaneRenderer; |
---|
| 49 | class VelocityArrowsSlice; |
---|
| 50 | class NvLIC; |
---|
| 51 | class PointSet; |
---|
| 52 | class Texture2D; |
---|
| 53 | class NvColorTableRenderer; |
---|
| 54 | class HeightMap; |
---|
[1370] | 55 | class NvVectorField; |
---|
[2831] | 56 | class Grid; |
---|
| 57 | class R2Fonts; |
---|
| 58 | class NvCamera; |
---|
| 59 | class TransferFunction; |
---|
| 60 | class Volume; |
---|
| 61 | class FlowCmd; |
---|
| 62 | class FlowIterator; |
---|
[1370] | 63 | |
---|
[2822] | 64 | class NanoVis |
---|
| 65 | { |
---|
[2831] | 66 | public: |
---|
| 67 | enum NanoVisFlags { |
---|
| 68 | REDRAW_PENDING = (1 << 0), |
---|
| 69 | MAP_FLOWS = (1 << 1), |
---|
| 70 | MAP_VOLUMES = (1 << 2), |
---|
| 71 | MAP_HEIGHTMAPS = (1 << 3), |
---|
| 72 | }; |
---|
[2822] | 73 | |
---|
[3452] | 74 | static void processCommands(); |
---|
[2831] | 75 | static void init(const char *path); |
---|
| 76 | static void initGL(); |
---|
[2877] | 77 | static void initOffscreenBuffer(); |
---|
| 78 | static void resizeOffscreenBuffer(int w, int h); |
---|
[2847] | 79 | static void display(); |
---|
[2951] | 80 | static void draw3dAxis(); |
---|
[2847] | 81 | static void idle(); |
---|
| 82 | static void update(); |
---|
[2951] | 83 | static void removeAllData(); |
---|
[2930] | 84 | |
---|
[3362] | 85 | static const NvCamera *getCamera() |
---|
| 86 | { |
---|
| 87 | return cam; |
---|
| 88 | } |
---|
[2847] | 89 | static void pan(float dx, float dy); |
---|
| 90 | static void zoom(float z); |
---|
[1299] | 91 | |
---|
[2877] | 92 | static void eventuallyRedraw(unsigned int flag = 0); |
---|
[2847] | 93 | |
---|
[2877] | 94 | static void setVolumeRanges(); |
---|
| 95 | static void setHeightmapRanges(); |
---|
[3362] | 96 | |
---|
| 97 | #ifdef KEEPSTATS |
---|
[3377] | 98 | static int getStatsFile(Tcl_Obj *objPtr); |
---|
| 99 | static int writeToStatsFile(int f, const char *s, size_t length); |
---|
[2951] | 100 | #endif |
---|
[2877] | 101 | static void ppmWrite(const char *prefix); |
---|
[1295] | 102 | static void sendDataToClient(const char *command, const char *data, |
---|
[2831] | 103 | size_t dlen); |
---|
[2877] | 104 | static void bmpWrite(const char *prefix); |
---|
| 105 | static void bmpWriteToFile(int frame_number, const char* directory_name); |
---|
[2847] | 106 | |
---|
[2877] | 107 | static TransferFunction *getTransfunc(const char *name); |
---|
| 108 | static TransferFunction *defineTransferFunction(const char *name, |
---|
[2847] | 109 | size_t n, float *data); |
---|
| 110 | |
---|
[2877] | 111 | static int renderLegend(TransferFunction *tf, double min, double max, |
---|
| 112 | int width, int height, const char *volArg); |
---|
[2847] | 113 | |
---|
[2877] | 114 | static Volume *loadVolume(const char *tag, int width, int height, int depth, |
---|
| 115 | int n, float* data, double vmin, double vmax, |
---|
| 116 | double nonZeroMin); |
---|
[1156] | 117 | |
---|
[2877] | 118 | static void removeVolume(Volume *volPtr); |
---|
| 119 | |
---|
| 120 | static void readScreen() |
---|
[2822] | 121 | { |
---|
[2877] | 122 | glReadPixels(0, 0, winWidth, winHeight, GL_RGB, GL_UNSIGNED_BYTE, |
---|
| 123 | screenBuffer); |
---|
[1028] | 124 | } |
---|
[2930] | 125 | static void bindOffscreenBuffer() |
---|
[2822] | 126 | { |
---|
[2877] | 127 | glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, _finalFbo); |
---|
[1028] | 128 | } |
---|
[1431] | 129 | |
---|
| 130 | static FlowCmd *FirstFlow(FlowIterator *iterPtr); |
---|
| 131 | static FlowCmd *NextFlow(FlowIterator *iterPtr); |
---|
[2831] | 132 | static void InitFlows(); |
---|
| 133 | static int GetFlow(Tcl_Interp *interp, Tcl_Obj *objPtr, |
---|
| 134 | FlowCmd **flowPtrPtr); |
---|
[1431] | 135 | static int CreateFlow(Tcl_Interp *interp, Tcl_Obj *objPtr); |
---|
| 136 | static void DeleteFlows(Tcl_Interp *interp); |
---|
[2831] | 137 | static bool MapFlows(); |
---|
| 138 | static void RenderFlows(); |
---|
| 139 | static void ResetFlows(); |
---|
| 140 | static bool UpdateFlows(); |
---|
| 141 | static void AdvectFlows(); |
---|
| 142 | |
---|
[2846] | 143 | static FILE *stdin, *logfile, *recfile; |
---|
[3376] | 144 | static int statsFile; |
---|
[2846] | 145 | static unsigned int flags; |
---|
[2877] | 146 | static bool debugFlag; |
---|
| 147 | static bool axisOn; |
---|
| 148 | static int winWidth; //size of the render window |
---|
| 149 | static int winHeight; //size of the render window |
---|
| 150 | static int renderWindow; |
---|
| 151 | static unsigned char *screenBuffer; |
---|
[2951] | 152 | static Texture2D *legendTexture; |
---|
[2846] | 153 | static Grid *grid; |
---|
| 154 | static R2Fonts *fonts; |
---|
| 155 | static int updir; |
---|
| 156 | static NvCamera *cam; |
---|
| 157 | static graphics::RenderContext *renderContext; |
---|
| 158 | |
---|
[2951] | 159 | static Tcl_HashTable tfTable; |
---|
[2846] | 160 | static Tcl_HashTable volumeTable; |
---|
[2951] | 161 | static Tcl_HashTable flowTable; |
---|
| 162 | static Tcl_HashTable heightmapTable; |
---|
[2846] | 163 | |
---|
| 164 | static double magMin, magMax; |
---|
| 165 | static float xMin, xMax, yMin, yMax, zMin, zMax, wMin, wMax; |
---|
| 166 | |
---|
[2951] | 167 | static NvColorTableRenderer *colorTableRenderer; |
---|
[2877] | 168 | static VolumeRenderer *volRenderer; |
---|
[2951] | 169 | #ifdef notdef |
---|
[2846] | 170 | static NvFlowVisRenderer *flowVisRenderer; |
---|
[2951] | 171 | #endif |
---|
[2846] | 172 | static VelocityArrowsSlice *velocityArrowsSlice; |
---|
| 173 | static NvLIC *licRenderer; |
---|
[2877] | 174 | static PlaneRenderer *planeRenderer; |
---|
[2846] | 175 | #if PLANE_CMD |
---|
[2930] | 176 | static int numPlanes; |
---|
[3362] | 177 | static Texture2D *plane[]; ///< Pointers to 2D planes |
---|
[2846] | 178 | #endif |
---|
| 179 | #ifdef USE_POINTSET_RENDERER |
---|
[2877] | 180 | static PointSetRenderer *pointSetRenderer; |
---|
[2846] | 181 | static std::vector<PointSet *> pointSet; |
---|
| 182 | #endif |
---|
| 183 | |
---|
| 184 | static Tcl_Interp *interp; |
---|
[3330] | 185 | static struct timeval startTime; /* Start of elapsed time. */ |
---|
[2831] | 186 | private: |
---|
[3362] | 187 | static float _licSlice; ///< Slice position [0,1] |
---|
| 188 | static int _licAxis; ///< Slice axis: 0:x, 1:y, 2:z |
---|
[2877] | 189 | |
---|
[2831] | 190 | //frame buffer for final rendering |
---|
[2877] | 191 | static GLuint _finalFbo, _finalColorTex, _finalDepthRb; |
---|
[835] | 192 | }; |
---|
[851] | 193 | |
---|
[2831] | 194 | #endif |
---|