diff --git a/Modules/ToFHardware/CMakeLists.txt b/Modules/ToFHardware/CMakeLists.txt index 4d423b5fb0..f7e4fcf55a 100644 --- a/Modules/ToFHardware/CMakeLists.txt +++ b/Modules/ToFHardware/CMakeLists.txt @@ -1,30 +1,35 @@ INCLUDE(mitkToFHardware.cmake) IF(MITK_USE_TOF_PMDCAMCUBE) SET(INCLUDE_DIRS_INTERNAL ${INCLUDE_DIRS_INTERNAL} ${MITK_PMD_SDK_DIR}/include) SET(ADDITIONAL_LIBS ${ADDITIONAL_LIBS} ${MITK_PMD_LIB}) ENDIF(MITK_USE_TOF_PMDCAMCUBE) IF(MITK_USE_TOF_O3) SET(INCLUDE_DIRS_INTERNAL ${INCLUDE_DIRS_INTERNAL} ${MITK_PMD_SDK_DIR}/include) SET(ADDITIONAL_LIBS ${ADDITIONAL_LIBS} ${MITK_PMD_LIB}) ENDIF(MITK_USE_TOF_O3) IF(MITK_USE_TOF_PMDCAMBOARD) SET(INCLUDE_DIRS_INTERNAL ${INCLUDE_DIRS_INTERNAL} ${MITK_PMD_SDK_DIR}/include) SET(ADDITIONAL_LIBS ${ADDITIONAL_LIBS} ${MITK_PMD_LIB}) ENDIF(MITK_USE_TOF_PMDCAMBOARD) +IF(MITK_USE_TOF_MESASR4000) + SET(INCLUDE_DIRS_INTERNAL ${INCLUDE_DIRS_INTERNAL} ${MITK_MESA_SDK_DIR}/include) + SET(ADDITIONAL_LIBS ${ADDITIONAL_LIBS} ${MITK_MESA_LIB}) +ENDIF(MITK_USE_TOF_MESASR4000) + MITK_CREATE_MODULE(mitkToFHardware SUBPROJECTS MITK-ToF INCLUDE_DIRS ${MITK_BIN_DIR} INTERNAL_INCLUDE_DIRS ${INCLUDE_DIRS_INTERNAL} DEPENDS Mitk MitkExt mitkOpenCVVideoSupport MitkIGT PROVIDES mitkToFHardware EXPORT_DEFINE MITK_TOFHARDWARE_EXPORT ADDITIONAL_LIBS ${ADDITIONAL_LIBS} ) ADD_SUBDIRECTORY(Testing) diff --git a/Modules/ToFHardware/files.cmake b/Modules/ToFHardware/files.cmake index ac0dc48c4c..a83287d1d4 100644 --- a/Modules/ToFHardware/files.cmake +++ b/Modules/ToFHardware/files.cmake @@ -1,66 +1,79 @@ SET(CPP_FILES mitkToFImageGrabberCreator.cpp mitkToFImageGrabber.cpp mitkToFOpenCVImageGrabber.cpp mitkToFCameraDevice.cpp mitkToFCameraMITKPlayerController.cpp mitkToFCameraMITKPlayerDevice.cpp mitkToFCameraPMDDevice.cpp mitkToFCameraPMDPlayerDevice.cpp mitkToFCameraPMDMITKPlayerDevice.cpp mitkToFCameraPMDO3Device.cpp mitkToFCameraPMDCamCubeDevice.cpp mitkToFCameraPMDCamBoardDevice.cpp + mitkToFCameraMESADevice.cpp + mitkToFCameraMESASR4000Device.cpp mitkToFImageRecorder.cpp mitkToFImageRecorderFilter.cpp mitkToFImageWriter.cpp mitkToFImageCsvWriter.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} mitkToFCameraPMDPlayerControllerStub.cpp mitkToFCameraPMDMITKPlayerControllerStub.cpp mitkToFCameraPMDCamCubeControllerStub.cpp mitkToFCameraPMDControllerStub.cpp ) ENDIF(MITK_USE_TOF_PMDCAMCUBE) 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(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_MESASR4000) +SET(CPP_FILES ${CPP_FILES} + mitkToFCameraMESASR4000Controller.cpp + mitkToFCameraMESAController.cpp +) +ELSE() +SET(CPP_FILES ${CPP_FILES} + mitkToFCameraMESASR4000ControllerStub.cpp +) +ENDIF(MITK_USE_TOF_MESASR4000) + diff --git a/Modules/ToFHardware/mitkToFCameraMESAController.cpp b/Modules/ToFHardware/mitkToFCameraMESAController.cpp new file mode 100644 index 0000000000..5650fff8c3 --- /dev/null +++ b/Modules/ToFHardware/mitkToFCameraMESAController.cpp @@ -0,0 +1,145 @@ +/*========================================================================= + +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 "mitkToFCameraMESAController.h" +#include +#include + +CMesaDevice* m_MESAHandle=0; + +namespace mitk +{ + ToFCameraMESAController::ToFCameraMESAController(): m_MESARes(0), m_PixelNumber(40000), m_NumberOfBytes(0), + m_CaptureWidth(0), m_CaptureHeight(0), m_NumImg(0), m_MaxRangeFactor(0.0), m_ConnectionCheck(false), + m_InputFileName("") + { + } + + ToFCameraMESAController::~ToFCameraMESAController() + { + } + + bool ToFCameraMESAController::CloseCameraConnection() + { + m_MESARes = SR_Close(m_MESAHandle); //res=SR_Close(srCam); + m_ConnectionCheck = ErrorText(m_MESARes); + m_MESAHandle = 0; + return m_ConnectionCheck; + } + + bool ToFCameraMESAController::ErrorText(int error) + { + //if(error != MESA_OK) + //{ + // //pmdGetLastError (m_MESAHandle, m_MESAError, 128); + // //MITK_ERROR << "Camera Error " << m_MESAError; + // return false; + //} + //else return true; + return true; + } + + bool ToFCameraMESAController::UpdateCamera() + { + m_MESARes = SR_Acquire(m_MESAHandle); //res=SR_Acquire(srCam); + //return ErrorText(m_MESARes); + return true; + } + + bool ToFCameraMESAController::GetAmplitudes(float* amplitudeArray) + { + unsigned short* data; + data = (unsigned short*)SR_GetImage(m_MESAHandle, 1); + for (int i=0; im_PixelNumber; i++) + { + if (data[i] & 0x8000) // bit 16 indicates saturation + { + amplitudeArray[i] = 0; + } + else + { + unsigned short value = data[i] & 0x7fff; // bit 16 indicates saturation + unsigned short value2 = value >> 2; // bits 1 and 2 are reserved/unused + amplitudeArray[i] = value2; + } + } + return true; + } + + bool ToFCameraMESAController::GetIntensities(float* intensityArray) + { + unsigned short* data; + data = (unsigned short*)SR_GetImage(m_MESAHandle, 1); + for (int i=0; im_PixelNumber; i++) + { + intensityArray[i] = data[i]; + } + return true; + } + + bool ToFCameraMESAController::GetDistances(float* distanceArray) + { + //this->m_MESARes = pmdGetDistances(m_MESAHandle, distanceArray, this->m_NumberOfBytes); + //return ErrorText(this->m_MESARes); + unsigned short* data; + /* + for(i=0; im_PixelNumber; i++) + { + if (data[i] < 0xFFF8) + { + distanceArray[i] = data[i] * this->m_MaxRangeFactor; + } + else + { + distanceArray[i] = 0.0; + } + } + + return true; + } + + int ToFCameraMESAController::SetIntegrationTime(unsigned int integrationTime) + { + return 0; + } + + int ToFCameraMESAController::GetIntegrationTime() + { + return 0; + } + + int ToFCameraMESAController::SetModulationFrequency(unsigned int modulationFrequency) + { + return 0; + } + + int ToFCameraMESAController::GetModulationFrequency() + { + return 0; + } + + void ToFCameraMESAController::SetInputFileName(std::string inputFileName) + { + this->m_InputFileName = inputFileName; + } +} diff --git a/Modules/ToFHardware/mitkToFCameraMESAController.h b/Modules/ToFHardware/mitkToFCameraMESAController.h new file mode 100644 index 0000000000..533e0fb95d --- /dev/null +++ b/Modules/ToFHardware/mitkToFCameraMESAController.h @@ -0,0 +1,146 @@ +/*========================================================================= + +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 __mitkToFCameraMESAController_h +#define __mitkToFCameraMESAController_h + +#include "mitkToFHardwareExports.h" +#include "mitkCommon.h" +#include "mitkToFCameraMESAController.h" + +#include "itkObject.h" +#include "itkObjectFactory.h" + +namespace mitk +{ + /** + * @brief Virtual interface and base class for all MESA Time-of-Flight devices. Wraps MESA API provided in library + * 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 ToFCameraMESAController : public itk::Object + { + public: + + mitkClassMacro( ToFCameraMESAController , 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 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 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 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 MESA 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); + + protected: + + ToFCameraMESAController(); + + ~ToFCameraMESAController(); + + /*! + \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 MESA function + \return flag indicating if an error occured (false) or not (true) + */ + bool ErrorText(int error); + + char m_MESAError[128]; ///< member holding the current error text + int m_MESARes; ///< holds the current result message provided by MESA + + 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_NumImg; ///< holds the number of images the camera provided (distance, intensity, etc) + + float m_MaxRangeFactor; ///< holds the factor to calculate the real distance depends on the modulation frequency + + bool m_ConnectionCheck; ///< flag showing whether the camera is connected (true) or not (false) + + std::string m_InputFileName; ///< input file name used by MESA player classes + + private: + + }; +} //END mitk namespace +#endif diff --git a/Modules/ToFHardware/mitkToFCameraMESADevice.cpp b/Modules/ToFHardware/mitkToFCameraMESADevice.cpp new file mode 100644 index 0000000000..b6fc0f4429 --- /dev/null +++ b/Modules/ToFHardware/mitkToFCameraMESADevice.cpp @@ -0,0 +1,451 @@ +/*========================================================================= + +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 "mitkToFCameraMESADevice.h" +#include "mitkRealTimeClock.h" + +#include "itkMultiThreader.h" +#include + +namespace mitk +{ + ToFCameraMESADevice::ToFCameraMESADevice() + { + } + + ToFCameraMESADevice::~ToFCameraMESADevice() + { + } + + bool ToFCameraMESADevice::ConnectCamera() + { + bool ok = false; + if (m_Controller) + { + ok = m_Controller->OpenCameraConnection(); + if (ok) + { + this->m_CaptureWidth = m_Controller->GetCaptureWidth(); + this->m_CaptureHeight = m_Controller->GetCaptureHeight(); + this->m_PixelNumber = this->m_CaptureWidth * this->m_CaptureHeight; + + // 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_DistanceDataBuffer = new float*[this->m_MaxBufferSize]; + for(int i=0; im_MaxBufferSize; i++) + { + this->m_DistanceDataBuffer[i] = new float[this->m_PixelNumber]; + } + this->m_AmplitudeDataBuffer = new float*[this->m_MaxBufferSize]; + for(int i=0; im_MaxBufferSize; i++) + { + this->m_AmplitudeDataBuffer[i] = new float[this->m_PixelNumber]; + } + this->m_IntensityDataBuffer = new float*[this->m_MaxBufferSize]; + for(int i=0; im_MaxBufferSize; i++) + { + this->m_IntensityDataBuffer[i] = new float[this->m_PixelNumber]; + } + + m_CameraConnected = true; + } + } + return ok; + } + + bool ToFCameraMESADevice::DisconnectCamera() + { + bool ok = false; + if (m_Controller) + { + ok = m_Controller->CloseCameraConnection(); + + // clean-up only if camera was connected + if (m_CameraConnected) + { + delete [] m_IntensityArray; + delete [] m_DistanceArray; + delete [] m_AmplitudeArray; + + for(int i=0; im_MaxBufferSize; i++) + { + delete[] this->m_DistanceDataBuffer[i]; + } + delete[] this->m_DistanceDataBuffer; + for(int i=0; im_MaxBufferSize; i++) + { + delete[] this->m_AmplitudeDataBuffer[i]; + } + delete[] this->m_AmplitudeDataBuffer; + for(int i=0; im_MaxBufferSize; i++) + { + delete[] this->m_IntensityDataBuffer[i]; + } + delete[] this->m_IntensityDataBuffer; + + m_CameraConnected = false; + } + + } + return ok; + } + + void ToFCameraMESADevice::StartCamera() + { + if (m_CameraConnected) + { + // get the first image + this->m_Controller->UpdateCamera(); + this->m_ImageMutex->Lock(); + this->m_Controller->GetDistances(this->m_DistanceDataBuffer[this->m_FreePos]); + this->m_Controller->GetAmplitudes(this->m_AmplitudeDataBuffer[this->m_FreePos]); + this->m_Controller->GetIntensities(this->m_IntensityDataBuffer[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(10); + } + else + { + MITK_INFO<<"Camera not connected"; + } + } + + void ToFCameraMESADevice::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 ToFCameraMESADevice::IsCameraActive() + { + m_CameraActiveMutex->Lock(); + bool ok = m_CameraActive; + m_CameraActiveMutex->Unlock(); + return ok; + } + + void ToFCameraMESADevice::UpdateCamera() + { + if (m_Controller) + { + m_Controller->UpdateCamera(); + } + } + + ITK_THREAD_RETURN_TYPE ToFCameraMESADevice::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; + } + ToFCameraMESADevice* toFCameraDevice = (ToFCameraMESADevice*)pInfo->UserData; + if (toFCameraDevice!=NULL) + { + mitk::RealTimeClock::Pointer realTimeClock; + 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 image data from the camera and write it at the next free position in the buffer + toFCameraDevice->m_Controller->GetDistances(toFCameraDevice->m_DistanceDataBuffer[toFCameraDevice->m_FreePos]); + toFCameraDevice->m_Controller->GetAmplitudes(toFCameraDevice->m_AmplitudeDataBuffer[toFCameraDevice->m_FreePos]); + toFCameraDevice->m_Controller->GetIntensities(toFCameraDevice->m_IntensityDataBuffer[toFCameraDevice->m_FreePos]); + + // call modified to indicate that cameraDevice was modified + toFCameraDevice->Modified(); + + /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + TODO Buffer Handling currently only works for buffer size 1 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/ + toFCameraDevice->m_ImageMutex->Lock(); + //toFCameraDevice->m_ImageSequence++; + 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) + { + // buffer overflow + //MITK_INFO << "Buffer overflow!! "; + //toFCameraDevice->m_CurrentPos = (toFCameraDevice->m_CurrentPos+1) % toFCameraDevice->m_BufferSize; + //toFCameraDevice->m_ImageSequence++; + overflow = true; + } + if (toFCameraDevice->m_ImageSequence % n == 0) + { + printStatus = true; + } + toFCameraDevice->m_ImageMutex->Unlock(); + if (overflow) + { + //itksys::SystemTools::Delay(10); + 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 ToFCameraMESADevice::ResetBuffer(int bufferSize) + // { + // this->m_BufferSize = bufferSize; + // this->m_CurrentPos = -1; + // this->m_FreePos = 0; + // } + + void ToFCameraMESADevice::GetAmplitudes(float* amplitudeArray, int& imageSequence) + { + m_ImageMutex->Lock(); + if (m_CameraActive) + { + // 1) copy the image buffer + // 2) Flip around y- axis (vertical axis) + + /* + this->m_Controller->GetAmplitudes(this->m_SourceDataBuffer[this->m_CurrentPos], this->m_AmplitudeArray); + for (int i=0; im_CaptureHeight; i++) + { + for (int j=0; jm_CaptureWidth; j++) + { + amplitudeArray[i*this->m_CaptureWidth+j] = this->m_AmplitudeArray[(i+1)*this->m_CaptureWidth-1-j]; + } + } + */ + for (int i=0; im_PixelNumber; i++) + { + amplitudeArray[i] = this->m_AmplitudeDataBuffer[this->m_CurrentPos][i]; + } + imageSequence = this->m_ImageSequence; + } + else + { + MITK_WARN("ToF") << "Warning: Data can only be acquired if camera is active."; + } + m_ImageMutex->Unlock(); + } + + void ToFCameraMESADevice::GetIntensities(float* intensityArray, int& imageSequence) + { + m_ImageMutex->Lock(); + if (m_CameraActive) + { + // 1) copy the image buffer + // 2) Flip around y- axis (vertical axis) + + /* + this->m_Controller->GetIntensities(this->m_SourceDataBuffer[this->m_CurrentPos], this->m_IntensityArray); + for (int i=0; im_CaptureHeight; i++) + { + for (int j=0; jm_CaptureWidth; j++) + { + intensityArray[i*this->m_CaptureWidth+j] = this->m_IntensityArray[(i+1)*this->m_CaptureWidth-1-j]; + } + } + */ + for (int i=0; im_PixelNumber; i++) + { + intensityArray[i] = this->m_IntensityDataBuffer[this->m_CurrentPos][i]; + } + imageSequence = this->m_ImageSequence; + } + else + { + MITK_WARN("ToF") << "Warning: Data can only be acquired if camera is active."; + } + m_ImageMutex->Unlock(); + } + + void ToFCameraMESADevice::GetDistances(float* distanceArray, int& imageSequence) + { + m_ImageMutex->Lock(); + if (m_CameraActive) + { + // 1) copy the image buffer + // 2) convert the distance values from m to mm + // 3) Flip around y- axis (vertical axis) + + /* + this->m_Controller->GetDistances(this->m_SourceDataBuffer[this->m_CurrentPos], this->m_DistanceArray); + for (int i=0; im_CaptureHeight; i++) + { + for (int j=0; jm_CaptureWidth; j++) + { + distanceArray[i*this->m_CaptureWidth+j] = 1000 * this->m_DistanceArray[(i+1)*this->m_CaptureWidth-1-j]; + } + } + */ + for (int i=0; im_PixelNumber; i++) + { + distanceArray[i] = this->m_DistanceDataBuffer[this->m_CurrentPos][i]; // * 1000 + } + imageSequence = this->m_ImageSequence; + } + else + { + MITK_WARN("ToF") << "Warning: Data can only be acquired if camera is active."; + } + m_ImageMutex->Unlock(); + } + + void ToFCameraMESADevice::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; + } + + // write image data to float arrays + for (int i=0; im_PixelNumber; i++) + { + distanceArray[i] = this->m_DistanceDataBuffer[pos][i] /* * 1000 */; + amplitudeArray[i] = this->m_AmplitudeDataBuffer[pos][i]; + intensityArray[i] = this->m_IntensityDataBuffer[pos][i]; + } + + m_ImageMutex->Unlock(); + + /* + this->m_Controller->GetDistances(this->m_SourceDataBuffer[pos], this->m_DistanceArray); + this->m_Controller->GetAmplitudes(this->m_SourceDataBuffer[pos], this->m_AmplitudeArray); + this->m_Controller->GetIntensities(this->m_SourceDataBuffer[pos], this->m_IntensityArray); + + 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] = 1000 * this->m_DistanceArray[v]; // unit in mm + //distanceArray[u] = this->m_DistanceArray[v]; // unit in meter + 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."; + } + } + + ToFCameraMESAController::Pointer ToFCameraMESADevice::GetController() + { + return this->m_Controller; + } + + void ToFCameraMESADevice::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); + } + } +} diff --git a/Modules/ToFHardware/mitkToFCameraMESADevice.h b/Modules/ToFHardware/mitkToFCameraMESADevice.h new file mode 100644 index 0000000000..af9248feef --- /dev/null +++ b/Modules/ToFHardware/mitkToFCameraMESADevice.h @@ -0,0 +1,148 @@ +/*========================================================================= + +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 __mitkToFCameraMESADevice_h +#define __mitkToFCameraMESADevice_h + +#include "mitkToFHardwareExports.h" +#include "mitkCommon.h" +#include "mitkToFCameraDevice.h" +#include "mitkToFCameraMESAController.h" + +#include "itkObject.h" +#include "itkObjectFactory.h" +#include "itkMultiThreader.h" +#include "itkFastMutexLock.h" + + +namespace mitk +{ + /** + * @brief Interface for all representations of MESA ToF devices. + * ToFCameraMESADevice internally holds an instance of ToFCameraMESAController 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 ToFCameraMESADevice : public ToFCameraDevice + { + public: + + mitkClassMacro( ToFCameraMESADevice , ToFCameraDevice ); + + itkNewMacro( Self ); + + /*! + \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 + */ + ToFCameraMESAController::Pointer GetController(); + + /*! + \brief set a BaseProperty + */ + virtual void SetProperty( const char *propertyKey, BaseProperty* propertyValue ); + + protected: + + ToFCameraMESADevice(); + + ~ToFCameraMESADevice(); + + /*! + \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(); + + ToFCameraMESAController::Pointer m_Controller; ///< corresponding CameraController + + float** m_DistanceDataBuffer; ///< buffer holding the last distance images + float** m_AmplitudeDataBuffer; ///< buffer holding the last amplitude images + float** m_IntensityDataBuffer; ///< buffer holding the last intensity images + + private: + + }; +} //END mitk namespace +#endif diff --git a/Modules/ToFHardware/mitkToFCameraMESASR4000Controller.cpp b/Modules/ToFHardware/mitkToFCameraMESASR4000Controller.cpp new file mode 100644 index 0000000000..e621703a0e --- /dev/null +++ b/Modules/ToFHardware/mitkToFCameraMESASR4000Controller.cpp @@ -0,0 +1,229 @@ +/*========================================================================= + +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 "mitkToFCameraMESASR4000Controller.h" +#include "mitkToFConfig.h" +#include + +extern CMesaDevice* m_MESAHandle; + +namespace mitk +{ + ToFCameraMESASR4000Controller::ToFCameraMESASR4000Controller() + { + this->m_Lambda = new float[MF_LAST]; + this->m_Frequency = new float[MF_LAST]; + this->m_Lambda[0] = 3.75f; + this->m_Lambda[1] = 5.0f; + this->m_Lambda[2] = 7.142857f; + this->m_Lambda[3] = 7.5f; + this->m_Lambda[4] = 7.894737f; + this->m_Lambda[5] = 2.5f; + this->m_Lambda[6] = 10.0f; + this->m_Lambda[7] = 15.0f; + this->m_Lambda[8] = 5.172414f; + this->m_Lambda[9] = 4.838710f; + this->m_Lambda[10] = 10.344828f; + this->m_Lambda[11] = 9.677419f; + this->m_Frequency[0] = 40.0f; + this->m_Frequency[1] = 30.0f; + this->m_Frequency[2] = 21.0f; + this->m_Frequency[3] = 20.0f; + this->m_Frequency[4] = 19.0f; + this->m_Frequency[5] = 60.0f; + this->m_Frequency[6] = 15.0f; + this->m_Frequency[7] = 10.0f; + this->m_Frequency[8] = 29.0f; + this->m_Frequency[9] = 31.0f; + this->m_Frequency[10] = 14.5f; + this->m_Frequency[11] = 15.5f; + } + + ToFCameraMESASR4000Controller::~ToFCameraMESASR4000Controller() + { + } + + bool ToFCameraMESASR4000Controller::OpenCameraConnection() + { + if(!m_ConnectionCheck) + { + /* + 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; + */ + //m_MESARes = SR_OpenDlg(&m_MESAHandle, 3, 0); + this->m_MESARes = SR_OpenUSB(&m_MESAHandle, 0); + this->m_ConnectionCheck = ErrorText(this->m_MESARes); + if (m_MESARes <= 0) + { + this->m_ConnectionCheck = false; + return this->m_ConnectionCheck; + } + + this->m_MESARes = SR_GetRows(m_MESAHandle); + this->m_CaptureHeight = this->m_MESARes; + this->m_MESARes = SR_GetCols(m_MESAHandle); + this->m_CaptureWidth = this->m_MESARes; + this->m_PixelNumber = this->m_CaptureWidth*this->m_CaptureHeight; + this->m_NumberOfBytes = this->m_PixelNumber * sizeof(float); + + ImgEntry* imgEntryArray; + this->m_NumImg = SR_GetImageList(m_MESAHandle, &imgEntryArray); + + //float lambda[MF_LAST]={3.75f, 5.f, 7.142857f, 7.5f, 7.894737f, 2.5f, 10.f, 15.f, 5.172414f, 4.838710f, 10.344828f, 9.677419f};//MF_40MHz,MF_30MHz,MF_21MHz,MF_20MHz,MF_19MHz,... + //float frequency[MF_LAST]={40.00f, 30.00f, 21.00f, 20.00f, 19.00f, 60.00f, 15.00f, 10.00f, 29.00f, 31.00f, 14.50f, 15.50f}; + ModulationFrq frq = SR_GetModulationFrequency(m_MESAHandle); + + this->m_MaxRangeFactor = (this->m_Lambda[frq] * 1000.00) / (float)0xffff; + + unsigned char integrationTime8bit = SR_GetIntegrationTime(m_MESAHandle); + float integrationTime = (0.3 + ((int)integrationTime8bit) * 0.1) * 1000; // for MESA4000 + + char deviceText[1024]; + this->m_MESARes = SR_GetDeviceString(m_MESAHandle, deviceText, _countof(deviceText));//returns the device ID used in other calls + MITK_INFO << "Device ID: " << deviceText <m_NumImg <m_CaptureWidth << " x " << this->m_CaptureHeight <m_Frequency[frq] << " MHz" <m_Lambda[frq] << " m" <m_MESARes = SR_SetIntegrationTime(m_MESAHandle, intTime); + MITK_INFO << "New integration time: " << integrationTime << " microsec" <m_MESARes = SR_SetModulationFrequency (m_MESAHandle, frq); + if (this->m_MESARes == 0) + { + this->m_MaxRangeFactor = (this->m_Lambda[frq] * 1000.00) / (float)0xffff; + MITK_INFO << "New modulation frequency: " << this->m_Frequency[frq] << " MHz" <m_MESARes; + } + } + + int ToFCameraMESASR4000Controller::GetModulationFrequency() + { + ModulationFrq frq = SR_GetModulationFrequency(m_MESAHandle); + this->m_MaxRangeFactor = (this->m_Lambda[frq] * 1000.00) / (float)0xffff; + float frequency = this->m_Frequency[frq]; + return (int)frequency; // TODO float!! + } + + void ToFCameraMESASR4000Controller::SetFPN( bool fpn ) + { + int acquireMode; + acquireMode = SR_GetMode(m_MESAHandle); + acquireMode &= ~AM_COR_FIX_PTRN; + if (fpn) + { + acquireMode |= AM_COR_FIX_PTRN; + } + this->m_MESARes = SR_SetMode(m_MESAHandle, acquireMode); + } + + void ToFCameraMESASR4000Controller::SetConvGray( bool ConvGray ) + { + int acquireMode; + acquireMode = SR_GetMode(m_MESAHandle); + acquireMode &= ~AM_CONV_GRAY; + if (ConvGray) + { + acquireMode |= AM_CONV_GRAY; + } + this->m_MESARes = SR_SetMode(m_MESAHandle, acquireMode); + } + + void ToFCameraMESASR4000Controller::SetMedian( bool median ) + { + int acquireMode; + acquireMode = SR_GetMode(m_MESAHandle); + acquireMode &= ~AM_MEDIAN; + if (median) + { + acquireMode |= AM_MEDIAN; + } + this->m_MESARes = SR_SetMode(m_MESAHandle, acquireMode); + } + + void ToFCameraMESASR4000Controller::SetANF( bool anf ) + { + int acquireMode; + acquireMode = SR_GetMode(m_MESAHandle); + acquireMode &= ~AM_DENOISE_ANF; + if (anf) + { + acquireMode |= AM_DENOISE_ANF; + } + this->m_MESARes = SR_SetMode(m_MESAHandle, acquireMode); + } + +} \ No newline at end of file diff --git a/Modules/ToFHardware/mitkToFCameraMESASR4000Controller.h b/Modules/ToFHardware/mitkToFCameraMESASR4000Controller.h new file mode 100644 index 0000000000..0bc560afe5 --- /dev/null +++ b/Modules/ToFHardware/mitkToFCameraMESASR4000Controller.h @@ -0,0 +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 __mitkToFCameraMESASR4000Controller_h +#define __mitkToFCameraMESASR4000Controller_h + +#include "mitkToFHardwareExports.h" +#include "mitkCommon.h" +#include "mitkToFCameraMESAController.h" + +#include "itkObject.h" +#include "itkObjectFactory.h" + +namespace mitk +{ + /** + * @brief Interface to the Time-of-Flight (ToF) camera MESA Swissranger 4000 + * + * + * @ingroup ToFHardware + */ + class MITK_TOFHARDWARE_EXPORT ToFCameraMESASR4000Controller : public mitk::ToFCameraMESAController + { + public: + + mitkClassMacro( ToFCameraMESASR4000Controller , mitk::ToFCameraMESAController ); + + itkNewMacro( Self ); + + /*! + \brief opens a connection to the ToF camera and initializes the hardware specific members + \return returns whether the connection was successful (true) or not (false) + */ + virtual bool OpenCameraConnection(); + /*! + \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 Sets the acquire mode of the MESA SR4000 camera. + The method sets some parameter supported by the MESA SR4000, see MESA API for more details. + \param fpn turns on fix pattern noise correction this should always be enabled for good distance measurement + */ + virtual void SetFPN( bool fpn ); + /*! + \brief Sets the acquire mode of the MESA SR4000 camera. + The method sets some parameter supported by the MESA SR4000, see MESA API for more details. + \param convGray Converts the amplitude image by multiplying by the square of the distance, resulting in image more like a conventional camera + */ + virtual void SetConvGray( bool convGray ); + /*! + \brief Sets the acquire mode of the MESA SR4000 camera. + The method sets some parameter supported by the MESA SR4000, see MESA API for more details. + \param median turns on a 3x3 median filter + */ + virtual void SetMedian( bool median ); + /*! + \brief Sets the acquire mode of the MESA SR4000 camera. + The method sets some parameter supported by the MESA SR4000, see MESA API for more details. + \param anf Turns on the 5x5 hardware adaptive neighborhood filter + */ + virtual void SetANF( bool anf ); + + protected: + + ToFCameraMESASR4000Controller(); + + ~ToFCameraMESASR4000Controller(); + + private: + + float *m_Lambda; + + float *m_Frequency; + + }; +} //END mitk namespace +#endif diff --git a/Modules/ToFHardware/mitkToFCameraMESASR4000ControllerStub.cpp b/Modules/ToFHardware/mitkToFCameraMESASR4000ControllerStub.cpp new file mode 100644 index 0000000000..5b33b528d2 --- /dev/null +++ b/Modules/ToFHardware/mitkToFCameraMESASR4000ControllerStub.cpp @@ -0,0 +1,41 @@ +/*========================================================================= + +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 "mitkToFCameraMESASR4000Controller.h" +#include "mitkToFConfig.h" +#include + +extern CMesaDevice* m_MESAHandle; + +namespace mitk +{ + ToFCameraMESASR4000Controller::ToFCameraMESASR4000Controller() + { + MITK_WARN("ToF") << "Error: MESA SR4000 currently not available"; + } + + ToFCameraMESASR4000Controller::~ToFCameraMESASR4000Controller() + { + MITK_WARN("ToF") << "Error: MESA SR4000 currently not available"; + } + + bool ToFCameraMESASR4000Controller::OpenCameraConnection() + { + MITK_WARN("ToF") << "Error: MESA SR4000 currently not available"; + return true; + } +} diff --git a/Modules/ToFHardware/mitkToFCameraMESASR4000Device.cpp b/Modules/ToFHardware/mitkToFCameraMESASR4000Device.cpp new file mode 100644 index 0000000000..c5ae49af28 --- /dev/null +++ b/Modules/ToFHardware/mitkToFCameraMESASR4000Device.cpp @@ -0,0 +1,71 @@ +/*========================================================================= + +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 "mitkToFCameraMESASR4000Device.h" +#include "mitkToFCameraMESASR4000Controller.h" +#include "mitkRealTimeClock.h" + +#include "itkMultiThreader.h" + + +namespace mitk +{ + ToFCameraMESASR4000Device::ToFCameraMESASR4000Device() + { + m_Controller = ToFCameraMESASR4000Controller::New(); + } + + ToFCameraMESASR4000Device::~ToFCameraMESASR4000Device() + { + } + + void ToFCameraMESASR4000Device::SetRegionOfInterest(unsigned int leftUpperCornerX, unsigned int leftUpperCornerY, unsigned int width, unsigned int height) + { + //if (m_Controller.IsNotNull()) + //{ + // dynamic_cast(m_Controller.GetPointer())->SetRegionOfInterest(leftUpperCornerX,leftUpperCornerY,width,height); + //} + } + + void ToFCameraMESASR4000Device::SetProperty( const char *propertyKey, BaseProperty* propertyValue ) + { + ToFCameraMESADevice::SetProperty(propertyKey,propertyValue); + this->m_PropertyList->SetProperty(propertyKey, propertyValue); + + ToFCameraMESASR4000Controller::Pointer myController = dynamic_cast(this->m_Controller.GetPointer()); + + bool boolValue = false; + GetBoolProperty(propertyValue, boolValue); + if (strcmp(propertyKey, "SetFPN") == 0) + { + myController->SetFPN(boolValue); + } + else if (strcmp(propertyKey, "SetConvGray") == 0) + { + myController->SetConvGray(boolValue); + } + else if (strcmp(propertyKey, "SetMedian") == 0) + { + myController->SetMedian(boolValue); + } + else if (strcmp(propertyKey, "SetANF") == 0) + { + myController->SetANF(boolValue); + } + } + +} diff --git a/Modules/ToFHardware/mitkToFCameraMESASR4000Device.h b/Modules/ToFHardware/mitkToFCameraMESASR4000Device.h new file mode 100644 index 0000000000..067f40e6af --- /dev/null +++ b/Modules/ToFHardware/mitkToFCameraMESASR4000Device.h @@ -0,0 +1,72 @@ +/*========================================================================= + +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 __mitkToFCameraMESASR4000Device_h +#define __mitkToFCameraMESASR4000Device_h + +#include "mitkToFHardwareExports.h" +#include "mitkCommon.h" +#include "mitkToFCameraDevice.h" +#include "mitkToFCameraMESADevice.h" +#include "mitkToFCameraMESASR4000Controller.h" + +#include "itkObject.h" +#include "itkObjectFactory.h" +#include "itkMultiThreader.h" +#include "itkFastMutexLock.h" + + +namespace mitk +{ + /** + * @brief Device class representing a MESA CamBoard camera + * + * @ingroup ToFHardware + */ + class MITK_TOFHARDWARE_EXPORT ToFCameraMESASR4000Device : public ToFCameraMESADevice + { + public: + + mitkClassMacro( ToFCameraMESASR4000Device , ToFCameraMESADevice ); + + itkNewMacro( Self ); + + /*! + \brief set a BaseProperty + */ + virtual void SetProperty( const char *propertyKey, BaseProperty* propertyValue ); + /*! + \brief Setting the region of interest, the camera is configured to only output a certain area of the image. + \param leftUpperCornerX x value of left upper corner of region + \param leftUpperCornerX y value of left upper corner of region + \param width width of region + \param height height of region + */ + void SetRegionOfInterest( unsigned int leftUpperCornerX, unsigned int leftUpperCornerY, unsigned int width, unsigned int height ); + + protected: + + ToFCameraMESASR4000Device(); + + ~ToFCameraMESASR4000Device(); + + + private: + + }; +} //END mitk namespace +#endif diff --git a/Modules/ToFHardware/mitkToFHardware.cmake b/Modules/ToFHardware/mitkToFHardware.cmake index ed03801df7..adadcafa6b 100644 --- a/Modules/ToFHardware/mitkToFHardware.cmake +++ b/Modules/ToFHardware/mitkToFHardware.cmake @@ -1,92 +1,107 @@ #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) 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) # 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) # 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 Camcube Hardware +#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.") + 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) # 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 4217f88439..516f58cd49 100644 --- a/Modules/ToFHardware/mitkToFImageGrabberCreator.cpp +++ b/Modules/ToFHardware/mitkToFImageGrabberCreator.cpp @@ -1,91 +1,100 @@ /*========================================================================= 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 "mitkToFCameraPMDCamBoardDevice.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::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::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 d3175d42de..35d965d6bf 100644 --- a/Modules/ToFHardware/mitkToFImageGrabberCreator.h +++ b/Modules/ToFHardware/mitkToFImageGrabberCreator.h @@ -1,100 +1,105 @@ /*========================================================================= 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 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 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/ToFProcessing/mitkToFDistanceImageToSurfaceFilter.cpp b/Modules/ToFProcessing/mitkToFDistanceImageToSurfaceFilter.cpp index 2eb280d1ee..934b1bc0c0 100644 --- a/Modules/ToFProcessing/mitkToFDistanceImageToSurfaceFilter.cpp +++ b/Modules/ToFProcessing/mitkToFDistanceImageToSurfaceFilter.cpp @@ -1,253 +1,253 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit Module: $RCSfile$ Language: C++ Date: $Date$ Version: $Revision$ Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notices for more information. =========================================================================*/ #include #include #include #include #include #include #include #include #include #include #include #include #include mitk::ToFDistanceImageToSurfaceFilter::ToFDistanceImageToSurfaceFilter(): m_CameraIntrinsics(), m_TextureImageWidth(0), m_TextureImageHeight(0), m_IplScalarImage(NULL), m_InterPixelDistance() { m_InterPixelDistance.Fill(0.045); m_CameraIntrinsics = mitk::CameraIntrinsics::New(); m_CameraIntrinsics->SetFocalLength(295.78960196187319,296.1255427948447); m_CameraIntrinsics->SetPrincipalPoint(113.29063841714108,97.243216122015184); m_CameraIntrinsics->SetDistorsionCoeffs(-0.36874385358645773f,-0.14339503290129013,0.0033210108720361795,-0.004277703352074105); } mitk::ToFDistanceImageToSurfaceFilter::~ToFDistanceImageToSurfaceFilter() { } void mitk::ToFDistanceImageToSurfaceFilter::SetInput( Image* distanceImage, mitk::CameraIntrinsics::Pointer cameraIntrinsics ) { this->SetCameraIntrinsics(cameraIntrinsics); this->SetInput(0,distanceImage); } void mitk::ToFDistanceImageToSurfaceFilter::SetInput( unsigned int idx, Image* distanceImage, mitk::CameraIntrinsics::Pointer cameraIntrinsics ) { this->SetCameraIntrinsics(cameraIntrinsics); this->SetInput(idx,distanceImage); } void mitk::ToFDistanceImageToSurfaceFilter::SetInput( mitk::Image* distanceImage ) { this->SetInput(0,distanceImage); } //TODO: braucht man diese Methode? void mitk::ToFDistanceImageToSurfaceFilter::SetInput( unsigned int idx, mitk::Image* distanceImage ) { if ((distanceImage == NULL) && (idx == this->GetNumberOfInputs() - 1)) // if the last input is set to NULL, reduce the number of inputs by one this->SetNumberOfInputs(this->GetNumberOfInputs() - 1); else this->ProcessObject::SetNthInput(idx, distanceImage); // Process object is not const-correct so the const_cast is required here this->CreateOutputsForAllInputs(); } mitk::Image* mitk::ToFDistanceImageToSurfaceFilter::GetInput() { return this->GetInput(0); } mitk::Image* mitk::ToFDistanceImageToSurfaceFilter::GetInput( unsigned int idx ) { if (this->GetNumberOfInputs() < 1) return NULL; //TODO: geeignete exception werfen return static_cast< mitk::Image*>(this->ProcessObject::GetInput(idx)); } void mitk::ToFDistanceImageToSurfaceFilter::GenerateData() { mitk::Surface::Pointer output = this->GetOutput(); assert(output); mitk::Image::Pointer input = this->GetInput(); assert(input); // mesh points unsigned int xDimension = input->GetDimension(0); unsigned int yDimension = input->GetDimension(1); unsigned int size = xDimension*yDimension; //size of the image-array std::vector isPointValid; isPointValid.resize(size); int pointCount = 0; vtkSmartPointer points = vtkSmartPointer::New(); points->SetDataTypeToDouble(); vtkSmartPointer polys = vtkSmartPointer::New(); vtkSmartPointer scalarArray = vtkSmartPointer::New(); vtkSmartPointer textureCoords = vtkSmartPointer::New(); textureCoords->SetNumberOfComponents(2); float textureScaleCorrection1 = 0.0; float textureScaleCorrection2 = 0.0; if (this->m_TextureImageHeight > 0.0 && this->m_TextureImageWidth > 0.0) { textureScaleCorrection1 = float(this->m_TextureImageHeight) / float(this->m_TextureImageWidth); textureScaleCorrection2 = ((float(this->m_TextureImageWidth) - float(this->m_TextureImageHeight))/2) / float(this->m_TextureImageWidth); } float* scalarFloatData = NULL; if (this->m_IplScalarImage) // if scalar image is defined use it for texturing { scalarFloatData = (float*)this->m_IplScalarImage->imageData; } else if ((this->GetNumberOfInputs()>2)&&this->GetInput(2)) // otherwise use intensity image (input(2)) { scalarFloatData = (float*)this->GetInput(2)->GetData(); } float* inputFloatData = (float*)(input->GetSliceData(0, 0, 0)->GetData()); - //calculate world coordinates mitk::ToFProcessingCommon::ToFScalarType focalLength = (m_CameraIntrinsics->GetFocalLengthX()*m_InterPixelDistance[0]+m_CameraIntrinsics->GetFocalLengthY()*m_InterPixelDistance[1])/2.0; mitk::ToFProcessingCommon::ToFPoint2D principalPoint; principalPoint[0] = m_CameraIntrinsics->GetPrincipalPointX(); principalPoint[1] = m_CameraIntrinsics->GetPrincipalPointY(); for (int j=0; jInsertPoint(pixelID, cartesianCoordinates.GetDataPointer()); if((i >= 1) && (j >= 1)) { vtkIdType xy = i+j*xDimension; vtkIdType x_1y = i-1+j*xDimension; vtkIdType xy_1 = i+(j-1)*xDimension; vtkIdType x_1y_1 = (i-1)+(j-1)*xDimension; if (isPointValid[xy]&&isPointValid[x_1y]&&isPointValid[x_1y_1]&&isPointValid[xy_1]) // check if points of cell are valid { polys->InsertNextCell(3); polys->InsertCellPoint(xy); polys->InsertCellPoint(x_1y); polys->InsertCellPoint(x_1y_1); polys->InsertNextCell(3); polys->InsertCellPoint(xy); polys->InsertCellPoint(x_1y_1); polys->InsertCellPoint(xy_1); } } if (scalarFloatData) { scalarArray->InsertTuple1(pixelID, scalarFloatData[pixel[0]+pixel[1]*xDimension]); + //scalarArray->InsertTuple1(pixelID, scalarFloatData[pixelID]); } if (this->m_TextureImageHeight > 0.0 && this->m_TextureImageWidth > 0.0) { float xNorm = (((float)pixel[0])/xDimension)*textureScaleCorrection1 + textureScaleCorrection2 ; // correct video texture scale 640 * 480!! float yNorm = 1.0 - ((float)pixel[1])/yDimension; //flip y-axis textureCoords->InsertTuple2(pixelID, xNorm, yNorm); } } pointCount++; } } vtkSmartPointer mesh = vtkSmartPointer::New(); mesh->SetPoints(points); mesh->SetPolys(polys); if (scalarArray->GetNumberOfTuples()>0) { mesh->GetPointData()->SetScalars(scalarArray); if (this->m_TextureImageHeight > 0.0 && this->m_TextureImageWidth > 0.0) { mesh->GetPointData()->SetTCoords(textureCoords); } } output->SetVtkPolyData(mesh); } void mitk::ToFDistanceImageToSurfaceFilter::CreateOutputsForAllInputs() { this->SetNumberOfOutputs(this->GetNumberOfInputs()); // create outputs for all inputs for (unsigned int idx = 0; idx < this->GetNumberOfOutputs(); ++idx) if (this->GetOutput(idx) == NULL) { DataObjectPointer newOutput = this->MakeOutput(idx); this->SetNthOutput(idx, newOutput); } this->Modified(); } void mitk::ToFDistanceImageToSurfaceFilter::GenerateOutputInformation() { this->GetOutput(); itkDebugMacro(<<"GenerateOutputInformation()"); } void mitk::ToFDistanceImageToSurfaceFilter::SetScalarImage(IplImage* iplScalarImage) { this->m_IplScalarImage = iplScalarImage; this->Modified(); } IplImage* mitk::ToFDistanceImageToSurfaceFilter::GetScalarImage() { return this->m_IplScalarImage; } void mitk::ToFDistanceImageToSurfaceFilter::SetTextureImageWidth(int width) { this->m_TextureImageWidth = width; } void mitk::ToFDistanceImageToSurfaceFilter::SetTextureImageHeight(int height) { this->m_TextureImageHeight = height; } diff --git a/Modules/ToFUI/Qmitk/QmitkToFConnectionWidget.cpp b/Modules/ToFUI/Qmitk/QmitkToFConnectionWidget.cpp index 36a6aba93e..5a3cb61fbf 100644 --- a/Modules/ToFUI/Qmitk/QmitkToFConnectionWidget.cpp +++ b/Modules/ToFUI/Qmitk/QmitkToFConnectionWidget.cpp @@ -1,359 +1,424 @@ /*========================================================================= 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 //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(); + + 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(int)), this, SLOT(OnSelectCamera(int)) ); connect( m_Controls->m_SelectCameraCombobox, SIGNAL(activated(int)), this, SLOT(OnSelectCamera(int)) ); connect( m_Controls->m_SelectCameraCombobox, SIGNAL(activated(int)), this, SIGNAL(ToFCameraSelected(int)) ); - connect( m_Controls->m_IntegrationTimeSpinBox, SIGNAL(valueChanged(int)), this, SLOT(OnChangeIntegrationTimeSpinBox(int)) ); - connect( m_Controls->m_ModulationFrequencySpinBox, SIGNAL(valueChanged(int)), this, SLOT(OnChangeModulationFrequencySpinBox(int)) ); + //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() +{ + int selectedCamera = m_Controls->m_SelectCameraCombobox->currentIndex(); + switch (selectedCamera) + { + case 0: + case 1: + case 2: ShowPMDParameterWidget(); + break; + case 3: ShowMESAParameterWidget(); + break; + default: 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(int index) { if (index == 0) // PMD camcube 2 { - m_Controls->m_IntegrationTimeSpinBox->setEnabled(true); - m_Controls->m_ModulationFrequencySpinBox->setEnabled(true); - m_Controls->m_CalibrationParameterGroupBox->setEnabled(true); + //m_Controls->m_IntegrationTimeSpinBox->setEnabled(true); + //m_Controls->m_ModulationFrequencySpinBox->setEnabled(true); + //m_Controls->m_CalibrationParameterGroupBox->setEnabled(true); + ShowPMDParameterWidget(); } else if (index == 1) // pmd camboard { - m_Controls->m_IntegrationTimeSpinBox->setEnabled(true); - m_Controls->m_ModulationFrequencySpinBox->setEnabled(true); - m_Controls->m_CalibrationParameterGroupBox->setEnabled(false); + //m_Controls->m_IntegrationTimeSpinBox->setEnabled(true); + //m_Controls->m_ModulationFrequencySpinBox->setEnabled(true); + //m_Controls->m_CalibrationParameterGroupBox->setEnabled(false); + ShowPMDParameterWidget(); } else if (index == 2) // pmd O3d { - m_Controls->m_IntegrationTimeSpinBox->setEnabled(true); - m_Controls->m_ModulationFrequencySpinBox->setEnabled(true); - m_Controls->m_CalibrationParameterGroupBox->setEnabled(false); + //m_Controls->m_IntegrationTimeSpinBox->setEnabled(true); + //m_Controls->m_ModulationFrequencySpinBox->setEnabled(true); + //m_Controls->m_CalibrationParameterGroupBox->setEnabled(false); + ShowPMDParameterWidget(); } - else if (index == 3) // pmd file player + else if (index == 3) // MESA 4000 { - m_Controls->m_IntegrationTimeSpinBox->setEnabled(false); - m_Controls->m_ModulationFrequencySpinBox->setEnabled(false); - m_Controls->m_CalibrationParameterGroupBox->setEnabled(false); + ShowMESAParameterWidget(); } - else if (index == 4) // pmd raw data player + else if (index == 4) // pmd file player { - m_Controls->m_IntegrationTimeSpinBox->setEnabled(false); - m_Controls->m_ModulationFrequencySpinBox->setEnabled(false); - m_Controls->m_CalibrationParameterGroupBox->setEnabled(false); + //m_Controls->m_IntegrationTimeSpinBox->setEnabled(false); + //m_Controls->m_ModulationFrequencySpinBox->setEnabled(false); + //m_Controls->m_CalibrationParameterGroupBox->setEnabled(false); + ShowPlayerParameterWidget(); } - else if (index == 5) // mitk player + else if (index == 5) // pmd raw data player { - m_Controls->m_IntegrationTimeSpinBox->setEnabled(false); - m_Controls->m_ModulationFrequencySpinBox->setEnabled(false); - m_Controls->m_CalibrationParameterGroupBox->setEnabled(false); + //m_Controls->m_IntegrationTimeSpinBox->setEnabled(false); + //m_Controls->m_ModulationFrequencySpinBox->setEnabled(false); + //m_Controls->m_CalibrationParameterGroupBox->setEnabled(false); + ShowPlayerParameterWidget(); + } + else if (index == 6) // 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); +// m_Controls->m_CalibrationParameterGroupBox->setEnabled(false); //repaint the widget this->repaint(); QString tmpFileName(""); QString fileFilter(""); //select the camera to connect with int selectedCamera = m_Controls->m_SelectCameraCombobox->currentIndex(); if (selectedCamera == 0) { //PMD CamCube this->m_ToFImageGrabber = mitk::ToFImageGrabberCreator::GetInstance()->GetPMDCamCubeImageGrabber(); } else if (selectedCamera == 1) { //PMD CamBoard this->m_ToFImageGrabber = mitk::ToFImageGrabberCreator::GetInstance()->GetPMDCamBoardImageGrabber(); } else if (selectedCamera == 2) {//PMD O3 this->m_ToFImageGrabber = mitk::ToFImageGrabberCreator::GetInstance()->GetPMDO3ImageGrabber(); } else if (selectedCamera == 3) + {//MESA SR4000 + this->m_ToFImageGrabber = mitk::ToFImageGrabberCreator::GetInstance()->GetMESASR4000ImageGrabber(); + } + else if (selectedCamera == 4) {//PMD player playerMode = true; fileFilter.append("PMD Files (*.pmd)"); this->m_ToFImageGrabber = mitk::ToFImageGrabberCreator::GetInstance()->GetPMDPlayerImageGrabber(); } - else if (selectedCamera == 4) + else if (selectedCamera == 5) {//PMD MITK player playerMode = true; fileFilter.append("MITK Images (*.pic)"); this->m_ToFImageGrabber = mitk::ToFImageGrabberCreator::GetInstance()->GetPMDMITKPlayerImageGrabber(); } - else if (selectedCamera == 5) + else if (selectedCamera == 6) {//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); +// m_Controls->m_CalibrationParameterGroupBox->setEnabled(true); OnSelectCamera(m_Controls->m_SelectCameraCombobox->currentIndex()); QMessageBox::information( this, "Template functionality", "Please select a valid image before starting some action."); return; } - if(selectedCamera == 3) + if(selectedCamera == 4) { //set the PMD file name this->m_ToFImageGrabber->SetStringProperty("PMDFileName", tmpFileName.toStdString().c_str() ); } - if (selectedCamera == 4 || selectedCamera == 5) + if (selectedCamera == 5 || selectedCamera == 6) { 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); +// m_Controls->m_CalibrationParameterGroupBox->setEnabled(true); OnSelectCamera(m_Controls->m_SelectCameraCombobox->currentIndex()); return; } } } //if a connection could be established - if (m_ToFImageGrabber->ConnectCamera()) + if (this->m_ToFImageGrabber->ConnectCamera()) { + this->m_Controls->m_PMDParameterWidget->SetToFImageGrabber(this->m_ToFImageGrabber); + this->m_Controls->m_MESAParameterWidget->SetToFImageGrabber(this->m_ToFImageGrabber); + + switch (selectedCamera) + { + case 0: + case 1: + case 2: this->m_Controls->m_PMDParameterWidget->ActivateAllParameters(); + break; + case 3: this->m_Controls->m_MESAParameterWidget->ActivateAllParameters(); + break; + } + + +/* //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); +// m_Controls->m_CalibrationParameterGroupBox->setEnabled(true); OnSelectCamera(m_Controls->m_SelectCameraCombobox->currentIndex()); 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); +// m_Controls->m_CalibrationParameterGroupBox->setEnabled(true); OnSelectCamera(m_Controls->m_SelectCameraCombobox->currentIndex()); 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(); } } } - +*/ diff --git a/Modules/ToFUI/Qmitk/QmitkToFConnectionWidget.h b/Modules/ToFUI/Qmitk/QmitkToFConnectionWidget.h index af5e214fc3..441f89ddef 100644 --- a/Modules/ToFUI/Qmitk/QmitkToFConnectionWidget.h +++ b/Modules/ToFUI/Qmitk/QmitkToFConnectionWidget.h @@ -1,120 +1,127 @@ /*========================================================================= 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. =========================================================================*/ #ifndef _QMITKTOFCONNECTIONWIDGET_H_INCLUDED #define _QMITKTOFCONNECTIONWIDGET_H_INCLUDED #include "mitkTOFUIExports.h" #include "ui_QmitkToFConnectionWidgetControls.h" //QT headers #include //mitk headers #include "mitkToFImageGrabber.h" /** * @brief Widget allowing to connect to different ToF / range cameras (located in module ToFProcessing) * * The widget basically allows to connect/disconnect to different ToF cameras * * @ingroup ToFUI */ class mitkTOFUI_EXPORT QmitkToFConnectionWidget :public QWidget { //this is needed for all Qt objects that should have a MOC object (everything that derives from QObject) Q_OBJECT public: static const std::string VIEW_ID; QmitkToFConnectionWidget(QWidget* p = 0, Qt::WindowFlags f1 = 0); virtual ~QmitkToFConnectionWidget(); /* @brief This method is part of the widget an needs not to be called seperately. */ virtual void CreateQtPartControl(QWidget *parent); /* @brief This method is part of the widget an needs not to be called seperately. (Creation of the connections of main and control widget.)*/ virtual void CreateConnections(); /*! \brief returns the ToFImageGrabber which was provided by the ToFImageGrabberCreator after selecting a camera / player \return ToFImageGrabber currently used by the widget */ mitk::ToFImageGrabber* GetToFImageGrabber(); signals: /*! \brief This signal is sent if the user has connected the TOF camera. * The ToFImageGrabber is now availiable if the method GetToFImageGrabber() is called. */ void ToFCameraConnected(); /*! \brief This signal is sent if the user has disconnect the TOF camera. */ void ToFCameraDisconnected(); /*! \brief signal that is emitted when the ToF camera is started */ void ToFCameraStart(); /*! \brief signal that is emitted when the ToF camera is stopped */ void ToFCameraStop(); /*! \brief signal that is emitted when a ToF camera is selected in the combo box */ void ToFCameraSelected(int); protected slots: /*! \brief slot called when the "Connect Camera" button was pressed * According to the selection in the camera combo box, the ToFImageGrabberCreator provides * the desired instance of the ToFImageGrabber */ void OnConnectCamera(); /*! \brief slot updating the GUI elements after the selection of the camera combo box has changed */ void OnSelectCamera(int index); /*! \brief slot updating the member m_IntegrationTime and the parameter "integration time" of the current ToFImageGrabber */ - void OnChangeIntegrationTimeSpinBox(int value); + //void OnChangeIntegrationTimeSpinBox(int value); /*! \brief slot updating the member m_ModulationFrequency and the parameter "modulation frequency" of the current ToFImageGrabber */ - void OnChangeModulationFrequencySpinBox(int value); + //void OnChangeModulationFrequencySpinBox(int value); protected: Ui::QmitkToFConnectionWidgetControls* m_Controls; ///< member holding the UI elements of this widget mitk::ToFImageGrabber* m_ToFImageGrabber; ///< member holding the current ToFImageGrabber int m_IntegrationTime; ///< member for the current integration time of the ToF device int m_ModulationFrequency; ///< member for the current modulation frequency of the ToF device private: + void ShowParameterWidget(); + + void ShowPMDParameterWidget(); + + void ShowMESAParameterWidget(); + + void ShowPlayerParameterWidget(); }; #endif // _QMITKTOFCONNECTIONWIDGET_H_INCLUDED diff --git a/Modules/ToFUI/Qmitk/QmitkToFConnectionWidgetControls.ui b/Modules/ToFUI/Qmitk/QmitkToFConnectionWidgetControls.ui index d48e468a47..55404b00c5 100644 --- a/Modules/ToFUI/Qmitk/QmitkToFConnectionWidgetControls.ui +++ b/Modules/ToFUI/Qmitk/QmitkToFConnectionWidgetControls.ui @@ -1,290 +1,162 @@ QmitkToFConnectionWidgetControls 0 0 405 - 177 + 124 0 0 QmitkToFConnection - + 11 ToF camera connection - + 0 0 10 0 7 QComboBox::InsertAtBottom QComboBox::AdjustToContents true PMD Camcube 2.0/3.0 PMD CamBoard PMD O3D + + + MESA SR4000 + + PMD Player PMD Raw Data Player MITK Player - + 0 50 10 Connect to camera Connect :/images/powerRed.png :/images/powerGreen.png:/images/powerRed.png 30 30 true - - - - - 10 - - - - Integr. Time/μs - - - - - - - - 0 - 0 - - - - - 60 - 23 - - - - 0 - - - 50000 - - - 100 - - - 500 - - + + - - - - - 10 - - - - Mod.Freq./MHz - - - - - - - - 0 - 0 - - - - 18 - - - 40 - - - 1 - - - 20 - - - - - - - - 0 - 0 - - - - Calibration Parameter - - - - - - FPN - - - true - - - - - - - true - - - FPPN - - - true - - - - - - - true - - - Linearity - - - false - - - - - - - true - - - - 8 - - - - LensCorrection - - - - - - - true - - - ExposureMode - - - false - - - - - + + + + + QmitkToFPMDParameterWidget + QWidget +
QmitkToFPMDParameterWidget.h
+ 1 +
+ + QmitkToFMESAParameterWidget + QWidget +
QmitkToFMESAParameterWidget.h
+ 1 +
+
diff --git a/Modules/ToFUI/Qmitk/QmitkToFMESAParameterWidget.cpp b/Modules/ToFUI/Qmitk/QmitkToFMESAParameterWidget.cpp new file mode 100644 index 0000000000..6c3f9e2ac0 --- /dev/null +++ b/Modules/ToFUI/Qmitk/QmitkToFMESAParameterWidget.cpp @@ -0,0 +1,176 @@ +/*========================================================================= + +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 + +//itk headers +#include + +const std::string QmitkToFMESAParameterWidget::VIEW_ID = "org.mitk.views.qmitktofpmdparameterwidget"; + +QmitkToFMESAParameterWidget::QmitkToFMESAParameterWidget(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); +} + +QmitkToFMESAParameterWidget::~QmitkToFMESAParameterWidget() +{ +} + +void QmitkToFMESAParameterWidget::CreateQtPartControl(QWidget *parent) +{ + if (!m_Controls) + { + // create GUI widgets + m_Controls = new Ui::QmitkToFMESAParameterWidgetControls; + m_Controls->setupUi(parent); + this->CreateConnections(); + } +} + +void QmitkToFMESAParameterWidget::CreateConnections() +{ + if ( m_Controls ) + { + connect( m_Controls->m_IntegrationTimeSpinBox, SIGNAL(valueChanged(int)), this, SLOT(OnChangeIntegrationTimeSpinBox(int)) ); + connect( m_Controls->m_ModulationFrequencyComboBox, SIGNAL(valueChanged(int)), this, SLOT(OnChangeModulationFrequencyComboBox(int)) ); + connect( m_Controls->m_FPNCB, SIGNAL(toggled(bool)), this, SLOT(OnChangeFPNCheckBox(bool)) ); + connect( m_Controls->m_ConvGrayCB, SIGNAL(toggled(bool)), this, SLOT(OnChangeConvGrayCheckBox(bool)) ); + connect( m_Controls->m_MedianCB, SIGNAL(toggled(bool)), this, SLOT(OnChangeMedianCheckBox(bool)) ); + connect( m_Controls->m_ANFCB, SIGNAL(toggled(bool)), this, SLOT(OnChangeANFCheckBox(bool)) ); + } +} + +mitk::ToFImageGrabber* QmitkToFMESAParameterWidget::GetToFImageGrabber() +{ + return this->m_ToFImageGrabber; +} + +void QmitkToFMESAParameterWidget::SetToFImageGrabber(mitk::ToFImageGrabber* aToFImageGrabber) +{ + this->m_ToFImageGrabber = aToFImageGrabber; +} + +void QmitkToFMESAParameterWidget::ActivateAllParameters() +{ + this->m_IntegrationTime = m_Controls->m_IntegrationTimeSpinBox->value(); + this->m_IntegrationTime = this->m_ToFImageGrabber->SetIntegrationTime(this->m_IntegrationTime); + + switch(m_Controls->m_ModulationFrequencyComboBox->currentIndex()) + { + case 0: this->m_ModulationFrequency = 29; break; + case 1: this->m_ModulationFrequency = 30; break; + case 2: this->m_ModulationFrequency = 31; break; + default: this->m_ModulationFrequency = 30; break; + } + this->m_ModulationFrequency = this->m_ToFImageGrabber->SetModulationFrequency(this->m_ModulationFrequency); + + //set the MESA acquire mode according to the check boxes + bool boolValue = false; + boolValue = m_Controls->m_FPNCB->isChecked(); + this->m_ToFImageGrabber->SetBoolProperty("SetFPN", boolValue); + boolValue = m_Controls->m_ConvGrayCB->isChecked(); + this->m_ToFImageGrabber->SetBoolProperty("SetConvGray", boolValue); + boolValue = m_Controls->m_MedianCB->isChecked(); + this->m_ToFImageGrabber->SetBoolProperty("SetMedian", boolValue); + boolValue = m_Controls->m_ANFCB->isChecked(); + this->m_ToFImageGrabber->SetBoolProperty("SetANF", boolValue); + + //reset the GUI elements + m_Controls->m_IntegrationTimeSpinBox->setValue(this->m_IntegrationTime); + //m_Controls->m_ModulationFrequencyComboBox->setValue(this->m_ModulationFrequency); +} + +void QmitkToFMESAParameterWidget::OnChangeFPNCheckBox(bool checked) +{ + this->m_ToFImageGrabber->SetBoolProperty("SetFPN", checked); +} + +void QmitkToFMESAParameterWidget::OnChangeConvGrayCheckBox(bool checked) +{ + this->m_ToFImageGrabber->SetBoolProperty("SetConvGray", checked); +} + +void QmitkToFMESAParameterWidget::OnChangeMedianCheckBox(bool checked) +{ + this->m_ToFImageGrabber->SetBoolProperty("SetMedian", checked); +} + +void QmitkToFMESAParameterWidget::OnChangeANFCheckBox(bool checked) +{ + this->m_ToFImageGrabber->SetBoolProperty("SetANF", checked); +} + +void QmitkToFMESAParameterWidget::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 QmitkToFMESAParameterWidget::OnChangeModulationFrequencyComboBox(int index) +{ + if (this->m_ToFImageGrabber != NULL) + { + // stop camera if active + bool active = m_ToFImageGrabber->IsCameraActive(); + if (active) + { + m_ToFImageGrabber->StopCamera(); + } + switch(index) + { + case 0: this->m_ModulationFrequency = 29; break; + case 1: this->m_ModulationFrequency = 30; break; + case 2: this->m_ModulationFrequency = 31; break; + default: this->m_ModulationFrequency = 30; break; + } + this->m_ModulationFrequency = this->m_ToFImageGrabber->SetModulationFrequency(this->m_ModulationFrequency); + if (active) + { + m_ToFImageGrabber->StartCamera(); + } + } +} + diff --git a/Modules/ToFUI/Qmitk/QmitkToFConnectionWidget.h b/Modules/ToFUI/Qmitk/QmitkToFMESAParameterWidget.h similarity index 76% copy from Modules/ToFUI/Qmitk/QmitkToFConnectionWidget.h copy to Modules/ToFUI/Qmitk/QmitkToFMESAParameterWidget.h index af5e214fc3..0e392ce3b8 100644 --- a/Modules/ToFUI/Qmitk/QmitkToFConnectionWidget.h +++ b/Modules/ToFUI/Qmitk/QmitkToFMESAParameterWidget.h @@ -1,120 +1,128 @@ /*========================================================================= 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. =========================================================================*/ -#ifndef _QMITKTOFCONNECTIONWIDGET_H_INCLUDED -#define _QMITKTOFCONNECTIONWIDGET_H_INCLUDED +#ifndef _QMITKTOFMESAPARAMETERWIDGET_H_INCLUDED +#define _QMITKTOFMESAPARAMETERWIDGET_H_INCLUDED #include "mitkTOFUIExports.h" -#include "ui_QmitkToFConnectionWidgetControls.h" +#include "ui_QmitkToFMESAParameterWidgetControls.h" //QT headers #include //mitk headers #include "mitkToFImageGrabber.h" /** * @brief Widget allowing to connect to different ToF / range cameras (located in module ToFProcessing) * * The widget basically allows to connect/disconnect to different ToF cameras * * @ingroup ToFUI */ -class mitkTOFUI_EXPORT QmitkToFConnectionWidget :public QWidget +class mitkTOFUI_EXPORT QmitkToFMESAParameterWidget :public QWidget { //this is needed for all Qt objects that should have a MOC object (everything that derives from QObject) Q_OBJECT public: static const std::string VIEW_ID; - QmitkToFConnectionWidget(QWidget* p = 0, Qt::WindowFlags f1 = 0); - virtual ~QmitkToFConnectionWidget(); + QmitkToFMESAParameterWidget(QWidget* p = 0, Qt::WindowFlags f1 = 0); + virtual ~QmitkToFMESAParameterWidget(); /* @brief This method is part of the widget an needs not to be called seperately. */ virtual void CreateQtPartControl(QWidget *parent); /* @brief This method is part of the widget an needs not to be called seperately. (Creation of the connections of main and control widget.)*/ virtual void CreateConnections(); /*! \brief returns the ToFImageGrabber which was provided by the ToFImageGrabberCreator after selecting a camera / player \return ToFImageGrabber currently used by the widget */ mitk::ToFImageGrabber* GetToFImageGrabber(); + + /*! + \brief sets the ToFImageGrabber which was provided by the ToFImageGrabberCreator after selecting a camera / player + */ + void SetToFImageGrabber(mitk::ToFImageGrabber* aToFImageGrabber); + /*! + \brief activate camera settings according to the parameters from GUI + */ + void ActivateAllParameters(); + signals: /*! \brief This signal is sent if the user has connected the TOF camera. * The ToFImageGrabber is now availiable if the method GetToFImageGrabber() is called. */ void ToFCameraConnected(); /*! \brief This signal is sent if the user has disconnect the TOF camera. */ void ToFCameraDisconnected(); /*! \brief signal that is emitted when the ToF camera is started */ void ToFCameraStart(); /*! \brief signal that is emitted when the ToF camera is stopped */ void ToFCameraStop(); /*! \brief signal that is emitted when a ToF camera is selected in the combo box */ void ToFCameraSelected(int); protected slots: - /*! - \brief slot called when the "Connect Camera" button was pressed - * According to the selection in the camera combo box, the ToFImageGrabberCreator provides - * the desired instance of the ToFImageGrabber - */ - void OnConnectCamera(); - /*! - \brief slot updating the GUI elements after the selection of the camera combo box has changed - */ - void OnSelectCamera(int index); /*! \brief slot updating the member m_IntegrationTime and the parameter "integration time" of the current ToFImageGrabber */ void OnChangeIntegrationTimeSpinBox(int value); /*! \brief slot updating the member m_ModulationFrequency and the parameter "modulation frequency" of the current ToFImageGrabber */ - void OnChangeModulationFrequencySpinBox(int value); + void OnChangeModulationFrequencyComboBox(int index); + + void OnChangeFPNCheckBox(bool checked); + + void OnChangeConvGrayCheckBox(bool checked); + + void OnChangeMedianCheckBox(bool checked); + + void OnChangeANFCheckBox(bool checked); protected: - Ui::QmitkToFConnectionWidgetControls* m_Controls; ///< member holding the UI elements of this widget + Ui::QmitkToFMESAParameterWidgetControls* m_Controls; ///< member holding the UI elements of this widget mitk::ToFImageGrabber* m_ToFImageGrabber; ///< member holding the current ToFImageGrabber int m_IntegrationTime; ///< member for the current integration time of the ToF device int m_ModulationFrequency; ///< member for the current modulation frequency of the ToF device private: }; #endif // _QMITKTOFCONNECTIONWIDGET_H_INCLUDED diff --git a/Modules/ToFUI/Qmitk/QmitkToFMESAParameterWidgetControls.ui b/Modules/ToFUI/Qmitk/QmitkToFMESAParameterWidgetControls.ui new file mode 100644 index 0000000000..dce4f3b12b --- /dev/null +++ b/Modules/ToFUI/Qmitk/QmitkToFMESAParameterWidgetControls.ui @@ -0,0 +1,185 @@ + + + QmitkToFMESAParameterWidgetControls + + + + 0 + 0 + 425 + 130 + + + + + 0 + 0 + + + + QmitkToFMESAParameter + + + + + + + 0 + 0 + + + + MESA Camera Parameter + + + + + + + 10 + + + + Integr. Time/μs + + + + + + + + 0 + 0 + + + + + 60 + 23 + + + + 300 + + + 25800 + + + 100 + + + 300 + + + + + + + + 10 + + + + Mod.Freq./MHz + + + + + + + 1 + + + + 29 + + + + + 30 + + + + + 31 + + + + + + + + + 0 + 0 + + + + Acquire mode + + + + + + FPN + + + true + + + + + + + true + + + Conv gray + + + false + + + + + + + true + + + Median + + + false + + + + + + + true + + + + 8 + + + + ANF + + + + + + + + + + + + + + + + + diff --git a/Modules/ToFUI/Qmitk/QmitkToFPMDParameterWidget.cpp b/Modules/ToFUI/Qmitk/QmitkToFPMDParameterWidget.cpp new file mode 100644 index 0000000000..223faacf41 --- /dev/null +++ b/Modules/ToFUI/Qmitk/QmitkToFPMDParameterWidget.cpp @@ -0,0 +1,142 @@ +/*========================================================================= + +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 + +//itk headers +#include + +const std::string QmitkToFPMDParameterWidget::VIEW_ID = "org.mitk.views.qmitktofpmdparameterwidget"; + +QmitkToFPMDParameterWidget::QmitkToFPMDParameterWidget(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); +} + +QmitkToFPMDParameterWidget::~QmitkToFPMDParameterWidget() +{ +} + +void QmitkToFPMDParameterWidget::CreateQtPartControl(QWidget *parent) +{ + if (!m_Controls) + { + // create GUI widgets + m_Controls = new Ui::QmitkToFPMDParameterWidgetControls; + m_Controls->setupUi(parent); + this->CreateConnections(); + } +} + +void QmitkToFPMDParameterWidget::CreateConnections() +{ + if ( m_Controls ) + { + connect( m_Controls->m_IntegrationTimeSpinBox, SIGNAL(valueChanged(int)), this, SLOT(OnChangeIntegrationTimeSpinBox(int)) ); + connect( m_Controls->m_ModulationFrequencySpinBox, SIGNAL(valueChanged(int)), this, SLOT(OnChangeModulationFrequencySpinBox(int)) ); + } +} + +mitk::ToFImageGrabber* QmitkToFPMDParameterWidget::GetToFImageGrabber() +{ + return this->m_ToFImageGrabber; +} + +void QmitkToFPMDParameterWidget::SetToFImageGrabber(mitk::ToFImageGrabber* aToFImageGrabber) +{ + this->m_ToFImageGrabber = aToFImageGrabber; +} + +void QmitkToFPMDParameterWidget::ActivateAllParameters() +{ + this->m_IntegrationTime = m_Controls->m_IntegrationTimeSpinBox->value(); + this->m_IntegrationTime = this->m_ToFImageGrabber->SetIntegrationTime(this->m_IntegrationTime); + + this->m_ModulationFrequency = m_Controls->m_ModulationFrequencySpinBox->value(); + 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); +} + +void QmitkToFPMDParameterWidget::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 QmitkToFPMDParameterWidget::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(); + } + } +} + diff --git a/Modules/ToFUI/Qmitk/QmitkToFConnectionWidget.h b/Modules/ToFUI/Qmitk/QmitkToFPMDParameterWidget.h similarity index 80% copy from Modules/ToFUI/Qmitk/QmitkToFConnectionWidget.h copy to Modules/ToFUI/Qmitk/QmitkToFPMDParameterWidget.h index af5e214fc3..9b24d80916 100644 --- a/Modules/ToFUI/Qmitk/QmitkToFConnectionWidget.h +++ b/Modules/ToFUI/Qmitk/QmitkToFPMDParameterWidget.h @@ -1,120 +1,120 @@ /*========================================================================= 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. =========================================================================*/ -#ifndef _QMITKTOFCONNECTIONWIDGET_H_INCLUDED -#define _QMITKTOFCONNECTIONWIDGET_H_INCLUDED +#ifndef _QMITKTOFPMDPARAMETERWIDGET_H_INCLUDED +#define _QMITKTOFPMDPARAMETERWIDGET_H_INCLUDED #include "mitkTOFUIExports.h" -#include "ui_QmitkToFConnectionWidgetControls.h" +#include "ui_QmitkToFPMDParameterWidgetControls.h" //QT headers #include //mitk headers #include "mitkToFImageGrabber.h" /** * @brief Widget allowing to connect to different ToF / range cameras (located in module ToFProcessing) * * The widget basically allows to connect/disconnect to different ToF cameras * * @ingroup ToFUI */ -class mitkTOFUI_EXPORT QmitkToFConnectionWidget :public QWidget +class mitkTOFUI_EXPORT QmitkToFPMDParameterWidget :public QWidget { //this is needed for all Qt objects that should have a MOC object (everything that derives from QObject) Q_OBJECT public: static const std::string VIEW_ID; - QmitkToFConnectionWidget(QWidget* p = 0, Qt::WindowFlags f1 = 0); - virtual ~QmitkToFConnectionWidget(); + QmitkToFPMDParameterWidget(QWidget* p = 0, Qt::WindowFlags f1 = 0); + virtual ~QmitkToFPMDParameterWidget(); /* @brief This method is part of the widget an needs not to be called seperately. */ virtual void CreateQtPartControl(QWidget *parent); /* @brief This method is part of the widget an needs not to be called seperately. (Creation of the connections of main and control widget.)*/ virtual void CreateConnections(); /*! \brief returns the ToFImageGrabber which was provided by the ToFImageGrabberCreator after selecting a camera / player \return ToFImageGrabber currently used by the widget */ mitk::ToFImageGrabber* GetToFImageGrabber(); + + /*! + \brief sets the ToFImageGrabber which was provided by the ToFImageGrabberCreator after selecting a camera / player + */ + void SetToFImageGrabber(mitk::ToFImageGrabber* aToFImageGrabber); + + /*! + \brief activate camera settings according to the parameters from GUI + */ + void ActivateAllParameters(); signals: /*! \brief This signal is sent if the user has connected the TOF camera. * The ToFImageGrabber is now availiable if the method GetToFImageGrabber() is called. */ void ToFCameraConnected(); /*! \brief This signal is sent if the user has disconnect the TOF camera. */ void ToFCameraDisconnected(); /*! \brief signal that is emitted when the ToF camera is started */ void ToFCameraStart(); /*! \brief signal that is emitted when the ToF camera is stopped */ void ToFCameraStop(); /*! \brief signal that is emitted when a ToF camera is selected in the combo box */ void ToFCameraSelected(int); protected slots: - /*! - \brief slot called when the "Connect Camera" button was pressed - * According to the selection in the camera combo box, the ToFImageGrabberCreator provides - * the desired instance of the ToFImageGrabber - */ - void OnConnectCamera(); - /*! - \brief slot updating the GUI elements after the selection of the camera combo box has changed - */ - void OnSelectCamera(int index); /*! \brief slot updating the member m_IntegrationTime and the parameter "integration time" of the current ToFImageGrabber */ void OnChangeIntegrationTimeSpinBox(int value); /*! \brief slot updating the member m_ModulationFrequency and the parameter "modulation frequency" of the current ToFImageGrabber */ void OnChangeModulationFrequencySpinBox(int value); protected: - Ui::QmitkToFConnectionWidgetControls* m_Controls; ///< member holding the UI elements of this widget + Ui::QmitkToFPMDParameterWidgetControls* m_Controls; ///< member holding the UI elements of this widget mitk::ToFImageGrabber* m_ToFImageGrabber; ///< member holding the current ToFImageGrabber int m_IntegrationTime; ///< member for the current integration time of the ToF device int m_ModulationFrequency; ///< member for the current modulation frequency of the ToF device private: }; #endif // _QMITKTOFCONNECTIONWIDGET_H_INCLUDED diff --git a/Modules/ToFUI/Qmitk/QmitkToFPMDParameterWidgetControls.ui b/Modules/ToFUI/Qmitk/QmitkToFPMDParameterWidgetControls.ui new file mode 100644 index 0000000000..6344a5f536 --- /dev/null +++ b/Modules/ToFUI/Qmitk/QmitkToFPMDParameterWidgetControls.ui @@ -0,0 +1,198 @@ + + + QmitkToFPMDParameterWidgetControls + + + + 0 + 0 + 425 + 130 + + + + + 0 + 0 + + + + QmitkToFPMDParameter + + + + + + + 0 + 0 + + + + PMD Camera Parameter + + + + + + + 10 + + + + Integr. Time/μs + + + + + + + + 0 + 0 + + + + + 60 + 23 + + + + 0 + + + 50000 + + + 100 + + + 500 + + + + + + + + 10 + + + + Mod.Freq./MHz + + + + + + + + 0 + 0 + + + + 18 + + + 40 + + + 1 + + + 20 + + + + + + + + 0 + 0 + + + + Calibration Parameter + + + + + + FPN + + + true + + + + + + + true + + + FPPN + + + true + + + + + + + true + + + Linearity + + + false + + + + + + + true + + + + 8 + + + + LensCorrection + + + + + + + true + + + ExposureMode + + + false + + + + + + + + + + + + + + + + + diff --git a/Modules/ToFUI/files.cmake b/Modules/ToFUI/files.cmake index 27b32dd894..61c0117ed9 100644 --- a/Modules/ToFUI/files.cmake +++ b/Modules/ToFUI/files.cmake @@ -1,25 +1,31 @@ SET(CPP_FILES Qmitk/QmitkToFConnectionWidget.cpp Qmitk/QmitkToFRecorderWidget.cpp Qmitk/QmitkToFVisualisationSettingsWidget.cpp Qmitk/QmitkToFCompositeFilterWidget.cpp + Qmitk/QmitkToFPMDParameterWidget.cpp + Qmitk/QmitkToFMESAParameterWidget.cpp ) SET(UI_FILES Qmitk/QmitkToFConnectionWidgetControls.ui Qmitk/QmitkToFRecorderWidgetControls.ui Qmitk/QmitkToFVisualisationSettingsWidgetControls.ui Qmitk/QmitkToFCompositeFilterWidgetControls.ui + Qmitk/QmitkToFPMDParameterWidgetControls.ui + Qmitk/QmitkToFMESAParameterWidgetControls.ui ) SET(MOC_H_FILES Qmitk/QmitkToFConnectionWidget.h Qmitk/QmitkToFRecorderWidget.h Qmitk/QmitkToFVisualisationSettingsWidget.h Qmitk/QmitkToFCompositeFilterWidget.h + Qmitk/QmitkToFPMDParameterWidget.h + Qmitk/QmitkToFMESAParameterWidget.h ) # uncomment the following line if you want to use Qt resources SET(QRC_FILES resources/QmitkToFUtilWidget.qrc ) \ No newline at end of file