00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef FILERENDERER_H
00024 #define FILERENDERER_H
00025
00026 #include <stdio.h>
00027
00028 #include "DisplayDevice.h"
00029 #include "Scene.h"
00030 #include "NameList.h"
00031 #include "Inform.h"
00032
00033 #define FILERENDERER_NOWARNINGS 0
00034 #define FILERENDERER_NOMISCFEATURE 1
00035 #define FILERENDERER_NOCLIP 2
00036 #define FILERENDERER_NOCUEING 4
00037 #define FILERENDERER_NOTEXTURE 8
00038 #define FILERENDERER_NOGEOM 16
00039 #define FILERENDERER_NOTEXT 32
00040
00044 class FileRenderer : public DisplayDevice {
00045 protected:
00046
00047 char *publicName, *defaultFilename, *defaultCommandLine;
00048 char *execCmd;
00049 FILE *outfile;
00050 int isOpened;
00051 char *my_filename;
00052 int has_aa;
00053 int aalevel;
00054 int has_imgsize;
00055
00056 int warningflags;
00057
00058
00059 int imgwidth, imgheight;
00060 float aspectratio;
00061 NameList<int> formats;
00062 int curformat;
00063
00066 virtual void update_exec_cmd() {}
00067
00069 struct LightState {
00070 float color[3];
00071 float pos[3];
00072 int on;
00073 };
00074
00075 LightState lightState[DISP_LIGHTS];
00076
00078 float matData[MAXCOLORS][3];
00079 virtual void do_use_colors();
00080
00082 float backColor[3];
00083
00084 public:
00086 FileRenderer(const char *public_name, const char *default_file_name,
00087 const char *default_command_line);
00088 virtual ~FileRenderer(void);
00089
00090 const char *visible_name(void) const { return publicName;}
00091 const char *default_filename(void) const {return defaultFilename;}
00092 const char *default_exec_string(void) const {return defaultCommandLine;}
00093 const char *saved_exec_string(void) const { return execCmd; }
00094
00095 void set_exec_string(const char *);
00096
00098 int has_antialiasing() const { return has_aa; }
00099
00101 int set_aalevel(int newval) {
00102 if (has_aa && newval >= 0) {
00103 aalevel = newval;
00104 update_exec_cmd();
00105 }
00106 return aalevel;
00107 }
00108
00110 int has_imagesize() const { return has_imgsize; }
00111
00116 int set_imagesize(int *w, int *h);
00117
00120 float set_aspectratio(float aspect);
00121
00123 int numformats() const { return formats.num(); }
00124
00126 const char *format(int i) const { return formats.name(i); }
00127 const char *format() const { return formats.name(curformat); }
00128 int set_format(const char *format) {
00129 int ind = formats.typecode(format);
00130 if (ind < 0) return FALSE;
00131 if (curformat != ind) {
00132 curformat = ind;
00133 update_exec_cmd();
00134 }
00135 return TRUE;
00136 }
00137
00139 virtual void set_background(const float *);
00140
00145 virtual int open_file(const char *filename);
00146
00147 virtual int do_define_light(int n, float *color, float *position);
00148 virtual int do_activate_light(int n, int turnon);
00149
00150 private:
00151 void reset_state(void);
00152 int sph_nverts;
00153 float *sph_verts;
00154
00155 protected:
00157 virtual void write_header(void) {};
00158
00159 public:
00160 virtual int prepare3D(int);
00161 virtual void render(const VMDDisplayList *);
00162
00163 protected:
00165 virtual void write_trailer(void) {};
00166
00170 virtual void close_file(void);
00171
00172 public:
00174 virtual void update(int) {
00175 if (isOpened) {
00176 write_trailer();
00177 close_file();
00178 isOpened = FALSE;
00179
00180
00181
00182 if (warningflags & FILERENDERER_NOCLIP)
00183 msgWarn << "User-defined clipping planes not exported for this renderer" << sendmsg;
00184
00185 if (warningflags & FILERENDERER_NOTEXT)
00186 msgWarn << "Text not exported for this renderer" << sendmsg;
00187
00188 if (warningflags & FILERENDERER_NOTEXTURE)
00189 msgWarn << "Texture mapping not exported for this renderer" << sendmsg;
00190
00191 if (warningflags & FILERENDERER_NOCUEING)
00192 msgWarn << "Depth cueing not exported for this renderer" << sendmsg;
00193
00194 if (warningflags & FILERENDERER_NOGEOM)
00195 msgWarn << "One or more geometry types not exported for this renderer" << sendmsg;
00196
00197 if (warningflags != FILERENDERER_NOWARNINGS)
00198 msgWarn << "Unimplemented features may negatively affect the appearance of the scene" << sendmsg;
00199 }
00200 }
00201
00202 protected:
00204 float *dataBlock;
00205
00207
00208
00209
00210 Stack<Matrix4> transMat;
00211 void super_load(float *cmdptr);
00212 virtual void load(const Matrix4& ) {}
00213 void super_multmatrix(const float *cmdptr);
00214 virtual void multmatrix(const Matrix4& ) {}
00215 void super_translate(float *cmdptr);
00216 virtual void translate(float , float , float ) {}
00217 void super_rot(float *cmdptr);
00218 virtual void rot(float , char ) {}
00219 void super_scale(float *cmdptr);
00220 void super_scale(float);
00221 virtual void scale(float , float ,
00222 float ) {}
00223 float scale_radius(float);
00224
00225
00226 int colorIndex;
00227 void super_set_color(int index);
00228 virtual void set_color(int) {}
00229
00234 int nearest_index(float r, float g, float b) const;
00235
00236
00237 int materialIndex;
00238 float mat_ambient;
00239 float mat_diffuse;
00240 float mat_specular;
00241 float mat_shininess;
00242 float mat_opacity;
00243 void super_set_material(int index);
00244 virtual void set_material(int) {}
00245
00246 float clip_center[VMD_MAX_CLIP_PLANE][3];
00247 float clip_normal[VMD_MAX_CLIP_PLANE][3];
00248 float clip_color[VMD_MAX_CLIP_PLANE][3];
00249 int clip_mode[VMD_MAX_CLIP_PLANE];
00250
00251 virtual void start_clipgroup();
00252 virtual void end_clipgroup() {}
00253
00254
00255 int lineWidth, lineStyle, pointSize;
00256 virtual void set_line_width(int new_width) {
00257 lineWidth = new_width;
00258 }
00259 virtual void set_line_style(int ) {}
00260
00261
00262 int sphereResolution, sphereStyle;
00263 virtual void set_sphere_res(int ) {}
00264 virtual void set_sphere_style(int ) {}
00265
00266 int materials_on;
00267 void super_materials(int on_or_off);
00268 virtual void activate_materials(void) {}
00269 virtual void deactivate_materials(void) {}
00270
00271
00273
00274
00275 virtual void cone(float * xyz1, float * xyz2, float radius, int resolution) {
00276 cone(xyz1, xyz2, radius, 0.0, resolution);
00277 }
00278
00279
00280
00281 virtual void cone(float * , float * ,
00282 float , float , int );
00283
00284
00285
00286 virtual void cylinder(float * base, float * apex, float radius, int filled);
00287
00288
00289
00290 virtual void line(float * a, float * b);
00291
00292
00293
00294 virtual void point(float * xyz) {
00295 float xyzr[4];
00296 vec_copy(xyzr, xyz);
00297 xyzr[3] = lineWidth * 0.002f;
00298 }
00299
00300
00301
00302 virtual void sphere(float * xyzr);
00303
00304
00305
00306 virtual void square(float * norm, float * a, float * b,
00307 float * c, float * d) {
00308
00309 triangle(a, b, c, norm, norm, norm);
00310 triangle(a, c, d, norm, norm, norm);
00311 }
00312
00313
00314
00315 virtual void triangle(const float * , const float * , const float * ,
00316 const float * , const float * , const float * ) {
00317 warningflags |= FILERENDERER_NOGEOM;
00318 }
00319
00320
00321
00322 virtual void tricolor(const float * xyz1, const float * xyz2, const float * xyz3,
00323 const float * n1, const float * n2, const float * n3,
00324 const float *c1, const float *c2, const float *c3) {
00325 int index = 1;
00326 float r, g, b;
00327 r = (c1[0] + c2[0] + c3[0]) / 3.0f;
00328 g = (c1[1] + c2[1] + c3[1]) / 3.0f;
00329 b = (c1[2] + c2[2] + c3[2]) / 3.0f;
00330
00331 index = nearest_index(r,g,b);
00332 super_set_color(index);
00333
00334 triangle(xyz1, xyz2, xyz3, n1, n2, n3);
00335 }
00336
00337
00338
00339 virtual void trimesh(int , float * cnv,
00340 int numfacets, int * facets) {
00341 int i;
00342 for (i=0; i<numfacets*3; i+=3) {
00343 int v0 = facets[i ] * 10;
00344 int v1 = facets[i + 1] * 10;
00345 int v2 = facets[i + 2] * 10;
00346 tricolor(cnv + v0 + 7,
00347 cnv + v1 + 7,
00348 cnv + v2 + 7,
00349 cnv + v0 + 4,
00350 cnv + v1 + 4,
00351 cnv + v2 + 4,
00352 cnv + v0,
00353 cnv + v1,
00354 cnv + v2);
00355 }
00356 }
00357
00358
00359
00360 virtual void tristrip(int , const float * cnv,
00361 int numstrips, const int *vertsperstrip,
00362 const int *facets) {
00363
00364
00365
00366 int strip, t, v = 0;
00367 int stripaddr[2][3] = { {0, 1, 2}, {1, 0, 2} };
00368
00369
00370 for (strip=0; strip < numstrips; strip++) {
00371
00372 for (t = 0; t < (vertsperstrip[strip] - 2); t++) {
00373
00374 int v0 = facets[v + (stripaddr[t & 0x01][0])] * 10;
00375 int v1 = facets[v + (stripaddr[t & 0x01][1])] * 10;
00376 int v2 = facets[v + (stripaddr[t & 0x01][2])] * 10;
00377
00378 tricolor(cnv + v0 + 7,
00379 cnv + v1 + 7,
00380 cnv + v2 + 7,
00381 cnv + v0 + 4,
00382 cnv + v1 + 4,
00383 cnv + v2 + 4,
00384 cnv + v0,
00385 cnv + v1,
00386 cnv + v2);
00387 v++;
00388 }
00389 v+=2;
00390 }
00391 }
00392
00393
00394
00395 virtual void define_volume_texture(int ID, int xs, int ys, int zs,
00396 const float *xplaneeq,
00397 const float *yplaneeq,
00398 const float *zplaneeq,
00399 unsigned char *texmap) {
00400 warningflags |= FILERENDERER_NOTEXTURE;
00401 }
00402
00403
00404
00405 virtual void volume_texture_on(int texmode) {
00406 warningflags |= FILERENDERER_NOTEXTURE;
00407 }
00408
00409
00410
00411 virtual void volume_texture_off(void) {
00412 warningflags |= FILERENDERER_NOTEXTURE;
00413 }
00414
00415
00416
00417 virtual void wiremesh(int , float * cnv,
00418 int numlines, int * lines) {
00419 int i;
00420 int index = 1;
00421
00422 for (i=0; i<numlines; i++) {
00423 float r, g, b;
00424 int ind = i * 2;
00425 int v0 = lines[ind ] * 10;
00426 int v1 = lines[ind + 1] * 10;
00427
00428 r = cnv[v0 + 0] + cnv[v1 + 0] / 2.0f;
00429 g = cnv[v0 + 1] + cnv[v1 + 1] / 2.0f;
00430 b = cnv[v0 + 2] + cnv[v1 + 2] / 2.0f;
00431
00432 index = nearest_index(r,g,b);
00433 super_set_color(index);
00434
00435 line(cnv + v0 + 7, cnv + v1 + 7);
00436 }
00437 }
00438
00439
00440 virtual void text(const char *);
00441 virtual void comment(const char *) {}
00442
00443 float textpos[3];
00444 void super_text_position(float x, float y, float z);
00445 virtual void text_position(float , float , float ) {
00446 warningflags |= FILERENDERER_NOTEXT;
00447 }
00448
00450 virtual void pick_point(float * , int ) {}
00451
00452 };
00453
00454 #endif
00455