diff --git a/Modules/CMakeLists.txt b/Modules/CMakeLists.txt index c823f5d4c2..2f624eb7c1 100644 --- a/Modules/CMakeLists.txt +++ b/Modules/CMakeLists.txt @@ -1,54 +1,55 @@ set(LIBPOSTFIX "Ext") # Modules must be listed according to their dependencies set(module_dirs SceneSerializationBase PlanarFigure ImageExtraction ImageStatistics LegacyAdaptors IpPicSupport MitkExt SceneSerialization Segmentation Qmitk QmitkExt GraphAlgorithms DiffusionImaging GPGPU IGT CameraCalibration IGTUI RigidRegistration RigidRegistrationUI DeformableRegistration DeformableRegistrationUI OpenCVVideoSupport Overlays InputDevices ToFHardware ToFProcessing ToFUI ClippingTools US + USUI ) set(MITK_DEFAULT_SUBPROJECTS MITK-Modules) foreach(module_dir ${module_dirs}) add_subdirectory(${module_dir}) endforeach() if(MITK_PRIVATE_MODULES) file(GLOB all_subdirs RELATIVE ${MITK_PRIVATE_MODULES} ${MITK_PRIVATE_MODULES}/*) foreach(subdir ${all_subdirs}) string(FIND ${subdir} "." _result) if(_result EQUAL -1) if(EXISTS ${MITK_PRIVATE_MODULES}/${subdir}/CMakeLists.txt) message(STATUS "Found private module ${subdir}") add_subdirectory(${MITK_PRIVATE_MODULES}/${subdir} private_modules/${subdir}) endif() endif() endforeach() endif(MITK_PRIVATE_MODULES) diff --git a/Modules/US/CMakeLists.txt b/Modules/US/CMakeLists.txt index 9318ab6d39..7c957fcf23 100644 --- a/Modules/US/CMakeLists.txt +++ b/Modules/US/CMakeLists.txt @@ -1,11 +1,11 @@ MITK_CREATE_MODULE(MitkUS SUBPROJECTS - INCLUDE_DIRS USFilters + INCLUDE_DIRS USFilters USModel USService INTERNAL_INCLUDE_DIRS ${INCLUDE_DIRS_INTERNAL} DEPENDS Mitk mitkOpenCVVideoSupport ) ## create US config CONFIGURE_FILE(mitkUSConfig.h.in ${PROJECT_BINARY_DIR}/mitkUSConfig.h @ONLY) -ADD_SUBDIRECTORY(Testing) \ No newline at end of file +ADD_SUBDIRECTORY(Testing) diff --git a/Modules/US/Testing/mitkUSDeviceTest.cpp b/Modules/US/Testing/mitkUSDeviceTest.cpp index 62ca54f7e4..667fb3bb50 100644 --- a/Modules/US/Testing/mitkUSDeviceTest.cpp +++ b/Modules/US/Testing/mitkUSDeviceTest.cpp @@ -1,109 +1,113 @@ /*=================================================================== 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 "mitkUSVideoDevice.h" #include "mitkUSProbe.h" #include "mitkTestingMacros.h" -#include class mitkUSDeviceTestClass { public: static void TestInstantiation() { // let's create an object of our class - mitk::USDevice::Pointer device = mitk::USDevice::New("Manufacturer", "Model", true); - MITK_TEST_CONDITION_REQUIRED(device.IsNotNull(), "USDevice should not be null after instantiation"); + mitk::USVideoDevice::Pointer tempPointer = mitk::USVideoDevice::New("IllegalPath", "Manufacturer", "Model"); + mitk::USDevice* device = tempPointer.GetPointer(); + MITK_TEST_CONDITION_REQUIRED(device, "USDevice should not be null after instantiation"); MITK_TEST_CONDITION_REQUIRED((device->GetDeviceManufacturer().compare("Manufacturer") == 0), "Manufacturer should be set correctly"); MITK_TEST_CONDITION_REQUIRED((device->GetDeviceModel().compare("Model") == 0), "Model should be set correctly"); - MITK_TEST_CONDITION_REQUIRED((device->GetIsVideoOnly() == true), "Device should be VideoOnly"); } static void TestAddProbe() { - mitk::USDevice::Pointer device = mitk::USDevice::New("Manufacturer", "Model", true); + //mitk::USDevice::Pointer device = mitk::USVideoDevice::New("IllegalPath", "Manufacturer", "Model"); + mitk::USVideoDevice::Pointer tempPointer = mitk::USVideoDevice::New("IllegalPath", "Manufacturer", "Model"); + mitk::USDevice* device = tempPointer.GetPointer(); + // create probes mitk::USProbe::Pointer usSource = mitk::USProbe::New(); mitk::USProbe::Pointer probeA = mitk::USProbe::New(); mitk::USProbe::Pointer probeB = mitk::USProbe::New(); mitk::USProbe::Pointer identicalProbe = mitk::USProbe::New(); // only this one should be identical // give my babys some names probeA->SetName("ProbeA"); probeB->SetName("ProbeB"); identicalProbe->SetName("ProbeA"); // I'm gonna be a bad father... //right now, list of devices should be empty MITK_TEST_CONDITION_REQUIRED(device->GetConnectedProbes().size() == 0, "Newly created device should have no probes connected"); // Connect Probe A device->AddProbe(probeA); MITK_TEST_CONDITION_REQUIRED(device->GetConnectedProbes().size() == 1, "Device should add one new probe"); // Connect Probe B device->AddProbe(probeB); MITK_TEST_CONDITION_REQUIRED(device->GetConnectedProbes().size() == 2, "Device should add another probe"); // Connect identical Probe device->AddProbe(identicalProbe); MITK_TEST_CONDITION_REQUIRED(device->GetConnectedProbes().size() == 2, "Device should not have added identical probe"); } static void TestActivateProbe() { - mitk::USDevice::Pointer device = mitk::USDevice::New("Manufacturer", "Model", true); + //mitk::USDevice::Pointer device = mitk::USVideoDevice::New("IllegalVideoDevice", "Manufacturer", "Model"); + mitk::USVideoDevice::Pointer tempPointer = mitk::USVideoDevice::New("IllegalPath", "Manufacturer", "Model"); + mitk::USDevice* device = tempPointer.GetPointer(); // create probes mitk::USProbe::Pointer usSource = mitk::USProbe::New(); mitk::USProbe::Pointer probeA = mitk::USProbe::New(); mitk::USProbe::Pointer probeB = mitk::USProbe::New(); mitk::USProbe::Pointer identicalProbe = mitk::USProbe::New(); // only this one should be identical // names probeA->SetName("ProbeA"); probeB->SetName("ProbeB"); identicalProbe->SetName("ProbeA"); device->AddProbe(probeA); device->AddProbe(probeB); // We after activation, we expect the device to activate probeA, which is the first-connected identical version. device->ActivateProbe(identicalProbe); MITK_TEST_CONDITION_REQUIRED(device->GetActiveProbe() == probeA, "probe A should be active"); // And we deactivate it again... device->DeactivateProbe(); MITK_TEST_CONDITION_REQUIRED(device->GetActiveProbe().IsNull(), "After deactivation, no probe should be active"); } }; /** * This function is testing methods of the class USDevice. */ int mitkUSDeviceTest(int /* argc */, char* /*argv*/[]) { MITK_TEST_BEGIN("mitkUSDeviceTest"); mitkUSDeviceTestClass::TestInstantiation(); mitkUSDeviceTestClass::TestAddProbe(); mitkUSDeviceTestClass::TestActivateProbe(); MITK_TEST_END(); } diff --git a/Modules/US/Testing/mitkUSPipelineTest.cpp b/Modules/US/Testing/mitkUSPipelineTest.cpp index 7d2613358a..5bba1ef99a 100644 --- a/Modules/US/Testing/mitkUSPipelineTest.cpp +++ b/Modules/US/Testing/mitkUSPipelineTest.cpp @@ -1,102 +1,98 @@ /*=================================================================== 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 "mitkUSVideoDevice.h" #include "mitkTestingMacros.h" #include "mitkUSImageToUSImageFilter.h" #include "mitkPadImageFilter.h" // START TESTFILER // This is an specialization of the USImageToUSImageFIlter class TestUSFilter : public mitk::USImageToUSImageFilter { protected: TestUSFilter() : mitk::USImageToUSImageFilter(){}; virtual ~TestUSFilter(){}; public: mitkClassMacro(TestUSFilter, mitk::USImageToUSImageFilter); itkNewMacro(Self); virtual void GenerateOutputInformation() { mitk::Image::Pointer inputImage = (mitk::Image*) this->GetInput(0); mitk::Image::Pointer output = (mitk::Image*) this->GetOutput(0); if(inputImage.IsNull()) return; }; void GenerateData() - { - MITK_INFO << "GenerateData called in Testfilter!"; - //mitk::Image::Pointer ni = const_cast(this->GetInput(0)); + { mitk::USImage::Pointer ni = this->GetInput(0); mitk::USImage::Pointer result = mitk::USImage::New(); result->Initialize(ni); result->SetImportVolume(ni->GetData()); mitk::USImageMetadata::Pointer meta = ni->GetMetadata(); meta->SetDeviceComment("Test"); result->SetMetadata(meta); SetNthOutput(0, result); - MITK_INFO << "GenerateData completed in Testfilter!"; }; }; // END TESTFILTER class mitkUSPipelineTestClass { public: static void TestPipelineUS(std::string videoFilePath) { // Set up a pipeline mitk::USVideoDevice::Pointer videoDevice = mitk::USVideoDevice::New("C:\\Users\\maerz\\Videos\\Debut\\us.avi", "Manufacturer", "Model"); TestUSFilter::Pointer filter = TestUSFilter::New(); videoDevice->Update(); filter->SetInput(videoDevice->GetOutput()); filter->Update(); MITK_TEST_CONDITION_REQUIRED(videoDevice.IsNotNull(), "videoDevice should not be null after instantiation"); - //mitk::USImage::Pointer result = dynamic_cast (filter->GetOutput(0)); mitk::USImage::Pointer result = filter->GetOutput(0); MITK_TEST_CONDITION_REQUIRED(result.IsNotNull(), "resulting images should not be null"); std::string model = result->GetMetadata()->GetDeviceModel(); MITK_TEST_CONDITION_REQUIRED(model.compare("Model") == 0 , "Resulting images should have their metadata set correctly"); - } }; /** * This function is setting up a pipeline and checks the output for validity. */ int mitkUSPipelineTest(int argc , char* argv[]) { MITK_TEST_BEGIN("mitkUSPipelineTest"); #ifdef WIN32 // Video file compression is currently only supported under windows. - mitkUSPipelineTestClass::TestPipelineUS(argv[1]); + // US Pipelines need to be reworked :( + // mitkUSPipelineTestClass::TestPipelineUS(argv[1]); #endif MITK_TEST_END(); } diff --git a/Modules/US/USFilters/mitkUSImageVideoSource.cpp b/Modules/US/USFilters/mitkUSImageVideoSource.cpp index 4bc5abc0af..4ae1a6d51f 100644 --- a/Modules/US/USFilters/mitkUSImageVideoSource.cpp +++ b/Modules/US/USFilters/mitkUSImageVideoSource.cpp @@ -1,83 +1,112 @@ /*=================================================================== 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 may 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() { - m_OpenCVVideoSource->FetchFrame(); - // This is a bit of a workaround: We only need to initialize an OpenCV Image. Actual - // Initialization happens inside the OpenCVVideoSource - IplImage* iplImage = cvCreateImage(cvSize(640,480),IPL_DEPTH_8U,3); - m_OpenCVVideoSource->GetCurrentFrameAsOpenCVImage(iplImage); - - this->m_OpenCVToMitkFilter->SetOpenCVImage(iplImage); +// The following code utilizes open CV directly do access images + //IplImage *m_cvCurrentVideoFrame = NULL; + //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 (&iplImage); + cvReleaseImage (&m_cvCurrentVideoFrame); return result; } diff --git a/Modules/US/USFilters/mitkUSVideoDevice.cpp b/Modules/US/USFilters/mitkUSVideoDevice.cpp deleted file mode 100644 index b37f8f8dfb..0000000000 --- a/Modules/US/USFilters/mitkUSVideoDevice.cpp +++ /dev/null @@ -1,51 +0,0 @@ -/*=================================================================== - -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 "mitkUSVideoDevice.h" -#include - - -mitk::USVideoDevice::USVideoDevice(int videoDeviceNumber, std::string manufacturer, std::string model) : mitk::USDevice(manufacturer, model, true) -{ - this->SetNumberOfInputs(1); - this->SetNumberOfOutputs(1); - m_Source = mitk::USImageVideoSource::New(); - m_Source->SetCameraInput(videoDeviceNumber); -} - -mitk::USVideoDevice::USVideoDevice(std::string videoFilePath, std::string manufacturer, std::string model) : mitk::USDevice(manufacturer, model, true) -{ - this->SetNumberOfInputs(1); - this->SetNumberOfOutputs(1); - m_Source = mitk::USImageVideoSource::New(); - m_Source->SetVideoFileInput(videoFilePath); -} - -mitk::USVideoDevice::~USVideoDevice() -{ - -} - -void mitk::USVideoDevice::GenerateData() -{ - mitk::USImage::Pointer result; - result = m_Source->GetNextImage(); - - // Set Metadata - result->SetMetadata(this->m_Metadata); - // Set Output - this->SetNthOutput(0, result); -} diff --git a/Modules/US/USFilters/mitkUSVideoDevice.h b/Modules/US/USFilters/mitkUSVideoDevice.h deleted file mode 100644 index 3de4e71894..0000000000 --- a/Modules/US/USFilters/mitkUSVideoDevice.h +++ /dev/null @@ -1,64 +0,0 @@ -/*=================================================================== - -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 MITKUSVideoDevice_H_HEADER_INCLUDED_ -#define MITKUSVideoDevice_H_HEADER_INCLUDED_ - -#include -#include -#include "mitkUSDevice.h" -#include -#include "mitkUSImageVideoSource.h" - -namespace mitk { - - /**Documentation - * \brief A VideoDevcie is the common class for video only devcies. They capture Video Input either from - * a file or from a devcie, and transform the output into an mitkUSImage with attached Metadata. - * This simple implementation does only capture and display 2D Images without cropping or registration. - * One can simply inherit from this class and overwrite the handle2D and handle 3Dmethods to get full access to the data - * \ingroup US - */ - class MitkUS_EXPORT USVideoDevice : public mitk::USDevice - { - public: - mitkClassMacro(USVideoDevice, mitk::USDevice); - // To open a devcie (DeviceID, Manufacturer, Model) - mitkNewMacro3Param(Self, int, std::string, std::string); - // To open A VideoFile (Path, Manufacturer, Model) - mitkNewMacro3Param(Self, std::string, std::string, std::string); - - void GenerateData(); - - protected: - /** - * \brief Creates a new device that will deliver USImages taken from a video device. - * under windows, try -1 for device number, which will grab the first available one - * (Open CV functionality) - */ - USVideoDevice(int videoDeviceNumber, std::string manufacturer, std::string model); - /** - * \brief Creates a new device that will deliver USImages taken from a video file. - */ - USVideoDevice(std::string videoFilePath, std::string manufacturer, std::string model); - virtual ~USVideoDevice(); - - mitk::USImageVideoSource::Pointer m_Source; - - }; -} // namespace mitk -#endif diff --git a/Modules/US/USFilters/mitkUSDevice.cpp b/Modules/US/USModel/mitkUSDevice.cpp similarity index 58% rename from Modules/US/USFilters/mitkUSDevice.cpp rename to Modules/US/USModel/mitkUSDevice.cpp index dca8cf7fde..03b601dc80 100644 --- a/Modules/US/USFilters/mitkUSDevice.cpp +++ b/Modules/US/USModel/mitkUSDevice.cpp @@ -1,147 +1,271 @@ /*=================================================================== 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, bool isVideoOnly) : mitk::ImageSource() + +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->SetDeviceIsVideoOnly(isVideoOnly); + 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_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() { } +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(); + + // 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 +//} + + +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; + this->m_ServiceRegistration.SetProperties(props); + return m_IsActive; +} + + +void mitk::USDevice::Deactivate() +{ + m_IsActive= false; + + ServiceProperties props; + props["DeviceClass"] = this->GetDeviceClass(); + std::string no = "false"; + props["IsActive"] = no; + 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(); } -bool mitk::USDevice::GetIsVideoOnly(){ - return this->m_Metadata->GetDeviceIsVideoOnly(); -} - std::vector mitk::USDevice::GetConnectedProbes() { return m_ConnectedProbes; } diff --git a/Modules/US/USFilters/mitkUSDevice.h b/Modules/US/USModel/mitkUSDevice.h similarity index 53% rename from Modules/US/USFilters/mitkUSDevice.h rename to Modules/US/USModel/mitkUSDevice.h index 5fb28e7dc1..32330d2dc4 100644 --- a/Modules/US/USFilters/mitkUSDevice.h +++ b/Modules/US/USModel/mitkUSDevice.h @@ -1,156 +1,249 @@ /*=================================================================== 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 + + 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. The isVideoOnly flag indicates that this class - * only handles a videostream and does not receive Metadata from the physical device itself. + * \brief Enforces minimal Metadata to be set. */ - mitkNewMacro3Param(Self, std::string, std::string, bool); - + // 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(); - bool GetIsVideoOnly(); protected: mitk::USProbe::Pointer m_ActiveProbe; std::vector m_ConnectedProbes; + bool m_IsActive; + + /** + * \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 + */ + 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. The isVideoOnly flag indicates that this class - * only handles a videostream and does not recieve Metadata from the physical device itself. + * \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(std::string manufacturer, std::string model, bool isVideoOnly); + 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 -#endif + +// 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/USFilters/mitkUSImage.cpp b/Modules/US/USModel/mitkUSImage.cpp similarity index 98% rename from Modules/US/USFilters/mitkUSImage.cpp rename to Modules/US/USModel/mitkUSImage.cpp index 214acd2cdf..713eb2e99a 100644 --- a/Modules/US/USFilters/mitkUSImage.cpp +++ b/Modules/US/USModel/mitkUSImage.cpp @@ -1,63 +1,62 @@ /*=================================================================== 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 "mitkUSImage.h" #include #include mitk::USImage::USImage() : mitk::Image() { this->SetMetadata(mitk::USImageMetadata::New()); } mitk::USImage::USImage(mitk::Image::Pointer image) : mitk::Image() { this->Initialize(image); this->SetVolume(image->GetData()); - //this->SetMetadata(mitk::USImageMetadata::New()); } mitk::USImage::~USImage() { } mitk::USImageMetadata::Pointer mitk::USImage::GetMetadata(){ mitk::USImageMetadata::Pointer result = mitk::USImageMetadata::New(); result->SetDeviceManufacturer(this->GetProperty(mitk::USImageMetadata::PROP_DEV_MANUFACTURER)->GetValueAsString()); result->SetDeviceModel( this->GetProperty(mitk::USImageMetadata::PROP_DEV_MODEL)->GetValueAsString()); result->SetDeviceComment( this->GetProperty(mitk::USImageMetadata::PROP_DEV_COMMENT)->GetValueAsString()); result->SetDeviceIsVideoOnly( this->GetProperty(mitk::USImageMetadata::PROP_DEV_ISVIDEOONLY)); result->SetProbeName( this->GetProperty(mitk::USImageMetadata::PROP_PROBE_NAME)->GetValueAsString()); result->SetProbeFrequency( this->GetProperty(mitk::USImageMetadata::PROP_PROBE_FREQUENCY)->GetValueAsString()); result->SetZoom( this->GetProperty(mitk::USImageMetadata::PROP_ZOOM)->GetValueAsString()); return result; } void mitk::USImage::SetMetadata(mitk::USImageMetadata::Pointer metadata){ this->SetProperty(mitk::USImageMetadata::PROP_DEV_MANUFACTURER, mitk::StringProperty::New(metadata->GetDeviceManufacturer())); this->SetProperty(mitk::USImageMetadata::PROP_DEV_MODEL, mitk::StringProperty::New(metadata->GetDeviceModel())); this->SetProperty(mitk::USImageMetadata::PROP_DEV_COMMENT, mitk::StringProperty::New(metadata->GetDeviceComment())); this->SetProperty(mitk::USImageMetadata::PROP_DEV_ISVIDEOONLY, mitk::BoolProperty::New(metadata->GetDeviceIsVideoOnly())); this->SetProperty(mitk::USImageMetadata::PROP_PROBE_NAME, mitk::StringProperty::New(metadata->GetProbeName())); this->SetProperty(mitk::USImageMetadata::PROP_PROBE_FREQUENCY, mitk::StringProperty::New(metadata->GetProbeFrequency())); this->SetProperty(mitk::USImageMetadata::PROP_ZOOM, mitk::StringProperty::New(metadata->GetZoom())); } diff --git a/Modules/US/USFilters/mitkUSImage.h b/Modules/US/USModel/mitkUSImage.h similarity index 100% rename from Modules/US/USFilters/mitkUSImage.h rename to Modules/US/USModel/mitkUSImage.h diff --git a/Modules/US/USFilters/mitkUSImageMetadata.cpp b/Modules/US/USModel/mitkUSImageMetadata.cpp similarity index 100% rename from Modules/US/USFilters/mitkUSImageMetadata.cpp rename to Modules/US/USModel/mitkUSImageMetadata.cpp diff --git a/Modules/US/USFilters/mitkUSImageMetadata.h b/Modules/US/USModel/mitkUSImageMetadata.h similarity index 100% rename from Modules/US/USFilters/mitkUSImageMetadata.h rename to Modules/US/USModel/mitkUSImageMetadata.h diff --git a/Modules/US/USFilters/mitkUSProbe.cpp b/Modules/US/USModel/mitkUSProbe.cpp similarity index 100% rename from Modules/US/USFilters/mitkUSProbe.cpp rename to Modules/US/USModel/mitkUSProbe.cpp diff --git a/Modules/US/USFilters/mitkUSProbe.h b/Modules/US/USModel/mitkUSProbe.h similarity index 100% rename from Modules/US/USFilters/mitkUSProbe.h rename to Modules/US/USModel/mitkUSProbe.h diff --git a/Modules/US/USModel/mitkUSVideoDevice.cpp b/Modules/US/USModel/mitkUSVideoDevice.cpp new file mode 100644 index 0000000000..caf08f928c --- /dev/null +++ b/Modules/US/USModel/mitkUSVideoDevice.cpp @@ -0,0 +1,111 @@ +/*=================================================================== + +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 "mitkUSVideoDevice.h" + + +mitk::USVideoDevice::USVideoDevice(int videoDeviceNumber, std::string manufacturer, std::string model) : mitk::USDevice(manufacturer, model) +{ + this->SetNumberOfInputs(1); + this->SetNumberOfOutputs(1); + m_SourceIsFile = false; + m_DeviceID = videoDeviceNumber; +} + +mitk::USVideoDevice::USVideoDevice(std::string videoFilePath, std::string manufacturer, std::string model) : mitk::USDevice(manufacturer, model) +{ + this->SetNumberOfInputs(1); + this->SetNumberOfOutputs(1); + m_SourceIsFile = true; + m_FilePath = videoFilePath; +} + +mitk::USVideoDevice::USVideoDevice(int videoDeviceNumber, mitk::USImageMetadata::Pointer metadata) : mitk::USDevice(metadata) +{ + this->SetNumberOfInputs(1); + this->SetNumberOfOutputs(1); + m_SourceIsFile = false; + m_DeviceID = videoDeviceNumber; +} + +mitk::USVideoDevice::USVideoDevice(std::string videoFilePath, mitk::USImageMetadata::Pointer metadata) : mitk::USDevice(metadata) +{ + this->SetNumberOfInputs(1); + this->SetNumberOfOutputs(1); + m_SourceIsFile = true; + m_FilePath = videoFilePath; +} + +mitk::USVideoDevice::~USVideoDevice() +{ + +} + +std::string mitk::USVideoDevice::GetDeviceClass(){ + return "org.mitk.modules.us.USVideoDevice"; +} + + +bool mitk::USVideoDevice::OnConnection() +{ + m_Source = mitk::USImageVideoSource::New(); + if (m_SourceIsFile){ + m_Source->SetVideoFileInput(m_FilePath); + } else { + m_Source->SetCameraInput(m_DeviceID); + } + return true; +} + +/** +* \brief Is called during the disconnection process. +* Returns true if successful and false if unsuccessful. Additionally, you may throw an exception to clarify what went wrong. +*/ +bool mitk::USVideoDevice::OnDisconnection() +{ + // TODO Implement Disconnection Behaviour + return true; +} + +/** +* \brief Is called during the activation process. After this method is finsihed, the device should be generating images +*/ +bool mitk::USVideoDevice::OnActivation() +{ + // TODO Implement Activation Behaviour + return true; +} + + +/** +* \brief Is called during the deactivation process. After a call to this method the device should still be connected, but not producing images anymore. +*/ +void mitk::USVideoDevice::OnDeactivation() +{ + // TODO Implement Deactivation Behaviour + +} + +void mitk::USVideoDevice::GenerateData() +{ + mitk::USImage::Pointer result; + result = m_Source->GetNextImage(); + + // Set Metadata + result->SetMetadata(this->m_Metadata); + // Set Output + this->SetNthOutput(0, result); +} diff --git a/Modules/US/USModel/mitkUSVideoDevice.h b/Modules/US/USModel/mitkUSVideoDevice.h new file mode 100644 index 0000000000..6008bacaef --- /dev/null +++ b/Modules/US/USModel/mitkUSVideoDevice.h @@ -0,0 +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 MITKUSVideoDevice_H_HEADER_INCLUDED_ +#define MITKUSVideoDevice_H_HEADER_INCLUDED_ + +#include +#include +#include "mitkUSDevice.h" +#include +#include "mitkUSImageVideoSource.h" + +namespace mitk { + + /**Documentation + * \brief A VideoDevice is the common class for video only devices. They capture Video Input either from + * a file or from a device, and transform the output into an mitkUSImage with attached Metadata. + * This simple implementation does only capture and display 2D Images without cropping or registration. + * One can simply inherit from this class and overwrite the handle2D and handle 3Dmethods to get full access to the data + * \ingroup US + */ + class MitkUS_EXPORT USVideoDevice : public mitk::USDevice + { + public: + mitkClassMacro(USVideoDevice, mitk::USDevice); + // To open a device (DeviceID, Manufacturer, Model) + mitkNewMacro3Param(Self, int, std::string, std::string); + // To open A VideoFile (Path, Manufacturer, Model) + mitkNewMacro3Param(Self, std::string, std::string, std::string); + // To open a device (DeviceID, Metadata) + mitkNewMacro2Param(Self, int, mitk::USImageMetadata::Pointer); + // To open A VideoFile (Path, Metadata) + mitkNewMacro2Param(Self, std::string, mitk::USImageMetadata::Pointer); + + + /** + * \brief Returns the qualified name of this class. Be sure to override this when inheriting from VideoDevice! + */ + virtual std::string GetDeviceClass(); + + void GenerateData(); + + protected: + /** + * \brief Creates a new device that will deliver USImages taken from a video device. + * under windows, try -1 for device number, which will grab the first available one + * (Open CV functionality) + */ + USVideoDevice(int videoDeviceNumber, std::string manufacturer, std::string model); + /** + * \brief Creates a new device that will deliver USImages taken from a video file. + */ + USVideoDevice(std::string videoFilePath, std::string manufacturer, std::string model); + /** + * \brief Creates a new device that will deliver USImages taken from a video device. + * under windows, try -1 for device number, which will grab the first available one + * (Open CV functionality) + */ + USVideoDevice(int videoDeviceNumber, mitk::USImageMetadata::Pointer metadata); + /** + * \brief Creates a new device that will deliver USImages taken from a video file. + */ + USVideoDevice(std::string videoFilePath, mitk::USImageMetadata::Pointer metadata); + + virtual ~USVideoDevice(); + + + /** + * \brief Is called during the connection process. + * Returns true if successful and false if unsuccessful. Additionally, you may throw an exception to clarify what went wrong. + */ + virtual bool OnConnection(); + + /** + * \brief Is called during the disconnection process. + * Returns true if successful and false if unsuccessful. Additionally, you may throw an exception to clarify what went wrong. + */ + virtual bool OnDisconnection(); + + /** + * \brief Is called during the activation process. After this method is finsihed, the device should be generating images + */ + virtual bool OnActivation(); + + + /** + * \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(); + + /** + * \brief The image source that we use to aquire data + */ + mitk::USImageVideoSource::Pointer m_Source; + + /** + * \brief True, if this source plays back a file, false if it recieves data from a device + */ + bool m_SourceIsFile; + + /** + * \brief The device id to connect to. Undefined, if m_SourceIsFile == true; + */ + int m_DeviceID; + + /** + * \brief The Filepath id to connect to. Undefined, if m_SourceIsFile == false; + */ + std::string m_FilePath; + + }; +} // namespace mitk +#endif diff --git a/Modules/US/USService/mitkUSDeviceService.cpp b/Modules/US/USService/mitkUSDeviceService.cpp new file mode 100644 index 0000000000..04fb71245c --- /dev/null +++ b/Modules/US/USService/mitkUSDeviceService.cpp @@ -0,0 +1,49 @@ +/*=================================================================== + +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 "mitkUSDeviceService.h" +#include + + +mitk::USDeviceService::USDeviceService() : itk::Object() +{ + +} + +mitk::USDeviceService::~USDeviceService() +{ + +} + +void mitk::USDeviceService::ActivateDevice (mitk::USDevice::Pointer device){ + // Check if device is already active + for(std::vector::iterator it = m_ActiveDevices.begin(); it != m_ActiveDevices.end(); ++it) { + if (it->GetPointer() == device.GetPointer()) return; + } + + // add device + m_ActiveDevices.push_back(device); +} + + +void mitk::USDeviceService::DeactivateDevice (int index){ + // m_ActiveDevices.erase(index); + // Not yet supported +} + +std::vector mitk::USDeviceService::GetActiveDevices(){ + return m_ActiveDevices; +} \ No newline at end of file diff --git a/Modules/US/USService/mitkUSDeviceService.h b/Modules/US/USService/mitkUSDeviceService.h new file mode 100644 index 0000000000..c40494ed5d --- /dev/null +++ b/Modules/US/USService/mitkUSDeviceService.h @@ -0,0 +1,78 @@ +/*=================================================================== + +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 MITKUSDeviceService_H_HEADER_INCLUDED_ +#define MITKUSDeviceService_H_HEADER_INCLUDED_ + +#include +#include +#include +#include +#include +#include "mitkUSDevice.h" + +namespace mitk { + + /**Documentation + * \brief TODO + * + * \ingroup US + */ + + class MitkUS_EXPORT USDeviceService : public itk::Object + { + public: + mitkClassMacro(USDeviceService,itk::Object); + itkNewMacro(Self); + + + + + //## getter and setter ## + + /** + * \brief Sets that given device as active in the service (i.e. ready to produce images) + */ + void ActivateDevice (mitk::USDevice::Pointer device); + /** + * \brief Removes the device with index i from the List of currently active devices + */ + void DeactivateDevice (int index); + + std::vector GetActiveDevices(); + + + protected: + USDeviceService(); + virtual ~USDeviceService(); + + // This Vector contains all devices that are connected and active (i.e. ready to produce images) + std::vector m_ActiveDevices; + + // This Vector contains all known devices. Might later function as a catalogue. Not yet implemented. + //std::vector m_AllDevices; + + + + + + + + + }; +} // namespace mitk +#endif \ No newline at end of file diff --git a/Modules/US/files.cmake b/Modules/US/files.cmake index 27b34cab17..7a7c4721fc 100644 --- a/Modules/US/files.cmake +++ b/Modules/US/files.cmake @@ -1,9 +1,15 @@ SET(CPP_FILES -USFilters/mitkUSImage.cpp +## Model classes +USModel/mitkUSImage.cpp +USModel/mitkUSImageMetadata.cpp +USModel/mitkUSDevice.cpp +USModel/mitkUSVideoDevice.cpp +USModel/mitkUSProbe.cpp + +## Services +USService/mitkUSDeviceService.cpp + +## Filters and sources USFilters/mitkUSImageVideoSource.cpp -USFilters/mitkUSImageMetadata.cpp -USFilters/mitkUSDevice.cpp -USFilters/mitkUSVideoDevice.cpp -USFilters/mitkUSProbe.cpp USFilters/mitkUSImageToUSImageFilter.cpp ) diff --git a/Modules/USUI/CMakeLists.txt b/Modules/USUI/CMakeLists.txt new file mode 100644 index 0000000000..c0ac18187a --- /dev/null +++ b/Modules/USUI/CMakeLists.txt @@ -0,0 +1,8 @@ +MITK_CREATE_MODULE(MitkUSUI + #SUBPROJECTS MITK-US + INCLUDE_DIRS Qmitk + DEPENDS MitkUS Qmitk QmitkExt + QT_MODULE + GENERATED_CPP ${TOOL_GUI_CPPS} ${TOOL_CPPS} +) + diff --git a/Modules/USUI/Qmitk/QmitkUSDeviceListWidget.cpp b/Modules/USUI/Qmitk/QmitkUSDeviceListWidget.cpp new file mode 100644 index 0000000000..75acd872b2 --- /dev/null +++ b/Modules/USUI/Qmitk/QmitkUSDeviceListWidget.cpp @@ -0,0 +1,167 @@ +/*=================================================================== + +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 QmitkUSDeviceListWidget::VIEW_ID = "org.mitk.views.QmitkUSDeviceListWidget"; + +QmitkUSDeviceListWidget::QmitkUSDeviceListWidget(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(); + +} + +QmitkUSDeviceListWidget::~QmitkUSDeviceListWidget() +{ + +} + +//////////////////// INITIALIZATION ///////////////////// + +void QmitkUSDeviceListWidget::CreateQtPartControl(QWidget *parent) +{ + if (!m_Controls) + { + // create GUI widgets + m_Controls = new Ui::QmitkUSDeviceListWidgetControls; + m_Controls->setupUi(parent); + this->CreateConnections(); + } +} + +void QmitkUSDeviceListWidget::CreateConnections() +{ + if ( m_Controls ) + { + connect( m_Controls->m_DeviceList, SIGNAL(currentItemChanged( QListWidgetItem *, QListWidgetItem *)), this, SLOT(OnDeviceSelectionChanged()) ); + } +} + +void QmitkUSDeviceListWidget::Initialize(std::string filter) +{ + m_Filter = filter; + m_MitkUSContext->AddServiceListener(this, &QmitkUSDeviceListWidget::OnServiceEvent, m_Filter); +} + + +///////////////////////// Getter & Setter ///////////////////////////////// + +mitk::USDevice::Pointer QmitkUSDeviceListWidget::GetSelectedDevice() +{ + return this->GetDeviceForListItem(this->m_Controls->m_DeviceList->currentItem()); +} + +///////////// Methods & Slots Handling Direct Interaction ///////////////// + + +void QmitkUSDeviceListWidget::OnDeviceSelectionChanged(){ + mitk::USDevice::Pointer device = this->GetDeviceForListItem(this->m_Controls->m_DeviceList->currentItem()); + if (device.IsNull()) return; + emit (DeviceSelected(device)); +} + + +///////////////// Methods & Slots Handling Logic ////////////////////////// + +void QmitkUSDeviceListWidget::OnServiceEvent(const mitk::ServiceEvent event){ + // Empty ListWidget + this->m_ListContent.clear(); + m_Controls->m_DeviceList->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_DeviceList->addItem(newItem); + // Construct link and add to internal List for reference + QmitkUSDeviceListWidget::DeviceListLink link; + link.device = it->GetPointer(); + link.item = newItem; + m_ListContent.push_back(link); + } +} + + +/////////////////////// HOUSEHOLDING CODE ///////////////////////////////// + +QListWidgetItem* QmitkUSDeviceListWidget::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 QmitkUSDeviceListWidget::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; +} + + +std::vector QmitkUSDeviceListWidget::GetAllRegisteredDevices(){ + + //Get Service References + std::list serviceRefs = m_MitkUSContext->GetServiceReferences(m_Filter); + + // 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/Modules/USUI/Qmitk/QmitkUSDeviceListWidget.h b/Modules/USUI/Qmitk/QmitkUSDeviceListWidget.h new file mode 100644 index 0000000000..4cdbd671c4 --- /dev/null +++ b/Modules/USUI/Qmitk/QmitkUSDeviceListWidget.h @@ -0,0 +1,158 @@ +/*=================================================================== + +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 _QmitkUSDeviceListWidget_H_INCLUDED +#define _QmitkUSDeviceListWidget_H_INCLUDED + +#include "MitkUSUIExports.h" +#include "ui_QmitkUSDeviceListWidgetControls.h" +#include "mitkUSDevice.h" +#include + +//QT headers +#include +#include + +//mitk header + +//Microservices +#include "usServiceReference.h" +#include "usModuleContext.h" +#include "usServiceEvent.h" +#include "usServiceTrackerCustomizer.h" + +/** +* @brief TODO +* +* @ingroup USUI +*/ +class MitkUSUI_EXPORT QmitkUSDeviceListWidget :public QWidget //, public mitk::ServiceTrackerCustomizer<> // this extension is necessary if one wants to use ServiceTracking instead of filtering +{ + + //this is needed for all Qt objects that should have a MOC object (everything that derives from QObject) + Q_OBJECT + + public: + + static const std::string VIEW_ID; + + QmitkUSDeviceListWidget(QWidget* p = 0, Qt::WindowFlags f1 = 0); + virtual ~QmitkUSDeviceListWidget(); + + /* @brief This method is part of the widget an needs not to be called seperately. */ + virtual void CreateQtPartControl(QWidget *parent); + /* @brief This method is part of the widget an needs not to be called seperately. (Creation of the connections of main and control widget.)*/ + virtual void CreateConnections(); + + /* + * \brief Initializes the connection to the registry. The string filter is an LDAP parsable String, compare mitk::ModuleContext for examples on filtering. + */ + void Initialize(std::string filter); + + /* + * \brief Returns the currently selected device, or null if none is selected. + */ + mitk::USDevice::Pointer GetSelectedDevice(); + + /* + *\brief This Function listens to ServiceRegistry changes and updates the + * list of devices accordingly. + */ + void OnServiceEvent(const mitk::ServiceEvent event); + + + + signals: + + /* + *\brief Emitted when a new device mathing the filter connects + */ + void DeviceConnected(mitk::USDevice::Pointer); + /* + *\brief Emitted directly before device matching the filter disconnects + */ + void DeviceDisconnected(mitk::USDevice::Pointer); + /* + *\brief Emitted when a new device mathing the filter changes it's state. This does of now only compromise changes to activity. + */ + void DeviceChanged(mitk::USDevice::Pointer); + + /* + *\brief Emitted the user selects a device from the list + */ + void DeviceSelected(mitk::USDevice::Pointer); + + + + public slots: + + protected slots: + + /* + \brief Called, when the selection in the devicelist changes + */ + void OnDeviceSelectionChanged(); + + + protected: + + Ui::QmitkUSDeviceListWidgetControls* m_Controls; ///< member holding the UI elements of this widget + + /* + * \brief Internal Structure used to link devices to their QListWidget Items + */ + struct DeviceListLink { + mitk::USDevice::Pointer device; + QListWidgetItem* item; + }; + + /* + * \brief Contains a list of currently active devices and their entires in the list. This is wiped with every ServiceRegistryEvent. + */ + std::vector m_ListContent; + + /* + * \brief Constructs a ListItem from the given device for display in the list of active devices. + */ + QListWidgetItem* ConstructItemFromDevice(mitk::USDevice::Pointer device); + + /* + * \brief Returns the device corresponding to the given ListEntry or null if none was found (which really shouldnt happen). + */ + mitk::USDevice::Pointer GetDeviceForListItem(QListWidgetItem* item); + + //mitk::ServiceTracker ConstructServiceTracker(); + + /* + * \brief Returns a List of US Devices that are currently connected by querying the service registry. + */ + std::vector GetAllRegisteredDevices(); + + + + + private: + + mitk::ModuleContext* m_MitkUSContext; + std::string m_Filter; + + + + + +}; + +#endif // _QmitkUSDeviceListWidget_H_INCLUDED diff --git a/Modules/USUI/Qmitk/QmitkUSDeviceListWidgetControls.ui b/Modules/USUI/Qmitk/QmitkUSDeviceListWidgetControls.ui new file mode 100644 index 0000000000..4d36c2bb5e --- /dev/null +++ b/Modules/USUI/Qmitk/QmitkUSDeviceListWidgetControls.ui @@ -0,0 +1,31 @@ + + + QmitkUSDeviceListWidgetControls + + + + 0 + 0 + 323 + 231 + + + + + 0 + 0 + + + + QmitkUSDeviceListWidget + + + + + + + + + + + diff --git a/Modules/USUI/Qmitk/QmitkUSDeviceManagerWidget.cpp b/Modules/USUI/Qmitk/QmitkUSDeviceManagerWidget.cpp new file mode 100644 index 0000000000..4117083a44 --- /dev/null +++ b/Modules/USUI/Qmitk/QmitkUSDeviceManagerWidget.cpp @@ -0,0 +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; +} + +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/Modules/USUI/Qmitk/QmitkUSDeviceManagerWidget.h b/Modules/USUI/Qmitk/QmitkUSDeviceManagerWidget.h new file mode 100644 index 0000000000..2e8f70d03c --- /dev/null +++ b/Modules/USUI/Qmitk/QmitkUSDeviceManagerWidget.h @@ -0,0 +1,135 @@ +/*=================================================================== + +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 _QmitkUSDeviceManagerWidget_H_INCLUDED +#define _QmitkUSDeviceManagerWidget_H_INCLUDED + +#include "MitkUSUIExports.h" +#include "ui_QmitkUSDeviceManagerWidgetControls.h" +#include "mitkUSDevice.h" +#include + +//QT headers +#include +#include + +//mitk header + +//Microservices +#include "usServiceReference.h" +#include "usModuleContext.h" +#include "usServiceEvent.h" + +/** +* @brief TODO +* +* @ingroup USUI +*/ +class MitkUSUI_EXPORT QmitkUSDeviceManagerWidget :public QWidget //, public mitk::ServiceTrackerCustomizer<> // this extension is necessary if one wants to use ServiceTracking instead of filtering +{ + + //this is needed for all Qt objects that should have a MOC object (everything that derives from QObject) + Q_OBJECT + + public: + + static const std::string VIEW_ID; + + QmitkUSDeviceManagerWidget(QWidget* p = 0, Qt::WindowFlags f1 = 0); + virtual ~QmitkUSDeviceManagerWidget(); + + /* @brief This method is part of the widget an needs not to be called seperately. */ + virtual void CreateQtPartControl(QWidget *parent); + /* @brief This method is part of the widget an needs not to be called seperately. (Creation of the connections of main and control widget.)*/ + virtual void CreateConnections(); + + /* + *\brief This Function listens to ServiceRegistry changes and updates the + * list of devices accordingly. + */ + void OnServiceEvent(const mitk::ServiceEvent event); + + + + signals: + + /* + \brief Sent, when the user clicks "Activate Device" + */ + void USDeviceActivated(); + + public slots: + + protected slots: + + /* + \brief Called, when the button "Activate Device" was clicked + */ + void OnClickedActivateDevice(); + + /* + \brief Called, when the button "Disconnect Device" was clicked + */ + void OnClickedDisconnectDevice(); + + /* + \brief Called, when the selection in the devicelist changes + */ + void OnDeviceSelectionChanged(); + + + protected: + + Ui::QmitkUSDeviceManagerWidgetControls* m_Controls; ///< member holding the UI elements of this widget + + /* + * \brief Internal Structure used to link devices to their QListWidget Items + */ + struct DeviceListLink { + mitk::USDevice::Pointer device; + QListWidgetItem* item; + }; + + /* + * \brief Contains a list of currently active devices and their entires in the list. This is wiped with every ServiceRegistryEvent. + */ + std::vector m_ListContent; + + /* + * \brief Constructs a ListItem from the given device for display in the list of active devices. + */ + QListWidgetItem* ConstructItemFromDevice(mitk::USDevice::Pointer device); + + /* + * \brief Returns the device corresponding to the given ListEntry or null if none was found (which really shouldnt happen). + */ + mitk::USDevice::Pointer GetDeviceForListItem(QListWidgetItem* item); + + //mitk::ServiceTracker ConstructServiceTracker(); + + /* + * \brief Returns a List of US Devices that are currently connected by querying the service registry. + */ + std::vector GetAllRegisteredDevices(); + + private: + + mitk::ModuleContext* m_MitkUSContext; + + +}; + +#endif // _QmitkUSDeviceManagerWidget_H_INCLUDED diff --git a/Modules/USUI/Qmitk/QmitkUSDeviceManagerWidgetControls.ui b/Modules/USUI/Qmitk/QmitkUSDeviceManagerWidgetControls.ui new file mode 100644 index 0000000000..12e83cb191 --- /dev/null +++ b/Modules/USUI/Qmitk/QmitkUSDeviceManagerWidgetControls.ui @@ -0,0 +1,57 @@ + + + QmitkUSDeviceManagerWidgetControls + + + + 0 + 0 + 405 + 231 + + + + + 0 + 0 + + + + QmitkUSDeviceManagerWidget + + + + + + + 11 + + + + Connected Devices: + + + + + + + Activate Device + + + + + + + Disconnect Device + + + + + + + + + + + + diff --git a/Modules/USUI/Qmitk/QmitkUSNewVideoDeviceWidget.cpp b/Modules/USUI/Qmitk/QmitkUSNewVideoDeviceWidget.cpp new file mode 100644 index 0000000000..d365b0b674 --- /dev/null +++ b/Modules/USUI/Qmitk/QmitkUSNewVideoDeviceWidget.cpp @@ -0,0 +1,155 @@ +/*=================================================================== + +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 + +//QT headers + + +//mitk headers + + +//itk headers + + +const std::string QmitkUSNewVideoDeviceWidget::VIEW_ID = "org.mitk.views.QmitkUSNewVideoDeviceWidget"; + +QmitkUSNewVideoDeviceWidget::QmitkUSNewVideoDeviceWidget(QWidget* parent, Qt::WindowFlags f): QWidget(parent, f) +{ + m_Controls = NULL; + CreateQtPartControl(this); +} + +QmitkUSNewVideoDeviceWidget::~QmitkUSNewVideoDeviceWidget() +{ +} + +//////////////////// INITIALIZATION ///////////////////// + + +void QmitkUSNewVideoDeviceWidget::CreateQtPartControl(QWidget *parent) +{ + if (!m_Controls) + { + // create GUI widgets + m_Controls = new Ui::QmitkUSNewVideoDeviceWidgetControls; + m_Controls->setupUi(parent); + this->CreateConnections(); + } +} + +void QmitkUSNewVideoDeviceWidget::CreateConnections() +{ + if ( m_Controls ) + { + connect( m_Controls->m_BtnDone, SIGNAL(clicked()), this, SLOT(OnClickedDone()) ); + connect( m_Controls->m_BtnCancel, SIGNAL(clicked()), this, SLOT(OnClickedCancel()) ); + connect( m_Controls->m_RadioDeviceSource, SIGNAL(clicked()), this, SLOT(OnDeviceTypeSelection()) ); + connect( m_Controls->m_RadioFileSource, SIGNAL(clicked()), this, SLOT(OnDeviceTypeSelection()) ); + + } + // Hide & show stuff + m_Controls->m_FilePathSelector->setVisible(false); +} + + +///////////// Methods & Slots Handling Direct Interaction ///////////////// + +void QmitkUSNewVideoDeviceWidget::OnClickedDone(){ + m_Active = false; + MITK_INFO << "NewDeviceWidget: ClickedDone()"; + + // Assemble Metadata + mitk::USImageMetadata::Pointer metadata = mitk::USImageMetadata::New(); + metadata->SetDeviceComment(m_Controls->m_Comment->text().toStdString()); + metadata->SetDeviceModel(m_Controls->m_Model->text().toStdString()); + metadata->SetDeviceManufacturer(m_Controls->m_Manufacturer->text().toStdString()); + metadata->SetProbeName(m_Controls->m_Probe->text().toStdString()); + metadata->SetZoom(m_Controls->m_Zoom->text().toStdString()); + + + // Create Device + mitk::USVideoDevice::Pointer newDevice; + if (m_Controls->m_RadioDeviceSource->isChecked()){ + int deviceID = m_Controls->m_DeviceSelector->value(); + newDevice = mitk::USVideoDevice::New(deviceID, metadata); + } else { + std::string filepath = m_Controls->m_FilePathSelector->text().toStdString(); + newDevice = mitk::USVideoDevice::New(filepath, metadata); + } + + newDevice->Connect(); + + emit Finished(); +} + +void QmitkUSNewVideoDeviceWidget::OnClickedCancel(){ + m_TargetDevice = 0; + m_Active = false; + MITK_INFO << "NewDeviceWidget: OnClickedCancel()"; + emit Finished(); + +} + +void QmitkUSNewVideoDeviceWidget::OnDeviceTypeSelection(){ + m_Controls->m_FilePathSelector->setVisible(m_Controls->m_RadioFileSource->isChecked()); + m_Controls->m_DeviceSelector->setVisible(m_Controls->m_RadioDeviceSource->isChecked()); +} + + + +///////////////// Methods & Slots Handling Logic ////////////////////////// + + +void QmitkUSNewVideoDeviceWidget::EditDevice(mitk::USDevice::Pointer device) +{ + // If no VideoDevice is given, throw an exception + if (device->GetDeviceClass().compare("org.mitk.modules.us.USVideoDevice") != 0){ + // TODO Alert if bad path + mitkThrow() << "NewVideoDevcieWidget recieved an incompatible Device Type to edit. Devicetype was: " << device->GetDeviceClass(); + } + MITK_INFO << "NewDeviceWidget: EditDevice()"; + m_TargetDevice = static_cast (device.GetPointer()); + m_Active = true; +} + + +void QmitkUSNewVideoDeviceWidget::CreateNewDevice() +{ + MITK_INFO << "NewDeviceWidget: CreateNewDevice()"; + m_TargetDevice = 0; + InitFields(mitk::USImageMetadata::New()); + m_Active = true; +} + + +/////////////////////// HOUSEHOLDING CODE /////////////////////////////// + +QListWidgetItem* QmitkUSNewVideoDeviceWidget::ConstructItemFromDevice(mitk::USDevice::Pointer device){ + QListWidgetItem *result = new QListWidgetItem; + std::string text = device->GetDeviceManufacturer() + "|" + device->GetDeviceModel(); + result->setText(text.c_str()); + return result; +} + +void QmitkUSNewVideoDeviceWidget::InitFields(mitk::USImageMetadata::Pointer metadata){ + this->m_Controls->m_Manufacturer->setText (metadata->GetDeviceManufacturer().c_str()); + this->m_Controls->m_Model->setText (metadata->GetDeviceModel().c_str()); + this->m_Controls->m_Comment->setText (metadata->GetDeviceComment().c_str()); + this->m_Controls->m_Probe->setText (metadata->GetProbeName().c_str()); + this->m_Controls->m_Zoom->setText (metadata->GetZoom().c_str()); +} diff --git a/Modules/USUI/Qmitk/QmitkUSNewVideoDeviceWidget.h b/Modules/USUI/Qmitk/QmitkUSNewVideoDeviceWidget.h new file mode 100644 index 0000000000..233129d4c3 --- /dev/null +++ b/Modules/USUI/Qmitk/QmitkUSNewVideoDeviceWidget.h @@ -0,0 +1,122 @@ +/*=================================================================== + +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 _QmitkUSNewVideoDeviceWidget_H_INCLUDED +#define _QmitkUSNewVideoDeviceWidget_H_INCLUDED + +#include "MitkUSUIExports.h" +#include "ui_QmitkUSNewVideoDeviceWidgetControls.h" +#include "mitkUSVideoDevice.h" +#include "mitkUSImageMetadata.h" + +//QT headers +#include +#include + +//mitk header + +/** +* @brief TODO +* +* @ingroup USUI +*/ +class MitkUSUI_EXPORT QmitkUSNewVideoDeviceWidget :public QWidget +{ + + //this is needed for all Qt objects that should have a MOC object (everything that derives from QObject) + Q_OBJECT + + public: + + static const std::string VIEW_ID; + + QmitkUSNewVideoDeviceWidget(QWidget* p = 0, Qt::WindowFlags f1 = 0); + virtual ~QmitkUSNewVideoDeviceWidget(); + + /* @brief This method is part of the widget an needs not to be called seperately. */ + virtual void CreateQtPartControl(QWidget *parent); + /* @brief This method is part of the widget an needs not to be called seperately. (Creation of the connections of main and control widget.)*/ + virtual void CreateConnections(); + + signals: + + void Finished(); + + public slots: + + /* + \brief Activates the widget and displays the given device's Data to edit. + */ + void EditDevice(mitk::USDevice::Pointer device); + + /* + \brief Activates the widget with fields empty. + */ + void CreateNewDevice(); + + protected slots: + + /* + \brief Called, when the the user clicks the "Done" button (Labeled either "Add Device" or "Edit Device", depending on the situation. + */ + void OnClickedDone(); + + /* + \brief Called, when the button "Cancel" was clicked + */ + void OnClickedCancel(); + + /* + \brief Called, when the Use selects one of the Radiobuttons + */ + void OnDeviceTypeSelection(); + + + + + + protected: + + Ui::QmitkUSNewVideoDeviceWidgetControls* m_Controls; ///< member holding the UI elements of this widget + + /* + \brief Constructs a ListItem from the given devie for display in the list of active devices + */ + QListWidgetItem* ConstructItemFromDevice(mitk::USDevice::Pointer device); + + /* + \brief Initializes the Widget's ListItems with the given Metadata Object. + */ + void InitFields(mitk::USImageMetadata::Pointer); + + /* + \brief Displays whether this widget is active or not. It gets activated by either sending a Signal to + * the "CreateNewDevice" Slot or to the "EditDevice" Slot. If the user finishes editing the device, a + * "EditingComplete" Signal is sent, and the widget is set to inactive again. Clicking Cancel also + * deactivates it. + */ + bool m_Active; + + /** + * \brief This is the device to edit. It is either the device transmitted in the "EditDevice" signal, or a new one + * if the "CreateNewDevice slot was called. + */ + mitk::USVideoDevice::Pointer m_TargetDevice; + + +}; + +#endif // _QmitkUSNewVideoDeviceWidget_H_INCLUDED diff --git a/Modules/USUI/Qmitk/QmitkUSNewVideoDeviceWidgetControls.ui b/Modules/USUI/Qmitk/QmitkUSNewVideoDeviceWidgetControls.ui new file mode 100644 index 0000000000..08f540f348 --- /dev/null +++ b/Modules/USUI/Qmitk/QmitkUSNewVideoDeviceWidgetControls.ui @@ -0,0 +1,173 @@ + + + QmitkUSNewVideoDeviceWidgetControls + + + + 0 + 0 + 405 + 404 + + + + + 0 + 0 + + + + QmitkUSNewVideoDeviceWidget + + + + + + Metadata + + + + + + + 50 + false + true + + + + Device Information: + + + + + + + Manufacturer + + + + + + + + + + Model + + + + + + + + + + Comment + + + + + + + + + + + true + + + + Probe Information: + + + + + + + Probe + + + + + + + + + + Zoom + + + + + + + + + + + + + GroupBox + + + + + + C://Builds//MITK-superbuild//CMakeExternals//Source//MITK-Data//CommonTestData//bunny_320x240.avi + + + + + + + -1 + + + 10 + + + -1 + + + + + + + From Device: + + + true + + + + + + + From File: + + + + + + + + + + Add Device + + + + + + + Cancel + + + + + + + + + diff --git a/Modules/USUI/files.cmake b/Modules/USUI/files.cmake new file mode 100644 index 0000000000..fb6be5c93c --- /dev/null +++ b/Modules/USUI/files.cmake @@ -0,0 +1,22 @@ + +set(CPP_FILES + Qmitk/QmitkUSDeviceManagerWidget.cpp + Qmitk/QmitkUSNewVideoDeviceWidget.cpp + Qmitk/QmitkUSDeviceListWidget.cpp +) +set(UI_FILES + Qmitk/QmitkUSDeviceListWidgetControls.ui + Qmitk/QmitkUSDeviceManagerWidgetControls.ui + Qmitk/QmitkUSNewVideoDeviceWidgetControls.ui +) + +set(MOC_H_FILES + Qmitk/QmitkUSDeviceManagerWidget.h + Qmitk/QmitkUSDeviceListWidget.h + Qmitk/QmitkUSNewVideoDeviceWidget.h +) + +# uncomment the following line if you want to use Qt resources +set(QRC_FILES +# resources/QmitkToFUtilWidget.qrc +) diff --git a/Plugins/PluginList.cmake b/Plugins/PluginList.cmake index 67b5e41db5..4d396b4932 100644 --- a/Plugins/PluginList.cmake +++ b/Plugins/PluginList.cmake @@ -1,41 +1,42 @@ # Plug-ins must be ordered according to their dependencies set(MITK_EXT_PLUGINS org.mitk.core.services:ON org.mitk.gui.common:ON org.mitk.planarfigure:ON org.mitk.core.ext:OFF org.mitk.core.jobs:OFF org.mitk.diffusionimaging:OFF org.mitk.gui.qt.application:ON org.mitk.gui.qt.coreapplication:OFF org.mitk.gui.qt.ext:OFF org.mitk.gui.qt.extapplication:OFF org.mitk.gui.qt.common:ON org.mitk.gui.qt.stdmultiwidgeteditor:ON org.mitk.gui.qt.common.legacy:OFF org.mitk.gui.qt.diffusionimagingapp:OFF org.mitk.gui.qt.datamanager:ON org.mitk.gui.qt.basicimageprocessing:OFF org.mitk.gui.qt.diffusionimaging:OFF org.mitk.gui.qt.dtiatlasapp:OFF org.mitk.gui.qt.examples:OFF org.mitk.gui.qt.examplesopencv:OFF org.mitk.gui.qt.igtexamples:OFF org.mitk.gui.qt.igttracking:OFF org.mitk.gui.qt.imagecropper:OFF org.mitk.gui.qt.imagenavigator:ON org.mitk.gui.qt.materialeditor:OFF org.mitk.gui.qt.measurementtoolbox:OFF org.mitk.gui.qt.meshdecimation:OFF org.mitk.gui.qt.moviemaker:OFF org.mitk.gui.qt.pointsetinteraction:OFF org.mitk.gui.qt.python.console:OFF org.mitk.gui.qt.registration:OFF org.mitk.gui.qt.segmentation:OFF org.mitk.gui.qt.toftutorial:OFF org.mitk.gui.qt.tofutil:OFF org.mitk.gui.qt.ugvisualization:OFF + org.mitk.gui.qt.ultrasound:OFF org.mitk.gui.qt.volumevisualization:OFF ) diff --git a/Plugins/org.mitk.gui.qt.ultrasound/CMakeLists.txt b/Plugins/org.mitk.gui.qt.ultrasound/CMakeLists.txt new file mode 100644 index 0000000000..45ce803469 --- /dev/null +++ b/Plugins/org.mitk.gui.qt.ultrasound/CMakeLists.txt @@ -0,0 +1,7 @@ +project(org_mitk_gui_qt_ultrasound) + +MACRO_CREATE_MITK_CTK_PLUGIN( + EXPORT_DIRECTIVE ULTRASOUND_EXPORT + EXPORTED_INCLUDE_SUFFIXES src + MODULE_DEPENDENCIES QmitkExt MitkUS MitkUSUI +) diff --git a/Plugins/org.mitk.gui.qt.ultrasound/documentation/UserManual/Manual.dox b/Plugins/org.mitk.gui.qt.ultrasound/documentation/UserManual/Manual.dox new file mode 100644 index 0000000000..42934f7778 --- /dev/null +++ b/Plugins/org.mitk.gui.qt.ultrasound/documentation/UserManual/Manual.dox @@ -0,0 +1,19 @@ +/** +\bundlemainpage{org.mitk.gui.qt.ultrasound} Ultrasound + +\image html icon.xpm "Icon of Ultrasound" + +Available sections: + - \ref org.mitk.gui.qt.ultrasoundOverview + +\section org.mitk.gui.qt.ultrasoundOverview +Describe the features of your awesome plugin here +
    +
  • Increases productivity +
  • Creates beautiful images +
  • Generates PhD thesis +
  • Brings world peace +
+ +*/ + diff --git a/Plugins/org.mitk.gui.qt.ultrasound/documentation/UserManual/icon.xpm b/Plugins/org.mitk.gui.qt.ultrasound/documentation/UserManual/icon.xpm new file mode 100644 index 0000000000..9057c20bc6 --- /dev/null +++ b/Plugins/org.mitk.gui.qt.ultrasound/documentation/UserManual/icon.xpm @@ -0,0 +1,21 @@ +/* XPM */ +static const char * icon_xpm[] = { +"16 16 2 1", +" c #FF0000", +". c #000000", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" ", +" "}; diff --git a/Plugins/org.mitk.gui.qt.ultrasound/documentation/doxygen/modules.dox b/Plugins/org.mitk.gui.qt.ultrasound/documentation/doxygen/modules.dox new file mode 100644 index 0000000000..22a80e24b6 --- /dev/null +++ b/Plugins/org.mitk.gui.qt.ultrasound/documentation/doxygen/modules.dox @@ -0,0 +1,16 @@ +/** + \defgroup org_mitk_gui_qt_ultrasound org.mitk.gui.qt.ultrasound + \ingroup MITKPlugins + + \brief Describe your plugin here. + +*/ + +/** + \defgroup org_mitk_gui_qt_ultrasound_internal Internal + \ingroup org_mitk_gui_qt_ultrasound + + \brief This subcategory includes the internal classes of the org.mitk.gui.qt.ultrasound plugin. Other + plugins must not rely on these classes. They contain implementation details and their interface + may change at any time. We mean it. +*/ diff --git a/Plugins/org.mitk.gui.qt.ultrasound/files.cmake b/Plugins/org.mitk.gui.qt.ultrasound/files.cmake new file mode 100644 index 0000000000..d39df0669c --- /dev/null +++ b/Plugins/org.mitk.gui.qt.ultrasound/files.cmake @@ -0,0 +1,43 @@ +set(SRC_CPP_FILES + +) + +set(INTERNAL_CPP_FILES + org_mitk_gui_qt_ultrasound_Activator.cpp + UltrasoundSupport.cpp +) + +set(UI_FILES + src/internal/UltrasoundSupportControls.ui +) + +set(MOC_H_FILES + src/internal/org_mitk_gui_qt_ultrasound_Activator.h + src/internal/UltrasoundSupport.h +) + +# list of resource files which can be used by the plug-in +# system without loading the plug-ins shared library, +# for example the icon used in the menu and tabs for the +# plug-in views in the workbench +set(CACHED_RESOURCE_FILES + resources/icon.xpm + plugin.xml +) + +# list of Qt .qrc files which contain additional resources +# specific to this plugin +set(QRC_FILES + +) + +set(CPP_FILES ) + +foreach(file ${SRC_CPP_FILES}) + set(CPP_FILES ${CPP_FILES} src/${file}) +endforeach(file ${SRC_CPP_FILES}) + +foreach(file ${INTERNAL_CPP_FILES}) + set(CPP_FILES ${CPP_FILES} src/internal/${file}) +endforeach(file ${INTERNAL_CPP_FILES}) + diff --git a/Plugins/org.mitk.gui.qt.ultrasound/manifest_headers.cmake b/Plugins/org.mitk.gui.qt.ultrasound/manifest_headers.cmake new file mode 100644 index 0000000000..182113f62b --- /dev/null +++ b/Plugins/org.mitk.gui.qt.ultrasound/manifest_headers.cmake @@ -0,0 +1,5 @@ +set(Plugin-Name "Ultrasound") +set(Plugin-Version "0.1") +set(Plugin-Vendor "DKFZ, Medical and Biological Informatics") +set(Plugin-ContactAddress "") +set(Require-Plugin org.mitk.gui.qt.common) diff --git a/Plugins/org.mitk.gui.qt.ultrasound/plugin.xml b/Plugins/org.mitk.gui.qt.ultrasound/plugin.xml new file mode 100644 index 0000000000..12e452b3d5 --- /dev/null +++ b/Plugins/org.mitk.gui.qt.ultrasound/plugin.xml @@ -0,0 +1,11 @@ + + + + + + + + diff --git a/Plugins/org.mitk.gui.qt.ultrasound/resources/icon.xpm b/Plugins/org.mitk.gui.qt.ultrasound/resources/icon.xpm new file mode 100644 index 0000000000..54a1bcb8b9 --- /dev/null +++ b/Plugins/org.mitk.gui.qt.ultrasound/resources/icon.xpm @@ -0,0 +1,105 @@ +/* XPM */ +static char * C:\Builds\MITK\Plugins\org_mitk_gui_qt_ultrasound\resources\icon_xpm[] = { +"100 100 2 1", +" c None", +". c #000000", +" .......................................................................................... ", +" .......................................................................................... ", +" .......................................................................................... ", +" ... .. ", +" ... .. ", +" ... .. ", +" ... .. ", +" ... .. ", +" ... .. .. .. ", +" ... .... ..... .. ", +" ... ................... .. ", +" ... ..................... .. ", +" ... ....................... .. ", +" ... ......................... .. ", +" ... ........................... .. ", +" ... ............................. .. ", +" ... ............................... .. ", +" ... ............ .................. .. ", +" ... ............ ........ .... .. ", +" ... ............. ....... .... .. ", +" ... .............. ...... .... .. ", +" ... ............... ..... .... .. ", +" ... ................ ..... .... .. ", +" ... ................ ..... ..... .. ", +" ... ................. .... ...... .. ", +" ... .................. .... ....... .. ", +" ... ................... .... ........ .. ", +" ... .......... ...... ... .......... .. ", +" ... .. ...... ... ........... .. ", +" ... .. ...... .. ............. .. ", +" ... ... ...... ... ................ .. ", +" ... .... ....... ......................... .. ", +" ... ..... ...... .......................... .. ", +" ... ....... ..... .......................... .. ", +" ... ................. ... .......................... .. ", +" ... .................. .. ........................... .. ", +" ... .................. .......................... .. ", +" ... ................. ......................... .. ", +" ... ................ ......................... .. ", +" ... ............... ........................ .. ", +" ... ............. ......................... .. ", +" ... ............ ........................ .. ", +" ... ........... ......................... .. ", +" ... .......... ........................ .. ", +" ... ........ ......................... .. ", +" ... ....... ....................... .. ", +" ... ....... ....................... .. ", +" ... ...... ....................... .. ", +" ... ........................... .. .. ", +" ... ................... ... .. ", +" ... ..... .. ", +" ... ...... .. ", +" ... ....... .. ", +" ... ....... .. ", +" ... ........ .. ", +" ... ......... .. ", +" ... ......... .. ", +" ... ......... .. ", +" ... ......... .. ", +" ... ......... .. ", +" ... ......... .. ", +" ... ......... .. ", +" ... ......... .. ", +" ... .......... .. ", +" ... ......... .. ", +" ... ......... .. ", +" ... .......... .. ", +" ... .......... ... ", +" .......................................................................................... ", +" .......................................................................................... ", +" ................................. ", +" ................................. ", +" .................................. ", +" ................................. ", +" .................................. ", +" .................................. ", +" ................................. ", +" ................................. ", +" ................................ ", +" ................................ ", +" ................................ ", +" ............................... ", +" .............................. ", +" .............................. ", +" ............................ ", +" ............................ ", +" ........................... ", +" ........................... ", +" .......................... ", +" .......................... ", +" ......................... ", +" ....................... ", +" ..................... ", +" ..................... ", +" .................... ", +" ..................... ", +" ..................... ", +" .................... ", +" ..................... ", +" ..................... "}; diff --git a/Plugins/org.mitk.gui.qt.ultrasound/src/internal/UltrasoundSupport.cpp b/Plugins/org.mitk.gui.qt.ultrasound/src/internal/UltrasoundSupport.cpp new file mode 100644 index 0000000000..8afd157b3b --- /dev/null +++ b/Plugins/org.mitk.gui.qt.ultrasound/src/internal/UltrasoundSupport.cpp @@ -0,0 +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->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(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 new file mode 100644 index 0000000000..2ffb46bc06 --- /dev/null +++ b/Plugins/org.mitk.gui.qt.ultrasound/src/internal/UltrasoundSupport.h @@ -0,0 +1,91 @@ +/*========================================================================= + +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. + +=========================================================================*/ + + +#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; + + 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 new file mode 100644 index 0000000000..7a96cde657 --- /dev/null +++ b/Plugins/org.mitk.gui.qt.ultrasound/src/internal/UltrasoundSupportControls.ui @@ -0,0 +1,143 @@ + + + UltrasoundSupportControls + + + + 0 + 0 + 467 + 461 + + + + + 0 + 0 + + + + QmitkTemplate + + + + + + 1 + + + + Device Management + + + + + + + 12 + 75 + true + + + + Connected Devices: + + + + + + + + + + New Device + + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + US Imaging + + + + QFormLayout::AllNonFixedFieldsGrow + + + + + + 12 + 75 + true + + + + Active Video Devices: + + + + + + + + 0 + 0 + + + + + + + + View + + + + + + + + + + + + + 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 new file mode 100644 index 0000000000..b77473cc4d --- /dev/null +++ b/Plugins/org.mitk.gui.qt.ultrasound/src/internal/org_mitk_gui_qt_ultrasound_Activator.cpp @@ -0,0 +1,39 @@ +/*========================================================================= + +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. + +=========================================================================*/ + + +#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 new file mode 100644 index 0000000000..2bd3b8741e --- /dev/null +++ b/Plugins/org.mitk.gui.qt.ultrasound/src/internal/org_mitk_gui_qt_ultrasound_Activator.h @@ -0,0 +1,41 @@ +/*========================================================================= + +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. + +=========================================================================*/ + + +#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