diff --git a/Core/Code/IO/mitkImageCreator.cpp b/Core/Code/IO/mitkImageCreator.cpp index e1deaa443f..e69de29bb2 100644 --- a/Core/Code/IO/mitkImageCreator.cpp +++ b/Core/Code/IO/mitkImageCreator.cpp @@ -1,75 +0,0 @@ -#include -#include -#include - -//creates a test image with given dimension filled with random values -//template -// static mitk::Image::Pointer mitk::ImageCreator::CreateTestImage(unsigned int dimX, -// unsigned int dimY, -// unsigned int dimZ, -// unsigned int dimT, -// unsigned int channels, -// const double randomMax, const double randMin) -//{ -// mitk::PixelType type; -// type.Initialize(typeid(TPixelType)); -// mitk::Image::Pointer output = mitk::Image::New(); -// unsigned int* dimensions = new unsigned int[4]; -// unsigned int numberOfDimensions = 0; -// unsigned int bufferSize = 0; -// bufferSize = dimX*dimY; - -// if(dimT == 0) -// { -// if(dimZ == 0) -// { -// numberOfDimensions = 2; -// } -// else -// { -// numberOfDimensions = 3; -// // bufferSize = dimX*dimY*dimZ; -// } -// } -// else -// { -// numberOfDimensions = 4; -// // bufferSize = dimX*dimY*dimZ*dimT; -// } - -// dimensions[0] = dimX; -// dimensions[1] = dimY; -// dimensions[2] = dimZ; -// dimensions[3] = dimT; - -// output->Initialize(type, numberOfDimensions, dimensions, channels); - -// TPixelType* imageBuffer = (TPixelType*)output->GetData(); -// itk::Statistics::MersenneTwisterRandomVariateGenerator::Pointer randomGenerator = itk::Statistics::MersenneTwisterRandomVariateGenerator::New(); - -// for(unsigned int t = 0; t < dimT; t++) -// { -// for(unsigned int s = 0; s < dimZ; s++) -// { -// 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))) -// { -// imageBuffer[i] = (TPixelType)randomGenerator->GetUniformVariate(randMin,randomMax); -// }else if(type == typeid(unsigned char)) -// { -// imageBuffer[i] = ((TPixelType)randomGenerator->GetIntegerVariate((int)randomMax)) % 256; -// } -// //TODO call different methods for other datatypes -// } -// output->SetSlice(imageBuffer, s, t, channels); -// } -// } - -// return output; -//} diff --git a/Core/Code/IO/mitkImageCreator.h b/Core/Code/IO/mitkImageCreator.h index 6059aceca6..531cbbd29d 100644 --- a/Core/Code/IO/mitkImageCreator.h +++ b/Core/Code/IO/mitkImageCreator.h @@ -1,106 +1,111 @@ /*========================================================================= 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 ImageCreator_H_HEADER_INCLUDED #define ImageCreator_H_HEADER_INCLUDED #include "mitkCommon.h" -#include "mitkImageSource.h" #include #include +#include namespace mitk { //##Documentation - //## @brief random generator for MITK images + //## @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 ImageCreator { public: template static mitk::Image::Pointer CreateRandomImage(unsigned int dimX, unsigned int dimY, unsigned int dimZ = 1, unsigned int dimT = 1, - unsigned int channels = 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 = dimX*dimY; + unsigned int bufferSize = 0; - if(dimT == 0) + //check which dimension is needed + if(dimT <= 1) { - if(dimZ == 0) - { + if(dimZ <= 1) + { //2D numberOfDimensions = 2; + dimensions[0] = dimX; + dimensions[1] = dimY; + bufferSize = dimX*dimY; } else - { + { //3D numberOfDimensions = 3; - // bufferSize = dimX*dimY*dimZ; + dimensions[0] = dimX; + dimensions[1] = dimY; + dimensions[2] = dimZ; + bufferSize = dimX*dimY*dimZ; } } else - { + { //4D numberOfDimensions = 4; - // bufferSize = dimX*dimY*dimZ*dimT; - } - - dimensions[0] = dimX; - dimensions[1] = dimY; - dimensions[2] = dimZ; - dimensions[3] = dimT; - - output->Initialize(type, numberOfDimensions, dimensions, channels); + 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(); - //for all time steps - for(unsigned int t = 0; t < dimT; t++) - { //for all slices - for(unsigned int s = 0; s < dimZ; s++) - { //for all pixels - for(unsigned int i = 0; i < bufferSize; i++) - { - if(type == typeid(int)) //call integer function - { - MITK_INFO << "1"; - 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 - { - MITK_INFO << "2"; - imageBuffer[i] = (TPixelType)randomGenerator->GetUniformVariate(randMin,randomMax); - }else if(type == typeid(unsigned char)) - { - MITK_INFO << "3"; - imageBuffer[i] = ((int)randomGenerator->GetIntegerVariate((int)randomMax)) % 256; - }else{ - MITK_INFO << "4"; - } - //TODO call different methods for other datatypes - } - output->SetSlice(imageBuffer, s, t, channels); + //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 /* ImageCreator_H_HEADER_INCLUDED */ diff --git a/Core/Code/Testing/files.cmake b/Core/Code/Testing/files.cmake index 69c61b54b2..9e356c5733 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 + mitkImageCreatorTest.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/mitkImageCreatorTest.cpp b/Core/Code/Testing/mitkImageCreatorTest.cpp new file mode 100644 index 0000000000..4dc4ca4e77 --- /dev/null +++ b/Core/Code/Testing/mitkImageCreatorTest.cpp @@ -0,0 +1,56 @@ +/*========================================================================= + +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 "mitkImageCreator.h" + +int mitkImageCreatorTest(int /*argc*/, char* /*argv*/[]) +{ + MITK_TEST_BEGIN("ToFImageWriter"); + + //create some images with arbitrary parameters (corner cases) + mitk::Image::Pointer image2Da = mitk::ImageCreator::CreateRandomImage(120, 205); + mitk::Image::Pointer image2Db = mitk::ImageCreator::CreateRandomImage(1, 1, 0, 0); + mitk::Image::Pointer image3Da = mitk::ImageCreator::CreateRandomImage(512, 205, 1, 0); + mitk::Image::Pointer image3Db = mitk::ImageCreator::CreateRandomImage(512, 532, 112, 0); + mitk::Image::Pointer image4Da = mitk::ImageCreator::CreateRandomImage(120, 205, 78, 1); + mitk::Image::Pointer image4Db = mitk::ImageCreator::CreateRandomImage(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_END(); +}