BornAgain  1.19.0
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/Utils/Assert.h"
18 
19 namespace RealSpace {
20 
21 Model::Model() : defCamPos(Vector3D::_1, Vector3D::_0, Vector3D::_z) {}
22 
24 {
25  for (auto o : objects) {
26  o->model = nullptr;
27  delete o;
28  }
29 
30  for (auto o : objectsBlend) {
31  o->model = nullptr;
32  delete o;
33  }
34 }
35 
37 {
38  while (!objects.isEmpty())
39  delete objects.first();
40  emit updated(false);
41 }
42 
44 {
45  while (!objectsBlend.isEmpty())
46  delete objectsBlend.first();
47  emit updated(false);
48 }
49 
51 {
52  using namespace Particles;
53 
54  float D = 2 * R;
55 
56  switch (k) {
57  case EShape::None:
58  return nullptr;
59  case EShape::BarGauss:
60  return new BarGauss(D, D, 5 * D);
61  case EShape::BarLorentz:
62  return new BarLorentz(D, D, 5 * D);
63  case EShape::Box:
64  return new Box(D, D, D);
65  case EShape::FullSphere:
66  return new FullSphere(R);
67  case EShape::FullSpheroid:
68  return new FullSpheroid(R / 2, D);
69  case EShape::Cylinder:
70  return new Cylinder(R, D);
71  case EShape::TruncatedSphere:
72  return new TruncatedSphere(R, D / 3);
73  case EShape::TruncatedSpheroid:
74  return new TruncatedSpheroid(R, 2 * R, 1.5);
75  case EShape::Cone:
76  return new Cone(R, D, 1.3f);
77  case EShape::Icosahedron:
78  return new Icosahedron(R * IcosahedronL2R);
79  case EShape::Dodecahedron:
80  return new Dodecahedron(R * DodecahedronL2R);
81  case EShape::TruncatedCube:
82  return new TruncatedCube(D, D / 3);
83  case EShape::Prism6:
84  return new Prism6(R, D);
85  case EShape::Cone6:
86  return new Cone6(R, D, 1.3f);
87  case EShape::Pyramid:
88  return new Pyramid(D, D, 1.3f);
89  case EShape::Cuboctahedron:
90  return new Cuboctahedron(D, R * 3 / 2, 2.f / 3, 2);
91  case EShape::Prism3:
92  return new Prism3(R, D);
93  case EShape::Tetrahedron:
94  return new Tetrahedron(R, D, 1.3f);
95  case EShape::EllipsoidalCylinder:
96  return new EllipsoidalCylinder(R, R / 2, D);
97  case EShape::HemiEllipsoid:
98  return new HemiEllipsoid(R, R, D);
99  case EShape::Dot:
100  return new Dot();
101  case EShape::CosineRippleBox:
102  return new CosineRippleBox(D, D, D); // TODO ripples should be elongated
103  case EShape::CosineRippleGauss:
104  return new CosineRippleGauss(D, D, D); // TODO ripples should be elongated
105  case EShape::CosineRippleLorentz:
106  return new CosineRippleLorentz(D, D, D); // TODO ripples should be elongated
107  case EShape::SawtoothRippleBox:
108  return new SawtoothRippleBox(D, D, D); // TODO ripples should be elongated
109  case EShape::SawtoothRippleGauss:
110  return new SawtoothRippleGauss(D, D, D); // TODO ripples should be elongated
111  case EShape::SawtoothRippleLorentz:
112  return new SawtoothRippleLorentz(D, D, D); // TODO ripples should be elongated
113  case EShape::AnisoPyramid:
114  return new AnisoPyramid(R, D, D, 1.3f);
115  }
116  return nullptr;
117 }
118 
120 {
121  ASSERT(o);
122  ASSERT(!o->model);
123  o->model = this;
124  objects.append(o);
125 }
126 
128 {
129  ASSERT(o);
130  ASSERT(!o->model);
131  o->model = this;
132  objectsBlend.append(o);
133 }
134 
136 {
137  int i;
138  if ((i = objects.indexOf(o)) >= 0)
139  objects.remove(i);
140  else if ((i = objectsBlend.indexOf(o)) >= 0)
141  objectsBlend.remove(i);
142  else
143  ASSERT(false); // object not found, should not happen, bad caller!
144 
145  o->releaseGeometry();
146  o->model = nullptr;
147 }
148 
150 {
151  for (auto o : objects)
152  o->releaseGeometry();
153  for (auto o : objectsBlend)
154  o->releaseGeometry();
155 }
156 
158 {
159  if (objects.isEmpty() && objectsBlend.isEmpty())
160  return true;
161  else
162  return false;
163 }
164 
165 void Model::draw(Canvas& canvas) const
166 {
167  for (auto o : objects)
168  o->draw(canvas);
169 }
170 
171 void Model::drawBlend(Canvas& canvas) const
172 {
173  for (auto o : objectsBlend)
174  o->draw(canvas);
175 }
176 
177 } // namespace RealSpace
Defines the macro ASSERT.
#define ASSERT(condition)
Definition: Assert.h:31
Definition: Box.h:25
void updated(bool withEye)
bool modelIsEmpty()
Definition: model.cpp:157
void rem(Object *)
Definition: model.cpp:135
void add(Object *)
Definition: model.cpp:119
void draw(Canvas &) const
Definition: model.cpp:165
void addBlend(Object *)
Definition: model.cpp:127
void clearBlend()
Definition: model.cpp:43
void clearOpaque()
Definition: model.cpp:36
void releaseGeometries()
Definition: model.cpp:149
QVector< Object * > objectsBlend
Definition: model.h:59
virtual ~Model()
Definition: model.cpp:23
static Particles::Particle * newParticle(Particles::EShape k, float R)
Definition: model.cpp:50
void drawBlend(Canvas &) const
Definition: model.cpp:171
QVector< Object * > objects
Definition: model.h:59
Model * model
Definition: object.h:48
void releaseGeometry()
Definition: object.cpp:91
Defines Geometry class.
Defines Model class.
const float DodecahedronL2R
const float IcosahedronL2R