Verified Commit 1a44bc90 authored by Tobias WEBER's avatar Tobias WEBER
Browse files

bz tool: continued with plotting

parent 2dd6d692
......@@ -153,6 +153,9 @@ protected:
std::vector<std::vector<t_mat>> m_sg_ops; // symops per space group
std::vector<std::vector<t_vec>> m_bz_polys; // polygons of the 3d bz
t_real m_min_x = 1., m_max_x = -1.; // plot ranges for curves
t_real m_min_y = 1., m_max_y = -1.; // plot ranges for curves
protected:
// space group / symops tab
......
......@@ -297,7 +297,7 @@ void BZDlg::CalcBZCut()
norm, d_invA, bz_poly, g_eps);
vecs = tl2::remove_duplicates(vecs, g_eps);
// calulate the hull of the bz cut
// calculate the hull of the bz cut
if(calc_bzcut_hull)
{
for(const t_vec& vec : vecs)
......@@ -333,7 +333,7 @@ void BZDlg::CalcBZCut()
}
}
// calulate the hull of the bz cut
// calculate the hull of the bz cut
if(calc_bzcut_hull)
{
cut_verts = tl2::remove_duplicates(cut_verts, g_eps);
......@@ -372,9 +372,35 @@ void BZDlg::CalcBZCut()
}
m_bzscene->clear();
// get ranges
m_min_x = std::numeric_limits<t_real>::max();
m_max_x = -m_min_x;
m_min_y = std::numeric_limits<t_real>::max();
m_max_y = -m_min_y;
for(const auto& tup : cut_lines)
{
const auto& pt1 = std::get<0>(tup);
const auto& pt2 = std::get<1>(tup);
m_min_x = std::min(m_min_x, pt1[0]);
m_min_x = std::min(m_min_x, pt2[0]);
m_max_x = std::max(m_max_x, pt1[0]);
m_max_x = std::max(m_max_x, pt2[0]);
m_min_y = std::min(m_min_y, pt1[1]);
m_min_y = std::min(m_min_y, pt2[1]);
m_max_y = std::max(m_max_y, pt1[1]);
m_max_y = std::max(m_max_y, pt2[1]);
}
// draw cut
m_bzscene->ClearAll();
m_bzscene->AddCut(cut_lines);
// get description of bz cut
ostr << "# Brillouin zone cut" << std::endl;
for(std::size_t i=0; i<cut_lines000.size(); ++i)
{
......@@ -385,6 +411,8 @@ void BZDlg::CalcBZCut()
}
m_descrBZCut = ostr.str();
// update calculation results
PlotSetPlane(norm, d_invA);
UpdateBZDescription();
CalcFormulas();
......@@ -396,6 +424,10 @@ void BZDlg::CalcBZCut()
*/
void BZDlg::CalcFormulas()
{
m_bzscene->ClearCurves();
if(m_max_x < m_min_x)
return;
std::vector<std::string> formulas = GetFormulas();
for(const std::string& formula : formulas)
{
......@@ -408,8 +440,23 @@ void BZDlg::CalcFormulas()
if(bool ok = parser.parse(formula); !ok)
continue;
// TODO
//t_real result = parser.eval();
int num_pts = 512;
t_real x_delta = (m_max_x - m_min_x) / t_real(num_pts);
std::vector<t_vec> curve;
curve.reserve(num_pts);
for(t_real x=m_min_x; x<=m_max_x; x+=x_delta)
{
parser.register_var("x", x);
t_real y = parser.eval();
if(y < m_min_y || y > m_max_y)
continue;
curve.emplace_back(tl2::create<t_vec>({ x, y }));
}
m_bzscene->AddCurve(curve);
}
catch(const std::exception& ex)
{
......
......@@ -37,9 +37,14 @@ BZCutScene::BZCutScene(QWidget *parent) : QGraphicsScene(parent)
BZCutScene::~BZCutScene()
{
ClearAll();
}
/**
* adds the line segments of a brillouin zone cut
* @arg [start, end, Q]
*/
void BZCutScene::AddCut(
const std::vector<std::tuple<t_vec, t_vec, std::array<t_real, 3>>>& lines)
{
......@@ -51,6 +56,8 @@ void BZCutScene::AddCut(
pen.setColor(qApp->palette().color(QPalette::WindowText));
pen.setWidthF(1.);
m_bzcut.reserve(lines.size() * 2);
// draw brillouin zones
for(const auto& line : lines)
{
......@@ -65,10 +72,12 @@ void BZCutScene::AddCut(
continue;
}
addLine(QLineF(
QGraphicsLineItem *plot_line = addLine(QLineF(
std::get<0>(line)[0]*m_scale, std::get<0>(line)[1]*m_scale,
std::get<1>(line)[0]*m_scale, std::get<1>(line)[1]*m_scale),
pen);
m_bzcut.push_back(plot_line);
}
......@@ -78,12 +87,63 @@ void BZCutScene::AddCut(
for(const auto* line : lines000)
{
addLine(QLineF(
QGraphicsLineItem *plot_line = addLine(QLineF(
std::get<0>(*line)[0]*m_scale, std::get<0>(*line)[1]*m_scale,
std::get<1>(*line)[0]*m_scale, std::get<1>(*line)[1]*m_scale),
pen);
m_bzcut.push_back(plot_line);
}
}
/**
* adds a plot curve from a set of points
*/
void BZCutScene::AddCurve(const std::vector<t_vec>& points)
{
QPen pen;
pen.setCosmetic(true);
pen.setColor(QColor(0x00, 0x00, 0xff));
pen.setWidthF(2.);
for(std::size_t i=0; i<points.size()-1; ++i)
{
std::size_t j = i+1;
QGraphicsLineItem *plot_line = addLine(QLineF(
points[i][0]*m_scale, points[i][1]*m_scale,
points[j][0]*m_scale, points[j][1]*m_scale),
pen);
m_curves.push_back(plot_line);
}
}
void BZCutScene::ClearAll()
{
ClearCut();
ClearCurves();
clear();
}
void BZCutScene::ClearCut()
{
for(QGraphicsItem *item : m_bzcut)
delete item;
m_bzcut.clear();
}
void BZCutScene::ClearCurves()
{
for(QGraphicsItem *item : m_curves)
delete item;
m_curves.clear();
}
// --------------------------------------------------------------------------------
......
......@@ -40,6 +40,7 @@
#include "globals.h"
class BZCutScene : public QGraphicsScene
{
public:
......@@ -49,14 +50,24 @@ public:
void AddCut(const std::vector<
// [x, y, Q]
std::tuple<t_vec, t_vec, std::array<t_real, 3>>>& lines);
void AddCurve(const std::vector<t_vec>& points);
t_real GetScale() const { return m_scale; }
void ClearAll();
void ClearCut();
void ClearCurves();
protected:
t_real m_scale = 100.;
std::vector<QGraphicsItem*> m_bzcut{};
std::vector<QGraphicsItem*> m_curves{};
};
class BZCutView : public QGraphicsView
{ Q_OBJECT
public:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment