diff --git a/Modules/US/USFilters/mitkUSImageVideoSource.cpp b/Modules/US/USFilters/mitkUSImageVideoSource.cpp index d237a5b0be..a2bd735038 100644 --- a/Modules/US/USFilters/mitkUSImageVideoSource.cpp +++ b/Modules/US/USFilters/mitkUSImageVideoSource.cpp @@ -1,114 +1,114 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ // MITK HEADER #include "mitkUSImageVideoSource.h" #include "mitkImage.h" //OpenCV HEADER #include #include //Other #include mitk::USImageVideoSource::USImageVideoSource() : itk::Object() { m_IsVideoReady = false; m_IsMetadataReady = false; m_IsGeometryReady = false; this->m_OpenCVToMitkFilter = mitk::OpenCVToMitkImageFilter::New(); } mitk::USImageVideoSource::~USImageVideoSource() { } void mitk::USImageVideoSource::SetVideoFileInput(std::string path) { m_OpenCVVideoSource = mitk::OpenCVVideoSource::New(); // Example: "C:\\Users\\maerz\\Videos\\Debut\\us.avi" m_OpenCVVideoSource->SetVideoFileInput(path.c_str(),true,false); m_OpenCVVideoSource->StartCapturing(); m_OpenCVVideoSource->FetchFrame(); // Let's see if we have been successful m_IsVideoReady = m_OpenCVVideoSource->IsCapturingEnabled(); } void mitk::USImageVideoSource::SetCameraInput(int deviceID) { /* Old Code, this will probably not work m_OpenCVVideoSource = mitk::OpenCVVideoSource::New(); m_OpenCVVideoSource->SetVideoCameraInput(deviceID); m_OpenCVVideoSource->StartCapturing(); m_OpenCVVideoSource->FetchFrame(); // Let's see if we have been successful m_IsVideoReady = m_OpenCVVideoSource->IsCapturingEnabled(); */ } mitk::USImage::Pointer mitk::USImageVideoSource::GetNextImage() { IplImage *m_cvCurrentVideoFrame = NULL; - CvCapture* capture = cvCaptureFromCAM( 50 ); + CvCapture* capture = cvCaptureFromCAM( 1000 ); if ( !capture ) { fprintf( stderr, "ERROR: capture is NULL \n" ); getchar(); return NULL; } // Show the image captured from the camera in the window and repeat // Get one frame m_cvCurrentVideoFrame = cvQueryFrame( capture ); /// WORKING CODE /*IplImage *m_cvCurrentVideoFrame = NULL; int height = m_OpenCVVideoSource->GetImageHeight(); int width = m_OpenCVVideoSource->GetImageWidth(); m_cvCurrentVideoFrame = cvCreateImage(cvSize(width,height),8,3); m_OpenCVVideoSource->GetCurrentFrameAsOpenCVImage(m_cvCurrentVideoFrame); m_OpenCVVideoSource->FetchFrame(); */ this->m_OpenCVToMitkFilter->SetOpenCVImage(m_cvCurrentVideoFrame); this->m_OpenCVToMitkFilter->Update(); // OpenCVToMitkImageFilter returns a standard mit::image. We then transform it into an USImage mitk::USImage::Pointer result = mitk::USImage::New(this->m_OpenCVToMitkFilter->GetOutput(0)); cvReleaseImage (&m_cvCurrentVideoFrame); return result; } diff --git a/Modules/USUI/Qmitk/QmitkUSDeviceManagerWidget.cpp b/Modules/USUI/Qmitk/QmitkUSDeviceManagerWidget.cpp index 0cd4ef8a7e..4117083a44 100644 --- a/Modules/USUI/Qmitk/QmitkUSDeviceManagerWidget.cpp +++ b/Modules/USUI/Qmitk/QmitkUSDeviceManagerWidget.cpp @@ -1,188 +1,183 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ //#define _USE_MATH_DEFINES #include #include //QT headers #include //mitk headers //itk headers //microservices #include #include #include const std::string QmitkUSDeviceManagerWidget::VIEW_ID = "org.mitk.views.QmitkUSDeviceManagerWidget"; QmitkUSDeviceManagerWidget::QmitkUSDeviceManagerWidget(QWidget* parent, Qt::WindowFlags f): QWidget(parent, f) { m_Controls = NULL; CreateQtPartControl(this); // get ModuleContext mitk::Module* mitkUS = mitk::ModuleRegistry::GetModule("MitkUS"); m_MitkUSContext = mitkUS->GetModuleContext(); //ServiceTracker* tracker = new ServiceTracker(m_MitkUSContext, this); // Register this Widget as a listener for Registry changes. // If devices are registered, unregistered or changed, notifications will go there std::string filter = "(&("; filter += mitk::ServiceConstants::OBJECTCLASS(); filter += "="; //filter += us_service_interface_iid(); filter += "org.mitk.services.UltrasoundDevice)(IsActive=false))"; m_MitkUSContext->AddServiceListener(this, &QmitkUSDeviceManagerWidget::OnServiceEvent, filter); } QmitkUSDeviceManagerWidget::~QmitkUSDeviceManagerWidget() { } //////////////////// INITIALIZATION ///////////////////// void QmitkUSDeviceManagerWidget::CreateQtPartControl(QWidget *parent) { if (!m_Controls) { // create GUI widgets m_Controls = new Ui::QmitkUSDeviceManagerWidgetControls; m_Controls->setupUi(parent); this->CreateConnections(); } } void QmitkUSDeviceManagerWidget::CreateConnections() { if ( m_Controls ) { connect( m_Controls->m_BtnActivate, SIGNAL(clicked()), this, SLOT(OnClickedActivateDevice()) ); connect( m_Controls->m_BtnDisconnect, SIGNAL(clicked()), this, SLOT(OnClickedDisconnectDevice()) ); connect( m_Controls->m_ConnectedDevices, SIGNAL(currentItemChanged( QListWidgetItem *, QListWidgetItem *)), this, SLOT(OnDeviceSelectionChanged()) ); } } ///////////// Methods & Slots Handling Direct Interaction ///////////////// void QmitkUSDeviceManagerWidget::OnClickedActivateDevice() { MITK_INFO << "Activated Device"; mitk::USDevice::Pointer device = this->GetDeviceForListItem(this->m_Controls->m_ConnectedDevices->currentItem()); if (device.IsNull()) return; if (device->GetIsActive()) device->Deactivate(); else device->Activate(); } void QmitkUSDeviceManagerWidget::OnClickedDisconnectDevice(){ MITK_INFO << "Disconnected Device"; mitk::USDevice::Pointer device = this->GetDeviceForListItem(this->m_Controls->m_ConnectedDevices->currentItem()); if (device.IsNull()) return; device->Disconnect(); } void QmitkUSDeviceManagerWidget::OnDeviceSelectionChanged(){ mitk::USDevice::Pointer device = this->GetDeviceForListItem(this->m_Controls->m_ConnectedDevices->currentItem()); if (device.IsNull()) return; if (device->GetIsActive()) m_Controls->m_BtnActivate->setText("Deactivate"); else m_Controls->m_BtnActivate->setText("Activate"); } ///////////////// Methods & Slots Handling Logic ////////////////////////// void QmitkUSDeviceManagerWidget::OnServiceEvent(const mitk::ServiceEvent event){ // Empty ListWidget this->m_ListContent.clear(); m_Controls->m_ConnectedDevices->clear(); // get Active Devices std::vector devices = this->GetAllRegisteredDevices(); // Transfer them to the List for(std::vector::iterator it = devices.begin(); it != devices.end(); ++it) { QListWidgetItem *newItem = ConstructItemFromDevice(it->GetPointer()); //Add new item to QListWidget m_Controls->m_ConnectedDevices->addItem(newItem); // Construct Link and add to internal List for reference QmitkUSDeviceManagerWidget::DeviceListLink link; link.device = it->GetPointer(); link.item = newItem; m_ListContent.push_back(link); } } /////////////////////// HOUSEHOLDING CODE ///////////////////////////////// QListWidgetItem* QmitkUSDeviceManagerWidget::ConstructItemFromDevice(mitk::USDevice::Pointer device){ QListWidgetItem *result = new QListWidgetItem; std::string text = device->GetDeviceManufacturer() + "|" + device->GetDeviceModel(); if (device->GetIsActive()) { result->foreground().setColor(Qt::blue); text += "|(ON)"; } else text += "|(OFF)"; result->setText(text.c_str()); return result; } mitk::USDevice::Pointer QmitkUSDeviceManagerWidget::GetDeviceForListItem(QListWidgetItem* item) { for(std::vector::iterator it = m_ListContent.begin(); it != m_ListContent.end(); ++it) { if (item == it->item) return it->device; } return 0; } - -//mitk::ServiceTracker QmitkUSDeviceManagerWidget::ConstructServiceTracker(){ -//return 0; -//} - std::vector QmitkUSDeviceManagerWidget::GetAllRegisteredDevices(){ //Get Service References std::list serviceRefs = m_MitkUSContext->GetServiceReferences(); // Convert Service References to US Devices std::vector* result = new std::vector; std::list::const_iterator iterator; for (iterator = serviceRefs.begin(); iterator != serviceRefs.end(); ++iterator) { mitk::USDevice::Pointer device = m_MitkUSContext->GetService(*iterator); if (device) result->push_back(device); } return *result; } \ No newline at end of file diff --git a/Plugins/org.mitk.gui.qt.ultrasound/src/internal/UltrasoundSupport.cpp b/Plugins/org.mitk.gui.qt.ultrasound/src/internal/UltrasoundSupport.cpp index 964581d2a3..0967d9a084 100644 --- a/Plugins/org.mitk.gui.qt.ultrasound/src/internal/UltrasoundSupport.cpp +++ b/Plugins/org.mitk.gui.qt.ultrasound/src/internal/UltrasoundSupport.cpp @@ -1,111 +1,108 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit Language: C++ Date: $Date$ Version: $Revision$ Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notices for more information. =========================================================================*/ // Blueberry #include #include //Mitk #include "mitkDataNode.h" // Qmitk #include "UltrasoundSupport.h" #include // Qt #include // Ultrasound #include "mitkUSDevice.h" const std::string UltrasoundSupport::VIEW_ID = "org.mitk.views.ultrasoundsupport"; void UltrasoundSupport::SetFocus() { m_Controls.m_AddDevice->setFocus(); } void UltrasoundSupport::CreateQtPartControl( QWidget *parent ) { m_Timer = new QTimer(this); // create GUI widgets from the Qt Designer's .ui file m_Controls.setupUi( parent ); connect( m_Controls.m_AddDevice, SIGNAL(clicked()), this, SLOT(OnClickedAddNewDevice()) ); // Change Widget Visibilities connect( m_Controls.m_AddDevice, SIGNAL(clicked()), this->m_Controls.m_NewVideoDeviceWidget, SLOT(CreateNewDevice()) ); // Init NewDeviceWidget connect( m_Controls.m_NewVideoDeviceWidget, SIGNAL(Finished()), this, SLOT(OnNewDeviceWidgetDone()) ); // After NewDeviceWidget finished editing connect( m_Controls.m_BtnView, SIGNAL(clicked()), this, SLOT(OnClickedViewDevice()) ); connect( m_Timer, SIGNAL(timeout()), this, SLOT(DisplayImage())); //connect (m_Controls.m_ActiveVideoDevices, SIGNAL()) // Initializations m_Controls.m_NewVideoDeviceWidget->setVisible(false); std::string filter = "(&(" + mitk::ServiceConstants::OBJECTCLASS() + "=" + "org.mitk.services.UltrasoundDevice)(IsActive=true))"; m_Controls.m_ActiveVideoDevices->Initialize(filter); m_Node = mitk::DataNode::New(); m_Node->SetName("US Image Stream"); this->GetDataStorage()->Add(m_Node); } void UltrasoundSupport::OnClickedAddNewDevice() { MITK_INFO << "USSUPPORT: OnClickedAddNewDevice()"; m_Controls.m_NewVideoDeviceWidget->setVisible(true); m_Controls.m_DeviceManagerWidget->setVisible(false); m_Controls.m_AddDevice->setVisible(false); m_Controls.m_Headline->setText("Add New Device:"); } void UltrasoundSupport::DisplayImage() { MITK_INFO << "USSUPPORT: DisplayImage()"; //QList nodes = this->GetDataManagerSelection(); // if (nodes.empty()) return; m_Device->UpdateOutputData(0); mitk::USImage::Pointer image = m_Device->GetOutput(); - //m_Node->Initialize(); m_Node->SetData(image); this->RequestRenderWindowUpdate(); - - } void UltrasoundSupport::OnClickedViewDevice() { MITK_INFO << "USSUPPORT: OnClickedViewDevice()"; m_Device = m_Controls.m_ActiveVideoDevices->GetSelectedDevice(); if (m_Device.IsNull()){ m_Timer->stop(); return; } m_Timer->start(100); } void UltrasoundSupport::OnNewDeviceWidgetDone() { MITK_INFO << "USSUPPORT: OnNewDeviceWidgetDone()"; m_Controls.m_NewVideoDeviceWidget->setVisible(false); m_Controls.m_DeviceManagerWidget->setVisible(true); m_Controls.m_AddDevice->setVisible(true); m_Controls.m_Headline->setText("Connected Devices:"); } \ No newline at end of file