Signals | Public Member Functions | Protected Slots | Protected Attributes

QmitkOpenCVVideoControls Class Reference

Offers widgets to play/pause/stop a video on a certain render window with the use of an !initialized! QmitkVideoBackground. The QmitkVideoBackground should contain an OpenCVVideoSource is then owned by this widget (and deleted) More...

#include <QmitkOpenCVVideoControls.h>

Collaboration diagram for QmitkOpenCVVideoControls:
Collaboration graph
[legend]

List of all members.

Signals

void NewOpenCVFrameAvailable (const IplImage *)

Public Member Functions

 QmitkOpenCVVideoControls (QmitkVideoBackground *_VideoBackground, QmitkStdMultiWidget *_MultiWidget, QWidget *parent=0, Qt::WindowFlags f=0)
virtual ~QmitkOpenCVVideoControls ()
void SetStdMultiWidget (QmitkStdMultiWidget *_MultiWidget)
QmitkStdMultiWidgetGetStdMultiWidget () const
void SetVideoBackground (QmitkVideoBackground *_VideoBackground)
QmitkVideoBackgroundGetVideoBackground () const

Protected Slots

void on_UseGrabbingDeviceButton_clicked (bool checked=false)
void on_UseVideoFileButton_clicked (bool checked=false)
void on_VideoProgressSlider_sliderPressed ()
void on_VideoProgressSlider_sliderReleased ()
void on_RepeatVideoButton_clicked (bool checked=false)
void on_PlayButton_clicked (bool checked=false)
void on_StopButton_clicked (bool checked=false)
void Stop ()
void Reset ()
void SwitchPlayButton (bool paused)
void QObjectDestroyed (QObject *obj=0)
void NewFrameAvailable (mitk::VideoSource *videoSource)

Protected Attributes

QmitkVideoBackgroundm_VideoBackground
QmitkStdMultiWidgetm_MultiWidget
mitk::OpenCVVideoSourcem_VideoSource
Ui::QmitkOpenCVVideoControls * m_Controls
bool m_SliderCurrentlyMoved

Detailed Description

Offers widgets to play/pause/stop a video on a certain render window with the use of an !initialized! QmitkVideoBackground. The QmitkVideoBackground should contain an OpenCVVideoSource is then owned by this widget (and deleted)

Definition at line 38 of file QmitkOpenCVVideoControls.h.


Constructor & Destructor Documentation

QmitkOpenCVVideoControls::QmitkOpenCVVideoControls ( QmitkVideoBackground _VideoBackground,
QmitkStdMultiWidget _MultiWidget,
QWidget *  parent = 0,
Qt::WindowFlags  f = 0 
)

Construct the widget with the given render window and the given preset values

Definition at line 23 of file QmitkOpenCVVideoControls.cpp.

References m_Controls, SetStdMultiWidget(), and SetVideoBackground().

: QWidget(parent, f)
, m_VideoBackground(0)
, m_MultiWidget(0)
, m_VideoSource(0)
, m_Controls(new Ui::QmitkOpenCVVideoControls)
, m_SliderCurrentlyMoved(false)
{
  m_Controls->setupUi(this);
  m_Controls->FileChooser->SetFileMustExist(true);
  m_Controls->FileChooser->SetSelectDir(false);

  this->SetStdMultiWidget(_MultiWidget);
  this->SetVideoBackground(_VideoBackground);
}
QmitkOpenCVVideoControls::~QmitkOpenCVVideoControls (  ) [virtual]

call reset if video playback is enabled here

Definition at line 41 of file QmitkOpenCVVideoControls.cpp.

References mitk::VideoSource::IsCapturingEnabled(), m_VideoSource, and Stop().

{
  if(m_VideoSource != 0 && m_VideoSource->IsCapturingEnabled())
    this->Stop(); // emulate stop
}

Member Function Documentation

QmitkStdMultiWidget * QmitkOpenCVVideoControls::GetStdMultiWidget (  ) const

returns the current multiwidget

Definition at line 263 of file QmitkOpenCVVideoControls.cpp.

References m_MultiWidget.

{
  return m_MultiWidget;
}
QmitkVideoBackground * QmitkOpenCVVideoControls::GetVideoBackground (  ) const

returns the current QmitkVideoBackground

Definition at line 316 of file QmitkOpenCVVideoControls.cpp.

References m_VideoBackground.

{
  return m_VideoBackground;
}
void QmitkOpenCVVideoControls::NewFrameAvailable ( mitk::VideoSource videoSource ) [protected, slot]
void QmitkOpenCVVideoControls::NewOpenCVFrameAvailable ( const IplImage *   ) [signal]

When playback is started this informs when a new frame was grabbed

Referenced by NewFrameAvailable().

void QmitkOpenCVVideoControls::on_PlayButton_clicked ( bool  checked = false ) [protected, slot]

Definition at line 96 of file QmitkOpenCVVideoControls.cpp.

References QmitkVideoBackground::AddRenderWindow(), QmitkStdMultiWidget::DisableGradientBackground(), QmitkVideoBackground::Enable(), mitk::OpenCVVideoSource::GetCapturePaused(), QmitkStdMultiWidget::GetRenderWindow4(), mitk::VideoSource::IsCapturingEnabled(), m_Controls, m_MultiWidget, m_VideoBackground, m_VideoSource, MITK_ERROR, MITK_INFO, NewFrameAvailable(), mitk::OpenCVVideoSource::PauseCapturing(), mitk::OpenCVVideoSource::SetRepeatVideo(), QmitkVideoBackground::SetTimerDelay(), mitk::OpenCVVideoSource::SetVideoCameraInput(), mitk::OpenCVVideoSource::SetVideoFileInput(), mitk::OpenCVVideoSource::StartCapturing(), and SwitchPlayButton().

{
  MITK_INFO << "play button clicked";
  if(checked)
  {
    if( m_VideoSource->GetCapturePaused() )
    {
      this->SwitchPlayButton(false);
      m_VideoSource->PauseCapturing();
    }
    else
    {
      if(m_Controls->UseGrabbingDeviceButton->isChecked())
      {
        m_VideoSource->SetVideoCameraInput(m_Controls->GrabbingDeviceNumber->text().toInt(),false);
        m_Controls->VideoFileControls->setEnabled(false);
      }
      else
      {
        m_VideoSource->SetVideoFileInput(m_Controls->FileChooser->GetFile().c_str(), m_Controls->RepeatVideoButton->isChecked(), false);
        m_VideoSource->SetRepeatVideo(m_Controls->RepeatVideoButton->isChecked());
        m_Controls->VideoProgressSlider->setValue(0);
      }

      m_VideoSource->StartCapturing();
      if(!m_VideoSource->IsCapturingEnabled())
      {
        MITK_ERROR << "Video could not be initialized!";
        m_Controls->PlayButton->setChecked(false);
      }

      else
      {
        int hertz = m_Controls->UpdateRate->text().toInt();
        int updateTime = itk::Math::Round( static_cast<double>(1000.0/hertz) );

        // resets the whole background
        m_VideoBackground->SetTimerDelay( updateTime );
        m_VideoBackground->AddRenderWindow( m_MultiWidget->GetRenderWindow4()->GetRenderWindow() );
        this->connect( m_VideoBackground, SIGNAL(NewFrameAvailable(mitk::VideoSource*))
          , this, SLOT(NewFrameAvailable(mitk::VideoSource*)));
        m_MultiWidget->DisableGradientBackground();

        m_VideoBackground->Enable();
        this->m_Controls->StopButton->setEnabled(true);
        // show video file controls
        if(m_Controls->UseVideoFileButton->isChecked())
        {
          m_Controls->VideoFileControls->setEnabled(true);
          m_Controls->RepeatVideoButton->setEnabled(true);
          m_Controls->VideoProgressSlider->setEnabled(true);
        }
        // show pause button
        this->SwitchPlayButton(false);
        // disable other controls
        m_Controls->GrabbingDevicePanel->setEnabled(false);
        m_Controls->VideoFilePanel->setEnabled(false);
        m_Controls->UseGrabbingDeviceButton->setEnabled(false);
        m_Controls->UseVideoFileButton->setEnabled(false);
        m_Controls->UpdateRatePanel->setEnabled(false);
      }
    }
  }
  else
  {
    // show pause button
    this->SwitchPlayButton(true);
    m_VideoSource->PauseCapturing();

  }
}
void QmitkOpenCVVideoControls::on_RepeatVideoButton_clicked ( bool  checked = false ) [protected, slot]

Definition at line 90 of file QmitkOpenCVVideoControls.cpp.

References m_VideoSource, MITK_INFO, and mitk::OpenCVVideoSource::SetRepeatVideo().

{
  MITK_INFO << "repeat video clicked";
  m_VideoSource->SetRepeatVideo(checked);
}
void QmitkOpenCVVideoControls::on_StopButton_clicked ( bool  checked = false ) [protected, slot]

Definition at line 168 of file QmitkOpenCVVideoControls.cpp.

References Stop().

{
  this->Stop();
}
void QmitkOpenCVVideoControls::on_UseGrabbingDeviceButton_clicked ( bool  checked = false ) [protected, slot]

Definition at line 47 of file QmitkOpenCVVideoControls.cpp.

References m_Controls.

Referenced by SetVideoBackground(), and Stop().

{
  m_Controls->GrabbingDevicePanel->setEnabled(true);
  m_Controls->VideoFilePanel->setEnabled(false);
}
void QmitkOpenCVVideoControls::on_UseVideoFileButton_clicked ( bool  checked = false ) [protected, slot]

Definition at line 53 of file QmitkOpenCVVideoControls.cpp.

References m_Controls.

Referenced by Stop().

{
  m_Controls->GrabbingDevicePanel->setEnabled(false);
  m_Controls->VideoFilePanel->setEnabled(true);
  m_Controls->FileChooser->setEnabled(true);
}
void QmitkOpenCVVideoControls::on_VideoProgressSlider_sliderPressed (  ) [protected, slot]
void QmitkOpenCVVideoControls::on_VideoProgressSlider_sliderReleased (  ) [protected, slot]

Definition at line 77 of file QmitkOpenCVVideoControls.cpp.

References mitk::OpenCVVideoSource::GetCapturePaused(), m_Controls, m_SliderCurrentlyMoved, m_VideoSource, MITK_DEBUG, mitk::OpenCVVideoSource::PauseCapturing(), and mitk::OpenCVVideoSource::SetVideoCaptureProperty().

{
  double progressRatio = static_cast<double>(m_Controls->VideoProgressSlider->value())
    /static_cast<double>(m_Controls->VideoProgressSlider->maximum());
  m_VideoSource->SetVideoCaptureProperty(CV_CAP_PROP_POS_AVI_RATIO, progressRatio);

  MITK_DEBUG << "resuming video with new pos ratio: "<< progressRatio;
  // resume the video ( if it was not paused by the user)
  if( m_VideoSource->GetCapturePaused() && m_Controls->PlayButton->isChecked() )
    m_VideoSource->PauseCapturing();
  m_SliderCurrentlyMoved = false;
}
void QmitkOpenCVVideoControls::QObjectDestroyed ( QObject *  obj = 0 ) [protected, slot]
void QmitkOpenCVVideoControls::Reset (  ) [protected, slot]

Definition at line 204 of file QmitkOpenCVVideoControls.cpp.

References Stop().

Referenced by SetStdMultiWidget(), and SetVideoBackground().

{
  this->Stop();
}
void QmitkOpenCVVideoControls::SetStdMultiWidget ( QmitkStdMultiWidget _MultiWidget )

sets the multiwidget for this video player

Definition at line 233 of file QmitkOpenCVVideoControls.cpp.

References m_MultiWidget, MITK_WARN, QObjectDestroyed(), and Reset().

Referenced by QmitkOpenCVVideoControls(), QObjectDestroyed(), and QmitkVideoPlayer::StdMultiWidgetAvailable().

{
  if(m_MultiWidget == _MultiWidget)
    return;

  if(m_MultiWidget != 0)
    this->disconnect( m_MultiWidget, SIGNAL(destroyed(QObject*))
    , this, SLOT(QObjectDestroyed(QObject*)));

  // In Reset() m_MultiWidget is used, set it to 0 now for avoiding errors
  if(_MultiWidget == 0)
    m_MultiWidget = 0;
  this->Reset();

  m_MultiWidget = _MultiWidget;

  if(m_MultiWidget == 0)
  {
    MITK_WARN << "m_MultiWidget is 0";
    this->setEnabled(false);
  }
  else
  {
    this->setEnabled(true);

    this->connect( m_MultiWidget, SIGNAL(destroyed(QObject*))
      , this, SLOT(QObjectDestroyed(QObject*)));
  }
}
void QmitkOpenCVVideoControls::SetVideoBackground ( QmitkVideoBackground _VideoBackground )

sets the qmitkvideobackground for this

Definition at line 268 of file QmitkOpenCVVideoControls.cpp.

References mitk::OpenCVVideoSource::GetGrabbingDeviceNumber(), QmitkVideoBackground::GetTimerDelay(), mitk::OpenCVVideoSource::GetVideoFileName(), QmitkVideoBackground::GetVideoSource(), m_Controls, m_VideoBackground, m_VideoSource, MITK_WARN, on_UseGrabbingDeviceButton_clicked(), QObjectDestroyed(), and Reset().

Referenced by QmitkOpenCVVideoControls(), and QObjectDestroyed().

{
  if(m_VideoBackground == _VideoBackground)
    return;

  if(m_VideoBackground != 0)
    this->disconnect( m_VideoBackground, SIGNAL(destroyed(QObject*))
    , this, SLOT(QObjectDestroyed(QObject*)));

  this->Reset();

  m_VideoBackground = _VideoBackground;

  if(m_VideoBackground == 0)
  {
    m_VideoSource = 0;
    MITK_WARN << "m_MultiWidget is 0";
    this->setEnabled(false);
  }
  else
  {
    this->setEnabled(true);
    m_VideoSource = dynamic_cast<mitk::OpenCVVideoSource*>(m_VideoBackground->GetVideoSource());
    // preset form entries
    if(m_VideoSource != 0)
    {
      if(!m_VideoSource->GetVideoFileName().empty())
      {
        m_Controls->FileChooser->SetFile( m_VideoSource->GetVideoFileName() );
        on_UseGrabbingDeviceButton_clicked( false );
      }
      else if( m_VideoSource->GetGrabbingDeviceNumber() >= 0)
        m_Controls->GrabbingDeviceNumber->setValue( m_VideoSource->GetGrabbingDeviceNumber() );

      m_Controls->UpdateRate->setValue( m_VideoBackground->GetTimerDelay() );

      this->connect( m_VideoBackground, SIGNAL(destroyed(QObject*))
        , this, SLOT(QObjectDestroyed(QObject*)));
    }
    else
    {
      MITK_WARN << "m_VideoSource is 0";
      this->setEnabled(false);
    }
  }

}
void QmitkOpenCVVideoControls::Stop (  ) [protected, slot]
void QmitkOpenCVVideoControls::SwitchPlayButton ( bool  paused ) [protected, slot]

Definition at line 209 of file QmitkOpenCVVideoControls.cpp.

References m_Controls.

Referenced by on_PlayButton_clicked(), and Stop().

{
  if(paused)
  {
    m_Controls->PlayButton->setText("Play");
    m_Controls->PlayButton->setIcon( QIcon(":/OpenCVVideoSupportUI/media-playback-start.png") );
    m_Controls->PlayButton->setChecked(false);
  }
  else
  {
    m_Controls->PlayButton->setText("Pause");
    m_Controls->PlayButton->setIcon( QIcon(":/OpenCVVideoSupportUI/media-playback-pause.png") );
    m_Controls->PlayButton->setChecked(true);
  }
}

Member Data Documentation

Ui::QmitkOpenCVVideoControls* QmitkOpenCVVideoControls::m_Controls [protected]

The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines