From fe158076fdb701d4ff570c965f1c2c00a9e700ff Mon Sep 17 00:00:00 2001 From: Gennady Pospelov <g.pospelov@fz-juelich.de> Date: Mon, 29 Jul 2013 17:33:23 +0200 Subject: [PATCH] setName for formfactors --- App/src/TestBugs.cpp | 8 +-- Core/FormFactors/inc/FormFactorBox.h | 3 +- .../inc/FormFactorDecoratorDebyeWaller.h | 5 +- .../inc/FormFactorDecoratorFactor.h | 4 +- .../inc/FormFactorDecoratorRefractiveIndex.h | 9 ++-- .../inc/FormFactorDecoratorTransformation.h | 6 +-- Core/FormFactors/inc/FormFactorSphere.h | 3 +- .../inc/FormFactorSphereGaussianRadius.h | 5 +- Core/FormFactors/src/FormFactorBox.cpp | 9 ++++ Core/FormFactors/src/FormFactorCone.cpp | 5 +- Core/FormFactors/src/FormFactorCrystal.cpp | 6 ++- Core/FormFactors/src/FormFactorCylinder.cpp | 4 +- Core/FormFactors/src/FormFactorDWBA.cpp | 7 +-- .../src/FormFactorDecoratorTransformation.cpp | 12 ++++- Core/FormFactors/src/FormFactorFullSphere.cpp | 5 +- .../src/FormFactorFullSpheroid.cpp | 5 +- Core/FormFactors/src/FormFactorGauss.cpp | 5 +- .../src/FormFactorHemiSpheroid.cpp | 5 +- Core/FormFactors/src/FormFactorLorentz.cpp | 5 +- .../src/FormFactorParallelepiped.cpp | 7 ++- Core/FormFactors/src/FormFactorPrism3.cpp | 5 +- Core/FormFactors/src/FormFactorPrism6.cpp | 4 +- Core/FormFactors/src/FormFactorPyramid.cpp | 5 +- Core/FormFactors/src/FormFactorSphere.cpp | 8 +++ .../FormFactors/src/FormFactorTethraedron.cpp | 5 +- Core/FormFactors/src/FormFactorWeighted.cpp | 7 +-- Core/Samples/inc/Particle.h | 18 ++++--- Core/Samples/src/Particle.cpp | 8 ++- Tests/UnitTests/TestCore/LayerTest.h | 2 - Tests/UnitTests/TestCore/ParticleTest.h | 54 ++++++++++++++++++- 30 files changed, 171 insertions(+), 63 deletions(-) diff --git a/App/src/TestBugs.cpp b/App/src/TestBugs.cpp index 358d2d60fb6..7af1e2254a3 100644 --- a/App/src/TestBugs.cpp +++ b/App/src/TestBugs.cpp @@ -25,11 +25,11 @@ void TestBugs::test_item339() { std::cout << "TestBugs::test_item339() -> " << std::endl; - const IMaterial *mAmbience = - MaterialManager::getHomogeneousMaterial("Air", 0.0, 0.0 ); +// const IMaterial *mAmbience = +// MaterialManager::getHomogeneousMaterial("Air", 0.0, 0.0 ); - const IMaterial *mSubstrate = - MaterialManager::getHomogeneousMaterial("Substrate", 6e-6, 2e-8 ); +// const IMaterial *mSubstrate = +// MaterialManager::getHomogeneousMaterial("Substrate", 6e-6, 2e-8 ); complex_t n_particle(1.0-6e-4, 2e-8); const IMaterial *mParticle = diff --git a/Core/FormFactors/inc/FormFactorBox.h b/Core/FormFactors/inc/FormFactorBox.h index 50a7badf0dd..493a4f7e83c 100644 --- a/Core/FormFactors/inc/FormFactorBox.h +++ b/Core/FormFactors/inc/FormFactorBox.h @@ -29,8 +29,7 @@ class FormFactorBox : public IFormFactorBorn ~FormFactorBox() {} - FormFactorBox *clone() const - { return new FormFactorBox(m_radius, m_width, m_height ); } + FormFactorBox *clone() const; virtual void accept(ISampleVisitor *visitor) const { visitor->visit(this); } diff --git a/Core/FormFactors/inc/FormFactorDecoratorDebyeWaller.h b/Core/FormFactors/inc/FormFactorDecoratorDebyeWaller.h index 53f7bdb1253..951542fe428 100644 --- a/Core/FormFactors/inc/FormFactorDecoratorDebyeWaller.h +++ b/Core/FormFactors/inc/FormFactorDecoratorDebyeWaller.h @@ -61,8 +61,11 @@ class FormFactorDecoratorDebyeWaller : public IFormFactorDecorator virtual FormFactorDecoratorDebyeWaller *clone() const { - return new FormFactorDecoratorDebyeWaller( + + FormFactorDecoratorDebyeWaller *result = new FormFactorDecoratorDebyeWaller( mp_form_factor->clone(), m_h_dw_factor, m_r_dw_factor); + result->setName(getName()); + return result; } virtual complex_t evaluate( diff --git a/Core/FormFactors/inc/FormFactorDecoratorFactor.h b/Core/FormFactors/inc/FormFactorDecoratorFactor.h index 5937fd5ae27..64d70b1a81a 100644 --- a/Core/FormFactors/inc/FormFactorDecoratorFactor.h +++ b/Core/FormFactors/inc/FormFactorDecoratorFactor.h @@ -45,7 +45,9 @@ inline FormFactorDecoratorFactor::FormFactorDecoratorFactor( inline FormFactorDecoratorFactor* FormFactorDecoratorFactor::clone() const { - return new FormFactorDecoratorFactor(mp_form_factor->clone(), m_factor); + FormFactorDecoratorFactor *result = new FormFactorDecoratorFactor(mp_form_factor->clone(), m_factor); + result->setName(getName()); + return result; } inline complex_t FormFactorDecoratorFactor::evaluate(const cvector_t& k_i, const Bin1DCVector& k_f_bin, double alpha_i, double alpha_f) const diff --git a/Core/FormFactors/inc/FormFactorDecoratorRefractiveIndex.h b/Core/FormFactors/inc/FormFactorDecoratorRefractiveIndex.h index 983f255103c..9aff5e804da 100644 --- a/Core/FormFactors/inc/FormFactorDecoratorRefractiveIndex.h +++ b/Core/FormFactors/inc/FormFactorDecoratorRefractiveIndex.h @@ -28,6 +28,8 @@ class FormFactorDecoratorRefractiveIndex : public FormFactorDecoratorFactor FormFactorDecoratorRefractiveIndex *clone() const; + virtual complex_t getAmbientRefractiveIndex() const { return m_refractive_index; } + virtual void setAmbientRefractiveIndex(const complex_t& ambient_refractive_index); private: complex_t getRefractiveIndexFactor(const complex_t& ambient_index, const complex_t& particle_index) const; @@ -50,10 +52,11 @@ inline FormFactorDecoratorRefractiveIndex::~FormFactorDecoratorRefractiveIndex() inline FormFactorDecoratorRefractiveIndex* FormFactorDecoratorRefractiveIndex::clone() const { - FormFactorDecoratorRefractiveIndex *p_new = + FormFactorDecoratorRefractiveIndex *result = new FormFactorDecoratorRefractiveIndex(mp_form_factor->clone(), m_refractive_index); - p_new->m_factor = m_factor; - return p_new; + result->m_factor = m_factor; + result->setName(getName()); + return result; } inline void FormFactorDecoratorRefractiveIndex::setAmbientRefractiveIndex( diff --git a/Core/FormFactors/inc/FormFactorDecoratorTransformation.h b/Core/FormFactors/inc/FormFactorDecoratorTransformation.h index 5212fbc4fba..cb5fa3dd669 100644 --- a/Core/FormFactors/inc/FormFactorDecoratorTransformation.h +++ b/Core/FormFactors/inc/FormFactorDecoratorTransformation.h @@ -36,11 +36,7 @@ class FormFactorDecoratorTransformation : public IFormFactorDecorator virtual ~FormFactorDecoratorTransformation() {} - virtual FormFactorDecoratorTransformation *clone() const - { - return new FormFactorDecoratorTransformation( - mp_form_factor->clone(), mP_transform); - } + virtual FormFactorDecoratorTransformation *clone() const; virtual complex_t evaluate( const cvector_t& k_i, const Bin1DCVector& k_f_bin, diff --git a/Core/FormFactors/inc/FormFactorSphere.h b/Core/FormFactors/inc/FormFactorSphere.h index cbc2e41b4cf..be914fd4437 100644 --- a/Core/FormFactors/inc/FormFactorSphere.h +++ b/Core/FormFactors/inc/FormFactorSphere.h @@ -29,8 +29,7 @@ class FormFactorSphere : public IFormFactorBorn ~FormFactorSphere() { delete m_integrator; } - virtual FormFactorSphere *clone() const - { return new FormFactorSphere(m_radius, m_height); } + virtual FormFactorSphere *clone() const; virtual void accept(ISampleVisitor *visitor) const { visitor->visit(this); } diff --git a/Core/FormFactors/inc/FormFactorSphereGaussianRadius.h b/Core/FormFactors/inc/FormFactorSphereGaussianRadius.h index 38f1fd48205..e12819cf91b 100644 --- a/Core/FormFactors/inc/FormFactorSphereGaussianRadius.h +++ b/Core/FormFactors/inc/FormFactorSphereGaussianRadius.h @@ -66,9 +66,10 @@ inline FormFactorSphereGaussianRadius::FormFactorSphereGaussianRadius(double mea inline FormFactorSphereGaussianRadius* FormFactorSphereGaussianRadius::clone() const { - FormFactorSphereGaussianRadius *p_clone = + FormFactorSphereGaussianRadius *result = new FormFactorSphereGaussianRadius(m_mean, m_sigma); - return p_clone; + result->setName(getName()); + return result; } inline FormFactorSphereGaussianRadius::~FormFactorSphereGaussianRadius() diff --git a/Core/FormFactors/src/FormFactorBox.cpp b/Core/FormFactors/src/FormFactorBox.cpp index 4ef4867edb9..96e0205f58a 100644 --- a/Core/FormFactors/src/FormFactorBox.cpp +++ b/Core/FormFactors/src/FormFactorBox.cpp @@ -16,6 +16,15 @@ #include "FormFactorBox.h" #include "MathFunctions.h" + +FormFactorBox *FormFactorBox::clone() const +{ + FormFactorBox *result = new FormFactorBox(m_radius, m_width, m_height); + result->setName(getName()); + return result; +} + + complex_t FormFactorBox::evaluate_for_q(const cvector_t& q) const { complex_t qxR = m_radius*q.x(); diff --git a/Core/FormFactors/src/FormFactorCone.cpp b/Core/FormFactors/src/FormFactorCone.cpp index 3679e2be587..5190b1d6a74 100644 --- a/Core/FormFactors/src/FormFactorCone.cpp +++ b/Core/FormFactors/src/FormFactorCone.cpp @@ -41,8 +41,9 @@ void FormFactorCone::init_parameters() FormFactorCone* FormFactorCone::clone() const { - FormFactorCone* ffCone = new FormFactorCone(m_radius, m_height, m_alpha); - return ffCone; + FormFactorCone* result = new FormFactorCone(m_radius, m_height, m_alpha); + result->setName(getName()); + return result; } //! Real part of the integral. diff --git a/Core/FormFactors/src/FormFactorCrystal.cpp b/Core/FormFactors/src/FormFactorCrystal.cpp index cbba5d856b9..d31453aa26b 100644 --- a/Core/FormFactors/src/FormFactorCrystal.cpp +++ b/Core/FormFactors/src/FormFactorCrystal.cpp @@ -23,6 +23,7 @@ FormFactorCrystal::FormFactorCrystal( , m_ambient_refractive_index(ambient_refractive_index) , m_max_rec_length(0.0) { + setName("FormFactorCrystal"); mp_particle = p_crystal.createBasis(); mp_basis_form_factor = mp_particle->createFormFactor(); mp_meso_form_factor = meso_crystal_form_factor.clone(); @@ -40,9 +41,10 @@ FormFactorCrystal::~FormFactorCrystal() FormFactorCrystal* FormFactorCrystal::clone() const { Crystal np_crystal(*mp_particle, m_lattice); - FormFactorCrystal *p_new = new FormFactorCrystal(np_crystal, + FormFactorCrystal *result = new FormFactorCrystal(np_crystal, *mp_meso_form_factor, m_ambient_refractive_index); - return p_new; + result->setName(getName()); + return result; } void FormFactorCrystal::setAmbientRefractiveIndex( diff --git a/Core/FormFactors/src/FormFactorCylinder.cpp b/Core/FormFactors/src/FormFactorCylinder.cpp index cf5fd9c8c59..2382bc92845 100644 --- a/Core/FormFactors/src/FormFactorCylinder.cpp +++ b/Core/FormFactors/src/FormFactorCylinder.cpp @@ -38,7 +38,9 @@ void FormFactorCylinder::init_parameters() FormFactorCylinder* FormFactorCylinder::clone() const { - return new FormFactorCylinder(m_height, m_radius); + FormFactorCylinder *result = new FormFactorCylinder(m_height, m_radius); + result->setName(getName()); + return result; } complex_t FormFactorCylinder::evaluate_for_q(const cvector_t& q) const diff --git a/Core/FormFactors/src/FormFactorDWBA.cpp b/Core/FormFactors/src/FormFactorDWBA.cpp index 931cbd53cb5..65c7c18158b 100644 --- a/Core/FormFactors/src/FormFactorDWBA.cpp +++ b/Core/FormFactors/src/FormFactorDWBA.cpp @@ -51,9 +51,10 @@ void FormFactorDWBA::calculateTerms(const cvector_t& k_i, const Bin1DCVector& k_ FormFactorDWBA* FormFactorDWBA::clone() const { - FormFactorDWBA *p_new = new FormFactorDWBA(mp_form_factor->clone()); - p_new->setReflectionTransmissionFunction(*mp_RT); - return p_new; + FormFactorDWBA *result = new FormFactorDWBA(mp_form_factor->clone()); + result->setReflectionTransmissionFunction(*mp_RT); + result->setName(getName()); + return result; } diff --git a/Core/FormFactors/src/FormFactorDecoratorTransformation.cpp b/Core/FormFactors/src/FormFactorDecoratorTransformation.cpp index a1a98e896dc..7911104d5c7 100644 --- a/Core/FormFactors/src/FormFactorDecoratorTransformation.cpp +++ b/Core/FormFactors/src/FormFactorDecoratorTransformation.cpp @@ -15,6 +15,16 @@ #include "FormFactorDecoratorTransformation.h" -// Everything done inline: Efficiency reasons? Proven useful? + + +FormFactorDecoratorTransformation *FormFactorDecoratorTransformation::clone() const +{ + FormFactorDecoratorTransformation *result = new FormFactorDecoratorTransformation( + mp_form_factor->clone(), mP_transform); + + result->setName(getName()); + return result; +} + diff --git a/Core/FormFactors/src/FormFactorFullSphere.cpp b/Core/FormFactors/src/FormFactorFullSphere.cpp index c9a1a028424..91b7836b9f9 100644 --- a/Core/FormFactors/src/FormFactorFullSphere.cpp +++ b/Core/FormFactors/src/FormFactorFullSphere.cpp @@ -36,8 +36,9 @@ void FormFactorFullSphere::init_parameters() FormFactorFullSphere* FormFactorFullSphere::clone() const { - FormFactorFullSphere *p_clone = new FormFactorFullSphere(m_radius); - return p_clone; + FormFactorFullSphere *result = new FormFactorFullSphere(m_radius); + result->setName(getName()); + return result; } complex_t FormFactorFullSphere::evaluate_for_q(const cvector_t& q) const diff --git a/Core/FormFactors/src/FormFactorFullSpheroid.cpp b/Core/FormFactors/src/FormFactorFullSpheroid.cpp index f041ec6fe1c..584b9e2f308 100644 --- a/Core/FormFactors/src/FormFactorFullSpheroid.cpp +++ b/Core/FormFactors/src/FormFactorFullSpheroid.cpp @@ -36,9 +36,10 @@ void FormFactorFullSpheroid::init_parameters() FormFactorFullSpheroid* FormFactorFullSpheroid::clone() const { - FormFactorFullSpheroid* ffFullSpheroid = + FormFactorFullSpheroid* result = new FormFactorFullSpheroid(m_radius, m_height); - return ffFullSpheroid; + result->setName(getName()); + return result; } complex_t FormFactorFullSpheroid::evaluate_for_q(const cvector_t& q) const diff --git a/Core/FormFactors/src/FormFactorGauss.cpp b/Core/FormFactors/src/FormFactorGauss.cpp index 9c7dffec627..ced5ab3c938 100644 --- a/Core/FormFactors/src/FormFactorGauss.cpp +++ b/Core/FormFactors/src/FormFactorGauss.cpp @@ -47,8 +47,9 @@ void FormFactorGauss::init_parameters() FormFactorGauss* FormFactorGauss::clone() const { - FormFactorGauss *p_clone = new FormFactorGauss(m_height, m_width); - return p_clone; + FormFactorGauss *result = new FormFactorGauss(m_height, m_width); + result->setName(getName()); + return result; } complex_t FormFactorGauss::evaluate_for_q(const cvector_t& q) const diff --git a/Core/FormFactors/src/FormFactorHemiSpheroid.cpp b/Core/FormFactors/src/FormFactorHemiSpheroid.cpp index 06bf63be682..314a085d61c 100644 --- a/Core/FormFactors/src/FormFactorHemiSpheroid.cpp +++ b/Core/FormFactors/src/FormFactorHemiSpheroid.cpp @@ -44,9 +44,10 @@ void FormFactorHemiSpheroid::init_parameters() FormFactorHemiSpheroid* FormFactorHemiSpheroid::clone() const { - FormFactorHemiSpheroid* ffSpheroid = + FormFactorHemiSpheroid* result = new FormFactorHemiSpheroid(m_radius, m_width, m_height); - return ffSpheroid; + result->setName(getName()); + return result; } //! Real part of the integral. diff --git a/Core/FormFactors/src/FormFactorLorentz.cpp b/Core/FormFactors/src/FormFactorLorentz.cpp index 8b81697bd16..9087c557866 100644 --- a/Core/FormFactors/src/FormFactorLorentz.cpp +++ b/Core/FormFactors/src/FormFactorLorentz.cpp @@ -45,8 +45,9 @@ void FormFactorLorentz::init_parameters() FormFactorLorentz* FormFactorLorentz::clone() const { - FormFactorLorentz *p_clone = new FormFactorLorentz(m_height, m_width); - return p_clone; + FormFactorLorentz *result = new FormFactorLorentz(m_height, m_width); + result->setName(getName()); + return result; } complex_t FormFactorLorentz::evaluate_for_q(const cvector_t& q) const diff --git a/Core/FormFactors/src/FormFactorParallelepiped.cpp b/Core/FormFactors/src/FormFactorParallelepiped.cpp index 4d7d4d16101..88aad45364b 100644 --- a/Core/FormFactors/src/FormFactorParallelepiped.cpp +++ b/Core/FormFactors/src/FormFactorParallelepiped.cpp @@ -20,13 +20,16 @@ FormFactorParallelepiped::FormFactorParallelepiped(double height, double radius) : m_height(height) , m_radius(radius) { + setName("FormFactorParallelepiped"); + init_parameters(); } FormFactorParallelepiped* FormFactorParallelepiped::clone() const { - FormFactorParallelepiped *p_clone = + FormFactorParallelepiped *result = new FormFactorParallelepiped(m_height, m_radius); - return p_clone; + result->setName(getName()); + return result; } complex_t FormFactorParallelepiped::evaluate_for_q(const cvector_t& q) const diff --git a/Core/FormFactors/src/FormFactorPrism3.cpp b/Core/FormFactors/src/FormFactorPrism3.cpp index 10a68c9b8fe..f3ad7bd6570 100644 --- a/Core/FormFactors/src/FormFactorPrism3.cpp +++ b/Core/FormFactors/src/FormFactorPrism3.cpp @@ -36,8 +36,9 @@ void FormFactorPrism3::init_parameters() FormFactorPrism3* FormFactorPrism3::clone() const { - FormFactorPrism3 *p_clone = new FormFactorPrism3(m_height, m_half_side ); - return p_clone; + FormFactorPrism3 *result = new FormFactorPrism3(m_height, m_half_side ); + result->setName(getName()); + return result; } complex_t FormFactorPrism3::evaluate_for_q(const cvector_t& q) const diff --git a/Core/FormFactors/src/FormFactorPrism6.cpp b/Core/FormFactors/src/FormFactorPrism6.cpp index 349ec977d7d..b9caa360bfa 100644 --- a/Core/FormFactors/src/FormFactorPrism6.cpp +++ b/Core/FormFactors/src/FormFactorPrism6.cpp @@ -36,7 +36,9 @@ void FormFactorPrism6::init_parameters() FormFactorPrism6* FormFactorPrism6::clone() const { - return new FormFactorPrism6(m_height, m_half_side); + FormFactorPrism6 *result = new FormFactorPrism6(m_height, m_half_side); + result->setName(getName()); + return result; } complex_t FormFactorPrism6::evaluate_for_q(const cvector_t& q) const diff --git a/Core/FormFactors/src/FormFactorPyramid.cpp b/Core/FormFactors/src/FormFactorPyramid.cpp index 67551f070b4..3a41b40d383 100644 --- a/Core/FormFactors/src/FormFactorPyramid.cpp +++ b/Core/FormFactors/src/FormFactorPyramid.cpp @@ -37,9 +37,10 @@ void FormFactorPyramid::init_parameters() FormFactorPyramid* FormFactorPyramid::clone() const { - FormFactorPyramid *p_clone = + FormFactorPyramid *result = new FormFactorPyramid(m_height, m_half_side, m_alpha); - return p_clone; + result->setName(getName()); + return result; } complex_t FormFactorPyramid::evaluate_for_q(const cvector_t& q) const diff --git a/Core/FormFactors/src/FormFactorSphere.cpp b/Core/FormFactors/src/FormFactorSphere.cpp index 1c42f88d363..01e2481aae3 100644 --- a/Core/FormFactors/src/FormFactorSphere.cpp +++ b/Core/FormFactors/src/FormFactorSphere.cpp @@ -42,6 +42,14 @@ void FormFactorSphere::init_parameters() registerParameter("height", &m_height); } +FormFactorSphere *FormFactorSphere::clone() const +{ + FormFactorSphere *result = new FormFactorSphere(m_radius, m_height); + result->setName(getName()); + return result; +} + + //! Integrand for complex formfactor. complex_t FormFactorSphere::Integrand(double Z, void* params) const diff --git a/Core/FormFactors/src/FormFactorTethraedron.cpp b/Core/FormFactors/src/FormFactorTethraedron.cpp index 975ad7230c6..15d0274743b 100644 --- a/Core/FormFactors/src/FormFactorTethraedron.cpp +++ b/Core/FormFactors/src/FormFactorTethraedron.cpp @@ -38,9 +38,10 @@ void FormFactorTethraedron::init_parameters() FormFactorTethraedron* FormFactorTethraedron::clone() const { - FormFactorTethraedron *p_clone = + FormFactorTethraedron *result = new FormFactorTethraedron(m_height, m_half_side, m_alpha); - return p_clone; + result->setName(getName()); + return result; } complex_t FormFactorTethraedron::evaluate_for_q(const cvector_t& q) const diff --git a/Core/FormFactors/src/FormFactorWeighted.cpp b/Core/FormFactors/src/FormFactorWeighted.cpp index 76ba87fb720..367665a22cc 100644 --- a/Core/FormFactors/src/FormFactorWeighted.cpp +++ b/Core/FormFactors/src/FormFactorWeighted.cpp @@ -29,11 +29,12 @@ FormFactorWeighted::~FormFactorWeighted() FormFactorWeighted* FormFactorWeighted::clone() const { - FormFactorWeighted *p_new = new FormFactorWeighted(); + FormFactorWeighted *result = new FormFactorWeighted(); for (size_t index=0; index<m_form_factors.size(); ++index) { - p_new->addFormFactor(*m_form_factors[index], m_weights[index]); + result->addFormFactor(*m_form_factors[index], m_weights[index]); } - return p_new; + result->setName(getName()); + return result; } void FormFactorWeighted::addFormFactor(const IFormFactor& form_factor, diff --git a/Core/Samples/inc/Particle.h b/Core/Samples/inc/Particle.h index f26e04735d7..eaea4c7ec0e 100644 --- a/Core/Samples/inc/Particle.h +++ b/Core/Samples/inc/Particle.h @@ -44,13 +44,7 @@ class BA_CORE_API_ Particle : public ICompositeSample m_ambient_refractive_index = refractive_index; } - virtual IFormFactor* createFormFactor() const - { - FormFactorDecoratorRefractiveIndex *p_ff = new FormFactorDecoratorRefractiveIndex( - mp_form_factor->clone(), getRefractiveIndex()); - p_ff->setAmbientRefractiveIndex(m_ambient_refractive_index); - return p_ff; - } + virtual IFormFactor* createFormFactor() const; //! Sets the form factor of the particle (not including scattering factor from refractive index) virtual void setSimpleFormFactor(IFormFactor* p_form_factor) @@ -95,6 +89,16 @@ class BA_CORE_API_ Particle : public ICompositeSample //!< pointer to the form factor }; +inline IFormFactor* Particle::createFormFactor() const +{ + if(!mp_form_factor) return 0; + FormFactorDecoratorRefractiveIndex *p_ff = new FormFactorDecoratorRefractiveIndex( + mp_form_factor->clone(), getRefractiveIndex()); + p_ff->setAmbientRefractiveIndex(m_ambient_refractive_index); + return p_ff; +} + + inline complex_t Particle::getRefractiveIndex() const { const HomogeneousMaterial *material = dynamic_cast<const HomogeneousMaterial *>(m_material); diff --git a/Core/Samples/src/Particle.cpp b/Core/Samples/src/Particle.cpp index 60bac234347..5fb19c232ed 100644 --- a/Core/Samples/src/Particle.cpp +++ b/Core/Samples/src/Particle.cpp @@ -52,15 +52,21 @@ Particle::~Particle() Particle* Particle::clone() const { - IFormFactor *p_form_factor = mp_form_factor->clone(); + IFormFactor *p_form_factor(0); + if(mp_form_factor) p_form_factor = mp_form_factor->clone(); + Particle *p_new = new Particle(m_material, p_form_factor); p_new->setAmbientRefractiveIndex(m_ambient_refractive_index); + + p_new->setName(getName()); return p_new; } std::vector<ParticleInfo*> Particle::createDistributedParticles( size_t samples_per_particle, double factor) const { + if(!mp_form_factor) throw NullPointerException("Particle::createDistributedParticles() -> No formfactor is defined."); + std::vector<ParticleInfo*> result; if (mp_form_factor->isDistributedFormFactor()) { std::vector<IFormFactor *> form_factors; diff --git a/Tests/UnitTests/TestCore/LayerTest.h b/Tests/UnitTests/TestCore/LayerTest.h index af5d5004bf7..2873c1cda0d 100644 --- a/Tests/UnitTests/TestCore/LayerTest.h +++ b/Tests/UnitTests/TestCore/LayerTest.h @@ -20,7 +20,6 @@ class LayerTest : public ::testing::Test TEST_F(LayerTest, LayerInitialState) { Layer layer; - EXPECT_EQ(NULL, layer.getMaterial()); EXPECT_EQ(NULL, layer.getDecoration()); EXPECT_EQ(0, layer.getThickness()); @@ -32,7 +31,6 @@ TEST_F(LayerTest, LayerInitialState) EXPECT_EQ(NULL, layer.createDiffuseDWBASimulation()); Layer *new_layer = layer.clone(); - EXPECT_EQ(NULL, new_layer->getMaterial()); EXPECT_EQ(NULL, new_layer->getDecoration()); EXPECT_EQ(0, new_layer->getThickness()); diff --git a/Tests/UnitTests/TestCore/ParticleTest.h b/Tests/UnitTests/TestCore/ParticleTest.h index 65ff942e0f2..9b78fb93eed 100644 --- a/Tests/UnitTests/TestCore/ParticleTest.h +++ b/Tests/UnitTests/TestCore/ParticleTest.h @@ -3,6 +3,10 @@ #include "Particle.h" #include "Units.h" +#include "HomogeneousMaterial.h" +#include "ParticleInfo.h" +#include "FormFactorFullSphere.h" +#include <iostream> class ParticleTest : public ::testing::Test { @@ -13,16 +17,62 @@ class ParticleTest : public ::testing::Test }; - TEST_F(ParticleTest, ParticleInitialState) { Particle particle; - EXPECT_EQ(NULL, particle.getMaterial()); EXPECT_EQ(complex_t(0,0), particle.getRefractiveIndex()); EXPECT_EQ(NULL, particle.getSimpleFormFactor()); EXPECT_FALSE(particle.hasDistributedFormFactor()); + EXPECT_EQ(NULL, particle.createFormFactor()); + ASSERT_THROW(particle.createDistributedParticles(0,0).size(), NullPointerException); + EXPECT_EQ("Particle", particle.getName()); + + Particle *particle2 = particle.clone(); + EXPECT_EQ(NULL, particle2->getMaterial()); + EXPECT_EQ(complex_t(0,0), particle2->getRefractiveIndex()); + EXPECT_EQ(NULL, particle2->getSimpleFormFactor()); + EXPECT_FALSE(particle2->hasDistributedFormFactor()); + EXPECT_EQ(NULL, particle2->createFormFactor()); + ASSERT_THROW(particle2->createDistributedParticles(0,0).size(), NullPointerException); + EXPECT_EQ("Particle", particle2->getName()); + delete particle2; +} + + +TEST_F(ParticleTest, ParticleConstructors) +{ + const IMaterial *mat = MaterialManager::getHomogeneousMaterial("Air",0,0); + + Particle *p1 = new Particle(mat); + EXPECT_EQ("Air", p1->getMaterial()->getName()); + EXPECT_EQ(complex_t(1,0), p1->getRefractiveIndex()); + EXPECT_EQ(NULL, p1->getSimpleFormFactor()); + EXPECT_FALSE(p1->hasDistributedFormFactor()); + EXPECT_EQ(NULL, p1->createFormFactor()); + ASSERT_THROW(p1->createDistributedParticles(0,0).size(), NullPointerException); + delete p1; + + FormFactorFullSphere sphere(1.0); + Particle *p2 = new Particle(mat, sphere); + EXPECT_EQ("FormFactorFullSphere", p2->getSimpleFormFactor()->getName()); + EXPECT_EQ(1, p2->getSimpleFormFactor()->getRadius()); + EXPECT_FALSE(p2->hasDistributedFormFactor()); + EXPECT_TRUE(dynamic_cast<FormFactorDecoratorRefractiveIndex *>(p2->createFormFactor())); + EXPECT_EQ(complex_t(1,0), + dynamic_cast<FormFactorDecoratorRefractiveIndex *>(p2->createFormFactor())->getAmbientRefractiveIndex()); + delete p2; + + FormFactorFullSphere *sphere3 = new FormFactorFullSphere(1.0); + sphere3->setName("sphere3"); + Particle *p3 = new Particle(mat, sphere3); + EXPECT_EQ(sphere3, p3->getSimpleFormFactor()); + + Particle *p4 = p3->clone(); + EXPECT_EQ("sphere3", p4->getSimpleFormFactor()->getName()); + delete p3; + delete p4; } -- GitLab