diff --git a/Core/Code/Algorithms/mitkCompareImageDataFilter.cpp b/Core/Code/Algorithms/mitkCompareImageDataFilter.cpp index 9e78c1d88c..015bbf4581 100644 --- a/Core/Code/Algorithms/mitkCompareImageDataFilter.cpp +++ b/Core/Code/Algorithms/mitkCompareImageDataFilter.cpp @@ -1,122 +1,135 @@ /*=================================================================== 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. ===================================================================*/ // mitk includes #include "mitkCompareImageDataFilter.h" #include "mitkImageAccessByItk.h" #include "mitkITKImageImport.h" #include "mitkImageCaster.h" -#include "mitkMultiChannelImageDataComparisonFilter.h" +#include "mitkMultiComponentImageDataComparisonFilter.h" // itk includes #include mitk::CompareImageDataFilter::CompareImageDataFilter() { this->SetNumberOfRequiredInputs(2); + + this->ResetCompareResultsToInitial(); } +void mitk::CompareImageDataFilter::ResetCompareResultsToInitial() +{ + m_CompareDetails.m_MaximumDifference = 0.0f; + m_CompareDetails.m_MinimumDifference = itk::NumericTraits< double >::max(); + m_CompareDetails.m_MeanDifference = 0.0f; + m_CompareDetails.m_TotalDifference = 0.0f; + m_CompareDetails.m_PixelsWithDifference = 0; + m_CompareDetails.m_FilterCompleted = false; + m_CompareDetails.m_ExceptionMessage = ""; +} void mitk::CompareImageDataFilter::GenerateData() { // check inputs const mitk::Image* input1 = this->GetInput(0); const mitk::Image* input2 = this->GetInput(1); // Generally this filter is part of the mitk::Image::Equal() method and only checks the equality of the image data // so no further image type comparison is performed! // CAVE: If the images differ in a parameter other then the image data, the filter may fail!! // check what number of components the inputs have if(input1->GetPixelType().GetNumberOfComponents() == 1 && input2->GetPixelType().GetNumberOfComponents() == 1) { AccessByItk_1( input1, EstimateValueDifference, input2); } else if(input1->GetPixelType().GetNumberOfComponents() > 1 && input2->GetPixelType().GetNumberOfComponents() > 1 ) { - MultiChannelImageDataComparisonFilter::Pointer mcComparator = MultiChannelImageDataComparisonFilter::New(); + this->ResetCompareResultsToInitial(); + + MultiComponentImageDataComparisonFilter::Pointer mcComparator = MultiComponentImageDataComparisonFilter::New(); mcComparator->SetTestImage(input1); mcComparator->SetValidImage(input2); mcComparator->SetCompareFilterResult( &m_CompareDetails); mcComparator->Update(); - //mcComparator->GetCompareFilterResult() } } bool mitk::CompareImageDataFilter::GetResult(size_t threshold) { if (! m_CompareResult) { return false; } if( m_CompareDetails.m_PixelsWithDifference > threshold ) { return false; } return true; } template< typename TPixel, unsigned int VImageDimension> void mitk::CompareImageDataFilter::EstimateValueDifference(itk::Image< TPixel, VImageDimension>* itkImage1, const mitk::Image* referenceImage) { typedef itk::Image< TPixel, VImageDimension> InputImageType; typedef itk::Image< double, VImageDimension > OutputImageType; typename InputImageType::Pointer itk_reference = InputImageType::New(); mitk::CastToItkImage( referenceImage, itk_reference ); typedef itk::Testing::ComparisonImageFilter< InputImageType, OutputImageType > CompareFilterType; typename CompareFilterType::Pointer compare_filter = CompareFilterType::New(); compare_filter->SetTestInput( itkImage1 ); compare_filter->SetValidInput( itk_reference ); try { compare_filter->Update(); } catch( const itk::ExceptionObject& e) { m_CompareDetails.m_FilterCompleted = false; m_CompareDetails.m_ExceptionMessage = e.what(); MITK_WARN << e.what(); m_CompareResult = false; return; } // the filter has completed the calculation m_CompareResult = true; m_CompareDetails.m_FilterCompleted = true; m_CompareDetails.m_MaximumDifference = compare_filter->GetMaximumDifference(); m_CompareDetails.m_MinimumDifference = compare_filter->GetMinimumDifference(); m_CompareDetails.m_MeanDifference = compare_filter->GetMeanDifference(); m_CompareDetails.m_TotalDifference = compare_filter->GetTotalDifference(); m_CompareDetails.m_PixelsWithDifference = compare_filter->GetNumberOfPixelsWithDifferences(); mitk::Image::Pointer output = mitk::GrabItkImageMemory( compare_filter->GetOutput() ); this->SetOutput( MakeNameFromOutputIndex(0), output.GetPointer() ); } diff --git a/Core/Code/Algorithms/mitkCompareImageDataFilter.h b/Core/Code/Algorithms/mitkCompareImageDataFilter.h index bfeb491d87..67fd799288 100644 --- a/Core/Code/Algorithms/mitkCompareImageDataFilter.h +++ b/Core/Code/Algorithms/mitkCompareImageDataFilter.h @@ -1,118 +1,120 @@ /*=================================================================== 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 MITKCOMPAREIMAGEDATAFILTER_H #define MITKCOMPAREIMAGEDATAFILTER_H //MITK #include "mitkImageToImageFilter.h" #include "mitkImage.h" //ITK #include namespace mitk { /** * @brief A simple struct to hold the result of the comparison filter. */ struct CompareFilterResults { void PrintSelf() { if( !m_FilterCompleted ) { - MITK_INFO << "Comparision filter terminated due to an exception: \n " + MITK_INFO << "Comparison filter terminated due to an exception: \n " << m_ExceptionMessage; return; } MITK_INFO << "Min. difference: " << m_MinimumDifference <<"\n" << "Max. difference: " << m_MaximumDifference <<"\n" << "Total difference: " << m_TotalDifference <<"\n" << "Mean difference: " << m_MeanDifference <<"\n" << "Number of pixels with differences: " << m_PixelsWithDifference; } double m_MinimumDifference; double m_MaximumDifference; double m_TotalDifference; double m_MeanDifference; size_t m_PixelsWithDifference; bool m_FilterCompleted; std::string m_ExceptionMessage; }; /** * @brief Filter for comparing two mitk::Image objects by pixel values * * The comparison is pixel-wise, the filter uses the itk::Testing::ComparisonImageFilter * to find differences. The filter expects two images as input, provide them by using the SetInput( int, mitk::Image) * method. */ class MITK_CORE_EXPORT CompareImageDataFilter : public ImageToImageFilter { public: mitkClassMacro(CompareImageDataFilter, ImageToImageFilter) itkSimpleNewMacro(Self) /** - * @brief Get the result of the comparision + * @brief Get the result of the comparison * * The method compares only the number of pixels with differences. It returns true if the amount * is under the specified threshold. To get the complete results, use the GetCompareResults method. * * Returns false also if the itk ComparisionImageFilter raises an exception during update. * * @param threshold Allowed amount of pixels with differences */ bool GetResult(size_t threshold = 0); /** * @brief Get the detailed results of the comparision run * * @sa CompareFilterResults */ CompareFilterResults GetCompareResults() { return m_CompareDetails; } protected: CompareImageDataFilter(); virtual ~CompareImageDataFilter() {} virtual void GenerateData(); + /*! \brief Method resets the compare detail memeber struct to its initial state */ + void ResetCompareResultsToInitial(); + /** ITK-like method which calls the ComparisionFilter on the two inputs of the filter */ template< typename TPixel, unsigned int VImageDimension> void EstimateValueDifference( itk::Image< TPixel, VImageDimension>* itkImage1, const mitk::Image* referenceImage); - bool m_CompareResult; CompareFilterResults m_CompareDetails; }; } // end namespace mitk #endif // MITKCompareImageDataFilter_H diff --git a/Core/Code/Algorithms/mitkMultiChannelImageDataComparisonFilter.cpp b/Core/Code/Algorithms/mitkMultiComponentImageDataComparisonFilter.cpp similarity index 61% rename from Core/Code/Algorithms/mitkMultiChannelImageDataComparisonFilter.cpp rename to Core/Code/Algorithms/mitkMultiComponentImageDataComparisonFilter.cpp index 986d2f6941..4dddb63fb2 100644 --- a/Core/Code/Algorithms/mitkMultiChannelImageDataComparisonFilter.cpp +++ b/Core/Code/Algorithms/mitkMultiComponentImageDataComparisonFilter.cpp @@ -1,183 +1,190 @@ /*=================================================================== 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. ===================================================================*/ // mitk includes -#include "mitkMultiChannelImageDataComparisonFilter.h" +#include "mitkMultiComponentImageDataComparisonFilter.h" #include "mitkImageReadAccessor.h" #include "mitkImagePixelReadAccessor.h" // other includes -#include +// #include namespace mitk { - MultiChannelImageDataComparisonFilter::MultiChannelImageDataComparisonFilter(): ImageToImageFilter(), + MultiComponentImageDataComparisonFilter::MultiComponentImageDataComparisonFilter(): ImageToImageFilter(), m_Tolerance(0.0f), m_CompareResult(false), m_CompareDetails(NULL) { this->SetNumberOfRequiredInputs(2); } - MultiChannelImageDataComparisonFilter::~MultiChannelImageDataComparisonFilter() + MultiComponentImageDataComparisonFilter::~MultiComponentImageDataComparisonFilter() { } - bool MultiChannelImageDataComparisonFilter::GetResult(double threshold) + bool MultiComponentImageDataComparisonFilter::GetResult(double threshold) { if ( !m_CompareResult ) { return false; } if( m_CompareDetails->m_PixelsWithDifference > threshold ) { return false; } return true; } - void MultiChannelImageDataComparisonFilter::SetValidImage( const Image *_arg ) + void MultiComponentImageDataComparisonFilter::SetValidImage( const Image *_arg ) { this->SetInput(0, _arg); } - void MultiChannelImageDataComparisonFilter::SetTestImage( const Image *_arg ) + void MultiComponentImageDataComparisonFilter::SetTestImage( const Image *_arg ) { this->SetInput(1, _arg); } - const Image* MultiChannelImageDataComparisonFilter::GetValidImage() + const Image* MultiComponentImageDataComparisonFilter::GetValidImage() { return this->GetInput(0); } - const Image* MultiChannelImageDataComparisonFilter::GetTestImage() + const Image* MultiComponentImageDataComparisonFilter::GetTestImage() { return this->GetInput(1); } - void MultiChannelImageDataComparisonFilter::SetCompareFilterResult( CompareFilterResults* results ) + void MultiComponentImageDataComparisonFilter::SetCompareFilterResult( CompareFilterResults* results ) { m_CompareDetails = results; } - CompareFilterResults* MultiChannelImageDataComparisonFilter::GetCompareFilterResult() + CompareFilterResults* MultiComponentImageDataComparisonFilter::GetCompareFilterResult() { return m_CompareDetails; } - void MultiChannelImageDataComparisonFilter::GenerateData() + void MultiComponentImageDataComparisonFilter::GenerateData() { // check inputs const Image* testInput = this->GetTestImage(); const Image* validInput = this->GetValidImage(); + // Generally this filter is part of the mitk::Image::Equal() method and only checks the equality of the image data + // so no further image type comparison is performed! + // CAVE: If the images differ in a parameter other then the image data, the filter may fail!! PixelType type = validInput->GetPixelType(); if(type.GetComponentType() == itk::ImageIOBase::CHAR) { - CompareMultiChannelImage( testInput, validInput); + CompareMultiComponentImage( testInput, validInput); } else if (type.GetComponentType() == itk::ImageIOBase::UCHAR) { - CompareMultiChannelImage( testInput, validInput); + CompareMultiComponentImage( testInput, validInput); } else if (type.GetComponentType() == itk::ImageIOBase::INT) { - CompareMultiChannelImage( testInput, validInput); + CompareMultiComponentImage( testInput, validInput); } else if (type.GetComponentType() == itk::ImageIOBase::UINT) { - CompareMultiChannelImage( testInput, validInput); + CompareMultiComponentImage( testInput, validInput); } else if (type.GetComponentType() == itk::ImageIOBase::SHORT) { - CompareMultiChannelImage( testInput, validInput); + CompareMultiComponentImage( testInput, validInput); } else if (type.GetComponentType() == itk::ImageIOBase::USHORT) { - CompareMultiChannelImage( testInput, validInput); + CompareMultiComponentImage( testInput, validInput); } else if (type.GetComponentType() == itk::ImageIOBase::LONG) { - CompareMultiChannelImage( testInput, validInput); + CompareMultiComponentImage( testInput, validInput); } else if (type.GetComponentType() == itk::ImageIOBase::ULONG) { - CompareMultiChannelImage( testInput, validInput); + CompareMultiComponentImage( testInput, validInput); } else if (type.GetComponentType() == itk::ImageIOBase::FLOAT) { - CompareMultiChannelImage( testInput, validInput); + CompareMultiComponentImage( testInput, validInput); } else if (type.GetComponentType() == itk::ImageIOBase::DOUBLE) { - CompareMultiChannelImage( testInput, validInput); + CompareMultiComponentImage( testInput, validInput); } else { + mitkThrow() << "Pixel component type not supported!"; } - - - // Generally this filter is part of the mitk::Image::Equal() method and only checks the equality of the image data - // so no further image type comparison is performed! - // CAVE: If the images differ in a parameter other then the image data, the filter may fail!! - } template - void mitk::MultiChannelImageDataComparisonFilter::CompareMultiChannelImage( const Image* testImage, const Image* validImage ) + void mitk::MultiComponentImageDataComparisonFilter::CompareMultiComponentImage( const Image* testImage, const Image* validImage ) { unsigned int noOfTimes = validImage->GetDimension(3); unsigned int noOfPixels = validImage->GetDimension(0)*validImage->GetDimension(1)*validImage->GetDimension(2); unsigned int noOfComponents = validImage->GetPixelType().GetNumberOfComponents(); for( int t = 0; t < noOfTimes; ++t) { ImageReadAccessor readAccTImage(const_cast(testImage), const_cast(testImage)->GetVolumeData(t)); ImageReadAccessor readAccVImage(const_cast(validImage), const_cast(validImage)->GetVolumeData(t)); - // #pragma omp parallel for for( int p = 0; p < noOfPixels*noOfComponents; ++p ) { TPixel vDataItem = static_cast(const_cast(readAccVImage.GetData()))[p]; TPixel tDataItem = static_cast(const_cast(readAccTImage.GetData()))[p]; if( tDataItem != vDataItem ) { ++m_CompareDetails->m_PixelsWithDifference; m_CompareDetails->m_MaximumDifference = std::max(m_CompareDetails->m_MaximumDifference, std::abs( static_cast(tDataItem - vDataItem) ) ); - m_CompareDetails->m_MinimumDifference = std::min(m_CompareDetails->m_MinimumDifference, + double min = std::min(m_CompareDetails->m_MinimumDifference, std::abs( static_cast(tDataItem - vDataItem) )); + if(min != 0.0f) // a difference of zero is not a difference! + m_CompareDetails->m_MinimumDifference = min; + m_CompareDetails->m_TotalDifference += std::abs(static_cast(tDataItem - vDataItem) ); } } } - m_CompareDetails->m_MeanDifference = m_CompareDetails->m_TotalDifference / m_CompareDetails->m_PixelsWithDifference; - m_CompareDetails->m_PixelsWithDifference /= noOfPixels*noOfComponents*noOfTimes; + if(m_CompareDetails->m_PixelsWithDifference != 0) + { + m_CompareDetails->m_MeanDifference = m_CompareDetails->m_TotalDifference / m_CompareDetails->m_PixelsWithDifference; + m_CompareResult = false; + } + else + { + m_CompareResult = true; + } } } // end namespace mitk \ No newline at end of file diff --git a/Core/Code/Algorithms/mitkMultiChannelImageDataComparisonFilter.h b/Core/Code/Algorithms/mitkMultiComponentImageDataComparisonFilter.h similarity index 80% rename from Core/Code/Algorithms/mitkMultiChannelImageDataComparisonFilter.h rename to Core/Code/Algorithms/mitkMultiComponentImageDataComparisonFilter.h index 639c50bbf8..2dae0159fd 100644 --- a/Core/Code/Algorithms/mitkMultiChannelImageDataComparisonFilter.h +++ b/Core/Code/Algorithms/mitkMultiComponentImageDataComparisonFilter.h @@ -1,92 +1,92 @@ /*=================================================================== 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 MITKMULTICHANNELIMAGEDATACOMPARISONFILTER_H -#define MITKMULTICHANNELIMAGEDATACOMPARISONFILTER_H +#ifndef MITKMULTICOMPONENTIMAGEDATACOMPARISONFILTER_H +#define MITKMULTICOMPONENTIMAGEDATACOMPARISONFILTER_H // mitk includes #include "mitkImageToImageFilter.h" #include "mitkCompareImageDataFilter.h" //struct CompareFilterResults; namespace mitk { /*! Documentation: * \brief Filter for comparing two multi channel mitk::Image objects by channel wise by pixel values * * The comparison is channel- / pixel-wise. */ - class MITK_CORE_EXPORT MultiChannelImageDataComparisonFilter : public ImageToImageFilter + class MITK_CORE_EXPORT MultiComponentImageDataComparisonFilter : public ImageToImageFilter { public: - mitkClassMacro(MultiChannelImageDataComparisonFilter, ImageToImageFilter); + mitkClassMacro(MultiComponentImageDataComparisonFilter, ImageToImageFilter); itkSimpleNewMacro(Self); /*! /brief */ void SetTestImage( const Image *_arg); const Image* GetTestImage(); /*! /brief */ void SetValidImage( const Image *_arg); const Image* GetValidImage(); /*! /brief Specify the tolerance of the image data comparison /param Tolerance Default is 0.0f. */ itkSetMacro(Tolerance, double); itkGetMacro(Tolerance, double); /*! /brief */ void SetCompareFilterResult( CompareFilterResults* results); /*! /brief Get the detailed results of the comparison run * /sa CompareFilterResults */ CompareFilterResults* GetCompareFilterResult(); /*! /brief Get the result of the comparison * The method compares only the number of pixels with differences. It returns true if the amount * is under the specified threshold. To get the complete results, use the GetCompareResults method. * Returns false also if the itk ComparisionImageFilter raises an exception during update. * /param threshold Allowed percentage of pixels with differences (between 0.0...1.0) */ bool GetResult( double threshold = 0.0f); protected: - MultiChannelImageDataComparisonFilter(); + MultiComponentImageDataComparisonFilter(); - ~MultiChannelImageDataComparisonFilter(); + ~MultiComponentImageDataComparisonFilter(); virtual void GenerateData(); template < typename TPixel > - void CompareMultiChannelImage( const Image* testImage, const Image* validImage); + void CompareMultiComponentImage( const Image* testImage, const Image* validImage); bool m_CompareResult; double m_Tolerance; CompareFilterResults* m_CompareDetails; }; } // end namespace mitk -#endif // MITKMULTICHANNELIMAGEDATACOMPARISONFILTER_H +#endif // MITKMULTICOMPONENTIMAGEDATACOMPARISONFILTER_H diff --git a/Core/Code/Testing/files.cmake b/Core/Code/Testing/files.cmake index 7ef459d238..21d965332b 100644 --- a/Core/Code/Testing/files.cmake +++ b/Core/Code/Testing/files.cmake @@ -1,175 +1,176 @@ # tests with no extra command line parameter set(MODULE_TESTS mitkAccessByItkTest.cpp mitkCoreObjectFactoryTest.cpp mitkMaterialTest.cpp mitkActionTest.cpp mitkDispatcherTest.cpp mitkEnumerationPropertyTest.cpp mitkEventTest.cpp mitkFocusManagerTest.cpp mitkGenericPropertyTest.cpp mitkGeometry2DTest.cpp mitkGeometry3DTest.cpp mitkGeometry3DEqualTest.cpp mitkGeometryDataToSurfaceFilterTest.cpp mitkGlobalInteractionTest.cpp mitkImageEqualTest.cpp mitkImageDataItemTest.cpp #mitkImageMapper2DTest.cpp mitkImageGeneratorTest.cpp mitkBaseDataTest.cpp #mitkImageToItkTest.cpp mitkImportItkImageTest.cpp mitkGrabItkImageMemoryTest.cpp mitkInstantiateAccessFunctionTest.cpp mitkInteractorTest.cpp #mitkITKThreadingTest.cpp mitkLevelWindowTest.cpp mitkMessageTest.cpp #mitkPipelineSmartPointerCorrectnessTest.cpp mitkPixelTypeTest.cpp mitkPlaneGeometryTest.cpp mitkPointSetEqualTest.cpp mitkPointSetFileIOTest.cpp mitkPointSetTest.cpp mitkPointSetWriterTest.cpp mitkPointSetReaderTest.cpp mitkPointSetInteractorTest.cpp mitkPropertyTest.cpp mitkPropertyListTest.cpp #mitkRegistrationBaseTest.cpp #mitkSegmentationInterpolationTest.cpp mitkSlicedGeometry3DTest.cpp mitkSliceNavigationControllerTest.cpp mitkStateMachineTest.cpp ##mitkStateMachineContainerTest.cpp ## rewrite test, indirect since no longer exported Bug 14529 mitkStateTest.cpp mitkSurfaceTest.cpp mitkSurfaceEqualTest.cpp mitkSurfaceToSurfaceFilterTest.cpp mitkTimeGeometryTest.cpp mitkTransitionTest.cpp mitkUndoControllerTest.cpp mitkVtkWidgetRenderingTest.cpp mitkVerboseLimitedLinearUndoTest.cpp mitkWeakPointerTest.cpp mitkTransferFunctionTest.cpp #mitkAbstractTransformGeometryTest.cpp mitkStepperTest.cpp itkTotalVariationDenoisingImageFilterTest.cpp mitkRenderingManagerTest.cpp vtkMitkThickSlicesFilterTest.cpp mitkNodePredicateSourceTest.cpp mitkVectorTest.cpp mitkClippedSurfaceBoundsCalculatorTest.cpp mitkExceptionTest.cpp mitkExtractSliceFilterTest.cpp mitkLogTest.cpp mitkImageDimensionConverterTest.cpp mitkLoggingAdapterTest.cpp mitkUIDGeneratorTest.cpp mitkShaderRepositoryTest.cpp mitkPlanePositionManagerTest.cpp mitkAffineTransformBaseTest.cpp mitkPropertyAliasesTest.cpp mitkPropertyDescriptionsTest.cpp mitkPropertyExtensionsTest.cpp mitkPropertyFiltersTest.cpp + mitkMultiComponentImageDataComparisonFilterTest.cpp ) # test with image filename as an extra command line parameter set(MODULE_IMAGE_TESTS mitkImageTimeSelectorTest.cpp #only runs on images mitkImageAccessorTest.cpp #only runs on images mitkDataNodeFactoryTest.cpp #runs on all types of data ) set(MODULE_SURFACE_TESTS mitkSurfaceVtkWriterTest.cpp #only runs on surfaces mitkDataNodeFactoryTest.cpp #runs on all types of data ) # list of images for which the tests are run set(MODULE_TESTIMAGES US4DCyl.nrrd Pic3D.nrrd Pic2DplusT.nrrd BallBinary30x30x30.nrrd Png2D-bw.png ) set(MODULE_TESTSURFACES binary.stl ball.stl ) set(MODULE_CUSTOM_TESTS #mitkLabeledImageToSurfaceFilterTest.cpp #mitkExternalToolsTest.cpp mitkDataStorageTest.cpp mitkDataNodeTest.cpp mitkDicomSeriesReaderTest.cpp mitkDICOMLocaleTest.cpp mitkEventMapperTest.cpp mitkEventConfigTest.cpp mitkNodeDependentPointSetInteractorTest.cpp mitkStateMachineFactoryTest.cpp mitkPointSetLocaleTest.cpp mitkImageTest.cpp mitkImageWriterTest.cpp mitkImageVtkMapper2DTest.cpp mitkImageVtkMapper2DLevelWindowTest.cpp mitkImageVtkMapper2DOpacityTest.cpp mitkImageVtkMapper2DResliceInterpolationPropertyTest.cpp mitkImageVtkMapper2DColorTest.cpp mitkImageVtkMapper2DSwivelTest.cpp mitkImageVtkMapper2DTransferFunctionTest.cpp mitkImageVtkMapper2DLookupTableTest.cpp mitkIOUtilTest.cpp mitkSurfaceVtkMapper3DTest mitkSurfaceVtkMapper3DTexturedSphereTest.cpp mitkSurfaceGLMapper2DColorTest.cpp mitkSurfaceGLMapper2DOpacityTest.cpp mitkVolumeCalculatorTest.cpp mitkLevelWindowManagerTest.cpp mitkPointSetVtkMapper2DTest.cpp mitkPointSetVtkMapper2DImageTest.cpp mitkPointSetVtkMapper2DGlyphTypeTest.cpp mitkPointSetVtkMapper2DTransformedPointsTest.cpp mitkLabelOverlay3DRendering2DTest.cpp mitkLabelOverlay3DRendering3DTest.cpp mitkTextOverlay2DRenderingTest.cpp mitkTextOverlay2DLayouterRenderingTest.cpp mitkTextOverlay3DRendering2DTest.cpp mitkTextOverlay3DRendering3DTest.cpp mitkTextOverlay3DColorRenderingTest.cpp mitkVTKRenderWindowSizeTest.cpp ) if (${VTK_MAJOR_VERSION} VERSION_LESS 6) # test can be removed with VTK 6 set(MODULE_TESTS ${MODULE_TESTS} mitkVTKRenderWindowSizeTest.cpp) endif() set(MODULE_RESOURCE_FILES Interactions/AddAndRemovePoints.xml Interactions/globalConfig.xml Interactions/StatemachineTest.xml Interactions/StatemachineConfigTest.xml ) # Create an artificial module initializing class for # the usServiceListenerTest.cpp usFunctionGenerateExecutableInit(testdriver_init_file IDENTIFIER ${MODULE_NAME}TestDriver ) # Embed the resources set(testdriver_resources ) usFunctionEmbedResources(testdriver_resources EXECUTABLE_NAME ${MODULE_NAME}TestDriver ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/Resources FILES ${MODULE_RESOURCE_FILES} ) set(TEST_CPP_FILES ${testdriver_init_file} ${testdriver_resources}) diff --git a/Core/Code/Testing/mitkMultiComponentImageDataComparisonFilterTest.cpp b/Core/Code/Testing/mitkMultiComponentImageDataComparisonFilterTest.cpp new file mode 100644 index 0000000000..e2225f5a45 --- /dev/null +++ b/Core/Code/Testing/mitkMultiComponentImageDataComparisonFilterTest.cpp @@ -0,0 +1,79 @@ +/*=================================================================== + +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. + +===================================================================*/ + +// mitk includes +#include "mitkTestingMacros.h" +#include "mitkMultiComponentImageDataComparisonFilter.h" +#include "mitkItkImageFileReader.h" + +#include "itkNumericTraits.h" + +int mitkMultiComponentImageDataComparisonFilterTest(int argc, char* argv[]) +{ + MITK_TEST_BEGIN("MultiComponentImageDataComparisonFilter"); + + // instantiation + mitk::MultiComponentImageDataComparisonFilter::Pointer testObject = mitk::MultiComponentImageDataComparisonFilter::New(); + MITK_TEST_CONDITION_REQUIRED(testObject.IsNotNull(), "Testing instantiation of test class!"); + + MITK_TEST_CONDITION_REQUIRED(testObject->GetCompareFilterResult() == NULL, "Testing initialization of result struct" ); + MITK_TEST_CONDITION_REQUIRED(testObject->GetTolerance() == 0.0f, "Testing initialization of tolerance member"); + MITK_TEST_CONDITION_REQUIRED(testObject->GetResult() == false, "Testing initialization of CompareResult member"); + + // initialize compare result struct and pass it to the filter + mitk::CompareFilterResults compareResult; + compareResult.m_MaximumDifference = 0.0f; + compareResult.m_MinimumDifference = itk::NumericTraits::max(); + compareResult.m_MeanDifference = 0.0f; + compareResult.m_FilterCompleted = false; + compareResult.m_TotalDifference = 0.0f; + compareResult.m_PixelsWithDifference = 0; + testObject->SetCompareFilterResult(&compareResult); + + MITK_TEST_CONDITION_REQUIRED(testObject->GetCompareFilterResult() != NULL, "Testing set/get of compare result struct" ); + MITK_TEST_CONDITION_REQUIRED(testObject->GetResult() == false, "CompareResult still false" ); + + //now load an image with several components and present it to the filter + mitk::ItkImageFileReader::Pointer imgReader = mitk::ItkImageFileReader::New(); + imgReader->SetFileName(argv[1]); + imgReader->Update(); + + mitk::Image::Pointer testImg = imgReader->GetOutput(); + mitk::Image::Pointer testImg2 = testImg->Clone(); + + testObject->SetValidImage(testImg); + testObject->SetTestImage(testImg2); + + MITK_TEST_CONDITION_REQUIRED(testObject->GetNumberOfIndexedInputs() == 2, "Testing correct handling of input images"); + + testObject->Update(); + + MITK_TEST_CONDITION_REQUIRED(testObject->GetResult(), "Testing filter processing with equal image data"); + + // now change some of the data and check if the response is correct + unsigned char* imgData = (unsigned char*) testImg2->GetData(); + imgData[10] += 1; + imgData[20] += 2; + imgData[30] += 3; + + testObject->Update(); + + MITK_TEST_CONDITION_REQUIRED(testObject->GetResult() == false, "Testing filter processing with unequal image data"); + MITK_TEST_CONDITION_REQUIRED(mitk::Equal((int)testObject->GetCompareFilterResult()->m_PixelsWithDifference, (int) 3) && + mitk::Equal((double)testObject->GetCompareFilterResult()->m_MaximumDifference, (double) 3.0) && + mitk::Equal((double)testObject->GetCompareFilterResult()->m_MeanDifference, (double) 2.0), "Assessing calculated image differences"); + MITK_TEST_END(); +} diff --git a/Core/Code/files.cmake b/Core/Code/files.cmake index 84442734cb..3dcef47052 100644 --- a/Core/Code/files.cmake +++ b/Core/Code/files.cmake @@ -1,400 +1,400 @@ 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 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/mitkConvert2Dto3DImageFilter.h Algorithms/mitkPlaneClipping.h Common/mitkExceptionMacro.h Common/mitkServiceBaseObject.h Common/mitkTestingMacros.h Common/mitkTesting.h DataManagement/mitkProportionalTimeGeometry.h DataManagement/mitkTimeGeometry.h DataManagement/mitkImageAccessByItk.h DataManagement/mitkImageCast.h DataManagement/mitkImagePixelAccessor.h DataManagement/mitkImagePixelReadAccessor.h DataManagement/mitkImagePixelWriteAccessor.h DataManagement/mitkImageReadAccessor.h DataManagement/mitkImageWriteAccessor.h DataManagement/mitkITKImageImport.h DataManagement/mitkITKImageImport.txx DataManagement/mitkImageToItk.h DataManagement/mitkImageToItk.txx DataManagement/mitkTimeSlicedGeometry.h # Deprecated, empty for compatibilty reasons. Interactions/mitkEventMapperAddOn.h Interfaces/mitkIDataNodeReader.h Rendering/mitkLocalStorageHandler.h IO/mitkPixelTypeTraits.h ) set(CPP_FILES Algorithms/mitkBaseDataSource.cpp Algorithms/mitkCompareImageDataFilter.cpp - Algorithms/mitkMultiChannelImageDataComparisonFilter.cpp + Algorithms/mitkMultiComponentImageDataComparisonFilter.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/mitkImageToSurfaceFilter.cpp Algorithms/mitkPointSetSource.cpp Algorithms/mitkPointSetToPointSetFilter.cpp Algorithms/mitkRGBToRGBACastImageFilter.cpp Algorithms/mitkSubImageSelector.cpp Algorithms/mitkSurfaceSource.cpp Algorithms/mitkSurfaceToImageFilter.cpp Algorithms/mitkSurfaceToSurfaceFilter.cpp Algorithms/mitkUIDGenerator.cpp Algorithms/mitkVolumeCalculator.cpp Algorithms/mitkClippedSurfaceBoundsCalculator.cpp Algorithms/mitkExtractSliceFilter.cpp Algorithms/mitkConvert2Dto3DImageFilter.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/mitkProportionalTimeGeometry.cpp DataManagement/mitkTimeGeometry.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/mitkImageAccessorBase.cpp DataManagement/mitkImageCaster.cpp DataManagement/mitkImageCastPart1.cpp DataManagement/mitkImageCastPart2.cpp DataManagement/mitkImageCastPart3.cpp DataManagement/mitkImageCastPart4.cpp DataManagement/mitkImageDataItem.cpp DataManagement/mitkImageDescriptor.cpp DataManagement/mitkImageVtkAccessor.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/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/mitkRenderingModeProperty.cpp DataManagement/mitkShaderProperty.cpp DataManagement/mitkResliceMethodProperty.cpp DataManagement/mitkMaterial.cpp DataManagement/mitkPointSetShapeProperty.cpp DataManagement/mitkFloatPropertyExtension.cpp DataManagement/mitkIntPropertyExtension.cpp DataManagement/mitkPropertyExtension.cpp DataManagement/mitkPropertyFilter.cpp DataManagement/mitkPropertyAliases.cpp DataManagement/mitkPropertyDescriptions.cpp DataManagement/mitkPropertyExtensions.cpp DataManagement/mitkPropertyFilters.cpp Interactions/mitkAction.cpp Interactions/mitkAffineInteractor.cpp Interactions/mitkBindDispatcherInteractor.cpp Interactions/mitkCoordinateSupplier.cpp Interactions/mitkDataInteractor.cpp Interactions/mitkDispatcher.cpp Interactions/mitkDisplayCoordinateOperation.cpp Interactions/mitkDisplayInteractor.cpp Interactions/mitkDisplayPositionEvent.cpp # Interactions/mitkDisplayVectorInteractorLevelWindow.cpp # legacy, prob even now unneeded # Interactions/mitkDisplayVectorInteractorScroll.cpp Interactions/mitkEvent.cpp Interactions/mitkEventConfig.cpp Interactions/mitkEventDescription.cpp Interactions/mitkEventFactory.cpp Interactions/mitkInteractionEventHandler.cpp Interactions/mitkEventMapper.cpp Interactions/mitkEventStateMachine.cpp Interactions/mitkGlobalInteraction.cpp Interactions/mitkInteractor.cpp Interactions/mitkInternalEvent.cpp Interactions/mitkInteractionEvent.cpp Interactions/mitkInteractionEventConst.cpp Interactions/mitkInteractionPositionEvent.cpp Interactions/mitkInteractionKeyEvent.cpp Interactions/mitkMousePressEvent.cpp Interactions/mitkMouseMoveEvent.cpp Interactions/mitkMouseReleaseEvent.cpp Interactions/mitkMouseWheelEvent.cpp Interactions/mitkMouseDoubleClickEvent.cpp Interactions/mitkMouseModeSwitcher.cpp Interactions/mitkMouseMovePointSetInteractor.cpp Interactions/mitkMoveBaseDataInteractor.cpp Interactions/mitkNodeDepententPointSetInteractor.cpp Interactions/mitkPointSetDataInteractor.cpp Interactions/mitkPointSetInteractor.cpp Interactions/mitkPositionEvent.cpp Interactions/mitkPositionTracker.cpp Interactions/mitkStateMachineAction.cpp Interactions/mitkStateMachineCondition.cpp Interactions/mitkStateMachineState.cpp Interactions/mitkStateMachineTransition.cpp Interactions/mitkState.cpp Interactions/mitkStateMachineContainer.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 Interfaces/mitkInteractionEventObserver.cpp Interfaces/mitkIShaderRepository.cpp Interfaces/mitkIPropertyAliases.cpp Interfaces/mitkIPropertyDescriptions.cpp Interfaces/mitkIPropertyExtensions.cpp Interfaces/mitkIPropertyFilters.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/mitkItkLoggingAdapter.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/mitkVtkLoggingAdapter.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/mitkVtkMapper.cpp Rendering/mitkRenderWindowFrame.cpp Rendering/mitkGeometry2DDataMapper2D.cpp Rendering/mitkGeometry2DDataVtkMapper3D.cpp Rendering/mitkGLMapper.cpp Rendering/mitkGradientBackground.cpp Rendering/mitkManufacturerLogo.cpp Rendering/mitkMapper.cpp Rendering/mitkPointSetGLMapper2D.cpp Rendering/mitkPointSetVtkMapper2D.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/vtkMitkLevelWindowFilter.cpp Rendering/vtkNeverTranslucentTexture.cpp Rendering/mitkRenderingTestHelper.cpp Rendering/mitkOverlay.cpp Rendering/mitkVtkOverlay.cpp Rendering/mitkVtkOverlay2D.cpp Rendering/mitkVtkOverlay3D.cpp Rendering/mitkOverlayManager.cpp Rendering/mitkAbstractOverlayLayouter.cpp Rendering/mitkTextOverlay2D.cpp Rendering/mitkTextOverlay3D.cpp Rendering/mitkLabelOverlay3D.cpp Rendering/mitkOverlay2DLayouter.cpp Common/mitkException.cpp Common/mitkCommon.h Common/mitkCoreObjectFactoryBase.cpp Common/mitkCoreObjectFactory.cpp Common/mitkCoreServices.cpp ) list(APPEND CPP_FILES ${CppMicroServices_SOURCES}) set(RESOURCE_FILES Interactions/globalConfig.xml Interactions/DisplayInteraction.xml Interactions/DisplayConfig.xml Interactions/DisplayConfigPACS.xml Interactions/DisplayConfigPACSPan.xml Interactions/DisplayConfigPACSScroll.xml Interactions/DisplayConfigPACSZoom.xml Interactions/DisplayConfigPACSLevelWindow.xml Interactions/DisplayConfigMITK.xml Interactions/PointSet.xml Interactions/Legacy/StateMachine.xml Interactions/Legacy/DisplayConfigMITKTools.xml Interactions/PointSetConfig.xml Shaders/mitkShaderLighting.xml mitkLevelWindowPresets.xml ) diff --git a/Modules/OpenCVVideoSupport/Testing/mitkOpenCVMitkConversionTest.cpp b/Modules/OpenCVVideoSupport/Testing/mitkOpenCVMitkConversionTest.cpp index 744df3b682..1d5660ca92 100644 --- a/Modules/OpenCVVideoSupport/Testing/mitkOpenCVMitkConversionTest.cpp +++ b/Modules/OpenCVVideoSupport/Testing/mitkOpenCVMitkConversionTest.cpp @@ -1,305 +1,278 @@ /*=================================================================== 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. ===================================================================*/ // mitk includes #include "mitkImageToOpenCVImageFilter.h" #include "mitkOpenCVToMitkImageFilter.h" #include #include #include #include #include "mitkItkImageFileReader.h" #include "mitkImageReadAccessor.h" #include "mitkImageSliceSelector.h" // itk includes #include #include #include // define test pixel indexes and intensities and other values typedef itk::RGBPixel< unsigned char > TestUCRGBPixelType; cv::Size testImageSize; cv::Point pos1; cv::Point pos2; cv::Point pos3; cv::Vec3b color1; cv::Vec3b color2; cv::Vec3b color3; uchar greyValue1; uchar greyValue2; uchar greyValue3; /*! Documentation * Test for image conversion of OpenCV images and mitk::Images. It tests the classes * OpenCVToMitkImageFilter and ImageToOpenCVImageFilter */ // Some declarations template void ComparePixels( itk::Image,VImageDimension>* image ); void ReadImageDataAndConvertForthAndBack(std::string imageFileName); void ConvertIplImageForthAndBack(mitk::Image::Pointer inputForCVMat, std::string imageFileName); void ConvertCVMatForthAndBack(mitk::Image::Pointer inputForCVMat, std::string imageFileName); // Begin the test for mitkImage to OpenCV image conversion and back. int mitkOpenCVMitkConversionTest(int argc, char* argv[]) { MITK_TEST_BEGIN("ImageToOpenCVImageFilter") - //// the first part of this test checks the conversion of a cv::Mat style OpenCV image. + // the first part of this test checks the conversion of a cv::Mat style OpenCV image. - //// we build an cv::Mat image - //MITK_INFO << "setting test values"; - //testImageSize = cv::Size(11,11); + // we build an cv::Mat image + MITK_INFO << "setting test values"; + testImageSize = cv::Size(11,11); - //pos1 = cv::Point(0,0); - //pos2 = cv::Point(5,5); - //pos3 = cv::Point(10,10); + pos1 = cv::Point(0,0); + pos2 = cv::Point(5,5); + pos3 = cv::Point(10,10); - //color1 = cv::Vec3b(50,0,0); - //color2 = cv::Vec3b(0,128,0); - //color3 = cv::Vec3b(0,0,255); + color1 = cv::Vec3b(50,0,0); + color2 = cv::Vec3b(0,128,0); + color3 = cv::Vec3b(0,0,255); - //greyValue1 = 0; - //greyValue2 = 128; - //greyValue3 = 255; + greyValue1 = 0; + greyValue2 = 128; + greyValue3 = 255; - //MITK_INFO << "generating test OpenCV image (RGB)"; - //cv::Mat testRGBImage = cv::Mat::zeros( testImageSize, CV_8UC3 ); + MITK_INFO << "generating test OpenCV image (RGB)"; + cv::Mat testRGBImage = cv::Mat::zeros( testImageSize, CV_8UC3 ); - //// generate some test intensity values - //testRGBImage.at(pos1)= color1; - //testRGBImage.at(pos2)= color2; - //testRGBImage.at(pos3)= color3; + // generate some test intensity values + testRGBImage.at(pos1)= color1; + testRGBImage.at(pos2)= color2; + testRGBImage.at(pos3)= color3; - ////cv::namedWindow("debug", CV_WINDOW_FREERATIO ); - ////cv::imshow("debug", testRGBImage.clone()); - ////cv::waitKey(0); + //cv::namedWindow("debug", CV_WINDOW_FREERATIO ); + //cv::imshow("debug", testRGBImage.clone()); + //cv::waitKey(0); - //// convert it to a mitk::Image - //MITK_INFO << "converting OpenCV test image to mitk image and comparing scalar rgb values"; - //mitk::OpenCVToMitkImageFilter::Pointer openCvToMitkFilter = - // mitk::OpenCVToMitkImageFilter::New(); - //openCvToMitkFilter->SetOpenCVMat( testRGBImage ); - //openCvToMitkFilter->Update(); + // convert it to a mitk::Image + MITK_INFO << "converting OpenCV test image to mitk image and comparing scalar rgb values"; + mitk::OpenCVToMitkImageFilter::Pointer openCvToMitkFilter = + mitk::OpenCVToMitkImageFilter::New(); + openCvToMitkFilter->SetOpenCVMat( testRGBImage ); + openCvToMitkFilter->Update(); - //mitk::Image::Pointer mitkImage = openCvToMitkFilter->GetOutput(); - //AccessFixedTypeByItk(mitkImage.GetPointer(), ComparePixels, - // (itk::RGBPixel), // rgb image - // (2) ); + mitk::Image::Pointer mitkImage = openCvToMitkFilter->GetOutput(); + AccessFixedTypeByItk(mitkImage.GetPointer(), ComparePixels, + (itk::RGBPixel), // rgb image + (2) ); - //// convert it back to OpenCV image - //MITK_INFO << "converting mitk image to OpenCV image and comparing scalar rgb values"; - //mitk::ImageToOpenCVImageFilter::Pointer mitkToOpenCv = mitk::ImageToOpenCVImageFilter::New(); - //mitkToOpenCv->SetImage( mitkImage ); - //cv::Mat openCvImage = mitkToOpenCv->GetOpenCVMat(); + // convert it back to OpenCV image + MITK_INFO << "converting mitk image to OpenCV image and comparing scalar rgb values"; + mitk::ImageToOpenCVImageFilter::Pointer mitkToOpenCv = mitk::ImageToOpenCVImageFilter::New(); + mitkToOpenCv->SetImage( mitkImage ); + cv::Mat openCvImage = mitkToOpenCv->GetOpenCVMat(); - //// and test equality of the sentinel pixel - //cv::Vec3b convertedColor1 = openCvImage.at(pos1); - //cv::Vec3b convertedColor2 = openCvImage.at(pos2); - //cv::Vec3b convertedColor3 = openCvImage.at(pos3); + // and test equality of the sentinel pixel + cv::Vec3b convertedColor1 = openCvImage.at(pos1); + cv::Vec3b convertedColor2 = openCvImage.at(pos2); + cv::Vec3b convertedColor3 = openCvImage.at(pos3); - //MITK_TEST_CONDITION( color1 == convertedColor1, "Testing if initially created color values " << static_cast( color1[0] ) << ", " << static_cast( color1[1] ) << ", " << static_cast( color1[2] ) << " matches the color values " << static_cast( convertedColor1[0] ) << ", " << static_cast( convertedColor1[1] ) << ", " << static_cast( convertedColor1[2] ) << " at the same position " << pos1.x << ", " << pos1.y << " in the back converted OpenCV image" ) + MITK_TEST_CONDITION( color1 == convertedColor1, "Testing if initially created color values " << static_cast( color1[0] ) << ", " << static_cast( color1[1] ) << ", " << static_cast( color1[2] ) << " matches the color values " << static_cast( convertedColor1[0] ) << ", " << static_cast( convertedColor1[1] ) << ", " << static_cast( convertedColor1[2] ) << " at the same position " << pos1.x << ", " << pos1.y << " in the back converted OpenCV image" ) - //MITK_TEST_CONDITION( color2 == convertedColor2, "Testing if initially created color values " << static_cast( color2[0] ) << ", " << static_cast( color2[1] ) << ", " << static_cast( color2[2] ) << " matches the color values " << static_cast( convertedColor2[0] ) << ", " << static_cast( convertedColor2[1] ) << ", " << static_cast( convertedColor2[2] ) << " at the same position " << pos2.x << ", " << pos2.y << " in the back converted OpenCV image" ) + MITK_TEST_CONDITION( color2 == convertedColor2, "Testing if initially created color values " << static_cast( color2[0] ) << ", " << static_cast( color2[1] ) << ", " << static_cast( color2[2] ) << " matches the color values " << static_cast( convertedColor2[0] ) << ", " << static_cast( convertedColor2[1] ) << ", " << static_cast( convertedColor2[2] ) << " at the same position " << pos2.x << ", " << pos2.y << " in the back converted OpenCV image" ) - //MITK_TEST_CONDITION( color3 == convertedColor3, "Testing if initially created color values " << static_cast( color3[0] ) << ", " << static_cast( color3[1] ) << ", " << static_cast( color3[2] ) << " matches the color values " << static_cast( convertedColor3[0] ) << ", " << static_cast( convertedColor3[1] ) << ", " << static_cast( convertedColor3[2] ) << " at the same position " << pos3.x << ", " << pos3.y << " in the back converted OpenCV image" ) + MITK_TEST_CONDITION( color3 == convertedColor3, "Testing if initially created color values " << static_cast( color3[0] ) << ", " << static_cast( color3[1] ) << ", " << static_cast( color3[2] ) << " matches the color values " << static_cast( convertedColor3[0] ) << ", " << static_cast( convertedColor3[1] ) << ", " << static_cast( convertedColor3[2] ) << " at the same position " << pos3.x << ", " << pos3.y << " in the back converted OpenCV image" ) // the second part of this test checks the conversion of mitk::Images to Ipl images and cv::Mat and back. for(unsigned int i = 1; i < argc; ++i ) { ReadImageDataAndConvertForthAndBack(argv[i]); } MITK_TEST_END(); } template void ComparePixels( itk::Image,VImageDimension>* image ) { typedef itk::RGBPixel PixelType; typedef itk::Image ImageType; typename ImageType::IndexType pixelIndex; pixelIndex[0] = pos1.x; pixelIndex[1] = pos1.y; PixelType onePixel = image->GetPixel( pixelIndex ); MITK_TEST_CONDITION( color1[0] == onePixel.GetBlue(), "Testing if blue value (= " << static_cast(color1[0]) << ") at postion " << pos1.x << ", " << pos1.y << " in OpenCV image is " << "equals the blue value (= " << static_cast(onePixel.GetBlue()) << ")" << " in the generated mitk image"); pixelIndex[0] = pos2.x; pixelIndex[1] = pos2.y; onePixel = image->GetPixel( pixelIndex ); MITK_TEST_CONDITION( color2[1] == onePixel.GetGreen(), "Testing if green value (= " << static_cast(color2[1]) << ") at postion " << pos2.x << ", " << pos2.y << " in OpenCV image is " << "equals the green value (= " << static_cast(onePixel.GetGreen()) << ")" << " in the generated mitk image"); pixelIndex[0] = pos3.x; pixelIndex[1] = pos3.y; onePixel = image->GetPixel( pixelIndex ); MITK_TEST_CONDITION( color3[2] == onePixel.GetRed(), "Testing if red value (= " << static_cast(color3[2]) << ") at postion " << pos3.x << ", " << pos3.y << " in OpenCV image is " << "equals the red value (= " << static_cast(onePixel.GetRed()) << ")" << " in the generated mitk image"); } void ReadImageDataAndConvertForthAndBack(std::string imageFileName) { // first we load an mitk::Image from the data repository mitk::ItkImageFileReader::Pointer reader = mitk::ItkImageFileReader::New(); reader->SetFileName(imageFileName); reader->Update(); mitk::Image::Pointer mitkTestImage = reader->GetOutput(); // some format checking mitk::Image::Pointer resultImg = NULL; if( mitkTestImage->GetDimension() <= 3 ) { if( mitkTestImage->GetDimension() > 2 && mitkTestImage->GetDimension(2) == 1 ) { mitk::ImageSliceSelector::Pointer sliceSelector = mitk::ImageSliceSelector::New(); sliceSelector->SetInput(mitkTestImage); sliceSelector->SetSliceNr(0); sliceSelector->Update(); resultImg = sliceSelector->GetOutput()->Clone(); } else if(mitkTestImage->GetDimension() < 3) { resultImg = mitkTestImage; } else { return; // 3D images are not supported, except with just one slice. } } else { return; // 4D images are not supported! } - //ConvertIplImageForthAndBack(resultImg, imageFileName); + ConvertIplImageForthAndBack(resultImg, imageFileName); ConvertCVMatForthAndBack(resultImg, imageFileName); } void ConvertCVMatForthAndBack(mitk::Image::Pointer inputForCVMat, std::string imageFileName) { // now we convert it to OpenCV IplImage mitk::ImageToOpenCVImageFilter::Pointer toOCvConverter = mitk::ImageToOpenCVImageFilter::New(); toOCvConverter->SetImage(inputForCVMat); cv::Mat cvmatTestImage = toOCvConverter->GetOpenCVMat(); MITK_TEST_CONDITION_REQUIRED( !cvmatTestImage.empty(), "Conversion to cv::Mat successful!"); - // temp visualization of IplImage - //cv::Mat matData = cv::Mat(iplTestImage, true); - double minVal, maxVal; - cv::minMaxLoc(cvmatTestImage, &minVal, &maxVal); - cv::Mat uCCvImage; - cvmatTestImage.convertTo(uCCvImage,CV_8U, 255.0/(maxVal - minVal), -minVal ); - cv::namedWindow("IplImage", CV_WINDOW_AUTOSIZE); - cv::imshow("IplImage", uCCvImage); - cv::waitKey(10000); - cv::destroyWindow("IplImage"); - // end temp visualization of IplImage - mitk::OpenCVToMitkImageFilter::Pointer toMitkConverter = mitk::OpenCVToMitkImageFilter::New(); toMitkConverter->SetOpenCVMat(cvmatTestImage); toMitkConverter->Update(); // initialize the image with the input image, since we want to test equality and OpenCV does not feature geometries and spacing mitk::Image::Pointer result = inputForCVMat->Clone(); mitk::ImageReadAccessor resultAcc(toMitkConverter->GetOutput(), toMitkConverter->GetOutput()->GetSliceData()); result->SetImportSlice(const_cast(resultAcc.GetData())); - // temp visualization of IplImage - mitk::ImageToOpenCVImageFilter::Pointer openCvImageCon = mitk::ImageToOpenCVImageFilter::New(); - openCvImageCon->SetImage(result); - cv::Mat cvImage2 = cv::Mat(openCvImageCon->GetOpenCVImage(), true); - //double minVal, maxVal; - cv::minMaxLoc(cvImage2, &minVal, &maxVal); - //cv::Mat uCCvImage; - cvImage2.convertTo(uCCvImage,CV_8U, 255.0/(maxVal - minVal), -minVal ); - cv::namedWindow("IplImage", CV_WINDOW_AUTOSIZE); - cv::imshow("IplImage", uCCvImage); - cv::waitKey(10000); - cv::destroyWindow("IplImage"); - // end temp visualization of IplImage - if( result->GetPixelType().GetNumberOfComponents() == 1 ) { MITK_TEST_EQUAL( result, inputForCVMat, "Testing equality of input and output image of cv::Mat conversion for " << imageFileName ); } else if( result->GetPixelType().GetNumberOfComponents() == 3 ) { MITK_TEST_EQUAL( result, inputForCVMat, "Testing equality of input and output image of cv::Mat conversion for " << imageFileName ); - //MITK_WARN << "Implement MITK_TEST_EQUAL functionality for three component images!"; } else { MITK_WARN << "Unhandled number of components used to test equality, please enhance test!"; } } void ConvertIplImageForthAndBack(mitk::Image::Pointer inputForIpl, std::string imageFileName) { // now we convert it to OpenCV IplImage mitk::ImageToOpenCVImageFilter::Pointer toOCvConverter = mitk::ImageToOpenCVImageFilter::New(); toOCvConverter->SetImage(inputForIpl); IplImage* iplTestImage = toOCvConverter->GetOpenCVImage(); MITK_TEST_CONDITION_REQUIRED( iplTestImage != NULL, "Conversion to OpenCv IplImage successful!"); mitk::OpenCVToMitkImageFilter::Pointer toMitkConverter = mitk::OpenCVToMitkImageFilter::New(); toMitkConverter->SetOpenCVImage(iplTestImage); toMitkConverter->Update(); // initialize the image with the input image, since we want to test equality and OpenCV does not feature geometries and spacing mitk::Image::Pointer result = inputForIpl->Clone(); mitk::ImageReadAccessor resultAcc(toMitkConverter->GetOutput(), toMitkConverter->GetOutput()->GetSliceData()); result->SetImportSlice(const_cast(resultAcc.GetData())); if( result->GetPixelType().GetNumberOfComponents() == 1 ) { MITK_TEST_EQUAL( result, inputForIpl, "Testing equality of input and output image of IplImage conversion for " << imageFileName ); } else if( result->GetPixelType().GetNumberOfComponents() == 3 ) { - MITK_WARN << "Implement MITK_TEST_EQUAL functionality for three component images!"; + MITK_TEST_EQUAL( result, inputForIpl, "Testing equality of input and output image of cv::Mat conversion for " << imageFileName ); } else { MITK_WARN << "Unhandled number of components used to test equality, please enhance test!"; } } \ No newline at end of file