-
-
Notifications
You must be signed in to change notification settings - Fork 665
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ENH: Add
itk::PointSetToImageFilter
unit tests
Add `itk::PointSetToImageFilter` unit tests.
- Loading branch information
1 parent
00a2987
commit 3adda5a
Showing
6 changed files
with
703 additions
and
0 deletions.
There are no files selected for viewing
1 change: 1 addition & 0 deletions
1
Modules/Core/Common/test/Baseline/itkPointSetToImageFilterTest1.png.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 @@ | ||
4676daffcc379ed78b411cebb9966722609e26fb2b7d4e709454d4fcd0e75ed040ec8bac9da98326f4a86cd75aa17fb0531f3a2de9dcac0188adbec190a5bec3 |
1 change: 1 addition & 0 deletions
1
Modules/Core/Common/test/Baseline/itkPointSetToImageFilterTest2.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 @@ | ||
a76fc3e9eac7c8c2cf7e1a77091e8de94712a1843f25eae0cc3629202223e40cd148bcd0457c1f48c03ccead138c7ed4c2d2aaeb29ac8a578ff65c8888149e95 |
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
114 changes: 114 additions & 0 deletions
114
Modules/Core/Common/test/itkPointSetToImageFilterTest1.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,114 @@ | ||
/*========================================================================= | ||
* | ||
* 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 | ||
* | ||
* http://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 "itkPointSetToImageFilter.h" | ||
#include "itkPointSet.h" | ||
#include "itkTestingMacros.h" | ||
|
||
|
||
int | ||
itkPointSetToImageFilterTest1(int argc, char * argv[]) | ||
{ | ||
if (argc != 2) | ||
{ | ||
std::cerr << "Missing parameters." << std::endl; | ||
std::cerr << "Usage: " << itkNameOfTestExecutableMacro(argv); | ||
std::cerr << " outputImageFile" << std::endl; | ||
return EXIT_FAILURE; | ||
} | ||
|
||
constexpr unsigned int PointSetDimension = 2; | ||
constexpr unsigned int ImageDimension = 2; | ||
|
||
using PointSetPointType = float; | ||
using PixelType = unsigned char; | ||
|
||
using PointSetType = itk::PointSet<PointSetPointType, PointSetDimension>; | ||
using BinaryImageType = itk::Image<PixelType, ImageDimension>; | ||
|
||
using PointSetType = itk::PointSet<PointSetPointType, PointSetDimension>; | ||
|
||
using PointType = PointSetType::PointType; | ||
|
||
auto pointSet = PointSetType::New(); | ||
|
||
// Create a point set describing a circle | ||
float radius = 100.0; | ||
unsigned int count = 0; | ||
for (float theta = 0; theta < 2.0 * itk::Math::pi; theta += 0.1) | ||
{ | ||
PointType point; | ||
point[0] = radius * std::cos(theta); | ||
point[1] = radius * std::sin(theta); | ||
|
||
pointSet->SetPoint(count, point); | ||
count++; | ||
} | ||
|
||
using FilterType = itk::PointSetToImageFilter<PointSetType, BinaryImageType>; | ||
auto filter = FilterType::New(); | ||
|
||
ITK_EXERCISE_BASIC_OBJECT_METHODS(filter, PointSetToImageFilter, ImageSource); | ||
|
||
|
||
BinaryImageType::SpacingType::ValueType spacingValue = 1.0; | ||
BinaryImageType::SpacingType spacing; | ||
spacing.Fill(spacingValue); | ||
filter->SetSpacing(spacing); | ||
ITK_TEST_SET_GET_VALUE(spacing, filter->GetSpacing()); | ||
|
||
BinaryImageType::PointType origin{ { -125, -125 } }; | ||
filter->SetOrigin(origin); | ||
ITK_TEST_SET_GET_VALUE(origin, filter->GetOrigin()); | ||
|
||
typename BinaryImageType::DirectionType direction; | ||
direction.SetIdentity(); | ||
filter->SetDirection(direction); | ||
ITK_TEST_SET_GET_VALUE(direction, filter->GetDirection()); | ||
|
||
typename BinaryImageType::ValueType insideValue = itk::NumericTraits<typename BinaryImageType::ValueType>::OneValue(); | ||
filter->SetInsideValue(insideValue); | ||
ITK_TEST_SET_GET_VALUE(insideValue, filter->GetInsideValue()); | ||
|
||
typename BinaryImageType::ValueType outsideValue = | ||
itk::NumericTraits<typename BinaryImageType::ValueType>::ZeroValue(); | ||
filter->SetOutsideValue(outsideValue); | ||
ITK_TEST_SET_GET_VALUE(outsideValue, filter->GetOutsideValue()); | ||
|
||
typename BinaryImageType::SizeType size = { { 250, 250 } }; | ||
filter->SetSize(size); | ||
ITK_TEST_SET_GET_VALUE(size, filter->GetSize()); | ||
|
||
filter->SetInput(pointSet); | ||
ITK_TEST_SET_GET_VALUE(pointSet, filter->GetInput()); | ||
|
||
unsigned int idx = 0; | ||
ITK_TEST_SET_GET_VALUE(pointSet, filter->GetInput(idx)); | ||
|
||
ITK_TRY_EXPECT_NO_EXCEPTION(filter->Update()); | ||
|
||
|
||
BinaryImageType::Pointer binaryImage = filter->GetOutput(); | ||
|
||
itk::WriteImage(binaryImage, argv[1]); | ||
|
||
|
||
std::cout << "Test finished." << std::endl; | ||
return EXIT_SUCCESS; | ||
} |
91 changes: 91 additions & 0 deletions
91
Modules/Core/Common/test/itkPointSetToImageFilterTest2.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,91 @@ | ||
/*========================================================================= | ||
* | ||
* 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 | ||
* | ||
* http://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 "itkPointSetToImageFilter.h" | ||
#include "itkPointSet.h" | ||
#include "itkTestingMacros.h" | ||
|
||
|
||
int | ||
itkPointSetToImageFilterTest2(int argc, char * argv[]) | ||
{ | ||
if (argc != 3) | ||
{ | ||
std::cerr << "Missing parameters." << std::endl; | ||
std::cerr << "Usage: " << itkNameOfTestExecutableMacro(argv); | ||
std::cerr << " pointSetFile outputImageFile" << std::endl; | ||
return EXIT_FAILURE; | ||
} | ||
|
||
constexpr unsigned int PointSetDimension = 3; | ||
constexpr unsigned int ImageDimension = 3; | ||
|
||
using PointSetPointType = float; | ||
using PixelType = unsigned char; | ||
|
||
using PointSetType = itk::PointSet<PointSetPointType, PointSetDimension>; | ||
using BinaryImageType = itk::Image<PixelType, ImageDimension>; | ||
|
||
using PointSetType = itk::PointSet<PointSetPointType, PointSetDimension>; | ||
|
||
auto pointSet = PointSetType::New(); | ||
|
||
using PointType = PointSetType::PointType; | ||
|
||
using PointsContainer = PointSetType::PointsContainer; | ||
auto pointContainer = PointsContainer::New(); | ||
|
||
PointType point; | ||
|
||
// Read the point set | ||
std::ifstream file; | ||
file.open(argv[1]); | ||
if (file.fail()) | ||
{ | ||
std::cerr << "Error opening point set file with name : " << std::endl; | ||
std::cerr << argv[1] << std::endl; | ||
return EXIT_FAILURE; | ||
} | ||
|
||
unsigned int pointId = 0; | ||
file >> point; | ||
while (!file.eof()) | ||
{ | ||
pointContainer->InsertElement(pointId, point); | ||
file >> point; | ||
pointId++; | ||
} | ||
pointSet->SetPoints(pointContainer); | ||
|
||
using FilterType = itk::PointSetToImageFilter<PointSetType, BinaryImageType>; | ||
auto filter = FilterType::New(); | ||
|
||
filter->SetInput(pointSet); | ||
|
||
ITK_TRY_EXPECT_NO_EXCEPTION(filter->Update()); | ||
|
||
|
||
BinaryImageType::Pointer binaryImage = filter->GetOutput(); | ||
|
||
itk::WriteImage(binaryImage, argv[2]); | ||
|
||
|
||
std::cout << "Test finished." << std::endl; | ||
return EXIT_SUCCESS; | ||
} |
Oops, something went wrong.