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

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

fixup new flow visualization command structure

File size: 6.6 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:
111    static VolumeRenderer* vol_renderer;
112    static PointSetRenderer* pointset_renderer;
113#ifndef NEW_FLOW_ENGINE
114    static NvParticleRenderer* flowVisRenderer;
115#else
116    static NvFlowVisRenderer* flowVisRenderer;
117#endif
118    static NvLIC* licRenderer;
119    static vector<PointSet*> pointSet;
120    static PlaneRenderer* plane_render;
121
122    /**
123     *  pointers to 2D planes, currently handle up 10
124     */
125    static Texture2D* plane[10];
126    static NvColorTableRenderer* color_table_renderer;
127    static graphics::RenderContext* renderContext;
128    static vector<HeightMap*> heightMap;
129    static unsigned char* screen_buffer;
130    static vector<Volume*> volume;
131    static vector<NvVectorField*> flow;
132    static Grid* grid;
133    static R2Fonts* fonts;
134    static int n_volumes;
135    static int updir;
136    static NvCamera *cam;
137
138    static float lic_slice_x;
139    static float lic_slice_y;
140    static float lic_slice_z;
141    static int lic_axis;        /* 0:x, 1:y, 2:z */
142
143    static bool axis_on;
144    static bool config_pending; // Indicates if the limits need to be recomputed.
145    static int win_width;       //size of the render window
146    static int win_height;      //size of the render window
147    static int render_window;
148
149    static bool debug_flag;
150
151    static Tcl_Interp *interp;
152    static Tcl_DString cmdbuffer;
153
154    static TransferFunction* get_transfunc(const char *name);
155    static TransferFunction* DefineTransferFunction(const char *name,
156        size_t n, float *data);
157    static void SetVolumeRanges(void);
158    static void SetHeightmapRanges(void);
159    static void init(const char* path);
160    static void initGL(void);
161    static void init_lic(void);
162    static void init_offscreen_buffer(void);
163    static void initParticle();
164    static void resize_offscreen_buffer(int w, int h);
165
166    // For development
167    static void resize(int w, int h);
168    static void render();
169
170    static void ppm_write(const char *prefix);
171    static void sendDataToClient(const char *command, const char *data,
172        size_t dlen);
173    static void bmp_write(const char *prefix);
174    static void bmp_write_to_file(int frame_number, const char* directory_name);
175    static void display(void);
176    static void idle(void);
177    static void update(void);
178    static void display_offscreen_buffer();
179    static int render_legend(TransferFunction *tf, double min, double max,
180        int width, int height, const char* volArg);
181    static Volume *load_volume(int index, int width, int height, int depth,
182        int n, float* data, double vmin, double vmax, double nzero_min);
183    static void xinetd_listen(void);
184    static int render_2d_contour(HeightMap* heightmap, int width, int height);
185    static void pan(float dx, float dy);
186
187#ifndef XINETD
188    static void keyboard(unsigned char key, int x, int y);
189    static void mouse(int button, int state, int x, int y);
190    static void motion(int x, int y);
191    static void update_rot(int delta_x, int delta_y);
192    static void update_trans(int delta_x, int delta_y, int delta_z);
193#endif
194
195    static FILE *stdin, *logfile, *recfile;
196
197    static void read_screen(void) {
198        glReadPixels(0, 0, win_width, win_height, GL_RGB, GL_UNSIGNED_BYTE,
199                screen_buffer);
200    }
201    static void offscreen_buffer_capture(void) {
202        glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, final_fbo);
203    }
204
205    static unsigned int flags;
206    static Tcl_HashTable flowTable;
207    static float magMin, magMax;
208    static float xMin, xMax, yMin, yMax, zMin, zMax, wMin, wMax;
209    static float xOrigin, yOrigin, zOrigin;
210
211    static FlowCmd *FirstFlow(FlowIterator *iterPtr);
212    static FlowCmd *NextFlow(FlowIterator *iterPtr);
213    static void InitFlows(void);
214    static int GetFlow(Tcl_Interp *interp, Tcl_Obj *objPtr,
215                       FlowCmd **flowPtrPtr);
216    static int CreateFlow(Tcl_Interp *interp, Tcl_Obj *objPtr);
217    static void DeleteFlows(Tcl_Interp *interp);
218    static bool MapFlows(void);
219    static void RenderFlows(void);
220    static void ResetFlows(void);
221    static bool UpdateFlows(void);
222    static void AdvectFlows(void);
223    enum NanoVisFlags {
224        REDRAW_PENDING=(1<<0),
225        MAP_FLOWS=(1<<1),
226        MAP_VOLUMES=(1<<2),
227        MAP_HEIGHTMAPS=(1<<3),
228    };
229    static void EventuallyRedraw(unsigned int flag = 0);
230};
231
232
233#endif  /* __NANOVIS_H__ */
Note: See TracBrowser for help on using the repository browser.