BornAgain  1.19.79
Simulate and fit neutron and x-ray scattering at grazing incidence
RealSpaceMesoCrystal Class Reference

Description

Definition at line 28 of file RealSpaceMesoCrystalUtils.h.

Collaboration diagram for RealSpaceMesoCrystal:
[legend]

Public Member Functions

 RealSpaceMesoCrystal (const MesoCrystalItem *mesoCrystalItem, double total_abundance, const QVector3D &origin, std::function< QColor(const QString &)> fnColorFromMaterialName)
 
 ~RealSpaceMesoCrystal ()=default
 
Particle3DContainer populateMesoCrystal ()
 

Private Attributes

std::unique_ptr< GUI::RealSpace::BuilderUtilsm_builderUtils
 
const MesoCrystalItemm_mesoCrystalItem
 
QVector3D m_origin
 
double m_total_abundance
 

Constructor & Destructor Documentation

◆ ~RealSpaceMesoCrystal()

RealSpaceMesoCrystal::~RealSpaceMesoCrystal ( )
default

◆ RealSpaceMesoCrystal()

RealSpaceMesoCrystal::RealSpaceMesoCrystal ( const MesoCrystalItem mesoCrystalItem,
double  total_abundance,
const QVector3D &  origin,
std::function< QColor(const QString &)>  fnColorFromMaterialName 
)

Definition at line 363 of file RealSpaceMesoCrystalUtils.cpp.

366 {
367  m_mesoCrystalItem = mesoCrystalItem;
368  m_total_abundance = total_abundance;
369  m_origin = origin;
370  m_builderUtils = std::make_unique<GUI::RealSpace::BuilderUtils>(fnColorFromMaterialName);
371 }
std::unique_ptr< GUI::RealSpace::BuilderUtils > m_builderUtils
const MesoCrystalItem * m_mesoCrystalItem

References m_builderUtils, m_mesoCrystalItem, m_origin, and m_total_abundance.

Member Function Documentation

◆ populateMesoCrystal()

Particle3DContainer RealSpaceMesoCrystal::populateMesoCrystal ( )

Definition at line 373 of file RealSpaceMesoCrystalUtils.cpp.

374 {
375  auto mesoCrystal = m_mesoCrystalItem->createMesoCrystal();
376 
377  std::unique_ptr<MesoCrystal> M_clone(mesoCrystal->clone()); // clone of the mesoCrystal
378 
379  // These methods DO NOT add rotation/translation of the mesoCrystal to its children
380  // and hence they need to be added manually
381  auto lattice = m_mesoCrystalItem->getLattice();
382  auto particleBasis = m_mesoCrystalItem->getBasis();
383  auto outerShapeff = m_mesoCrystalItem->getOuterShape();
384 
385  const auto* mesoCrystal_rotation = M_clone->rotation();
386  auto mesoCrystal_translation = M_clone->particlePosition();
387 
388  Particle3DContainer mesoCrystalBasis3DContainer;
389 
390  if (dynamic_cast<const ParticleComposition*>(particleBasis.get())) {
391  const auto* particleComposition =
392  dynamic_cast<const ParticleComposition*>(particleBasis.get());
393  mesoCrystalBasis3DContainer =
394  m_builderUtils->particleComposition3DContainer(*particleComposition, 1.0, m_origin);
395  } else if (dynamic_cast<const ParticleCoreShell*>(particleBasis.get())) {
396  const auto* particleCoreShell = dynamic_cast<const ParticleCoreShell*>(particleBasis.get());
397  mesoCrystalBasis3DContainer =
398  m_builderUtils->particleCoreShell3DContainer(*particleCoreShell, 1.0, m_origin);
399  } else if (dynamic_cast<const MesoCrystal*>(particleBasis.get())) {
400  // TODO: Implement method to populate MesoCrystal from CORE and NOT from MesoCrystalItem
401  // as it is done currently in GUI::RealSpace::BuilderUtils::mesoCrystal3DContainer
402  std::ostringstream ostr;
403  ostr << "Sorry, MesoCrystal inside MesoCrystal not yet implemented";
404  ostr << "\n\nStay tuned!";
405  throw std::runtime_error(ostr.str());
406  } else {
407  const auto* particle = dynamic_cast<const Particle*>(particleBasis.get());
408  mesoCrystalBasis3DContainer =
409  m_builderUtils->singleParticle3DContainer(*particle, 1.0, m_origin);
410  }
411 
412  Particle3DContainer mesoCrystal3DContainer;
413 
414  for (int k = -n; k <= n; k++) {
415  for (int j = -n; j <= n; j++) {
416  for (int i = -n; i <= n; i++) {
417  auto positionInside = i * lattice.basisVectorA() + j * lattice.basisVectorB()
418  + k * lattice.basisVectorC();
419 
420  if (isPositionInsideMesoCrystal(outerShapeff.get(), positionInside)) {
421  for (size_t it = 0; it < mesoCrystalBasis3DContainer.containerSize(); ++it) {
422  auto particle3D = mesoCrystalBasis3DContainer.createParticle(it);
423  particle3D->addTranslation(
424  QVector3D(static_cast<float>(positionInside.x()),
425  static_cast<float>(positionInside.y()),
426  static_cast<float>(positionInside.z())));
427 
428  particle3D->addExtrinsicRotation(
429  m_builderUtils->implementParticleRotationfromIRotation(
430  mesoCrystal_rotation));
431 
432  particle3D->addTranslation(
433  QVector3D(static_cast<float>(mesoCrystal_translation.x()),
434  static_cast<float>(mesoCrystal_translation.y()),
435  static_cast<float>(mesoCrystal_translation.z())));
436 
437  mesoCrystal3DContainer.addParticle(
438  particle3D.release(), mesoCrystalBasis3DContainer.particle3DBlend(it));
439  }
440  }
441  }
442  }
443  }
444 
445  // Add outer shape for visualization
446  auto outerShape3D = GUI::View::TransformTo3D::createParticlefromFormfactor(outerShapeff.get());
447  outerShape3D->addTransform(
448  m_builderUtils->implementParticleRotationfromIRotation(mesoCrystal_rotation),
449  QVector3D(static_cast<float>(mesoCrystal_translation.x()),
450  static_cast<float>(mesoCrystal_translation.y()),
451  static_cast<float>(mesoCrystal_translation.z())));
452 
453  // assign grey (default) color to the outer shape
454  QColor color = {};
455  color.setAlphaF(0.3);
456  outerShape3D->color = color;
457  mesoCrystal3DContainer.addParticle(outerShape3D.release(), true);
458 
459  // set the correct abundance for the MesoCrystal
460  mesoCrystal3DContainer.setCumulativeAbundance(M_clone->abundance() / m_total_abundance);
461  mesoCrystal3DContainer.setParticleType("MesoCrystal");
462 
463  return mesoCrystal3DContainer;
464 }
std::unique_ptr< IFormFactor > getOuterShape() const
std::unique_ptr< MesoCrystal > createMesoCrystal() const
std::unique_ptr< IParticle > getBasis() const
Lattice3D getLattice() const
std::unique_ptr< GUI::RealSpace::Particles::Particle > createParticle(const size_t &index) const
void setCumulativeAbundance(double cumulativeAbundance)
void addParticle(GUI::RealSpace::Particles::Particle *particle3D, bool blend)
size_t containerSize() const
void setParticleType(QString particleType)
bool particle3DBlend(const size_t &index) const
std::unique_ptr< GUI::RealSpace::Particles::Particle > createParticlefromFormfactor(const IFormFactor *ff)

References Particle3DContainer::addParticle(), Particle3DContainer::containerSize(), MesoCrystalItem::createMesoCrystal(), Particle3DContainer::createParticle(), GUI::View::TransformTo3D::createParticlefromFormfactor(), MesoCrystalItem::getBasis(), MesoCrystalItem::getLattice(), MesoCrystalItem::getOuterShape(), m_builderUtils, m_mesoCrystalItem, m_origin, m_total_abundance, Particle3DContainer::particle3DBlend(), Particle3DContainer::setCumulativeAbundance(), and Particle3DContainer::setParticleType().

Referenced by GUI::RealSpace::BuilderUtils::mesoCrystal3DContainer().

Here is the call graph for this function:

Member Data Documentation

◆ m_builderUtils

std::unique_ptr<GUI::RealSpace::BuilderUtils> RealSpaceMesoCrystal::m_builderUtils
private

Definition at line 42 of file RealSpaceMesoCrystalUtils.h.

Referenced by RealSpaceMesoCrystal(), and populateMesoCrystal().

◆ m_mesoCrystalItem

const MesoCrystalItem* RealSpaceMesoCrystal::m_mesoCrystalItem
private

Definition at line 39 of file RealSpaceMesoCrystalUtils.h.

Referenced by RealSpaceMesoCrystal(), and populateMesoCrystal().

◆ m_origin

QVector3D RealSpaceMesoCrystal::m_origin
private

Definition at line 41 of file RealSpaceMesoCrystalUtils.h.

Referenced by RealSpaceMesoCrystal(), and populateMesoCrystal().

◆ m_total_abundance

double RealSpaceMesoCrystal::m_total_abundance
private

Definition at line 40 of file RealSpaceMesoCrystalUtils.h.

Referenced by RealSpaceMesoCrystal(), and populateMesoCrystal().


The documentation for this class was generated from the following files: