101 qreal norm1 = tf_matrix.maxCoeff();
102 qreal mnorm = tf_matrix.minCoeff();
103 if (std::fabs(mnorm) > norm1)
108 QImage* image_to_tf_plot =
new QImage(tf_matrix.cols(), tf_matrix.rows(), QImage::Format_RGB32);
112 for (qint32 y = 0; y < tf_matrix.rows(); y++) {
113 for (qint32 x = 0; x < tf_matrix.cols(); x++) {
134 image_to_tf_plot->setPixel(x, tf_matrix.rows() - 1 - y, color.rgb());
138 *image_to_tf_plot = image_to_tf_plot->scaled(tf_matrix.cols(), tf_matrix.cols() / 2, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
139 *image_to_tf_plot = image_to_tf_plot->scaledToWidth( 1026, Qt::SmoothTransformation);
141 QGraphicsPixmapItem* tf_pixmap =
new QGraphicsPixmapItem(QPixmap::fromImage(*image_to_tf_plot));
143 QGraphicsScene* tf_scene =
new QGraphicsScene();
144 tf_scene->addItem(tf_pixmap);
146 QImage* coeffs_image =
new QImage(10, tf_matrix.rows(), QImage::Format_RGB32);
147 qreal norm = tf_matrix.maxCoeff();
148 for (qint32 it = 0; it < tf_matrix.rows(); it++) {
149 for (qint32 x = 0; x < 10; x++) {
170 coeffs_image->setPixel(x, tf_matrix.rows() - 1 - it, color.rgb());
174 *coeffs_image = coeffs_image->scaled(10, tf_matrix.cols() / 2, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
175 *coeffs_image = coeffs_image->scaledToHeight(image_to_tf_plot->height(), Qt::SmoothTransformation);
177 QLayout* layout =
new QGridLayout();
178 QGraphicsView* view =
new QGraphicsView();
179 view->setObjectName(
"tf_view");
180 view->setScene(tf_scene);
181 QLinearGradient lgrad(tf_scene->sceneRect().topLeft(), tf_scene->sceneRect().bottomRight());
182 lgrad.setColorAt(0.0, Qt::white);
183 lgrad.setColorAt(1.0, Qt::lightGray);
185 tf_scene->setBackgroundBrush(lgrad);
188 QGraphicsTextItem* x_axis_name =
new QGraphicsTextItem(
"time [sec]", tf_pixmap);
189 x_axis_name->setFont(QFont(
"arial", 14));
191 QList<QGraphicsItem*> x_axis_values;
192 QList<QGraphicsItem*> x_axis_lines;
194 qreal scaleXText = (tf_matrix.cols() - 1) / sample_rate / 20.0;
196 for (qint32 j = 0; j < 21; j++) {
197 QGraphicsTextItem* text_item =
new QGraphicsTextItem(QString::number(j * scaleXText,
'f', 2), tf_pixmap);
198 text_item->setFont(QFont(
"arial", 10));
199 x_axis_values.append(text_item);
200 QGraphicsLineItem* x_line_item =
new QGraphicsLineItem(tf_pixmap);
201 x_line_item->setLine(0, -3, 0, 3);
202 x_line_item->setPen(QPen(Qt::darkGray, 2, Qt::SolidLine, Qt::SquareCap, Qt::MiterJoin));
203 x_axis_lines.append(x_line_item);
206 x_axis_name->setPos(tf_pixmap->boundingRect().width() / 2 - x_axis_name->boundingRect().width() / 2,
207 tf_pixmap->boundingRect().height() + 0.8 * x_axis_values.at(0)->boundingRect().height());
209 qreal scale_x = qreal(tf_pixmap->boundingRect().width()) / qreal(x_axis_values.length() - 1);
211 for (qint32 i = 0; i < x_axis_values.length(); i++) {
212 x_axis_values.at(i)->setPos(qreal(i) * scale_x - x_axis_values.at(0)->boundingRect().width() / 2,
213 tf_pixmap->boundingRect().height());
214 x_axis_lines.at(i)->setPos(qreal(i) * scale_x,
215 tf_pixmap->boundingRect().height());
220 QGraphicsTextItem* y_axis_name =
new QGraphicsTextItem(
"frequency [Hz]", tf_pixmap);
221 y_axis_name->setFont(QFont(
"arial", 14));
223 QList<QGraphicsItem*> y_axis_values;
224 QList<QGraphicsItem*> y_axis_lines;
226 qreal scale_y_text = 0;
228 if (lower_frq == 0 && upper_frq == 0) {
229 scale_y_text = 0.5 * sample_rate / 10.0;
231 scale_y_text = (upper_frq - lower_frq) / 10.0;
234 for (qint32 j = 0; j < 11; j++) {
235 QGraphicsTextItem* text_item =
new QGraphicsTextItem(QString::number(lower_frq + j * scale_y_text,
238 text_item->setFont(QFont(
"arial", 10));
239 y_axis_values.append(text_item);
240 QGraphicsLineItem* y_line_item =
new QGraphicsLineItem(tf_pixmap);
241 y_line_item->setLine(-3, 0, 3, 0);
242 y_line_item->setPen(QPen(Qt::darkGray, 2, Qt::SolidLine, Qt::SquareCap, Qt::MiterJoin));
243 y_axis_lines.append(y_line_item);
246 y_axis_name->setPos(-x_axis_values.at(0)->boundingRect().width() - y_axis_name->boundingRect().height(),
247 tf_pixmap->boundingRect().height() / 2 + y_axis_name->boundingRect().height() / 2);
248 y_axis_name->setRotation(-90);
250 qreal scale_y = qreal(tf_pixmap->boundingRect().height()) / qreal(y_axis_values.length() - 1);
252 for (qint32 i = 0; i < y_axis_values.length(); i++) {
253 y_axis_values.at(i)->setPos(-y_axis_values.last()->boundingRect().width() - 0.5 * y_axis_lines.last()->boundingRect().width() - 1, tf_pixmap->boundingRect().height() - y_axis_values.last()->boundingRect().height() / 2 - qreal(i) * scale_y);
254 y_axis_lines.at(i)->setPos(0, qreal(i) * scale_y);
258 QGraphicsPixmapItem* coeffs_item = tf_scene->addPixmap(QPixmap::fromImage(*coeffs_image));
259 coeffs_item->setParentItem(tf_pixmap);
260 coeffs_item->setPos(tf_pixmap->boundingRect().width() + 5, 0);
262 QGraphicsSimpleTextItem* axis_name_item =
new QGraphicsSimpleTextItem(
"coefficients", coeffs_item);
263 QGraphicsSimpleTextItem* axis_zero_item =
new QGraphicsSimpleTextItem(
"0", coeffs_item);
264 QGraphicsSimpleTextItem* axis_one_item =
new QGraphicsSimpleTextItem(
"1", coeffs_item);
265 axis_name_item->setFont(QFont(
"arial", 14));
266 axis_zero_item->setFont(QFont(
"arial", 10));
267 axis_one_item->setFont(QFont(
"arial", 10));
269 axis_name_item->setPos(coeffs_item->boundingRect().width() + 1,
270 coeffs_item->boundingRect().height() / 2 + axis_name_item->boundingRect().height() / 2);
271 axis_name_item->setRotation(-90);
272 axis_zero_item->setPos(1 + coeffs_item->boundingRect().width(),
273 coeffs_item->boundingRect().height() - axis_zero_item->boundingRect().height());
274 axis_one_item->setPos(1 + coeffs_item->boundingRect().width(), 0);
277 view->fitInView(layout->contentsRect(), Qt::KeepAspectRatio);
278 layout->addWidget(view);
279 this->setLayout(layout);