Renderer.cpp
Go to the documentation of this file.00001 /**<!--------------------------------------------------------------------> 00002 @file Renderer.cpp 00003 @author Travis Fischer (fisch0920@gmail.com) 00004 @author Matthew Jacobs (jacobs.mh@gmail.com) 00005 @date Fall 2008 00006 00007 @brief 00008 Abstract rendering engine which attempts to evaluate a rendering 00009 equation over a given 2D domain (the film plane) and pipes its output 00010 to an equally abstract RenderOutput (generally an image wrapper, but 00011 allowing for distributed rendering) 00012 <!-------------------------------------------------------------------->**/ 00013 00014 #include "Renderer.h" 00015 00016 #include <DirectIllumination.h> 00017 #include <Camera.h> 00018 #include <Scene.h> 00019 #include <sstream> 00020 00021 Renderer::~Renderer() { 00022 safeDelete(m_scene); 00023 safeDelete(m_camera); 00024 safeDelete(m_directIllumination); 00025 } 00026 00027 void Renderer::init() { 00028 ASSERT(m_scene && m_camera); 00029 00030 if (!m_initted) { 00031 //cerr << "Renderer: " << *((PropertyMap *)this) << endl; 00032 m_initted = true; 00033 00034 cout << "initializing renderer" << endl; 00035 m_scene->init(); 00036 00037 Material *m = new Material(); 00038 m->init(); 00039 00040 m_scene->getMaterials().push_back(m); 00041 m_camera->setMaterial(m); 00042 m_camera->init(m_scene); 00043 00044 // TODO: make this customizable via loader / scenefile 00045 m_directIllumination = new DirectIllumination(this); 00046 00047 m_directIllumination->inherit(*this); 00048 m_directIllumination->init(); 00049 } else { 00050 cerr << "warning: Renderers may only be initialized once" << endl; 00051 } 00052 } 00053 00054 std::string Renderer::getElapsedTime() const { 00055 // TODO: bug in boost::timer -- reports ~2.5x time on my system 00056 00057 // 'elapsed' is measured in seconds since the timer was constructed 00058 const double elapsed = m_timer.elapsed(); 00059 std::stringstream s; 00060 00061 s << elapsed << " seconds"; 00062 00063 if (elapsed >= 60) { 00064 unsigned minutes = floor(elapsed / 60); 00065 unsigned seconds = floor(elapsed - (60 * minutes)); 00066 00067 if (minutes >= 60) { 00068 unsigned hours = (minutes / 60); 00069 minutes %= 60; 00070 00071 s << " (" << hours << "h:" << minutes << "m:" << seconds << "s)"; 00072 } else { 00073 s << " (" << minutes << "m:" << seconds << "s)"; 00074 } 00075 } 00076 00077 return s.str(); 00078 } 00079
Generated on 28 Feb 2009 for Milton by
1.5.6