diff --git a/Modules/ToFHardware/Testing/files.cmake b/Modules/ToFHardware/Testing/files.cmake index 3ce7f37e36..bf326b3022 100644 --- a/Modules/ToFHardware/Testing/files.cmake +++ b/Modules/ToFHardware/Testing/files.cmake @@ -1,24 +1,28 @@ SET(MODULE_TESTS + mitkThreadedToFRawDataReconstructionTest.cpp mitkToFCameraMITKPlayerControllerTest.cpp mitkToFCameraMITKPlayerDeviceTest.cpp mitkToFCameraPMDCamBoardControllerTest.cpp mitkToFCameraPMDCamBoardDeviceTest.cpp + mitkToFCameraPMDRawDataCamBoardDeviceTest.cpp mitkToFCameraPMDCamCubeControllerTest.cpp mitkToFCameraPMDCamCubeDeviceTest.cpp + mitkToFCameraPMDRawDataCamCubeDeviceTest.cpp mitkToFCameraPMDControllerTest.cpp mitkToFCameraPMDDeviceTest.cpp + mitkToFCameraPMDRawDataDeviceTest.cpp mitkToFCameraPMDMITKPlayerControllerTest.cpp mitkToFCameraPMDMITKPlayerDeviceTest.cpp mitkToFCameraPMDO3ControllerTest.cpp mitkToFCameraPMDO3DeviceTest.cpp mitkToFCameraPMDPlayerControllerTest.cpp mitkToFCameraPMDPlayerDeviceTest.cpp mitkToFImageCsvWriterTest.cpp mitkToFImageGrabberTest.cpp mitkToFImageGrabberCreatorTest.cpp mitkToFImageRecorderTest.cpp mitkToFImageRecorderFilterTest.cpp mitkToFImageWriterTest.cpp mitkToFOpenCVImageGrabberTest.cpp ) diff --git a/Modules/ToFHardware/Testing/mitkThreadedToFRawDataReconstructionTest.cpp b/Modules/ToFHardware/Testing/mitkThreadedToFRawDataReconstructionTest.cpp new file mode 100644 index 0000000000..446c4362ee --- /dev/null +++ b/Modules/ToFHardware/Testing/mitkThreadedToFRawDataReconstructionTest.cpp @@ -0,0 +1,93 @@ +/*========================================================================= + +Program: Medical Imaging & Interaction Toolkit +Language: C++ +Date: $Date: 2010-03-12 14:05:50 +0100 (Fr, 12 Mrz 2010) $ +Version: $Revision: 16010 $ + +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 +#include "mitkThreadedToFRawDataReconstruction.h" +#include "mitkToFCameraPMDRawDataCamBoardDevice.h" + +class RawDataDeviceHelperImpl : public mitk::ToFCameraPMDRawDataCamBoardDevice +{ +public: + mitkClassMacro(RawDataDeviceHelperImpl, mitk::ToFCameraPMDRawDataCamBoardDevice); + itkNewMacro(Self); + + itkSetMacro(CaptureWidth, int); + itkSetMacro(CaptureHeight, int); + +}; + +/**Documentation + * test for the class "mitkThreadedToFRawDataReconstruction". + */ +int mitkThreadedToFRawDataReconstructionTest(int /* argc */, char* /*argv*/[]) +{ + MITK_TEST_BEGIN("mitkThreadedToFRawDataReconstruction"); + mitk::ThreadedToFRawDataReconstruction::Pointer testObject = mitk::ThreadedToFRawDataReconstruction::New(); + + MITK_TEST_CONDITION_REQUIRED(testObject.GetPointer(), "Testing initializing of class"); + MITK_TEST_CONDITION_REQUIRED(!testObject->GetInit(), "Testing initial state of GetInit()"); + int width = 176; + int height = 144; + int modfreq = 20; + int sdsize = width*height*8*sizeof(short); + testObject->Initialize(width, height, modfreq, sdsize ); + MITK_TEST_CONDITION_REQUIRED(testObject->GetInit(), "Testing state of GetInit() after initialization"); + + // generate artificial data + short* shortSource = new short[sdsize]; + vtkShortArray* channelData = vtkShortArray::New(); + + for(long i = 0; i < sdsize; ++i) + { + shortSource[i] = i+1; + } + + // use the helper object to set required variables + RawDataDeviceHelperImpl::Pointer testHelper = RawDataDeviceHelperImpl::New(); + testHelper->SetCaptureWidth(width); + testHelper->SetCaptureHeight(height); + testHelper->GetChannelSourceData(shortSource, channelData); + testObject->SetChannelData( channelData ); + testObject->Update(); + + float* distances = new float[width*height]; + float* amplitudes = new float[width*height]; + float* intensties = new float[width*height]; + + // set random value and check if it has changed after filter update + distances[50] = -111; + amplitudes[50] = -111; + intensties[50] = -111; + float before = distances[50]; + + testObject->GetDistances(distances); + testObject->GetAmplitudes(amplitudes); + testObject->GetIntensities(intensties); + MITK_TEST_CONDITION_REQUIRED(before != distances[50], "Testing distance data generation and output"); + MITK_TEST_CONDITION_REQUIRED(before != amplitudes[50], "Testing ampltude data generation and output"); + MITK_TEST_CONDITION_REQUIRED(before != intensties[50], "Testing intensity data generation and output"); + + // clean up the mess + delete[] distances; + delete[] amplitudes; + delete[] intensties; + delete[] shortSource; + channelData->Delete(); + MITK_TEST_END(); +} + + diff --git a/Modules/ToFHardware/Testing/mitkToFCameraPMDControllerTest.cpp b/Modules/ToFHardware/Testing/mitkToFCameraPMDControllerTest.cpp index 3dc2b5d695..98d7676adc 100644 --- a/Modules/ToFHardware/Testing/mitkToFCameraPMDControllerTest.cpp +++ b/Modules/ToFHardware/Testing/mitkToFCameraPMDControllerTest.cpp @@ -1,77 +1,80 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit Language: C++ Date: $Date: 2010-03-12 14:05:50 +0100 (Fr, 12 Mrz 2010) $ Version: $Revision: 16010 $ 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. =========================================================================*/ // mitk includes #include #include #include #include // itk includes #include "itkObject.h" #include "itkObjectFactory.h" /**Documentation * test for the class "ToFCameraPMDController". */ //creating a concrete test implementation of the abstract class namespace mitk { class ToFCameraPMDControllerTest : public ToFCameraPMDController { public: mitkClassMacro( ToFCameraPMDControllerTest, ToFCameraPMDController); itkNewMacro( ToFCameraPMDControllerTest ); inline bool OpenCameraConnection(){return true;}; protected: inline ToFCameraPMDControllerTest(){}; inline ~ToFCameraPMDControllerTest(){}; private: }; } // end namespace mitk int mitkToFCameraPMDControllerTest(int /* argc */, char* /*argv*/[]) { MITK_TEST_BEGIN("ToFCameraPMDController"); // initialize test mitk::ToFCameraPMDControllerTest::Pointer testObject = mitk::ToFCameraPMDControllerTest::New(); MITK_TEST_CONDITION_REQUIRED(!(testObject.GetPointer() == NULL) ,"Testing initialization class"); MITK_TEST_CONDITION_REQUIRED(testObject->GetCaptureHeight()== 200 ,"Testing initialization of CaptureHeight"); MITK_TEST_CONDITION_REQUIRED(testObject->GetCaptureWidth()== 200 ,"Testing initialization of CaptureWidth"); int numberOfPixels = testObject->GetCaptureHeight()*testObject->GetCaptureWidth(); float* dataArray = new float[numberOfPixels]; char* sourceArray = new char[numberOfPixels]; + short* shortSource = new short[numberOfPixels]; MITK_TEST_CONDITION_REQUIRED(testObject->OpenCameraConnection(),"Testing OpenCameraConnection()"); MITK_TEST_CONDITION_REQUIRED(testObject->UpdateCamera(),"Testing UpdateCamera() with no camera connected"); MITK_TEST_CONDITION_REQUIRED(testObject->GetAmplitudes(dataArray),"Testing GetAmplitudes(float*) with no camera connected"); MITK_TEST_CONDITION_REQUIRED(testObject->GetAmplitudes(sourceArray,dataArray),"Testing GetAmplitudes(char*,float*) with no camera connected"); MITK_TEST_CONDITION_REQUIRED(testObject->GetIntensities(dataArray),"Testing GetIntensities(float*) with no camera connected"); MITK_TEST_CONDITION_REQUIRED(testObject->GetIntensities(sourceArray,dataArray),"Testing GetIntensities(char*,float*) with no camera connected"); MITK_TEST_CONDITION_REQUIRED(testObject->GetDistances(dataArray),"Testing GetDistances(float*) with no camera connected"); MITK_TEST_CONDITION_REQUIRED(testObject->GetDistances(sourceArray,dataArray),"Testing GetDistances(char*,float*) with no camera connected"); MITK_TEST_CONDITION_REQUIRED(testObject->GetSourceData(sourceArray),"Testing GetSourceData(char*) with no camera connected"); + MITK_TEST_CONDITION_REQUIRED(testObject->GetShortSourceData(shortSource), "Testing GetShortSourceData(short*) with no camera connected"); MITK_TEST_CONDITION_REQUIRED(testObject->CloseCameraConnection(),"Testing closing of connection"); delete [] dataArray; delete [] sourceArray; + delete [] shortSource; MITK_TEST_END(); } diff --git a/Modules/ToFHardware/Testing/mitkToFCameraPMDRawDataCamBoardDeviceTest.cpp b/Modules/ToFHardware/Testing/mitkToFCameraPMDRawDataCamBoardDeviceTest.cpp new file mode 100644 index 0000000000..cbcda56cd8 --- /dev/null +++ b/Modules/ToFHardware/Testing/mitkToFCameraPMDRawDataCamBoardDeviceTest.cpp @@ -0,0 +1,74 @@ +/*========================================================================= + +Program: Medical Imaging & Interaction Toolkit +Language: C++ +Date: $Date: 2010-03-12 14:05:50 +0100 (Fr, 12 Mrz 2010) $ +Version: $Revision: 16010 $ + +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 +#include + +// vtk includes +#include "vtkShortArray.h" + +/**Documentation + * test for the class "ToFCameraPMDCamBoardDevice". + */ +int mitkToFCameraPMDRawDataCamBoardDeviceTest(int /* argc */, char* /*argv*/[]) +{ + MITK_TEST_BEGIN("ToFCameraPMDRawDataCamBoardDevice"); + + mitk::ToFCameraPMDRawDataCamBoardDevice::Pointer tofCameraPMDRawDataCamBoardDevice = mitk::ToFCameraPMDRawDataCamBoardDevice::New(); + // No hardware attached for automatic testing -> test correct error handling + MITK_TEST_CONDITION_REQUIRED(tofCameraPMDRawDataCamBoardDevice->ConnectCamera(), "Test ConnectCamera()"); + MITK_TEST_CONDITION_REQUIRED(!tofCameraPMDRawDataCamBoardDevice->IsCameraActive(), "Test IsCameraActive() before StartCamera()"); + MITK_TEST_OUTPUT(<<"Call StartCamera()"); + tofCameraPMDRawDataCamBoardDevice->StartCamera(); + MITK_TEST_CONDITION_REQUIRED(tofCameraPMDRawDataCamBoardDevice->IsCameraActive(), "Test IsCameraActive() after StartCamera()"); + MITK_TEST_OUTPUT(<<"Call UpdateCamera()"); + tofCameraPMDRawDataCamBoardDevice->UpdateCamera(); + int numberOfPixels = tofCameraPMDRawDataCamBoardDevice->GetCaptureWidth()*tofCameraPMDRawDataCamBoardDevice->GetCaptureHeight(); + MITK_INFO<GetChannelSourceData(shortSource, channelData); + MITK_TEST_CONDITION_REQUIRED(tofCameraPMDRawDataCamBoardDevice->GetChannelSize()!=0, "Test if channelsize is set!"); + MITK_TEST_CONDITION_REQUIRED(channelData->GetNumberOfTuples()== 4, "Check channel data processing!"); + channelData->Delete(); + + tofCameraPMDRawDataCamBoardDevice->GetDistances(distances,imageSequence); + tofCameraPMDRawDataCamBoardDevice->GetAmplitudes(amplitudes,imageSequence); + tofCameraPMDRawDataCamBoardDevice->GetIntensities(intensities,imageSequence); + tofCameraPMDRawDataCamBoardDevice->GetAllImages(distances,amplitudes,intensities,sourceData,requiredImageSequence,imageSequence); + MITK_TEST_CONDITION_REQUIRED(tofCameraPMDRawDataCamBoardDevice->IsCameraActive(), "Test IsCameraActive() before StopCamera()"); + MITK_TEST_OUTPUT(<<"Call StopCamera()"); + tofCameraPMDRawDataCamBoardDevice->StopCamera(); + MITK_TEST_CONDITION_REQUIRED(!tofCameraPMDRawDataCamBoardDevice->IsCameraActive(), "Test IsCameraActive() after StopCamera()"); + + MITK_TEST_CONDITION_REQUIRED(tofCameraPMDRawDataCamBoardDevice->DisconnectCamera(), "Test DisonnectCamera()"); + delete[] distances; + delete[] amplitudes; + delete[] intensities; + delete[] sourceData; + + MITK_TEST_END(); + +} + + diff --git a/Modules/ToFHardware/Testing/mitkToFCameraPMDRawDataCamCubeDeviceTest.cpp b/Modules/ToFHardware/Testing/mitkToFCameraPMDRawDataCamCubeDeviceTest.cpp new file mode 100644 index 0000000000..31016abd35 --- /dev/null +++ b/Modules/ToFHardware/Testing/mitkToFCameraPMDRawDataCamCubeDeviceTest.cpp @@ -0,0 +1,75 @@ +/*========================================================================= + +Program: Medical Imaging & Interaction Toolkit +Language: C++ +Date: $Date: 2010-03-12 14:05:50 +0100 (Fr, 12 Mrz 2010) $ +Version: $Revision: 16010 $ + +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 +#include + +// vtk includes +#include "vtkShortArray.h" + +/**Documentation + * test for the class "ToFCameraPMDRawDataCamCubeDevice". + */ +int mitkToFCameraPMDRawDataCamCubeDeviceTest(int /* argc */, char* /*argv*/[]) +{ + MITK_TEST_BEGIN("ToFCameraPMDRawDataCamCubeDevice"); + + mitk::ToFCameraPMDRawDataCamCubeDevice::Pointer tofCameraPMDRawDataCamCubeDevice = mitk::ToFCameraPMDRawDataCamCubeDevice::New(); + // No hardware attached for automatic testing -> test correct error handling + MITK_TEST_CONDITION_REQUIRED(tofCameraPMDRawDataCamCubeDevice->ConnectCamera(), "Test ConnectCamera()"); + MITK_TEST_CONDITION_REQUIRED(!tofCameraPMDRawDataCamCubeDevice->IsCameraActive(), "Test IsCameraActive() before StartCamera()"); + MITK_TEST_OUTPUT(<<"Call StartCamera()"); + tofCameraPMDRawDataCamCubeDevice->StartCamera(); + MITK_TEST_CONDITION_REQUIRED(tofCameraPMDRawDataCamCubeDevice->IsCameraActive(), "Test IsCameraActive() after StartCamera()"); + MITK_TEST_OUTPUT(<<"Call UpdateCamera()"); + tofCameraPMDRawDataCamCubeDevice->UpdateCamera(); + int numberOfPixels = tofCameraPMDRawDataCamCubeDevice->GetCaptureWidth()*tofCameraPMDRawDataCamCubeDevice->GetCaptureHeight(); + MITK_INFO<GetChannelSourceData(shortSource, vtkArray); + MITK_TEST_CONDITION_REQUIRED(tofCameraPMDRawDataCamCubeDevice->GetChannelSize()!=0, "Test if channelsize is set!"); + MITK_TEST_CONDITION_REQUIRED(vtkArray->GetNumberOfTuples()== 4, "Check channel data processing!"); + vtkArray->Delete(); + + tofCameraPMDRawDataCamCubeDevice->GetDistances(distances,imageSequence); + tofCameraPMDRawDataCamCubeDevice->GetAmplitudes(amplitudes,imageSequence); + tofCameraPMDRawDataCamCubeDevice->GetIntensities(intensities,imageSequence); + tofCameraPMDRawDataCamCubeDevice->GetAllImages(distances,amplitudes,intensities,sourceData,requiredImageSequence,imageSequence); + MITK_TEST_CONDITION_REQUIRED(tofCameraPMDRawDataCamCubeDevice->IsCameraActive(), "Test IsCameraActive() before StopCamera()"); + MITK_TEST_OUTPUT(<<"Call StopCamera()"); + tofCameraPMDRawDataCamCubeDevice->StopCamera(); + MITK_TEST_CONDITION_REQUIRED(!tofCameraPMDRawDataCamCubeDevice->IsCameraActive(), "Test IsCameraActive() after StopCamera()"); + + MITK_TEST_CONDITION_REQUIRED(tofCameraPMDRawDataCamCubeDevice->DisconnectCamera(), "Test DisonnectCamera()"); + delete[] distances; + delete[] amplitudes; + delete[] intensities; + delete[] sourceData; + delete[] shortSource; + + MITK_TEST_END(); + +} + + diff --git a/Modules/ToFHardware/Testing/mitkToFCameraPMDRawDataDeviceTest.cpp b/Modules/ToFHardware/Testing/mitkToFCameraPMDRawDataDeviceTest.cpp new file mode 100644 index 0000000000..7d7d56cb3d --- /dev/null +++ b/Modules/ToFHardware/Testing/mitkToFCameraPMDRawDataDeviceTest.cpp @@ -0,0 +1,61 @@ +/*========================================================================= + +Program: Medical Imaging & Interaction Toolkit +Language: C++ +Date: $Date: 2010-03-12 14:05:50 +0100 (Fr, 12 Mrz 2010) $ +Version: $Revision: 16010 $ + +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 +#include + +/**Documentation + * test for the class "ToFCameraPMDDevice". + */ +int mitkToFCameraPMDRawDataDeviceTest(int /* argc */, char* /*argv*/[]) +{ + MITK_TEST_BEGIN("ToFCameraPMDRawDataDevice"); + + mitk::ToFCameraPMDRawDataDevice::Pointer tofCameraPMDRawDataDevice = mitk::ToFCameraPMDRawDataDevice::New(); + // No hardware attached for automatic testing -> test correct error handling + MITK_TEST_CONDITION_REQUIRED(!tofCameraPMDRawDataDevice->ConnectCamera(), "Test ConnectCamera()"); + MITK_TEST_CONDITION_REQUIRED(!tofCameraPMDRawDataDevice->IsCameraActive(), "Test IsCameraActive()"); + MITK_TEST_OUTPUT(<<"Call StartCamera()"); + tofCameraPMDRawDataDevice->StartCamera(); + MITK_TEST_OUTPUT(<<"Call UpdateCamera()"); + tofCameraPMDRawDataDevice->UpdateCamera(); + int numberOfPixels = tofCameraPMDRawDataDevice->GetCaptureWidth()*tofCameraPMDRawDataDevice->GetCaptureHeight(); + MITK_INFO<GetDistances(distances,imageSequence); + tofCameraPMDRawDataDevice->GetAmplitudes(amplitudes,imageSequence); + tofCameraPMDRawDataDevice->GetIntensities(intensities,imageSequence); + tofCameraPMDRawDataDevice->GetAllImages(distances,amplitudes,intensities,sourceData,requiredImageSequence,imageSequence); + MITK_TEST_OUTPUT(<<"Call StopCamera()"); + tofCameraPMDRawDataDevice->StopCamera(); + + MITK_TEST_CONDITION_REQUIRED(!tofCameraPMDRawDataDevice->DisconnectCamera(), "Test DisonnectCamera()"); + delete[] distances; + delete[] amplitudes; + delete[] intensities; + delete[] sourceData; + + MITK_TEST_END(); + +} + + diff --git a/Modules/ToFHardware/Testing/mitkToFImageGrabberCreatorTest.cpp b/Modules/ToFHardware/Testing/mitkToFImageGrabberCreatorTest.cpp index bd930bbe9e..cbcf0cf5b9 100644 --- a/Modules/ToFHardware/Testing/mitkToFImageGrabberCreatorTest.cpp +++ b/Modules/ToFHardware/Testing/mitkToFImageGrabberCreatorTest.cpp @@ -1,71 +1,87 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit Language: C++ Date: $Date: 2010-03-12 14:05:50 +0100 (Fr, 12 Mrz 2010) $ Version: $Revision: 16010 $ 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 #include #include #include +#include #include +#include #include #include #include /**Documentation * test for the class "ToFImageGrabberCreatorCreator". */ int mitkToFImageGrabberCreatorTest(int /* argc */, char* /*argv*/[]) { MITK_TEST_BEGIN("ToFImageGrabberCreator"); MITK_TEST_CONDITION_REQUIRED(mitk::ToFImageGrabberCreator::GetInstance()!=NULL,"Test GetInstance()"); mitk::ToFImageGrabber::Pointer imageGrabber = NULL; // ToFCameraMITKPlayer imageGrabber = mitk::ToFImageGrabberCreator::GetInstance()->GetMITKPlayerImageGrabber(); MITK_TEST_CONDITION_REQUIRED(imageGrabber.IsNotNull(),"Test if MITKPlayerImageGrabber could be created"); mitk::ToFCameraMITKPlayerDevice* mitkPlayerDevice = dynamic_cast(imageGrabber->GetCameraDevice()); MITK_TEST_CONDITION_REQUIRED(mitkPlayerDevice!=NULL,"Test if image grabber was initialized with ToFCameraMITKPlayerDevice"); // ToFCameraPMDCamCube imageGrabber = mitk::ToFImageGrabberCreator::GetInstance()->GetPMDCamCubeImageGrabber(); MITK_TEST_CONDITION_REQUIRED(imageGrabber.IsNotNull(),"Test if MITKPlayerImageGrabber could be created"); mitk::ToFCameraPMDCamCubeDevice* camCubeDevice = dynamic_cast(imageGrabber->GetCameraDevice()); MITK_TEST_CONDITION_REQUIRED(camCubeDevice!=NULL,"Test if image grabber was initialized with ToFCameraPMDCamCubeDevice"); + // ToFCameraPMDRawDataCamCube + imageGrabber = mitk::ToFImageGrabberCreator::GetInstance()->GetPMDRawDataCamCubeImageGrabber(); + MITK_TEST_CONDITION_REQUIRED(imageGrabber.IsNotNull(),"Test if MITKPlayerImageGrabber could be created"); + mitk::ToFCameraPMDRawDataCamCubeDevice* camCubeRawDevice + = dynamic_cast(imageGrabber->GetCameraDevice()); + MITK_TEST_CONDITION_REQUIRED(camCubeRawDevice!=NULL,"Test if image grabber was initialized"); + MITK_TEST_CONDITION_REQUIRED(!strcmp(camCubeRawDevice->GetNameOfClass(), "ToFCameraPMDRawDataCamCubeDevice"), "Test if image grabber was initialized with ToFCameraPMDRawDataCamCubeDevice"); // ToFCameraPMDCamBoard imageGrabber = mitk::ToFImageGrabberCreator::GetInstance()->GetPMDCamBoardImageGrabber(); MITK_TEST_CONDITION_REQUIRED(imageGrabber.IsNotNull(),"Test if MITKPlayerImageGrabber could be created"); mitk::ToFCameraPMDCamBoardDevice* camBoardDevice = dynamic_cast(imageGrabber->GetCameraDevice()); MITK_TEST_CONDITION_REQUIRED(camBoardDevice!=NULL,"Test if image grabber was initialized with ToFCameraPMDCamBoardDevice"); + // ToFCameraPMDRawDataCamBoard + imageGrabber = mitk::ToFImageGrabberCreator::GetInstance()->GetPMDRawDataCamBoardImageGrabber(); + MITK_TEST_CONDITION_REQUIRED(imageGrabber.IsNotNull(),"Test if MITKPlayerImageGrabber could be created"); + mitk::ToFCameraPMDRawDataCamBoardDevice* camBoardRawDevice + = dynamic_cast(imageGrabber->GetCameraDevice()); + MITK_TEST_CONDITION_REQUIRED(camBoardRawDevice!=NULL,"Test if image grabber was initialized with ToFCameraPMDRawDataCamBoardDevice"); + MITK_TEST_CONDITION_REQUIRED(!strcmp(camBoardRawDevice->GetNameOfClass(), "ToFCameraPMDRawDataCamBoardDevice"), "Test if image grabber was initialized with ToFCameraPMDRawDataCamCubeDevice"); // ToFCameraPMDPlayer imageGrabber = mitk::ToFImageGrabberCreator::GetInstance()->GetPMDPlayerImageGrabber(); MITK_TEST_CONDITION_REQUIRED(imageGrabber.IsNotNull(),"Test if MITKPlayerImageGrabber could be created"); mitk::ToFCameraPMDPlayerDevice* pmdPlayerDevice = dynamic_cast(imageGrabber->GetCameraDevice()); MITK_TEST_CONDITION_REQUIRED(pmdPlayerDevice!=NULL,"Test if image grabber was initialized with ToFCameraPMDPlayerDevice"); // ToFCameraPMDMITKPlayer imageGrabber = mitk::ToFImageGrabberCreator::GetInstance()->GetPMDMITKPlayerImageGrabber(); MITK_TEST_CONDITION_REQUIRED(imageGrabber.IsNotNull(),"Test if MITKPlayerImageGrabber could be created"); mitk::ToFCameraPMDMITKPlayerDevice* pmdMITKPlayerDevice = dynamic_cast(imageGrabber->GetCameraDevice()); MITK_TEST_CONDITION_REQUIRED(pmdMITKPlayerDevice!=NULL,"Test if image grabber was initialized with ToFCameraPMDMITKPlayerDevice"); MITK_TEST_END(); } diff --git a/Modules/ToFHardware/files.cmake b/Modules/ToFHardware/files.cmake index f7e9933d45..efb36df81a 100644 --- a/Modules/ToFHardware/files.cmake +++ b/Modules/ToFHardware/files.cmake @@ -1,90 +1,94 @@ SET(CPP_FILES mitkToFImageGrabberCreator.cpp mitkToFImageGrabber.cpp mitkToFOpenCVImageGrabber.cpp mitkToFCameraDevice.cpp mitkToFCameraMITKPlayerController.cpp mitkToFCameraMITKPlayerDevice.cpp mitkToFCameraPMDDevice.cpp + mitkToFCameraPMDRawDataDevice.cpp mitkToFCameraPMDPlayerDevice.cpp mitkToFCameraPMDMITKPlayerDevice.cpp mitkToFCameraPMDO3Device.cpp mitkToFCameraPMDCamCubeDevice.cpp + mitkToFCameraPMDRawDataCamCubeDevice.cpp mitkToFCameraPMDCamBoardDevice.cpp + mitkToFCameraPMDRawDataCamBoardDevice.cpp mitkToFCameraMESADevice.cpp mitkToFCameraMESASR4000Device.cpp mitkToFImageRecorder.cpp mitkToFImageRecorderFilter.cpp mitkToFImageWriter.cpp mitkToFImageCsvWriter.cpp + mitkThreadedToFRawDataReconstruction.cpp ) IF(MITK_USE_TOF_PMDCAMCUBE) SET(CPP_FILES ${CPP_FILES} mitkToFCameraPMDMITKPlayerController.cpp mitkToFCameraPMDCamCubeController.cpp mitkToFCameraPMDController.cpp ) IF(WIN32) IF(CMAKE_CL_64) SET(CPP_FILES ${CPP_FILES} mitkToFCameraPMDPlayerControllerStub.cpp) ELSE(CMAKE_CL_64) SET(CPP_FILES ${CPP_FILES} mitkToFCameraPMDPlayerController.cpp) ENDIF(CMAKE_CL_64) ELSE(WIN32) SET(CPP_FILES ${CPP_FILES} mitkToFCameraPMDPlayerControllerStub.cpp) ENDIF(WIN32) ELSE() SET(CPP_FILES ${CPP_FILES} mitkToFCameraPMDMITKPlayerControllerStub.cpp mitkToFCameraPMDCamCubeControllerStub.cpp mitkToFCameraPMDPlayerControllerStub.cpp ) ENDIF(MITK_USE_TOF_PMDCAMCUBE) IF(MITK_USE_TOF_PMDCAMBOARD) SET(CPP_FILES ${CPP_FILES} mitkToFCameraPMDCamBoardController.cpp mitkToFCameraPMDController.cpp ) ELSE() SET(CPP_FILES ${CPP_FILES} mitkToFCameraPMDCamBoardControllerStub.cpp ) ENDIF(MITK_USE_TOF_PMDCAMBOARD) IF(MITK_USE_TOF_PMDO3) SET(CPP_FILES ${CPP_FILES} mitkToFCameraPMDO3Controller.cpp mitkToFCameraPMDController.cpp ) ELSE() SET(CPP_FILES ${CPP_FILES} mitkToFCameraPMDO3ControllerStub.cpp ) ENDIF(MITK_USE_TOF_PMDO3) IF(NOT MITK_USE_TOF_PMDCAMCUBE) IF(NOT MITK_USE_TOF_PMDCAMBOARD) IF(NOT MITK_USE_TOF_PMDO3) SET(CPP_FILES ${CPP_FILES} mitkToFCameraPMDControllerStub.cpp ) ENDIF(NOT MITK_USE_TOF_PMDO3) ENDIF(NOT MITK_USE_TOF_PMDCAMBOARD) ENDIF(NOT MITK_USE_TOF_PMDCAMCUBE) IF(MITK_USE_TOF_MESASR4000) SET(CPP_FILES ${CPP_FILES} mitkToFCameraMESASR4000Controller.cpp mitkToFCameraMESAController.cpp ) ELSE() SET(CPP_FILES ${CPP_FILES} mitkToFCameraMESAControllerStub.cpp mitkToFCameraMESASR4000ControllerStub.cpp ) ENDIF(MITK_USE_TOF_MESASR4000) diff --git a/Modules/ToFHardware/mitkThreadedToFRawDataReconstruction.cpp b/Modules/ToFHardware/mitkThreadedToFRawDataReconstruction.cpp new file mode 100644 index 0000000000..4121f9a9d2 --- /dev/null +++ b/Modules/ToFHardware/mitkThreadedToFRawDataReconstruction.cpp @@ -0,0 +1,325 @@ +/*========================================================================= + +Program: Medical Imaging & Interaction Toolkit +Module: $RCSfile$ +Language: C++ +Date: $Date$ +Version: $Revision: 11415 $ + +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. + +=========================================================================*/ +// mitk includes +#include "mitkThreadedToFRawDataReconstruction.h" +#include "mitkITKImageImport.h" +#include "mitkImageDataItem.h" + +// stl includes +#include +#include +#include + +// vtk includes +#include +#include +#include + +// itk includes +#include +#include + +#ifdef WIN32 +#include +#else +#include +#endif +#include + +#define PI 3.14159265; +#define cAir 299704944; +#define fMod 20000000; + +namespace mitk +{ + + ThreadedToFRawDataReconstruction::ThreadedToFRawDataReconstruction(): m_Threader(0), + m_CISDist(0), m_CISAmpl(0), m_CISInten(0), + m_ThreadedCISDist(0), m_ThreadedCISAmpl(0), m_ThreadedCISInten(0), + m_Init(0), m_Width(0), m_Height(0), m_SourceDataSize(0), m_ImageSize(0), m_SourceData(0) + { + m_ThreadData = new ThreadDataStruct; + m_ThreadData->m_ModulationFrequency = fMod; + + m_ThreadData->m_ImageDataMutex = itk::FastMutexLock::New(); + m_ThreadData->m_ThreadDataMutex = itk::FastMutexLock::New(); + + m_StackSize = 1; + } + + ThreadedToFRawDataReconstruction::~ThreadedToFRawDataReconstruction() + { + if(m_ThreadData != NULL) + delete m_ThreadData; + + if(m_CISDist != NULL) + delete[] m_CISDist; + + if(m_CISAmpl != NULL) + delete[] m_CISAmpl; + + if(m_CISInten != NULL) + delete[] m_CISInten; + + if(m_ThreadedCISInten != NULL) + delete[] m_ThreadedCISInten; + + if(m_ThreadedCISAmpl != NULL) + delete[] m_ThreadedCISAmpl; + + if(m_ThreadedCISDist != NULL) + delete[] m_ThreadedCISDist; + + } + +void ThreadedToFRawDataReconstruction::Initialize(int width, int height, int modulationFrequency, int sourceDataSize ) +{ + m_Width = width; + m_Height = height; + m_SourceDataSize = sourceDataSize; + m_ImageSize = width * height; + m_ThreadData->m_ModulationFrequency = modulationFrequency * 1e6; + + if(!m_Init) + { + m_SourceData = vtkShortArray::New(); + m_SourceData->SetNumberOfComponents(m_SourceDataSize); + m_SourceData->SetNumberOfTuples(4); + m_SourceData->Allocate(1); + + m_CISDist = new float[m_ImageSize]; + m_CISAmpl = new float[m_ImageSize]; + m_CISInten = new float[m_ImageSize]; + m_ThreadedCISDist = new float[m_ImageSize]; + m_ThreadedCISAmpl = new float[m_ImageSize]; + m_ThreadedCISInten = new float[m_ImageSize]; + + m_ThreadData->m_OutputData.push_back( m_ThreadedCISDist ); + m_ThreadData->m_OutputData.push_back( m_ThreadedCISAmpl ); + m_ThreadData->m_OutputData.push_back( m_ThreadedCISInten ); + + m_Init = true; + } +} + +void ThreadedToFRawDataReconstruction::SetChannelData(vtkShortArray* sourceData) +{ + m_SourceData->DeepCopy(sourceData); +} + +void ThreadedToFRawDataReconstruction::GetDistances(float* dist) +{ + memcpy(dist, m_CISDist, m_ImageSize*sizeof(float) ); +} + +void ThreadedToFRawDataReconstruction::GetAmplitudes(float* ampl) +{ + memcpy(ampl, m_CISAmpl, m_ImageSize*sizeof(float)); +} + +void ThreadedToFRawDataReconstruction::GetIntensities(float* inten) +{ + memcpy(inten, m_CISInten, m_ImageSize*sizeof(float)); +} + + void ThreadedToFRawDataReconstruction::GenerateData() + { + if(m_Init) + { + this->BeforeThreadedGenerateData(); + } + } + + void ThreadedToFRawDataReconstruction::BeforeThreadedGenerateData() + { + int sourceDataSize = m_SourceDataSize; + int lineWidth = m_Width; + int frameHeight = m_Height; + int channelSize = lineWidth*frameHeight*2; + int quadChannelSize = channelSize/4; + + std::vector quad = std::vector(quadChannelSize); + + // clean the thread data array + m_ThreadData->m_InputData.erase(m_ThreadData->m_InputData.begin(),m_ThreadData->m_InputData.end()); + + int channelNo = 0; + while(channelNo < m_SourceData->GetNumberOfTuples()) + { + short* sourceData = new short[channelSize]; + m_SourceData->GetTupleValue(channelNo, sourceData); + quad.insert(quad.begin(), sourceData, sourceData+channelSize); + m_ThreadData->m_InputData.push_back(quad); + delete[]sourceData; + ++channelNo; + } + + if(m_Threader.IsNull()) + { + m_Threader = this->GetMultiThreader(); + } + int maxThreadNr = 0; + + if(m_Threader->GetGlobalDefaultNumberOfThreads()> 5) + { + maxThreadNr = 5; + } + else if(m_Threader->GetGlobalMaximumNumberOfThreads()>5) + { + maxThreadNr = 5; + } + else + { + maxThreadNr = m_Threader->GetGlobalMaximumNumberOfThreads(); + } + + if ( m_ThreadData->m_Barrier.IsNull()) + { + m_ThreadData->m_Barrier = itk::Barrier::New(); + m_ThreadData->m_Barrier->Initialize(maxThreadNr); // + } + m_ThreadData->m_DataSize = quadChannelSize; + m_ThreadData->m_LineWidth = lineWidth; + m_ThreadData->m_FrameHeight = frameHeight/4; + std::vector threadIDVector; + int threadcounter = 0; + while(threadcounter != maxThreadNr-1) + { + if (m_Threader->GetNumberOfThreads() < m_Threader->GetGlobalMaximumNumberOfThreads()) + { + int threadID = m_Threader->SpawnThread(this->ThreadedGenerateDataCallbackFunction, m_ThreadData); + threadIDVector.push_back(threadID); + threadcounter++; + } + } + m_ThreadData->m_Barrier->Wait(); + + int count = 0; + while(count != threadIDVector.size()) + { + m_Threader->TerminateThread(threadIDVector.at(count)); + count++; + } + m_ThreadData->m_ImageDataMutex->Lock(); + memcpy(m_CISDist, m_ThreadData->m_OutputData.at(0), (channelSize/2)*sizeof(float)); + memcpy(m_CISAmpl, m_ThreadData->m_OutputData.at(1), (channelSize/2)*sizeof(float)); + memcpy(m_CISInten, m_ThreadData->m_OutputData.at(2), (channelSize/2)*sizeof(float)); + m_ThreadData->m_ImageDataMutex->Unlock(); + + } + + ITK_THREAD_RETURN_TYPE ThreadedToFRawDataReconstruction::ThreadedGenerateDataCallbackFunction(void* data) + { + /* extract this pointer from Thread Info structure */ + struct itk::MultiThreader::ThreadInfoStruct * pInfo = (struct itk::MultiThreader::ThreadInfoStruct*)data; + if (pInfo == NULL) + { + return ITK_THREAD_RETURN_VALUE; + } + if (pInfo->UserData == NULL) + { + return ITK_THREAD_RETURN_VALUE; + } + int quadrant = pInfo->ThreadID; + ThreadDataStruct* threadData = (ThreadDataStruct*) pInfo->UserData; + + // some needed variables + int x = 0; + int index = 0; + int index2 = 0; + double phi = 0; + double phi2 = 0; + double A1 = 0; + double A2 = 0; + double A3 = 0; + double A4 = 0; + double A5 = 0; + double A6 = 0; + double A7 = 0; + double A8 = 0; + double A3m1 = 0; + double A4m2 = 0; + double A7m5 = 0; + double A8m6 = 0; + double cair = cAir; + double pi = PI; + double modFreq = fMod; + double intermed1 = 0; + int linewidth = 0; + int frameheight = 0; + + threadData->m_ThreadDataMutex->Lock(); + std::vector quad1 = threadData->m_InputData.at(0); + std::vector quad2 = threadData->m_InputData.at(1); + std::vector quad3 = threadData->m_InputData.at(2); + std::vector quad4 = threadData->m_InputData.at(3); + index = (quadrant*2); + index2 = 3-quadrant; + modFreq = threadData->m_ModulationFrequency; + linewidth = threadData->m_LineWidth; + frameheight = threadData->m_FrameHeight; + threadData->m_ThreadDataMutex->Unlock(); + + do + { + index += 2*linewidth; + x++; + do + { + index -= 8; + A1 = htons(quad1.at(index)); + A2 = htons(quad2.at(index)); + A3 = htons(quad3.at(index)); + A4 = htons(quad4.at(index)); + A5 = htons(quad1.at(index+1)); + A6 = htons(quad2.at(index+1)); + A7 = htons(quad3.at(index+1)); + A8 = htons(quad4.at(index+1)); + + phi = atan2((A3 - A1),(A2 - A4)) + pi; + phi2 = atan2((A7 - A5),(A6 - A8)); + if(phi2<0) phi2 +=2*pi; + + intermed1 = cair/(4*pi*modFreq); + A3m1 = A3*A3 - 2*A3*A1 + A1*A1; + A4m2 = A4*A4 - 2*A4*A2 + A2*A2; + A7m5 = A7*A7 - 2*A7*A5 + A5*A5; + A8m6 = A8*A8 - 2*A8*A6 + A6*A6; + threadData->m_ImageDataMutex->Lock(); + threadData->m_OutputData.at(0)[index2] = (((phi*intermed1) + (phi2*intermed1))/2)*1000; + threadData->m_OutputData.at(1)[index2] = (sqrt(A3m1 + A4m2)/2) + (sqrt(A7m5 + A8m6)/2); + threadData->m_OutputData.at(2)[index2] = (A1+A2+A3+A4+A5+A6+A7+A8)/8; + threadData->m_ImageDataMutex->Unlock(); + + index2 += 4; + }while(index2 <= (x*linewidth) - (1+quadrant)); + + index += 2*linewidth; + + }while(index < 2*(linewidth*frameheight*4)); + + threadData->m_Barrier->Wait(); + + return ITK_THREAD_RETURN_VALUE; + } + + void ThreadedToFRawDataReconstruction::Update() + { + this->GenerateData(); + } +} // end mitk namespace diff --git a/Modules/ToFHardware/mitkThreadedToFRawDataReconstruction.h b/Modules/ToFHardware/mitkThreadedToFRawDataReconstruction.h new file mode 100644 index 0000000000..8cb4d1c7f7 --- /dev/null +++ b/Modules/ToFHardware/mitkThreadedToFRawDataReconstruction.h @@ -0,0 +1,115 @@ +/*========================================================================= + +Program: Medical Imaging & Interaction Toolkit +Module: $RCSfile$ +Language: C++ +Date: $Date$ +Version: $Revision: 11415 $ + +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 __mitkThreadedToFRawDataReconstruction_h +#define __mitkThreadedToFRawDataReconstruction_h + +// mitk includes +#include "mitkImageSource.h" +#include "mitkToFHardwareExports.h" + +// itk includes +#include +#include + +// vtk includes +#include "vtkShortArray.h" + +namespace mitk +{ + struct ThreadDataStruct + { + std::vector > m_InputData; + std::vector m_OutputData; + unsigned int m_DataSize; + unsigned int m_LineWidth; + unsigned int m_FrameHeight; + unsigned int m_ModulationFrequency; + itk::Barrier::Pointer m_Barrier; ///< barrier to synchronize ends of threads + itk::FastMutexLock::Pointer m_ImageDataMutex; ///< mutex for coordinated access to image data + itk::FastMutexLock::Pointer m_ThreadDataMutex; ///< mutex to control access to images + }; + + class MITK_TOFHARDWARE_EXPORT ThreadedToFRawDataReconstruction : public itk::ProcessObject + { + public: + + mitkClassMacro( ThreadedToFRawDataReconstruction , itk::ProcessObject ); + itkNewMacro( Self ); + + itkGetMacro(Init, bool); + + void SetChannelData(vtkShortArray* sourceData); + + void Initialize(int width, int height, int modulationFrequency, int sourceDataSize); + + void GetDistances(float* dist); + void GetAmplitudes(float* ampl); + void GetIntensities(float* inten); + + void Update(); + + protected: + /*! + \brief standard constructor + */ + ThreadedToFRawDataReconstruction(); + /*! + \brief standard destructor + */ + ~ThreadedToFRawDataReconstruction(); + + /*! + \brief method generating the outputs of this filter. Called in the updated process of the pipeline. + This method generates the two outputs of the ToFImageSource: The distance and the intensity image + */ + virtual void GenerateData(); + + /*! + \brief method configures the camera output and prepares the thread data struct for threaded data + generation + */ + virtual void BeforeThreadedGenerateData(); + + /*! + \brief threader callback function for multi threaded data generation + */ + static ITK_THREAD_RETURN_TYPE ThreadedGenerateDataCallbackFunction(void* data); + + // member variables + int m_StackSize; ///< + int m_Width; + int m_Height; + int m_ImageSize; + int m_SourceDataSize; + vtkShortArray* m_SourceData; + bool m_Init; + + float* m_CISDist; ///< holds the distance information from for one distance image slice + float* m_CISAmpl; ///< holds the amplitude information from for one amplitude image slice + float* m_CISInten; ///< holds the intensity information from for one intensity image slice + float* m_ThreadedCISDist; + float* m_ThreadedCISAmpl; + float* m_ThreadedCISInten; + + itk::MultiThreader::Pointer m_Threader; + ThreadDataStruct* m_ThreadData; + + }; +} //end mitk namespace + +#endif // __mitkThreadedToFRawDataReconstruction_h diff --git a/Modules/ToFHardware/mitkToFCameraPMDCamCubeController.cpp b/Modules/ToFHardware/mitkToFCameraPMDCamCubeController.cpp index 0142d158e1..a2e820f96e 100644 --- a/Modules/ToFHardware/mitkToFCameraPMDCamCubeController.cpp +++ b/Modules/ToFHardware/mitkToFCameraPMDCamCubeController.cpp @@ -1,232 +1,232 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit Module: $RCSfile$ Language: C++ Date: $Date: 2010-05-27 16:06:53 +0200 (Do, 27 Mai 2010) $ 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 "mitkToFCameraPMDCamCubeController.h" #include "mitkToFConfig.h" #include //Plugin defines for CamCube #define SOURCE_PARAM "" #define PROC_PARAM "" extern PMDHandle m_PMDHandle; //TODO extern PMDDataDescription m_DataDescription; //TODO namespace mitk { ToFCameraPMDCamCubeController::ToFCameraPMDCamCubeController() { m_SourcePlugin = MITK_TOF_PMDCAMCUBE_SOURCE_PLUGIN; m_SourceParam = SOURCE_PARAM; m_ProcPlugin = MITK_TOF_PMDCAMCUBE_PROCESSING_PLUGIN; m_ProcParam = PROC_PARAM; } ToFCameraPMDCamCubeController::~ToFCameraPMDCamCubeController() { } bool ToFCameraPMDCamCubeController::OpenCameraConnection() { if(!m_ConnectionCheck) { - m_PMDRes = pmdOpen (&m_PMDHandle , m_SourcePlugin , m_SourceParam , m_ProcPlugin , m_ProcParam ); + m_PMDRes = pmdOpen(&m_PMDHandle , m_SourcePlugin , m_SourceParam , m_ProcPlugin , m_ProcParam ); m_ConnectionCheck = ErrorText(m_PMDRes); if (!m_ConnectionCheck) { return m_ConnectionCheck; } // get image properties from camera this->UpdateCamera(); m_PMDRes = pmdGetSourceDataDescription(m_PMDHandle, &m_DataDescription); ErrorText(m_PMDRes); m_CaptureWidth = m_DataDescription.img.numColumns; m_CaptureHeight = m_DataDescription.img.numRows; m_PixelNumber = m_CaptureWidth*m_CaptureHeight; m_NumberOfBytes = m_PixelNumber * sizeof(float); m_SourceDataSize = m_DataDescription.size; m_SourceDataStructSize = m_DataDescription.size + sizeof(PMDDataDescription); char serial[16]; m_PMDRes = pmdSourceCommand (m_PMDHandle, serial, 16, "GetSerialNumber"); ErrorText(m_PMDRes); MITK_INFO << "Serial-No: " << serial <m_SourceDataSize <GetIntegrationTime(); MITK_INFO << "Modulation Frequence: " << this->GetModulationFrequency(); return m_ConnectionCheck; } else return m_ConnectionCheck; } bool mitk::ToFCameraPMDCamCubeController::SetDistanceOffset( float offset ) { std::stringstream command; command<<"SetSoftOffset "<m_PMDRes = pmdSourceCommand(m_PMDHandle,0,0,command.str().c_str()); return ErrorText(this->m_PMDRes); } float mitk::ToFCameraPMDCamCubeController::GetDistanceOffset() { char offset[16]; this->m_PMDRes = pmdSourceCommand(m_PMDHandle, offset, 16, "GetSoftOffset"); ErrorText(this->m_PMDRes); return atof(offset); } bool mitk::ToFCameraPMDCamCubeController::SetRegionOfInterest( unsigned int leftUpperCornerX, unsigned int leftUpperCornerY, unsigned int width, unsigned int height ) { // check if leftUpperCornerX and width are divisible by 3 otherwise round to the next value divisible by 3 unsigned int factor = leftUpperCornerX/3; leftUpperCornerX = 3*factor; factor = width/3; width = 3*factor; std::stringstream command; command<<"SetROI "<m_PMDRes = pmdSourceCommand(m_PMDHandle,0,0,command.str().c_str()); return ErrorText(this->m_PMDRes); } bool mitk::ToFCameraPMDCamCubeController::SetRegionOfInterest( unsigned int roi[4] ) { return this->SetRegionOfInterest(roi[0],roi[1],roi[2],roi[3]); } unsigned int* mitk::ToFCameraPMDCamCubeController::GetRegionOfInterest() { /* char result[64]; this->m_PMDRes = pmdSourceCommand(m_PMDHandle, result, 64, "GetROI"); ErrorText(this->m_PMDRes); // convert char array to uint array unsigned int roi[4]; std::stringstream currentValue; int counter = 0; std::string resultString = result; char blank = ' '; for (int i=0; i<64; i++) { if (result[i]!=blank) { currentValue<m_PMDRes = pmdSourceCommand(m_PMDHandle, 0, 0, "SetExposureMode Normal"); return ErrorText(this->m_PMDRes); } else if (mode==1) // SMB mode { this->m_PMDRes = pmdSourceCommand(m_PMDHandle, 0, 0, "SetExposureMode SMB"); return ErrorText(this->m_PMDRes); } else { MITK_ERROR<<"Specified exposure mode not supported. Exposure mode must be 0 (Normal) or 1 (SMB)"; return false; } } bool mitk::ToFCameraPMDCamCubeController::SetFieldOfView( float fov ) { std::stringstream commandStream; commandStream<<"SetFOV "<m_PMDRes = pmdProcessingCommand(m_PMDHandle, 0, 0, commandStream.str().c_str()); return ErrorText(this->m_PMDRes); } bool mitk::ToFCameraPMDCamCubeController::SetFPNCalibration( bool on ) { if(on) { this->m_PMDRes=pmdSourceCommand(m_PMDHandle,0,0,"SetFPNCalibration On"); return this->ErrorText(this->m_PMDRes); } else { this->m_PMDRes=pmdSourceCommand(m_PMDHandle,0,0,"SetFPNCalibration Off"); return this->ErrorText(this->m_PMDRes); } } bool mitk::ToFCameraPMDCamCubeController::SetFPPNCalibration( bool on ) { if(on) { this->m_PMDRes=pmdProcessingCommand(m_PMDHandle,0,0,"SetFPPNCalibration On"); return this->ErrorText(this->m_PMDRes); } else { this->m_PMDRes=pmdProcessingCommand(m_PMDHandle,0,0,"SetFPPNCalibration Off"); return this->ErrorText(this->m_PMDRes); } } bool mitk::ToFCameraPMDCamCubeController::SetLinearityCalibration( bool on ) { if(on) { this->m_PMDRes=pmdProcessingCommand(m_PMDHandle,0,0,"SetLinearityCalibration On"); return this->ErrorText(this->m_PMDRes); } else { this->m_PMDRes=pmdProcessingCommand(m_PMDHandle,0,0,"SetLinearityCalibration Off"); return this->ErrorText(this->m_PMDRes); } } bool mitk::ToFCameraPMDCamCubeController::SetLensCalibration( bool on ) { if (on) { this->m_PMDRes = pmdProcessingCommand(m_PMDHandle, 0, 0, "SetLensCalibration On"); return ErrorText(this->m_PMDRes); } else { this->m_PMDRes = pmdProcessingCommand(m_PMDHandle, 0, 0, "SetLensCalibration Off"); return ErrorText(this->m_PMDRes); } } } diff --git a/Modules/ToFHardware/mitkToFCameraPMDController.cpp b/Modules/ToFHardware/mitkToFCameraPMDController.cpp index b010beff72..85d159e361 100644 --- a/Modules/ToFHardware/mitkToFCameraPMDController.cpp +++ b/Modules/ToFHardware/mitkToFCameraPMDController.cpp @@ -1,164 +1,171 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit Module: $RCSfile$ Language: C++ Date: $Date: 2010-05-27 16:06:53 +0200 (Do, 27 Mai 2010) $ 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 "mitkToFCameraPMDController.h" #include #include PMDHandle m_PMDHandle; //TODO PMDDataDescription m_DataDescription; //TODO struct SourceDataStruct { PMDDataDescription dataDescription; char sourceData; }; namespace mitk { ToFCameraPMDController::ToFCameraPMDController(): m_PMDRes(0), m_PixelNumber(40000), m_NumberOfBytes(0), m_CaptureWidth(200), m_CaptureHeight(200), m_SourceDataSize(0), m_SourceDataStructSize(0), m_ConnectionCheck(false), m_InputFileName("") { } ToFCameraPMDController::~ToFCameraPMDController() { } bool ToFCameraPMDController::CloseCameraConnection() { m_PMDRes = pmdClose(m_PMDHandle); m_ConnectionCheck = ErrorText(m_PMDRes); m_PMDHandle = 0; return m_ConnectionCheck; } bool ToFCameraPMDController::ErrorText(int error) { if(error != PMD_OK) { pmdGetLastError (m_PMDHandle, m_PMDError, 128); MITK_ERROR << "Camera Error " << m_PMDError; return false; } else return true; } bool ToFCameraPMDController::UpdateCamera() { m_PMDRes = pmdUpdate(m_PMDHandle); return ErrorText(m_PMDRes); } bool ToFCameraPMDController::GetAmplitudes(float* amplitudeArray) { this->m_PMDRes = pmdGetAmplitudes(m_PMDHandle, amplitudeArray, this->m_NumberOfBytes); return ErrorText(this->m_PMDRes); } bool ToFCameraPMDController::GetAmplitudes(char* sourceData, float* amplitudeArray) { this->m_PMDRes = pmdCalcAmplitudes(m_PMDHandle, amplitudeArray, this->m_NumberOfBytes, m_DataDescription, &((SourceDataStruct*)sourceData)->sourceData); return ErrorText(this->m_PMDRes); } bool ToFCameraPMDController::GetIntensities(float* intensityArray) { this->m_PMDRes = pmdGetIntensities(m_PMDHandle, intensityArray, this->m_NumberOfBytes); return ErrorText(this->m_PMDRes); } bool ToFCameraPMDController::GetIntensities(char* sourceData, float* intensityArray) { this->m_PMDRes = pmdCalcIntensities(m_PMDHandle, intensityArray, this->m_NumberOfBytes, m_DataDescription, &((SourceDataStruct*)sourceData)->sourceData); return ErrorText(this->m_PMDRes); } bool ToFCameraPMDController::GetDistances(float* distanceArray) { this->m_PMDRes = pmdGetDistances(m_PMDHandle, distanceArray, this->m_NumberOfBytes); return ErrorText(this->m_PMDRes); } bool ToFCameraPMDController::GetSourceData(char* sourceDataArray) { this->m_PMDRes = pmdGetSourceDataDescription(m_PMDHandle, &m_DataDescription); if (!ErrorText(this->m_PMDRes)) { return false; } memcpy(&((SourceDataStruct*)sourceDataArray)->dataDescription, &m_DataDescription, sizeof(m_DataDescription)); this->m_PMDRes = pmdGetSourceData(m_PMDHandle, &((SourceDataStruct*)sourceDataArray)->sourceData, this->m_SourceDataSize); return ErrorText(this->m_PMDRes); } + bool ToFCameraPMDController::GetShortSourceData( short* sourceData) + { + this->m_PMDRes = pmdGetSourceDataDescription(m_PMDHandle,&m_DataDescription); + ErrorText( this->m_PMDRes); + this->m_PMDRes = pmdGetSourceData(m_PMDHandle,sourceData,m_DataDescription.size); + return ErrorText( this->m_PMDRes); + } bool ToFCameraPMDController::GetDistances(char* sourceData, float* distanceArray) { this->m_PMDRes = pmdCalcDistances(m_PMDHandle, distanceArray, this->m_NumberOfBytes, m_DataDescription, &((SourceDataStruct*)sourceData)->sourceData); return ErrorText(this->m_PMDRes); } int ToFCameraPMDController::SetIntegrationTime(unsigned int integrationTime) { unsigned int result; this->m_PMDRes = pmdGetValidIntegrationTime(m_PMDHandle, &result, 0, AtLeast, integrationTime); ErrorText(this->m_PMDRes); if (this->m_PMDRes != 0) { return 0; } this->m_PMDRes = pmdSetIntegrationTime(m_PMDHandle, 0, result); ErrorText(this->m_PMDRes); return result; } int ToFCameraPMDController::GetIntegrationTime() { unsigned int integrationTime = 0; this->m_PMDRes = pmdGetIntegrationTime(m_PMDHandle, &integrationTime, 0); ErrorText(this->m_PMDRes); return integrationTime; } int ToFCameraPMDController::SetModulationFrequency(unsigned int modulationFrequency) { unsigned int result; this->m_PMDRes = pmdGetValidModulationFrequency(m_PMDHandle, &result, 0, AtLeast, (modulationFrequency*1000000)); ErrorText(this->m_PMDRes); if (this->m_PMDRes != 0) { return 0; } this->m_PMDRes = pmdSetModulationFrequency(m_PMDHandle, 0, result); ErrorText(this->m_PMDRes); return (result/1000000);; } int ToFCameraPMDController::GetModulationFrequency() { unsigned int modulationFrequency = 0; this->m_PMDRes = pmdGetModulationFrequency (m_PMDHandle, &modulationFrequency, 0); ErrorText(this->m_PMDRes); return (modulationFrequency/1000000); } void ToFCameraPMDController::SetInputFileName(std::string inputFileName) { this->m_InputFileName = inputFileName; } } diff --git a/Modules/ToFHardware/mitkToFCameraPMDController.h b/Modules/ToFHardware/mitkToFCameraPMDController.h index 99a6073a88..6c9f1ef42a 100644 --- a/Modules/ToFHardware/mitkToFCameraPMDController.h +++ b/Modules/ToFHardware/mitkToFCameraPMDController.h @@ -1,175 +1,180 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit Module: $RCSfile$ Language: C++ Date: $Date: 2010-05-27 16:06:53 +0200 (Do, 27 Mai 2010) $ 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 __mitkToFCameraPMDController_h #define __mitkToFCameraPMDController_h #include "mitkToFHardwareExports.h" #include "mitkCommon.h" #include "mitkToFCameraPMDController.h" #include "itkObject.h" #include "itkObjectFactory.h" namespace mitk { /** * @brief Virtual interface and base class for all PMD Time-of-Flight devices. Wraps PMD API provided in PMDSDK2 * Provides methods for accessing current distance, amplitude, intensity and raw data. * Allows to set parameters like modulation frequency and integration time. * * @ingroup ToFHardware */ class MITK_TOFHARDWARE_EXPORT ToFCameraPMDController : public itk::Object { public: mitkClassMacro( ToFCameraPMDController , itk::Object ); /*! \brief opens a connection to the ToF camera. Has to be implemented by the sub class */ //TODO return value virtual bool OpenCameraConnection() = 0; /*! \brief closes the connection to the camera */ //TODO return value virtual bool CloseCameraConnection(); /*! \brief Gets the current amplitude array from the device \param amplitudeArray float array where the amplitude data will be saved */ virtual bool GetAmplitudes(float* amplitudeArray); /*! \brief Calculates the current amplitude data from the raw source data using the processing plugin of the PMDSDK \param sourceData raw data array \param amplitudeArray float array where the amplitude data will be saved */ virtual bool GetAmplitudes(char* sourceData, float* amplitudeArray); /*! \brief Gets the current intensity array from the device \param intensityArray float array where the intensity data will be saved */ virtual bool GetIntensities(float* intensityArray); /*! \brief Calculates the current intensity data from the raw source data using the processing plugin of the PMDSDK \param sourceData raw data array \param intensityArray float array where the intensity data will be saved */ virtual bool GetIntensities(char* sourceData, float* intensityArray); /*! \brief Gets the current distance array from the device \param distanceArray float array where the distance data will be saved */ virtual bool GetDistances(float* distanceArray); /*! \brief Calculates the current distance data from the raw source data using the processing plugin of the PMDSDK \param sourceData raw data array \param distanceArray float array where the distance data will be saved */ virtual bool GetDistances(char* sourceData, float* distanceArray); /*! \brief Gets the PMD raw data from the ToF device. \param sourceDataArray array where the raw data will be saved */ virtual bool GetSourceData(char* sourceDataArray); + /*! + \brief Convenience method to get the PMD raw data from the ToF device as short array. + \param sourceData array where the short raw data will be saved + */ + bool GetShortSourceData(short* sourceData); + /*! \brief calls update on the camera -> a new ToF-image is aquired */ virtual bool UpdateCamera(); /*! \brief Returns the currently set modulation frequency. \return modulation frequency */ virtual int GetModulationFrequency(); /*! \brief Sets the modulation frequency of the ToF device. The method automatically calculates a valid value from the given frequency to make sure that only valid frequencies are used. \param modulationFrequency modulation frequency \return frequency set after validation step */ virtual int SetModulationFrequency(unsigned int modulationFrequency); /*! \brief Returns the currently set integration time. \return integration time */ virtual int GetIntegrationTime(); /*! \brief Sets the integration time of the ToF device. The method automatically calculates a valid value from the given integration time to make sure that only valid times are used. \param integrationTime integration time \return integration time set after validation step */ virtual int SetIntegrationTime(unsigned int integrationTime); /*! \brief set input file name used by PMD player classes */ virtual void SetInputFileName(std::string inputFileName); /*! \brief Access the resolution of the image in x direction \return widht of image in pixel */ itkGetMacro(CaptureWidth, unsigned int); /*! \brief Access the resolution of the image in y direction \return height of image in pixel */ itkGetMacro(CaptureHeight, unsigned int); itkGetMacro(SourceDataStructSize, int); protected: ToFCameraPMDController(); ~ToFCameraPMDController(); /*! \brief Method printing the current error message to the console and returning whether the previous command was successful \param error error number returned by the PMD function \return flag indicating if an error occured (false) or not (true) */ bool ErrorText(int error); - char m_PMDError[128]; ///< member holding the current error text int m_PMDRes; ///< holds the current result message provided by PMD int m_PixelNumber; ///< holds the number of pixels contained in the image int m_NumberOfBytes; ///< holds the number of bytes contained in the image unsigned int m_CaptureWidth; ///< holds the width of the image in pixel unsigned int m_CaptureHeight; ///< holds the height of the image in pixel int m_SourceDataSize; ///< size of the original PMD source data int m_SourceDataStructSize; ///< size of the PMD source data struct and the PMD source data bool m_ConnectionCheck; ///< flag showing whether the camera is connected (true) or not (false) std::string m_InputFileName; ///< input file name used by PMD player classes char *m_SourcePlugin; ///< holds name of source plugin to be loaded (e.g. camcube3.W64.pap for CamCube 3.0 on Win64 platform) char *m_SourceParam; ///< holds source parameter(s) char *m_ProcPlugin; ///< holds name of processing plugin to be loaded (e.g. camcubeproc.W64.pap for CamCube 3.0 on Win64 platform) char *m_ProcParam; ///< holds processing parameter(s) private: }; } //END mitk namespace #endif diff --git a/Modules/ToFHardware/mitkToFCameraPMDControllerStub.cpp b/Modules/ToFHardware/mitkToFCameraPMDControllerStub.cpp index 1ad8e73067..c5ea728c38 100644 --- a/Modules/ToFHardware/mitkToFCameraPMDControllerStub.cpp +++ b/Modules/ToFHardware/mitkToFCameraPMDControllerStub.cpp @@ -1,121 +1,127 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit Module: $RCSfile$ Language: C++ Date: $Date: 2010-05-27 16:06:53 +0200 (Do, 27 Mai 2010) $ 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 "mitkToFCameraPMDController.h" namespace mitk { ToFCameraPMDController::ToFCameraPMDController():m_PMDRes(0), m_PixelNumber(40000), m_NumberOfBytes(0), m_CaptureWidth(200), m_CaptureHeight(200), m_SourceDataSize(0), m_SourceDataStructSize(0), m_ConnectionCheck(false), m_InputFileName("") { MITK_WARN("ToF") << "PMD devices currently not available"; } ToFCameraPMDController::~ToFCameraPMDController() { } bool ToFCameraPMDController::CloseCameraConnection() { MITK_WARN("ToF") << "PMD devices currently not available"; return true; } bool ToFCameraPMDController::ErrorText(int error) { MITK_WARN("ToF") << "PMD devices currently not available"; return true; } bool ToFCameraPMDController::UpdateCamera() { MITK_WARN("ToF") << "PMD devices currently not available"; return true; } bool ToFCameraPMDController::GetAmplitudes(float* amplitudeArray) { MITK_WARN("ToF") << "PMD devices currently not available"; return true; } bool ToFCameraPMDController::GetAmplitudes(char* sourceData, float* amplitudeArray) { MITK_WARN("ToF") << "PMD devices currently not available"; return true; } bool ToFCameraPMDController::GetIntensities(float* intensityArray) { MITK_WARN("ToF") << "PMD devices currently not available"; return true; } bool ToFCameraPMDController::GetIntensities(char* sourceData, float* intensityArray) { MITK_WARN("ToF") << "PMD devices currently not available"; return true; } bool ToFCameraPMDController::GetDistances(float* distanceArray) { MITK_WARN("ToF") << "PMD devices currently not available"; return true; } bool ToFCameraPMDController::GetSourceData(char* sourceDataArray) { MITK_WARN("ToF") << "PMD devices currently not available"; return true; } + bool ToFCameraPMDController::GetShortSourceData(short* sourceData) + { + MITK_WARN("ToF") << "PMD devices currently not available"; + return true; + } + bool ToFCameraPMDController::GetDistances(char* sourceData, float* distanceArray) { MITK_WARN("ToF") << "PMD devices currently not available"; return true; } int ToFCameraPMDController::SetIntegrationTime(unsigned int integrationTime) { MITK_WARN("ToF") << "PMD devices currently not available"; return 0; } int ToFCameraPMDController::GetIntegrationTime() { MITK_WARN("ToF") << "PMD devices currently not available"; return 0; } int ToFCameraPMDController::SetModulationFrequency(unsigned int modulationFrequency) { MITK_WARN("ToF") << "PMD devices currently not available"; return 0; } int ToFCameraPMDController::GetModulationFrequency() { MITK_WARN("ToF") << "PMD devices currently not available"; return 0; } void ToFCameraPMDController::SetInputFileName(std::string inputFileName) { MITK_WARN("ToF") << "PMD devices currently not available"; } } diff --git a/Modules/ToFHardware/mitkToFCameraPMDRawDataCamBoardDevice.cpp b/Modules/ToFHardware/mitkToFCameraPMDRawDataCamBoardDevice.cpp new file mode 100644 index 0000000000..3e4d7efeac --- /dev/null +++ b/Modules/ToFHardware/mitkToFCameraPMDRawDataCamBoardDevice.cpp @@ -0,0 +1,104 @@ +/*========================================================================= + +Program: Medical Imaging & Interaction Toolkit +Module: $RCSfile$ +Language: C++ +Date: $Date: 2010-05-27 16:06:53 +0200 (Do, 27 Mai 2010) $ +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 "mitkToFCameraPMDRawDataCamBoardDevice.h" +#include "mitkToFCameraPMDCamBoardController.h" + +// vtk includes +#include "vtkSmartPointer.h" + +namespace mitk +{ + ToFCameraPMDRawDataCamBoardDevice::ToFCameraPMDRawDataCamBoardDevice() + { + m_Controller = ToFCameraPMDCamBoardController::New(); + } + + ToFCameraPMDRawDataCamBoardDevice::~ToFCameraPMDRawDataCamBoardDevice() + { + } + + void ToFCameraPMDRawDataCamBoardDevice::GetChannelSourceData(short* sourceData, vtkShortArray* vtkChannelArray ) + { + int i = 0; + //unsigned int channelDataPosition = 0; + unsigned int channelSize = (this->GetCaptureHeight()*this->GetCaptureWidth()*2); + this->SetChannelSize(channelSize); + signed short* channel1; + signed short* channel2; + signed short* channel3; + signed short* channel4; + + vtkSmartPointer cvtkChannelArray = vtkShortArray::New(); + cvtkChannelArray->SetNumberOfComponents(channelSize); + cvtkChannelArray->SetNumberOfTuples(4); + cvtkChannelArray->Allocate(1); + + channel1 = sourceData; + cvtkChannelArray->InsertTupleValue(0,channel1); + sourceData += channelSize; + channel2 = sourceData; + cvtkChannelArray->InsertTupleValue(1,channel2); + sourceData += channelSize; + channel3 = sourceData; + cvtkChannelArray->InsertTupleValue(2,channel3); + sourceData += channelSize; + channel4 = sourceData; + cvtkChannelArray->InsertTupleValue(3,channel4); + vtkChannelArray->DeepCopy(cvtkChannelArray); + cvtkChannelArray->Delete(); + } + + void ToFCameraPMDRawDataCamBoardDevice::SetProperty( const char *propertyKey, BaseProperty* propertyValue ) + { + ToFCameraPMDRawDataDevice::SetProperty(propertyKey,propertyValue); + this->m_PropertyList->SetProperty(propertyKey, propertyValue); + + ToFCameraPMDCamBoardController::Pointer myController = dynamic_cast(this->m_Controller.GetPointer()); + + bool boolValue = false; + GetBoolProperty(propertyValue, boolValue); + if (strcmp(propertyKey, "SetFPNCalibration") == 0) + { + myController->SetFPNCalibration(boolValue); + } + else if (strcmp(propertyKey, "SetFPPNCalibration") == 0) + { + myController->SetFPPNCalibration(boolValue); + } + else if (strcmp(propertyKey, "SetLinearityCalibration") == 0) + { + myController->SetLinearityCalibration(boolValue); + } + else if (strcmp(propertyKey, "SetLensCalibration") == 0) + { + myController->SetLensCalibration(boolValue); + } + else if (strcmp(propertyKey, "SetExposureMode") == 0) + { + if (boolValue) + { + myController->SetExposureMode(1); + } + else + { + myController->SetExposureMode(0); + } + } + } + +} diff --git a/Modules/ToFHardware/mitkToFCameraPMDRawDataCamBoardDevice.h b/Modules/ToFHardware/mitkToFCameraPMDRawDataCamBoardDevice.h new file mode 100644 index 0000000000..1701eb5324 --- /dev/null +++ b/Modules/ToFHardware/mitkToFCameraPMDRawDataCamBoardDevice.h @@ -0,0 +1,56 @@ +/*========================================================================= + +Program: Medical Imaging & Interaction Toolkit +Module: $RCSfile$ +Language: C++ +Date: $Date: 2010-05-27 16:06:53 +0200 (Do, 27 Mai 2010) $ +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 __mitkToFCameraPMDRawDataCamBoardDevice_h +#define __mitkToFCameraPMDRawDataCamBoardDevice_h + +#include "mitkToFHardwareExports.h" +#include "mitkCommon.h" +#include "mitkToFCameraDevice.h" +#include "mitkToFCameraPMDRawDataDevice.h" + +namespace mitk +{ + /** + * @brief Device class representing a PMD CamCube camera + * + * + * @ingroup ToFHardwareMBI + */ + class MITK_TOFHARDWARE_EXPORT ToFCameraPMDRawDataCamBoardDevice : public ToFCameraPMDRawDataDevice + { + public: + + mitkClassMacro( ToFCameraPMDRawDataCamBoardDevice , ToFCameraPMDRawDataDevice ); + + itkNewMacro( Self ); + + virtual void SetProperty( const char *propertyKey, BaseProperty* propertyValue ); + + virtual void GetChannelSourceData(short* sourceData, vtkShortArray* vtkChannelArray ); + + + protected: + + ToFCameraPMDRawDataCamBoardDevice(); + + ~ToFCameraPMDRawDataCamBoardDevice(); + private: + + }; +} //END mitk namespace +#endif // __mitkToFCameraPMDRawDataCamBoardDevice_h diff --git a/Modules/ToFHardware/mitkToFCameraPMDRawDataCamCubeDevice.cpp b/Modules/ToFHardware/mitkToFCameraPMDRawDataCamCubeDevice.cpp new file mode 100644 index 0000000000..ec25396d66 --- /dev/null +++ b/Modules/ToFHardware/mitkToFCameraPMDRawDataCamCubeDevice.cpp @@ -0,0 +1,107 @@ +/*========================================================================= + +Program: Medical Imaging & Interaction Toolkit +Module: $RCSfile$ +Language: C++ +Date: $Date: 2010-05-27 16:06:53 +0200 (Do, 27 Mai 2010) $ +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 "mitkToFCameraPMDRawDataCamCubeDevice.h" +#include "mitkToFCameraPMDCamCubeController.h" + +// vtk includes +#include "vtkSmartPointer.h" + +namespace mitk +{ + ToFCameraPMDRawDataCamCubeDevice::ToFCameraPMDRawDataCamCubeDevice() + { + m_Controller = ToFCameraPMDCamCubeController::New(); + } + + ToFCameraPMDRawDataCamCubeDevice::~ToFCameraPMDRawDataCamCubeDevice() + { + } + + void ToFCameraPMDRawDataCamCubeDevice::GetChannelSourceData(short* sourceData, vtkShortArray* vtkChannelArray ) + { + int i = 0; + unsigned int channelSize = (this->GetCaptureHeight()*this->GetCaptureWidth()*2); + this->SetChannelSize(channelSize); + signed short* channel1; + signed short* channel2; + signed short* channel3; + signed short* channel4; + + vtkSmartPointer tempVTKChannelArray = vtkShortArray::New(); + tempVTKChannelArray->SetNumberOfComponents(channelSize); + tempVTKChannelArray->SetNumberOfTuples(4); + tempVTKChannelArray->Allocate(1); + + sourceData += 256; + channel1 = sourceData; + tempVTKChannelArray->InsertTupleValue(0,channel1); + sourceData += channelSize; + sourceData += 256; + channel2 = sourceData; + tempVTKChannelArray->InsertTupleValue(1,channel2); + sourceData += channelSize; + sourceData += 256; + channel3 = sourceData; + tempVTKChannelArray->InsertTupleValue(2,channel3); + sourceData += channelSize; + sourceData += 256; + channel4 = sourceData; + tempVTKChannelArray->InsertTupleValue(3,channel4); + vtkChannelArray->DeepCopy(tempVTKChannelArray); + tempVTKChannelArray->Delete(); + } + + void ToFCameraPMDRawDataCamCubeDevice::SetProperty( const char *propertyKey, BaseProperty* propertyValue ) + { + ToFCameraPMDRawDataDevice::SetProperty(propertyKey,propertyValue); + this->m_PropertyList->SetProperty(propertyKey, propertyValue); + + ToFCameraPMDCamCubeController::Pointer myController = dynamic_cast(this->m_Controller.GetPointer()); + + bool boolValue = false; + GetBoolProperty(propertyValue, boolValue); + if (strcmp(propertyKey, "SetFPNCalibration") == 0) + { + myController->SetFPNCalibration(boolValue); + } + else if (strcmp(propertyKey, "SetFPPNCalibration") == 0) + { + myController->SetFPPNCalibration(boolValue); + } + else if (strcmp(propertyKey, "SetLinearityCalibration") == 0) + { + myController->SetLinearityCalibration(boolValue); + } + else if (strcmp(propertyKey, "SetLensCalibration") == 0) + { + myController->SetLensCalibration(boolValue); + } + else if (strcmp(propertyKey, "SetExposureMode") == 0) + { + if (boolValue) + { + myController->SetExposureMode(1); + } + else + { + myController->SetExposureMode(0); + } + } + } + +} diff --git a/Modules/ToFHardware/mitkToFCameraPMDRawDataCamCubeDevice.h b/Modules/ToFHardware/mitkToFCameraPMDRawDataCamCubeDevice.h new file mode 100644 index 0000000000..ac8bf27d69 --- /dev/null +++ b/Modules/ToFHardware/mitkToFCameraPMDRawDataCamCubeDevice.h @@ -0,0 +1,56 @@ +/*========================================================================= + +Program: Medical Imaging & Interaction Toolkit +Module: $RCSfile$ +Language: C++ +Date: $Date: 2010-05-27 16:06:53 +0200 (Do, 27 Mai 2010) $ +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 __mitkToFCameraPMDRawDataCamCubeDevice_h +#define __mitkToFCameraPMDRawDataCamCubeDevice_h + +#include "mitkToFHardwareExports.h" +#include "mitkCommon.h" +#include "mitkToFCameraDevice.h" +#include "mitkToFCameraPMDRawDataDevice.h" + +namespace mitk +{ + /** + * @brief Device class representing a PMD CamCube camera + * + * + * @ingroup ToFHardwareMBI + */ + class MITK_TOFHARDWARE_EXPORT ToFCameraPMDRawDataCamCubeDevice : public ToFCameraPMDRawDataDevice + { + public: + + mitkClassMacro( ToFCameraPMDRawDataCamCubeDevice , ToFCameraPMDRawDataDevice ); + + itkNewMacro( Self ); + + virtual void SetProperty( const char *propertyKey, BaseProperty* propertyValue ); + + virtual void GetChannelSourceData(short* sourceData, vtkShortArray* vtkChannelArray ); + + + protected: + + ToFCameraPMDRawDataCamCubeDevice(); + + ~ToFCameraPMDRawDataCamCubeDevice(); + private: + + }; +} //END mitk namespace +#endif diff --git a/Modules/ToFHardware/mitkToFCameraPMDRawDataDevice.cpp b/Modules/ToFHardware/mitkToFCameraPMDRawDataDevice.cpp new file mode 100644 index 0000000000..4c67815343 --- /dev/null +++ b/Modules/ToFHardware/mitkToFCameraPMDRawDataDevice.cpp @@ -0,0 +1,491 @@ +/*========================================================================= + +Program: Medical Imaging & Interaction Toolkit +Module: $RCSfile$ +Language: C++ +Date: $Date: 2010-05-27 16:06:53 +0200 (Do, 27 Mai 2010) $ +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 "mitkToFCameraPMDRawDataDevice.h" +#include "mitkRealTimeClock.h" + +#include "itkMultiThreader.h" +#include + +namespace mitk +{ + ToFCameraPMDRawDataDevice::ToFCameraPMDRawDataDevice() : + m_SourceDataArray(NULL), m_SourceDataBuffer(NULL), m_ShortSourceData(NULL) + { + m_RawDataSource = ThreadedToFRawDataReconstruction::New(); + + } + + ToFCameraPMDRawDataDevice::~ToFCameraPMDRawDataDevice() + { + this->CleanUpSourceData(); + } + + bool ToFCameraPMDRawDataDevice::ConnectCamera() + { + bool ok = false; + if (m_Controller.IsNotNull()) + { + ok = m_Controller->OpenCameraConnection(); + if (ok) + { + this->m_CaptureWidth = m_Controller->GetCaptureWidth(); + this->m_CaptureHeight = m_Controller->GetCaptureHeight(); + this->m_SourceDataSize = m_Controller->GetSourceDataStructSize(); + this->m_PixelNumber = this->m_CaptureWidth * this->m_CaptureHeight; + + // allocate buffers + this->AllocatePixelArrays(); + this->AllocateSourceData(); + + m_CameraConnected = true; + } + } + return ok; + } + + bool ToFCameraPMDRawDataDevice::DisconnectCamera() + { + bool ok = false; + if (m_Controller) + { + ok = m_Controller->CloseCameraConnection(); + if (ok) + { + m_CameraConnected = false; + } + } + return ok; + } + + void ToFCameraPMDRawDataDevice::StartCamera() + { + if (m_CameraConnected) + { + // get the first image + this->m_Controller->UpdateCamera(); + + this->m_ImageMutex->Lock(); + this->m_Controller->GetSourceData(this->m_SourceDataBuffer[this->m_FreePos]); + this->m_FreePos = (this->m_FreePos+1) % this->m_BufferSize; + this->m_CurrentPos = (this->m_CurrentPos+1) % this->m_BufferSize; + this->m_ImageSequence++; + this->m_ImageMutex->Unlock(); + + this->m_CameraActiveMutex->Lock(); + this->m_CameraActive = true; + this->m_CameraActiveMutex->Unlock(); + + this->m_ThreadID = this->m_MultiThreader->SpawnThread(this->Acquire, this); + // wait a little to make sure that the thread is started + itksys::SystemTools::Delay(100); + } + else + { + MITK_INFO<<"Camera not connected"; + } + } + + void ToFCameraPMDRawDataDevice::StopCamera() + { + m_CameraActiveMutex->Lock(); + m_CameraActive = false; + m_CameraActiveMutex->Unlock(); + + itksys::SystemTools::Delay(100); + if (m_MultiThreader.IsNotNull()) + { + m_MultiThreader->TerminateThread(m_ThreadID); + } + // wait a little to make sure that the thread is terminated + itksys::SystemTools::Delay(10); + } + + bool ToFCameraPMDRawDataDevice::IsCameraActive() + { + m_CameraActiveMutex->Lock(); + bool ok = m_CameraActive; + m_CameraActiveMutex->Unlock(); + return ok; + } + + void ToFCameraPMDRawDataDevice::UpdateCamera() + { + if (m_Controller) + { + m_Controller->UpdateCamera(); + } + } + + ITK_THREAD_RETURN_TYPE ToFCameraPMDRawDataDevice::Acquire(void* pInfoStruct) + { + /* extract this pointer from Thread Info structure */ + struct itk::MultiThreader::ThreadInfoStruct * pInfo = (struct itk::MultiThreader::ThreadInfoStruct*)pInfoStruct; + if (pInfo == NULL) + { + return ITK_THREAD_RETURN_VALUE; + } + if (pInfo->UserData == NULL) + { + return ITK_THREAD_RETURN_VALUE; + } + ToFCameraPMDRawDataDevice* toFCameraDevice = (ToFCameraPMDRawDataDevice*)pInfo->UserData; + if (toFCameraDevice!=NULL) + { + mitk::RealTimeClock::Pointer realTimeClock = mitk::RealTimeClock::New(); + double t1, t2; + t1 = realTimeClock->GetCurrentStamp(); + int n = 100; + bool overflow = false; + bool printStatus = false; + + while (toFCameraDevice->IsCameraActive()) + { + // update the ToF camera + toFCameraDevice->UpdateCamera(); + // get the source data from the camera and write it at the next free position in the buffer + vtkShortArray* channelData = vtkShortArray::New(); + toFCameraDevice->m_ImageMutex->Lock(); + toFCameraDevice->m_Controller->GetSourceData(toFCameraDevice->m_SourceDataArray); + toFCameraDevice->m_Controller->GetShortSourceData(toFCameraDevice->m_ShortSourceData); + toFCameraDevice->GetChannelSourceData( toFCameraDevice->m_ShortSourceData, channelData ); + toFCameraDevice->m_ImageMutex->Unlock(); + + // call modified to indicate that cameraDevice was modified + toFCameraDevice->Modified(); + + + /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + TODO Buffer Handling currently only works for buffer size 1 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/ + if(!toFCameraDevice->m_RawDataSource->GetInit()) + { + toFCameraDevice->m_RawDataSource->Initialize(toFCameraDevice->m_CaptureWidth, toFCameraDevice->m_CaptureHeight, + toFCameraDevice->m_Controller->GetModulationFrequency(), toFCameraDevice->GetChannelSize()); + } + toFCameraDevice->m_RawDataSource->SetChannelData(channelData); + toFCameraDevice->m_RawDataSource->Update(); + toFCameraDevice->m_ImageMutex->Lock(); + toFCameraDevice->m_RawDataSource->GetAmplitudes(toFCameraDevice->m_AmplitudeArray); + toFCameraDevice->m_RawDataSource->GetIntensities(toFCameraDevice->m_IntensityArray); + toFCameraDevice->m_RawDataSource->GetDistances(toFCameraDevice->m_DistanceArray); + toFCameraDevice->m_ImageMutex->Unlock(); + + toFCameraDevice->m_FreePos = (toFCameraDevice->m_FreePos+1) % toFCameraDevice->m_BufferSize; + toFCameraDevice->m_CurrentPos = (toFCameraDevice->m_CurrentPos+1) % toFCameraDevice->m_BufferSize; + toFCameraDevice->m_ImageSequence++; + if (toFCameraDevice->m_FreePos == toFCameraDevice->m_CurrentPos) + { + overflow = true; + } + if (toFCameraDevice->m_ImageSequence % n == 0) + { + printStatus = true; + } + channelData->Delete(); + + if (overflow) + { + overflow = false; + } + /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + END TODO Buffer Handling currently only works for buffer size 1 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/ + + // print current framerate + if (printStatus) + { + t2 = realTimeClock->GetCurrentStamp() - t1; + //MITK_INFO << "t2: " << t2 <<" Time (s) for 1 image: " << (t2/1000) / n << " Framerate (fps): " << n / (t2/1000) << " Sequence: " << toFCameraDevice->m_ImageSequence; + MITK_INFO << " Framerate (fps): " << n / (t2/1000) << " Sequence: " << toFCameraDevice->m_ImageSequence; + t1 = realTimeClock->GetCurrentStamp(); + printStatus = false; + } + + } // end of while loop + } + return ITK_THREAD_RETURN_VALUE; + } + + // TODO: Buffer size currently set to 1. Once Buffer handling is working correctly, method may be reactivated + // void ToFCameraPMDDevice::ResetBuffer(int bufferSize) + // { + // this->m_BufferSize = bufferSize; + // this->m_CurrentPos = -1; + // this->m_FreePos = 0; + // } + + void ToFCameraPMDRawDataDevice::GetAmplitudes(float* amplitudeArray, int& imageSequence) + { + m_ImageMutex->Lock(); + if (m_CameraActive) + { + // Flip around y- axis (vertical axis) + this->XYAxisFlipImage(this->m_AmplitudeArray, amplitudeArray, 1, 0 ); + imageSequence = this->m_ImageSequence; + } + else + { + MITK_WARN("ToF") << "Warning: Data can only be acquired if camera is active."; + } + m_ImageMutex->Unlock(); + } + + void ToFCameraPMDRawDataDevice::GetIntensities(float* intensityArray, int& imageSequence) + { + m_ImageMutex->Lock(); + if (m_CameraActive) + { + // Flip around y- axis (vertical axis) + this->XYAxisFlipImage(this->m_IntensityArray, intensityArray, 0, 1); + imageSequence = this->m_ImageSequence; + } + else + { + MITK_WARN("ToF") << "Warning: Data can only be acquired if camera is active."; + } + m_ImageMutex->Unlock(); + } + + void ToFCameraPMDRawDataDevice::GetDistances(float* distanceArray, int& imageSequence) + { + m_ImageMutex->Lock(); + if (m_CameraActive) + { + // Flip around y- axis (vertical axis) + this->XYAxisFlipImage(this->m_DistanceArray,distanceArray, 1, 1); + imageSequence = this->m_ImageSequence; + } + else + { + MITK_WARN("ToF") << "Warning: Data can only be acquired if camera is active."; + } + m_ImageMutex->Unlock(); + } + + void ToFCameraPMDRawDataDevice::GetAllImages(float* distanceArray, float* amplitudeArray, float* intensityArray, char* sourceDataArray, + int requiredImageSequence, int& capturedImageSequence) + { + if (m_CameraActive) + { + m_ImageMutex->Lock(); + // 1) copy the image buffer + // 2) convert the distance values from m to mm + // 3) Flip around y- axis (vertical axis) + + // check for empty buffer + if (this->m_ImageSequence < 0) + { + // buffer empty + MITK_INFO << "Buffer empty!! "; + capturedImageSequence = this->m_ImageSequence; + m_ImageMutex->Unlock(); + return; + } + + // determine position of image in buffer + int pos = 0; + if ((requiredImageSequence < 0) || (requiredImageSequence > this->m_ImageSequence)) + { + capturedImageSequence = this->m_ImageSequence; + pos = this->m_CurrentPos; + //MITK_INFO << "Required image not found! Required: " << requiredImageSequence << " delivered/current: " << this->m_ImageSequence; + } + else if (requiredImageSequence <= this->m_ImageSequence - this->m_BufferSize) + { + capturedImageSequence = (this->m_ImageSequence - this->m_BufferSize) + 1; + pos = (this->m_CurrentPos + 1) % this->m_BufferSize; + //MITK_INFO << "Out of buffer! Required: " << requiredImageSequence << " delivered: " << capturedImageSequence << " current: " << this->m_ImageSequence; + } + else // (requiredImageSequence > this->m_ImageSequence - this->m_BufferSize) && (requiredImageSequence <= this->m_ImageSequence) + + { + capturedImageSequence = requiredImageSequence; + pos = (this->m_CurrentPos + (10-(this->m_ImageSequence - requiredImageSequence))) % this->m_BufferSize; + } + m_ImageMutex->Unlock(); + + int u, v; + for (int i=0; im_CaptureHeight; i++) + { + for (int j=0; jm_CaptureWidth; j++) + { + u = i*this->m_CaptureWidth+j; + v = (i+1)*this->m_CaptureWidth-1-j; + distanceArray[u] = this->m_DistanceArray[v]; // unit in millimeter + amplitudeArray[u] = this->m_AmplitudeArray[v]; + intensityArray[u] = this->m_IntensityArray[v]; + } + } + + memcpy(sourceDataArray, this->m_SourceDataBuffer[this->m_CurrentPos], this->m_SourceDataSize); + } + else + { + MITK_WARN("ToF") << "Warning: Data can only be acquired if camera is active."; + } + } + + void ToFCameraPMDRawDataDevice::XYAxisFlipImage( float* imageData, float* &flippedData, int xAxis, int yAxis, int dimension ) + { + int captureWidth = this->GetCaptureWidth(); + int captureHeight = this->GetCaptureHeight(); + + // + //flips image around x- axis (horizontal axis) + // + + if(xAxis == 1 && yAxis != 1) + { + for (int i=0; im_Controller; + } + + void ToFCameraPMDRawDataDevice::SetProperty( const char *propertyKey, BaseProperty* propertyValue ) + { + ToFCameraDevice::SetProperty(propertyKey,propertyValue); + this->m_PropertyList->SetProperty(propertyKey, propertyValue); + if (strcmp(propertyKey, "ModulationFrequency") == 0) + { + int modulationFrequency = 0; + GetIntProperty(propertyValue, modulationFrequency); + m_Controller->SetModulationFrequency(modulationFrequency); + } + else if (strcmp(propertyKey, "IntegrationTime") == 0) + { + int integrationTime = 0; + GetIntProperty(propertyValue, integrationTime); + m_Controller->SetIntegrationTime(integrationTime); + } + } + + void ToFCameraPMDRawDataDevice::CleanupPixelArrays() + { + if (m_IntensityArray) + { + delete [] m_IntensityArray; + } + if (m_DistanceArray) + { + delete [] m_DistanceArray; + } + if (m_AmplitudeArray) + { + delete [] m_AmplitudeArray; + } + if (m_ShortSourceData) + { + delete [] m_ShortSourceData; + } + } + + void ToFCameraPMDRawDataDevice::AllocatePixelArrays() + { + // free memory if it was already allocated + CleanupPixelArrays(); + // allocate buffer + this->m_IntensityArray = new float[this->m_PixelNumber]; + for(int i=0; im_PixelNumber; i++) {this->m_IntensityArray[i]=0.0;} + this->m_DistanceArray = new float[this->m_PixelNumber]; + for(int i=0; im_PixelNumber; i++) {this->m_DistanceArray[i]=0.0;} + this->m_AmplitudeArray = new float[this->m_PixelNumber]; + for(int i=0; im_PixelNumber; i++) {this->m_AmplitudeArray[i]=0.0;} + this->m_ShortSourceData = new short[this->m_SourceDataSize]; + for(int i=0; im_SourceDataSize; i++) {this->m_ShortSourceData[i]=0.0;} + + } + + void ToFCameraPMDRawDataDevice::AllocateSourceData() + { + // clean up if array and data have already been allocated + CleanUpSourceData(); + // (re-) allocate memory + this->m_SourceDataArray = new char[this->m_SourceDataSize]; + for(int i=0; im_SourceDataSize; i++) {this->m_SourceDataArray[i]=0;} + + this->m_SourceDataBuffer = new char*[this->m_MaxBufferSize]; + for(int i=0; im_MaxBufferSize; i++) + { + this->m_SourceDataBuffer[i] = new char[this->m_SourceDataSize]; + } + } + + void ToFCameraPMDRawDataDevice::CleanUpSourceData() + { + if (m_SourceDataArray) + { + delete[] m_SourceDataArray; + } + if (m_SourceDataBuffer) + { + for(int i=0; im_MaxBufferSize; i++) + { + delete[] this->m_SourceDataBuffer[i]; + } + delete[] this->m_SourceDataBuffer; + } + } +} diff --git a/Modules/ToFHardware/mitkToFCameraPMDRawDataDevice.h b/Modules/ToFHardware/mitkToFCameraPMDRawDataDevice.h new file mode 100644 index 0000000000..20f65bc362 --- /dev/null +++ b/Modules/ToFHardware/mitkToFCameraPMDRawDataDevice.h @@ -0,0 +1,177 @@ +/*========================================================================= + +Program: Medical Imaging & Interaction Toolkit +Module: $RCSfile$ +Language: C++ +Date: $Date: 2010-05-27 16:06:53 +0200 (Do, 27 Mai 2010) $ +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 __mitkToFCameraPMDRawDataDevice_h +#define __mitkToFCameraPMDRawDataDevice_h + +#include "mitkToFHardwareExports.h" +#include "mitkToFCameraDevice.h" +#include "mitkToFCameraPMDController.h" +#include "mitkThreadedToFRawDataReconstruction.h" + +namespace mitk +{ + /** + * @brief Interface for all representations of PMD ToF devices. + * ToFCameraPMDDevice internally holds an instance of ToFCameraPMDController and starts a thread + * that continuously grabs images from the controller. A buffer structure buffers the last acquired images + * to provide the image data loss-less. + * + * @ingroup ToFHardware + */ + class MITK_TOFHARDWARE_EXPORT ToFCameraPMDRawDataDevice : public ToFCameraDevice + { + public: + + mitkClassMacro( ToFCameraPMDRawDataDevice , ToFCameraDevice ); + + itkNewMacro( Self ); + + itkSetMacro(ChannelSize, int); + itkGetMacro(ChannelSize, int); + /*! + \brief opens a connection to the ToF camera + */ + virtual bool ConnectCamera(); + /*! + \brief closes the connection to the camera + */ + virtual bool DisconnectCamera(); + /*! + \brief starts the continuous updating of the camera. + A separate thread updates the source data, the main thread processes the source data and creates images and coordinates + */ + virtual void StartCamera(); + /*! + \brief stops the continuous updating of the camera + */ + virtual void StopCamera(); + /*! + \brief updates the camera for image acquisition + */ + virtual void UpdateCamera(); + /*! + \brief returns whether the camera is currently active or not + */ + virtual bool IsCameraActive(); + /*! + \brief gets the amplitude data from the ToF camera as the strength of the active illumination of every pixel. Caution! The user is responsible for allocating and deleting the images. + These values can be used to determine the quality of the distance values. The higher the amplitude value, the higher the accuracy of the according distance value + \param imageSequence the actually captured image sequence number + \param amplitudeArray contains the returned amplitude data as an array. + */ + virtual void GetAmplitudes(float* amplitudeArray, int& imageSequence); + /*! + \brief gets the intensity data from the ToF camera as a greyscale image. Caution! The user is responsible for allocating and deleting the images. + \param intensityArray contains the returned intensities data as an array. + \param imageSequence the actually captured image sequence number + */ + virtual void GetIntensities(float* intensityArray, int& imageSequence); + /*! + \brief gets the distance data from the ToF camera measuring the distance between the camera and the different object points in millimeters. Caution! The user is responsible for allocating and deleting the images. + \param distanceArray contains the returned distances data as an array. + \param imageSequence the actually captured image sequence number + */ + virtual void GetDistances(float* distanceArray, int& imageSequence); + /*! + \brief gets the 3 images (distance, amplitude, intensity) from the ToF camera. Caution! The user is responsible for allocating and deleting the images. + \param distanceArray contains the returned distance data as an array. + \param amplitudeArray contains the returned amplitude data as an array. + \param intensityArray contains the returned intensity data as an array. + \param sourceDataArray contains the complete source data from the camera device. + \param requiredImageSequence the required image sequence number + \param capturedImageSequence the actually captured image sequence number + */ + virtual void GetAllImages(float* distanceArray, float* amplitudeArray, float* intensityArray, char* sourceDataArray, + int requiredImageSequence, int& capturedImageSequence); +// TODO: Buffer size currently set to 1. Once Buffer handling is working correctly, method may be reactivated +// /*! +// \brief pure virtual method resetting the buffer using the specified bufferSize. Has to be implemented by sub-classes +// \param bufferSize buffer size the buffer should be reset to +// */ +// virtual void ResetBuffer(int bufferSize) = 0; + //TODO add/correct documentation for requiredImageSequence and capturedImageSequence in the GetAllImages, GetDistances, GetIntensities and GetAmplitudes methods. + + /*! + \brief returns the corresponding camera controller + */ + ToFCameraPMDController::Pointer GetController(); + + virtual void GetChannelSourceData(short* sourceData, vtkShortArray* vtkChannelArray ){}; + + /*! + \brief set a BaseProperty + */ + virtual void SetProperty( const char *propertyKey, BaseProperty* propertyValue ); + + protected: + + ToFCameraPMDRawDataDevice(); + + ~ToFCameraPMDRawDataDevice(); + + /*! + \brief method for allocating m_SourceDataArray and m_SourceDataBuffer + */ + virtual void AllocateSourceData(); + + /*! + \brief method for cleaning up memory allocated for m_SourceDataArray and m_SourceDataBuffer + */ + virtual void CleanUpSourceData(); + + /*! + \brief method for allocating memory for pixel arrays m_IntensityArray, m_DistanceArray and m_AmplitudeArray + */ + virtual void AllocatePixelArrays(); + /*! + \brief method for cleanup memory allocated for pixel arrays m_IntensityArray, m_DistanceArray and m_AmplitudeArray + */ + virtual void CleanupPixelArrays(); + /*! + \brief Thread method continuously acquiring images from the ToF hardware + */ + static ITK_THREAD_RETURN_TYPE Acquire(void* pInfoStruct); + + /*! + \brief moves the position pointer m_CurrentPos to the next position in the buffer if that's not the next free position to prevent reading from an empty buffer + */ + void GetNextPos(); + + /*! + \brief gets the image data and flips it according to user needs Caution! The user is responsible for allocating and deleting the data. + \param imageData contains array to the input data. + \param flippedData contains flipped output array - Caution! The user is responsible for allocating and deleting the data. Size should be equal to imageData! + \param xAxis flag is set to flip around x axis (1 - set, 0 - not set). + \param yAxis flag is set to flip around y axis (1 - set, 0 - not set). + \param dimension contains the extend of the z dimension (preset is 1) + */ + void XYAxisFlipImage( float* imageData, float* &flippedData, int xAxis, int yAxis, int dimension = 1 ); + + ToFCameraPMDController::Pointer m_Controller; ///< corresponding CameraController + ThreadedToFRawDataReconstruction::Pointer m_RawDataSource; + char** m_SourceDataBuffer; ///< buffer holding the last acquired images + char* m_SourceDataArray; ///< array holding the current PMD source data + short* m_ShortSourceData; ///< array holding the current PMD raw data + private: + + //member variables + int m_ChannelSize; ///< member holds the size of a single raw data channel + + }; +} //END mitk namespace +#endif diff --git a/Modules/ToFHardware/mitkToFHardware.cmake b/Modules/ToFHardware/mitkToFHardware.cmake index 27e5d47825..f7ffb2a970 100644 --- a/Modules/ToFHardware/mitkToFHardware.cmake +++ b/Modules/ToFHardware/mitkToFHardware.cmake @@ -1,116 +1,116 @@ #option MITK_USE_TOF_HARDWARE IF(WIN32) IF(CMAKE_CL_64) SET(_PLATFORM_STRING "W64") ELSE(CMAKE_CL_64) SET(_PLATFORM_STRING "W32") ENDIF(CMAKE_CL_64) ELSE(WIN32) IF(CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64") SET(_PLATFORM_STRING "L64") ELSE(CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64") SET(_PLATFORM_STRING "L32") ENDIF(CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64") ENDIF(WIN32) SET(MITK_TOF_AVAILABLE_CAMERAS MITK Player) OPTION(MITK_ENABLE_TOF_HARDWARE "Support for range cameras" OFF) IF(MITK_ENABLE_TOF_HARDWARE) #Begin PMD Camcube hardware OPTION(MITK_USE_TOF_PMDCAMCUBE "Enable support for PMD camcube" OFF) # only if PMD Camcube is enabled IF(MITK_USE_TOF_PMDCAMCUBE) FIND_LIBRARY(MITK_PMD_LIB pmdaccess2 DOC "PMD access library.") GET_FILENAME_COMPONENT(MITK_PMD_SDK_DIR ${MITK_PMD_LIB} PATH) SET(MITK_PMD_SDK_DIR ${MITK_PMD_SDK_DIR}/..) FIND_PATH(MITK_PMD_INCLUDE_DIR pmdsdk2.h ${MITK_PMD_SDK_DIR}/include DOC "Include directory of PMD-SDK.") SET(MITK_TOF_PMD_CAMCUBE_SOURCE ${MITK_PMD_SDK_DIR}/plugins/camcube3.${_PLATFORM_STRING}.pap) SET(MITK_TOF_PMD_CAMCUBE_PROC ${MITK_PMD_SDK_DIR}/plugins/camcubeproc.${_PLATFORM_STRING}.ppp) SET(MITK_TOF_PMD_FILE_SOURCE ${MITK_PMD_SDK_DIR}/plugins/pmdfile.${_PLATFORM_STRING}.pcp) - SET(MITK_TOF_AVAILABLE_CAMERAS ${MITK_TOF_AVAILABLE_CAMERAS},PMD CamCube 2.0/3.0,PMD Player,PMD Raw Data Player) + SET(MITK_TOF_AVAILABLE_CAMERAS ${MITK_TOF_AVAILABLE_CAMERAS},PMD CamCube 2.0/3.0,PMD CamCubeRaw 2.0/3.0,PMD Player,PMD Raw Data Player) # FILE(GLOB MITK_TOF_PMD_CAMCUBE_SOURCE camcube3.${_PLATFORM_STRING}.pap) # FILE(GLOB MITK_TOF_PMD_CAMCUBE_PROC camcubeproc.${_PLATFORM_STRING}.ppp) # FILE(GLOB MITK_TOF_PMD_FILE_SOURCE pmdfile.${_PLATFORM_STRING}.pcp) IF(WIN32) MITK_INSTALL(FILES ${MITK_PMD_SDK_DIR}/bin/pmdaccess2.dll CONFIGURATIONS Release) MITK_INSTALL(FILES ${MITK_PMD_SDK_DIR}/plugins/camcube3.W32.pap CONFIGURATIONS Release) MITK_INSTALL(FILES ${MITK_PMD_SDK_DIR}/plugins/camcubeproc.W32.ppp CONFIGURATIONS Release) MITK_INSTALL(FILES ${MITK_PMD_SDK_DIR}/plugins/camcube3.W64.pap CONFIGURATIONS Release) MITK_INSTALL(FILES ${MITK_PMD_SDK_DIR}/plugins/camcubeproc.W64.ppp CONFIGURATIONS Release) MITK_INSTALL(FILES ${MITK_PMD_SDK_DIR}/plugins/pmdfile.W32.pcp CONFIGURATIONS Release) ENDIf(WIN32) ENDIF(MITK_USE_TOF_PMDCAMCUBE) #End PMD Camcube Hardware #Begin PMD CamBoard hardware OPTION(MITK_USE_TOF_PMDCAMBOARD "Enable support for PMD camboard" OFF) # only if PMD CamBoard is enabled IF(MITK_USE_TOF_PMDCAMBOARD) FIND_LIBRARY(MITK_PMD_LIB pmdaccess2 DOC "PMD access library.") GET_FILENAME_COMPONENT(MITK_PMD_SDK_DIR ${MITK_PMD_LIB} PATH) SET(MITK_PMD_SDK_DIR ${MITK_PMD_SDK_DIR}/..) FIND_PATH(MITK_PMD_INCLUDE_DIR pmdsdk2.h ${MITK_PMD_SDK_DIR}/include DOC "Include directory of PMD-SDK.") SET(MITK_TOF_PMD_CAMBOARD_SOURCE ${MITK_PMD_SDK_DIR}/plugins/camboard.${_PLATFORM_STRING}.pap) SET(MITK_TOF_PMD_CAMBOARD_PROC ${MITK_PMD_SDK_DIR}/plugins/camboardproc.${_PLATFORM_STRING}.ppp) - SET(MITK_TOF_AVAILABLE_CAMERAS ${MITK_TOF_AVAILABLE_CAMERAS},PMD CamBoard) + SET(MITK_TOF_AVAILABLE_CAMERAS ${MITK_TOF_AVAILABLE_CAMERAS},PMD CamBoard,PMD CamBoardRaw) # FILE(GLOB MITK_TOF_PMD_CAMBOARD_SOURCE camboard.${_PLATFORM_STRING}.pap) # FILE(GLOB MITK_TOF_PMD_CAMBOARD_PROC camboardproc.${_PLATFORM_STRING}.ppp) # FILE(GLOB MITK_TOF_PMD_FILE_SOURCE ${MITK_PMD_SDK_DIR}/plugins/pmdfile.${_PLATFORM_STRING}.pcp) IF(WIN32) INSTALL(FILES ${MITK_PMD_SDK_DIR}/bin/pmdaccess2.dll DESTINATION bin CONFIGURATIONS Release) INSTALL(FILES ${MITK_PMD_SDK_DIR}/plugins/camboard.W32.pap DESTINATION bin CONFIGURATIONS Release) INSTALL(FILES ${MITK_PMD_SDK_DIR}/plugins/camboardproc.W32.ppp DESTINATION bin CONFIGURATIONS Release) # INSTALL(FILES ${MITK_PMD_SDK_DIR}/plugins/camboard.W64.pap DESTINATION bin CONFIGURATIONS Release) # INSTALL(FILES ${MITK_PMD_SDK_DIR}/plugins/camboardproc.W64.ppp DESTINATION bin CONFIGURATIONS Release) # INSTALL(FILES ${MITK_PMD_SDK_DIR}/plugins/pmdfile.W32.pcp DESTINATION bin CONFIGURATIONS Release) ENDIf(WIN32) ENDIF(MITK_USE_TOF_PMDCAMBOARD) #End PMD CamBoard Hardware #Begin MESA SR4000 hardware OPTION(MITK_USE_TOF_MESASR4000 "Enable support for MESA SR4000" OFF) # only if MESA SR4000 is enabled IF(MITK_USE_TOF_MESASR4000) FIND_LIBRARY(MITK_MESA_LIB libMesaSR DOC "MESA access library.") GET_FILENAME_COMPONENT(MITK_MESA_SDK_DIR ${MITK_MESA_LIB} PATH) SET(MITK_MESA_SDK_DIR ${MITK_MESA_SDK_DIR}/..) FIND_PATH(MITK_MESA_INCLUDE_DIR libMesaSR.h ${MITK_MESA_SDK_DIR}/include DOC "Include directory of MESA-SDK.") SET(MITK_TOF_AVAILABLE_CAMERAS ${MITK_TOF_AVAILABLE_CAMERAS},MESA Swissranger 4000) IF(WIN32) INSTALL(FILES ${MITK_MESA_SDK_DIR}/bin/libMesaSR.dll DESTINATION bin CONFIGURATIONS Release) ENDIf(WIN32) ENDIF(MITK_USE_TOF_MESASR4000) #End MESA SR4000 Hardware IF (WIN32) #Begin PMD O3 hardware OPTION(MITK_USE_TOF_PMDO3 "Enable support for PMD O3 camera" OFF) # only if PMD O3 is enabled IF(MITK_USE_TOF_PMDO3) FIND_LIBRARY(MITK_PMD_LIB pmdaccess2 DOC "PMD access library.") GET_FILENAME_COMPONENT(MITK_PMD_SDK_DIR ${MITK_PMD_LIB} PATH) SET(MITK_PMD_SDK_DIR ${MITK_PMD_SDK_DIR}/..) FIND_PATH(MITK_PMD_INCLUDE_DIR pmdsdk2.h ${MITK_PMD_SDK_DIR}/include DOC "Include directory of PMD-SDK.") SET(MITK_TOF_PMD_O3D_SOURCE ${MITK_PMD_SDK_DIR}/plugins/o3d.${_PLATFORM_STRING}.pcp) SET(MITK_TOF_PMD_O3D_PROC ${MITK_PMD_SDK_DIR}/plugins/o3d.${_PLATFORM_STRING}.pcp) SET(MITK_TOF_AVAILABLE_CAMERAS ${MITK_TOF_AVAILABLE_CAMERAS},PMD O3D) # FILE(GLOB MITK_TOF_PMD_O3D_SOURCE o3d.${_PLATFORM_STRING}.pcp) # FILE(GLOB MITK_TOF_PMD_O3D_PROC o3d.${_PLATFORM_STRING}.pcp) MITK_INSTALL(FILES ${MITK_PMD_SDK_DIR}/bin/pmdaccess2.dll CONFIGURATIONS Release) MITK_INSTALL(FILES ${MITK_PMD_SDK_DIR}/plugins/o3d.W32.pcp CONFIGURATIONS Release) ENDIF(MITK_USE_TOF_PMDO3) #End PMD O3 Hardware ENDIF(WIN32) ENDIF(MITK_ENABLE_TOF_HARDWARE) CONFIGURE_FILE(mitkToFConfig.h.in ${PROJECT_BINARY_DIR}/mitkToFConfig.h @ONLY) diff --git a/Modules/ToFHardware/mitkToFImageGrabberCreator.cpp b/Modules/ToFHardware/mitkToFImageGrabberCreator.cpp index 516f58cd49..e3093d0656 100644 --- a/Modules/ToFHardware/mitkToFImageGrabberCreator.cpp +++ b/Modules/ToFHardware/mitkToFImageGrabberCreator.cpp @@ -1,100 +1,116 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit Module: $RCSfile$ Language: C++ Date: $Date: 2010-05-27 16:06:53 +0200 (Do, 27 Mai 2010) $ 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 "mitkToFImageGrabberCreator.h" #include "mitkToFImageGrabber.h" #include "mitkToFCameraPMDCamCubeDevice.h" +#include "mitkToFCameraPMDRawDataCamCubeDevice.h" #include "mitkToFCameraPMDCamBoardDevice.h" +#include "mitkToFCameraPMDRawDataCamBoardDevice.h" #include "mitkToFCameraPMDO3Device.h" #include "mitkToFCameraPMDPlayerDevice.h" #include "mitkToFCameraPMDMITKPlayerDevice.h" #include "mitkToFCameraMITKPlayerDevice.h" #include "mitkToFCameraMESASR4000Device.h" namespace mitk { ToFImageGrabberCreator::Pointer ToFImageGrabberCreator::s_Instance = NULL; ToFImageGrabberCreator::ToFImageGrabberCreator() { m_ToFImageGrabber = mitk::ToFImageGrabber::New(); } ToFImageGrabberCreator::~ToFImageGrabberCreator() { } ToFImageGrabberCreator* ToFImageGrabberCreator::GetInstance() { if ( !ToFImageGrabberCreator::s_Instance ) { s_Instance = ToFImageGrabberCreator::New(); } return s_Instance; } ToFImageGrabber::Pointer ToFImageGrabberCreator::GetPMDCamCubeImageGrabber() { m_ToFCameraDevice = mitk::ToFCameraPMDCamCubeDevice::New(); m_ToFImageGrabber->SetCameraDevice(m_ToFCameraDevice); return m_ToFImageGrabber; } + ToFImageGrabber::Pointer ToFImageGrabberCreator::GetPMDRawDataCamCubeImageGrabber() + { + m_ToFCameraDevice = mitk::ToFCameraPMDRawDataCamCubeDevice::New(); + m_ToFImageGrabber->SetCameraDevice(m_ToFCameraDevice); + return m_ToFImageGrabber; + } + ToFImageGrabber::Pointer ToFImageGrabberCreator::GetPMDO3ImageGrabber() { m_ToFCameraDevice = mitk::ToFCameraPMDO3Device::New(); m_ToFImageGrabber->SetCameraDevice(m_ToFCameraDevice); return m_ToFImageGrabber; } ToFImageGrabber::Pointer ToFImageGrabberCreator::GetPMDCamBoardImageGrabber() { m_ToFCameraDevice = mitk::ToFCameraPMDCamBoardDevice::New(); m_ToFImageGrabber->SetCameraDevice(m_ToFCameraDevice); return m_ToFImageGrabber; } + ToFImageGrabber::Pointer ToFImageGrabberCreator::GetPMDRawDataCamBoardImageGrabber() + { + m_ToFCameraDevice = mitk::ToFCameraPMDRawDataCamBoardDevice::New(); + m_ToFImageGrabber->SetCameraDevice(m_ToFCameraDevice); + return m_ToFImageGrabber; + } + ToFImageGrabber::Pointer ToFImageGrabberCreator::GetPMDPlayerImageGrabber() { m_ToFCameraDevice = mitk::ToFCameraPMDPlayerDevice::New(); m_ToFImageGrabber->SetCameraDevice(m_ToFCameraDevice); return m_ToFImageGrabber; } ToFImageGrabber::Pointer ToFImageGrabberCreator::GetPMDMITKPlayerImageGrabber() { m_ToFCameraDevice = mitk::ToFCameraPMDMITKPlayerDevice::New(); m_ToFImageGrabber->SetCameraDevice(m_ToFCameraDevice); return m_ToFImageGrabber; } ToFImageGrabber::Pointer ToFImageGrabberCreator::GetMITKPlayerImageGrabber() { m_ToFCameraDevice = mitk::ToFCameraMITKPlayerDevice::New(); m_ToFImageGrabber->SetCameraDevice(m_ToFCameraDevice); return m_ToFImageGrabber; } ToFImageGrabber::Pointer ToFImageGrabberCreator::GetMESASR4000ImageGrabber() { m_ToFCameraDevice = mitk::ToFCameraMESASR4000Device::New(); m_ToFImageGrabber->SetCameraDevice(m_ToFCameraDevice); return m_ToFImageGrabber; } } diff --git a/Modules/ToFHardware/mitkToFImageGrabberCreator.h b/Modules/ToFHardware/mitkToFImageGrabberCreator.h index 35d965d6bf..af32c44505 100644 --- a/Modules/ToFHardware/mitkToFImageGrabberCreator.h +++ b/Modules/ToFHardware/mitkToFImageGrabberCreator.h @@ -1,105 +1,114 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit Module: $RCSfile$ Language: C++ Date: $Date: 2010-05-27 16:06:53 +0200 (Do, 27 Mai 2010) $ 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 __mitkToFImageGrabberCreator_h #define __mitkToFImageGrabberCreator_h #include "mitkToFHardwareExports.h" #include "mitkCommon.h" #include "mitkToFImageGrabber.h" #include "mitkToFCameraDevice.h" #include "itkObject.h" #include "itkObjectFactory.h" namespace mitk { /** * @brief Class providing ready-to-use instances of ToFImageGrabbers * This singleton can be used to create ToFImageGrabber objects of * the supported ToF cameras. The ImageGrabbers are already initialized * with the correct device object. * When new hardware is added to MITK-ToF they should also be included in * this creator class. * * @ingroup ToFHardware */ class MITK_TOFHARDWARE_EXPORT ToFImageGrabberCreator : public itk::Object { public: mitkClassMacro( ToFImageGrabberCreator , itk::Object ); itkNewMacro( Self ); /*! \brief Get the RenderingManager singleton instance. */ static ToFImageGrabberCreator* GetInstance(); /*! \brief Create a ImageGrabber object with a PMD CamCube Camera */ ToFImageGrabber::Pointer GetPMDCamCubeImageGrabber(); + + /*! + \brief Create a ImageGrabber object with a PMD raw data CamCube Camera + */ + ToFImageGrabber::Pointer GetPMDRawDataCamCubeImageGrabber(); /*! \brief Create a ImageGrabber object with a PMD O3 Camera */ ToFImageGrabber::Pointer GetPMDO3ImageGrabber(); /*! \brief Create a ImageGrabber object with a PMD CamBoard Camera */ ToFImageGrabber::Pointer GetPMDCamBoardImageGrabber(); + /*! + \brief Create a ImageGrabber object with a PMD raw data CamBoard Camera + */ + ToFImageGrabber::Pointer GetPMDRawDataCamBoardImageGrabber(); + /*! \brief Create a ImageGrabber object with a PMD Player Camera */ ToFImageGrabber::Pointer GetPMDPlayerImageGrabber(); /*! \brief Create a ImageGrabber object with a PMD MITK Player Camera */ ToFImageGrabber::Pointer GetPMDMITKPlayerImageGrabber(); /*! \brief Create a ImageGrabber object with a MITK Player Camera */ ToFImageGrabber::Pointer GetMITKPlayerImageGrabber(); /*! \brief Create a ImageGrabber object with a MESA SR4000 Camera */ ToFImageGrabber::Pointer GetMESASR4000ImageGrabber(); protected: static ToFImageGrabberCreator::Pointer s_Instance; ///< Instance to the singleton ToFImageGrabberCreator. Can be accessed by GetInstance() ToFCameraDevice::Pointer m_ToFCameraDevice; ///< ToFCameraDevice currently used in the provided ToFImageGrabber ToFImageGrabber::Pointer m_ToFImageGrabber; ///< ToFImageGrabber that will be returned configured with the specific ToFCameraDevice ToFImageGrabberCreator(); ~ToFImageGrabberCreator(); - private: }; } //END mitk namespace #endif diff --git a/Modules/ToFUI/Qmitk/QmitkToFConnectionWidget.cpp b/Modules/ToFUI/Qmitk/QmitkToFConnectionWidget.cpp index f95f3ac3e1..f0a1d53f73 100644 --- a/Modules/ToFUI/Qmitk/QmitkToFConnectionWidget.cpp +++ b/Modules/ToFUI/Qmitk/QmitkToFConnectionWidget.cpp @@ -1,432 +1,442 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit Module: $RCSfile$ Language: C++ Date: $Date: 2009-05-20 13:35:09 +0200 (Mi, 20 Mai 2009) $ Version: $Revision: 17332 $ 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. =========================================================================*/ //#define _USE_MATH_DEFINES #include //QT headers #include #include #include //mitk headers #include "mitkToFConfig.h" #include //itk headers #include const std::string QmitkToFConnectionWidget::VIEW_ID = "org.mitk.views.qmitktofconnectionwidget"; QmitkToFConnectionWidget::QmitkToFConnectionWidget(QWidget* parent, Qt::WindowFlags f): QWidget(parent, f) { this->m_IntegrationTime = 0; this->m_ModulationFrequency = 0; this->m_ToFImageGrabber = NULL; m_Controls = NULL; CreateQtPartControl(this); } QmitkToFConnectionWidget::~QmitkToFConnectionWidget() { } void QmitkToFConnectionWidget::CreateQtPartControl(QWidget *parent) { if (!m_Controls) { // create GUI widgets m_Controls = new Ui::QmitkToFConnectionWidgetControls; m_Controls->setupUi(parent); this->CreateConnections(); // set available cameras to combo box QString string(MITK_TOF_CAMERAS); string.replace(";"," "); QStringList list = string.split(","); m_Controls->m_SelectCameraCombobox->addItems(list); ShowParameterWidget(); } } void QmitkToFConnectionWidget::CreateConnections() { if ( m_Controls ) { connect( (QObject*)(m_Controls->m_ConnectCameraButton), SIGNAL(clicked()),(QObject*) this, SLOT(OnConnectCamera()) ); connect( m_Controls->m_SelectCameraCombobox, SIGNAL(currentIndexChanged(const QString)), this, SLOT(OnSelectCamera(const QString)) ); connect( m_Controls->m_SelectCameraCombobox, SIGNAL(activated(const QString)), this, SLOT(OnSelectCamera(const QString)) ); connect( m_Controls->m_SelectCameraCombobox, SIGNAL(activated(const QString)), this, SIGNAL(ToFCameraSelected(const QString)) ); //connect( m_Controls->m_IntegrationTimeSpinBox, SIGNAL(valueChanged(int)), this, SLOT(OnChangeIntegrationTimeSpinBox(int)) ); //connect( m_Controls->m_ModulationFrequencySpinBox, SIGNAL(valueChanged(int)), this, SLOT(OnChangeModulationFrequencySpinBox(int)) ); } } void QmitkToFConnectionWidget::ShowParameterWidget() { QString selectedCamera = m_Controls->m_SelectCameraCombobox->currentText(); - if ((selectedCamera == "PMD CamCube 2.0/3.0")||(selectedCamera == "PMD CamBoard")||(selectedCamera=="PMD O3D")) + if ((selectedCamera == "PMD CamCube 2.0/3.0")||(selectedCamera == "PMD CamBoard")||(selectedCamera=="PMD O3D")|| + (selectedCamera=="PMD CamBoardRaw")||(selectedCamera=="PMD CamCubeRaw") ) { ShowPMDParameterWidget(); } else if (selectedCamera=="MESA Swissranger 4000") { ShowMESAParameterWidget(); } else { this->m_Controls->m_PMDParameterWidget->hide(); this->m_Controls->m_MESAParameterWidget->hide(); } } void QmitkToFConnectionWidget::ShowPMDParameterWidget() { this->m_Controls->m_PMDParameterWidget->show(); this->m_Controls->m_MESAParameterWidget->hide(); } void QmitkToFConnectionWidget::ShowMESAParameterWidget() { this->m_Controls->m_PMDParameterWidget->hide(); this->m_Controls->m_MESAParameterWidget->show(); } void QmitkToFConnectionWidget::ShowPlayerParameterWidget() { this->m_Controls->m_PMDParameterWidget->hide(); this->m_Controls->m_MESAParameterWidget->hide(); } mitk::ToFImageGrabber* QmitkToFConnectionWidget::GetToFImageGrabber() { return m_ToFImageGrabber; } void QmitkToFConnectionWidget::OnSelectCamera(const QString selectedText) { - if (selectedText == "PMD CamCube 2.0/3.0") // PMD camcube 2 + if (selectedText == "PMD CamCube 2.0/3.0" || selectedText == "PMD CamCubeRaw 2.0/3.0" ) // PMD camcube 2 { //m_Controls->m_IntegrationTimeSpinBox->setEnabled(true); //m_Controls->m_ModulationFrequencySpinBox->setEnabled(true); //m_Controls->m_CalibrationParameterGroupBox->setEnabled(true); ShowPMDParameterWidget(); } - else if (selectedText == "PMD CamBoard") // pmd camboard + else if (selectedText == "PMD CamBoard" || selectedText == "PMD CamBoardRaw" ) // pmd camboard { //m_Controls->m_IntegrationTimeSpinBox->setEnabled(true); //m_Controls->m_ModulationFrequencySpinBox->setEnabled(true); //m_Controls->m_CalibrationParameterGroupBox->setEnabled(false); ShowPMDParameterWidget(); } else if (selectedText == "PMD O3D") // pmd O3d { //m_Controls->m_IntegrationTimeSpinBox->setEnabled(true); //m_Controls->m_ModulationFrequencySpinBox->setEnabled(true); //m_Controls->m_CalibrationParameterGroupBox->setEnabled(false); ShowPMDParameterWidget(); } else if (selectedText == "MESA Swissranger 4000") // MESA 4000 { ShowMESAParameterWidget(); } else if (selectedText == "PMD Player") // pmd file player { //m_Controls->m_IntegrationTimeSpinBox->setEnabled(false); //m_Controls->m_ModulationFrequencySpinBox->setEnabled(false); //m_Controls->m_CalibrationParameterGroupBox->setEnabled(false); ShowPlayerParameterWidget(); } else if (selectedText == "PMD Raw Data Player") // pmd raw data player { //m_Controls->m_IntegrationTimeSpinBox->setEnabled(false); //m_Controls->m_ModulationFrequencySpinBox->setEnabled(false); //m_Controls->m_CalibrationParameterGroupBox->setEnabled(false); ShowPlayerParameterWidget(); } else if (selectedText == "MITK Player") // mitk player { //m_Controls->m_IntegrationTimeSpinBox->setEnabled(false); //m_Controls->m_ModulationFrequencySpinBox->setEnabled(false); //m_Controls->m_CalibrationParameterGroupBox->setEnabled(false); ShowPlayerParameterWidget(); } } void QmitkToFConnectionWidget::OnConnectCamera() { bool playerMode = false; if (m_Controls->m_ConnectCameraButton->text()=="Connect") { //reset the status of the GUI buttons m_Controls->m_ConnectCameraButton->setEnabled(false); m_Controls->m_SelectCameraCombobox->setEnabled(false); // m_Controls->m_CalibrationParameterGroupBox->setEnabled(false); //repaint the widget this->repaint(); QString tmpFileName(""); QString fileFilter(""); //select the camera to connect with QString selectedCamera = m_Controls->m_SelectCameraCombobox->currentText(); if (selectedCamera == "PMD CamCube 2.0/3.0") { //PMD CamCube this->m_ToFImageGrabber = mitk::ToFImageGrabberCreator::GetInstance()->GetPMDCamCubeImageGrabber(); } + else if (selectedCamera == "PMD CamCubeRaw 2.0/3.0") + { //PMD CamCube + this->m_ToFImageGrabber = mitk::ToFImageGrabberCreator::GetInstance()->GetPMDRawDataCamCubeImageGrabber(); + } else if (selectedCamera == "PMD CamBoard") { //PMD CamBoard this->m_ToFImageGrabber = mitk::ToFImageGrabberCreator::GetInstance()->GetPMDCamBoardImageGrabber(); } + else if (selectedCamera == "PMD CamBoardRaw") + { //PMD CamBoard + this->m_ToFImageGrabber = mitk::ToFImageGrabberCreator::GetInstance()->GetPMDRawDataCamBoardImageGrabber(); + } else if (selectedCamera == "PMD O3D") {//PMD O3 this->m_ToFImageGrabber = mitk::ToFImageGrabberCreator::GetInstance()->GetPMDO3ImageGrabber(); } else if (selectedCamera == "MESA Swissranger 4000") {//MESA SR4000 this->m_ToFImageGrabber = mitk::ToFImageGrabberCreator::GetInstance()->GetMESASR4000ImageGrabber(); } else if (selectedCamera == "PMD Player") {//PMD player playerMode = true; fileFilter.append("PMD Files (*.pmd)"); this->m_ToFImageGrabber = mitk::ToFImageGrabberCreator::GetInstance()->GetPMDPlayerImageGrabber(); } else if (selectedCamera == "PMD Raw Data Player") {//PMD MITK player playerMode = true; fileFilter.append("MITK Images (*.pic)"); this->m_ToFImageGrabber = mitk::ToFImageGrabberCreator::GetInstance()->GetPMDMITKPlayerImageGrabber(); } else if (selectedCamera == "MITK Player") {//MITK player playerMode = true; fileFilter.append("MITK Images (*.pic)"); this->m_ToFImageGrabber = mitk::ToFImageGrabberCreator::GetInstance()->GetMITKPlayerImageGrabber(); } // if a player was selected ... if (playerMode) { //... open a QFileDialog to chose the corresponding file from the disc tmpFileName = QFileDialog::getOpenFileName(NULL, "Play Image From...", "", fileFilter); if (tmpFileName.isEmpty()) { m_Controls->m_ConnectCameraButton->setChecked(false); m_Controls->m_ConnectCameraButton->setEnabled(true); m_Controls->m_SelectCameraCombobox->setEnabled(true); // m_Controls->m_CalibrationParameterGroupBox->setEnabled(true); OnSelectCamera(m_Controls->m_SelectCameraCombobox->currentText()); QMessageBox::information( this, "Template functionality", "Please select a valid image before starting some action."); return; } if(selectedCamera == "PMD Player") { //set the PMD file name this->m_ToFImageGrabber->SetStringProperty("PMDFileName", tmpFileName.toStdString().c_str() ); } if (selectedCamera == "PMD Raw Data Player" || selectedCamera == "MITK Player") { std::string msg = ""; try { //get 3 corresponding file names std::string dir = itksys::SystemTools::GetFilenamePath( tmpFileName.toStdString() ); std::string baseFilename = itksys::SystemTools::GetFilenameWithoutLastExtension( tmpFileName.toStdString() ); std::string extension = itksys::SystemTools::GetFilenameLastExtension( tmpFileName.toStdString() ); if (extension != ".pic") { msg = msg + "Invalid file format, please select a \".pic\"-file"; throw std::logic_error(msg.c_str()); } int found = baseFilename.rfind("_DistanceImage"); if (found == std::string::npos) { found = baseFilename.rfind("_AmplitudeImage"); } if (found == std::string::npos) { found = baseFilename.rfind("_IntensityImage"); } if (found == std::string::npos) { msg = msg + "Input file name must end with \"_DistanceImage.pic\", \"_AmplitudeImage.pic\" or \"_IntensityImage.pic\"!"; throw std::logic_error(msg.c_str()); } std::string baseFilenamePrefix = baseFilename.substr(0,found); std::string distanceImageFileName = dir + "/" + baseFilenamePrefix + "_DistanceImage" + extension; std::string amplitudeImageFileName = dir + "/" + baseFilenamePrefix + "_AmplitudeImage" + extension; std::string intensityImageFileName = dir + "/" + baseFilenamePrefix + "_IntensityImage" + extension; if (!itksys::SystemTools::FileExists(distanceImageFileName.c_str(), true)) { msg = msg + "Inputfile not exist! " + distanceImageFileName; throw std::logic_error(msg.c_str()); } if (!itksys::SystemTools::FileExists(amplitudeImageFileName.c_str(), true)) { msg = msg + "Inputfile not exist! " + amplitudeImageFileName; throw std::logic_error(msg.c_str()); } if (!itksys::SystemTools::FileExists(intensityImageFileName.c_str(), true)) { msg = msg + "Inputfile not exist! " + intensityImageFileName; throw std::logic_error(msg.c_str()); } //set the file names this->m_ToFImageGrabber->SetStringProperty("DistanceImageFileName", distanceImageFileName.c_str()); this->m_ToFImageGrabber->SetStringProperty("AmplitudeImageFileName", amplitudeImageFileName.c_str()); this->m_ToFImageGrabber->SetStringProperty("IntensityImageFileName", intensityImageFileName.c_str()); } catch (std::exception &e) { MITK_ERROR << e.what(); QMessageBox::critical( this, "Error", e.what() ); m_Controls->m_ConnectCameraButton->setChecked(false); m_Controls->m_ConnectCameraButton->setEnabled(true); m_Controls->m_SelectCameraCombobox->setEnabled(true); // m_Controls->m_CalibrationParameterGroupBox->setEnabled(true); OnSelectCamera(m_Controls->m_SelectCameraCombobox->currentText()); return; } } } //if a connection could be established if (this->m_ToFImageGrabber->ConnectCamera()) { this->m_Controls->m_PMDParameterWidget->SetToFImageGrabber(this->m_ToFImageGrabber); this->m_Controls->m_MESAParameterWidget->SetToFImageGrabber(this->m_ToFImageGrabber); - if ((selectedCamera == "PMD CamCube 2.0/3.0")||(selectedCamera == "PMD CamBoard")||(selectedCamera=="PMD O3D")) + if ((selectedCamera == "PMD CamCube 2.0/3.0")||(selectedCamera == "PMD CamBoard")||(selectedCamera=="PMD O3D")|| + (selectedCamera=="PMD CamBoardRaw")||(selectedCamera=="PMD CamCubeRaw")) { this->m_Controls->m_PMDParameterWidget->ActivateAllParameters(); } else if (selectedCamera=="MESA Swissranger 4000") { this->m_Controls->m_MESAParameterWidget->ActivateAllParameters(); } /* //get the integration time and modulation frequency this->m_IntegrationTime = m_Controls->m_IntegrationTimeSpinBox->value(); this->m_ModulationFrequency = m_Controls->m_ModulationFrequencySpinBox->value(); //set the integration time and modulation frequency in the grabber this->m_IntegrationTime = this->m_ToFImageGrabber->SetIntegrationTime(this->m_IntegrationTime); this->m_ModulationFrequency = this->m_ToFImageGrabber->SetModulationFrequency(this->m_ModulationFrequency); //set the PMD calibration according to the check boxes bool boolValue = false; boolValue = m_Controls->m_FPNCalibCB->isChecked(); this->m_ToFImageGrabber->SetBoolProperty("SetFPNCalibration", boolValue); boolValue = m_Controls->m_FPPNCalibCB->isChecked(); this->m_ToFImageGrabber->SetBoolProperty("SetFPPNCalibration", boolValue); boolValue = m_Controls->m_LinearityCalibCB->isChecked(); this->m_ToFImageGrabber->SetBoolProperty("SetLinearityCalibration", boolValue); boolValue = m_Controls->m_LensCorrection->isChecked(); this->m_ToFImageGrabber->SetBoolProperty("SetLensCalibration", boolValue); boolValue = m_Controls->m_ExposureModeCB->isChecked(); this->m_ToFImageGrabber->SetBoolProperty("SetExposureMode", boolValue); //reset the GUI elements m_Controls->m_IntegrationTimeSpinBox->setValue(this->m_IntegrationTime); m_Controls->m_ModulationFrequencySpinBox->setValue(this->m_ModulationFrequency); */ m_Controls->m_ConnectCameraButton->setText("Disconnect"); // send connect signal to the caller functionality emit ToFCameraConnected(); } else { QMessageBox::critical( this, "Error", "Connection failed. Check if you have installed the latest driver for your system." ); m_Controls->m_ConnectCameraButton->setChecked(false); m_Controls->m_ConnectCameraButton->setEnabled(true); m_Controls->m_SelectCameraCombobox->setEnabled(true); // m_Controls->m_CalibrationParameterGroupBox->setEnabled(true); OnSelectCamera(m_Controls->m_SelectCameraCombobox->currentText()); return; } m_Controls->m_ConnectCameraButton->setEnabled(true); } else if (m_Controls->m_ConnectCameraButton->text()=="Disconnect") { //send camera stop to the caller functionality emit ToFCameraStop(); this->m_ToFImageGrabber->StopCamera(); this->m_ToFImageGrabber->DisconnectCamera(); m_Controls->m_ConnectCameraButton->setText("Connect"); m_Controls->m_SelectCameraCombobox->setEnabled(true); // m_Controls->m_CalibrationParameterGroupBox->setEnabled(true); OnSelectCamera(m_Controls->m_SelectCameraCombobox->currentText()); this->m_ToFImageGrabber = NULL; // send disconnect signal to the caller functionality emit ToFCameraDisconnected(); } } /* void QmitkToFConnectionWidget::OnChangeIntegrationTimeSpinBox(int value) { if (this->m_ToFImageGrabber != NULL) { // stop camera if active bool active = m_ToFImageGrabber->IsCameraActive(); if (active) { m_ToFImageGrabber->StopCamera(); } this->m_IntegrationTime = m_Controls->m_IntegrationTimeSpinBox->value(); this->m_IntegrationTime = this->m_ToFImageGrabber->SetIntegrationTime(this->m_IntegrationTime); if (active) { m_ToFImageGrabber->StartCamera(); } } } void QmitkToFConnectionWidget::OnChangeModulationFrequencySpinBox(int value) { if (this->m_ToFImageGrabber != NULL) { // stop camera if active bool active = m_ToFImageGrabber->IsCameraActive(); if (active) { m_ToFImageGrabber->StopCamera(); } this->m_ModulationFrequency = m_Controls->m_ModulationFrequencySpinBox->value(); this->m_ModulationFrequency = this->m_ToFImageGrabber->SetModulationFrequency(this->m_ModulationFrequency); if (active) { m_ToFImageGrabber->StartCamera(); } } } */