diff --git a/Core/Code/IO/mitkImageGenerator.cpp b/Core/Code/IO/mitkImageGenerator.cpp new file mode 100644 index 0000000000..ae33022a75 --- /dev/null +++ b/Core/Code/IO/mitkImageGenerator.cpp @@ -0,0 +1,10 @@ +/*========================================================================= +Copyright (c) German Cancer Research Center, Division of Medical and +Biological Informatics. All rights reserved. +See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. + +This software is distributed WITHOUT ANY WARRANTY; without even +the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR +PURPOSE. See the above copyright notices for more information. + +=========================================================================*/ diff --git a/Core/Code/IO/mitkImageGenerator.h b/Core/Code/IO/mitkImageGenerator.h new file mode 100644 index 0000000000..97b41ae210 --- /dev/null +++ b/Core/Code/IO/mitkImageGenerator.h @@ -0,0 +1,110 @@ +/*========================================================================= +Copyright (c) German Cancer Research Center, Division of Medical and +Biological Informatics. All rights reserved. +See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. + +This software is distributed WITHOUT ANY WARRANTY; without even +the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR +PURPOSE. See the above copyright notices for more information. + +=========================================================================*/ + +#ifndef ImageGenerator_H_HEADER_INCLUDED +#define ImageGenerator_H_HEADER_INCLUDED + +#include "mitkCommon.h" +#include +#include + +namespace mitk { + //##Documentation + //## @brief generator for random MITK images + //## This is a helper class to generate MITK images filled with random values. + //## The parameters dimX, dimY, dimZ, and dimT are used to set the dimensions of the MITK image. + //## Default parameters are dimT = 1 and dimZ = 1 which is a 2D image (or a 4D image with just 1 slice and 1 time step). + //## The parameters randomMax and randomMin are boundary values for the random generator. + //## In other words: the generator will generate values between randomMin and randomMax. + //## @ingroup IO + class MITK_CORE_EXPORT ImageGenerator + { + public: + template + static mitk::Image::Pointer GenerateRandomImage(unsigned int dimX, + unsigned int dimY, + unsigned int dimZ = 1, + unsigned int dimT = 1, + const double randomMax = 1000.0f, const double randMin = 0.0f) + { + //set the data type according to the template + mitk::PixelType type; + type.Initialize(typeid(TPixelType)); + + //initialize the MITK image with given dimenion and data type + mitk::Image::Pointer output = mitk::Image::New(); + unsigned int* dimensions = new unsigned int[4]; + unsigned int numberOfDimensions = 0; + unsigned int bufferSize = 0; + + //check which dimension is needed + if(dimT <= 1) + { + if(dimZ <= 1) + { //2D + numberOfDimensions = 2; + dimensions[0] = dimX; + dimensions[1] = dimY; + bufferSize = dimX*dimY; + } + else + { //3D + numberOfDimensions = 3; + dimensions[0] = dimX; + dimensions[1] = dimY; + dimensions[2] = dimZ; + bufferSize = dimX*dimY*dimZ; + } + } + else + { //4D + numberOfDimensions = 4; + dimensions[0] = dimX; + dimensions[1] = dimY; + dimensions[2] = dimZ; + dimensions[3] = dimT; + bufferSize = dimX*dimY*dimZ*dimT; + } + output->Initialize(type, numberOfDimensions, dimensions); + + //get a pointer to the image buffer to write into + TPixelType* imageBuffer = (TPixelType*)output->GetData(); + + //initialize the random generator + itk::Statistics::MersenneTwisterRandomVariateGenerator::Pointer randomGenerator = itk::Statistics::MersenneTwisterRandomVariateGenerator::New(); + randomGenerator->Initialize(); + + //fill the buffer for each pixel/voxel + for(unsigned int i = 0; i < bufferSize; i++) + { + if(type == typeid(int)) //call integer function + { + imageBuffer[i] = (TPixelType)randomGenerator->GetIntegerVariate((int)randomMax); + //TODO random generator does not support integer values in a given range (e.g. from 5-10) + //range is always [0, (int)randomMax] + }else if((type == typeid(double)) || (type == typeid(float))) //call integer function + { + imageBuffer[i] = (TPixelType)randomGenerator->GetUniformVariate(randMin,randomMax); + }else if(type == typeid(unsigned char)) + { + //use the integer randomGenerator with mod 256 to generate unsigned char values + imageBuffer[i] = (unsigned char) ((int)randomGenerator->GetIntegerVariate((int)randomMax)) % 256; + }else{ + MITK_ERROR << "Datatype not supported yet."; + //TODO call different methods for other datatypes + } + } + return output; + } + }; +} // namespace mitk + +#endif /* ImageGenerator_H_HEADER_INCLUDED */ diff --git a/Core/Code/Testing/files.cmake b/Core/Code/Testing/files.cmake index 69c61b54b2..5a83571bcb 100644 --- a/Core/Code/Testing/files.cmake +++ b/Core/Code/Testing/files.cmake @@ -1,91 +1,92 @@ # tests with no extra command line parameter SET(MODULE_TESTS mitkCoreObjectFactoryTest.cpp mitkPointSetWriterTest.cpp mitkMaterialTest.cpp mitkDataNodeTest.cpp mitkActionTest.cpp mitkDataStorageTest.cpp mitkEnumerationPropertyTest.cpp mitkEventMapperTest.cpp mitkEventTest.cpp mitkFocusManagerTest.cpp mitkGenericPropertyTest.cpp mitkGeometry3DTest.cpp mitkGeometryDataToSurfaceFilterTest.cpp mitkGlobalInteractionTest.cpp mitkImageDataItemTest.cpp #mitkImageMapper2DTest.cpp mitkImageTest.cpp + mitkImageGeneratorTest.cpp mitkBaseDataTest.cpp #mitkImageToItkTest.cpp mitkInteractorTest.cpp mitkITKThreadingTest.cpp # mitkLevelWindowManagerTest.cpp mitkLevelWindowTest.cpp mitkMessageTest.cpp #mitkPipelineSmartPointerCorrectnessTest.cpp mitkPixelTypeTest.cpp mitkPlaneGeometryTest.cpp mitkPointSetFileIOTest.cpp mitkPointSetTest.cpp mitkPointSetInteractorTest.cpp mitkNodeDependentPointSetInteractorTest.cpp mitkPropertyListTest.cpp #mitkRegistrationBaseTest.cpp #mitkSegmentationInterpolationTest.cpp mitkSlicedGeometry3DTest.cpp mitkSliceNavigationControllerTest.cpp mitkStateMachineTest.cpp mitkStateMachineFactoryTest.cpp mitkStateTest.cpp mitkSurfaceTest.cpp mitkSurfaceToSurfaceFilterTest.cpp mitkTimeSlicedGeometryTest.cpp mitkTransitionTest.cpp mitkUndoControllerTest.cpp mitkVtkWidgetRenderingTest.cpp mitkVerboseLimitedLinearUndoTest.cpp mitkWeakPointerTest.cpp mitkTransferFunctionTest.cpp #mitkAbstractTransformGeometryTest.cpp #mitkPicFileIOTest.cpp mitkStepperTest.cpp itkTotalVariationDenoisingImageFilterTest.cpp mitkDICOMLocaleTest.cpp mitkPointSetLocaleTest.cpp mitkRenderingManagerTest.cpp vtkMitkThickSlicesFilterTest.cpp mitkNodePredicateSourceTest.cpp ) # test with image filename as an extra command line parameter SET(MODULE_IMAGE_TESTS mitkSurfaceVtkWriterTest.cpp mitkPicFileWriterTest.cpp mitkImageWriterTest.cpp #mitkImageSliceSelectorTest.cpp mitkImageTimeSelectorTest.cpp mitkPicFileReaderTest.cpp # mitkVtkPropRendererTest.cpp mitkDataNodeFactoryTest.cpp #mitkSTLFileReaderTest.cpp ) # list of images for which the tests are run SET(MODULE_TESTIMAGES US4DCyl.pic.gz Pic3D.pic.gz Pic2DplusT.pic.gz BallBinary30x30x30.pic.gz binary.stl ball.stl ) SET(MODULE_CUSTOM_TESTS #mitkLabeledImageToSurfaceFilterTest.cpp #mitkExternalToolsTest.cpp mitkDicomSeriesReaderTest.cpp ) diff --git a/Core/Code/Testing/mitkImageGeneratorTest.cpp b/Core/Code/Testing/mitkImageGeneratorTest.cpp new file mode 100644 index 0000000000..301b01e92f --- /dev/null +++ b/Core/Code/Testing/mitkImageGeneratorTest.cpp @@ -0,0 +1,62 @@ +/*========================================================================= + +Program: Medical Imaging & Interaction Toolkit +Language: C++ +Date: $Date$ +Version: $Revision$ + +Copyright (c) German Cancer Research Center, Division of Medical and +Biological Informatics. All rights reserved. +See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. + +This software is distributed WITHOUT ANY WARRANTY; without even +the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR +PURPOSE. See the above copyright notices for more information. + +=========================================================================*/ + +#include +#include "mitkImage.h" +#include "mitkImageGenerator.h" + +int mitkImageGeneratorTest(int /*argc*/, char* /*argv*/[]) +{ + MITK_TEST_BEGIN("ToFImageWriter"); + + //create some images with arbitrary parameters (corner cases) + mitk::Image::Pointer image2Da = mitk::ImageGenerator::GenerateRandomImage(120, 205, 0, 0, 577, 23); + mitk::Image::Pointer image2Db = mitk::ImageGenerator::GenerateRandomImage(1, 1, 0, 0); + mitk::Image::Pointer image3Da = mitk::ImageGenerator::GenerateRandomImage(512, 205, 1, 0); + mitk::Image::Pointer image3Db = mitk::ImageGenerator::GenerateRandomImage(512, 532, 112, 0); + mitk::Image::Pointer image4Da = mitk::ImageGenerator::GenerateRandomImage(120, 205, 78, 1); + mitk::Image::Pointer image4Db = mitk::ImageGenerator::GenerateRandomImage(550, 33, 78, 150); + + MITK_TEST_CONDITION_REQUIRED(image2Da->GetDimension() == 2, "Testing if the dimension is set correctly."); + MITK_TEST_CONDITION_REQUIRED(image2Db->GetDimension() == 2, "Testing if the dimension is set correctly."); + MITK_TEST_CONDITION_REQUIRED(image3Da->GetDimension() == 2, "Testing if the dimension is set correctly."); + MITK_TEST_CONDITION_REQUIRED(image3Db->GetDimension() == 3, "Testing if the dimension is set correctly."); + MITK_TEST_CONDITION_REQUIRED(image4Da->GetDimension() == 3, "Testing if the dimension is set correctly."); + MITK_TEST_CONDITION_REQUIRED(image4Db->GetDimension() == 4, "Testing if the dimension is set correctly."); + + MITK_TEST_CONDITION_REQUIRED(image2Da->GetDimension(0) == 120, "Testing if the dimensions are set correctly."); + MITK_TEST_CONDITION_REQUIRED(image2Db->GetDimension(1) == 1, "Testing if the dimensions are set correctly."); + MITK_TEST_CONDITION_REQUIRED(image3Da->GetDimension(2) == 1, "Testing if the dimensions are set correctly."); + MITK_TEST_CONDITION_REQUIRED(image3Db->GetDimension(2) == 112, "Testing if the dimensions are set correctly."); + MITK_TEST_CONDITION_REQUIRED(image4Da->GetDimension(3) == 1, "Testing if the dimensions are set correctly."); + MITK_TEST_CONDITION_REQUIRED(image4Db->GetDimension(3) == 150, "Testing if the dimensions are set correctly."); + + MITK_TEST_CONDITION_REQUIRED(image2Da->GetPixelType() == typeid(float), "Testing if the data type is set correctly."); + MITK_TEST_CONDITION_REQUIRED(image2Db->GetPixelType() == typeid(unsigned char), "Testing if the data type is set correctly."); + MITK_TEST_CONDITION_REQUIRED(image3Da->GetPixelType() == typeid(int), "Testing if the data type is set correctly."); + MITK_TEST_CONDITION_REQUIRED(image3Db->GetPixelType() == typeid(double), "Testing if the data type is set correctly."); + MITK_TEST_CONDITION_REQUIRED(image4Da->GetPixelType() == typeid(float), "Testing if the data type is set correctly."); + MITK_TEST_CONDITION_REQUIRED(image4Db->GetPixelType() == typeid(unsigned char), "Testing if the ddata type is set correctly."); + + MITK_TEST_CONDITION_REQUIRED(image2Da->GetScalarValueMax() <= 577, "Testing if max value holds"); + MITK_TEST_CONDITION_REQUIRED(image2Da->GetScalarValueMin() >= 23, "Testing if min value holds"); + + MITK_TEST_CONDITION_REQUIRED(image3Da->GetScalarValueMax() <= 1000, "Testing if max value holds"); + MITK_TEST_CONDITION_REQUIRED(image3Da->GetScalarValueMin() >= 0, "Testing if min value holds"); + + MITK_TEST_END(); +} diff --git a/Core/Code/files.cmake b/Core/Code/files.cmake index 6784c9cc9e..99a9f7f4e8 100644 --- a/Core/Code/files.cmake +++ b/Core/Code/files.cmake @@ -1,225 +1,226 @@ SET(H_FILES Algorithms/itkLocalVariationImageFilter.h Algorithms/itkTotalVariationDenoisingImageFilter.h Algorithms/itkTotalVariationSingleIterationImageFilter.h DataManagement/mitkCommon.h Interactions/mitkEventMapperAddOn.h ) SET(CPP_FILES Algorithms/mitkBaseDataSource.cpp Algorithms/mitkBaseProcess.cpp Algorithms/mitkCoreObjectFactoryBase.cpp Algorithms/mitkCoreObjectFactory.cpp Algorithms/mitkDataNodeFactory.cpp Algorithms/mitkDataNodeSource.cpp Algorithms/mitkGeometry2DDataToSurfaceFilter.cpp Algorithms/mitkHistogramGenerator.cpp Algorithms/mitkImageCaster.cpp Algorithms/mitkImageCastPart1.cpp Algorithms/mitkImageCastPart2.cpp Algorithms/mitkImageCastPart3.cpp Algorithms/mitkImageCastPart4.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 Controllers/mitkBaseController.cpp Controllers/mitkCallbackFromGUIThread.cpp Controllers/mitkCameraController.cpp Controllers/mitkCameraRotationController.cpp Controllers/mitkFocusManager.cpp Controllers/mitkLimitedLinearUndo.cpp Controllers/mitkOperationEvent.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/mitkColorProperty.cpp DataManagement/mitkDataStorage.cpp #DataManagement/mitkDataTree.cpp DataManagement/mitkDataNode.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/mitkImageDataItem.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/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/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/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 IO/mitkBaseDataIOFactory.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/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/mitkImageMapperGL2D.cpp Rendering/vtkMitkThickSlicesFilter.cpp )