Home · All Namespaces · All Classes · Functions · Coding Style · Plugins · File Structure

core/StelGrid.hpp

00001 /*
00002  * Stellarium
00003  * Copyright (C) 2007 Guillaume Chereau
00004  * 
00005  * This program is free software; you can redistribute it and/or
00006  * modify it under the terms of the GNU General Public License
00007  * as published by the Free Software Foundation; either version 2
00008  * of the License, or (at your option) any later version.
00009  * 
00010  * This program is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  * GNU General Public License for more details.
00014  * 
00015  * You should have received a copy of the GNU General Public License
00016  * along with this program; if not, write to the Free Software
00017  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00018  */
00019  
00020 #ifndef _STELGRID_HPP_
00021 #define _STELGRID_HPP_
00022 
00023 #include "StelGridObject.hpp"
00024 #include "StelSphereGeometry.hpp"
00025 
00026 using namespace StelGeom;
00027 
00028 class StelGrid : public std::vector<StelGridObject*>
00029 {
00030 public:
00031     StelGrid() {}
00032     
00033     virtual ~StelGrid() {}
00034 
00036     virtual void filterIntersect(const ConvexS& s) {;}
00037     
00039     virtual std::vector<StelGridObject*> getAllObjects() = 0;
00040 
00042     void insertResult(StelGridObject* obj)
00043     {
00044         std::vector<StelGridObject*>::push_back(obj);
00045     }
00046     
00048     void insertResult(const std::vector<StelGridObject*>& objs)
00049     {
00050         std::vector<StelGridObject*>::insert(std::vector<StelGridObject*>::end(), objs.begin(), objs.end());
00051     }
00052 };
00053 
00054 class SimpleGrid : public StelGrid
00055 {
00056 public:
00057     SimpleGrid() {}
00058 
00059     ~SimpleGrid() {}
00060     void insert(StelGridObject* obj)
00061     {
00062         all.push_back(obj);
00063     }
00064 
00065     template<class Shape>
00066             void filterIntersect(const Shape& s);
00067 
00069     virtual std::vector<StelGridObject*> getAllObjects() {return all;}
00070 
00071 private:
00072     typedef std::vector<StelGridObject*> AllObjects;
00073     AllObjects all;
00074 };
00075 
00076 template<class Shape> void SimpleGrid::filterIntersect(const Shape& s)
00077 {
00078     // This is a totaly non-optimized method
00079     // because we recompute everything each time, when we
00080     // should use the previous informations we have
00081     this->clear();
00082     for (AllObjects::iterator iter = all.begin(); iter != all.end(); ++iter)
00083     {
00084         if (intersect(s, (*iter)->getPositionForGrid()))
00085         {
00086             this->StelGrid::insertResult(*iter);
00087         }
00088     }
00089 }
00090 
00091 #endif // _STELGRID_HPP_
00092 

Generated on Mon Mar 9 16:16:15 2009 for Stellarium by  doxygen 1.5.5