BornAgain  1.19.79
Simulate and fit neutron and x-ray scattering at grazing incidence
model.cpp
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file GUI/ba3d/model/model.cpp
6 //! @brief Implements Model class
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 
15 #include "GUI/ba3d/model/model.h"
16 #include "Base/Util/Assert.h"
18 
19 namespace GUI::RealSpace {
20 
22  : defCamPos(Vector3D::_1, Vector3D::_0, Vector3D::_z)
23 {
24 }
25 
27 {
28  for (auto* o : objects) {
29  o->model = nullptr;
30  delete o;
31  }
32 
33  for (auto* o : objectsBlend) {
34  o->model = nullptr;
35  delete o;
36  }
37 }
38 
40 {
41  while (!objects.isEmpty())
42  delete objects.first();
43  emit updated(false);
44 }
45 
47 {
48  while (!objectsBlend.isEmpty())
49  delete objectsBlend.first();
50  emit updated(false);
51 }
52 
54 {
55  using namespace Particles;
56 
57  float D = 2 * R;
58 
59  switch (k) {
60  case EShape::None:
61  return nullptr;
62  case EShape::BarGauss:
63  return new BarGauss(D, D, 5 * D);
64  case EShape::BarLorentz:
65  return new BarLorentz(D, D, 5 * D);
66  case EShape::Box:
67  return new Box(D, D, D);
68  case EShape::Sphere:
69  return new Sphere(R);
70  case EShape::Spheroid:
71  return new Spheroid(R / 2, D);
72  case EShape::Cylinder:
73  return new Cylinder(R, D);
74  case EShape::TruncatedSphere:
75  return new TruncatedSphere(R, D / 3);
76  case EShape::TruncatedSpheroid:
77  return new TruncatedSpheroid(R, 2 * R, 1.5);
78  case EShape::Cone:
79  return new Cone(R, D, 1.3f);
80  case EShape::Icosahedron:
81  return new Icosahedron(R * IcosahedronL2R);
82  case EShape::Dodecahedron:
83  return new Dodecahedron(R * DodecahedronL2R);
84  case EShape::TruncatedCube:
85  return new TruncatedCube(D, D / 3);
86  case EShape::Prism6:
87  return new Prism6(R, D);
88  case EShape::Pyramid6:
89  return new Pyramid6(R, D, 1.3f);
90  case EShape::Pyramid4:
91  return new Pyramid4(D, D, 1.3f);
92  case EShape::Bipyramid4:
93  return new Bipyramid4(D, R * 3 / 2, 2.f / 3, 2);
94  case EShape::Prism3:
95  return new Prism3(R, D);
96  case EShape::Pyramid3:
97  return new Pyramid3(R, D, 1.3f);
98  case EShape::EllipsoidalCylinder:
99  return new EllipsoidalCylinder(R, R / 2, D);
100  case EShape::HemiEllipsoid:
101  return new HemiEllipsoid(R, R, D);
102  case EShape::CosineRippleBox:
103  return new CosineRippleBox(D, D, D); // TODO ripples should be elongated
104  case EShape::CosineRippleGauss:
105  return new CosineRippleGauss(D, D, D); // TODO ripples should be elongated
106  case EShape::CosineRippleLorentz:
107  return new CosineRippleLorentz(D, D, D); // TODO ripples should be elongated
108  case EShape::SawtoothRippleBox:
109  return new SawtoothRippleBox(D, D, D); // TODO ripples should be elongated
110  case EShape::SawtoothRippleGauss:
111  return new SawtoothRippleGauss(D, D, D); // TODO ripples should be elongated
112  case EShape::SawtoothRippleLorentz:
113  return new SawtoothRippleLorentz(D, D, D); // TODO ripples should be elongated
114  case EShape::CantellatedCube:
115  return new CantellatedCube(D, D / 3);
116  case EShape::HorizontalCylinder:
117  return new HorizontalCylinder(R, D, -R, R);
118  case EShape::PlatonicOctahedron:
119  return new PlatonicOctahedron(D);
120  case EShape::PlatonicTetrahedron:
121  return new PlatonicTetrahedron(D);
122  case EShape::Pyramid2:
123  return new Pyramid2(R, D, D, 1.3f);
124  }
125  return nullptr;
126 }
127 
129 {
130  ASSERT(o);
131  ASSERT(!o->model);
132  o->model = this;
133  objects.append(o);
134 }
135 
137 {
138  ASSERT(o);
139  ASSERT(!o->model);
140  o->model = this;
141  objectsBlend.append(o);
142 }
143 
145 {
146  if (int i = objects.indexOf(o); i >= 0)
147  objects.remove(i);
148  else if (int i = objectsBlend.indexOf(o); i >= 0)
149  objectsBlend.remove(i);
150  else
151  ASSERT(false); // object not found, should not happen, bad caller!
152 
153  o->releaseGeometry();
154  o->model = nullptr;
155 }
156 
158 {
159  for (auto* o : objects)
160  o->releaseGeometry();
161  for (auto* o : objectsBlend)
162  o->releaseGeometry();
163 }
164 
166 {
167  return objects.isEmpty() && objectsBlend.isEmpty();
168 }
169 
170 void Model::draw(Canvas& canvas) const
171 {
172  for (auto* o : objects)
173  o->draw(canvas);
174 }
175 
176 void Model::drawBlend(Canvas& canvas) const
177 {
178  for (auto* o : objectsBlend)
179  o->draw(canvas);
180 }
181 
182 } // namespace GUI::RealSpace
QVector< Object * > objectsBlend
Definition: model.h:58
static Particles::Particle * newParticle(Particles::EShape k, float R)
Definition: model.cpp:53
void addBlend(Object *)
add a transparent object, the model takes ownership
Definition: model.cpp:136
~Model() override
Definition: model.cpp:26
void add(Object *)
add an opaque object, the model takes ownership
Definition: model.cpp:128
void draw(Canvas &) const
Definition: model.cpp:170
void drawBlend(Canvas &) const
Definition: model.cpp:176
void updated(bool withEye)
void releaseGeometries()
may be called any time
Definition: model.cpp:157
QVector< Object * > objects
Definition: model.h:58
void rem(Object *)
removes an object, the caller becomes responsible
Definition: model.cpp:144
A geometric object.
Definition: object.h:28
Defines Geometry class.
Defines Model class.
const float DodecahedronL2R
const float IcosahedronL2R