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

scenebuilder.h

Go to the documentation of this file.
00001 /*
00002     toxic - A Global Illumination Renderer
00003     Copyright (C) 2003-2004 Francois Beaune
00004     Contact: http://toxicengine.sourceforge.net/
00005 
00006     This file is part of toxic.
00007 
00008     toxic is free software; you can redistribute it and/or modify
00009     it under the terms of the GNU General Public License as published by
00010     the Free Software Foundation; either version 2 of the License, or
00011     (at your option) any later version.
00012 
00013     toxic is distributed in the hope that it will be useful,
00014     but WITHOUT ANY WARRANTY; without even the implied warranty of
00015     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016     GNU General Public License for more details.
00017 
00018     You should have received a copy of the GNU General Public License
00019     along with toxic; if not, write to the Free Software
00020     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00021 */
00022 
00023 #ifndef TOXIC_DRIVER_SCENEBUILDER_H
00024 #define TOXIC_DRIVER_SCENEBUILDER_H
00025 
00026 #include "common/math/matrix4.h"
00027 #include "common/math/real.h"
00028 #include "common/math/vector3.h"
00029 #include "common/misc/consoleprogressmonitor.h"
00030 #include "common/misc/stringutils.h"
00031 #include "objectrepository.h"
00032 #include "renderer/color3.h"
00033 #include "renderer/globals.h"
00034 #include "renderer/imagetexture.h"
00035 #include "renderer/iobject.h"
00036 #include "renderer/meshbuilder.h"
00037 #include "surfaceshaderrepository.h"
00038 
00039 #include <xercesc/dom/DOM.hpp>
00040 
00041 #include <memory>   // std::auto_ptr<>
00042 #include <string>
00043 
00044 namespace toxic {
00045 
00046     class Collection;
00047     class Color3;
00048     class ConstantTexture;
00049     class Context;
00050     class Framebuffer;
00051     class IBDF;
00052     class IEDF;
00053 //  class ImageTexture;
00054     class ISurfaceShader;
00055     class ITexture;
00056     class Octree;
00057     class ParameterMap;
00058     class Scene;
00059 
00060     //! Cameras forward definition.
00061     class PinholeCamera;
00062     class ThinLensCamera;
00063 
00064     //! Lights forward definition.
00065     class PointLight;
00066 
00067     //! Objects forward definition.
00068     class Cube;
00069     class Mesh;
00070     class Plane;
00071     class Ring;
00072     class Sphere;
00073     class Square;
00074 
00075     class SceneBuilder {
00076     public:
00077         //! This is the base class for all exceptions thrown by the SceneBuilder class.
00078         struct LoadErrorException {
00079             LoadErrorException(const std::string &message) :
00080                 m_message(message) {}
00081 
00082             std::string m_message;
00083         };
00084 
00085         //! This exception is thrown if an error occurs when loading the XML document.
00086         //! It is either an I/O error or, if a schema was provided, a XML document
00087         //! validation error (the XML document could not be validated against the schema).
00088         struct ParseErrorException : public LoadErrorException {
00089             ParseErrorException(const std::string &message) :
00090                 LoadErrorException(message) {}
00091         };
00092 
00093         struct MultipleDefinitionException : public LoadErrorException {
00094             MultipleDefinitionException(const std::string &element) :
00095                 LoadErrorException("Multiple definition of '" + element + "'.") {}
00096         };
00097 
00098         SceneBuilder(
00099             const Context &context,
00100             const Framebuffer *framebuffer,
00101             const std::string &filename,
00102             const std::string &home_path,
00103             sheep::ConsoleProgressMonitor *progmon);
00104 
00105         ~SceneBuilder();
00106 
00107         std::auto_ptr<Scene> GetScene();
00108         std::auto_ptr<ICamera> GetCamera();
00109 
00110     private:
00111         const Context &m_context;
00112         const Framebuffer *m_framebuffer;
00113         const std::string m_path;                   //!< Path to scene file.
00114         sheep::ConsoleProgressMonitor *m_progmon;
00115 
00116         SurfaceShaderRepository m_surface_shaders;
00117         ObjectRepository m_objects;
00118 
00119         Collection *m_root; //!< The root object is always allocated and allow to store unbounded objects.
00120         Octree *m_octree;   //!< If non-null, bounded objects must be stored into this octree.
00121 
00122         std::auto_ptr<Scene> m_scene;
00123         std::auto_ptr<ICamera> m_camera;
00124 
00125         sheep::Vector3 parse_vector3(const std::string &s) const;
00126         Color3 parse_color3(const std::string &s) const;
00127 
00128         void parse_parameter(
00129             const xercesc::DOMNode *node,
00130             std::string *name,
00131             std::string *value
00132         ) const;
00133 
00134         void store_parameter(
00135             const std::string &name,
00136             const std::string &value,
00137             ParameterMap *params
00138         ) const;
00139 
00140         void parse_file(const std::string &filename, const std::string &home_path);
00141         void parse_root(const xercesc::DOMNode *noden);
00142         void parse_frame(const xercesc::DOMNode *node);
00143 
00144         const IBDF *bdf_builder(const xercesc::DOMNode *node) const;
00145         const ConstantTexture *constant_texture_builder(const xercesc::DOMNode *node) const;
00146         const IEDF *edf_builder(const xercesc::DOMNode *node) const;
00147         const ImageTexture *image_texture_builder(const xercesc::DOMNode *node) const;
00148         sheep::Matrix4 matrix_builder(const xercesc::DOMNode *node) const;
00149         void object_builder(const xercesc::DOMNode *node);
00150         Color3 radiant_exitance_builder(const xercesc::DOMNode *node) const;
00151         const ITexture *reflectance_builder(const xercesc::DOMNode *node) const;
00152         sheep::Matrix4 rotation_builder(const xercesc::DOMNode *node) const;
00153         sheep::Matrix4 scale_builder(const xercesc::DOMNode *node) const;
00154         void surface_shader_builder(const xercesc::DOMNode *node);
00155         sheep::Matrix4 transform_builder(const xercesc::DOMNode *node) const;
00156         sheep::Matrix4 translation_builder(const xercesc::DOMNode *node) const;
00157 
00158         void insert_into_repository(const std::string &key, const IObject *object);
00159         void insert_into_scene(IBoundedObject *object);
00160         void insert_into_scene(Plane *plane);
00161 
00162         // Camera builders.
00163 
00164         PinholeCamera *pinholecamera_builder(
00165             const sheep::Matrix4 &transform,
00166             const ParameterMap &params
00167         ) const;
00168 
00169         ThinLensCamera *thinlenscamera_builder(
00170             const sheep::Matrix4 &transform,
00171             const ParameterMap &params
00172         ) const;
00173 
00174         // Light builders.
00175 
00176         PointLight *pointlight_builder(
00177             const sheep::Matrix4 &transform,
00178             const ParameterMap &params
00179         ) const;
00180 
00181         // Object builders.
00182 
00183         Cube *cube_builder(
00184             const sheep::Matrix4 &transform,
00185             IObject::IntersectionMask intersection_mask,
00186             const ParameterMap &params
00187         ) const;
00188 
00189         MeshBuilder::MeshVector mesh_builder(
00190             const sheep::Matrix4 &transform,
00191             IObject::IntersectionMask intersection_mask,
00192             const ParameterMap &params
00193         ) const;
00194 
00195         Plane *plane_builder(
00196             const sheep::Matrix4 &transform,
00197             IObject::IntersectionMask intersection_mask,
00198             const ParameterMap &params
00199         ) const;
00200 
00201         Ring *ring_builder(
00202             const sheep::Matrix4 &transform,
00203             IObject::IntersectionMask intersection_mask,
00204             const ParameterMap &params
00205         ) const;
00206 
00207         Sphere *sphere_builder(
00208             const sheep::Matrix4 &transform,
00209             IObject::IntersectionMask intersection_mask,
00210             const ParameterMap &params
00211         ) const;
00212 
00213         Square *square_builder(
00214             const sheep::Matrix4 &transform,
00215             IObject::IntersectionMask intersection_mask,
00216             const ParameterMap &params
00217         ) const;
00218     };
00219 
00220 #include "scenebuilder.inl"
00221 
00222 }
00223 
00224 #endif  // !TOXIC_DRIVER_SCENEBUILDER_H

Generated on Tue May 11 01:31:52 2004 for toxic by doxygen 1.3.6