00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #include <stdio.h>
00027 #include <string.h>
00028 #include <math.h>
00029 #include "ArtDisplayDevice.h"
00030 #include "Matrix4.h"
00031 #include "DispCmds.h"
00032 #include "Inform.h"
00033 #include "utilities.h"
00034
00035 #define DEFAULT_RADIUS 0.002f
00036 #define DASH_LENGTH 0.02f
00037
00038
00039
00040
00041
00042 #define ORDER(x,y,z) -z, -x, y
00043
00044
00046
00047
00048 ArtDisplayDevice::ArtDisplayDevice()
00049 : FileRenderer("ART", "plot.scn", "art %s 500 650"){ }
00050
00051
00052 ArtDisplayDevice::~ArtDisplayDevice(void) { }
00053
00055
00056
00057 void ArtDisplayDevice::point(float * spdata) {
00058 float vec[3];
00059
00060
00061 (transMat.top()).multpoint3d(spdata, vec);
00062
00063
00064 fprintf(outfile, "sphere {\ncolour %f,%f,%f\n",
00065 matData[colorIndex][0],
00066 matData[colorIndex][1],
00067 matData[colorIndex][2]);
00068
00069 fprintf(outfile, "radius %f\n", float(lineWidth) * DEFAULT_RADIUS);
00070 fprintf(outfile, "center (%f,%f,%f)\n}\n", ORDER(vec[0], vec[1], vec[2]));
00071 }
00072
00073
00074 void ArtDisplayDevice::sphere(float * spdata) {
00075 float vec[3];
00076 float radius;
00077
00078
00079 (transMat.top()).multpoint3d(spdata, vec);
00080 radius = scale_radius(spdata[3]);
00081
00082
00083 fprintf(outfile, "sphere {\ncolour %f,%f,%f\n",
00084 matData[colorIndex][0],
00085 matData[colorIndex][1],
00086 matData[colorIndex][2]);
00087
00088 fprintf(outfile, "radius %f\n", radius);
00089 fprintf(outfile, "center (%f,%f,%f)\n}\n", ORDER(vec[0], vec[1], vec[2]));
00090 }
00091
00092
00093
00094 void ArtDisplayDevice::line(float *a, float *b) {
00095 int i, j, test;
00096 float dirvec[3], unitdirvec[3];
00097 float from[3], to[3], tmp1[3], tmp2[3];
00098 float len;
00099
00100 if(lineStyle == ::SOLIDLINE ) {
00101
00102 (transMat.top()).multpoint3d(a, from);
00103 (transMat.top()).multpoint3d(b, to);
00104
00105
00106 fprintf(outfile, "cylinder {\n");
00107 fprintf(outfile, "colour %f,%f,%f\n",
00108 matData[colorIndex][0],
00109 matData[colorIndex][1],
00110 matData[colorIndex][2]);
00111 fprintf(outfile, "center(%f,%f,%f)\n",
00112 ORDER(from[0], from[1], from[2]));
00113 fprintf(outfile, "center(%f,%f,%f)\n",
00114 ORDER(to[0], to[1], to[2]));
00115 fprintf(outfile, "radius %f\n}\n",
00116 float(lineWidth)*DEFAULT_RADIUS);
00117
00118 } else if (lineStyle == ::DASHEDLINE ) {
00119
00120
00121 (transMat.top()).multpoint3d(a, tmp1);
00122 (transMat.top()).multpoint3d(b, tmp2);
00123
00124
00125 for(i=0;i<3;i++) {
00126 dirvec[i] = tmp2[i] - tmp1[i];
00127 }
00128 len = sqrtf( dirvec[0]*dirvec[0] + dirvec[1]*dirvec[1] + dirvec[2]*dirvec[2] );
00129 for(i=0;i<3;i++) {
00130 unitdirvec[i] = dirvec[i] / sqrtf(len);
00131 }
00132
00133 test = 1;
00134 i = 0;
00135
00136 while( test == 1 ) {
00137 for(j=0;j<3;j++) {
00138 from[j] = tmp1[j] + (2*i)*DASH_LENGTH*unitdirvec[j];
00139 to[j] = tmp1[j] + (2*i + 1)*DASH_LENGTH*unitdirvec[j];
00140 }
00141 if( fabsf(tmp1[0] - to[0]) >= fabsf(dirvec[0]) ) {
00142 for(j=0;j<3;j++) {
00143 to[j] = tmp2[j];
00144 }
00145 test = 0;
00146 }
00147
00148
00149 fprintf(outfile, "cylinder {\n");
00150 fprintf(outfile, "colour %f,%f,%f\n",
00151 matData[colorIndex][0],
00152 matData[colorIndex][1],
00153 matData[colorIndex][2]);
00154
00155
00156 fprintf(outfile, "center(%f,%f,%f)\n",
00157 ORDER(from[0], from[1], from[2]));
00158
00159 fprintf(outfile, "center(%f,%f,%f)\n",
00160 ORDER(to[0], to[1], to[2]));
00161
00162 fprintf(outfile, "radius %f\n}\n",
00163 float(lineWidth)*DEFAULT_RADIUS);
00164
00165 i++;
00166 }
00167 } else {
00168 msgErr << "ArtDisplayDevice: Unknown line style " << lineStyle << sendmsg;
00169 }
00170
00171 }
00172
00173
00174 void ArtDisplayDevice::cylinder(float *a, float *b, float r,int ) {
00175
00176 float vec1[3], vec2[3];
00177
00178
00179 (transMat.top()).multpoint3d(a, vec1);
00180 (transMat.top()).multpoint3d(b, vec2);
00181
00182
00183 fprintf(outfile, "cylinder {\n");
00184 fprintf(outfile, "colour %f,%f,%f\n",
00185 matData[colorIndex][0],
00186 matData[colorIndex][1],
00187 matData[colorIndex][2]);
00188
00189 fprintf(outfile, "center(%f,%f,%f)\n",
00190 ORDER(vec1[0], vec1[1], vec1[2]));
00191
00192 fprintf(outfile, "center(%f,%f,%f)\n",
00193 ORDER(vec2[0], vec2[1], vec2[2]));
00194
00195 fprintf(outfile, "radius %f\n}\n",
00196 scale_radius(r));
00197 }
00198
00199
00200 void ArtDisplayDevice::cone(float *a, float *b, float r) {
00201
00202 float vec1[3], vec2[3];
00203
00204
00205 (transMat.top()).multpoint3d(a, vec1);
00206 (transMat.top()).multpoint3d(b, vec2);
00207
00208 fprintf(outfile, "cone {\n");
00209 fprintf(outfile, "colour %f,%f,%f\n",
00210 matData[colorIndex][0],
00211 matData[colorIndex][1],
00212 matData[colorIndex][2]);
00213
00214 fprintf(outfile, "vertex(%f,%f,%f)\n",
00215 ORDER(vec2[0], vec2[1], vec2[2]));
00216
00217 fprintf(outfile, "center(%f,%f,%f)\n",
00218 ORDER(vec1[0], vec1[1], vec1[2]));
00219
00220 fprintf(outfile, "radius %f\n}\n", scale_radius(r));
00221 }
00222
00223
00224 void ArtDisplayDevice::triangle(const float *a, const float *b, const float *c, const float *n1,
00225 const float *n2, const float *n3) {
00226
00227 float vec1[3], vec2[3], vec3[3];
00228 float nor1[3], nor2[3], nor3[3];
00229
00230
00231 (transMat.top()).multpoint3d(a, vec1);
00232 (transMat.top()).multpoint3d(b, vec2);
00233 (transMat.top()).multpoint3d(c, vec3);
00234
00235
00236 (transMat.top()).multnorm3d(n1, nor1);
00237 (transMat.top()).multnorm3d(n2, nor2);
00238 (transMat.top()).multnorm3d(n3, nor3);
00239
00240
00241 fprintf(outfile, "polygon {\n");
00242 fprintf(outfile, "colour %f,%f,%f\n",
00243 matData[colorIndex][0],
00244 matData[colorIndex][1],
00245 matData[colorIndex][2]);
00246
00247 fprintf(outfile, "vertex (%f,%f,%f),(%f,%f,%f)\n",
00248 ORDER(vec1[0], vec1[1], vec1[2]),
00249 ORDER(nor1[0], nor1[1], nor1[2]));
00250
00251 fprintf(outfile, "vertex (%f,%f,%f),(%f,%f,%f)\n",
00252 ORDER(vec2[0], vec2[1], vec2[2]),
00253 ORDER(nor2[0], nor2[1], nor2[2]));
00254 fprintf(outfile, "vertex (%f,%f,%f),(%f,%f,%f)\n",
00255 ORDER(vec3[0], vec3[1], vec3[2]),
00256 ORDER(nor3[0], nor3[1], nor3[2]));
00257 fprintf(outfile, "}\n");
00258 }
00259
00260
00261 void ArtDisplayDevice::square(float *, float *a, float *b, float *c, float *d) {
00262
00263 float vec1[3], vec2[3], vec3[3], vec4[3];
00264
00265
00266 (transMat.top()).multpoint3d(a, vec1);
00267 (transMat.top()).multpoint3d(b, vec2);
00268 (transMat.top()).multpoint3d(c, vec3);
00269 (transMat.top()).multpoint3d(d, vec4);
00270
00271
00272 fprintf(outfile, "polygon {\n");
00273 fprintf(outfile, "colour %f,%f,%f\n",
00274 matData[colorIndex][0],
00275 matData[colorIndex][1],
00276 matData[colorIndex][2]);
00277
00278 fprintf(outfile, "vertex (%f,%f,%f)\n",
00279 ORDER(vec1[0], vec1[1], vec1[2]));
00280 fprintf(outfile, "vertex (%f,%f,%f)\n",
00281 ORDER(vec2[0], vec2[1], vec2[2]));
00282 fprintf(outfile, "vertex (%f,%f,%f)\n",
00283 ORDER(vec3[0], vec3[1], vec3[2]));
00284 fprintf(outfile, "vertex (%f,%f,%f)\n",
00285 ORDER(vec4[0], vec4[1], vec4[2]));
00286 fprintf(outfile, "}\n");
00287
00288 }
00289
00290 void ArtDisplayDevice::comment(const char *s)
00291 {
00292 fprintf(outfile, "// %s\n", s);
00293 }
00294
00296
00297
00298 void ArtDisplayDevice::write_header() {
00299
00300 Initialized = TRUE;
00301
00302 fprintf(outfile, "up(0, 0, 1) \n");
00303 fprintf(outfile, "lookat(-1, 0, 0, 0, 0, 0, 0)\n");
00304 fprintf(outfile, "fieldofview 45 \n");
00305
00306
00307
00308
00309
00310 fprintf(outfile, "light {\n\tcolour 1, 1, 1\n"
00311 "\tlocation (-10, 0, 0)\n}\n");
00312
00313
00314 fprintf(outfile, "background %f, %f, %f\n", backColor[0],
00315 backColor[1], backColor[2]);
00316
00317
00318 fprintf(outfile, "material 0.0, 0.75, 0.25, 20.0\n");
00319 }
00320
00321
00322
00323 void ArtDisplayDevice::write_trailer() {
00324 fprintf(outfile, "//End of tokens \n");
00325 msgInfo << "Art file generation finished" << sendmsg;
00326 }
00327