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

Last change on this file since 1475 was 1475, checked in by vrinside, 15 years ago

mofified a way of dealing with volumes by adding reference counts to data objects.

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