diff --git a/Modules/Bundles/org.mitk.gui.qt.tofutil/src/internal/QmitkToFUtilView.cpp b/Modules/Bundles/org.mitk.gui.qt.tofutil/src/internal/QmitkToFUtilView.cpp index 15132b5cfe..45dd34823e 100644 --- a/Modules/Bundles/org.mitk.gui.qt.tofutil/src/internal/QmitkToFUtilView.cpp +++ b/Modules/Bundles/org.mitk.gui.qt.tofutil/src/internal/QmitkToFUtilView.cpp @@ -1,974 +1,514 @@ /*========================================================================= 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. =========================================================================*/ // Qmitk #include "QmitkToFUtilView.h" #include +#include // Qt #include #include // MITK #include -#include -#include -#include -#include -#include +#include +#include +#include +#include // VTK #include +// ITK +#include + const std::string QmitkToFUtilView::VIEW_ID = "org.mitk.views.tofutil"; QmitkToFUtilView::QmitkToFUtilView() : QmitkFunctionality() -, m_Controls(NULL) -, m_MultiWidget( NULL ) -, m_DistanceImageNode(NULL) -, m_AmplitudeImageNode(NULL) -, m_IntensityImageNode(NULL) -, m_SurfaceNode(NULL) -, m_QmitkVideoBackground(NULL) -, m_QmitkToFImageBackground1(NULL) -, m_QmitkToFImageBackground2(NULL) -, m_QmitkToFImageBackground3(NULL) +, m_Controls(NULL), m_MultiWidget( NULL ) +, m_MitkDistanceImage(NULL), m_MitkAmplitudeImage(NULL), m_MitkIntensityImage(NULL), m_Surface(NULL) +, m_DistanceImageNode(NULL), m_AmplitudeImageNode(NULL), m_IntensityImageNode(NULL), m_SurfaceNode(NULL) +, m_ToFImageRecorder(NULL), m_ToFImageGrabber(NULL), m_ToFDistanceImageToSurfaceFilter(NULL), m_ToFCompositeFilter(NULL) +, m_SurfaceDisplayCount(0), m_2DDisplayCount(0) +, m_RealTimeClock(NULL) +, m_StepsForFramerate(100) +, m_2DTimeBefore(0.0) +, m_2DTimeAfter(0.0) +, m_VideoEnabled(false) { - //this->m_FrameRate = 0; this->m_Frametimer = new QTimer(this); - this->m_MitkDistanceImage = mitk::Image::New(); - this->m_MitkAmplitudeImage = mitk::Image::New(); - this->m_MitkIntensityImage = mitk::Image::New(); - this->m_MitkAllImage = mitk::Image::New(); - this->m_MitkRawImage = mitk::Image::New(); - this->m_SurfaceInputImage = mitk::Image::New(); - this->m_SurfaceTextureImage = mitk::Image::New(); - this->m_SurfaceIntensityImage = mitk::Image::New(); - this->m_Surface = mitk::Surface::New(); - -// this->m_ToFSurfaceGenerationFilter = mitk::ToFSurfaceGenerationFilter::New(); this->m_ToFDistanceImageToSurfaceFilter = mitk::ToFDistanceImageToSurfaceFilter::New(); - - - this->m_ToFImageGrabber = NULL; + this->m_ToFCompositeFilter = mitk::ToFCompositeFilter::New(); this->m_ToFImageRecorder = mitk::ToFImageRecorder::New(); - - this->m_DataNodesInitilized = false; - this->m_TransferFunctionInitialized = false; - this->m_SurfaceInitialized = false; - this->m_ImageSequence = 0; - - //this->m_DistLut = vtkLookupTable::New(); - //this->m_AmplLut = vtkLookupTable::New(); - //this->m_IntenLut = vtkLookupTable::New(); - //PrepareColorLut(this->m_DistLut, 300.0, 1000.0); - //PrepareBinaryLut(this->m_AmplLut, 0.0, 100.0); - //PrepareBinaryLut(this->m_IntenLut, 0.0, 100.0); - - this->m_DataBuffer = NULL; - this->m_DataBufferCurrentIndex = 0; - this->m_DataBufferMaxSize = 0; - this->m_IndexBuffer = NULL; - this->m_VideoEnabled = false; - this->m_ToFSurfaceVtkMapper3D = mitk::ToFSurfaceVtkMapper3D::New(); - - this->m_ToFCompositeFilter = mitk::ToFCompositeFilter::New(); - this->m_ToFVisualizationFilter = mitk::ToFVisualizationFilter::New(); } QmitkToFUtilView::~QmitkToFUtilView() { - // remove nodes - RemoveNode("ToF_Distance", this->m_DistanceImageNode); - RemoveNode("ToF_Amplitude", this->m_AmplitudeImageNode); - RemoveNode("ToF_Intensity", this->m_IntensityImageNode); - RemoveNode("ToF_Surface", this->m_SurfaceNode); - //RemoveBackground(); + OnToFCameraStopped(); + OnToFCameraDisconnected(); } -void QmitkToFUtilView::RemoveNode(const char* nodename, mitk::DataNode::Pointer node) -{ - if(this->GetDataStorage()->GetNamedNode(nodename) != NULL) - { - this->GetDataStorage()->Remove(node); - } -} - -void QmitkToFUtilView::CreateNode(const char* nodename, mitk::DataNode::Pointer& node) -{ - node = mitk::DataNode::New(); - node->SetProperty( "name", mitk::StringProperty::New(nodename)); -} - - void QmitkToFUtilView::CreateQtPartControl( QWidget *parent ) { // build up qt view, unless already done if ( !m_Controls ) { // create GUI widgets from the Qt Designer's .ui file m_Controls = new Ui::QmitkToFUtilViewControls; m_Controls->setupUi( parent ); connect(m_Frametimer, SIGNAL(timeout()), this, SLOT(OnUpdateCamera())); connect( (QObject*)(m_Controls->m_ToFConnectionWidget), SIGNAL(ToFCameraConnected()), this, SLOT(OnToFCameraConnected()) ); connect( (QObject*)(m_Controls->m_ToFConnectionWidget), SIGNAL(ToFCameraDisconnected()), this, SLOT(OnToFCameraDisconnected()) ); - connect( (QObject*)(m_Controls->m_ToFConnectionWidget), SIGNAL(ToFCameraStop()), this, SLOT(OnToFCameraStop()) ); connect( (QObject*)(m_Controls->m_ToFConnectionWidget), SIGNAL(ToFCameraSelected(const QString)), this, SLOT(OnToFCameraSelected(const QString)) ); connect( (QObject*)(m_Controls->m_ToFRecorderWidget), SIGNAL(ToFCameraStarted()), this, SLOT(OnToFCameraStarted()) ); connect( (QObject*)(m_Controls->m_ToFRecorderWidget), SIGNAL(ToFCameraStopped()), this, SLOT(OnToFCameraStopped()) ); - connect( (QObject*)(m_Controls->m_SurfaceCheckBox), SIGNAL(toggled(bool)), this, SLOT(OnSurfaceCheckBoxChecked(bool)) ); connect( (QObject*)(m_Controls->m_TextureCheckBox), SIGNAL(toggled(bool)), this, SLOT(OnTextureCheckBoxChecked(bool)) ); connect( (QObject*)(m_Controls->m_VideoTextureCheckBox), SIGNAL(toggled(bool)), this, SLOT(OnVideoTextureCheckBoxChecked(bool)) ); } } void QmitkToFUtilView::StdMultiWidgetAvailable (QmitkStdMultiWidget &stdMultiWidget) { m_MultiWidget = &stdMultiWidget; } void QmitkToFUtilView::StdMultiWidgetNotAvailable() { m_MultiWidget = NULL; } void QmitkToFUtilView::Activated() { QmitkFunctionality::Activated(); - // add necessary nodes - CreateNode("ToF_Distance", this->m_DistanceImageNode); - CreateNode("ToF_Amplitude", this->m_AmplitudeImageNode); - CreateNode("ToF_Intensity", this->m_IntensityImageNode); - CreateNode("ToF_Surface", this->m_SurfaceNode); // configure views m_MultiWidget->SetWidgetPlanesVisibility(false); m_MultiWidget->mitkWidget1->GetSliceNavigationController()->SetDefaultViewDirection(mitk::SliceNavigationController::Transversal); m_MultiWidget->mitkWidget1->GetSliceNavigationController()->SliceLockedOn(); m_MultiWidget->mitkWidget2->GetSliceNavigationController()->SetDefaultViewDirection(mitk::SliceNavigationController::Transversal); m_MultiWidget->mitkWidget2->GetSliceNavigationController()->SliceLockedOn(); m_MultiWidget->mitkWidget3->GetSliceNavigationController()->SetDefaultViewDirection(mitk::SliceNavigationController::Transversal); m_MultiWidget->mitkWidget3->GetSliceNavigationController()->SliceLockedOn(); - //m_Controls->m_ToFImageConverterWidget->Initialize(this->GetDefaultDataStorage(), m_MultiWidget); - m_Controls->m_ToFVisualisationSettingsWidget->Initialize(this->GetDefaultDataStorage(), m_MultiWidget); - m_Controls->m_ToFVisualisationSettingsWidget->SetParameter(this->m_ToFVisualizationFilter); + this->UseToFVisibilitySettings(true); m_Controls->m_ToFCompositeFilterWidget->SetToFCompositeFilter(this->m_ToFCompositeFilter); - if (this->m_ToFImageGrabber == NULL) + if (this->m_ToFImageGrabber.IsNull()) { m_Controls->m_ToFRecorderWidget->setEnabled(false); m_Controls->m_ToFVisualisationSettingsWidget->setEnabled(false); } } void QmitkToFUtilView::Deactivated() { m_MultiWidget->SetWidgetPlanesVisibility(true); m_MultiWidget->mitkWidget1->GetSliceNavigationController()->SetDefaultViewDirection(mitk::SliceNavigationController::Transversal); m_MultiWidget->mitkWidget1->GetSliceNavigationController()->SliceLockedOff(); m_MultiWidget->mitkWidget2->GetSliceNavigationController()->SetDefaultViewDirection(mitk::SliceNavigationController::Sagittal); m_MultiWidget->mitkWidget2->GetSliceNavigationController()->SliceLockedOff(); m_MultiWidget->mitkWidget3->GetSliceNavigationController()->SetDefaultViewDirection(mitk::SliceNavigationController::Frontal); m_MultiWidget->mitkWidget3->GetSliceNavigationController()->SliceLockedOff(); + this->UseToFVisibilitySettings(false); + mitk::RenderingManager::GetInstance()->InitializeViews(); mitk::RenderingManager::GetInstance()->ForceImmediateUpdateAll(); - RemoveBackground(); QmitkFunctionality::Deactivated(); } void QmitkToFUtilView::OnToFCameraConnected() { - RemoveNode("ToF_Distance", this->m_DistanceImageNode); - RemoveNode("ToF_Amplitude", this->m_AmplitudeImageNode); - RemoveNode("ToF_Intensity", this->m_IntensityImageNode); - RemoveNode("ToF_Surface", this->m_SurfaceNode); - - CreateNode("ToF_Distance", this->m_DistanceImageNode); - CreateNode("ToF_Amplitude", this->m_AmplitudeImageNode); - CreateNode("ToF_Intensity", this->m_IntensityImageNode); - CreateNode("ToF_Surface", this->m_SurfaceNode); - - this->m_DistanceImageNode->SetData( NULL ); - this->m_AmplitudeImageNode->SetData( NULL ); - this->m_IntensityImageNode->SetData( NULL ); - this->m_SurfaceNode->SetData( NULL ); - - this->m_DataNodesInitilized = false; - this->m_TransferFunctionInitialized = false; - this->m_SurfaceInitialized = false; - this->m_ImageSequence = 0; - - //this->m_ToFImageGrabber = dynamic_cast(m_Controls->m_ToFConnectionWidget->GetToFImageGrabber()); - this->m_ToFImageGrabber = m_Controls->m_ToFConnectionWidget->GetToFImageGrabber(); - this->m_ToFCaptureWidth = this->m_ToFImageGrabber->GetCaptureWidth(); - this->m_ToFCaptureHeight = this->m_ToFImageGrabber->GetCaptureHeight(); - - this->m_ToFImageRecorder->SetCameraDevice(this->m_ToFImageGrabber->GetCameraDevice()); - - //this->m_MitkDistanceImage->ReleaseData(); - //this->m_MitkAmplitudeImage->ReleaseData(); - //this->m_MitkIntensityImage->ReleaseData(); - //this->m_MitkAllImage->ReleaseData(); - this->m_MitkDistanceImage = mitk::Image::New(); - this->m_MitkAmplitudeImage = mitk::Image::New(); - this->m_MitkIntensityImage = mitk::Image::New(); - this->m_MitkAllImage = mitk::Image::New(); - - InitImage(this->m_MitkDistanceImage, 1); - InitImage(this->m_MitkAmplitudeImage, 1); - InitImage(this->m_MitkIntensityImage, 1); - InitImage(this->m_MitkAllImage, 3); - - InitImage(this->m_SurfaceInputImage, 1); - InitImage(this->m_SurfaceIntensityImage, 1); - this->m_SurfaceDisplayCount = 0; this->m_2DDisplayCount = 0; + this->m_ToFImageGrabber = m_Controls->m_ToFConnectionWidget->GetToFImageGrabber(); - this->m_IplDistanceImage = cvCreateImageHeader(cvSize(this->m_ToFCaptureWidth, this->m_ToFCaptureHeight), IPL_DEPTH_32F, 1); // no allocation - this->m_IplIntensityImage = cvCreateImageHeader(cvSize(this->m_ToFCaptureWidth, this->m_ToFCaptureHeight), IPL_DEPTH_32F, 1); // no allocation - this->m_OutputIplImage = cvCreateImage(cvSize(this->m_ToFCaptureWidth, this->m_ToFCaptureHeight), IPL_DEPTH_32F, 1); - - this->m_ItkInputImage = ItkImageType2D::New(); - ItkImageType2D::IndexType startIndex; - startIndex[0] = 0; // first index on X - startIndex[1] = 0; // first index on Y - ItkImageType2D::SizeType size; - size[0] = this->m_ToFCaptureWidth; // size along X - size[1] = this->m_ToFCaptureHeight; // size along Y - ItkImageType2D::RegionType region; - region.SetSize( size ); - region.SetIndex( startIndex ); - this->m_ItkInputImage->SetRegions( region ); - this->m_ItkInputImage->Allocate(); - - if ( this->m_SurfaceNode.IsNotNull() ) - { - this->m_SurfaceNode->SetProperty( "visible" , mitk::BoolProperty::New( true )); - this->m_SurfaceNode->SetVisibility( false, mitk::BaseRenderer::GetInstance(GetActiveStdMultiWidget()->mitkWidget1->GetRenderWindow() ) ); - this->m_SurfaceNode->SetVisibility( false, mitk::BaseRenderer::GetInstance(GetActiveStdMultiWidget()->mitkWidget2->GetRenderWindow() ) ); - this->m_SurfaceNode->SetVisibility( false, mitk::BaseRenderer::GetInstance(GetActiveStdMultiWidget()->mitkWidget3->GetRenderWindow() ) ); - this->m_SurfaceNode->SetProperty( "inRenWin4" , mitk::BoolProperty::New( true )); - this->m_SurfaceNode->SetProperty( "material.representation", mitk::VtkRepresentationProperty::New("Surface")); - this->m_SurfaceNode->SetIntProperty("layer", 10); - this->m_SurfaceNode->SetBoolProperty("scalar visibility", false); - this->m_SurfaceNode->SetFloatProperty("ScalarsRangeMaximum", 20000); - this->m_SurfaceNode->SetFloatProperty("color_coefficient", 0); - this->m_SurfaceNode->SetBoolProperty("color mode", true); - - this->m_SurfaceNode->SetData(mitk::Surface::New()); - this->m_SurfaceNode->SetMapper(mitk::BaseRenderer::Standard3D, this->m_ToFSurfaceVtkMapper3D); - this->GetDefaultDataStorage()->Add( this->m_SurfaceNode ); - } - if(this->GetDataStorage()->GetNamedNode("ToF_Distance") == NULL) - { - this->m_DistanceImageNode->SetProperty( "visible" , mitk::BoolProperty::New( true )); - this->m_DistanceImageNode->SetVisibility( false, mitk::BaseRenderer::GetInstance(GetActiveStdMultiWidget()->mitkWidget1->GetRenderWindow() ) ); - this->m_DistanceImageNode->SetVisibility( false, mitk::BaseRenderer::GetInstance(GetActiveStdMultiWidget()->mitkWidget3->GetRenderWindow() ) ); - this->m_DistanceImageNode->SetVisibility( false, mitk::BaseRenderer::GetInstance(GetActiveStdMultiWidget()->mitkWidget4->GetRenderWindow() ) ); - this->m_DistanceImageNode->SetProperty( "inRenWin2" , mitk::BoolProperty::New( true )); - //m_DistanceImageNode->SetProperty( "use color", mitk::BoolProperty::New( false )); - this->m_DistanceImageNode->SetProperty( "use color", mitk::BoolProperty::New( true )); - this->m_DistanceImageNode->SetProperty( "binary", mitk::BoolProperty::New( false )); - //m_DistanceImageNode->SetIntProperty( "layer", 10); - //this->m_DistanceImageNode->SetData( this->m_MitkDistanceImage ); - - mitk::Image::Pointer myImage = mitk::Image::New(); - unsigned int dimensions[2]; - dimensions[0] = this->m_ToFImageGrabber->GetCaptureWidth(); - dimensions[1] = this->m_ToFImageGrabber->GetCaptureHeight(); - myImage->Initialize(mitk::PixelType(mitkIpPicUInt, 24, 3), 2, dimensions); //unsigned char RGB - - this->m_DistanceImageNode->SetData( myImage ); - this->GetDataStorage()->Add( this->m_DistanceImageNode ); - } - - m_Controls->m_ToFRecorderWidget->SetParameter(dynamic_cast(this->m_ToFImageGrabber), this->m_ToFImageRecorder); - + this->m_ToFImageRecorder->SetCameraDevice(this->m_ToFImageGrabber->GetCameraDevice()); + m_Controls->m_ToFRecorderWidget->SetParameter(this->m_ToFImageGrabber, this->m_ToFImageRecorder); + m_Controls->m_ToFRecorderWidget->setEnabled(true); + m_Controls->m_ToFRecorderWidget->ResetGUIToInitial(); + m_Controls->m_ToFVisualisationSettingsWidget->setEnabled(true); //TODO this->m_RealTimeClock = mitk::RealTimeClock::New(); - this->m_StepsForFramerate = 100; - this->m_TimeBefore = this->m_RealTimeClock->GetCurrentStamp(); this->m_2DTimeBefore = this->m_RealTimeClock->GetCurrentStamp(); - this->m_SurfaceTimeBefore = this->m_RealTimeClock->GetCurrentStamp(); try { this->m_VideoSource = mitk::OpenCVVideoSource::New(); this->m_VideoSource->SetVideoCameraInput(0, false); this->m_VideoSource->StartCapturing(); if(!this->m_VideoSource->IsCapturingEnabled()) { MITK_INFO << "unable to initialize video grabbing/playback"; this->m_VideoEnabled = false; m_Controls->m_VideoTextureCheckBox->setEnabled(false); } else { this->m_VideoEnabled = true; m_Controls->m_VideoTextureCheckBox->setEnabled(true); } if (this->m_VideoEnabled) { this->m_VideoSource->FetchFrame(); this->m_VideoCaptureHeight = this->m_VideoSource->GetImageHeight(); this->m_VideoCaptureWidth = this->m_VideoSource->GetImageWidth(); int videoTexSize = this->m_VideoCaptureWidth * this->m_VideoCaptureHeight * 3; // for each pixel three values for rgb are needed!! this->m_VideoTexture = this->m_VideoSource->GetVideoTexture(); unsigned int dimensions[2]; dimensions[0] = this->m_VideoCaptureWidth; dimensions[1] = this->m_VideoCaptureHeight; - this->m_SurfaceTextureImage->Initialize(mitk::PixelType(typeid(unsigned char), 3), 2, dimensions, 1); - - //this->m_SurfaceWorkerThread.SetTextureImageWidth(this->m_VideoCaptureWidth); - //this->m_SurfaceWorkerThread.SetTextureImageHeight(this->m_VideoCaptureHeight); this->m_ToFDistanceImageToSurfaceFilter->SetTextureImageWidth(this->m_VideoCaptureWidth); this->m_ToFDistanceImageToSurfaceFilter->SetTextureImageHeight(this->m_VideoCaptureHeight); this->m_ToFSurfaceVtkMapper3D->SetTextureWidth(this->m_VideoCaptureWidth); this->m_ToFSurfaceVtkMapper3D->SetTextureHeight(this->m_VideoCaptureHeight); } m_MultiWidget->DisableGradientBackground(); - - this->AddBackground(); } catch (std::logic_error& e) { QMessageBox::warning(NULL, "Warning", QString(e.what())); MITK_ERROR << e.what(); return; } - //this->m_SurfaceWorkerThread.SetAbort(false); - //this->m_SurfaceWorkerThread.SetFilterThread(&(this->m_FilterWorkerThread)); - //this->m_FilterWorkerThread.SetAbort(false); - - - m_Controls->m_ToFRecorderWidget->setEnabled(true); - m_Controls->m_ToFRecorderWidget->ResetGUIToInitial(); - m_Controls->m_ToFVisualisationSettingsWidget->setEnabled(true); mitk::RenderingManager::GetInstance()->ForceImmediateUpdateAll(); } void QmitkToFUtilView::OnToFCameraDisconnected() { - //this->m_SurfaceWorkerThread.SetAbort(true); - //this->m_SurfaceWorkerThread.quit(); - //this->m_FilterWorkerThread.SetAbort(true); - + m_Controls->m_ToFRecorderWidget->OnStop(); m_Controls->m_ToFRecorderWidget->setEnabled(false); m_Controls->m_ToFVisualisationSettingsWidget->setEnabled(false); if(this->m_VideoSource) { this->m_VideoSource->StopCapturing(); this->m_VideoSource = NULL; } - RemoveBackground(); mitk::RenderingManager::GetInstance()->ForceImmediateUpdateAll(); - - cvReleaseImage(&(this->m_IplDistanceImage)); - cvReleaseImage(&(this->m_IplIntensityImage)); - cvReleaseImage(&(this->m_OutputIplImage)); - - delete[] this->m_Widget1Texture; - delete[] this->m_Widget2Texture; - delete[] this->m_Widget3Texture; - - //mitk::ToFImageGrabber* aToFImageGrabber = dynamic_cast(m_ToFImageGrabber); - //aToFImageGrabber->Delete(); } void QmitkToFUtilView::OnToFCameraStarted() { - //this->m_FilterWorkerThread.SetAbort(false); - //this->m_FilterWorkerThread.StartProcessing(this->m_ToFImageGrabber, this->m_MitkAllImage); - //this->m_SurfaceWorkerThread.SetAbort(false); - - // initial update of image grabber - this->m_ToFImageGrabber->Update(); - - this->m_ToFCompositeFilter->SetInput(0,this->m_ToFImageGrabber->GetOutput(0)); - this->m_ToFCompositeFilter->SetInput(1,this->m_ToFImageGrabber->GetOutput(1)); - this->m_ToFCompositeFilter->SetInput(2,this->m_ToFImageGrabber->GetOutput(2)); - // initial update of composite filter - this->m_ToFCompositeFilter->Update(); - this->m_ToFVisualizationFilter->SetInput(0,this->m_ToFCompositeFilter->GetOutput(0)); - this->m_ToFVisualizationFilter->SetInput(1,this->m_ToFCompositeFilter->GetOutput(1)); - this->m_ToFVisualizationFilter->SetInput(2,this->m_ToFCompositeFilter->GetOutput(2)); - // initial update of visualization filter - this->m_ToFVisualizationFilter->Update(); - //this->m_MitkDistanceImage = m_ToFVisualizationFilter->GetOutput(0); - //this->m_MitkAmplitudeImage = m_ToFVisualizationFilter->GetOutput(1); - //this->m_MitkIntensityImage = m_ToFVisualizationFilter->GetOutput(2); - this->m_MitkDistanceImage = m_ToFCompositeFilter->GetOutput(0); - this->m_MitkAmplitudeImage = m_ToFCompositeFilter->GetOutput(1); - this->m_MitkIntensityImage = m_ToFCompositeFilter->GetOutput(2); - this->m_ToFDistanceImageToSurfaceFilter->SetInput(0,this->m_ToFCompositeFilter->GetOutput(0)); - this->m_ToFDistanceImageToSurfaceFilter->SetInput(1,this->m_ToFCompositeFilter->GetOutput(1)); - this->m_ToFDistanceImageToSurfaceFilter->SetInput(2,this->m_ToFCompositeFilter->GetOutput(2)); - this->m_Surface = this->m_ToFDistanceImageToSurfaceFilter->GetOutput(0); - - this->m_Frametimer->start(0); - - //if (m_Controls->m_AveragingFilterCheckBox->isChecked()) - //{ - // OnAveragingFilterCheckBoxChecked(true); - //} - //if (m_Controls->m_ThresholdFilterCheckBox->isChecked()) - //{ - // OnThresholdFilterCheckBoxChecked(true); - //} - //if (m_Controls->m_BilateralFilterCheckBox->isChecked()) - //{ - // OnBilateralFilterCheckBoxChecked(true); - //} - - m_Controls->m_ToFCompositeFilterWidget->UpdateFilterParameter(); - - if (m_Controls->m_SurfaceCheckBox->isChecked()) - { - OnSurfaceCheckBoxChecked(true); - } - if (m_Controls->m_TextureCheckBox->isChecked()) - { - OnTextureCheckBoxChecked(true); - } - if (m_Controls->m_VideoTextureCheckBox->isChecked()) - { - OnVideoTextureCheckBoxChecked(true); + if (m_ToFImageGrabber.IsNotNull()) + { + // initial update of image grabber + this->m_ToFImageGrabber->Update(); + + this->m_ToFCompositeFilter->SetInput(0,this->m_ToFImageGrabber->GetOutput(0)); + this->m_ToFCompositeFilter->SetInput(1,this->m_ToFImageGrabber->GetOutput(1)); + this->m_ToFCompositeFilter->SetInput(2,this->m_ToFImageGrabber->GetOutput(2)); + // initial update of composite filter + this->m_ToFCompositeFilter->Update(); + this->m_MitkDistanceImage = m_ToFCompositeFilter->GetOutput(0); + this->m_DistanceImageNode = ReplaceNodeData("Distance image",m_MitkDistanceImage); + this->m_MitkAmplitudeImage = m_ToFCompositeFilter->GetOutput(1); + this->m_AmplitudeImageNode = ReplaceNodeData("Amplitude image",m_MitkAmplitudeImage); + this->m_MitkIntensityImage = m_ToFCompositeFilter->GetOutput(2); + this->m_IntensityImageNode = ReplaceNodeData("Intensity image",m_MitkIntensityImage); + + this->m_ToFDistanceImageToSurfaceFilter->SetInput(0,m_MitkDistanceImage); + this->m_ToFDistanceImageToSurfaceFilter->SetInput(1,m_MitkAmplitudeImage); + this->m_ToFDistanceImageToSurfaceFilter->SetInput(2,m_MitkIntensityImage); + this->m_Surface = this->m_ToFDistanceImageToSurfaceFilter->GetOutput(0); + this->m_SurfaceNode = ReplaceNodeData("Surface",m_Surface); + + this->UseToFVisibilitySettings(true); + + this->m_Frametimer->start(0); + + m_Controls->m_ToFCompositeFilterWidget->UpdateFilterParameter(); + // initialize visualization widget + m_Controls->m_ToFVisualisationSettingsWidget->Initialize(this->m_MitkDistanceImage, this->m_MitkAmplitudeImage, this->m_MitkIntensityImage); + + if (m_Controls->m_TextureCheckBox->isChecked()) + { + OnTextureCheckBoxChecked(true); + } + if (m_Controls->m_VideoTextureCheckBox->isChecked()) + { + OnVideoTextureCheckBoxChecked(true); + } } - -} - -void QmitkToFUtilView::OnToFCameraStop() -{ - - //this->m_Frametimer->stop(); - - //this->m_SurfaceWorkerThread.SetAbort(true); - //this->m_FilterWorkerThread.SetAbort(true); - m_Controls->m_ToFRecorderWidget->OnStop(); + m_Controls->m_TextureCheckBox->setEnabled(true); + // initialize point set measurement + m_Controls->tofMeasurementWidget->InitializeWidget(m_MultiWidget,this->GetDefaultDataStorage(),m_MitkDistanceImage); } void QmitkToFUtilView::OnToFCameraStopped() { this->m_Frametimer->stop(); - //this->m_SurfaceWorkerThread.SetAbort(true); - //this->m_FilterWorkerThread.SetAbort(true); } void QmitkToFUtilView::OnToFCameraSelected(const QString selected) { if ((selected=="PMD CamBoard")||(selected=="PMD O3D")) { MITK_INFO<<"Surface representation currently not available for CamBoard and O3. Intrinsic parameters missing."; this->m_Controls->m_SurfaceCheckBox->setEnabled(false); this->m_Controls->m_TextureCheckBox->setEnabled(false); this->m_Controls->m_VideoTextureCheckBox->setEnabled(false); this->m_Controls->m_SurfaceCheckBox->setChecked(false); this->m_Controls->m_TextureCheckBox->setChecked(false); this->m_Controls->m_VideoTextureCheckBox->setChecked(false); } else { this->m_Controls->m_SurfaceCheckBox->setEnabled(true); this->m_Controls->m_TextureCheckBox->setEnabled(true); // TODO enable when bug 8106 is solved this->m_Controls->m_VideoTextureCheckBox->setEnabled(true); } } -void QmitkToFUtilView::InitImage(mitk::Image::Pointer image, int numOfChannel) -{ - unsigned int dimensions[4]; - dimensions[0] = this->m_ToFImageGrabber->GetCaptureWidth(); - dimensions[1] = this->m_ToFImageGrabber->GetCaptureHeight(); - dimensions[2] = 1; - dimensions[3] = 1; - image->Initialize(mitk::PixelType(typeid(float)), 2, dimensions, numOfChannel); -} - -void QmitkToFUtilView::InitTexture(unsigned char* &image, int width, int height) -{ - int texSize = width * height * 3; - image = new unsigned char[ texSize ]; - for(int i=0; iGetDataStorage()->GetNamedNode("ToF_Distance") == NULL) - { - //m_DistanceImageNode->SetProperty( "visible" , mitk::BoolProperty::New( true )); - //m_DistanceImageNode->SetVisibility( false, mitk::BaseRenderer::GetInstance(GetActiveStdMultiWidget()->mitkWidget1->GetRenderWindow() ) ); - //m_DistanceImageNode->SetVisibility( false, mitk::BaseRenderer::GetInstance(GetActiveStdMultiWidget()->mitkWidget3->GetRenderWindow() ) ); - //m_DistanceImageNode->SetVisibility( false, mitk::BaseRenderer::GetInstance(GetActiveStdMultiWidget()->mitkWidget4->GetRenderWindow() ) ); - //m_DistanceImageNode->SetProperty( "inRenWin2" , mitk::BoolProperty::New( true )); - ////m_DistanceImageNode->SetProperty( "use color", mitk::BoolProperty::New( false )); - //m_DistanceImageNode->SetProperty( "use color", mitk::BoolProperty::New( true )); - //m_DistanceImageNode->SetProperty( "binary", mitk::BoolProperty::New( false )); - //m_DistanceImageNode->SetIntProperty( "layer", 10); - //this->GetDataStorage()->Add( this->m_DistanceImageNode ); - } - if(this->GetDataStorage()->GetNamedNode("ToF_Amplitude") == NULL) - { - //m_AmplitudeImageNode->SetProperty( "visible" , mitk::BoolProperty::New( true )); - //m_AmplitudeImageNode->SetVisibility( false, mitk::BaseRenderer::GetInstance(GetActiveStdMultiWidget()->mitkWidget2->GetRenderWindow() ) ); - //m_AmplitudeImageNode->SetVisibility( false, mitk::BaseRenderer::GetInstance(GetActiveStdMultiWidget()->mitkWidget3->GetRenderWindow() ) ); - //m_AmplitudeImageNode->SetVisibility( false, mitk::BaseRenderer::GetInstance(GetActiveStdMultiWidget()->mitkWidget4->GetRenderWindow() ) ); - //m_AmplitudeImageNode->SetProperty( "inRenWin1" , mitk::BoolProperty::New( true )); - //m_AmplitudeImageNode->SetProperty( "use color", mitk::BoolProperty::New( true )); - //m_AmplitudeImageNode->SetProperty( "binary", mitk::BoolProperty::New( false )); - //m_AmplitudeImageNode->SetIntProperty( "layer", 10); - //this->GetDataStorage()->Add( this->m_AmplitudeImageNode ); - } - if(this->GetDataStorage()->GetNamedNode("ToF_Intensity") == NULL) - { - //m_IntensityImageNode->SetProperty( "visible" , mitk::BoolProperty::New( true )); - //m_IntensityImageNode->SetVisibility( false, mitk::BaseRenderer::GetInstance(GetActiveStdMultiWidget()->mitkWidget1->GetRenderWindow() ) ); - //m_IntensityImageNode->SetVisibility( false, mitk::BaseRenderer::GetInstance(GetActiveStdMultiWidget()->mitkWidget2->GetRenderWindow() ) ); - //m_IntensityImageNode->SetVisibility( false, mitk::BaseRenderer::GetInstance(GetActiveStdMultiWidget()->mitkWidget4->GetRenderWindow() ) ); - //m_IntensityImageNode->SetProperty( "inRenWin3" , mitk::BoolProperty::New( true )); - //m_IntensityImageNode->SetProperty( "use color", mitk::BoolProperty::New( true )); - //m_IntensityImageNode->SetProperty( "binary", mitk::BoolProperty::New( false )); - //m_IntensityImageNode->SetIntProperty( "layer", 10); - //this->GetDataStorage()->Add( this->m_IntensityImageNode ); - } - - if(this->GetDataStorage()->GetNamedNode("ToF_All") == NULL) - { - //m_AllImageNode->SetProperty( "visible" , mitk::BoolProperty::New( true )); - /* - m_IntensityImageNode->SetVisibility( false, mitk::BaseRenderer::GetInstance(GetActiveStdMultiWidget()->mitkWidget1->GetRenderWindow() ) ); - m_IntensityImageNode->SetVisibility( false, mitk::BaseRenderer::GetInstance(GetActiveStdMultiWidget()->mitkWidget2->GetRenderWindow() ) ); - m_IntensityImageNode->SetVisibility( false, mitk::BaseRenderer::GetInstance(GetActiveStdMultiWidget()->mitkWidget4->GetRenderWindow() ) ); - m_IntensityImageNode->SetProperty( "inRenWin3" , mitk::BoolProperty::New( true )); - m_IntensityImageNode->SetProperty( "use color", mitk::BoolProperty::New( true )); - m_IntensityImageNode->SetProperty( "binary", mitk::BoolProperty::New( false )); - m_IntensityImageNode->SetIntProperty( "layer", 10); - */ - - //mitk::Mapper::Pointer aMapper = mitk::ToFImageMapper::New(); - //m_AllImageNode->SetMapper(mitk::BaseRenderer::Standard2D, aMapper); - //this->GetDataStorage()->Add( this->m_AllImageNode ); - } - -} - -void* QmitkToFUtilView::GetDataFromImage(std::string imageType) -{ - void* data; - if (imageType.compare("Distance")==0) - { - data = this->m_MitkDistanceImage->GetData(); - //data = this->m_MitkAllImage->GetSliceData(0, 0, 0)->GetData(); - } - else if (imageType.compare("Amplitude")==0) - { - data = this->m_MitkAmplitudeImage->GetData(); - //data = this->m_MitkAllImage->GetSliceData(0, 0, 1)->GetData(); - } - if (imageType.compare("Intensity")==0) - { - data = this->m_MitkIntensityImage->GetData(); - //data = this->m_MitkAllImage->GetSliceData(0, 0, 2)->GetData(); - } - return data; -} - void QmitkToFUtilView::OnUpdateCamera() { int currentImageSequence = 0; - // update pipeline - this->m_MitkDistanceImage->Update(); - // update distance image node - this->m_DistanceImageNode->SetData(this->m_MitkDistanceImage); - - if (!this->m_TransferFunctionInitialized) - { - m_Controls->m_ToFVisualisationSettingsWidget->InitializeTransferFunction(this->m_MitkDistanceImage, this->m_MitkAmplitudeImage, this->m_MitkIntensityImage); - this->m_TransferFunctionInitialized = true; - } - if (m_Controls->m_VideoTextureCheckBox->isChecked() && this->m_VideoEnabled && this->m_VideoSource) { this->m_VideoTexture = this->m_VideoSource->GetVideoTexture(); ProcessVideoTransform(); } - vtkColorTransferFunction* colorTransferFunction; - std::string imageType; - - colorTransferFunction = m_Controls->m_ToFVisualisationSettingsWidget->GetWidget1ColorTransferFunction(); - imageType = m_Controls->m_ToFVisualisationSettingsWidget->GetWidget1ImageType(); - RenderWidget(m_MultiWidget->mitkWidget1, this->m_QmitkToFImageBackground1, this->m_Widget1ImageType, imageType, - colorTransferFunction, this->m_VideoTexture, this->m_Widget1Texture ); - - colorTransferFunction = m_Controls->m_ToFVisualisationSettingsWidget->GetWidget2ColorTransferFunction(); - imageType = m_Controls->m_ToFVisualisationSettingsWidget->GetWidget2ImageType(); - RenderWidget(m_MultiWidget->mitkWidget2, this->m_QmitkToFImageBackground2, this->m_Widget2ImageType, imageType, - colorTransferFunction, this->m_VideoTexture, this->m_Widget2Texture ); - - colorTransferFunction = m_Controls->m_ToFVisualisationSettingsWidget->GetWidget3ColorTransferFunction(); - imageType = m_Controls->m_ToFVisualisationSettingsWidget->GetWidget3ImageType(); - RenderWidget(m_MultiWidget->mitkWidget3, this->m_QmitkToFImageBackground3, this->m_Widget3ImageType, imageType, - colorTransferFunction, this->m_VideoTexture, this->m_Widget3Texture ); + vtkColorTransferFunction* colorTransferFunction1; + colorTransferFunction1 = m_Controls->m_ToFVisualisationSettingsWidget->GetWidget1ColorTransferFunction(); + mitk::TransferFunction::Pointer tf1 = mitk::TransferFunction::New(); + tf1->SetColorTransferFunction( colorTransferFunction1 ); + m_DistanceImageNode->SetProperty("Image Rendering.Transfer Function",mitk::TransferFunctionProperty::New(tf1)); + vtkColorTransferFunction* colorTransferFunction2; + colorTransferFunction2 = m_Controls->m_ToFVisualisationSettingsWidget->GetWidget2ColorTransferFunction(); + mitk::TransferFunction::Pointer tf2 = mitk::TransferFunction::New(); + tf2->SetColorTransferFunction( colorTransferFunction2 ); + m_AmplitudeImageNode->SetProperty("Image Rendering.Transfer Function",mitk::TransferFunctionProperty::New(tf2)); + vtkColorTransferFunction* colorTransferFunction3; + colorTransferFunction3 = m_Controls->m_ToFVisualisationSettingsWidget->GetWidget3ColorTransferFunction(); + mitk::TransferFunction::Pointer tf3 = mitk::TransferFunction::New(); + tf3->SetColorTransferFunction( colorTransferFunction3 ); + m_IntensityImageNode->SetProperty("Image Rendering.Transfer Function",mitk::TransferFunctionProperty::New(tf3)); if (m_Controls->m_SurfaceCheckBox->isChecked()) { // update surface + m_ToFDistanceImageToSurfaceFilter->SetTextureIndex(m_Controls->m_ToFVisualisationSettingsWidget->GetSelectedImageIndex()); this->m_Surface->Update(); - colorTransferFunction = m_Controls->m_ToFVisualisationSettingsWidget->GetColorTransferFunctionByImageType("Intensity"); + vtkColorTransferFunction* colorTransferFunction = m_Controls->m_ToFVisualisationSettingsWidget->GetSelectedColorTransferFunction(); this->m_ToFSurfaceVtkMapper3D->SetVtkScalarsToColors(colorTransferFunction); - if (this->m_SurfaceDisplayCount < 2) + if (this->m_SurfaceDisplayCount<2) { this->m_SurfaceNode->SetData(this->m_Surface); this->m_SurfaceNode->SetMapper(mitk::BaseRenderer::Standard3D, m_ToFSurfaceVtkMapper3D); mitk::RenderingManager::GetInstance()->InitializeViews( this->m_Surface->GetTimeSlicedGeometry(), mitk::RenderingManager::REQUEST_UPDATE_3DWINDOWS, true); mitk::Point3D surfaceCenter= this->m_Surface->GetGeometry()->GetCenter(); m_MultiWidget->mitkWidget4->GetRenderer()->GetVtkRenderer()->GetActiveCamera()->SetPosition(0,0,-50); m_MultiWidget->mitkWidget4->GetRenderer()->GetVtkRenderer()->GetActiveCamera()->SetViewUp(0,-1,0); m_MultiWidget->mitkWidget4->GetRenderer()->GetVtkRenderer()->GetActiveCamera()->SetFocalPoint(0,0,surfaceCenter[2]); m_MultiWidget->mitkWidget4->GetRenderer()->GetVtkRenderer()->GetActiveCamera()->SetViewAngle(40); m_MultiWidget->mitkWidget4->GetRenderer()->GetVtkRenderer()->GetActiveCamera()->SetClippingRange(1, 10000); } this->m_SurfaceDisplayCount++; } + else + { + // update pipeline + this->m_MitkDistanceImage->Update(); + } - - - mitk::RenderingManager::GetInstance()->ForceImmediateUpdateAll(); + mitk::RenderingManager::GetInstance()->RequestUpdateAll(); this->m_2DDisplayCount++; if ((this->m_2DDisplayCount % this->m_StepsForFramerate) == 0) { this->m_2DTimeAfter = this->m_RealTimeClock->GetCurrentStamp() - this->m_2DTimeBefore; - MITK_INFO << " 2D-Display-framerate (fps): " << this->m_StepsForFramerate / (this->m_2DTimeAfter/1000) << " Sequence: " << this->m_ImageSequence; + MITK_INFO << " 2D-Display-framerate (fps): " << this->m_StepsForFramerate / (this->m_2DTimeAfter/1000); this->m_2DTimeBefore = this->m_RealTimeClock->GetCurrentStamp(); } } void QmitkToFUtilView::ProcessVideoTransform() { - /* - this->m_VideoTexture - this->m_IplIntensityImage->imageData = (char*)intensityFloatData; - this->m_IplIntensityImage = cvCreateImageHeader(cvSize(this->m_ToFCaptureWidth, this->m_ToFCaptureHeight), IPL_DEPTH_32F, 1); // no allocation - this->m_OutputIplImage = cvCreateImage(cvSize(this->m_ToFCaptureWidth, this->m_ToFCaptureHeight), IPL_DEPTH_32F, 1); -*/ - - IplImage *src, *dst; src = cvCreateImageHeader(cvSize(this->m_VideoCaptureWidth, this->m_VideoCaptureHeight), IPL_DEPTH_8U, 3); src->imageData = (char*)this->m_VideoTexture; CvPoint2D32f srcTri[3], dstTri[3]; CvMat* rot_mat = cvCreateMat(2,3,CV_32FC1); CvMat* warp_mat = cvCreateMat(2,3,CV_32FC1); dst = cvCloneImage(src); dst->origin = src->origin; cvZero( dst ); // Create angle and scale double angle = 0.0; double scale = 1.0; int xOffset = 0;//m_Controls->m_XOffsetSpinBox->value(); int yOffset = 0;//m_Controls->m_YOffsetSpinBox->value(); int zoom = 0;//m_Controls->m_ZoomSpinBox->value(); // Compute warp matrix srcTri[0].x = 0 + zoom; srcTri[0].y = 0 + zoom; srcTri[1].x = src->width - 1 - zoom; srcTri[1].y = 0 + zoom; srcTri[2].x = 0 + zoom; srcTri[2].y = src->height - 1 - zoom; dstTri[0].x = 0; dstTri[0].y = 0; dstTri[1].x = src->width - 1; dstTri[1].y = 0; dstTri[2].x = 0; dstTri[2].y = src->height - 1; cvGetAffineTransform( srcTri, dstTri, warp_mat ); cvWarpAffine( src, dst, warp_mat ); cvCopy ( dst, src ); // Compute warp matrix srcTri[0].x = 0; srcTri[0].y = 0; srcTri[1].x = src->width - 1; srcTri[1].y = 0; srcTri[2].x = 0; srcTri[2].y = src->height - 1; dstTri[0].x = srcTri[0].x + xOffset; dstTri[0].y = srcTri[0].y + yOffset; dstTri[1].x = srcTri[1].x + xOffset; dstTri[1].y = srcTri[1].y + yOffset; dstTri[2].x = srcTri[2].x + xOffset; dstTri[2].y = srcTri[2].y + yOffset; cvGetAffineTransform( srcTri, dstTri, warp_mat ); cvWarpAffine( src, dst, warp_mat ); cvCopy ( dst, src ); src->imageData = NULL; cvReleaseImage( &src ); cvReleaseImage( &dst ); cvReleaseMat( &rot_mat ); cvReleaseMat( &warp_mat ); } -void QmitkToFUtilView::RenderWidget(QmitkRenderWindow* mitkWidget, QmitkToFImageBackground* imageBackground, - std::string& oldImageType, std::string newImageType, - vtkColorTransferFunction* colorTransferFunction, unsigned char* videoTexture, unsigned char* tofTexture ) +void QmitkToFUtilView::OnTextureCheckBoxChecked(bool checked) { - if (newImageType.compare("Video") == 0) + if(m_SurfaceNode.IsNotNull()) { - if (this->m_VideoEnabled) + if (checked) { - if (oldImageType.compare(newImageType)!=0) - { - imageBackground->AddRenderWindow(mitkWidget->GetRenderWindow(), this->m_VideoCaptureWidth, this->m_VideoCaptureHeight); - oldImageType = newImageType; - } - imageBackground->UpdateBackground(videoTexture); + this->m_SurfaceNode->SetBoolProperty("scalar visibility", true); } - } - else - { - if (oldImageType.compare(newImageType)!=0) + else { - imageBackground->AddRenderWindow(mitkWidget->GetRenderWindow(), this->m_ToFCaptureWidth, this->m_ToFCaptureHeight); - oldImageType = newImageType; + this->m_SurfaceNode->SetBoolProperty("scalar visibility", false); } - void* data = GetDataFromImage(newImageType); - PrepareImageForBackground(colorTransferFunction, (float*)data, tofTexture); - imageBackground->UpdateBackground(tofTexture); - } -} - -//void QmitkToFUtilView::CreateSurface() -//{ -// static int count = 0; -// //this->m_ToFSurfaceGenerationFilter = mitk::ToFSurfaceGenerationFilter::New(); - -// this->m_ToFSurfaceGenerationFilter->SetInput(this->m_MitkDistanceImage); -// this->m_ToFSurfaceGenerationFilter->Modified(); -// this->m_ToFSurfaceGenerationFilter->Update(); -// this->m_Surface->ReleaseData(); -// vtkPolyData* polydata = this->m_ToFSurfaceGenerationFilter->GetOutput()->GetVtkPolyData(); -// //this->m_Surface->GetVtkPolyData()->ReleaseData(); -// this->m_Surface->SetVtkPolyData(polydata); -// //this->m_Surface = this->m_ToFSurfaceGenerationFilter->GetOutput(); - -// this->m_SurfaceNode->SetData(this->m_Surface); -// //if(!this->m_SurfaceInitialized) -// if (count < 1) -// { -// //mitk::RenderingManager::GetInstance()->InitializeViews( -// // this->m_Surface->GetTimeSlicedGeometry(), mitk::RenderingManager::REQUEST_UPDATE_3DWINDOWS, true); - -// m_MultiWidget->mitkWidget4->GetRenderer()->GetVtkRenderer()->ResetCamera(); -// m_MultiWidget->mitkWidget4->GetRenderer()->GetVtkRenderer()->GetActiveCamera()->SetPosition(-500,-120,-6000); -// m_MultiWidget->mitkWidget4->GetRenderer()->GetVtkRenderer()->GetActiveCamera()->SetViewUp(0,-1,0); -// m_MultiWidget->mitkWidget4->GetRenderer()->GetVtkRenderer()->GetActiveCamera()->SetFocalPoint(-130,0,2300); -// m_MultiWidget->mitkWidget4->GetRenderer()->GetVtkRenderer()->GetActiveCamera()->SetViewAngle(40); -// //this->m_SurfaceInitialized = true; -// count++; -// } -//} - -void QmitkToFUtilView::OnTextureCheckBoxChecked(bool checked) -{ - if (checked) - { - this->m_SurfaceNode->SetBoolProperty("scalar visibility", true); - } - else - { - this->m_SurfaceNode->SetBoolProperty("scalar visibility", false); } } void QmitkToFUtilView::OnVideoTextureCheckBoxChecked(bool checked) { if (checked) { if (this->m_VideoEnabled) { - this->m_SurfaceTextureImage->SetSlice(this->m_VideoTexture, 0, 0, 0); this->m_ToFSurfaceVtkMapper3D->SetTexture(this->m_VideoTexture); } else { this->m_ToFSurfaceVtkMapper3D->SetTexture(NULL); } } else { this->m_ToFSurfaceVtkMapper3D->SetTexture(NULL); } } -void QmitkToFUtilView::OnSurfaceCheckBoxChecked(bool checked) +mitk::DataNode::Pointer QmitkToFUtilView::ReplaceNodeData( std::string nodeName, mitk::BaseData* data ) { - //if (checked) - //{ - // void* surfaceInputdata = this->m_MitkAllImage->GetSliceData(0, 0, 0)->GetData(); - - // this->m_SurfaceInputImage->SetSlice(surfaceInputdata, 0, 0, 0); - - // void* surfaceIntensitydata = this->m_MitkAllImage->GetSliceData(0, 0, 2)->GetData(); - // this->m_SurfaceIntensityImage->SetSlice(surfaceIntensitydata, 0, 0, 0); - // if (m_Controls->m_VideoTextureCheckBox->isChecked()) - // { - // OnVideoTextureCheckBoxChecked(true); - // } - // else - // { - // OnVideoTextureCheckBoxChecked(false); - // } - // if (m_Controls->m_TextureCheckBox->isChecked()) - // { - // OnTextureCheckBoxChecked(true); - // } - // else - // { - // OnTextureCheckBoxChecked(false); - // } - // //this->m_SurfaceWorkerThread.SetAbort(false); - // //this->m_SurfaceDisplayCount = 0; - // //this->m_SurfaceWorkerThread.CreateSurface(this->m_SurfaceInputImage, this->m_SurfaceIntensityImage, this->m_SurfaceTextureImage, this->m_Surface); - //} - //else - //{ - // //this->m_SurfaceWorkerThread.SetAbort(true); - //} -} - -void QmitkToFUtilView::PrepareImageForBackground(vtkLookupTable* lut, float* floatData, unsigned char* image) -{ - vtkSmartPointer floatArrayDist = vtkFloatArray::New(); - floatArrayDist->Initialize(); - int numOfPixel = this->m_ToFCaptureWidth * this->m_ToFCaptureHeight; - float* flippedFloatData = new float[numOfPixel]; - for (int i=0; im_ToFCaptureHeight; i++) + mitk::DataNode::Pointer node = this->GetDefaultDataStorage()->GetNamedNode(nodeName); + if (node.IsNull()) { - for (int j=0; jm_ToFCaptureWidth; j++) - { - flippedFloatData[i*this->m_ToFCaptureWidth+j] = floatData[((this->m_ToFCaptureHeight-1-i)*this->m_ToFCaptureWidth)+j]; - } + node = mitk::DataNode::New(); + node->SetData(data); + node->SetName(nodeName); + this->GetDefaultDataStorage()->Add(node); } - - floatArrayDist->SetArray(flippedFloatData, numOfPixel, 0); - lut->MapScalarsThroughTable(floatArrayDist, image, VTK_RGB); - - delete[] flippedFloatData; -} - -void QmitkToFUtilView::PrepareImageForBackground(vtkColorTransferFunction* colorTransferFunction, float* floatData, unsigned char* image) -{ - vtkSmartPointer floatArrayDist = vtkFloatArray::New(); - floatArrayDist->Initialize(); - int numOfPixel = this->m_ToFCaptureWidth * this->m_ToFCaptureHeight; - float* flippedFloatData = new float[numOfPixel]; - - for (int i=0; im_ToFCaptureHeight; i++) + else { - for (int j=0; jm_ToFCaptureWidth; j++) - { - flippedFloatData[i*this->m_ToFCaptureWidth+j] = floatData[((this->m_ToFCaptureHeight-1-i)*this->m_ToFCaptureWidth)+j]; - } + node->SetData(data); } - - floatArrayDist->SetArray(flippedFloatData, numOfPixel, 0); - colorTransferFunction->MapScalarsThroughTable(floatArrayDist, image, VTK_RGB); - - delete[] flippedFloatData; + return node; } -void QmitkToFUtilView::RemoveBackground() +void QmitkToFUtilView::UseToFVisibilitySettings(bool useToF) { - if(this->m_QmitkToFImageBackground1) + // set node properties + if (m_DistanceImageNode.IsNotNull()) { - this->m_QmitkToFImageBackground1->RemoveRenderWindow(m_MultiWidget->mitkWidget1->GetRenderWindow()); + this->m_DistanceImageNode->SetProperty( "visible" , mitk::BoolProperty::New( true )); + this->m_DistanceImageNode->SetVisibility( !useToF, mitk::BaseRenderer::GetInstance(GetActiveStdMultiWidget()->mitkWidget2->GetRenderWindow() ) ); + this->m_DistanceImageNode->SetVisibility( !useToF, mitk::BaseRenderer::GetInstance(GetActiveStdMultiWidget()->mitkWidget3->GetRenderWindow() ) ); + this->m_DistanceImageNode->SetVisibility( !useToF, mitk::BaseRenderer::GetInstance(GetActiveStdMultiWidget()->mitkWidget4->GetRenderWindow() ) ); } - if(this->m_QmitkToFImageBackground2) + if (m_AmplitudeImageNode.IsNotNull()) { - this->m_QmitkToFImageBackground2->RemoveRenderWindow(m_MultiWidget->mitkWidget2->GetRenderWindow()); + this->m_AmplitudeImageNode->SetProperty( "visible" , mitk::BoolProperty::New( true )); + this->m_AmplitudeImageNode->SetVisibility( !useToF, mitk::BaseRenderer::GetInstance(GetActiveStdMultiWidget()->mitkWidget1->GetRenderWindow() ) ); + this->m_AmplitudeImageNode->SetVisibility( !useToF, mitk::BaseRenderer::GetInstance(GetActiveStdMultiWidget()->mitkWidget3->GetRenderWindow() ) ); + this->m_AmplitudeImageNode->SetVisibility( !useToF, mitk::BaseRenderer::GetInstance(GetActiveStdMultiWidget()->mitkWidget4->GetRenderWindow() ) ); } - if(this->m_QmitkToFImageBackground3) + if (m_IntensityImageNode.IsNotNull()) { - this->m_QmitkToFImageBackground3->RemoveRenderWindow(m_MultiWidget->mitkWidget3->GetRenderWindow()); + this->m_IntensityImageNode->SetProperty( "visible" , mitk::BoolProperty::New( true )); + this->m_IntensityImageNode->SetVisibility( !useToF, mitk::BaseRenderer::GetInstance(GetActiveStdMultiWidget()->mitkWidget1->GetRenderWindow() ) ); + this->m_IntensityImageNode->SetVisibility( !useToF, mitk::BaseRenderer::GetInstance(GetActiveStdMultiWidget()->mitkWidget2->GetRenderWindow() ) ); + this->m_IntensityImageNode->SetVisibility( !useToF, mitk::BaseRenderer::GetInstance(GetActiveStdMultiWidget()->mitkWidget4->GetRenderWindow() ) ); + } + // initialize images + if (m_MitkDistanceImage.IsNotNull()) + { + mitk::RenderingManager::GetInstance()->InitializeViews( + this->m_MitkDistanceImage->GetTimeSlicedGeometry(), mitk::RenderingManager::REQUEST_UPDATE_2DWINDOWS, true); } -} - -void QmitkToFUtilView::AddBackground() -{ - InitTexture(this->m_Widget1Texture, this->m_ToFCaptureWidth, this->m_ToFCaptureHeight); - InitTexture(this->m_Widget2Texture, this->m_ToFCaptureWidth, this->m_ToFCaptureHeight); - InitTexture(this->m_Widget3Texture, this->m_ToFCaptureWidth, this->m_ToFCaptureHeight); - - this->m_QmitkToFImageBackground1 = new QmitkToFImageBackground(); - this->m_QmitkToFImageBackground1->AddRenderWindow(m_MultiWidget->mitkWidget1->GetRenderWindow(), this->m_ToFCaptureWidth, this->m_ToFCaptureHeight); - this->m_QmitkToFImageBackground1->UpdateBackground(this->m_Widget1Texture); - this->m_Widget1ImageType = m_Controls->m_ToFVisualisationSettingsWidget->GetWidget1ImageType(); - - this->m_QmitkToFImageBackground2 = new QmitkToFImageBackground(); - this->m_QmitkToFImageBackground2->AddRenderWindow(m_MultiWidget->mitkWidget2->GetRenderWindow(), this->m_ToFCaptureWidth, this->m_ToFCaptureHeight); - this->m_QmitkToFImageBackground2->UpdateBackground(this->m_Widget2Texture); - this->m_Widget2ImageType = m_Controls->m_ToFVisualisationSettingsWidget->GetWidget2ImageType(); - - this->m_QmitkToFImageBackground3 = new QmitkToFImageBackground(); - this->m_QmitkToFImageBackground3->AddRenderWindow(m_MultiWidget->mitkWidget3->GetRenderWindow(), this->m_ToFCaptureWidth, this->m_ToFCaptureHeight); - this->m_QmitkToFImageBackground3->UpdateBackground(this->m_Widget3Texture); - this->m_Widget3ImageType = m_Controls->m_ToFVisualisationSettingsWidget->GetWidget3ImageType(); } diff --git a/Modules/Bundles/org.mitk.gui.qt.tofutil/src/internal/QmitkToFUtilView.h b/Modules/Bundles/org.mitk.gui.qt.tofutil/src/internal/QmitkToFUtilView.h index 894fa016e8..204653aad4 100644 --- a/Modules/Bundles/org.mitk.gui.qt.tofutil/src/internal/QmitkToFUtilView.h +++ b/Modules/Bundles/org.mitk.gui.qt.tofutil/src/internal/QmitkToFUtilView.h @@ -1,278 +1,170 @@ /*========================================================================= 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. =========================================================================*/ #ifndef QmitkToFUtilView_h #define QmitkToFUtilView_h #include -#include "QmitkToFImageBackground.h" -#include +#include #include #include #include #include #include #include #include #include #include #include -#include - -typedef itk::Image ItkImageType2D; - /*! \brief QmitkToFUtilView - \warning This application is still under active development. Complete documentation will be added when class is finished. + Application that allows simple playing, recording, visualization, processing and measurement of Time-of-Flight (ToF) data. + Currently the following features are implemented: +
    +
  • Connecting and showing ToF data from various cameras (PMD CamCube 2/3, PMD CamBoard, PMD O3, MESA SwissRanger)
  • +
  • Recording and playing of ToF data
  • +
  • Color coded visualization of ToF images
  • +
  • Preprocessing of the distance data: Threshold, median, average and bilateral filtering; surface generation
  • +
  • Simple measurement and PointSet definition
  • +
\sa QmitkFunctionality \ingroup Functionalities */ class QmitkToFUtilView : public QmitkFunctionality { // this is needed for all Qt objects that should have a Qt meta-object // (everything that derives from QObject and wants to have signal/slots) Q_OBJECT public: static const std::string VIEW_ID; QmitkToFUtilView(); - QmitkToFUtilView(const QmitkToFUtilView& other) - { - Q_UNUSED(other) - throw std::runtime_error("Copy constructor not implemented"); - } ~QmitkToFUtilView(); virtual void CreateQtPartControl(QWidget *parent); /// \brief Called when the functionality is activated virtual void Activated(); + /// \brief Called when the functionality is deactivated virtual void Deactivated(); virtual void StdMultiWidgetAvailable (QmitkStdMultiWidget &stdMultiWidget); virtual void StdMultiWidgetNotAvailable(); protected slots: - /// \brief Called when the user clicks the GUI button + /*! + \brief Slot triggered from the timer to update the images and visualization + */ void OnUpdateCamera(); - - /*! - \This method is automatically called by the connection widgets when the configuration is completed + /*! + \brief Slot called when the "Connect" button of the ConnectionWidget is pressed */ void OnToFCameraConnected(); - + /*! + \brief Slot called when the "Disconnect" button of the ConnectionWidget is pressed + */ void OnToFCameraDisconnected(); - + /*! + \brief Slot called when the camera selection in the ConnectionWidget has changed + */ + void OnToFCameraSelected(const QString selected); + /*! + \brief Slot called when the "Start" button of the RecorderWidget is pressed + */ void OnToFCameraStarted(); - + /*! + \brief Slot called when the "Stop" button of the RecorderWidget is pressed + */ void OnToFCameraStopped(); - - void OnToFCameraStop(); - - void OnToFCameraSelected(const QString selected); - - void OnSurfaceCheckBoxChecked(bool checked); - + /*! + \brief Slot invoked when the texture checkbox is checked. Enables the scalar visibility of the surface + */ void OnTextureCheckBoxChecked(bool checked); - + /*! + \brief Slot invoked when the video texture checkbox is checked. Enables the texture of the surface + */ void OnVideoTextureCheckBoxChecked(bool checked); protected: - static ITK_THREAD_RETURN_TYPE OnUpdateCameraITKThread(void* pInfoStruct); - - static void UpdateCamera(); - - void InitImage(mitk::Image::Pointer image, int numOfChannel); - - void InitTexture(unsigned char* &image, int width, int height); - - //void PrepareBinaryLut(vtkLookupTable* lut, double minRange, double maxRange); - - //void PrepareColorLut(vtkLookupTable* lut, double minRange, double maxRange); - - void PrepareImageForBackground(vtkLookupTable* lut, float* floadData, unsigned char* image); - - void PrepareImageForBackground(vtkColorTransferFunction* colorTransferFunction, float* floatData, unsigned char* image); - - void RemoveBackground(); - - void AddBackground(); - -// void CreateSurface(); + /*! + \brief initialize the visibility settings of ToF data (images + surface) + \param useToF true: distance image: widget1, amplitude image: widget 2, intensity image: widget 3; false: standard + */ + void UseToFVisibilitySettings(bool useToF); Ui::QmitkToFUtilViewControls* m_Controls; QmitkStdMultiWidget* m_MultiWidget; - QTimer* m_Frametimer; - - //int m_FrameRate; - - mitk::ToFImageGrabber* m_ToFImageGrabber; - //mitk::ToFImageGrabber* m_ToFImageGrabber; - - mitk::Image::Pointer m_MitkInDistanceImage; ///< object to hold the distance image - - mitk::Image::Pointer m_MitkDistanceImage; ///< object to hold the distance image - - mitk::Image::Pointer m_MitkAmplitudeImage; ///< object to hold the amplitude image - - mitk::Image::Pointer m_MitkIntensityImage; ///< object to hold the amplitude image - - mitk::Image::Pointer m_MitkAllImage; ///< object to hold all image - - mitk::Image::Pointer m_MitkRawImage; ///< object to hold the raw image - - mitk::Image::Pointer m_SurfaceInputImage; - - mitk::Image::Pointer m_SurfaceTextureImage; - - mitk::Image::Pointer m_SurfaceIntensityImage; - - mitk::Surface::Pointer m_Surface; - - mitk::DataNode::Pointer m_DistanceImageNode; ///< DataNode to get the distance image into the DataStorage - - mitk::DataNode::Pointer m_AmplitudeImageNode; ///< DataNode to get the amplitude image into the DataStorage - - mitk::DataNode::Pointer m_IntensityImageNode; ///< DataNode to get the intensity image into the DataStorage - - mitk::DataNode::Pointer m_AllImageNode; ///< DataNode to get all images into the DataStorage - - mitk::DataNode::Pointer m_SurfaceNode; - - mitk::ToFImageRecorder::Pointer m_ToFImageRecorder; - - int m_ImageSequence; - - mitk::RealTimeClock::Pointer m_RealTimeClock; - - int m_StepsForFramerate; - - double m_TimeBefore, m_TimeAfter; - double m_SurfaceTimeBefore, m_SurfaceTimeAfter; - double m_2DTimeBefore, m_2DTimeAfter; - double m_2DTimeSum; - - QmitkVideoBackground* m_QmitkVideoBackground; - QmitkToFImageBackground* m_QmitkToFImageBackground1; - QmitkToFImageBackground* m_QmitkToFImageBackground2; - QmitkToFImageBackground* m_QmitkToFImageBackground3; - - mitk::OpenCVVideoSource::Pointer m_VideoSource; - unsigned char* m_VideoTexture; - unsigned char* m_Widget1Texture; - unsigned char* m_Widget2Texture; - unsigned char* m_Widget3Texture; - - vtkLookupTable* m_DistLut; - vtkLookupTable* m_AmplLut; - vtkLookupTable* m_IntenLut; - - int m_ToFCaptureWidth; - int m_ToFCaptureHeight; - int m_VideoCaptureWidth; - int m_VideoCaptureHeight; - -// mitk::ToFSurfaceGenerationFilter::Pointer m_ToFSurfaceGenerationFilter; - mitk::ToFDistanceImageToSurfaceFilter::Pointer m_ToFDistanceImageToSurfaceFilter; - - mitk::ToFCompositeFilter::Pointer m_ToFCompositeFilter; - mitk::ToFVisualizationFilter::Pointer m_ToFVisualizationFilter; + QTimer* m_Frametimer; ///< Timer used to continuously update the images + + mitk::Image::Pointer m_MitkDistanceImage; ///< member holding a pointer to the distance image of the selected camera + mitk::Image::Pointer m_MitkAmplitudeImage; ///< member holding a pointer to the amplitude image of the selected camera + mitk::Image::Pointer m_MitkIntensityImage; ///< member holding a pointer to the intensity image of the selected camera + mitk::Surface::Pointer m_Surface; ///< member holding a pointer to the surface generated from the distance image of the selected camera + + mitk::DataNode::Pointer m_DistanceImageNode; ///< DataNode holding the distance image of the selected camera + mitk::DataNode::Pointer m_AmplitudeImageNode; ///< DataNode holding the amplitude image of the selected camera + mitk::DataNode::Pointer m_IntensityImageNode; ///< DataNode holding the intensity image of the selected camera + mitk::DataNode::Pointer m_SurfaceNode; ///< DataNode holding the surface generated from the distanc image of the selected camera + + // ToF processing and recording filter + mitk::ToFImageRecorder::Pointer m_ToFImageRecorder; ///< ToF image recorder used for lossless recording of ToF image data + mitk::ToFImageGrabber::Pointer m_ToFImageGrabber; ///< Source of a ToF image processing pipeline. Provides pointers to distance, amplitude and intensity image + mitk::ToFDistanceImageToSurfaceFilter::Pointer m_ToFDistanceImageToSurfaceFilter; ///< Filter for calculating a surface representation from a given distance image + mitk::ToFCompositeFilter::Pointer m_ToFCompositeFilter; ///< Filter combining several processing steps (thresholding, Median filtering, Bilateral filtering) + + int m_SurfaceDisplayCount; ///< member used to determine whether surface is initialized or not + int m_2DDisplayCount; ///< member used to determine whether frame rate output should be shown + // members for calculating the frame rate + mitk::RealTimeClock::Pointer m_RealTimeClock; ///< real time clock used to calculate the display framerate + int m_StepsForFramerate; ///< number of steps used for calculating the display framerate + double m_2DTimeBefore; ///< holds the time stamp at the beginning of the display framerate measurement + double m_2DTimeAfter; ///< holds the time stamp at the end of the display framerate measurement + + // members used for displaying an external video source + mitk::OpenCVVideoSource::Pointer m_VideoSource; ///< OpenCV video source to connect a video device + unsigned char* m_VideoTexture; ///< texture used to show video image + int m_VideoCaptureWidth; ///< width of the video image + int m_VideoCaptureHeight; ///< height of the video image + bool m_VideoEnabled; ///< flag indicating whether video grabbing is enabled. Set via the RGB texture checkbox private: - void RemoveNode(const char* nodename, mitk::DataNode::Pointer node); - - void CreateNode(const char* nodename, mitk::DataNode::Pointer& node); - - void* GetDataFromImage(std::string imageType); - - ItkImageType2D::Pointer ProcessThresholdFilter(ItkImageType2D::Pointer inputItkImage, int min, int max); - - void ProcessCVThresholdFilter(IplImage* inputIplImage, int min, int max); - - void ProcessCVEdgeFilter(IplImage* inputIplImage, float threshold); - - ItkImageType2D::Pointer ProcessItkBilateralFilter(ItkImageType2D::Pointer inputItkImage, int domainSigma, int rangeSigma, int kernelRadius); - - void ProcessCVBilateralFilter(IplImage* inputIplImage, IplImage* outputIplImage, int domainSigma, int rangeSigma, int kernelRadius); - - void ProcessCVMedianFilter(IplImage* inputIplImage, IplImage* outputIplImage, int radius = 3); - - void ProcessStreamedAverageImageFilter(float* data, int numOfImages); - - void ProcessStreamedMedianImageFilter(float* data, int numOfImages); - - void ProcessStreamedQuickSelectMedianImageFilter(IplImage* inputIplImage, int numOfImages); - - float quick_select(float arr[], int n); - - void AddNodesToDataStorage(); - - void RenderWidget(QmitkRenderWindow* mitkWidget, QmitkToFImageBackground* imageBackground, std::string& oldImageType, std::string newImageType, - vtkColorTransferFunction* colorTransferFunction, unsigned char* videoTexture, unsigned char* tofTexture ); - - void SetBilateralFilterParameter(); - - void SetThresholdFilterParameter(); + /*! + \brief helper method to replace data of the specified node. If node does not exist it will be created + \param nodeName Name of the node + \param data Data object to be replaced + \return returns the node + */ + mitk::DataNode::Pointer ReplaceNodeData(std::string nodeName, mitk::BaseData* data); void ProcessVideoTransform(); - bool m_DataNodesInitilized; - - bool m_TransferFunctionInitialized; - - bool m_SurfaceInitialized; - - float** m_DataBuffer; - int m_DataBufferCurrentIndex; - int m_DataBufferMaxSize; - - int** m_IndexBuffer; - - int m_SurfaceDisplayCount; - int m_2DDisplayCount; - bool m_VideoEnabled; - - IplImage* m_IplDistanceImage; - IplImage* m_IplIntensityImage; - IplImage* m_OutputIplImage; - - std::string m_Widget1ImageType; - std::string m_Widget2ImageType; - std::string m_Widget3ImageType; - mitk::ToFSurfaceVtkMapper3D::Pointer m_ToFSurfaceVtkMapper3D; - - ItkImageType2D::Pointer m_ItkInputImage; - ItkImageType2D::Pointer m_ItkOutputImage; - }; - - #endif // _QMITKTOFUTILVIEW_H_INCLUDED diff --git a/Modules/Bundles/org.mitk.gui.qt.tofutil/src/internal/QmitkToFUtilViewControls.ui b/Modules/Bundles/org.mitk.gui.qt.tofutil/src/internal/QmitkToFUtilViewControls.ui index 8e29f45e88..9068c86efd 100644 --- a/Modules/Bundles/org.mitk.gui.qt.tofutil/src/internal/QmitkToFUtilViewControls.ui +++ b/Modules/Bundles/org.mitk.gui.qt.tofutil/src/internal/QmitkToFUtilViewControls.ui @@ -1,152 +1,162 @@ QmitkToFUtilViewControls 0 0 466 452 0 0 QmitkTemplate 0 0 0 0 0 0 true 0 0 Surface Surface true RGB Texture - true + false Texture + + + Qt::Vertical 20 311 m_ToFConnectionWidget m_ToFRecorderWidget m_ToFVisualisationSettingsWidget groupBox_3 verticalSpacer m_ToFCompositeFilterWidget + tofMeasurementWidget QmitkToFConnectionWidget QWidget
QmitkToFConnectionWidget.h
1
QmitkToFRecorderWidget QWidget
QmitkToFRecorderWidget.h
1
QmitkToFVisualisationSettingsWidget QWidget
QmitkToFVisualisationSettingsWidget.h
1
QmitkToFCompositeFilterWidget QWidget
QmitkToFCompositeFilterWidget.h
1
+ + QmitkToFPointSetWidget + QWidget +
QmitkToFPointSetWidget.h
+ 1 +
diff --git a/Modules/ToFHardware/mitkToFCameraMITKPlayerDevice.cpp b/Modules/ToFHardware/mitkToFCameraMITKPlayerDevice.cpp index 5462df4087..7d1d702e61 100644 --- a/Modules/ToFHardware/mitkToFCameraMITKPlayerDevice.cpp +++ b/Modules/ToFHardware/mitkToFCameraMITKPlayerDevice.cpp @@ -1,370 +1,373 @@ /*========================================================================= 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 "mitkToFCameraMITKPlayerDevice.h" #include "mitkToFCameraMITKPlayerController.h" #include "mitkRealTimeClock.h" #include "itkMultiThreader.h" #include namespace mitk { ToFCameraMITKPlayerDevice::ToFCameraMITKPlayerDevice() : m_DistanceDataBuffer(NULL), m_IntensityDataBuffer(NULL), m_AmplitudeDataBuffer(NULL) { m_Controller = ToFCameraMITKPlayerController::New(); } ToFCameraMITKPlayerDevice::~ToFCameraMITKPlayerDevice() { DisconnectCamera(); CleanUpDataBuffers(); } bool ToFCameraMITKPlayerDevice::ConnectCamera() { bool ok = m_Controller->OpenCameraConnection(); if (ok) { this->m_CaptureWidth = m_Controller->GetCaptureWidth(); this->m_CaptureHeight = m_Controller->GetCaptureHeight(); this->m_PixelNumber = this->m_CaptureWidth * this->m_CaptureHeight; AllocatePixelArrays(); AllocateDataBuffers(); m_CameraConnected = true; } return ok; } bool ToFCameraMITKPlayerDevice::DisconnectCamera() { bool ok = m_Controller->CloseCameraConnection(); if (ok) { m_CameraConnected = false; } return ok; } void ToFCameraMITKPlayerDevice::StartCamera() { if (m_CameraConnected) { // get the first image this->m_Controller->UpdateCamera(); this->m_ImageMutex->Lock(); this->m_Controller->GetDistances(this->m_DistanceDataBuffer[this->m_FreePos]); this->m_Controller->GetAmplitudes(this->m_AmplitudeDataBuffer[this->m_FreePos]); this->m_Controller->GetIntensities(this->m_IntensityDataBuffer[this->m_FreePos]); this->m_FreePos = (this->m_FreePos+1) % this->m_BufferSize; this->m_CurrentPos = (this->m_CurrentPos+1) % this->m_BufferSize; this->m_ImageSequence++; this->m_ImageMutex->Unlock(); this->m_CameraActiveMutex->Lock(); this->m_CameraActive = true; this->m_CameraActiveMutex->Unlock(); this->m_ThreadID = this->m_MultiThreader->SpawnThread(this->Acquire, this); // wait a little to make sure that the thread is started itksys::SystemTools::Delay(10); } else { MITK_INFO<<"Camera not connected"; } } void ToFCameraMITKPlayerDevice::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(100); } bool ToFCameraMITKPlayerDevice::IsCameraActive() { m_CameraActiveMutex->Lock(); bool ok = m_CameraActive; m_CameraActiveMutex->Unlock(); return ok; } void ToFCameraMITKPlayerDevice::UpdateCamera() { m_Controller->UpdateCamera(); } ITK_THREAD_RETURN_TYPE ToFCameraMITKPlayerDevice::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; } ToFCameraMITKPlayerDevice* toFCameraDevice = (ToFCameraMITKPlayerDevice*)pInfo->UserData; if (toFCameraDevice!=NULL) { mitk::RealTimeClock::Pointer realTimeClock; realTimeClock = mitk::RealTimeClock::New(); int n = 100; double t1, t2; t1 = realTimeClock->GetCurrentStamp(); bool overflow = false; bool printStatus = false; while (toFCameraDevice->IsCameraActive()) { // update the ToF camera toFCameraDevice->UpdateCamera(); // get image data from controller and write it to the according buffer toFCameraDevice->m_Controller->GetDistances(toFCameraDevice->m_DistanceDataBuffer[toFCameraDevice->m_FreePos]); toFCameraDevice->m_Controller->GetAmplitudes(toFCameraDevice->m_AmplitudeDataBuffer[toFCameraDevice->m_FreePos]); toFCameraDevice->m_Controller->GetIntensities(toFCameraDevice->m_IntensityDataBuffer[toFCameraDevice->m_FreePos]); toFCameraDevice->Modified(); /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! TODO Buffer Handling currently only works for buffer size 1 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/ toFCameraDevice->m_ImageMutex->Lock(); toFCameraDevice->m_FreePos = (toFCameraDevice->m_FreePos+1) % toFCameraDevice->m_BufferSize; toFCameraDevice->m_CurrentPos = (toFCameraDevice->m_CurrentPos+1) % toFCameraDevice->m_BufferSize; toFCameraDevice->m_ImageSequence++; if (toFCameraDevice->m_FreePos == toFCameraDevice->m_CurrentPos) { // buffer overflow //MITK_INFO << "Buffer overflow!! "; //toFCameraDevice->m_CurrentPos = (toFCameraDevice->m_CurrentPos+1) % toFCameraDevice->m_BufferSize; //toFCameraDevice->m_ImageSequence++; overflow = true; } if (toFCameraDevice->m_ImageSequence % n == 0) { printStatus = true; } toFCameraDevice->m_ImageMutex->Unlock(); if (overflow) { //itksys::SystemTools::Delay(10); overflow = false; } /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! END TODO Buffer Handling currently only works for buffer size 1 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/ // print current framerate if (printStatus) { t2 = realTimeClock->GetCurrentStamp() - t1; MITK_INFO << " 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 ToFCameraMITKPlayerDevice::ResetBuffer(int bufferSize) // { // this->m_BufferSize = bufferSize; // this->m_CurrentPos = -1; // this->m_FreePos = 0; // } void ToFCameraMITKPlayerDevice::GetAmplitudes(float* amplitudeArray, int& imageSequence) { m_ImageMutex->Lock(); /*!!!!!!!!!!!!!!!!!!!!!! TODO Buffer handling??? !!!!!!!!!!!!!!!!!!!!!!!!*/ // write amplitude image data to float array for (int i=0; im_PixelNumber; i++) { amplitudeArray[i] = this->m_AmplitudeDataBuffer[this->m_CurrentPos][i]; } imageSequence = this->m_ImageSequence; m_ImageMutex->Unlock(); } void ToFCameraMITKPlayerDevice::GetIntensities(float* intensityArray, int& imageSequence) { m_ImageMutex->Lock(); /*!!!!!!!!!!!!!!!!!!!!!! TODO Buffer handling??? !!!!!!!!!!!!!!!!!!!!!!!!*/ // write intensity image data to float array for (int i=0; im_PixelNumber; i++) { intensityArray[i] = this->m_IntensityDataBuffer[this->m_CurrentPos][i]; } imageSequence = this->m_ImageSequence; m_ImageMutex->Unlock(); } void ToFCameraMITKPlayerDevice::GetDistances(float* distanceArray, int& imageSequence) { m_ImageMutex->Lock(); /*!!!!!!!!!!!!!!!!!!!!!! TODO Buffer handling??? !!!!!!!!!!!!!!!!!!!!!!!!*/ // write distance image data to float array for (int i=0; im_PixelNumber; i++) { distanceArray[i] = this->m_DistanceDataBuffer[this->m_CurrentPos][i]; } imageSequence = this->m_ImageSequence; m_ImageMutex->Unlock(); } void ToFCameraMITKPlayerDevice::GetAllImages(float* distanceArray, float* amplitudeArray, float* intensityArray, char* sourceDataArray, int requiredImageSequence, int& capturedImageSequence) { /*!!!!!!!!!!!!!!!!!!!!!! TODO Document this method! !!!!!!!!!!!!!!!!!!!!!!!!*/ m_ImageMutex->Lock(); //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; } 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; } else // (requiredImageSequence > this->m_ImageSequence - this->m_BufferSize) && (requiredImageSequence <= this->m_ImageSequence) { capturedImageSequence = requiredImageSequence; pos = (this->m_CurrentPos + (10-(this->m_ImageSequence - requiredImageSequence))) % this->m_BufferSize; } - // write image data to float arrays - for (int i=0; im_PixelNumber; i++) + if(this->m_DistanceDataBuffer&&this->m_AmplitudeDataBuffer&&this->m_IntensityDataBuffer) { - distanceArray[i] = this->m_DistanceDataBuffer[pos][i]; - amplitudeArray[i] = this->m_AmplitudeDataBuffer[pos][i]; - intensityArray[i] = this->m_IntensityDataBuffer[pos][i]; + // write image data to float arrays + for (int i=0; im_PixelNumber; i++) + { + distanceArray[i] = this->m_DistanceDataBuffer[pos][i]; + amplitudeArray[i] = this->m_AmplitudeDataBuffer[pos][i]; + intensityArray[i] = this->m_IntensityDataBuffer[pos][i]; + } } m_ImageMutex->Unlock(); } void ToFCameraMITKPlayerDevice::SetInputFileName(std::string inputFileName) { this->m_InputFileName = inputFileName; this->m_Controller->SetInputFileName(inputFileName); } void ToFCameraMITKPlayerDevice::SetProperty( const char *propertyKey, BaseProperty* propertyValue ) { this->m_PropertyList->SetProperty(propertyKey, propertyValue); ToFCameraMITKPlayerController::Pointer myController = dynamic_cast(this->m_Controller.GetPointer()); std::string strValue; GetStringProperty(propertyValue, strValue); if (strcmp(propertyKey, "DistanceImageFileName") == 0) { myController->SetDistanceImageFileName(strValue); } else if (strcmp(propertyKey, "AmplitudeImageFileName") == 0) { myController->SetAmplitudeImageFileName(strValue); } else if (strcmp(propertyKey, "IntensityImageFileName") == 0) { myController->SetIntensityImageFileName(strValue); } } void ToFCameraMITKPlayerDevice::CleanUpDataBuffers() { if (m_DistanceDataBuffer) { for(int i=0; im_MaxBufferSize; i++) { delete[] this->m_DistanceDataBuffer[i]; } delete[] this->m_DistanceDataBuffer; } if (m_AmplitudeDataBuffer) { for(int i=0; im_MaxBufferSize; i++) { delete[] this->m_AmplitudeDataBuffer[i]; } delete[] this->m_AmplitudeDataBuffer; } if (m_IntensityDataBuffer) { for(int i=0; im_MaxBufferSize; i++) { delete[] this->m_IntensityDataBuffer[i]; } delete[] this->m_IntensityDataBuffer; } } void ToFCameraMITKPlayerDevice::AllocateDataBuffers() { // free memory if it was already allocated this->CleanUpDataBuffers(); // allocate buffers this->m_DistanceDataBuffer = new float*[this->m_MaxBufferSize]; for(int i=0; im_MaxBufferSize; i++) { this->m_DistanceDataBuffer[i] = new float[this->m_PixelNumber]; } this->m_AmplitudeDataBuffer = new float*[this->m_MaxBufferSize]; for(int i=0; im_MaxBufferSize; i++) { this->m_AmplitudeDataBuffer[i] = new float[this->m_PixelNumber]; } this->m_IntensityDataBuffer = new float*[this->m_MaxBufferSize]; for(int i=0; im_MaxBufferSize; i++) { this->m_IntensityDataBuffer[i] = new float[this->m_PixelNumber]; } } } diff --git a/Modules/ToFProcessing/mitkToFDistanceImageToSurfaceFilter.cpp b/Modules/ToFProcessing/mitkToFDistanceImageToSurfaceFilter.cpp index bd84dc462b..06b6881d83 100644 --- a/Modules/ToFProcessing/mitkToFDistanceImageToSurfaceFilter.cpp +++ b/Modules/ToFProcessing/mitkToFDistanceImageToSurfaceFilter.cpp @@ -1,253 +1,253 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit Module: $RCSfile$ Language: C++ Date: $Date$ Version: $Revision$ Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notices for more information. =========================================================================*/ #include #include #include #include #include #include #include #include #include #include #include #include #include mitk::ToFDistanceImageToSurfaceFilter::ToFDistanceImageToSurfaceFilter(): m_CameraIntrinsics(), -m_TextureImageWidth(0), m_TextureImageHeight(0), m_IplScalarImage(NULL), m_InterPixelDistance() + m_TextureImageWidth(0), m_TextureImageHeight(0), m_IplScalarImage(NULL), m_InterPixelDistance(), m_TextureIndex(0) { m_InterPixelDistance.Fill(0.045); m_CameraIntrinsics = mitk::CameraIntrinsics::New(); m_CameraIntrinsics->SetFocalLength(295.78960196187319,296.1255427948447); m_CameraIntrinsics->SetPrincipalPoint(113.29063841714108,97.243216122015184); m_CameraIntrinsics->SetDistorsionCoeffs(-0.36874385358645773f,-0.14339503290129013,0.0033210108720361795,-0.004277703352074105); } mitk::ToFDistanceImageToSurfaceFilter::~ToFDistanceImageToSurfaceFilter() { } void mitk::ToFDistanceImageToSurfaceFilter::SetInput( Image* distanceImage, mitk::CameraIntrinsics::Pointer cameraIntrinsics ) { this->SetCameraIntrinsics(cameraIntrinsics); this->SetInput(0,distanceImage); } void mitk::ToFDistanceImageToSurfaceFilter::SetInput( unsigned int idx, Image* distanceImage, mitk::CameraIntrinsics::Pointer cameraIntrinsics ) { this->SetCameraIntrinsics(cameraIntrinsics); this->SetInput(idx,distanceImage); } void mitk::ToFDistanceImageToSurfaceFilter::SetInput( mitk::Image* distanceImage ) { this->SetInput(0,distanceImage); } //TODO: braucht man diese Methode? void mitk::ToFDistanceImageToSurfaceFilter::SetInput( unsigned int idx, mitk::Image* distanceImage ) { if ((distanceImage == NULL) && (idx == this->GetNumberOfInputs() - 1)) // if the last input is set to NULL, reduce the number of inputs by one this->SetNumberOfInputs(this->GetNumberOfInputs() - 1); else this->ProcessObject::SetNthInput(idx, distanceImage); // Process object is not const-correct so the const_cast is required here this->CreateOutputsForAllInputs(); } mitk::Image* mitk::ToFDistanceImageToSurfaceFilter::GetInput() { return this->GetInput(0); } mitk::Image* mitk::ToFDistanceImageToSurfaceFilter::GetInput( unsigned int idx ) { if (this->GetNumberOfInputs() < 1) return NULL; //TODO: geeignete exception werfen return static_cast< mitk::Image*>(this->ProcessObject::GetInput(idx)); } void mitk::ToFDistanceImageToSurfaceFilter::GenerateData() { mitk::Surface::Pointer output = this->GetOutput(); assert(output); mitk::Image::Pointer input = this->GetInput(); assert(input); // mesh points unsigned int xDimension = input->GetDimension(0); unsigned int yDimension = input->GetDimension(1); unsigned int size = xDimension*yDimension; //size of the image-array std::vector isPointValid; isPointValid.resize(size); int pointCount = 0; vtkSmartPointer points = vtkSmartPointer::New(); points->SetDataTypeToDouble(); vtkSmartPointer polys = vtkSmartPointer::New(); vtkSmartPointer scalarArray = vtkSmartPointer::New(); vtkSmartPointer textureCoords = vtkSmartPointer::New(); textureCoords->SetNumberOfComponents(2); float textureScaleCorrection1 = 0.0; float textureScaleCorrection2 = 0.0; if (this->m_TextureImageHeight > 0.0 && this->m_TextureImageWidth > 0.0) { textureScaleCorrection1 = float(this->m_TextureImageHeight) / float(this->m_TextureImageWidth); textureScaleCorrection2 = ((float(this->m_TextureImageWidth) - float(this->m_TextureImageHeight))/2) / float(this->m_TextureImageWidth); } float* scalarFloatData = NULL; if (this->m_IplScalarImage) // if scalar image is defined use it for texturing { scalarFloatData = (float*)this->m_IplScalarImage->imageData; } - else if ((this->GetNumberOfInputs()>2)&&this->GetInput(2)) // otherwise use intensity image (input(2)) + else if (this->GetInput(m_TextureIndex)) // otherwise use intensity image (input(2)) { - scalarFloatData = (float*)this->GetInput(2)->GetData(); + scalarFloatData = (float*)this->GetInput(m_TextureIndex)->GetData(); } float* inputFloatData = (float*)(input->GetSliceData(0, 0, 0)->GetData()); //calculate world coordinates mitk::ToFProcessingCommon::ToFScalarType focalLength = (m_CameraIntrinsics->GetFocalLengthX()*m_InterPixelDistance[0]+m_CameraIntrinsics->GetFocalLengthY()*m_InterPixelDistance[1])/2.0; mitk::ToFProcessingCommon::ToFPoint2D principalPoint; principalPoint[0] = m_CameraIntrinsics->GetPrincipalPointX(); principalPoint[1] = m_CameraIntrinsics->GetPrincipalPointY(); for (int j=0; jInsertPoint(pixelID, cartesianCoordinates.GetDataPointer()); if((i >= 1) && (j >= 1)) { vtkIdType xy = i+j*xDimension; vtkIdType x_1y = i-1+j*xDimension; vtkIdType xy_1 = i+(j-1)*xDimension; vtkIdType x_1y_1 = (i-1)+(j-1)*xDimension; if (isPointValid[xy]&&isPointValid[x_1y]&&isPointValid[x_1y_1]&&isPointValid[xy_1]) // check if points of cell are valid { polys->InsertNextCell(3); polys->InsertCellPoint(x_1y); polys->InsertCellPoint(xy); polys->InsertCellPoint(x_1y_1); polys->InsertNextCell(3); polys->InsertCellPoint(x_1y_1); polys->InsertCellPoint(xy); polys->InsertCellPoint(xy_1); } } if (scalarFloatData) { scalarArray->InsertTuple1(pixelID, scalarFloatData[pixel[0]+pixel[1]*xDimension]); //scalarArray->InsertTuple1(pixelID, scalarFloatData[pixelID]); } if (this->m_TextureImageHeight > 0.0 && this->m_TextureImageWidth > 0.0) { float xNorm = (((float)pixel[0])/xDimension)*textureScaleCorrection1 + textureScaleCorrection2 ; // correct video texture scale 640 * 480!! float yNorm = 1.0 - ((float)pixel[1])/yDimension; //flip y-axis textureCoords->InsertTuple2(pixelID, xNorm, yNorm); } } pointCount++; } } vtkSmartPointer mesh = vtkSmartPointer::New(); mesh->SetPoints(points); mesh->SetPolys(polys); if (scalarArray->GetNumberOfTuples()>0) { mesh->GetPointData()->SetScalars(scalarArray); if (this->m_TextureImageHeight > 0.0 && this->m_TextureImageWidth > 0.0) { mesh->GetPointData()->SetTCoords(textureCoords); } } output->SetVtkPolyData(mesh); } void mitk::ToFDistanceImageToSurfaceFilter::CreateOutputsForAllInputs() { this->SetNumberOfOutputs(this->GetNumberOfInputs()); // create outputs for all inputs for (unsigned int idx = 0; idx < this->GetNumberOfOutputs(); ++idx) if (this->GetOutput(idx) == NULL) { DataObjectPointer newOutput = this->MakeOutput(idx); this->SetNthOutput(idx, newOutput); } this->Modified(); } void mitk::ToFDistanceImageToSurfaceFilter::GenerateOutputInformation() { this->GetOutput(); itkDebugMacro(<<"GenerateOutputInformation()"); } void mitk::ToFDistanceImageToSurfaceFilter::SetScalarImage(IplImage* iplScalarImage) { this->m_IplScalarImage = iplScalarImage; this->Modified(); } IplImage* mitk::ToFDistanceImageToSurfaceFilter::GetScalarImage() { return this->m_IplScalarImage; } void mitk::ToFDistanceImageToSurfaceFilter::SetTextureImageWidth(int width) { this->m_TextureImageWidth = width; } void mitk::ToFDistanceImageToSurfaceFilter::SetTextureImageHeight(int height) { this->m_TextureImageHeight = height; } diff --git a/Modules/ToFProcessing/mitkToFDistanceImageToSurfaceFilter.h b/Modules/ToFProcessing/mitkToFDistanceImageToSurfaceFilter.h index 70211c39b1..88fed281fe 100644 --- a/Modules/ToFProcessing/mitkToFDistanceImageToSurfaceFilter.h +++ b/Modules/ToFProcessing/mitkToFDistanceImageToSurfaceFilter.h @@ -1,152 +1,155 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit Module: $RCSfile$ Language: C++ Date: $Date$ Version: $Revision$ Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notices for more information. =========================================================================*/ #ifndef __mitkToFDistanceImageToSurfaceFilter_h #define __mitkToFDistanceImageToSurfaceFilter_h #include #include #include #include #include #include "mitkCameraIntrinsics.h" #include #include namespace mitk { /** * @brief Converts a Time-of-Flight (ToF) distance image to a 3D surface using the pinhole camera model for coordinate computation. * The intrinsic parameters of the camera (FocalLength, PrincipalPoint, InterPixelDistance) are set via SetCameraIntrinsics(). The * measured distance for each pixel corresponds to the distance between the object point and the corresponding image point on the * image plane. * * The coordinate conversion follows the model of a common pinhole camera where the origin of the camera * coordinate system (world coordinates) is at the pinhole * \image html ../Modules/ToFProcessing/Documentation/PinholeCameraModel.png * The definition of the image plane and its coordinate systems (pixel and mm) is depicted in the following image * \image html ../Modules/ToFProcessing/Documentation/ImagePlane.png * * @ingroup SurfaceFilters * @ingroup ToFProcessing */ class mitkToFProcessing_EXPORT ToFDistanceImageToSurfaceFilter : public SurfaceSource { public: mitkClassMacro( ToFDistanceImageToSurfaceFilter , SurfaceSource ); itkNewMacro( Self ); itkSetMacro(CameraIntrinsics, mitk::CameraIntrinsics::Pointer); itkGetMacro(CameraIntrinsics, mitk::CameraIntrinsics::Pointer); itkSetMacro(InterPixelDistance,ToFProcessingCommon::ToFPoint2D); itkGetMacro(InterPixelDistance,ToFProcessingCommon::ToFPoint2D); + itkSetMacro(TextureIndex,int); /*! \brief Set scalar image used as texture of the surface. \param iplScalarImage OpenCV image for texturing */ void SetScalarImage(IplImage* iplScalarImage); /*! \brief Set scalar image used as texture of the surface. \return OpenCV image for texturing */ IplImage* GetScalarImage(); /*! \brief Set width of the scalar image used for texturing the surface \param width width (x-dimension) of the texture image */ void SetTextureImageWidth(int width); /*! \brief Set height of the scalar image used for texturing the surface \param height height (y-dimension) of the texture image */ void SetTextureImageHeight(int height); /*! \brief Sets the input of this filter \param distanceImage input is the distance image of e.g. a ToF camera */ virtual void SetInput( Image* distanceImage); /*! \brief Sets the input of this filter and the intrinsic parameters \param distanceImage input is the distance image of e.g. a ToF camera */ virtual void SetInput( Image* distanceImage, mitk::CameraIntrinsics::Pointer cameraIntrinsics ); /*! \brief Sets the input of this filter at idx \param idx number of the current input \param distanceImage input is the distance image of e.g. a ToF camera */ virtual void SetInput(unsigned int idx, Image* distanceImage); /*! \brief Sets the input of this filter at idx and the intrinsic parameters \param idx number of the current input \param distanceImage input is the distance image of e.g. a ToF camera \param cameraIntrinsics This is the camera model which holds parameters like focal length, pixel size, etc. which are needed for the reconstruction of the surface. */ virtual void SetInput( unsigned int idx, Image* distanceImage, mitk::CameraIntrinsics::Pointer cameraIntrinsics ); /*! \brief Returns the input of this filter */ Image* GetInput(); /*! \brief Returns the input with id idx of this filter */ Image* GetInput(unsigned int idx); protected: /*! \brief Standard constructor */ ToFDistanceImageToSurfaceFilter(); /*! \brief Standard destructor */ ~ToFDistanceImageToSurfaceFilter(); virtual void GenerateOutputInformation(); /*! \brief Method generating the output of this filter. Called in the updated process of the pipeline. This method generates the output of the ToFSurfaceSource: The generated surface of the 3d points */ virtual void GenerateData(); /** * \brief Create an output for each input * * This Method sets the number of outputs to the number of inputs * and creates missing outputs objects. * \warning any additional outputs that exist before the method is called are deleted */ void CreateOutputsForAllInputs(); IplImage* m_IplScalarImage; ///< Scalar image used for surface texturing mitk::CameraIntrinsics::Pointer m_CameraIntrinsics; ///< Specifies the intrinsic parameters //mitk::CameraIntrinsics::Pointer m_CameraModel; ///< Specifies the intrinsic parameters int m_TextureImageWidth; ///< Width (x-dimension) of the texture image int m_TextureImageHeight; ///< Height (y-dimension) of the texture image ToFProcessingCommon::ToFPoint2D m_InterPixelDistance; ///< distance in mm between two adjacent pixels on the ToF camera chip + int m_TextureIndex; ///< Index of the input used as texture image when no scalar image was set via SetIplScalarImage(). 0 = Distance, 1 = Amplitude, 2 = Intensity + }; } //END mitk namespace #endif diff --git a/Modules/ToFUI/CMakeLists.txt b/Modules/ToFUI/CMakeLists.txt index 9f165e73c1..7320e2a23a 100644 --- a/Modules/ToFUI/CMakeLists.txt +++ b/Modules/ToFUI/CMakeLists.txt @@ -1,8 +1,8 @@ MITK_CREATE_MODULE(mitkTOFUI SUBPROJECTS MITK-ToF INCLUDE_DIRS Qmitk - DEPENDS mitkToFHardware mitkToFProcessing Qmitk QmitkExt + DEPENDS mitkToFHardware mitkToFProcessing Qmitk QmitkExt Overlays QT_MODULE GENERATED_CPP ${TOOL_GUI_CPPS} ${TOOL_CPPS} ) diff --git a/Modules/ToFUI/Qmitk/QmitkToFConnectionWidget.cpp b/Modules/ToFUI/Qmitk/QmitkToFConnectionWidget.cpp index e414b294fe..3ec6e9ea2d 100644 --- a/Modules/ToFUI/Qmitk/QmitkToFConnectionWidget.cpp +++ b/Modules/ToFUI/Qmitk/QmitkToFConnectionWidget.cpp @@ -1,442 +1,346 @@ /*========================================================================= 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")|| (selectedCamera=="PMD CamBoardRaw")||(selectedCamera=="PMD CamCubeRaw") ) { ShowPMDParameterWidget(); } else if (selectedCamera=="MESA Swissranger 4000") { ShowMESAParameterWidget(); } else { this->m_Controls->m_PMDParameterWidget->hide(); this->m_Controls->m_MESAParameterWidget->hide(); } } void QmitkToFConnectionWidget::ShowPMDParameterWidget() { this->m_Controls->m_PMDParameterWidget->show(); this->m_Controls->m_MESAParameterWidget->hide(); } void QmitkToFConnectionWidget::ShowMESAParameterWidget() { this->m_Controls->m_PMDParameterWidget->hide(); this->m_Controls->m_MESAParameterWidget->show(); } void QmitkToFConnectionWidget::ShowPlayerParameterWidget() { this->m_Controls->m_PMDParameterWidget->hide(); this->m_Controls->m_MESAParameterWidget->hide(); } mitk::ToFImageGrabber* QmitkToFConnectionWidget::GetToFImageGrabber() { return m_ToFImageGrabber; } void QmitkToFConnectionWidget::OnSelectCamera(const QString selectedText) { if (selectedText == "PMD CamCube 2.0/3.0" || 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" || selectedText == "PMD CamBoardRaw" ) // pmd camboard { - //m_Controls->m_IntegrationTimeSpinBox->setEnabled(true); - //m_Controls->m_ModulationFrequencySpinBox->setEnabled(true); - //m_Controls->m_CalibrationParameterGroupBox->setEnabled(false); ShowPMDParameterWidget(); } else if (selectedText == "PMD O3D") // pmd O3d { - //m_Controls->m_IntegrationTimeSpinBox->setEnabled(true); - //m_Controls->m_ModulationFrequencySpinBox->setEnabled(true); - //m_Controls->m_CalibrationParameterGroupBox->setEnabled(false); ShowPMDParameterWidget(); } else if (selectedText == "MESA Swissranger 4000") // MESA 4000 { ShowMESAParameterWidget(); } else if (selectedText == "PMD Player") // pmd file player { - //m_Controls->m_IntegrationTimeSpinBox->setEnabled(false); - //m_Controls->m_ModulationFrequencySpinBox->setEnabled(false); - //m_Controls->m_CalibrationParameterGroupBox->setEnabled(false); ShowPlayerParameterWidget(); } else if (selectedText == "PMD Raw Data Player") // pmd raw data player { - //m_Controls->m_IntegrationTimeSpinBox->setEnabled(false); - //m_Controls->m_ModulationFrequencySpinBox->setEnabled(false); - //m_Controls->m_CalibrationParameterGroupBox->setEnabled(false); ShowPlayerParameterWidget(); } else if (selectedText == "MITK Player") // mitk player { - //m_Controls->m_IntegrationTimeSpinBox->setEnabled(false); - //m_Controls->m_ModulationFrequencySpinBox->setEnabled(false); - //m_Controls->m_CalibrationParameterGroupBox->setEnabled(false); ShowPlayerParameterWidget(); } } void QmitkToFConnectionWidget::OnConnectCamera() { bool playerMode = false; if (m_Controls->m_ConnectCameraButton->text()=="Connect") { //reset the status of the GUI buttons m_Controls->m_ConnectCameraButton->setEnabled(false); m_Controls->m_SelectCameraCombobox->setEnabled(false); -// m_Controls->m_CalibrationParameterGroupBox->setEnabled(false); //repaint the widget this->repaint(); QString tmpFileName(""); QString fileFilter(""); //select the camera to connect with QString selectedCamera = m_Controls->m_SelectCameraCombobox->currentText(); if (selectedCamera == "PMD CamCube 2.0/3.0") { //PMD CamCube this->m_ToFImageGrabber = mitk::ToFImageGrabberCreator::GetInstance()->GetPMDCamCubeImageGrabber(); } else if (selectedCamera == "PMD CamCubeRaw 2.0/3.0") { //PMD CamCube this->m_ToFImageGrabber = mitk::ToFImageGrabberCreator::GetInstance()->GetPMDRawDataCamCubeImageGrabber(); } else if (selectedCamera == "PMD CamBoard") { //PMD CamBoard this->m_ToFImageGrabber = mitk::ToFImageGrabberCreator::GetInstance()->GetPMDCamBoardImageGrabber(); } else if (selectedCamera == "PMD CamBoardRaw") { //PMD CamBoard this->m_ToFImageGrabber = mitk::ToFImageGrabberCreator::GetInstance()->GetPMDRawDataCamBoardImageGrabber(); } else if (selectedCamera == "PMD O3D") {//PMD O3 this->m_ToFImageGrabber = mitk::ToFImageGrabberCreator::GetInstance()->GetPMDO3ImageGrabber(); } else if (selectedCamera == "MESA Swissranger 4000") {//MESA SR4000 this->m_ToFImageGrabber = mitk::ToFImageGrabberCreator::GetInstance()->GetMESASR4000ImageGrabber(); } else if (selectedCamera == "PMD Player") {//PMD player playerMode = true; fileFilter.append("PMD Files (*.pmd)"); this->m_ToFImageGrabber = mitk::ToFImageGrabberCreator::GetInstance()->GetPMDPlayerImageGrabber(); } else if (selectedCamera == "PMD Raw Data Player") {//PMD MITK player playerMode = true; fileFilter.append("NRRD Images (*.nrrd);;PIC Images - deprecated (*.pic)"); this->m_ToFImageGrabber = mitk::ToFImageGrabberCreator::GetInstance()->GetPMDMITKPlayerImageGrabber(); } else if (selectedCamera == "MITK Player") {//MITK player playerMode = true; fileFilter.append("NRRD Images (*.nrrd);;PIC Images - deprecated (*.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); this->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" && extension != ".nrrd") { msg = msg + "Invalid file format, please select a \".nrrd\"-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); this->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")|| (selectedCamera=="PMD CamBoardRaw")||(selectedCamera=="PMD CamCubeRaw")) { this->m_Controls->m_PMDParameterWidget->ActivateAllParameters(); } else if (selectedCamera=="MESA Swissranger 4000") { this->m_Controls->m_MESAParameterWidget->ActivateAllParameters(); } - - -/* - //get the integration time and modulation frequency - this->m_IntegrationTime = m_Controls->m_IntegrationTimeSpinBox->value(); - this->m_ModulationFrequency = m_Controls->m_ModulationFrequencySpinBox->value(); - - //set the integration time and modulation frequency in the grabber - this->m_IntegrationTime = this->m_ToFImageGrabber->SetIntegrationTime(this->m_IntegrationTime); - this->m_ModulationFrequency = this->m_ToFImageGrabber->SetModulationFrequency(this->m_ModulationFrequency); - - //set the PMD calibration according to the check boxes - bool boolValue = false; - boolValue = m_Controls->m_FPNCalibCB->isChecked(); - this->m_ToFImageGrabber->SetBoolProperty("SetFPNCalibration", boolValue); - boolValue = m_Controls->m_FPPNCalibCB->isChecked(); - this->m_ToFImageGrabber->SetBoolProperty("SetFPPNCalibration", boolValue); - boolValue = m_Controls->m_LinearityCalibCB->isChecked(); - this->m_ToFImageGrabber->SetBoolProperty("SetLinearityCalibration", boolValue); - boolValue = m_Controls->m_LensCorrection->isChecked(); - this->m_ToFImageGrabber->SetBoolProperty("SetLensCalibration", boolValue); - boolValue = m_Controls->m_ExposureModeCB->isChecked(); - this->m_ToFImageGrabber->SetBoolProperty("SetExposureMode", boolValue); - - //reset the GUI elements - m_Controls->m_IntegrationTimeSpinBox->setValue(this->m_IntegrationTime); - m_Controls->m_ModulationFrequencySpinBox->setValue(this->m_ModulationFrequency); -*/ m_Controls->m_ConnectCameraButton->setText("Disconnect"); // send connect signal to the caller functionality emit ToFCameraConnected(); } else { QMessageBox::critical( this, "Error", "Connection failed. Check if you have installed the latest driver for your system." ); m_Controls->m_ConnectCameraButton->setChecked(false); m_Controls->m_ConnectCameraButton->setEnabled(true); m_Controls->m_SelectCameraCombobox->setEnabled(true); -// m_Controls->m_CalibrationParameterGroupBox->setEnabled(true); this->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); this->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(); - } - } -} -*/ diff --git a/Modules/ToFUI/Qmitk/QmitkToFConnectionWidget.h b/Modules/ToFUI/Qmitk/QmitkToFConnectionWidget.h index 09a7895d68..ae46b113c1 100644 --- a/Modules/ToFUI/Qmitk/QmitkToFConnectionWidget.h +++ b/Modules/ToFUI/Qmitk/QmitkToFConnectionWidget.h @@ -1,127 +1,111 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit Module: $RCSfile$ Language: C++ Date: $Date: 2009-05-20 13:35:09 +0200 (Mi, 20 Mai 2009) $ Version: $Revision: 17332 $ Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notices for more information. =========================================================================*/ #ifndef _QMITKTOFCONNECTIONWIDGET_H_INCLUDED #define _QMITKTOFCONNECTIONWIDGET_H_INCLUDED #include "mitkTOFUIExports.h" #include "ui_QmitkToFConnectionWidgetControls.h" //QT headers #include //mitk headers #include "mitkToFImageGrabber.h" /** * @brief Widget allowing to connect to different ToF / range cameras (located in module ToFProcessing) * * The widget basically allows to connect/disconnect to different ToF cameras * * @ingroup ToFUI */ class mitkTOFUI_EXPORT QmitkToFConnectionWidget :public QWidget { //this is needed for all Qt objects that should have a MOC object (everything that derives from QObject) Q_OBJECT public: static const std::string VIEW_ID; QmitkToFConnectionWidget(QWidget* p = 0, Qt::WindowFlags f1 = 0); virtual ~QmitkToFConnectionWidget(); /* @brief This method is part of the widget an needs not to be called seperately. */ virtual void CreateQtPartControl(QWidget *parent); /* @brief This method is part of the widget an needs not to be called seperately. (Creation of the connections of main and control widget.)*/ virtual void CreateConnections(); /*! \brief returns the ToFImageGrabber which was provided by the ToFImageGrabberCreator after selecting a camera / player \return ToFImageGrabber currently used by the widget */ mitk::ToFImageGrabber* GetToFImageGrabber(); signals: /*! \brief This signal is sent if the user has connected the TOF camera. * The ToFImageGrabber is now availiable if the method GetToFImageGrabber() is called. */ void ToFCameraConnected(); /*! \brief This signal is sent if the user has disconnect the TOF camera. */ void ToFCameraDisconnected(); /*! - \brief signal that is emitted when the ToF camera is started - */ - void ToFCameraStart(); - /*! - \brief signal that is emitted when the ToF camera is stopped - */ - void ToFCameraStop(); - /*! \brief signal that is emitted when a ToF camera is selected in the combo box */ void ToFCameraSelected(const QString selectedText); protected slots: /*! \brief slot called when the "Connect Camera" button was pressed * According to the selection in the camera combo box, the ToFImageGrabberCreator provides * the desired instance of the ToFImageGrabber */ void OnConnectCamera(); /*! \brief slot updating the GUI elements after the selection of the camera combo box has changed */ void OnSelectCamera(const QString selectedText); - /*! - \brief slot updating the member m_IntegrationTime and the parameter "integration time" of the current ToFImageGrabber - */ - //void OnChangeIntegrationTimeSpinBox(int value); - /*! - \brief slot updating the member m_ModulationFrequency and the parameter "modulation frequency" of the current ToFImageGrabber - */ - //void OnChangeModulationFrequencySpinBox(int value); protected: Ui::QmitkToFConnectionWidgetControls* m_Controls; ///< member holding the UI elements of this widget mitk::ToFImageGrabber* m_ToFImageGrabber; ///< member holding the current ToFImageGrabber int m_IntegrationTime; ///< member for the current integration time of the ToF device int m_ModulationFrequency; ///< member for the current modulation frequency of the ToF device private: void ShowParameterWidget(); void ShowPMDParameterWidget(); void ShowMESAParameterWidget(); void ShowPlayerParameterWidget(); }; #endif // _QMITKTOFCONNECTIONWIDGET_H_INCLUDED diff --git a/Modules/ToFUI/Qmitk/QmitkToFPointSetWidget.cpp b/Modules/ToFUI/Qmitk/QmitkToFPointSetWidget.cpp new file mode 100644 index 0000000000..f92f0b431d --- /dev/null +++ b/Modules/ToFUI/Qmitk/QmitkToFPointSetWidget.cpp @@ -0,0 +1,349 @@ +/*========================================================================= + +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. + +=========================================================================*/ + +#include + +#include + +#include +#include + +const std::string QmitkToFPointSetWidget::VIEW_ID = "org.mitk.views.qmitktofpointsetwidget"; + +QmitkToFPointSetWidget::QmitkToFPointSetWidget(QWidget* parent, Qt::WindowFlags f): QWidget(parent, f) +, m_CameraIntrinsics(NULL) +, m_VtkTextActor(NULL) +, m_ForegroundRenderer1(NULL) +, m_ForegroundRenderer2(NULL) +, m_ForegroundRenderer3(NULL) +, m_RenderWindow1(NULL) +, m_RenderWindow2(NULL) +, m_RenderWindow3(NULL) +, m_MeasurementPointSet2D(NULL) +, m_MeasurementPointSet3DNode(NULL) +, m_PointSet2D(NULL) +, m_PointSet3DNode(NULL) +, m_PointSetInteractor(NULL) +, m_MeasurementPointSetInteractor(NULL) +, m_MeasurementPointSetChangedObserverTag(0) +, m_PointSetChangedObserverTag(0) +{ + m_Controls = NULL; + CreateQtPartControl(this); +} + +QmitkToFPointSetWidget::~QmitkToFPointSetWidget() +{ + if (m_MeasurementPointSet2D.IsNotNull()) + { + m_MeasurementPointSet2D->RemoveObserver(m_MeasurementPointSetChangedObserverTag); + } + if (m_PointSet2D.IsNotNull()) + { + m_PointSet2D->RemoveObserver(m_PointSetChangedObserverTag); + } + if (m_MultiWidget) + { + if (m_ForegroundRenderer1&&m_RenderWindow1) + { + if (mitk::VtkLayerController::GetInstance(m_RenderWindow1)) + { + mitk::VtkLayerController::GetInstance(m_RenderWindow1)->RemoveRenderer(m_ForegroundRenderer1); + } + } + if (m_ForegroundRenderer2&&m_RenderWindow2) + { + if (mitk::VtkLayerController::GetInstance(m_RenderWindow2)) + { + mitk::VtkLayerController::GetInstance(m_RenderWindow2)->RemoveRenderer(m_ForegroundRenderer2); + } + } + if (m_ForegroundRenderer3&&m_RenderWindow3) + { + if (mitk::VtkLayerController::GetInstance(m_RenderWindow3)) + { + mitk::VtkLayerController::GetInstance(m_RenderWindow3)->RemoveRenderer(m_ForegroundRenderer3); + } + } + } + if (mitk::RenderingManager::GetInstance()) + { + mitk::RenderingManager::GetInstance()->RequestUpdateAll(); + } +} + +void QmitkToFPointSetWidget::CreateQtPartControl(QWidget *parent) +{ + if (!m_Controls) + { + // create GUI widgets + m_Controls = new Ui::QmitkToFPointSetWidgetControls; + m_Controls->setupUi(parent); + + this->CreateConnections(); + } +} + +void QmitkToFPointSetWidget::CreateConnections() +{ + if ( m_Controls ) + { + connect( (QObject*)(m_Controls->measureButton), SIGNAL(clicked()),(QObject*) this, SLOT(OnMeasurement()) ); + connect( (QObject*)(m_Controls->pointSetButton), SIGNAL(clicked()),(QObject*) this, SLOT(OnPointSet()) ); + } +} + +void QmitkToFPointSetWidget::InitializeWidget(QmitkStdMultiWidget* stdMultiWidget, mitk::DataStorage::Pointer dataStorage, mitk::Image::Pointer distanceImage) +{ + // initialize members + m_MultiWidget = stdMultiWidget; + m_DistanceImage = distanceImage; + if ((stdMultiWidget!=NULL)&&(dataStorage.IsNotNull())) + { + // enable buttons + m_Controls->pointSetButton->setEnabled(true); + m_Controls->measureButton->setEnabled(true); + // initialize overlays + this->m_VtkTextActor = vtkTextActor::New(); + this->m_VtkTextActor->SetInput("Choose measurement points with SHIFT+Click"); + int windowHeight = m_MultiWidget->mitkWidget1->GetRenderer()->GetSizeY(); + this->m_VtkTextActor->SetDisplayPosition(10,windowHeight-30); + this->m_VtkTextActor->GetTextProperty()->SetFontSize(16); +// this->m_VtkTextActor->GetTextProperty()->SetColor(1,0,0); + this->m_VtkTextActor->GetTextProperty()->BoldOn(); + this->m_VtkTextActor->SetVisibility(0); + this->m_ForegroundRenderer1 = vtkRenderer::New(); + this->m_ForegroundRenderer1->AddActor(m_VtkTextActor); + m_RenderWindow1 = m_MultiWidget->mitkWidget1->GetRenderWindow(); + mitk::VtkLayerController::GetInstance(m_MultiWidget->mitkWidget1->GetRenderWindow())->InsertForegroundRenderer(m_ForegroundRenderer1,true); + this->m_ForegroundRenderer2 = vtkRenderer::New(); + this->m_ForegroundRenderer2->AddActor(m_VtkTextActor); + m_RenderWindow2 = m_MultiWidget->mitkWidget2->GetRenderWindow(); + mitk::VtkLayerController::GetInstance(m_RenderWindow2)->InsertForegroundRenderer(m_ForegroundRenderer2,true); + this->m_ForegroundRenderer3 = vtkRenderer::New(); + this->m_ForegroundRenderer3->AddActor(m_VtkTextActor); + m_RenderWindow3 = m_MultiWidget->mitkWidget3->GetRenderWindow(); + mitk::VtkLayerController::GetInstance(m_RenderWindow3)->InsertForegroundRenderer(m_ForegroundRenderer3,true); + // initialize 2D measurement point set + m_MeasurementPointSet2D = mitk::PointSet::New(); + mitk::DataNode::Pointer measurementNode2D = mitk::DataNode::New(); + measurementNode2D->SetName("Measurement PointSet 2D"); + measurementNode2D->SetBoolProperty("helper object",true); + measurementNode2D->SetBoolProperty("show contour",true); + measurementNode2D->SetVisibility(false,stdMultiWidget->mitkWidget4->GetRenderer()); + measurementNode2D->SetData(m_MeasurementPointSet2D); + dataStorage->Add(measurementNode2D); + m_MeasurementPointSetInteractor = mitk::PointSetInteractor::New("pointsetinteractor",measurementNode2D,2); + // create observer for m_MeasurementPointSet2D + itk::SimpleMemberCommand::Pointer measurementPointSetChangedCommand; + measurementPointSetChangedCommand = itk::SimpleMemberCommand::New(); + measurementPointSetChangedCommand->SetCallbackFunction(this, &QmitkToFPointSetWidget::MeasurementPointSetChanged); + m_MeasurementPointSetChangedObserverTag = m_MeasurementPointSet2D->AddObserver(itk::ModifiedEvent(), measurementPointSetChangedCommand); + // initialize 3D measurement PointSet + m_MeasurementPointSet3DNode = mitk::DataNode::New(); + m_MeasurementPointSet3DNode->SetName("Measurement PointSet 3D"); + m_MeasurementPointSet3DNode->SetBoolProperty("helper object",true); + m_MeasurementPointSet3DNode->SetBoolProperty("show contour",true); + m_MeasurementPointSet3DNode->SetFloatProperty("pointsize",5.0f); + mitk::PointSet::Pointer measurementPointSet3D = mitk::PointSet::New(); + m_MeasurementPointSet3DNode->SetData(measurementPointSet3D); + dataStorage->Add(m_MeasurementPointSet3DNode); + // initialize PointSets + m_PointSet2D = mitk::PointSet::New(); + mitk::DataNode::Pointer pointSet2DNode = mitk::DataNode::New(); + pointSet2DNode->SetName("ToF PointSet 2D"); + pointSet2DNode->SetVisibility(false,stdMultiWidget->mitkWidget4->GetRenderer()); + pointSet2DNode->SetData(m_PointSet2D); + dataStorage->Add(pointSet2DNode); + m_PointSetInteractor = mitk::PointSetInteractor::New("pointsetinteractor",pointSet2DNode); + // create observer for m_MeasurementPointSet2D + itk::SimpleMemberCommand::Pointer pointSetChangedCommand; + pointSetChangedCommand = itk::SimpleMemberCommand::New(); + pointSetChangedCommand->SetCallbackFunction(this, &QmitkToFPointSetWidget::PointSetChanged); + m_PointSetChangedObserverTag = m_PointSet2D->AddObserver(itk::ModifiedEvent(), pointSetChangedCommand); + // initialize 3D point set + m_PointSet3DNode = mitk::DataNode::New(); + m_PointSet3DNode->SetName("ToF PointSet 3D"); + m_PointSet3DNode->SetFloatProperty("pointsize",5.0f); + mitk::PointSet::Pointer pointSet3D = mitk::PointSet::New(); + m_PointSet3DNode->SetData(pointSet3D); + dataStorage->Add(m_PointSet3DNode); + } +} + +void QmitkToFPointSetWidget::SetCameraIntrinsics(mitk::CameraIntrinsics::Pointer cameraIntrinsics) +{ + m_CameraIntrinsics = cameraIntrinsics; +} + +void QmitkToFPointSetWidget::OnMeasurement() +{ + if (m_Controls->measureButton->isChecked()) + { + // disable point set interaction + if (m_Controls->pointSetButton->isChecked()) + { + m_Controls->pointSetButton->setChecked(false); + // remove interactor + mitk::GlobalInteraction::GetInstance()->RemoveInteractor(m_PointSetInteractor); + } + // show overlays + m_VtkTextActor->SetVisibility(1); + this->m_VtkTextActor->SetInput("Choose measurement points with SHIFT+Click"); + // enable interactor + mitk::GlobalInteraction::GetInstance()->AddInteractor(m_MeasurementPointSetInteractor); + // initial update of measurement + this->MeasurementPointSetChanged(); + } + else + { + // hide overlays + m_VtkTextActor->SetVisibility(0); + // disable interactor + mitk::GlobalInteraction::GetInstance()->RemoveInteractor(m_MeasurementPointSetInteractor); + } +} + +void QmitkToFPointSetWidget::OnPointSet() +{ + if (m_Controls->pointSetButton->isChecked()) + { + // disable measurement + if (m_Controls->measureButton->isChecked()) + { + m_Controls->measureButton->setChecked(false); + // remove interactor + mitk::GlobalInteraction::GetInstance()->RemoveInteractor(m_MeasurementPointSetInteractor); + } + // show overlays + m_VtkTextActor->SetVisibility(1); + this->m_VtkTextActor->SetInput("Choose points with SHIFT+Click"); + // enable interactor + mitk::GlobalInteraction::GetInstance()->AddInteractor(m_PointSetInteractor); + // initial update of PointSet + this->PointSetChanged(); + } + else + { + // hide overlays + m_VtkTextActor->SetVisibility(0); + // disable interactor + mitk::GlobalInteraction::GetInstance()->RemoveInteractor(m_PointSetInteractor); + } +} + +void QmitkToFPointSetWidget::MeasurementPointSetChanged() +{ + // replace text actor + int windowHeight = m_MultiWidget->mitkWidget1->GetRenderer()->GetSizeY(); + this->m_VtkTextActor->SetDisplayPosition(10,windowHeight-30); + // check if points are inside the image range + int imageSizeX = m_DistanceImage->GetDimensions()[0]; + int imageSizeY = m_DistanceImage->GetDimensions()[1]; + mitk::Point3D point1 = m_MeasurementPointSet2D->GetPoint(0); + mitk::Point3D point2 = m_MeasurementPointSet2D->GetPoint(1); + if (m_MeasurementPointSet2D->GetSize()>0) + { + if ((point1[0]>=0.0f)&&(point1[0]=0)&&(point1[1]=0.0f)&&(point2[0]=0)&&(point2[1]SetCameraIntrinsics(m_CameraIntrinsics); + } + toFDistanceImageToPointSetFilter->SetInput(m_DistanceImage); + toFDistanceImageToPointSetFilter->SetSubset(m_MeasurementPointSet2D); + toFDistanceImageToPointSetFilter->Update(); + mitk::PointSet::Pointer measurementPointSet3D = toFDistanceImageToPointSetFilter->GetOutput(); + m_MeasurementPointSet3DNode->SetData(measurementPointSet3D); + + // calculate distance between points + if (measurementPointSet3D->GetSize()==2) + { + mitk::Point3D point1 = measurementPointSet3D->GetPoint(0); + mitk::Point3D point2 = measurementPointSet3D->GetPoint(1); + float distance = point1.EuclideanDistanceTo(point2); + std::stringstream stream; + stream<m_VtkTextActor->SetInput(stream.str().c_str()); + } + else + { + this->m_VtkTextActor->SetInput("Choose measurement points with SHIFT+Click"); + } + } + else + { + this->m_VtkTextActor->SetInput("Measurement outside image range."); + } + } + else + { + // initialize 3D pointset empty + mitk::PointSet::Pointer pointSet3D = mitk::PointSet::New(); + m_MeasurementPointSet3DNode->SetData(pointSet3D); + } +} + +void QmitkToFPointSetWidget::PointSetChanged() +{ + int imageSizeX = m_DistanceImage->GetDimensions()[0]; + int imageSizeY = m_DistanceImage->GetDimensions()[1]; + int pointSetValid = 1; + for (int i=0; iGetSize(); i++) + { + mitk::Point3D currentPoint = m_PointSet2D->GetPoint(i); + if ((currentPoint[0]>=0.0f)&&(currentPoint[0]=0)&&(currentPoint[1]GetSize()>0) + { + if (pointSetValid) + { + // create PointSet filter + mitk::ToFDistanceImageToPointSetFilter::Pointer toFDistanceImageToPointSetFilter = mitk::ToFDistanceImageToPointSetFilter::New(); + if (m_CameraIntrinsics.IsNotNull()) + { + toFDistanceImageToPointSetFilter->SetCameraIntrinsics(m_CameraIntrinsics); + } + toFDistanceImageToPointSetFilter->SetInput(m_DistanceImage); + toFDistanceImageToPointSetFilter->SetSubset(m_PointSet2D); + toFDistanceImageToPointSetFilter->Update(); + mitk::PointSet::Pointer pointSet3D = toFDistanceImageToPointSetFilter->GetOutput(); + m_PointSet3DNode->SetData(pointSet3D); + this->m_VtkTextActor->SetInput("Choose points with SHIFT+Click"); } + else + { + this->m_VtkTextActor->SetInput("Point set outside image range."); + } + } + else + { + // initialize 3D pointset empty + mitk::PointSet::Pointer pointSet3D = mitk::PointSet::New(); + m_PointSet3DNode->SetData(pointSet3D); + } +} diff --git a/Modules/ToFUI/Qmitk/QmitkToFPointSetWidget.h b/Modules/ToFUI/Qmitk/QmitkToFPointSetWidget.h new file mode 100644 index 0000000000..97a1b5dde1 --- /dev/null +++ b/Modules/ToFUI/Qmitk/QmitkToFPointSetWidget.h @@ -0,0 +1,132 @@ +/*========================================================================= + +Program: Medical Imaging & Interaction Toolkit +Module: $RCSfile$ +Language: C++ +Date: $Date: 2009-05-20 13:35:09 +0200 (Mi, 20 Mai 2009) $ +Version: $Revision: 17332 $ + +Copyright (c) German Cancer Research Center, Division of Medical and +Biological Informatics. All rights reserved. +See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. + +This software is distributed WITHOUT ANY WARRANTY; without even +the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR +PURPOSE. See the above copyright notices for more information. + +=========================================================================*/ + +#ifndef _QmitkToFPointSetWidget_H_INCLUDED +#define _QmitkToFPointSetWidget_H_INCLUDED + +#include "mitkTOFUIExports.h" +#include "ui_QmitkToFPointSetWidgetControls.h" + +//mitk headers +#include +#include +#include +#include +#include +#include + +// Qmitk headers +#include + +// vtk includes +#include +#include +#include + +/** +* @brief Widget allowing interaction with point sets for measurement and PointSet definition +* +* The widget allows to +* 1. Measure the distance between two points in 3D ToF space by clicking the points in the 2D slices +* 2. Defining a ToF PointSet both in 2D and 3D. CameraIntrinsics are used for calculation between 2D and 3D +* +* @ingroup ToFUI +*/ +class mitkTOFUI_EXPORT QmitkToFPointSetWidget :public QWidget +{ + //this is needed for all Qt objects that should have a MOC object (everything that derives from QObject) + Q_OBJECT + + public: + + static const std::string VIEW_ID; + + QmitkToFPointSetWidget(QWidget* p = 0, Qt::WindowFlags f1 = 0); + virtual ~QmitkToFPointSetWidget(); + + /* @brief This method is part of the widget an needs not to be called seperately. */ + virtual void CreateQtPartControl(QWidget *parent); + /* @brief This method is part of the widget an needs not to be called seperately. (Creation of the connections of main and control widget.)*/ + virtual void CreateConnections(); + + /*! + \brief initializes the widget + \param stdMultiWidget QmitkStdMultiWidget used for painting overlays for measurement + \param dataStorage DataStorage to add PointSets + \param distanceImage range image used to calculate 3D PointSet from 2D index + */ + void InitializeWidget(QmitkStdMultiWidget* stdMultiWidget, mitk::DataStorage::Pointer dataStorage, mitk::Image::Pointer distanceImage); + + /*! + \brief specify the intrinsic parameters of the camera (holds focal length, principal point, distortion coefficients) + */ + void SetCameraIntrinsics(mitk::CameraIntrinsics::Pointer cameraIntrinsics); + + signals: + + protected slots: + /*! + \brief Activates the interactor for the measurement point set + */ + void OnMeasurement(); + /*! + \brief Activates the interactor for the point set + */ + void OnPointSet(); + + protected: + + /*! + \brief function called when the 2D measurement PointSet has changed + */ + void MeasurementPointSetChanged(); + /*! + \brief function called when the 2D PointSet has changed + */ + void PointSetChanged(); + + Ui::QmitkToFPointSetWidgetControls* m_Controls; ///< member holding the UI elements of this widget + + QmitkStdMultiWidget* m_MultiWidget; ///< multi widget used for overlay visualization + + mitk::Image::Pointer m_DistanceImage; ///< image holding the range data of the ToF camera + mitk::CameraIntrinsics::Pointer m_CameraIntrinsics; ///< intrinsic parameters of the camera + + vtkSmartPointer m_VtkTextActor; ///< actor containing the text of the overlay + vtkSmartPointer m_ForegroundRenderer1; ///< renderer responsible for text rendering in the foreground of widget 1 + vtkSmartPointer m_ForegroundRenderer2; ///< renderer responsible for text rendering in the foreground of widget 2 + vtkSmartPointer m_ForegroundRenderer3; ///< renderer responsible for text rendering in the foreground of widget 3 + vtkSmartPointer m_RenderWindow1; ///< vtk render window used for showing overlay in widget 1 + vtkSmartPointer m_RenderWindow2; ///< vtk render window used for showing overlay in widget 2 + vtkSmartPointer m_RenderWindow3; ///< vtk render window used for showing overlay in widget 3 + + mitk::PointSet::Pointer m_MeasurementPointSet2D; ///< PointSet holding the 2D ToF image point selection used for measuring + mitk::DataNode::Pointer m_MeasurementPointSet3DNode; ///< DataNode holding the 3D ToF coordinates used for measuring + mitk::PointSet::Pointer m_PointSet2D; ///< PointSet holding the 2D ToF image points + mitk::DataNode::Pointer m_PointSet3DNode; ///< DataNode holding the 3D ToF coordinates + + mitk::PointSetInteractor::Pointer m_PointSetInteractor; ///< PointSetInteractor used for PointSet definition + mitk::PointSetInteractor::Pointer m_MeasurementPointSetInteractor; ///< PointSetInteractor used for measurement + + long m_MeasurementPointSetChangedObserverTag; ///< observer tag for measurement PointSet observer + long m_PointSetChangedObserverTag; ///< observer tag for PointSet observer + + private: +}; + +#endif // _QmitkToFPointSetWidget_H_INCLUDED diff --git a/Modules/ToFUI/Qmitk/QmitkToFPointSetWidgetControls.ui b/Modules/ToFUI/Qmitk/QmitkToFPointSetWidgetControls.ui new file mode 100644 index 0000000000..d4b6ff7b5d --- /dev/null +++ b/Modules/ToFUI/Qmitk/QmitkToFPointSetWidgetControls.ui @@ -0,0 +1,138 @@ + + + QmitkToFPointSetWidgetControls + + + + 0 + 0 + 426 + 103 + + + + + 0 + 0 + + + + QmitkToFCompositeFilter + + + + + + + 11 + + + + ToF Measurement + + + + + + + + + false + + + + 0 + 0 + + + + + 70 + 60 + + + + + 16777215 + 60 + + + + Shift+Click to add measurement points. Select points in PointSet by clicking. Delete Points by selecting and typing DEL. + + + Measure + + + + :/images/measurement.png:/images/measurement.png + + + + 32 + 32 + + + + true + + + Qt::ToolButtonTextUnderIcon + + + + + + + false + + + + 0 + 0 + + + + + 70 + 60 + + + + + 16777215 + 60 + + + + Shift+Click to add points to PointSet. Select points in PointSet by clicking. Delete Points by selecting and typing DEL. + + + PointSet + + + + :/images/path.png:/images/path.png + + + + 32 + 32 + + + + true + + + Qt::ToolButtonTextUnderIcon + + + + + + + + + + + diff --git a/Modules/ToFUI/Qmitk/QmitkToFRecorderWidget.cpp b/Modules/ToFUI/Qmitk/QmitkToFRecorderWidget.cpp index 392fbb79a7..0e97b4d94a 100644 --- a/Modules/ToFUI/Qmitk/QmitkToFRecorderWidget.cpp +++ b/Modules/ToFUI/Qmitk/QmitkToFRecorderWidget.cpp @@ -1,393 +1,393 @@ /*========================================================================= 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 "QmitkToFRecorderWidget.h" //QT headers #include #include #include #include #include #include //mitk headers #include //itk headers #pragma GCC visibility push(default) #include #pragma GCC visibility pop #include struct QFileDialogArgs; class QFileDialogPrivate; const std::string QmitkToFRecorderWidget::VIEW_ID = "org.mitk.views.qmitktofrecorderwidget"; QmitkToFRecorderWidget::QmitkToFRecorderWidget(QWidget* parent, Qt::WindowFlags f): QWidget(parent, f) { this->m_ToFImageRecorder = NULL; this->m_ToFImageGrabber = NULL; this->m_RecordMode = mitk::ToFImageRecorder::PerFrames; this-> m_Controls = NULL; CreateQtPartControl(this); } QmitkToFRecorderWidget::~QmitkToFRecorderWidget() { } void QmitkToFRecorderWidget::CreateQtPartControl(QWidget *parent) { if (!m_Controls) { // create GUI widgets this->m_Controls = new Ui::QmitkToFRecorderWidgetControls; this->m_Controls->setupUi(parent); this->CreateConnections(); } } void QmitkToFRecorderWidget::CreateConnections() { if ( m_Controls ) { connect( (QObject*)(m_Controls->m_PlayButton), SIGNAL(clicked()),(QObject*) this, SLOT(OnPlay()) ); connect( (QObject*)(m_Controls->m_StopButton), SIGNAL(clicked()),(QObject*) this, SLOT(OnStop()) ); connect( (QObject*)(m_Controls->m_StartRecordingButton), SIGNAL(clicked()),(QObject*) this, SLOT(OnStartRecorder()) ); connect( (QObject*)(m_Controls->m_RecordModeComboBox), SIGNAL(currentIndexChanged(int)),(QObject*) this, SLOT(OnChangeRecordModeComboBox(int)) ); connect(this, SIGNAL(RecordingStopped()), this, SLOT(OnRecordingStopped()), Qt::BlockingQueuedConnection); } } -void QmitkToFRecorderWidget::SetParameter(mitk::ToFImageGrabber* ToFImageGrabber, mitk::ToFImageRecorder* toFImageRecorder) +void QmitkToFRecorderWidget::SetParameter(mitk::ToFImageGrabber* toFImageGrabber, mitk::ToFImageRecorder* toFImageRecorder) { - this->m_ToFImageGrabber = ToFImageGrabber; + this->m_ToFImageGrabber = toFImageGrabber; this->m_ToFImageRecorder = toFImageRecorder; this->m_StopRecordingCommand = CommandType::New(); this->m_StopRecordingCommand->SetCallbackFunction(this, &QmitkToFRecorderWidget::StopRecordingCallback); this->m_ToFImageRecorder->RemoveAllObservers(); this->m_ToFImageRecorder->AddObserver(itk::AbortEvent(), this->m_StopRecordingCommand); m_Controls->m_PlayButton->setChecked(false); m_Controls->m_PlayButton->setEnabled(true); m_Controls->m_StartRecordingButton->setChecked(false); m_Controls->m_RecorderGroupBox->setEnabled(true); } void QmitkToFRecorderWidget::StopRecordingCallback() { emit RecordingStopped(); } void QmitkToFRecorderWidget::ResetGUIToInitial() { m_Controls->m_PlayButton->setChecked(false); m_Controls->m_PlayButton->setEnabled(true); m_Controls->m_RecorderGroupBox->setEnabled(false); } void QmitkToFRecorderWidget::OnRecordingStopped() { m_Controls->m_StartRecordingButton->setChecked(false); m_Controls->m_RecorderGroupBox->setEnabled(true); } void QmitkToFRecorderWidget::OnStop() { StopCamera(); StopRecorder(); ResetGUIToInitial(); emit ToFCameraStopped(); } void QmitkToFRecorderWidget::OnPlay() { m_Controls->m_PlayButton->setChecked(true); m_Controls->m_PlayButton->setEnabled(false); m_Controls->m_RecorderGroupBox->setEnabled(true); this->repaint(); StartCamera(); emit ToFCameraStarted(); } void QmitkToFRecorderWidget::StartCamera() { bool ok = false; if (!m_ToFImageGrabber->IsCameraActive()) { m_ToFImageGrabber->StartCamera(); } } void QmitkToFRecorderWidget::StopCamera() { m_ToFImageGrabber->StopCamera(); } void QmitkToFRecorderWidget::StopRecorder() { this->m_ToFImageRecorder->StopRecording(); } void QmitkToFRecorderWidget::OnStartRecorder() { m_Controls->m_StartRecordingButton->setChecked(true); m_Controls->m_RecorderGroupBox->setEnabled(false); this->repaint(); int numOfFrames = m_Controls->m_NumOfFramesSpinBox->value(); try { bool fileOK = true; bool distanceImageSelected = true; bool amplitudeImageSelected = true; bool intensityImageSelected = true; bool rawDataSelected = false; QString tmpFileName(""); QString selectedFilter(""); QString imageFileName(""); mitk::ToFImageWriter::ToFImageType tofImageType; tmpFileName = QmitkToFRecorderWidget::getSaveFileName(tofImageType, distanceImageSelected, amplitudeImageSelected, intensityImageSelected, rawDataSelected, NULL, "Save Image To...", imageFileName, "NRRD Images (*.nrrd);;PIC Images - deprecated (*.pic);;Text (*.csv)", &selectedFilter); if (tmpFileName.isEmpty()) { fileOK = false; } else { imageFileName = tmpFileName; } if (fileOK) { std::string dir = itksys::SystemTools::GetFilenamePath( imageFileName.toStdString() ); std::string baseFilename = itksys::SystemTools::GetFilenameWithoutLastExtension( imageFileName.toStdString() ); std::string extension = itksys::SystemTools::GetFilenameLastExtension( imageFileName.toStdString() ); int integrationTime = this->m_ToFImageGrabber->GetIntegrationTime(); int modulationFreq = this->m_ToFImageGrabber->GetModulationFrequency(); QString integrationTimeStr; integrationTimeStr.setNum(integrationTime); QString modulationFreqStr; modulationFreqStr.setNum(modulationFreq); QString numOfFramesStr(""); if (this->m_RecordMode == mitk::ToFImageRecorder::PerFrames) { numOfFramesStr.setNum(numOfFrames); } std::string distImageFileName = prepareFilename(dir, baseFilename, modulationFreqStr.toStdString(), integrationTimeStr.toStdString(), numOfFramesStr.toStdString(), extension, "_DistanceImage"); MITK_INFO << "Save distance data to: " << distImageFileName; std::string amplImageFileName = prepareFilename(dir, baseFilename, modulationFreqStr.toStdString(), integrationTimeStr.toStdString(), numOfFramesStr.toStdString(), extension, "_AmplitudeImage"); MITK_INFO << "Save amplitude data to: " << amplImageFileName; std::string intenImageFileName = prepareFilename(dir, baseFilename, modulationFreqStr.toStdString(), integrationTimeStr.toStdString(), numOfFramesStr.toStdString(), extension, "_IntensityImage"); MITK_INFO << "Save intensity data to: " << intenImageFileName; if (selectedFilter.compare("Text (*.csv)") == 0) { this->m_ToFImageRecorder->SetFileFormat(".csv"); } else if (selectedFilter.compare("PIC Images - deprecated (*.pic)") == 0) { //default this->m_ToFImageRecorder->SetFileFormat(".pic"); QMessageBox::warning(NULL, "Deprecated File Format!", "Please note that *.pic file format is deprecated and not longer supported! The suggested file format for images is *.nrrd!"); } else if (selectedFilter.compare("NRRD Images (*.nrrd)") == 0) { this->m_ToFImageRecorder->SetFileFormat(".nrrd"); } else { QMessageBox::warning(NULL, "Unsupported file format!", "Please specify one of the supported file formats *.nrrd, *.csv!"); return; } numOfFrames = m_Controls->m_NumOfFramesSpinBox->value(); this->m_ToFImageRecorder->SetDistanceImageFileName(distImageFileName); this->m_ToFImageRecorder->SetAmplitudeImageFileName(amplImageFileName); this->m_ToFImageRecorder->SetIntensityImageFileName(intenImageFileName); this->m_ToFImageRecorder->SetToFImageType(tofImageType); this->m_ToFImageRecorder->SetDistanceImageSelected(distanceImageSelected); this->m_ToFImageRecorder->SetAmplitudeImageSelected(amplitudeImageSelected); this->m_ToFImageRecorder->SetIntensityImageSelected(intensityImageSelected); this->m_ToFImageRecorder->SetRecordMode(this->m_RecordMode); this->m_ToFImageRecorder->SetNumOfFrames(numOfFrames); this->m_ToFImageRecorder->StartRecording(); } else { this->OnRecordingStopped(); } } catch(std::exception& e) { QMessageBox::critical(NULL, "Error", QString(e.what())); this->OnRecordingStopped(); } } QString QmitkToFRecorderWidget::getSaveFileName(mitk::ToFImageWriter::ToFImageType& tofImageType, bool& distanceImageSelected, bool& amplitudeImageSelected, bool& intensityImageSelected, bool& rawDataSelected, QWidget *parent, const QString &caption, const QString &dir, const QString &filter, QString *selectedFilter, QFileDialog::Options options ) { QString selectedFileName = ""; QComboBox* combo = new QComboBox; combo->addItem("3D"); combo->addItem("2D + t"); QHBoxLayout* checkBoxGroup = new QHBoxLayout(); QCheckBox* distanceImageCheckBox = new QCheckBox; distanceImageCheckBox->setText("Distance image"); distanceImageCheckBox->setChecked(true); QCheckBox* amplitudeImageCheckBox = new QCheckBox; amplitudeImageCheckBox->setText("Amplitude image"); amplitudeImageCheckBox->setChecked(true); QCheckBox* intensityImageCheckBox = new QCheckBox; intensityImageCheckBox->setText("Intensity image"); intensityImageCheckBox->setChecked(true); QCheckBox* rawDataCheckBox = new QCheckBox; rawDataCheckBox->setText("Raw data"); rawDataCheckBox->setChecked(false); rawDataCheckBox->setEnabled(false); checkBoxGroup->addWidget(distanceImageCheckBox); checkBoxGroup->addWidget(amplitudeImageCheckBox); checkBoxGroup->addWidget(intensityImageCheckBox); checkBoxGroup->addWidget(rawDataCheckBox); QFileDialog* fileDialog = new QFileDialog(parent, caption, dir, filter); QLayout* layout = fileDialog->layout(); QGridLayout* gridbox = qobject_cast(layout); if (gridbox) { gridbox->addWidget(new QLabel("ToF-Image type:")); gridbox->addWidget(combo); int lastRow = gridbox->rowCount(); gridbox->addLayout(checkBoxGroup, lastRow, 0, 1, -1); } fileDialog->setLayout(gridbox); fileDialog->setAcceptMode(QFileDialog::AcceptSave); if (selectedFilter) { fileDialog->selectNameFilter(*selectedFilter); } if (fileDialog->exec() == QDialog::Accepted) { if (selectedFilter) { *selectedFilter = fileDialog->selectedFilter(); } if (combo->currentIndex() == 0) { tofImageType = mitk::ToFImageWriter::ToFImageType3D; } else { tofImageType = mitk::ToFImageWriter::ToFImageType2DPlusT; } distanceImageSelected = distanceImageCheckBox->isChecked(); amplitudeImageSelected = amplitudeImageCheckBox->isChecked(); intensityImageSelected = intensityImageCheckBox->isChecked(); rawDataSelected = rawDataCheckBox->isChecked(); selectedFileName = fileDialog->selectedFiles().value(0); } delete fileDialog; return selectedFileName; } std::string QmitkToFRecorderWidget::prepareFilename(std::string dir, std::string baseFilename, std::string modulationFreq, std::string integrationTime, std::string numOfFrames, std::string extension, std::string imageType) { std::string filenName(""); filenName.append(dir); filenName.append("/"); filenName.append(baseFilename); filenName.append("_MF"); filenName.append(modulationFreq); filenName.append("_IT"); filenName.append(integrationTime); filenName.append("_"); filenName.append(numOfFrames); filenName.append("Images"); filenName.append(imageType); filenName.append(extension); return filenName; } void QmitkToFRecorderWidget::OnChangeRecordModeComboBox(int index) { if (index == 0) { this->m_RecordMode = mitk::ToFImageRecorder::PerFrames; m_Controls->m_NumOfFramesSpinBox->setEnabled(true); } else { this->m_RecordMode = mitk::ToFImageRecorder::Infinite; m_Controls->m_NumOfFramesSpinBox->setEnabled(false); } } diff --git a/Modules/ToFUI/Qmitk/QmitkToFVisualisationSettingsWidget.cpp b/Modules/ToFUI/Qmitk/QmitkToFVisualisationSettingsWidget.cpp index 2bb2f78f5f..5a83b4a3da 100644 --- a/Modules/ToFUI/Qmitk/QmitkToFVisualisationSettingsWidget.cpp +++ b/Modules/ToFUI/Qmitk/QmitkToFVisualisationSettingsWidget.cpp @@ -1,674 +1,361 @@ /*========================================================================= 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 #include "QmitkToFVisualisationSettingsWidget.h" //QT headers -#include #include #include -//mitk headers -#include "mitkToFImageGrabber.h" -#include "mitkNodePredicateDataType.h" -#include - -#include - -//itk headers - -//vtk headers - -//Qmitk headers -#include "QmitkStdMultiWidget.h" - const std::string QmitkToFVisualisationSettingsWidget::VIEW_ID = "org.mitk.views.qmitktofvisualisationsettingswidget"; QmitkToFVisualisationSettingsWidget::QmitkToFVisualisationSettingsWidget(QWidget* parent, Qt::WindowFlags f): QWidget(parent, f) +, m_Controls(NULL) +, m_RangeSliderMin(0) +, m_RangeSliderMax(0) +, m_MitkDistanceImage(NULL) +, m_MitkAmplitudeImage(NULL) +, m_MitkIntensityImage(NULL) +, m_Widget1ColorTransferFunction(NULL) +, m_Widget2ColorTransferFunction(NULL) +, m_Widget3ColorTransferFunction(NULL) +, m_Widget1TransferFunctionType(1) +, m_Widget2TransferFunctionType(0) +, m_Widget3TransferFunctionType(0) { - InitMember(); - - m_Controls = NULL; CreateQtPartControl(this); - - //this->setupUi(this); - -} - -void QmitkToFVisualisationSettingsWidget::InitMember() -{ - this->m_Channel = 0; - this->m_Type = 0; - this->m_CurrentImageNode = NULL; - - //SetImageType(this->m_Widget1ImageType, 0); - //SetImageType(this->m_Widget2ImageType, 1); - //SetImageType(this->m_Widget3ImageType, 2); - //SetImageType(this->m_Widget4ImageType, 3); - - this->m_ToFVisualizationFilter = NULL; } QmitkToFVisualisationSettingsWidget::~QmitkToFVisualisationSettingsWidget() { } void QmitkToFVisualisationSettingsWidget::CreateQtPartControl(QWidget *parent) { if (!m_Controls) { // create GUI widgets m_Controls = new Ui::QmitkToFVisualisationSettingsWidgetControls; m_Controls->setupUi(parent); this->CreateConnections(); } } -void QmitkToFVisualisationSettingsWidget::StdMultiWidgetAvailable (QmitkStdMultiWidget &stdMultiWidget) -{ - //m_MultiWidget = &stdMultiWidget; -} - -void QmitkToFVisualisationSettingsWidget::StdMultiWidgetNotAvailable() -{ - //m_MultiWidget = NULL; -} - void QmitkToFVisualisationSettingsWidget::CreateConnections() { if ( m_Controls ) { connect( (QObject*)(m_Controls->m_SelectWidgetCombobox), SIGNAL(currentIndexChanged(int)),(QObject*) this, SLOT(OnWidgetSelected(int)) ); - - connect( (QObject*)(m_Controls->m_SelectImageTypeCombobox), SIGNAL(currentIndexChanged(int)),(QObject*) this, SLOT(OnImageTypeSelected(int)) ); - connect( (QObject*)(m_Controls->m_SelectTransferFunctionTypeCombobox), SIGNAL(currentIndexChanged(int)),(QObject*) this, SLOT(OnTransferFunctionTypeSelected(int)) ); - connect( (QObject*)(m_Controls->m_TransferFunctionResetButton), SIGNAL(clicked()),(QObject*) this, SLOT(OnTransferFunctionReset()) ); - - connect(m_Controls->m_XEditColor, SIGNAL(returnPressed()), this, SLOT(SetXValueColor())); - + connect(m_Controls->m_XEditColor, SIGNAL(returnPressed()), this, SLOT(OnSetXValueColor())); connect(m_Controls->m_RangeSliderMaxEdit, SIGNAL(returnPressed()), this, SLOT(OnRangeSliderMaxChanged())); - connect(m_Controls->m_RangeSliderMinEdit, SIGNAL(returnPressed()), this, SLOT(OnRangeSliderMinChanged())); + connect(m_Controls->m_RangeSliderReset, SIGNAL(pressed()), this, SLOT(OnResetSlider())); + connect(m_Controls->m_RangeSlider, SIGNAL(spanChanged(int, int) ),this, SLOT( OnSpanChanged(int , int ) )); QPlastiqueStyle *sliderStyle = new QPlastiqueStyle(); - m_Controls->m_RangeSlider->setMaximum(2048); m_Controls->m_RangeSlider->setMinimum(-2048); m_Controls->m_RangeSlider->setHandleMovementMode(QxtSpanSlider::NoOverlapping); m_Controls->m_RangeSlider->setStyle(sliderStyle); - connect(m_Controls->m_RangeSlider, SIGNAL(spanChanged(int, int) ),this, SLOT( OnSpanChanged(int , int ) )); - - //reset button - connect(m_Controls->m_RangeSliderReset, SIGNAL(pressed()), this, SLOT(OnResetSlider())); m_Controls->m_ColorTransferFunctionCanvas->SetQLineEdits(m_Controls->m_XEditColor, 0); - m_Controls->m_ColorTransferFunctionCanvas->SetTitle(""/*"Value -> Grayscale/Color"*/); - } } -void QmitkToFVisualisationSettingsWidget::Initialize(mitk::DataStorage* dataStorage, QmitkStdMultiWidget* multiWidget) -{ - this->m_DataStorage = dataStorage; - this->m_MultiWidget = multiWidget; -} - -void QmitkToFVisualisationSettingsWidget::SetParameter(mitk::ToFVisualizationFilter* ToFVisualizationFilter) -{ - this->m_ToFVisualizationFilter = ToFVisualizationFilter; -} - -void QmitkToFVisualisationSettingsWidget::Reset() -{ -} - -mitk::ToFVisualizationFilter* QmitkToFVisualisationSettingsWidget::GetToFVisualizationFilter() -{ - if (this->m_ToFVisualizationFilter.IsNull()) - { - this->m_ToFVisualizationFilter = mitk::ToFVisualizationFilter::New(); - } - return this->m_ToFVisualizationFilter; -} - -void QmitkToFVisualisationSettingsWidget::SetXValueColor() +void QmitkToFVisualisationSettingsWidget::OnSetXValueColor() { m_Controls->m_ColorTransferFunctionCanvas->SetX(m_Controls->m_XEditColor->text().toFloat()); mitk::RenderingManager::GetInstance()->RequestUpdateAll(); } void QmitkToFVisualisationSettingsWidget::OnRangeSliderMaxChanged() { m_Controls->m_RangeSlider->setMaximum(m_Controls->m_RangeSliderMaxEdit->text().toInt()); UpdateRanges(); m_Controls->m_ColorTransferFunctionCanvas->update(); } void QmitkToFVisualisationSettingsWidget::OnRangeSliderMinChanged() { m_Controls->m_RangeSlider->setMinimum(m_Controls->m_RangeSliderMinEdit->text().toInt()); UpdateRanges(); m_Controls->m_ColorTransferFunctionCanvas->update(); } void QmitkToFVisualisationSettingsWidget::OnSpanChanged(int /*lower*/, int /*upper*/) { UpdateRanges(); m_Controls->m_ColorTransferFunctionCanvas->update(); } void QmitkToFVisualisationSettingsWidget::OnResetSlider() { m_Controls->m_RangeSlider->setUpperValue(m_RangeSliderMax); m_Controls->m_RangeSlider->setLowerValue(m_RangeSliderMin); UpdateRanges(); m_Controls->m_ColorTransferFunctionCanvas->update(); } void QmitkToFVisualisationSettingsWidget::UpdateRanges() { int lower = m_Controls->m_RangeSlider->lowerValue(); int upper = m_Controls->m_RangeSlider->upperValue(); m_Controls->m_ColorTransferFunctionCanvas->SetMin(lower); m_Controls->m_ColorTransferFunctionCanvas->SetMax(upper); } -void QmitkToFVisualisationSettingsWidget::SetDataNode(mitk::DataNode* node) -{ - if (node) - { - m_TfpToChange = dynamic_cast(node->GetProperty("TransferFunction")); - - if(!m_TfpToChange) - { - if (! dynamic_cast(node->GetData())) - { - MITK_WARN << "QmitkTransferFunctionWidget::SetDataNode called with non-image node"; - goto turnOff; - } - - m_TfpToChange = mitk::TransferFunctionProperty::New(); - mitk::TransferFunction::Pointer ctf = mitk::TransferFunction::New(); - ctf->InitializeByMitkImage(dynamic_cast(node->GetData())); - m_TfpToChange->SetValue(ctf); - node->SetProperty("TransferFunction", m_TfpToChange ); - } - - mitk::TransferFunction::Pointer tf = m_TfpToChange->GetValue(); - - if( mitk::Image* image = dynamic_cast( node->GetData() ) ) - { - mitk::SimpleHistogram *h = histogramCache[image]; - - m_RangeSliderMin= h->GetMin(); - m_RangeSliderMax= h->GetMax(); - - } - - OnUpdateCanvas(); - - m_Controls->m_RangeSlider->setSpan( m_RangeSliderMin, m_RangeSliderMax); - - UpdateRanges(); - - return; - } - - turnOff: - - m_Controls->m_ColorTransferFunctionCanvas->setEnabled(false); - m_TfpToChange = 0; -} - -void QmitkToFVisualisationSettingsWidget::InitializeTransferFunction(mitk::Image* distanceImage, mitk::Image* amplitudeImage, mitk::Image* intensityImage) +void QmitkToFVisualisationSettingsWidget::Initialize(mitk::Image* distanceImage, mitk::Image* amplitudeImage, mitk::Image* intensityImage) { this->m_MitkDistanceImage = distanceImage; this->m_MitkAmplitudeImage = amplitudeImage; this->m_MitkIntensityImage = intensityImage; - if (distanceImage && distanceImage && intensityImage) + if (!m_MitkDistanceImage && !m_MitkAmplitudeImage && !m_MitkIntensityImage) { - m_RangeSliderMin = distanceImage->GetScalarValueMin(); - m_RangeSliderMax = distanceImage->GetScalarValueMax(); - - //m_Widget1ColorTransferFunction = vtkColorTransferFunction::New(); - ////m_Widget1ColorTransferFunction->RemoveAllPoints(); - ////m_Widget1ColorTransferFunction->AddRGBPoint(m_RangeSliderMin, 1, 0, 0); - ////m_Widget1ColorTransferFunction->AddRGBPoint((m_RangeSliderMin+(m_RangeSliderMax-m_RangeSliderMin)/2, 0, 1, 0); - ////m_Widget1ColorTransferFunction->AddRGBPoint(m_RangeSliderMax, 0, 0, 1); - ////m_Widget1ColorTransferFunction->SetColorSpaceToHSV(); - //this->m_Widget1TransferFunctionType = 1; - //ResetTransferFunction(this->m_Widget1ColorTransferFunction, this->m_Widget1TransferFunctionType ,distanceImage->GetScalarValueMin(), distanceImage->GetScalarValueMax()); - - //m_Widget2ColorTransferFunction = vtkColorTransferFunction::New(); - ////m_Widget2ColorTransferFunction->RemoveAllPoints(); - ////m_Widget2ColorTransferFunction->AddRGBPoint(amplitudeImage->GetScalarValueMin(), 1, 1, 1); - ////m_Widget2ColorTransferFunction->AddRGBPoint(amplitudeImage->GetScalarValueMax(), 0, 0, 0); - ////m_Widget2ColorTransferFunction->SetColorSpaceToHSV(); - //this->m_Widget2TransferFunctionType = 0; - //ResetTransferFunction(this->m_Widget2ColorTransferFunction, this->m_Widget2TransferFunctionType, amplitudeImage->GetScalarValueMin(), amplitudeImage->GetScalarValueMax()); - - //m_Widget3ColorTransferFunction = vtkColorTransferFunction::New(); - ////m_Widget3ColorTransferFunction->RemoveAllPoints(); - ////m_Widget3ColorTransferFunction->AddRGBPoint(intensityImage->GetScalarValueMin(), 1, 1, 1); - ////m_Widget3ColorTransferFunction->AddRGBPoint(intensityImage->GetScalarValueMax(), 0, 0, 0); - ////m_Widget3ColorTransferFunction->SetColorSpaceToHSV(); - //this->m_Widget3TransferFunctionType = 0; - //ResetTransferFunction(this->m_Widget3ColorTransferFunction, this->m_Widget3TransferFunctionType, intensityImage->GetScalarValueMin(), intensityImage->GetScalarValueMax()); - - OnUpdateCanvas(); - - int border = (m_RangeSliderMax - m_RangeSliderMin) * 0.1; - m_Controls->m_RangeSlider->setMinimum(m_RangeSliderMin - border); - m_Controls->m_RangeSlider->setMaximum(m_RangeSliderMax + border); - m_Controls->m_RangeSliderMinEdit->setText(QString("").setNum(m_RangeSliderMin - border)); - m_Controls->m_RangeSliderMaxEdit->setText(QString("").setNum(m_RangeSliderMax + border)); - m_Controls->m_RangeSlider->setSpan( m_RangeSliderMin, m_RangeSliderMax); - - UpdateRanges(); - + m_Controls->m_ColorTransferFunctionCanvas->setEnabled(false); } else { - m_Controls->m_ColorTransferFunctionCanvas->setEnabled(false); + m_Controls->m_ColorTransferFunctionCanvas->setEnabled(true); + int numberOfImages = 0; + if (m_MitkDistanceImage) + { + m_RangeSliderMin = distanceImage->GetScalarValueMin(); + m_RangeSliderMax = distanceImage->GetScalarValueMax(); + + m_Widget1ColorTransferFunction = vtkColorTransferFunction::New(); + this->m_Widget1TransferFunctionType = 1; + m_Controls->m_SelectTransferFunctionTypeCombobox->setCurrentIndex(this->m_Widget1TransferFunctionType); + ResetTransferFunction(this->m_Widget1ColorTransferFunction, this->m_Widget1TransferFunctionType ,distanceImage->GetScalarValueMin(), distanceImage->GetScalarValueMax()); + UpdateCanvas(); + + int border = (m_RangeSliderMax - m_RangeSliderMin) * 0.1; + m_Controls->m_RangeSlider->setMinimum(m_RangeSliderMin - border); + m_Controls->m_RangeSlider->setMaximum(m_RangeSliderMax + border); + m_Controls->m_RangeSliderMinEdit->setText(QString("").setNum(m_RangeSliderMin - border)); + m_Controls->m_RangeSliderMaxEdit->setText(QString("").setNum(m_RangeSliderMax + border)); + m_Controls->m_RangeSlider->setSpan( m_RangeSliderMin, m_RangeSliderMax); + + UpdateRanges(); + numberOfImages++; + } + if (m_MitkAmplitudeImage) + { + m_Widget2ColorTransferFunction = vtkColorTransferFunction::New(); + this->m_Widget2TransferFunctionType = 0; + ResetTransferFunction(this->m_Widget2ColorTransferFunction, this->m_Widget2TransferFunctionType, amplitudeImage->GetScalarValueMin(), amplitudeImage->GetScalarValueMax()); + numberOfImages++; + } + if (m_MitkIntensityImage) + { + m_Widget3ColorTransferFunction = vtkColorTransferFunction::New(); + this->m_Widget3TransferFunctionType = 0; + ResetTransferFunction(this->m_Widget3ColorTransferFunction, this->m_Widget3TransferFunctionType, intensityImage->GetScalarValueMin(), intensityImage->GetScalarValueMax()); + numberOfImages++; + } + m_Controls->m_SelectWidgetCombobox->setMaxCount(numberOfImages); } } -void QmitkToFVisualisationSettingsWidget::OnUpdateCanvas() +void QmitkToFVisualisationSettingsWidget::UpdateCanvas() { - //m_Controls->m_ColorTransferFunctionCanvas->SetColorTransferFunction( this->m_Widget1ColorTransferFunction ); - m_Controls->m_ColorTransferFunctionCanvas->SetColorTransferFunction( this->m_ToFVisualizationFilter->GetWidget1ColorTransferFunction() ); + m_Controls->m_ColorTransferFunctionCanvas->SetColorTransferFunction( this->GetSelectedColorTransferFunction() ); UpdateRanges(); m_Controls->m_ColorTransferFunctionCanvas->update(); } -std::string QmitkToFVisualisationSettingsWidget::GetImageType(int index) -{ - if (index == 0) - { - return "Distance"; - } - else if (index == 1) - { - return "Amplitude"; - } - else if (index == 2) - { - return"Intensity"; - } - else if (index == 3) - { - return "Video"; - } - else if (index == 5) - { - return "Surface"; - } - return ""; -} - -void QmitkToFVisualisationSettingsWidget::OnImageTypeSelected(int index) -{ - int currentWidgetIndex = m_Controls->m_SelectWidgetCombobox->currentIndex(); - if (currentWidgetIndex == 0) - { - //SetImageType(this->m_ToFVisualizationFilter->GetWidget1ImageType(), index); - this->m_ToFVisualizationFilter->SetWidget1ImageType(GetImageType(index)); - m_Controls->m_SelectTransferFunctionTypeCombobox->setCurrentIndex(this->m_ToFVisualizationFilter->GetWidget1TransferFunctionType()); - } - else if (currentWidgetIndex == 1) - { - //SetImageType(this->m_ToFVisualizationFilter->GetWidget2ImageType(), index); - this->m_ToFVisualizationFilter->SetWidget2ImageType(GetImageType(index)); - m_Controls->m_SelectTransferFunctionTypeCombobox->setCurrentIndex(this->m_ToFVisualizationFilter->GetWidget2TransferFunctionType()); - } - else if (currentWidgetIndex == 2) - { - //SetImageType(this->m_ToFVisualizationFilter->GetWidget3ImageType(), index); - this->m_ToFVisualizationFilter->SetWidget3ImageType(GetImageType(index)); - m_Controls->m_SelectTransferFunctionTypeCombobox->setCurrentIndex(this->m_ToFVisualizationFilter->GetWidget3TransferFunctionType()); - } - //else if (currentWidgetIndex == 3) - //{ - // SetImageType(this->m_Widget4ImageType, index); - //} - else - { - return; - } - - if (index==3) - { - m_Controls->m_MappingGroupBox->setEnabled(false); - m_Controls->m_FitScaleGroupBox->setEnabled(false); - } - else - { - m_Controls->m_MappingGroupBox->setEnabled(true); - m_Controls->m_FitScaleGroupBox->setEnabled(true); - } -} - void QmitkToFVisualisationSettingsWidget::OnTransferFunctionTypeSelected(int index) { int currentWidgetIndex = m_Controls->m_SelectWidgetCombobox->currentIndex(); if (currentWidgetIndex == 0) { - this->m_ToFVisualizationFilter->SetWidget1TransferFunctionType(index); + this->m_Widget1TransferFunctionType = index; } else if (currentWidgetIndex == 1) { - this->m_ToFVisualizationFilter->SetWidget2TransferFunctionType(index); + this->m_Widget2TransferFunctionType = index; } else if (currentWidgetIndex == 2) { - this->m_ToFVisualizationFilter->SetWidget3TransferFunctionType(index); + this->m_Widget3TransferFunctionType = index; } else { return; } } -int QmitkToFVisualisationSettingsWidget::GetImageTypeIndex(std::string imageType) -{ - if (imageType.compare("Distance") == 0) - { - return 0; - } - else if (imageType.compare("Amplitude") == 0) - { - return 1; - } - else if (imageType.compare("Intensity") == 0) - { - return 2; - } - else if (imageType.compare("Video") == 0) - { - return 3; - } - else if (imageType.compare("Surface") == 0) - { - return 4; - } - return 5; -} - void QmitkToFVisualisationSettingsWidget::OnWidgetSelected(int index) { int currentWidgetIndex = m_Controls->m_SelectWidgetCombobox->currentIndex(); double valMin[6]; double valMax[6]; int numPoints; if (currentWidgetIndex == 0) { - m_Controls->m_SelectImageTypeCombobox->setCurrentIndex(GetImageTypeIndex(this->m_ToFVisualizationFilter->GetWidget1ImageType())); - numPoints = this->m_ToFVisualizationFilter->GetWidget1ColorTransferFunction()->GetSize(); - this->m_ToFVisualizationFilter->GetWidget1ColorTransferFunction()->GetNodeValue( 0, valMin ); - this->m_ToFVisualizationFilter->GetWidget1ColorTransferFunction()->GetNodeValue( numPoints-1, valMax ); - m_Controls->m_ColorTransferFunctionCanvas->SetColorTransferFunction( this->m_ToFVisualizationFilter->GetWidget1ColorTransferFunction() ); + m_Controls->m_SelectTransferFunctionTypeCombobox->setCurrentIndex(this->m_Widget1TransferFunctionType); + numPoints = this->m_Widget1ColorTransferFunction->GetSize(); + this->m_Widget1ColorTransferFunction->GetNodeValue( 0, valMin ); + this->m_Widget1ColorTransferFunction->GetNodeValue( numPoints-1, valMax ); + m_Controls->m_ColorTransferFunctionCanvas->SetColorTransferFunction( this->m_Widget1ColorTransferFunction ); } else if (currentWidgetIndex == 1) { - m_Controls->m_SelectImageTypeCombobox->setCurrentIndex(GetImageTypeIndex(this->m_ToFVisualizationFilter->GetWidget2ImageType())); - numPoints = this->m_ToFVisualizationFilter->GetWidget2ColorTransferFunction()->GetSize(); - this->m_ToFVisualizationFilter->GetWidget2ColorTransferFunction()->GetNodeValue( 0, valMin ); - this->m_ToFVisualizationFilter->GetWidget2ColorTransferFunction()->GetNodeValue( numPoints-1, valMax ); - m_Controls->m_ColorTransferFunctionCanvas->SetColorTransferFunction( this->m_ToFVisualizationFilter->GetWidget2ColorTransferFunction() ); + m_Controls->m_SelectTransferFunctionTypeCombobox->setCurrentIndex(this->m_Widget2TransferFunctionType); + numPoints = this->m_Widget2ColorTransferFunction->GetSize(); + this->m_Widget2ColorTransferFunction->GetNodeValue( 0, valMin ); + this->m_Widget2ColorTransferFunction->GetNodeValue( numPoints-1, valMax ); + m_Controls->m_ColorTransferFunctionCanvas->SetColorTransferFunction( this->m_Widget2ColorTransferFunction ); } else if (currentWidgetIndex == 2) { - m_Controls->m_SelectImageTypeCombobox->setCurrentIndex(GetImageTypeIndex(this->m_ToFVisualizationFilter->GetWidget3ImageType())); - numPoints = this->m_ToFVisualizationFilter->GetWidget3ColorTransferFunction()->GetSize(); - this->m_ToFVisualizationFilter->GetWidget3ColorTransferFunction()->GetNodeValue( 0, valMin ); - this->m_ToFVisualizationFilter->GetWidget3ColorTransferFunction()->GetNodeValue( numPoints-1, valMax ); - m_Controls->m_ColorTransferFunctionCanvas->SetColorTransferFunction( this->m_ToFVisualizationFilter->GetWidget3ColorTransferFunction() ); + m_Controls->m_SelectTransferFunctionTypeCombobox->setCurrentIndex(this->m_Widget3TransferFunctionType); + numPoints = this->m_Widget3ColorTransferFunction->GetSize(); + this->m_Widget3ColorTransferFunction->GetNodeValue( 0, valMin ); + this->m_Widget3ColorTransferFunction->GetNodeValue( numPoints-1, valMax ); + m_Controls->m_ColorTransferFunctionCanvas->SetColorTransferFunction( this->m_Widget3ColorTransferFunction ); } else if (currentWidgetIndex == 3) { } else { return; } m_RangeSliderMin = valMin[0]; m_RangeSliderMax = valMax[0]; int border = (m_RangeSliderMax - m_RangeSliderMin) * 0.1; m_Controls->m_RangeSlider->setMinimum(m_RangeSliderMin - border); m_Controls->m_RangeSlider->setMaximum(m_RangeSliderMax + border); m_Controls->m_RangeSliderMinEdit->setText(QString("").setNum(m_RangeSliderMin - border)); m_Controls->m_RangeSliderMaxEdit->setText(QString("").setNum(m_RangeSliderMax + border)); m_Controls->m_RangeSlider->setSpan( m_RangeSliderMin, m_RangeSliderMax); UpdateRanges(); m_Controls->m_ColorTransferFunctionCanvas->update(); } void QmitkToFVisualisationSettingsWidget::ResetTransferFunction(vtkColorTransferFunction* colorTransferFunction, int type, double min, double max) { colorTransferFunction->RemoveAllPoints(); if (type == 0) { colorTransferFunction->AddRGBPoint(min, 0, 0, 0); colorTransferFunction->AddRGBPoint(max, 1, 1, 1); } else { if (min>0.01) { colorTransferFunction->AddRGBPoint(0.0, 0, 0, 0); colorTransferFunction->AddRGBPoint(min-0.01, 0, 0, 0); } colorTransferFunction->AddRGBPoint(min, 1, 0, 0); colorTransferFunction->AddRGBPoint(min+(max-min)/2, 1, 1, 0); colorTransferFunction->AddRGBPoint(max, 0, 0, 1); } colorTransferFunction->SetColorSpaceToHSV(); } void QmitkToFVisualisationSettingsWidget::OnTransferFunctionReset() { - //TODO implement the Enum Conversion type int currentTransferFunctionTypeIndex = m_Controls->m_SelectTransferFunctionTypeCombobox->currentIndex(); int currentWidgetIndex = m_Controls->m_SelectWidgetCombobox->currentIndex(); - int currentImageTypeIndex = m_Controls->m_SelectImageTypeCombobox->currentIndex(); - int numOfPixel = this->m_MitkDistanceImage->GetDimension(0) * this->m_MitkDistanceImage->GetDimension(1); - - if (currentImageTypeIndex == 0) - { - ComputeMinMax((float*)this->m_MitkDistanceImage->GetSliceData(0,0,0)->GetData(), numOfPixel, m_RangeSliderMin, m_RangeSliderMax); - } - else if (currentImageTypeIndex == 1) - { - ComputeMinMax((float*)this->m_MitkAmplitudeImage->GetSliceData(0,0,0)->GetData(), numOfPixel, m_RangeSliderMin, m_RangeSliderMax); - } - else if (currentImageTypeIndex == 2) - { - ComputeMinMax((float*)this->m_MitkIntensityImage->GetSliceData(0,0,0)->GetData(), numOfPixel, m_RangeSliderMin, m_RangeSliderMax); - } - else - { - return; - } if (currentWidgetIndex == 0) { - this->m_ToFVisualizationFilter->SetWidget1TransferFunctionType(currentTransferFunctionTypeIndex); - ResetTransferFunction(this->m_ToFVisualizationFilter->GetWidget1ColorTransferFunction(), this->m_ToFVisualizationFilter->GetWidget1TransferFunctionType(), - this->m_RangeSliderMin, this->m_RangeSliderMax); - m_Controls->m_ColorTransferFunctionCanvas->SetColorTransferFunction( this->m_ToFVisualizationFilter->GetWidget1ColorTransferFunction() ); + // use second minimum to draw 0 values (that are usually segmented) black + m_RangeSliderMin = this->m_MitkDistanceImage->GetScalarValue2ndMin(); + m_RangeSliderMax = this->m_MitkDistanceImage->GetScalarValueMaxNoRecompute(); + ResetTransferFunction(this->m_Widget1ColorTransferFunction, currentTransferFunctionTypeIndex, this->m_RangeSliderMin, this->m_RangeSliderMax); + m_Controls->m_ColorTransferFunctionCanvas->SetColorTransferFunction( this->m_Widget1ColorTransferFunction ); } else if (currentWidgetIndex == 1) { - this->m_ToFVisualizationFilter->SetWidget2TransferFunctionType(currentTransferFunctionTypeIndex); - ResetTransferFunction(this->m_ToFVisualizationFilter->GetWidget2ColorTransferFunction(), this->m_ToFVisualizationFilter->GetWidget2TransferFunctionType(), - this->m_RangeSliderMin, this->m_RangeSliderMax); - m_Controls->m_ColorTransferFunctionCanvas->SetColorTransferFunction( this->m_ToFVisualizationFilter->GetWidget2ColorTransferFunction() ); + m_RangeSliderMin = this->m_MitkAmplitudeImage->GetScalarValueMin(); + m_RangeSliderMax = this->m_MitkAmplitudeImage->GetScalarValueMaxNoRecompute(); + ResetTransferFunction(this->m_Widget2ColorTransferFunction, currentTransferFunctionTypeIndex, this->m_RangeSliderMin, this->m_RangeSliderMax); + m_Controls->m_ColorTransferFunctionCanvas->SetColorTransferFunction( this->m_Widget2ColorTransferFunction ); } else if (currentWidgetIndex == 2) { - this->m_ToFVisualizationFilter->SetWidget1TransferFunctionType(currentTransferFunctionTypeIndex); - ResetTransferFunction(this->m_ToFVisualizationFilter->GetWidget3ColorTransferFunction(), this->m_ToFVisualizationFilter->GetWidget3TransferFunctionType(), - this->m_RangeSliderMin, this->m_RangeSliderMax); - m_Controls->m_ColorTransferFunctionCanvas->SetColorTransferFunction( this->m_ToFVisualizationFilter->GetWidget3ColorTransferFunction() ); + m_RangeSliderMin = this->m_MitkIntensityImage->GetScalarValueMin(); + m_RangeSliderMax = this->m_MitkIntensityImage->GetScalarValueMaxNoRecompute(); + ResetTransferFunction(this->m_Widget3ColorTransferFunction, currentTransferFunctionTypeIndex, this->m_RangeSliderMin, this->m_RangeSliderMax); + m_Controls->m_ColorTransferFunctionCanvas->SetColorTransferFunction( this->m_Widget3ColorTransferFunction ); } - else if (currentWidgetIndex == 3) - { - } - else + else { return; } int border = (m_RangeSliderMax - m_RangeSliderMin) * 0.1; m_Controls->m_RangeSlider->setMinimum(m_RangeSliderMin - border); m_Controls->m_RangeSlider->setMaximum(m_RangeSliderMax + border); m_Controls->m_RangeSliderMinEdit->setText(QString("").setNum(m_RangeSliderMin - border)); m_Controls->m_RangeSliderMaxEdit->setText(QString("").setNum(m_RangeSliderMax + border)); m_Controls->m_RangeSlider->setSpan( m_RangeSliderMin, m_RangeSliderMax); UpdateRanges(); m_Controls->m_ColorTransferFunctionCanvas->update(); } -vtkColorTransferFunction* QmitkToFVisualisationSettingsWidget::GetColorTransferFunctionByImageType(char* imageType) +vtkColorTransferFunction* QmitkToFVisualisationSettingsWidget::GetWidget1ColorTransferFunction() +{ + return this->m_Widget1ColorTransferFunction; +} + +vtkColorTransferFunction* QmitkToFVisualisationSettingsWidget::GetWidget2ColorTransferFunction() +{ + return this->m_Widget2ColorTransferFunction; +} + +vtkColorTransferFunction* QmitkToFVisualisationSettingsWidget::GetWidget3ColorTransferFunction() +{ + return this->m_Widget3ColorTransferFunction; +} + +vtkColorTransferFunction* QmitkToFVisualisationSettingsWidget::GetSelectedColorTransferFunction() { -/* - if (this->m_Widget1ImageType.compare(imageType) == 0) + int currentWidgetIndex = m_Controls->m_SelectWidgetCombobox->currentIndex(); + if (currentWidgetIndex==0) { -<<<<<<< .mine - return this->m_ToFVisualizationFilter->GetWidget1ColorTransferFunction(); - //return this->m_Widget1ColorTransferFunction; -======= - //return this->m_ToFVisualizationFilter->GetWidget1ColorTransferFunction(); return this->m_Widget1ColorTransferFunction; ->>>>>>> .r29631 } - else if (this->m_Widget2ImageType.compare(imageType) == 0) + else if (currentWidgetIndex==1) { return this->m_Widget2ColorTransferFunction; } - else if (this->m_Widget3ImageType.compare(imageType) == 0) + else if (currentWidgetIndex==2) { return this->m_Widget3ColorTransferFunction; } else { return this->m_Widget3ColorTransferFunction; } -*/ - if (this->m_ToFVisualizationFilter->GetWidget1ImageType().compare(imageType) == 0) - { - return this->m_ToFVisualizationFilter->GetWidget1ColorTransferFunction(); - } - else if (this->m_ToFVisualizationFilter->GetWidget2ImageType().compare(imageType) == 0) - { - return this->m_ToFVisualizationFilter->GetWidget2ColorTransferFunction(); - } - else if (this->m_ToFVisualizationFilter->GetWidget3ImageType().compare(imageType) == 0) - { - return this->m_ToFVisualizationFilter->GetWidget3ColorTransferFunction(); - } - else - { - return this->m_ToFVisualizationFilter->GetWidget3ColorTransferFunction(); - } - -} - -mitk::TransferFunction::Pointer QmitkToFVisualisationSettingsWidget::GetTransferFunction() -{ - mitk::TransferFunction::Pointer tf = m_TfpToChange->GetValue(); - return tf; -} - -vtkColorTransferFunction* QmitkToFVisualisationSettingsWidget::GetWidget1ColorTransferFunction() -{ - return this->m_ToFVisualizationFilter->GetWidget1ColorTransferFunction(); -} - -void QmitkToFVisualisationSettingsWidget::SetWidget1ColorTransferFunction(vtkColorTransferFunction* colorTransferFunction) -{ - this->m_ToFVisualizationFilter->SetWidget1ColorTransferFunction(colorTransferFunction); -} - -vtkColorTransferFunction* QmitkToFVisualisationSettingsWidget::GetWidget2ColorTransferFunction() -{ - return this->m_ToFVisualizationFilter->GetWidget2ColorTransferFunction(); -} - -void QmitkToFVisualisationSettingsWidget::SetWidget2ColorTransferFunction(vtkColorTransferFunction* colorTransferFunction) -{ - this->m_ToFVisualizationFilter->SetWidget2ColorTransferFunction(colorTransferFunction); } -vtkColorTransferFunction* QmitkToFVisualisationSettingsWidget::GetWidget3ColorTransferFunction() -{ - return this->m_ToFVisualizationFilter->GetWidget3ColorTransferFunction(); -} - -void QmitkToFVisualisationSettingsWidget::SetWidget3ColorTransferFunction(vtkColorTransferFunction* colorTransferFunction) -{ - this->m_ToFVisualizationFilter->SetWidget3ColorTransferFunction(colorTransferFunction); -} - -//vtkColorTransferFunction* QmitkToFVisualisationSettingsWidget::GetWidget4ColorTransferFunction() -//{ -// return m_Widget4ColorTransferFunction; -//} - -//void QmitkToFVisualisationSettingsWidget::SetWidget4ColorTransferFunction(vtkColorTransferFunction* colorTransferFunction) -//{ -// m_Widget4ColorTransferFunction = colorTransferFunction; -//} - -std::string QmitkToFVisualisationSettingsWidget::GetWidget1ImageType() +int QmitkToFVisualisationSettingsWidget::GetSelectedImageIndex() { - return this->m_ToFVisualizationFilter->GetWidget1ImageType(); + return this->m_Controls->m_SelectWidgetCombobox->currentIndex(); } - -std::string QmitkToFVisualisationSettingsWidget::GetWidget2ImageType() -{ - return this->m_ToFVisualizationFilter->GetWidget2ImageType(); -} - -std::string QmitkToFVisualisationSettingsWidget::GetWidget3ImageType() -{ - return this->m_ToFVisualizationFilter->GetWidget3ImageType(); -} - -void QmitkToFVisualisationSettingsWidget::ComputeMinMax(float* data, int num, int& min, int& max) -{ - min = std::numeric_limits::max(); - max = 0; - - for(int i=0; i max) max = data[i]; - } - -} - diff --git a/Modules/ToFUI/Qmitk/QmitkToFVisualisationSettingsWidget.h b/Modules/ToFUI/Qmitk/QmitkToFVisualisationSettingsWidget.h index ea6682bbbe..58640dce3f 100644 --- a/Modules/ToFUI/Qmitk/QmitkToFVisualisationSettingsWidget.h +++ b/Modules/ToFUI/Qmitk/QmitkToFVisualisationSettingsWidget.h @@ -1,182 +1,161 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit Module: $RCSfile$ Language: C++ Date: $Date: 2009-05-20 13:35:09 +0200 (Mi, 20 Mai 2009) $ Version: $Revision: 17332 $ Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notices for more information. =========================================================================*/ #ifndef _QMITKTOFVISUALISATIONSETTINGSWIDGET_H_INCLUDED #define _QMITKTOFVISUALISATIONSETTINGSWIDGET_H_INCLUDED #include "mitkTOFUIExports.h" #include "ui_QmitkToFVisualisationSettingsWidgetControls.h" -//QT headers +// QT headers #include -#include -#include - -//std headers - -//itk headers - -//mitk headers -#include "mitkToFImageGrabber.h" -#include -#include - -//Qmitk headers -#include "QmitkRenderWindow.h" -#include "mitkToFVisualizationFilter.h" - +// vtk includes #include class QmitkStdMultiWidget; /** Documentation: - * \ingroup MBIIGTUI + * Widget controlling the visualization of Time-of-Flight image data. A color transfer function can be configured for + * a given distance, amplitude and intensity image. The pre-configured vtkColorTransferFunctions can be accessed as + * an output of the widget. + * + * \ingroup ToFUI */ class mitkTOFUI_EXPORT QmitkToFVisualisationSettingsWidget :public QWidget { //this is needed for all Qt objects that should have a MOC object (everything that derives from QObject) Q_OBJECT public: static const std::string VIEW_ID; QmitkToFVisualisationSettingsWidget (QWidget* p = 0, Qt::WindowFlags f1 = 0); virtual ~QmitkToFVisualisationSettingsWidget (); /* @brief This method is part of the widget an needs not to be called seperately. */ virtual void CreateQtPartControl(QWidget *parent); /* @brief This method is part of the widget an needs not to be called seperately. (Creation of the connections of main and control widget.)*/ virtual void CreateConnections(); - /* @brief This method is part of the widget an needs not to be called seperately. */ - virtual void StdMultiWidgetAvailable (QmitkStdMultiWidget &stdMultiWidget); - /* @brief This method is part of the widget an needs not to be called seperately. */ - virtual void StdMultiWidgetNotAvailable(); - - /* @brief initialize the Widget */ - void Initialize(mitk::DataStorage* dataStorage, QmitkStdMultiWidget* multiWidget); - - /* @brief set the required parameters - * - */ - void SetParameter(mitk::ToFVisualizationFilter* ToFVisualizationFilter); - - void InitializeTransferFunction(mitk::Image* distanceImage, mitk::Image* amplitudeImage, mitk::Image* intensityImage); - - void InitMember(); - - void Reset(); - - void SetDataNode(mitk::DataNode* node); - - mitk::ToFVisualizationFilter* GetToFVisualizationFilter(); - - mitk::TransferFunction::Pointer GetTransferFunction(); - + /*! + \brief initialize the widget with the images to be shown + \param distanceImage image holding the range image of a ToF camera + \param amplitudeImage image holding the amplitude image of a ToF camera + \param intensityImage image holding the intensity image of a ToF camera + */ + void Initialize(mitk::Image* distanceImage=NULL, mitk::Image* amplitudeImage=NULL, mitk::Image* intensityImage=NULL); + + /*! + \brief Access the color transfer function of widget 1 (distance image) + \return vtkColorTransferFunction that can be used to define a TransferFunctionProperty + */ vtkColorTransferFunction* GetWidget1ColorTransferFunction(); - - void SetWidget1ColorTransferFunction(vtkColorTransferFunction* colorTransferFunction); - + /*! + \brief Access the color transfer function of widget 2 (distance image) + \return vtkColorTransferFunction that can be used to define a TransferFunctionProperty + */ vtkColorTransferFunction* GetWidget2ColorTransferFunction(); - - void SetWidget2ColorTransferFunction(vtkColorTransferFunction* colorTransferFunction); - + /*! + \brief Access the color transfer function of widget 3 (distance image) + \return vtkColorTransferFunction that can be used to define a TransferFunctionProperty + */ vtkColorTransferFunction* GetWidget3ColorTransferFunction(); - - void SetWidget3ColorTransferFunction(vtkColorTransferFunction* colorTransferFunction); - - //vtkColorTransferFunction* GetWidget4ColorTransferFunction(); - - //void SetWidget4ColorTransferFunction(vtkColorTransferFunction* colorTransferFunction); - - vtkColorTransferFunction* GetColorTransferFunctionByImageType(char* imageType); - - std::string GetWidget1ImageType(); - - std::string GetWidget2ImageType(); - - std::string GetWidget3ImageType(); - - //QString GetWidget4ImageType(); + /*! + \brief Access the color transfer of the currently selected widget + \return vtkColorTransferFunction that can be used to define a TransferFunctionProperty + */ + vtkColorTransferFunction* GetSelectedColorTransferFunction(); + /*! + \brief Return the index of the selected image: 0 = Distance, 1 = Amplitude, 2 = Intensity + */ + int GetSelectedImageIndex(); protected slots: - /* @brief slot performing region growing and setting result for registration method - * - */ - void SetXValueColor(); - void OnUpdateCanvas(); - void UpdateRanges(); + void OnSetXValueColor(); + /*! + \brief Slot invoking a reset of the RangeSlider to the minimal and maximal values of the according image + */ void OnResetSlider(); + /*! + \brief Slot called when the range span has changed. + */ void OnSpanChanged (int lower, int upper); + /*! + \brief Resets the transfer function according to the currently selected widget / image + */ void OnTransferFunctionReset(); + /*! + \brief Updates the GUI according to the widget / image selection + */ void OnWidgetSelected(int index); - void OnImageTypeSelected(int index); + /*! + \brief Slot called when the line edit of the maximal value of the range slider has changed. Leads to an update of the range slider. + */ void OnRangeSliderMaxChanged(); + /*! + \brief Slot called when the line edit of the minimal value of the range slider has changed. Leads to an update of the range slider. + */ void OnRangeSliderMinChanged(); + /*! + \brief Sets the TransferFunctionType members according to the selection of the widget and the transfer type. + */ void OnTransferFunctionTypeSelected(int index); protected: - Ui::QmitkToFVisualisationSettingsWidgetControls* m_Controls; - QmitkStdMultiWidget* m_MultiWidget; - mitk::DataStorage* m_DataStorage; - - mitk::ToFImageGrabber* m_ToFImageGrabber; - - int m_Channel; - int m_Type; - QString m_NewImageName; - mitk::DataNode::Pointer m_CurrentImageNode; - - mitk::TransferFunctionProperty::Pointer m_TfpToChange; - int m_RangeSliderMin; - int m_RangeSliderMax; - mitk::SimpleHistogramCache histogramCache; + /*! + \brief Invokes an update of the ColorTransferFunctionCanvas. Called when the ColorTransferFunction has changed + */ + void UpdateCanvas(); + /*! + \brief Resets the ColorTransferFunctionCanvas according to the lower and upper value of the RangeSlider + */ + void UpdateRanges(); - //vtkColorTransferFunction* m_Widget1ColorTransferFunction; - //vtkColorTransferFunction* m_Widget2ColorTransferFunction; - //vtkColorTransferFunction* m_Widget3ColorTransferFunction; - //vtkColorTransferFunction* m_Widget4ColorTransferFunction; + Ui::QmitkToFVisualisationSettingsWidgetControls* m_Controls; - //QString m_Widget1ImageType; - //QString m_Widget2ImageType; - //QString m_Widget3ImageType; - //QString m_Widget4ImageType; + int m_RangeSliderMin; ///< Minimal value of the transfer function range. Initialized to the minimal value of the corresponding image. + int m_RangeSliderMax; ///< Maximal value of the transfer function range. Initialized to the maximal value of the corresponding image. - mitk::Image::Pointer m_MitkDistanceImage; - mitk::Image::Pointer m_MitkAmplitudeImage; - mitk::Image::Pointer m_MitkIntensityImage; + mitk::Image::Pointer m_MitkDistanceImage; ///< Range image of the ToF camera as set by Initialize() + mitk::Image::Pointer m_MitkAmplitudeImage; ///< Amplitud image of the ToF camera as set by Initialize() + mitk::Image::Pointer m_MitkIntensityImage; ///< Intensity image of the ToF camera as set by Initialize() - //int m_Widget1TransferFunctionType; - //int m_Widget2TransferFunctionType; - //int m_Widget3TransferFunctionType; + vtkColorTransferFunction* m_Widget1ColorTransferFunction; ///< vtkColorTransferFunction of widget 1 (distance) that can be used to define a TransferFunctionProperty + vtkColorTransferFunction* m_Widget2ColorTransferFunction; ///< vtkColorTransferFunction of widget 2 (amplitude) that can be used to define a TransferFunctionProperty + vtkColorTransferFunction* m_Widget3ColorTransferFunction; ///< vtkColorTransferFunction of widget 3 (intensity) that can be used to define a TransferFunctionProperty - mitk::ToFVisualizationFilter::Pointer m_ToFVisualizationFilter; + int m_Widget1TransferFunctionType; ///< member holding the type of the transfer function applied to the image shown in widget 1 (distance image): 0 = gray scale, 1 = color + int m_Widget2TransferFunctionType; ///< member holding the type of the transfer function applied to the image shown in widget 2 (amplitude image): 0 = gray scale, 1 = color + int m_Widget3TransferFunctionType; ///< member holding the type of the transfer function applied to the image shown in widget 3 (intensity image): 0 = gray scale, 1 = color private: - std::string GetImageType(int index); - int GetImageTypeIndex(std::string imageType); + /*! + \brief Reset the color transfer function to the given type and range + \param colorTransferFunction vtkColorTransferfunction to be resetted + \param type type of the transfer function: 0 = gray scale, 1 = color + \param min minimal value to be set to the transfer function + \param max maximal value to be set to the transfer function + */ void ResetTransferFunction(vtkColorTransferFunction* colorTransferFunction, int type, double min, double max); - void ComputeMinMax(float* data, int num, int& min, int& max); - }; -#endif // _QMITKNEEDLESHAPEREGISTRATIONWIDGET_H_INCLUDED \ No newline at end of file +#endif // _QMITKTOFVISUALISATIONSETTINGSWIDGET_H_INCLUDED diff --git a/Modules/ToFUI/Qmitk/QmitkToFVisualisationSettingsWidgetControls.ui b/Modules/ToFUI/Qmitk/QmitkToFVisualisationSettingsWidgetControls.ui index f74edf23f4..85256ee8b1 100644 --- a/Modules/ToFUI/Qmitk/QmitkToFVisualisationSettingsWidgetControls.ui +++ b/Modules/ToFUI/Qmitk/QmitkToFVisualisationSettingsWidgetControls.ui @@ -1,483 +1,438 @@ QmitkToFVisualisationSettingsWidgetControls 0 0 - 421 - 202 + 482 + 227 0 0 QmitkToFVisualisationSettings 11 ToF Visualization - - - - 0 - 0 - - - - - 60 - 50 - - - - - 10 - - - - 0 - - - 3 - - - QComboBox::InsertAtBottom - - - QComboBox::AdjustToContents - - - - 30 - 30 - - - - true - - - - - - - - :/images/widget1.png:/images/widget1.png - - - - - - - - - :/images/widget2.png:/images/widget2.png - - - - - - - - - :/images/widget3.png:/images/widget3.png - - - - - - - - true - - - - 0 - 0 - - - - - 10 - - - - 0 - - - 3 - - - QComboBox::InsertAtBottom - - - QComboBox::AdjustToContents - - - true - + - - Distance - - - - - Amplitude - - - - - Intensity - - - - - Video - - - - - Surface - - - - - - - - - - - - 3 - - - 3 - - - - - true - - - - 0 - 0 - - - - - 10 - + + + + 0 + 0 + + + + + 200 + 50 + + + + + 10 + + + + 0 + + + 3 + + + QComboBox::InsertAtBottom + + + QComboBox::AdjustToContents + + + + 30 + 30 + + + + true + + + + Distance - - 0 + + + :/images/widget1.png:/images/widget1.png - - 3 + + + + Amplitude - - QComboBox::InsertAtBottom + + + :/images/widget2.png:/images/widget2.png - - QComboBox::AdjustToContents + + + + Intensity - - - 60 - 18 - + + + :/images/widget3.png:/images/widget3.png - - true + + + + + + + true + + + + 0 + 0 + + + + + 150 + 50 + + + + + 16777215 + 50 + + + + + 10 + + + + 0 + + + 3 + + + QComboBox::InsertAtBottom + + + QComboBox::AdjustToContents + + + + 100 + 35 + + + + true + + + + - - - - - - - :/images/grayscale.png:/images/grayscale.png - - - - - - - - - :/images/color.png:/images/color.png - - - - - - - - - 10 - + + + :/images/grayscale.png:/images/grayscale.png + + - Fit scale + - - - - + + + :/images/color.png:/images/color.png + + + + + + + + + 100 + 50 + + + + + 16777215 + 50 + + + + + 10 + + + + Fit scale + + + + - + Gray value/color mapping QFrame::StyledPanel QFrame::Raised 0 modify actual seen window by dragging left and right slider. Qt::Horizontal 0 0 48 16777215 Resets range to histogram minimum and maximum. Reset 1 1 0 28 Left-click to select a point or add a new point. Hold left mouse button to move selected point. Click right mouse button to delete a point. Double-click left mouse button to change color of a point. true 0 0 48 0 48 16777215 7 Edit x-coordinate (grayvalue) of currently selected point. Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter Qt::Horizontal 86 20 0 0 48 0 48 16777215 7 Edit x-coordinate (grayvalue) of currently selected point. Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter Qt::Horizontal 85 20 0 0 48 0 48 16777215 7 Edit x-coordinate (grayvalue) of currently selected point. Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter QxtSpanSlider QSlider
qxtspanslider.h
QmitkColorTransferFunctionCanvas QWidget
QmitkColorTransferFunctionCanvas.h
diff --git a/Modules/ToFUI/files.cmake b/Modules/ToFUI/files.cmake index 61c0117ed9..af636a4574 100644 --- a/Modules/ToFUI/files.cmake +++ b/Modules/ToFUI/files.cmake @@ -1,31 +1,34 @@ SET(CPP_FILES Qmitk/QmitkToFConnectionWidget.cpp + Qmitk/QmitkToFPointSetWidget.cpp Qmitk/QmitkToFRecorderWidget.cpp Qmitk/QmitkToFVisualisationSettingsWidget.cpp Qmitk/QmitkToFCompositeFilterWidget.cpp Qmitk/QmitkToFPMDParameterWidget.cpp Qmitk/QmitkToFMESAParameterWidget.cpp ) SET(UI_FILES Qmitk/QmitkToFConnectionWidgetControls.ui + Qmitk/QmitkToFPointSetWidgetControls.ui Qmitk/QmitkToFRecorderWidgetControls.ui Qmitk/QmitkToFVisualisationSettingsWidgetControls.ui Qmitk/QmitkToFCompositeFilterWidgetControls.ui Qmitk/QmitkToFPMDParameterWidgetControls.ui Qmitk/QmitkToFMESAParameterWidgetControls.ui ) SET(MOC_H_FILES Qmitk/QmitkToFConnectionWidget.h + Qmitk/QmitkToFPointSetWidget.h Qmitk/QmitkToFRecorderWidget.h Qmitk/QmitkToFVisualisationSettingsWidget.h Qmitk/QmitkToFCompositeFilterWidget.h Qmitk/QmitkToFPMDParameterWidget.h Qmitk/QmitkToFMESAParameterWidget.h ) # uncomment the following line if you want to use Qt resources SET(QRC_FILES resources/QmitkToFUtilWidget.qrc -) \ No newline at end of file +) diff --git a/Modules/ToFUI/resources/QmitkToFUtilWidget.qrc b/Modules/ToFUI/resources/QmitkToFUtilWidget.qrc index 78e17447ed..42f151c4da 100644 --- a/Modules/ToFUI/resources/QmitkToFUtilWidget.qrc +++ b/Modules/ToFUI/resources/QmitkToFUtilWidget.qrc @@ -1,19 +1,21 @@ powerGreen.png open.png doc.png SaveAs.png powerRed.png pause.png stop.png rec.png play.png widget1.png widget2.png widget3.png widget4.png grayscale.png color.png + measurement.png + path.png diff --git a/Modules/ToFUI/resources/measurement.png b/Modules/ToFUI/resources/measurement.png new file mode 100644 index 0000000000..32d3911503 Binary files /dev/null and b/Modules/ToFUI/resources/measurement.png differ diff --git a/Modules/ToFUI/resources/path.png b/Modules/ToFUI/resources/path.png new file mode 100644 index 0000000000..95f95f8f8c Binary files /dev/null and b/Modules/ToFUI/resources/path.png differ