void ProgressDialog::showProgressDialog(QOpenGLWidget *parent) { progressDialog = new QProgressDialog(parent); progressDialog->setWindowTitle("Image rendering progress"); progressDialog->setMinimumSize(300, 40); progressDialog->setCancelButton(NULL); progressDialog->show(); }
void MainWindow::OnImportNANDBackup() { auto response = QMessageBox::question( this, tr("Question"), tr("Merging a new NAND over your currently selected NAND will overwrite any channels " "and savegames that already exist. This process is not reversible, so it is " "recommended that you keep backups of both NANDs. Are you sure you want to " "continue?")); if (response == QMessageBox::No) return; QString file = QFileDialog::getOpenFileName(this, tr("Select the save file"), QDir::currentPath(), tr("BootMii NAND backup file (*.bin);;" "All Files (*)")); if (file.isEmpty()) return; QProgressDialog* dialog = new QProgressDialog(this); dialog->setMinimum(0); dialog->setMaximum(0); dialog->setLabelText(tr("Importing NAND backup")); dialog->setCancelButton(nullptr); auto beginning = QDateTime::currentDateTime().toMSecsSinceEpoch(); auto result = std::async(std::launch::async, [&] { DiscIO::NANDImporter().ImportNANDBin( file.toStdString(), [&dialog, beginning] { QueueOnObject(dialog, [&dialog, beginning] { dialog->setLabelText( tr("Importing NAND backup\n Time elapsed: %1s") .arg((QDateTime::currentDateTime().toMSecsSinceEpoch() - beginning) / 1000)); }); }, [this] { return RunOnObject(this, [this] { return QFileDialog::getOpenFileName(this, tr("Select the keys file (OTP/SEEPROM dump)"), QDir::currentPath(), tr("BootMii keys file (*.bin);;" "All Files (*)")) .toStdString(); }); }); QueueOnObject(dialog, &QProgressDialog::close); }); dialog->exec(); result.wait(); m_menu_bar->UpdateToolsMenu(Core::IsRunning()); }
void SearchDialog::newSearch() { QString phrase = QInputDialog::getText(pgView, "Search in notebook", "Search phrase:", QLineEdit::Normal, lastPhrase); lastPhrase = phrase; if (phrase.isEmpty()) return; QProgressDialog *progress = new QProgressDialog(pgView); progress->setLabelText("Searching..."); progress->setCancelButton(0); progress->setMinimumDuration(500); progress->setValue(0); Search *search = new Search(pgView->notebook()); QList<SearchResult> res = search->immediatelyFindPhrase(phrase); if (res.isEmpty()) { delete progress; QMessageBox::information(pgView, "Search - eln", QString::fromUtf8("Search phrase “%1” not found") .arg(phrase)); return; } SearchResultScene *scene = new SearchResultScene(phrase, QString::fromUtf8("Search results for “%1”") .arg(phrase), res, pgView->notebook()->bookData()); scene->populate(); connect(scene, SIGNAL(pageNumberClicked(int, Qt::KeyboardModifiers, QString, QString)), this, SLOT(gotoPage(int, Qt::KeyboardModifiers, QString, QString))); SearchView *view = new SearchView(scene); view->setAttribute(Qt::WA_DeleteOnClose, true); connect(parent(), SIGNAL(destroyed()), view, SLOT(close())); delete progress; view->resize(pgView->size()*.9); QString ttl = pgView->notebook()->bookData()->title(); view->setWindowTitle("Search in: " + ttl.replace(QRegExp("\\s\\s*"), " ") + " - eln"); view->show(); }
void ShortestPathComputer::init(ccMesh *mesh, QWidget *parentWidget/* = NULL*/) { mMesh = mesh; ccGenericPointCloud *cloud = mesh->getAssociatedCloud(); const unsigned vertexNum = cloud->size(); const unsigned triangleNum = mesh->size(); const unsigned edgeNum = triangleNum * 3; //半边 Edge *edges = new Edge[edgeNum]; float *edgeWeights = new float[edgeNum]; const unsigned triangleEdgeVertexIndexs[3][2] = { 0, 1, 1, 2, 2, 0 }; unsigned edgeIndexBase, edgeIndex; mesh->placeIteratorAtBegining(); for (unsigned i = 0; i < triangleNum; i++) { CCLib::TriangleSummitsIndexes* indexs = mesh->getNextTriangleIndexes(); assert(indexs->i[0] < vertexNum && indexs->i[1] < vertexNum && indexs->i[2] < vertexNum); const CCVector3 *triangleVertices[3] = { cloud->getPoint(indexs->i[0]), cloud->getPoint(indexs->i[1]), cloud->getPoint(indexs->i[2]) }; edgeIndexBase = i * 3; for (unsigned j = 0; j < 3; j++) { edgeIndex = edgeIndexBase + j; edges[edgeIndex].first = indexs->i[triangleEdgeVertexIndexs[j][0]]; edges[edgeIndex].second = indexs->i[triangleEdgeVertexIndexs[j][1]]; edgeWeights[edgeIndex] = CCVector3::vdistance(triangleVertices[triangleEdgeVertexIndexs[j][0]]->u, triangleVertices[triangleEdgeVertexIndexs[j][1]]->u); } } //开启新线程初始化BGL图并显示进度条 BoostGraphInitThread thread; thread.setGraphData(&mGraph, edges, edgeNum, edgeWeights, vertexNum); thread.start(); QProgressDialog progress; if (parentWidget) { progress.setParent(parentWidget); } progress.setWindowModality(Qt::WindowModal); progress.setWindowFlags(Qt::SubWindow | Qt::Popup); progress.setMinimumWidth(200); progress.setCancelButton(0); progress.setWindowTitle(QString::fromAscii("BGL图初始化")); progress.setLabelText(QString::fromAscii("BGL图初始化中,请稍后...")); progress.setRange(0, 0); progress.show(); while (thread.isRunning()) { QApplication::processEvents(); } progress.close(); //mGraph = MyGraph(edges, edges + edgeNum, edgeWeights, vertexNum); }
void Polar::setPolarName(QString fname) { isCsv=true; loaded=false; clearPolar(); if(this->mainWindow->getSelectedBoat() && this->mainWindow->getSelectedBoat()->get_boatType()==BOAT_REAL) coeffPolar=Settings::getSetting("polarEfficiency",100).toInt()/100.0; else coeffPolar=1.0; //qWarning() << "Opening polar" << fname<<"with coeff"<<coeffPolar; name=fname; QString nameF = appFolder.value("polar")+fname+".csv"; QFile file(nameF); if (fname.endsWith(".csv",Qt::CaseInsensitive) || fname.endsWith(".pol",Qt::CaseInsensitive)) { nameF=appFolder.value("polar")+fname; file.setFileName(nameF); if (!file.open(QIODevice::ReadOnly | QIODevice::Text )) { QMessageBox::warning(0,QObject::tr("Lecture de polaire"), QString(QObject::tr("Impossible d'ouvrir le fichier %1")).arg(name)); return; } isCsv=fname.endsWith("csv",Qt::CaseInsensitive); } else { if (!file.open(QIODevice::ReadOnly | QIODevice::Text )) { isCsv=false; nameF = appFolder.value("polar")+fname+".pol"; file.setFileName(nameF); if (!file.open(QIODevice::ReadOnly | QIODevice::Text )) { QMessageBox::warning(0,QObject::tr("Lecture de polaire"), QString(QObject::tr("Impossible d'ouvrir le fichier %1 (ni en .csv ni en .pol)")).arg(name)); return; } } } QTextStream stream(&file); QString line; QStringList list; /* read first line to see line length */ line=stream.readLine(); line.remove("\""); if(line.isNull()) { QMessageBox::warning(0,QObject::tr("Lecture de polaire"), QString(QObject::tr("Fichier %1 vide")).arg(fname)); file.close(); return; } if(isCsv) list = line.split(';'); else list = line.split('\t'); if(list[0].toUpper() != "TWA\\TWS" && list[0].toUpper() != "TWA/TWS" && list[0].toUpper() != "TWA") { QMessageBox::warning(0,QObject::tr("Lecture de polaire"), QString(QObject::tr("Fichier %1 invalide (doit commencer par TWA\\TWS et non '%2')")) .arg(fname) .arg(list[0])); file.close(); return; } int i; for(i=1;i<list.count();++i) { if(!tws.isEmpty() && list[i].toDouble()<=tws.last()) break; tws.append(list[i].toDouble()); } bool missingTws0=false; if(tws.first()!=0.0) { missingTws0=true; } bool firstTWA=true; while(true) { line=stream.readLine(); if(line.isNull()) break; line.remove("\""); if (isCsv) list = line.split(";"); else list = line.split("\t"); if(firstTWA) { firstTWA=false; if(list.first().toDouble()!=0.0) { for(int t=0;t<tws.count();++t) { polar_data.append(0); } if(missingTws0) polar_data.append(0); twa.append(0.0); } } twa.append(list[0].toDouble()); if(missingTws0) polar_data.append(0); for(i=1;i<list.count();++i) { if(i>tws.count()) break; polar_data.append(list[i].toDouble()*this->coeffPolar); } while(i<=tws.count()) polar_data.append(0); } if(missingTws0) tws.prepend(0.0); #if 0 qWarning()<<"polar data for"<<nameF; QString debug="xxx.x "; foreach(double dd,tws) debug+=QString().sprintf("%04.1f ",dd); qWarning()<<debug; QListIterator<double> i1(polar_data); QListIterator<double> i2(twa); while(i2.hasNext()) { debug=QString().sprintf("%05.1f ",i2.next()); for(int nn=0;nn<tws.count();++nn) debug+=QString().sprintf("%04.1f ",i1.next()); qWarning()<<debug; } #endif mid_twa=qRound(twa.count()/2.0); mid_tws=qRound(tws.count()/2.0); /* polaire chargee */ /* pre-calculate B-VMG for every tws at 0.1 precision with a twa step of 1 and then .1 */ double ws=0.0; double wa=0.0; double bvmg,bvmg_d,bvmg_u,wa_u,wa_d,wa_limit; maxSpeed=0.0; do { wa_u=0.0; wa_d=180.0; bvmg_u=bvmg_d=0; double speed; do { speed=myGetSpeed(ws,wa,true); if(speed>maxSpeed) maxSpeed=speed; bvmg=speed*cos(degToRad(wa)); if(bvmg_u<bvmg) //bvmg is positive here { bvmg_u=bvmg; wa_u=wa; } if(bvmg_d>bvmg) //bvmg is negative here { bvmg_d=bvmg; wa_d=wa; } wa=qRound(wa+1); } while(wa<181.00); wa=wa_u-1; wa_limit=wa_u+1; if(wa<0) wa=0.0; if(wa_limit<1) wa_limit=1.0; if(wa_limit>180) wa_limit=180.0; bvmg_u=0.0; do { speed=myGetSpeed(ws,wa,true); if(speed>maxSpeed) maxSpeed=speed; bvmg=speed*cos(degToRad(wa)); if(bvmg_u<bvmg) { bvmg_u=bvmg; wa_u=wa; } wa=wa+0.1; } while(wa<(wa_limit+0.1000)); wa=wa_d-1; wa_limit=wa_d+1; if(wa<0) wa=0.0; if(wa_limit<1) wa_limit=1.0; if(wa_limit>180) wa_limit=180.0; bvmg_d=0.0; do { speed=myGetSpeed(ws,wa,true); if(speed>maxSpeed) maxSpeed=speed; bvmg=speed*cos(degToRad(wa)); if(bvmg_d>bvmg) { bvmg_d=bvmg; wa_d=wa; } wa=wa+0.1; }while(wa<wa_limit+0.1); best_vmg_up.append(wa_u); best_vmg_down.append(wa_d); wa=0.0; ws=ws+.1; }while(ws<60.1); loaded=true; QFileInfo fi(file.fileName()); QString nameFVmg = appFolder.value("polar")+fi.baseName()+".vmg"; fileVMG.setFileName(nameFVmg); if (fileVMG.open(QIODevice::ReadOnly | QIODevice::Text )) { if(fileVMG.size()<4329500 || fileVMG.size()>4329700) fileVMG.remove(); else { QFileInfo info1(fileVMG); QFileInfo info2(file); if(this->mainWindow->isStartingUp && info1.lastModified()<info2.lastModified()) fileVMG.remove(); else { file.close(); return; } } } file.close(); //precalculate regular VMGs //qWarning() << "Start computing vmg"; fileVMG.open(QIODevice::WriteOnly | QIODevice::Text ); double vmg=0; QTextStream sVmg(&fileVMG); QString ssVmg; QProgressDialog * progress; progress=new QProgressDialog((QWidget*)mainWindow); progress->setWindowModality(Qt::ApplicationModal); progress->setLabelText(tr("Pre-calcul des valeurs de VMG pour ")+fname); progress->setMaximum(600); progress->setMinimum(0); progress->setCancelButton(NULL); progress->setMaximumHeight(100); progress->show(); for (int tws=0;tws<601;tws++) { progress->setValue(tws); for (int twa=0;twa<1801;twa++) { bvmgWind((double) twa/10.0,(double) tws/10.0,&vmg); ssVmg.sprintf("%.4d",qRound(A360(vmg)*10.0)); sVmg<<ssVmg; } } fileVMG.close(); if(!fileVMG.open(QIODevice::ReadOnly | QIODevice::Text )) qWarning()<<"fileVMG could not be re-opened!"; progress->close(); delete progress; }
KOnlineBankingSetupWizard::KOnlineBankingSetupWizard(QWidget *parent): QWizard(parent), d(new Private), m_fDone(false), m_fInit(false), m_appId(0) { setupUi(this); m_applicationEdit->hide(); m_headerVersionEdit->hide(); #ifndef LIBOFX_HAVE_CLIENTUID m_editClientUid->setEnabled(false); m_clientUidLabel->setEnabled(false); #endif m_appId = new OfxAppVersion(m_applicationCombo, m_applicationEdit, ""); m_headerVersion = new OfxHeaderVersion(m_headerVersionCombo, ""); // fill the list view with banks QProgressDialog* dlg = new QProgressDialog(this); dlg->setWindowTitle(i18n("Loading banklist")); dlg->setLabelText(i18n("Getting list of banks from http://moneycentral.msn.com/\nThis may take some time depending on the available bandwidth.")); dlg->setModal(true); dlg->setCancelButton(0); // force to show immediately as the call to OfxPartner::BankNames() // does not call the processEvents() loop dlg->setMinimumDuration(0); QCoreApplication::processEvents(); //set password field according to KDE preferences m_editPassword->setPasswordMode(true); KListWidgetSearchLine* searchLine = new KListWidgetSearchLine(autoTab, m_listFi); vboxLayout1->insertWidget(0, searchLine); QTimer::singleShot(20, searchLine, SLOT(setFocus())); OfxPartner::setDirectory(QStandardPaths::writableLocation(QStandardPaths::DataLocation) + QLatin1Char('/') + ""); m_listFi->addItems(OfxPartner::BankNames()); m_fInit = true; delete dlg; checkNextButton(); connect(this, SIGNAL(currentIdChanged(int)), this, SLOT(checkNextButton())); connect(this, SIGNAL(currentIdChanged(int)), this, SLOT(newPage(int))); connect(m_listFi, SIGNAL(itemSelectionChanged()), this, SLOT(checkNextButton())); connect(m_listAccount, SIGNAL(itemSelectionChanged()), this, SLOT(checkNextButton())); connect(m_selectionTab, SIGNAL(currentChanged(int)), this, SLOT(checkNextButton())); connect(m_fid, SIGNAL(userTextChanged(QString)), this, SLOT(checkNextButton())); connect(m_bankName, SIGNAL(userTextChanged(QString)), this, SLOT(checkNextButton())); connect(m_url, SIGNAL(textChanged(QString)), this, SLOT(checkNextButton())); connect(m_editUsername, SIGNAL(userTextChanged(QString)), this, SLOT(checkNextButton())); connect(m_editPassword, SIGNAL(userTextChanged(QString)), this, SLOT(checkNextButton())); connect(m_applicationEdit, SIGNAL(userTextChanged(QString)), this, SLOT(checkNextButton())); connect(m_applicationCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(applicationSelectionChanged())); // setup text on buttons setButtonText(QWizard::NextButton, i18nc("Go to next page of the wizard", "&Next")); setButtonText(QWizard::BackButton, KStandardGuiItem::back().text()); // setup icons button(QWizard::FinishButton)->setIcon(KStandardGuiItem::ok().icon()); button(QWizard::CancelButton)->setIcon(KStandardGuiItem::cancel().icon()); button(QWizard::NextButton)->setIcon(KStandardGuiItem::forward(KStandardGuiItem::UseRTL).icon()); button(QWizard::BackButton)->setIcon(KStandardGuiItem::back(KStandardGuiItem::UseRTL).icon()); }
void Hypergraph::updateLayout(const vector<int> &changedSet, int boundary [], int dim, float c) { _layoutDim = dim; int nIteration = 500; float temperature = 10; srand(time(NULL)); int area = 1; for (int i=0; i<dim; ++i) { area *= boundary[2*i+1]-boundary[2*i]; } float k = c*sqrt(area*1.0f/_nVertices); int nEdges = _edges.size(); int nTotal = _nVertices+nEdges; vector<fvec> dispBuf (nTotal); for (int i=0; i<nTotal; ++i) { dispBuf[i] = fvec(dim); } int i,j; vector<bool> bMovable (nTotal); for (i=0; i<changedSet.size(); ++i) { bMovable[changedSet[i]] = true; } QProgressDialog prog ("Performing graph layout ...", "", 0, nIteration-1); prog.setCancelButton(NULL); for (int it=0; it<nIteration; ++it) { DWORD t1 = GetTickCount(); bool bChanged = false; for (i=0; i<nTotal; ++i) { dispBuf[i].fill(0); } DWORD t2 = GetTickCount(); /*calculate repulsive force*/ for (i=0; i<changedSet.size(); ++i) { int idx = changedSet[i]; for (j=0; j<nTotal; ++j) { if (j==idx) { continue; } fvec d = _layout[j]-_layout[idx]; fvec disp; float normD = norm(d,2); if (normD<1.0e-5) { disp = fvec(dim); for (int iDim=0; iDim<dim; ++iDim) { disp(iDim) = rand()%100/100.0f; } disp *= temperature; } else { disp = d*k*k/pow(normD,2); } dispBuf[idx] -= disp; } } DWORD tRepForce = GetTickCount()-t2; /*calculate attractive force*/ for (i=0; i<_edges.size(); ++i) { int edgeIdx = i+_nVertices; for (j=0; j<_edges[i].size(); ++j) { if (!bMovable[_edges[i][j]]) { continue; } float c2 = 3.0; fvec d1 = _layout[edgeIdx] - _layout[_edges[i][j]]; fvec disp1 = c2*d1*norm(d1,2)/k; dispBuf[edgeIdx] -= disp1; dispBuf[_edges[i][j]] += disp1; for (int m=0; m<_edges[i].size(); ++m) { if (m==j) { continue; } fvec d = _layout[_edges[i][m]] - _layout[_edges[i][j]]; fvec disp = d*norm(d,2)/k; dispBuf[_edges[i][j]] += disp; } } } DWORD tRepAttrForces = GetTickCount()-t2; /*restrict the points from being pushed towards the boundary*/ for (i=0; i<nTotal; ++i) { if (!bMovable[i]) { continue; } for (j=0; j<dim; ++j) { float c1=1.0e6; float x = _layout[i](j); if (x==boundary[j*2] || x==boundary[j*2+1]) { int stop = 1; } float d = c1*(1/(x-boundary[j*2]+1.0e-3)-1/(boundary[j*2+1]-x+1.0e-3)); dispBuf[i](j) += d; } } /*limit the maximum displacement, boundary check*/ for (i=0; i<nTotal; ++i) { if (!bMovable[i]) { continue; } float n = norm(dispBuf[i],2); fvec newLayout = _layout[i]+dispBuf[i]*min(n, temperature)/n; for (j=0; j<dim; ++j) { int minBoundary = boundary[2*j]; int maxBoundary = boundary[2*j+1]; newLayout(j) = newLayout(j) < minBoundary?minBoundary:(newLayout(j)>maxBoundary?maxBoundary:newLayout(j)); } if (norm(newLayout-_layout[i], 2)>1.0e-3) { _layout[i] = newLayout; bChanged = true; } } if (!bChanged) { break; } DWORD perItTime = GetTickCount() - t1; t1 = GetTickCount(); prog.setValue(it); } }
void Hypergraph::layoutGraph( int boundary [], int dim/*=2*/, float c/*=1.0*/ ) { _layoutDim = dim; int nIteration = 500; float temperature = 10; srand(time(NULL)); int area = 1; for (int i=0; i<dim; ++i) { area *= boundary[2*i+1]-boundary[2*i]; } float k = c*sqrt(area*1.0f/_nVertices); /*initialize vertex layout*/ int nEdges = _edges.size(); int nTotal = _nVertices+nEdges; _layout.resize(nTotal); vector<fvec> dispBuf (nTotal); for (int i=0; i<nTotal; ++i) { _layout[i] = fvec(dim); for (int j=0; j<dim; ++j) { _layout[i](j) = boundary[2*j]+rand()%(boundary[2*j+1]-boundary[2*j]); } dispBuf[i] = fvec(dim); } int i,j; QProgressDialog prog ("Performing graph layout ...", "", 0, nIteration-1); prog.setCancelButton(NULL); for (int it=0; it<nIteration; ++it) { DWORD t1 = GetTickCount(); bool bChanged = false; for (i=0; i<nTotal; ++i) { dispBuf[i].fill(0); } DWORD t2 = GetTickCount(); /*calculate repulsive force*/ for (i=0; i<nTotal; ++i) { for (j=0; j<i; ++j) { if (j==i) { continue; } fvec disp = getRepulsiveForce(_layout[i], _layout[j], k); dispBuf[j] += disp; dispBuf[i] -= disp; } } DWORD tRepForce = GetTickCount()-t2; /*calculate attractive force*/ for (i=0; i<_edges.size(); ++i) { int edgeIdx = i+_nVertices; for (j=0; j<_edges[i].size(); ++j) { float c2 = 300.0; fvec disp1 = c2*getAttractiveForce(_layout[_edges[i][j]], _layout[edgeIdx], k); dispBuf[edgeIdx] -= disp1; dispBuf[_edges[i][j]] += disp1; } } DWORD tRepAttrForces = GetTickCount()-t2; /*restrict the points from being pushed towards the boundary*/ for (i=0; i<nTotal; ++i) { for (j=0; j<dim; ++j) { float c1=1.0e6; float x = _layout[i](j); if (x==boundary[j*2] || x==boundary[j*2+1]) { int stop = 1; } float d = c1*(1/(x-boundary[j*2]+1.0e-3)-1/(boundary[j*2+1]-x+1.0e-3)); dispBuf[i](j) += d; } } /*limit the maximum displacement, boundary check*/ for (i=0; i<nTotal; ++i) { float n = norm(dispBuf[i],2); fvec newLayout = _layout[i]+dispBuf[i]*min(n, temperature)/n; for (j=0; j<dim; ++j) { int minBoundary = boundary[2*j]; int maxBoundary = boundary[2*j+1]; newLayout(j) = newLayout(j) < minBoundary?minBoundary:(newLayout(j)>maxBoundary?maxBoundary:newLayout(j)); } if (norm(newLayout-_layout[i], 2)>1.0e-3) { _layout[i] = newLayout; bChanged = true; } } if (!bChanged) { break; } DWORD perItTime = GetTickCount() - t1; t1 = GetTickCount(); prog.setValue(it); } }
void Hypergraph::layoutFast(int boundary [], int dim, float c, int Vmax, int Smax, int nIteration) { _layoutDim = dim; float temperature = 10; srand(time(NULL)); int area = 1; for (int i=0; i<dim; ++i) { area *= boundary[2*i+1]-boundary[2*i]; } float k = c*sqrt(area*1.0f/_nVertices); /*initialize vertex layout*/ int nEdges = _edges.size(); int nTotal = _nVertices+nEdges; _layout.resize(nTotal); vector<fvec> dispBuf (nTotal); for (int i=0; i<nTotal; ++i) { _layout[i] = fvec(dim); for (int j=0; j<dim; ++j) { _layout[i](j) = boundary[2*j]+rand()%(boundary[2*j+1]-boundary[2*j]); } dispBuf[i] = fvec(dim); } int i,j; vector<list<int> > sampleBufs (nTotal); vector<int> Vsizes (nTotal); vector<float> maxDists (nTotal); maxDists.assign(nTotal, 40); /*initialize distance matrix*/ vector<float> distMat (nTotal*(nTotal-1)/2); distMat.assign(nTotal*(nTotal-1)/2, 50); for (int i=0; i<nEdges; ++i) { int edgeIdx = i+_nVertices; for (int j=0; j<_edges[i].size(); ++j) { int n1 = _edges[i][j]; for (int k=0; k<j; ++k) { int n2 = _edges[i][k]; distMat[n1*(n1-1)/2+n2] = 20; } distMat[edgeIdx*(edgeIdx-1)/2+n1] = 10; } } QProgressDialog prog ("Performing graph layout ...", "", 0, nIteration-1); prog.setCancelButton(NULL); for (int it=0; it<nIteration; ++it) { DWORD t1 = GetTickCount(); bool bChanged = false; for (i=0; i<nTotal; ++i) { dispBuf[i].fill(0); } DWORD t2 = GetTickCount(); DWORD tFindSample = 0; for (i=0; i<nTotal; ++i) { DWORD t3 = GetTickCount(); findSampleSets(i, maxDists[i], distMat, sampleBufs[i], Vsizes[i], Vmax, Smax); list<int> &sampleBuf = sampleBufs[i]; tFindSample += GetTickCount()-t3; //for (j=0; j<sampleBuf.size(); ++j) for (list<int>::iterator sampleIt = sampleBuf.begin(); sampleIt!=sampleBuf.end(); ++sampleIt) { int sampleIdx = *sampleIt; ++sampleIt; float dist = *sampleIt; if (sampleIdx==i) { continue; } fvec d = _layout[sampleIdx]-_layout[i]; float normD = norm(d,2); /*calculate repulsive force*/ fvec dispRepulsive; if (normD<1.0e-5) { dispRepulsive = fvec(dim); for (int iDim=0; iDim<dim; ++iDim) { dispRepulsive(iDim) = rand()%100/100.0f; } dispRepulsive *= temperature; } else { dispRepulsive = d*k*k/pow(normD,2); } dispBuf[i] -= dispRepulsive; dispBuf[sampleIdx] += dispRepulsive; /*calculate attractive force*/ //float dist = i>sampleIdx?distMat[i*(i-1)/2+sampleIdx]:distMat[sampleIdx*(sampleIdx-1)/2+i]; /*if (dist<50) { float c3 = dist<15?3.0:1.0; fvec dispAttractive = c3*d*normD/k; dispBuf[i] += dispAttractive; dispBuf[sampleIdx] -= dispAttractive; }*/ } } DWORD tRepAttrForces = GetTickCount()-t2; /*restrict the points from being pushed towards the boundary*/ t2 = GetTickCount(); for (i=0; i<nTotal; ++i) { for (j=0; j<dim; ++j) { float c1=1.0e6; float x = _layout[i](j); if (x==boundary[j*2] || x==boundary[j*2+1]) { int stop = 1; } float d = c1*(1/(x-boundary[j*2]+1.0e-3)-1/(boundary[j*2+1]-x+1.0e-3)); dispBuf[i](j) += d; } } DWORD tBoundaries = GetTickCount()-t2; /*limit the maximum displacement, boundary check*/ t2 = GetTickCount(); for (i=0; i<nTotal; ++i) { float n = norm(dispBuf[i],2); fvec newLayout = _layout[i]+dispBuf[i]*min(n, temperature)/n; for (j=0; j<dim; ++j) { int minBoundary = boundary[2*j]; int maxBoundary = boundary[2*j+1]; newLayout(j) = newLayout(j) < minBoundary?minBoundary:(newLayout(j)>maxBoundary?maxBoundary:newLayout(j)); } } DWORD tLimits = GetTickCount()-t2; DWORD perItTime = GetTickCount() - t1; t1 = GetTickCount(); prog.setValue(it); } }
void Hypergraph::layoutPartitioned(int boundary [], bool bUpdate) { int dim = 2; int nIteration = bUpdate?50:500; float temperature = 10; typedef fvec2 LayoutPoint; srand(time(NULL)); int area = 1; for (int i=0; i<dim; ++i) { area *= boundary[2*i+1]-boundary[2*i]; } float k = 1.0*sqrt(area*1.0f/_nVertices); /*initialize vertex layout*/ int nEdges = _edges.size(); int nTotal = _nVertices+nEdges; _layout.resize(nTotal); vector<LayoutPoint> dispBuf (nTotal); if (!bUpdate) { for (int i=0; i<nTotal; ++i) { _layout[i] = fvec(dim); for (int j=0; j<dim; ++j) { _layout[i](j) = boundary[2*j]+rand()%(boundary[2*j+1]-boundary[2*j]); } dispBuf[i] = fvec(dim); } _pinWeights.resize(nTotal); _pinWeights.assign(nTotal, 1); } int nClusters = *max_element(_clusters.begin(), _clusters.end())+1; int nPartitions; vector<int> partitionSizes; getPartitionsByEdge(nPartitions, partitionSizes, _partitions); //getPartitionsByCluster(nPartitions, partitionSizes, _partitions); //getPartitionsByKDTree(nPartitions, partitionSizes, _partitions); vector<LayoutPoint> partCenters (nPartitions); vector<vector<int> > edgeBuf (_nVertices); for (int i=0; i<_edges.size(); ++i) { for (int j=0; j<_edges[i].size(); ++j) { edgeBuf[_edges[i][j]].push_back(i+_nVertices); } } int i,j; DWORD t0 = GetTickCount(); DWORD perItTime = 0; DWORD tReplInt = 0; DWORD tReplExt = 0; DWORD tAttr = 0; QProgressDialog prog ("Performing graph layout ...", "", 0, nIteration-1); prog.setCancelButton(NULL); for (int it=0; it<nIteration; ++it) { DWORD t1 = GetTickCount(); bool bChanged = false; for (int i=0; i<nTotal; ++i) { dispBuf[i].fill(0); } for (int i=0; i<nPartitions; ++i) { partCenters[i].fill(0); for (int j=0; j<nTotal; ++j) { if (i!=_partitions[j]) { continue; } partCenters[i] += _layout[j]; } partCenters[i] /= partitionSizes[i]; } for (int i=0; i<nTotal; ++i) { if (_pinWeights[i]<1.0e-3) { continue; } float edgeLength = (i<_nVertices&&_clusters[i]==-1)?1.5*k:k; /*interior repulsive forces*/ DWORD t2 = GetTickCount(); for (int j=0; j<i; ++j) { if (_partitions[i]!=_partitions[j]) { continue; } int vertexIdx = j; fvec disp = getRepulsiveForce(_layout[i], _layout[j], k); dispBuf[i] -= disp; dispBuf[j] += disp; } tReplInt += GetTickCount() - t2; /*exterior repulsive forces*/ t2 = GetTickCount(); for (int j=0; j<nPartitions; ++j) { if (j==_partitions[i]) { continue; } if (partitionSizes[j]!=0) { fvec disp = partitionSizes[j]*getRepulsiveForce(_layout[i], partCenters[j], k); dispBuf[i] -= disp; } } tReplExt += GetTickCount() - t2; /*attractive forces*/ t2 = GetTickCount(); if (i<_nVertices) { for (int j=0; j<edgeBuf[i].size(); ++j) { int edgeIdx = edgeBuf[i][j]; fvec disp = getAttractiveForce(_layout[i], _layout[edgeIdx], edgeLength); dispBuf[i] += 3.0*disp; dispBuf[edgeIdx] -= 3.0*disp; } } tAttr += GetTickCount() - t2; } /*cooling*/ for (int i=0; i<nTotal; ++i) { /*adjust forces*/ for (int j=0; j<dim; ++j) { float c1=1.0e5; float x = _layout[i](j); float d = c1*(1.0/(x-boundary[j*2]+1.0e-3)-1.0/(boundary[j*2+1]-x+1.0e-3)); dispBuf[i](j) += d; } float n = norm(dispBuf[i],2); fvec newLayout = _layout[i]+dispBuf[i]*min(n, temperature*_pinWeights[i])/n; for (int j=0; j<dim; ++j) { int minBoundary = boundary[2*j]; int maxBoundary = boundary[2*j+1]; newLayout(j) = newLayout(j) < minBoundary?minBoundary:(newLayout(j)>maxBoundary?maxBoundary:newLayout(j)); } _layout[i] = newLayout; } perItTime += GetTickCount() - t1; prog.setValue(it); } DWORD totalTime = GetTickCount()-t0; tReplInt /= nIteration; tReplExt /= nIteration; tAttr /= nIteration; perItTime /= nIteration; return; }
void Hypergraph::layoutClustered(int boundary [], int nIteration, int dim/* =2 */, float c/* =1.0 */) { _layoutDim = dim; float temperature = 10; int nEdges = _edges.size(); int nTotal = _nVertices+nEdges; srand(time(NULL)); int area = 1; for (int i=0; i<dim; ++i) { area *= boundary[2*i+1]-boundary[2*i]; } float k = c*sqrt(area*1.0f/nTotal); /*initialize vertex layout*/ _layout.resize(nTotal); vector<fvec> dispBuf (nTotal); for (int i=0; i<nTotal; ++i) { _layout[i] = fvec(dim); for (int j=0; j<dim; ++j) { _layout[i](j) = boundary[2*j]+rand()%(boundary[2*j+1]-boundary[2*j]); } dispBuf[i] = fvec(dim); } int i,j; QProgressDialog prog ("Performing graph layout ...", "", 0, nIteration-1); prog.setCancelButton(NULL); for (int it=0; it<nIteration; ++it) { DWORD t1 = GetTickCount(); bool bChanged = false; for (i=0; i<nTotal; ++i) { dispBuf[i].fill(0); } DWORD t2 = GetTickCount(); /*calculate repulsive force*/ for (i=0; i<nTotal; ++i) { int clusterI = i<_nVertices?_clusters[i]:i-_nVertices; for (j=0; j<i; ++j) { int clusterJ = j<_nVertices?_clusters[j]:j-_nVertices; float edgeLengthSqr = 1; if (i<_nVertices) { edgeLengthSqr = clusterI==clusterJ?1.5:4; } else { if (j<_nVertices) { edgeLengthSqr = clusterI==clusterJ?1:4; } else { edgeLengthSqr = 9; } } edgeLengthSqr*=k*k; fvec d = _layout[j]-_layout[i]; fvec disp; float normD = norm(d,2); if (normD<1.0e-5) { disp = fvec(dim); for (int iDim=0; iDim<dim; ++iDim) { disp(iDim) = rand()%100/100.0f; } disp *= temperature; } else { //disp = d*k*k/pow(normD,2); disp = edgeLengthSqr/pow(normD, 2)*d; } dispBuf[j] += disp; dispBuf[i] -= disp; } } DWORD tRepForce = GetTickCount()-t2; /*calculate attractive force*/ for (i=0; i<_edges.size(); ++i) { int edgeIdx = i+_nVertices; for (j=0; j<_edges[i].size(); ++j) { float c2 = 10; float edgeLengthSqr = _clusters[_edges[i][j]]==i?1:9.0; edgeLengthSqr *= k; fvec d = _layout[edgeIdx] - _layout[_edges[i][j]]; fvec disp = c2*d*norm(d,2)/edgeLengthSqr; dispBuf[edgeIdx] -= disp; dispBuf[_edges[i][j]] += disp; /*for (int m=0; m<j; ++m) { if (m==j) { continue; } float edgeLengthSqr = _clusters[_edges[i][j]]==_clusters[_edges[i][m]]?1:16.0; edgeLengthSqr *= k; fvec d = _layout[_edges[i][m]] - _layout[_edges[i][j]]; fvec disp = c2*d*norm(d,2)/edgeLengthSqr; dispBuf[_edges[i][m]] -= disp; dispBuf[_edges[i][j]] += disp; }*/ } } DWORD tRepAttrForces = GetTickCount()-t2; /*restrict the points from being pushed towards the boundary*/ for (i=0; i<nTotal; ++i) { for (j=0; j<dim; ++j) { float c1=1.0e6; float x = _layout[i](j); if (x==boundary[j*2] || x==boundary[j*2+1]) { int stop = 1; } float d = c1*(1/(x-boundary[j*2]+1.0e-3)-1/(boundary[j*2+1]-x+1.0e-3)); dispBuf[i](j) += d; } } /*limit the maximum displacement, boundary check*/ for (i=0; i<nTotal; ++i) { float n = norm(dispBuf[i],2); fvec newLayout = _layout[i]+dispBuf[i]*min(n, temperature)/n; for (j=0; j<dim; ++j) { int minBoundary = boundary[2*j]; int maxBoundary = boundary[2*j+1]; newLayout(j) = newLayout(j) < minBoundary?minBoundary:(newLayout(j)>maxBoundary?maxBoundary:newLayout(j)); } if (norm(newLayout-_layout[i], 2)>1.0e-3) { _layout[i] = newLayout; bChanged = true; } } if (!bChanged) { break; } DWORD perItTime = GetTickCount() - t1; t1 = GetTickCount(); prog.setValue(it); } }
void qCSF::doAction() { //m_app should have already been initialized by CC when plugin is loaded! //(--> pure internal check) assert(m_app); if (!m_app) return; if ( !m_app->haveOneSelection() ) { m_app->dispToConsole("Select only one cloud!", ccMainAppInterface::ERR_CONSOLE_MESSAGE); return; } const ccHObject::Container& selectedEntities = m_app->getSelectedEntities(); ccHObject* ent = selectedEntities[0]; assert(ent); if (!ent || !ent->isA(CC_TYPES::POINT_CLOUD)) { m_app->dispToConsole("Select a real point cloud!", ccMainAppInterface::ERR_CONSOLE_MESSAGE); return; } //to get the point cloud from selected entity. ccPointCloud* pc = static_cast<ccPointCloud*>(ent); //Convert CC point cloud to CSF type unsigned count = pc->size(); wl::PointCloud csfPC; try { csfPC.reserve(count); } catch (const std::bad_alloc&) { m_app->dispToConsole("Not enough memory!", ccMainAppInterface::ERR_CONSOLE_MESSAGE); return; } for (unsigned i = 0; i < count; i++) { const CCVector3* P = pc->getPoint(i); wl::Point tmpPoint; //tmpPoint.x = P->x; //tmpPoint.y = P->y; //tmpPoint.z = P->z; tmpPoint.x = P->x; tmpPoint.y = -P->z; tmpPoint.z = P->y; csfPC.push_back(tmpPoint); } //initial dialog parameters static bool csf_postprocessing = false; static double cloth_resolution = 2; static double class_threshold = 0.5; static int csf_rigidness = 2; static int MaxIteration = 500; static bool ExportClothMesh = false; // display the dialog { ccCSFDlg csfDlg(m_app->getMainWindow()); csfDlg.postprocessingcheckbox->setChecked(csf_postprocessing); csfDlg.rig1->setChecked(csf_rigidness == 1); csfDlg.rig2->setChecked(csf_rigidness == 2); csfDlg.rig3->setChecked(csf_rigidness == 3); csfDlg.MaxIterationSpinBox->setValue(MaxIteration); csfDlg.cloth_resolutionSpinBox->setValue(cloth_resolution); csfDlg.class_thresholdSpinBox->setValue(class_threshold); csfDlg.exportClothMeshCheckBox->setChecked(ExportClothMesh); if (!csfDlg.exec()) { return; } //save the parameters for next time csf_postprocessing = csfDlg.postprocessingcheckbox->isChecked(); if (csfDlg.rig1->isChecked()) csf_rigidness = 1; else if (csfDlg.rig2->isChecked()) csf_rigidness = 2; else csf_rigidness = 3; MaxIteration = csfDlg.MaxIterationSpinBox->value(); cloth_resolution = csfDlg.cloth_resolutionSpinBox->value(); class_threshold = csfDlg.class_thresholdSpinBox->value(); ExportClothMesh = csfDlg.exportClothMeshCheckBox->isChecked(); } //display the progress dialog QProgressDialog pDlg; pDlg.setWindowTitle("CSF"); pDlg.setLabelText("Computing...."); pDlg.setCancelButton(0); pDlg.show(); QApplication::processEvents(); QElapsedTimer timer; timer.start(); //instantiation a CSF class CSF csf(csfPC); // setup parameter csf.params.k_nearest_points = 1; csf.params.bSloopSmooth = csf_postprocessing; csf.params.time_step = 0.65; csf.params.class_threshold = class_threshold; csf.params.cloth_resolution = cloth_resolution; csf.params.rigidness = csf_rigidness; csf.params.iterations = MaxIteration; //to do filtering std::vector<int> groundIndexes, offGroundIndexes; ccMesh* clothMesh = 0; if (!csf.do_filtering(groundIndexes, offGroundIndexes, ExportClothMesh, clothMesh, m_app)) { m_app->dispToConsole("Process failed", ccMainAppInterface::ERR_CONSOLE_MESSAGE); return; } m_app->dispToConsole(QString("[CSF] %1% of points classified as ground points").arg((groundIndexes.size() * 100.0) / count, 0, 'f', 2), ccMainAppInterface::STD_CONSOLE_MESSAGE); m_app->dispToConsole(QString("[CSF] Timing: %1 s.").arg(timer.elapsed() / 1000.0, 0, 'f', 1), ccMainAppInterface::STD_CONSOLE_MESSAGE); //extract ground subset ccPointCloud* groundpoint = 0; { CCLib::ReferenceCloud groundpc(pc); if (groundpc.reserve(static_cast<unsigned>(groundIndexes.size()))) { for (unsigned j = 0; j < groundIndexes.size(); ++j) { groundpc.addPointIndex(groundIndexes[j]); } groundpoint = pc->partialClone(&groundpc); } } if (!groundpoint) { m_app->dispToConsole("Failed to extract the ground subset (not enough memory)", ccMainAppInterface::WRN_CONSOLE_MESSAGE); } //extract off-ground subset ccPointCloud* offgroundpoint = 0; { CCLib::ReferenceCloud offgroundpc(pc); if (offgroundpc.reserve(static_cast<unsigned>(offGroundIndexes.size()))) { for (unsigned k = 0; k < offGroundIndexes.size(); ++k) { offgroundpc.addPointIndex(offGroundIndexes[k]); } offgroundpoint = pc->partialClone(&offgroundpc); } } if (!offgroundpoint) { m_app->dispToConsole("Failed to extract the off-ground subset (not enough memory)", ccMainAppInterface::WRN_CONSOLE_MESSAGE); if (!groundpoint) { //nothing to do! return; } } pDlg.hide(); QApplication::processEvents(); //hide the original cloud pc->setEnabled(false); //we add new group to DB/display ccHObject* cloudContainer = new ccHObject(pc->getName() + QString("_csf")); if (groundpoint) { groundpoint->setVisible(true); groundpoint->setName("ground points"); cloudContainer->addChild(groundpoint); } if (offgroundpoint) { offgroundpoint->setVisible(true); offgroundpoint->setName("off-ground points"); cloudContainer->addChild(offgroundpoint); } if (clothMesh) { clothMesh->computePerVertexNormals(); clothMesh->showNormals(true); cloudContainer->addChild(clothMesh); } m_app->addToDB(cloudContainer); m_app->refreshAll(); }
void FontSelectFrame::setFontsDirectory(QString dir_name) { if (m_config) m_config->setPath(dir_name); m_database.clear(); ui->lineEditFontsDir->setText(dir_name); FT_Library library = 0; int error = FT_Init_FreeType(&library); if (error) { qDebug() << "FT_Open_Library error " << error; return; } QDir dir(dir_name); QStringList files = dir.entryList( QStringList() << "*.ttf" << "*.pcf" << "*.ttc" << "*.pcf.gz" << "*.otf", QDir::Files | QDir::Readable ); QProgressDialog* progress = 0; if (!files.isEmpty()) { progress = new QProgressDialog( tr("Scanning directory.."), tr("Cancel"), 0,files.size(),this); progress->setCancelButton(0); progress->setWindowModality(Qt::WindowModal); //progress->show(); } int progress_val = 0; foreach (QString file_name, files) { //qDebug() << "found font file : " << file_name; QFile file(dir.filePath(file_name)); if (file.open(QFile::ReadOnly)) { QByteArray bytes = file.readAll(); const FT_Byte* data = reinterpret_cast<const FT_Byte* >(bytes.data()); FT_Face face; int error = FT_New_Memory_Face(library, data,bytes.size(),-1,&face); if (error==0) { int faces_num = face->num_faces; FT_Done_Face(face); for (int face_n = 0;face_n<faces_num;face_n++) { error = FT_New_Memory_Face(library, data,bytes.size(),face_n,&face); /// skip font if load error if (error!=0) continue; QString family = face->family_name; //qDebug() << "face " << family << " " // << face->style_name; /// skip font if not have family if (family.isEmpty()) continue; bool fixedsizes = (FT_FACE_FLAG_SCALABLE & face->face_flags ) == 0; m_database[face->family_name].push_back( FontDef(face->style_name, file_name, face_n, fixedsizes)); if (fixedsizes) { for (int i=0;i<face->num_fixed_sizes;i++) { m_database[family].back().fixedsizes.push_back( QPair<int,int>( face->available_sizes[i].width, face->available_sizes[i].height)); } qDebug() << " fixed sizes " << m_database[family].back().fixedsizes; } FT_Done_Face(face); } } } progress_val++; progress->setValue(progress_val); }
void Uploading::uploadingProcess(const QString &actionId) { { QProgressDialog progressDialog; progressDialog.setWindowModality(Qt::WindowModal); progressDialog.setWindowTitle(tr("Выгрузка базы данных")); progressDialog.setLabelText(tr("Процесс выгрузки базы данных")); progressDialog.setCancelButton(0); progressDialog.setMinimumDuration(0); progressDialog.setMaximum(6); progressDialog.setValue(0); QSqlDatabase db = QSqlDatabase::database(UPLOADING); createDBScheme(); progressDialog.setValue(1); QApplication::processEvents(QEventLoop::ExcludeUserInputEvents); QSqlQuery selectDataQuery(QSqlDatabase::database(mConnection)); QSqlQuery insertDataQuery(db); if(selectDataQuery.exec("SELECT id, title, performer FROM Actions WHERE id = " + actionId)) { insertDataQuery.prepare("INSERT INTO Actions VALUES(:id, :title, :performer);"); while(selectDataQuery.next()) { insertDataQuery.bindValue(":id", selectDataQuery.value(0)); insertDataQuery.bindValue(":title", selectDataQuery.value(1)); insertDataQuery.bindValue(":performer", selectDataQuery.value(2)); insertDataQuery.exec(); } } progressDialog.setValue(2); QList<int> placeSchemeIds; QList<int> clientIds; if(selectDataQuery.exec("SELECT id, id_action, id_placeScheme, id_client, identifier FROM Tickets WHERE id_action = " + actionId)) { insertDataQuery.prepare("INSERT INTO Tickets VALUES(NULL, :id_action, :id_placeScheme, :id_client, :identifier, :passedFlag);"); while(selectDataQuery.next()) { insertDataQuery.bindValue(":id_action", selectDataQuery.value(1)); insertDataQuery.bindValue(":id_placeScheme", selectDataQuery.value(2)); insertDataQuery.bindValue(":id_client", selectDataQuery.value(3)); insertDataQuery.bindValue(":identifier", selectDataQuery.value(4)); insertDataQuery.bindValue(":passedFlag", "false"); insertDataQuery.exec(); if(selectDataQuery.isNull(2) == false) placeSchemeIds.append(selectDataQuery.value(2).toInt()); if(selectDataQuery.isNull(3) == false) clientIds.append(selectDataQuery.value(4).toInt()); } } progressDialog.setValue(3); if(placeSchemeIds.isEmpty() == false) { if(selectDataQuery.exec("SELECT id, seatNumber, row FROM PlaceSchemes")) { insertDataQuery.prepare("INSERT INTO PlaceSchemes VALUES(:id, :seatNumber, :row)"); while(selectDataQuery.next()) { if(placeSchemeIds.contains( selectDataQuery.value(0).toInt()) ) { insertDataQuery.bindValue(":id", selectDataQuery.value(0)); insertDataQuery.bindValue(":seatNumber", selectDataQuery.value(1)); insertDataQuery.bindValue(":row", selectDataQuery.value(2)); insertDataQuery.exec(); } } } } progressDialog.setValue(4); if(clientIds.isEmpty() == false) { if(selectDataQuery.exec("SELECT id, name, login FROM Clients")) { insertDataQuery.prepare("INSERT INTO Clients VALUES(:id, :name, :login)"); while(selectDataQuery.next()) { if(clientIds.contains( selectDataQuery.value(0).toInt() )) { insertDataQuery.bindValue(":id", selectDataQuery.value(0)); insertDataQuery.bindValue(":name", selectDataQuery.value(1)); insertDataQuery.bindValue(":login", selectDataQuery.value(2)); insertDataQuery.exec(); } } } } progressDialog.setValue(5); if(selectDataQuery.exec("SELECT id, id_client, identifier FROM ReturnedTickets WHERE id_action = " + actionId)) { insertDataQuery.prepare("INSERT INTO ReturnedTickets VALUES(NULL, :id_client, :identifier);"); while(selectDataQuery.next()) { insertDataQuery.bindValue(":id_client", selectDataQuery.value(1)); insertDataQuery.bindValue(":identifier", selectDataQuery.value(2)); insertDataQuery.exec(); } } progressDialog.setValue(6); progressDialog.close(); db.close(); } QSqlDatabase::removeDatabase(UPLOADING); }
void MainWindow::on_computeButton_clicked() { //disabling actions that could make the application crash ui->openButton->setEnabled(false); ui->computeButton->setEnabled(false); QPrincipalAxisGenerator generator; if( computedMeshes ){ //cleaning previous calculation for( int i=1;i<nViewers; i++ ){ leftWidgets[i]->deleteMeshes(); rightWidgets[i]->deleteMeshes(); } } vector<Method> methods2compute; //add them in the order of the tabs methods2compute.push_back( JUST_PCA ); methods2compute.push_back( ROBUS_DETERMINATION ); int progressIt=0; QProgressDialog progress; progress.setWindowTitle("Loading"); progress.setLabelText("Computing meshes..."); progress.setCancelButton(NULL); progress.setMinimum(0); progress.setMaximum(100); progress.show(); for( int i=0; i< leftWidgets[0]->getNumberOfMeshes(); i++ ){ generator.setMesh( leftWidgets[0]->getMesh(i) ); for( int j=0; j<methods2compute.size(); j++ ){ generator.setMethod( methods2compute.at(j) );//selecting method to generate axis generator.start();//computing on other thread not to freeze the main window while(generator.isRunning()){ //forcing window refresh events so the window not freezes during the wait qApp->processEvents(); update(); repaint(); ui->centralWidget->repaint(); } //tab position, 0 is the original tab leftWidgets[j+1]->insert_mesh( leftWidgets[0]->getMesh(i),generator.getAxis() ); rightWidgets[j+1]->insert_mesh( rightWidgets[0]->getMesh(i),generator.getAxis() ); leftWidgets[j+1]->setMeshVisiblility( i,leftWidgets[0]->isMeshVisible(i) ); rightWidgets[j+1]->setMeshVisiblility( i,leftWidgets[0]->isMeshVisible(i) ); progressIt++; progress.setValue( progressIt*100/(leftWidgets[0]->getNumberOfMeshes()*2) ); progress.update(); } /* //stating way, just for debuging generator.setMethod( JUST_PCA );//selecting method to generate axis generator.start();//computing on other thread not to freeze the main window while(generator.isRunning()){ //forcing window refresh events so the window not freezes during the wait qApp->processEvents(); update(); repaint(); ui->centralWidget->repaint(); } leftWidgets[1]->insert_mesh( leftWidgets[0]->getMesh(i),generator.getAxis() ); rightWidgets[1]->insert_mesh( rightWidgets[0]->getMesh(i),generator.getAxis() ); leftWidgets[1]->setMeshVisiblility( i,leftWidgets[0]->isMeshVisible(i) ); rightWidgets[1]->setMeshVisiblility( i,leftWidgets[0]->isMeshVisible(i) ); progressIt++; progress.setValue( progressIt*100/(leftWidgets[0]->getNumberOfMeshes()*2) ); progress.update(); //sleep(2); generator.setMethod( ROBUS_DETERMINATION ); generator.start(); while(generator.isRunning()){ //forcing window refresh events so the window not freezes during the wait qApp->processEvents(); update(); repaint(); ui->centralWidget->repaint(); } leftWidgets[2]->insert_mesh( leftWidgets[0]->getMesh(i),generator.getAxis() ); rightWidgets[2]->insert_mesh( rightWidgets[0]->getMesh(i),generator.getAxis() ); leftWidgets[2]->setMeshVisiblility( i,leftWidgets[0]->isMeshVisible(i) ); rightWidgets[2]->setMeshVisiblility( i,leftWidgets[0]->isMeshVisible(i) ); progressIt++; progress.setValue( progressIt*100/(leftWidgets[0]->getNumberOfMeshes()*2) ); progress.update(); */ //sleep(2); } progress.setValue(100); progress.close(); //apply translation and rotation cout <<"Computing axis completed"<<endl; computedMeshes=true; ui->openButton->setEnabled(true); ui->computeButton->setEnabled(true); ui->alignButton->setEnabled(true); }