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

Description

Definition at line 37 of file RealSpaceBuilder.h.

Collaboration diagram for RealSpaceBuilder:
[legend]

Public Types

using ItemForRealSpace = std::variant< MultiLayerItem *, LayerItem *, ParticleLayoutItem *, ItemWithParticles * >
 Defines the item types this class can handle. More...
 

Public Member Functions

 RealSpaceBuilder (std::function< QColor(const QString &)> fnColorFromMaterialName)
 
void populate (RealSpace::Model *model, ItemForRealSpace item, const SceneGeometry &sceneGeometry, const RealSpace::Camera::Position &cameraPosition=RealSpace::Camera::Position(RealSpace::Vector3D(0, -200, 120), RealSpace::Vector3D(0, 0, 0), RealSpace::Vector3D::_z)) const
 
void populateParticleFromParticle3DContainer (RealSpace::Model *model, const Particle3DContainer &particle3DContainer, const QVector3D &lattice_position={}) const
 

Private Member Functions

void populateLayer (RealSpace::Model *model, const LayerItem &layerItem, const SceneGeometry &sceneGeometry, const QVector3D &origin={}, bool isTopLayer=false) const
 
void populateLayout (RealSpace::Model *model, const ParticleLayoutItem &layoutItem, const SceneGeometry &sceneGeometry, const QVector3D &origin={}) const
 
void populateMultiLayer (RealSpace::Model *model, const MultiLayerItem &mlayerItem, const SceneGeometry &sceneGeometry, const QVector3D &origin={}) const
 
void populateParticleFromParticleItem (RealSpace::Model *model, const ItemWithParticles &particleItem) const
 

Private Attributes

std::unique_ptr< RealSpace::BuilderUtilsm_builderUtils
 

Member Typedef Documentation

◆ ItemForRealSpace

Defines the item types this class can handle.

Definition at line 41 of file RealSpaceBuilder.h.

Constructor & Destructor Documentation

◆ RealSpaceBuilder()

RealSpaceBuilder::RealSpaceBuilder ( std::function< QColor(const QString &)>  fnColorFromMaterialName)

Definition at line 66 of file RealSpaceBuilder.cpp.

67 {
68  m_builderUtils = std::make_unique<RealSpace::BuilderUtils>(fnColorFromMaterialName);
69 }
std::unique_ptr< RealSpace::BuilderUtils > m_builderUtils

References m_builderUtils.

Member Function Documentation

◆ populate()

void RealSpaceBuilder::populate ( RealSpace::Model model,
ItemForRealSpace  item,
const SceneGeometry sceneGeometry,
const RealSpace::Camera::Position cameraPosition = RealSpace::Camera::Position(RealSpace::Vector3D(0, -200, 120),                                                   RealSpace::Vector3D(0, 0, 0),                                                        RealSpace::Vector3D::_z) 
) const

Definition at line 71 of file RealSpaceBuilder.cpp.

74 {
75  // default value of cameraPosition is in RealSpaceBuilder.h
76  model->defCamPos = cameraPosition;
77 
78  if (const auto* p = std::get_if<MultiLayerItem*>(&item))
79  populateMultiLayer(model, **p, sceneGeometry);
80  else if (const auto* p = std::get_if<LayerItem*>(&item))
81  populateLayer(model, **p, sceneGeometry);
82  else if (const auto* p = std::get_if<ParticleLayoutItem*>(&item))
83  populateLayout(model, **p, sceneGeometry);
84  else if (const auto* p = std::get_if<ItemWithParticles*>(&item))
86 }
Camera::Position defCamPos
default camera params
Definition: model.h:52
void populateLayer(RealSpace::Model *model, const LayerItem &layerItem, const SceneGeometry &sceneGeometry, const QVector3D &origin={}, bool isTopLayer=false) const
void populateParticleFromParticleItem(RealSpace::Model *model, const ItemWithParticles &particleItem) const
void populateMultiLayer(RealSpace::Model *model, const MultiLayerItem &mlayerItem, const SceneGeometry &sceneGeometry, const QVector3D &origin={}) const
void populateLayout(RealSpace::Model *model, const ParticleLayoutItem &layoutItem, const SceneGeometry &sceneGeometry, const QVector3D &origin={}) const

References GUI::RealSpace::Model::defCamPos, populateLayer(), populateLayout(), populateMultiLayer(), and populateParticleFromParticleItem().

Referenced by RealSpaceCanvas::updateScene().

Here is the call graph for this function:

◆ populateLayer()

void RealSpaceBuilder::populateLayer ( RealSpace::Model model,
const LayerItem layerItem,
const SceneGeometry sceneGeometry,
const QVector3D &  origin = {},
bool  isTopLayer = false 
) const
private

Definition at line 107 of file RealSpaceBuilder.cpp.

110 {
111  auto layer = GUI::View::TransformTo3D::createLayer(layerItem, sceneGeometry, origin);
112  if (layer && !isTopLayer)
113  model->addBlend(layer.release());
114 
115  for (ParticleLayoutItem* layout : layerItem.layouts())
116  populateLayout(model, *layout, sceneGeometry, origin);
117 }
void addBlend(Object *)
add a transparent object, the model takes ownership
Definition: model.cpp:136
QVector< ParticleLayoutItem * > layouts() const
Definition: LayerItem.cpp:136
std::unique_ptr< GUI::RealSpace::Layer > createLayer(const LayerItem &layerItem, const SceneGeometry &sceneGeometry, const QVector3D &origin={})

References GUI::RealSpace::Model::addBlend(), GUI::View::TransformTo3D::createLayer(), LayerItem::layouts(), and populateLayout().

Referenced by populate(), and populateMultiLayer().

Here is the call graph for this function:

◆ populateLayout()

void RealSpaceBuilder::populateLayout ( RealSpace::Model model,
const ParticleLayoutItem layoutItem,
const SceneGeometry sceneGeometry,
const QVector3D &  origin = {} 
) const
private

Definition at line 119 of file RealSpaceBuilder.cpp.

123 {
124  // If there is no particle to populate
125  if (layoutItem.particles().empty())
126  return;
127 
128  double layer_size = sceneGeometry.layerSize;
129  double total_density = layoutItem.totalDensity();
130 
131  auto particle3DContainer_vector = m_builderUtils->particle3DContainerVector(layoutItem, origin);
132 
133  const auto latticePositions = generatePositions(layoutItem, layer_size, total_density);
134  m_builderUtils->populateParticlesAtLatticePositions(
135  latticePositions, particle3DContainer_vector, model, sceneGeometry, this);
136 }
DoubleDescriptor totalDensity() const
The real density.
QVector< ItemWithParticles * > particles() const
The particles this layout contains.
std::vector< std::vector< double > > latticePositions(const Interference2DParaCrystal *, double layer_size)

References GUI::RealSpace::Paracrystal2D::latticePositions(), SceneGeometry::layerSize, m_builderUtils, ParticleLayoutItem::particles(), and ParticleLayoutItem::totalDensity().

Referenced by populate(), and populateLayer().

Here is the call graph for this function:

◆ populateMultiLayer()

void RealSpaceBuilder::populateMultiLayer ( RealSpace::Model model,
const MultiLayerItem mlayerItem,
const SceneGeometry sceneGeometry,
const QVector3D &  origin = {} 
) const
private

Definition at line 88 of file RealSpaceBuilder.cpp.

92 {
93  double total_height(0.0);
94  int index(0);
95  for (LayerItem* layer : mlayerItem.layers()) {
96  bool isTopLayer = index == 0;
97  populateLayer(model, *layer, sceneGeometry,
98  QVector3D(0, 0, static_cast<float>(-total_height)), isTopLayer);
99 
100  if (index != 0)
101  total_height += GUI::View::TransformTo3D::visualLayerThickness(*layer, sceneGeometry);
102 
103  ++index;
104  }
105 }
QVector< LayerItem * > layers() const
double visualLayerThickness(const LayerItem &layerItem, const SceneGeometry &sceneGeometry)

References MultiLayerItem::layers(), populateLayer(), and GUI::View::TransformTo3D::visualLayerThickness().

Referenced by populate().

Here is the call graph for this function:

◆ populateParticleFromParticle3DContainer()

void RealSpaceBuilder::populateParticleFromParticle3DContainer ( RealSpace::Model model,
const Particle3DContainer particle3DContainer,
const QVector3D &  lattice_position = {} 
) const

Definition at line 169 of file RealSpaceBuilder.cpp.

172 {
173  if (particle3DContainer.containerSize()) {
174  for (size_t i = 0; i < particle3DContainer.containerSize(); ++i) {
175  auto particle3D = particle3DContainer.createParticle(i);
176  particle3D->addTranslation(lattice_position);
177  if (particle3D) {
178  if (!particle3DContainer.particle3DBlend(i))
179  model->add(particle3D.release());
180  else
181  model->addBlend(particle3D.release()); // use addBlend() for transparent object
182  }
183  }
184  }
185 }
void add(Object *)
add an opaque object, the model takes ownership
Definition: model.cpp:128
std::unique_ptr< GUI::RealSpace::Particles::Particle > createParticle(const size_t &index) const
size_t containerSize() const
bool particle3DBlend(const size_t &index) const

References GUI::RealSpace::Model::add(), GUI::RealSpace::Model::addBlend(), Particle3DContainer::containerSize(), Particle3DContainer::createParticle(), and Particle3DContainer::particle3DBlend().

Referenced by populateParticleFromParticleItem(), and GUI::RealSpace::BuilderUtils::populateParticlesAtLatticePositions().

Here is the call graph for this function:

◆ populateParticleFromParticleItem()

void RealSpaceBuilder::populateParticleFromParticleItem ( RealSpace::Model model,
const ItemWithParticles particleItem 
) const
private

Definition at line 138 of file RealSpaceBuilder.cpp.

140 {
141  Particle3DContainer particle3DContainer;
142  if (const auto* pItem = dynamic_cast<const ParticleItem*>(&particleItem)) {
143  auto particle = pItem->createParticle();
144  particle3DContainer = m_builderUtils->singleParticle3DContainer(*particle);
145  } else if (const auto* particleCoreShellItem =
146  dynamic_cast<const ParticleCoreShellItem*>(&particleItem)) {
147  // If there is no CORE or SHELL to populate inside ParticleCoreShellItem
148  if (!particleCoreShellItem->core() || !particleCoreShellItem->shell())
149  return;
150  auto particleCoreShell = particleCoreShellItem->createParticleCoreShell();
151  particle3DContainer = m_builderUtils->particleCoreShell3DContainer(*particleCoreShell);
152  } else if (const auto* particleCompositionItem =
153  dynamic_cast<const ParticleCompositionItem*>(&particleItem)) {
154  // If there is no particle to populate inside ParticleCompositionItem
155  if (!particleCompositionItem->particles().empty())
156  return;
157  auto particleComposition = particleCompositionItem->createParticleComposition();
158  particle3DContainer = m_builderUtils->particleComposition3DContainer(*particleComposition);
159  } else if (const auto* mesoCrystalItem = dynamic_cast<const MesoCrystalItem*>(&particleItem)) {
160  // If there is no particle to populate inside MesoCrystalItem
161  if (!mesoCrystalItem->basisParticle())
162  return;
163  particle3DContainer = m_builderUtils->mesoCrystal3DContainer(*mesoCrystalItem);
164  }
165 
166  populateParticleFromParticle3DContainer(model, particle3DContainer);
167 }
void populateParticleFromParticle3DContainer(RealSpace::Model *model, const Particle3DContainer &particle3DContainer, const QVector3D &lattice_position={}) const

References Particle3DContainer::createParticle(), m_builderUtils, and populateParticleFromParticle3DContainer().

Referenced by populate().

Here is the call graph for this function:

Member Data Documentation

◆ m_builderUtils

std::unique_ptr<RealSpace::BuilderUtils> RealSpaceBuilder::m_builderUtils
private

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