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/mitkThreadedToFRawDataReconstruction.cpp b/Modules/ToFHardware/mitkThreadedToFRawDataReconstruction.cpp index 9286ea66db..4121f9a9d2 100644 --- a/Modules/ToFHardware/mitkThreadedToFRawDataReconstruction.cpp +++ b/Modules/ToFHardware/mitkThreadedToFRawDataReconstruction.cpp @@ -1,434 +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_Dimensions(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) { - //this->SetNumberOfOutputs(1); - //this->SetNthOutput(0, this->MakeOutput(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_Dimensions != NULL) - // delete[] m_Dimensions; - if(m_ThreadedCISInten != NULL) delete[] m_ThreadedCISInten; if(m_ThreadedCISAmpl != NULL) delete[] m_ThreadedCISAmpl; if(m_ThreadedCISDist != NULL) delete[] m_ThreadedCISDist; } - //void ThreadedToFRawDataReconstruction::SetToFCameraController(ToFCameraController::Pointer cameraController) - //{ - // m_CameraController = cameraController; - // this->InitializeDataArrays(); - //} - // - //void ThreadedToFRawDataReconstruction::SetStackSize(int size) - //{ - // m_StackSize = size; - //} - // - //void ThreadedToFRawDataReconstruction::SetRawDataRequired(bool flag) - //{ - // m_RawDataRequired = flag; - //} - // - //void ThreadedToFRawDataReconstruction::SetFPPNCompensationRequired(bool flag) - //{ - // m_FPPNCompensationRequired = flag; - //} - - //void ThreadedToFRawDataReconstruction::SetCalibrationParameter() - //{ - // ToFCalibrationFileReader::Pointer reader = ToFCalibrationFileReader::New(); - // reader->GenerateOutputInformation(); - // m_IntrinsicParameter = reader->GetIntrinsicParameter(); - // m_DistortionParameter = reader->GetDistortionParameter(); - // m_InterpolationPoints = reader->GetInterpolationPoints(); - // m_FPPNCompensationArray = reader->GetFPPNCompensationArray(); - //} - 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)); } - //ImageSource::OutputImageType::Pointer ThreadedToFRawDataReconstruction::FetchIntensityFrame(int slice) - //{ - // Image::Pointer intensityImage = Image::New(); - // //int x = 0; - // intensityImage->Initialize(PixelType(typeid(float)),4,m_Dimensions); - // intensityImage->SetSlice(m_CISInten,0,0,0); - // return intensityImage; - //} - // - //ImageSource::OutputImageType::Pointer ThreadedToFRawDataReconstruction::FetchAmplitudeFrame(int slice) - //{ - // Image::Pointer amplitudeImage = Image::New(); - // //int x = 0; - // amplitudeImage->Initialize(PixelType(typeid(float)),4,m_Dimensions); - // amplitudeImage->SetSlice(m_CISAmpl,0,0,0); - // return amplitudeImage; - //} - // - //ImageSource::OutputImageType::Pointer ThreadedToFRawDataReconstruction::FetchDistanceFrame(int slice) - //{ - // Image::Pointer distanceImage = Image::New(); - // //int x = 0; - // distanceImage->Initialize(PixelType(typeid(float)), 4, m_Dimensions); - // distanceImage->SetSlice(m_CISDist, 0, 0, 0); - // return distanceImage; - //} - void ThreadedToFRawDataReconstruction::GenerateData() { - //if(!m_Init) - //{ - // this->SetNthOutput(0, this->MakeOutput(0)); - // this->SetNthOutput(1, this->MakeOutput(1)); - // this->SetNthOutput(2, this->MakeOutput(2)); - - // if(m_CameraController.IsNotNull()) - // { - // int captureWidth = m_CameraController->GetCaptureWidth(); - // int captureHeight = m_CameraController->GetCaptureHeight(); - // unsigned int* dimensions = new unsigned int[4]; - // dimensions[0] = captureWidth; - // dimensions[1] = captureHeight; - // dimensions[2] = m_StackSize; - // dimensions[3] = 1; - - // this->GetOutput(0)->Initialize(mitk::PixelType(typeid(float)) , 4 , dimensions); - // this->GetOutput(1)->Initialize(mitk::PixelType(typeid(float)) , 4 , dimensions); - // this->GetOutput(2)->Initialize(mitk::PixelType(typeid(float)) , 4 , dimensions); - // m_Init = true; - // delete[] dimensions; - // } - //} - if(m_Init) { - //mitk::Image* dist = static_cast(this->GetOutput(1)); - //mitk::Image* inten = static_cast(this->GetOutput(0)); - //mitk::Image* ampl = static_cast(this->GetOutput(2)); - this->BeforeThreadedGenerateData(); - //dist->SetSlice(m_CISDist,0,0,0); - //inten->SetSlice(m_CISInten,0,0,0); - //ampl->SetSlice(m_CISAmpl,0,0,0); } } void ThreadedToFRawDataReconstruction::BeforeThreadedGenerateData() { int sourceDataSize = m_SourceDataSize; int lineWidth = m_Width; int frameHeight = m_Height; int channelSize = lineWidth*frameHeight*2; int quadChannelSize = channelSize/4; - //int headerSize = 256; std::vector quad = std::vector(quadChannelSize); - - //std::vector quad1; - //std::vector quad2; - //std::vector quad3; - //std::vector quad4; // 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; } - //quad2.insert(quad2.begin(), sourceData+2*headerSize+channelSize, sourceData+2*headerSize+2*channelSize); - //m_ThreadData->m_InputData.push_back(quad2); - //quad3.insert(quad3.begin(), sourceData+3*headerSize+2*channelSize, sourceData+3*headerSize+3*channelSize); - //m_ThreadData->m_InputData.push_back(quad3); - //quad4.insert(quad4.begin(), sourceData+4*headerSize+3*channelSize, sourceData+4*headerSize+4*channelSize); - //m_ThreadData->m_InputData.push_back(quad4); - //delete[] sourceData; - 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 index 2e00339536..8cb4d1c7f7 100644 --- a/Modules/ToFHardware/mitkThreadedToFRawDataReconstruction.h +++ b/Modules/ToFHardware/mitkThreadedToFRawDataReconstruction.h @@ -1,166 +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" -//#include "mitkToFCalibrationFileReader.h" // itk includes -//#include -//#include -//#include #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 endsof threads + 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 { - //typedef itk::Image ImageType; - //typedef itk::ImageRegionIterator IteratorType; - //typedef itk::FlipImageFilter FlipImageFilterType; - //typedef FlipImageFilterType::FlipAxesArrayType FlipAxesArrayType; - //typedef std::vector StdFloatVectorType; - //typedef std::vector StdPointVectorType; - - public: + public: mitkClassMacro( ThreadedToFRawDataReconstruction , itk::ProcessObject ); itkNewMacro( Self ); itkGetMacro(Init, bool); - //void SetToFCameraController(mitk::ToFCameraController::Pointer cameraController); - 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(); - //void SetStackSize(int size); - //void SetRawDataRequired(bool flag); - //void SetFPPNCompensationRequired(bool flag); - //void SetCalibrationParameter(); - //void DetermineDepthCalibrationImageSlice(); - - protected: + 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 method fetching one frame containing the intensity values of the ToF camera - \return intensity image - */ - //mitk::ImageSource::OutputImageType::Pointer FetchIntensityFrame(int slice); - ///*! - //\brief method fetching one frame containing the amplitude values of the ToF camera - //\return intensity image - //*/ - //mitk::ImageSource::OutputImageType::Pointer FetchAmplitudeFrame(int slice); - ///*! - //\brief method fetching one frame containing the distance values of the ToF camera - //\return distance image - //*/ - //mitk::ImageSource::OutputImageType::Pointer FetchDistanceFrame(int slice); - ///*! - //\brief gets the raw data poitner and calculates Amplitude, Distance and Intensity from the data - //*/ - //void GenerateImageFromRawData(); - ///*! - //\brief initializes the member variables Amplitude, Distance and Intensity with camera controller dimensions - //*/ - //void InitializeDataArrays(); - + /*! \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; - //float* m_DepthCalibrationParameter; - //unsigned int* m_Dimensions; - //mitk::ToFCalibrationFileReader::Pointer m_CalibrationFileReader; - //mitk::Matrix3D m_IntrinsicParameter; - //mitk::Matrix3D m_DistortionParameter; - //StdPointVectorType m_InterpolationPoints; - //StdFloatVectorType m_FPPNCompensationArray; - //mitk::ToFCameraController::Pointer m_CameraController; ///< member holding the controller for communicating with the ToF camera. Can be set via SetToFCameraController - //bool m_RawDataRequired; - //bool m_FPPNCompensationRequired; - }; } //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/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 index 7a320853b9..3e4d7efeac 100644 --- a/Modules/ToFHardware/mitkToFCameraPMDRawDataCamBoardDevice.cpp +++ b/Modules/ToFHardware/mitkToFCameraPMDRawDataCamBoardDevice.cpp @@ -1,116 +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); - //sourceData += 256; - //channelDataPosition += 256; channel1 = sourceData; cvtkChannelArray->InsertTupleValue(0,channel1); sourceData += channelSize; - //channelDataPosition += channelSize; - //sourceData += 256; - //channelDataPosition += 256; channel2 = sourceData; cvtkChannelArray->InsertTupleValue(1,channel2); sourceData += channelSize; - //channelDataPosition += channelSize; - //sourceData += 256; - //channelDataPosition += 256; channel3 = sourceData; cvtkChannelArray->InsertTupleValue(2,channel3); sourceData += channelSize; - //channelDataPosition += channelSize; - //sourceData += 256; - //channelDataPosition += 256; channel4 = sourceData; cvtkChannelArray->InsertTupleValue(3,channel4); - //sourceData -= channelDataPosition; 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/mitkToFCameraPMDRawDataCamCubeDevice.cpp b/Modules/ToFHardware/mitkToFCameraPMDRawDataCamCubeDevice.cpp index 401762b54d..ec25396d66 100644 --- a/Modules/ToFHardware/mitkToFCameraPMDRawDataCamCubeDevice.cpp +++ b/Modules/ToFHardware/mitkToFCameraPMDRawDataCamCubeDevice.cpp @@ -1,116 +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 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); + vtkSmartPointer tempVTKChannelArray = vtkShortArray::New(); + tempVTKChannelArray->SetNumberOfComponents(channelSize); + tempVTKChannelArray->SetNumberOfTuples(4); + tempVTKChannelArray->Allocate(1); sourceData += 256; - //channelDataPosition += 256; channel1 = sourceData; - cvtkChannelArray->InsertTupleValue(0,channel1); + tempVTKChannelArray->InsertTupleValue(0,channel1); sourceData += channelSize; - //channelDataPosition += channelSize; sourceData += 256; - //channelDataPosition += 256; channel2 = sourceData; - cvtkChannelArray->InsertTupleValue(1,channel2); + tempVTKChannelArray->InsertTupleValue(1,channel2); sourceData += channelSize; - //channelDataPosition += channelSize; sourceData += 256; - //channelDataPosition += 256; channel3 = sourceData; - cvtkChannelArray->InsertTupleValue(2,channel3); + tempVTKChannelArray->InsertTupleValue(2,channel3); sourceData += channelSize; - //channelDataPosition += channelSize; sourceData += 256; - //channelDataPosition += 256; channel4 = sourceData; - cvtkChannelArray->InsertTupleValue(3,channel4); - //sourceData -= channelDataPosition; - vtkChannelArray->DeepCopy(cvtkChannelArray); - cvtkChannelArray->Delete(); + 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); } } } }