35 void MatrixDatafieldDisplayWidget::updateRequested()
38 this->data = matrixDatafieldOffsetFiltered->getDataField()->get<
MatrixFloat>()->
toEigen();
39 this->percentiles = percentilesDatafield->getDataField()->get<
MatrixFloat>()->toVector();
47 this->matrixDatafield = DatafieldRefPtr::dynamicCast(matrixDatafield);
48 this->observer = observer;
51 this->data = MatrixXf(1, 1);
54 QColor
c[] = {QColor::fromHsv(0, 0, 0), QColor::fromHsv(240, 255, 255), QColor::fromHsv(270, 255, 255), QColor::fromHsv(300, 255, 255),
55 QColor::fromHsv(0, 255, 255), QColor::fromHsv(30, 255, 255), QColor::fromHsv(60, 255, 255)
57 this->colors = std::valarray<QColor>(
c,
sizeof c /
sizeof c[0]);
60 connect(
this, SIGNAL(
doUpdate()), SLOT(updateRequested()), Qt::QueuedConnection);
72 int paddingBottom = 40;
73 QPainter painter(
this);
74 painter.fillRect(rect(), QColor::fromRgb(0, 0, 0));
75 int matrixHeight = (height() - paddingBottom) * 8 / 10;
76 int percentilesHeight = (height() - paddingBottom) - matrixHeight;
77 drawMatrix(QRect(0, 0, width(), matrixHeight), painter);
78 drawPercentiles(QRect(0, matrixHeight, width() - 1, percentilesHeight), painter);
80 painter.setPen(QColor(Qt::GlobalColor::gray));
81 painter.setFont(QFont(
"Arial", 12));
82 painter.drawText(rect(), Qt::AlignBottom | Qt::AlignRight, infoOverlay);
91 this->matrixDatafieldOffsetFiltered = DatafieldRefPtr::dynamicCast(observer->createFilteredDatafield(DatafieldFilterBasePtr(
new filters::OffsetFilter()), matrixDatafield));
95 this->matrixDatafieldOffsetFiltered = this->matrixDatafield;
98 this->percentilesDatafield = DatafieldRefPtr::dynamicCast(observer->createFilteredDatafield(DatafieldFilterBasePtr(
new filters::MatrixPercentilesFilter(50)), matrixDatafieldOffsetFiltered));
110 if (
value >= colors.size() - 1)
112 return colors[colors.size() - 1];
116 float f2 =
value - i;
118 QColor c1 = colors[i];
119 QColor c2 = colors[i + 1];
120 return QColor((
int)(c1.red() * f1 + c2.red() * f2), (
int)(c1.green() * f1 + c2.green() * f2), (
int)(c1.blue() * f1 + c2.blue() * f2));
123 void MatrixDatafieldDisplayWidget::drawMatrix(
const QRect&
target, QPainter& painter)
126 int dx = (
target.width() - pixelSize * data.cols()) / 2;
127 int dy = (
target.height() - pixelSize * data.rows()) / 2;
128 painter.setFont(QFont(
"Arial", 8));
129 painter.setPen(QColor(Qt::GlobalColor::gray));
131 for (
int x = 0; x < data.cols(); x++)
133 for (
int y = 0; y < data.rows(); y++)
135 QRect
target = QRect(dx + x * pixelSize, dy + y * pixelSize, pixelSize, pixelSize);
137 painter.drawText(
target, Qt::AlignCenter, QString::number(data(y, x)));
142 void MatrixDatafieldDisplayWidget::drawPercentiles(
const QRect&
target, QPainter& painter)
144 painter.setPen(QColor(Qt::GlobalColor::gray));
148 for (
int i = 0; i < (int)percentiles.size() - 1; i++)
150 int x1 = i *
target.width() / (percentiles.size() - 1);
151 int x2 = (i + 1) *
target.width() / (percentiles.size() - 1);
152 float y1 = (percentiles.at(i) - min) / (max - min) *
target.height();
153 float y2 = (percentiles.at(i + 1) - min) / (max - min) *
target.height();