pol.cpp 18.8 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

23
24
25
26
#include "tlibs2/libs/glplot.h"
#include "tlibs2/libs/math20.h"
#include "tlibs2/libs/str.h"
#include "tlibs2/libs/helper.h"
27
28
29
30
31
32
33

#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
34
using namespace tl2_ops;
35
36
37

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


// ----------------------------------------------------------------------------
class PolDlg : public QDialog
{ /*Q_OBJECT*/
private:
	QSettings m_sett{"tobis_stuff", "pol"};
48
	int m_prec = 6;		// precision
49
50

	std::shared_ptr<GlPlot> m_plot{std::make_shared<GlPlot>(this)};
Tobias WEBER's avatar
Tobias WEBER committed
51
	QLabel *m_labelGlInfos[4] = { nullptr, nullptr, nullptr, nullptr };
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
79
80

	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
81
82
	std::optional<std::size_t> m_curPickedObj{};
	std::optional<std::size_t> m_curDraggedObj{};
83
84
85


protected:
86
	virtual void closeEvent(QCloseEvent *) override
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
	{
		// 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
113
114
115
116
117
118
		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("."));
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
176
177


		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
178
179
		m_curPickedObj.reset();

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

			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
188
			else m_curPickedObj.reset();
189
190
		}

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


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

			t_vec3_gl posSph = *posSphere;

Tobias WEBER's avatar
Tobias WEBER committed
207
			if(*m_curDraggedObj == m_arrow_pi)
208
			{
209
210
211
				m_editPiX->setText(tl2::var_to_str(posSph[0], m_prec).c_str());
				m_editPiY->setText(tl2::var_to_str(posSph[1], m_prec).c_str());
				m_editPiZ->setText(tl2::var_to_str(posSph[2], m_prec).c_str());
212
213
				CalcPol();
			}
Tobias WEBER's avatar
Tobias WEBER committed
214
			else if(*m_curDraggedObj == m_arrow_M_Re)
215
			{
216
217
218
				m_editMPerpReX->setText(tl2::var_to_str(posSph[0], m_prec).c_str());
				m_editMPerpReY->setText(tl2::var_to_str(posSph[1], m_prec).c_str());
				m_editMPerpReZ->setText(tl2::var_to_str(posSph[2], m_prec).c_str());
219
220
				CalcPol();
			}
Tobias WEBER's avatar
Tobias WEBER committed
221
			else if(*m_curDraggedObj == m_arrow_M_Im)
222
			{
223
224
225
				m_editMPerpImX->setText(tl2::var_to_str(posSph[0], m_prec).c_str());
				m_editMPerpImY->setText(tl2::var_to_str(posSph[1], m_prec).c_str());
				m_editMPerpImZ->setText(tl2::var_to_str(posSph[2], m_prec).c_str());
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
				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
243
244
245
246
247
248
			if((m_curDraggedObj = m_curPickedObj))
			{
				auto lenVec = GetArrowLen(*m_curDraggedObj);
				if(lenVec > 0.)
					m_plot->GetImpl()->SetPickerSphereRadius(lenVec);
			}
249
250
251
252
253
254
255
256
257
258
259
260
261
262
		}
	}


	/**
	 * 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
263
			m_curDraggedObj.reset();
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
	}


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);
298
			m_labelStatus->setFrameStyle(int(QFrame::Sunken) | int(QFrame::Panel));
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
370
371
			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
372
373
374
			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);
375

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

			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
406
407
408
409
410
411
			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);
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
			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
431
432
		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
433
		m_plot->GetImpl()->SetCoordMax(5.);
Tobias WEBER's avatar
Tobias WEBER committed
434
435
		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
436

437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
		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
462
		const t_vec Mperp = tl2::create<t_vec>({
463
464
465
			t_cplx(MPerpReX,MPerpImX),
			t_cplx(MPerpReY,MPerpImY),
			t_cplx(MPerpReZ,MPerpImZ) });
Tobias WEBER's avatar
Tobias WEBER committed
466
		const t_vec Pi = tl2::create<t_vec>({PiX, PiY, PiZ});
467
468

		// calculate final polarisation vector and intensity
Tobias WEBER's avatar
Tobias WEBER committed
469
470
		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);
471
472

		// set final polarisation
473
474
475
		m_editPfX->setText(tl2::var_to_str(P_f[0].real(), m_prec).c_str());
		m_editPfY->setText(tl2::var_to_str(P_f[1].real(), m_prec).c_str());
		m_editPfZ->setText(tl2::var_to_str(P_f[2].real(), m_prec).c_str());
476
477
478
479
480
481
482


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

			// P_f
			t_mat_gl matPf = GlPlot_impl::GetArrowMatrix(
Tobias WEBER's avatar
Tobias WEBER committed
491
				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
492
				1., 								// scale
Tobias WEBER's avatar
Tobias WEBER committed
493
494
				tl2::create<t_vec_gl>({0,0,0.5}),		// translate
				tl2::create<t_vec_gl>({0,0,1}));		// from
495
496
497
498
499
			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
500
				tl2::create<t_vec_gl>({t_real_gl(MPerpReX), t_real_gl(MPerpReY), t_real_gl(MPerpReZ)}), 	// to
501
				lenReM,								// scale
Tobias WEBER's avatar
Tobias WEBER committed
502
503
				tl2::create<t_vec_gl>({0,0,0.5}),		// translate
				tl2::create<t_vec_gl>({0,0,1}));		// from
504
			m_plot->GetImpl()->SetObjectMatrix(m_arrow_M_Re, matMRe);
Tobias WEBER's avatar
Tobias WEBER committed
505
			m_plot->GetImpl()->SetObjectVisible(m_arrow_M_Re, !tl2::equals(lenReM, t_real_gl(0)));
506
507
508
509

			// 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
510
				tl2::create<t_vec_gl>({t_real_gl(MPerpImX), t_real_gl(MPerpImY), t_real_gl(MPerpImZ)}), 	// to
511
				lenImM,								// scale
Tobias WEBER's avatar
Tobias WEBER committed
512
513
				tl2::create<t_vec_gl>({0,0,0.5}),		// translate
				tl2::create<t_vec_gl>({0,0,1}));		// from
514
			m_plot->GetImpl()->SetObjectMatrix(m_arrow_M_Im, matMIm);
Tobias WEBER's avatar
Tobias WEBER committed
515
			m_plot->GetImpl()->SetObjectVisible(m_arrow_M_Im, !tl2::equals(lenImM, t_real_gl(0)));
Tobias WEBER's avatar
Tobias WEBER committed
516
517

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




// ----------------------------------------------------------------------------
Tobias WEBER's avatar
Tobias WEBER committed
527
528
529
#ifndef BUILD_LIB	// build application


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

Tobias WEBER's avatar
Tobias WEBER committed
535
	QApplication::addLibraryPath(QString(".") + QDir::separator() + "qtplugins");
536
537
538
539
540
541
	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
542
543
544
545
546
547
548


#else	// build library


#include <boost/dll/alias.hpp>

Tobias WEBER's avatar
Tobias WEBER committed
549

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

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

Tobias WEBER's avatar
Tobias WEBER committed
561

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


/**
 * create the plugin main dialog
 */
Tobias WEBER's avatar
Tobias WEBER committed
575
QDialog* create(QWidget *pParent)
Tobias WEBER's avatar
Tobias WEBER committed
576
577
{
	//std::cout << "In " << __FUNCTION__ << std::endl;
Tobias WEBER's avatar
Tobias WEBER committed
578
579
580
581
582
583
584
585
586
587
588
	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
589
590
}

Tobias WEBER's avatar
Tobias WEBER committed
591
592

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


#endif
599
// ----------------------------------------------------------------------------