Commit bd792845 authored by Tobias WEBER's avatar Tobias WEBER
Browse files

coloured nuclei

parent fe827aa3
......@@ -123,8 +123,8 @@ GlPlotObj GlPlot_impl::CreateTriangleObject(const std::vector<t_vec3_gl>& verts,
{
qgl_funcs* pGl = GetGlFunctions();
GLint attrVertex = m_attrVertex;
GLint attrVertexNormal = m_attrVertexNormal;
GLint attrVertexColor = m_attrVertexColor;
GLint attrVertexNormal = m_attrVertexNorm;
GLint attrVertexColor = m_attrVertexCol;
GlPlotObj obj;
obj.m_type = GlPlotObjType::TRIANGLES;
......@@ -213,7 +213,7 @@ GlPlotObj GlPlot_impl::CreateLineObject(const std::vector<t_vec3_gl>& verts, con
{
qgl_funcs* pGl = GetGlFunctions();
GLint attrVertex = m_attrVertex;
GLint attrVertexColor = m_attrVertexColor;
GLint attrVertexColor = m_attrVertexCol;
GlPlotObj obj;
obj.m_type = GlPlotObjType::LINES;
......@@ -284,6 +284,12 @@ void GlPlot_impl::SetObjectMatrix(std::size_t idx, const t_mat_gl& mat)
}
void GlPlot_impl::SetObjectCol(std::size_t idx, t_real_gl r, t_real_gl g, t_real_gl b, t_real_gl a)
{
if(idx >= m_objs.size()) return;
m_objs[idx].m_color = m::create<t_vec_gl>({r,g,b,a});
}
void GlPlot_impl::SetObjectLabel(std::size_t idx, const std::string& label)
{
if(idx >= m_objs.size()) return;
......@@ -307,11 +313,13 @@ void GlPlot_impl::RemoveObject(std::size_t idx)
std::size_t GlPlot_impl::AddLinkedObject(std::size_t linkTo,
t_real_gl x, t_real_gl y, t_real_gl z)
t_real_gl x, t_real_gl y, t_real_gl z,
t_real_gl r, t_real_gl g, t_real_gl b, t_real_gl a)
{
GlPlotObj obj;
obj.linkedObj = linkTo;
obj.m_mat = m::hom_translation<t_mat_gl>(x, y, z);
obj.m_color = m::create<t_vec_gl>({r, g, b, a});
QMutexLocker _locker{&m_mutexObj};
m_objs.emplace_back(std::move(obj));
......@@ -417,13 +425,13 @@ void GlPlot_impl::initialiseGL()
// --------------------------------------------------------------------
std::string strFragShader = R"RAW(#version ${GLSL_VERSION}
in vec4 fragcolor;
out vec4 outcolor;
in vec4 fragcol;
out vec4 outcol;
void main()
{
//outcolor = vec4(0,0,0,1);
outcolor = fragcolor;
outcol = fragcol;
})RAW";
// --------------------------------------------------------------------
......@@ -433,16 +441,17 @@ std::string strVertexShader = R"RAW(#version ${GLSL_VERSION}
in vec4 vertex;
in vec4 normal;
in vec4 vertexcolor;
out vec4 fragcolor;
in vec4 vertexcol;
out vec4 fragcol;
uniform mat4 proj = mat4(1.);
uniform mat4 cam = mat4(1.);
uniform mat4 obj = mat4(1.);
//vec4 vertexcolor = vec4(0, 0, 1, 1);
uniform vec4 constcol = vec4(1, 1, 1, 1);
vec3 light_dir = vec3(2, 2, -1);
float lighting(vec3 lightdir)
{
float I = dot(vec3(cam*normal), normalize(lightdir));
......@@ -450,13 +459,15 @@ float lighting(vec3 lightdir)
return I;
}
void main()
{
gl_Position = proj * cam * obj * vertex;
float I = lighting(light_dir);
fragcolor = vertexcolor * I;
fragcolor[3] = 1;
fragcol = vertexcol * I;
fragcol *= constcol;
fragcol[3] = 1;
})RAW";
// --------------------------------------------------------------------
......@@ -510,9 +521,10 @@ void main()
m_uniMatrixCam = m_pShaders->uniformLocation("cam");
m_uniMatrixProj = m_pShaders->uniformLocation("proj");
m_uniMatrixObj = m_pShaders->uniformLocation("obj");
m_uniConstCol = m_pShaders->uniformLocation("constcol");
m_attrVertex = m_pShaders->attributeLocation("vertex");
m_attrVertexNormal = m_pShaders->attributeLocation("normal");
m_attrVertexColor = m_pShaders->attributeLocation("vertexcolor");
m_attrVertexNorm = m_pShaders->attributeLocation("normal");
m_attrVertexCol = m_pShaders->attributeLocation("vertexcol");
}
LOGGLERR(pGl);
......@@ -803,8 +815,19 @@ void GlPlot_impl::paintGL()
{
const GlPlotObj *linkedObj = &obj;
if(obj.linkedObj)
{
// get linked object
linkedObj = &m_objs[*obj.linkedObj];
// override constant color for linked object
m_pShaders->setUniformValue(m_uniConstCol, obj.m_color);
}
else
{
// set override color to white for non-linked objects
m_pShaders->setUniformValue(m_uniConstCol, m::create<t_vec_gl>({1,1,1,1}));
}
if(!obj.m_visible || !obj.m_valid) continue;
// main vertex array object
......@@ -814,12 +837,12 @@ void GlPlot_impl::paintGL()
pGl->glEnableVertexAttribArray(m_attrVertex);
if(linkedObj->m_type == GlPlotObjType::TRIANGLES)
pGl->glEnableVertexAttribArray(m_attrVertexNormal);
pGl->glEnableVertexAttribArray(m_attrVertexColor);
BOOST_SCOPE_EXIT(pGl, &m_attrVertex, &m_attrVertexNormal, &m_attrVertexColor)
pGl->glEnableVertexAttribArray(m_attrVertexNorm);
pGl->glEnableVertexAttribArray(m_attrVertexCol);
BOOST_SCOPE_EXIT(pGl, &m_attrVertex, &m_attrVertexNorm, &m_attrVertexCol)
{
pGl->glDisableVertexAttribArray(m_attrVertexColor);
pGl->glDisableVertexAttribArray(m_attrVertexNormal);
pGl->glDisableVertexAttribArray(m_attrVertexCol);
pGl->glDisableVertexAttribArray(m_attrVertexNorm);
pGl->glDisableVertexAttribArray(m_attrVertex);
}
BOOST_SCOPE_EXIT_END
......@@ -875,8 +898,12 @@ void GlPlot_impl::paintGL()
QFont fontLabel = fontOrig;
QPen penLabel = penOrig;
fontLabel.setStyleStrategy(QFont::StyleStrategy(QFont::OpenGLCompatible | QFont::PreferAntialias | QFont::PreferQuality));
fontLabel.setWeight(QFont::Medium);
//penLabel.setColor(QColor(int((1.-obj.m_color[0])*255.), int((1.-obj.m_color[1])*255.), int((1.-obj.m_color[2])*255.), int(obj.m_color[3]*255.)));
penLabel.setColor(QColor(0,0,0,255));
painter.setFont(fontLabel);
painter.setPen(penLabel);
painter.drawText(posLabel2d, obj.m_label.c_str());
fontLabel.setWeight(QFont::Normal);
......@@ -961,8 +988,19 @@ void GlPlot_impl::paintGL()
{
const GlPlotObj *linkedObj = &obj;
if(obj.linkedObj)
{
// get linked object
linkedObj = &m_objs[*obj.linkedObj];
// override constant color for linked object
m_pShaders->setUniformValue(m_uniConstCol, obj.m_color);
}
else
{
// set override color to white for non-linked objects
m_pShaders->setUniformValue(m_uniConstCol, m::create<t_vec_gl>({1,1,1,1}));
}
if(!obj.m_visible || !obj.m_valid) continue;
// main vertex array object
......@@ -972,12 +1010,12 @@ void GlPlot_impl::paintGL()
pGl->glEnableVertexAttribArray(m_attrVertex);
if(linkedObj->m_type == GlPlotObjType::TRIANGLES)
pGl->glEnableVertexAttribArray(m_attrVertexNormal);
pGl->glEnableVertexAttribArray(m_attrVertexColor);
BOOST_SCOPE_EXIT(pGl, &m_attrVertex, &m_attrVertexNormal, &m_attrVertexColor)
pGl->glEnableVertexAttribArray(m_attrVertexNorm);
pGl->glEnableVertexAttribArray(m_attrVertexCol);
BOOST_SCOPE_EXIT(pGl, &m_attrVertex, &m_attrVertexNorm, &m_attrVertexCol)
{
pGl->glDisableVertexAttribArray(m_attrVertexColor);
pGl->glDisableVertexAttribArray(m_attrVertexNormal);
pGl->glDisableVertexAttribArray(m_attrVertexCol);
pGl->glDisableVertexAttribArray(m_attrVertexNorm);
pGl->glDisableVertexAttribArray(m_attrVertex);
}
BOOST_SCOPE_EXIT_END
......
......@@ -129,8 +129,9 @@ protected:
std::shared_ptr<QOpenGLShaderProgram> m_pShaders;
GLint m_attrVertex = -1;
GLint m_attrVertexNormal = -1;
GLint m_attrVertexColor = -1;
GLint m_attrVertexNorm = -1;
GLint m_attrVertexCol = -1;
GLint m_uniConstCol = -1;
GLint m_uniMatrixProj = -1;
GLint m_uniMatrixCam = -1;
GLint m_uniMatrixObj = -1;
......@@ -195,7 +196,8 @@ public:
void RemoveObject(std::size_t obj);
std::size_t AddLinkedObject(std::size_t linkTo,
t_real_gl x=0, t_real_gl y=0, t_real_gl z=0);
t_real_gl x=0, t_real_gl y=0, t_real_gl z=0,
t_real_gl r=1, t_real_gl g=1, t_real_gl b=1, t_real_gl a=1);
std::size_t AddSphere(t_real_gl rad=1,
t_real_gl x=0, t_real_gl y=0, t_real_gl z=0,
t_real_gl r=0, t_real_gl g=0, t_real_gl b=0, t_real_gl a=1);
......@@ -211,6 +213,7 @@ public:
std::size_t AddCoordinateCross(t_real_gl min, t_real_gl max);
void SetObjectMatrix(std::size_t idx, const t_mat_gl& mat);
void SetObjectCol(std::size_t idx, t_real_gl r, t_real_gl g, t_real_gl b, t_real_gl a=1);
void SetObjectLabel(std::size_t idx, const std::string& label);
void SetObjectVisible(std::size_t idx, bool visible);
......
......@@ -46,6 +46,7 @@ enum : int
COL_SCATLEN_RE,
COL_SCATLEN_IM,
COL_X, COL_Y, COL_Z,
COL_COL,
NUM_COLS
};
......@@ -90,6 +91,7 @@ StructFactDlg::StructFactDlg(QWidget* pParent) : QDialog{pParent},
m_nuclei->setHorizontalHeaderItem(COL_X, new QTableWidgetItem{"x (frac.)"});
m_nuclei->setHorizontalHeaderItem(COL_Y, new QTableWidgetItem{"y (frac.)"});
m_nuclei->setHorizontalHeaderItem(COL_Z, new QTableWidgetItem{"z (frac.)"});
m_nuclei->setHorizontalHeaderItem(COL_COL, new QTableWidgetItem{"Colour"});
m_nuclei->setColumnWidth(COL_NAME, 90);
m_nuclei->setColumnWidth(COL_SCATLEN_RE, 75);
......@@ -97,6 +99,7 @@ StructFactDlg::StructFactDlg(QWidget* pParent) : QDialog{pParent},
m_nuclei->setColumnWidth(COL_X, 75);
m_nuclei->setColumnWidth(COL_Y, 75);
m_nuclei->setColumnWidth(COL_Z, 75);
m_nuclei->setColumnWidth(COL_COL, 75);
QToolButton *pTabBtnAdd = new QToolButton(m_nucleipanel);
QToolButton *pTabBtnDel = new QToolButton(m_nucleipanel);
......@@ -291,7 +294,7 @@ StructFactDlg::StructFactDlg(QWidget* pParent) : QDialog{pParent},
std::string strBoost = BOOST_LIB_VERSION;
algo::replace_all(strBoost, "_", ".");
auto labelTitle = new QLabel("Structure Factors", infopanel);
auto labelTitle = new QLabel("Structure Factor Calculator", infopanel);
auto fontTitle = labelTitle->font();
fontTitle.setBold(true);
labelTitle->setFont(fontTitle);
......@@ -345,7 +348,7 @@ StructFactDlg::StructFactDlg(QWidget* pParent) : QDialog{pParent},
// ----------------------------------------------------------------------------
void StructFactDlg::AddTabItem(int row,
const std::string& name, t_real bRe, t_real bIm, t_real x, t_real y, t_real z)
const std::string& name, t_real bRe, t_real bIm, t_real x, t_real y, t_real z, const std::string& col)
{
bool bclone = 0;
m_ignoreChanges = 1;
......@@ -379,6 +382,7 @@ void StructFactDlg::AddTabItem(int row,
m_nuclei->setItem(row, COL_X, new NumericTableWidgetItem<t_real>(x));
m_nuclei->setItem(row, COL_Y, new NumericTableWidgetItem<t_real>(y));
m_nuclei->setItem(row, COL_Z, new NumericTableWidgetItem<t_real>(z));
m_nuclei->setItem(row, COL_COL, new QTableWidgetItem(col.c_str()));
}
Add3DItem(row);
......@@ -408,16 +412,24 @@ void StructFactDlg::Add3DItem(int row)
return;
}
auto *itemName = m_nuclei->item(row, COL_NAME);
auto *itemx = m_nuclei->item(row, COL_X);
auto *itemy = m_nuclei->item(row, COL_Y);
auto *itemz = m_nuclei->item(row, COL_Z);
t_real_gl posx, posy, posz;
auto *itemCol = m_nuclei->item(row, COL_COL);
t_real_gl posx=0, posy=0, posz=0;
std::istringstream{itemx->text().toStdString()} >> posx;
std::istringstream{itemy->text().toStdString()} >> posy;
std::istringstream{itemz->text().toStdString()} >> posz;
auto obj = m_plot->GetImpl()->AddLinkedObject(m_sphere);
qreal r=1, g=1, b=1;
QColor col{itemCol->text()};
col.getRgbF(&r, &g, &b);
auto obj = m_plot->GetImpl()->AddLinkedObject(m_sphere, 0,0,0, r,g,b,1);
m_plot->GetImpl()->SetObjectMatrix(obj, m::hom_translation<t_mat_gl>(posx, posy, posz));
m_plot->GetImpl()->SetObjectLabel(obj, itemName->text().toStdString());
m_plot->update();
m_nuclei->item(row, COL_NAME)->setData(Qt::UserRole, unsigned(obj));
......@@ -585,15 +597,24 @@ void StructFactDlg::TableItemChanged(QTableWidgetItem *item)
int row = item->row();
if(std::size_t obj = m_nuclei->item(row, COL_NAME)->data(Qt::UserRole).toUInt(); obj)
{
auto *itemName = m_nuclei->item(row, COL_NAME);
auto *itemx = m_nuclei->item(row, COL_X);
auto *itemy = m_nuclei->item(row, COL_Y);
auto *itemz = m_nuclei->item(row, COL_Z);
auto *itemCol = m_nuclei->item(row, COL_COL);
t_real_gl posx, posy, posz;
std::istringstream{itemx->text().toStdString()} >> posx;
std::istringstream{itemy->text().toStdString()} >> posy;
std::istringstream{itemz->text().toStdString()} >> posz;
qreal r=1, g=1, b=1;
QColor col{itemCol->text()};
col.getRgbF(&r, &g, &b);
m_plot->GetImpl()->SetObjectMatrix(obj, m::hom_translation<t_mat_gl>(posx, posy, posz));
m_plot->GetImpl()->SetObjectCol(obj, r, g, b, 1);
m_plot->GetImpl()->SetObjectLabel(obj, itemName->text().toStdString());
m_plot->update();
}
}
......@@ -699,8 +720,9 @@ void StructFactDlg::Load()
auto optX = nucl.second.get<t_real>("x", 0.);
auto optY = nucl.second.get<t_real>("y", 0.);
auto optZ = nucl.second.get<t_real>("z", 0.);
auto optCol = nucl.second.get<std::string>("col", "#ff0000");
AddTabItem(-1, optName, optbRe, optbIm, optX, optY, optZ);
AddTabItem(-1, optName, optbRe, optbIm, optX, optY, optZ, optCol);
}
}
}
......@@ -759,6 +781,7 @@ void StructFactDlg::Save()
itemNode.put<t_real>("x", x);
itemNode.put<t_real>("y", y);
itemNode.put<t_real>("z", z);
itemNode.put<std::string>("col", m_nuclei->item(row, COL_COL)->text().toStdString());
node.add_child("sfact.nuclei.nucleus", itemNode);
}
......@@ -996,6 +1019,7 @@ void StructFactDlg::PickerIntersection(const t_vec3_gl* pos, std::size_t objIdx,
}
/**
* set status label text in 3d dialog
*/
......@@ -1041,7 +1065,7 @@ void StructFactDlg::AfterGLInitialisation()
{
if(!m_plot) return;
m_sphere = m_plot->GetImpl()->AddSphere(0.1, 0.,0.,0., 1.,0.,0.,1.);
m_sphere = m_plot->GetImpl()->AddSphere(0.1, 0.,0.,0., 1.,1.,1.,1.);
m_plot->GetImpl()->SetObjectVisible(m_sphere, false);
// add all 3d objects
......
......@@ -102,7 +102,8 @@ protected:
QMenu *m_pTabContextMenuNoItem = nullptr; // menu if nothing is selected
protected:
void AddTabItem(int row=-1, const std::string& name="n/a", t_real bRe=0., t_real bIm=0., t_real x=0., t_real y=0., t_real z=0.);
void AddTabItem(int row=-1, const std::string& name="n/a", t_real bRe=0., t_real bIm=0.,
t_real x=0., t_real y=0., t_real z=0., const std::string &col="#ff0000");
void DelTabItem(bool clearAll=false);
void MoveTabItemUp();
void MoveTabItemDown();
......
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