BornAgain  1.19.79
Simulate and fit neutron and x-ray scattering at grazing incidence
TransformTo3D.cpp
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file GUI/View/Realspace/TransformTo3D.cpp
6 //! @brief Implements namespace GUI::View::TransformTo3D
7 //!
8 //! @homepage http://www.bornagainproject.org
9 //! @license GNU General Public License v3 or higher (see COPYING)
10 //! @copyright Forschungszentrum Jülich GmbH 2018
11 //! @authors Scientific Computing Group at MLZ (see CITATION, AUTHORS)
12 //
13 // ************************************************************************************************
14 
21 #include "Sample/HardParticle/HardParticles.h"
22 
23 
25  const SceneGeometry& sceneGeometry)
26 {
27  double thickness(0.0);
28  if (layerItem.isTopLayer() || layerItem.isBottomLayer())
29  thickness = sceneGeometry.topOrBottomLayerThickness;
30  else
31  thickness = layerItem.thickness();
32 
33  return thickness == 0.0 ? sceneGeometry.layerMinimumThickness : thickness;
34 }
35 
36 std::unique_ptr<GUI::RealSpace::Layer>
38  const SceneGeometry& sceneGeometry, const QVector3D& origin)
39 {
40  double thickness = GUI::View::TransformTo3D::visualLayerThickness(layerItem, sceneGeometry);
41 
42  double s2 = sceneGeometry.layerSize;
43  auto ztop = static_cast<double>(origin.z());
44  double zbottom = static_cast<double>(origin.z()) - thickness;
45 
46  std::unique_ptr<GUI::RealSpace::Layer> result =
47  std::make_unique<GUI::RealSpace::Layer>(GUI::RealSpace::VectorRange(
48  GUI::RealSpace::Range(static_cast<float>(-s2), static_cast<float>(+s2)),
49  GUI::RealSpace::Range(static_cast<float>(-s2), static_cast<float>(+s2)),
50  GUI::RealSpace::Range(static_cast<float>(ztop), static_cast<float>(zbottom))));
51 
52  QColor color = layerItem.materialColor();
53  color.setAlphaF(.3);
54 
55  result->color = color;
56 
57  return result;
58 }
59 
60 std::unique_ptr<GUI::RealSpace::Particles::Particle>
62 {
63  if (const auto* ff_Pyramid2 = dynamic_cast<const Pyramid2*>(ff)) {
64  double length = ff_Pyramid2->length();
65  double width = ff_Pyramid2->width();
66  double height = ff_Pyramid2->height();
67  double alpha = ff_Pyramid2->alpha();
68  return std::make_unique<GUI::RealSpace::Particles::Pyramid2>(length, width, height, alpha);
69  }
70  if (const auto* ff_BarGauss = dynamic_cast<const BarGauss*>(ff)) {
71  double length = ff_BarGauss->length();
72  double width = ff_BarGauss->width();
73  double height = ff_BarGauss->height();
74  return std::make_unique<GUI::RealSpace::Particles::BarGauss>(length, width, height);
75  }
76  if (const auto* ff_BarLorentz = dynamic_cast<const BarLorentz*>(ff)) {
77  double length = ff_BarLorentz->length();
78  double width = ff_BarLorentz->width();
79  double height = ff_BarLorentz->height();
80  return std::make_unique<GUI::RealSpace::Particles::BarLorentz>(length, width, height);
81  }
82  if (const auto* ff_Box = dynamic_cast<const Box*>(ff)) {
83  double length = ff_Box->length();
84  double width = ff_Box->width();
85  double height = ff_Box->height();
86  return std::make_unique<GUI::RealSpace::Particles::Box>(length, width, height);
87  }
88  if (const auto* ff_Cone = dynamic_cast<const Cone*>(ff)) {
89  double radius = ff_Cone->radius();
90  double height = ff_Cone->height();
91  double alpha = ff_Cone->alpha();
92  return std::make_unique<GUI::RealSpace::Particles::Cone>(radius, height, alpha);
93  }
94  if (const auto* ff_Pyramid6 = dynamic_cast<const Pyramid6*>(ff)) {
95  double baseedge = ff_Pyramid6->baseEdge();
96  double height = ff_Pyramid6->height();
97  double alpha = ff_Pyramid6->alpha();
98  return std::make_unique<GUI::RealSpace::Particles::Pyramid6>(baseedge, height, alpha);
99  }
100  if (const auto* ff_Bipyramid4 = dynamic_cast<const Bipyramid4*>(ff)) {
101  double length = ff_Bipyramid4->length();
102  double height = ff_Bipyramid4->height();
103  double height_ratio = ff_Bipyramid4->heightRatio();
104  double alpha = ff_Bipyramid4->alpha();
105  return std::make_unique<GUI::RealSpace::Particles::Bipyramid4>(length, height, height_ratio,
106  alpha);
107  }
108  if (const auto* ff_Cylinder = dynamic_cast<const Cylinder*>(ff)) {
109  double radius = ff_Cylinder->radius();
110  double height = ff_Cylinder->height();
111  return std::make_unique<GUI::RealSpace::Particles::Cylinder>(radius, height);
112  }
113  if (const auto* ff_Dodecahedron = dynamic_cast<const Dodecahedron*>(ff)) {
114  double edge = ff_Dodecahedron->edge();
115  return std::make_unique<GUI::RealSpace::Particles::Dodecahedron>(edge);
116  }
117  if (const auto* ff_EllipsoidalCylinder = dynamic_cast<const EllipsoidalCylinder*>(ff)) {
118  double radius_x = ff_EllipsoidalCylinder->radiusX();
119  double radius_y = ff_EllipsoidalCylinder->radiusY();
120  double height = ff_EllipsoidalCylinder->height();
121  return std::make_unique<GUI::RealSpace::Particles::EllipsoidalCylinder>(radius_x, radius_y,
122  height);
123  }
124  if (const auto* ff_Sphere = dynamic_cast<const Sphere*>(ff)) {
125  double radius = ff_Sphere->radius();
126  return std::make_unique<GUI::RealSpace::Particles::Sphere>(radius);
127  }
128  if (const auto* ff_Spheroid = dynamic_cast<const Spheroid*>(ff)) {
129  double radius = ff_Spheroid->radius();
130  double height = ff_Spheroid->height();
131  return std::make_unique<GUI::RealSpace::Particles::Spheroid>(radius, height);
132  }
133  if (const auto* ff_HemiEllipsoid = dynamic_cast<const HemiEllipsoid*>(ff)) {
134  double radius_x = ff_HemiEllipsoid->radiusX();
135  double radius_y = ff_HemiEllipsoid->radiusY();
136  double height = ff_HemiEllipsoid->height();
137  return std::make_unique<GUI::RealSpace::Particles::HemiEllipsoid>(radius_x, radius_y,
138  height);
139  }
140  if (const auto* ff_Icosahedron = dynamic_cast<const Icosahedron*>(ff)) {
141  double edge = ff_Icosahedron->edge();
142  return std::make_unique<GUI::RealSpace::Particles::Icosahedron>(edge);
143  }
144  if (const auto* ff_Prism3 = dynamic_cast<const Prism3*>(ff)) {
145  double baseedge = ff_Prism3->baseEdge();
146  double height = ff_Prism3->height();
147  return std::make_unique<GUI::RealSpace::Particles::Prism3>(baseedge, height);
148  }
149  if (const auto* ff_Prism6 = dynamic_cast<const Prism6*>(ff)) {
150  double baseedge = ff_Prism6->baseEdge();
151  double height = ff_Prism6->height();
152  return std::make_unique<GUI::RealSpace::Particles::Prism6>(baseedge, height);
153  }
154  if (const auto* ff_Pyramid4 = dynamic_cast<const Pyramid4*>(ff)) {
155  double baseedge = ff_Pyramid4->baseEdge();
156  double height = ff_Pyramid4->height();
157  double alpha = ff_Pyramid4->alpha();
158  return std::make_unique<GUI::RealSpace::Particles::Pyramid4>(baseedge, height, alpha);
159  }
160  if (const auto* ff_CosineRippleBox = dynamic_cast<const CosineRippleBox*>(ff)) {
161  double length = ff_CosineRippleBox->length();
162  double width = ff_CosineRippleBox->width();
163  double height = ff_CosineRippleBox->height();
164  return std::make_unique<GUI::RealSpace::Particles::CosineRippleBox>(length, width, height);
165  }
166  if (const auto* ff_CosineRippleGauss = dynamic_cast<const CosineRippleGauss*>(ff)) {
167  double length = ff_CosineRippleGauss->length();
168  double width = ff_CosineRippleGauss->width();
169  double height = ff_CosineRippleGauss->height();
170  return std::make_unique<GUI::RealSpace::Particles::CosineRippleGauss>(length, width,
171  height);
172  }
173  if (const auto* ff_CosineRippleLorentz = dynamic_cast<const CosineRippleLorentz*>(ff)) {
174  double length = ff_CosineRippleLorentz->length();
175  double width = ff_CosineRippleLorentz->width();
176  double height = ff_CosineRippleLorentz->height();
177  return std::make_unique<GUI::RealSpace::Particles::CosineRippleLorentz>(length, width,
178  height);
179  }
180  if (const auto* ff_SawtoothRippleBox = dynamic_cast<const SawtoothRippleBox*>(ff)) {
181  double length = ff_SawtoothRippleBox->length();
182  double width = ff_SawtoothRippleBox->width();
183  double height = ff_SawtoothRippleBox->height();
184  return std::make_unique<GUI::RealSpace::Particles::SawtoothRippleBox>(length, width,
185  height);
186  }
187  if (const auto* ff_SawtoothRippleGauss = dynamic_cast<const SawtoothRippleGauss*>(ff)) {
188  double length = ff_SawtoothRippleGauss->length();
189  double width = ff_SawtoothRippleGauss->width();
190  double height = ff_SawtoothRippleGauss->height();
191  return std::make_unique<GUI::RealSpace::Particles::SawtoothRippleGauss>(length, width,
192  height);
193  }
194  if (const auto* ff_SawtoothRippleLorentz = dynamic_cast<const SawtoothRippleLorentz*>(ff)) {
195  double length = ff_SawtoothRippleLorentz->length();
196  double width = ff_SawtoothRippleLorentz->width();
197  double height = ff_SawtoothRippleLorentz->height();
198  return std::make_unique<GUI::RealSpace::Particles::SawtoothRippleLorentz>(length, width,
199  height);
200  }
201  if (const auto* ff_Pyramid3 = dynamic_cast<const Pyramid3*>(ff)) {
202  double baseedge = ff_Pyramid3->baseEdge();
203  double height = ff_Pyramid3->height();
204  double alpha = ff_Pyramid3->alpha();
205  return std::make_unique<GUI::RealSpace::Particles::Pyramid3>(baseedge, height, alpha);
206  }
207  if (const auto* ff_TruncatedCube = dynamic_cast<const TruncatedCube*>(ff)) {
208  double length = ff_TruncatedCube->length();
209  double removed_length = ff_TruncatedCube->removedLength();
210  return std::make_unique<GUI::RealSpace::Particles::TruncatedCube>(length, removed_length);
211  }
212  if (const auto* ff_TruncatedSphere = dynamic_cast<const TruncatedSphere*>(ff)) {
213  double radius = ff_TruncatedSphere->radius();
214  double height = ff_TruncatedSphere->height();
215  double deltaH = ff_TruncatedSphere->removedTop();
216  return std::make_unique<GUI::RealSpace::Particles::TruncatedSphere>(radius, height, deltaH);
217  }
218  if (const auto* ff_TruncatedSpheroid = dynamic_cast<const TruncatedSpheroid*>(ff)) {
219  double radius = ff_TruncatedSpheroid->radius();
220  double height = ff_TruncatedSpheroid->height();
221  double hfc = ff_TruncatedSpheroid->heightFlattening();
222  double deltaH = ff_TruncatedSpheroid->removedTop();
223  return std::make_unique<GUI::RealSpace::Particles::TruncatedSpheroid>(radius, height, hfc,
224  deltaH);
225  }
226  if (const auto* ff_CantellatedCube = dynamic_cast<const CantellatedCube*>(ff)) {
227  double length = ff_CantellatedCube->length();
228  double removed_length = ff_CantellatedCube->removedLength();
229  return std::make_unique<GUI::RealSpace::Particles::CantellatedCube>(length, removed_length);
230  }
231  if (const auto* ff_HorizontalCylinder = dynamic_cast<const HorizontalCylinder*>(ff)) {
232  double radius = ff_HorizontalCylinder->radius();
233  double length = ff_HorizontalCylinder->length();
234  double slice_bottom = ff_HorizontalCylinder->slice_bottom();
235  double slice_top = ff_HorizontalCylinder->slice_top();
236  return std::make_unique<GUI::RealSpace::Particles::HorizontalCylinder>(
237  radius, length, slice_bottom, slice_top);
238  }
239  if (const auto* ff_PlatonicOctahedron = dynamic_cast<const PlatonicOctahedron*>(ff)) {
240  double edge = ff_PlatonicOctahedron->edge();
241  return std::make_unique<GUI::RealSpace::Particles::PlatonicOctahedron>(edge);
242  }
243  if (const auto* ff_PlatonicTetrahedron = dynamic_cast<const PlatonicTetrahedron*>(ff)) {
244  double edge = ff_PlatonicTetrahedron->edge();
245  return std::make_unique<GUI::RealSpace::Particles::PlatonicTetrahedron>(edge);
246  }
247  return {};
248 }
Defines FormFactorItems classes.
Defines class LayerItem.
Defines class MultiLayerItem.
Defines class ParticleItem.
Defines class RealSpaceCanvas.
Defines namespace GUI::View::TransformTo3D.
QColor materialColor() const
bool isTopLayer() const
Definition: LayerItem.cpp:168
bool isBottomLayer() const
Definition: LayerItem.cpp:178
DoubleDescriptor thickness() const
Definition: LayerItem.cpp:97
std::unique_ptr< GUI::RealSpace::Layer > createLayer(const LayerItem &layerItem, const SceneGeometry &sceneGeometry, const QVector3D &origin={})
double visualLayerThickness(const LayerItem &layerItem, const SceneGeometry &sceneGeometry)
std::unique_ptr< GUI::RealSpace::Particles::Particle > createParticlefromFormfactor(const IFormFactor *ff)
Range of float.
Definition: def.h:61
Range of coordinates.
Definition: def.h:70
Size and thickness information of layers.
double topOrBottomLayerThickness
double layerMinimumThickness