Skip to content
Snippets Groups Projects
Commit c6794638 authored by Van Herck, Walter's avatar Van Herck, Walter
Browse files

Refactor: internally store material pointers in...

Refactor: internally store material pointers in FormFactorDecoratorScalarMaterial instead of the refractive indices
parent 45d8dad4
No related branches found
No related tags found
No related merge requests found
......@@ -34,26 +34,30 @@ class FormFactorDecoratorScalarMaterial : public FormFactorDecoratorFactor
//! Sets the material of the scatterer
void setMaterial(const IMaterial *p_material);
//! Retrieves the refractive index of the ambient material
virtual complex_t getAmbientRefractiveIndex() const {
return m_refractive_index;
if (mp_ambient_material) {
return mp_ambient_material->getRefractiveIndex();
}
return 1.0;
}
//! Sets the ambient material
virtual void setAmbientMaterial(const IMaterial *p_material);
private:
complex_t getRefractiveIndexFactor(const complex_t& ambient_index,
const complex_t& particle_index) const;
complex_t getRefractiveIndexFactor() const;
complex_t m_refractive_index;
complex_t m_ambient_refractive_index;
complex_t m_wavevector_scattering_factor;
const IMaterial *mp_material;
const IMaterial *mp_ambient_material;
};
inline FormFactorDecoratorScalarMaterial::FormFactorDecoratorScalarMaterial(
IFormFactor* p_form_factor, complex_t wavevector_scattering_factor)
: FormFactorDecoratorFactor(p_form_factor, 1.0)
, m_refractive_index(1.0)
, m_ambient_refractive_index(1.0)
, m_wavevector_scattering_factor(wavevector_scattering_factor)
, mp_material(0)
, mp_ambient_material(0)
{
setName("FormFactorDecoratorScalarMaterial");
}
......@@ -68,9 +72,8 @@ FormFactorDecoratorScalarMaterial::clone() const
FormFactorDecoratorScalarMaterial *result =
new FormFactorDecoratorScalarMaterial(mp_form_factor->clone(),
m_wavevector_scattering_factor);
result->m_refractive_index = m_refractive_index;
result->m_ambient_refractive_index = m_ambient_refractive_index;
result->m_factor = m_factor;
result->setMaterial(mp_material);
result->setAmbientMaterial(mp_ambient_material);
result->setName(getName());
return result;
}
......@@ -79,27 +82,30 @@ inline void FormFactorDecoratorScalarMaterial::setMaterial(
const IMaterial* p_material)
{
if (p_material) {
m_refractive_index = p_material->getRefractiveIndex();
mp_material = p_material;
}
m_factor = getRefractiveIndexFactor(m_ambient_refractive_index,
m_refractive_index);
m_factor = getRefractiveIndexFactor();
}
inline void FormFactorDecoratorScalarMaterial::setAmbientMaterial(
const IMaterial *p_material)
{
if (p_material) {
m_ambient_refractive_index = p_material->getRefractiveIndex();
mp_ambient_material = p_material;
}
m_factor = getRefractiveIndexFactor(m_ambient_refractive_index,
m_refractive_index);
m_factor = getRefractiveIndexFactor();
}
inline complex_t FormFactorDecoratorScalarMaterial::getRefractiveIndexFactor(
const complex_t& ambient_index, const complex_t& particle_index) const
inline complex_t
FormFactorDecoratorScalarMaterial::getRefractiveIndexFactor() const
{
return m_wavevector_scattering_factor *
(particle_index*particle_index - ambient_index*ambient_index);
if (mp_material && mp_ambient_material) {
complex_t particle_index = mp_material->getRefractiveIndex();
complex_t ambient_index = mp_ambient_material->getRefractiveIndex();
return m_wavevector_scattering_factor *
(particle_index*particle_index - ambient_index*ambient_index);
}
else return m_wavevector_scattering_factor;
}
#endif /* FORMFACTORDECORATORSCALARMATERIAL_H_ */
......
......@@ -63,10 +63,6 @@ class BA_CORE_API_ Particle : public ICompositeSample
virtual FormFactorPol* createFormFactorMatrix(
complex_t wavevector_scattering_factor) const;
//! Sets the form factor of the particle (not including scattering factor
//! from refractive index)
virtual void setSimpleFormFactor(IFormFactor* p_form_factor);
//! Sets _material_ and _thickness_.
virtual void setMaterial(const IMaterial* p_material) {
mp_material = p_material;
......@@ -96,6 +92,10 @@ class BA_CORE_API_ Particle : public ICompositeSample
return mp_form_factor;
}
//! Sets the form factor of the particle (not including scattering factor
//! from refractive index)
virtual void setSimpleFormFactor(IFormFactor* p_form_factor);
//! Creates list of contained particles for diffuse calculations
virtual std::vector<DiffuseParticleInfo *> *createDiffuseParticleInfo(
const ParticleInfo& parent_info) const;
......
......@@ -99,29 +99,6 @@ Particle* Particle::cloneInvertB() const
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;
std::vector<double> probabilities;
mp_form_factor->createDistributedFormFactors(form_factors, probabilities, samples_per_particle);
if (form_factors.size() > 0 && form_factors.size()==probabilities.size()) {
for (size_t i=0; i<form_factors.size(); ++i) {
Particle *new_particle = clone();
new_particle->setSimpleFormFactor(form_factors[i]);
ParticleInfo *p_info =
new ParticleInfo(new_particle, 0., probabilities[i]*factor);
result.push_back(p_info);
}
}
}
return result;
}
IFormFactor* Particle::createFormFactor(
complex_t wavevector_scattering_factor) const
{
......@@ -152,6 +129,29 @@ FormFactorPol* Particle::createFormFactorMatrix(
return p_ff;
}
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;
std::vector<double> probabilities;
mp_form_factor->createDistributedFormFactors(form_factors, probabilities, samples_per_particle);
if (form_factors.size() > 0 && form_factors.size()==probabilities.size()) {
for (size_t i=0; i<form_factors.size(); ++i) {
Particle *new_particle = clone();
new_particle->setSimpleFormFactor(form_factors[i]);
ParticleInfo *p_info =
new ParticleInfo(new_particle, 0., probabilities[i]*factor);
result.push_back(p_info);
}
}
}
return result;
}
void Particle::setSimpleFormFactor(IFormFactor* p_form_factor)
{
if (!p_form_factor) return;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment