Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Image panel cursor info #1482

Merged
merged 2 commits into from
Oct 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
110 changes: 60 additions & 50 deletions ui/zenoedit/panel/zenoimagepanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include "zeno/utils/format.h"
#include <zeno/types/UserData.h>
#include <zeno/types/PrimitiveObject.h>
#include <zenoui/comctrl/zcombobox.h>
#include "zeno/utils/vec.h"
#include "zeno/utils/log.h"
#include "zenoapplication.h"
#include "zassert.h"
Expand Down Expand Up @@ -43,7 +43,6 @@ void ZenoImagePanel::setPrim(std::string primid) {
return;

bool enableGamma = pGamma->checkState() == Qt::Checked;
bool enableAlpha = pAlpha->checkState() == Qt::Checked;
bool found = false;
for (auto const &[key, ptr]: scene->objectsMan->pairs()) {
if ((key.substr(0, key.find(":"))) != primid) {
Expand All @@ -58,52 +57,46 @@ void ZenoImagePanel::setPrim(std::string primid) {
int width = ud.get2<int>("w");
int height = ud.get2<int>("h");
if (image_view) {
QImage img(width, height, QImage::Format_RGB32);
int gridSize = 50;
if (obj->verts.has_attr("alpha")&&enableAlpha) {
auto &alpha = obj->verts.attr<float>("alpha");
if (pMode->currentText() != "Alpha") {
QImage img(width, height, QImage::Format_RGB32);
for (auto i = 0; i < obj->verts.size(); i++) {
int h = i / width;
//int h = i % height; check image vert order
int w = i % width;
//int w = i / height;
auto foreground = obj->verts[i];
auto c = obj->verts[i];
if (enableGamma) {
foreground = zeno::pow(foreground, 1.0f / 2.2f);
}
zeno::vec3f background;
if ((h / gridSize) % 2 == (w / gridSize) % 2) {
background = {1, 1, 1};
}
else {
background = {0.86, 0.86, 0.86};
c = zeno::pow(c, 1.0f / 2.2f);
}
zeno::vec3f c = zeno::mix(background, foreground, alpha[i]);

int r = glm::clamp(int(c[0] * 255.99), 0, 255);
int g = glm::clamp(int(c[1] * 255.99), 0, 255);
int b = glm::clamp(int(c[2] * 255.99), 0, 255);
auto index = std::map<QString, zeno::vec3i>{
{"RGB", {0, 1, 2}},
{"Red", {0, 0, 0}},
{"Green", {1, 1, 1}},
{"Blue", {2, 2, 2}},
}.at(pMode->currentText());
int r = glm::clamp(int(c[index[0]] * 255.99), 0, 255);
int g = glm::clamp(int(c[index[1]] * 255.99), 0, 255);
int b = glm::clamp(int(c[index[2]] * 255.99), 0, 255);

img.setPixel(w, height - 1 - h, qRgb(r, g, b));
//img.setPixel(width - 1 - w, h, qRgb(r, g, b));
}
image_view->setImage(img);
}
else{
for (auto i = 0; i < obj->verts.size(); i++) {
int h = i / width;
int w = i % width;
auto c = obj->verts[i];
if (enableGamma) {
c = zeno::pow(c, 1.0f / 2.2f);
}
int r = glm::clamp(int(c[0] * 255.99), 0, 255);
int g = glm::clamp(int(c[1] * 255.99), 0, 255);
int b = glm::clamp(int(c[2] * 255.99), 0, 255);
else if (pMode->currentText() == "Alpha") {
QImage img(width, height, QImage::Format_RGB32);
if (obj->verts.has_attr("alpha")) {
auto &alpha = obj->verts.attr<float>("alpha");
for (auto i = 0; i < obj->verts.size(); i++) {
int h = i / width;
int w = i % width;
auto c = alpha[i];
int r = glm::clamp(int(c * 255.99), 0, 255);
int g = glm::clamp(int(c * 255.99), 0, 255);
int b = glm::clamp(int(c * 255.99), 0, 255);

img.setPixel(w, height - 1 - h, qRgb(r, g, b));
img.setPixel(w, height - 1 - h, qRgb(r, g, b));
}
}
image_view->setImage(img);
}
image_view->setImage(img);
}
QString statusInfo = QString(zeno::format("width: {}, height: {}", width, height).c_str());
pStatusBar->setText(statusInfo);
Expand Down Expand Up @@ -140,9 +133,13 @@ ZenoImagePanel::ZenoImagePanel(QWidget *parent) : QWidget(parent) {
pGamma->setCheckState(Qt::Checked);
pTitleLayout->addWidget(pGamma);

pAlpha->setStyleSheet("color: white;");
pAlpha->setCheckState(Qt::Unchecked);
pTitleLayout->addWidget(pAlpha);
pMode->addItem("RGB");
pMode->addItem("Red");
pMode->addItem("Green");
pMode->addItem("Blue");
pMode->addItem("Alpha");
pMode->setCurrentIndex(0);
pTitleLayout->addWidget(pMode);

pFit->setProperty("cssClass", "grayButton");
pTitleLayout->addWidget(pFit);
Expand Down Expand Up @@ -197,7 +194,7 @@ ZenoImagePanel::ZenoImagePanel(QWidget *parent) : QWidget(parent) {
}
}
});
connect(pAlpha, &QCheckBox::stateChanged, this, [=](int state) {
connect(pMode, &ZComboBox::_textActivated, [=](const QString& text) {
std::string prim_name = pPrimName->text().toStdString();
Zenovis* zenovis = wids[0]->getZenoVis();
ZASSERT_EXIT(zenovis);
Expand Down Expand Up @@ -245,17 +242,30 @@ ZenoImagePanel::ZenoImagePanel(QWidget *parent) : QWidget(parent) {
int height = ud.get2<int>("h");
int w = int(zeno::clamp(x, 0, width - 1));
int h = int(zeno::clamp(y, 0, height - 1));
int i = h * width + w;
int i = (height - 1 - h) * width + w;
auto c = obj->verts[i];
QString statusInfo = QString(zeno::format("width: {}, height: {} | ({}, {}) : ({}, {}, {})"
, width
, height
, w
, h
, c[0]
, c[1]
, c[2]
).c_str());
std::string info = zeno::format("width: {}, height: {}", width, height);
info += zeno::format(" | x: {}, y: {}", w, h);
if (pMode->currentText() == "RGB") {
info += zeno::format(" | value: {}, {}, {}", c[0], c[1], c[2]);
}
else if (pMode->currentText() == "Red") {
info += zeno::format(" | value: {}", c[0]);
}
else if (pMode->currentText() == "Green") {
info += zeno::format(" | value: {}", c[1]);
}
else if (pMode->currentText() == "Blue") {
info += zeno::format(" | value: {}", c[2]);
}
else if (pMode->currentText() == "Alpha") {
if (obj->verts.has_attr("alpha")) {
auto &alpha = obj->verts.attr<float>("alpha");
info += zeno::format(" | value: {}", alpha[i]);
}
}

QString statusInfo = QString(info.c_str());
pStatusBar->setText(statusInfo);
}
}
Expand Down
3 changes: 2 additions & 1 deletion ui/zenoedit/panel/zenoimagepanel.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#define ZENO_ZENOIMAGEPANEL_H

#include <QtWidgets>
#include <zenoui/comctrl/zcombobox.h>

class ZenoImageView: public QGraphicsView {
Q_OBJECT
Expand Down Expand Up @@ -92,7 +93,7 @@ class ZenoImagePanel : public QWidget {
QLabel* pStatusBar = new QLabel();
QLabel* pPrimName = new QLabel();
QCheckBox *pGamma = new QCheckBox("Gamma");
QCheckBox *pAlpha = new QCheckBox("Checkerboard");
ZComboBox *pMode = new ZComboBox();
QPushButton *pFit = new QPushButton("Fit");
ZenoImageView *image_view = nullptr;

Expand Down