diff --git a/GUI/Model/FromCore/ItemizeSample.cpp b/GUI/Model/FromCore/ItemizeSample.cpp index 2d30f92ed91a4ef1fd6610d7643af74c0d1b09de..a014b377e44de1dd1eebbddc880d1e4e280e1e9b 100644 --- a/GUI/Model/FromCore/ItemizeSample.cpp +++ b/GUI/Model/FromCore/ItemizeSample.cpp @@ -44,33 +44,33 @@ using NodeUtils::OnlyChildOfType; namespace { -void setPDF1D(InterferenceRadialParacrystalItem* item, const IProfile1D* ipdf) +void setPDF1D(InterferenceRadialParacrystalItem* parent, const IProfile1D* ipdf) { if (const auto* pdf = dynamic_cast<const Profile1DCauchy*>(ipdf)) { - auto* pdfItem = new Profile1DCauchyItem(); - pdfItem->omega().set(pdf->omega()); - item->setPDFType(pdfItem); + auto* item = new Profile1DCauchyItem(); + item->omega().set(pdf->omega()); + parent->setPDFType(item); } else if (const auto* pdf = dynamic_cast<const Profile1DGauss*>(ipdf)) { - auto* pdfItem = new Profile1DGaussItem(); - pdfItem->omega().set(pdf->omega()); - item->setPDFType(pdfItem); + auto* item = new Profile1DGaussItem(); + item->omega().set(pdf->omega()); + parent->setPDFType(item); } else if (const auto* pdf = dynamic_cast<const Profile1DGate*>(ipdf)) { - auto* pdfItem = new Profile1DGateItem(); - pdfItem->omega().set(pdf->omega()); - item->setPDFType(pdfItem); + auto* item = new Profile1DGateItem(); + item->omega().set(pdf->omega()); + parent->setPDFType(item); } else if (const auto* pdf = dynamic_cast<const Profile1DTriangle*>(ipdf)) { - auto* pdfItem = new Profile1DTriangleItem(); - pdfItem->omega().set(pdf->omega()); - item->setPDFType(pdfItem); + auto* item = new Profile1DTriangleItem(); + item->omega().set(pdf->omega()); + parent->setPDFType(item); } else if (const auto* pdf = dynamic_cast<const Profile1DCosine*>(ipdf)) { - auto* pdfItem = new Profile1DCosineItem(); - pdfItem->omega().set(pdf->omega()); - item->setPDFType(pdfItem); + auto* item = new Profile1DCosineItem(); + item->omega().set(pdf->omega()); + parent->setPDFType(item); } else if (const auto* pdf = dynamic_cast<const Profile1DVoigt*>(ipdf)) { - auto* pdfItem = new Profile1DVoigtItem(); - pdfItem->omega().set(pdf->omega()); - pdfItem->eta().set(pdf->eta()); - item->setPDFType(pdfItem); + auto* item = new Profile1DVoigtItem(); + item->omega().set(pdf->omega()); + item->eta().set(pdf->eta()); + parent->setPDFType(item); } else throw Error("GUI::Transform::FromCore::setPDF1D: -> Error"); } @@ -79,131 +79,131 @@ void setPDF1D(InterferenceRadialParacrystalItem* item, const IProfile1D* ipdf) template <class T> struct SetterPDF1Type { - T* operator()(Interference2DParacrystalItem* item) + T* operator()(Interference2DParacrystalItem* parent) { auto* p = new T(); - item->setPDF1Type(p); + parent->setPDF1Type(p); return p; } }; template <class T> struct SetterPDF2Type { - T* operator()(Interference2DParacrystalItem* item) + T* operator()(Interference2DParacrystalItem* parent) { auto* p = new T(); - item->setPDF2Type(p); + parent->setPDF2Type(p); return p; } }; template <template <class T> class setType> -void setPDF2D(Interference2DParacrystalItem* item, const IProfile2D* pdf) +void setPDF2D(Interference2DParacrystalItem* parent, const IProfile2D* pdf) { if (const auto* pdf_cauchy = dynamic_cast<const Profile2DCauchy*>(pdf)) { - Profile2DCauchyItem* pdfItem = setType<Profile2DCauchyItem>()(item); - pdfItem->setOmegaX(pdf_cauchy->omegaX()); - pdfItem->setOmegaY(pdf_cauchy->omegaY()); - pdfItem->setGamma(Units::rad2deg(pdf_cauchy->gamma())); + Profile2DCauchyItem* item = setType<Profile2DCauchyItem>()(parent); + item->setOmegaX(pdf_cauchy->omegaX()); + item->setOmegaY(pdf_cauchy->omegaY()); + item->setGamma(Units::rad2deg(pdf_cauchy->gamma())); } else if (const auto* pdf_gauss = dynamic_cast<const Profile2DGauss*>(pdf)) { - Profile2DGaussItem* pdfItem = setType<Profile2DGaussItem>()(item); - pdfItem->setOmegaX(pdf_gauss->omegaX()); - pdfItem->setOmegaY(pdf_gauss->omegaY()); - pdfItem->setGamma(Units::rad2deg(pdf_gauss->gamma())); + Profile2DGaussItem* item = setType<Profile2DGaussItem>()(parent); + item->setOmegaX(pdf_gauss->omegaX()); + item->setOmegaY(pdf_gauss->omegaY()); + item->setGamma(Units::rad2deg(pdf_gauss->gamma())); } else if (const auto* pdf_gate = dynamic_cast<const Profile2DGate*>(pdf)) { - Profile2DGateItem* pdfItem = setType<Profile2DGateItem>()(item); - pdfItem->setOmegaX(pdf_gate->omegaX()); - pdfItem->setOmegaY(pdf_gate->omegaY()); - pdfItem->setGamma(Units::rad2deg(pdf_gate->gamma())); + Profile2DGateItem* item = setType<Profile2DGateItem>()(parent); + item->setOmegaX(pdf_gate->omegaX()); + item->setOmegaY(pdf_gate->omegaY()); + item->setGamma(Units::rad2deg(pdf_gate->gamma())); } else if (const auto* pdf_cone = dynamic_cast<const Profile2DCone*>(pdf)) { - Profile2DConeItem* pdfItem = setType<Profile2DConeItem>()(item); - pdfItem->setOmegaX(pdf_cone->omegaX()); - pdfItem->setOmegaY(pdf_cone->omegaY()); - pdfItem->setGamma(Units::rad2deg(pdf_cone->gamma())); + Profile2DConeItem* item = setType<Profile2DConeItem>()(parent); + item->setOmegaX(pdf_cone->omegaX()); + item->setOmegaY(pdf_cone->omegaY()); + item->setGamma(Units::rad2deg(pdf_cone->gamma())); } else if (const auto* pdf_voigt = dynamic_cast<const Profile2DVoigt*>(pdf)) { - Profile2DVoigtItem* pdfItem = setType<Profile2DVoigtItem>()(item); - pdfItem->setOmegaX(pdf_voigt->omegaX()); - pdfItem->setOmegaY(pdf_voigt->omegaY()); - pdfItem->setGamma(Units::rad2deg(pdf_voigt->gamma())); - pdfItem->setEta(pdf_voigt->eta()); + Profile2DVoigtItem* item = setType<Profile2DVoigtItem>()(parent); + item->setOmegaX(pdf_voigt->omegaX()); + item->setOmegaY(pdf_voigt->omegaY()); + item->setGamma(Units::rad2deg(pdf_voigt->gamma())); + item->setEta(pdf_voigt->eta()); } else throw Error("GUI::Transform::FromCore::setPDF2D: -> Error"); } -void setDecayFunction1D(Interference1DLatticeItem* item, const IProfile1D* ipdf) +void setDecayFunction1D(Interference1DLatticeItem* parent, const IProfile1D* ipdf) { if (const auto* pdf = dynamic_cast<const Profile1DCauchy*>(ipdf)) { - auto* pdfItem = new Profile1DCauchyItem(); - pdfItem->omega().set(pdf->omega()); - item->setDecayFunction(pdfItem); + auto* item = new Profile1DCauchyItem(); + item->omega().set(pdf->omega()); + parent->setDecayFunction(item); } else if (const auto* pdf = dynamic_cast<const Profile1DGauss*>(ipdf)) { - auto* pdfItem = new Profile1DGaussItem(); - pdfItem->omega().set(pdf->omega()); - item->setDecayFunction(pdfItem); + auto* item = new Profile1DGaussItem(); + item->omega().set(pdf->omega()); + parent->setDecayFunction(item); } else if (const auto* pdf = dynamic_cast<const Profile1DTriangle*>(ipdf)) { - auto* pdfItem = new Profile1DTriangleItem(); - pdfItem->omega().set(pdf->omega()); - item->setDecayFunction(pdfItem); + auto* item = new Profile1DTriangleItem(); + item->omega().set(pdf->omega()); + parent->setDecayFunction(item); } else if (const auto* pdf = dynamic_cast<const Profile1DVoigt*>(ipdf)) { - auto* pdfItem = new Profile1DVoigtItem(); - pdfItem->omega().set(pdf->omega()); - pdfItem->eta().set(pdf->eta()); - item->setDecayFunction(pdfItem); + auto* item = new Profile1DVoigtItem(); + item->omega().set(pdf->omega()); + item->eta().set(pdf->eta()); + parent->setDecayFunction(item); } else throw Error("GUI::Transform::FromCore::setDecayFunction1D: -> Error"); } -void setDecayFunction2D(Interference2DLatticeItem* item, const IProfile2D* pdf) +void setDecayFunction2D(Interference2DLatticeItem* parent, const IProfile2D* pdf) { if (const auto* pdf_cauchy = dynamic_cast<const Profile2DCauchy*>(pdf)) { - auto* pdfItem = new Profile2DCauchyItem(); - pdfItem->setOmegaX(pdf_cauchy->omegaX()); - pdfItem->setOmegaY(pdf_cauchy->omegaY()); - pdfItem->setGamma(Units::rad2deg(pdf_cauchy->gamma())); - item->setDecayFunctionType(pdfItem); + auto* item = new Profile2DCauchyItem(); + item->setOmegaX(pdf_cauchy->omegaX()); + item->setOmegaY(pdf_cauchy->omegaY()); + item->setGamma(Units::rad2deg(pdf_cauchy->gamma())); + parent->setDecayFunctionType(item); } else if (const auto* pdf_gauss = dynamic_cast<const Profile2DGauss*>(pdf)) { - auto* pdfItem = new Profile2DGaussItem(); - pdfItem->setOmegaX(pdf_gauss->omegaX()); - pdfItem->setOmegaY(pdf_gauss->omegaY()); - pdfItem->setGamma(Units::rad2deg(pdf_gauss->gamma())); - item->setDecayFunctionType(pdfItem); + auto* item = new Profile2DGaussItem(); + item->setOmegaX(pdf_gauss->omegaX()); + item->setOmegaY(pdf_gauss->omegaY()); + item->setGamma(Units::rad2deg(pdf_gauss->gamma())); + parent->setDecayFunctionType(item); } else if (const auto* pdf_voigt = dynamic_cast<const Profile2DVoigt*>(pdf)) { - auto* pdfItem = new Profile2DVoigtItem(); - pdfItem->setOmegaX(pdf_voigt->omegaX()); - pdfItem->setOmegaY(pdf_voigt->omegaY()); - pdfItem->setGamma(Units::rad2deg(pdf_voigt->gamma())); - pdfItem->setEta(pdf_voigt->eta()); - item->setDecayFunctionType(pdfItem); + auto* item = new Profile2DVoigtItem(); + item->setOmegaX(pdf_voigt->omegaX()); + item->setOmegaY(pdf_voigt->omegaY()); + item->setGamma(Units::rad2deg(pdf_voigt->gamma())); + item->setEta(pdf_voigt->eta()); + parent->setDecayFunctionType(item); } else throw Error("GUI::Transform::FromCore::setDecayFunction2D: -> Error"); } -void set2DLatticeParameters(Interference2DAbstractLatticeItem* item, const Lattice2D& lattice) +void set2DLatticeParameters(Interference2DAbstractLatticeItem* parent, const Lattice2D& lattice) { - Lattice2DItem* latticeItem(nullptr); + Lattice2DItem* item(nullptr); if (lattice.className() == "SquareLattice2D") { auto* squareLatticeItem = new SquareLattice2DItem(); squareLatticeItem->setLatticeLength(lattice.length1()); - latticeItem = squareLatticeItem; + item = squareLatticeItem; } else if (lattice.className() == "HexagonalLattice2D") { auto* hexLatticeItem = new HexagonalLattice2DItem(); hexLatticeItem->setLatticeLength(lattice.length1()); - latticeItem = hexLatticeItem; + item = hexLatticeItem; } else { auto* basicLatticeItem = new BasicLattice2DItem(); basicLatticeItem->setLatticeLength1(lattice.length1()); basicLatticeItem->setLatticeLength2(lattice.length2()); basicLatticeItem->setLatticeAngle(Units::rad2deg(lattice.latticeAngle())); - latticeItem = basicLatticeItem; + item = basicLatticeItem; } - latticeItem->setLatticeRotationAngle(Units::rad2deg(lattice.rotationAngle())); - item->setLatticeType(latticeItem); + item->setLatticeRotationAngle(Units::rad2deg(lattice.rotationAngle())); + parent->setLatticeType(item); } -void setPositionVariance(InterferenceItem* item, const IInterference& iff) +void setPositionVariance(InterferenceItem* parent, const IInterference& iff) { double pos_var = iff.positionVariance(); - item->positionVariance().set(pos_var); + parent->positionVariance().set(pos_var); } template <typename T> @@ -215,76 +215,76 @@ T* addFormFactorItem(std::variant<ParticleItem*, MesocrystalItem*> parent) return std::get<MesocrystalItem*>(parent)->setOuterShapeType<T>(); } -void set1DLatticeItem(Interference1DLatticeItem* item, const Interference1DLattice& sample) +void set1DLatticeItem(Interference1DLatticeItem* parent, const Interference1DLattice& sample) { - item->length().set(sample.length()); - item->rotationAngle().set(Units::rad2deg(sample.xi())); + parent->length().set(sample.length()); + parent->rotationAngle().set(Units::rad2deg(sample.xi())); const auto* pdf = OnlyChildOfType<IProfile1D>(sample); - setDecayFunction1D(item, pdf); - setPositionVariance(item, sample); + setDecayFunction1D(parent, pdf); + setPositionVariance(parent, sample); } -void set2DLatticeItem(Interference2DLatticeItem* item, const Interference2DLattice& sample) +void set2DLatticeItem(Interference2DLatticeItem* parent, const Interference2DLattice& sample) { - set2DLatticeParameters(item, sample.lattice()); + set2DLatticeParameters(parent, sample.lattice()); - item->setXiIntegration(sample.integrationOverXi()); + parent->setXiIntegration(sample.integrationOverXi()); const auto* p_pdf = OnlyChildOfType<IProfile2D>(sample); - setDecayFunction2D(item, p_pdf); - setPositionVariance(item, sample); + setDecayFunction2D(parent, p_pdf); + setPositionVariance(parent, sample); } -void set2DParacrystalItem(Interference2DParacrystalItem* item, +void set2DParacrystalItem(Interference2DParacrystalItem* parent, const Interference2DParacrystal& sample) { - set2DLatticeParameters(item, sample.lattice()); + set2DLatticeParameters(parent, sample.lattice()); - item->setDampingLength(sample.dampingLength()); - item->setDomainSize1(sample.domainSizes()[0]); - item->setDomainSize2(sample.domainSizes()[1]); - item->setXiIntegration(sample.integrationOverXi()); + parent->setDampingLength(sample.dampingLength()); + parent->setDomainSize1(sample.domainSizes()[0]); + parent->setDomainSize2(sample.domainSizes()[1]); + parent->setXiIntegration(sample.integrationOverXi()); auto pdfs = ChildNodesOfType<IProfile2D>(sample); if (!pdfs.empty()) { - setPDF2D<SetterPDF1Type>(item, pdfs[0]); + setPDF2D<SetterPDF1Type>(parent, pdfs[0]); if (pdfs.size() >= 2) - setPDF2D<SetterPDF2Type>(item, pdfs[1]); + setPDF2D<SetterPDF2Type>(parent, pdfs[1]); } - setPositionVariance(item, sample); + setPositionVariance(parent, sample); } -void setFinite2DLatticeItem(InterferenceFinite2DLatticeItem* item, +void setFinite2DLatticeItem(InterferenceFinite2DLatticeItem* parent, const InterferenceFinite2DLattice& sample) { - set2DLatticeParameters(item, sample.lattice()); + set2DLatticeParameters(parent, sample.lattice()); - item->setDomainSize1(sample.numberUnitCells1()); - item->setDomainSize2(sample.numberUnitCells2()); - item->setXiIntegration(sample.integrationOverXi()); - setPositionVariance(item, sample); + parent->setDomainSize1(sample.numberUnitCells1()); + parent->setDomainSize2(sample.numberUnitCells2()); + parent->setXiIntegration(sample.integrationOverXi()); + setPositionVariance(parent, sample); } -void setHardDiskItem(InterferenceHardDiskItem* item, const InterferenceHardDisk& sample) +void setHardDiskItem(InterferenceHardDiskItem* parent, const InterferenceHardDisk& sample) { - item->radius().set(sample.radius()); - item->density().set(sample.density()); - setPositionVariance(item, sample); + parent->radius().set(sample.radius()); + parent->density().set(sample.density()); + setPositionVariance(parent, sample); } -void setRadialParacrystalItem(InterferenceRadialParacrystalItem* item, +void setRadialParacrystalItem(InterferenceRadialParacrystalItem* parent, const InterferenceRadialParacrystal& sample) { - item->peakDistance().set(sample.peakDistance()); - item->dampingLength().set(sample.dampingLength()); - item->domainSize().set(sample.domainSize()); - item->kappa().set(sample.kappa()); + parent->peakDistance().set(sample.peakDistance()); + parent->dampingLength().set(sample.dampingLength()); + parent->domainSize().set(sample.domainSize()); + parent->kappa().set(sample.kappa()); const auto* ipdf = OnlyChildOfType<IProfile1D>(sample); - setPDF1D(item, ipdf); - setPositionVariance(item, sample); + setPDF1D(parent, ipdf); + setPositionVariance(parent, sample); } //! Returns true if given roughness is non-zero roughness @@ -298,234 +298,233 @@ bool isValidRoughness(const LayerRoughness* roughness) return true; } -void setRoughnessItem(LayerBasicRoughnessItem* item, const LayerRoughness& sample) +void setRoughnessItem(LayerBasicRoughnessItem* parent, const LayerRoughness& sample) { - item->sigma().set(sample.sigma()); - item->hurst().set(sample.hurst()); - item->lateralCorrelationLength().set(sample.lateralCorrLength()); + parent->sigma().set(sample.sigma()); + parent->hurst().set(sample.hurst()); + parent->lateralCorrelationLength().set(sample.lateralCorrLength()); } -void setLayerItem(LayerItem* layerItem, const Layer* layer, const LayerInterface* top_interface) +void setLayerItem(LayerItem* parent, const Layer* layer, const LayerInterface* top_interface) { - layerItem->thickness().set(layer->thickness()); - layerItem->clearRoughness(); - layerItem->numSlices().set(layer->numberOfSlices()); + parent->thickness().set(layer->thickness()); + parent->clearRoughness(); + parent->numSlices().set(layer->numberOfSlices()); if (top_interface) { const LayerRoughness* roughness = top_interface->roughness(); if (isValidRoughness(roughness)) { - layerItem->setBasicRoughness(); - setRoughnessItem(layerItem->roughness().currentItem(), *roughness); + parent->setBasicRoughness(); + setRoughnessItem(parent->roughness().currentItem(), *roughness); } } } -void setRotation(ItemWithParticles* item, const IRotation* rotation) +void setRotation(ItemWithParticles* parent, const IRotation* rotation) { if (!rotation) - item->setRotation(nullptr); + parent->setRotation(nullptr); else if (const auto* r = dynamic_cast<const RotationX*>(rotation)) { - auto* rotationItem = new XRotationItem(); - rotationItem->angle().set(Units::rad2deg(r->angle())); - item->setRotation(rotationItem); + auto* item = new XRotationItem(); + item->angle().set(Units::rad2deg(r->angle())); + parent->setRotation(item); } else if (const auto* r = dynamic_cast<const RotationY*>(rotation)) { - auto* rotationItem = new YRotationItem(); - rotationItem->angle().set(Units::rad2deg(r->angle())); - item->setRotation(rotationItem); + auto* item = new YRotationItem(); + item->angle().set(Units::rad2deg(r->angle())); + parent->setRotation(item); } else if (const auto* r = dynamic_cast<const RotationZ*>(rotation)) { - auto* rotationItem = new ZRotationItem(); - rotationItem->angle().set(Units::rad2deg(r->angle())); - item->setRotation(rotationItem); + auto* item = new ZRotationItem(); + item->angle().set(Units::rad2deg(r->angle())); + parent->setRotation(item); } else if (const auto* r = dynamic_cast<const RotationEuler*>(rotation)) { - auto* rotationItem = new EulerRotationItem(); - rotationItem->alpha().set(Units::rad2deg(r->alpha())); - rotationItem->beta().set(Units::rad2deg(r->beta())); - rotationItem->gamma().set(Units::rad2deg(r->gamma())); - item->setRotation(rotationItem); + auto* item = new EulerRotationItem(); + item->alpha().set(Units::rad2deg(r->alpha())); + item->beta().set(Units::rad2deg(r->beta())); + item->gamma().set(Units::rad2deg(r->gamma())); + parent->setRotation(item); } } -void setInterference(ParticleLayoutItem* layoutItem, const IInterference* interference) +void setInterference(ParticleLayoutItem* parent, const IInterference* interference) { if (!interference) - layoutItem->removeInterference(); + parent->removeInterference(); else if (const auto* itf = dynamic_cast<const Interference1DLattice*>(interference)) { - auto* itfItem = new Interference1DLatticeItem(); - set1DLatticeItem(itfItem, *itf); - layoutItem->setInterference(itfItem); + auto* item = new Interference1DLatticeItem(); + set1DLatticeItem(item, *itf); + parent->setInterference(item); } else if (const auto* itf = dynamic_cast<const Interference2DLattice*>(interference)) { - auto* itfItem = new Interference2DLatticeItem(); - set2DLatticeItem(itfItem, *itf); - layoutItem->setInterference(itfItem); + auto* item = new Interference2DLatticeItem(); + set2DLatticeItem(item, *itf); + parent->setInterference(item); } else if (const auto* itf = dynamic_cast<const Interference2DParacrystal*>(interference)) { - auto* itfItem = new Interference2DParacrystalItem(); - set2DParacrystalItem(itfItem, *itf); - layoutItem->setInterference(itfItem); + auto* item = new Interference2DParacrystalItem(); + set2DParacrystalItem(item, *itf); + parent->setInterference(item); } else if (const auto* itf = dynamic_cast<const InterferenceFinite2DLattice*>(interference)) { - auto* itfItem = new InterferenceFinite2DLatticeItem(); - setFinite2DLatticeItem(itfItem, *itf); - layoutItem->setInterference(itfItem); + auto* item = new InterferenceFinite2DLatticeItem(); + setFinite2DLatticeItem(item, *itf); + parent->setInterference(item); } else if (const auto* itf = dynamic_cast<const InterferenceHardDisk*>(interference)) { - auto* itfItem = new InterferenceHardDiskItem(); - setHardDiskItem(itfItem, *itf); - layoutItem->setInterference(itfItem); + auto* item = new InterferenceHardDiskItem(); + setHardDiskItem(item, *itf); + parent->setInterference(item); } else if (const auto* itf = dynamic_cast<const InterferenceRadialParacrystal*>(interference)) { - auto* itfItem = new InterferenceRadialParacrystalItem(); - setRadialParacrystalItem(itfItem, *itf); - layoutItem->setInterference(itfItem); + auto* item = new InterferenceRadialParacrystalItem(); + setRadialParacrystalItem(item, *itf); + parent->setInterference(item); } else ASSERT(false); // missing implementation for interference type } -void setFormFactor(std::variant<ParticleItem*, MesocrystalItem*> parent, - const IFormFactor* iFormFactor) +void setFormFactor(std::variant<ParticleItem*, MesocrystalItem*> parent, const IFormFactor* ff) { - if (const auto* formfactor = dynamic_cast<const Pyramid2*>(iFormFactor)) { - auto* formfactorItem = addFormFactorItem<Pyramid2Item>(parent); - formfactorItem->setLength(formfactor->length()); - formfactorItem->setWidth(formfactor->width()); - formfactorItem->setHeight(formfactor->height()); - formfactorItem->setAlpha(Units::rad2deg(formfactor->alpha())); - } else if (const auto* formfactor = dynamic_cast<const BarGauss*>(iFormFactor)) { - auto* formfactorItem = addFormFactorItem<BarGaussItem>(parent); - formfactorItem->setLength(formfactor->length()); - formfactorItem->setWidth(formfactor->width()); - formfactorItem->setHeight(formfactor->height()); - } else if (const auto* formfactor = dynamic_cast<const BarLorentz*>(iFormFactor)) { - auto* formfactorItem = addFormFactorItem<BarLorentzItem>(parent); - formfactorItem->setLength(formfactor->length()); - formfactorItem->setWidth(formfactor->width()); - formfactorItem->setHeight(formfactor->height()); - } else if (const auto* formfactor = dynamic_cast<const Box*>(iFormFactor)) { - auto* formfactorItem = addFormFactorItem<BoxItem>(parent); - formfactorItem->setLength(formfactor->length()); - formfactorItem->setWidth(formfactor->width()); - formfactorItem->setHeight(formfactor->height()); - } else if (const auto* formfactor = dynamic_cast<const Cone*>(iFormFactor)) { - auto* formfactorItem = addFormFactorItem<ConeItem>(parent); - formfactorItem->setRadius(formfactor->radius()); - formfactorItem->setHeight(formfactor->height()); - formfactorItem->setAlpha(Units::rad2deg(formfactor->alpha())); - } else if (const auto* formfactor = dynamic_cast<const Pyramid6*>(iFormFactor)) { - auto* formfactorItem = addFormFactorItem<Pyramid6Item>(parent); - formfactorItem->setBaseEdge(formfactor->baseEdge()); - formfactorItem->setHeight(formfactor->height()); - formfactorItem->setAlpha(Units::rad2deg(formfactor->alpha())); - } else if (const auto* formfactor = dynamic_cast<const Bipyramid4*>(iFormFactor)) { - auto* formfactorItem = addFormFactorItem<Bipyramid4Item>(parent); - formfactorItem->setLength(formfactor->length()); - formfactorItem->setHeight(formfactor->height()); - formfactorItem->setHeightRatio(formfactor->heightRatio()); - formfactorItem->setAlpha(Units::rad2deg(formfactor->alpha())); - } else if (const auto* formfactor = dynamic_cast<const Cylinder*>(iFormFactor)) { - auto* formfactorItem = addFormFactorItem<CylinderItem>(parent); - formfactorItem->setRadius(formfactor->radius()); - formfactorItem->setHeight(formfactor->height()); - } else if (const auto* formfactor = dynamic_cast<const Dodecahedron*>(iFormFactor)) { - auto* formfactorItem = addFormFactorItem<DodecahedronItem>(parent); - formfactorItem->setEdge(formfactor->edge()); - } else if (const auto* formfactor = dynamic_cast<const EllipsoidalCylinder*>(iFormFactor)) { - auto* formfactorItem = addFormFactorItem<EllipsoidalCylinderItem>(parent); - formfactorItem->setRadiusX(formfactor->radiusX()); - formfactorItem->setRadiusY(formfactor->radiusY()); - formfactorItem->setHeight(formfactor->height()); - } else if (const auto* formfactor = dynamic_cast<const Sphere*>(iFormFactor)) { - auto* formfactorItem = addFormFactorItem<SphereItem>(parent); - formfactorItem->setRadius(formfactor->radius()); - } else if (const auto* formfactor = dynamic_cast<const Spheroid*>(iFormFactor)) { - auto* formfactorItem = addFormFactorItem<SpheroidItem>(parent); - formfactorItem->setRadius(formfactor->radius()); - formfactorItem->setHeight(formfactor->height()); - } else if (const auto* formfactor = dynamic_cast<const Icosahedron*>(iFormFactor)) { - auto* formfactorItem = addFormFactorItem<IcosahedronItem>(parent); - formfactorItem->setEdge(formfactor->edge()); - } else if (const auto* formfactor = dynamic_cast<const HemiEllipsoid*>(iFormFactor)) { - auto* formfactorItem = addFormFactorItem<HemiEllipsoidItem>(parent); - formfactorItem->setRadiusX(formfactor->radiusX()); - formfactorItem->setRadiusY(formfactor->radiusY()); - formfactorItem->setHeight(formfactor->height()); - } else if (const auto* formfactor = dynamic_cast<const Prism3*>(iFormFactor)) { - auto* formfactorItem = addFormFactorItem<Prism3Item>(parent); - formfactorItem->setBaseEdge(formfactor->baseEdge()); - formfactorItem->setHeight(formfactor->height()); - } else if (const auto* formfactor = dynamic_cast<const Prism6*>(iFormFactor)) { - auto* formfactorItem = addFormFactorItem<Prism6Item>(parent); - formfactorItem->setBaseEdge(formfactor->baseEdge()); - formfactorItem->setHeight(formfactor->height()); - } else if (const auto* formfactor = dynamic_cast<const Pyramid4*>(iFormFactor)) { - auto* formfactorItem = addFormFactorItem<Pyramid4Item>(parent); - formfactorItem->setBaseEdge(formfactor->baseEdge()); - formfactorItem->setHeight(formfactor->height()); - formfactorItem->setAlpha(Units::rad2deg(formfactor->alpha())); - } else if (const auto* formfactor = dynamic_cast<const CosineRippleBox*>(iFormFactor)) { - auto* formfactorItem = addFormFactorItem<CosineRippleBoxItem>(parent); - formfactorItem->setLength(formfactor->length()); - formfactorItem->setWidth(formfactor->width()); - formfactorItem->setHeight(formfactor->height()); - } else if (const auto* formfactor = dynamic_cast<const CosineRippleGauss*>(iFormFactor)) { - auto* formfactorItem = addFormFactorItem<CosineRippleGaussItem>(parent); - formfactorItem->setLength(formfactor->length()); - formfactorItem->setWidth(formfactor->width()); - formfactorItem->setHeight(formfactor->height()); - } else if (const auto* formfactor = dynamic_cast<const CosineRippleLorentz*>(iFormFactor)) { - auto* formfactorItem = addFormFactorItem<CosineRippleLorentzItem>(parent); - formfactorItem->setLength(formfactor->length()); - formfactorItem->setWidth(formfactor->width()); - formfactorItem->setHeight(formfactor->height()); - } else if (const auto* formfactor = dynamic_cast<const SawtoothRippleBox*>(iFormFactor)) { - auto* formfactorItem = addFormFactorItem<SawtoothRippleBoxItem>(parent); - formfactorItem->setLength(formfactor->length()); - formfactorItem->setWidth(formfactor->width()); - formfactorItem->setHeight(formfactor->height()); - formfactorItem->setAsymmetry(formfactor->asymmetry()); - } else if (const auto* formfactor = dynamic_cast<const SawtoothRippleGauss*>(iFormFactor)) { - auto* formfactorItem = addFormFactorItem<SawtoothRippleGaussItem>(parent); - formfactorItem->setLength(formfactor->length()); - formfactorItem->setWidth(formfactor->width()); - formfactorItem->setHeight(formfactor->height()); - formfactorItem->setAsymmetry(formfactor->asymmetry()); - } else if (const auto* formfactor = dynamic_cast<const SawtoothRippleLorentz*>(iFormFactor)) { - auto* formfactorItem = addFormFactorItem<SawtoothRippleLorentzItem>(parent); - formfactorItem->setLength(formfactor->length()); - formfactorItem->setWidth(formfactor->width()); - formfactorItem->setHeight(formfactor->height()); - formfactorItem->setAsymmetry(formfactor->asymmetry()); - } else if (const auto* formfactor = dynamic_cast<const Pyramid3*>(iFormFactor)) { - auto* formfactorItem = addFormFactorItem<Pyramid3Item>(parent); - formfactorItem->setBaseEdge(formfactor->baseEdge()); - formfactorItem->setHeight(formfactor->height()); - formfactorItem->setAlpha(Units::rad2deg(formfactor->alpha())); - } else if (const auto* formfactor = dynamic_cast<const TruncatedCube*>(iFormFactor)) { - auto* formfactorItem = addFormFactorItem<TruncatedCubeItem>(parent); - formfactorItem->setLength(formfactor->length()); - formfactorItem->setRemovedLength(formfactor->removedLength()); - } else if (const auto* formfactor = dynamic_cast<const TruncatedSphere*>(iFormFactor)) { - auto* formfactorItem = addFormFactorItem<TruncatedSphereItem>(parent); - formfactorItem->setRadius(formfactor->radius()); - formfactorItem->setHeight(formfactor->height()); - formfactorItem->setRemovedTop(formfactor->removedTop()); - } else if (const auto* formfactor = dynamic_cast<const TruncatedSpheroid*>(iFormFactor)) { - auto* formfactorItem = addFormFactorItem<TruncatedSpheroidItem>(parent); - formfactorItem->setRadius(formfactor->radius()); - formfactorItem->setHeight(formfactor->height()); - formfactorItem->setHeightFlattening(formfactor->heightFlattening()); - formfactorItem->setRemovedTop(formfactor->removedTop()); - } else if (const auto* formfactor = dynamic_cast<const CantellatedCube*>(iFormFactor)) { - auto* formfactorItem = addFormFactorItem<CantellatedCubeItem>(parent); - formfactorItem->setLength(formfactor->length()); - formfactorItem->setRemovedLength(formfactor->removedLength()); - } else if (const auto* formfactor = dynamic_cast<const HorizontalCylinder*>(iFormFactor)) { - auto* formfactorItem = addFormFactorItem<HorizontalCylinderItem>(parent); - formfactorItem->setRadius(formfactor->radius()); - formfactorItem->setLength(formfactor->length()); - formfactorItem->setSliceBottom(formfactor->slice_bottom()); - formfactorItem->setSliceTop(formfactor->slice_top()); - } else if (const auto* formfactor = dynamic_cast<const PlatonicOctahedron*>(iFormFactor)) { - auto* formfactorItem = addFormFactorItem<PlatonicOctahedronItem>(parent); - formfactorItem->setEdge(formfactor->edge()); - } else if (const auto* formfactor = dynamic_cast<const PlatonicTetrahedron*>(iFormFactor)) { - auto* formfactorItem = addFormFactorItem<PlatonicTetrahedronItem>(parent); - formfactorItem->setEdge(formfactor->edge()); + if (const auto* formfactor = dynamic_cast<const Pyramid2*>(ff)) { + auto* item = addFormFactorItem<Pyramid2Item>(parent); + item->setLength(formfactor->length()); + item->setWidth(formfactor->width()); + item->setHeight(formfactor->height()); + item->setAlpha(Units::rad2deg(formfactor->alpha())); + } else if (const auto* formfactor = dynamic_cast<const BarGauss*>(ff)) { + auto* item = addFormFactorItem<BarGaussItem>(parent); + item->setLength(formfactor->length()); + item->setWidth(formfactor->width()); + item->setHeight(formfactor->height()); + } else if (const auto* formfactor = dynamic_cast<const BarLorentz*>(ff)) { + auto* item = addFormFactorItem<BarLorentzItem>(parent); + item->setLength(formfactor->length()); + item->setWidth(formfactor->width()); + item->setHeight(formfactor->height()); + } else if (const auto* formfactor = dynamic_cast<const Box*>(ff)) { + auto* item = addFormFactorItem<BoxItem>(parent); + item->setLength(formfactor->length()); + item->setWidth(formfactor->width()); + item->setHeight(formfactor->height()); + } else if (const auto* formfactor = dynamic_cast<const Cone*>(ff)) { + auto* item = addFormFactorItem<ConeItem>(parent); + item->setRadius(formfactor->radius()); + item->setHeight(formfactor->height()); + item->setAlpha(Units::rad2deg(formfactor->alpha())); + } else if (const auto* formfactor = dynamic_cast<const Pyramid6*>(ff)) { + auto* item = addFormFactorItem<Pyramid6Item>(parent); + item->setBaseEdge(formfactor->baseEdge()); + item->setHeight(formfactor->height()); + item->setAlpha(Units::rad2deg(formfactor->alpha())); + } else if (const auto* formfactor = dynamic_cast<const Bipyramid4*>(ff)) { + auto* item = addFormFactorItem<Bipyramid4Item>(parent); + item->setLength(formfactor->length()); + item->setHeight(formfactor->height()); + item->setHeightRatio(formfactor->heightRatio()); + item->setAlpha(Units::rad2deg(formfactor->alpha())); + } else if (const auto* formfactor = dynamic_cast<const Cylinder*>(ff)) { + auto* item = addFormFactorItem<CylinderItem>(parent); + item->setRadius(formfactor->radius()); + item->setHeight(formfactor->height()); + } else if (const auto* formfactor = dynamic_cast<const Dodecahedron*>(ff)) { + auto* item = addFormFactorItem<DodecahedronItem>(parent); + item->setEdge(formfactor->edge()); + } else if (const auto* formfactor = dynamic_cast<const EllipsoidalCylinder*>(ff)) { + auto* item = addFormFactorItem<EllipsoidalCylinderItem>(parent); + item->setRadiusX(formfactor->radiusX()); + item->setRadiusY(formfactor->radiusY()); + item->setHeight(formfactor->height()); + } else if (const auto* formfactor = dynamic_cast<const Sphere*>(ff)) { + auto* item = addFormFactorItem<SphereItem>(parent); + item->setRadius(formfactor->radius()); + } else if (const auto* formfactor = dynamic_cast<const Spheroid*>(ff)) { + auto* item = addFormFactorItem<SpheroidItem>(parent); + item->setRadius(formfactor->radius()); + item->setHeight(formfactor->height()); + } else if (const auto* formfactor = dynamic_cast<const Icosahedron*>(ff)) { + auto* item = addFormFactorItem<IcosahedronItem>(parent); + item->setEdge(formfactor->edge()); + } else if (const auto* formfactor = dynamic_cast<const HemiEllipsoid*>(ff)) { + auto* item = addFormFactorItem<HemiEllipsoidItem>(parent); + item->setRadiusX(formfactor->radiusX()); + item->setRadiusY(formfactor->radiusY()); + item->setHeight(formfactor->height()); + } else if (const auto* formfactor = dynamic_cast<const Prism3*>(ff)) { + auto* item = addFormFactorItem<Prism3Item>(parent); + item->setBaseEdge(formfactor->baseEdge()); + item->setHeight(formfactor->height()); + } else if (const auto* formfactor = dynamic_cast<const Prism6*>(ff)) { + auto* item = addFormFactorItem<Prism6Item>(parent); + item->setBaseEdge(formfactor->baseEdge()); + item->setHeight(formfactor->height()); + } else if (const auto* formfactor = dynamic_cast<const Pyramid4*>(ff)) { + auto* item = addFormFactorItem<Pyramid4Item>(parent); + item->setBaseEdge(formfactor->baseEdge()); + item->setHeight(formfactor->height()); + item->setAlpha(Units::rad2deg(formfactor->alpha())); + } else if (const auto* formfactor = dynamic_cast<const CosineRippleBox*>(ff)) { + auto* item = addFormFactorItem<CosineRippleBoxItem>(parent); + item->setLength(formfactor->length()); + item->setWidth(formfactor->width()); + item->setHeight(formfactor->height()); + } else if (const auto* formfactor = dynamic_cast<const CosineRippleGauss*>(ff)) { + auto* item = addFormFactorItem<CosineRippleGaussItem>(parent); + item->setLength(formfactor->length()); + item->setWidth(formfactor->width()); + item->setHeight(formfactor->height()); + } else if (const auto* formfactor = dynamic_cast<const CosineRippleLorentz*>(ff)) { + auto* item = addFormFactorItem<CosineRippleLorentzItem>(parent); + item->setLength(formfactor->length()); + item->setWidth(formfactor->width()); + item->setHeight(formfactor->height()); + } else if (const auto* formfactor = dynamic_cast<const SawtoothRippleBox*>(ff)) { + auto* item = addFormFactorItem<SawtoothRippleBoxItem>(parent); + item->setLength(formfactor->length()); + item->setWidth(formfactor->width()); + item->setHeight(formfactor->height()); + item->setAsymmetry(formfactor->asymmetry()); + } else if (const auto* formfactor = dynamic_cast<const SawtoothRippleGauss*>(ff)) { + auto* item = addFormFactorItem<SawtoothRippleGaussItem>(parent); + item->setLength(formfactor->length()); + item->setWidth(formfactor->width()); + item->setHeight(formfactor->height()); + item->setAsymmetry(formfactor->asymmetry()); + } else if (const auto* formfactor = dynamic_cast<const SawtoothRippleLorentz*>(ff)) { + auto* item = addFormFactorItem<SawtoothRippleLorentzItem>(parent); + item->setLength(formfactor->length()); + item->setWidth(formfactor->width()); + item->setHeight(formfactor->height()); + item->setAsymmetry(formfactor->asymmetry()); + } else if (const auto* formfactor = dynamic_cast<const Pyramid3*>(ff)) { + auto* item = addFormFactorItem<Pyramid3Item>(parent); + item->setBaseEdge(formfactor->baseEdge()); + item->setHeight(formfactor->height()); + item->setAlpha(Units::rad2deg(formfactor->alpha())); + } else if (const auto* formfactor = dynamic_cast<const TruncatedCube*>(ff)) { + auto* item = addFormFactorItem<TruncatedCubeItem>(parent); + item->setLength(formfactor->length()); + item->setRemovedLength(formfactor->removedLength()); + } else if (const auto* formfactor = dynamic_cast<const TruncatedSphere*>(ff)) { + auto* item = addFormFactorItem<TruncatedSphereItem>(parent); + item->setRadius(formfactor->radius()); + item->setHeight(formfactor->height()); + item->setRemovedTop(formfactor->removedTop()); + } else if (const auto* formfactor = dynamic_cast<const TruncatedSpheroid*>(ff)) { + auto* item = addFormFactorItem<TruncatedSpheroidItem>(parent); + item->setRadius(formfactor->radius()); + item->setHeight(formfactor->height()); + item->setHeightFlattening(formfactor->heightFlattening()); + item->setRemovedTop(formfactor->removedTop()); + } else if (const auto* formfactor = dynamic_cast<const CantellatedCube*>(ff)) { + auto* item = addFormFactorItem<CantellatedCubeItem>(parent); + item->setLength(formfactor->length()); + item->setRemovedLength(formfactor->removedLength()); + } else if (const auto* formfactor = dynamic_cast<const HorizontalCylinder*>(ff)) { + auto* item = addFormFactorItem<HorizontalCylinderItem>(parent); + item->setRadius(formfactor->radius()); + item->setLength(formfactor->length()); + item->setSliceBottom(formfactor->slice_bottom()); + item->setSliceTop(formfactor->slice_top()); + } else if (const auto* formfactor = dynamic_cast<const PlatonicOctahedron*>(ff)) { + auto* item = addFormFactorItem<PlatonicOctahedronItem>(parent); + item->setEdge(formfactor->edge()); + } else if (const auto* formfactor = dynamic_cast<const PlatonicTetrahedron*>(ff)) { + auto* item = addFormFactorItem<PlatonicTetrahedronItem>(parent); + item->setEdge(formfactor->edge()); } else ASSERT(false); } @@ -536,92 +535,90 @@ MaterialItem* findMaterialItem(MaterialItems& matItems, const ISampleNode* node) QString materialName = QString::fromStdString(material->materialName()); - MaterialItem* materialItem = matItems.materialFromName(materialName); - if (materialItem) - return materialItem; + MaterialItem* result = matItems.materialFromName(materialName); + if (result) + return result; complex_t material_data = material->materialData(); if (material->typeID() == MATERIAL_TYPES::RefractiveMaterial) { - materialItem = matItems.addRefractiveMaterial(materialName, material_data.real(), - material_data.imag()); + result = matItems.addRefractiveMaterial(materialName, material_data.real(), + material_data.imag()); } else if (material->typeID() == MATERIAL_TYPES::MaterialBySLD) { - materialItem = - matItems.addSLDMaterial(materialName, material_data.real(), material_data.imag()); + result = matItems.addSLDMaterial(materialName, material_data.real(), material_data.imag()); } else ASSERT(0); - materialItem->setMagnetization(material->magnetization()); + result->setMagnetization(material->magnetization()); - return materialItem; + return result; } -void copyParticleItem(ParticleItem* particleItem, MaterialItems& matItems, const Particle* particle) +void copyParticleItem(ParticleItem* parent, MaterialItems& matItems, const Particle* particle) { - particleItem->setAbundance(particle->abundance()); - particleItem->setPosition(particle->particlePosition()); - particleItem->setMaterial(findMaterialItem(matItems, particle)); - setRotation(particleItem, particle->rotation()); - setFormFactor(particleItem, particle->formfactor_at_bottom()); + parent->setAbundance(particle->abundance()); + parent->setPosition(particle->particlePosition()); + parent->setMaterial(findMaterialItem(matItems, particle)); + setRotation(parent, particle->rotation()); + setFormFactor(parent, particle->formfactor_at_bottom()); } void copyParticle(const IParticle* iparticle, MaterialItems& matItems, std::function<void(ItemWithParticles*)> addToParent) { if (const auto* particle = dynamic_cast<const Particle*>(iparticle)) { - auto* particle_item = new ParticleItem(&matItems); - copyParticleItem(particle_item, matItems, particle); - addToParent(particle_item); + auto* item = new ParticleItem(&matItems); + copyParticleItem(item, matItems, particle); + addToParent(item); } else if (const auto* coreshell = dynamic_cast<const CoreAndShell*>(iparticle)) { if (!coreshell->coreParticle()) throw std::runtime_error("core/shell particle has no core particle."); if (!coreshell->shellParticle()) throw std::runtime_error("core/shell particle has no shell particle."); - auto* coreShellItem = new CoreAndShellItem(&matItems); - coreShellItem->setAbundance(coreshell->abundance()); - coreShellItem->setPosition(coreshell->particlePosition()); - setRotation(coreShellItem, coreshell->rotation()); + auto* item = new CoreAndShellItem(&matItems); + item->setAbundance(coreshell->abundance()); + item->setPosition(coreshell->particlePosition()); + setRotation(item, coreshell->rotation()); if (const Particle* p = coreshell->coreParticle()) { - coreShellItem->createCore(&matItems); - copyParticleItem(coreShellItem->core(), matItems, p); + item->createCore(&matItems); + copyParticleItem(item->core(), matItems, p); } if (const Particle* p = coreshell->shellParticle()) { - coreShellItem->createShell(&matItems); - copyParticleItem(coreShellItem->shell(), matItems, p); + item->createShell(&matItems); + copyParticleItem(item->shell(), matItems, p); } - addToParent(coreShellItem); + addToParent(item); } else if (const auto* meso = dynamic_cast<const Mesocrystal*>(iparticle)) { if (!meso->particleStructure().basis()) throw std::runtime_error("Meso crystal has no basis."); - auto* mesoItem = new MesocrystalItem(&matItems); - mesoItem->setAbundance(meso->abundance()); - mesoItem->setPosition(meso->particlePosition()); - setFormFactor(mesoItem, meso->outerShape()); - setRotation(mesoItem, meso->rotation()); + auto* item = new MesocrystalItem(&matItems); + item->setAbundance(meso->abundance()); + item->setPosition(meso->particlePosition()); + setFormFactor(item, meso->outerShape()); + setRotation(item, meso->rotation()); const Lattice3D* lattice = meso->particleStructure().lattice(); - mesoItem->setRawDataVectorA(lattice->basisVectorA()); - mesoItem->setRawDataVectorB(lattice->basisVectorB()); - mesoItem->setRawDataVectorC(lattice->basisVectorC()); - addToParent(mesoItem); + item->setRawDataVectorA(lattice->basisVectorA()); + item->setRawDataVectorB(lattice->basisVectorB()); + item->setRawDataVectorC(lattice->basisVectorC()); + addToParent(item); copyParticle(meso->particleStructure().basis(), matItems, - [=](ItemWithParticles* p) { mesoItem->setBasis(p); }); + [=](ItemWithParticles* p) { item->setBasis(p); }); } else if (const auto* particleComposition = dynamic_cast<const Compound*>(iparticle)) { - auto* particleCompositionItem = new CompoundItem(&matItems); + auto* item = new CompoundItem(&matItems); - particleCompositionItem->setAbundance(particleComposition->abundance()); - particleCompositionItem->setPosition(particleComposition->particlePosition()); - setRotation(particleCompositionItem, particleComposition->rotation()); - addToParent(particleCompositionItem); + item->setAbundance(particleComposition->abundance()); + item->setPosition(particleComposition->particlePosition()); + setRotation(item, particleComposition->rotation()); + addToParent(item); for (const auto* p : particleComposition->particles()) - copyParticle(p, matItems, - [=](ItemWithParticles* p) { particleCompositionItem->addParticle(p); }); + copyParticle(p, matItems, [=](ItemWithParticles* p) { item->addParticle(p); }); } } diff --git a/GUI/View/Realspace/RealspaceBuilder.cpp b/GUI/View/Realspace/RealspaceBuilder.cpp index b4bafc877e91c4a2d8d2d639d0f33d530ec78b12..ca68d7b2f5b8d3f7deede855fdaa7cd1539692f8 100644 --- a/GUI/View/Realspace/RealspaceBuilder.cpp +++ b/GUI/View/Realspace/RealspaceBuilder.cpp @@ -163,8 +163,8 @@ void RealspaceBuilder::populateLayout(Img3D::Model* model, const ParticleLayoutI auto particle3DContainer_vector = m_builderUtils->particle3DContainerVector(layoutItem, origin); const auto latticePositions = generatePositions(layoutItem, layer_size, total_density); - populateParticlesAtLatticePositions( - latticePositions, particle3DContainer_vector, model, sceneGeometry, this); + populateParticlesAtLatticePositions(latticePositions, particle3DContainer_vector, model, + sceneGeometry, this); } void RealspaceBuilder::populateParticleFromParticleItem(Img3D::Model* model, diff --git a/GUI/View/Realspace/RealspaceBuilderUtils.cpp b/GUI/View/Realspace/RealspaceBuilderUtils.cpp index 7069b986b92ac87511842f715802b2b1ec4ad1c2..87fcb6227dac7dfaab541cf391c18bcc70898672 100644 --- a/GUI/View/Realspace/RealspaceBuilderUtils.cpp +++ b/GUI/View/Realspace/RealspaceBuilderUtils.cpp @@ -52,8 +52,7 @@ R3 to_kvector(const F3& origin) //! Apply transformations (translation, rotation) to a 3D Particle //! or to a particle belonging to a Compound -void applyParticleTransformations(const Particle& particle, - Img3D::Particles::Particle& particle3D, +void applyParticleTransformations(const Particle& particle, Img3D::Particles::Particle& particle3D, const R3& origin) { // rotation @@ -77,8 +76,7 @@ void applyParticleTransformations(const Particle& particle, //! Apply transformations (translation, rotation) to a particle (core/shell) in a CoreAndShell void applyCoreAndShellTransformations(const Particle& particle, Img3D::Particles::Particle& particle3D, - const CoreAndShell& particleCoreShell, - const R3& origin) + const CoreAndShell& particleCoreShell, const R3& origin) { std::unique_ptr<Particle> P_clone(particle.clone()); // clone of the current particle @@ -293,8 +291,7 @@ Img3D::BuilderUtils::mesocrystal3DContainer(const MesocrystalItem& mesocrystalIt particleComposition3DContainer(*particleComposition, 1.0, origin); } else if (dynamic_cast<const CoreAndShell*>(particleBasis.get())) { const auto* particleCoreShell = dynamic_cast<const CoreAndShell*>(particleBasis.get()); - mesocrystalBasis3DContainer = - particleCoreShell3DContainer(*particleCoreShell, 1.0, origin); + mesocrystalBasis3DContainer = particleCoreShell3DContainer(*particleCoreShell, 1.0, origin); } else if (dynamic_cast<const Mesocrystal*>(particleBasis.get())) { // TODO: Implement method to populate Mesocrystal from CORE and NOT from MesocrystalItem // as it is done currently in Img3D::BuilderUtils::mesocrystal3DContainer @@ -304,8 +301,7 @@ Img3D::BuilderUtils::mesocrystal3DContainer(const MesocrystalItem& mesocrystalIt throw std::runtime_error(ostr.str()); } else { const auto* particle = dynamic_cast<const Particle*>(particleBasis.get()); - mesocrystalBasis3DContainer = - singleParticle3DContainer(*particle, 1.0, origin); + mesocrystalBasis3DContainer = singleParticle3DContainer(*particle, 1.0, origin); } Particle3DContainer result; @@ -326,8 +322,8 @@ Img3D::BuilderUtils::mesocrystal3DContainer(const MesocrystalItem& mesocrystalIt particle3D->addTranslation(Img3D::F3fromR3(mesocrystal_translation)); - result.addParticle( - particle3D.release(), mesocrystalBasis3DContainer.particle3DBlend(it)); + result.addParticle(particle3D.release(), + mesocrystalBasis3DContainer.particle3DBlend(it)); } } } @@ -336,9 +332,8 @@ Img3D::BuilderUtils::mesocrystal3DContainer(const MesocrystalItem& mesocrystalIt // Add outer shape for visualization auto outerShape3D = GUI::View::TransformTo3D::createParticlefromFormfactor(outerShapeff.get()); - outerShape3D->addTransform( - Img3D::Tool::EulerAngles(mesocrystal_rotation), - Img3D::F3fromR3(mesocrystal_translation)); + outerShape3D->addTransform(Img3D::Tool::EulerAngles(mesocrystal_rotation), + Img3D::F3fromR3(mesocrystal_translation)); // assign grey (default) color to the outer shape QColor color = {}; diff --git a/GUI/View/Realspace/RealspaceTool.cpp b/GUI/View/Realspace/RealspaceTool.cpp index 3b64c94c44090972940af0fdc0ac6a182a9495ec..6bea15dbd64ea6d354235c58436a5f50e3776656 100644 --- a/GUI/View/Realspace/RealspaceTool.cpp +++ b/GUI/View/Realspace/RealspaceTool.cpp @@ -18,9 +18,9 @@ #include "GUI/Model/Sample/ParticleItem.h" #include "GUI/Model/Sample/ParticleLayoutItem.h" #include "Sample/HardParticle/HardParticles.h" +#include "Sample/Particle/Mesocrystal.h" #include "Sample/Particle/Particle.h" #include "Sample/Scattering/Rotations.h" -#include "Sample/Particle/Mesocrystal.h" Img3D::F3 Img3D::Tool::EulerAngles(const IRotation*& rotation) { @@ -163,8 +163,7 @@ bool Img3D::Tool::isPositionInsideMesocrystal(const IFormFactor* outerShape, R3 ostr << "Sorry, outer shape Dodecahedron not yet implemented for Mesocrystal"; ostr << "\n\nStay tuned!"; throw std::runtime_error(ostr.str()); - } else if (const auto* ff = - dynamic_cast<const EllipsoidalCylinder*>(outerShape)) { + } else if (const auto* ff = dynamic_cast<const EllipsoidalCylinder*>(outerShape)) { double a = ff->radiusX(); // semi-axis length along x double b = ff->radiusY(); // semi-axis length along y double H = ff->height(); diff --git a/GUI/View/Realspace/RealspaceTool.h b/GUI/View/Realspace/RealspaceTool.h index bb86805454a11b3a951c9b9606253080a60c96c8..14cdee15469c59d3ca1e23f4c10f52eac75a392b 100644 --- a/GUI/View/Realspace/RealspaceTool.h +++ b/GUI/View/Realspace/RealspaceTool.h @@ -33,6 +33,6 @@ QVector<double> cumulativeAbundances(const ParticleLayoutItem& layoutItem); bool isPositionInsideMesocrystal(const IFormFactor* outerShape, R3 positionInside); -} // namespace Tool +} // namespace Img3D::Tool #endif // BORNAGAIN_GUI_VIEW_REALSPACE_REALSPACETOOL_H diff --git a/GUI/View/Realspace/TransformTo3D.cpp b/GUI/View/Realspace/TransformTo3D.cpp index 46e3e768cb9f0d8591cc30623bfa68c25cd9d6bc..868f15c559075888c4c977a555a5eb4d6a23add6 100644 --- a/GUI/View/Realspace/TransformTo3D.cpp +++ b/GUI/View/Realspace/TransformTo3D.cpp @@ -56,181 +56,181 @@ GUI::View::TransformTo3D::createLayer(const LayerItem& layerItem, } std::unique_ptr<Img3D::Particles::Particle> -GUI::View::TransformTo3D::createParticlefromFormfactor(const IFormFactor* ff) +GUI::View::TransformTo3D::createParticlefromFormfactor(const IFormFactor* ff_arg) { - if (const auto* ff_Pyramid2 = dynamic_cast<const Pyramid2*>(ff)) { - double length = ff_Pyramid2->length(); - double width = ff_Pyramid2->width(); - double height = ff_Pyramid2->height(); - double alpha = ff_Pyramid2->alpha(); + if (const auto* ff = dynamic_cast<const Pyramid2*>(ff_arg)) { + double length = ff->length(); + double width = ff->width(); + double height = ff->height(); + double alpha = ff->alpha(); return std::make_unique<Img3D::Particles::Pyramid2>(length, width, height, alpha); } - if (const auto* ff_BarGauss = dynamic_cast<const BarGauss*>(ff)) { - double length = ff_BarGauss->length(); - double width = ff_BarGauss->width(); - double height = ff_BarGauss->height(); + if (const auto* ff = dynamic_cast<const BarGauss*>(ff_arg)) { + double length = ff->length(); + double width = ff->width(); + double height = ff->height(); return std::make_unique<Img3D::Particles::BarGauss>(length, width, height); } - if (const auto* ff_BarLorentz = dynamic_cast<const BarLorentz*>(ff)) { - double length = ff_BarLorentz->length(); - double width = ff_BarLorentz->width(); - double height = ff_BarLorentz->height(); + if (const auto* ff = dynamic_cast<const BarLorentz*>(ff_arg)) { + double length = ff->length(); + double width = ff->width(); + double height = ff->height(); return std::make_unique<Img3D::Particles::BarLorentz>(length, width, height); } - if (const auto* ff_Box = dynamic_cast<const Box*>(ff)) { - double length = ff_Box->length(); - double width = ff_Box->width(); - double height = ff_Box->height(); + if (const auto* ff = dynamic_cast<const Box*>(ff_arg)) { + double length = ff->length(); + double width = ff->width(); + double height = ff->height(); return std::make_unique<Img3D::Particles::Box>(length, width, height); } - if (const auto* ff_Cone = dynamic_cast<const Cone*>(ff)) { - double radius = ff_Cone->radius(); - double height = ff_Cone->height(); - double alpha = ff_Cone->alpha(); + if (const auto* ff = dynamic_cast<const Cone*>(ff_arg)) { + double radius = ff->radius(); + double height = ff->height(); + double alpha = ff->alpha(); return std::make_unique<Img3D::Particles::Cone>(radius, height, alpha); } - if (const auto* ff_Pyramid6 = dynamic_cast<const Pyramid6*>(ff)) { - double baseedge = ff_Pyramid6->baseEdge(); - double height = ff_Pyramid6->height(); - double alpha = ff_Pyramid6->alpha(); + if (const auto* ff = dynamic_cast<const Pyramid6*>(ff_arg)) { + double baseedge = ff->baseEdge(); + double height = ff->height(); + double alpha = ff->alpha(); return std::make_unique<Img3D::Particles::Pyramid6>(baseedge, height, alpha); } - if (const auto* ff_Bipyramid4 = dynamic_cast<const Bipyramid4*>(ff)) { - double length = ff_Bipyramid4->length(); - double height = ff_Bipyramid4->height(); - double height_ratio = ff_Bipyramid4->heightRatio(); - double alpha = ff_Bipyramid4->alpha(); + if (const auto* ff = dynamic_cast<const Bipyramid4*>(ff_arg)) { + double length = ff->length(); + double height = ff->height(); + double height_ratio = ff->heightRatio(); + double alpha = ff->alpha(); return std::make_unique<Img3D::Particles::Bipyramid4>(length, height, height_ratio, alpha); } - if (const auto* ff_Cylinder = dynamic_cast<const Cylinder*>(ff)) { - double radius = ff_Cylinder->radius(); - double height = ff_Cylinder->height(); + if (const auto* ff = dynamic_cast<const Cylinder*>(ff_arg)) { + double radius = ff->radius(); + double height = ff->height(); return std::make_unique<Img3D::Particles::Cylinder>(radius, height); } - if (const auto* ff_Dodecahedron = dynamic_cast<const Dodecahedron*>(ff)) { - double edge = ff_Dodecahedron->edge(); + if (const auto* ff = dynamic_cast<const Dodecahedron*>(ff_arg)) { + double edge = ff->edge(); return std::make_unique<Img3D::Particles::Dodecahedron>(edge); } - if (const auto* ff_EllipsoidalCylinder = dynamic_cast<const EllipsoidalCylinder*>(ff)) { - double radius_x = ff_EllipsoidalCylinder->radiusX(); - double radius_y = ff_EllipsoidalCylinder->radiusY(); - double height = ff_EllipsoidalCylinder->height(); + if (const auto* ff = dynamic_cast<const EllipsoidalCylinder*>(ff_arg)) { + double radius_x = ff->radiusX(); + double radius_y = ff->radiusY(); + double height = ff->height(); return std::make_unique<Img3D::Particles::EllipsoidalCylinder>(radius_x, radius_y, height); } - if (const auto* ff_Sphere = dynamic_cast<const Sphere*>(ff)) { - double radius = ff_Sphere->radius(); + if (const auto* ff = dynamic_cast<const Sphere*>(ff_arg)) { + double radius = ff->radius(); return std::make_unique<Img3D::Particles::Sphere>(radius); } - if (const auto* ff_Spheroid = dynamic_cast<const Spheroid*>(ff)) { - double radius = ff_Spheroid->radius(); - double height = ff_Spheroid->height(); + if (const auto* ff = dynamic_cast<const Spheroid*>(ff_arg)) { + double radius = ff->radius(); + double height = ff->height(); return std::make_unique<Img3D::Particles::Spheroid>(radius, height); } - if (const auto* ff_HemiEllipsoid = dynamic_cast<const HemiEllipsoid*>(ff)) { - double radius_x = ff_HemiEllipsoid->radiusX(); - double radius_y = ff_HemiEllipsoid->radiusY(); - double height = ff_HemiEllipsoid->height(); + if (const auto* ff = dynamic_cast<const HemiEllipsoid*>(ff_arg)) { + double radius_x = ff->radiusX(); + double radius_y = ff->radiusY(); + double height = ff->height(); return std::make_unique<Img3D::Particles::HemiEllipsoid>(radius_x, radius_y, height); } - if (const auto* ff_Icosahedron = dynamic_cast<const Icosahedron*>(ff)) { - double edge = ff_Icosahedron->edge(); + if (const auto* ff = dynamic_cast<const Icosahedron*>(ff_arg)) { + double edge = ff->edge(); return std::make_unique<Img3D::Particles::Icosahedron>(edge); } - if (const auto* ff_Prism3 = dynamic_cast<const Prism3*>(ff)) { - double baseedge = ff_Prism3->baseEdge(); - double height = ff_Prism3->height(); + if (const auto* ff = dynamic_cast<const Prism3*>(ff_arg)) { + double baseedge = ff->baseEdge(); + double height = ff->height(); return std::make_unique<Img3D::Particles::Prism3>(baseedge, height); } - if (const auto* ff_Prism6 = dynamic_cast<const Prism6*>(ff)) { - double baseedge = ff_Prism6->baseEdge(); - double height = ff_Prism6->height(); + if (const auto* ff = dynamic_cast<const Prism6*>(ff_arg)) { + double baseedge = ff->baseEdge(); + double height = ff->height(); return std::make_unique<Img3D::Particles::Prism6>(baseedge, height); } - if (const auto* ff_Pyramid4 = dynamic_cast<const Pyramid4*>(ff)) { - double baseedge = ff_Pyramid4->baseEdge(); - double height = ff_Pyramid4->height(); - double alpha = ff_Pyramid4->alpha(); + if (const auto* ff = dynamic_cast<const Pyramid4*>(ff_arg)) { + double baseedge = ff->baseEdge(); + double height = ff->height(); + double alpha = ff->alpha(); return std::make_unique<Img3D::Particles::Pyramid4>(baseedge, height, alpha); } - if (const auto* ff_CosineRippleBox = dynamic_cast<const CosineRippleBox*>(ff)) { - double length = ff_CosineRippleBox->length(); - double width = ff_CosineRippleBox->width(); - double height = ff_CosineRippleBox->height(); + if (const auto* ff = dynamic_cast<const CosineRippleBox*>(ff_arg)) { + double length = ff->length(); + double width = ff->width(); + double height = ff->height(); return std::make_unique<Img3D::Particles::CosineRippleBox>(length, width, height); } - if (const auto* ff_CosineRippleGauss = dynamic_cast<const CosineRippleGauss*>(ff)) { - double length = ff_CosineRippleGauss->length(); - double width = ff_CosineRippleGauss->width(); - double height = ff_CosineRippleGauss->height(); + if (const auto* ff = dynamic_cast<const CosineRippleGauss*>(ff_arg)) { + double length = ff->length(); + double width = ff->width(); + double height = ff->height(); return std::make_unique<Img3D::Particles::CosineRippleGauss>(length, width, height); } - if (const auto* ff_CosineRippleLorentz = dynamic_cast<const CosineRippleLorentz*>(ff)) { - double length = ff_CosineRippleLorentz->length(); - double width = ff_CosineRippleLorentz->width(); - double height = ff_CosineRippleLorentz->height(); + if (const auto* ff = dynamic_cast<const CosineRippleLorentz*>(ff_arg)) { + double length = ff->length(); + double width = ff->width(); + double height = ff->height(); return std::make_unique<Img3D::Particles::CosineRippleLorentz>(length, width, height); } - if (const auto* ff_SawtoothRippleBox = dynamic_cast<const SawtoothRippleBox*>(ff)) { - double length = ff_SawtoothRippleBox->length(); - double width = ff_SawtoothRippleBox->width(); - double height = ff_SawtoothRippleBox->height(); + if (const auto* ff = dynamic_cast<const SawtoothRippleBox*>(ff_arg)) { + double length = ff->length(); + double width = ff->width(); + double height = ff->height(); return std::make_unique<Img3D::Particles::SawtoothRippleBox>(length, width, height); } - if (const auto* ff_SawtoothRippleGauss = dynamic_cast<const SawtoothRippleGauss*>(ff)) { - double length = ff_SawtoothRippleGauss->length(); - double width = ff_SawtoothRippleGauss->width(); - double height = ff_SawtoothRippleGauss->height(); + if (const auto* ff = dynamic_cast<const SawtoothRippleGauss*>(ff_arg)) { + double length = ff->length(); + double width = ff->width(); + double height = ff->height(); return std::make_unique<Img3D::Particles::SawtoothRippleGauss>(length, width, height); } - if (const auto* ff_SawtoothRippleLorentz = dynamic_cast<const SawtoothRippleLorentz*>(ff)) { - double length = ff_SawtoothRippleLorentz->length(); - double width = ff_SawtoothRippleLorentz->width(); - double height = ff_SawtoothRippleLorentz->height(); + if (const auto* ff = dynamic_cast<const SawtoothRippleLorentz*>(ff_arg)) { + double length = ff->length(); + double width = ff->width(); + double height = ff->height(); return std::make_unique<Img3D::Particles::SawtoothRippleLorentz>(length, width, height); } - if (const auto* ff_Pyramid3 = dynamic_cast<const Pyramid3*>(ff)) { - double baseedge = ff_Pyramid3->baseEdge(); - double height = ff_Pyramid3->height(); - double alpha = ff_Pyramid3->alpha(); + if (const auto* ff = dynamic_cast<const Pyramid3*>(ff_arg)) { + double baseedge = ff->baseEdge(); + double height = ff->height(); + double alpha = ff->alpha(); return std::make_unique<Img3D::Particles::Pyramid3>(baseedge, height, alpha); } - if (const auto* ff_TruncatedCube = dynamic_cast<const TruncatedCube*>(ff)) { - double length = ff_TruncatedCube->length(); - double removed_length = ff_TruncatedCube->removedLength(); + if (const auto* ff = dynamic_cast<const TruncatedCube*>(ff_arg)) { + double length = ff->length(); + double removed_length = ff->removedLength(); return std::make_unique<Img3D::Particles::TruncatedCube>(length, removed_length); } - if (const auto* ff_TruncatedSphere = dynamic_cast<const TruncatedSphere*>(ff)) { - double radius = ff_TruncatedSphere->radius(); - double height = ff_TruncatedSphere->height(); - double deltaH = ff_TruncatedSphere->removedTop(); + if (const auto* ff = dynamic_cast<const TruncatedSphere*>(ff_arg)) { + double radius = ff->radius(); + double height = ff->height(); + double deltaH = ff->removedTop(); return std::make_unique<Img3D::Particles::TruncatedSphere>(radius, height, deltaH); } - if (const auto* ff_TruncatedSpheroid = dynamic_cast<const TruncatedSpheroid*>(ff)) { - double radius = ff_TruncatedSpheroid->radius(); - double height = ff_TruncatedSpheroid->height(); - double hfc = ff_TruncatedSpheroid->heightFlattening(); - double deltaH = ff_TruncatedSpheroid->removedTop(); + if (const auto* ff = dynamic_cast<const TruncatedSpheroid*>(ff_arg)) { + double radius = ff->radius(); + double height = ff->height(); + double hfc = ff->heightFlattening(); + double deltaH = ff->removedTop(); return std::make_unique<Img3D::Particles::TruncatedSpheroid>(radius, height, hfc, deltaH); } - if (const auto* ff_CantellatedCube = dynamic_cast<const CantellatedCube*>(ff)) { - double length = ff_CantellatedCube->length(); - double removed_length = ff_CantellatedCube->removedLength(); + if (const auto* ff = dynamic_cast<const CantellatedCube*>(ff_arg)) { + double length = ff->length(); + double removed_length = ff->removedLength(); return std::make_unique<Img3D::Particles::CantellatedCube>(length, removed_length); } - if (const auto* ff_HorizontalCylinder = dynamic_cast<const HorizontalCylinder*>(ff)) { - double radius = ff_HorizontalCylinder->radius(); - double length = ff_HorizontalCylinder->length(); - double slice_bottom = ff_HorizontalCylinder->slice_bottom(); - double slice_top = ff_HorizontalCylinder->slice_top(); + if (const auto* ff = dynamic_cast<const HorizontalCylinder*>(ff_arg)) { + double radius = ff->radius(); + double length = ff->length(); + double slice_bottom = ff->slice_bottom(); + double slice_top = ff->slice_top(); return std::make_unique<Img3D::Particles::HorizontalCylinder>(radius, length, slice_bottom, slice_top); } - if (const auto* ff_PlatonicOctahedron = dynamic_cast<const PlatonicOctahedron*>(ff)) { - double edge = ff_PlatonicOctahedron->edge(); + if (const auto* ff = dynamic_cast<const PlatonicOctahedron*>(ff_arg)) { + double edge = ff->edge(); return std::make_unique<Img3D::Particles::PlatonicOctahedron>(edge); } - if (const auto* ff_PlatonicTetrahedron = dynamic_cast<const PlatonicTetrahedron*>(ff)) { - double edge = ff_PlatonicTetrahedron->edge(); + if (const auto* ff = dynamic_cast<const PlatonicTetrahedron*>(ff_arg)) { + double edge = ff->edge(); return std::make_unique<Img3D::Particles::PlatonicTetrahedron>(edge); } return {};