47 const double layerBorderWidth = 10.0;
58 kvector_t to_kvector(
const QVector3D& origin)
60 return kvector_t(
static_cast<double>(origin.x()),
static_cast<double>(origin.y()),
61 static_cast<double>(origin.z()));
70 double total_abundance = 0.0;
71 QVector<double> cumulative_abundances;
77 cumulative_abundances.append(total_abundance);
80 return cumulative_abundances;
84 const std::vector<std::vector<double>>& lattice_positions,
85 const std::vector<Particle3DContainer>& particle3DContainer_vector,
RealSpaceModel* model,
88 double layer_size = sceneGeometry.
layer_size();
89 double layer_thickness =
92 for (std::vector<double> position : lattice_positions) {
94 double rand_num = (rand() /
static_cast<double>(RAND_MAX));
97 for (
const auto& particle3DContainer : particle3DContainer_vector) {
98 if (rand_num <= particle3DContainer.cumulativeAbundance()) {
100 double pos_x = position[0];
101 double pos_y = position[1];
104 if (std::abs(pos_x) <= layer_size - layerBorderWidth
105 && std::abs(pos_y) <= layer_size - layerBorderWidth
106 && std::abs(pos_z) <= layer_thickness) {
109 model, particle3DContainer,
110 QVector3D(
static_cast<float>(position[0]),
static_cast<float>(position[1]),
111 static_cast<float>(0)));
128 if (
auto rotX =
dynamic_cast<const RotationX*
>(rotation)) {
129 beta = rotX->getAngle();
130 }
else if (
auto rotY =
dynamic_cast<const RotationY*
>(rotation)) {
132 beta = rotY->getAngle();
134 }
else if (
auto rotZ =
dynamic_cast<const RotationZ*
>(rotation)) {
135 alpha = rotZ->getAngle();
136 }
else if (
auto rotEuler =
dynamic_cast<const RotationEuler*
>(rotation)) {
137 alpha = rotEuler->getAlpha();
138 beta = rotEuler->getBeta();
139 gamma = rotEuler->getGamma();
142 static_cast<float>(gamma));
157 float x =
static_cast<float>(particle.
position().
x());
158 float y =
static_cast<float>(particle.
position().
y());
159 float z =
static_cast<float>(particle.
position().
z());
161 y +
static_cast<float>(origin.
y()),
162 z +
static_cast<float>(origin.
z()));
176 std::unique_ptr<Particle> P_clone(particle.
clone());
182 if (rotationCoreShell)
183 P_clone->rotate(*rotationCoreShell);
185 const IRotation* rotation = P_clone->rotation();
193 P_clone->translate(positionCoreShell);
196 static_cast<float>(P_clone->position().y() + origin.
y()),
197 static_cast<float>(P_clone->position().z() + origin.
z()));
199 particle3D.
transform(particle_rotate, position);
208 QString material_name = QString::fromStdString(particle_material->
getName());
210 QColor color = materialItem->
color();
211 color.setAlphaF(alpha);
212 particle3D.
color = color;
215 std::vector<Particle3DContainer>
217 const QVector3D& origin)
219 std::vector<Particle3DContainer> particle3DContainer_vector;
223 double cumulative_abundance = 0;
229 if (particleItem->modelType() ==
"Particle") {
230 auto pItem =
dynamic_cast<const ParticleItem*
>(particleItem);
233 }
else if (particleItem->modelType() ==
"ParticleCoreShell") {
240 particle3DContainer =
242 }
else if (particleItem->modelType() ==
"ParticleComposition") {
243 auto particleCompositionItem =
249 particle3DContainer =
251 }
else if (particleItem->modelType() ==
"ParticleDistribution") {
252 auto particleDistributionItem =
258 std::vector<Particle3DContainer> pd_ContainerVector =
260 for (
size_t i = 0; i < pd_ContainerVector.size(); ++i) {
261 cumulative_abundance += pd_ContainerVector[i].cumulativeAbundance();
262 pd_ContainerVector[i].setCumulativeAbundance(cumulative_abundance);
263 particle3DContainer_vector.emplace_back(std::move(pd_ContainerVector[i]));
266 }
else if (particleItem->modelType() ==
"MesoCrystal") {
267 auto mesoCrystalItem =
dynamic_cast<const MesoCrystalItem*
>(particleItem);
272 *mesoCrystalItem, total_abundance, origin);
277 particle3DContainer_vector.emplace_back(std::move(particle3DContainer));
280 return particle3DContainer_vector;
284 double total_abundance,
285 const QVector3D& origin)
287 std::unique_ptr<Particle> P_clone(particle.
clone());
289 std::unique_ptr<const IFormFactor> particleff(P_clone->createFormFactor());
290 auto ff = getUnderlyingFormFactor(particleff.get());
306 double total_abundance,
const QVector3D& origin)
309 std::unique_ptr<ParticleCoreShell> PCS_clone(particleCoreShell.
clone());
311 std::unique_ptr<const IFormFactor> coreParticleff(
312 PCS_clone->coreParticle()->createFormFactor());
313 std::unique_ptr<const IFormFactor> shellParticleff(
314 PCS_clone->shellParticle()->createFormFactor());
316 auto coreff = getUnderlyingFormFactor(coreParticleff.get());
317 auto shellff = getUnderlyingFormFactor(shellParticleff.get());
343 const ParticleComposition& particleComposition,
double total_abundance,
const QVector3D& origin)
346 std::unique_ptr<ParticleComposition> PC_clone(particleComposition.
clone());
352 for (
const IParticle* pc_particle : pc_vector) {
358 }
else if (
dynamic_cast<const MesoCrystal*
>(pc_particle)) {
361 std::ostringstream ostr;
362 ostr <<
"Sorry, MesoCrystal inside ParticleComposition not yet implemented";
363 ostr <<
"\n\nStay tuned!";
364 throw std::runtime_error(ostr.str());
366 auto particle =
dynamic_cast<const Particle*
>(pc_particle);
370 for (
size_t i = 0; i < particle3DContainer.
containerSize(); ++i) {
384 const QVector3D& origin)
388 std::vector<Particle3DContainer> particleDistribution3DContainer_vector;
390 for (
auto pd_particle : pd_vector) {
394 particle3DContainer =
398 particle3DContainer =
400 }
else if (
dynamic_cast<const MesoCrystal*
>(pd_particle)) {
403 std::ostringstream ostr;
404 ostr <<
"Sorry, MesoCrystal inside ParticleDistribution not yet implemented";
405 ostr <<
"\n\nStay tuned!";
406 throw std::runtime_error(ostr.str());
408 auto particle =
dynamic_cast<const Particle*
>(pd_particle);
411 particleDistribution3DContainer_vector.emplace_back(std::move(particle3DContainer));
413 return particleDistribution3DContainer_vector;
418 double total_abundance,
const QVector3D& origin)
Defines InterferenceFunctionItems's classes.
Includes all interference function definitions.
Defines classes Lattice2DItems.
Defines class MaterialItem.
Defines class MaterialModel.
Defines class MesoCrystalItem.
Defines class MesoCrystal.
Defines class MultiLayerItem.
Implements namespace TransformTo3D.
Defines class ParticleCompositionItem.
Defines class ParticleCoreShellItem.
Defines ParticleCoreShell.
Defines class ParticleDistributionItem.
Defines class ParticleItem.
Defines class ParticleLayoutItem.
Defines RealSpaceBuilderUtils namespace.
Defines class RealSpaceBuilder.
Defines class RealSpaceCanvas.
Defines RealSpaceBuilderUtils namespace.
Defines RealSpaceModel namespace.
Defines class RotationItems.
Defines some unit conversion factors and other constants in namespace Units.
Defines class VectorItem.
BasicVector3D< double > kvector_t
static MaterialModel * materialModel()
T z() const
Returns z-component in cartesian coordinate system.
T y() const
Returns y-component in cartesian coordinate system.
T x() const
Returns x-component in cartesian coordinate system.
Abstract base class for Particle, ParticleComposition, ParticleCoreShell, MesoCrystal.
kvector_t position() const
Returns particle position.
const IRotation * rotation() const
Returns rotation object.
Abstract base class for rotations.
MaterialItem * materialFromName(const QString &name)
A wrapper for underlying material implementation.
std::string getName() const
Returns the name of material.
static const QString T_BASIS_PARTICLE
A particle with an internal structure of smaller particles.
double cumulativeAbundance() const
void setCumulativeAbundance(double cumulativeAbundance)
std::unique_ptr< RealSpace::Particles::Particle > createParticle(const size_t &index) const
void addParticle(RealSpace::Particles::Particle *particle3D, bool blend)
size_t containerSize() const
void setParticleType(QString particleType)
bool particle3DBlend(const size_t &index) const
static const QString T_PARTICLES
std::unique_ptr< ParticleComposition > createParticleComposition() const
A composition of particles at fixed positions.
ParticleComposition * clone() const final
Returns a clone of this ISampleNode object.
static const QString T_CORE
static const QString T_SHELL
std::unique_ptr< ParticleCoreShell > createParticleCoreShell() const
A particle with a core/shell geometry.
ParticleCoreShell * clone() const final
Returns a clone of this ISampleNode object.
std::unique_ptr< ParticleDistribution > createParticleDistribution() const
static const QString T_PARTICLES
A particle type that is a parametric distribution of IParticle's.
SafePointerVector< IParticle > generateParticles() const
Returns list of new particles generated according to a distribution.
std::unique_ptr< Particle > createParticle() const
static const QString P_ABUNDANCE
static const QString T_PARTICLES
A particle with a form factor and refractive index.
Particle * clone() const final
Returns a clone of this ISampleNode object.
const Material * material() const final
Returns nullptr, unless overwritten to return a specific material.
void populateParticleFromParticle3DContainer(RealSpaceModel *model, const Particle3DContainer &particle3DContainer, const QVector3D &lattice_position={}) const
Particle3DContainer populateMesoCrystal()
void addTransform(Vector3D rotate, Vector3D translate)
void transform(Vector3D rotate, Vector3D translate)
A sequence of rotations about the z-x'-z'' axes.
A rotation about the x axis.
A rotation about the y axis.
A rotation about the z axis.
A vector of pointers, owned by *this, with methods to handle them safely.
double layer_top_thickness() const
double layer_bottom_thickness() const
double layer_size() const
QVector< SessionItem * > getItems(const QString &tag="") const
Returns vector of all items of given tag.
QVector< double > computeCumulativeAbundances(const SessionItem &layoutItem)
Particle3DContainer particleCoreShell3DContainer(const ParticleCoreShell &particleCoreShell, double total_abundance=1.0, const QVector3D &origin={})
Particle3DContainer particleComposition3DContainer(const ParticleComposition &particleComposition3DContainer, double total_abundance=1.0, const QVector3D &origin={})
void populateParticlesAtLatticePositions(const std::vector< std::vector< double >> &lattice_positions, const std::vector< Particle3DContainer > &particle3DContainer_vector, RealSpaceModel *model, const SceneGeometry &sceneGeometry, const RealSpaceBuilder *builder3D)
std::vector< Particle3DContainer > particle3DContainerVector(const SessionItem &layoutItem, const QVector3D &origin={})
void applyParticleTransformations(const Particle &particle, RealSpace::Particles::Particle &particle3D, const kvector_t &origin=kvector_t(0, 0, 0))
Apply transformations (translation, rotation) to a 3D Particle or to a particle belonging to a Partic...
std::vector< Particle3DContainer > particleDistribution3DContainer(const ParticleDistribution &particleDistribution, double total_abundance=1.0, const QVector3D &origin={})
void applyParticleCoreShellTransformations(const Particle &particle, RealSpace::Particles::Particle &particle3D, const ParticleCoreShell &particleCoreShell, const kvector_t &origin=kvector_t(0, 0, 0))
Apply transformations (translation, rotation) to a particle (core/shell) in a ParticleCoreShell.
Particle3DContainer mesoCrystal3DContainer(const MesoCrystalItem &mesoCrystalItem, double total_abundance=1.0, const QVector3D &origin={})
RealSpace::Vector3D implementParticleRotationfromIRotation(const IRotation *&rotation)
void applyParticleColor(const Particle &particle, RealSpace::Particles::Particle &particle3D, double alpha=1)
Particle3DContainer singleParticle3DContainer(const Particle &particle, double total_abundance=1.0, const QVector3D &origin={})
double deg2rad(double angle)