diff --git a/Modules/US/USHardwareTelemed/mitkUSTelemedImageSource.cpp b/Modules/US/USHardwareTelemed/mitkUSTelemedImageSource.cpp index 1d6c97c287..2fb6db6714 100644 --- a/Modules/US/USHardwareTelemed/mitkUSTelemedImageSource.cpp +++ b/Modules/US/USHardwareTelemed/mitkUSTelemedImageSource.cpp @@ -1,85 +1,141 @@ /*=================================================================== 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 "mitkUSTelemedImageSource.h" #include "mitkUSTelemedSDKHeader.h" #include "MITKUSTelemedScanConverterPlugin.h" #include "mitkImageReadAccessor.h" mitk::USTelemedImageSource::USTelemedImageSource( ) : m_Image(mitk::Image::New()), m_ImageMutex(itk::FastMutexLock::New()), m_Plugin(0), - m_PluginCallback(0) + m_PluginCallback(0), + m_UsgDataView(0), + m_ImageProperties(0), + m_DepthProperties(0), + m_upDateCounter(0) { } mitk::USTelemedImageSource::~USTelemedImageSource( ) { SAFE_RELEASE(m_PluginCallback); SAFE_RELEASE(m_Plugin); + SAFE_RELEASE(m_ImageProperties); + SAFE_RELEASE(m_DepthProperties); } void mitk::USTelemedImageSource::GetNextRawImage( mitk::Image::Pointer& image) { if ( image.IsNull() ) { image = mitk::Image::New(); } + + //if depth changed: update geometry, but 20 frames after the change because it takes this time until geometry adapts + if (m_upDateCounter==20 && m_Image->IsInitialized()) + { + UpdateImageGeometry(); + m_upDateCounter++; + } + if (m_OldDepth != m_DepthProperties->Current) + { + m_upDateCounter=0; + m_OldDepth = m_DepthProperties->GetCurrent(); + } + if (m_upDateCounter<20) m_upDateCounter++; + + //now update image if ( m_Image->IsInitialized() ) { m_ImageMutex->Lock(); // copy contents of the given image into the member variable image->Initialize(m_Image->GetPixelType(), m_Image->GetDimension(), m_Image->GetDimensions()); mitk::ImageReadAccessor inputReadAccessor(m_Image, m_Image->GetSliceData(0,0,0)); image->SetSlice(inputReadAccessor.GetData()); + image->SetGeometry(m_Image->GetGeometry()); m_ImageMutex->Unlock(); } + +} + +void mitk::USTelemedImageSource::UpdateImageGeometry() +{ + Usgfw2Lib::tagPixelsOrigin origin = Usgfw2Lib::tagPixelsOrigin(); + Usgfw2Lib::tagImageResolution resolutionInMeters; + m_ImageProperties->GetResolution(&resolutionInMeters,0); + + mitk::Vector3D spacing; + spacing[0] = ((double)1 / resolutionInMeters.nXPelsPerUnit) * 1000; //conversion: meters to millimeters + spacing[1] = ((double)1 / resolutionInMeters.nXPelsPerUnit) * 1000; //conversion: meters to millimeters + spacing[2] = 1; + + m_ImageMutex->Lock(); + if(m_Image.IsNotNull() && (m_Image->GetGeometry()!=NULL)) + { + m_Image->GetGeometry()->SetSpacing(spacing); + m_Image->GetGeometry()->Modified(); + } + else + {MITK_WARN << "image or geometry was NULL, can't adapt geometry";} + m_ImageMutex->Unlock(); + + MITK_DEBUG << "UpdateImageGeometry called!"; + MITK_DEBUG << "depth: " << m_DepthProperties->GetCurrent(); + MITK_DEBUG << "new spacing: " << spacing; } bool mitk::USTelemedImageSource::CreateAndConnectConverterPlugin(Usgfw2Lib::IUsgDataView* usgDataView, Usgfw2Lib::tagScanMode scanMode) { IUnknown* tmp_obj = NULL; // create control object from Telemed API mitk::telemed::CreateUsgControl( usgDataView, Usgfw2Lib::IID_IUsgScanConverterPlugin, scanMode, 0, (void**)&tmp_obj ); if ( ! tmp_obj ) { MITK_ERROR("USImageSource")("USTelemedImageSource") << "Could not create scan converter plugin."; return false; } // create the callback object for the scan conversion if ( ! m_PluginCallback ) { m_PluginCallback = new USTelemedScanConverterPlugin(); // current image buffer should be copied to m_Image at every callback m_PluginCallback->SetOutputImage(m_Image.GetPointer(), m_ImageMutex); } else { // make sure that the scan converter plugin is not set // to the plugin callback any longer m_PluginCallback->SetScanConverterPlugin(0); } // now the ScanConverterPlugin can be created and set as plugin SAFE_RELEASE(m_Plugin); m_Plugin = (Usgfw2Lib::IUsgScanConverterPlugin*)tmp_obj; m_PluginCallback->SetScanConverterPlugin(m_Plugin); + //last: create some connections which are needed inside this class for communication with the telemed device + m_UsgDataView = usgDataView; + + // create telemed controls + if (!m_DepthProperties) {CREATE_TelemedControl(m_DepthProperties, m_UsgDataView, Usgfw2Lib::IID_IUsgDepth, Usgfw2Lib::IUsgDepth, Usgfw2Lib::SCAN_MODE_B);} + if (!m_ImageProperties) {CREATE_TelemedControl(m_ImageProperties, m_UsgDataView, Usgfw2Lib::IID_IUsgImageProperties, Usgfw2Lib::IUsgImageProperties, Usgfw2Lib::SCAN_MODE_B);} + return true; } \ No newline at end of file diff --git a/Modules/US/USHardwareTelemed/mitkUSTelemedImageSource.h b/Modules/US/USHardwareTelemed/mitkUSTelemedImageSource.h index e6f9dde4f0..2961df65d0 100644 --- a/Modules/US/USHardwareTelemed/mitkUSTelemedImageSource.h +++ b/Modules/US/USHardwareTelemed/mitkUSTelemedImageSource.h @@ -1,67 +1,83 @@ /*=================================================================== 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 MITKUSTelemedImageSource_H_HEADER_INCLUDED_ #define MITKUSTelemedImageSource_H_HEADER_INCLUDED_ #include "mitkUSImageSource.h" #include "mitkUSTelemedSDKHeader.h" #include "mitkUSTelemedScanConverterPlugin.h" #include "itkFastMutexLock.h" namespace mitk { /** * \brief Implementation of mitk::USImageSource for Telemed API devices. * The method mitk::USImageSource::GetNextRawImage() is implemented for * getting images from the Telemed API. * * A method for connecting this ImageSource to the Telemed API is * implemented (mitk::USTelemedImageSource::CreateAndConnectConverterPlugin()). * This method is available for being used by mitk::USTelemedDevice. */ class USTelemedImageSource : public USImageSource { public: mitkClassMacro(USTelemedImageSource, USImageSource); itkFactorylessNewMacro(Self) itkCloneMacro(Self) /** * Implementation of the superclass method. Returns the pointer * to the mitk::Image filled by Telemed API callback. */ virtual void GetNextRawImage( mitk::Image::Pointer& ); + /** + * Updates the geometry of the current image from the API. + * Is used internally when a new image is initialized, but + * also needs to be called if, e.g., the zoom factor is changed. + */ + void UpdateImageGeometry(); + /** * \brief Connect this object to the Telemed API. * This method is for being used by mitk::USTelemedDevice. */ bool CreateAndConnectConverterPlugin( Usgfw2Lib::IUsgDataView*, Usgfw2Lib::tagScanMode ); protected: USTelemedImageSource( ); virtual ~USTelemedImageSource( ); Usgfw2Lib::IUsgScanConverterPlugin* m_Plugin; USTelemedScanConverterPlugin* m_PluginCallback; + Usgfw2Lib::IUsgDataView* m_UsgDataView; // main SDK object for comminucating with the Telemed API + + //API objects for communication, used to get the right geometry + Usgfw2Lib::IUsgImageProperties* m_ImageProperties; + Usgfw2Lib::IUsgDepth* m_DepthProperties; + double m_OldDepth; + int m_upDateCounter; + + mitk::Image::Pointer m_Image; itk::FastMutexLock::Pointer m_ImageMutex; }; } // namespace mitk #endif // MITKUSTelemedImageSource_H diff --git a/Modules/US/USModel/mitkUSDevice.cpp b/Modules/US/USModel/mitkUSDevice.cpp index a5ef150a61..1bfca80e85 100644 --- a/Modules/US/USModel/mitkUSDevice.cpp +++ b/Modules/US/USModel/mitkUSDevice.cpp @@ -1,559 +1,561 @@ /*=================================================================== 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 "mitkImageReadAccessor.h" // US Control Interfaces #include "mitkUSControlInterfaceProbes.h" #include "mitkUSControlInterfaceBMode.h" #include "mitkUSControlInterfaceDoppler.h" // Microservices #include #include #include #include mitk::USDevice::PropertyKeys mitk::USDevice::GetPropertyKeys() { static mitk::USDevice::PropertyKeys propertyKeys; return propertyKeys; } mitk::USDevice::USImageCropArea mitk::USDevice::GetCropArea() { MITK_INFO << "Return Crop Area L:" << m_CropArea.cropLeft << " R:" << m_CropArea.cropRight << " T:" << m_CropArea.cropTop << " B:" << m_CropArea.cropBottom; return m_CropArea; } mitk::USDevice::USDevice(std::string manufacturer, std::string model) : mitk::ImageSource(), m_IsFreezed(false), m_DeviceState(State_NoState), m_Manufacturer(manufacturer), m_Name(model), m_SpawnAcquireThread(true), m_MultiThreader(itk::MultiThreader::New()), m_ImageMutex(itk::FastMutexLock::New()), m_ThreadID(-1), m_UnregisteringStarted(false) { USImageCropArea empty; empty.cropBottom = 0; empty.cropTop = 0; empty.cropLeft = 0; empty.cropRight = 0; this->m_CropArea = empty; //set number of outputs this->SetNumberOfIndexedOutputs(1); //create a new output mitk::Image::Pointer newOutput = mitk::Image::New(); this->SetNthOutput(0,newOutput); } mitk::USDevice::USDevice(mitk::USImageMetadata::Pointer metadata) : mitk::ImageSource(), m_IsFreezed(false), m_DeviceState(State_NoState), m_SpawnAcquireThread(true), m_MultiThreader(itk::MultiThreader::New()), m_ImageMutex(itk::FastMutexLock::New()), m_ThreadID(-1), m_UnregisteringStarted(false) { m_Manufacturer = metadata->GetDeviceManufacturer(); m_Name = metadata->GetDeviceModel(); m_Comment = metadata->GetDeviceComment(); USImageCropArea empty; empty.cropBottom = 0; empty.cropTop = 0; empty.cropLeft = 0; empty.cropRight = 0; this->m_CropArea = empty; //set number of outputs this->SetNumberOfIndexedOutputs(1); //create a new output mitk::Image::Pointer newOutput = mitk::Image::New(); this->SetNthOutput(0,newOutput); } mitk::USDevice::~USDevice() { if (m_ThreadID >= 0) { m_MultiThreader->TerminateThread(m_ThreadID); } // make sure that the us device is not registered at the micro service // anymore after it is destructed this->UnregisterOnService(); } mitk::USAbstractControlInterface::Pointer mitk::USDevice::GetControlInterfaceCustom() { MITK_INFO << "Custom control interface does not exist for this object."; return 0; } mitk::USControlInterfaceBMode::Pointer mitk::USDevice::GetControlInterfaceBMode() { MITK_INFO << "Control interface BMode does not exist for this object."; return 0; } mitk::USControlInterfaceProbes::Pointer mitk::USDevice::GetControlInterfaceProbes() { MITK_INFO << "Control interface Probes does not exist for this object."; return 0; } mitk::USControlInterfaceDoppler::Pointer mitk::USDevice::GetControlInterfaceDoppler() { MITK_INFO << "Control interface Doppler does not exist for this object."; return 0; } void mitk::USDevice::SetManufacturer(std::string manufacturer) { m_Manufacturer = manufacturer; if ( m_DeviceState >= State_Initialized ) { this->UpdateServiceProperty(mitk::USDevice::GetPropertyKeys().US_PROPKEY_MANUFACTURER, manufacturer); } } void mitk::USDevice::SetName(std::string name) { m_Name = name; if ( m_DeviceState >= State_Initialized ) { this->UpdateServiceProperty(mitk::USDevice::GetPropertyKeys().US_PROPKEY_NAME, name); } } void mitk::USDevice::SetComment(std::string comment) { m_Comment = comment; if ( m_DeviceState >= State_Initialized ) { this->UpdateServiceProperty(mitk::USDevice::GetPropertyKeys().US_PROPKEY_COMMENT, comment); } } us::ServiceProperties mitk::USDevice::ConstructServiceProperties() { mitk::USDevice::PropertyKeys propertyKeys = mitk::USDevice::GetPropertyKeys(); us::ServiceProperties props; props[propertyKeys.US_PROPKEY_ISCONNECTED] = this->GetIsConnected() ? "true" : "false"; props[propertyKeys.US_PROPKEY_ISACTIVE] = this->GetIsActive() ? "true" : "false"; props[propertyKeys.US_PROPKEY_LABEL] = this->GetServicePropertyLabel(); // get identifier of selected probe if there is one selected mitk::USControlInterfaceProbes::Pointer probesControls = this->GetControlInterfaceProbes(); if (probesControls.IsNotNull() && probesControls->GetIsActive()) { mitk::USProbe::Pointer probe = probesControls->GetSelectedProbe(); if (probe.IsNotNull()) { props[propertyKeys.US_PROPKEY_PROBES_SELECTED] = probe->GetName(); } } props[ propertyKeys.US_PROPKEY_CLASS ] = GetDeviceClass(); props[ propertyKeys.US_PROPKEY_MANUFACTURER ] = m_Manufacturer; props[ propertyKeys.US_PROPKEY_NAME ] = m_Name; props[ propertyKeys.US_PROPKEY_COMMENT ] = m_Comment; m_ServiceProperties = props; return props; } void mitk::USDevice::UnregisterOnService() { // unregister on micro service if ( m_ServiceRegistration && ! m_UnregisteringStarted) { // make sure that unregister is not started a second // time due to a callback during unregister for example m_UnregisteringStarted = true; m_ServiceRegistration.Unregister(); m_ServiceRegistration = 0; } } bool mitk::USDevice::Initialize() { if (! this->OnInitialization() ) { return false; } m_DeviceState = State_Initialized; // Get Context and Module us::ModuleContext* context = us::GetModuleContext(); us::ServiceProperties props = this->ConstructServiceProperties(); m_ServiceRegistration = context->RegisterService(this, props); return true; } bool mitk::USDevice::Connect() { if ( this->GetIsConnected() ) { MITK_INFO("mitkUSDevice") << "Tried to connect an ultrasound device that was already connected. Ignoring call..."; return true; } if ( ! this->GetIsInitialized() ) { MITK_ERROR("mitkUSDevice") << "Cannot connect device if it is not in initialized state."; return false; } // Prepare connection, fail if this fails. if ( ! this->OnConnection() ) { return false; } // Update state m_DeviceState = State_Connected; this->UpdateServiceProperty(mitk::USDevice::GetPropertyKeys().US_PROPKEY_ISCONNECTED, true); return true; } void mitk::USDevice::ConnectAsynchron() { this->m_MultiThreader->SpawnThread(this->ConnectThread, this); } bool mitk::USDevice::Disconnect() { if ( ! GetIsConnected()) { MITK_WARN << "Tried to disconnect an ultrasound device that was not connected. Ignoring call..."; return false; } // Prepare connection, fail if this fails. if (! this->OnDisconnection()) return false; // Update state m_DeviceState = State_Initialized; this->UpdateServiceProperty(mitk::USDevice::GetPropertyKeys().US_PROPKEY_ISCONNECTED, false); return true; } bool mitk::USDevice::Activate() { if (! this->GetIsConnected()) { MITK_INFO("mitkUSDevice") << "Cannot activate device if it is not in connected state."; return true; } if ( OnActivation() ) { m_DeviceState = State_Activated; m_FreezeBarrier = itk::ConditionVariable::New(); // spawn thread for aquire images if us device is active if (m_SpawnAcquireThread) { this->m_ThreadID = this->m_MultiThreader->SpawnThread(this->Acquire, this); } this->UpdateServiceProperty(mitk::USDevice::GetPropertyKeys().US_PROPKEY_ISACTIVE, true); this->UpdateServiceProperty(mitk::USDevice::GetPropertyKeys().US_PROPKEY_LABEL, this->GetServicePropertyLabel()); // initialize the b mode control properties of the micro service mitk::USControlInterfaceBMode::Pointer bmodeControls = this->GetControlInterfaceBMode(); if ( bmodeControls.IsNotNull() ) { bmodeControls->Initialize(); } } return m_DeviceState == State_Activated; } void mitk::USDevice::Deactivate() { if ( ! this->GetIsActive() ) { MITK_WARN("mitkUSDevice") << "Cannot deactivate a device which is not activae."; return; } if ( ! OnDeactivation() ) { return; } m_DeviceState = State_Connected; this->UpdateServiceProperty(mitk::USDevice::GetPropertyKeys().US_PROPKEY_ISACTIVE, false); this->UpdateServiceProperty(mitk::USDevice::GetPropertyKeys().US_PROPKEY_LABEL, this->GetServicePropertyLabel()); } void mitk::USDevice::SetIsFreezed(bool freeze) { if ( ! this->GetIsActive() ) { MITK_WARN("mitkUSDevice") << "Cannot freeze or unfreeze if device is not active."; return; } this->OnFreeze(freeze); if ( freeze ) { m_IsFreezed = true; } else { m_IsFreezed = false; // wake up the image acquisition thread m_FreezeBarrier->Signal(); } } bool mitk::USDevice::GetIsFreezed() { if ( ! this->GetIsActive() ) { MITK_WARN("mitkUSDevice")("mitkUSTelemedDevice") << "Cannot get freeze state if the hardware interface is not ready. Returning false..."; return false; } return m_IsFreezed; } void mitk::USDevice::PushFilter(AbstractOpenCVImageFilter::Pointer filter) { mitk::USImageSource::Pointer imageSource = this->GetUSImageSource(); if ( imageSource.IsNull() ) { MITK_ERROR << "ImageSource must not be null when pushing a filter."; mitkThrow() << "ImageSource must not be null when pushing a filter."; } imageSource->PushFilter(filter); } void mitk::USDevice::PushFilterIfNotPushedBefore(AbstractOpenCVImageFilter::Pointer filter) { mitk::USImageSource::Pointer imageSource = this->GetUSImageSource(); if ( imageSource.IsNull() ) { MITK_ERROR << "ImageSource must not be null when pushing a filter."; mitkThrow() << "ImageSource must not be null when pushing a filter."; } if ( ! imageSource->GetIsFilterInThePipeline(filter) ) { imageSource->PushFilter(filter); } } bool mitk::USDevice::RemoveFilter(AbstractOpenCVImageFilter::Pointer filter) { mitk::USImageSource::Pointer imageSource = this->GetUSImageSource(); if ( imageSource.IsNull() ) { MITK_ERROR << "ImageSource must not be null when pushing a filter."; mitkThrow() << "ImageSource must not be null when removing a filter."; } return imageSource->RemoveFilter(filter); } void mitk::USDevice::UpdateServiceProperty(std::string key, std::string value) { m_ServiceProperties[ key ] = value; m_ServiceRegistration.SetProperties(m_ServiceProperties); // send event to notify listeners about the changed property m_PropertyChangedMessage(key, value); } void mitk::USDevice::UpdateServiceProperty(std::string key, double value) { std::stringstream stream; stream << value; this->UpdateServiceProperty(key, stream.str()); } void mitk::USDevice::UpdateServiceProperty(std::string key, bool value) { this->UpdateServiceProperty(key, value ? std::string("true") : std::string("false")); } /** mitk::Image* mitk::USDevice::GetOutput() { if (this->GetNumberOfOutputs() < 1) return NULL; return static_cast(this->ProcessObject::GetPrimaryOutput()); } mitk::Image* 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 ); } */ void mitk::USDevice::GrabImage() { mitk::Image::Pointer image = this->GetUSImageSource()->GetNextImage(); m_ImageMutex->Lock(); this->SetImage(image); m_ImageMutex->Unlock(); + //if (image.IsNotNull() && (image->GetGeometry()!=NULL)){ + // MITK_INFO << "Spacing: " << image->GetGeometry()->GetSpacing();} } //########### GETTER & SETTER ##################// bool mitk::USDevice::GetIsInitialized() { return m_DeviceState == State_Initialized; } bool mitk::USDevice::GetIsActive() { return m_DeviceState == State_Activated; } bool mitk::USDevice::GetIsConnected() { return m_DeviceState == State_Connected; } std::string mitk::USDevice::GetDeviceManufacturer(){ return m_Manufacturer; } std::string mitk::USDevice::GetDeviceModel(){ return m_Name; } std::string mitk::USDevice::GetDeviceComment(){ return m_Comment; } void mitk::USDevice::GenerateData() { m_ImageMutex->Lock(); if ( m_Image.IsNull() || ! m_Image->IsInitialized() ) { m_ImageMutex->Unlock(); return; } mitk::Image::Pointer output = this->GetOutput(); if ( ! output->IsInitialized() || output->GetDimension(0) != m_Image->GetDimension(0) || output->GetDimension(1) != m_Image->GetDimension(1) ) { output->Initialize(m_Image->GetPixelType(), m_Image->GetDimension(), m_Image->GetDimensions()); } mitk::ImageReadAccessor inputReadAccessor(m_Image, m_Image->GetSliceData(0,0,0)); output->SetSlice(inputReadAccessor.GetData()); - + output->SetGeometry(m_Image->GetGeometry()); m_ImageMutex->Unlock(); }; std::string mitk::USDevice::GetServicePropertyLabel() { std::string isActive; if (this->GetIsActive()) { isActive = " (Active)"; } else { isActive = " (Inactive)"; } // e.g.: Zonare MyLab5 (Active) return m_Manufacturer + " " + m_Name + isActive; } ITK_THREAD_RETURN_TYPE mitk::USDevice::Acquire(void* pInfoStruct) { /* extract this pointer from Thread Info structure */ struct itk::MultiThreader::ThreadInfoStruct * pInfo = (struct itk::MultiThreader::ThreadInfoStruct*)pInfoStruct; mitk::USDevice* device = (mitk::USDevice*) pInfo->UserData; while (device->GetIsActive()) { // lock this thread when ultrasound device is freezed if ( device->m_IsFreezed ) { itk::SimpleMutexLock* mutex = &(device->m_FreezeMutex); mutex->Lock(); if (device->m_FreezeBarrier.IsNotNull()) { device->m_FreezeBarrier->Wait(mutex); } } device->GrabImage(); } return ITK_THREAD_RETURN_VALUE; } ITK_THREAD_RETURN_TYPE mitk::USDevice::ConnectThread(void* pInfoStruct) { /* extract this pointer from Thread Info structure */ struct itk::MultiThreader::ThreadInfoStruct * pInfo = (struct itk::MultiThreader::ThreadInfoStruct*)pInfoStruct; mitk::USDevice* device = (mitk::USDevice*) pInfo->UserData; device->Connect(); return ITK_THREAD_RETURN_VALUE; } 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 18df30ce2c..aed540e70b 100644 --- a/Plugins/org.mitk.gui.qt.ultrasound/src/internal/UltrasoundSupport.cpp +++ b/Plugins/org.mitk.gui.qt.ultrasound/src/internal/UltrasoundSupport.cpp @@ -1,338 +1,351 @@ /*=================================================================== 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. ===================================================================*/ // Blueberry #include #include //Mitk #include #include #include #include #include // Qmitk #include "UltrasoundSupport.h" #include // Qt #include // Ultrasound #include "mitkUSDevice.h" #include "QmitkUSAbstractCustomWidget.h" #include #include #include "usServiceReference.h" #include "internal/org_mitk_gui_qt_ultrasound_Activator.h" const std::string UltrasoundSupport::VIEW_ID = "org.mitk.views.ultrasoundsupport"; void UltrasoundSupport::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_DeviceManagerWidget, SIGNAL(NewDeviceButtonClicked()), this, SLOT(OnClickedAddNewDevice()) ); // Change Widget Visibilities - connect( m_Controls.m_DeviceManagerWidget, SIGNAL(NewDeviceButtonClicked()), this->m_Controls.m_NewVideoDeviceWidget, SLOT(CreateNewDevice()) ); // Init NewDeviceWidget - connect( m_Controls.m_ActiveVideoDevices, SIGNAL(ServiceSelectionChanged(us::ServiceReferenceU)), this, SLOT(OnChangedActiveDevice()) ); - connect( m_Controls.m_ShowImageStream, SIGNAL(clicked()), this, SLOT(OnChangedActiveDevice()) ); - connect( m_Controls.m_NewVideoDeviceWidget, SIGNAL(Finished()), this, SLOT(OnNewDeviceWidgetDone()) ); // After NewDeviceWidget finished editing - connect( m_Controls.m_FrameRate, SIGNAL(valueChanged(int)), this, SLOT(OnChangedFramerateLimit(int)) ); - connect( m_Controls.m_FreezeButton, SIGNAL(clicked()), this, SLOT(OnClickedFreezeButton()) ); - connect( m_Timer, SIGNAL(timeout()), this, SLOT(DisplayImage())); - - // Initializations - m_Controls.m_NewVideoDeviceWidget->setVisible(false); - std::string filter = "(&(" + us::ServiceConstants::OBJECTCLASS() + "=" - + "org.mitk.services.UltrasoundDevice)(" - + mitk::USDevice::GetPropertyKeys().US_PROPKEY_ISACTIVE + "=true))"; - m_Controls.m_ActiveVideoDevices->Initialize( - mitk::USDevice::GetPropertyKeys().US_PROPKEY_LABEL ,filter); - m_Controls.m_ActiveVideoDevices->SetAutomaticallySelectFirstEntry(true); - - // Create Node for US Stream - if (m_Node.IsNull()) - { - m_Node = mitk::DataNode::New(); - m_Node->SetName("US Support Viewing Stream"); - //create a dummy image (gray values 0..255) for correct initialization of level window, etc. - mitk::Image::Pointer dummyImage = mitk::ImageGenerator::GenerateRandomImage(100, 100, 1, 1, 1, 1, 1, 255,0); - m_Node->SetData(dummyImage); - } +m_Timer = new QTimer(this); + +// create GUI widgets from the Qt Designer's .ui file +m_Controls.setupUi( parent ); + +connect( m_Controls.m_DeviceManagerWidget, SIGNAL(NewDeviceButtonClicked()), this, SLOT(OnClickedAddNewDevice()) ); // Change Widget Visibilities +connect( m_Controls.m_DeviceManagerWidget, SIGNAL(NewDeviceButtonClicked()), this->m_Controls.m_NewVideoDeviceWidget, SLOT(CreateNewDevice()) ); // Init NewDeviceWidget +connect( m_Controls.m_ActiveVideoDevices, SIGNAL(ServiceSelectionChanged(us::ServiceReferenceU)), this, SLOT(OnChangedActiveDevice()) ); +connect( m_Controls.m_ShowImageStream, SIGNAL(clicked()), this, SLOT(OnChangedActiveDevice()) ); +connect( m_Controls.m_NewVideoDeviceWidget, SIGNAL(Finished()), this, SLOT(OnNewDeviceWidgetDone()) ); // After NewDeviceWidget finished editing +connect( m_Controls.m_FrameRate, SIGNAL(valueChanged(int)), this, SLOT(OnChangedFramerateLimit(int)) ); +connect( m_Controls.m_FreezeButton, SIGNAL(clicked()), this, SLOT(OnClickedFreezeButton()) ); +connect( m_Timer, SIGNAL(timeout()), this, SLOT(DisplayImage())); + +// Initializations +m_Controls.m_NewVideoDeviceWidget->setVisible(false); +std::string filter = "(&(" + us::ServiceConstants::OBJECTCLASS() + "=" ++ "org.mitk.services.UltrasoundDevice)(" ++ mitk::USDevice::GetPropertyKeys().US_PROPKEY_ISACTIVE + "=true))"; +m_Controls.m_ActiveVideoDevices->Initialize( +mitk::USDevice::GetPropertyKeys().US_PROPKEY_LABEL ,filter); +m_Controls.m_ActiveVideoDevices->SetAutomaticallySelectFirstEntry(true); + +// Create Node for US Stream +if (m_Node.IsNull()) +{ +m_Node = mitk::DataNode::New(); +m_Node->SetName("US Support Viewing Stream"); +//create a dummy image (gray values 0..255) for correct initialization of level window, etc. +mitk::Image::Pointer dummyImage = mitk::ImageGenerator::GenerateRandomImage(100, 100, 1, 1, 1, 1, 1, 255,0); +m_Node->SetData(dummyImage); +m_OldGeometry = dummyImage->GetGeometry(); +} - m_Controls.tabWidget->setTabEnabled(1, false); +m_Controls.tabWidget->setTabEnabled(1, false); } void UltrasoundSupport::OnClickedAddNewDevice() { - m_Controls.m_NewVideoDeviceWidget->setVisible(true); - m_Controls.m_DeviceManagerWidget->setVisible(false); - m_Controls.m_Headline->setText("Add New Video Device:"); - m_Controls.m_WidgetActiveDevices->setVisible(false); +m_Controls.m_NewVideoDeviceWidget->setVisible(true); +m_Controls.m_DeviceManagerWidget->setVisible(false); +m_Controls.m_Headline->setText("Add New Video Device:"); +m_Controls.m_WidgetActiveDevices->setVisible(false); } void UltrasoundSupport::DisplayImage() { - //Update device - m_Device->Modified(); - m_Device->Update(); +//Update device +m_Device->Modified(); +m_Device->Update(); - //Update data node - mitk::Image::Pointer curOutput = m_Device->GetOutput(); - m_Node->SetData(curOutput); +//Update data node +mitk::Image::Pointer curOutput = m_Device->GetOutput(); +m_Node->SetData(curOutput); - //Only update the view if the image is shown - if(m_Controls.m_ShowImageStream->isChecked()) - { - this->RequestRenderWindowUpdate(); - if ( curOutput->GetDimension() > 1 - && (curOutput->GetDimension(0) != m_CurrentImageWidth - || curOutput->GetDimension(1) != m_CurrentImageHeight) ) - { - // make a reinit on the ultrasound image - mitk::IRenderWindowPart* renderWindow = this->GetRenderWindowPart(); - if ( renderWindow != NULL && curOutput->GetTimeGeometry()->IsValid() ) - { - renderWindow->GetRenderingManager()->InitializeViews( - curOutput->GetTimeGeometry(), mitk::RenderingManager::REQUEST_UPDATE_ALL, true ); - renderWindow->GetRenderingManager()->RequestUpdateAll(); - } - - m_CurrentImageWidth = curOutput->GetDimension(0); - m_CurrentImageHeight = curOutput->GetDimension(1); - } - } +// if the geometry changed: make a reinit on the ultrasound image +if(!mitk::Equal(m_OldGeometry.GetPointer(),curOutput->GetGeometry(),0.0001,false)) +{ +mitk::IRenderWindowPart* renderWindow = this->GetRenderWindowPart(); +if ( renderWindow != NULL && curOutput->GetTimeGeometry()->IsValid() ) +{ +renderWindow->GetRenderingManager()->InitializeViews( +curOutput->GetGeometry(), mitk::RenderingManager::REQUEST_UPDATE_ALL, true ); +renderWindow->GetRenderingManager()->RequestUpdateAll(); +} +m_OldGeometry = curOutput->GetGeometry(); +} - //Update frame counter - m_FrameCounter ++; - if (m_FrameCounter == 10) - { - int nMilliseconds = m_Clock.restart(); - int fps = 10000.0f / (nMilliseconds ); - m_Controls.m_FramerateLabel->setText("Current Framerate: "+ QString::number(fps) +" FPS"); - m_FrameCounter = 0; - } +//Only update the view if the image is shown +if(m_Controls.m_ShowImageStream->isChecked()) +{ +this->RequestRenderWindowUpdate(); +if ( curOutput->GetDimension() > 1 +&& (curOutput->GetDimension(0) != m_CurrentImageWidth +|| curOutput->GetDimension(1) != m_CurrentImageHeight) ) +{ +// make a reinit on the ultrasound image +mitk::IRenderWindowPart* renderWindow = this->GetRenderWindowPart(); +if ( renderWindow != NULL && curOutput->GetTimeGeometry()->IsValid() ) +{ +renderWindow->GetRenderingManager()->InitializeViews( +curOutput->GetTimeGeometry(), mitk::RenderingManager::REQUEST_UPDATE_ALL, true ); +renderWindow->GetRenderingManager()->RequestUpdateAll(); +} + +m_CurrentImageWidth = curOutput->GetDimension(0); +m_CurrentImageHeight = curOutput->GetDimension(1); +} +} + +//Update frame counter +m_FrameCounter ++; +if (m_FrameCounter == 10) +{ +int nMilliseconds = m_Clock.restart(); +int fps = 10000.0f / (nMilliseconds ); +m_Controls.m_FramerateLabel->setText("Current Framerate: "+ QString::number(fps) +" FPS"); +m_FrameCounter = 0; +} } void UltrasoundSupport::OnChangedFramerateLimit(int value) { - m_Timer->setInterval(1000 / value); +m_Timer->setInterval(1000 / value); } void UltrasoundSupport::OnClickedFreezeButton() { if ( m_Device.IsNull() ) { MITK_WARN("UltrasoundSupport") << "Freeze button clicked though no device is selected."; return; } - - if ( m_Device->GetIsFreezed() ) - { - m_Device->SetIsFreezed(false); - m_Controls.m_FreezeButton->setText("Freeze"); - } - else - { - m_Device->SetIsFreezed(true); - m_Controls.m_FreezeButton->setText("Start Viewing Again"); - } +if ( m_Device->GetIsFreezed() ) +{ +m_Device->SetIsFreezed(false); +m_Controls.m_FreezeButton->setText("Freeze"); +} +else +{ +m_Device->SetIsFreezed(true); +m_Controls.m_FreezeButton->setText("Start Viewing Again"); +} } void UltrasoundSupport::OnChangedActiveDevice() { //clean up and stop timer m_Timer->stop(); this->RemoveControlWidgets(); this->GetDataStorage()->Remove(m_Node); m_Node->ReleaseData(); //get current device, abort if it is invalid m_Device = m_Controls.m_ActiveVideoDevices->GetSelectedService(); if (m_Device.IsNull()) - { - MITK_WARN << "Selected device is not valid, aborting"; - m_Controls.tabWidget->setTabEnabled(1, false); - return; - } +{ +MITK_WARN << "Selected device is not valid, aborting"; +m_Controls.tabWidget->setTabEnabled(1, false); +return; +} //create the widgets for this device and enable the widget tab this->CreateControlWidgets(); m_Controls.tabWidget->setTabEnabled(1, true); //show node if the option is enabled if(m_Controls.m_ShowImageStream->isChecked()) - {this->GetDataStorage()->Add(m_Node);} +{this->GetDataStorage()->Add(m_Node);} //start timer int interval = (1000 / m_Controls.m_FrameRate->value()); m_Timer->setInterval(interval); m_Timer->start(); } void UltrasoundSupport::OnNewDeviceWidgetDone() { - m_Controls.m_NewVideoDeviceWidget->setVisible(false); - m_Controls.m_DeviceManagerWidget->setVisible(true); - m_Controls.m_Headline->setText("Ultrasound Devices:"); - m_Controls.m_WidgetActiveDevices->setVisible(true); +m_Controls.m_NewVideoDeviceWidget->setVisible(false); +m_Controls.m_DeviceManagerWidget->setVisible(true); +m_Controls.m_Headline->setText("Ultrasound Devices:"); +m_Controls.m_WidgetActiveDevices->setVisible(true); } void UltrasoundSupport::CreateControlWidgets() { - m_ControlProbesWidget = new QmitkUSControlsProbesWidget(m_Device->GetControlInterfaceProbes(), m_Controls.m_ToolBoxControlWidgets); - m_Controls.probesWidgetContainer->addWidget(m_ControlProbesWidget); +m_ControlProbesWidget = new QmitkUSControlsProbesWidget(m_Device->GetControlInterfaceProbes(), m_Controls.m_ToolBoxControlWidgets); +m_Controls.probesWidgetContainer->addWidget(m_ControlProbesWidget); - // create b mode widget for current device - m_ControlBModeWidget = new QmitkUSControlsBModeWidget(m_Device->GetControlInterfaceBMode(), m_Controls.m_ToolBoxControlWidgets); - m_Controls.m_ToolBoxControlWidgets->addItem(m_ControlBModeWidget, "B Mode Controls"); - if ( ! m_Device->GetControlInterfaceBMode() ) - { - m_Controls.m_ToolBoxControlWidgets->setItemEnabled(m_Controls.m_ToolBoxControlWidgets->count()-1, false); - } +// create b mode widget for current device +m_ControlBModeWidget = new QmitkUSControlsBModeWidget(m_Device->GetControlInterfaceBMode(), m_Controls.m_ToolBoxControlWidgets); +m_Controls.m_ToolBoxControlWidgets->addItem(m_ControlBModeWidget, "B Mode Controls"); +if ( ! m_Device->GetControlInterfaceBMode() ) +{ +m_Controls.m_ToolBoxControlWidgets->setItemEnabled(m_Controls.m_ToolBoxControlWidgets->count()-1, false); +} - // create doppler widget for current device - m_ControlDopplerWidget = new QmitkUSControlsDopplerWidget(m_Device->GetControlInterfaceDoppler(), m_Controls.m_ToolBoxControlWidgets); - m_Controls.m_ToolBoxControlWidgets->addItem(m_ControlDopplerWidget, "Doppler Controls"); - if ( ! m_Device->GetControlInterfaceDoppler() ) - { - m_Controls.m_ToolBoxControlWidgets->setItemEnabled(m_Controls.m_ToolBoxControlWidgets->count()-1, false); - } +// create doppler widget for current device +m_ControlDopplerWidget = new QmitkUSControlsDopplerWidget(m_Device->GetControlInterfaceDoppler(), m_Controls.m_ToolBoxControlWidgets); +m_Controls.m_ToolBoxControlWidgets->addItem(m_ControlDopplerWidget, "Doppler Controls"); +if ( ! m_Device->GetControlInterfaceDoppler() ) +{ +m_Controls.m_ToolBoxControlWidgets->setItemEnabled(m_Controls.m_ToolBoxControlWidgets->count()-1, false); +} - ctkPluginContext* pluginContext = mitk::PluginActivator::GetContext(); - if ( pluginContext ) - { - std::string filter = "(ork.mitk.services.UltrasoundCustomWidget.deviceClass=" + m_Device->GetDeviceClass() + ")"; - - QString interfaceName ( us_service_interface_iid() ); - m_CustomWidgetServiceReference = pluginContext->getServiceReferences(interfaceName, QString::fromStdString(filter)); - - if (m_CustomWidgetServiceReference.size() > 0) - { - m_ControlCustomWidget = pluginContext->getService - (m_CustomWidgetServiceReference.at(0))->CloneForQt(m_Controls.tab2); - m_ControlCustomWidget->SetDevice(m_Device); - m_Controls.m_ToolBoxControlWidgets->addItem(m_ControlCustomWidget, "Custom Controls"); - } - else - { - m_Controls.m_ToolBoxControlWidgets->addItem(new QWidget(m_Controls.m_ToolBoxControlWidgets), "Custom Controls"); - m_Controls.m_ToolBoxControlWidgets->setItemEnabled(m_Controls.m_ToolBoxControlWidgets->count()-1, false); - } - } +ctkPluginContext* pluginContext = mitk::PluginActivator::GetContext(); +if ( pluginContext ) +{ +std::string filter = "(ork.mitk.services.UltrasoundCustomWidget.deviceClass=" + m_Device->GetDeviceClass() + ")"; - // select first enabled control widget - for ( int n = 0; n < m_Controls.m_ToolBoxControlWidgets->count(); ++n) - { - if ( m_Controls.m_ToolBoxControlWidgets->isItemEnabled(n) ) - { - m_Controls.m_ToolBoxControlWidgets->setCurrentIndex(n); - break; - } - } +QString interfaceName ( us_service_interface_iid() ); +m_CustomWidgetServiceReference = pluginContext->getServiceReferences(interfaceName, QString::fromStdString(filter)); + +if (m_CustomWidgetServiceReference.size() > 0) +{ +m_ControlCustomWidget = pluginContext->getService +(m_CustomWidgetServiceReference.at(0))->CloneForQt(m_Controls.tab2); +m_ControlCustomWidget->SetDevice(m_Device); +m_Controls.m_ToolBoxControlWidgets->addItem(m_ControlCustomWidget, "Custom Controls"); +} +else +{ +m_Controls.m_ToolBoxControlWidgets->addItem(new QWidget(m_Controls.m_ToolBoxControlWidgets), "Custom Controls"); +m_Controls.m_ToolBoxControlWidgets->setItemEnabled(m_Controls.m_ToolBoxControlWidgets->count()-1, false); +} +} + +// select first enabled control widget +for ( int n = 0; n < m_Controls.m_ToolBoxControlWidgets->count(); ++n) +{ +if ( m_Controls.m_ToolBoxControlWidgets->isItemEnabled(n) ) +{ +m_Controls.m_ToolBoxControlWidgets->setCurrentIndex(n); +break; +} +} } void UltrasoundSupport::RemoveControlWidgets() { - if(!m_ControlProbesWidget) {return;} //widgets do not exist... nothing to do +if(!m_ControlProbesWidget) {return;} //widgets do not exist... nothing to do - // remove all control widgets from the tool box widget - while (m_Controls.m_ToolBoxControlWidgets->count() > 0) - { - m_Controls.m_ToolBoxControlWidgets->removeItem(0); - } +// remove all control widgets from the tool box widget +while (m_Controls.m_ToolBoxControlWidgets->count() > 0) +{ +m_Controls.m_ToolBoxControlWidgets->removeItem(0); +} - // remove probes widget (which is not part of the tool box widget) - m_Controls.probesWidgetContainer->removeWidget(m_ControlProbesWidget); - delete m_ControlProbesWidget; - m_ControlProbesWidget = 0; +// remove probes widget (which is not part of the tool box widget) +m_Controls.probesWidgetContainer->removeWidget(m_ControlProbesWidget); +delete m_ControlProbesWidget; +m_ControlProbesWidget = 0; - delete m_ControlBModeWidget; - m_ControlBModeWidget = 0; +delete m_ControlBModeWidget; +m_ControlBModeWidget = 0; - delete m_ControlDopplerWidget; - m_ControlDopplerWidget = 0; +delete m_ControlDopplerWidget; +m_ControlDopplerWidget = 0; - // delete custom widget if it is present - if ( m_ControlCustomWidget ) - { - ctkPluginContext* pluginContext = mitk::PluginActivator::GetContext(); - delete m_ControlCustomWidget; m_ControlCustomWidget = 0; +// delete custom widget if it is present +if ( m_ControlCustomWidget ) +{ +ctkPluginContext* pluginContext = mitk::PluginActivator::GetContext(); +delete m_ControlCustomWidget; m_ControlCustomWidget = 0; - if ( m_CustomWidgetServiceReference.size() > 0 ) - { - pluginContext->ungetService(m_CustomWidgetServiceReference.at(0)); - } - } +if ( m_CustomWidgetServiceReference.size() > 0 ) +{ +pluginContext->ungetService(m_CustomWidgetServiceReference.at(0)); +} +} } void UltrasoundSupport::OnDeciveServiceEvent(const ctkServiceEvent event) { - if ( m_Device.IsNull() || event.getType() != us::ServiceEvent::MODIFIED ) { return; } +if ( m_Device.IsNull() || event.getType() != us::ServiceEvent::MODIFIED ) { return; } - ctkServiceReference service = event.getServiceReference(); +ctkServiceReference service = event.getServiceReference(); - if ( m_Device->GetManufacturer() != service.getProperty(QString::fromStdString(mitk::USDevice::GetPropertyKeys().US_PROPKEY_MANUFACTURER)).toString().toStdString() - && m_Device->GetName() != service.getProperty(QString::fromStdString(mitk::USDevice::GetPropertyKeys().US_PROPKEY_NAME)).toString().toStdString() ) - { - return; - } +if ( m_Device->GetManufacturer() != service.getProperty(QString::fromStdString(mitk::USDevice::GetPropertyKeys().US_PROPKEY_MANUFACTURER)).toString().toStdString() +&& m_Device->GetName() != service.getProperty(QString::fromStdString(mitk::USDevice::GetPropertyKeys().US_PROPKEY_NAME)).toString().toStdString() ) +{ +return; +} - if ( ! m_Device->GetIsActive() && m_Timer->isActive() ) - { - m_Timer->stop(); - } +if ( ! m_Device->GetIsActive() && m_Timer->isActive() ) +{ +m_Timer->stop(); +} - if ( m_CurrentDynamicRange != service.getProperty(QString::fromStdString(mitk::USDevice::GetPropertyKeys().US_PROPKEY_BMODE_DYNAMIC_RANGE)).toDouble() ) - { - m_CurrentDynamicRange = service.getProperty(QString::fromStdString(mitk::USDevice::GetPropertyKeys().US_PROPKEY_BMODE_DYNAMIC_RANGE)).toDouble(); +if ( m_CurrentDynamicRange != service.getProperty(QString::fromStdString(mitk::USDevice::GetPropertyKeys().US_PROPKEY_BMODE_DYNAMIC_RANGE)).toDouble() ) +{ +m_CurrentDynamicRange = service.getProperty(QString::fromStdString(mitk::USDevice::GetPropertyKeys().US_PROPKEY_BMODE_DYNAMIC_RANGE)).toDouble(); - // update level window for the current dynamic range - mitk::LevelWindow levelWindow; - m_Node->GetLevelWindow(levelWindow); - levelWindow.SetAuto(m_Image, true, true); - m_Node->SetLevelWindow(levelWindow); - } +// update level window for the current dynamic range +mitk::LevelWindow levelWindow; +m_Node->GetLevelWindow(levelWindow); +levelWindow.SetAuto(m_Image, true, true); +m_Node->SetLevelWindow(levelWindow); +} } UltrasoundSupport::UltrasoundSupport() : m_ControlCustomWidget(0), m_ControlBModeWidget(0), - m_ControlProbesWidget(0), m_ImageAlreadySetToNode(false), - m_CurrentImageWidth(0), m_CurrentImageHeight(0) +m_ControlProbesWidget(0), m_ImageAlreadySetToNode(false), +m_CurrentImageWidth(0), m_CurrentImageHeight(0) { - ctkPluginContext* pluginContext = mitk::PluginActivator::GetContext(); +ctkPluginContext* pluginContext = mitk::PluginActivator::GetContext(); - if ( pluginContext ) - { - // to be notified about service event of an USDevice - pluginContext->connectServiceListener(this, "OnDeciveServiceEvent", - QString::fromStdString("(" + us::ServiceConstants::OBJECTCLASS() + "=" + us_service_interface_iid() + ")")); - } +if ( pluginContext ) +{ +// to be notified about service event of an USDevice +pluginContext->connectServiceListener(this, "OnDeciveServiceEvent", +QString::fromStdString("(" + us::ServiceConstants::OBJECTCLASS() + "=" + us_service_interface_iid() + ")")); +} } UltrasoundSupport::~UltrasoundSupport() { } 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 54f7fd5b40..ac2fa56c8e 100644 --- a/Plugins/org.mitk.gui.qt.ultrasound/src/internal/UltrasoundSupport.h +++ b/Plugins/org.mitk.gui.qt.ultrasound/src/internal/UltrasoundSupport.h @@ -1,125 +1,127 @@ /*=================================================================== 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 UltrasoundSupport_h #define UltrasoundSupport_h #include #include #include "ui_UltrasoundSupportControls.h" #include "QmitkUSAbstractCustomWidget.h" #include "QmitkUSControlsBModeWidget.h" #include "QmitkUSControlsDopplerWidget.h" #include "QmitkUSControlsProbesWidget.h" #include #include /*! \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); UltrasoundSupport(); virtual ~UltrasoundSupport(); public slots: /* * \brief This is called when the newDeviceWidget is closed */ void OnNewDeviceWidgetDone(); protected slots: void OnClickedAddNewDevice(); void OnChangedFramerateLimit(int); /* *\brief Called, when the selection in the list of the active devices changes. */ void OnChangedActiveDevice(); void OnClickedFreezeButton(); void OnDeciveServiceEvent(const ctkServiceEvent event); /* * \brief This is the main imaging loop that is called regularily during the imaging process */ void DisplayImage(); protected: void CreateControlWidgets(); void RemoveControlWidgets(); int m_FrameCounter; /* * \brief This timer triggers periodic updates to the pipeline */ QTimer* m_Timer; QTime m_Clock; /* * \brief The device that is currently used to aquire images */ mitk::USDevice::Pointer m_Device; /* * \brief The node that we feed images into */ mitk::DataNode::Pointer m_Node; mitk::Image::Pointer m_Image; + mitk::Geometry3D::Pointer m_OldGeometry; + Ui::UltrasoundSupportControls m_Controls; QmitkUSAbstractCustomWidget* m_ControlCustomWidget; QmitkUSControlsBModeWidget* m_ControlBModeWidget; QmitkUSControlsDopplerWidget* m_ControlDopplerWidget; QmitkUSControlsProbesWidget* m_ControlProbesWidget; QList m_CustomWidgetServiceReference; bool m_ImageAlreadySetToNode; unsigned int m_CurrentImageWidth; unsigned int m_CurrentImageHeight; double m_CurrentDynamicRange; }; #endif // UltrasoundSupport_h