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

FileRenderList.C

Go to the documentation of this file.
00001 /***************************************************************************
00002  *cr                                                                       
00003  *cr            (C) Copyright 1995-2008 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: FileRenderList.C,v $
00013  *      $Author: johns $        $Locker:  $             $State: Exp $
00014  *      $Revision: 1.60 $       $Date: 2008/03/27 19:36:38 $
00015  *
00016  ***************************************************************************
00017  * DESCRIPTION:
00018  *
00019  * The FileRenderList class maintains a list of available FileRenderer
00020  * objects
00021  *
00022  ***************************************************************************/
00023 
00024 #include "config.h"  // create dependency so new compile options cause rebuild
00025 #include "FileRenderList.h"
00026 #include "VMDApp.h"
00027 #include "CmdRender.h"
00028 #include "CommandQueue.h"
00029 #include "Scene.h"
00030 #include "DisplayDevice.h"
00031 #include "TextEvent.h"
00032 #include "Inform.h"
00033 #include <stdlib.h>  // for system()
00034 
00035 //
00036 // Supported external rendering programs
00037 //
00038 #include "ArtDisplayDevice.h"         // Art ray tracer
00039 #include "GelatoDisplayDevice.h"      // nVidia Gelato
00040 #include "POV3DisplayDevice.h"        // POVRay 3.x 
00041 #include "PSDisplayDevice.h"          // Postscript
00042 #include "R3dDisplayDevice.h"         // Raster3D
00043 #include "RayShadeDisplayDevice.h"    // Rayshade 4.0 
00044 #include "RadianceDisplayDevice.h"    // Radiance, unknown version 
00045 #include "RenderManDisplayDevice.h"   // RenderMan interface
00046 #include "SnapshotDisplayDevice.h"    // Built-in snapshot capability
00047 #include "STLDisplayDevice.h"         // Stereolithography files
00048 #include "TachyonDisplayDevice.h"     // Tachyon ray tracer
00049 #include "VrmlDisplayDevice.h"        // VRML 1.0 
00050 #include "Vrml2DisplayDevice.h"       // VRML 2.0 
00051 #include "WavefrontDisplayDevice.h"   // Wavefront "OBJ" files
00052 
00053 #if defined(VMDLIBTACHYON) 
00054 #include "LibTachyonDisplayDevice.h"  // Compiled-in Tachyon ray tracer
00055 #endif
00056 #if defined(VMDLIBGELATO)
00057 #include "LibGelatoDisplayDevice.h"   // Compiled-in Gelato renderer
00058 #endif
00059 
00060 // constructor, start off with the default means of rendering
00061 FileRenderList::FileRenderList(VMDApp *vmdapp) : app(vmdapp) {
00062   add(new SnapshotDisplayDevice(app->display));
00063 #if defined(VMDLIBTACHYON)
00064   add(new LibTachyonDisplayDevice());
00065 #endif
00066 #if defined(VMDLIBGELATO)
00067   // Only add the internally linked gelato display device to the
00068   // menu if the user has correctly set the GELATOHOME environment
00069   // variable.  If we allow them to use it otherwise, it may lead
00070   // to crashing, or failed renders.  This way they won't even see it
00071   // as an option unless they've got Gelato installed and the environment
00072   // at least minimally configured.
00073   if (getenv("GELATOHOME") != NULL) {
00074     add(new LibGelatoDisplayDevice());
00075   }
00076 #endif
00077   add(new TachyonDisplayDevice());
00078   add(new POV3DisplayDevice());
00079   add(new Vrml2DisplayDevice());
00080   add(new RenderManDisplayDevice());
00081   add(new GelatoDisplayDevice());
00082   add(new STLDisplayDevice());
00083   add(new ArtDisplayDevice());
00084   add(new PSDisplayDevice());
00085   add(new RayShadeDisplayDevice());
00086   add(new RadianceDisplayDevice());
00087   add(new R3dDisplayDevice());
00088   add(new VrmlDisplayDevice());
00089   add(new WavefrontDisplayDevice());
00090 }
00091 
00092 // destructor, deallocate all the info
00093 FileRenderList::~FileRenderList(void) {
00094   for (int i=0;i<renderList.num();i++)
00095     delete renderList.data(i);
00096 }
00097 
00098 // add a new render class with its corresponding name
00099 void FileRenderList::add(FileRenderer *newRenderer) {
00100   if(newRenderer)
00101     renderList.add_name(newRenderer->name, newRenderer);
00102 }
00103 
00104 // figure out how many render classes are installed
00105 int FileRenderList::num(void) {
00106   return renderList.num();
00107 }
00108 
00109 // return the name for the ith class, returns NULL if out of range
00110 const char *FileRenderList::name(int i) {
00111   if(i>=0 && i < renderList.num()) {
00112     return renderList.name(i);
00113   }
00114   return NULL;
00115 }
00116 
00117 // find class (case-insensitive) for a renderer name, else return NULL  
00118 FileRenderer *FileRenderList::find(const char *rname) {
00119   int indx = renderList.typecode(rname);
00120   
00121   if(indx >= 0)
00122     return renderList.data(indx);
00123   else
00124     return NULL;
00125 }
00126 
00127 int FileRenderList::render(const char *filename, const char *method,
00128                            const char *extcmd) {
00129   msgInfo << "Rendering current scene to '" << filename << "' ..." << sendmsg;
00130 
00131   FileRenderer *render = find(method);
00132   if (!render) {
00133     msgErr << "Invalid render method '" << method << sendmsg;
00134     return FALSE;
00135   }
00136 
00137   // XXX Snapshot grabs the wrong buffer, so if we're doing snapshot, swap
00138   // the buffers, render, then swap back.
00139   if (!strcmp(method, "snapshot")) app->display->update(TRUE);
00140   int retval = app->scene->filedraw(render, filename, app->display);
00141   if (!strcmp(method, "snapshot")) app->display->update(TRUE);
00142 
00143   // if successful, execute external command
00144   if (retval && extcmd && *extcmd != '\0') {
00145     JString strbuf(extcmd);
00146     strbuf.gsub("%s", filename);
00147     // substitute display %w and %h for display width and height
00148     int w=100, h=100;
00149     char buf[32];
00150     app->display_get_size(&w, &h);
00151     sprintf(buf, "%d", w);
00152     strbuf.gsub("%w", buf);
00153     sprintf(buf, "%d", h);
00154     strbuf.gsub("%h", buf);
00155     msgInfo << "Executing post-render cmd '" << (const char *)strbuf << "' ..." << sendmsg;
00156     vmd_system(strbuf);
00157   }
00158 
00159   // return result
00160   msgInfo << "Rendering complete." << sendmsg;
00161   return retval;
00162 }
00163 
00164 int FileRenderList::set_render_option(const char *method, const char *option) {
00165   FileRenderer *ren;
00166   ren = find(method);
00167   if (!ren) {
00168     msgErr << "No rendering method '" << method << "' available." << sendmsg;
00169     return FALSE;
00170   }
00171   ren->set_exec_string(option);
00172   return TRUE;
00173 } 
00174 
00175 int FileRenderList::has_antialiasing(const char *method) {
00176   FileRenderer *ren = find(method);
00177   if (ren) return ren->has_antialiasing();
00178   return 0;
00179 }
00180 
00181 int FileRenderList::aalevel(const char *method, int aalevel) {
00182   FileRenderer *ren = find(method);
00183   if (ren) return ren->set_aalevel(aalevel);
00184   return -1;
00185 }
00186 
00187 int FileRenderList::imagesize(const char *method, int *w, int *h) {
00188   FileRenderer *ren = find(method);
00189   if (!ren) return FALSE;
00190   return ren->set_imagesize(w, h);
00191 }
00192 
00193 int FileRenderList::has_imagesize(const char *method) {
00194   FileRenderer *ren = find(method);
00195   if (!ren) return FALSE;
00196   return ren->has_imagesize();
00197 }
00198 
00199 int FileRenderList::aspectratio(const char *method, float *aspect) {
00200   FileRenderer *ren = find(method);
00201   if (!ren) return FALSE;
00202   *aspect = ren->set_aspectratio(*aspect);
00203   return TRUE;
00204 }
00205 
00206 int FileRenderList::numformats(const char *method) {
00207   FileRenderer *ren = find(method);
00208   if (!ren) return 0;
00209   return ren->numformats();
00210 }
00211 
00212 const char *FileRenderList::format(const char *method, int i) {
00213   FileRenderer *ren = find(method);
00214   if (!ren) return NULL;
00215   if (i < 0) return ren->format();
00216   return ren->format(i);
00217 }
00218 
00219 int FileRenderList::set_format(const char *method, const char *format) {
00220   FileRenderer *ren = find(method);
00221   if (!ren) return FALSE;
00222   return ren->set_format(format);
00223 }
00224 

Generated on Mon Oct 6 01:26:12 2008 for VMD (current) by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002