Changeset 5267
- Timestamp:
- May 2, 2008, 12:13:55 PM (17 years ago)
- Location:
- anuga_work/development/anugavis/src
- Files:
-
- 8 edited
- 2 moved
Legend:
- Unmodified
- Added
- Removed
-
anuga_work/development/anugavis/src/Makefile.am
r5263 r5267 15 15 netcdf_util.c \ 16 16 netcdf_util.h \ 17 x malloc.c \18 x malloc.h17 xfunctions.c \ 18 xfunctions.h 19 19 libanugavis_a_CFLAGS = @SDL_CFLAGS@ @GLU_CFLAGS@ 20 20 libanugavis_a_LIBADD = @LIBOBJS@ -
anuga_work/development/anugavis/src/anugavis_simple.c
r5264 r5267 14 14 return 1; 15 15 } 16 printf("%d\n", anugavis.number_of_timesteps); 16 17 if(AnugaVis_DefineHeightQuantity("elevation", 0, 1, 128, 128, 128) == -1){ 17 18 printf("AnugaVis_DefineHeightQuantity() Error: %s\n", AnugaVis_GetError()); -
anuga_work/development/anugavis/src/error.c
r5260 r5267 1 #ifdef HAVE_CONFIG_H 2 # include "config.h" 3 #endif 4 5 #ifdef HAVE_GL_GLU_H 6 # include <GL/glu.h> 7 #elif HAVE_OPENGL_GLU_H 8 # include <OpenGL/glu.h> 9 #endif 1 10 #include <stdarg.h> 2 11 #include <netcdf.h> … … 4 13 #include "error.h" 5 14 6 #define MAX_ERROR_LEN 10015 #define MAX_ERROR_LEN 200 7 16 8 17 static char error[MAX_ERROR_LEN]; … … 27 36 AnugaVis_SetError("NetCDF Error: %s", nc_strerror(ncerr)); 28 37 } 38 39 void AnugaVis_OpenGLError(GLenum errorCode){ 40 AnugaVis_SetError("OpenGL Error: %s", gluErrorString(errorCode)); 41 } -
anuga_work/development/anugavis/src/error.h
r5259 r5267 1 1 #ifndef ANUGAVIS_ERROR_H 2 2 #define ANUGAVIS_ERROR_H 3 4 #ifdef HAVE_CONFIG_H 5 # include "config.h" 6 #endif 7 8 #ifdef HAVE_GL_GL_H 9 # include <GL/gl.h> 10 #elif HAVE_OPENGL_GL_H 11 # include <OpenGL/gl.h> 12 #endif 3 13 4 14 /* Set the error message with a printf-style format string. 5 15 */ 6 16 void AnugaVis_SetError(const char *format, ...); 7 8 17 /* Report a SDL error. 9 18 */ 10 19 void AnugaVis_SDLError(void); 11 12 20 /* Report a NetCDF error. 13 21 */ 14 22 void AnugaVis_NetCDFError(int ncerr); 23 /* Report an OpenGL error. 24 */ 25 void AnugaVis_OpenGLError(GLenum errorCode); 15 26 16 27 /* Get detailed error information. The returned string should not be -
anuga_work/development/anugavis/src/globals.h
r5264 r5267 8 8 SDL_Surface *screen; 9 9 int netcdfId; 10 /* These are populated from the NetCDF file */ 10 11 size_t number_of_points; 11 12 size_t number_of_vertices; 12 13 size_t number_of_volumes; 14 size_t number_of_timesteps; 13 15 float *x; 14 16 float *y; -
anuga_work/development/anugavis/src/height_quantity.c
r5261 r5267 9 9 # include <string.h> 10 10 #endif 11 #ifdef HAVE_GL_GL_H 12 # include <GL/gl.h> 13 #elif HAVE_OPENGL_GL_H 14 # include <OpenGL/gl.h> 15 #endif 11 16 #include <netcdf.h> 12 17 #include <SDL.h> … … 14 19 #include "globals.h" 15 20 #include "height_quantity.h" 16 #include "xmalloc.h" 21 #include "netcdf_util.h" 22 #include "xfunctions.h" 23 24 static int compileDisplayLists(struct height_quantity_simple *height){ 25 int frame; 26 unsigned int vol; 27 unsigned int vertex; 28 int vertIndex; 29 int x[3]; 30 int y[3]; 31 int z[3]; 32 float *heights = xmalloc(sizeof(float) 33 * anugavis.number_of_points 34 * height->frames, "compileDisplayLists()"); 35 if(heights == NULL) 36 return -1; 37 if(nc_get_var_float_by_name(anugavis.netcdfId, 38 height->name, heights) != NC_NOERR){ 39 free(heights); 40 return -1; 41 } 42 43 for(frame = 0 ; frame < height->frames ; frame++){ 44 glNewList(height->displayLists + frame, GL_COMPILE); 45 for(vol = 0 ; vol < anugavis.number_of_volumes ; vol++){ 46 glBegin(GL_POLYGON); 47 for(vertex = 0 ; vertex < 3 ; vertex++){ /* Calculate normal */ 48 vertIndex = anugavis.volumes[vol*anugavis.number_of_vertices + vertex]; 49 x[vertex] = anugavis.x[vertIndex]; 50 y[vertex] = anugavis.y[vertIndex]; 51 z[vertex] = heights[frame * anugavis.number_of_timesteps + vertIndex]; 52 } 53 glNormal3f((y[1] - y[0]) * (z[2] - z[0]) - (z[1] - z[0]) * (y[2] - y[0]), 54 (z[1] - z[0]) * (x[2] - x[0]) - (x[1] - x[0]) * (z[2] - z[0]), 55 (x[1] - x[0]) * (y[2] - y[0]) - (y[1] - y[0]) * (x[2] - x[0])); 56 for(vertex = 0 ; vertex < anugavis.number_of_vertices ; vertex++){ 57 vertIndex = anugavis.volumes[vol*anugavis.number_of_vertices + vertex]; 58 glVertex3f(anugavis.x[vertIndex], anugavis.y[vertIndex], 59 heights[frame * anugavis.number_of_timesteps + vertIndex]); 60 } 61 glEnd(); 62 } 63 glEndList(); 64 } 65 66 free(heights); 67 return 0; 68 } 69 70 static void freeHeightQuantity(struct height_quantity_simple *height){ 71 if(height->name != NULL) free(height->name); 72 if(glIsList(height->displayLists) == GL_TRUE) 73 glDeleteLists(height->displayLists, height->frames); 74 free(height); 75 } 17 76 18 77 int AnugaVis_DefineHeightQuantity(const char *name, … … 23 82 int ncvarid; 24 83 int numdims; 84 GLenum glerror; 25 85 /* Check that it's actually in the NetCDF file */ 26 86 if((ncstatus = nc_inq_varid(anugavis.netcdfId, name, &ncvarid)) != NC_NOERR){ … … 37 97 "AnugaVis_DefineHeightQuantity()")) == NULL) 38 98 return -1; 99 100 height->name = NULL; 101 height->displayLists = -1; 102 103 if((height->name = xstrdup(name, 104 "AnugaVis_DefineHeightQuantity()")) == NULL){ 105 freeHeightQuantity(height); 106 return -1; 107 } 108 109 /* If the NetCDF variable is 2-dimensional, then it's dynamic. */ 110 if((ncstatus = nc_inq_varndims(anugavis.netcdfId, 111 ncvarid, &numdims)) != NC_NOERR){ 112 AnugaVis_NetCDFError(ncstatus); 113 freeHeightQuantity(height); 114 return -1; 115 } 116 117 height->frames = (numdims == 2) ? anugavis.number_of_timesteps : 1; 118 height->displayLists = glGenLists(height->frames); 119 if((glerror = glGetError()) != GL_NO_ERROR){ 120 AnugaVis_OpenGLError(glerror); 121 freeHeightQuantity(height); 122 return -1; 123 } 124 125 if(compileDisplayLists(height) == -1){ 126 freeHeightQuantity(height); 127 return -1; 128 } 129 39 130 height->next = anugavis.heights; 40 131 anugavis.heights = height; 41 132 } 42 43 /* If the NetCDF variable is 2-dimensional, then it's dynamic. */ 44 if((ncstatus = nc_inq_varndims(anugavis.netcdfId, 45 ncvarid, &numdims)) != NC_NOERR){ 46 AnugaVis_NetCDFError(ncstatus); 47 return -1; 48 } 49 height->dynamic = (numdims == 2); 133 50 134 height->offset = offset; 51 135 height->scale = scale; … … 60 144 if(!strcmp(name, height->name)){ 61 145 anugavis.heights = height->next; 62 free (height);146 freeHeightQuantity(height); 63 147 return; 64 148 } … … 68 152 nextHeight = height->next; 69 153 height->next = height->next->next; 70 free (nextHeight);154 freeHeightQuantity(nextHeight); 71 155 return; 72 156 } -
anuga_work/development/anugavis/src/height_quantity.h
r5259 r5267 2 2 #define HEIGHT_QUANTITY_H 3 3 4 #ifdef HAVE_CONFIG_H 5 # include "config.h" 6 #endif 7 8 #ifdef HAVE_GL_GL_H 9 # include <GL/gl.h> 10 #elif HAVE_OPENGL_GL_H 11 # include <OpenGL/gl.h> 12 #endif 4 13 #include <SDL.h> 5 14 6 15 struct height_quantity_simple{ 7 16 char *name; 8 uint8_t dynamic;17 uint8_t frames; 9 18 double offset; 10 19 double scale; 11 20 Uint32 color; 21 GLuint displayLists; 12 22 struct height_quantity_simple *next; 13 23 }; -
anuga_work/development/anugavis/src/init.c
r5264 r5267 20 20 #include "error.h" 21 21 #include "globals.h" 22 #include "init.h" 22 23 #include "netcdf_util.h" 23 #include "x malloc.h"24 #include "xfunctions.h" 24 25 25 26 int AnugaVis_Init(int width, int height, const char *swwFilePath){ … … 43 44 } 44 45 46 SDL_WM_SetCaption("ANUGA Visualiser", "ANUGA Visualiser"); 45 47 glEnable(GL_DEPTH_TEST); 46 48 glShadeModel(GL_FLAT); … … 63 65 (nc_inq_dimlen_by_name(anugavis.netcdfId, "number_of_volumes", 64 66 &anugavis.number_of_volumes) != NC_NOERR) || 67 (nc_inq_dimlen_by_name(anugavis.netcdfId, "number_of_timesteps", 68 &anugavis.number_of_timesteps) != NC_NOERR) || 65 69 ((anugavis.x = xmalloc(sizeof(float) * anugavis.number_of_points, 66 70 "AnugaVis_Init()")) == NULL) || … … 77 81 (nc_get_var_int_by_name(anugavis.netcdfId, "volumes", 78 82 anugavis.volumes) != NC_NOERR)){ 79 nc_close(anugavis.netcdfId); 80 if(anugavis.x != NULL) free(anugavis.x); 81 if(anugavis.y != NULL) free(anugavis.y); 82 if(anugavis.volumes != NULL) free(anugavis.volumes); 83 SDL_Quit(); 83 AnugaVis_DeInit(); 84 84 return -1; 85 85 } … … 91 91 AnugaVis_UndefineHeightQuantity(anugavis.heights->name); 92 92 nc_close(anugavis.netcdfId); 93 free(anugavis.x);94 free(anugavis.y);95 free(anugavis.volumes);93 if(anugavis.x != NULL) free(anugavis.x); 94 if(anugavis.y != NULL) free(anugavis.y); 95 if(anugavis.volumes != NULL) free(anugavis.volumes); 96 96 SDL_Quit(); 97 97 } -
anuga_work/development/anugavis/src/xfunctions.c
r5266 r5267 10 10 #endif 11 11 #include "error.h" 12 #include "x malloc.h"12 #include "xfunctions.h" 13 13 14 14 void *xmalloc(size_t size, const char *message){ -
anuga_work/development/anugavis/src/xfunctions.h
r5266 r5267 1 #ifndef X MALLOC_H2 #define X MALLOC_H1 #ifndef XFUNCTIONS_H 2 #define XFUNCTIONS_H 3 3 4 4 /* For a given func, xfunc behaves like func but sets an error message 5 * using AnugaVis_SetError() .5 * using AnugaVis_SetError() if something goes wrong. 6 6 */ 7 7 extern void *xmalloc(size_t size, const char *message);
Note: See TracChangeset
for help on using the changeset viewer.