ESyS-Particle  4.0.1
ParticleCollection.h
00001 
00002 //                                                         //
00003 // Copyright (c) 2003-2011 by The University of Queensland //
00004 // Earth Systems Science Computational Centre (ESSCC)      //
00005 // http://www.uq.edu.au/esscc                              //
00006 //                                                         //
00007 // Primary Business: Brisbane, Queensland, Australia       //
00008 // Licensed under the Open Software License version 3.0    //
00009 // http://www.opensource.org/licenses/osl-3.0.php          //
00010 //                                                         //
00012 
00013 #ifndef ESYS_LSMPARTICLECOLLECTION_H
00014 #define ESYS_LSMPARTICLECOLLECTION_H
00015 
00016 #include "Foundation/BoundingBox.h"
00017 #include "Foundation/StlIterator.h"
00018 #include "Geometry/Vec3L.h"
00019 
00020 #include <boost/shared_ptr.hpp>
00021 #include <boost/pool/object_pool.hpp>
00022 
00023 #include <vector>
00024 #include <float.h>
00025 
00026 namespace esys
00027 {
00028   namespace lsm
00029   {
00033     template <typename TmplParticle>
00034     class ParticleCollection
00035     {
00036     public:
00037       typedef TmplParticle Particle;
00038       typedef boost::object_pool<Particle>         ParticlePool;
00039       typedef boost::shared_ptr<ParticlePool>      ParticlePoolPtr;
00040 
00041     private:
00042       typedef std::vector<Particle *>              ParticleVector;
00043       typedef ForwardIterator<ParticleVector>      VectorIterator;
00044       typedef ForwardConstIterator<ParticleVector> VectorConstIterator;
00045 
00046     public:
00047 
00048       class ParticleIterator : public VectorIterator
00049       {
00050       public:
00051         typedef Particle& value_type;
00052         ParticleIterator(const VectorIterator &it)
00053          : VectorIterator(it)
00054         {
00055         }
00056 
00057         value_type next()
00058         {
00059           return *(VectorIterator::next());
00060         }
00061 
00062         value_type current() const
00063         {
00064           return *(VectorIterator::current());
00065         }
00066       };
00067 
00068       class ParticleConstIterator : public VectorConstIterator
00069       {
00070       public:
00071         typedef const Particle& value_type;
00072         ParticleConstIterator(const VectorConstIterator &it)
00073          : VectorConstIterator(it)
00074         {
00075         }
00076 
00077         ParticleConstIterator(const VectorIterator &it)
00078          : VectorConstIterator(it)
00079         {
00080         }
00081 
00082         value_type next()
00083         {
00084           return *(VectorConstIterator::next());
00085         }
00086 
00087         value_type current() const
00088         {
00089           return *(VectorConstIterator::current());
00090         }
00091       };
00092 
00093       ParticleCollection();
00094 
00095       ParticleCollection(ParticlePoolPtr particlePoolPtr);
00096 
00097       ParticleCollection(const ParticleCollection &p);
00098 
00099       ParticleCollection &operator=(const ParticleCollection &p);
00100       
00101       virtual ~ParticleCollection();
00102 
00103       int getNumParticles() const;
00104 
00105       BoundingBox getParticleBBox() const;
00106 
00107       ParticleIterator getParticleIterator()
00108       {
00109         return ParticleIterator(VectorIterator(m_particleVector));
00110       }
00111 
00112       ParticleConstIterator getParticleIterator() const
00113       {
00114         return ParticleConstIterator(VectorConstIterator(m_particleVector));
00115       }
00116 
00122       void translateBy(const Vec3 &vec);
00123 
00131       void rotate(const Vec3 &rotation, const Vec3 &posn);
00132 
00138       void incrementIdBy(typename Particle::Id idIncr);
00139 
00144       void insertRef(Particle &p);
00145 
00151       Particle &createParticle(const Particle &p);
00152 
00153     protected:
00158       void noCheckInsertRef(Particle &p);
00159 
00160     private:
00161       ParticlePoolPtr m_particlePoolPtr;
00162       ParticleVector  m_particleVector;
00163     };
00164   };
00165 };
00166 
00167 #include "Geometry/ParticleCollection.hpp"
00168 
00169 #endif