obstDet.cpp

00001 /* Obstacle Detection Program
00002     Code of main constructor.
00003 */
00004 #include "obstDet.h"
00005 #include <qwt_plot.h>
00006 
00007 obstDet::obstDet(QWidget *parent)
00008 {
00009     mf.setupUi(&w);
00010     // Connect some signals and slots
00011     QObject::connect(mf.action_Open_File, SIGNAL( activated() ), this, SLOT( openFile() ) );
00012     QObject::connect(mf.action_About, SIGNAL( activated() ), this, SLOT( about() ) );
00013     QObject::connect(mf.intervalBox, SIGNAL( valueChanged(int) ), this, SLOT( updateCaptureInt(int) ) );
00014     QObject::connect(mf.captureBool, SIGNAL( stateChanged(int) ), this, SLOT( toggleCapture(int) ) );
00015     QObject::connect(&fs, SIGNAL( frameReady(QImage*) ), mf.video1, SLOT( displayImage(QImage*) ) );
00016     QObject::connect(mf.algCheck, SIGNAL( stateChanged(int) ), this, SLOT( algToggle(int) ) );
00017     QObject::connect(mf.playButton, SIGNAL( clicked() ), this, SLOT( togglePause() ) );
00018     //mf.obsplot->setAxisScale( mf.obsplot::xLeft, -90.0, 90.0);
00019     //mf.obsplot->setAxisScale( mf.obsplot::yBottom,-110.0, 110.0);
00020     fs.setCaptureRate(mf.intervalBox->value());
00021     w.showMaximized();
00022     w.show();
00023 
00024         // Now add our agorithm(s) to the list of available choices
00025         mf.algSelector->addItem(tsAlg.getName());
00026         
00027         //     
00028     //testing code
00029     
00030     test();
00031 }
00032 void obstDet::openFile()
00033 {
00034     QString s = QFileDialog::getOpenFileName( this,"Choose a video file","/home","Videos (*.avi *.mpg *.mpeg)");
00035     if ( !s.isNull() )
00036     {
00037     if ( fs.attachSource(&s) )
00038         {
00039                 QMessageBox::warning(this, "VisualODF",
00040                                     "Could not open the specified video source.\n");
00041         }
00042     else
00043     {
00044         mf.captureBool->setEnabled(true);
00045         mf.algCheck->setEnabled(true);
00046         fs.togglePause();
00047     }
00048         
00049     }
00050          
00051         
00052 }
00053 void obstDet::togglePause()
00054 {
00055         fs.togglePause();
00056 }
00057 
00058 void obstDet::about()
00059 {
00060     QMessageBox::about( this, "About...","Contributors:\nRob Russell (robbie _-dot-_ russell _-at-_ gmail _-dot_- com)" );
00061 }
00062 void obstDet::test()
00063 {
00064     // A utility function that will be removed later to test some aspects of the program
00065     //QString f = "example.png";
00066     //mf.video1->loadImage(&f);
00067     //QString msg;
00068     //msg="Opening video file 'test_flight.avi' ...\nVideo file opened successfully.\nUsing algorithm: NONE for obstacle detection.\nPlaying video at 30.23 fps.";
00069     //addVideoMessage(&msg);
00070     //msg="Obstacle detected: 98m @ 9deg left of heading\nObstacle type: THREAT";
00071     //addTcasMessage(&msg);
00072     
00073     // Add the threat
00074     unsigned long mkey;
00075     //mf.tcas->addThreat(threatReal, descending, -1,275, 80, mkey);
00076     //mf.pieDisp->addThreat(threatReal,-1,45,-135, mkey);
00077     
00078     // Ok, let's start a video.
00079     //mf.qtffplayer->grabWindow();
00080 //    mf.qtffplayer->init();
00081     
00082 }
00083 
00084 void obstDet::addVideoMessage(QString *str)
00085 {
00086     mf.vidMsgTxt->append(*str);
00087 }
00088 
00089 void obstDet::addTcasMessage(QString *str)
00090 {
00091     mf.tcasMsgTxt->append(*str);
00092 }
00093 
00094 void obstDet::updateCaptureInt(int i)
00095 {
00096         fs.setCaptureRate(i);
00097         QString str = "Updated capture interval to every ";
00098         str.append(QString::number(i));
00099         str.append("ms");
00100         addVideoMessage(&str);
00101         
00102 }
00103 
00104 void obstDet::toggleCapture(int i)
00105 {
00106         QString str;
00107         if ( i == Qt::Checked )
00108                 {
00109                         fs.startCapture();
00110                         str="Capture started.";
00111                 }
00112         else if ( i == Qt::Unchecked )
00113                 {
00114                         fs.stopCapture();
00115                         str="Capture stopped.";
00116                 }
00117                 addVideoMessage(&str);
00118         
00119 }
00120 
00121 void obstDet::algToggle(int i)
00122 {
00123         QString str;
00124         QString tmpstr =  mf.algSelector->currentText();
00125         if ( i == Qt::Checked )
00126                 {
00134                          // Disable the algorithm chooser so it cant be changed unless you disable the current one
00135                          mf.algSelector->setEnabled(false);
00136                         if (tmpstr == tsAlg.getName())
00137                         {
00138                                         // connect the signal and slot between the frameserver and the processing slot of the algorithm
00139                                         QObject::connect(&fs, SIGNAL( frameReady(QImage*) ), &tsAlg, SLOT( processFrame(QImage*) ) );
00140                                         // connect the signal and slot between the algorithm and processed video
00141                                         QObject::connect(&tsAlg, SIGNAL( imageReady(QImage*) ), mf.video2, SLOT( displayImage(QImage*) ) );
00142                                         // connect the signal and slot between the algorithm and TCAS display
00143                                         QObject::connect(&tsAlg, SIGNAL(foundObstacle(threatType, trendDir, int , int , int, unsigned long& ) ), mf.tcas, SLOT( addThreat(threatType, trendDir, int, int, int, unsigned long&)) );
00144                                 QObject::connect(&tsAlg, SIGNAL(foundObstacle(threatType, trendDir, int , int , int, unsigned long& ) ), mf.pieDisp, SLOT( addThreat(threatType, trendDir, int, int, int, unsigned long&)) );
00145 
00146                                         QObject::connect(&tsAlg, SIGNAL( displayMessage(QString*) ), this, SLOT( addTcasMessage(QString*) ) );
00147                                         // connect the signal and slot between the algorithm and pie display
00148                                         // connect the signal and slot between the algorithm and the plot display
00149                         }
00150                         else if (tmpstr == "Pretend Second Algorithm Goes Here")
00151                         {}
00152                         
00153                         str="Algorithm enabled.";
00154                 }
00155         else if ( i == Qt::Unchecked )
00156                 {
00161                  // Re-enable switching between algorithms
00162                 mf.algSelector->setEnabled(true);
00163                 
00164                 if (tmpstr == tsAlg.getName())
00165                 {
00166                         QObject::disconnect(&fs, SIGNAL( frameReady(QImage*) ), &tsAlg, SLOT( processFrame(QImage*) ) );
00167                         QObject::disconnect(&tsAlg, SIGNAL( imageReady(QImage*) ), mf.video2, SLOT( displayImage(QImage*) ) );
00168                         QObject::disconnect(&tsAlg, SIGNAL(foundObstacle(threatType, trendDir, int , int , int, unsigned long& ) ), mf.tcas, SLOT( addThreat(threatType, trendDir, int, int, int,unsigned long&) ));
00169                         QObject::disconnect(&tsAlg, SIGNAL( displayMessage(QString*) ), this, SLOT( addTcasMessage(QString*) ) );
00170                         QObject::disconnect(&tsAlg, SIGNAL(foundObstacle(threatType, trendDir, int , int , int, unsigned long& ) ), mf.pieDisp, SLOT( addThreat(threatType, trendDir, int, int, int, unsigned long&)) );
00171                 }
00172                 else if (tmpstr == "Pretend Second Algorithm Goes Here")
00173                         {}
00174                 str="Algorithm disabled.";
00175                 }
00176                 addVideoMessage(&str);
00177 }

Generated on Thu Aug 17 12:14:56 2006 for VisualODF by  doxygen 1.4.7