Main Page   Namespace List   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-2011 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.70 $       $Date: 2011/03/13 22:52:28 $
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 #if defined(VMDLIBTACHYON) 
00041 #include "LibTachyonDisplayDevice.h"  // Compiled-in Tachyon ray tracer
00042 #endif
00043 #if defined(VMDLIBGELATO)
00044 #include "LibGelatoDisplayDevice.h"   // Compiled-in Gelato renderer
00045 #endif
00046 #include "MayaDisplayDevice.h"        // Autodesk Maya
00047 #include "POV3DisplayDevice.h"        // POVRay 3.x 
00048 #include "PSDisplayDevice.h"          // Postscript
00049 #include "R3dDisplayDevice.h"         // Raster3D
00050 #include "RadianceDisplayDevice.h"    // Radiance, unknown version 
00051 #include "RayShadeDisplayDevice.h"    // Rayshade 4.0 
00052 #include "RenderManDisplayDevice.h"   // RenderMan interface
00053 #include "SnapshotDisplayDevice.h"    // Built-in snapshot capability
00054 #include "STLDisplayDevice.h"         // Stereolithography files
00055 #include "TachyonDisplayDevice.h"     // Tachyon ray tracer
00056 #include "VrmlDisplayDevice.h"        // VRML 1.0 
00057 #include "Vrml2DisplayDevice.h"       // VRML 2.0 / VRML97
00058 #include "WavefrontDisplayDevice.h"   // Wavefront "OBJ" files
00059 #include "X3DDisplayDevice.h"         // X3D (XML encoding)
00060 
00061 
00062 // constructor, start off with the default means of rendering
00063 FileRenderList::FileRenderList(VMDApp *vmdapp) : app(vmdapp) {
00064   add(new ArtDisplayDevice());
00065   add(new GelatoDisplayDevice());
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   // XXX until the native Maya ASCII export code is finished,
00078   // only show it when a magic environment variable is set.
00079   if (getenv("VMDENABLEMAYA") != NULL) {
00080     add(new MayaDisplayDevice());
00081   }
00082   add(new PSDisplayDevice());
00083   add(new R3dDisplayDevice());
00084   add(new RadianceDisplayDevice());
00085   add(new RayShadeDisplayDevice());
00086   add(new RenderManDisplayDevice());
00087   add(new SnapshotDisplayDevice(app->display));
00088   add(new STLDisplayDevice());
00089   add(new TachyonDisplayDevice());
00090 #if defined(VMDLIBTACHYON)
00091   add(new LibTachyonDisplayDevice());
00092 #endif
00093   add(new POV3DisplayDevice());
00094   add(new VrmlDisplayDevice());
00095   add(new Vrml2DisplayDevice());
00096   add(new WavefrontDisplayDevice());
00097   add(new X3DDisplayDevice());
00098   add(new X3DOMDisplayDevice());
00099 }
00100 
00101 // destructor, deallocate all the info
00102 FileRenderList::~FileRenderList(void) {
00103   for (int i=0;i<renderList.num();i++)
00104     delete renderList.data(i);
00105 }
00106 
00107 // add a new render class with its corresponding name
00108 void FileRenderList::add(FileRenderer *newRenderer) {
00109   if (newRenderer)
00110     renderList.add_name(newRenderer->name, newRenderer);
00111 }
00112 
00113 // figure out how many render classes are installed
00114 int FileRenderList::num(void) {
00115   return renderList.num();
00116 }
00117 
00118 // return the name for the ith class, returns NULL if out of range
00119 const char *FileRenderList::name(int i) {
00120   if (i>=0 && i < renderList.num()) {
00121     return renderList.name(i);
00122   }
00123   return NULL;
00124 }
00125 
00126 // return the "pretty" name (used in GUIs) for the ith class.
00127 // returns NULL if out of range
00128 const char *FileRenderList::pretty_name(int i) {
00129   if (i>=0 && i < renderList.num()) {
00130     const FileRenderer * fr = renderList.data(i);
00131     return fr->pretty_name();
00132   }
00133   return NULL;
00134 }
00135 
00136 // find class (case-insensitive) for a renderer name, else return NULL  
00137 FileRenderer *FileRenderList::find(const char *rname) {
00138   int indx = renderList.typecode(rname);
00139   
00140   if (indx >= 0)
00141     return renderList.data(indx);
00142   else
00143     return NULL;
00144 }
00145 
00146 // given a "pretty" render name, return the corresponding class
00147 FileRenderer *FileRenderList::find_pretty_name(const char *pretty) {
00148   int i;
00149   for (i=0; i<renderList.num(); i++) {
00150     if (!strcmp(pretty_name(i), pretty)) {
00151       return renderList.data(i); 
00152     }
00153   }
00154   return NULL;
00155 }
00156 
00157 // given a "pretty" renderer name, return the short name
00158 const char *FileRenderList::find_short_name_from_pretty_name(const char *pretty) {
00159   const FileRenderer *fr = find_pretty_name(pretty);
00160   if (fr)
00161     return fr->visible_name();
00162   return NULL;
00163 }
00164 
00165 int FileRenderList::render(const char *filename, const char *method,
00166                            const char *extcmd) {
00167   msgInfo << "Rendering current scene to '" << filename << "' ..." << sendmsg;
00168 
00169   FileRenderer *render = find(method);
00170   if (!render) {
00171     msgErr << "Invalid render method '" << method << sendmsg;
00172     return FALSE;
00173   }
00174 
00175   // XXX Snapshot grabs the wrong buffer, so if we're doing snapshot, swap
00176   // the buffers, render, then swap back.
00177   if (!strcmp(method, "snapshot")) app->display->update(TRUE);
00178   int retval = app->scene->filedraw(render, filename, app->display);
00179   if (!strcmp(method, "snapshot")) app->display->update(TRUE);
00180 
00181   // if successful, execute external command
00182   if (retval && extcmd && *extcmd != '\0') {
00183     JString strbuf(extcmd);
00184     strbuf.gsub("%s", filename);
00185     // substitute display %w and %h for display width and height
00186     int w=100, h=100;
00187     char buf[32];
00188     app->display_get_size(&w, &h);
00189     sprintf(buf, "%d", w);
00190     strbuf.gsub("%w", buf);
00191     sprintf(buf, "%d", h);
00192     strbuf.gsub("%h", buf);
00193     msgInfo << "Executing post-render cmd '" << (const char *)strbuf << "' ..." << sendmsg;
00194     vmd_system(strbuf);
00195   }
00196 
00197   // return result
00198   msgInfo << "Rendering complete." << sendmsg;
00199   return retval;
00200 }
00201 
00202 int FileRenderList::set_render_option(const char *method, const char *option) {
00203   FileRenderer *ren;
00204   ren = find(method);
00205   if (!ren) {
00206     msgErr << "No rendering method '" << method << "' available." << sendmsg;
00207     return FALSE;
00208   }
00209   ren->set_exec_string(option);
00210   return TRUE;
00211 } 
00212 
00213 int FileRenderList::has_antialiasing(const char *method) {
00214   FileRenderer *ren = find(method);
00215   if (ren) return ren->has_antialiasing();
00216   return 0;
00217 }
00218 
00219 int FileRenderList::aasamples(const char *method, int aasamples) {
00220   FileRenderer *ren = find(method);
00221   if (ren) return ren->set_aasamples(aasamples);
00222   return -1;
00223 }
00224 
00225 int FileRenderList::aosamples(const char *method, int aosamples) {
00226   FileRenderer *ren = find(method);
00227   if (ren) return ren->set_aosamples(aosamples);
00228   return -1;
00229 }
00230 
00231 int FileRenderList::imagesize(const char *method, int *w, int *h) {
00232   FileRenderer *ren = find(method);
00233   if (!ren) return FALSE;
00234   return ren->set_imagesize(w, h);
00235 }
00236 
00237 int FileRenderList::has_imagesize(const char *method) {
00238   FileRenderer *ren = find(method);
00239   if (!ren) return FALSE;
00240   return ren->has_imagesize();
00241 }
00242 
00243 int FileRenderList::aspectratio(const char *method, float *aspect) {
00244   FileRenderer *ren = find(method);
00245   if (!ren) return FALSE;
00246   *aspect = ren->set_aspectratio(*aspect);
00247   return TRUE;
00248 }
00249 
00250 int FileRenderList::numformats(const char *method) {
00251   FileRenderer *ren = find(method);
00252   if (!ren) return 0;
00253   return ren->numformats();
00254 }
00255 
00256 const char *FileRenderList::format(const char *method, int i) {
00257   FileRenderer *ren = find(method);
00258   if (!ren) return NULL;
00259   if (i < 0) return ren->format();
00260   return ren->format(i);
00261 }
00262 
00263 int FileRenderList::set_format(const char *method, const char *format) {
00264   FileRenderer *ren = find(method);
00265   if (!ren) return FALSE;
00266   return ren->set_format(format);
00267 }
00268 

Generated on Wed May 16 01:49:17 2012 for VMD (current) by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002