ESyS-Particle
4.0.1
|
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_LSMRANDOMSPHEREPACKER_H 00015 #define ESYS_LSMRANDOMSPHEREPACKER_H 00016 00017 #include "Foundation/console.h" 00018 #include "Foundation/Rng.h" 00019 #include "Foundation/BoundingSphere.h" 00020 #include "Geometry/CubicBoxPacker.h" 00021 #include "Geometry/SphereFitter.h" 00022 #include "Geometry/Plane.h" 00023 00024 00025 #include <vector> 00026 #include <boost/shared_ptr.hpp> 00027 00028 namespace esys 00029 { 00030 namespace lsm 00031 { 00032 template <typename TmplFitterTraits> 00033 class SphereFittedPIterator 00034 { 00035 public: 00036 typedef TmplFitterTraits FitterTraits; 00037 typedef typename FitterTraits::Plane Plane; 00038 typedef typename FitterTraits::PlaneVector PlaneVector; 00039 typedef typename FitterTraits::Packer Packer; 00040 typedef typename Packer::Particle Particle; 00041 typedef typename Packer::ParticleVector ParticleVector; 00042 00043 class FitTraits 00044 { 00045 public: 00046 typedef Packer Validator; 00047 typedef typename Packer::Particle Particle; 00048 typedef typename Packer::ParticleVector ParticleVector; 00049 typedef typename FitterTraits::Plane Plane; 00050 }; 00051 00052 typedef SphereFitter<FitTraits> Fitter; 00053 typedef boost::shared_ptr<Fitter> FitterPtr; 00054 typedef std::vector<FitterPtr> FitterPtrVector; 00055 typedef MoveToSurfaceFitter<FitTraits> Move2SurfaceFitter; 00056 typedef ThreeDSphereFitter<FitTraits> ThreeDFitter; 00057 typedef TwoDSphereFitter<FitTraits> TwoDSFitter; 00058 typedef TwoDSphereSphereFitter<FitTraits> TwoDSSphereFitter; 00059 typedef ThreeDSphereSphereFitter<FitTraits> ThreeDSSphereFitter; 00060 00061 SphereFittedPIterator( 00062 Packer &packer, 00063 int maxInsertionFailures, 00064 const BoundingSphere &bSphere 00065 ); 00066 00067 void initialiseFitterPtrVector(); 00068 00069 const BoundingSphere &getBSphere() const; 00070 00071 int getMaxInsertionFailures() const; 00072 00073 const FitterPtrVector &getFitterPtrVector() const; 00074 00075 FitterPtrVector &getFitterPtrVector(); 00076 00077 const Packer &getPacker() const; 00078 00079 Packer &getPacker(); 00080 00081 double getRandom(double min, double max) const; 00082 00083 Vec3 getRandomPoint() const; 00084 00085 Particle getCandidateParticle(const Vec3 &point); 00086 00087 ParticleVector getClosestNeighbours(const Particle& particle, int numClosest); 00088 00089 Particle &generateNext(); 00090 00091 bool hasNext(); 00092 00093 Particle next(); 00094 00095 void logInfo(); 00096 00097 private: 00098 Packer *m_pPacker; 00099 FitterPtrVector m_fitterPtrVector; 00100 int m_maxInsertionFailures; 00101 int m_lastFailCount; 00102 int m_successCount; 00103 Particle m_next; 00104 BoundingSphere m_bSphere; 00105 }; 00106 00110 template <typename TmplParticleGenerator,template <typename TmplPartGen> class TmplCubicBoxPackerWrap> 00111 class RandomSpherePacker : public TmplCubicBoxPackerWrap<TmplParticleGenerator>::CubicBoxPackerBase 00112 { 00113 public: 00114 typedef 00115 typename TmplCubicBoxPackerWrap<TmplParticleGenerator>::CubicBoxPackerBase 00116 Inherited; 00117 typedef typename Inherited::ParticleGenerator ParticleGenerator; 00118 typedef typename Inherited::ParticleGeneratorPtr ParticleGeneratorPtr; 00119 typedef typename Inherited::Particle Particle; 00120 typedef typename Inherited::NTable NTable; 00121 typedef typename Inherited::NTablePtr NTablePtr; 00122 typedef typename NTable::ParticleVector ParticleVector; 00123 typedef typename Inherited::ParticlePool ParticlePool; 00124 typedef typename Inherited::ParticlePoolPtr ParticlePoolPtr; 00125 00126 class StufferTraits 00127 { 00128 public: 00129 typedef RandomSpherePacker Packer; 00130 typedef esys::lsm::Plane Plane; 00131 typedef std::vector<Plane> PlaneVector; 00132 }; 00133 typedef SphereFittedPIterator<StufferTraits> StuffedParticleIterator; 00134 00135 RandomSpherePacker( 00136 ParticleGeneratorPtr particleGeneratorPtr, 00137 ParticlePoolPtr particlePoolPtr, 00138 NTablePtr nTablePtr, 00139 const BoundingSphere &bSphere, 00140 double tolerance, 00141 double cubicPackRadius, 00142 int maxInsertionFailures, 00143 bool do2d 00144 ); 00145 00146 virtual ~RandomSpherePacker(); 00147 00148 const BoundingSphere &getBSphere() const; 00149 00150 bool particleIsValid(const Particle &particle) const; 00151 00152 double getRandom(double min, double max) const; 00153 00154 Vec3 getRandomPoint() const; 00155 00156 ParticleVector getClosestNeighbours(const Particle& particle, int numClosest); 00157 00158 int getMaxInsertionFailures() const; 00159 00160 bool particleFitsInBSphere(const Particle &particle) const; 00161 00162 bool particleFitsInBSphereWithNeighbours(const Particle &particle) const; 00163 00164 void generateCubicPackingInSphere(); 00165 00166 void generateRandomFill(); 00167 00168 virtual void generate(); 00169 00170 private: 00171 BoundingSphere m_bSphere; 00172 int m_maxInsertionFailures; 00173 }; 00174 }; 00175 }; 00176 00177 #include "Geometry/RandomSpherePacker.hpp" 00178 00179 #endif