source: trunk/packages/vizservers/nanovis/nanovis.h @ 1478

Last change on this file since 1478 was 1478, checked in by gah, 15 years ago

Fix volume management routines to handle deletion

File size: 6.8 KB
Line 
1/*
2 * ----------------------------------------------------------------------
3 *  nanovis.h: package header
4 *
5 * ======================================================================
6 *  AUTHOR:  Wei Qiao <qiaow@purdue.edu>
7 *           Purdue Rendering and Perceptualization Lab (PURPL)
8 *
9 *  Copyright (c) 2004-2006  Purdue Research Foundation
10 *
11 *  See the file "license.terms" for information on usage and
12 *  redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
13 * ======================================================================
14 */
15#ifndef __NANOVIS_H__
16#define __NANOVIS_H__
17
18#include <tcl.h>
19
20#include <GL/glew.h>
21#include <GL/glut.h>
22#include <Cg/cgGL.h>
23#include <stdlib.h>
24#include <math.h>
25#include <time.h>
26#include <iostream>
27#include <stdio.h>
28#include <assert.h>
29#include <float.h>
30#include <getopt.h>
31#include <stdio.h>
32#include <math.h>
33#include <fstream>
34#include <sstream>
35#include <string>
36#include <sys/time.h>
37#include <sys/types.h>
38#include <unistd.h>
39#include <fcntl.h>
40#include <signal.h>
41
42#include "define.h"
43#include "global.h"
44#include "socket/Socket.h"
45#include "NvCamera.h"
46#include "ConvexPolygon.h"
47#include "Texture3D.h"
48#include "Texture2D.h"
49#include "Texture1D.h"
50#include "TransferFunction.h"
51#include "Mat4x4.h"
52#include "Volume.h"
53#include "NvParticleRenderer.h"
54#include "NvFlowVisRenderer.h"
55#include "PerfQuery.h"
56#include "Event.h"
57#include "VolumeRenderer.h"
58#include "PlaneRenderer.h"
59#include "NvColorTableRenderer.h"
60#include "PointSetRenderer.h"
61#include "PointSet.h"
62#include "HeightMap.h"
63#include "Grid.h"
64
65#include "config.h"
66
67
68//defines for the image based flow visualization
69#define NPN 256         //resolution of background pattern
70#define NMESH 256       //resolution of flow mesh
71#define DM  ((float) (1.0/(NMESH-1.0))) //distance in world coords between mesh lines
72#define NPIX  512       //display size
73#define SCALE 3.0       //scale for background pattern. small value -> fine texture
74
75class NvVectorField;
76
77struct Vector2 {
78    float x, y;
79    float mag(void) {
80        return sqrt(x*x+y*y);
81    }
82};
83
84struct RegGrid2{
85    int width, height;
86    Vector2* field;
87   
88    RegGrid2(int w, int h){
89        width = w;
90        height = h;
91        field = new Vector2[w*h];
92    }
93
94    void put(Vector2& v, int x ,int y) {
95        field[x+y*width] = v;
96    }
97   
98    Vector2& get(int x, int y) {
99        return field[x+y*width];
100    }
101};
102
103class NvLIC;
104class FlowCmd;
105class FlowIterator;
106
107class NanoVis {
108    //frame buffer for final rendering
109    static NVISid final_fbo, final_color_tex, final_depth_rb;
110public:
111public:
112    static VolumeRenderer* vol_renderer;
113    static PointSetRenderer* pointset_renderer;
114#ifndef NEW_FLOW_ENGINE
115    static NvParticleRenderer* flowVisRenderer;
116#else
117    static NvFlowVisRenderer* flowVisRenderer;
118#endif
119    static NvLIC* licRenderer;
120    static vector<PointSet*> pointSet;
121    static PlaneRenderer* plane_render;
122
123    /**
124     *  pointers to 2D planes, currently handle up 10
125     */
126    static Texture2D* plane[10];
127    static NvColorTableRenderer* color_table_renderer;
128    static graphics::RenderContext* renderContext;
129    static vector<HeightMap*> heightMap;
130    static unsigned char* screen_buffer;
131    static vector<Volume *> volumes;
132    static vector<NvVectorField*> flow;
133    static Grid* grid;
134    static R2Fonts* fonts;
135    static int n_volumes;
136    static int updir;
137    static NvCamera *cam;
138
139    static float lic_slice_x;
140    static float lic_slice_y;
141    static float lic_slice_z;
142    static int lic_axis;        /* 0:x, 1:y, 2:z */
143
144    static bool axis_on;
145    static bool config_pending; // Indicates if the limits need to be recomputed.
146    static int win_width;       //size of the render window
147    static int win_height;      //size of the render window
148    static int render_window;
149
150    static bool debug_flag;
151
152    static Tcl_Interp *interp;
153    static Tcl_DString cmdbuffer;
154
155    static int _last_data_id;
156public :
157    static TransferFunction* get_transfunc(const char *name);
158    static TransferFunction* DefineTransferFunction(const char *name,
159        size_t n, float *data);
160    static void SetVolumeRanges(void);
161    static void SetHeightmapRanges(void);
162    static void init(const char* path);
163    static void initGL(void);
164    static void init_lic(void);
165    static void init_offscreen_buffer(void);
166    static void initParticle();
167    static void resize_offscreen_buffer(int w, int h);
168
169    // For development
170    static void resize(int w, int h);
171    static void render();
172
173    static void ppm_write(const char *prefix);
174    static void sendDataToClient(const char *command, const char *data,
175        size_t dlen);
176    static void bmp_write(const char *prefix);
177    static void bmp_write_to_file(int frame_number, const char* directory_name);
178    static void display(void);
179    static void idle(void);
180    static void update(void);
181    static void display_offscreen_buffer();
182    static int render_legend(TransferFunction *tf, double min, double max,
183        int width, int height, const char* volArg);
184    static Volume *load_volume(int volDataID, int width, int height, int depth,
185        int n, float* data, double vmin, double vmax, double nzero_min);
186    static void xinetd_listen(void);
187    static int render_2d_contour(HeightMap* heightmap, int width, int height);
188    static void pan(float dx, float dy);
189
190#ifndef XINETD
191    static void keyboard(unsigned char key, int x, int y);
192    static void mouse(int button, int state, int x, int y);
193    static void motion(int x, int y);
194    static void update_rot(int delta_x, int delta_y);
195    static void update_trans(int delta_x, int delta_y, int delta_z);
196#endif
197
198    static FILE *stdin, *logfile, *recfile;
199
200    static void read_screen(void) {
201        glReadPixels(0, 0, win_width, win_height, GL_RGB, GL_UNSIGNED_BYTE,
202                screen_buffer);
203    }
204    static void offscreen_buffer_capture(void) {
205        glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, final_fbo);
206    }
207
208    static unsigned int flags;
209    static Tcl_HashTable flowTable;
210    static float magMin, magMax;
211    static float xMin, xMax, yMin, yMax, zMin, zMax, wMin, wMax;
212    static float xOrigin, yOrigin, zOrigin;
213
214    static FlowCmd *FirstFlow(FlowIterator *iterPtr);
215    static FlowCmd *NextFlow(FlowIterator *iterPtr);
216    static void InitFlows(void);
217    static int GetFlow(Tcl_Interp *interp, Tcl_Obj *objPtr,
218                       FlowCmd **flowPtrPtr);
219    static int CreateFlow(Tcl_Interp *interp, Tcl_Obj *objPtr);
220    static void DeleteFlows(Tcl_Interp *interp);
221    static bool MapFlows(void);
222    static void RenderFlows(void);
223    static void ResetFlows(void);
224    static bool UpdateFlows(void);
225    static void AdvectFlows(void);
226    enum NanoVisFlags {
227        REDRAW_PENDING=(1<<0),
228        MAP_FLOWS=(1<<1),
229        MAP_VOLUMES=(1<<2),
230        MAP_HEIGHTMAPS=(1<<3),
231    };
232    static void EventuallyRedraw(unsigned int flag = 0);
233    static void remove_volume(size_t index);
234    static int generate_data_identifier();
235};
236
237
238#endif  /* __NANOVIS_H__ */
Note: See TracBrowser for help on using the repository browser.