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 6627b3feec..42e60bc98e 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,726 +1,749 @@ /*========================================================================= 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 // Qt #include #include // MITK #include #include // VTK #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_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_ToFImageGrabber(NULL) +, m_TransferFunctionInitialized(false), m_ImageSequence(0), m_VideoEnabled(false) +, m_DistanceImageNode(NULL), m_AmplitudeImageNode(NULL), m_IntensityImageNode(NULL), m_SurfaceNode(NULL) // TODO necessary? +, m_QmitkToFImageBackground1(NULL), m_QmitkToFImageBackground2(NULL), m_QmitkToFImageBackground3(NULL) // TODO necessary? { - //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_Surface = mitk::Surface::New(); - this->m_ToFDistanceImageToSurfaceFilter = mitk::ToFDistanceImageToSurfaceFilter::New(); - - this->m_ToFImageGrabber = NULL; - this->m_ToFImageRecorder = mitk::ToFImageRecorder::New(); - - this->m_TransferFunctionInitialized = false; - this->m_ImageSequence = 0; - - this->m_VideoEnabled = false; - - this->m_ToFSurfaceVtkMapper3D = mitk::ToFSurfaceVtkMapper3D::New(); - this->m_ToFCompositeFilter = mitk::ToFCompositeFilter::New(); this->m_ToFVisualizationFilter = mitk::ToFVisualizationFilter::New(); + this->m_ToFImageRecorder = mitk::ToFImageRecorder::New(); + this->m_ToFSurfaceVtkMapper3D = mitk::ToFSurfaceVtkMapper3D::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(); } 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_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); 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(); 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); +// 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); +// 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_DistanceImageNode->SetData( NULL ); +// this->m_AmplitudeImageNode->SetData( NULL ); +// this->m_IntensityImageNode->SetData( NULL ); +// this->m_SurfaceNode->SetData( NULL ); this->m_TransferFunctionInitialized = 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()); + 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); - this->m_MitkDistanceImage = mitk::Image::New(); - this->m_MitkAmplitudeImage = mitk::Image::New(); - this->m_MitkIntensityImage = mitk::Image::New(); +// this->m_MitkDistanceImage = mitk::Image::New(); +// this->m_MitkAmplitudeImage = mitk::Image::New(); +// this->m_MitkIntensityImage = mitk::Image::New(); - InitImage(this->m_MitkDistanceImage, 1); - InitImage(this->m_MitkAmplitudeImage, 1); - InitImage(this->m_MitkIntensityImage, 1); +// InitImage(this->m_MitkDistanceImage, 1); +// InitImage(this->m_MitkAmplitudeImage, 1); +// InitImage(this->m_MitkIntensityImage, 1); this->m_SurfaceDisplayCount = 0; this->m_2DDisplayCount = 0; - 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); +// 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 ); +// } - 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); //TODO this->m_RealTimeClock = mitk::RealTimeClock::New(); this->m_StepsForFramerate = 100; this->m_2DTimeBefore = 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_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; } - m_Controls->m_ToFRecorderWidget->setEnabled(true); - m_Controls->m_ToFRecorderWidget->ResetGUIToInitial(); - m_Controls->m_ToFVisualisationSettingsWidget->setEnabled(true); mitk::RenderingManager::GetInstance()->ForceImmediateUpdateAll(); } void QmitkToFUtilView::OnToFCameraDisconnected() { 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(); delete[] this->m_Widget1Texture; delete[] this->m_Widget2Texture; delete[] this->m_Widget3Texture; } void QmitkToFUtilView::OnToFCameraStarted() { - // 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); - - m_Controls->m_ToFCompositeFilterWidget->UpdateFilterParameter(); - - if (m_Controls->m_TextureCheckBox->isChecked()) + if (m_ToFImageGrabber.IsNotNull()) { - OnTextureCheckBoxChecked(true); - } - if (m_Controls->m_VideoTextureCheckBox->isChecked()) - { - OnVideoTextureCheckBoxChecked(true); - } + // 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_DistanceImageNode = ReplaceNodeData("Distance image",m_MitkDistanceImage); + this->m_DistanceImageNode->SetProperty( "visible" , mitk::BoolProperty::New( true )); + this->m_DistanceImageNode->SetVisibility( false, mitk::BaseRenderer::GetInstance(GetActiveStdMultiWidget()->mitkWidget2->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_MitkAmplitudeImage = m_ToFCompositeFilter->GetOutput(1); + this->m_AmplitudeImageNode = ReplaceNodeData("Amplitude image",m_MitkAmplitudeImage); + this->m_AmplitudeImageNode->SetProperty( "visible" , mitk::BoolProperty::New( true )); + this->m_AmplitudeImageNode->SetVisibility( false, mitk::BaseRenderer::GetInstance(GetActiveStdMultiWidget()->mitkWidget1->GetRenderWindow() ) ); + this->m_AmplitudeImageNode->SetVisibility( false, mitk::BaseRenderer::GetInstance(GetActiveStdMultiWidget()->mitkWidget3->GetRenderWindow() ) ); + this->m_AmplitudeImageNode->SetVisibility( false, mitk::BaseRenderer::GetInstance(GetActiveStdMultiWidget()->mitkWidget4->GetRenderWindow() ) ); + + this->m_MitkIntensityImage = m_ToFCompositeFilter->GetOutput(2); + this->m_IntensityImageNode = ReplaceNodeData("Intensity image",m_MitkIntensityImage); + this->m_IntensityImageNode->SetProperty( "visible" , mitk::BoolProperty::New( true )); + this->m_IntensityImageNode->SetVisibility( false, mitk::BaseRenderer::GetInstance(GetActiveStdMultiWidget()->mitkWidget1->GetRenderWindow() ) ); + this->m_IntensityImageNode->SetVisibility( false, mitk::BaseRenderer::GetInstance(GetActiveStdMultiWidget()->mitkWidget2->GetRenderWindow() ) ); + this->m_IntensityImageNode->SetVisibility( false, mitk::BaseRenderer::GetInstance(GetActiveStdMultiWidget()->mitkWidget4->GetRenderWindow() ) ); + + 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); + + mitk::RenderingManager::GetInstance()->InitializeViews( + this->m_MitkDistanceImage->GetTimeSlicedGeometry(), mitk::RenderingManager::REQUEST_UPDATE_ALL, true); + this->m_Frametimer->start(0); + + m_Controls->m_ToFCompositeFilterWidget->UpdateFilterParameter(); + + if (m_Controls->m_TextureCheckBox->isChecked()) + { + OnTextureCheckBoxChecked(true); + } + if (m_Controls->m_VideoTextureCheckBox->isChecked()) + { + OnVideoTextureCheckBoxChecked(true); + } + } } void QmitkToFUtilView::OnToFCameraStopped() { this->m_Frametimer->stop(); } 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; im_MitkDistanceImage->GetData(); } else if (imageType.compare("Amplitude")==0) { data = this->m_MitkAmplitudeImage->GetData(); } if (imageType.compare("Intensity")==0) { data = this->m_MitkIntensityImage->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 (!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(); - } +// 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; +// 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->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->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 ); +// 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 ); if (m_Controls->m_SurfaceCheckBox->isChecked()) { // update surface this->m_Surface->Update(); colorTransferFunction = m_Controls->m_ToFVisualisationSettingsWidget->GetColorTransferFunctionByImageType("Intensity"); this->m_ToFSurfaceVtkMapper3D->SetVtkScalarsToColors(colorTransferFunction); 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(); + // // update distance image node + // this->m_DistanceImageNode->SetData(this->m_MitkDistanceImage); + } mitk::RenderingManager::GetInstance()->ForceImmediateUpdateAll(); 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; this->m_2DTimeBefore = this->m_RealTimeClock->GetCurrentStamp(); } } void QmitkToFUtilView::ProcessVideoTransform() { 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 ) { if (newImageType.compare("Video") == 0) { if (this->m_VideoEnabled) { if (oldImageType.compare(newImageType)!=0) { imageBackground->AddRenderWindow(mitkWidget->GetRenderWindow(), this->m_VideoCaptureWidth, this->m_VideoCaptureHeight); oldImageType = newImageType; } imageBackground->UpdateBackground(videoTexture); } } else { if (oldImageType.compare(newImageType)!=0) { imageBackground->AddRenderWindow(mitkWidget->GetRenderWindow(), this->m_ToFCaptureWidth, this->m_ToFCaptureHeight); oldImageType = newImageType; } void* data = GetDataFromImage(newImageType); PrepareImageForBackground(colorTransferFunction, (float*)data, tofTexture); imageBackground->UpdateBackground(tofTexture); } } 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_ToFSurfaceVtkMapper3D->SetTexture(this->m_VideoTexture); } else { this->m_ToFSurfaceVtkMapper3D->SetTexture(NULL); } } else { this->m_ToFSurfaceVtkMapper3D->SetTexture(NULL); } } 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++) { for (int j=0; jm_ToFCaptureWidth; j++) { flippedFloatData[i*this->m_ToFCaptureWidth+j] = floatData[((this->m_ToFCaptureHeight-1-i)*this->m_ToFCaptureWidth)+j]; } } 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++) { for (int j=0; jm_ToFCaptureWidth; j++) { flippedFloatData[i*this->m_ToFCaptureWidth+j] = floatData[((this->m_ToFCaptureHeight-1-i)*this->m_ToFCaptureWidth)+j]; } } floatArrayDist->SetArray(flippedFloatData, numOfPixel, 0); colorTransferFunction->MapScalarsThroughTable(floatArrayDist, image, VTK_RGB); delete[] flippedFloatData; } void QmitkToFUtilView::RemoveBackground() { if(this->m_QmitkToFImageBackground1) { this->m_QmitkToFImageBackground1->RemoveRenderWindow(m_MultiWidget->mitkWidget1->GetRenderWindow()); } if(this->m_QmitkToFImageBackground2) { this->m_QmitkToFImageBackground2->RemoveRenderWindow(m_MultiWidget->mitkWidget2->GetRenderWindow()); } if(this->m_QmitkToFImageBackground3) { this->m_QmitkToFImageBackground3->RemoveRenderWindow(m_MultiWidget->mitkWidget3->GetRenderWindow()); } } 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(); } + +mitk::DataNode::Pointer QmitkToFUtilView::ReplaceNodeData( std::string nodeName, mitk::BaseData* data ) +{ + + mitk::DataNode::Pointer node = this->GetDefaultDataStorage()->GetNamedNode(nodeName); + if (node.IsNull()) + { + node = mitk::DataNode::New(); + node->SetData(data); + node->SetName(nodeName); + this->GetDefaultDataStorage()->Add(node); + } + else + { + node->SetData(data); + } + return node; +} 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 a5e811b4fe..db7e0b399a 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,194 +1,202 @@ /*========================================================================= 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 typedef itk::Image ItkImageType2D; /*! \brief QmitkToFUtilView \warning This application is still under active development. Complete documentation will be added when class is finished. \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(); virtual void Deactivated(); virtual void StdMultiWidgetAvailable (QmitkStdMultiWidget &stdMultiWidget); virtual void StdMultiWidgetNotAvailable(); protected slots: /// \brief Called when the user clicks the GUI button void OnUpdateCamera(); /*! \This method is automatically called by the connection widgets when the configuration is completed */ void OnToFCameraConnected(); void OnToFCameraDisconnected(); void OnToFCameraStarted(); void OnToFCameraStopped(); void OnToFCameraSelected(const QString selected); void OnTextureCheckBoxChecked(bool checked); void OnVideoTextureCheckBoxChecked(bool checked); protected: void InitImage(mitk::Image::Pointer image, int numOfChannel); void InitTexture(unsigned char* &image, int width, int height); void PrepareImageForBackground(vtkLookupTable* lut, float* floadData, unsigned char* image); void PrepareImageForBackground(vtkColorTransferFunction* colorTransferFunction, float* floatData, unsigned char* image); void RemoveBackground(); void AddBackground(); Ui::QmitkToFUtilViewControls* m_Controls; QmitkStdMultiWidget* m_MultiWidget; QTimer* m_Frametimer; - mitk::ToFImageGrabber* m_ToFImageGrabber; + mitk::ToFImageGrabber::Pointer m_ToFImageGrabber; 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::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_SurfaceNode; mitk::ToFImageRecorder::Pointer m_ToFImageRecorder; int m_ImageSequence; mitk::RealTimeClock::Pointer m_RealTimeClock; int m_StepsForFramerate; double m_2DTimeBefore, m_2DTimeAfter; 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; int m_ToFCaptureWidth; int m_ToFCaptureHeight; int m_VideoCaptureWidth; int m_VideoCaptureHeight; mitk::ToFDistanceImageToSurfaceFilter::Pointer m_ToFDistanceImageToSurfaceFilter; mitk::ToFCompositeFilter::Pointer m_ToFCompositeFilter; mitk::ToFVisualizationFilter::Pointer m_ToFVisualizationFilter; private: + /*! + \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 RemoveNode(const char* nodename, mitk::DataNode::Pointer node); void CreateNode(const char* nodename, mitk::DataNode::Pointer& node); void* GetDataFromImage(std::string imageType); void RenderWidget(QmitkRenderWindow* mitkWidget, QmitkToFImageBackground* imageBackground, std::string& oldImageType, std::string newImageType, vtkColorTransferFunction* colorTransferFunction, unsigned char* videoTexture, unsigned char* tofTexture ); void ProcessVideoTransform(); bool m_TransferFunctionInitialized; int m_SurfaceDisplayCount; int m_2DDisplayCount; bool m_VideoEnabled; std::string m_Widget1ImageType; std::string m_Widget2ImageType; std::string m_Widget3ImageType; mitk::ToFSurfaceVtkMapper3D::Pointer m_ToFSurfaceVtkMapper3D; }; #endif // _QMITKTOFUTILVIEW_H_INCLUDED 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); } }