You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

275 lines
9.5 KiB

6 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. #include "main_window.h"
  2. mainWinow* mainWinow::_instance = 0;
  3. void mainWinow::changeEvent(QEvent *event){
  4. if(event->type() == QEvent::WindowStateChange ){
  5. if (!isMinimized()) {
  6. setAttribute(Qt::WA_Mapped);
  7. };
  8. };
  9. };
  10. mainWinow::mainWinow() : QMainWindow(){
  11. m_pSettings = basicSettingsProvider::getInstance()->getSubNode(NULL, (CSTR)"APPLICATION_GUI");
  12. m_pFactory = cortexLayersFactory::getInstance();
  13. m_pCortex = NULL;
  14. m_bChangesAreSaved = true;
  15. m_pMainWidget = new QWidget( NULL );
  16. m_pMainWidget->setObjectName("m_pMainWidget");
  17. setCentralWidget( m_pMainWidget );
  18. QVBoxLayout* layout = new QVBoxLayout;
  19. layout->setContentsMargins(5, 5, 5, 5);
  20. //m_pMainWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
  21. m_pLayerTable = new QTableWidget( this );
  22. m_pLayerTable->setColumnCount( 5 );
  23. m_pLayerTable->setSortingEnabled( false );
  24. m_pLayerTable->setSelectionMode( QAbstractItemView::SingleSelection );
  25. m_pLayerTable->setSelectionBehavior( QAbstractItemView::SelectRows );
  26. m_pLayerTable->setGridStyle( Qt::DashLine );
  27. m_pLayerTable->setCornerButtonEnabled( true );
  28. layout->addWidget(m_pLayerTable);
  29. QTableWidgetItem* __qtablewidgetitem;
  30. __qtablewidgetitem = new QTableWidgetItem();
  31. __qtablewidgetitem->setText("Type");
  32. m_pLayerTable->setHorizontalHeaderItem( 0, __qtablewidgetitem );
  33. __qtablewidgetitem = new QTableWidgetItem();
  34. __qtablewidgetitem->setText("Filter");
  35. m_pLayerTable->setHorizontalHeaderItem( 1, __qtablewidgetitem );
  36. __qtablewidgetitem = new QTableWidgetItem();
  37. __qtablewidgetitem->setText("FIlter Size");
  38. m_pLayerTable->setHorizontalHeaderItem( 2, __qtablewidgetitem );
  39. __qtablewidgetitem = new QTableWidgetItem();
  40. __qtablewidgetitem->setText("Input");
  41. m_pLayerTable->setHorizontalHeaderItem( 3, __qtablewidgetitem );
  42. __qtablewidgetitem = new QTableWidgetItem();
  43. __qtablewidgetitem->setText("Output");
  44. m_pLayerTable->setHorizontalHeaderItem( 4, __qtablewidgetitem );
  45. connect(m_pLayerTable, &QTableWidget::cellClicked, this, &mainWinow::selectLayerRow );
  46. QHBoxLayout* hlayout = new QHBoxLayout;
  47. hlayout->setContentsMargins(5, 5, 5, 5);
  48. m_pTabWidget = new QTabWidget( this );
  49. m_pTabWidget->setObjectName( "m_pTabWidget" );
  50. m_pTabLayerVisual = new QWidget();
  51. m_pTabLayerVisual->setObjectName("m_pTabLayerVisual");
  52. QHBoxLayout* hlayout1 = new QHBoxLayout;
  53. hlayout1->setContentsMargins(5, 5, 5, 5);
  54. m_pLayerPreview = new CortexLayerWidget( m_pTabLayerVisual );
  55. if( m_pLayerPreview->init() ){
  56. };
  57. hlayout1->addWidget(m_pLayerPreview);
  58. m_pTabLayerVisual->setLayout(hlayout1);
  59. m_pTabWidget->addTab(m_pTabLayerVisual, "Layer Visual");
  60. m_pTabCategories = new QWidget();
  61. m_pTabCategories->setObjectName("m_pTabCategories");
  62. m_pTabWidget->addTab(m_pTabCategories, "Classes");
  63. m_pTabLearning = new QWidget();
  64. m_pTabLearning->setObjectName("m_pTabLearning");
  65. m_pTabWidget->addTab(m_pTabLearning, "Learning");
  66. m_pTabInput = new QWidget();
  67. m_pTabInput->setObjectName("m_pTabInput");
  68. QHBoxLayout* hlayout2 = new QHBoxLayout;
  69. hlayout2->setContentsMargins(5, 5, 5, 5);
  70. m_pInputStream = new MediaDestWidget( m_pTabInput );
  71. if( m_pInputStream->init() ){
  72. m_pAVLIBSource = new videoAVLIBSource();
  73. if (m_pAVLIBSource != NULL) {
  74. if( m_pAVLIBSource->_open("C:\\KeepVid Pro Downloaded\\The Renter.mp4") ){
  75. m_pAVLIBSource->attachDestination(m_pInputStream);
  76. };
  77. };
  78. };
  79. hlayout2->addWidget(m_pInputStream);
  80. m_pTabInput->setLayout(hlayout2);
  81. m_pTabWidget->addTab(m_pTabInput, "Input");
  82. m_pTabOutput = new QWidget();
  83. m_pTabOutput->setObjectName("m_pTabOutput");
  84. m_pOutputStream = new MediaDestWidget( m_pTabOutput );
  85. m_pOutputStream->init();
  86. m_pTabWidget->addTab(m_pTabOutput, "Output");
  87. m_pTabProcessingUnits = new QWidget();
  88. m_pTabProcessingUnits->setObjectName("m_pTabProcessingUnits");
  89. m_pTabWidget->addTab(m_pTabProcessingUnits, "Processing Unit");
  90. hlayout->addWidget(m_pTabWidget);
  91. layout->addItem( hlayout );
  92. m_pMainWidget->setLayout(layout);
  93. setObjectName("Mainwindow");
  94. /* Menu Things */
  95. actionNew_Network = new QAction( QIcon(":/general/file.png"), "&New", this );
  96. actionNew_Network->setShortcuts(QKeySequence::New);
  97. actionNew_Network->setStatusTip(tr("Create a new Network"));
  98. connect( actionNew_Network, &QAction::triggered, this, &mainWinow::newNetwork );
  99. actionOpen = new QAction( QIcon(":/layout/PNG/layout/049.png"), "&Open", this );
  100. actionOpen->setShortcuts(QKeySequence::Open);
  101. actionOpen->setStatusTip(tr("Open Network Config"));
  102. connect( actionOpen, &QAction::triggered, this, &mainWinow::open );
  103. actionSave = new QAction( QIcon(":/layout/PNG/layout/048.png"), "&Save", this );
  104. actionSave->setShortcuts(QKeySequence::Save);
  105. actionSave->setStatusTip(tr("Save Network Config"));
  106. connect(actionSave, &QAction::triggered, this, &mainWinow::save);
  107. actionSave_As = new QAction( QIcon(":/layout/PNG/layout/048.png"), "Save &As", this );
  108. actionSave_As->setShortcuts(QKeySequence::SaveAs);
  109. actionSave_As->setStatusTip(tr("Save Network Config in Another File"));
  110. connect(actionSave_As, &QAction::triggered, this, &mainWinow::saveAs);
  111. actionExit = new QAction( QIcon(":/layout/PNG/layout/076.png"), "&Exit", this);
  112. actionExit->setShortcuts(QKeySequence::Close);
  113. actionExit->setStatusTip(tr("Exit Application"));
  114. connect(actionExit, &QAction::triggered, this, &mainWinow::exitApp);
  115. menuFile = menuBar()->addMenu(QIcon(":/menu/PNG/devices/008.png"),"&File");
  116. menuFile->setObjectName("menuFile");
  117. menuFile->addAction(actionNew_Network);
  118. menuFile->addAction(actionOpen);
  119. menuFile->addAction(actionSave);
  120. menuFile->addAction(actionSave_As);
  121. menuFile->addAction(actionExit);
  122. toolBar = addToolBar("Yoba!");
  123. toolBar->setObjectName("toolBar");
  124. toolBar->setOrientation(Qt::Horizontal);
  125. toolBar->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
  126. toolBar->setFloatable(true);
  127. tbActionAdd = toolBar->addAction(QIcon(":/layout/PNG/layout/064.png"), "Add Layer");
  128. tbActionInsert = toolBar->addAction(QIcon(":/layout/PNG/layout/067.png"), "Insert Layer");
  129. tbActionEdit = toolBar->addAction(QIcon(":/layout/PNG/layout/073.png"), "Edit Layer");
  130. tbActionEdit->setEnabled(false);
  131. tbActionDelete = toolBar->addAction(QIcon(":/layout/PNG/layout/066.png"), "Delete Layer");
  132. tbActionDelete->setEnabled(false);
  133. toolBar->addSeparator();
  134. tbActionLoadWeights = toolBar->addAction(QIcon(":/layout/PNG/layout/024.png"), "Load Weights");
  135. tbActionLoadWeights->setEnabled(false);
  136. insertToolBarBreak(toolBar);
  137. statusBar()->showMessage("Init Done.");
  138. setWindowTitle(tr("Neural Network Manager"));
  139. setMinimumSize(160, 160);
  140. };
  141. mainWinow::~mainWinow(){
  142. if (m_pAVLIBSource != NULL) {
  143. m_pAVLIBSource->_stop();
  144. delete(m_pAVLIBSource);
  145. };
  146. };
  147. /**
  148. * Returns the single instance of the object.
  149. */
  150. mainWinow* mainWinow::getInstance() {
  151. // check if the instance has been created yet
  152. if (0 == _instance){
  153. // if not, then create it
  154. _instance = new mainWinow();
  155. };
  156. // return the single instance
  157. return _instance;
  158. };
  159. void mainWinow::newNetwork(){
  160. if (m_pFactory != NULL) {
  161. m_pFactory->cleanFactory();
  162. };
  163. };
  164. void mainWinow::open(){
  165. QString fileName;
  166. fileName = QFileDialog::getOpenFileName(this, "Open Data", "data/", "Data Files (*.cfg *.raw *.jpg *.bmp)");
  167. char fName[MAX_PATH];
  168. sprintf( fName, "%s", fileName.toStdString().c_str() );
  169. if( strlen(fName) ){
  170. char tBuff[1024];
  171. sprintf(tBuff, "Neural Network Manager: %s", fName );
  172. setWindowTitle(tBuff);
  173. if (m_pCortex != NULL) {
  174. for (uint32_t index = m_pLayerTable->rowCount(); index > -1; index-- ) m_pLayerTable->removeRow(index);
  175. delete(m_pCortex);
  176. m_pCortex = NULL;
  177. };
  178. m_pCortex = m_pFactory->parseConfig(fName);
  179. if( m_pCortex!= NULL ) {
  180. for( uint32_t index = 0; index < m_pCortex->getLayersCount(); index++ ){
  181. char tBuff[256];
  182. m_pLayerTable->insertRow(index);
  183. QTableWidgetItem * __qtablewidgetitem;
  184. __qtablewidgetitem = new QTableWidgetItem();
  185. __qtablewidgetitem->setText( m_pCortex->getLayer(index)->getString() );
  186. m_pLayerTable->setItem( index, 0, __qtablewidgetitem );
  187. __qtablewidgetitem = new QTableWidgetItem();
  188. sprintf(tBuff, "%dx%dx%d", m_pCortex->getLayer(index)->getInputSizeWidth(), m_pCortex->getLayer(index)->getInputSizeHeight(), m_pCortex->getLayer(index)->getInputSizeChannels() );
  189. __qtablewidgetitem->setText(tBuff );
  190. m_pLayerTable->setItem(index, 3, __qtablewidgetitem);
  191. __qtablewidgetitem = new QTableWidgetItem();
  192. sprintf(tBuff, "%dx%dx%d", m_pCortex->getLayer(index)->getOutputSizeWidth(), m_pCortex->getLayer(index)->getOutputSizeHeight(), m_pCortex->getLayer(index)->getOutputSizeChannels());
  193. __qtablewidgetitem->setText(tBuff);
  194. m_pLayerTable->setItem(index, 4, __qtablewidgetitem);
  195. };
  196. tbActionLoadWeights->setEnabled(true);
  197. };
  198. };
  199. };
  200. void mainWinow::save(){
  201. m_bChangesAreSaved = true;
  202. };
  203. void mainWinow::saveAs(){
  204. QString fileName;
  205. fileName = QFileDialog::getSaveFileName(this, "Save Data As ...", "data/", "Data Files (*.raw *.jpg *.bmp)");
  206. m_bChangesAreSaved = true;
  207. };
  208. void mainWinow::exitApp() {
  209. if (m_bChangesAreSaved) {
  210. QApplication::quit();
  211. } else {
  212. QMessageBox::StandardButton reply;
  213. reply = QMessageBox::question( this, "Unsaved Data", "Are you sure to Quit?", QMessageBox::Yes | QMessageBox::No);
  214. if( reply == QMessageBox::Yes ){
  215. QApplication::quit();
  216. };
  217. };
  218. };
  219. void mainWinow::contextMenuEvent(QContextMenuEvent* event){
  220. QMenu menu(this);
  221. //menu.addAction(cutAct);
  222. //menu.addAction(copyAct);
  223. //menu.addAction(pasteAct);
  224. menu.exec(event->globalPos());
  225. };
  226. void mainWinow::selectLayerRow( int row, int col ){
  227. tbActionEdit->setEnabled(true);
  228. tbActionDelete->setEnabled(true);
  229. m_pLayerPreview->attachCortexLayer(m_pCortex->getLayer(row));
  230. };