123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289 |
- #pragma execution_character_set("utf-8")
- #include "blobselectshape.h"
- #include "ui_blobselectshape.h"
- #include "../ToolDialog.h"
- class ToolDialogImpl;
- BlobSelectShape::BlobSelectShape(QWidget *parent , ToolDialogImpl* p)
- : ToolInterface(parent), ui(new Ui::BlobSelectShape)
- {
- ui->setupUi(this);
- m_pToolDialogImpl = p;
- ui->tableWidget->verticalHeader()->setVisible(false);
- ui->tableWidget->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
- ui->tableWidget->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
- ui->tableWidget->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
- ui->tableWidget->setFocusPolicy(Qt::NoFocus);
- ui->tableWidget->setShowGrid(false);
- ui->tableWidget->setSelectionBehavior(QAbstractItemView::SelectRows);
- QMenu *menu = new QMenu();
- QMenu* shuxing = menu->addMenu("属性");
- shuxing->addAction("面积", this, SLOT(ActionSlot()));
- shuxing->addAction("X", this, SLOT(ActionSlot()));
- shuxing->addAction("Y", this, SLOT(ActionSlot()));
- shuxing->addAction("宽度", this, SLOT(ActionSlot()));
- shuxing->addAction("高度", this, SLOT(ActionSlot()));
- shuxing->addAction("角度", this, SLOT(ActionSlot()));
- QMenu *xingtai = menu->addMenu("形态");
- xingtai->addAction("圆度", this, SLOT(ActionSlot()));
- xingtai->addAction("紧密度", this, SLOT(ActionSlot()));
- xingtai->addAction("凸度", this, SLOT(ActionSlot()));
- xingtai->addAction("矩形度", this, SLOT(ActionSlot()));
- xingtai->addAction("最大内接", this, SLOT(ActionSlot()));
- ui->BTN_Add->setMenu(menu);
- ui->comboBox->setView(new QListView());
- ui->comboBox_index->setView(new QListView());
- if(m_pToolDialogImpl->m_LinkProcess.size() > 0)
- {
- ui->comboBox_index->setVisible(true);
- ui->label_index->setVisible(true);
- }
- else
- {
- ui->comboBox_index->setVisible(false);
- ui->label_index->setVisible(false);
- }
- for(int i = 0; i < m_pToolDialogImpl->m_LinkProcess.size(); i++)
- {
- ui->comboBox_index->addItem(QString::number(i));
- }
- m_NamesMap.insert("面积", "area");
- m_NamesMap.insert("X", "column");
- m_NamesMap.insert("Y", "row");
- m_NamesMap.insert("宽度", "width");
- m_NamesMap.insert("高度", "height");
- m_NamesMap.insert("角度", "rect2_phi");
- m_NamesMap.insert("紧密度", "compactness");
- m_NamesMap.insert("凸度", "convexity");
- m_NamesMap.insert("矩形度", "rectangularity");
- m_NamesMap.insert("最大内接", "max_diameter");
- }
- void BlobSelectShape::ActionSlot()
- {
- QAction* action = (QAction*)sender();
- QString strName = action->text();
- AddTool(strName, 0 , 999999 );
- }
- BlobSelectShape::~BlobSelectShape()
- {
- delete ui;
- }
- bool BlobSelectShape::Serialized(QDataStream& ar, bool bIsOut)
- {
- int paranum;//参数数量
- if (bIsOut)//保存参数流程
- {
- paranum = 3;//以下参数的数量
- ar << paranum;//先保存参数数量
- ar << (UINT)m_AllScreening.size();
- for (UINT i = 0; i < m_AllScreening.size(); i++)
- {
- Screening nScreening = m_AllScreening[i];
- ar << (int)1 << nScreening.strName;
- ar << (int)2 << nScreening.nMin;
- ar << (int)3 << nScreening.nMax;
- }
- }
- else//加载参数流程,参数加载顺序一定要跟保存顺序一致
- {
- m_AllScreening.clear();
- ui->tableWidget->clear();
- UINT nToolSize = 0;
- ar >> paranum;//读取参数数量
- ar >> nToolSize;
- for (UINT i = 0; i < nToolSize; i++)
- {
- int nToolID = 0;
- QString strName;
- int nMin;
- int nMax;
- int nPpara;
- for (int j = 0; j < paranum; j++)
- {
- ar >> nPpara;
- switch (nPpara)
- {
- case 1: ar >> strName; break;
- case 2: ar >> nMin; break;
- case 3: ar >> nMax; break;
- default:
- return false;
- }
- }
- AddTool(strName, nMin, nMax);
-
- }
- emit updateParameter(ShowParameter());
- }
- return true;
- }
- QString BlobSelectShape::ShowParameter()
- {
- m_Key.Clear();
- m_MinValue.Clear();
- m_MaxValue.Clear();
- for (int i = 0; i < m_AllScreening.size(); i++)
- {
- Screening nScreening = m_AllScreening[i];
- QString strName = m_NamesMap.value(nScreening.strName);
- int nMin = nScreening.nMin;
- int nMax = nScreening.nMax;
- m_Key[i] = HTuple(strName.toStdString().c_str());
- m_MinValue[i] = HTuple(nMin);
- m_MaxValue[i] = HTuple(nMax);
- // if (i != 0)
- // {
- // m_Key.Append();
- //
- // m_MinValue.Append(HTuple(nMin));
- // m_MaxValue.Append(HTuple(nMax));
- // }
- // else
- // {
- // m_Key = HTuple(strName.toStdString().c_str());
- // m_MinValue = HTuple(nMin);
- // m_MaxValue = HTuple(nMax);
- // }
- }
- // SelectShape(ho_ConnectedRegions, &ho_SelectedRegions, (HTuple("width").Append("height")), "and", (HTuple(1000).Append(200)), (HTuple(2000).Append(1000)));
- return ui->comboBox->currentText();
- }
- int BlobSelectShape::Execute()
- {
- int result = 1;
- try
- {
- if (m_AllScreening.size() == 0)
- {
- m_OutImage = m_InImage;
- }
- else
- {
- if (ui->comboBox_index->currentIndex() == 0)
- {
- SelectShape(m_InImage, &m_OutImage, m_Key, "and", m_MinValue, m_MaxValue);
- }
- else
- {
- SelectShape(m_InImage, &m_OutImage, m_Key, "or", m_MinValue, m_MaxValue);
- }
- }
- }
- catch(...)
- {
- vWarning() << "Error";
- }
- return result;
- }
- void BlobSelectShape::AddTool(QString strName, int nMin, int nMax)
- {
- int nIndex = m_AllScreening.size();
-
- Screening nScreening;
- nScreening.nIndex = nIndex;
- nScreening.strName = strName;
- nScreening.nMin = nMin;
- nScreening.nMax = nMax;
- m_AllScreening.push_back(nScreening);
- ui->tableWidget->setRowCount(nIndex + 1);
- ui->tableWidget->setItem(nIndex, 0, new QTableWidgetItem(strName));
- ui->tableWidget->item(nIndex, 0)->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
- ui->tableWidget->setItem(nIndex, 1, new QTableWidgetItem(QString::number(nScreening.nMin)));
- ui->tableWidget->item(nIndex, 1)->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
- ui->tableWidget->setItem(nIndex, 2, new QTableWidgetItem(QString::number(nScreening.nMax)));
- ui->tableWidget->item(nIndex, 2)->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
- }
- void BlobSelectShape::on_comboBox_currentIndexChanged(int index)
- {
- emit updateParameter(ShowParameter());
- }
- void BlobSelectShape::on_tableWidget_cellChanged(int row, int column)
- {
- int rowIndex = ui->tableWidget->currentRow();
- if (rowIndex != -1)
- { // 更新数据
- QTableWidgetItem* item1 = ui->tableWidget->item(row, 1);
- if (item1 != nullptr)
- {
- int nMinValue = item1->text().toInt();
- m_AllScreening[row].nMin = nMinValue;
-
- emit updateParameter(ShowParameter());
- }
- QTableWidgetItem* item2 = ui->tableWidget->item(row, 2);
- if (item2 != nullptr)
- {
- int nMaxValue = item2->text().toInt();
- m_AllScreening[row].nMax = nMaxValue;
- emit updateParameter(ShowParameter());
- }
- }
- }
- void BlobSelectShape::on_BTN_Del_clicked()
- {
- int rowIndex = ui->tableWidget->currentRow();
- if (rowIndex != -1)
- {
- ui->tableWidget->removeRow(rowIndex);
- m_AllScreening.remove(rowIndex);
-
- }
- }
- void BlobSelectShape::on_comboBox_index_currentIndexChanged(int index)
- {
- if(index > 0)
- {
- emit updateParameterIndex(QString::number(index - 1));
- }
- emit updateParameter(ShowParameter());
- }
|