diff --git a/Modules/US/Testing/mitkUSImageVideoSourceTest.cpp b/Modules/US/Testing/mitkUSImageVideoSourceTest.cpp index 636725a81f..433c6eeaf6 100644 --- a/Modules/US/Testing/mitkUSImageVideoSourceTest.cpp +++ b/Modules/US/Testing/mitkUSImageVideoSourceTest.cpp @@ -1,58 +1,64 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit Language: C++ Date: $Date: 2008-02-25 17:27:17 +0100 (Mo, 25 Feb 2008) $ Version: $Revision: 7837 $ 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 "mitkUSImageVideoSource.h" #include "mitkTestingMacros.h" class mitkUSImageVideoSourceTestClass { public: - // Anm: Implementierung der einzelnen Testmethoden - static void TestInstantiation() { // let's create an object of our class mitk::USImageVideoSource::Pointer usSource = mitk::USImageVideoSource::New(); MITK_TEST_CONDITION_REQUIRED(usSource.IsNotNull(), "USImageVideoSource should not be null after instantiation"); } static void TestOpenVideoFile() { mitk::USImageVideoSource::Pointer usSource = mitk::USImageVideoSource::New(); // "C:\\Users\\maerz\\Videos\\Debut\\us.avi" - usSource->OpenVideoFile("C:\\Users\\maerz\\Videos\\Debut\\us.avi"); + usSource->SetVideoFileInput("C:\\Users\\maerz\\Videos\\Debut\\us.avi"); MITK_TEST_CONDITION_REQUIRED(usSource->GetIsVideoReady(), "USImageVideoSource should have isVideoReady flag set after opening a Video File"); } + static void TestOpenDevice() + { + mitk::USImageVideoSource::Pointer usSource = mitk::USImageVideoSource::New(); + usSource->SetCameraInput(-1); + MITK_TEST_CONDITION_REQUIRED(usSource->GetIsVideoReady(), "USImageVideoSource should have isVideoReady flag set after opening a Camera device"); + } + }; /** * This function is testing methods of the class USImageVideoSource. */ int mitkUSImageVideoSourceTest(int /* argc */, char* /*argv*/[]) { MITK_TEST_BEGIN("mitkUSImageVideoSourceTest"); mitkUSImageVideoSourceTestClass::TestInstantiation(); mitkUSImageVideoSourceTestClass::TestOpenVideoFile(); + mitkUSImageVideoSourceTestClass::TestOpenDevice(); MITK_TEST_END(); } \ No newline at end of file diff --git a/Modules/US/USFilters/mitkUSImageVideoSource.cpp b/Modules/US/USFilters/mitkUSImageVideoSource.cpp index 41df978a27..84c0d545c5 100644 --- a/Modules/US/USFilters/mitkUSImageVideoSource.cpp +++ b/Modules/US/USFilters/mitkUSImageVideoSource.cpp @@ -1,101 +1,112 @@ /*========================================================================= 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 "mitkUSImageVideoSource.h" mitk::USImageVideoSource::USImageVideoSource() : itk::ProcessObject() { m_IsVideoReady = false; m_IsMetadataReady = false; m_IsGeometryReady = false; } mitk::USImageVideoSource::~USImageVideoSource() { } -void mitk::USImageVideoSource::OpenVideoFile(std::string path) +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); //wenn kein Bild erscheint, Passwort für G eingeben + 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){ + this->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* mitk::USImageVideoSource::GetOutput() { if (this->GetNumberOfOutputs() < 1) return NULL; return static_cast(this->ProcessObject::GetOutput(0)); } mitk::USImage* mitk::USImageVideoSource::GetOutput(unsigned int idx) { if (this->GetNumberOfOutputs() < 1) return NULL; return static_cast(this->ProcessObject::GetOutput(idx)); } void mitk::USImageVideoSource::GraftOutput(itk::DataObject *graft) { this->GraftNthOutput(0, graft); } void mitk::USImageVideoSource::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::USImageVideoSource::MakeOutput( unsigned int /*idx */) { mitk::USImage::Pointer p = mitk::USImage::New(); return static_cast(p.GetPointer()); } \ No newline at end of file diff --git a/Modules/US/USFilters/mitkUSImageVideoSource.h b/Modules/US/USFilters/mitkUSImageVideoSource.h index e0f0e1d6d2..a6b6c903f4 100644 --- a/Modules/US/USFilters/mitkUSImageVideoSource.h +++ b/Modules/US/USFilters/mitkUSImageVideoSource.h @@ -1,112 +1,119 @@ /*========================================================================= 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 MITKUSImageVideoSource_H_HEADER_INCLUDED_ #define MITKUSImageVideoSource_H_HEADER_INCLUDED_ #include #include "mitkUSImage.h" #include "mitkOpenCVVideoSource.h" namespace mitk { /**Documentation * \brief TODO * * \ingroup US */ class MitkUS_EXPORT USImageVideoSource : public itk::ProcessObject { public: mitkClassMacro(USImageVideoSource, itk::ProcessObject); itkNewMacro(Self); /** *\brief Opens a video file for streaming. If nothing goes wrong, the * VideoSource is ready to deliver images after calling this function. */ - void OpenVideoFile(std::string path); + void SetVideoFileInput(std::string path); + + /** + *\brief Opens a video device for streaming. Takes the Device id. Try -1 for "grab the first you can get" + * which works quite well if only one device is available. If nothing goes wrong, the + * VideoSource is ready to deliver images after calling this function. + */ + void SetCameraInput(int deviceID); /** *\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 itkGetMacro(OpenCVVideoSource, mitk::OpenCVVideoSource::Pointer); itkSetMacro(OpenCVVideoSource, mitk::OpenCVVideoSource::Pointer); itkGetMacro(IsVideoReady, bool); itkGetMacro(IsMetadataReady, bool); itkGetMacro(IsGeometryReady, bool); protected: USImageVideoSource(); virtual ~USImageVideoSource(); /** * \brief The source of the video */ mitk::OpenCVVideoSource::Pointer m_OpenCVVideoSource; /** * \brief The Following flags are used internally, to assure that all necessary steps are taken before capturing */ bool m_IsVideoReady; bool m_IsMetadataReady; bool m_IsGeometryReady; }; } // namespace mitk #endif /* MITKUSImageVideoSource_H_HEADER_INCLUDED_ */ \ No newline at end of file diff --git a/Modules/US/USFilters/mitkUSVideoDevice.cpp b/Modules/US/USFilters/mitkUSVideoDevice.cpp new file mode 100644 index 0000000000..01594c389a --- /dev/null +++ b/Modules/US/USFilters/mitkUSVideoDevice.cpp @@ -0,0 +1,34 @@ +/*========================================================================= + +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 "mitkUSVideoDevice.h" +#include + + +mitk::USVideoDevice::USVideoDevice(int deviceNumber) : itk::Object() +{ + m_Source = mitk::USImageVideoSource::New(); + +} + + + + +mitk::USVideoDevice::~USVideoDevice() +{ + +} diff --git a/Modules/US/USFilters/mitkUSVideoDevice.h b/Modules/US/USFilters/mitkUSVideoDevice.h new file mode 100644 index 0000000000..da8480b52f --- /dev/null +++ b/Modules/US/USFilters/mitkUSVideoDevice.h @@ -0,0 +1,58 @@ +/*========================================================================= + +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 MITKUSVideoDevice_H_HEADER_INCLUDED_ +#define MITKUSVideoDevice_H_HEADER_INCLUDED_ + +#include +#include +#include +#include +#include "mitkUSImageVideoSource.h" + +namespace mitk { + + /**Documentation + * \brief TODO + * \ingroup US + */ + class MitkUS_EXPORT USVideoDevice : public itk::Object + { + public: + mitkClassMacro(USVideoDevice,itk::Object); + mitkNewMacro1Param(Self, int); + + + + + //## getter and setter ## + + // itkGetMacro(Name, std::string); + // itkSetMacro(Name, std::string); + + protected: + USVideoDevice(int deviceNumber); + virtual ~USVideoDevice(); + + mitk::USImageVideoSource::Pointer m_Source; + + + + }; +} // namespace mitk +#endif \ No newline at end of file diff --git a/Modules/US/files.cmake b/Modules/US/files.cmake index 62f3ffd5f1..0c63678665 100644 --- a/Modules/US/files.cmake +++ b/Modules/US/files.cmake @@ -1,8 +1,9 @@ SET(CPP_FILES USFilters/mitkUSImage.cpp USFilters/mitkUSImage2D.cpp USFilters/mitkUSImageVideoSource.cpp USFilters/mitkUSImageMetadata.cpp USFilters/mitkUSDevice.cpp +USFilters/mitkUSVideoDevice.cpp USFilters/mitkUSProbe.cpp )