diff --git a/Modules/Bundles/org.mitk.gui.qt.diffusionimaging/src/internal/QmitkFiberBundleDeveloperView.cpp b/Modules/Bundles/org.mitk.gui.qt.diffusionimaging/src/internal/QmitkFiberBundleDeveloperView.cpp index 393283aeca..481983a691 100644 --- a/Modules/Bundles/org.mitk.gui.qt.diffusionimaging/src/internal/QmitkFiberBundleDeveloperView.cpp +++ b/Modules/Bundles/org.mitk.gui.qt.diffusionimaging/src/internal/QmitkFiberBundleDeveloperView.cpp @@ -1,704 +1,703 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit Language: C++ Date: $Date: 2010-03-31 16:40:27 +0200 (Mi, 31 Mrz 2010) $ Version: $Revision: 21975 $ Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notices for more information. =========================================================================*/ // Blueberry application and interaction service #include #include // Qmitk #include "QmitkFiberBundleDeveloperView.h" #include // Qt #include // MITK //#include //for fiberStructure //===needed when timeSlicedGeometry is null to invoke rendering mechansims ==== #include #include // VTK #include //for randomized FiberStructure #include //for fiberStructure #include //for fiberStructure #include //for geometry //ITK #include /*=================================================================================== * THIS METHOD IMPLEMENTS THE ACTIONS WHICH SHALL BE EXECUTED by the according THREAD */ QmitkFiberIDWorker::QmitkFiberIDWorker(QThread* hostingThread, Package4WorkingThread itemPackage) : m_itemPackage(itemPackage), m_hostingThread(hostingThread) { } void QmitkFiberIDWorker::run() { - MITK_INFO << "WmitkFiberIDWORKER....RUN()"; - + + //accurate time measurement using ITK timeProbe itk::TimeProbe clock; clock.Start(); m_itemPackage.st_FBX->DoGenerateFiberIds(); - m_itemPackage.st_idGenerateTimer->stop(); //stop fancy timer + m_itemPackage.st_idGenerateTimer->stop(); //stop fancy Qt-timer in GUI - clock.Stop(); - m_itemPackage.st_Controls-> + m_itemPackage.st_Controls->infoTimerGenerateFiberIds->setText( QString::number(clock.GetTotal()) ); MITK_INFO << "==== Generate idSet ====\n Mean: " << clock.GetMean() << "\n Total: " << clock.GetTotal() ; // m_hostingThread->quit(); } // ========= HERE STARTS THE ACTUAL FIBERBUNDLE DEVELOPER VIEW IMPLEMENTATION ====== const std::string QmitkFiberBundleDeveloperView::VIEW_ID = "org.mitk.views.fiberbundledeveloper"; const std::string id_DataManager = "org.mitk.views.datamanager"; using namespace berry; QmitkFiberBundleDeveloperView::QmitkFiberBundleDeveloperView() : QmitkFunctionality() , m_Controls( 0 ) , m_MultiWidget( NULL ) { m_hostThread = new QThread; m_threadInProgress = false; } // Destructor QmitkFiberBundleDeveloperView::~QmitkFiberBundleDeveloperView() { m_FiberBundleX->Delete(); delete m_hostThread; delete m_FiberIDGenerator; // m_idGenerateTimer no need to delete, is not initialized using "new" } void QmitkFiberBundleDeveloperView::CreateQtPartControl( QWidget *parent ) { // build up qt view, unless already done in QtDesigner, etc. if ( !m_Controls ) { // create GUI widgets from the Qt Designer's .ui file m_Controls = new Ui::QmitkFiberBundleDeveloperViewControls; m_Controls->setupUi( parent ); /*=========INITIALIZE BUTTON CONFIGURATION ================*/ m_Controls->radioButton_directionX->setEnabled(false); m_Controls->radioButton_directionY->setEnabled(false); m_Controls->radioButton_directionZ->setEnabled(false); m_Controls->buttonGenerateFiberIds->setEnabled(false); m_Controls->buttonGenerateFibers->setEnabled(true); connect( m_Controls->buttonGenerateFibers, SIGNAL(clicked()), this, SLOT(DoGenerateFibers()) ); connect( m_Controls->buttonGenerateFiberIds, SIGNAL(pressed()), this, SLOT(DoGenerateFiberIDs()) ); connect( m_Controls->radioButton_directionRandom, SIGNAL(clicked()), this, SLOT(DoUpdateGenerateFibersWidget()) ); connect( m_Controls->radioButton_directionX, SIGNAL(clicked()), this, SLOT(DoUpdateGenerateFibersWidget()) ); connect( m_Controls->radioButton_directionY, SIGNAL(clicked()), this, SLOT(DoUpdateGenerateFibersWidget()) ); connect( m_Controls->radioButton_directionZ, SIGNAL(clicked()), this, SLOT(DoUpdateGenerateFibersWidget()) ); connect( m_Controls->toolBox, SIGNAL(currentChanged ( int ) ), this, SLOT(SelectionChangedToolBox(int)) ); } // Checkpoint for fiber ORIENTATION if ( m_DirectionRadios.empty() ) { m_DirectionRadios.insert(0, m_Controls->radioButton_directionRandom); m_DirectionRadios.insert(1, m_Controls->radioButton_directionX); m_DirectionRadios.insert(2, m_Controls->radioButton_directionY); m_DirectionRadios.insert(3, m_Controls->radioButton_directionZ); } // set GUI elements of FiberGenerator to according configuration DoUpdateGenerateFibersWidget(); } /* THIS METHOD UPDATES ALL GUI ELEMENTS OF QGroupBox DEPENDING ON CURRENTLY SELECTED * RADIO BUTTONS */ void QmitkFiberBundleDeveloperView::DoUpdateGenerateFibersWidget() { //get selected radioButton QString fibDirection; //stores the object_name of selected radiobutton QVector::const_iterator i; for (i = m_DirectionRadios.begin(); i != m_DirectionRadios.end(); ++i) { QRadioButton* rdbtn = *i; if (rdbtn->isChecked()) fibDirection = rdbtn->objectName(); } if ( fibDirection == FIB_RADIOBUTTON_DIRECTION_RANDOM ) { // disable radiobuttons if (m_Controls->boxFiberMinLength->isEnabled()) m_Controls->boxFiberMinLength->setEnabled(false); if (m_Controls->labelFiberMinLength->isEnabled()) m_Controls->labelFiberMinLength->setEnabled(false); if (m_Controls->boxFiberMaxLength->isEnabled()) m_Controls->boxFiberMaxLength->setEnabled(false); if (m_Controls->labelFiberMaxLength->isEnabled()) m_Controls->labelFiberMaxLength->setEnabled(false); //enable radiobuttons if (!m_Controls->labelFibersTotal->isEnabled()) m_Controls->labelFibersTotal->setEnabled(true); if (!m_Controls->boxFiberNumbers->isEnabled()) m_Controls->boxFiberNumbers->setEnabled(true); if (!m_Controls->labelDistrRadius->isEnabled()) m_Controls->labelDistrRadius->setEnabled(true); if (!m_Controls->boxDistributionRadius->isEnabled()) m_Controls->boxDistributionRadius->setEnabled(true); } else { // disable radiobuttons if (m_Controls->labelDistrRadius->isEnabled()) m_Controls->labelDistrRadius->setEnabled(false); if (m_Controls->boxDistributionRadius->isEnabled()) m_Controls->boxDistributionRadius->setEnabled(false); //enable radiobuttons if (!m_Controls->labelFibersTotal->isEnabled()) m_Controls->labelFibersTotal->setEnabled(true); if (!m_Controls->boxFiberNumbers->isEnabled()) m_Controls->boxFiberNumbers->setEnabled(true); if (!m_Controls->boxFiberMinLength->isEnabled()) m_Controls->boxFiberMinLength->setEnabled(true); if (!m_Controls->labelFiberMinLength->isEnabled()) m_Controls->labelFiberMinLength->setEnabled(true); if (!m_Controls->boxFiberMaxLength->isEnabled()) m_Controls->boxFiberMaxLength->setEnabled(true); if (!m_Controls->labelFiberMaxLength->isEnabled()) m_Controls->labelFiberMaxLength->setEnabled(true); } } void QmitkFiberBundleDeveloperView::DoGenerateFibers() { // GET SELECTED FIBER DIRECTION QString fibDirection; //stores the object_name of selected radiobutton QVector::const_iterator i; for (i = m_DirectionRadios.begin(); i != m_DirectionRadios.end(); ++i) { QRadioButton* rdbtn = *i; if (rdbtn->isChecked()) fibDirection = rdbtn->objectName(); } vtkPolyData* output; // FiberPD stores the generated PolyData if ( fibDirection == FIB_RADIOBUTTON_DIRECTION_RANDOM ) { // build polydata with random lines and fibers output = GenerateVtkFibersRandom(); } else if ( fibDirection == FIB_RADIOBUTTON_DIRECTION_X ) { // build polydata with XDirection fibers //output = GenerateVtkFibersDirectionX(); } else if ( fibDirection == FIB_RADIOBUTTON_DIRECTION_Y ) { // build polydata with YDirection fibers // output = GenerateVtkFibersDirectionY(); } else if ( fibDirection == FIB_RADIOBUTTON_DIRECTION_Z ) { // build polydata with ZDirection fibers // output = GenerateVtkFibersDirectionZ(); } mitk::FiberBundleX::Pointer FB = mitk::FiberBundleX::New(); FB->SetFibers(output); FB->SetGeometry(this->GenerateStandardGeometryForMITK()); mitk::DataNode::Pointer FBNode; FBNode = mitk::DataNode::New(); FBNode->SetName("FiberBundleX"); FBNode->SetData(FB); FBNode->SetVisibility(true); GetDataStorage()->Add(FBNode); //output->Delete(); const mitk::PlaneGeometry * tsgeo = m_MultiWidget->GetTimeNavigationController()->GetCurrentPlaneGeometry(); if (tsgeo == NULL) { /* GetDataStorage()->Modified etc. have no effect, therefore proceed as followed below */ // get all nodes that have not set "includeInBoundingBox" to false mitk::NodePredicateNot::Pointer pred = mitk::NodePredicateNot::New(mitk::NodePredicateProperty::New("includeInBoundingBox" , mitk::BoolProperty::New(false))); mitk::DataStorage::SetOfObjects::ConstPointer rs = GetDataStorage()->GetSubset(pred); // calculate bounding geometry of these nodes mitk::TimeSlicedGeometry::Pointer bounds = GetDataStorage()->ComputeBoundingGeometry3D(rs); // initialize the views to the bounding geometry mitk::RenderingManager::GetInstance()->InitializeViews(bounds); } else { GetDataStorage()->Modified(); //necessary?? m_MultiWidget->RequestUpdate(); //necessary?? } } /* * Generate polydata of random fibers */ vtkPolyData* QmitkFiberBundleDeveloperView::GenerateVtkFibersRandom() { int numOfFibers = m_Controls->boxFiberNumbers->value(); int distrRadius = m_Controls->boxDistributionRadius->value(); int numOfPoints = numOfFibers * distrRadius; std::vector< std::vector > fiberStorage; for (int i=0; i a; fiberStorage.push_back( a ); } //get number of items in fiberStorage MITK_INFO << "Fibers in fiberstorage: " << fiberStorage.size(); /* Generate Point Cloud */ vtkSmartPointer randomPoints = vtkSmartPointer::New(); randomPoints->SetCenter(0.0, 0.0, 0.0); randomPoints->SetNumberOfPoints(numOfPoints); randomPoints->SetRadius(distrRadius); randomPoints->Update(); vtkPoints* pnts = randomPoints->GetOutput()->GetPoints(); /*====== checkpoint: compare initialized and required points =============================*/ if (numOfPoints != pnts->GetNumberOfPoints()) { MITK_INFO << "VTK POINT ERROR, WRONG AMOUNT OF GENRERATED POINTS... COULD BE VTK BUG OR BITFLIP DUE TO COSMIC RADIATION!"; return NULL; }/* ================================= */ /* ASSIGN EACH POINT TO A RANDOM FIBER */ srand((unsigned)time(0)); // init randomizer for (int i=0; iGetNumberOfPoints(); ++i) { //generate random number between 0 and numOfFibers-1 int random_integer; random_integer = (rand()%numOfFibers); //add current point to random fiber fiberStorage.at(random_integer).push_back(i); // MITK_INFO << "point" << i << " |" << pnts->GetPoint(random_integer)[0] << "|" << pnts->GetPoint(random_integer)[1]<< "|" << pnts->GetPoint(random_integer)[2] << "| into fiber" << random_integer; } //=====timer measurement==== itk::TimeProbe clock; clock.Start(); //========================== /* GENERATE VTK POLYLINES OUT OF FIBERSTORAGE */ vtkSmartPointer linesCell = vtkSmartPointer::New(); // Host vtkPolyLines linesCell->Allocate(pnts->GetNumberOfPoints()*2); //allocate for each cellindex also space for the pointId, e.g. [idx | pntID] for (unsigned long i=0; i singleFiber = fiberStorage.at(i); vtkSmartPointer fiber = vtkSmartPointer::New(); fiber->GetPointIds()->SetNumberOfIds((int)singleFiber.size()); for (unsigned long si=0; siGetPointIds()->SetId( si, singleFiber.at(si) ); } linesCell->InsertNextCell(fiber); } /* =======checkpoint for cellarray allocation ==========*/ if ( (linesCell->GetSize()/pnts->GetNumberOfPoints()) != 2 ) { MITK_INFO << "RANDOM FIBER ALLOCATION CAN NOT BE TRUSTED ANYMORE! Correct leak or remove command: linesCell->Allocate(pnts->GetNumberOfPoints()*2) but be aware of possible loss in performance."; }/* ====================================================*/ // MITK_INFO << "CellSize: " << linesCell->GetSize() << " NumberOfCells: " << linesCell->GetNumberOfCells(); /* HOSTING POLYDATA FOR RANDOM FIBERSTRUCTURE */ vtkPolyData* PDRandom = vtkPolyData::New(); PDRandom->SetPoints(pnts); PDRandom->SetLines(linesCell); //====timer measurement======== clock.Stop(); MITK_INFO << "=====Assambling random Fibers to Polydata======\nMean: " << clock.GetMean() << std::endl; MITK_INFO << "Total: " << clock.GetTotal() << std::endl; //============================= return PDRandom; } vtkSmartPointer QmitkFiberBundleDeveloperView::GenerateVtkFibersDirectionX() { int numOfFibers = m_Controls->boxFiberNumbers->value(); vtkSmartPointer linesCell = vtkSmartPointer::New(); vtkSmartPointer points = vtkSmartPointer::New(); //insert Origin point, this point has index 0 in point array double originX = 0.0; double originY = 0.0; double originZ = 0.0; //after each iteration the origin of the new fiber increases //here you set which direction is affected. double increaseX = 0.0; double increaseY = 1.0; double increaseZ = 0.0; //walk along X axis //length of fibers increases in each iteration for (int i=0; i newFiber = vtkSmartPointer::New(); newFiber->GetPointIds()->SetNumberOfIds(i+2); //create starting point and add it to pointset points->InsertNextPoint(originX + (double)i * increaseX , originY + (double)i * increaseY, originZ + (double)i * increaseZ); //add starting point to fiber newFiber->GetPointIds()->SetId(0,points->GetNumberOfPoints()-1); //insert remaining points for fiber for (int pj=0; pj<=i ; ++pj) { //generate next point on X axis points->InsertNextPoint( originX + (double)pj+1 , originY + (double)i * increaseY, originZ + (double)i * increaseZ ); newFiber->GetPointIds()->SetId(pj+1,points->GetNumberOfPoints()-1); } linesCell->InsertNextCell(newFiber); } vtkSmartPointer PDX = vtkSmartPointer::New(); PDX->SetPoints(points); PDX->SetLines(linesCell); return PDX; } vtkSmartPointer QmitkFiberBundleDeveloperView::GenerateVtkFibersDirectionY() { vtkSmartPointer PDY = vtkSmartPointer::New(); //todo return PDY; } vtkSmartPointer QmitkFiberBundleDeveloperView::GenerateVtkFibersDirectionZ() { vtkSmartPointer PDZ = vtkSmartPointer::New(); //todo return PDZ; } /* === OutSourcedMethod: THIS METHOD GENERATES ESSENTIAL GEOMETRY PARAMETERS FOR THE MITK FRAMEWORK === * WITHOUT, the rendering mechanism will ignore objects without valid Geometry * for each object, MITK requires: ORIGIN, SPACING, TRANSFORM MATRIX, BOUNDING-BOX */ mitk::Geometry3D::Pointer QmitkFiberBundleDeveloperView::GenerateStandardGeometryForMITK() { mitk::Geometry3D::Pointer geometry = mitk::Geometry3D::New(); // generate origin mitk::Point3D origin; origin[0] = 0; origin[1] = 0; origin[2] = 0; geometry->SetOrigin(origin); // generate spacing float spacing[3] = {1,1,1}; geometry->SetSpacing(spacing); // generate identity transform-matrix vtkMatrix4x4* m = vtkMatrix4x4::New(); geometry->SetIndexToWorldTransformByVtkMatrix(m); // generate boundingbox // for an usable bounding-box use gui parameters to estimate the boundingbox float bounds[] = {500, 500, 500, -500, -500, -500}; // GET SELECTED FIBER DIRECTION QString fibDirection; //stores the object_name of selected radiobutton QVector::const_iterator i; for (i = m_DirectionRadios.begin(); i != m_DirectionRadios.end(); ++i) { QRadioButton* rdbtn = *i; if (rdbtn->isChecked()) fibDirection = rdbtn->objectName(); } if ( fibDirection == FIB_RADIOBUTTON_DIRECTION_RANDOM ) { // use information about distribution parameter to calculate bounding box int distrRadius = m_Controls->boxDistributionRadius->value(); bounds[0] = distrRadius; bounds[1] = distrRadius; bounds[2] = distrRadius; bounds[3] = -distrRadius; bounds[4] = -distrRadius; bounds[5] = -distrRadius; } else { // so far only X,Y,Z directions are available MITK_INFO << "_______GEOMETRY ISSUE_____\n***BoundingBox for X, Y, Z fiber directions are not optimized yet!***"; int maxFibLength = m_Controls->boxFiberMaxLength->value(); bounds[0] = maxFibLength; bounds[1] = maxFibLength; bounds[2] = maxFibLength; bounds[3] = -maxFibLength; bounds[4] = -maxFibLength; bounds[5] = -maxFibLength; } geometry->SetFloatBounds(bounds); geometry->SetImageGeometry(true); //?? return geometry; } void QmitkFiberBundleDeveloperView::UpdateFiberIDTimer() { //MAKE SURE by yourself THAT NOTHING ELSE THAN A NUMBER IS SET IN THAT LABEL QString crntValue = m_Controls->infoTimerGenerateFiberIds->text(); int tmpVal = crntValue.toInt(); m_Controls->infoTimerGenerateFiberIds->setText(QString::number(++tmpVal)); m_Controls->infoTimerGenerateFiberIds->update(); } /* Initialie ID dataset in FiberBundleX */ void QmitkFiberBundleDeveloperView::DoGenerateFiberIDs() { struct Package4WorkingThread FiberIdPackage; FiberIdPackage.st_FBX = m_FiberBundleX; FiberIdPackage.st_idGenerateTimer = &m_idGenerateTimer; FiberIdPackage.st_Controls = m_Controls; /* ===== TIMER CONFIGURATIONS for visual effect ====== * start and stop is called in Thread pre- and postprocessing methods */ m_idGenerateTimer.setInterval( 10 ); connect( &m_idGenerateTimer, SIGNAL(timeout()), this, SLOT(UpdateFiberIDTimer()) ); // THREAD CONFIGURATION m_FiberIDGenerator = new QmitkFiberIDWorker(m_hostThread, FiberIdPackage); m_FiberIDGenerator->moveToThread(m_hostThread); connect(m_hostThread, SIGNAL(started()), this, SLOT( BeforeThread_IdGenerate()) ); connect(m_hostThread, SIGNAL(started()), m_FiberIDGenerator, SLOT(run())); connect(m_hostThread, SIGNAL(finished()), this, SLOT(AfterThread_IdGenerate())); connect(m_hostThread, SIGNAL(terminated()), this, SLOT(AfterThread_IdGenerate())); m_hostThread->start(QThread::LowestPriority); // m_Controls->infoTimerGenerateFiberIds->setText(QString::number(clock.GetTotal())); } void QmitkFiberBundleDeveloperView::BeforeThread_IdGenerate() { m_Controls->infoTimerGenerateFiberIds->setText(QString::number(0)); //set GUI representation of timer to 0 m_threadInProgress = true; m_idGenerateTimer.start(); } void QmitkFiberBundleDeveloperView::AfterThread_IdGenerate() { // m_idGenerateTimer.stop(); //not smart to set timer.stop here, cuz this will override the actual measurements of ITK:PROBE in GUI m_threadInProgress = false; } void QmitkFiberBundleDeveloperView::ResetFiberInfoWidget() { if (m_Controls->infoAnalyseNumOfFibers->isEnabled()) { m_Controls->infoAnalyseNumOfFibers->setText("-"); m_Controls->infoAnalyseNumOfPoints->setText("-"); m_Controls->infoAnalyseNumOfFibers->setEnabled(false); } } void QmitkFiberBundleDeveloperView::FeedFiberInfoWidget() { if (!m_Controls->infoAnalyseNumOfFibers->isEnabled()) m_Controls->infoAnalyseNumOfFibers->setEnabled(true); QString numOfFibers; numOfFibers.setNum( m_FiberBundleX->GetFibers()->GetNumberOfLines() ); QString numOfPoints; numOfPoints.setNum( m_FiberBundleX->GetFibers()->GetNumberOfPoints() ); m_Controls->infoAnalyseNumOfFibers->setText( numOfFibers ); m_Controls->infoAnalyseNumOfPoints->setText( numOfPoints ); } void QmitkFiberBundleDeveloperView::SelectionChangedToolBox(int idx) { MITK_INFO << "printtoolbox: " << idx; if (m_Controls->page_FiberInfo->isVisible() && m_FiberBundleX != NULL) { FeedFiberInfoWidget(); } else { //if infolables are disabled: return //else set info back to - and set label and info to disabled if (!m_Controls->page_FiberInfo->isVisible()) { return; } else { ResetFiberInfoWidget(); } } } void QmitkFiberBundleDeveloperView::FBXDependendGUIElementsConfigurator(bool isVisible) { // ==== FIBER PROCESSING ELEMENTS ====== m_Controls->buttonGenerateFiberIds->setEnabled(isVisible); } void QmitkFiberBundleDeveloperView::StdMultiWidgetAvailable (QmitkStdMultiWidget &stdMultiWidget) { m_MultiWidget = &stdMultiWidget; } void QmitkFiberBundleDeveloperView::StdMultiWidgetNotAvailable() { m_MultiWidget = NULL; } /* OnSelectionChanged is registered to SelectionService, therefore no need to implement SelectionService Listener explicitly */ void QmitkFiberBundleDeveloperView::OnSelectionChanged( std::vector nodes ) { /* ==== reset everyhing related to FiberBundleX ====== * - variable m_FiberBundleX * - visualization of analysed fiberbundle */ m_FiberBundleX = NULL; //reset pointer, so that member does not point to depricated locations ResetFiberInfoWidget(); FBXDependendGUIElementsConfigurator(false); m_Controls->infoTimerGenerateFiberIds->setText("-"); //set GUI representation of timer to - //==================================================== if (nodes.empty()) return; for( std::vector::iterator it = nodes.begin(); it != nodes.end(); ++it ) { mitk::DataNode::Pointer node = *it; /* CHECKPOINT: FIBERBUNDLE*/ if( node.IsNotNull() && dynamic_cast(node->GetData()) ) { m_FiberBundleX = dynamic_cast(node->GetData()); if (m_FiberBundleX == NULL) MITK_INFO << "========ATTENTION=========\n unable to load selected FiberBundleX to FiberBundleDeveloper-plugin \n"; // ==== FIBERBUNDLE_INFO ELEMENTS ==== if ( m_Controls->page_FiberInfo->isVisible() ) FeedFiberInfoWidget(); // enable FiberBundleX related Gui Elements, such as buttons etc. FBXDependendGUIElementsConfigurator(true); } } } void QmitkFiberBundleDeveloperView::Activated() { MITK_INFO << "FB DevelopersV ACTIVATED()"; } diff --git a/Modules/ToFHardware/files.cmake b/Modules/ToFHardware/files.cmake index f7e9933d45..4f45703c33 100644 --- a/Modules/ToFHardware/files.cmake +++ b/Modules/ToFHardware/files.cmake @@ -1,90 +1,93 @@ SET(CPP_FILES mitkToFImageGrabberCreator.cpp mitkToFImageGrabber.cpp mitkToFOpenCVImageGrabber.cpp mitkToFCameraDevice.cpp mitkToFCameraMITKPlayerController.cpp mitkToFCameraMITKPlayerDevice.cpp mitkToFCameraPMDDevice.cpp + mitkToFCameraPMDRawDataDevice.cpp mitkToFCameraPMDPlayerDevice.cpp mitkToFCameraPMDMITKPlayerDevice.cpp mitkToFCameraPMDO3Device.cpp mitkToFCameraPMDCamCubeDevice.cpp + mitkToFCameraPMDRawDataCamCubeDevice.cpp mitkToFCameraPMDCamBoardDevice.cpp mitkToFCameraMESADevice.cpp mitkToFCameraMESASR4000Device.cpp mitkToFImageRecorder.cpp mitkToFImageRecorderFilter.cpp mitkToFImageWriter.cpp mitkToFImageCsvWriter.cpp + mitkThreadedToFRawDataReconstruction.cpp ) IF(MITK_USE_TOF_PMDCAMCUBE) SET(CPP_FILES ${CPP_FILES} mitkToFCameraPMDMITKPlayerController.cpp mitkToFCameraPMDCamCubeController.cpp mitkToFCameraPMDController.cpp ) IF(WIN32) IF(CMAKE_CL_64) SET(CPP_FILES ${CPP_FILES} mitkToFCameraPMDPlayerControllerStub.cpp) ELSE(CMAKE_CL_64) SET(CPP_FILES ${CPP_FILES} mitkToFCameraPMDPlayerController.cpp) ENDIF(CMAKE_CL_64) ELSE(WIN32) SET(CPP_FILES ${CPP_FILES} mitkToFCameraPMDPlayerControllerStub.cpp) ENDIF(WIN32) ELSE() SET(CPP_FILES ${CPP_FILES} mitkToFCameraPMDMITKPlayerControllerStub.cpp mitkToFCameraPMDCamCubeControllerStub.cpp mitkToFCameraPMDPlayerControllerStub.cpp ) ENDIF(MITK_USE_TOF_PMDCAMCUBE) IF(MITK_USE_TOF_PMDCAMBOARD) SET(CPP_FILES ${CPP_FILES} mitkToFCameraPMDCamBoardController.cpp mitkToFCameraPMDController.cpp ) ELSE() SET(CPP_FILES ${CPP_FILES} mitkToFCameraPMDCamBoardControllerStub.cpp ) ENDIF(MITK_USE_TOF_PMDCAMBOARD) IF(MITK_USE_TOF_PMDO3) SET(CPP_FILES ${CPP_FILES} mitkToFCameraPMDO3Controller.cpp mitkToFCameraPMDController.cpp ) ELSE() SET(CPP_FILES ${CPP_FILES} mitkToFCameraPMDO3ControllerStub.cpp ) ENDIF(MITK_USE_TOF_PMDO3) IF(NOT MITK_USE_TOF_PMDCAMCUBE) IF(NOT MITK_USE_TOF_PMDCAMBOARD) IF(NOT MITK_USE_TOF_PMDO3) SET(CPP_FILES ${CPP_FILES} mitkToFCameraPMDControllerStub.cpp ) ENDIF(NOT MITK_USE_TOF_PMDO3) ENDIF(NOT MITK_USE_TOF_PMDCAMBOARD) ENDIF(NOT MITK_USE_TOF_PMDCAMCUBE) IF(MITK_USE_TOF_MESASR4000) SET(CPP_FILES ${CPP_FILES} mitkToFCameraMESASR4000Controller.cpp mitkToFCameraMESAController.cpp ) ELSE() SET(CPP_FILES ${CPP_FILES} mitkToFCameraMESAControllerStub.cpp mitkToFCameraMESASR4000ControllerStub.cpp ) ENDIF(MITK_USE_TOF_MESASR4000) diff --git a/Modules/ToFHardware/mitkThreadedToFRawDataReconstruction.cpp b/Modules/ToFHardware/mitkThreadedToFRawDataReconstruction.cpp new file mode 100644 index 0000000000..0a8fa26a91 --- /dev/null +++ b/Modules/ToFHardware/mitkThreadedToFRawDataReconstruction.cpp @@ -0,0 +1,430 @@ +/*========================================================================= + +Program: Medical Imaging & Interaction Toolkit +Module: $RCSfile$ +Language: C++ +Date: $Date$ +Version: $Revision: 11415 $ + +Copyright (c) German Cancer Research Center, Division of Medical and +Biological Informatics. All rights reserved. +See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. + +This software is distributed WITHOUT ANY WARRANTY; without even +the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR +PURPOSE. See the above copyright notices for more information. + +=========================================================================*/ +// mitk includes +#include "mitkThreadedToFRawDataReconstruction.h" +#include "mitkITKImageImport.h" +#include "mitkImageDataItem.h" + +// stl includes +#include +#include +#include + +// vtk includes +#include +#include +#include + +// itk includes +#include +#include + +#ifdef WIN32 +#include +#else +#include +#endif +#include + +#define PI 3.14159265; +#define cAir 299704944; +#define fMod 20000000; + +namespace mitk +{ + + ThreadedToFRawDataReconstruction::ThreadedToFRawDataReconstruction(): m_Threader(0), + m_CISDist(0), m_CISAmpl(0), m_CISInten(0) /*, m_Dimensions(0)*/, + m_ThreadedCISDist(0), m_ThreadedCISAmpl(0), m_ThreadedCISInten(0), + m_Init(0), m_Width(0), m_Height(0), m_SourceDataSize(0), m_ImageSize(0), m_SourceData(0) + { + //this->SetNumberOfOutputs(1); + //this->SetNthOutput(0, this->MakeOutput(0)); + + m_ThreadData = new ThreadDataStruct; + m_ThreadData->m_ModulationFrequency = fMod; + + m_ThreadData->m_ImageDataMutex = itk::FastMutexLock::New(); + m_ThreadData->m_ThreadDataMutex = itk::FastMutexLock::New(); + + m_StackSize = 1; + } + + ThreadedToFRawDataReconstruction::~ThreadedToFRawDataReconstruction() + { + if(m_ThreadData != NULL) + delete m_ThreadData; + + if(m_CISDist != NULL) + delete[] m_CISDist; + + if(m_CISAmpl != NULL) + delete[] m_CISAmpl; + + if(m_CISInten != NULL) + delete[] m_CISInten; + + //if(m_Dimensions != NULL) + // delete[] m_Dimensions; + + if(m_ThreadedCISInten != NULL) + delete[] m_ThreadedCISInten; + + if(m_ThreadedCISAmpl != NULL) + delete[] m_ThreadedCISAmpl; + + if(m_ThreadedCISDist != NULL) + delete[] m_ThreadedCISDist; + + } + + //void ThreadedToFRawDataReconstruction::SetToFCameraController(ToFCameraController::Pointer cameraController) + //{ + // m_CameraController = cameraController; + // this->InitializeDataArrays(); + //} + // + //void ThreadedToFRawDataReconstruction::SetStackSize(int size) + //{ + // m_StackSize = size; + //} + // + //void ThreadedToFRawDataReconstruction::SetRawDataRequired(bool flag) + //{ + // m_RawDataRequired = flag; + //} + // + //void ThreadedToFRawDataReconstruction::SetFPPNCompensationRequired(bool flag) + //{ + // m_FPPNCompensationRequired = flag; + //} + + //void ThreadedToFRawDataReconstruction::SetCalibrationParameter() + //{ + // ToFCalibrationFileReader::Pointer reader = ToFCalibrationFileReader::New(); + // reader->GenerateOutputInformation(); + // m_IntrinsicParameter = reader->GetIntrinsicParameter(); + // m_DistortionParameter = reader->GetDistortionParameter(); + // m_InterpolationPoints = reader->GetInterpolationPoints(); + // m_FPPNCompensationArray = reader->GetFPPNCompensationArray(); + //} + +void ThreadedToFRawDataReconstruction::Initialize(int width, int height, int modulationFrequency, int sourceDataSize ) +{ + m_Width = width; + m_Height = height; + m_SourceDataSize = sourceDataSize; + m_ImageSize = width * height; + m_ThreadData->m_ModulationFrequency = modulationFrequency * 1e6; + + if(!m_Init) + { + m_SourceData = vtkShortArray::New(); + m_SourceData->SetNumberOfComponents(m_SourceDataSize); + m_SourceData->SetNumberOfTuples(4); + m_SourceData->Allocate(1); + + m_CISDist = new float[m_ImageSize]; + m_CISAmpl = new float[m_ImageSize]; + m_CISInten = new float[m_ImageSize]; + m_ThreadedCISDist = new float[m_ImageSize]; + m_ThreadedCISAmpl = new float[m_ImageSize]; + m_ThreadedCISInten = new float[m_ImageSize]; + + m_ThreadData->m_OutputData.push_back( m_ThreadedCISDist ); + m_ThreadData->m_OutputData.push_back( m_ThreadedCISAmpl ); + m_ThreadData->m_OutputData.push_back( m_ThreadedCISInten ); + + m_Init = true; + } +} + +void ThreadedToFRawDataReconstruction::SetChannelData(vtkShortArray* sourceData) +{ + m_SourceData->DeepCopy(sourceData); +} + +void ThreadedToFRawDataReconstruction::GetDistances(float* dist) +{ + memcpy(dist, m_CISDist, m_ImageSize*sizeof(float) ); +} + +void ThreadedToFRawDataReconstruction::GetAmplitudes(float* ampl) +{ + memcpy(ampl, m_CISAmpl, m_ImageSize*sizeof(float)); +} + +void ThreadedToFRawDataReconstruction::GetIntensities(float* inten) +{ + memcpy(inten, m_CISInten, m_ImageSize*sizeof(float)); +} + + //ImageSource::OutputImageType::Pointer ThreadedToFRawDataReconstruction::FetchIntensityFrame(int slice) + //{ + // Image::Pointer intensityImage = Image::New(); + // //int x = 0; + // intensityImage->Initialize(PixelType(typeid(float)),4,m_Dimensions); + // intensityImage->SetSlice(m_CISInten,0,0,0); + // return intensityImage; + //} + // + //ImageSource::OutputImageType::Pointer ThreadedToFRawDataReconstruction::FetchAmplitudeFrame(int slice) + //{ + // Image::Pointer amplitudeImage = Image::New(); + // //int x = 0; + // amplitudeImage->Initialize(PixelType(typeid(float)),4,m_Dimensions); + // amplitudeImage->SetSlice(m_CISAmpl,0,0,0); + // return amplitudeImage; + //} + // + //ImageSource::OutputImageType::Pointer ThreadedToFRawDataReconstruction::FetchDistanceFrame(int slice) + //{ + // Image::Pointer distanceImage = Image::New(); + // //int x = 0; + // distanceImage->Initialize(PixelType(typeid(float)), 4, m_Dimensions); + // distanceImage->SetSlice(m_CISDist, 0, 0, 0); + // return distanceImage; + //} + + void ThreadedToFRawDataReconstruction::GenerateData() + { + //if(!m_Init) + //{ + // this->SetNthOutput(0, this->MakeOutput(0)); + // this->SetNthOutput(1, this->MakeOutput(1)); + // this->SetNthOutput(2, this->MakeOutput(2)); + + // if(m_CameraController.IsNotNull()) + // { + // int captureWidth = m_CameraController->GetCaptureWidth(); + // int captureHeight = m_CameraController->GetCaptureHeight(); + // unsigned int* dimensions = new unsigned int[4]; + // dimensions[0] = captureWidth; + // dimensions[1] = captureHeight; + // dimensions[2] = m_StackSize; + // dimensions[3] = 1; + + // this->GetOutput(0)->Initialize(mitk::PixelType(typeid(float)) , 4 , dimensions); + // this->GetOutput(1)->Initialize(mitk::PixelType(typeid(float)) , 4 , dimensions); + // this->GetOutput(2)->Initialize(mitk::PixelType(typeid(float)) , 4 , dimensions); + // m_Init = true; + // delete[] dimensions; + // } + //} + + if(m_Init) + { + //mitk::Image* dist = static_cast(this->GetOutput(1)); + //mitk::Image* inten = static_cast(this->GetOutput(0)); + //mitk::Image* ampl = static_cast(this->GetOutput(2)); + + this->BeforeThreadedGenerateData(); + //dist->SetSlice(m_CISDist,0,0,0); + //inten->SetSlice(m_CISInten,0,0,0); + //ampl->SetSlice(m_CISAmpl,0,0,0); + } + } + + void ThreadedToFRawDataReconstruction::BeforeThreadedGenerateData() + { + int sourceDataSize = m_SourceDataSize; + int lineWidth = m_Width; + int frameHeight = m_Height; + int channelSize = lineWidth*frameHeight*2; + int quadChannelSize = channelSize/4; + //int headerSize = 256; + + std::vector quad = std::vector(quadChannelSize); + + //std::vector quad1; + //std::vector quad2; + //std::vector quad3; + //std::vector quad4; + + // clean the thread data array + m_ThreadData->m_InputData.erase(m_ThreadData->m_InputData.begin(),m_ThreadData->m_InputData.end()); + + int channelNo = 0; + while(channelNo < m_SourceData->GetNumberOfTuples()) + { + short* sourceData = new short[channelSize]; + m_SourceData->GetTupleValue(channelNo, sourceData); + quad.insert(quad.begin(), sourceData, sourceData+channelSize); + m_ThreadData->m_InputData.push_back(quad); + delete[]sourceData; + ++channelNo; + } + + //quad2.insert(quad2.begin(), sourceData+2*headerSize+channelSize, sourceData+2*headerSize+2*channelSize); + //m_ThreadData->m_InputData.push_back(quad2); + //quad3.insert(quad3.begin(), sourceData+3*headerSize+2*channelSize, sourceData+3*headerSize+3*channelSize); + //m_ThreadData->m_InputData.push_back(quad3); + //quad4.insert(quad4.begin(), sourceData+4*headerSize+3*channelSize, sourceData+4*headerSize+4*channelSize); + //m_ThreadData->m_InputData.push_back(quad4); + //delete[] sourceData; + + if(m_Threader.IsNull()) + { + m_Threader = this->GetMultiThreader(); + } + int maxThreadNr = 0; + + if(m_Threader->GetGlobalDefaultNumberOfThreads()> 5) + { + maxThreadNr = 5; + } + else + { + maxThreadNr = m_Threader->GetGlobalMaximumNumberOfThreads(); + } + + if ( m_ThreadData->m_Barrier.IsNull()) + { + m_ThreadData->m_Barrier = itk::Barrier::New(); + m_ThreadData->m_Barrier->Initialize(maxThreadNr); // + } + m_ThreadData->m_DataSize = quadChannelSize; + m_ThreadData->m_LineWidth = lineWidth; + m_ThreadData->m_FrameHeight = frameHeight/4; + std::vector threadIDVector; + int threadcounter = 0; + while(threadcounter != maxThreadNr-1) + { + if (m_Threader->GetNumberOfThreads() < m_Threader->GetGlobalMaximumNumberOfThreads()) + { + int threadID = m_Threader->SpawnThread(this->ThreadedGenerateDataCallbackFunction, m_ThreadData); + threadIDVector.push_back(threadID); + threadcounter++; + } + } + m_ThreadData->m_Barrier->Wait(); + + int count = 0; + while(count != threadIDVector.size()) + { + m_Threader->TerminateThread(threadIDVector.at(count)); + count++; + } + m_ThreadData->m_ImageDataMutex->Lock(); + memcpy(m_CISDist, m_ThreadData->m_OutputData.at(0), (channelSize/2)*sizeof(float)); + memcpy(m_CISAmpl, m_ThreadData->m_OutputData.at(1), (channelSize/2)*sizeof(float)); + memcpy(m_CISInten, m_ThreadData->m_OutputData.at(2), (channelSize/2)*sizeof(float)); + m_ThreadData->m_ImageDataMutex->Unlock(); + + } + + ITK_THREAD_RETURN_TYPE ThreadedToFRawDataReconstruction::ThreadedGenerateDataCallbackFunction(void* data) + { + /* extract this pointer from Thread Info structure */ + struct itk::MultiThreader::ThreadInfoStruct * pInfo = (struct itk::MultiThreader::ThreadInfoStruct*)data; + if (pInfo == NULL) + { + return ITK_THREAD_RETURN_VALUE; + } + if (pInfo->UserData == NULL) + { + return ITK_THREAD_RETURN_VALUE; + } + int quadrant = pInfo->ThreadID; + ThreadDataStruct* threadData = (ThreadDataStruct*) pInfo->UserData; + + // some needed variables + int x = 0; + int index = 0; + int index2 = 0; + double phi = 0; + double phi2 = 0; + double A1 = 0; + double A2 = 0; + double A3 = 0; + double A4 = 0; + double A5 = 0; + double A6 = 0; + double A7 = 0; + double A8 = 0; + double A3m1 = 0; + double A4m2 = 0; + double A7m5 = 0; + double A8m6 = 0; + double cair = cAir; + double pi = PI; + double modFreq = fMod; + double intermed1 = 0; + int linewidth = 0; + int frameheight = 0; + + threadData->m_ThreadDataMutex->Lock(); + std::vector quad1 = threadData->m_InputData.at(0); + std::vector quad2 = threadData->m_InputData.at(1); + std::vector quad3 = threadData->m_InputData.at(2); + std::vector quad4 = threadData->m_InputData.at(3); + index = (quadrant*2); + index2 = 3-quadrant; + modFreq = threadData->m_ModulationFrequency; + linewidth = threadData->m_LineWidth; + frameheight = threadData->m_FrameHeight; + threadData->m_ThreadDataMutex->Unlock(); + + do + { + index += 2*linewidth; + x++; + do + { + index -= 8; + A1 = htons(quad1.at(index)); + A2 = htons(quad2.at(index)); + A3 = htons(quad3.at(index)); + A4 = htons(quad4.at(index)); + A5 = htons(quad1.at(index+1)); + A6 = htons(quad2.at(index+1)); + A7 = htons(quad3.at(index+1)); + A8 = htons(quad4.at(index+1)); + + phi = atan2((A3 - A1),(A2 - A4)) + pi; + phi2 = atan2((A7 - A5),(A6 - A8)); + if(phi2<0) phi2 +=2*pi; + + intermed1 = cair/(4*pi*modFreq); + A3m1 = A3*A3 - 2*A3*A1 + A1*A1; + A4m2 = A4*A4 - 2*A4*A2 + A2*A2; + A7m5 = A7*A7 - 2*A7*A5 + A5*A5; + A8m6 = A8*A8 - 2*A8*A6 + A6*A6; + threadData->m_ImageDataMutex->Lock(); + threadData->m_OutputData.at(0)[index2] = (((phi*intermed1) + (phi2*intermed1))/2)*1000; + threadData->m_OutputData.at(1)[index2] = (sqrt(A3m1 + A4m2)/2) + (sqrt(A7m5 + A8m6)/2); + threadData->m_OutputData.at(2)[index2] = (A1+A2+A3+A4+A5+A6+A7+A8)/8; + threadData->m_ImageDataMutex->Unlock(); + + index2 += 4; + }while(index2 <= (x*linewidth) - (1+quadrant)); + + index += 2*linewidth; + + }while(index < 2*(linewidth*frameheight*4)); + + threadData->m_Barrier->Wait(); + + return ITK_THREAD_RETURN_VALUE; + } + + void ThreadedToFRawDataReconstruction::Update() + { + this->GenerateData(); + } +} // end mitk namespace diff --git a/Modules/ToFHardware/mitkThreadedToFRawDataReconstruction.h b/Modules/ToFHardware/mitkThreadedToFRawDataReconstruction.h new file mode 100644 index 0000000000..2e00339536 --- /dev/null +++ b/Modules/ToFHardware/mitkThreadedToFRawDataReconstruction.h @@ -0,0 +1,166 @@ +/*========================================================================= + +Program: Medical Imaging & Interaction Toolkit +Module: $RCSfile$ +Language: C++ +Date: $Date$ +Version: $Revision: 11415 $ + +Copyright (c) German Cancer Research Center, Division of Medical and +Biological Informatics. All rights reserved. +See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. + +This software is distributed WITHOUT ANY WARRANTY; without even +the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR +PURPOSE. See the above copyright notices for more information. + +=========================================================================*/ +#ifndef __mitkThreadedToFRawDataReconstruction_h +#define __mitkThreadedToFRawDataReconstruction_h + +// mitk includes +#include "mitkImageSource.h" +#include "mitkToFHardwareExports.h" +//#include "mitkToFCalibrationFileReader.h" + +// itk includes +//#include +//#include +//#include +#include +#include + +// vtk includes +#include "vtkShortArray.h" + +namespace mitk +{ + struct ThreadDataStruct + { + std::vector > m_InputData; + std::vector m_OutputData; + unsigned int m_DataSize; + unsigned int m_LineWidth; + unsigned int m_FrameHeight; + unsigned int m_ModulationFrequency; + itk::Barrier::Pointer m_Barrier; ///< barrier to synchronize endsof threads + itk::FastMutexLock::Pointer m_ImageDataMutex; ///< mutex for coordinated access to image data + itk::FastMutexLock::Pointer m_ThreadDataMutex; ///< mutex to control access to images + }; + + class MITK_TOFHARDWARE_EXPORT ThreadedToFRawDataReconstruction : public itk::ProcessObject + { + //typedef itk::Image ImageType; + //typedef itk::ImageRegionIterator IteratorType; + //typedef itk::FlipImageFilter FlipImageFilterType; + //typedef FlipImageFilterType::FlipAxesArrayType FlipAxesArrayType; + //typedef std::vector StdFloatVectorType; + //typedef std::vector StdPointVectorType; + + public: + + mitkClassMacro( ThreadedToFRawDataReconstruction , itk::ProcessObject ); + itkNewMacro( Self ); + + itkGetMacro(Init, bool); + + //void SetToFCameraController(mitk::ToFCameraController::Pointer cameraController); + + void SetChannelData(vtkShortArray* sourceData); + + void Initialize(int width, int height, int modulationFrequency, int sourceDataSize); + + void GetDistances(float* dist); + void GetAmplitudes(float* ampl); + void GetIntensities(float* inten); + + void Update(); + + //void SetStackSize(int size); + //void SetRawDataRequired(bool flag); + //void SetFPPNCompensationRequired(bool flag); + //void SetCalibrationParameter(); + //void DetermineDepthCalibrationImageSlice(); + + protected: + /*! + \brief standard constructor + */ + ThreadedToFRawDataReconstruction(); + /*! + \brief standard destructor + */ + ~ThreadedToFRawDataReconstruction(); + + /*! + \brief method generating the outputs of this filter. Called in the updated process of the pipeline. + This method generates the two outputs of the ToFImageSource: The distance and the intensity image + */ + virtual void GenerateData(); + /*! + \brief method configures the camera output and prepares the thread data struct for threaded data + generation + */ + virtual void BeforeThreadedGenerateData(); + /*! + \brief method fetching one frame containing the intensity values of the ToF camera + \return intensity image + */ + //mitk::ImageSource::OutputImageType::Pointer FetchIntensityFrame(int slice); + ///*! + //\brief method fetching one frame containing the amplitude values of the ToF camera + //\return intensity image + //*/ + //mitk::ImageSource::OutputImageType::Pointer FetchAmplitudeFrame(int slice); + ///*! + //\brief method fetching one frame containing the distance values of the ToF camera + //\return distance image + //*/ + //mitk::ImageSource::OutputImageType::Pointer FetchDistanceFrame(int slice); + ///*! + //\brief gets the raw data poitner and calculates Amplitude, Distance and Intensity from the data + //*/ + //void GenerateImageFromRawData(); + ///*! + //\brief initializes the member variables Amplitude, Distance and Intensity with camera controller dimensions + //*/ + //void InitializeDataArrays(); + + /*! + \brief threader callback function for multi threaded data generation + */ + static ITK_THREAD_RETURN_TYPE ThreadedGenerateDataCallbackFunction(void* data); + // member variables + int m_StackSize; ///< + int m_Width; + int m_Height; + int m_ImageSize; + int m_SourceDataSize; + vtkShortArray* m_SourceData; + bool m_Init; + + float* m_CISDist; ///< holds the distance information from for one distance image slice + float* m_CISAmpl; ///< holds the amplitude information from for one amplitude image slice + float* m_CISInten; ///< holds the intensity information from for one intensity image slice + float* m_ThreadedCISDist; + float* m_ThreadedCISAmpl; + float* m_ThreadedCISInten; + + itk::MultiThreader::Pointer m_Threader; + ThreadDataStruct* m_ThreadData; + + //float* m_DepthCalibrationParameter; + //unsigned int* m_Dimensions; + //mitk::ToFCalibrationFileReader::Pointer m_CalibrationFileReader; + //mitk::Matrix3D m_IntrinsicParameter; + //mitk::Matrix3D m_DistortionParameter; + //StdPointVectorType m_InterpolationPoints; + //StdFloatVectorType m_FPPNCompensationArray; + //mitk::ToFCameraController::Pointer m_CameraController; ///< member holding the controller for communicating with the ToF camera. Can be set via SetToFCameraController + //bool m_RawDataRequired; + //bool m_FPPNCompensationRequired; + + }; +} //end mitk namespace + +#endif // __mitkThreadedToFRawDataReconstruction_h diff --git a/Modules/ToFHardware/mitkToFCameraPMDController.cpp b/Modules/ToFHardware/mitkToFCameraPMDController.cpp index b010beff72..85d159e361 100644 --- a/Modules/ToFHardware/mitkToFCameraPMDController.cpp +++ b/Modules/ToFHardware/mitkToFCameraPMDController.cpp @@ -1,164 +1,171 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit Module: $RCSfile$ Language: C++ Date: $Date: 2010-05-27 16:06:53 +0200 (Do, 27 Mai 2010) $ Version: $Revision: $ Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notices for more information. =========================================================================*/ #include "mitkToFCameraPMDController.h" #include #include PMDHandle m_PMDHandle; //TODO PMDDataDescription m_DataDescription; //TODO struct SourceDataStruct { PMDDataDescription dataDescription; char sourceData; }; namespace mitk { ToFCameraPMDController::ToFCameraPMDController(): m_PMDRes(0), m_PixelNumber(40000), m_NumberOfBytes(0), m_CaptureWidth(200), m_CaptureHeight(200), m_SourceDataSize(0), m_SourceDataStructSize(0), m_ConnectionCheck(false), m_InputFileName("") { } ToFCameraPMDController::~ToFCameraPMDController() { } bool ToFCameraPMDController::CloseCameraConnection() { m_PMDRes = pmdClose(m_PMDHandle); m_ConnectionCheck = ErrorText(m_PMDRes); m_PMDHandle = 0; return m_ConnectionCheck; } bool ToFCameraPMDController::ErrorText(int error) { if(error != PMD_OK) { pmdGetLastError (m_PMDHandle, m_PMDError, 128); MITK_ERROR << "Camera Error " << m_PMDError; return false; } else return true; } bool ToFCameraPMDController::UpdateCamera() { m_PMDRes = pmdUpdate(m_PMDHandle); return ErrorText(m_PMDRes); } bool ToFCameraPMDController::GetAmplitudes(float* amplitudeArray) { this->m_PMDRes = pmdGetAmplitudes(m_PMDHandle, amplitudeArray, this->m_NumberOfBytes); return ErrorText(this->m_PMDRes); } bool ToFCameraPMDController::GetAmplitudes(char* sourceData, float* amplitudeArray) { this->m_PMDRes = pmdCalcAmplitudes(m_PMDHandle, amplitudeArray, this->m_NumberOfBytes, m_DataDescription, &((SourceDataStruct*)sourceData)->sourceData); return ErrorText(this->m_PMDRes); } bool ToFCameraPMDController::GetIntensities(float* intensityArray) { this->m_PMDRes = pmdGetIntensities(m_PMDHandle, intensityArray, this->m_NumberOfBytes); return ErrorText(this->m_PMDRes); } bool ToFCameraPMDController::GetIntensities(char* sourceData, float* intensityArray) { this->m_PMDRes = pmdCalcIntensities(m_PMDHandle, intensityArray, this->m_NumberOfBytes, m_DataDescription, &((SourceDataStruct*)sourceData)->sourceData); return ErrorText(this->m_PMDRes); } bool ToFCameraPMDController::GetDistances(float* distanceArray) { this->m_PMDRes = pmdGetDistances(m_PMDHandle, distanceArray, this->m_NumberOfBytes); return ErrorText(this->m_PMDRes); } bool ToFCameraPMDController::GetSourceData(char* sourceDataArray) { this->m_PMDRes = pmdGetSourceDataDescription(m_PMDHandle, &m_DataDescription); if (!ErrorText(this->m_PMDRes)) { return false; } memcpy(&((SourceDataStruct*)sourceDataArray)->dataDescription, &m_DataDescription, sizeof(m_DataDescription)); this->m_PMDRes = pmdGetSourceData(m_PMDHandle, &((SourceDataStruct*)sourceDataArray)->sourceData, this->m_SourceDataSize); return ErrorText(this->m_PMDRes); } + bool ToFCameraPMDController::GetShortSourceData( short* sourceData) + { + this->m_PMDRes = pmdGetSourceDataDescription(m_PMDHandle,&m_DataDescription); + ErrorText( this->m_PMDRes); + this->m_PMDRes = pmdGetSourceData(m_PMDHandle,sourceData,m_DataDescription.size); + return ErrorText( this->m_PMDRes); + } bool ToFCameraPMDController::GetDistances(char* sourceData, float* distanceArray) { this->m_PMDRes = pmdCalcDistances(m_PMDHandle, distanceArray, this->m_NumberOfBytes, m_DataDescription, &((SourceDataStruct*)sourceData)->sourceData); return ErrorText(this->m_PMDRes); } int ToFCameraPMDController::SetIntegrationTime(unsigned int integrationTime) { unsigned int result; this->m_PMDRes = pmdGetValidIntegrationTime(m_PMDHandle, &result, 0, AtLeast, integrationTime); ErrorText(this->m_PMDRes); if (this->m_PMDRes != 0) { return 0; } this->m_PMDRes = pmdSetIntegrationTime(m_PMDHandle, 0, result); ErrorText(this->m_PMDRes); return result; } int ToFCameraPMDController::GetIntegrationTime() { unsigned int integrationTime = 0; this->m_PMDRes = pmdGetIntegrationTime(m_PMDHandle, &integrationTime, 0); ErrorText(this->m_PMDRes); return integrationTime; } int ToFCameraPMDController::SetModulationFrequency(unsigned int modulationFrequency) { unsigned int result; this->m_PMDRes = pmdGetValidModulationFrequency(m_PMDHandle, &result, 0, AtLeast, (modulationFrequency*1000000)); ErrorText(this->m_PMDRes); if (this->m_PMDRes != 0) { return 0; } this->m_PMDRes = pmdSetModulationFrequency(m_PMDHandle, 0, result); ErrorText(this->m_PMDRes); return (result/1000000);; } int ToFCameraPMDController::GetModulationFrequency() { unsigned int modulationFrequency = 0; this->m_PMDRes = pmdGetModulationFrequency (m_PMDHandle, &modulationFrequency, 0); ErrorText(this->m_PMDRes); return (modulationFrequency/1000000); } void ToFCameraPMDController::SetInputFileName(std::string inputFileName) { this->m_InputFileName = inputFileName; } } diff --git a/Modules/ToFHardware/mitkToFCameraPMDController.h b/Modules/ToFHardware/mitkToFCameraPMDController.h index 99a6073a88..6c9f1ef42a 100644 --- a/Modules/ToFHardware/mitkToFCameraPMDController.h +++ b/Modules/ToFHardware/mitkToFCameraPMDController.h @@ -1,175 +1,180 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit Module: $RCSfile$ Language: C++ Date: $Date: 2010-05-27 16:06:53 +0200 (Do, 27 Mai 2010) $ Version: $Revision: $ Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notices for more information. =========================================================================*/ #ifndef __mitkToFCameraPMDController_h #define __mitkToFCameraPMDController_h #include "mitkToFHardwareExports.h" #include "mitkCommon.h" #include "mitkToFCameraPMDController.h" #include "itkObject.h" #include "itkObjectFactory.h" namespace mitk { /** * @brief Virtual interface and base class for all PMD Time-of-Flight devices. Wraps PMD API provided in PMDSDK2 * Provides methods for accessing current distance, amplitude, intensity and raw data. * Allows to set parameters like modulation frequency and integration time. * * @ingroup ToFHardware */ class MITK_TOFHARDWARE_EXPORT ToFCameraPMDController : public itk::Object { public: mitkClassMacro( ToFCameraPMDController , itk::Object ); /*! \brief opens a connection to the ToF camera. Has to be implemented by the sub class */ //TODO return value virtual bool OpenCameraConnection() = 0; /*! \brief closes the connection to the camera */ //TODO return value virtual bool CloseCameraConnection(); /*! \brief Gets the current amplitude array from the device \param amplitudeArray float array where the amplitude data will be saved */ virtual bool GetAmplitudes(float* amplitudeArray); /*! \brief Calculates the current amplitude data from the raw source data using the processing plugin of the PMDSDK \param sourceData raw data array \param amplitudeArray float array where the amplitude data will be saved */ virtual bool GetAmplitudes(char* sourceData, float* amplitudeArray); /*! \brief Gets the current intensity array from the device \param intensityArray float array where the intensity data will be saved */ virtual bool GetIntensities(float* intensityArray); /*! \brief Calculates the current intensity data from the raw source data using the processing plugin of the PMDSDK \param sourceData raw data array \param intensityArray float array where the intensity data will be saved */ virtual bool GetIntensities(char* sourceData, float* intensityArray); /*! \brief Gets the current distance array from the device \param distanceArray float array where the distance data will be saved */ virtual bool GetDistances(float* distanceArray); /*! \brief Calculates the current distance data from the raw source data using the processing plugin of the PMDSDK \param sourceData raw data array \param distanceArray float array where the distance data will be saved */ virtual bool GetDistances(char* sourceData, float* distanceArray); /*! \brief Gets the PMD raw data from the ToF device. \param sourceDataArray array where the raw data will be saved */ virtual bool GetSourceData(char* sourceDataArray); + /*! + \brief Convenience method to get the PMD raw data from the ToF device as short array. + \param sourceData array where the short raw data will be saved + */ + bool GetShortSourceData(short* sourceData); + /*! \brief calls update on the camera -> a new ToF-image is aquired */ virtual bool UpdateCamera(); /*! \brief Returns the currently set modulation frequency. \return modulation frequency */ virtual int GetModulationFrequency(); /*! \brief Sets the modulation frequency of the ToF device. The method automatically calculates a valid value from the given frequency to make sure that only valid frequencies are used. \param modulationFrequency modulation frequency \return frequency set after validation step */ virtual int SetModulationFrequency(unsigned int modulationFrequency); /*! \brief Returns the currently set integration time. \return integration time */ virtual int GetIntegrationTime(); /*! \brief Sets the integration time of the ToF device. The method automatically calculates a valid value from the given integration time to make sure that only valid times are used. \param integrationTime integration time \return integration time set after validation step */ virtual int SetIntegrationTime(unsigned int integrationTime); /*! \brief set input file name used by PMD player classes */ virtual void SetInputFileName(std::string inputFileName); /*! \brief Access the resolution of the image in x direction \return widht of image in pixel */ itkGetMacro(CaptureWidth, unsigned int); /*! \brief Access the resolution of the image in y direction \return height of image in pixel */ itkGetMacro(CaptureHeight, unsigned int); itkGetMacro(SourceDataStructSize, int); protected: ToFCameraPMDController(); ~ToFCameraPMDController(); /*! \brief Method printing the current error message to the console and returning whether the previous command was successful \param error error number returned by the PMD function \return flag indicating if an error occured (false) or not (true) */ bool ErrorText(int error); - char m_PMDError[128]; ///< member holding the current error text int m_PMDRes; ///< holds the current result message provided by PMD int m_PixelNumber; ///< holds the number of pixels contained in the image int m_NumberOfBytes; ///< holds the number of bytes contained in the image unsigned int m_CaptureWidth; ///< holds the width of the image in pixel unsigned int m_CaptureHeight; ///< holds the height of the image in pixel int m_SourceDataSize; ///< size of the original PMD source data int m_SourceDataStructSize; ///< size of the PMD source data struct and the PMD source data bool m_ConnectionCheck; ///< flag showing whether the camera is connected (true) or not (false) std::string m_InputFileName; ///< input file name used by PMD player classes char *m_SourcePlugin; ///< holds name of source plugin to be loaded (e.g. camcube3.W64.pap for CamCube 3.0 on Win64 platform) char *m_SourceParam; ///< holds source parameter(s) char *m_ProcPlugin; ///< holds name of processing plugin to be loaded (e.g. camcubeproc.W64.pap for CamCube 3.0 on Win64 platform) char *m_ProcParam; ///< holds processing parameter(s) private: }; } //END mitk namespace #endif diff --git a/Modules/ToFHardware/mitkToFCameraPMDRawDataCamCubeDevice.cpp b/Modules/ToFHardware/mitkToFCameraPMDRawDataCamCubeDevice.cpp new file mode 100644 index 0000000000..401762b54d --- /dev/null +++ b/Modules/ToFHardware/mitkToFCameraPMDRawDataCamCubeDevice.cpp @@ -0,0 +1,116 @@ +/*========================================================================= + +Program: Medical Imaging & Interaction Toolkit +Module: $RCSfile$ +Language: C++ +Date: $Date: 2010-05-27 16:06:53 +0200 (Do, 27 Mai 2010) $ +Version: $Revision: $ + +Copyright (c) German Cancer Research Center, Division of Medical and +Biological Informatics. All rights reserved. +See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. + +This software is distributed WITHOUT ANY WARRANTY; without even +the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR +PURPOSE. See the above copyright notices for more information. + +=========================================================================*/ +#include "mitkToFCameraPMDRawDataCamCubeDevice.h" +#include "mitkToFCameraPMDCamCubeController.h" + +// vtk includes +#include "vtkSmartPointer.h" + +namespace mitk +{ + ToFCameraPMDRawDataCamCubeDevice::ToFCameraPMDRawDataCamCubeDevice() + { + m_Controller = ToFCameraPMDCamCubeController::New(); + } + + ToFCameraPMDRawDataCamCubeDevice::~ToFCameraPMDRawDataCamCubeDevice() + { + } + + void ToFCameraPMDRawDataCamCubeDevice::GetChannelSourceData(short* sourceData, vtkShortArray* vtkChannelArray ) + { + int i = 0; + //unsigned int channelDataPosition = 0; + unsigned int channelSize = (this->GetCaptureHeight()*this->GetCaptureWidth()*2); + this->SetChannelSize(channelSize); + signed short* channel1; + signed short* channel2; + signed short* channel3; + signed short* channel4; + + vtkSmartPointer cvtkChannelArray = vtkShortArray::New(); + cvtkChannelArray->SetNumberOfComponents(channelSize); + cvtkChannelArray->SetNumberOfTuples(4); + cvtkChannelArray->Allocate(1); + + sourceData += 256; + //channelDataPosition += 256; + channel1 = sourceData; + cvtkChannelArray->InsertTupleValue(0,channel1); + sourceData += channelSize; + //channelDataPosition += channelSize; + sourceData += 256; + //channelDataPosition += 256; + channel2 = sourceData; + cvtkChannelArray->InsertTupleValue(1,channel2); + sourceData += channelSize; + //channelDataPosition += channelSize; + sourceData += 256; + //channelDataPosition += 256; + channel3 = sourceData; + cvtkChannelArray->InsertTupleValue(2,channel3); + sourceData += channelSize; + //channelDataPosition += channelSize; + sourceData += 256; + //channelDataPosition += 256; + channel4 = sourceData; + cvtkChannelArray->InsertTupleValue(3,channel4); + //sourceData -= channelDataPosition; + vtkChannelArray->DeepCopy(cvtkChannelArray); + cvtkChannelArray->Delete(); + } + + void ToFCameraPMDRawDataCamCubeDevice::SetProperty( const char *propertyKey, BaseProperty* propertyValue ) + { + ToFCameraPMDRawDataDevice::SetProperty(propertyKey,propertyValue); + this->m_PropertyList->SetProperty(propertyKey, propertyValue); + + ToFCameraPMDCamCubeController::Pointer myController = dynamic_cast(this->m_Controller.GetPointer()); + + bool boolValue = false; + GetBoolProperty(propertyValue, boolValue); + if (strcmp(propertyKey, "SetFPNCalibration") == 0) + { + myController->SetFPNCalibration(boolValue); + } + else if (strcmp(propertyKey, "SetFPPNCalibration") == 0) + { + myController->SetFPPNCalibration(boolValue); + } + else if (strcmp(propertyKey, "SetLinearityCalibration") == 0) + { + myController->SetLinearityCalibration(boolValue); + } + else if (strcmp(propertyKey, "SetLensCalibration") == 0) + { + myController->SetLensCalibration(boolValue); + } + else if (strcmp(propertyKey, "SetExposureMode") == 0) + { + if (boolValue) + { + myController->SetExposureMode(1); + } + else + { + myController->SetExposureMode(0); + } + } + } + +} diff --git a/Modules/ToFHardware/mitkToFCameraPMDRawDataCamCubeDevice.h b/Modules/ToFHardware/mitkToFCameraPMDRawDataCamCubeDevice.h new file mode 100644 index 0000000000..ac8bf27d69 --- /dev/null +++ b/Modules/ToFHardware/mitkToFCameraPMDRawDataCamCubeDevice.h @@ -0,0 +1,56 @@ +/*========================================================================= + +Program: Medical Imaging & Interaction Toolkit +Module: $RCSfile$ +Language: C++ +Date: $Date: 2010-05-27 16:06:53 +0200 (Do, 27 Mai 2010) $ +Version: $Revision: $ + +Copyright (c) German Cancer Research Center, Division of Medical and +Biological Informatics. All rights reserved. +See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. + +This software is distributed WITHOUT ANY WARRANTY; without even +the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR +PURPOSE. See the above copyright notices for more information. + +=========================================================================*/ +#ifndef __mitkToFCameraPMDRawDataCamCubeDevice_h +#define __mitkToFCameraPMDRawDataCamCubeDevice_h + +#include "mitkToFHardwareExports.h" +#include "mitkCommon.h" +#include "mitkToFCameraDevice.h" +#include "mitkToFCameraPMDRawDataDevice.h" + +namespace mitk +{ + /** + * @brief Device class representing a PMD CamCube camera + * + * + * @ingroup ToFHardwareMBI + */ + class MITK_TOFHARDWARE_EXPORT ToFCameraPMDRawDataCamCubeDevice : public ToFCameraPMDRawDataDevice + { + public: + + mitkClassMacro( ToFCameraPMDRawDataCamCubeDevice , ToFCameraPMDRawDataDevice ); + + itkNewMacro( Self ); + + virtual void SetProperty( const char *propertyKey, BaseProperty* propertyValue ); + + virtual void GetChannelSourceData(short* sourceData, vtkShortArray* vtkChannelArray ); + + + protected: + + ToFCameraPMDRawDataCamCubeDevice(); + + ~ToFCameraPMDRawDataCamCubeDevice(); + private: + + }; +} //END mitk namespace +#endif diff --git a/Modules/ToFHardware/mitkToFCameraPMDRawDataDevice.cpp b/Modules/ToFHardware/mitkToFCameraPMDRawDataDevice.cpp new file mode 100644 index 0000000000..7e8f7a9693 --- /dev/null +++ b/Modules/ToFHardware/mitkToFCameraPMDRawDataDevice.cpp @@ -0,0 +1,489 @@ +/*========================================================================= + +Program: Medical Imaging & Interaction Toolkit +Module: $RCSfile$ +Language: C++ +Date: $Date: 2010-05-27 16:06:53 +0200 (Do, 27 Mai 2010) $ +Version: $Revision: $ + +Copyright (c) German Cancer Research Center, Division of Medical and +Biological Informatics. All rights reserved. +See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. + +This software is distributed WITHOUT ANY WARRANTY; without even +the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR +PURPOSE. See the above copyright notices for more information. + +=========================================================================*/ +#include "mitkToFCameraPMDRawDataDevice.h" +#include "mitkRealTimeClock.h" + +#include "itkMultiThreader.h" +#include + +namespace mitk +{ + ToFCameraPMDRawDataDevice::ToFCameraPMDRawDataDevice() : + m_SourceDataArray(NULL), m_SourceDataBuffer(NULL), m_ShortSourceData(NULL) + { + m_RawDataSource = ThreadedToFRawDataReconstruction::New(); + + } + + ToFCameraPMDRawDataDevice::~ToFCameraPMDRawDataDevice() + { + this->CleanUpSourceData(); + } + + bool ToFCameraPMDRawDataDevice::ConnectCamera() + { + bool ok = false; + if (m_Controller.IsNotNull()) + { + ok = m_Controller->OpenCameraConnection(); + if (ok) + { + this->m_CaptureWidth = m_Controller->GetCaptureWidth(); + this->m_CaptureHeight = m_Controller->GetCaptureHeight(); + this->m_SourceDataSize = m_Controller->GetSourceDataStructSize(); + this->m_PixelNumber = this->m_CaptureWidth * this->m_CaptureHeight; + + // allocate buffers + this->AllocatePixelArrays(); + this->AllocateSourceData(); + + m_CameraConnected = true; + } + } + return ok; + } + + bool ToFCameraPMDRawDataDevice::DisconnectCamera() + { + bool ok = false; + if (m_Controller) + { + ok = m_Controller->CloseCameraConnection(); + if (ok) + { + m_CameraConnected = false; + } + } + return ok; + } + + void ToFCameraPMDRawDataDevice::StartCamera() + { + if (m_CameraConnected) + { + // get the first image + this->m_Controller->UpdateCamera(); + + this->m_ImageMutex->Lock(); + this->m_Controller->GetSourceData(this->m_SourceDataBuffer[this->m_FreePos]); + this->m_FreePos = (this->m_FreePos+1) % this->m_BufferSize; + this->m_CurrentPos = (this->m_CurrentPos+1) % this->m_BufferSize; + this->m_ImageSequence++; + this->m_ImageMutex->Unlock(); + + this->m_CameraActiveMutex->Lock(); + this->m_CameraActive = true; + this->m_CameraActiveMutex->Unlock(); + + this->m_ThreadID = this->m_MultiThreader->SpawnThread(this->Acquire, this); + // wait a little to make sure that the thread is started + itksys::SystemTools::Delay(10); + } + else + { + MITK_INFO<<"Camera not connected"; + } + } + + void ToFCameraPMDRawDataDevice::StopCamera() + { + m_CameraActiveMutex->Lock(); + m_CameraActive = false; + m_CameraActiveMutex->Unlock(); + + itksys::SystemTools::Delay(100); + if (m_MultiThreader.IsNotNull()) + { + m_MultiThreader->TerminateThread(m_ThreadID); + } + // wait a little to make sure that the thread is terminated + itksys::SystemTools::Delay(10); + } + + bool ToFCameraPMDRawDataDevice::IsCameraActive() + { + m_CameraActiveMutex->Lock(); + bool ok = m_CameraActive; + m_CameraActiveMutex->Unlock(); + return ok; + } + + void ToFCameraPMDRawDataDevice::UpdateCamera() + { + if (m_Controller) + { + m_Controller->UpdateCamera(); + } + } + + ITK_THREAD_RETURN_TYPE ToFCameraPMDRawDataDevice::Acquire(void* pInfoStruct) + { + /* extract this pointer from Thread Info structure */ + struct itk::MultiThreader::ThreadInfoStruct * pInfo = (struct itk::MultiThreader::ThreadInfoStruct*)pInfoStruct; + if (pInfo == NULL) + { + return ITK_THREAD_RETURN_VALUE; + } + if (pInfo->UserData == NULL) + { + return ITK_THREAD_RETURN_VALUE; + } + ToFCameraPMDRawDataDevice* toFCameraDevice = (ToFCameraPMDRawDataDevice*)pInfo->UserData; + if (toFCameraDevice!=NULL) + { + mitk::RealTimeClock::Pointer realTimeClock = mitk::RealTimeClock::New(); + double t1, t2; + t1 = realTimeClock->GetCurrentStamp(); + int n = 100; + bool overflow = false; + bool printStatus = false; + + while (toFCameraDevice->IsCameraActive()) + { + // update the ToF camera + toFCameraDevice->UpdateCamera(); + // get the source data from the camera and write it at the next free position in the buffer + toFCameraDevice->m_Controller->GetSourceData(toFCameraDevice->m_SourceDataArray); + toFCameraDevice->m_Controller->GetShortSourceData(toFCameraDevice->m_ShortSourceData); + vtkShortArray* channelData = vtkShortArray::New(); + toFCameraDevice->GetChannelSourceData( toFCameraDevice->m_ShortSourceData, channelData ); + + // call modified to indicate that cameraDevice was modified + toFCameraDevice->Modified(); + + + /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + TODO Buffer Handling currently only works for buffer size 1 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/ + if(!toFCameraDevice->m_RawDataSource->GetInit()) + { + toFCameraDevice->m_RawDataSource->Initialize(toFCameraDevice->m_CaptureWidth, toFCameraDevice->m_CaptureHeight, + toFCameraDevice->m_Controller->GetModulationFrequency(), toFCameraDevice->GetChannelSize()); + } + toFCameraDevice->m_RawDataSource->SetChannelData(channelData); + + toFCameraDevice->m_ImageMutex->Lock(); + toFCameraDevice->m_RawDataSource->Update(); + toFCameraDevice->m_RawDataSource->GetAmplitudes(toFCameraDevice->m_AmplitudeArray); + toFCameraDevice->m_RawDataSource->GetIntensities(toFCameraDevice->m_IntensityArray); + toFCameraDevice->m_RawDataSource->GetDistances(toFCameraDevice->m_DistanceArray); + channelData->Delete(); + + toFCameraDevice->m_FreePos = (toFCameraDevice->m_FreePos+1) % toFCameraDevice->m_BufferSize; + toFCameraDevice->m_CurrentPos = (toFCameraDevice->m_CurrentPos+1) % toFCameraDevice->m_BufferSize; + toFCameraDevice->m_ImageSequence++; + if (toFCameraDevice->m_FreePos == toFCameraDevice->m_CurrentPos) + { + overflow = true; + } + if (toFCameraDevice->m_ImageSequence % n == 0) + { + printStatus = true; + } + toFCameraDevice->m_ImageMutex->Unlock(); + if (overflow) + { + overflow = false; + } + /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + END TODO Buffer Handling currently only works for buffer size 1 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/ + + // print current framerate + if (printStatus) + { + t2 = realTimeClock->GetCurrentStamp() - t1; + //MITK_INFO << "t2: " << t2 <<" Time (s) for 1 image: " << (t2/1000) / n << " Framerate (fps): " << n / (t2/1000) << " Sequence: " << toFCameraDevice->m_ImageSequence; + MITK_INFO << " Framerate (fps): " << n / (t2/1000) << " Sequence: " << toFCameraDevice->m_ImageSequence; + t1 = realTimeClock->GetCurrentStamp(); + printStatus = false; + } + + } // end of while loop + } + return ITK_THREAD_RETURN_VALUE; + } + + // TODO: Buffer size currently set to 1. Once Buffer handling is working correctly, method may be reactivated + // void ToFCameraPMDDevice::ResetBuffer(int bufferSize) + // { + // this->m_BufferSize = bufferSize; + // this->m_CurrentPos = -1; + // this->m_FreePos = 0; + // } + + void ToFCameraPMDRawDataDevice::GetAmplitudes(float* amplitudeArray, int& imageSequence) + { + m_ImageMutex->Lock(); + if (m_CameraActive) + { + // Flip around y- axis (vertical axis) + this->XYAxisFlipImage(this->m_AmplitudeArray, amplitudeArray, 0, 1 ); + imageSequence = this->m_ImageSequence; + } + else + { + MITK_WARN("ToF") << "Warning: Data can only be acquired if camera is active."; + } + m_ImageMutex->Unlock(); + } + + void ToFCameraPMDRawDataDevice::GetIntensities(float* intensityArray, int& imageSequence) + { + m_ImageMutex->Lock(); + if (m_CameraActive) + { + // Flip around y- axis (vertical axis) + this->XYAxisFlipImage(this->m_IntensityArray, intensityArray,0,1); + imageSequence = this->m_ImageSequence; + } + else + { + MITK_WARN("ToF") << "Warning: Data can only be acquired if camera is active."; + } + m_ImageMutex->Unlock(); + } + + void ToFCameraPMDRawDataDevice::GetDistances(float* distanceArray, int& imageSequence) + { + m_ImageMutex->Lock(); + if (m_CameraActive) + { + // Flip around y- axis (vertical axis) + this->XYAxisFlipImage(this->m_DistanceArray,distanceArray,0,1); + imageSequence = this->m_ImageSequence; + } + else + { + MITK_WARN("ToF") << "Warning: Data can only be acquired if camera is active."; + } + m_ImageMutex->Unlock(); + } + + void ToFCameraPMDRawDataDevice::GetAllImages(float* distanceArray, float* amplitudeArray, float* intensityArray, char* sourceDataArray, + int requiredImageSequence, int& capturedImageSequence) + { + if (m_CameraActive) + { + m_ImageMutex->Lock(); + // 1) copy the image buffer + // 2) convert the distance values from m to mm + // 3) Flip around y- axis (vertical axis) + + // check for empty buffer + if (this->m_ImageSequence < 0) + { + // buffer empty + MITK_INFO << "Buffer empty!! "; + capturedImageSequence = this->m_ImageSequence; + m_ImageMutex->Unlock(); + return; + } + + // determine position of image in buffer + int pos = 0; + if ((requiredImageSequence < 0) || (requiredImageSequence > this->m_ImageSequence)) + { + capturedImageSequence = this->m_ImageSequence; + pos = this->m_CurrentPos; + //MITK_INFO << "Required image not found! Required: " << requiredImageSequence << " delivered/current: " << this->m_ImageSequence; + } + else if (requiredImageSequence <= this->m_ImageSequence - this->m_BufferSize) + { + capturedImageSequence = (this->m_ImageSequence - this->m_BufferSize) + 1; + pos = (this->m_CurrentPos + 1) % this->m_BufferSize; + //MITK_INFO << "Out of buffer! Required: " << requiredImageSequence << " delivered: " << capturedImageSequence << " current: " << this->m_ImageSequence; + } + else // (requiredImageSequence > this->m_ImageSequence - this->m_BufferSize) && (requiredImageSequence <= this->m_ImageSequence) + + { + capturedImageSequence = requiredImageSequence; + pos = (this->m_CurrentPos + (10-(this->m_ImageSequence - requiredImageSequence))) % this->m_BufferSize; + } + m_ImageMutex->Unlock(); + + int u, v; + for (int i=0; im_CaptureHeight; i++) + { + for (int j=0; jm_CaptureWidth; j++) + { + u = i*this->m_CaptureWidth+j; + v = (i+1)*this->m_CaptureWidth-1-j; + distanceArray[u] = this->m_DistanceArray[v]; // unit in millimeter + amplitudeArray[u] = this->m_AmplitudeArray[v]; + intensityArray[u] = this->m_IntensityArray[v]; + } + } + + memcpy(sourceDataArray, this->m_SourceDataBuffer[this->m_CurrentPos], this->m_SourceDataSize); + } + else + { + MITK_WARN("ToF") << "Warning: Data can only be acquired if camera is active."; + } + } + + void ToFCameraPMDRawDataDevice::XYAxisFlipImage( float* imageData, float* &flippedData, int xAxis, int yAxis, int dimension ) + { + int captureWidth = this->GetCaptureWidth(); + int captureHeight = this->GetCaptureHeight(); + + // + //flips image around x- axis (horizontal axis) + // + + if(xAxis == 1 && yAxis != 1) + { + for (int i=0; im_Controller; + } + + void ToFCameraPMDRawDataDevice::SetProperty( const char *propertyKey, BaseProperty* propertyValue ) + { + ToFCameraDevice::SetProperty(propertyKey,propertyValue); + this->m_PropertyList->SetProperty(propertyKey, propertyValue); + if (strcmp(propertyKey, "ModulationFrequency") == 0) + { + int modulationFrequency = 0; + GetIntProperty(propertyValue, modulationFrequency); + m_Controller->SetModulationFrequency(modulationFrequency); + } + else if (strcmp(propertyKey, "IntegrationTime") == 0) + { + int integrationTime = 0; + GetIntProperty(propertyValue, integrationTime); + m_Controller->SetIntegrationTime(integrationTime); + } + } + + void ToFCameraPMDRawDataDevice::CleanupPixelArrays() + { + if (m_IntensityArray) + { + delete [] m_IntensityArray; + } + if (m_DistanceArray) + { + delete [] m_DistanceArray; + } + if (m_AmplitudeArray) + { + delete [] m_AmplitudeArray; + } + if (m_ShortSourceData) + { + delete [] m_ShortSourceData; + } + } + + void ToFCameraPMDRawDataDevice::AllocatePixelArrays() + { + // free memory if it was already allocated + CleanupPixelArrays(); + // allocate buffer + this->m_IntensityArray = new float[this->m_PixelNumber]; + for(int i=0; im_PixelNumber; i++) {this->m_IntensityArray[i]=0.0;} + this->m_DistanceArray = new float[this->m_PixelNumber]; + for(int i=0; im_PixelNumber; i++) {this->m_DistanceArray[i]=0.0;} + this->m_AmplitudeArray = new float[this->m_PixelNumber]; + for(int i=0; im_PixelNumber; i++) {this->m_AmplitudeArray[i]=0.0;} + this->m_ShortSourceData = new short[this->m_SourceDataSize]; + for(int i=0; im_SourceDataSize; i++) {this->m_ShortSourceData[i]=0.0;} + + } + + void ToFCameraPMDRawDataDevice::AllocateSourceData() + { + // clean up if array and data have already been allocated + CleanUpSourceData(); + // (re-) allocate memory + this->m_SourceDataArray = new char[this->m_SourceDataSize]; + for(int i=0; im_SourceDataSize; i++) {this->m_SourceDataArray[i]=0;} + + this->m_SourceDataBuffer = new char*[this->m_MaxBufferSize]; + for(int i=0; im_MaxBufferSize; i++) + { + this->m_SourceDataBuffer[i] = new char[this->m_SourceDataSize]; + } + } + + void ToFCameraPMDRawDataDevice::CleanUpSourceData() + { + if (m_SourceDataArray) + { + delete[] m_SourceDataArray; + } + if (m_SourceDataBuffer) + { + for(int i=0; im_MaxBufferSize; i++) + { + delete[] this->m_SourceDataBuffer[i]; + } + delete[] this->m_SourceDataBuffer; + } + } +} diff --git a/Modules/ToFHardware/mitkToFCameraPMDRawDataDevice.h b/Modules/ToFHardware/mitkToFCameraPMDRawDataDevice.h new file mode 100644 index 0000000000..20f65bc362 --- /dev/null +++ b/Modules/ToFHardware/mitkToFCameraPMDRawDataDevice.h @@ -0,0 +1,177 @@ +/*========================================================================= + +Program: Medical Imaging & Interaction Toolkit +Module: $RCSfile$ +Language: C++ +Date: $Date: 2010-05-27 16:06:53 +0200 (Do, 27 Mai 2010) $ +Version: $Revision: $ + +Copyright (c) German Cancer Research Center, Division of Medical and +Biological Informatics. All rights reserved. +See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. + +This software is distributed WITHOUT ANY WARRANTY; without even +the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR +PURPOSE. See the above copyright notices for more information. + +=========================================================================*/ +#ifndef __mitkToFCameraPMDRawDataDevice_h +#define __mitkToFCameraPMDRawDataDevice_h + +#include "mitkToFHardwareExports.h" +#include "mitkToFCameraDevice.h" +#include "mitkToFCameraPMDController.h" +#include "mitkThreadedToFRawDataReconstruction.h" + +namespace mitk +{ + /** + * @brief Interface for all representations of PMD ToF devices. + * ToFCameraPMDDevice internally holds an instance of ToFCameraPMDController and starts a thread + * that continuously grabs images from the controller. A buffer structure buffers the last acquired images + * to provide the image data loss-less. + * + * @ingroup ToFHardware + */ + class MITK_TOFHARDWARE_EXPORT ToFCameraPMDRawDataDevice : public ToFCameraDevice + { + public: + + mitkClassMacro( ToFCameraPMDRawDataDevice , ToFCameraDevice ); + + itkNewMacro( Self ); + + itkSetMacro(ChannelSize, int); + itkGetMacro(ChannelSize, int); + /*! + \brief opens a connection to the ToF camera + */ + virtual bool ConnectCamera(); + /*! + \brief closes the connection to the camera + */ + virtual bool DisconnectCamera(); + /*! + \brief starts the continuous updating of the camera. + A separate thread updates the source data, the main thread processes the source data and creates images and coordinates + */ + virtual void StartCamera(); + /*! + \brief stops the continuous updating of the camera + */ + virtual void StopCamera(); + /*! + \brief updates the camera for image acquisition + */ + virtual void UpdateCamera(); + /*! + \brief returns whether the camera is currently active or not + */ + virtual bool IsCameraActive(); + /*! + \brief gets the amplitude data from the ToF camera as the strength of the active illumination of every pixel. Caution! The user is responsible for allocating and deleting the images. + These values can be used to determine the quality of the distance values. The higher the amplitude value, the higher the accuracy of the according distance value + \param imageSequence the actually captured image sequence number + \param amplitudeArray contains the returned amplitude data as an array. + */ + virtual void GetAmplitudes(float* amplitudeArray, int& imageSequence); + /*! + \brief gets the intensity data from the ToF camera as a greyscale image. Caution! The user is responsible for allocating and deleting the images. + \param intensityArray contains the returned intensities data as an array. + \param imageSequence the actually captured image sequence number + */ + virtual void GetIntensities(float* intensityArray, int& imageSequence); + /*! + \brief gets the distance data from the ToF camera measuring the distance between the camera and the different object points in millimeters. Caution! The user is responsible for allocating and deleting the images. + \param distanceArray contains the returned distances data as an array. + \param imageSequence the actually captured image sequence number + */ + virtual void GetDistances(float* distanceArray, int& imageSequence); + /*! + \brief gets the 3 images (distance, amplitude, intensity) from the ToF camera. Caution! The user is responsible for allocating and deleting the images. + \param distanceArray contains the returned distance data as an array. + \param amplitudeArray contains the returned amplitude data as an array. + \param intensityArray contains the returned intensity data as an array. + \param sourceDataArray contains the complete source data from the camera device. + \param requiredImageSequence the required image sequence number + \param capturedImageSequence the actually captured image sequence number + */ + virtual void GetAllImages(float* distanceArray, float* amplitudeArray, float* intensityArray, char* sourceDataArray, + int requiredImageSequence, int& capturedImageSequence); +// TODO: Buffer size currently set to 1. Once Buffer handling is working correctly, method may be reactivated +// /*! +// \brief pure virtual method resetting the buffer using the specified bufferSize. Has to be implemented by sub-classes +// \param bufferSize buffer size the buffer should be reset to +// */ +// virtual void ResetBuffer(int bufferSize) = 0; + //TODO add/correct documentation for requiredImageSequence and capturedImageSequence in the GetAllImages, GetDistances, GetIntensities and GetAmplitudes methods. + + /*! + \brief returns the corresponding camera controller + */ + ToFCameraPMDController::Pointer GetController(); + + virtual void GetChannelSourceData(short* sourceData, vtkShortArray* vtkChannelArray ){}; + + /*! + \brief set a BaseProperty + */ + virtual void SetProperty( const char *propertyKey, BaseProperty* propertyValue ); + + protected: + + ToFCameraPMDRawDataDevice(); + + ~ToFCameraPMDRawDataDevice(); + + /*! + \brief method for allocating m_SourceDataArray and m_SourceDataBuffer + */ + virtual void AllocateSourceData(); + + /*! + \brief method for cleaning up memory allocated for m_SourceDataArray and m_SourceDataBuffer + */ + virtual void CleanUpSourceData(); + + /*! + \brief method for allocating memory for pixel arrays m_IntensityArray, m_DistanceArray and m_AmplitudeArray + */ + virtual void AllocatePixelArrays(); + /*! + \brief method for cleanup memory allocated for pixel arrays m_IntensityArray, m_DistanceArray and m_AmplitudeArray + */ + virtual void CleanupPixelArrays(); + /*! + \brief Thread method continuously acquiring images from the ToF hardware + */ + static ITK_THREAD_RETURN_TYPE Acquire(void* pInfoStruct); + + /*! + \brief moves the position pointer m_CurrentPos to the next position in the buffer if that's not the next free position to prevent reading from an empty buffer + */ + void GetNextPos(); + + /*! + \brief gets the image data and flips it according to user needs Caution! The user is responsible for allocating and deleting the data. + \param imageData contains array to the input data. + \param flippedData contains flipped output array - Caution! The user is responsible for allocating and deleting the data. Size should be equal to imageData! + \param xAxis flag is set to flip around x axis (1 - set, 0 - not set). + \param yAxis flag is set to flip around y axis (1 - set, 0 - not set). + \param dimension contains the extend of the z dimension (preset is 1) + */ + void XYAxisFlipImage( float* imageData, float* &flippedData, int xAxis, int yAxis, int dimension = 1 ); + + ToFCameraPMDController::Pointer m_Controller; ///< corresponding CameraController + ThreadedToFRawDataReconstruction::Pointer m_RawDataSource; + char** m_SourceDataBuffer; ///< buffer holding the last acquired images + char* m_SourceDataArray; ///< array holding the current PMD source data + short* m_ShortSourceData; ///< array holding the current PMD raw data + private: + + //member variables + int m_ChannelSize; ///< member holds the size of a single raw data channel + + }; +} //END mitk namespace +#endif diff --git a/Modules/ToFHardware/mitkToFHardware.cmake b/Modules/ToFHardware/mitkToFHardware.cmake index 27e5d47825..f4aeee0e1c 100644 --- a/Modules/ToFHardware/mitkToFHardware.cmake +++ b/Modules/ToFHardware/mitkToFHardware.cmake @@ -1,116 +1,116 @@ #option MITK_USE_TOF_HARDWARE IF(WIN32) IF(CMAKE_CL_64) SET(_PLATFORM_STRING "W64") ELSE(CMAKE_CL_64) SET(_PLATFORM_STRING "W32") ENDIF(CMAKE_CL_64) ELSE(WIN32) IF(CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64") SET(_PLATFORM_STRING "L64") ELSE(CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64") SET(_PLATFORM_STRING "L32") ENDIF(CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64") ENDIF(WIN32) SET(MITK_TOF_AVAILABLE_CAMERAS MITK Player) OPTION(MITK_ENABLE_TOF_HARDWARE "Support for range cameras" OFF) IF(MITK_ENABLE_TOF_HARDWARE) #Begin PMD Camcube hardware OPTION(MITK_USE_TOF_PMDCAMCUBE "Enable support for PMD camcube" OFF) # only if PMD Camcube is enabled IF(MITK_USE_TOF_PMDCAMCUBE) FIND_LIBRARY(MITK_PMD_LIB pmdaccess2 DOC "PMD access library.") GET_FILENAME_COMPONENT(MITK_PMD_SDK_DIR ${MITK_PMD_LIB} PATH) SET(MITK_PMD_SDK_DIR ${MITK_PMD_SDK_DIR}/..) FIND_PATH(MITK_PMD_INCLUDE_DIR pmdsdk2.h ${MITK_PMD_SDK_DIR}/include DOC "Include directory of PMD-SDK.") SET(MITK_TOF_PMD_CAMCUBE_SOURCE ${MITK_PMD_SDK_DIR}/plugins/camcube3.${_PLATFORM_STRING}.pap) SET(MITK_TOF_PMD_CAMCUBE_PROC ${MITK_PMD_SDK_DIR}/plugins/camcubeproc.${_PLATFORM_STRING}.ppp) SET(MITK_TOF_PMD_FILE_SOURCE ${MITK_PMD_SDK_DIR}/plugins/pmdfile.${_PLATFORM_STRING}.pcp) - SET(MITK_TOF_AVAILABLE_CAMERAS ${MITK_TOF_AVAILABLE_CAMERAS},PMD CamCube 2.0/3.0,PMD Player,PMD Raw Data Player) + SET(MITK_TOF_AVAILABLE_CAMERAS ${MITK_TOF_AVAILABLE_CAMERAS},PMD CamCube 2.0/3.0,PMD CamCubeRaw 2.0/3.0,PMD Player,PMD Raw Data Player) # FILE(GLOB MITK_TOF_PMD_CAMCUBE_SOURCE camcube3.${_PLATFORM_STRING}.pap) # FILE(GLOB MITK_TOF_PMD_CAMCUBE_PROC camcubeproc.${_PLATFORM_STRING}.ppp) # FILE(GLOB MITK_TOF_PMD_FILE_SOURCE pmdfile.${_PLATFORM_STRING}.pcp) IF(WIN32) MITK_INSTALL(FILES ${MITK_PMD_SDK_DIR}/bin/pmdaccess2.dll CONFIGURATIONS Release) MITK_INSTALL(FILES ${MITK_PMD_SDK_DIR}/plugins/camcube3.W32.pap CONFIGURATIONS Release) MITK_INSTALL(FILES ${MITK_PMD_SDK_DIR}/plugins/camcubeproc.W32.ppp CONFIGURATIONS Release) MITK_INSTALL(FILES ${MITK_PMD_SDK_DIR}/plugins/camcube3.W64.pap CONFIGURATIONS Release) MITK_INSTALL(FILES ${MITK_PMD_SDK_DIR}/plugins/camcubeproc.W64.ppp CONFIGURATIONS Release) MITK_INSTALL(FILES ${MITK_PMD_SDK_DIR}/plugins/pmdfile.W32.pcp CONFIGURATIONS Release) ENDIf(WIN32) ENDIF(MITK_USE_TOF_PMDCAMCUBE) #End PMD Camcube Hardware #Begin PMD CamBoard hardware OPTION(MITK_USE_TOF_PMDCAMBOARD "Enable support for PMD camboard" OFF) # only if PMD CamBoard is enabled IF(MITK_USE_TOF_PMDCAMBOARD) FIND_LIBRARY(MITK_PMD_LIB pmdaccess2 DOC "PMD access library.") GET_FILENAME_COMPONENT(MITK_PMD_SDK_DIR ${MITK_PMD_LIB} PATH) SET(MITK_PMD_SDK_DIR ${MITK_PMD_SDK_DIR}/..) FIND_PATH(MITK_PMD_INCLUDE_DIR pmdsdk2.h ${MITK_PMD_SDK_DIR}/include DOC "Include directory of PMD-SDK.") SET(MITK_TOF_PMD_CAMBOARD_SOURCE ${MITK_PMD_SDK_DIR}/plugins/camboard.${_PLATFORM_STRING}.pap) SET(MITK_TOF_PMD_CAMBOARD_PROC ${MITK_PMD_SDK_DIR}/plugins/camboardproc.${_PLATFORM_STRING}.ppp) SET(MITK_TOF_AVAILABLE_CAMERAS ${MITK_TOF_AVAILABLE_CAMERAS},PMD CamBoard) # FILE(GLOB MITK_TOF_PMD_CAMBOARD_SOURCE camboard.${_PLATFORM_STRING}.pap) # FILE(GLOB MITK_TOF_PMD_CAMBOARD_PROC camboardproc.${_PLATFORM_STRING}.ppp) # FILE(GLOB MITK_TOF_PMD_FILE_SOURCE ${MITK_PMD_SDK_DIR}/plugins/pmdfile.${_PLATFORM_STRING}.pcp) IF(WIN32) INSTALL(FILES ${MITK_PMD_SDK_DIR}/bin/pmdaccess2.dll DESTINATION bin CONFIGURATIONS Release) INSTALL(FILES ${MITK_PMD_SDK_DIR}/plugins/camboard.W32.pap DESTINATION bin CONFIGURATIONS Release) INSTALL(FILES ${MITK_PMD_SDK_DIR}/plugins/camboardproc.W32.ppp DESTINATION bin CONFIGURATIONS Release) # INSTALL(FILES ${MITK_PMD_SDK_DIR}/plugins/camboard.W64.pap DESTINATION bin CONFIGURATIONS Release) # INSTALL(FILES ${MITK_PMD_SDK_DIR}/plugins/camboardproc.W64.ppp DESTINATION bin CONFIGURATIONS Release) # INSTALL(FILES ${MITK_PMD_SDK_DIR}/plugins/pmdfile.W32.pcp DESTINATION bin CONFIGURATIONS Release) ENDIf(WIN32) ENDIF(MITK_USE_TOF_PMDCAMBOARD) #End PMD CamBoard Hardware #Begin MESA SR4000 hardware OPTION(MITK_USE_TOF_MESASR4000 "Enable support for MESA SR4000" OFF) # only if MESA SR4000 is enabled IF(MITK_USE_TOF_MESASR4000) FIND_LIBRARY(MITK_MESA_LIB libMesaSR DOC "MESA access library.") GET_FILENAME_COMPONENT(MITK_MESA_SDK_DIR ${MITK_MESA_LIB} PATH) SET(MITK_MESA_SDK_DIR ${MITK_MESA_SDK_DIR}/..) FIND_PATH(MITK_MESA_INCLUDE_DIR libMesaSR.h ${MITK_MESA_SDK_DIR}/include DOC "Include directory of MESA-SDK.") SET(MITK_TOF_AVAILABLE_CAMERAS ${MITK_TOF_AVAILABLE_CAMERAS},MESA Swissranger 4000) IF(WIN32) INSTALL(FILES ${MITK_MESA_SDK_DIR}/bin/libMesaSR.dll DESTINATION bin CONFIGURATIONS Release) ENDIf(WIN32) ENDIF(MITK_USE_TOF_MESASR4000) #End MESA SR4000 Hardware IF (WIN32) #Begin PMD O3 hardware OPTION(MITK_USE_TOF_PMDO3 "Enable support for PMD O3 camera" OFF) # only if PMD O3 is enabled IF(MITK_USE_TOF_PMDO3) FIND_LIBRARY(MITK_PMD_LIB pmdaccess2 DOC "PMD access library.") GET_FILENAME_COMPONENT(MITK_PMD_SDK_DIR ${MITK_PMD_LIB} PATH) SET(MITK_PMD_SDK_DIR ${MITK_PMD_SDK_DIR}/..) FIND_PATH(MITK_PMD_INCLUDE_DIR pmdsdk2.h ${MITK_PMD_SDK_DIR}/include DOC "Include directory of PMD-SDK.") SET(MITK_TOF_PMD_O3D_SOURCE ${MITK_PMD_SDK_DIR}/plugins/o3d.${_PLATFORM_STRING}.pcp) SET(MITK_TOF_PMD_O3D_PROC ${MITK_PMD_SDK_DIR}/plugins/o3d.${_PLATFORM_STRING}.pcp) SET(MITK_TOF_AVAILABLE_CAMERAS ${MITK_TOF_AVAILABLE_CAMERAS},PMD O3D) # FILE(GLOB MITK_TOF_PMD_O3D_SOURCE o3d.${_PLATFORM_STRING}.pcp) # FILE(GLOB MITK_TOF_PMD_O3D_PROC o3d.${_PLATFORM_STRING}.pcp) MITK_INSTALL(FILES ${MITK_PMD_SDK_DIR}/bin/pmdaccess2.dll CONFIGURATIONS Release) MITK_INSTALL(FILES ${MITK_PMD_SDK_DIR}/plugins/o3d.W32.pcp CONFIGURATIONS Release) ENDIF(MITK_USE_TOF_PMDO3) #End PMD O3 Hardware ENDIF(WIN32) ENDIF(MITK_ENABLE_TOF_HARDWARE) CONFIGURE_FILE(mitkToFConfig.h.in ${PROJECT_BINARY_DIR}/mitkToFConfig.h @ONLY) diff --git a/Modules/ToFHardware/mitkToFImageGrabberCreator.cpp b/Modules/ToFHardware/mitkToFImageGrabberCreator.cpp index 516f58cd49..30ef5c7f5d 100644 --- a/Modules/ToFHardware/mitkToFImageGrabberCreator.cpp +++ b/Modules/ToFHardware/mitkToFImageGrabberCreator.cpp @@ -1,100 +1,108 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit Module: $RCSfile$ Language: C++ Date: $Date: 2010-05-27 16:06:53 +0200 (Do, 27 Mai 2010) $ Version: $Revision: $ Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notices for more information. =========================================================================*/ #include "mitkToFImageGrabberCreator.h" #include "mitkToFImageGrabber.h" #include "mitkToFCameraPMDCamCubeDevice.h" +#include "mitkToFCameraPMDRawDataCamCubeDevice.h" #include "mitkToFCameraPMDCamBoardDevice.h" #include "mitkToFCameraPMDO3Device.h" #include "mitkToFCameraPMDPlayerDevice.h" #include "mitkToFCameraPMDMITKPlayerDevice.h" #include "mitkToFCameraMITKPlayerDevice.h" #include "mitkToFCameraMESASR4000Device.h" namespace mitk { ToFImageGrabberCreator::Pointer ToFImageGrabberCreator::s_Instance = NULL; ToFImageGrabberCreator::ToFImageGrabberCreator() { m_ToFImageGrabber = mitk::ToFImageGrabber::New(); } ToFImageGrabberCreator::~ToFImageGrabberCreator() { } ToFImageGrabberCreator* ToFImageGrabberCreator::GetInstance() { if ( !ToFImageGrabberCreator::s_Instance ) { s_Instance = ToFImageGrabberCreator::New(); } return s_Instance; } ToFImageGrabber::Pointer ToFImageGrabberCreator::GetPMDCamCubeImageGrabber() { m_ToFCameraDevice = mitk::ToFCameraPMDCamCubeDevice::New(); m_ToFImageGrabber->SetCameraDevice(m_ToFCameraDevice); return m_ToFImageGrabber; } + ToFImageGrabber::Pointer ToFImageGrabberCreator::GetPMDRawDataCamCubeImageGrabber() + { + m_ToFCameraDevice = mitk::ToFCameraPMDRawDataCamCubeDevice::New(); + m_ToFImageGrabber->SetCameraDevice(m_ToFCameraDevice); + return m_ToFImageGrabber; + } + ToFImageGrabber::Pointer ToFImageGrabberCreator::GetPMDO3ImageGrabber() { m_ToFCameraDevice = mitk::ToFCameraPMDO3Device::New(); m_ToFImageGrabber->SetCameraDevice(m_ToFCameraDevice); return m_ToFImageGrabber; } ToFImageGrabber::Pointer ToFImageGrabberCreator::GetPMDCamBoardImageGrabber() { m_ToFCameraDevice = mitk::ToFCameraPMDCamBoardDevice::New(); m_ToFImageGrabber->SetCameraDevice(m_ToFCameraDevice); return m_ToFImageGrabber; } ToFImageGrabber::Pointer ToFImageGrabberCreator::GetPMDPlayerImageGrabber() { m_ToFCameraDevice = mitk::ToFCameraPMDPlayerDevice::New(); m_ToFImageGrabber->SetCameraDevice(m_ToFCameraDevice); return m_ToFImageGrabber; } ToFImageGrabber::Pointer ToFImageGrabberCreator::GetPMDMITKPlayerImageGrabber() { m_ToFCameraDevice = mitk::ToFCameraPMDMITKPlayerDevice::New(); m_ToFImageGrabber->SetCameraDevice(m_ToFCameraDevice); return m_ToFImageGrabber; } ToFImageGrabber::Pointer ToFImageGrabberCreator::GetMITKPlayerImageGrabber() { m_ToFCameraDevice = mitk::ToFCameraMITKPlayerDevice::New(); m_ToFImageGrabber->SetCameraDevice(m_ToFCameraDevice); return m_ToFImageGrabber; } ToFImageGrabber::Pointer ToFImageGrabberCreator::GetMESASR4000ImageGrabber() { m_ToFCameraDevice = mitk::ToFCameraMESASR4000Device::New(); m_ToFImageGrabber->SetCameraDevice(m_ToFCameraDevice); return m_ToFImageGrabber; } } diff --git a/Modules/ToFHardware/mitkToFImageGrabberCreator.h b/Modules/ToFHardware/mitkToFImageGrabberCreator.h index 35d965d6bf..12c49bc62b 100644 --- a/Modules/ToFHardware/mitkToFImageGrabberCreator.h +++ b/Modules/ToFHardware/mitkToFImageGrabberCreator.h @@ -1,105 +1,109 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit Module: $RCSfile$ Language: C++ Date: $Date: 2010-05-27 16:06:53 +0200 (Do, 27 Mai 2010) $ Version: $Revision: $ Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notices for more information. =========================================================================*/ #ifndef __mitkToFImageGrabberCreator_h #define __mitkToFImageGrabberCreator_h #include "mitkToFHardwareExports.h" #include "mitkCommon.h" #include "mitkToFImageGrabber.h" #include "mitkToFCameraDevice.h" #include "itkObject.h" #include "itkObjectFactory.h" namespace mitk { /** * @brief Class providing ready-to-use instances of ToFImageGrabbers * This singleton can be used to create ToFImageGrabber objects of * the supported ToF cameras. The ImageGrabbers are already initialized * with the correct device object. * When new hardware is added to MITK-ToF they should also be included in * this creator class. * * @ingroup ToFHardware */ class MITK_TOFHARDWARE_EXPORT ToFImageGrabberCreator : public itk::Object { public: mitkClassMacro( ToFImageGrabberCreator , itk::Object ); itkNewMacro( Self ); /*! \brief Get the RenderingManager singleton instance. */ static ToFImageGrabberCreator* GetInstance(); /*! \brief Create a ImageGrabber object with a PMD CamCube Camera */ ToFImageGrabber::Pointer GetPMDCamCubeImageGrabber(); + + /*! + \brief Create a ImageGrabber object with a PMD raw data CamCube Camera + */ + ToFImageGrabber::Pointer GetPMDRawDataCamCubeImageGrabber(); /*! \brief Create a ImageGrabber object with a PMD O3 Camera */ ToFImageGrabber::Pointer GetPMDO3ImageGrabber(); /*! \brief Create a ImageGrabber object with a PMD CamBoard Camera */ ToFImageGrabber::Pointer GetPMDCamBoardImageGrabber(); /*! \brief Create a ImageGrabber object with a PMD Player Camera */ ToFImageGrabber::Pointer GetPMDPlayerImageGrabber(); /*! \brief Create a ImageGrabber object with a PMD MITK Player Camera */ ToFImageGrabber::Pointer GetPMDMITKPlayerImageGrabber(); /*! \brief Create a ImageGrabber object with a MITK Player Camera */ ToFImageGrabber::Pointer GetMITKPlayerImageGrabber(); /*! \brief Create a ImageGrabber object with a MESA SR4000 Camera */ ToFImageGrabber::Pointer GetMESASR4000ImageGrabber(); protected: static ToFImageGrabberCreator::Pointer s_Instance; ///< Instance to the singleton ToFImageGrabberCreator. Can be accessed by GetInstance() ToFCameraDevice::Pointer m_ToFCameraDevice; ///< ToFCameraDevice currently used in the provided ToFImageGrabber ToFImageGrabber::Pointer m_ToFImageGrabber; ///< ToFImageGrabber that will be returned configured with the specific ToFCameraDevice ToFImageGrabberCreator(); ~ToFImageGrabberCreator(); - private: }; } //END mitk namespace #endif diff --git a/Modules/ToFUI/Qmitk/QmitkToFConnectionWidget.cpp b/Modules/ToFUI/Qmitk/QmitkToFConnectionWidget.cpp index f95f3ac3e1..0af3c6e12c 100644 --- a/Modules/ToFUI/Qmitk/QmitkToFConnectionWidget.cpp +++ b/Modules/ToFUI/Qmitk/QmitkToFConnectionWidget.cpp @@ -1,432 +1,436 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit Module: $RCSfile$ Language: C++ Date: $Date: 2009-05-20 13:35:09 +0200 (Mi, 20 Mai 2009) $ Version: $Revision: 17332 $ Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notices for more information. =========================================================================*/ //#define _USE_MATH_DEFINES #include //QT headers #include #include #include //mitk headers #include "mitkToFConfig.h" #include //itk headers #include const std::string QmitkToFConnectionWidget::VIEW_ID = "org.mitk.views.qmitktofconnectionwidget"; QmitkToFConnectionWidget::QmitkToFConnectionWidget(QWidget* parent, Qt::WindowFlags f): QWidget(parent, f) { this->m_IntegrationTime = 0; this->m_ModulationFrequency = 0; this->m_ToFImageGrabber = NULL; m_Controls = NULL; CreateQtPartControl(this); } QmitkToFConnectionWidget::~QmitkToFConnectionWidget() { } void QmitkToFConnectionWidget::CreateQtPartControl(QWidget *parent) { if (!m_Controls) { // create GUI widgets m_Controls = new Ui::QmitkToFConnectionWidgetControls; m_Controls->setupUi(parent); this->CreateConnections(); // set available cameras to combo box QString string(MITK_TOF_CAMERAS); string.replace(";"," "); QStringList list = string.split(","); m_Controls->m_SelectCameraCombobox->addItems(list); ShowParameterWidget(); } } void QmitkToFConnectionWidget::CreateConnections() { if ( m_Controls ) { connect( (QObject*)(m_Controls->m_ConnectCameraButton), SIGNAL(clicked()),(QObject*) this, SLOT(OnConnectCamera()) ); connect( m_Controls->m_SelectCameraCombobox, SIGNAL(currentIndexChanged(const QString)), this, SLOT(OnSelectCamera(const QString)) ); connect( m_Controls->m_SelectCameraCombobox, SIGNAL(activated(const QString)), this, SLOT(OnSelectCamera(const QString)) ); connect( m_Controls->m_SelectCameraCombobox, SIGNAL(activated(const QString)), this, SIGNAL(ToFCameraSelected(const QString)) ); //connect( m_Controls->m_IntegrationTimeSpinBox, SIGNAL(valueChanged(int)), this, SLOT(OnChangeIntegrationTimeSpinBox(int)) ); //connect( m_Controls->m_ModulationFrequencySpinBox, SIGNAL(valueChanged(int)), this, SLOT(OnChangeModulationFrequencySpinBox(int)) ); } } void QmitkToFConnectionWidget::ShowParameterWidget() { QString selectedCamera = m_Controls->m_SelectCameraCombobox->currentText(); if ((selectedCamera == "PMD CamCube 2.0/3.0")||(selectedCamera == "PMD CamBoard")||(selectedCamera=="PMD O3D")) { ShowPMDParameterWidget(); } else if (selectedCamera=="MESA Swissranger 4000") { ShowMESAParameterWidget(); } else { this->m_Controls->m_PMDParameterWidget->hide(); this->m_Controls->m_MESAParameterWidget->hide(); } } void QmitkToFConnectionWidget::ShowPMDParameterWidget() { this->m_Controls->m_PMDParameterWidget->show(); this->m_Controls->m_MESAParameterWidget->hide(); } void QmitkToFConnectionWidget::ShowMESAParameterWidget() { this->m_Controls->m_PMDParameterWidget->hide(); this->m_Controls->m_MESAParameterWidget->show(); } void QmitkToFConnectionWidget::ShowPlayerParameterWidget() { this->m_Controls->m_PMDParameterWidget->hide(); this->m_Controls->m_MESAParameterWidget->hide(); } mitk::ToFImageGrabber* QmitkToFConnectionWidget::GetToFImageGrabber() { return m_ToFImageGrabber; } void QmitkToFConnectionWidget::OnSelectCamera(const QString selectedText) { - if (selectedText == "PMD CamCube 2.0/3.0") // PMD camcube 2 + if (selectedText == "PMD CamCube 2.0/3.0" || selectedText == "PMD CamCubeRaw 2.0/3.0" ) // PMD camcube 2 { //m_Controls->m_IntegrationTimeSpinBox->setEnabled(true); //m_Controls->m_ModulationFrequencySpinBox->setEnabled(true); //m_Controls->m_CalibrationParameterGroupBox->setEnabled(true); ShowPMDParameterWidget(); } else if (selectedText == "PMD CamBoard") // pmd camboard { //m_Controls->m_IntegrationTimeSpinBox->setEnabled(true); //m_Controls->m_ModulationFrequencySpinBox->setEnabled(true); //m_Controls->m_CalibrationParameterGroupBox->setEnabled(false); ShowPMDParameterWidget(); } else if (selectedText == "PMD O3D") // pmd O3d { //m_Controls->m_IntegrationTimeSpinBox->setEnabled(true); //m_Controls->m_ModulationFrequencySpinBox->setEnabled(true); //m_Controls->m_CalibrationParameterGroupBox->setEnabled(false); ShowPMDParameterWidget(); } else if (selectedText == "MESA Swissranger 4000") // MESA 4000 { ShowMESAParameterWidget(); } else if (selectedText == "PMD Player") // pmd file player { //m_Controls->m_IntegrationTimeSpinBox->setEnabled(false); //m_Controls->m_ModulationFrequencySpinBox->setEnabled(false); //m_Controls->m_CalibrationParameterGroupBox->setEnabled(false); ShowPlayerParameterWidget(); } else if (selectedText == "PMD Raw Data Player") // pmd raw data player { //m_Controls->m_IntegrationTimeSpinBox->setEnabled(false); //m_Controls->m_ModulationFrequencySpinBox->setEnabled(false); //m_Controls->m_CalibrationParameterGroupBox->setEnabled(false); ShowPlayerParameterWidget(); } else if (selectedText == "MITK Player") // mitk player { //m_Controls->m_IntegrationTimeSpinBox->setEnabled(false); //m_Controls->m_ModulationFrequencySpinBox->setEnabled(false); //m_Controls->m_CalibrationParameterGroupBox->setEnabled(false); ShowPlayerParameterWidget(); } } void QmitkToFConnectionWidget::OnConnectCamera() { bool playerMode = false; if (m_Controls->m_ConnectCameraButton->text()=="Connect") { //reset the status of the GUI buttons m_Controls->m_ConnectCameraButton->setEnabled(false); m_Controls->m_SelectCameraCombobox->setEnabled(false); // m_Controls->m_CalibrationParameterGroupBox->setEnabled(false); //repaint the widget this->repaint(); QString tmpFileName(""); QString fileFilter(""); //select the camera to connect with QString selectedCamera = m_Controls->m_SelectCameraCombobox->currentText(); if (selectedCamera == "PMD CamCube 2.0/3.0") { //PMD CamCube this->m_ToFImageGrabber = mitk::ToFImageGrabberCreator::GetInstance()->GetPMDCamCubeImageGrabber(); } + else if (selectedCamera == "PMD CamCubeRaw 2.0/3.0") + { //PMD CamCube + this->m_ToFImageGrabber = mitk::ToFImageGrabberCreator::GetInstance()->GetPMDRawDataCamCubeImageGrabber(); + } else if (selectedCamera == "PMD CamBoard") { //PMD CamBoard this->m_ToFImageGrabber = mitk::ToFImageGrabberCreator::GetInstance()->GetPMDCamBoardImageGrabber(); } else if (selectedCamera == "PMD O3D") {//PMD O3 this->m_ToFImageGrabber = mitk::ToFImageGrabberCreator::GetInstance()->GetPMDO3ImageGrabber(); } else if (selectedCamera == "MESA Swissranger 4000") {//MESA SR4000 this->m_ToFImageGrabber = mitk::ToFImageGrabberCreator::GetInstance()->GetMESASR4000ImageGrabber(); } else if (selectedCamera == "PMD Player") {//PMD player playerMode = true; fileFilter.append("PMD Files (*.pmd)"); this->m_ToFImageGrabber = mitk::ToFImageGrabberCreator::GetInstance()->GetPMDPlayerImageGrabber(); } else if (selectedCamera == "PMD Raw Data Player") {//PMD MITK player playerMode = true; fileFilter.append("MITK Images (*.pic)"); this->m_ToFImageGrabber = mitk::ToFImageGrabberCreator::GetInstance()->GetPMDMITKPlayerImageGrabber(); } else if (selectedCamera == "MITK Player") {//MITK player playerMode = true; fileFilter.append("MITK Images (*.pic)"); this->m_ToFImageGrabber = mitk::ToFImageGrabberCreator::GetInstance()->GetMITKPlayerImageGrabber(); } // if a player was selected ... if (playerMode) { //... open a QFileDialog to chose the corresponding file from the disc tmpFileName = QFileDialog::getOpenFileName(NULL, "Play Image From...", "", fileFilter); if (tmpFileName.isEmpty()) { m_Controls->m_ConnectCameraButton->setChecked(false); m_Controls->m_ConnectCameraButton->setEnabled(true); m_Controls->m_SelectCameraCombobox->setEnabled(true); // m_Controls->m_CalibrationParameterGroupBox->setEnabled(true); OnSelectCamera(m_Controls->m_SelectCameraCombobox->currentText()); QMessageBox::information( this, "Template functionality", "Please select a valid image before starting some action."); return; } if(selectedCamera == "PMD Player") { //set the PMD file name this->m_ToFImageGrabber->SetStringProperty("PMDFileName", tmpFileName.toStdString().c_str() ); } if (selectedCamera == "PMD Raw Data Player" || selectedCamera == "MITK Player") { std::string msg = ""; try { //get 3 corresponding file names std::string dir = itksys::SystemTools::GetFilenamePath( tmpFileName.toStdString() ); std::string baseFilename = itksys::SystemTools::GetFilenameWithoutLastExtension( tmpFileName.toStdString() ); std::string extension = itksys::SystemTools::GetFilenameLastExtension( tmpFileName.toStdString() ); if (extension != ".pic") { msg = msg + "Invalid file format, please select a \".pic\"-file"; throw std::logic_error(msg.c_str()); } int found = baseFilename.rfind("_DistanceImage"); if (found == std::string::npos) { found = baseFilename.rfind("_AmplitudeImage"); } if (found == std::string::npos) { found = baseFilename.rfind("_IntensityImage"); } if (found == std::string::npos) { msg = msg + "Input file name must end with \"_DistanceImage.pic\", \"_AmplitudeImage.pic\" or \"_IntensityImage.pic\"!"; throw std::logic_error(msg.c_str()); } std::string baseFilenamePrefix = baseFilename.substr(0,found); std::string distanceImageFileName = dir + "/" + baseFilenamePrefix + "_DistanceImage" + extension; std::string amplitudeImageFileName = dir + "/" + baseFilenamePrefix + "_AmplitudeImage" + extension; std::string intensityImageFileName = dir + "/" + baseFilenamePrefix + "_IntensityImage" + extension; if (!itksys::SystemTools::FileExists(distanceImageFileName.c_str(), true)) { msg = msg + "Inputfile not exist! " + distanceImageFileName; throw std::logic_error(msg.c_str()); } if (!itksys::SystemTools::FileExists(amplitudeImageFileName.c_str(), true)) { msg = msg + "Inputfile not exist! " + amplitudeImageFileName; throw std::logic_error(msg.c_str()); } if (!itksys::SystemTools::FileExists(intensityImageFileName.c_str(), true)) { msg = msg + "Inputfile not exist! " + intensityImageFileName; throw std::logic_error(msg.c_str()); } //set the file names this->m_ToFImageGrabber->SetStringProperty("DistanceImageFileName", distanceImageFileName.c_str()); this->m_ToFImageGrabber->SetStringProperty("AmplitudeImageFileName", amplitudeImageFileName.c_str()); this->m_ToFImageGrabber->SetStringProperty("IntensityImageFileName", intensityImageFileName.c_str()); } catch (std::exception &e) { MITK_ERROR << e.what(); QMessageBox::critical( this, "Error", e.what() ); m_Controls->m_ConnectCameraButton->setChecked(false); m_Controls->m_ConnectCameraButton->setEnabled(true); m_Controls->m_SelectCameraCombobox->setEnabled(true); // m_Controls->m_CalibrationParameterGroupBox->setEnabled(true); OnSelectCamera(m_Controls->m_SelectCameraCombobox->currentText()); return; } } } //if a connection could be established if (this->m_ToFImageGrabber->ConnectCamera()) { this->m_Controls->m_PMDParameterWidget->SetToFImageGrabber(this->m_ToFImageGrabber); this->m_Controls->m_MESAParameterWidget->SetToFImageGrabber(this->m_ToFImageGrabber); if ((selectedCamera == "PMD CamCube 2.0/3.0")||(selectedCamera == "PMD CamBoard")||(selectedCamera=="PMD O3D")) { this->m_Controls->m_PMDParameterWidget->ActivateAllParameters(); } else if (selectedCamera=="MESA Swissranger 4000") { this->m_Controls->m_MESAParameterWidget->ActivateAllParameters(); } /* //get the integration time and modulation frequency this->m_IntegrationTime = m_Controls->m_IntegrationTimeSpinBox->value(); this->m_ModulationFrequency = m_Controls->m_ModulationFrequencySpinBox->value(); //set the integration time and modulation frequency in the grabber this->m_IntegrationTime = this->m_ToFImageGrabber->SetIntegrationTime(this->m_IntegrationTime); this->m_ModulationFrequency = this->m_ToFImageGrabber->SetModulationFrequency(this->m_ModulationFrequency); //set the PMD calibration according to the check boxes bool boolValue = false; boolValue = m_Controls->m_FPNCalibCB->isChecked(); this->m_ToFImageGrabber->SetBoolProperty("SetFPNCalibration", boolValue); boolValue = m_Controls->m_FPPNCalibCB->isChecked(); this->m_ToFImageGrabber->SetBoolProperty("SetFPPNCalibration", boolValue); boolValue = m_Controls->m_LinearityCalibCB->isChecked(); this->m_ToFImageGrabber->SetBoolProperty("SetLinearityCalibration", boolValue); boolValue = m_Controls->m_LensCorrection->isChecked(); this->m_ToFImageGrabber->SetBoolProperty("SetLensCalibration", boolValue); boolValue = m_Controls->m_ExposureModeCB->isChecked(); this->m_ToFImageGrabber->SetBoolProperty("SetExposureMode", boolValue); //reset the GUI elements m_Controls->m_IntegrationTimeSpinBox->setValue(this->m_IntegrationTime); m_Controls->m_ModulationFrequencySpinBox->setValue(this->m_ModulationFrequency); */ m_Controls->m_ConnectCameraButton->setText("Disconnect"); // send connect signal to the caller functionality emit ToFCameraConnected(); } else { QMessageBox::critical( this, "Error", "Connection failed. Check if you have installed the latest driver for your system." ); m_Controls->m_ConnectCameraButton->setChecked(false); m_Controls->m_ConnectCameraButton->setEnabled(true); m_Controls->m_SelectCameraCombobox->setEnabled(true); // m_Controls->m_CalibrationParameterGroupBox->setEnabled(true); OnSelectCamera(m_Controls->m_SelectCameraCombobox->currentText()); return; } m_Controls->m_ConnectCameraButton->setEnabled(true); } else if (m_Controls->m_ConnectCameraButton->text()=="Disconnect") { //send camera stop to the caller functionality emit ToFCameraStop(); this->m_ToFImageGrabber->StopCamera(); this->m_ToFImageGrabber->DisconnectCamera(); m_Controls->m_ConnectCameraButton->setText("Connect"); m_Controls->m_SelectCameraCombobox->setEnabled(true); // m_Controls->m_CalibrationParameterGroupBox->setEnabled(true); OnSelectCamera(m_Controls->m_SelectCameraCombobox->currentText()); this->m_ToFImageGrabber = NULL; // send disconnect signal to the caller functionality emit ToFCameraDisconnected(); } } /* void QmitkToFConnectionWidget::OnChangeIntegrationTimeSpinBox(int value) { if (this->m_ToFImageGrabber != NULL) { // stop camera if active bool active = m_ToFImageGrabber->IsCameraActive(); if (active) { m_ToFImageGrabber->StopCamera(); } this->m_IntegrationTime = m_Controls->m_IntegrationTimeSpinBox->value(); this->m_IntegrationTime = this->m_ToFImageGrabber->SetIntegrationTime(this->m_IntegrationTime); if (active) { m_ToFImageGrabber->StartCamera(); } } } void QmitkToFConnectionWidget::OnChangeModulationFrequencySpinBox(int value) { if (this->m_ToFImageGrabber != NULL) { // stop camera if active bool active = m_ToFImageGrabber->IsCameraActive(); if (active) { m_ToFImageGrabber->StopCamera(); } this->m_ModulationFrequency = m_Controls->m_ModulationFrequencySpinBox->value(); this->m_ModulationFrequency = this->m_ToFImageGrabber->SetModulationFrequency(this->m_ModulationFrequency); if (active) { m_ToFImageGrabber->StartCamera(); } } } */