Esempio n. 1
0
void ProgressDialog::updateProgress(float progress, const QString &stepString) {
  progressDialog->setValue(int(progress * 100));
  QString message(stepString);
  if (message.length() > 33)
    message = message.left(17) + "..." + message.right(12);
  progressDialog->setLabelText(message);
  progressDialog->update();
  qApp->processEvents();
}
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);
}