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 #include <stdio.h>
00026 #include <string.h>
00027 #include <math.h>
00028 #include <time.h>
00029 #include "STLDisplayDevice.h"
00030 #include "Matrix4.h"
00031 #include "DispCmds.h"
00032 #include "Inform.h"
00033 #include "utilities.h"
00034
00035
00036 STLDisplayDevice::STLDisplayDevice(void)
00037 : FileRenderer("STL", "STL (triangle mesh only)", "vmdscene.stl", "true") { }
00038
00039
00040 STLDisplayDevice::~STLDisplayDevice(void) { }
00041
00042 void STLDisplayDevice::triangle(const float *v1, const float *v2, const float *v3,
00043 const float *n1, const float *n2, const float *n3) {
00044 float a[3], b[3], c[3];
00045 float norm1[3], norm2[3], norm3[3];
00046
00047
00048 (transMat.top()).multpoint3d(v1, a);
00049 (transMat.top()).multpoint3d(v2, b);
00050 (transMat.top()).multpoint3d(v3, c);
00051
00052
00053 (transMat.top()).multnorm3d(n1, norm1);
00054 (transMat.top()).multnorm3d(n2, norm2);
00055 (transMat.top()).multnorm3d(n3, norm3);
00056
00057
00058 #if 1
00059
00060 fprintf(outfile, " facet normal 0.0 0.0 0.0\n");
00061 #else
00062
00063 float nx, ny, nz, n;
00064 nx = a[1]*(b[2]-c[2])+b[1]*(c[2]-a[2])+c[1]*(a[2]-b[2]);
00065 ny = a[2]*(b[0]-c[0])+b[2]*(c[0]-a[0])+c[2]*(a[0]-b[0]);
00066 nz = a[0]*(b[1]-c[1])+b[0]*(c[1]-a[1])+c[0]*(a[1]-b[1]);
00067 n = nx*nx+ny*ny+nz*nz;
00068 n = sqrt(n);
00069 nx /= n; ny /= n; nz /= n;
00070 fprintf (outfile, " facet normal %f %f %f\n", nx, ny, nz);
00071 #endif
00072
00073 fprintf(outfile," outer loop\n");
00074 fprintf(outfile," vertex %f %f %f\n", a[0], a[1], a[2]);
00075 fprintf(outfile," vertex %f %f %f\n", b[0], b[1], b[2]);
00076 fprintf(outfile," vertex %f %f %f\n", c[0], c[1], c[2]);
00077 fprintf(outfile," endloop\n");
00078 fprintf(outfile," endfacet\n");
00079 }
00080
00081 void STLDisplayDevice::write_header (void) {
00082 fprintf (outfile, "solid molecule\n");
00083 }
00084
00085 void STLDisplayDevice::write_trailer (void) {
00086 fprintf (outfile, "endsolid\n");
00087 msgWarn << "Only triangles in the present scene have been processed.\n";
00088 msgWarn << "Materials and colors are not exported to STL files.\n";
00089 }
00090