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

Last change on this file since 2381 was 2381, checked in by gah, 13 years ago
  • Property svn:eol-style set to native
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#define NANOVIS_VERSION         "1.0"
71
72//defines for the image based flow visualization
73#define NPN 256         //resolution of background pattern
74#define NMESH 256       //resolution of flow mesh
75#define DM  ((float) (1.0/(NMESH-1.0))) //distance in world coords between mesh lines
76#define NPIX  512       //display size
77#define SCALE 3.0       //scale for background pattern. small value -> fine texture
78
79class NvVectorField;
80
81struct Vector2 {
82    float x, y;
83    float mag(void) {
84        return sqrt(x*x+y*y);
85    }
86};
87
88struct RegGrid2{
89    int width, height;
90    Vector2* field;
91   
92    RegGrid2(int w, int h){
93        width = w;
94        height = h;
95        field = new Vector2[w*h];
96    }
97
98    void put(Vector2& v, int x ,int y) {
99        field[x+y*width] = v;
100    }
101   
102    Vector2& get(int x, int y) {
103        return field[x+y*width];
104    }
105};
106
107class NvLIC;
108class FlowCmd;
109class FlowIterator;
110
111class NanoVis {
112    //frame buffer for final rendering
113    static GLuint final_fbo, final_color_tex, final_depth_rb;
114public:
115public:
116    static VolumeRenderer* vol_renderer;
117    static PointSetRenderer* pointset_renderer;
118#ifndef NEW_FLOW_ENGINE
119    static NvParticleRenderer* flowVisRenderer;
120#else
121    static NvFlowVisRenderer* flowVisRenderer;
122#endif
123    static VelocityArrowsSlice* velocityArrowsSlice;
124    static NvLIC* licRenderer;
125    static vector<PointSet*> pointSet;
126    static PlaneRenderer* plane_render;
127
128    /**
129     *  pointers to 2D planes, currently handle up 10
130     */
131    static Texture2D* plane[10];
132    static NvColorTableRenderer* color_table_renderer;
133    static graphics::RenderContext* renderContext;
134    static vector<HeightMap*> heightMap;
135    static unsigned char* screen_buffer;
136    static Tcl_HashTable volumeTable;
137    static Tcl_HashTable heightmapTable;
138    static vector<NvVectorField*> flow;
139    static Grid* grid;
140    static R2Fonts* fonts;
141    static int updir;
142    static NvCamera *cam;
143
144    static float lic_slice_x;
145    static float lic_slice_y;
146    static float lic_slice_z;
147    static int lic_axis;        /* 0:x, 1:y, 2:z */
148
149    static bool axis_on;
150    static bool config_pending; // Indicates if the limits need to be recomputed.
151    static int win_width;       //size of the render window
152    static int win_height;      //size of the render window
153    static int render_window;
154
155    static bool debug_flag;
156
157    static Tcl_Interp *interp;
158    static Tcl_DString cmdbuffer;
159
160public :
161    static TransferFunction* get_transfunc(const char *name);
162    static TransferFunction* DefineTransferFunction(const char *name,
163        size_t n, float *data);
164    static void SetVolumeRanges(void);
165    static void SetHeightmapRanges(void);
166    static void init(const char* path);
167    static void initGL(void);
168    static void init_lic(void);
169    static void init_offscreen_buffer(void);
170    static void initParticle();
171    static void resize_offscreen_buffer(int w, int h);
172
173    // For development
174    static void resize(int w, int h);
175    static void render();
176
177    static void ppm_write(const char *prefix);
178    static void sendDataToClient(const char *command, const char *data,
179        size_t dlen);
180    static void bmp_write(const char *prefix);
181    static void bmp_write_to_file(int frame_number, const char* directory_name);
182    static void display(void);
183    static void idle(void);
184    static void update(void);
185    static void display_offscreen_buffer();
186    static int render_legend(TransferFunction *tf, double min, double max,
187        int width, int height, const char* volArg);
188    static Volume *load_volume(const char *tag, int width, int height,
189                int depth, int n, float* data, double vmin, double vmax,
190                double nzero_min);
191    static void xinetd_listen(void);
192    static int render_2d_contour(HeightMap* heightmap, int width, int height);
193    static void pan(float dx, float dy);
194
195#ifndef XINETD
196    static void keyboard(unsigned char key, int x, int y);
197    static void mouse(int button, int state, int x, int y);
198    static void motion(int x, int y);
199    static void update_rot(int delta_x, int delta_y);
200    static void update_trans(int delta_x, int delta_y, int delta_z);
201#endif
202
203    static FILE *stdin, *logfile, *recfile;
204
205    static void read_screen(void) {
206        glReadPixels(0, 0, win_width, win_height, GL_RGB, GL_UNSIGNED_BYTE,
207                screen_buffer);
208    }
209    static void offscreen_buffer_capture(void) {
210        glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, final_fbo);
211    }
212
213    static unsigned int flags;
214    static Tcl_HashTable flowTable;
215    static double magMin, magMax;
216    static float xMin, xMax, yMin, yMax, zMin, zMax, wMin, wMax;
217    static float xOrigin, yOrigin, zOrigin;
218
219    static FlowCmd *FirstFlow(FlowIterator *iterPtr);
220    static FlowCmd *NextFlow(FlowIterator *iterPtr);
221    static void InitFlows(void);
222    static int GetFlow(Tcl_Interp *interp, Tcl_Obj *objPtr,
223                       FlowCmd **flowPtrPtr);
224    static int CreateFlow(Tcl_Interp *interp, Tcl_Obj *objPtr);
225    static void DeleteFlows(Tcl_Interp *interp);
226    static bool MapFlows(void);
227    static void RenderFlows(void);
228    static void ResetFlows(void);
229    static bool UpdateFlows(void);
230    static void AdvectFlows(void);
231    enum NanoVisFlags {
232        REDRAW_PENDING=(1<<0),
233        MAP_FLOWS=(1<<1),
234        MAP_VOLUMES=(1<<2),
235        MAP_HEIGHTMAPS=(1<<3),
236    };
237    static void EventuallyRedraw(unsigned int flag = 0);
238    static void remove_volume(Volume *volPtr);
239    static Tcl_HashTable tfTable;
240};
241
242extern Volume *load_volume_stream(Rappture::Outcome &status, const char *tag,
243                        std::iostream& fin);
244extern Volume *load_volume_stream_odx(Rappture::Outcome &status,
245        const char *tag, const char *buf, int nBytes);
246extern Volume *load_volume_stream2(Rappture::Outcome &status, const char *tag,
247        std::iostream& fin);
248
249extern Volume *load_vector_stream(Rappture::Outcome &result, const char *tag,
250        size_t length, char *bytes);
251extern Volume *load_vector_stream2(Rappture::Outcome &result, const char *tag,
252        size_t length, char *bytes);
253
254
255#endif  /* __NANOVIS_H__ */
Note: See TracBrowser for help on using the repository browser.