00001 // This file is part of ff3d - http://www.freefem.org/ff3d 00002 // Copyright (C) 2001, 2002, 2003 Stéphane Del Pino 00003 00004 // This program is free software; you can redistribute it and/or modify 00005 // it under the terms of the GNU General Public License as published by 00006 // the Free Software Foundation; either version 2, or (at your option) 00007 // any later version. 00008 00009 // This program is distributed in the hope that it will be useful, 00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 // GNU General Public License for more details. 00013 00014 // You should have received a copy of the GNU General Public License 00015 // along with this program; if not, write to the Free Software Foundation, 00016 // Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00017 00018 // $Id: Scene.hpp,v 1.7 2007/06/09 10:37:08 delpinux Exp $ 00019 00020 #ifndef SCENE_HPP 00021 #define SCENE_HPP 00022 00023 #include <Object.hpp> 00024 #include <Index.hpp> 00025 00026 #include <StreamCenter.hpp> 00027 00028 #include <Stringify.hpp> 00029 #include <ErrorHandler.hpp> 00030 00031 #include <map> 00032 00045 class Scene 00046 { 00047 private: 00049 std::vector<ConstReferenceCounting<Object> > __objects; 00050 00051 struct VectorOrder 00052 { 00053 bool operator()(const TinyVector<3>& a, 00054 const TinyVector<3>& b) const 00055 { 00056 bool less; 00057 if (a[0] < b[0]) { 00058 less = true; 00059 } else if (a[0] == b[0]) { 00060 if (a[1] < b[1]) { 00061 less = true; 00062 } else if (a[1] == b[1]) { 00063 if (a[2] < b[2]) { 00064 less = true; 00065 } else { 00066 less = false; 00067 } 00068 } else { 00069 less = false; 00070 } 00071 } else { 00072 less = false; 00073 } 00074 return less; 00075 } 00076 }; 00077 00079 typedef std::map<TinyVector<3,real_t>, int, 00080 Scene::VectorOrder> ReferenceMap; 00081 ReferenceMap __references; 00082 00083 public: 00085 inline size_t nbObjects() const 00086 { 00087 return __objects.size(); 00088 } 00089 00095 inline void add(ConstReferenceCounting<Object> o) 00096 { 00097 if (o->hasReference()) { 00098 ReferenceMap::iterator i = __references.find(o->reference()); 00099 if (i == __references.end()) { 00100 int size = __references.size(); 00101 __references[o->reference()] = size; 00102 } 00103 } 00104 00105 // finaly store the object 00106 __objects.push_back(o); 00107 } 00108 00110 ConstReferenceCounting<Object> object(const size_t& i) const 00111 { 00112 ASSERT (i<__objects.size()); 00113 return __objects[i]; 00114 } 00115 00116 int getReferenceNumber(const TinyVector<3,real_t>& t) const 00117 { 00118 ReferenceMap::const_iterator i = __references.find(t); 00119 if (i == __references.end()) { 00120 throw ErrorHandler(__FILE__,__LINE__, 00121 stringify(t)+" reference has not been found", 00122 ErrorHandler::normal); 00123 } 00124 return i->second; 00125 } 00126 00131 Scene(); 00132 00138 Scene(const Scene& S); 00139 00144 ~Scene() 00145 { 00146 ; 00147 } 00148 }; 00149 00150 #endif // SCENE_HPP
1.5.6