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

Last change on this file since 2822 was 2822, checked in by ldelgass, 9 years ago

Const correctness fixes, pass vector/matrix objects by reference, various
formatting and style cleanups, don't spam syslog and uncomment openlog() call.
Still needs to be compiled with -DWANT_TRACE to get tracing, but now trace
output will be output to file in /tmp.

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