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
00326
00327 cone_trunc(xyz1, xyz2, radius, 0.0f, resolution);
00328 }
00329
00331 virtual void cone_trunc(float * , float * ,
00332 float , float ,
00333 int );
00334
00335
00337 virtual void cylinder(float * base, float * apex, float radius, int filled);
00338
00339
00341 virtual void line(float * a, float * b);
00342
00344 virtual void line_array(int num, float thickness, float *points);
00345
00347 virtual void polyline_array(int num, float thickness, float *points);
00348
00349
00351 virtual void point(float * xyz) {
00352 float xyzr[4];
00353 vec_copy(xyzr, xyz);
00354 xyzr[3] = lineWidth * 0.002f;
00355 }
00356
00358 virtual void point_array(int num, float size, float *xyz, float *colors);
00359
00361 virtual void point_array_lit(int num, float size,
00362 float *xyz, float *norm, float *colors);
00363
00364
00366 virtual void sphere(float * xyzr);
00367
00369 virtual void sphere_array(int num, int res, float *centers, float *radii, float *colors);
00370
00371
00373 virtual void square(float * norm, float * a, float * b,
00374 float * c, float * d) {
00375
00376 triangle(a, b, c, norm, norm, norm);
00377 triangle(a, c, d, norm, norm, norm);
00378 }
00379
00380
00382 virtual void triangle(const float * , const float * , const float * ,
00383 const float * , const float * , const float * ) {
00384 warningflags |= FILERENDERER_NOGEOM;
00385 }
00386
00387
00389 virtual void tricolor(const float * xyz1, const float * xyz2, const float * xyz3,
00390 const float * n1, const float * n2, const float * n3,
00391 const float *c1, const float *c2, const float *c3) {
00392 int index = 1;
00393 float r, g, b;
00394 r = (c1[0] + c2[0] + c3[0]) / 3.0f;
00395 g = (c1[1] + c2[1] + c3[1]) / 3.0f;
00396 b = (c1[2] + c2[2] + c3[2]) / 3.0f;
00397
00398 index = nearest_index(r,g,b);
00399 super_set_color(index);
00400
00401 triangle(xyz1, xyz2, xyz3, n1, n2, n3);
00402 }
00403
00405 virtual void trimesh_n3f_v3f(float *n, float *v, int numfacets) {
00406 int i;
00407 for (i=0; i<numfacets*9; i+=9) {
00408 triangle(v + i ,
00409 v + i + 3,
00410 v + i + 6,
00411 n + i ,
00412 n + i + 3,
00413 n + i + 6);
00414 }
00415 }
00416
00417 virtual void trimesh_n3b_v3f(char *n, float *v, int numfacets) {
00418 int i;
00419 const float cn2f = 1.0f / 127.5f;
00420 const float ci2f = 1.0f / 255.0f;
00421
00422 for (i=0; i<numfacets*9; i+=9) {
00423 float norm[9];
00424
00425
00426
00427 norm[0] = n[i ] * cn2f + ci2f;
00428 norm[1] = n[i + 1] * cn2f + ci2f;
00429 norm[2] = n[i + 2] * cn2f + ci2f;
00430 norm[3] = n[i + 3] * cn2f + ci2f;
00431 norm[4] = n[i + 4] * cn2f + ci2f;
00432 norm[5] = n[i + 5] * cn2f + ci2f;
00433 norm[6] = n[i + 6] * cn2f + ci2f;
00434 norm[7] = n[i + 7] * cn2f + ci2f;
00435 norm[8] = n[i + 8] * cn2f + ci2f;
00436
00437 triangle(v + i ,
00438 v + i + 3,
00439 v + i + 6,
00440 &norm[0],
00441 &norm[3],
00442 &norm[6]);
00443 }
00444 }
00445
00447 virtual void trimesh_c3f_n3f_v3f(float *c, float *n, float *v, int numfacets) {
00448 int i;
00449 for (i=0; i<numfacets*9; i+=9) {
00450 tricolor(v + i ,
00451 v + i + 3,
00452 v + i + 6,
00453 n + i ,
00454 n + i + 3,
00455 n + i + 6,
00456 c + i ,
00457 c + i + 3,
00458 c + i + 6);
00459 }
00460 }
00461
00463 virtual void trimesh_c4n3v3(int , float * cnv,
00464 int numfacets, int * facets) {
00465 int i;
00466 for (i=0; i<numfacets*3; i+=3) {
00467 int v0 = facets[i ] * 10;
00468 int v1 = facets[i + 1] * 10;
00469 int v2 = facets[i + 2] * 10;
00470 tricolor(cnv + v0 + 7,
00471 cnv + v1 + 7,
00472 cnv + v2 + 7,
00473 cnv + v0 + 4,
00474 cnv + v1 + 4,
00475 cnv + v2 + 4,
00476 cnv + v0,
00477 cnv + v1,
00478 cnv + v2);
00479 }
00480 }
00481
00483 virtual void trimesh_c4u_n3f_v3f(unsigned char *c, float *n, float *v,
00484 int numfacets) {
00485 int i, j;
00486 const float ci2f = 1.0f / 255.0f;
00487 for (i=0,j=0; i<numfacets*9; i+=9,j+=12) {
00488 float col[9];
00489
00490
00491
00492 col[0] = c[j ] * ci2f;
00493 col[1] = c[j + 1] * ci2f;
00494 col[2] = c[j + 2] * ci2f;
00495 col[3] = c[j + 4] * ci2f;
00496 col[4] = c[j + 5] * ci2f;
00497 col[5] = c[j + 6] * ci2f;
00498 col[6] = c[j + 8] * ci2f;
00499 col[7] = c[j + 9] * ci2f;
00500 col[8] = c[j + 10] * ci2f;
00501
00502 tricolor(v + i ,
00503 v + i + 3,
00504 v + i + 6,
00505 n + i ,
00506 n + i + 3,
00507 n + i + 6,
00508 &col[0],
00509 &col[3],
00510 &col[6]);
00511 }
00512 }
00513
00515 virtual void trimesh_c4u_n3b_v3f(unsigned char *c, char *n, float *v,
00516 int numfacets) {
00517 int i, j;
00518 const float ci2f = 1.0f / 255.0f;
00519 const float cn2f = 1.0f / 127.5f;
00520 for (i=0,j=0; i<numfacets*9; i+=9,j+=12) {
00521 float col[9], norm[9];
00522
00523
00524
00525 col[0] = c[j ] * ci2f;
00526 col[1] = c[j + 1] * ci2f;
00527 col[2] = c[j + 2] * ci2f;
00528 col[3] = c[j + 4] * ci2f;
00529 col[4] = c[j + 5] * ci2f;
00530 col[5] = c[j + 6] * ci2f;
00531 col[6] = c[j + 8] * ci2f;
00532 col[7] = c[j + 9] * ci2f;
00533 col[8] = c[j + 10] * ci2f;
00534
00535
00536
00537 norm[0] = n[i ] * cn2f + ci2f;
00538 norm[1] = n[i + 1] * cn2f + ci2f;
00539 norm[2] = n[i + 2] * cn2f + ci2f;
00540 norm[3] = n[i + 3] * cn2f + ci2f;
00541 norm[4] = n[i + 4] * cn2f + ci2f;
00542 norm[5] = n[i + 5] * cn2f + ci2f;
00543 norm[6] = n[i + 6] * cn2f + ci2f;
00544 norm[7] = n[i + 7] * cn2f + ci2f;
00545 norm[8] = n[i + 8] * cn2f + ci2f;
00546
00547 tricolor(v + i ,
00548 v + i + 3,
00549 v + i + 6,
00550 &norm[0],
00551 &norm[3],
00552 &norm[6],
00553 &col[0],
00554 &col[3],
00555 &col[6]);
00556 }
00557 }
00558
00559
00561 virtual void trimesh_singlecolor(int cindex, int , float * nv,
00562 int numfacets, int * facets) {
00563 super_set_color(cindex);
00564
00565 int i;
00566 for (i=0; i<numfacets*3; i+=3) {
00567 int v0 = facets[i ] * 6;
00568 int v1 = facets[i + 1] * 6;
00569 int v2 = facets[i + 2] * 6;
00570 triangle(nv + v0 + 3,
00571 nv + v1 + 3,
00572 nv + v2 + 3,
00573 nv + v0,
00574 nv + v1,
00575 nv + v2);
00576 }
00577 }
00578
00579
00581 virtual void tristrip(int , const float * cnv,
00582 int numstrips, const int *vertsperstrip,
00583 const int *facets) {
00584
00585
00586
00587 int strip, t, v = 0;
00588 int stripaddr[2][3] = { {0, 1, 2}, {1, 0, 2} };
00589
00590
00591 for (strip=0; strip < numstrips; strip++) {
00592
00593 for (t = 0; t < (vertsperstrip[strip] - 2); t++) {
00594
00595 int v0 = facets[v + (stripaddr[t & 0x01][0])] * 10;
00596 int v1 = facets[v + (stripaddr[t & 0x01][1])] * 10;
00597 int v2 = facets[v + (stripaddr[t & 0x01][2])] * 10;
00598
00599 tricolor(cnv + v0 + 7,
00600 cnv + v1 + 7,
00601 cnv + v2 + 7,
00602 cnv + v0 + 4,
00603 cnv + v1 + 4,
00604 cnv + v2 + 4,
00605 cnv + v0,
00606 cnv + v1,
00607 cnv + v2);
00608 v++;
00609 }
00610 v+=2;
00611 }
00612 }
00613
00614
00617 virtual void tristrip_singlecolor(int , const float * nv,
00618 int numstrips, const int *stripcolindex,
00619 const int *vertsperstrip, const int *facets) {
00620
00621
00622
00623 int strip, t, v = 0;
00624 int stripaddr[2][3] = { {0, 1, 2}, {1, 0, 2} };
00625
00626
00627 for (strip=0; strip < numstrips; strip++) {
00628 super_set_color(stripcolindex[strip]);
00629
00630
00631 for (t = 0; t < (vertsperstrip[strip] - 2); t++) {
00632
00633 int v0 = facets[v + (stripaddr[t & 0x01][0])] * 6;
00634 int v1 = facets[v + (stripaddr[t & 0x01][1])] * 6;
00635 int v2 = facets[v + (stripaddr[t & 0x01][2])] * 6;
00636
00637 triangle(nv + v0 + 3,
00638 nv + v1 + 3,
00639 nv + v2 + 3,
00640 nv + v0,
00641 nv + v1,
00642 nv + v2);
00643 v++;
00644 }
00645 v+=2;
00646 }
00647 }
00648
00649
00652 virtual void trifan_singlecolor(int , const float * nv,
00653 int numfans, const int *fancolindex,
00654 const int *vertsperfan, const int *facets) {
00655
00656
00657
00658 int fan, t, v = 0;
00659
00660
00661 for (fan=0; fan < numfans; fan++) {
00662 super_set_color(fancolindex[fan]);
00663
00664
00665 int v0 = facets[v] * 6;
00666 v++;
00667 for (t = 1; t < (vertsperfan[fan] - 1); t++) {
00668
00669 int v1 = facets[v ] * 6;
00670 int v2 = facets[v + 1] * 6;
00671
00672 triangle(nv + v0 + 3,
00673 nv + v1 + 3,
00674 nv + v2 + 3,
00675 nv + v0,
00676 nv + v1,
00677 nv + v2);
00678 v++;
00679 }
00680 v++;
00681 }
00682 }
00683
00684
00686 virtual void define_volume_texture(int ID, int xs, int ys, int zs,
00687 const float *xplaneeq,
00688 const float *yplaneeq,
00689 const float *zplaneeq,
00690 unsigned char *texmap) {
00691 warningflags |= FILERENDERER_NOTEXTURE;
00692 }
00693
00694
00696 virtual void volume_texture_on(int texmode) {
00697 warningflags |= FILERENDERER_NOTEXTURE;
00698 }
00699
00700
00702 virtual void volume_texture_off(void) {
00703 warningflags |= FILERENDERER_NOTEXTURE;
00704 }
00705
00706
00708 virtual void wiremesh(int , float * cnv,
00709 int numlines, int * lines) {
00710 int i;
00711 int index = 1;
00712
00713 for (i=0; i<numlines; i++) {
00714 float r, g, b;
00715 int ind = i * 2;
00716 int v0 = lines[ind ] * 10;
00717 int v1 = lines[ind + 1] * 10;
00718
00719 r = cnv[v0 + 0] + cnv[v1 + 0] / 2.0f;
00720 g = cnv[v0 + 1] + cnv[v1 + 1] / 2.0f;
00721 b = cnv[v0 + 2] + cnv[v1 + 2] / 2.0f;
00722
00723 index = nearest_index(r,g,b);
00724 super_set_color(index);
00725
00726 line(cnv + v0 + 7, cnv + v1 + 7);
00727 }
00728 }
00729
00733 virtual void beginrepgeomgroup(const char *) {}
00734
00736 virtual void comment(const char *) {}
00737
00739 virtual void text(float *pos, float size, float thickness, const char *str);
00740
00742 virtual void pick_point(float * , int ) {}
00743
00744 };
00745
00746 #endif
00747