1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179
|
/////////////////////////////////////////////////////////////
// //
// Copyright (c) 2003-2011 by The University of Queensland //
// Earth Systems Science Computational Centre (ESSCC) //
// http://www.uq.edu.au/esscc //
// //
// Primary Business: Brisbane, Queensland, Australia //
// Licensed under the Open Software License version 3.0 //
// http://www.opensource.org/licenses/osl-3.0.php //
// //
/////////////////////////////////////////////////////////////
#ifndef ESYS_LSMRANDOMSPHEREPACKER_H
#define ESYS_LSMRANDOMSPHEREPACKER_H
#include "Foundation/console.h"
#include "Foundation/Rng.h"
#include "Foundation/BoundingSphere.h"
#include "Geometry/CubicBoxPacker.h"
#include "Geometry/SphereFitter.h"
#include "Geometry/Plane.h"
#include <vector>
#include <boost/shared_ptr.hpp>
namespace esys
{
namespace lsm
{
template <typename TmplFitterTraits>
class SphereFittedPIterator
{
public:
typedef TmplFitterTraits FitterTraits;
typedef typename FitterTraits::Plane Plane;
typedef typename FitterTraits::PlaneVector PlaneVector;
typedef typename FitterTraits::Packer Packer;
typedef typename Packer::Particle Particle;
typedef typename Packer::ParticleVector ParticleVector;
class FitTraits
{
public:
typedef Packer Validator;
typedef typename Packer::Particle Particle;
typedef typename Packer::ParticleVector ParticleVector;
typedef typename FitterTraits::Plane Plane;
};
typedef SphereFitter<FitTraits> Fitter;
typedef boost::shared_ptr<Fitter> FitterPtr;
typedef std::vector<FitterPtr> FitterPtrVector;
typedef MoveToSurfaceFitter<FitTraits> Move2SurfaceFitter;
typedef ThreeDSphereFitter<FitTraits> ThreeDFitter;
typedef TwoDSphereFitter<FitTraits> TwoDSFitter;
typedef TwoDSphereSphereFitter<FitTraits> TwoDSSphereFitter;
typedef ThreeDSphereSphereFitter<FitTraits> ThreeDSSphereFitter;
SphereFittedPIterator(
Packer &packer,
int maxInsertionFailures,
const BoundingSphere &bSphere
);
void initialiseFitterPtrVector();
const BoundingSphere &getBSphere() const;
int getMaxInsertionFailures() const;
const FitterPtrVector &getFitterPtrVector() const;
FitterPtrVector &getFitterPtrVector();
const Packer &getPacker() const;
Packer &getPacker();
double getRandom(double min, double max) const;
Vec3 getRandomPoint() const;
Particle getCandidateParticle(const Vec3 &point);
ParticleVector getClosestNeighbours(const Particle& particle, int numClosest);
Particle &generateNext();
bool hasNext();
Particle next();
void logInfo();
private:
Packer *m_pPacker;
FitterPtrVector m_fitterPtrVector;
int m_maxInsertionFailures;
int m_lastFailCount;
int m_successCount;
Particle m_next;
BoundingSphere m_bSphere;
};
/**
*
*/
template <typename TmplParticleGenerator,template <typename TmplPartGen> class TmplCubicBoxPackerWrap>
class RandomSpherePacker : public TmplCubicBoxPackerWrap<TmplParticleGenerator>::CubicBoxPackerBase
{
public:
typedef
typename TmplCubicBoxPackerWrap<TmplParticleGenerator>::CubicBoxPackerBase
Inherited;
typedef typename Inherited::ParticleGenerator ParticleGenerator;
typedef typename Inherited::ParticleGeneratorPtr ParticleGeneratorPtr;
typedef typename Inherited::Particle Particle;
typedef typename Inherited::NTable NTable;
typedef typename Inherited::NTablePtr NTablePtr;
typedef typename NTable::ParticleVector ParticleVector;
typedef typename Inherited::ParticlePool ParticlePool;
typedef typename Inherited::ParticlePoolPtr ParticlePoolPtr;
class StufferTraits
{
public:
typedef RandomSpherePacker Packer;
typedef esys::lsm::Plane Plane;
typedef std::vector<Plane> PlaneVector;
};
typedef SphereFittedPIterator<StufferTraits> StuffedParticleIterator;
RandomSpherePacker(
ParticleGeneratorPtr particleGeneratorPtr,
ParticlePoolPtr particlePoolPtr,
NTablePtr nTablePtr,
const BoundingSphere &bSphere,
double tolerance,
double cubicPackRadius,
int maxInsertionFailures,
bool do2d
);
virtual ~RandomSpherePacker();
const BoundingSphere &getBSphere() const;
bool particleIsValid(const Particle &particle) const;
double getRandom(double min, double max) const;
Vec3 getRandomPoint() const;
ParticleVector getClosestNeighbours(const Particle& particle, int numClosest);
int getMaxInsertionFailures() const;
bool particleFitsInBSphere(const Particle &particle) const;
bool particleFitsInBSphereWithNeighbours(const Particle &particle) const;
void generateCubicPackingInSphere();
void generateRandomFill();
virtual void generate();
private:
BoundingSphere m_bSphere;
int m_maxInsertionFailures;
};
};
};
#include "Geometry/RandomSpherePacker.hpp"
#endif
|