Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ENH: Increase coverage for
itk::RandomImageSource
Increase coverage for `itk::RandomImageSource`: - Exercise basic object methods using the `ITK_EXERCISE_BASIC_OBJECT_METHODS` macro. - Test the Set/Get methods using the `ITK_TEST_SET_GET_VALUE` macro. Add the accompanying content data link file.
- Loading branch information
1 parent
056fee3
commit 84fc5be
Showing
4 changed files
with
173 additions
and
0 deletions.
There are no files selected for viewing
1 change: 1 addition & 0 deletions
1
Modules/Core/TestKernel/test/Baseline/itkRandomImageSourceValuesTest.mha.sha512
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
350ff29c22d89ca426c8791b56272b2449f965fb920117406d9c01874bc365f4ddaee3445b529cd831d7c59ce209d060c046bce4cf18dd04e91823b4fca45578 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
104 changes: 104 additions & 0 deletions
104
Modules/Core/TestKernel/test/itkRandomImageSourceAttributesTest.cxx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
/*========================================================================= | ||
* | ||
* Copyright NumFOCUS | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0.txt | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
*=========================================================================*/ | ||
|
||
#include "itkRandomImageSource.h" | ||
#include "itkTestingMacros.h" | ||
|
||
|
||
template <typename TImage> | ||
int | ||
itkRandomImageSourceAttributesTestHelper(const typename TImage::SizeType size, | ||
const typename TImage::SpacingType spacing, | ||
const typename TImage::PointType origin, | ||
const typename TImage::DirectionType direction, | ||
const typename TImage::ValueType min, | ||
const typename TImage::ValueType max) | ||
{ | ||
|
||
using ImageSourceType = itk::RandomImageSource<TImage>; | ||
auto randomImageSource = ImageSourceType::New(); | ||
|
||
ITK_EXERCISE_BASIC_OBJECT_METHODS(randomImageSource, RandomImageSource, ImageSource); | ||
|
||
|
||
randomImageSource->SetSize(size); | ||
ITK_TEST_SET_GET_VALUE(*size.GetSize(), *randomImageSource->GetSize()); | ||
|
||
randomImageSource->SetSpacing(spacing); | ||
ITK_TEST_SET_GET_VALUE(spacing, randomImageSource->GetSpacing()); | ||
|
||
randomImageSource->SetOrigin(origin); | ||
ITK_TEST_SET_GET_VALUE(origin, randomImageSource->GetOrigin()); | ||
|
||
randomImageSource->SetDirection(direction); | ||
ITK_TEST_SET_GET_VALUE(direction, randomImageSource->GetDirection()); | ||
|
||
randomImageSource->SetMin(min); | ||
ITK_TEST_SET_GET_VALUE(min, randomImageSource->GetMin()); | ||
|
||
randomImageSource->SetMax(max); | ||
ITK_TEST_SET_GET_VALUE(max, randomImageSource->GetMax()); | ||
|
||
|
||
return EXIT_SUCCESS; | ||
} | ||
|
||
|
||
int | ||
itkRandomImageSourceAttributesTest(int, char *[]) | ||
{ | ||
|
||
constexpr unsigned int Dimension2D = 2; | ||
constexpr unsigned int Dimension3D = 3; | ||
|
||
using PixelType = float; | ||
|
||
int testStatus = EXIT_SUCCESS; | ||
|
||
{ | ||
using ImageType2D = itk::Image<PixelType, Dimension2D>; | ||
|
||
const ImageType2D::SizeType size{ 25, 25 }; | ||
const ImageType2D::SpacingType spacing{ { 0.7, 2.1 } }; | ||
const ImageType2D::PointType origin{ { -1.7, 5.2 } }; | ||
const double d[4] = { 0, 1.0, 1.0, 0 }; | ||
const ImageType2D::DirectionType direction = ImageType2D::DirectionType::InternalMatrixType(d); | ||
const ImageType2D::ValueType min{ 0.0 }; | ||
const ImageType2D::ValueType max{ 1000.0 }; | ||
|
||
testStatus = itkRandomImageSourceAttributesTestHelper<ImageType2D>(size, spacing, origin, direction, min, max); | ||
} | ||
|
||
{ | ||
using ImageType3D = itk::Image<PixelType, Dimension3D>; | ||
|
||
const ImageType3D::SizeType size{ 14, 17, 36 }; | ||
const ImageType3D::SpacingType spacing{ { 0.7, 0.4, 1.2 } }; | ||
const ImageType3D::PointType origin{ { -1.7, 5.2, 3.4 } }; | ||
const double d[9] = { 0, 1.0, 0, 1.0, 0, 0, 0, 1.0, 0 }; | ||
const ImageType3D::DirectionType direction = ImageType3D::DirectionType::InternalMatrixType(d); | ||
const ImageType3D::ValueType min{ 0.0 }; | ||
const ImageType3D::ValueType max{ 10.0 }; | ||
|
||
testStatus = itkRandomImageSourceAttributesTestHelper<ImageType3D>(size, spacing, origin, direction, min, max); | ||
} | ||
|
||
|
||
std::cout << "Test finished." << std::endl; | ||
return testStatus; | ||
} |
58 changes: 58 additions & 0 deletions
58
Modules/Core/TestKernel/test/itkRandomImageSourceValuesTest.cxx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/*========================================================================= | ||
* | ||
* Copyright NumFOCUS | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0.txt | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
*=========================================================================*/ | ||
|
||
#include "itkImageFileWriter.h" | ||
#include "itkRandomImageSource.h" | ||
#include "itkTestingMacros.h" | ||
|
||
|
||
int | ||
itkRandomImageSourceValuesTest(int argc, char * argv[]) | ||
{ | ||
if (argc != 2) | ||
{ | ||
std::cerr << "Missing parameters." << std::endl; | ||
std::cerr << "Usage: " << itkNameOfTestExecutableMacro(argv) << " outputFileName" << std::endl; | ||
return EXIT_FAILURE; | ||
} | ||
|
||
constexpr unsigned int Dimension = 2; | ||
|
||
using PixelType = float; | ||
using ImageType = itk::Image<PixelType, Dimension>; | ||
|
||
using ImageSourceType = itk::RandomImageSource<ImageType>; | ||
auto randomImageSource = ImageSourceType::New(); | ||
|
||
const ImageType::SizeType size{ { 10, 10 } }; | ||
randomImageSource->SetSize(size); | ||
|
||
randomImageSource->SetMin(0.0); | ||
randomImageSource->SetMax(20.0); | ||
|
||
randomImageSource->SetNumberOfWorkUnits(1); | ||
|
||
ITK_TRY_EXPECT_NO_EXCEPTION(randomImageSource->Update()); | ||
|
||
|
||
itk::WriteImage(randomImageSource->GetOutput(), argv[1]); | ||
|
||
|
||
std::cout << "Test finished." << std::endl; | ||
return EXIT_SUCCESS; | ||
} |