diff --git a/Core/Code/Testing/mitkOverwriteSliceFilterTest.cpp b/Core/Code/Testing/mitkOverwriteSliceFilterTest.cpp index b7fcad8258..5512e61ca0 100644 --- a/Core/Code/Testing/mitkOverwriteSliceFilterTest.cpp +++ b/Core/Code/Testing/mitkOverwriteSliceFilterTest.cpp @@ -1,183 +1,213 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit Language: C++ Date: $Date$ Version: $Revision: 7837 $ 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 #include #include #include #include #include #include #include #include + +int VolumeSize = 5; + + + +static void OverwriteByIndexShiftTest(mitk::Image* workingImage, mitk::Image* refImg) +{ + // +} + + + +static void OverwriteByPointerTest(mitk::Image* workingImage, mitk::Image* refImg) +{ + + /* ============= setup plane ============*/ + int sliceindex = 3;//rand() % 32; + bool isFrontside = true; + bool isRotated = false; + + mitk::PlaneGeometry::Pointer plane = mitk::PlaneGeometry::New(); + plane->InitializeStandardPlane(workingImage->GetGeometry(), mitk::PlaneGeometry::Transversal, sliceindex, isFrontside, isRotated); + mitk::Point3D origin = plane->GetOrigin(); + mitk::Vector3D normal; + normal = plane->GetNormal(); + normal.Normalize(); + origin += normal * 0.5;//pixelspacing is 1, so half the spacing is 0.5 + plane->SetOrigin(origin); + + + + /* ============= extract slice ============*/ + vtkSmartPointer resliceMap = vtkSmartPointer::New(); + mitk::ExtractSliceFilter::Pointer slicerMap = mitk::ExtractSliceFilter::New(resliceMap); + slicerMap->SetInput(workingImage); + slicerMap->SetWorldGeometry(plane); + slicerMap->SetVtkOutputRequest(true); + slicerMap->Modified(); + slicerMap->Update(); + + vtkSmartPointer slice = vtkSmartPointer::New(); + slice = slicerMap->GetVtkOutput(); + + + + /* ============= overwrite slice ============*/ + resliceMap->SetOverwriteMode(true); + resliceMap->Modified(); + slicerMap->Modified(); + slicerMap->Update();//implicit overwrite + + + + /* ============= check ref == working ============*/ + bool areSame = true; + mitk::Index3D id; + id[0] = id[1] = id[2] = 0; + for (int x = 0; x < VolumeSize; ++x){ + id[0] = x; + for (int y = 0; y < VolumeSize; ++y){ + id[1] = y; + for (int z = 0; z < VolumeSize; ++z){ + id[2] = z; + areSame = refImg->GetPixelValueByIndex(id) == workingImage->GetPixelValueByIndex(id); + if(!areSame) + goto stop; + } + } + } +stop: + MITK_TEST_CONDITION(areSame,"comparing images"); + + + + /* ============= edit slice ============*/ + int idX = VolumeSize-3; + int idY = VolumeSize-2; + int idZ = 0; + int component = 0; + double val = 33.0; + + slice->SetScalarComponentFromDouble(idX,idY,idZ,component,val); + + + + /* ============= overwrite slice ============*/ + resliceMap->Modified(); + slicerMap->Modified(); + slicerMap->Update(); + + + + /* ============= check ============*/ + areSame = true; + + int x,y,z; + + for ( x = 0; x < VolumeSize; ++x){ + id[0] = x; + for ( y = 0; y < VolumeSize; ++y){ + id[1] = y; + for ( z = 0; z < VolumeSize; ++z){ + id[2] = z; + areSame = refImg->GetPixelValueByIndex(id) == workingImage->GetPixelValueByIndex(id); + if(!areSame) + goto stop2; + } + } + } +stop2: + MITK_INFO << "index: [" << x << ", " << y << ", " << z << "]"; + MITK_TEST_CONDITION(x==idX && y==idY && z==sliceindex,"overwrited the right index"); +} + + + + + + /*================ #BEGIN test main ================*/ int mitkOverwriteSliceFilterTest(int argc, char* argv[]) { MITK_TEST_BEGIN("mitkOverwriteSliceFilterTest") - int VolumeSize = 10; + typedef itk::Image ImageType; typedef itk::ImageRegionConstIterator< ImageType > ImageIterator; ImageType::Pointer image = ImageType::New(); ImageType::IndexType start; start[0] = start[1] = start[2] = 0; ImageType::SizeType size; size[0] = size[1] = size[2] = VolumeSize; ImageType::RegionType imgRegion; imgRegion.SetSize(size); imgRegion.SetIndex(start); image->SetRegions(imgRegion); image->SetSpacing(1.0); image->Allocate(); ImageIterator imageIterator( image, image->GetLargestPossibleRegion() ); imageIterator.GoToBegin(); unsigned short pixelValue = 0; //fill the image with distinct values while ( !imageIterator.IsAtEnd() ) { image->SetPixel(imageIterator.GetIndex(), pixelValue); ++imageIterator; ++pixelValue; } /* end setup itk image */ - mitk::Image::Pointer imageInMitk; - CastToMitkImage(image, imageInMitk); - - - - int sliceindex = 6;//rand() % 32; - bool isFrontside = true; - bool isRotated = false; - - mitk::PlaneGeometry::Pointer plane = mitk::PlaneGeometry::New(); - plane->InitializeStandardPlane(imageInMitk->GetGeometry(), mitk::PlaneGeometry::Transversal, sliceindex, isFrontside, isRotated); - mitk::Point3D origin = plane->GetOrigin(); - mitk::Vector3D normal; - normal = plane->GetNormal(); - normal.Normalize(); - origin += normal * 0.5;//pixelspacing is 1, so half the spacing is 0.5 - plane->SetOrigin(origin); - - - - - mitk::ExtractSliceFilter::Pointer slicer = mitk::ExtractSliceFilter::New(); - slicer->SetInput(imageInMitk); - slicer->SetWorldGeometry(plane); - slicer->SetVtkOutputRequest(true); - slicer->Modified(); - slicer->Update(); - - vtkSmartPointer slice = vtkSmartPointer::New(); - slice = slicer->GetVtkOutput(); - - - vtkSmartPointer resliceMap = vtkSmartPointer::New(); - mitk::ExtractSliceFilter::Pointer slicerMap = mitk::ExtractSliceFilter::New(resliceMap); - slicerMap->SetInput(imageInMitk); - slicerMap->SetWorldGeometry(plane); - slicerMap->SetVtkOutputRequest(true); - slicerMap->Modified(); - slicerMap->Update(); - vtkSmartPointer map = vtkSmartPointer::New(); - map = slicerMap->GetVtkOutput(); + mitk::Image::Pointer refImage; + CastToMitkImage(image, refImage); + mitk::Image::Pointer workingImg; + CastToMitkImage(image, workingImg); + OverwriteByPointerTest(workingImg, refImage); + mitk::Image::Pointer refImage2; + CastToMitkImage(image, refImage2); + mitk::Image::Pointer workingImg2; + CastToMitkImage(image, workingImg2); + OverwriteByIndexShiftTest(workingImg2, refImage2); - mitk::OverwriteSliceFilter::Pointer overwriter = mitk::OverwriteSliceFilter::New(); - overwriter->SetInput(imageInMitk); - overwriter->SetInputSlice(slice); - overwriter->SetInputMap(map); - overwriter->Modified(); - overwriter->Update(); - - mitk::Image::Pointer overwritedImage = overwriter->GetOutput(); - - bool areSame = true; - mitk::Index3D id; - id[0] = id[1] = id[2] = 0; - for (int x = 0; x < VolumeSize; ++x){ - id[0] = x; - for (int y = 0; y < VolumeSize; ++y){ - id[1] = y; - for (int z = 0; z < VolumeSize; ++z){ - id[2] = z; - areSame = imageInMitk->GetPixelValueByIndex(id) == overwritedImage->GetPixelValueByIndex(id); - if(!areSame) - goto stop; - } - } - } -stop: - MITK_TEST_CONDITION(areSame,"comparing images"); - - - - slice->SetScalarComponentFromDouble(2,3,4,0,0.0); - overwriter->SetInput(overwritedImage); - overwriter->SetInputSlice(slice); - overwriter->Modified(); - overwriter->Update(); - - mitk::Image::Pointer overwr = overwriter->GetOutput(); - - areSame = true; - - int x,y,z; - - for ( x = 0; x < VolumeSize; ++x){ - id[0] = x; - for ( y = 0; y < VolumeSize; ++y){ - id[1] = y; - for ( z = 0; z < VolumeSize; ++z){ - id[2] = z; - MITK_INFO << imageInMitk->GetPixelValueByIndex(id); - MITK_INFO << overwr->GetPixelValueByIndex(id); - areSame = imageInMitk->GetPixelValueByIndex(id) == overwr->GetPixelValueByIndex(id); - if(!areSame) - goto stop2; - } - } - } -stop2: - MITK_INFO << x << " " << y << " " << z; - MITK_TEST_CONDITION(x==2 && y==3 && z==4,"overwrited the right index"); MITK_TEST_END() }