diff --git a/Modules/US/USFilters/mitkUSImageVideoSource.cpp b/Modules/US/USFilters/mitkUSImageVideoSource.cpp index e80dc4005c..442123b4f0 100644 --- a/Modules/US/USFilters/mitkUSImageVideoSource.cpp +++ b/Modules/US/USFilters/mitkUSImageVideoSource.cpp @@ -1,128 +1,128 @@ /*=================================================================== 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_IsGreyscale = true; this->m_OpenCVToMitkFilter = mitk::OpenCVToMitkImageFilter::New(); } mitk::USImageVideoSource::~USImageVideoSource() { } void mitk::USImageVideoSource::SetVideoFileInput(std::string path) { m_OpenCVVideoSource = mitk::OpenCVVideoSource::New(); 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) { 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(); } void mitk::USImageVideoSource::SetColorOutput(bool isColor){ m_IsGreyscale = !isColor; } void mitk::USImageVideoSource::SetRegionOfInterest(int topLeftX, int topLeftY, int bottomRightX, int bottomRightY) { // First, let's do some basic checks to make sure rectangle is inside of actual image if (topLeftX < 0) topLeftX = 0; if (topLeftY < 0) topLeftY = 0; if (bottomRightX > m_OpenCVVideoSource->GetImageWidth()) bottomRightX = m_OpenCVVideoSource->GetImageWidth(); if (bottomRightX > m_OpenCVVideoSource->GetImageHeight()) bottomRightY = m_OpenCVVideoSource->GetImageHeight(); if (topLeftX > bottomRightX) mitkThrow() << "Invalid boundaries supplied to USImageVideoSource::SetRegionOfInterest()"; if (topLeftY > bottomRightY) mitkThrow() << "Invalid boundaries supplied to USImageVideoSource::SetRegionOfInterest()"; m_CropRegion = cv::Rect(topLeftX, topLeftY, bottomRightX - topLeftX, bottomRightY - topLeftY); } void mitk::USImageVideoSource::RemoveRegionOfInterest(){ m_CropRegion.width = 0; m_CropRegion.height = 0; } mitk::USImage::Pointer mitk::USImageVideoSource::GetNextImage() { // Setup Pointers cv::Mat image; cv::Mat buffer; //Get dimensions and init rgb int width = m_OpenCVVideoSource->GetImageWidth(); int height = m_OpenCVVideoSource->GetImageHeight(); // Get Frame from Source - image = m_OpenCVVideoSource->GetImage(); m_OpenCVVideoSource->FetchFrame(); + image = m_OpenCVVideoSource->GetImage(); // if Region of interest is set, crop image if (m_CropRegion.width > 0){ buffer = image(m_CropRegion); image = buffer; } // If this is a greyscale image, convert it if (m_IsGreyscale) { cv::cvtColor(image, buffer, CV_RGB2GRAY, 1); image = buffer; } IplImage ipl_img = image; this->m_OpenCVToMitkFilter->SetOpenCVImage(&ipl_img); this->m_OpenCVToMitkFilter->Update(); // OpenCVToMitkImageFilter returns a standard mitk::image. We then transform it into an USImage mitk::USImage::Pointer result = mitk::USImage::New(this->m_OpenCVToMitkFilter->GetOutput(0)); return result; } diff --git a/Modules/US/USModel/mitkUSDevice.cpp b/Modules/US/USModel/mitkUSDevice.cpp index 03b601dc80..e31fbc8a60 100644 --- a/Modules/US/USModel/mitkUSDevice.cpp +++ b/Modules/US/USModel/mitkUSDevice.cpp @@ -1,271 +1,266 @@ /*=================================================================== 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. ===================================================================*/ #include "mitkUSDevice.h" #include "mitkUSImageMetadata.h" //Microservices #include #include #include #include "mitkModuleContext.h" mitk::USDevice::USDevice(std::string manufacturer, std::string model) : mitk::ImageSource() { // Initialize Members m_Metadata = mitk::USImageMetadata::New(); m_Metadata->SetDeviceManufacturer(manufacturer); m_Metadata->SetDeviceModel(model); + //m_Metadata->SetDeviceClass(GetDeviceClass()); m_IsActive = false; //set number of outputs this->SetNumberOfOutputs(1); //create a new output mitk::USImage::Pointer newOutput = mitk::USImage::New(); this->SetNthOutput(0,newOutput); } mitk::USDevice::USDevice(mitk::USImageMetadata::Pointer metadata) : mitk::ImageSource() { m_Metadata = metadata; + //m_Metadata->SetDeviceClass(GetDeviceClass()); m_IsActive = false; //set number of outputs this->SetNumberOfOutputs(1); //create a new output mitk::USImage::Pointer newOutput = mitk::USImage::New(); this->SetNthOutput(0,newOutput); } mitk::USDevice::~USDevice() { } + +// Constructing Service Properties for the device +mitk::ServiceProperties mitk::USDevice::ConstructServiceProperties() +{ + ServiceProperties props; + std::string yes = "true"; + std::string no = "false"; + + if(this->GetIsActive()) + props["IsActive"] = yes; + else + props["IsActive"] = no; + props[ "DeviceClass" ] = GetDeviceClass(); + props[ mitk::USImageMetadata::PROP_DEV_MANUFACTURER ] = m_Metadata->GetDeviceManufacturer(); + props[ mitk::USImageMetadata::PROP_DEV_MODEL ] = m_Metadata->GetDeviceModel(); + props[ mitk::USImageMetadata::PROP_DEV_COMMENT ] = m_Metadata->GetDeviceComment(); + props[ mitk::USImageMetadata::PROP_PROBE_NAME ] = m_Metadata->GetProbeName(); + props[ mitk::USImageMetadata::PROP_PROBE_FREQUENCY ] = m_Metadata->GetProbeFrequency(); + props[ mitk::USImageMetadata::PROP_ZOOM ] = m_Metadata->GetZoom(); + return props; +} + + bool mitk::USDevice::Connect() { //TODO Throw Exception is already activated before connection - + // Prepare connection, fail if this fails. if (! this->OnConnection()) return false; // Get Context and Module mitk::ModuleContext* context = GetModuleContext(); + ServiceProperties props = ConstructServiceProperties(); - // Define ServiceProps - ServiceProperties props; - props["DeviceClass"] = this->GetDeviceClass(); - std::string no = "false"; - props["IsActive"] = no; m_ServiceRegistration = context->RegisterService(this, props); return true; } bool mitk::USDevice::Disconnect() { // Prepare connection, fail if this fails. if (! this->OnDisconnection()) return false; // Unregister m_ServiceRegistration.Unregister(); m_ServiceRegistration = 0; return true; } //bool mitk::USDevice::OnConnection() //{ // return true; // // TODO: Make Abstract //} // //bool mitk::USDevice::OnDisconnection() //{ // return true; // // TODO Make Abstract //} +//Changed bool mitk::USDevice::Activate() { if (! this->GetIsConnected()) return false; m_IsActive = OnActivation(); - ServiceProperties props; - props["DeviceClass"] = this->GetDeviceClass(); - std::string yes = "true"; - props["IsActive"] = yes; + ServiceProperties props = ConstructServiceProperties(); this->m_ServiceRegistration.SetProperties(props); - return m_IsActive; + return m_IsActive; } void mitk::USDevice::Deactivate() { m_IsActive= false; - ServiceProperties props; - props["DeviceClass"] = this->GetDeviceClass(); - std::string no = "false"; - props["IsActive"] = no; + ServiceProperties props = ConstructServiceProperties(); this->m_ServiceRegistration.SetProperties(props); OnDeactivation(); } -// -//bool mitk::USDevice::OnActivation() -//{ -// return true; -// // TODO Make Abstract -//} -// -// -//void mitk::USDevice::OnDeactivation() -//{ -// // TODO Make Abstract -//} -// -// -//std::string mitk::USDevice::GetDeviceClass() -//{ -// return "org.mitk.Ultrasound.GenericDevice"; -//} - - - void mitk::USDevice::AddProbe(mitk::USProbe::Pointer probe) { for(int i = 0; i < m_ConnectedProbes.size(); i++) { if (m_ConnectedProbes[i]->IsEqualToProbe(probe)) return; } this->m_ConnectedProbes.push_back(probe); } void mitk::USDevice::ActivateProbe(mitk::USProbe::Pointer probe){ // currently, we may just add the probe. This behaviour must be changed, should more complicated SDK applications emerge AddProbe(probe); int index = -1; for(int i = 0; i < m_ConnectedProbes.size(); i++) { if (m_ConnectedProbes[i]->IsEqualToProbe(probe)) index = i; } // index now contains the position of the original instance of this probe m_ActiveProbe = m_ConnectedProbes[index]; } void mitk::USDevice::DeactivateProbe(){ m_ActiveProbe = 0; } void mitk::USDevice::GenerateData() { } mitk::USImage* mitk::USDevice::GetOutput() { if (this->GetNumberOfOutputs() < 1) return NULL; return static_cast(this->ProcessObject::GetOutput(0)); } mitk::USImage* mitk::USDevice::GetOutput(unsigned int idx) { if (this->GetNumberOfOutputs() < 1) return NULL; return static_cast(this->ProcessObject::GetOutput(idx)); } void mitk::USDevice::GraftOutput(itk::DataObject *graft) { this->GraftNthOutput(0, graft); } void mitk::USDevice::GraftNthOutput(unsigned int idx, itk::DataObject *graft) { if ( idx >= this->GetNumberOfOutputs() ) { itkExceptionMacro(<<"Requested to graft output " << idx << " but this filter only has " << this->GetNumberOfOutputs() << " Outputs."); } if ( !graft ) { itkExceptionMacro(<<"Requested to graft output with a NULL pointer object" ); } itk::DataObject* output = this->GetOutput(idx); if ( !output ) { itkExceptionMacro(<<"Requested to graft output that is a NULL pointer" ); } // Call Graft on USImage to copy member data output->Graft( graft ); } itk::ProcessObject::DataObjectPointer mitk::USDevice::MakeOutput( unsigned int /*idx */) { mitk::USImage::Pointer p = mitk::USImage::New(); return static_cast(p.GetPointer()); } //########### GETTER & SETTER ##################// bool mitk::USDevice::GetIsActive() { return m_IsActive; } bool mitk::USDevice::GetIsConnected() { // a device is connected if it is registered with the service return (m_ServiceRegistration != 0); } std::string mitk::USDevice::GetDeviceManufacturer(){ return this->m_Metadata->GetDeviceManufacturer(); } std::string mitk::USDevice::GetDeviceModel(){ return this->m_Metadata->GetDeviceModel(); } std::string mitk::USDevice::GetDeviceComment(){ return this->m_Metadata->GetDeviceComment(); } std::vector mitk::USDevice::GetConnectedProbes() { return m_ConnectedProbes; } diff --git a/Modules/US/USModel/mitkUSDevice.h b/Modules/US/USModel/mitkUSDevice.h index 32330d2dc4..42b1e6bceb 100644 --- a/Modules/US/USModel/mitkUSDevice.h +++ b/Modules/US/USModel/mitkUSDevice.h @@ -1,249 +1,262 @@ /*=================================================================== 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. ===================================================================*/ #ifndef MITKUSDevice_H_HEADER_INCLUDED_ #define MITKUSDevice_H_HEADER_INCLUDED_ #include #include "mitkUSProbe.h" #include "mitkUSImageMetadata.h" #include "mitkUSImage.h" #include #include #include #include // Microservices #include #include +#include namespace mitk { /**Documentation * \brief A device holds information about it's model, make and the connected probes. It is the * common super class for all devices and acts as an image source for mitkUSImages. It is the base class * for all US Devices, and every new device should extend it. * \ingroup US */ + class MitkUS_EXPORT USDevice : public mitk::ImageSource { public: mitkClassMacro(USDevice, mitk::ImageSource); /** * \brief Enforces minimal Metadata to be set. */ // mitkNewMacro3Param(Self, std::string, std::string, bool); /** * \brief Constructs a device with the given Metadata. Make sure the Metadata contains meaningful content! * */ // mitkNewMacro2Param(Self, mitk::USImageMetadata::Pointer, bool); + + /** * \brief Connects this device. A connected device is ready to deliver images (i.e. be Activated). A Connected Device can be active. A disconnected Device cannot be active. * Internally calls onConnect and then registers the device with the service. A device usually should * override the OnConnection() method, but never the Connect() method, since this will possibly exclude the device * from normal service management. The exact flow of events is: * 0. Check if the device is already connected. If yes, return true anyway, but don't do anything. * 1. Call OnConnection() Here, a device should establish it's connection with the hardware Afterwards, it should be ready to start transmitting images at any time. * 2. If OnConnection() returns true ("successful"), then the device is registered with the service. * 3. if not, it the method itself returns false or may throw an expection, depeneding on the device implementation. * */ bool Connect(); /** * \brief Works analogously to mitk::USDevice::Connect(). Don't override this Method, but onDisconnection instead. */ bool Disconnect(); /** * \brief Activates this device. After the activation process, the device will start to produce images. This Method will fail, if the device is not connected. */ bool Activate(); /** * \brief Deactivates this device. After the deactivation process, the device will no longer produce images, but still be connected. */ void Deactivate(); /** * \brief Add a probe to the device without connecting to it. * This should usually be done before connecting to the probe. */ virtual void AddProbe(mitk::USProbe::Pointer probe); /** * \brief Connect to a probe and activate it. The probe should be added first. * Usually, a VideoDevice will simply add a probe it wants to connect to, * but an SDK Device might require adding a probe first. */ virtual void ActivateProbe(mitk::USProbe::Pointer probe); /** * \brief Deactivates the currently active probe. */ virtual void DeactivateProbe(); /** * \brief Removes a probe from the ist of currently added probes. */ //virtual void removeProbe(mitk::USProbe::Pointer probe); /** * \brief Returns a vector containing all connected probes. */ std::vector GetConnectedProbes(); /** *\brief return the output (output with id 0) of the filter */ USImage* GetOutput(void); /** *\brief return the output with id idx of the filter */ USImage* GetOutput(unsigned int idx); /** *\brief Graft the specified DataObject onto this ProcessObject's output. * * See itk::ImageSource::GraftNthOutput for details */ virtual void GraftNthOutput(unsigned int idx, itk::DataObject *graft); /** * \brief Graft the specified DataObject onto this ProcessObject's output. * * See itk::ImageSource::Graft Output for details */ virtual void GraftOutput(itk::DataObject *graft); /** * \brief Make a DataObject of the correct type to used as the specified output. * * This method is automatically called when DataObject::DisconnectPipeline() * is called. DataObject::DisconnectPipeline, disconnects a data object * from being an output of its current source. When the data object * is disconnected, the ProcessObject needs to construct a replacement * output data object so that the ProcessObject is in a valid state. * Subclasses of USImageVideoSource that have outputs of different * data types must overwrite this method so that proper output objects * are created. */ virtual DataObjectPointer MakeOutput(unsigned int idx); //########### GETTER & SETTER ##################// /** * \brief Returns the Class of the Device. This Method must be reimplemented by every Inheriting Class. */ virtual std::string GetDeviceClass() = 0; /** * \brief True, if the device is currently generating image data, false otherwise. */ bool GetIsActive(); /** * \brief True, if the device is currently ready to start transmitting image data or is already * transmitting image data. A disconnected device cannot be activated. */ bool GetIsConnected(); /** * \brief Returns the currently active probe or null, if none is active */ itkGetMacro(ActiveProbe, mitk::USProbe::Pointer); std::string GetDeviceManufacturer(); std::string GetDeviceModel(); std::string GetDeviceComment(); protected: mitk::USProbe::Pointer m_ActiveProbe; std::vector m_ConnectedProbes; bool m_IsActive; + + /* + * \brief This Method constructs the service properties which can later be used to + * register the object with the Microservices + * Return service properties + */ + mitk::ServiceProperties ConstructServiceProperties(); + + /** * \brief Is called during the connection process. Override this method in your subclass to handle the actual connection. * Return true if successful and false if unsuccessful. Additionally, you may throw an exception to clarify what went wrong. */ virtual bool OnConnection() = 0; /** * \brief Is called during the disconnection process. Override this method in your subclass to handle the actual disconnection. * Return true if successful and false if unsuccessful. Additionally, you may throw an exception to clarify what went wrong. */ virtual bool OnDisconnection() = 0; /** - * \brief Is called during the activation process. After this method is finsihed, the device should be generating images + * \brief Is called during the activation process. After this method is finished, the device should be generating images */ virtual bool OnActivation() = 0; /** * \brief Is called during the deactivation process. After a call to this method the device should still be connected, but not producing images anymore. */ virtual void OnDeactivation() = 0; /** * \brief This metadata set is privately used to imprint USImages with Metadata later. * At instantiation time, it only contains Information about the Device, * At scan time, it integrates this data with the probe information and imprints it on * the produced images. This field is intentionally hidden from outside interference. */ mitk::USImageMetadata::Pointer m_Metadata; /** * \brief Enforces minimal Metadata to be set. */ USDevice(std::string manufacturer, std::string model); /** * \brief Constructs a device with the given Metadata. Make sure the Metadata contains meaningful content! */ USDevice(mitk::USImageMetadata::Pointer metadata); virtual ~USDevice(); /** * \brief Grabs the next frame from the Video input. This method is called internally, whenever Update() is invoked by an Output. */ void GenerateData(); private: mitk::ServiceRegistration m_ServiceRegistration; }; } // namespace mitk // This is the microservice declaration. Do not meddle! US_DECLARE_SERVICE_INTERFACE(mitk::USDevice, "org.mitk.services.UltrasoundDevice") #endif \ No newline at end of file diff --git a/Modules/US/USModel/mitkUSImageMetadata.cpp b/Modules/US/USModel/mitkUSImageMetadata.cpp index 89dcc177a5..06b3701730 100644 --- a/Modules/US/USModel/mitkUSImageMetadata.cpp +++ b/Modules/US/USModel/mitkUSImageMetadata.cpp @@ -1,45 +1,45 @@ /*=================================================================== 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. ===================================================================*/ #include "mitkUSImageMetadata.h" const char* mitk::USImageMetadata::PROP_DEV_MANUFACTURER = "US.Device.Manufacturer"; const char* mitk::USImageMetadata::PROP_DEV_MODEL = "US.Device.Model"; const char* mitk::USImageMetadata::PROP_DEV_COMMENT = "US.Device.Comment"; const char* mitk::USImageMetadata::PROP_DEV_ISVIDEOONLY = "US.Device.VideoOnly"; const char* mitk::USImageMetadata::PROP_PROBE_NAME = "US.Probe.Name"; const char* mitk::USImageMetadata::PROP_PROBE_FREQUENCY = "US.Probe.Frequency"; const char* mitk::USImageMetadata::PROP_ZOOM = "US.Zoom.Factor"; - - +const char* mitk::USImageMetadata::PROP_DEVICE_CLASS = "org.mitk.modules.us.USVideoDevice"; + mitk::USImageMetadata::USImageMetadata() : itk::Object() { // Set Default Values this->SetDeviceComment("None"); this->SetDeviceIsVideoOnly(true); this->SetDeviceManufacturer("Unknown Manufacturer"); this->SetDeviceModel("Unknown Model"); this->SetProbeFrequency("Unknown Frequency"); this->SetProbeName("Unknown Probe"); this->SetZoom("Unknown Zoom Factor"); } mitk::USImageMetadata::~USImageMetadata() { } diff --git a/Modules/US/USModel/mitkUSImageMetadata.h b/Modules/US/USModel/mitkUSImageMetadata.h index b95c0b45ab..69f161014b 100644 --- a/Modules/US/USModel/mitkUSImageMetadata.h +++ b/Modules/US/USModel/mitkUSImageMetadata.h @@ -1,88 +1,93 @@ /*=================================================================== 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. ===================================================================*/ #ifndef MITKUSIMAGEMETADATA_H_HEADER_INCLUDED_ #define MITKUSIMAGEMETADATA_H_HEADER_INCLUDED_ #include #include #include #include namespace mitk { /**Documentation * \brief This class encapsulates all necessary metadata to describe a US Image. * \ingroup US */ class MitkUS_EXPORT USImageMetadata : public itk::Object { public: mitkClassMacro(USImageMetadata, itk::Object); itkNewMacro(Self); //## getter and setter ## itkGetMacro(DeviceManufacturer, std::string); itkSetMacro(DeviceManufacturer, std::string); itkGetMacro(DeviceModel, std::string); itkSetMacro(DeviceModel, std::string); itkGetMacro(DeviceComment, std::string); itkSetMacro(DeviceComment, std::string); itkGetMacro(ProbeName, std::string); itkSetMacro(ProbeName, std::string); itkGetMacro(ProbeFrequency, std::string); itkSetMacro(ProbeFrequency, std::string); itkGetMacro(Zoom, std::string); itkSetMacro(Zoom, std::string); itkGetMacro(DeviceIsVideoOnly, bool); itkSetMacro(DeviceIsVideoOnly, bool); + itkGetMacro(DeviceClass, std::string); + itkSetMacro(DeviceClass, std::string); + // The following constants define how metadata is written to and read from an mitk image // when defining new properties, add them here, define them in the cpp, and add them to // USImage's getMetadata and setMetadata methods as well static const char* PROP_DEV_MANUFACTURER; static const char* PROP_DEV_MODEL; static const char* PROP_DEV_COMMENT; static const char* PROP_DEV_ISVIDEOONLY; static const char* PROP_PROBE_NAME; static const char* PROP_PROBE_FREQUENCY; static const char* PROP_ZOOM; + static const char* PROP_DEVICE_CLASS; protected: /** * \brief Creates a new metadata object with all fields set to default values. */ USImageMetadata(); virtual ~USImageMetadata(); std::string m_DeviceManufacturer; std::string m_DeviceModel; std::string m_DeviceComment; std::string m_ProbeName; std::string m_ProbeFrequency; std::string m_Zoom; + std::string m_DeviceClass; bool m_DeviceIsVideoOnly; }; } // namespace mitk #endif 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 8afd157b3b..fbc327f7cd 100644 --- a/Plugins/org.mitk.gui.qt.ultrasound/src/internal/UltrasoundSupport.cpp +++ b/Plugins/org.mitk.gui.qt.ultrasound/src/internal/UltrasoundSupport.cpp @@ -1,108 +1,120 @@ -/*========================================================================= +/*=================================================================== -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. +The Medical Imaging Interaction Toolkit (MITK) -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. +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. + +===================================================================*/ // 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->SetData(image); + // m_Image->Update(); this->RequestRenderWindowUpdate(); } void UltrasoundSupport::OnClickedViewDevice() { - - MITK_INFO << "USSUPPORT: OnClickedViewDevice()"; - m_Device = m_Controls.m_ActiveVideoDevices->GetSelectedDevice(); - if (m_Device.IsNull()){ + // We use the activity state of the timer to determine whether we are currently viewing images + if ( ! m_Timer->isActive() ) // Activate Imaging + { + m_Device = m_Controls.m_ActiveVideoDevices->GetSelectedDevice(); + // if (m_Node) m_Node->ReleaseData(); + if (m_Device.IsNull()){ + m_Timer->stop(); + return; + } + m_Device->UpdateOutputData(0); + m_Image = m_Device->GetOutput(0); + m_Node->SetData(m_Device->GetOutput(0)); + int interval = (1000 / m_Controls.m_FrameRate->value()); + m_Timer->setInterval(interval); + m_Timer->start(); + m_Controls.m_BtnView->setText("Stop Viewing"); + } + else + { //deactivate Imaging + m_Controls.m_BtnView->setText("Start Viewing"); m_Timer->stop(); - return; + m_Node->ReleaseData(); + this->RequestRenderWindowUpdate(); } - - m_Timer->start(50); } 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 diff --git a/Plugins/org.mitk.gui.qt.ultrasound/src/internal/UltrasoundSupport.h b/Plugins/org.mitk.gui.qt.ultrasound/src/internal/UltrasoundSupport.h index 2ffb46bc06..dd18f29e70 100644 --- a/Plugins/org.mitk.gui.qt.ultrasound/src/internal/UltrasoundSupport.h +++ b/Plugins/org.mitk.gui.qt.ultrasound/src/internal/UltrasoundSupport.h @@ -1,91 +1,92 @@ -/*========================================================================= +/*=================================================================== -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. +The Medical Imaging Interaction Toolkit (MITK) -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. +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. + +===================================================================*/ #ifndef UltrasoundSupport_h #define UltrasoundSupport_h #include #include #include "ui_UltrasoundSupportControls.h" /*! \brief UltrasoundSupport This plugin provides functionality to manage Ultrasound devices, create video devices and to view device images. \sa QmitkFunctionality \ingroup ${plugin_target}_internal */ class UltrasoundSupport : public QmitkAbstractView { // this is needed for all Qt objects that should have a Qt meta-object // (everything that derives from QObject and wants to have signal/slots) Q_OBJECT public: virtual void SetFocus(); static const std::string VIEW_ID; virtual void CreateQtPartControl(QWidget *parent); signals: public slots: /* * \brief This is called when the newDeviceWidget is closed */ void OnNewDeviceWidgetDone(); protected slots: void OnClickedAddNewDevice(); void OnClickedViewDevice(); /* * \brief This is the main imaging loop that is called regularily during the imaging process */ void DisplayImage(); protected: /* * \brief This timer triggers periodic updates to the pipeline */ QTimer *m_Timer; /* * \brief The device that is currently used to quire images */ mitk::USDevice::Pointer m_Device; /* * \brief The node that we feed images into */ mitk::DataNode::Pointer m_Node; + mitk::Image::Pointer m_Image; + Ui::UltrasoundSupportControls m_Controls; }; #endif // UltrasoundSupport_h diff --git a/Plugins/org.mitk.gui.qt.ultrasound/src/internal/UltrasoundSupportControls.ui b/Plugins/org.mitk.gui.qt.ultrasound/src/internal/UltrasoundSupportControls.ui index 7a96cde657..ae8c41b15f 100644 --- a/Plugins/org.mitk.gui.qt.ultrasound/src/internal/UltrasoundSupportControls.ui +++ b/Plugins/org.mitk.gui.qt.ultrasound/src/internal/UltrasoundSupportControls.ui @@ -1,143 +1,186 @@ UltrasoundSupportControls 0 0 467 461 0 0 QmitkTemplate - 1 + 0 Device Management 12 75 true Connected Devices: New Device Qt::Vertical 20 40 US Imaging - - - QFormLayout::AllNonFixedFieldsGrow - - + + 12 75 true - Active Video Devices: + Active Ultrasound Devices: - + 0 0 - + - View + Start Viewing + + + + + 75 + true + + + + Framerate: + + + + + + + 1 + + + 50 + + + 30 + + + + + + + (Restart viewing to make changes effective) + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + QmitkUSDeviceManagerWidget QWidget
QmitkUSDeviceManagerWidget.h
1
QmitkUSNewVideoDeviceWidget QWidget
QmitkUSNewVideoDeviceWidget.h
1
QmitkUSDeviceListWidget QWidget
QmitkUSDeviceListWidget.h
1
diff --git a/Plugins/org.mitk.gui.qt.ultrasound/src/internal/org_mitk_gui_qt_ultrasound_Activator.cpp b/Plugins/org.mitk.gui.qt.ultrasound/src/internal/org_mitk_gui_qt_ultrasound_Activator.cpp index b77473cc4d..62e01948a7 100644 --- a/Plugins/org.mitk.gui.qt.ultrasound/src/internal/org_mitk_gui_qt_ultrasound_Activator.cpp +++ b/Plugins/org.mitk.gui.qt.ultrasound/src/internal/org_mitk_gui_qt_ultrasound_Activator.cpp @@ -1,39 +1,38 @@ -/*========================================================================= - -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. - -=========================================================================*/ +/*=================================================================== + +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. + +===================================================================*/ #include "org_mitk_gui_qt_ultrasound_Activator.h" #include #include "UltrasoundSupport.h" namespace mitk { void org_mitk_gui_qt_ultrasound_Activator::start(ctkPluginContext* context) { BERRY_REGISTER_EXTENSION_CLASS(UltrasoundSupport, context) } void org_mitk_gui_qt_ultrasound_Activator::stop(ctkPluginContext* context) { Q_UNUSED(context) } } Q_EXPORT_PLUGIN2(org_mitk_gui_qt_ultrasound, mitk::org_mitk_gui_qt_ultrasound_Activator) diff --git a/Plugins/org.mitk.gui.qt.ultrasound/src/internal/org_mitk_gui_qt_ultrasound_Activator.h b/Plugins/org.mitk.gui.qt.ultrasound/src/internal/org_mitk_gui_qt_ultrasound_Activator.h index 2bd3b8741e..fb4c11a908 100644 --- a/Plugins/org.mitk.gui.qt.ultrasound/src/internal/org_mitk_gui_qt_ultrasound_Activator.h +++ b/Plugins/org.mitk.gui.qt.ultrasound/src/internal/org_mitk_gui_qt_ultrasound_Activator.h @@ -1,41 +1,40 @@ -/*========================================================================= - -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. - -=========================================================================*/ +/*=================================================================== + +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. + +===================================================================*/ #ifndef org_mitk_gui_qt_ultrasound_Activator_h #define org_mitk_gui_qt_ultrasound_Activator_h #include namespace mitk { class org_mitk_gui_qt_ultrasound_Activator : public QObject, public ctkPluginActivator { Q_OBJECT Q_INTERFACES(ctkPluginActivator) public: void start(ctkPluginContext* context); void stop(ctkPluginContext* context); }; // org_mitk_gui_qt_ultrasound_Activator } #endif // org_mitk_gui_qt_ultrasound_Activator_h