MatrixDisplayWidget.cpp
Go to the documentation of this file.
1 /*
2  * This file is part of ArmarX.
3  *
4  * Copyright (C) 2011-2016, High Performance Humanoid Technologies (H2T), Karlsruhe Institute of Technology (KIT), all rights reserved.
5  *
6  * ArmarX is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 as
8  * published by the Free Software Foundation.
9  *
10  * ArmarX is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  *
18  * @package
19  * @author
20  * @date
21  * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
22  * GNU General Public License
23  */
24 #include "MatrixDisplayWidget.h"
25 #include <RobotAPI/gui-plugins/HapticUnitPlugin/ui_MatrixDisplayWidget.h>
26 
27 #include <QPainter>
28 #include <pthread.h>
29 #include <iostream>
30 
31 namespace armarx
32 {
34  QWidget(parent),
35  ui(new Ui::MatrixDisplayWidget)
36  {
37  ui->setupUi(this);
38  this->min = 0;
39  this->max = 1;
40  this->data = MatrixXf(1, 1);
41  this->data(0, 0) = 0;
42  QColor c[] = {QColor::fromHsv(0, 0, 0), QColor::fromHsv(240, 255, 255), QColor::fromHsv(270, 255, 255), QColor::fromHsv(300, 255, 255),
43  QColor::fromHsv(0, 255, 255), QColor::fromHsv(30, 255, 255), QColor::fromHsv(60, 255, 255)
44  };
45  this->colors = std::valarray<QColor>(c, sizeof c / sizeof c[0]);
46 
47  //connect(this, SIGNAL(updateData(MatrixXf)), SLOT(setData(MatrixXf)), Qt::QueuedConnection);
48  connect(this, SIGNAL(doUpdate()), SLOT(update()), Qt::QueuedConnection);
49  }
50 
52  {
53  delete ui;
54  }
55 
57  {
58  mtx.lock();
59  MatrixXf data = this->data;
60 
61  //cout << "[" << pthread_self() << "] MatrixDisplayWidget::paintEvent" << endl;
62 
63  int pixelSize = std::min(width() / data.cols(), height() / data.rows());
64  int dx = (width() - pixelSize * data.cols()) / 2;
65  int dy = (height() - pixelSize * data.rows()) / 2;
66  QPainter painter(this);
67  painter.fillRect(rect(), QColor::fromRgb(0, 0, 0));
68  painter.setFont(QFont("Arial", 8));
69 
70  for (int x = 0; x < data.cols(); x++)
71  {
72  for (int y = 0; y < data.rows(); y++)
73  {
74  QRect target = QRect(dx + x * pixelSize, dy + y * pixelSize, pixelSize, pixelSize);
75  painter.fillRect(target, getColor(data(y, x), min, max));
76  painter.drawText(target, Qt::AlignCenter, QString::number(data(y, x)));
77  }
78  }
79 
80  painter.setFont(QFont("Arial", 12));
81  painter.drawText(rect(), Qt::AlignBottom | Qt::AlignRight, infoOverlay);
82 
83  mtx.unlock();
84  }
85 
86  QColor MatrixDisplayWidget::getColor(float value, float min, float max)
87  {
88  value = (value - min) / (max - min) * (colors.size() - 1);
89 
90  if (value < 0)
91  {
92  return colors[0];
93  }
94 
95  if (value >= colors.size() - 1)
96  {
97  return colors[colors.size() - 1];
98  }
99 
100  int i = (int)value;
101  float f2 = value - i;
102  float f1 = 1 - f2;
103  QColor c1 = colors[i];
104  QColor c2 = colors[i + 1];
105  return QColor((int)(c1.red() * f1 + c2.red() * f2), (int)(c1.green() * f1 + c2.green() * f2), (int)(c1.blue() * f1 + c2.blue() * f2));
106  }
107 }
MatrixDisplayWidget.h
boost::target
Vertex target(const detail::edge_base< Directed, Vertex > &e, const PCG &)
Definition: point_cloud_graph.h:688
armarx::max
std::vector< T > max(const std::vector< T > &v1, const std::vector< T > &v2)
Definition: VectorHelpers.h:267
c
constexpr T c
Definition: UnscentedKalmanFilterTest.cpp:43
armarx::MatrixDisplayWidget::MatrixDisplayWidget
MatrixDisplayWidget(QWidget *parent=0)
Definition: MatrixDisplayWidget.cpp:33
cxxopts::value
std::shared_ptr< Value > value()
Definition: cxxopts.hpp:926
Ui
ArmarX Headers.
Definition: ArmarXMainWindow.h:58
armarx::MatrixDisplayWidget::getColor
QColor getColor(float value, float min, float max)
Definition: MatrixDisplayWidget.cpp:86
data
uint8_t data[1]
Definition: EtherCATFrame.h:68
armarx::MatrixDisplayWidget::~MatrixDisplayWidget
~MatrixDisplayWidget() override
Definition: MatrixDisplayWidget.cpp:51
armarx::MatrixDisplayWidget::doUpdate
void doUpdate()
armarx::armem::server::ltm::util::mongodb::detail::update
bool update(mongocxx::collection &coll, const nlohmann::json &query, const nlohmann::json &update)
Definition: mongodb.cpp:67
armarx::MatrixDisplayWidget
Definition: MatrixDisplayWidget.h:40
armarx::min
std::vector< T > min(const std::vector< T > &v1, const std::vector< T > &v2)
Definition: VectorHelpers.h:294
min
T min(T t1, T t2)
Definition: gdiam.h:42
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28
armarx::MatrixDisplayWidget::paintEvent
void paintEvent(QPaintEvent *) override
Definition: MatrixDisplayWidget.cpp:56