pol.cpp 18.6 KB
Newer Older
1
2
3
4
5
/**
 * Calculation of polarisation vector
 * @author Tobias Weber <tweber@ill.fr>
 * @date Oct-2018
 * @license GPLv3, see 'LICENSE' file
Tobias WEBER's avatar
Tobias WEBER committed
6
 * @desc The present version was forked on 8-Nov-2018 from my privately developed "magtools" project (https://github.com/t-weber/magtools).
7
8
9
 */

#include <QtCore/QSettings>
Tobias WEBER's avatar
Tobias WEBER committed
10
#include <QtCore/QDir>
11
12
13
14
15
16
17
18
19
20
#include <QtWidgets/QApplication>
#include <QtWidgets/QGridLayout>
#include <QtWidgets/QLabel>
#include <QtWidgets/QLineEdit>
#include <QtWidgets/QTabWidget>

#include <locale>
#include <iostream>
#include <vector>
#include <string>
Tobias WEBER's avatar
Tobias WEBER committed
21
#include <optional>
22

Tobias WEBER's avatar
Tobias WEBER committed
23
#include "libs/glplot.h"
Tobias WEBER's avatar
Tobias WEBER committed
24
#include "libs/math20.h"
Tobias WEBER's avatar
Tobias WEBER committed
25
#include "libs/helper.h"
26
27
28
29
30
31
32

#include <boost/version.hpp>
#include <boost/config.hpp>
#include <boost/algorithm/string/replace.hpp>
namespace algo = boost::algorithm;


Tobias WEBER's avatar
Tobias WEBER committed
33
using namespace tl2_ops;
34
35
36

using t_real = double;
using t_cplx = std::complex<t_real>;
Tobias WEBER's avatar
Tobias WEBER committed
37
using t_vec = tl2::vec<t_cplx, std::vector>;
Tobias WEBER's avatar
Tobias WEBER committed
38
using t_mat = tl2::mat<t_cplx, std::vector>;
39
40
41
42
43
44
45
46
47
48
using t_matvec = std::vector<t_mat>;


// ----------------------------------------------------------------------------
class PolDlg : public QDialog
{ /*Q_OBJECT*/
private:
	QSettings m_sett{"tobis_stuff", "pol"};

	std::shared_ptr<GlPlot> m_plot{std::make_shared<GlPlot>(this)};
Tobias WEBER's avatar
Tobias WEBER committed
49
	QLabel *m_labelGlInfos[4] = { nullptr, nullptr, nullptr, nullptr };
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78

	QLineEdit* m_editNRe = new QLineEdit("0", this);
	QLineEdit* m_editNIm = new QLineEdit("0", this);

	QLineEdit* m_editMPerpReX = new QLineEdit("0", this);
	QLineEdit* m_editMPerpReY = new QLineEdit("1", this);
	QLineEdit* m_editMPerpReZ = new QLineEdit("0", this);
	QLineEdit* m_editMPerpImX = new QLineEdit("0", this);
	QLineEdit* m_editMPerpImY = new QLineEdit("0", this);
	QLineEdit* m_editMPerpImZ = new QLineEdit("0", this);

	QLineEdit* m_editPiX = new QLineEdit("1", this);
	QLineEdit* m_editPiY = new QLineEdit("0", this);
	QLineEdit* m_editPiZ = new QLineEdit("0", this);
	QLineEdit* m_editPfX = new QLineEdit(this);
	QLineEdit* m_editPfY = new QLineEdit(this);
	QLineEdit* m_editPfZ = new QLineEdit(this);

	QLabel* m_labelStatus = new QLabel(this);


	// 3d object handles
	std::size_t m_arrow_pi = 0;
	std::size_t m_arrow_pf = 0;
	std::size_t m_arrow_M_Re = 0;
	std::size_t m_arrow_M_Im = 0;

	bool m_3dobjsReady = false;
	bool m_mouseDown[3] = {false, false, false};
Tobias WEBER's avatar
Tobias WEBER committed
79
80
	std::optional<std::size_t> m_curPickedObj{};
	std::optional<std::size_t> m_curDraggedObj{};
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110


protected:
	virtual void closeEvent(QCloseEvent *evt) override
	{
		// save window size and position
		m_sett.setValue("geo", saveGeometry());

		// save values
		m_sett.setValue("n_re", m_editNRe->text().toDouble());
		m_sett.setValue("n_im", m_editNIm->text().toDouble());
		m_sett.setValue("mx_re", m_editMPerpReX->text().toDouble());
		m_sett.setValue("my_re", m_editMPerpReY->text().toDouble());
		m_sett.setValue("mz_re", m_editMPerpReZ->text().toDouble());
		m_sett.setValue("mx_im", m_editMPerpImX->text().toDouble());
		m_sett.setValue("my_im", m_editMPerpImY->text().toDouble());
		m_sett.setValue("mz_im", m_editMPerpImZ->text().toDouble());
		m_sett.setValue("pix", m_editPiX->text().toDouble());
		m_sett.setValue("piy", m_editPiY->text().toDouble());
		m_sett.setValue("piz", m_editPiZ->text().toDouble());
	}


protected slots:
	/**
	 * called after the plotter has initialised
	 */
	void AfterGLInitialisation()
	{
		// GL device info
Tobias WEBER's avatar
Tobias WEBER committed
111
112
113
114
115
116
		auto [strGlVer, strGlShaderVer, strGlVendor, strGlRenderer]
			= m_plot->GetImpl()->GetGlDescr();
		m_labelGlInfos[0]->setText(QString("GL Version: ") + strGlVer.c_str() + QString("."));
		m_labelGlInfos[1]->setText(QString("GL Shader Version: ") + strGlShaderVer.c_str() + QString("."));
		m_labelGlInfos[2]->setText(QString("GL Vendor: ") + strGlVendor.c_str() + QString("."));
		m_labelGlInfos[3]->setText(QString("GL Device: ") + strGlRenderer.c_str() + QString("."));
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175


		if(!m_3dobjsReady)		// create 3d objects
		{
			m_arrow_pi = m_plot->GetImpl()->AddArrow(0.05, 1., 0.,0.,0.5,  0.,0.,0.85,1.);
			m_arrow_pf = m_plot->GetImpl()->AddArrow(0.05, 1., 0.,0.,0.5,  0.,0.5,0.,1.);
			m_arrow_M_Re = m_plot->GetImpl()->AddArrow(0.05, 1., 0.,0.,0.5,  0.85,0.,0.,1.);
			m_arrow_M_Im = m_plot->GetImpl()->AddArrow(0.05, 1., 0.,0.,0.5,  0.85,0.25,0.,1.);

			m_plot->GetImpl()->SetObjectLabel(m_arrow_pi, "P_i");
			m_plot->GetImpl()->SetObjectLabel(m_arrow_pf, "P_f");
			m_plot->GetImpl()->SetObjectLabel(m_arrow_M_Re, "Re{M_perp}");
			m_plot->GetImpl()->SetObjectLabel(m_arrow_M_Im, "Im{M_perp}");

			m_3dobjsReady = true;
			CalcPol();
		}
	}


	/**
	 * get the length of a vector
	 */
	t_real GetArrowLen(std::size_t objIdx) const
	{
		if(objIdx == m_arrow_pi)
		{
			return std::sqrt(std::pow(m_editPiX->text().toDouble(), 2.)
				+ std::pow(m_editPiY->text().toDouble(), 2.)
				+ std::pow(m_editPiZ->text().toDouble(), 2.));
		}
		else if(objIdx == m_arrow_pf)
		{
			return std::sqrt(std::pow(m_editPfX->text().toDouble(), 2.)
				+ std::pow(m_editPfY->text().toDouble(), 2.)
				+ std::pow(m_editPfZ->text().toDouble(), 2.));
		}
		else if(objIdx == m_arrow_M_Re)
		{
			return std::sqrt(std::pow(m_editMPerpReX->text().toDouble(), 2.)
				+ std::pow(m_editMPerpReY->text().toDouble(), 2.)
				+ std::pow(m_editMPerpReZ->text().toDouble(), 2.));
		}
		else if(objIdx == m_arrow_M_Im)
		{
			return std::sqrt(std::pow(m_editMPerpImX->text().toDouble(), 2.)
				+ std::pow(m_editMPerpImY->text().toDouble(), 2.)
				+ std::pow(m_editMPerpImZ->text().toDouble(), 2.));
		}

		return -1.;
	}


	/**
	 * called when the mouse hovers over an object
	 */
	void PickerIntersection(const t_vec3_gl* pos, std::size_t objIdx, const t_vec3_gl* posSphere)
	{
Tobias WEBER's avatar
Tobias WEBER committed
176
177
		m_curPickedObj.reset();

178
179
		if(pos)
		{	// object selected?
Tobias WEBER's avatar
Tobias WEBER committed
180
			m_curPickedObj = objIdx;
181
182
183
184
185

			if(objIdx == m_arrow_pi) m_labelStatus->setText("P_i");
			else if(objIdx == m_arrow_pf) m_labelStatus->setText("P_f");
			else if(objIdx == m_arrow_M_Re) m_labelStatus->setText("Re{M_perp}");
			else if(objIdx == m_arrow_M_Im) m_labelStatus->setText("Im{M_perp}");
Tobias WEBER's avatar
Tobias WEBER committed
186
			else m_curPickedObj.reset();
187
188
		}

Tobias WEBER's avatar
Tobias WEBER committed
189
		if(m_curPickedObj)
190
191
192
193
194
195
196
197
198
199
		{
			setCursor(Qt::CrossCursor);
		}
		else
		{
			m_labelStatus->setText("");
			setCursor(Qt::ArrowCursor);
		}


Tobias WEBER's avatar
Tobias WEBER committed
200
		if(posSphere && m_mouseDown[0] && m_curDraggedObj)
201
202
203
204
		{	// picker intersecting unit sphere and mouse dragged?

			t_vec3_gl posSph = *posSphere;

Tobias WEBER's avatar
Tobias WEBER committed
205
			if(*m_curDraggedObj == m_arrow_pi)
206
207
208
209
210
211
			{
				m_editPiX->setText(QVariant(posSph[0]).toString());
				m_editPiY->setText(QVariant(posSph[1]).toString());
				m_editPiZ->setText(QVariant(posSph[2]).toString());
				CalcPol();
			}
Tobias WEBER's avatar
Tobias WEBER committed
212
			else if(*m_curDraggedObj == m_arrow_M_Re)
213
214
215
216
217
218
			{
				m_editMPerpReX->setText(QVariant(posSph[0]).toString());
				m_editMPerpReY->setText(QVariant(posSph[1]).toString());
				m_editMPerpReZ->setText(QVariant(posSph[2]).toString());
				CalcPol();
			}
Tobias WEBER's avatar
Tobias WEBER committed
219
			else if(*m_curDraggedObj == m_arrow_M_Im)
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
			{
				m_editMPerpImX->setText(QVariant(posSph[0]).toString());
				m_editMPerpImY->setText(QVariant(posSph[1]).toString());
				m_editMPerpImZ->setText(QVariant(posSph[2]).toString());
				CalcPol();
			}
		}
	}


	/**
	 * mouse button pressed
	 */
	void MouseDown(bool left, bool mid, bool right)
	{
		if(left) m_mouseDown[0] = true;
		if(mid) m_mouseDown[1] = true;
		if(right) m_mouseDown[2] = true;

		if(m_mouseDown[0])
		{
Tobias WEBER's avatar
Tobias WEBER committed
241
242
243
244
245
246
			if((m_curDraggedObj = m_curPickedObj))
			{
				auto lenVec = GetArrowLen(*m_curDraggedObj);
				if(lenVec > 0.)
					m_plot->GetImpl()->SetPickerSphereRadius(lenVec);
			}
247
248
249
250
251
252
253
254
255
256
257
258
259
260
		}
	}


	/**
	 * mouse button released
	 */
	void MouseUp(bool left, bool mid, bool right)
	{
		if(left) m_mouseDown[0] = false;
		if(mid) m_mouseDown[1] = false;
		if(right) m_mouseDown[2] = false;

		if(!m_mouseDown[0])
Tobias WEBER's avatar
Tobias WEBER committed
261
			m_curDraggedObj.reset();
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
	}


public:
	PolDlg() = delete;

	/**
	 * create UI
	 */
	PolDlg(QWidget* pParent) : QDialog{pParent, Qt::Window}
	{
		setWindowTitle("Polarisation Vectors");
		setSizeGripEnabled(true);

		auto tabs = new QTabWidget(this);


		{	// plot panel
			auto plotpanel = new QWidget(this);

			auto labelN = new QLabel("Re{N}, Im{N}:", plotpanel);
			auto labelMPerpRe = new QLabel("Re{M_perp}:", plotpanel);
			auto labelMPerpIm = new QLabel("Im{M_perp}:", plotpanel);
			auto labelPi = new QLabel("P_i:", plotpanel);
			auto labelPf = new QLabel("P_f:", plotpanel);


			for(auto* label : {labelMPerpRe, labelMPerpIm, labelPi, labelPf})
				label->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);

			for(auto* editPf : {m_editPfX, m_editPfY, m_editPfZ})
				editPf->setReadOnly(true);

			m_labelStatus->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
			m_labelStatus->setFrameStyle(QFrame::Sunken | QFrame::Panel);
			m_labelStatus->setLineWidth(1);


			// connections
			for(auto* edit : {m_editNRe, m_editNIm,
				m_editMPerpReX, m_editMPerpReY, m_editMPerpReZ,
				m_editMPerpImX, m_editMPerpImY, m_editMPerpImZ,
				m_editPiX, m_editPiY, m_editPiZ,
				m_editPfX, m_editPfY, m_editPfZ})
				connect(edit, &QLineEdit::textEdited, this, &PolDlg::CalcPol);

			connect(m_plot.get(), &GlPlot::AfterGLInitialisation, this, &PolDlg::AfterGLInitialisation);
			connect(m_plot->GetImpl(), &GlPlot_impl::PickerIntersection, this, &PolDlg::PickerIntersection);

			connect(m_plot.get(), &GlPlot::MouseDown, this, &PolDlg::MouseDown);
			connect(m_plot.get(), &GlPlot::MouseUp, this, &PolDlg::MouseUp);


			auto pGrid = new QGridLayout(plotpanel);
			pGrid->setSpacing(4);
			pGrid->setContentsMargins(4,4,4,4);

			pGrid->addWidget(m_plot.get(), 0,0,1,4);

			pGrid->addWidget(labelN, 1,0,1,1);
			pGrid->addWidget(labelMPerpRe, 2,0,1,1);
			pGrid->addWidget(labelMPerpIm, 3,0,1,1);
			pGrid->addWidget(labelPi, 4,0,1,1);
			pGrid->addWidget(labelPf, 5,0,1,1);

			pGrid->addWidget(m_editNRe, 1,1,1,1);
			pGrid->addWidget(m_editNIm, 1,2,1,1);

			pGrid->addWidget(m_editMPerpReX, 2,1,1,1);
			pGrid->addWidget(m_editMPerpReY, 2,2,1,1);
			pGrid->addWidget(m_editMPerpReZ, 2,3,1,1);
			pGrid->addWidget(m_editMPerpImX, 3,1,1,1);
			pGrid->addWidget(m_editMPerpImY, 3,2,1,1);
			pGrid->addWidget(m_editMPerpImZ, 3,3,1,1);

			pGrid->addWidget(m_editPiX, 4,1,1,1);
			pGrid->addWidget(m_editPiY, 4,2,1,1);
			pGrid->addWidget(m_editPiZ, 4,3,1,1);
			pGrid->addWidget(m_editPfX, 5,1,1,1);
			pGrid->addWidget(m_editPfY, 5,2,1,1);
			pGrid->addWidget(m_editPfZ, 5,3,1,1);

			pGrid->addWidget(m_labelStatus, 6,0,1,4);

			// restore last values
			if(m_sett.contains("n_re")) m_editNRe->setText(m_sett.value("n_re").toString());
			if(m_sett.contains("n_im")) m_editNIm->setText(m_sett.value("n_im").toString());
			if(m_sett.contains("mx_re")) m_editMPerpReX->setText(m_sett.value("mx_re").toString());
			if(m_sett.contains("my_re")) m_editMPerpReY->setText(m_sett.value("my_re").toString());
			if(m_sett.contains("mz_re")) m_editMPerpReZ->setText(m_sett.value("mz_re").toString());
			if(m_sett.contains("mx_im")) m_editMPerpImX->setText(m_sett.value("mx_im").toString());
			if(m_sett.contains("my_im")) m_editMPerpImY->setText(m_sett.value("my_im").toString());
			if(m_sett.contains("mz_im")) m_editMPerpImZ->setText(m_sett.value("mz_im").toString());
			if(m_sett.contains("pix")) m_editPiX->setText(m_sett.value("pix").toString());
			if(m_sett.contains("piy")) m_editPiY->setText(m_sett.value("piy").toString());
			if(m_sett.contains("piz")) m_editPiZ->setText(m_sett.value("piz").toString());


			tabs->addTab(plotpanel, "Calculation");
		}


		{	// info panel
			auto infopanel = new QWidget(this);
			auto pGrid = new QGridLayout(infopanel);
			pGrid->setSpacing(4);
			pGrid->setContentsMargins(4,4,4,4);

Tobias WEBER's avatar
Tobias WEBER committed
370
371
372
			auto sep1 = new QFrame(infopanel); sep1->setFrameStyle(QFrame::HLine);
			auto sep2 = new QFrame(infopanel); sep2->setFrameStyle(QFrame::HLine);
			auto sep3 = new QFrame(infopanel); sep3->setFrameStyle(QFrame::HLine);
373

Tobias WEBER's avatar
Tobias WEBER committed
374
375
376
377
378
			for(int i=0; i<4; ++i)
			{
				m_labelGlInfos[i] = new QLabel("", infopanel);
				m_labelGlInfos[i]->setSizePolicy(QSizePolicy::Ignored, m_labelGlInfos[i]->sizePolicy().verticalPolicy());
			}
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403

			std::string strBoost = BOOST_LIB_VERSION;
			algo::replace_all(strBoost, "_", ".");

			auto labelTitle = new QLabel("Polarisation Calculator", infopanel);
			auto fontTitle = labelTitle->font();
			fontTitle.setBold(true);
			labelTitle->setFont(fontTitle);
			labelTitle->setAlignment(Qt::AlignHCenter);

			auto labelAuthor = new QLabel("Written by Tobias Weber <tweber@ill.fr>.", infopanel);
			labelAuthor->setAlignment(Qt::AlignHCenter);

			auto labelDate = new QLabel("November 2018.", infopanel);
			labelDate->setAlignment(Qt::AlignHCenter);

			int y = 0;
			pGrid->addWidget(labelTitle, y++,0, 1,1);
			pGrid->addWidget(labelAuthor, y++,0, 1,1);
			pGrid->addWidget(labelDate, y++,0, 1,1);
			pGrid->addItem(new QSpacerItem(16,16, QSizePolicy::Minimum, QSizePolicy::Fixed), y++,0, 1,1);
			pGrid->addWidget(sep1, y++,0, 1,1);
			pGrid->addWidget(new QLabel(QString("Compiler: ") + QString(BOOST_COMPILER) + ".", infopanel), y++,0, 1,1);
			pGrid->addWidget(new QLabel(QString("C++ Library: ") + QString(BOOST_STDLIB) + ".", infopanel), y++,0, 1,1);
			pGrid->addWidget(new QLabel(QString("Build Date: ") + QString(__DATE__) + ", " + QString(__TIME__) + ".", infopanel), y++,0, 1,1);
Tobias WEBER's avatar
Tobias WEBER committed
404
405
406
407
408
409
			pGrid->addWidget(sep2, y++,0, 1,1);
			pGrid->addWidget(new QLabel(QString("Qt Version: ") + QString(QT_VERSION_STR) + ".", infopanel), y++,0, 1,1);
			pGrid->addWidget(new QLabel(QString("Boost Version: ") + strBoost.c_str() + ".", infopanel), y++,0, 1,1);
			pGrid->addWidget(sep3, y++,0, 1,1);
			for(int i=0; i<4; ++i)
				pGrid->addWidget(m_labelGlInfos[i], y++,0, 1,1);
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
			pGrid->addItem(new QSpacerItem(16,16, QSizePolicy::Minimum, QSizePolicy::Expanding), y++,0, 1,1);

			tabs->addTab(infopanel, "Infos");
		}


		auto pmainGrid = new QGridLayout(this);
		pmainGrid->setSpacing(4);
		pmainGrid->setContentsMargins(4,4,4,4);
		pmainGrid->addWidget(tabs, 0,0, 1,1);


		// restory window size and position
		if(m_sett.contains("geo"))
			restoreGeometry(m_sett.value("geo").toByteArray());
		else
			resize(800, 600);

		// have scattering plane in horizontal plane
Tobias WEBER's avatar
Tobias WEBER committed
429
430
		m_plot->GetImpl()->SetLight(0, tl2::create<t_vec3_gl>({ 5, 5, 5 }));
		m_plot->GetImpl()->SetLight(1, tl2::create<t_vec3_gl>({ -5, -5, -5 }));
Tobias WEBER's avatar
Tobias WEBER committed
431
		m_plot->GetImpl()->SetCoordMax(5.);
Tobias WEBER's avatar
Tobias WEBER committed
432
433
		m_plot->GetImpl()->SetCamBase(tl2::create<t_mat_gl>({1,0,0,0,  0,0,1,0,  0,-1,0,-5,  0,0,0,1}),
			tl2::create<t_vec_gl>({1,0,0,0}), tl2::create<t_vec_gl>({0,0,1,0}));
Tobias WEBER's avatar
Tobias WEBER committed
434

435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
		CalcPol();
	}


	/**
	 * calculate final polarisation vector
	 */
	void CalcPol()
	{
		// get values from line edits
		t_real NRe = t_real(m_editNRe->text().toDouble());
		t_real NIm = t_real(m_editNIm->text().toDouble());

		t_real MPerpReX = t_real(m_editMPerpReX->text().toDouble());
		t_real MPerpReY = t_real(m_editMPerpReY->text().toDouble());
		t_real MPerpReZ = t_real(m_editMPerpReZ->text().toDouble());
		t_real MPerpImX = t_real(m_editMPerpImX->text().toDouble());
		t_real MPerpImY = t_real(m_editMPerpImY->text().toDouble());
		t_real MPerpImZ = t_real(m_editMPerpImZ->text().toDouble());

		t_real PiX = t_real(m_editPiX->text().toDouble());
		t_real PiY = t_real(m_editPiY->text().toDouble());
		t_real PiZ = t_real(m_editPiZ->text().toDouble());

		const t_cplx N(NRe, NIm);
Tobias WEBER's avatar
Tobias WEBER committed
460
		const t_vec Mperp = tl2::create<t_vec>({
461
462
463
			t_cplx(MPerpReX,MPerpImX),
			t_cplx(MPerpReY,MPerpImY),
			t_cplx(MPerpReZ,MPerpImZ) });
Tobias WEBER's avatar
Tobias WEBER committed
464
		const t_vec Pi = tl2::create<t_vec>({PiX, PiY, PiZ});
465
466

		// calculate final polarisation vector and intensity
Tobias WEBER's avatar
Tobias WEBER committed
467
468
		auto [I, P_f] = tl2::blume_maleev_indir<t_mat, t_vec, t_cplx>(Pi, Mperp, N);
		//auto [I, P_f] = tl2::blume_maleev<t_vec, t_cplx>(Pi, Mperp, N);
469
470
471
472
473
474
475
476
477
478
479
480

		// set final polarisation
		m_editPfX->setText(std::to_string(P_f[0].real()).c_str());
		m_editPfY->setText(std::to_string(P_f[1].real()).c_str());
		m_editPfZ->setText(std::to_string(P_f[2].real()).c_str());


		// update 3d objects
		if(m_3dobjsReady)
		{
			// P_i
			t_mat_gl matPi = GlPlot_impl::GetArrowMatrix(
Tobias WEBER's avatar
Tobias WEBER committed
481
				tl2::create<t_vec_gl>({t_real_gl(PiX), t_real_gl(PiY), t_real_gl(PiZ)}), 	// to
482
				1., 								// scale
Tobias WEBER's avatar
Tobias WEBER committed
483
484
				tl2::create<t_vec_gl>({0,0,0.5}),		// translate
				tl2::create<t_vec_gl>({0,0,1}));		// from
485
486
487
488
			m_plot->GetImpl()->SetObjectMatrix(m_arrow_pi, matPi);

			// P_f
			t_mat_gl matPf = GlPlot_impl::GetArrowMatrix(
Tobias WEBER's avatar
Tobias WEBER committed
489
				tl2::create<t_vec_gl>({t_real_gl(P_f[0].real()), t_real_gl(P_f[1].real()), t_real_gl(P_f[2].real())}), 	// to
490
				1., 								// scale
Tobias WEBER's avatar
Tobias WEBER committed
491
492
				tl2::create<t_vec_gl>({0,0,0.5}),		// translate
				tl2::create<t_vec_gl>({0,0,1}));		// from
493
494
495
496
497
			m_plot->GetImpl()->SetObjectMatrix(m_arrow_pf, matPf);

			// Re(M)
			const t_real_gl lenReM = t_real_gl(std::sqrt(MPerpReX*MPerpReX + MPerpReY*MPerpReY + MPerpReZ*MPerpReZ));
			t_mat_gl matMRe = GlPlot_impl::GetArrowMatrix(
Tobias WEBER's avatar
Tobias WEBER committed
498
				tl2::create<t_vec_gl>({t_real_gl(MPerpReX), t_real_gl(MPerpReY), t_real_gl(MPerpReZ)}), 	// to
499
				lenReM,								// scale
Tobias WEBER's avatar
Tobias WEBER committed
500
501
				tl2::create<t_vec_gl>({0,0,0.5}),		// translate
				tl2::create<t_vec_gl>({0,0,1}));		// from
502
			m_plot->GetImpl()->SetObjectMatrix(m_arrow_M_Re, matMRe);
Tobias WEBER's avatar
Tobias WEBER committed
503
			m_plot->GetImpl()->SetObjectVisible(m_arrow_M_Re, !tl2::equals(lenReM, t_real_gl(0)));
504
505
506
507

			// Im(M)
			const t_real_gl lenImM = t_real_gl(std::sqrt(MPerpImX*MPerpImX + MPerpImY*MPerpImY + MPerpImZ*MPerpImZ));
			t_mat_gl matMIm = GlPlot_impl::GetArrowMatrix(
Tobias WEBER's avatar
Tobias WEBER committed
508
				tl2::create<t_vec_gl>({t_real_gl(MPerpImX), t_real_gl(MPerpImY), t_real_gl(MPerpImZ)}), 	// to
509
				lenImM,								// scale
Tobias WEBER's avatar
Tobias WEBER committed
510
511
				tl2::create<t_vec_gl>({0,0,0.5}),		// translate
				tl2::create<t_vec_gl>({0,0,1}));		// from
512
			m_plot->GetImpl()->SetObjectMatrix(m_arrow_M_Im, matMIm);
Tobias WEBER's avatar
Tobias WEBER committed
513
			m_plot->GetImpl()->SetObjectVisible(m_arrow_M_Im, !tl2::equals(lenImM, t_real_gl(0)));
Tobias WEBER's avatar
Tobias WEBER committed
514
515

			m_plot->update();
516
517
518
519
520
521
522
523
524
		}
	}
};
// ----------------------------------------------------------------------------




// ----------------------------------------------------------------------------
Tobias WEBER's avatar
Tobias WEBER committed
525
526
527
#ifndef BUILD_LIB	// build application


528
529
530
int main(int argc, char** argv)
{
	set_gl_format(1, _GL_MAJ_VER, _GL_MIN_VER, 8);
Tobias WEBER's avatar
Tobias WEBER committed
531
	tl2::set_locales();
Tobias WEBER's avatar
Tobias WEBER committed
532

Tobias WEBER's avatar
Tobias WEBER committed
533
	QApplication::addLibraryPath(QString(".") + QDir::separator() + "qtplugins");
534
535
536
537
538
539
	auto app = std::make_unique<QApplication>(argc, argv);
	auto dlg = std::make_unique<PolDlg>(nullptr);
	dlg->show();

	return app->exec();
}
Tobias WEBER's avatar
Tobias WEBER committed
540
541
542
543
544
545
546


#else	// build library


#include <boost/dll/alias.hpp>

Tobias WEBER's avatar
Tobias WEBER committed
547

Tobias WEBER's avatar
Tobias WEBER committed
548
549
550
/**
 * initialise plugin
 */
Tobias WEBER's avatar
Tobias WEBER committed
551
bool init()
Tobias WEBER's avatar
Tobias WEBER committed
552
553
{
	set_gl_format(1, _GL_MAJ_VER, _GL_MIN_VER, 8);
Tobias WEBER's avatar
Tobias WEBER committed
554
	tl2::set_locales();
Tobias WEBER's avatar
Tobias WEBER committed
555
556
557

	return true;
}
Tobias WEBER's avatar
Tobias WEBER committed
558

Tobias WEBER's avatar
Tobias WEBER committed
559

Tobias WEBER's avatar
Tobias WEBER committed
560
561
/**
 * plugin descriptor
Tobias WEBER's avatar
Tobias WEBER committed
562
 * type; title; description
Tobias WEBER's avatar
Tobias WEBER committed
563
 */
Tobias WEBER's avatar
Tobias WEBER committed
564
const char* descr()
Tobias WEBER's avatar
Tobias WEBER committed
565
{
Tobias WEBER's avatar
Tobias WEBER committed
566
	return "dlg;Polarisation Vectors;Calculates polarisation vectors.";
Tobias WEBER's avatar
Tobias WEBER committed
567
568
569
570
571
572
}


/**
 * create the plugin main dialog
 */
Tobias WEBER's avatar
Tobias WEBER committed
573
QDialog* create(QWidget *pParent)
Tobias WEBER's avatar
Tobias WEBER committed
574
575
{
	//std::cout << "In " << __FUNCTION__ << std::endl;
Tobias WEBER's avatar
Tobias WEBER committed
576
577
578
579
580
581
582
583
584
585
586
	return new PolDlg(pParent);
}


/**
 * destroy the plugin main dialog
 */
void destroy(QDialog* dlg)
{
	//std::cout << "In " << __FUNCTION__ << std::endl;
	if(dlg) delete dlg;
Tobias WEBER's avatar
Tobias WEBER committed
587
588
}

Tobias WEBER's avatar
Tobias WEBER committed
589
590

BOOST_DLL_ALIAS(init, tl_init);
Tobias WEBER's avatar
Tobias WEBER committed
591
BOOST_DLL_ALIAS(descr, tl_descr);
Tobias WEBER's avatar
Tobias WEBER committed
592
BOOST_DLL_ALIAS(create, tl_create);
Tobias WEBER's avatar
Tobias WEBER committed
593
BOOST_DLL_ALIAS(destroy, tl_destroy);
Tobias WEBER's avatar
Tobias WEBER committed
594
595
596


#endif
597
// ----------------------------------------------------------------------------