1 #include <QDockWidget>
2 #include <meshlab/glarea.h>
3 #include "edit_mutualcorrsDialog.h"
4 #include "ui_edit_mutualcorrsDialog.h"
5 #include "edit_mutualcorrs.h"
6 
edit_mutualcorrsDialog(QWidget * parent,EditMutualCorrsPlugin * plugin)7 edit_mutualcorrsDialog::edit_mutualcorrsDialog(QWidget *parent, EditMutualCorrsPlugin *plugin) : QDockWidget(parent), ui(new Ui::edit_mutualcorrsDialog)
8 {
9     ui->setupUi(this);
10     this->setWidget(ui->frame);
11     this->setFeatures(QDockWidget::AllDockWidgetFeatures);
12     this->setAllowedAreas(Qt::LeftDockWidgetArea);
13     QPoint p = parent->mapToGlobal(QPoint(0,0));
14     this->setFloating(true);
15     this->setGeometry(p.x()+(parent->width() - this->width()), p.y() + 40, this->width(), this->height());
16 
17     this->mutualcorrsPlugin = plugin;
18 }
19 
~edit_mutualcorrsDialog()20 edit_mutualcorrsDialog::~edit_mutualcorrsDialog()
21 {
22     delete ui;
23 }
24 
closeEvent(QCloseEvent *)25 void edit_mutualcorrsDialog::closeEvent(QCloseEvent * /*event*/)
26 {
27     emit closing();
28 }
29 
updateTable()30 void edit_mutualcorrsDialog::updateTable()
31 {
32     this->mutualcorrsPlugin->status_error = "";
33     this->ui->tableWidget->clear();
34     this->ui->tableWidget->setRowCount(int(this->mutualcorrsPlugin->usePoint.size()));
35 
36 	this->ui->tableWidget->setHorizontalHeaderLabels(QString("Active; ID ;X (3D);Y (3D);Z (3D);X (2D);Y (2D);Error").split(";"));
37 
38     this->ui->tableWidget->setSelectionMode(QAbstractItemView::SingleSelection);
39     this->ui->tableWidget->setSelectionBehavior(QAbstractItemView::SelectRows);
40 
41     for(size_t pindex=0; pindex < this->mutualcorrsPlugin->usePoint.size(); pindex++)
42     {
43         QTableWidgetItem* useIt = new QTableWidgetItem();
44         if(this->mutualcorrsPlugin->usePoint[pindex])
45         {
46             useIt->setText("active");
47             useIt->setBackground(QBrush(QColor::fromRgbF(0.8, 0.9, 0.8)));
48         }
49         else
50         {
51             useIt->setText("inactive");
52             useIt->setBackground(QBrush(QColor::fromRgbF(0.9, 0.8, 0.8)));
53         }
54         useIt->setFlags(useIt->flags() ^ Qt::ItemIsEditable);
55         this->ui->tableWidget->setItem(pindex, 0, useIt);
56 
57         QTableWidgetItem* id = new QTableWidgetItem(this->mutualcorrsPlugin->pointID[pindex]);
58         this->ui->tableWidget->setItem(pindex, 1, id);
59 
60         QTableWidgetItem* pickX = new QTableWidgetItem(QString::number(this->mutualcorrsPlugin->modelPoints[pindex][0]));
61         pickX->setBackground(QBrush(QColor::fromRgb(233, 233, 155)));
62         this->ui->tableWidget->setItem(pindex, 2, pickX);
63         QTableWidgetItem* pickY = new QTableWidgetItem(QString::number(this->mutualcorrsPlugin->modelPoints[pindex][1]));
64         pickY->setBackground(QBrush(QColor::fromRgb(233, 233, 155)));
65         this->ui->tableWidget->setItem(pindex, 3, pickY);
66         QTableWidgetItem* pickZ = new QTableWidgetItem(QString::number(this->mutualcorrsPlugin->modelPoints[pindex][2]));
67         pickZ->setBackground(QBrush(QColor::fromRgb(233, 233, 155)));
68         this->ui->tableWidget->setItem(pindex, 4, pickZ);
69 
70         QTableWidgetItem* refX = new QTableWidgetItem(QString::number(this->mutualcorrsPlugin->imagePoints[pindex][0]));
71         refX->setBackground(QBrush(QColor::fromRgb(155, 233, 233)));
72         this->ui->tableWidget->setItem(pindex, 5, refX);
73         QTableWidgetItem* refY = new QTableWidgetItem(QString::number(this->mutualcorrsPlugin->imagePoints[pindex][1]));
74         refY->setBackground(QBrush(QColor::fromRgb(155, 233, 233)));
75         this->ui->tableWidget->setItem(pindex, 6, refY);
76        /* QTableWidgetItem* refZ = new QTableWidgetItem(QString::number(this->mutualcorrsPlugin->imagePoints[pindex][2]));
77         refZ->setBackground(QBrush(QColor::fromRgb(155, 233, 233)));
78         this->ui->tableWidget->setItem(pindex, 7, refZ);*/
79 
80         QTableWidgetItem* error = new QTableWidgetItem(QString::number(this->mutualcorrsPlugin->pointError[pindex]));
81         error->setFlags(error->flags() ^ Qt::ItemIsEditable);
82         error->setBackground(QBrush(QColor::fromRgbF(0.9, 0.7, 0.7)));
83         this->ui->tableWidget->setItem(pindex, 7, error);
84     }
85 
86     this->mutualcorrsPlugin->glArea->update();
87     return;
88 }
89 
on_tableWidget_itemChanged(QTableWidgetItem * item)90 void edit_mutualcorrsDialog::on_tableWidget_itemChanged(QTableWidgetItem *item)
91 {
92     this->mutualcorrsPlugin->status_error = "";
93     // an item in the table has changed
94     int rowInd = this->ui->tableWidget->currentRow();
95     int colInd = this->ui->tableWidget->currentColumn();
96 
97     if((rowInd == -1)||(colInd == -1))
98         return;
99 
100     if(colInd == 1) // id is just a text, just transfer it
101     {
102         this->mutualcorrsPlugin->pointID[rowInd] = item->text();
103         this->mutualcorrsPlugin->glArea->update();
104         return;
105     }
106 
107     if(colInd == 2) //check numerical value
108     {
109         bool convOK;
110         double newDValue = item->text().toDouble(&convOK);
111 
112         if(convOK)
113             this->mutualcorrsPlugin->modelPoints[rowInd][0] = newDValue;
114         else
115             item->setText(QString::number(this->mutualcorrsPlugin->modelPoints[rowInd][0]));
116 
117         this->mutualcorrsPlugin->glArea->update();
118         return;
119     }
120 
121     if(colInd == 3) //check numerical value
122     {
123         bool convOK;
124         double newDValue = item->text().toDouble(&convOK);
125 
126         if(convOK)
127             this->mutualcorrsPlugin->modelPoints[rowInd][1] = newDValue;
128         else
129             item->setText(QString::number(this->mutualcorrsPlugin->modelPoints[rowInd][1]));
130 
131         this->mutualcorrsPlugin->glArea->update();
132         return;
133     }
134 
135     if(colInd == 4) //check numerical value
136     {
137         bool convOK;
138         double newDValue = item->text().toDouble(&convOK);
139 
140         if(convOK)
141             this->mutualcorrsPlugin->modelPoints[rowInd][2] = newDValue;
142         else
143             item->setText(QString::number(this->mutualcorrsPlugin->modelPoints[rowInd][2]));
144 
145         this->mutualcorrsPlugin->glArea->update();
146         return;
147     }
148 
149     if(colInd == 5) //check numerical value
150     {
151         bool convOK;
152         double newDValue = item->text().toDouble(&convOK);
153 
154         if(convOK)
155             this->mutualcorrsPlugin->imagePoints[rowInd][0] = newDValue;
156         else
157             item->setText(QString::number(this->mutualcorrsPlugin->imagePoints[rowInd][0]));
158 
159         this->mutualcorrsPlugin->glArea->update();
160         return;
161     }
162 
163     if(colInd == 6) //check numerical value
164     {
165         bool convOK;
166         double newDValue = item->text().toDouble(&convOK);
167 
168         if(convOK)
169             this->mutualcorrsPlugin->imagePoints[rowInd][1] = newDValue;
170         else
171             item->setText(QString::number(this->mutualcorrsPlugin->imagePoints[rowInd][1]));
172 
173         this->mutualcorrsPlugin->glArea->update();
174         return;
175     }
176 
177     //if(colInd == 7) //check numerical value
178     //{
179     //    bool convOK;
180     //    double newDValue = item->text().toDouble(&convOK);
181 
182     //    if(convOK)
183     //        this->mutualcorrsPlugin->imagePoints[rowInd][2] = newDValue;
184     //    else
185     //        item->setText(QString::number(this->mutualcorrsPlugin->imagePoints[rowInd][2]));
186 
187     //    this->mutualcorrsPlugin->glArea->update();
188     //    return;
189     //}
190 
191 }
192 
on_tableWidget_cellDoubleClicked(int row,int column)193 void edit_mutualcorrsDialog::on_tableWidget_cellDoubleClicked(int row, int column)
194 {
195     this->mutualcorrsPlugin->status_error = "";
196     // only significative for forst column, to toggle between active<->inactive
197     if(column == 0)
198     {
199         this->mutualcorrsPlugin->usePoint[row] = !(this->mutualcorrsPlugin->usePoint[row]);
200 
201         if(this->mutualcorrsPlugin->usePoint[row])
202         {
203             this->ui->tableWidget->item(row,column)->setText("active");
204             this->ui->tableWidget->item(row,column)->setBackground(QBrush(QColor::fromRgbF(0.8, 0.9, 0.8)));
205         }
206         else
207         {
208             this->ui->tableWidget->item(row,column)->setText("inactive");
209             this->ui->tableWidget->item(row,column)->setBackground(QBrush(QColor::fromRgbF(0.9, 0.8, 0.8)));
210         }
211     }
212 
213     this->mutualcorrsPlugin->glArea->update();
214     return;
215 }
216 
on_tableWidget_currentCellChanged(int,int,int,int)217 void edit_mutualcorrsDialog::on_tableWidget_currentCellChanged(int /*currentRow*/, int /*currentColumn*/, int /*previousRow*/, int /*previousColumn*/)
218 {
219     this->mutualcorrsPlugin->status_error = "";
220     this->mutualcorrsPlugin->glArea->update();
221     return;
222 }
223