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

Last change on this file since 2837 was 2836, checked in by ldelgass, 12 years ago

More cleanups, remove NEW_FLOW_ENGINE define flag

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