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 char *publicName;
00047 char *publicPrettyName;
00048 char *defaultFilename;
00049 char *defaultCommandLine;
00050
00051 char *execCmd;
00052 FILE *outfile;
00053 int isOpened;
00054 char *my_filename;
00055 int has_aa;
00056 int aasamples;
00057 int aosamples;
00058 int has_imgsize;
00059
00060 int warningflags;
00061
00062
00063 int imgwidth, imgheight;
00064 float aspectratio;
00065 NameList<int> formats;
00066 int curformat;
00067
00068 float textoffset_x;
00069 float textoffset_y;
00070
00073 virtual void update_exec_cmd() {}
00074
00076 struct LightState {
00077 float color[3];
00078 float pos[3];
00079 int on;
00080 };
00081 LightState lightState[DISP_LIGHTS];
00082
00084 struct AdvancedLightState {
00085 float color[3];
00086 float pos[3];
00087 float constfactor;
00088 float linearfactor;
00089 float quadfactor;
00090 float spotdir[3];
00091 float fallstart;
00092 float fallend;
00093 int spoton;
00094 int on;
00095 };
00096 AdvancedLightState advLightState[DISP_LIGHTS];
00097
00099 float matData[MAXCOLORS][3];
00100 virtual void do_use_colors();
00101
00103 float backColor[3];
00104
00105 float backgradientenabled;
00106 float backgradienttopcolor[3];
00107 float backgradientbotcolor[3];
00108
00109 public:
00111 FileRenderer(const char *public_name,
00112 const char *public_pretty_name,
00113 const char *default_file_name,
00114 const char *default_command_line);
00115 virtual ~FileRenderer(void);
00116
00117 const char *visible_name(void) const { return publicName;}
00118 const char *pretty_name(void) const { return publicPrettyName;}
00119 const char *default_filename(void) const {return defaultFilename;}
00120 const char *default_exec_string(void) const {return defaultCommandLine;}
00121 const char *saved_exec_string(void) const { return execCmd; }
00122
00123 void set_exec_string(const char *);
00124
00126 int has_antialiasing() const { return has_aa; }
00127
00129 int set_aasamples(int newval) {
00130 if (has_aa && (newval >= 0)) {
00131 aasamples = newval;
00132 update_exec_cmd();
00133 }
00134 return aasamples;
00135 }
00136
00138 int set_aosamples(int newval) {
00139 if (newval >= 0) {
00140 aosamples = newval;
00141 update_exec_cmd();
00142 }
00143 return aosamples;
00144 }
00145
00147 int has_imagesize() const { return has_imgsize; }
00148
00153 int set_imagesize(int *w, int *h);
00154
00157 float set_aspectratio(float aspect);
00158
00160 int numformats() const { return formats.num(); }
00161
00163 const char *format(int i) const { return formats.name(i); }
00164 const char *format() const { return formats.name(curformat); }
00165 int set_format(const char *format) {
00166 int ind = formats.typecode(format);
00167 if (ind < 0) return FALSE;
00168 if (curformat != ind) {
00169 curformat = ind;
00170 update_exec_cmd();
00171 }
00172 return TRUE;
00173 }
00174
00176 virtual void set_background(const float *);
00177
00179 virtual void set_backgradient(const float *top, const float *bot);
00180
00185 virtual int open_file(const char *filename);
00186
00187 virtual int do_define_light(int n, float *color, float *position);
00188 virtual int do_activate_light(int n, int turnon);
00189
00190 virtual int do_define_adv_light(int n, float *color, float *position,
00191 float constant, float linear, float quad,
00192 float *spotdir, float fallstart,
00193 float fallend, int spoton);
00194 virtual int do_activate_adv_light(int n, int turnon);
00195
00196 private:
00197 int sph_nverts;
00198 float *sph_verts;
00199
00200 protected:
00202 virtual void write_header(void) {};
00203 void reset_state(void);
00204
00205 public:
00206 virtual int prepare3D(int);
00207 virtual void render(const VMDDisplayList *);
00208
00209 protected:
00211 virtual void write_trailer(void) {};
00212
00216 virtual void close_file(void);
00217
00218 public:
00220 virtual void update(int) {
00221 if (isOpened) {
00222 write_trailer();
00223 close_file();
00224 isOpened = FALSE;
00225
00226
00227
00228 if (warningflags & FILERENDERER_NOCLIP)
00229 msgWarn << "User-defined clipping planes not exported for this renderer" << sendmsg;
00230
00231 if (warningflags & FILERENDERER_NOTEXT)
00232 msgWarn << "Text not exported for this renderer" << sendmsg;
00233
00234 if (warningflags & FILERENDERER_NOTEXTURE)
00235 msgWarn << "Texture mapping not exported for this renderer" << sendmsg;
00236
00237 if (warningflags & FILERENDERER_NOCUEING)
00238 msgWarn << "Depth cueing not exported for this renderer" << sendmsg;
00239
00240 if (warningflags & FILERENDERER_NOGEOM)
00241 msgWarn << "One or more geometry types not exported for this renderer" << sendmsg;
00242
00243 if (warningflags != FILERENDERER_NOWARNINGS)
00244 msgWarn << "Unimplemented features may negatively affect the appearance of the scene" << sendmsg;
00245 }
00246 }
00247
00248 protected:
00250
00251
00252
00253 Stack<Matrix4> transMat;
00254 void super_load(float *cmdptr);
00255 virtual void load(const Matrix4& ) {}
00256 void super_multmatrix(const float *cmdptr);
00257 virtual void multmatrix(const Matrix4& ) {}
00258 void super_translate(float *cmdptr);
00259 virtual void translate(float , float , float ) {}
00260 void super_rot(float *cmdptr);
00261 virtual void rot(float , char ) {}
00262 void super_scale(float *cmdptr);
00263 void super_scale(float);
00264 virtual void scale(float , float ,
00265 float ) {}
00266
00267 float scale_factor(void);
00268
00269 float scale_radius(float);
00270
00271
00272 int colorIndex;
00273 void super_set_color(int index);
00274 virtual void set_color(int) {}
00275
00280 int nearest_index(float r, float g, float b) const;
00281
00282
00283 int materialIndex;
00284 float mat_ambient;
00285 float mat_diffuse;
00286 float mat_specular;
00287 float mat_shininess;
00288 float mat_opacity;
00289 float mat_outline;
00290 float mat_outlinewidth;
00291 float mat_transmode;
00292 void super_set_material(int index);
00293 virtual void set_material(int) {}
00294
00295 float clip_center[VMD_MAX_CLIP_PLANE][3];
00296 float clip_normal[VMD_MAX_CLIP_PLANE][3];
00297 float clip_color[VMD_MAX_CLIP_PLANE][3];
00298 int clip_mode[VMD_MAX_CLIP_PLANE];
00299
00300 virtual void start_clipgroup();
00301 virtual void end_clipgroup() {}
00302
00303
00304 int lineWidth, lineStyle, pointSize;
00305 virtual void set_line_width(int new_width) {
00306 lineWidth = new_width;
00307 }
00308 virtual void set_line_style(int ) {}
00309
00310
00311 int sphereResolution, sphereStyle;
00312 virtual void set_sphere_res(int ) {}
00313 virtual void set_sphere_style(int ) {}
00314
00315 int materials_on;
00316 void super_materials(int on_or_off);
00317 virtual void activate_materials(void) {}
00318 virtual void deactivate_materials(void) {}
00319
00320
00322
00324 virtual void cone(float * xyz1, float * xyz2, float radius, int resolution) {
00325 cone(xyz1, xyz2, radius, 0.0, resolution);
00326 }
00327
00329 virtual void cone(float * , float * ,
00330 float , float , int );
00331
00332
00334 virtual void cylinder(float * base, float * apex, float radius, int filled);
00335
00336
00338 virtual void line(float * a, float * b);
00339
00341 virtual void line_array(int num, float thickness, float *points);
00342
00344 virtual void polyline_array(int num, float thickness, float *points);
00345
00346
00348 virtual void point(float * xyz) {
00349 float xyzr[4];
00350 vec_copy(xyzr, xyz);
00351 xyzr[3] = lineWidth * 0.002f;
00352 }
00353
00355 virtual void point_array(int num, float size, float *xyz, float *colors);
00356
00358 virtual void point_array_lit(int num, float size,
00359 float *xyz, float *norm, float *colors);
00360
00361
00363 virtual void sphere(float * xyzr);
00364
00366 virtual void sphere_array(int num, int res, float *centers, float *radii, float *colors);
00367
00368
00370 virtual void square(float * norm, float * a, float * b,
00371 float * c, float * d) {
00372
00373 triangle(a, b, c, norm, norm, norm);
00374 triangle(a, c, d, norm, norm, norm);
00375 }
00376
00377
00379 virtual void triangle(const float * , const float * , const float * ,
00380 const float * , const float * , const float * ) {
00381 warningflags |= FILERENDERER_NOGEOM;
00382 }
00383
00384
00386 virtual void tricolor(const float * xyz1, const float * xyz2, const float * xyz3,
00387 const float * n1, const float * n2, const float * n3,
00388 const float *c1, const float *c2, const float *c3) {
00389 int index = 1;
00390 float r, g, b;
00391 r = (c1[0] + c2[0] + c3[0]) / 3.0f;
00392 g = (c1[1] + c2[1] + c3[1]) / 3.0f;
00393 b = (c1[2] + c2[2] + c3[2]) / 3.0f;
00394
00395 index = nearest_index(r,g,b);
00396 super_set_color(index);
00397
00398 triangle(xyz1, xyz2, xyz3, n1, n2, n3);
00399 }
00400
00402 virtual void trimesh_n3v3(float *n, float *v, int numfacets) {
00403 int i;
00404 for (i=0; i<numfacets*9; i+=9) {
00405 triangle(v + i ,
00406 v + i + 3,
00407 v + i + 6,
00408 n + i ,
00409 n + i + 3,
00410 n + i + 6);
00411 }
00412 }
00413
00415 virtual void trimesh_c3n3v3(float *c, float *n, float *v, int numfacets) {
00416 int i;
00417 for (i=0; i<numfacets*9; i+=9) {
00418 tricolor(v + i ,
00419 v + i + 3,
00420 v + i + 6,
00421 n + i ,
00422 n + i + 3,
00423 n + i + 6,
00424 c + i ,
00425 c + i + 3,
00426 c + i + 6);
00427 }
00428 }
00429
00431 virtual void trimesh_c4n3v3(int , float * cnv,
00432 int numfacets, int * facets) {
00433 int i;
00434 for (i=0; i<numfacets*3; i+=3) {
00435 int v0 = facets[i ] * 10;
00436 int v1 = facets[i + 1] * 10;
00437 int v2 = facets[i + 2] * 10;
00438 tricolor(cnv + v0 + 7,
00439 cnv + v1 + 7,
00440 cnv + v2 + 7,
00441 cnv + v0 + 4,
00442 cnv + v1 + 4,
00443 cnv + v2 + 4,
00444 cnv + v0,
00445 cnv + v1,
00446 cnv + v2);
00447 }
00448 }
00449
00450
00452 virtual void trimesh_singlecolor(int cindex, int , float * nv,
00453 int numfacets, int * facets) {
00454 super_set_color(cindex);
00455
00456 int i;
00457 for (i=0; i<numfacets*3; i+=3) {
00458 int v0 = facets[i ] * 6;
00459 int v1 = facets[i + 1] * 6;
00460 int v2 = facets[i + 2] * 6;
00461 triangle(nv + v0 + 3,
00462 nv + v1 + 3,
00463 nv + v2 + 3,
00464 nv + v0,
00465 nv + v1,
00466 nv + v2);
00467 }
00468 }
00469
00470
00472 virtual void tristrip(int , const float * cnv,
00473 int numstrips, const int *vertsperstrip,
00474 const int *facets) {
00475
00476
00477
00478 int strip, t, v = 0;
00479 int stripaddr[2][3] = { {0, 1, 2}, {1, 0, 2} };
00480
00481
00482 for (strip=0; strip < numstrips; strip++) {
00483
00484 for (t = 0; t < (vertsperstrip[strip] - 2); t++) {
00485
00486 int v0 = facets[v + (stripaddr[t & 0x01][0])] * 10;
00487 int v1 = facets[v + (stripaddr[t & 0x01][1])] * 10;
00488 int v2 = facets[v + (stripaddr[t & 0x01][2])] * 10;
00489
00490 tricolor(cnv + v0 + 7,
00491 cnv + v1 + 7,
00492 cnv + v2 + 7,
00493 cnv + v0 + 4,
00494 cnv + v1 + 4,
00495 cnv + v2 + 4,
00496 cnv + v0,
00497 cnv + v1,
00498 cnv + v2);
00499 v++;
00500 }
00501 v+=2;
00502 }
00503 }
00504
00505
00508 virtual void tristrip_singlecolor(int , const float * nv,
00509 int numstrips, const int *stripcolindex,
00510 const int *vertsperstrip, const int *facets) {
00511
00512
00513
00514 int strip, t, v = 0;
00515 int stripaddr[2][3] = { {0, 1, 2}, {1, 0, 2} };
00516
00517
00518 for (strip=0; strip < numstrips; strip++) {
00519 super_set_color(stripcolindex[strip]);
00520
00521
00522 for (t = 0; t < (vertsperstrip[strip] - 2); t++) {
00523
00524 int v0 = facets[v + (stripaddr[t & 0x01][0])] * 6;
00525 int v1 = facets[v + (stripaddr[t & 0x01][1])] * 6;
00526 int v2 = facets[v + (stripaddr[t & 0x01][2])] * 6;
00527
00528 triangle(nv + v0 + 3,
00529 nv + v1 + 3,
00530 nv + v2 + 3,
00531 nv + v0,
00532 nv + v1,
00533 nv + v2);
00534 v++;
00535 }
00536 v+=2;
00537 }
00538 }
00539
00540
00543 virtual void trifan_singlecolor(int , const float * nv,
00544 int numfans, const int *fancolindex,
00545 const int *vertsperfan, const int *facets) {
00546
00547
00548
00549 int fan, t, v = 0;
00550
00551
00552 for (fan=0; fan < numfans; fan++) {
00553 super_set_color(fancolindex[fan]);
00554
00555
00556 int v0 = facets[v] * 6;
00557 v++;
00558 for (t = 1; t < (vertsperfan[fan] - 1); t++) {
00559
00560 int v1 = facets[v ] * 6;
00561 int v2 = facets[v + 1] * 6;
00562
00563 triangle(nv + v0 + 3,
00564 nv + v1 + 3,
00565 nv + v2 + 3,
00566 nv + v0,
00567 nv + v1,
00568 nv + v2);
00569 v++;
00570 }
00571 v++;
00572 }
00573 }
00574
00575
00577 virtual void define_volume_texture(int ID, int xs, int ys, int zs,
00578 const float *xplaneeq,
00579 const float *yplaneeq,
00580 const float *zplaneeq,
00581 unsigned char *texmap) {
00582 warningflags |= FILERENDERER_NOTEXTURE;
00583 }
00584
00585
00587 virtual void volume_texture_on(int texmode) {
00588 warningflags |= FILERENDERER_NOTEXTURE;
00589 }
00590
00591
00593 virtual void volume_texture_off(void) {
00594 warningflags |= FILERENDERER_NOTEXTURE;
00595 }
00596
00597
00599 virtual void wiremesh(int , float * cnv,
00600 int numlines, int * lines) {
00601 int i;
00602 int index = 1;
00603
00604 for (i=0; i<numlines; i++) {
00605 float r, g, b;
00606 int ind = i * 2;
00607 int v0 = lines[ind ] * 10;
00608 int v1 = lines[ind + 1] * 10;
00609
00610 r = cnv[v0 + 0] + cnv[v1 + 0] / 2.0f;
00611 g = cnv[v0 + 1] + cnv[v1 + 1] / 2.0f;
00612 b = cnv[v0 + 2] + cnv[v1 + 2] / 2.0f;
00613
00614 index = nearest_index(r,g,b);
00615 super_set_color(index);
00616
00617 line(cnv + v0 + 7, cnv + v1 + 7);
00618 }
00619 }
00620
00624 virtual void beginrepgeomgroup(const char *) {}
00625
00627 virtual void comment(const char *) {}
00628
00630 virtual void text(float *pos, float size, float thickness, const char *str);
00631
00633 virtual void pick_point(float * , int ) {}
00634
00635 };
00636
00637 #endif
00638