Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include "QmitkOpenCVVideoControls.h"
00019 #include <QmitkVideoBackground.h>
00020 #include <QmitkStdMultiWidget.h>
00021 #include <mitkOpenCVVideoSource.h>
00022
00023 QmitkOpenCVVideoControls::QmitkOpenCVVideoControls( QmitkVideoBackground* _VideoBackground
00024 , QmitkStdMultiWidget* _MultiWidget
00025 , QWidget * parent, Qt::WindowFlags f)
00026 : QWidget(parent, f)
00027 , m_VideoBackground(0)
00028 , m_MultiWidget(0)
00029 , m_VideoSource(0)
00030 , m_Controls(new Ui::QmitkOpenCVVideoControls)
00031 , m_SliderCurrentlyMoved(false)
00032 {
00033 m_Controls->setupUi(this);
00034 m_Controls->FileChooser->SetFileMustExist(true);
00035 m_Controls->FileChooser->SetSelectDir(false);
00036
00037 this->SetStdMultiWidget(_MultiWidget);
00038 this->SetVideoBackground(_VideoBackground);
00039 }
00040
00041 QmitkOpenCVVideoControls::~QmitkOpenCVVideoControls()
00042 {
00043 if(m_VideoSource != 0 && m_VideoSource->IsCapturingEnabled())
00044 this->Stop();
00045 }
00046
00047 void QmitkOpenCVVideoControls::on_UseGrabbingDeviceButton_clicked( bool )
00048 {
00049 m_Controls->GrabbingDevicePanel->setEnabled(true);
00050 m_Controls->VideoFilePanel->setEnabled(false);
00051 }
00052
00053 void QmitkOpenCVVideoControls::on_UseVideoFileButton_clicked( bool )
00054 {
00055 m_Controls->GrabbingDevicePanel->setEnabled(false);
00056 m_Controls->VideoFilePanel->setEnabled(true);
00057 m_Controls->FileChooser->setEnabled(true);
00058 }
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068 void QmitkOpenCVVideoControls::on_VideoProgressSlider_sliderPressed()
00069 {
00070 m_SliderCurrentlyMoved = true;
00071
00072 if( !m_VideoSource->GetCapturePaused() )
00073 m_VideoSource->PauseCapturing();
00074 MITK_DEBUG << "freezing video with old pos ratio: "<< m_VideoSource->GetVideoCaptureProperty(CV_CAP_PROP_POS_AVI_RATIO);
00075 }
00076
00077 void QmitkOpenCVVideoControls::on_VideoProgressSlider_sliderReleased()
00078 {
00079 double progressRatio = static_cast<double>(m_Controls->VideoProgressSlider->value())
00080 /static_cast<double>(m_Controls->VideoProgressSlider->maximum());
00081 m_VideoSource->SetVideoCaptureProperty(CV_CAP_PROP_POS_AVI_RATIO, progressRatio);
00082
00083 MITK_DEBUG << "resuming video with new pos ratio: "<< progressRatio;
00084
00085 if( m_VideoSource->GetCapturePaused() && m_Controls->PlayButton->isChecked() )
00086 m_VideoSource->PauseCapturing();
00087 m_SliderCurrentlyMoved = false;
00088 }
00089
00090 void QmitkOpenCVVideoControls::on_RepeatVideoButton_clicked( bool checked )
00091 {
00092 MITK_INFO << "repeat video clicked";
00093 m_VideoSource->SetRepeatVideo(checked);
00094 }
00095
00096 void QmitkOpenCVVideoControls::on_PlayButton_clicked( bool checked )
00097 {
00098 MITK_INFO << "play button clicked";
00099 if(checked)
00100 {
00101 if( m_VideoSource->GetCapturePaused() )
00102 {
00103 this->SwitchPlayButton(false);
00104 m_VideoSource->PauseCapturing();
00105 }
00106 else
00107 {
00108 if(m_Controls->UseGrabbingDeviceButton->isChecked())
00109 {
00110 m_VideoSource->SetVideoCameraInput(m_Controls->GrabbingDeviceNumber->text().toInt(),false);
00111 m_Controls->VideoFileControls->setEnabled(false);
00112 }
00113 else
00114 {
00115 m_VideoSource->SetVideoFileInput(m_Controls->FileChooser->GetFile().c_str(), m_Controls->RepeatVideoButton->isChecked(), false);
00116 m_VideoSource->SetRepeatVideo(m_Controls->RepeatVideoButton->isChecked());
00117 m_Controls->VideoProgressSlider->setValue(0);
00118 }
00119
00120 m_VideoSource->StartCapturing();
00121 if(!m_VideoSource->IsCapturingEnabled())
00122 {
00123 MITK_ERROR << "Video could not be initialized!";
00124 m_Controls->PlayButton->setChecked(false);
00125 }
00126
00127 else
00128 {
00129 int hertz = m_Controls->UpdateRate->text().toInt();
00130 int updateTime = itk::Math::Round( static_cast<double>(1000.0/hertz) );
00131
00132
00133 m_VideoBackground->SetTimerDelay( updateTime );
00134 m_VideoBackground->AddRenderWindow( m_MultiWidget->GetRenderWindow4()->GetRenderWindow() );
00135 this->connect( m_VideoBackground, SIGNAL(NewFrameAvailable(mitk::VideoSource*))
00136 , this, SLOT(NewFrameAvailable(mitk::VideoSource*)));
00137 m_MultiWidget->DisableGradientBackground();
00138
00139 m_VideoBackground->Enable();
00140 this->m_Controls->StopButton->setEnabled(true);
00141
00142 if(m_Controls->UseVideoFileButton->isChecked())
00143 {
00144 m_Controls->VideoFileControls->setEnabled(true);
00145 m_Controls->RepeatVideoButton->setEnabled(true);
00146 m_Controls->VideoProgressSlider->setEnabled(true);
00147 }
00148
00149 this->SwitchPlayButton(false);
00150
00151 m_Controls->GrabbingDevicePanel->setEnabled(false);
00152 m_Controls->VideoFilePanel->setEnabled(false);
00153 m_Controls->UseGrabbingDeviceButton->setEnabled(false);
00154 m_Controls->UseVideoFileButton->setEnabled(false);
00155 m_Controls->UpdateRatePanel->setEnabled(false);
00156 }
00157 }
00158 }
00159 else
00160 {
00161
00162 this->SwitchPlayButton(true);
00163 m_VideoSource->PauseCapturing();
00164
00165 }
00166 }
00167
00168 void QmitkOpenCVVideoControls::on_StopButton_clicked( bool )
00169 {
00170 this->Stop();
00171 }
00172
00173 void QmitkOpenCVVideoControls::Stop()
00174 {
00175
00176 m_Controls->UseGrabbingDeviceButton->setEnabled(true);
00177 m_Controls->UseVideoFileButton->setEnabled(true);
00178 if(m_Controls->UseGrabbingDeviceButton->isChecked())
00179 on_UseGrabbingDeviceButton_clicked(true);
00180 else
00181 on_UseVideoFileButton_clicked(true);
00182
00183 m_Controls->UpdateRatePanel->setEnabled(true);
00184 m_Controls->VideoFileControls->setEnabled(false);
00185 this->m_Controls->StopButton->setEnabled(false);
00186 this->SwitchPlayButton(true);
00187
00188 if(m_MultiWidget)
00189 m_MultiWidget->EnableGradientBackground();
00190 if(m_VideoBackground)
00191 {
00192 m_VideoBackground->Disable();
00193
00194 if(m_MultiWidget)
00195 m_VideoBackground->RemoveRenderWindow( m_MultiWidget->GetRenderWindow4()->GetRenderWindow() );
00196
00197 this->disconnect( m_VideoBackground, SIGNAL(NewFrameAvailable(mitk::VideoSource*))
00198 , this, SLOT(NewFrameAvailable(mitk::VideoSource*)));
00199 }
00200 if(m_VideoSource != 0)
00201 m_VideoSource->StopCapturing();
00202 }
00203
00204 void QmitkOpenCVVideoControls::Reset()
00205 {
00206 this->Stop();
00207 }
00208
00209 void QmitkOpenCVVideoControls::SwitchPlayButton(bool paused)
00210 {
00211 if(paused)
00212 {
00213 m_Controls->PlayButton->setText("Play");
00214 m_Controls->PlayButton->setIcon( QIcon(":/OpenCVVideoSupportUI/media-playback-start.png") );
00215 m_Controls->PlayButton->setChecked(false);
00216 }
00217 else
00218 {
00219 m_Controls->PlayButton->setText("Pause");
00220 m_Controls->PlayButton->setIcon( QIcon(":/OpenCVVideoSupportUI/media-playback-pause.png") );
00221 m_Controls->PlayButton->setChecked(true);
00222 }
00223 }
00224
00225 void QmitkOpenCVVideoControls::NewFrameAvailable( mitk::VideoSource* )
00226 {
00227 emit NewOpenCVFrameAvailable( m_VideoSource->GetCurrentFrame() );
00228 if(!m_SliderCurrentlyMoved)
00229 m_Controls->VideoProgressSlider->setValue( itk::Math::Round( m_VideoSource->GetVideoCaptureProperty(CV_CAP_PROP_POS_AVI_RATIO)
00230 *m_Controls->VideoProgressSlider->maximum() ) );
00231 }
00232
00233 void QmitkOpenCVVideoControls::SetStdMultiWidget( QmitkStdMultiWidget* _MultiWidget )
00234 {
00235 if(m_MultiWidget == _MultiWidget)
00236 return;
00237
00238 if(m_MultiWidget != 0)
00239 this->disconnect( m_MultiWidget, SIGNAL(destroyed(QObject*))
00240 , this, SLOT(QObjectDestroyed(QObject*)));
00241
00242
00243 if(_MultiWidget == 0)
00244 m_MultiWidget = 0;
00245 this->Reset();
00246
00247 m_MultiWidget = _MultiWidget;
00248
00249 if(m_MultiWidget == 0)
00250 {
00251 MITK_WARN << "m_MultiWidget is 0";
00252 this->setEnabled(false);
00253 }
00254 else
00255 {
00256 this->setEnabled(true);
00257
00258 this->connect( m_MultiWidget, SIGNAL(destroyed(QObject*))
00259 , this, SLOT(QObjectDestroyed(QObject*)));
00260 }
00261 }
00262
00263 QmitkStdMultiWidget* QmitkOpenCVVideoControls::GetStdMultiWidget() const
00264 {
00265 return m_MultiWidget;
00266 }
00267
00268 void QmitkOpenCVVideoControls::SetVideoBackground( QmitkVideoBackground* _VideoBackground )
00269 {
00270 if(m_VideoBackground == _VideoBackground)
00271 return;
00272
00273 if(m_VideoBackground != 0)
00274 this->disconnect( m_VideoBackground, SIGNAL(destroyed(QObject*))
00275 , this, SLOT(QObjectDestroyed(QObject*)));
00276
00277 this->Reset();
00278
00279 m_VideoBackground = _VideoBackground;
00280
00281 if(m_VideoBackground == 0)
00282 {
00283 m_VideoSource = 0;
00284 MITK_WARN << "m_MultiWidget is 0";
00285 this->setEnabled(false);
00286 }
00287 else
00288 {
00289 this->setEnabled(true);
00290 m_VideoSource = dynamic_cast<mitk::OpenCVVideoSource*>(m_VideoBackground->GetVideoSource());
00291
00292 if(m_VideoSource != 0)
00293 {
00294 if(!m_VideoSource->GetVideoFileName().empty())
00295 {
00296 m_Controls->FileChooser->SetFile( m_VideoSource->GetVideoFileName() );
00297 on_UseGrabbingDeviceButton_clicked( false );
00298 }
00299 else if( m_VideoSource->GetGrabbingDeviceNumber() >= 0)
00300 m_Controls->GrabbingDeviceNumber->setValue( m_VideoSource->GetGrabbingDeviceNumber() );
00301
00302 m_Controls->UpdateRate->setValue( m_VideoBackground->GetTimerDelay() );
00303
00304 this->connect( m_VideoBackground, SIGNAL(destroyed(QObject*))
00305 , this, SLOT(QObjectDestroyed(QObject*)));
00306 }
00307 else
00308 {
00309 MITK_WARN << "m_VideoSource is 0";
00310 this->setEnabled(false);
00311 }
00312 }
00313
00314 }
00315
00316 QmitkVideoBackground* QmitkOpenCVVideoControls::GetVideoBackground() const
00317 {
00318 return m_VideoBackground;
00319 }
00320
00321 void QmitkOpenCVVideoControls::QObjectDestroyed( QObject * obj )
00322 {
00323 if(m_MultiWidget == obj)
00324 this->SetStdMultiWidget(0);
00325 else if(m_VideoBackground == obj)
00326 {
00327 m_VideoSource = 0;
00328 this->SetVideoBackground(0);
00329 }
00330 }