diff --git a/Core/Code/Algorithms/mitk2DTo3DImageFilter.cpp b/Core/Code/Algorithms/mitk2DTo3DImageFilter.cpp new file mode 100644 index 0000000000..755e7496c1 --- /dev/null +++ b/Core/Code/Algorithms/mitk2DTo3DImageFilter.cpp @@ -0,0 +1,65 @@ +/*=================================================================== + +The Medical Imaging Interaction Toolkit (MITK) + +Copyright (c) German Cancer Research Center, +Division of Medical and Biological Informatics. +All rights reserved. + +This software is distributed WITHOUT ANY WARRANTY; without +even the implied warranty of MERCHANTABILITY or FITNESS FOR +A PARTICULAR PURPOSE. + +See LICENSE.txt or http://www.mitk.org for details. + +===================================================================*/ + +#include "mitkImageAccessByItk.h" +#include "mitkITKImageImport.h" +#include "mitk2DTo3DImageFilter.h" + +mitk::2DTo3DImageFilter::BilateralFilter() + : m_DomainSigma(2.0f), m_RangeSigma(50.0f), m_AutoKernel(true), m_KernelRadius(1u) +{ + //default parameters DomainSigma: 2 , RangeSigma: 50, AutoKernel: true, KernelRadius: 1 +} + +mitk::BilateralFilter::~BilateralFilter() +{ +} + +void mitk::BilateralFilter::GenerateData() +{ + +} + +template +void mitk::BilateralFilter::ItkImageProcessing( itk::Image* itkImage ) +{ + //ITK Image type given from the input image + typedef itk::Image< TPixel, VImageDimension > ItkImageType; + //bilateral filter with same type + typedef itk::BilateralImageFilter BilateralFilterType; + typename BilateralFilterType::Pointer bilateralFilter = BilateralFilterType::New(); + bilateralFilter->SetInput(itkImage); + //set parameters + if(!m_AutoKernel){ + bilateralFilter->SetAutomaticKernelSize(m_AutoKernel); + bilateralFilter->SetRadius(m_KernelRadius); + } + bilateralFilter->SetDomainSigma(m_DomainSigma); + bilateralFilter->SetRangeSigma(m_RangeSigma); + bilateralFilter->UpdateLargestPossibleRegion(); + //get Pointer to output image + mitk::Image::Pointer resultImage = this->GetOutput(); + //write into output image + mitk::CastToMitkImage(bilateralFilter->GetOutput(), resultImage); +} + +void mitk::BilateralFilter::GenerateOutputInformation() +{ + mitk::Image::Pointer inputImage = (mitk::Image*) this->GetInput(); + mitk::Image::Pointer output = this->GetOutput(); + itkDebugMacro(<<"GenerateOutputInformation()"); + if(inputImage.IsNull()) return; +} diff --git a/Core/Code/Algorithms/mitk2DTo3DImageFilter.h b/Core/Code/Algorithms/mitk2DTo3DImageFilter.h new file mode 100644 index 0000000000..5b45552632 --- /dev/null +++ b/Core/Code/Algorithms/mitk2DTo3DImageFilter.h @@ -0,0 +1,77 @@ +/*=================================================================== + +The Medical Imaging Interaction Toolkit (MITK) + +Copyright (c) German Cancer Research Center, +Division of Medical and Biological Informatics. +All rights reserved. + +This software is distributed WITHOUT ANY WARRANTY; without +even the implied warranty of MERCHANTABILITY or FITNESS FOR +A PARTICULAR PURPOSE. + +See LICENSE.txt or http://www.mitk.org for details. + +===================================================================*/ +#ifndef __mitk2DTo3DImageFilter_h +#define __mitk2DTo3DImageFilter_h + +//MITK +#include +#include "mitkImageToImageFilter.h" + +#include + +namespace mitk +{ + + class MITK_CORE_EXPORT 2DTo3DImageFilter : public ImageToImageFilter + { + public: + + mitkClassMacro( 2DTo3DImageFilter , ImageToImageFilter ); + itkNewMacro( Self ); + + itkSetMacro(DomainSigma,float); + itkSetMacro(RangeSigma,float); + itkSetMacro(AutoKernel,bool); + itkSetMacro(KernelRadius,unsigned int); + + itkGetMacro(DomainSigma,float); + itkGetMacro(RangeSigma,float); + itkGetMacro(AutoKernel,bool); + itkGetMacro(KernelRadius,unsigned int); + + protected: + /*! + \brief standard constructor + */ + BilateralFilter(); + /*! + \brief standard destructor + */ + ~BilateralFilter(); + /*! + \brief Method generating the output information of this filter (e.g. image dimension, image type, etc.). + The interface ImageToImageFilter requires this implementation. Everything is taken from the input image. + */ + virtual void GenerateOutputInformation(); + /*! + \brief Method generating the output of this filter. Called in the updated process of the pipeline. + This method generates the smoothed output image. + */ + virtual void GenerateData(); + + /*! + \brief Internal templated method calling the ITK bilteral filter. Here the actual filtering is performed. + */ + template + void ItkImageProcessing( itk::Image* itkImage ); + + float m_DomainSigma; ///Sigma of the gaussian kernel. See ITK docu + float m_RangeSigma; ///Sigma of the range mask kernel. See ITK docu + bool m_AutoKernel; //true: kernel size is calculated from DomainSigma. See ITK Doc; false: set by m_KernelRadius + unsigned int m_KernelRadius; //use in combination with m_AutoKernel = true + }; +} //END mitk namespace +#endif diff --git a/Core/Code/files.cmake b/Core/Code/files.cmake index fd463e7704..b40882dcde 100644 --- a/Core/Code/files.cmake +++ b/Core/Code/files.cmake @@ -1,302 +1,305 @@ set(H_FILES Algorithms/itkImportMitkImageContainer.h Algorithms/itkImportMitkImageContainer.txx Algorithms/itkLocalVariationImageFilter.h Algorithms/itkLocalVariationImageFilter.txx Algorithms/itkMITKScalarImageToHistogramGenerator.h Algorithms/itkMITKScalarImageToHistogramGenerator.txx Algorithms/itkTotalVariationDenoisingImageFilter.h Algorithms/itkTotalVariationDenoisingImageFilter.txx Algorithms/itkTotalVariationSingleIterationImageFilter.h Algorithms/itkTotalVariationSingleIterationImageFilter.txx Algorithms/mitkBilateralFilter.h Algorithms/mitkBilateralFilter.cpp Algorithms/mitkInstantiateAccessFunctions.h Algorithms/mitkPixelTypeList.h # Preprocessor macros taken from Boost Algorithms/mitkPPArithmeticDec.h Algorithms/mitkPPArgCount.h Algorithms/mitkPPCat.h Algorithms/mitkPPConfig.h Algorithms/mitkPPControlExprIIf.h Algorithms/mitkPPControlIf.h Algorithms/mitkPPControlIIf.h Algorithms/mitkPPDebugError.h Algorithms/mitkPPDetailAutoRec.h Algorithms/mitkPPDetailDMCAutoRec.h Algorithms/mitkPPExpand.h Algorithms/mitkPPFacilitiesEmpty.h Algorithms/mitkPPFacilitiesExpand.h Algorithms/mitkPPLogicalBool.h Algorithms/mitkPPRepetitionDetailDMCFor.h Algorithms/mitkPPRepetitionDetailEDGFor.h Algorithms/mitkPPRepetitionDetailFor.h Algorithms/mitkPPRepetitionDetailMSVCFor.h Algorithms/mitkPPRepetitionFor.h Algorithms/mitkPPSeqElem.h Algorithms/mitkPPSeqForEach.h Algorithms/mitkPPSeqForEachProduct.h Algorithms/mitkPPSeq.h Algorithms/mitkPPSeqEnum.h Algorithms/mitkPPSeqSize.h Algorithms/mitkPPSeqToTuple.h Algorithms/mitkPPStringize.h Algorithms/mitkPPTupleEat.h Algorithms/mitkPPTupleElem.h Algorithms/mitkPPTupleRem.h Algorithms/mitkClippedSurfaceBoundsCalculator.h Algorithms/mitkExtractSliceFilter.h + Algorithms/mitk2DTo3DImageFilter.h DataManagement/mitkImageAccessByItk.h DataManagement/mitkImageCast.h DataManagement/mitkITKImageImport.h DataManagement/mitkITKImageImport.txx DataManagement/mitkImageToItk.h DataManagement/mitkImageToItk.txx Interfaces/mitkIDataNodeReader.h IO/mitkPixelTypeTraits.h Interactions/mitkEventMapperAddOn.h Common/mitkExceptionMacro.h Common/mitkTestingMacros.h + ) set(CPP_FILES Algorithms/mitkBaseDataSource.cpp Algorithms/mitkBaseProcess.cpp Algorithms/mitkDataNodeSource.cpp Algorithms/mitkGeometry2DDataToSurfaceFilter.cpp Algorithms/mitkHistogramGenerator.cpp Algorithms/mitkImageChannelSelector.cpp Algorithms/mitkImageSliceSelector.cpp Algorithms/mitkImageSource.cpp Algorithms/mitkImageTimeSelector.cpp Algorithms/mitkImageToImageFilter.cpp Algorithms/mitkPointSetSource.cpp Algorithms/mitkPointSetToPointSetFilter.cpp Algorithms/mitkRGBToRGBACastImageFilter.cpp Algorithms/mitkSubImageSelector.cpp Algorithms/mitkSurfaceSource.cpp Algorithms/mitkSurfaceToSurfaceFilter.cpp Algorithms/mitkUIDGenerator.cpp Algorithms/mitkVolumeCalculator.cpp Algorithms/mitkClippedSurfaceBoundsCalculator.cpp Algorithms/mitkExtractSliceFilter.cpp + Algorithms/mitk2DTo3DImageFilter.cpp Controllers/mitkBaseController.cpp Controllers/mitkCallbackFromGUIThread.cpp Controllers/mitkCameraController.cpp Controllers/mitkCameraRotationController.cpp Controllers/mitkCoreActivator.cpp Controllers/mitkFocusManager.cpp Controllers/mitkLimitedLinearUndo.cpp Controllers/mitkOperationEvent.cpp Controllers/mitkPlanePositionManager.cpp Controllers/mitkProgressBar.cpp Controllers/mitkRenderingManager.cpp Controllers/mitkSliceNavigationController.cpp Controllers/mitkSlicesCoordinator.cpp Controllers/mitkSlicesRotator.cpp Controllers/mitkSlicesSwiveller.cpp Controllers/mitkStatusBar.cpp Controllers/mitkStepper.cpp Controllers/mitkTestManager.cpp Controllers/mitkUndoController.cpp Controllers/mitkVerboseLimitedLinearUndo.cpp Controllers/mitkVtkInteractorCameraController.cpp Controllers/mitkVtkLayerController.cpp DataManagement/mitkAbstractTransformGeometry.cpp DataManagement/mitkAnnotationProperty.cpp DataManagement/mitkApplicationCursor.cpp DataManagement/mitkBaseData.cpp DataManagement/mitkBaseProperty.cpp DataManagement/mitkClippingProperty.cpp DataManagement/mitkChannelDescriptor.cpp DataManagement/mitkColorProperty.cpp DataManagement/mitkDataStorage.cpp #DataManagement/mitkDataTree.cpp DataManagement/mitkDataNode.cpp DataManagement/mitkDataNodeFactory.cpp #DataManagement/mitkDataTreeStorage.cpp DataManagement/mitkDisplayGeometry.cpp DataManagement/mitkEnumerationProperty.cpp DataManagement/mitkGeometry2D.cpp DataManagement/mitkGeometry2DData.cpp DataManagement/mitkGeometry3D.cpp DataManagement/mitkGeometryData.cpp DataManagement/mitkGroupTagProperty.cpp DataManagement/mitkImage.cpp DataManagement/mitkImageCaster.cpp DataManagement/mitkImageCastPart1.cpp DataManagement/mitkImageCastPart2.cpp DataManagement/mitkImageCastPart3.cpp DataManagement/mitkImageCastPart4.cpp DataManagement/mitkImageDataItem.cpp DataManagement/mitkImageDescriptor.cpp DataManagement/mitkImageStatisticsHolder.cpp DataManagement/mitkLandmarkBasedCurvedGeometry.cpp DataManagement/mitkLandmarkProjectorBasedCurvedGeometry.cpp DataManagement/mitkLandmarkProjector.cpp DataManagement/mitkLevelWindow.cpp DataManagement/mitkLevelWindowManager.cpp DataManagement/mitkLevelWindowPreset.cpp DataManagement/mitkLevelWindowProperty.cpp DataManagement/mitkLookupTable.cpp DataManagement/mitkLookupTables.cpp # specializations of GenericLookupTable DataManagement/mitkMemoryUtilities.cpp DataManagement/mitkModalityProperty.cpp DataManagement/mitkModeOperation.cpp DataManagement/mitkNodePredicateAnd.cpp DataManagement/mitkNodePredicateBase.cpp DataManagement/mitkNodePredicateCompositeBase.cpp DataManagement/mitkNodePredicateData.cpp DataManagement/mitkNodePredicateDataType.cpp DataManagement/mitkNodePredicateDimension.cpp DataManagement/mitkNodePredicateFirstLevel.cpp DataManagement/mitkNodePredicateNot.cpp DataManagement/mitkNodePredicateOr.cpp DataManagement/mitkNodePredicateProperty.cpp DataManagement/mitkNodePredicateSource.cpp DataManagement/mitkPlaneOrientationProperty.cpp DataManagement/mitkPlaneGeometry.cpp DataManagement/mitkPlaneOperation.cpp DataManagement/mitkPointOperation.cpp DataManagement/mitkPointSet.cpp DataManagement/mitkProperties.cpp DataManagement/mitkPropertyList.cpp DataManagement/mitkRestorePlanePositionOperation.cpp DataManagement/mitkRotationOperation.cpp DataManagement/mitkSlicedData.cpp DataManagement/mitkSlicedGeometry3D.cpp DataManagement/mitkSmartPointerProperty.cpp DataManagement/mitkStandaloneDataStorage.cpp DataManagement/mitkStateTransitionOperation.cpp DataManagement/mitkStringProperty.cpp DataManagement/mitkSurface.cpp DataManagement/mitkSurfaceOperation.cpp DataManagement/mitkThinPlateSplineCurvedGeometry.cpp DataManagement/mitkTimeSlicedGeometry.cpp DataManagement/mitkTransferFunction.cpp DataManagement/mitkTransferFunctionProperty.cpp DataManagement/mitkTransferFunctionInitializer.cpp DataManagement/mitkVector.cpp DataManagement/mitkVtkInterpolationProperty.cpp DataManagement/mitkVtkRepresentationProperty.cpp DataManagement/mitkVtkResliceInterpolationProperty.cpp DataManagement/mitkVtkScalarModeProperty.cpp DataManagement/mitkVtkVolumeRenderingProperty.cpp DataManagement/mitkWeakPointerProperty.cpp DataManagement/mitkShaderProperty.cpp DataManagement/mitkResliceMethodProperty.cpp DataManagement/mitkMaterial.cpp Interactions/mitkAction.cpp Interactions/mitkAffineInteractor.cpp Interactions/mitkCoordinateSupplier.cpp Interactions/mitkDisplayCoordinateOperation.cpp Interactions/mitkDisplayInteractor.cpp Interactions/mitkDisplayPositionEvent.cpp Interactions/mitkDisplayVectorInteractor.cpp Interactions/mitkDisplayVectorInteractorLevelWindow.cpp Interactions/mitkDisplayVectorInteractorScroll.cpp Interactions/mitkEvent.cpp Interactions/mitkEventDescription.cpp Interactions/mitkEventMapper.cpp Interactions/mitkGlobalInteraction.cpp Interactions/mitkInteractor.cpp Interactions/mitkMouseModeSwitcher.cpp Interactions/mitkMouseMovePointSetInteractor.cpp Interactions/mitkMoveSurfaceInteractor.cpp Interactions/mitkNodeDepententPointSetInteractor.cpp Interactions/mitkPointSetInteractor.cpp Interactions/mitkPositionEvent.cpp Interactions/mitkPositionTracker.cpp Interactions/mitkState.cpp Interactions/mitkStateEvent.cpp Interactions/mitkStateMachine.cpp Interactions/mitkStateMachineFactory.cpp Interactions/mitkTransition.cpp Interactions/mitkWheelEvent.cpp Interactions/mitkKeyEvent.cpp Interactions/mitkVtkEventAdapter.cpp Interactions/mitkVtkInteractorStyle.cxx Interactions/mitkCrosshairPositionEvent.cpp IO/mitkBaseDataIOFactory.cpp IO/mitkCoreDataNodeReader.cpp IO/mitkDicomSeriesReader.cpp IO/mitkFileReader.cpp IO/mitkFileSeriesReader.cpp IO/mitkFileWriter.cpp #IO/mitkIpPicGet.c IO/mitkImageGenerator.cpp IO/mitkImageWriter.cpp IO/mitkImageWriterFactory.cpp IO/mitkItkImageFileIOFactory.cpp IO/mitkItkImageFileReader.cpp IO/mitkItkPictureWrite.cpp IO/mitkIOUtil.cpp IO/mitkLookupTableProperty.cpp IO/mitkOperation.cpp #IO/mitkPicFileIOFactory.cpp #IO/mitkPicFileReader.cpp #IO/mitkPicFileWriter.cpp #IO/mitkPicHelper.cpp #IO/mitkPicVolumeTimeSeriesIOFactory.cpp #IO/mitkPicVolumeTimeSeriesReader.cpp IO/mitkPixelType.cpp IO/mitkPointSetIOFactory.cpp IO/mitkPointSetReader.cpp IO/mitkPointSetWriter.cpp IO/mitkPointSetWriterFactory.cpp IO/mitkRawImageFileReader.cpp IO/mitkStandardFileLocations.cpp IO/mitkSTLFileIOFactory.cpp IO/mitkSTLFileReader.cpp IO/mitkSurfaceVtkWriter.cpp IO/mitkSurfaceVtkWriterFactory.cpp IO/mitkVtiFileIOFactory.cpp IO/mitkVtiFileReader.cpp IO/mitkVtkImageIOFactory.cpp IO/mitkVtkImageReader.cpp IO/mitkVtkSurfaceIOFactory.cpp IO/mitkVtkSurfaceReader.cpp IO/vtkPointSetXMLParser.cpp IO/mitkLog.cpp Rendering/mitkBaseRenderer.cpp Rendering/mitkVtkMapper2D.cpp Rendering/mitkVtkMapper3D.cpp Rendering/mitkRenderWindowFrame.cpp Rendering/mitkGeometry2DDataMapper2D.cpp Rendering/mitkGeometry2DDataVtkMapper3D.cpp Rendering/mitkGLMapper2D.cpp Rendering/mitkGradientBackground.cpp Rendering/mitkManufacturerLogo.cpp Rendering/mitkMapper2D.cpp Rendering/mitkMapper3D.cpp Rendering/mitkMapper.cpp Rendering/mitkPointSetGLMapper2D.cpp Rendering/mitkPointSetVtkMapper3D.cpp Rendering/mitkPolyDataGLMapper2D.cpp Rendering/mitkSurfaceGLMapper2D.cpp Rendering/mitkSurfaceVtkMapper3D.cpp Rendering/mitkVolumeDataVtkMapper3D.cpp Rendering/mitkVtkPropRenderer.cpp Rendering/mitkVtkWidgetRendering.cpp Rendering/vtkMitkRectangleProp.cpp Rendering/vtkMitkRenderProp.cpp Rendering/mitkVtkEventProvider.cpp Rendering/mitkRenderWindow.cpp Rendering/mitkRenderWindowBase.cpp Rendering/mitkShaderRepository.cpp Rendering/mitkImageVtkMapper2D.cpp Rendering/vtkMitkThickSlicesFilter.cpp Rendering/vtkMitkApplyLevelWindowToRGBFilter.cpp Common/mitkException.cpp Common/mitkCommon.h Common/mitkCoreObjectFactoryBase.cpp Common/mitkCoreObjectFactory.cpp ) list(APPEND CPP_FILES ${CppMicroServices_SOURCES}) diff --git a/Modules/QmitkExt/QmitkApplicationBase/QmitkCommonFunctionality.cpp b/Modules/QmitkExt/QmitkApplicationBase/QmitkCommonFunctionality.cpp index cf63db8a7d..6a10eb9703 100644 --- a/Modules/QmitkExt/QmitkApplicationBase/QmitkCommonFunctionality.cpp +++ b/Modules/QmitkExt/QmitkApplicationBase/QmitkCommonFunctionality.cpp @@ -1,813 +1,816 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #include #include #include #include #include #include #include "mitkPointSetWriter.h" #include "mitkConfig.h" #include "mitkCoreObjectFactory.h" #include "QmitkCommonFunctionality.h" #include #include #include #include #include #include #include #include #include #include #include void CommonFunctionality::SaveToFileWriter( mitk::FileWriterWithInformation::Pointer fileWriter, mitk::BaseData::Pointer data, const char* aFileName, const char* propFileName) { // Check if desired format is supported if (! fileWriter->CanWriteBaseDataType(data) ) { QMessageBox::critical(NULL,"ERROR","Could not write file. Invalid data type for file writer."); return; } // Ensure a valid filename QString fileName; if (aFileName == NULL) { QString proposedName(""); if(propFileName == NULL) { proposedName.append(fileWriter->GetDefaultFilename()); } else { proposedName.append(propFileName).append(fileWriter->GetDefaultExtension()); } fileName = GetSaveFileNameStartingInLastDirectory("Save file", proposedName,QString::fromAscii(fileWriter->GetFileDialogPattern())); // Check if an extension exists already and if not, append the default extension if ( !fileName.contains( QRegExp("\\.\\w+$") ) ) { fileName.append( fileWriter->GetDefaultExtension() ); } else { std::string extension = itksys::SystemTools::GetFilenameLastExtension( fileName.toLocal8Bit().constData() ); if (!fileWriter->IsExtensionValid(extension)) { QString message; message.append("File extension not suitable for writing given data. Choose one extension of this list: "); message.append(fileWriter->GetPossibleFileExtensionsAsString().c_str()); QMessageBox::critical(NULL,"ERROR",message); return; } } } else fileName = aFileName; // Write if (fileName.isEmpty() == false ) { fileWriter->SetFileName( fileName.toLocal8Bit().constData() ); fileWriter->DoWrite( data ); } } /** * Saves the given mitk::BaseData to a file. The user is prompted to * enter a file name. Currently only mitk::Image, mitk::Surface, mitk::PointSet and * mitk::VesselGraphData are supported. This function is deprecated * until the save-problem is solved by means of a Save-Factory or any * other "nice" mechanism */ void CommonFunctionality::SaveBaseData( mitk::BaseData* data, const char * aFileName ) { //save initial time QDateTime initialTime = QDateTime::currentDateTime(); std::string fileNameUsed; //file name that was actually used by the writer (e.g. after file open dialog) bool writingSuccessful = false; try{ if (data != NULL) { mitk::Image::Pointer image = dynamic_cast(data); QString classname(data->GetNameOfClass()); if ( image.IsNotNull() && (classname.compare("Image")==0 || classname.compare("SeedsImage")==0 ) ) { fileNameUsed = CommonFunctionality::SaveImage(image, aFileName, true); if(!(fileNameUsed.length()>0)){ return; } else { writingSuccessful = true; } } if(!writingSuccessful) { mitk::PointSet::Pointer pointset = dynamic_cast(data); if(pointset.IsNotNull()) { std::string fileName; if(aFileName == NULL) fileName = "PointSet"; else fileName = aFileName; fileName = itksys::SystemTools::GetFilenameWithoutExtension(fileName); QString initialFileName = QString::fromStdString(fileName); QString selected_suffix("MITK Point-Sets (*.mps)"); QString possible_suffixes("MITK Point-Sets (*.mps)"); /*QString qfileName = QFileDialog::getSaveFileName( NULL, "Save image", initialFilename ,mitk::CoreObjectFactory::GetInstance()->GetSaveFileExtensions(),&selected_suffix); */ QString qfileName = GetSaveFileNameStartingInLastDirectory("Save file", initialFileName, possible_suffixes, &selected_suffix); MITK_INFO<IsExtensionValid(extension)) { QString message; message.append("File extension not suitable for writing point set data. Choose one extension of this list: "); message.append(writer->GetPossibleFileExtensionsAsString().c_str()); QMessageBox::critical(NULL,"ERROR",message); return; } if (qfileName.isEmpty() == false ) { writer->SetInput( pointset ); writer->SetFileName( qfileName.toLocal8Bit().constData() ); writer->Update(); fileNameUsed = writer->GetFileName(); writingSuccessful = true; } else { return; } } if(!writingSuccessful) { mitk::Surface::Pointer surface = dynamic_cast(data); if(surface.IsNotNull()) { fileNameUsed = CommonFunctionality::SaveSurface(surface, aFileName); if(!(fileNameUsed.length()>0)){ return; } else { writingSuccessful = true; } } if(!writingSuccessful) { // now try the file writers provided by the CoreObjectFactory mitk::CoreObjectFactory::FileWriterList fileWriters = mitk::CoreObjectFactory::GetInstance()->GetFileWriters(); bool writerFound = false; for (mitk::CoreObjectFactory::FileWriterList::iterator it = fileWriters.begin() ; it != fileWriters.end() ; ++it) { if ( (*it)->CanWriteBaseDataType(data) ) { writerFound = true; SaveToFileWriter(*it, data, NULL, aFileName); fileNameUsed = (*it)->GetFileName(); // correct writer has been found->break if(!(fileNameUsed.length()>0)){ return; } else { writingSuccessful = true; break; } } } if(!writerFound) { // no appropriate writer has been found QMessageBox::critical(NULL,"ERROR","Could not find file writer for this data type"); return; } } } } } else { QMessageBox::critical(NULL,"ERROR","Cannot write data (invalid/empty)"); return; } } catch(itk::ExceptionObject e) { QMessageBox::critical( NULL, "SaveDialog", e.GetDescription(),QMessageBox::Ok, QMessageBox::NoButton, QMessageBox::NoButton); } //writing is assumed to have been successful //check if file exists, file size >0 and last modified after this function was called try{ QFileInfo* fileInfo = new QFileInfo(QString(fileNameUsed.c_str())); if(!fileInfo->exists()) { QMessageBox::warning(NULL,"WARNING","File was not created or was split into multiple files"); } else if(fileInfo->size()==0) { QMessageBox::warning(NULL,"WARNING","File is empty"); } else if(fileInfo->lastModified()SetFileName( fileName ); factory->Update(); return factory->GetOutput( 0 ); } catch ( itk::ExceptionObject & ex ) { itkGenericOutputMacro( << "Exception during file open: " << ex ); return NULL; } } mitk::DataNode::Pointer CommonFunctionality::FileOpenImageSequence(const QString& aFileName) { return FileOpenImageSequence( aFileName.toLocal8Bit().constData() ); } mitk::DataNode::Pointer CommonFunctionality::FileOpenImageSequence(const char* aFileName) { if(aFileName==NULL) return NULL; mitk::DataNodeFactory::Pointer factory = mitk::DataNodeFactory::New(); QString fileName = aFileName; if (!fileName.contains("dcm") && !fileName.contains("DCM")) { int fnstart = fileName.lastIndexOf( QRegExp("[/\\\\]"), fileName.length() ); if(fnstart<0) fnstart=0; int start = fileName.indexOf( QRegExp("[0-9]"), fnstart ); if(start<0) { return FileOpen(fileName.toLocal8Bit().constData());; } char prefix[1024], pattern[1024]; strncpy(prefix, fileName.toLocal8Bit().constData(), start); prefix[start]=0; int stop=fileName.indexOf( QRegExp("[^0-9]"), start ); sprintf(pattern, "%%s%%0%uu%s",stop-start,fileName.toLocal8Bit().constData()+stop); factory->SetFilePattern( pattern ); factory->SetFilePrefix( prefix ); } else { // factory->SetFileName( fileName ); factory->SetFilePattern( fileName.toLocal8Bit().constData() ); factory->SetFilePrefix( fileName.toLocal8Bit().constData() ); } factory->Update(); return factory->GetOutput( 0 ); } mitk::DataNode::Pointer CommonFunctionality::FileOpenImageSequence() { QString fileName = QFileDialog::getOpenFileName(NULL,mitk::CoreObjectFactory::GetInstance()->GetFileExtensions()); if ( !fileName.isNull() ) { return FileOpenImageSequence(fileName); } else { return NULL; } } mitk::DataNode::Pointer CommonFunctionality::FileOpen() { return CommonFunctionality::FileOpenSpecific( mitk::CoreObjectFactory::GetInstance()->GetFileExtensions() ); } mitk::DataNode::Pointer CommonFunctionality::FileOpenSpecific( const QString& fileExtensions) { return FileOpenSpecific( fileExtensions.toLocal8Bit().constData() ); } mitk::DataNode::Pointer CommonFunctionality::FileOpenSpecific( const char *fileExtensions ) { QString fileName = QFileDialog::getOpenFileName( NULL, fileExtensions ); if ( !fileName.isNull() ) { mitk::DataNode::Pointer result = FileOpen(fileName.toLocal8Bit().constData()); if ( result.IsNull() ) { return FileOpenImageSequence(fileName); } else { return result; } } else { return NULL; } } mitk::DataNode::Pointer CommonFunctionality::OpenVolumeOrSliceStack() { mitk::DataNode::Pointer newNode = NULL; QString fileName = QFileDialog::getOpenFileName(NULL,mitk::CoreObjectFactory::GetInstance()->GetFileExtensions() ); if ( !fileName.isNull() ) { newNode = CommonFunctionality::FileOpen(fileName); if (newNode.IsNotNull()) { mitk::Image::Pointer imageData = dynamic_cast (newNode->GetData()) ; if (imageData.IsNull()) return NULL; if (imageData->GetDimension(2) == 1) { // std::string dir = itksys::SystemTools::GetFilenamePath( std::string(fileName.ascii()) ) newNode = CommonFunctionality::FileOpenImageSequence(fileName); imageData = dynamic_cast (newNode->GetData()); } return newNode; } } { return NULL; } } #include "mitkSurfaceVtkWriter.h" #include #include #include std::string CommonFunctionality::SaveSurface(mitk::Surface* surface, const char* aFileName) { std::string fileName; if(aFileName == NULL) fileName = "Surface"; else fileName = aFileName; std::string selectedItemsName = itksys::SystemTools::GetFilenameWithoutExtension(fileName); //selectedItemsName += ".stl" QString selected_suffix("STL File (*.stl)"); QString possible_suffixes("STL File (*.stl);; VTK File (*.vtk);; VTP File (*.vtp)"); QString qfileName = GetSaveFileNameStartingInLastDirectory("Save surface object", QString::fromStdString(selectedItemsName), possible_suffixes,&selected_suffix); if (qfileName.isEmpty()) return ""; std::string extension = itksys::SystemTools::GetFilenameLastExtension( qfileName.toStdString() ); if (extension == "") // if no extension has been entered manually into the filename { // get from combobox selected file extension extension = itksys::SystemTools::GetFilenameLastExtension( selected_suffix.toLocal8Bit().constData()); extension = extension.substr(0, extension.size()-1); qfileName += QString::fromStdString(extension); } if(extension == ".stl" ) { mitk::SurfaceVtkWriter::Pointer writer=mitk::SurfaceVtkWriter::New(); // check if surface actually consists of triangles; if not, the writer will not do anything; so, convert to triangles... vtkPolyData* polys = surface->GetVtkPolyData(); if( polys->GetNumberOfStrips() > 0 ) { vtkTriangleFilter* triangleFilter = vtkTriangleFilter::New(); triangleFilter->SetInput(polys); triangleFilter->Update(); polys = triangleFilter->GetOutput(); polys->Register(NULL); triangleFilter->Delete(); surface->SetVtkPolyData(polys); } writer->SetInput( surface ); writer->SetFileName(qfileName.toLocal8Bit().constData()); writer->GetVtkWriter()->SetFileTypeToBinary(); writer->Write(); } else if(extension == ".vtp") { mitk::SurfaceVtkWriter::Pointer writer=mitk::SurfaceVtkWriter::New(); writer->SetInput( surface ); writer->SetFileName(qfileName.toLocal8Bit().constData()); writer->GetVtkWriter()->SetDataModeToBinary(); writer->Write(); } else if (extension == ".vtk") { mitk::SurfaceVtkWriter::Pointer writer=mitk::SurfaceVtkWriter::New(); writer->SetInput( surface ); writer->SetFileName(qfileName.toLocal8Bit().constData()); writer->Write(); } else { // file extension not suitable for writing specified data type QMessageBox::critical(NULL,"ERROR","File extension not suitable for writing Surface data. Choose .vtk, .stl or .vtp"); return ""; } return qfileName.toLocal8Bit().constData(); } #include "mitkImageWriter.h" #include std::string CommonFunctionality::SaveImage(mitk::Image* image, const char* aFileName, bool askForDifferentFilename) { QString selected_suffix("Nearly Raw Raster Data (*.nrrd)"); std::string defaultExtension = ".nrrd"; std::string fileName; if(aFileName == NULL || askForDifferentFilename) { QString initialFilename(aFileName); if (initialFilename.isEmpty()) initialFilename = "NewImage.pic"; QString qfileName = GetSaveFileNameStartingInLastDirectory("Save image", initialFilename ,mitk::CoreObjectFactory::GetInstance()->GetSaveFileExtensions(),&selected_suffix); MITK_INFO<IsExtensionValid(extension)) { // muellerm, 12-05-02, using default file extension // if no valid extension was given, see bug 11799 MITK_WARN << extension << " extension is unknown. Writing image to file " << fileName << defaultExtension; extension = defaultExtension; baseFilename = itksys::SystemTools::GetFilenameName( fileName ); //MITK_INFO << baseFilename; /* QString message; message.append("File extension not suitable for writing image data. Choose one extension of this list: "); message.append(imageWriter->GetPossibleFileExtensionsAsString().c_str()); QMessageBox::critical(NULL,"ERROR",message); return ""; */ } dir += "/"; dir += baseFilename; if( itksys::SystemTools::FileExists( (dir + extension).c_str() ) ) { int answer = QMessageBox::question( QApplication::topLevelWidgets().at(0), "Warning", QString("File %1 already exists. Overwrite?").arg( QString::fromStdString(dir + extension) ), QMessageBox::Yes, QMessageBox::No ); if( answer == QMessageBox::No ) return ""; } // Check if Image data/ Geometry information is lost if (image->GetDimension() == 2) { //if image is 2D the transformation matrix is cropped to 2D. Check if information is lost here. bool informationIsLost = false; while(1) { - if (image->GetGeometry()->GetSpacing()[2] != 0) + MITK_INFO << "spac: " << image->GetGeometry()->GetSpacing(); + if (image->GetGeometry()->GetSpacing()[2] != 1) { informationIsLost = true; break; } + MITK_INFO << "orig: " << image->GetGeometry()->GetOrigin(); if (image->GetGeometry()->GetOrigin()[2] != 0) { informationIsLost = true; break; } mitk::Vector3D col0, col1, col2; col0.Set_vnl_vector(image->GetGeometry()->GetIndexToWorldTransform()->GetMatrix().GetVnlMatrix().get_column(0)); col1.Set_vnl_vector(image->GetGeometry()->GetIndexToWorldTransform()->GetMatrix().GetVnlMatrix().get_column(1)); col2.Set_vnl_vector(image->GetGeometry()->GetIndexToWorldTransform()->GetMatrix().GetVnlMatrix().get_column(2)); - if ((col0[2] != 0) || (col1[2] != 0) || (col2[0] != 0) || (col2[1] != 0) || (col2[2] != 0)) + MITK_INFO << "col0: " << col0; + MITK_INFO << "col1 " << col1; + MITK_INFO << "col2: " << col2; + if ((col0[2] != 0) || (col1[2] != 0) || (col2[0] != 0) || (col2[1] != 0) || (col2[2] != 1)) { informationIsLost = true; break; } + break; }; if (informationIsLost) { // information will be lost, if continuing to save this file as 2D // tell it the user and offer to save it as 3D // todo: if format is png, jpg, etc.. forget it, no geometry information at all QMessageBox msgBox; msgBox.setText("You are trying to save a 2D image that has 3D geometry informations."); msgBox.setInformativeText("You will lose the 3D geometry information this way. Do you rather want to save it as a 3D image?"); msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel); msgBox.setDefaultButton(QMessageBox::Yes); int ret = msgBox.exec(); if (ret == QMessageBox::YesRole) { // Save as 3D // todo: convert image to 3D image mitk::Image::Pointer imageAs3D; AccessFixedDimensionByItk_2(image,Convert2DImageTo3D,2,image,imageAs3D); image = imageAs3D; } else if (ret == QMessageBox::NoRole) { // Continue Saving as 2D } else { // Abort, don't save anything return 0; } - - } - } // write image imageWriter->SetInput(image); imageWriter->SetFileName(dir.c_str()); imageWriter->SetExtension(extension.c_str()); imageWriter->Write(); fileName = dir + extension; } catch ( itk::ExceptionObject &err) { itkGenericOutputMacro( << "Exception during write: " << err ); QString exceptionString; exceptionString.append("Error during write image: "); exceptionString.append(err.GetDescription()); QMessageBox::critical(NULL,"ERROR",exceptionString); return ""; } catch ( ... ) { itkGenericOutputMacro( << "Unknown type of exception during write" ); QMessageBox::critical(NULL,"ERROR","Error during write image. Possibly no writing permission."); fileName = ""; } return fileName; } std::string CommonFunctionality::SaveScreenshot( vtkRenderWindow* renderWindow , const char* filename ) { // // perform some error checking // if ( ! renderWindow ) { itkGenericOutputMacro( << "render window is NULL!" ); return std::string(""); } if ( ! renderWindow ) { itkGenericOutputMacro( << "Unsupported type of render window! The only supported type is currently QmitkRenderWindow." ); return std::string(""); } // // create the screenshot before the filechooser is opened, // so there the file chooser will not be part of the screenshot // //QPixmap buffer = QPixmap::grabWindow( qtRenderWindow->winId() ); // new Version: //// take screenshot of render window without the coloured frame of 2 pixels by cropping the raw image data vtkWindowToImageFilter* wti = vtkWindowToImageFilter::New(); wti->SetInput( renderWindow ); wti->Update(); vtkImageData* imageData = wti->GetOutput(); int framesize = 5; int* windowSize = renderWindow->GetSize(); int numberOfScalarComponents = imageData->GetNumberOfScalarComponents(); vtkImageData* processedImageData = vtkImageData::New(); processedImageData->SetNumberOfScalarComponents(numberOfScalarComponents); processedImageData->SetExtent(0,windowSize[0]-2*framesize-1,0,windowSize[1]-2*framesize-1,0,0); processedImageData->SetScalarTypeToUnsignedChar(); for (int i=framesize; iSetScalarComponentFromDouble(i-framesize,j-framesize,0,k,imageData->GetScalarComponentAsDouble(i,j,0,k)); } } } // write new image as *.png to file vtkPNGWriter* pngWriter = vtkPNGWriter::New(); // // if the provided filename is empty ask the user // for the name of the file in which the screenshot // should be saved // std::string concreteFilename = ""; if( filename == NULL ) { // // show a file selector with the supported file formats // QString qfileName = GetSaveFileNameStartingInLastDirectory("Save screenshot", QString::fromStdString(""), QString::fromStdString(".png") ); if ( qfileName.isEmpty() ) return ""; concreteFilename = qfileName.toLocal8Bit().constData(); } else concreteFilename = filename; // make sure the filename ends with .png const std::string outFileSuffix("png"); std::string::size_type pos = concreteFilename.rfind('.'); if ( pos == std::string::npos ) concreteFilename = concreteFilename + '.' + outFileSuffix; else { std::string extname = concreteFilename.substr(pos+1); if ( extname.empty() ) concreteFilename += outFileSuffix; // name ended with '.' if ( !(extname == outFileSuffix) ) concreteFilename.replace( pos+1, std::string::npos, "png" ); } // // wait for 500 ms to let the file chooser close itself // // int msecs = 500; // clock_t ticks = ( clock_t )( ( ( ( float ) msecs ) / 1000.0f ) * ( ( float ) CLOCKS_PER_SEC ) ); // clock_t goal = ticks + std::clock(); // while ( goal > std::clock() ); // // // save the screenshot under the given filename // pngWriter->SetInput(processedImageData); //pngWriter->SetInput( wti->GetOutput() ); pngWriter->SetFileName( concreteFilename.c_str() ); pngWriter->Write(); if ( pngWriter->GetErrorCode() != 0 ) QMessageBox::information(NULL, "Save Screenshot...", "The file could not be saved. Please check filename, format and access rights..."); wti->Delete(); pngWriter->Delete(); return concreteFilename; } QString CommonFunctionality::GetSaveFileNameStartingInLastDirectory(QString caption, QString defaultFilename, QString filter, QString* selectedFilter) { QString returnValue = ""; static QString lastDirectory = ""; QString filename = lastDirectory + defaultFilename; returnValue = QFileDialog::getSaveFileName(NULL,caption,filename,filter,selectedFilter); if (returnValue != "") { std::string dir = itksys::SystemTools::GetFilenamePath( returnValue.toStdString() ); dir += Poco::Path::separator(); lastDirectory = dir.c_str(); // remember path for next save dialog } return returnValue; } template < typename TPixel, unsigned int VImageDimension > void CommonFunctionality::Convert2DImageTo3D( const itk::Image< TPixel, VImageDimension > *image, mitk::Image::Pointer oldImage, mitk::Image::Pointer &newImage) { typedef itk::Image ImageType; // create new 3D ITK image with just one slice. typename ImageType::Pointer outputImage = ImageType::New(); typename ImageType::RegionType myRegion; typename ImageType::SizeType mySize; typename ImageType::IndexType myIndex; typename ImageType::SpacingType mySpacing; mySpacing[0] = oldImage->GetGeometry()->GetSpacing()[0]; mySpacing[1] = oldImage->GetGeometry()->GetSpacing()[1]; mySpacing[2] = oldImage->GetGeometry()->GetSpacing()[2]; myIndex[0] = oldImage->GetGeometry()->GetOrigin()[0]; myIndex[1] = oldImage->GetGeometry()->GetOrigin()[1]; myIndex[2] = oldImage->GetGeometry()->GetOrigin()[2]; mySize[0] = oldImage->GetLargestPossibleRegion().GetSize()[0]; mySize[1] = oldImage->GetLargestPossibleRegion().GetSize()[1]; mySize[2] = oldImage->GetLargestPossibleRegion().GetSize()[2]; myRegion.SetSize( mySize); myRegion.SetIndex( myIndex ); outputImage->SetSpacing(mySpacing); outputImage->SetRegions( myRegion); outputImage->Allocate(); outputImage->FillBuffer(0); // Copy values itk::Index<3> index3; itk::Index<2> index2; for (int x=0; xGetDimension(0); x++) { for (int y=0; yGetDimension(1); y++) { index2[0] = x; index2[1] = y; index3[0] = x; index3[1] = y; index3[2] = 0; outputImage->SetPixel(index3,image->GetPixel(index2)); } } // produce MITK image as output CastToMitkImage(outputImage, newImage); } \ No newline at end of file