gee_world.h

Go to the documentation of this file.
00001 /* -*- C++ -*- */
00002 
00003 /* COPYRIGHT
00004  *
00005  * This file is part of the Visual Effects Engine - VEE
00006  *
00007  * Read the "VEE-LICENSE" file for the license.
00008  *
00009  * Authors & Copyright:   
00010  *
00011  * Tommi Ilmonen, Tuukka Heikura, Marko Myllymaa and 
00012  * Janne Kontkanen 2001-2004
00013  *
00014  * Additional copyrights: Tekes 2003-2004
00015  *
00016  * firstname.lastname@hut.fi
00017  *
00018  */
00019 
00020 #ifndef GEE_WORLD_H
00021 #define GEE_WORLD_H
00022 
00023 #include <gee_camera_parameters.h>
00024 #include <gee_geometry.h>
00025 #include <gee_operator.h>
00026 
00027 #include <vee_reference_object.h>
00028 
00029 #include <di_types.h>
00030 
00031 #include <map>
00032 
00033 class GEE_Engine;
00034 class GEE_Renderer;
00035 
00036 class VEE_RenderClass;
00037 
00047 class GEE_World : public GEE_IdContainer
00048 {
00049 public:
00050 
00051   friend class GEE_LayerGeometryIterator;
00052 
00053   typedef std::map<GEE_id_t, VEE_RefPtr<GEE_Geometry> > container;
00054   typedef container::iterator iterator;
00055 
00056   typedef std::map<GEE_id_t, GEE_CameraParameters> cameraContainer;
00057   typedef cameraContainer::iterator cameraIterator;
00058 
00059 
00060   GEE_World(GEE_Engine * host = 0);
00061   ~GEE_World();
00062 
00063   GEE_id_t addGeometry(GEE_Geometry *);
00064   GEE_id_t addGeometry2(VEE_RefPtr<GEE_Geometry> &);
00065 
00066   inline GEE_Geometry * geometry(GEE_id_t id);
00067   inline VEE_RefPtr<GEE_Geometry> * geometry2(GEE_id_t id);
00068   bool eraseGeometry(GEE_id_t id);
00069 
00070   void render(GEE_Renderer *);
00071   // void clearAfter(GEE_TimeStamp ts);
00072 
00073   void clear();
00074 
00075   iterator begin() { return m_geometry.begin(); }
00076   iterator end()   { return m_geometry.end(); }
00077 
00078   void setGarbageBin(VEE_GarbageBin * bin) { m_deleted = bin; }
00079   
00080   static VEE_RefPtr<GEE_Geometry> & getGeometry(iterator & i) 
00081   { return (*i).second; }
00082 
00083   bool read(GEE_Io *);
00084   bool write(GEE_Io *);
00085 
00086   void collectIds(GEE_IdContainer::id_remap &);
00087   void remapIds(GEE_IdContainer::id_remap &);
00088   void setAllGenerations(int g);
00089   
00090   const VEE_Rgba &backgroundColor() const { return m_bgColor; }
00091   void setBackgroundColor(const VEE_Rgba &color) { m_bgColor = color; }
00092 
00093   void deNearlySelectAll();
00094   void selectAll(uint selectionState);
00095 
00096   void dump();
00097 
00098   static void addTextureId(const std::string & name, int id);
00099   static int textureId(const std::string & name);
00100   static std::string textureName(int id);
00101   static void loadTextureDefinitions(const char * filename);
00102 
00103   static void addRenderClass(const std::string & id, const VEE_RenderClass * );
00104   static VEE_RenderClass * renderClass(const std::string & id);
00105   static void getRenderClassNames(std::list<std::string> * classes);
00106 
00107   void merge(GEE_World &);
00108   void allGeometriesToLayer(GEE_id_t layer);
00109 
00110   void getBoundingBox(VEE_BoundingBox *);
00111   GEE_Engine     * host() { return m_host; }
00112 
00113   uint geometryCount() const { return m_geometry.size(); }
00114 
00115   GEE_CameraParameters * camera(GEE_id_t);
00116   void setCamera(GEE_id_t, const GEE_CameraParameters &);
00117 
00118   cameraIterator beginCamera() { return m_cameras.begin(); }
00119   cameraIterator endCamera()   { return m_cameras.end(); }
00120 
00121 protected:
00122 
00123   // static void cleanContainer(container &, GEE_TimeStamp);
00124 
00125   container        m_geometry;
00126 
00127   VEE_GarbageBin * m_deleted;
00128 
00129   VEE_Rgba         m_bgColor;
00130 
00131   GEE_Engine     * m_host;
00132 
00133   cameraContainer  m_cameras;
00134 };
00135 
00136 
00137 inline GEE_Geometry * GEE_World::geometry(GEE_id_t id)
00138 {
00139   iterator it = m_geometry.find(id);
00140   if(it == m_geometry.end())
00141     return 0;
00142 
00143   return (*it).second.ptr();
00144 }
00145 
00146 inline VEE_RefPtr<GEE_Geometry> * GEE_World::geometry2(GEE_id_t id)
00147 {
00148   iterator it = m_geometry.find(id);
00149   if(it == m_geometry.end())
00150     return 0;
00151 
00152   return & (*it).second;
00153 }
00154 
00157 
00164 class GEE_LayerGeometryIterator
00165 {
00166 public:
00170   GEE_LayerGeometryIterator(GEE_World *w, GEE_id_t layer, bool visibles=true) 
00171     : m_layer(layer), m_it(w->begin()), m_end(w->end()), m_world(w)
00172   {
00173     if((layer != -1) && (m_it != m_end)) {
00174       while((m_it != m_end) && ((*m_it).second.ptr()->layer() != layer))
00175   m_it++;
00176     }
00177     if(visibles && (m_it != m_end) && !(*m_it).second.ptr()->visible())
00178       nextVisible();
00179   }
00180   
00184   GEE_Geometry * operator * () 
00185   { return (m_it == m_end) ? 0 : GEE_World::getGeometry(m_it).ptr(); }
00186   
00190   void operator ++ ()
00191   {
00192     m_it++;
00193 
00194     if(m_layer != -1) {
00195       while((m_it != m_end) && 
00196       ((*m_it).second.ptr()->layer() != m_layer))
00197   m_it++;
00198     }
00199   }
00200   
00203   void nextVisible()
00204   {
00205     m_it++;
00206     if(m_layer == -1) {
00207       while((m_it != m_end) && !(*m_it).second.ptr()->visible())
00208   m_it++;
00209     }
00210     else {
00211       while((m_it != m_end) &&
00212       (((*m_it).second.ptr()->layer() != m_layer) ||
00213        !(*m_it).second.ptr()->visible()))
00214   m_it++;
00215     }
00216   }
00217 
00221   void eraseAndNextVisible();
00222 
00223 protected:
00224 
00225   GEE_id_t   m_layer;
00226   GEE_World::iterator   m_it;
00227   GEE_World::iterator   m_end;
00228   GEE_World * m_world;
00229 };
00230 
00231 
00232 #endif

Generated on Mon Mar 12 21:09:00 2007 for VEE - The Visual Effects Engine by  doxygen 1.4.6