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

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