Quantum Phenomena Explorer 7.9.8
Interactive quantum-phenomena Explorer Tutor — source documentation
Loading...
Searching...
No Matches
quantumaharonovbohmplotwidget.cpp
Go to the documentation of this file.
1/**
2 * @file quantumaharonovbohmplotwidget.cpp
3 * @brief Implements the quantumaharonovbohmplotwidget visualization component used by QPE.
4 * @ingroup qpe_graphics
5 *
6 * Source: @c graphics/renderer/quantumaharonovbohmplotwidget.cpp. This file is part of Quantum Phenomena Explorer (QPE),
7 * maintained by Officina Turini. See LICENSE_IT.txt / LICENSE.txt for the
8 * QPE freeware source-available terms and THIRD_PARTY_NOTICES.txt for
9 * third-party components.
10 */
11
13#include <QPainter>
14#include <QPaintEvent>
15#include <QPainterPath>
16#include <algorithm>
17#include <cmath>
18
19namespace {
20/**
21 * @brief Performs heat.
22 * @param v The v value used by the operation.
23 */
24QColor heat(double v)
25{
26 v = std::max(0.0, std::min(1.0, v));
27 if (v < 0.5) {
28 const double u = v / 0.5;
29 return QColor(static_cast<int>(8 + 20*u), static_cast<int>(12 + 90*u), static_cast<int>(30 + 180*u));
30 }
31 const double u = (v - 0.5) / 0.5;
32 return QColor(static_cast<int>(28 + 227*u), static_cast<int>(102 + 130*u), static_cast<int>(210 - 80*u));
33}
34}
35
39QSize QuantumAharonovBohmPlotWidget::minimumSizeHint() const{return QSize(650,430);}
40
42{
43 Q_UNUSED(event);
44 QPainter p(this); p.setRenderHint(QPainter::Antialiasing,true); p.fillRect(rect(),QColor(10,14,20));
45 QFont f=font();f.setBold(true);p.setFont(f);p.setPen(QColor(225,235,244));
46 p.drawText(QRect(12,7,width()-24,24),Qt::AlignLeft|Qt::AlignVCenter,QStringLiteral("Aharonov-Bohm — detector interference vs enclosed flux"));
48 p.setFont(font());p.setPen(QColor(150,166,180));
49 p.drawText(QRect(20,50,width()-40,height()-70),Qt::AlignCenter|Qt::TextWordWrap,
50 QStringLiteral("Load Aharonov-Bohm Effect / Magnetic Flux and press Play"));return;
51 }
52 const auto &samples=history_->samples(); const auto &cfg=history_->config();
53 const int left=64,right=18,top=40,gap=34; const int traceH=130;
54 QRect map(left,top,std::max(10,width()-left-right),std::max(100,height()-top-gap-traceH-28));
55 QRect trace(left,map.bottom()+gap,map.width(),std::max(90,height()-(map.bottom()+gap)-28));
56 p.setPen(QColor(55,72,88));p.setBrush(QColor(5,9,15));p.drawRect(map);p.drawRect(trace);
57 double vmax=1e-15,cmax=1e-15;
58 for(const auto&s:samples){for(float v:s.detectorProfileY)vmax=std::max(vmax,(double)v);cmax=std::max(cmax,s.detectorCenterSignal);}
59 const std::size_t ny=history_->gridHeight();
60 for(std::size_t si=0;si<samples.size();++si){
61 const auto&s=samples[si];
62 int x0=map.left()+int((double(si)/samples.size())*map.width());
63 int x1=map.left()+int((double(si+1)/samples.size())*map.width());
64 int ww=std::max(1,x1-x0+1);
65 for(std::size_t yi=0;yi<ny&&yi<s.detectorProfileY.size();++yi){
66 int y1=map.bottom()-int((double(yi)/ny)*map.height());
67 int y0=map.bottom()-int((double(yi+1)/ny)*map.height());
68 int hh=std::max(1,y1-y0+1);
69 double a=std::sqrt(std::max(0.0,(double)s.detectorProfileY[yi])/vmax);
70 p.fillRect(QRect(x0,y0,ww,hh),heat(a));
71 }
72 }
73 const double tmax=std::max(cfg.analysisEndTime,samples.back().time);
74 auto tx=[&](double t){return trace.left()+t/std::max(1e-12,tmax)*trace.width();};
75 auto cy=[&](double v){return trace.bottom()-v/cmax*trace.height();};
76 QPainterPath path;for(std::size_t i=0;i<samples.size();++i){QPointF pt(tx(samples[i].time),cy(samples[i].detectorCenterSignal));if(i==0)path.moveTo(pt);else path.lineTo(pt);}
77 p.setPen(QPen(QColor(90,225,255),2.0));p.drawPath(path);
78 p.setPen(QColor(180,198,212));p.setFont(font());
79 p.drawText(QRect(4,map.top(),left-10,20),Qt::AlignRight|Qt::AlignVCenter,QStringLiteral("+y"));
80 p.drawText(QRect(4,map.bottom()-20,left-10,20),Qt::AlignRight|Qt::AlignVCenter,QStringLiteral("-y"));
81 p.drawText(QRect(map.left(),map.bottom()+4,map.width(),20),Qt::AlignCenter,QStringLiteral("time — detector density profile rho(xd,y,t)"));
82 p.drawText(QRect(trace.left(),trace.bottom()+4,trace.width(),20),Qt::AlignCenter,QStringLiteral("time — central fringe intensity"));
83 const auto &last=samples.back(); const double deg=360.0*cfg.fluxQuanta;
84 p.setPen(QColor(232,238,244));
85 p.drawText(QRect(trace.left()+8,trace.top()+5,trace.width()-16,22),Qt::AlignLeft|Qt::AlignVCenter,
86 QStringLiteral("Phi/Phi0=%1 AB phase=%2 deg center=%3 line=%4 norm=%5")
87 .arg(cfg.fluxQuanta,0,'f',3).arg(deg,0,'f',1).arg(last.detectorCenterSignal,0,'g',5)
88 .arg(last.detectorSignal,0,'g',5).arg(last.norm,0,'f',6));
89}
const qpe::QuantumAharonovBohmHistory2D * history_
QSize minimumSizeHint() const override
Performs minimum size hint.
QuantumAharonovBohmPlotWidget(QWidget *parent=nullptr)
Performs quantum aharonov bohm plot widget.
void paintEvent(QPaintEvent *event) override
Paints event.
void setData(const qpe::QuantumAharonovBohmHistory2D &history)
Sets data.
Implements the Quantum Aharonov Bohm History2D component.
bool empty() const noexcept
Returns whether the object contains no data.
std::size_t gridHeight() const noexcept
Carries out grid height.
const QuantumAharonovBohm2DConfig & config() const noexcept
Returns config.
const std::vector< QuantumAharonovBohmSample2D > & samples() const noexcept
Samples s.
bool configured() const noexcept
Returns configured.
Declares the quantumaharonovbohmplotwidget visualization component used by QPE.