Main Page Namespace List Class Hierarchy Alphabetical List Compound List File List Namespace Members Compound Members File Members Related Pages

STLDisplayDevice.C

Go to the documentation of this file.
00001 /***************************************************************************
00002 *cr
00003 *cr (C) Copyright 1995-2019 The Board of Trustees of the
00004 *cr University of Illinois
00005 *cr All Rights Reserved
00006 *cr
00007 ***************************************************************************/
00008 
00009 /***************************************************************************
00010 * RCS INFORMATION:
00011 *
00012 * $RCSfile: STLDisplayDevice.C,v $
00013 * $Author: johns $ $Locker: $ $State: Exp $
00014 * $Revision: 1.40 $ $Date: 2019年01月17日 21:21:01 $
00015 *
00016 ***************************************************************************
00017 * DESCRIPTION:
00018 *
00019 * Render to a STL (Stereo-Lithography file). 
00020 * See http://www.sdsc.edu/tmf/ for more information on the file format and
00021 * how to make a physical 3-D model from VMD.
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 // constructor ... call the parent with the right values
00036 STLDisplayDevice::STLDisplayDevice(void) 
00037 : FileRenderer("STL", "STL (triangle mesh only)", "vmdscene.stl", "true") { }
00038 
00039 // destructor
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 // transform the world coordinates
00048 (transMat.top()).multpoint3d(v1, a);
00049 (transMat.top()).multpoint3d(v2, b);
00050 (transMat.top()).multpoint3d(v3, c);
00051 
00052 // and the normals
00053 (transMat.top()).multnorm3d(n1, norm1);
00054 (transMat.top()).multnorm3d(n2, norm2);
00055 (transMat.top()).multnorm3d(n3, norm3);
00056 
00057 // draw the triangle 
00058 #if 1
00059 // do not calculate surface normals, return a 0 vector.
00060 fprintf(outfile, " facet normal 0.0 0.0 0.0\n");
00061 #else
00062 // calculate surface normals for each triangle.
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 

Generated on Wed Nov 19 02:47:18 2025 for VMD (current) by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002

AltStyle によって変換されたページ (->オリジナル) /