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

Last change on this file since 2831 was 2831, checked in by ldelgass, 13 years ago

Refactor texture classes, misc. cleanups, cut down on header pollution -- still
need to fix header deps in Makefile.in

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