ESyS-Particle  4.0.1
NeighbourTable.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 
00014 #ifndef ESYS_LSMNEIGHBOURTABLE_H
00015 #define ESYS_LSMNEIGHBOURTABLE_H
00016 
00017 #include <Foundation/BoundingBox.h>
00018 #include <Foundation/StlIterator.h>
00019 #include <Geometry/Vec3L.h>
00020 #include <vector>
00021 #include <algorithm>
00022 #include <boost/shared_array.hpp>
00023 
00024 namespace esys
00025 {
00026   namespace lsm
00027   {
00031     template <class TmplParticle>
00032     class NeighbourTable
00033     {
00034     public:
00035       typedef TmplParticle            Particle; 
00036       typedef std::vector<Particle *> ParticleVector;
00037 
00038       NeighbourTable(const BoundingBox &bBox, double gridSpacing);
00039 
00040       NeighbourTable(const NeighbourTable &nTable);
00041       
00042       virtual ~NeighbourTable();
00043       
00044       void clear();
00045       
00046       double getGridSpacing() const;
00047 
00048       void resize(const BoundingBox &bBox, double gridSpacing);
00049 
00050       const Vec3L &getDimensions() const;
00051 
00052       const BoundingBox &getBBox() const;
00053 
00054       const Vec3 &getMinPt() const;
00055 
00059       size_t size() const;
00060 
00061       int getScalarIndex(int xIdx, int yIdx, int zIdx) const;
00062 
00063       int getScalarIndex(const Vec3L &index) const;
00064 
00065       int getScalarIndex(const Vec3 &pt) const;
00066 
00067       const Vec3L &getMinVecIndex() const;
00068 
00069       const Vec3L &getMaxVecIndex() const;
00070 
00071       Vec3L getVecIndex(const Vec3 &pt) const;
00072 
00073       ParticleVector getNeighbourVector(const Vec3 &pt, double radius) const;
00074 
00075       ParticleVector getUniqueNeighbourVector(const Vec3 &pt, double radius) const;
00076 
00077       ParticleVector getNeighbourVector(const Vec3 &pt) const;
00078 
00079       void insert(Particle *pParticle);
00080 
00081       void insert(Particle &particle);
00082 
00083       typedef ForwardIterator<ParticleVector> ParticleIterator;
00084       typedef ForwardConstIterator<ParticleVector> ParticleConstIterator;
00085 
00086       ParticleIterator getParticleIterator();
00087 
00088       ParticleConstIterator getParticleIterator() const;
00089 
00090     protected:
00091 
00092       void insertInTable(Particle *pParticle, const Vec3L &minIdx, const Vec3L &maxIdx);
00093 
00094       void addInserted(Particle *pParticle);
00095 
00096       int getNumCells() const;
00097 
00098       ParticleVector getInsertedParticles() const;
00099 
00100       void clearAndRecomputeGrid(const BoundingBox &bBox, double gridSpacing);
00101       
00102     private:
00103       typedef boost::shared_array<ParticleVector> ParticleVectorArrayPtr;
00104 
00105       Vec3L                  m_dimensions;
00106       Vec3L                  m_minIndex;
00107       Vec3L                  m_maxIndex;
00108       double                 m_gridSpacing;
00109       BoundingBox            m_bBox;
00110       ParticleVector         m_insertedParticles;
00111       ParticleVectorArrayPtr m_tablePtr;
00112     };
00113   }
00114 }
00115 
00116 #include "Geometry/NeighbourTable.hpp"
00117 
00118 #endif