#include using namespace std; #include "SlideWriter.h" using namespace CCS; void SlideWriter::outputVertex(Vertex *v, Face *usingFace, TXS::UVs uv) { list faces = v->getIncidentFaces(); Point p = v->getPoint(); char pointName[64]; // NOTE: SLIDE inteprets v=0 as the texture TOP going down // but we always assume v=0 is the texture bottom going up // so, we must flip and translate uv.v = 1.0 - uv.v; // get name for vert use this->vertUseName(pointName, usingFace, v); this->slfOut << "point " << pointName << " " << " (" << (p[0]) << " " << (p[1]) << " " << (p[2]) << ") " << " texture ( " << uv.u << " " << uv.v << " ) endpoint " << endl; } void SlideWriter::outputFace(Face *f) { char surfaceName[64]; char faceName[64]; char vertUseName[64]; // get the texture image to write TiffImage *img = f->txtr; // get surface name for texture file this->surfaceName(surfaceName, img); // output the points with UVs list::iterator use_iter; list::iterator uv_iter = f->uvs.begin(); for(use_iter = f->edgeUses.begin(); use_iter != f->edgeUses.end(); ++use_iter) { EdgeUse use = *use_iter; Vertex *v = use.getUseStart(); // check if(uv_iter == f->uvs.end()) { __ERROR__("more edge uses than UVs for a CCS::Face!"); exit(1); } this->outputVertex(v, f, *uv_iter); ++uv_iter; } // now, finally output the face SLF // face name (v0 v1 v2) surface surfaceName endface this->faceName(faceName, f); this->slfOut << "face " << faceName << " ("; // now, output the verts // visit each vert use for(use_iter = f->edgeUses.begin(); use_iter != f->edgeUses.end(); ++use_iter) { EdgeUse use = *use_iter; Vertex *v = use.getUseStart(); // get name for vert use this->vertUseName(vertUseName, f, v); // do it this->slfOut << vertUseName << " "; } // complete it if(doTxtrs) { this->slfOut << " ) surface " << surfaceName << " endface " << endl; } else { this->slfOut << " ) endface " << endl; } } void SlideWriter::writeTextureTiffs(Mesh *mesh) { list faces = mesh->faces; list::iterator fit; // accum all DISTINCT txtr files // use a set to keep distinct set txtrs; for(fit = faces.begin(); fit != faces.end(); ++fit) { Face* f = *fit; txtrs.insert(f->txtr); } // write em all out, and add them to the batch conversion char surfaceName[100]; char filepath[100]; set::iterator t_iter; for(t_iter = txtrs.begin(); t_iter != txtrs.end(); ++t_iter) { TiffImage* t = *t_iter; // write the TIFF file this->surfaceName(surfaceName, t); sprintf(filepath, "%s/%s.tif", this->outDir, surfaceName); t->writeToTiff(filepath); // write the BAT and SLF code // output first half of tif->gif convert cmd // but the BATCH doesn't need the outDir sprintf(filepath, "%s.tif", surfaceName); this->batOut << "convert " << filepath << " -size 200% "/*"-gaussian 2 "*/; // output surface def // SLIDE code: surface surf_arrows bitmap "texture.GIF" SLF_TEXMAP endsurface // remember to use .gif, isntead of .tif // and don't use the directory prefix sprintf(filepath, "%s.gif", surfaceName); this->slfOut << "# FACE" << endl; this->slfOut << "surface " << surfaceName << " " << " bitmap \"" << filepath << "\" SLF_TEXMAP " << " endsurface " << endl; // complete convert cmd this->batOut << " " << filepath << endl; } } void SlideWriter::outputMesh(Mesh *mesh) { list faces = mesh->faces; list::iterator fit; if(doTxtrs) { this->writeTextureTiffs(mesh); } // output faces for(fit = faces.begin(); fit != faces.end(); ++fit) { Face* f = *fit; this->outputFace(f); } // now put all faces together into the object // object txsObject (f1 f2 f3 ...) this->slfOut << "# OBJECT" << endl; this->slfOut << "object txsObject ( " << endl; char faceName[64]; for(fit = faces.begin(); fit != faces.end(); ++fit) { Face* f = *fit; this->faceName(faceName, f); this->slfOut << " " << faceName << endl; } this->slfOut << ") " << endl << "solid SLF_SOLID" << endl << "shading SLF_FLAT" << endl << "endobject" << endl; // done! // this->slfOut.close(); this->batOut.close(); } SlideWriter::SlideWriter() { this->outDir = NULL; this->mesh = NULL; } void SlideWriter::write(char *outDir, Mesh *mesh, bool doTxtrs) { this->outDir = outDir; this->mesh = mesh; this->doTxtrs = doTxtrs; char filename[100]; // the SLF file sprintf(filename, "%s/_open_me_in_slide_.slf", outDir); __LOG__("SLF out filename: \"" << filename << "\""); slfOut.open(filename); if(!slfOut.is_open()) { __ERROR__("SlideOutputMeshVisitor: couldn't open the file!"); } // the BAT file sprintf(filename, "%s/convert-TIFs.bat", outDir); __LOG__("BAT out filename: \"" << filename << "\""); batOut.open(filename); if(!batOut.is_open()) { __ERROR__("SlideOutputMeshVisitor: couldn't open the file!"); } this->outputMesh(this->mesh); }