From 2f1f240f16a93e64e4c0bc4620ee688b7a7318d7 Mon Sep 17 00:00:00 2001 From: Bradley Lowekamp Date: Fri, 22 Oct 2021 14:46:24 +0000 Subject: [PATCH] Adding wrapping for TransformGeometryImageFilter The test was initially generated from the code generation then modified. The code generation only handles inputs of Image types. --- .../json/TransformGeometryImageFilter.json | 28 ++++ .../Components/ExecuteNoParameters.cxx.in | 2 +- ...rmGeometryImageFilter_defaults.nrrd.sha512 | 1 + Testing/Unit/CMakeLists.txt | 2 + .../Unit/sitkImageFilterTestTemplate.cxx.in | 2 +- .../sitkTransformGeometryImageFilterTest.cxx | 144 ++++++++++++++++++ 6 files changed, 177 insertions(+), 2 deletions(-) create mode 100644 Code/BasicFilters/json/TransformGeometryImageFilter.json create mode 100644 Testing/Data/Baseline/BasicFilters_TransformGeometryImageFilter_defaults.nrrd.sha512 create mode 100644 Testing/Unit/sitkTransformGeometryImageFilterTest.cxx diff --git a/Code/BasicFilters/json/TransformGeometryImageFilter.json b/Code/BasicFilters/json/TransformGeometryImageFilter.json new file mode 100644 index 0000000000..152184f1c3 --- /dev/null +++ b/Code/BasicFilters/json/TransformGeometryImageFilter.json @@ -0,0 +1,28 @@ +{ + "name" : "TransformGeometryImageFilter", + "template_code_filename" : "ImageFilter", + "number_of_inputs" : 0, + "doc" : "", + "pixel_types" : "NonLabelPixelIDTypeList", + "filter_type" : "itk::TransformGeometryImageFilter", + "inputs" : [ + { + "name" : "Image", + "type" : "Image" + }, + { + "name" : "Transform", + "type" : "Transform", + "custom_itk_cast" : "const typename FilterType::TransformType *itkTx = dynamic_cast(inTransform->GetITKBase() );\n if ( !itkTx )\n {\n sitkExceptionMacro( \"Unexpected error converting transform! Possible miss matching dimensions!\" );\n }\n else { filter->SetTransform( itkTx ); }", + "no_size_check" : 0 + } + ], + "members" : [], + "custom_methods" : [], + "tests" : [], + "briefdescription" : "", + "detaileddescription" : "", + "itk_module" : "ITKTransform", + "itk_group" : "Transform", + "in_place" : true +} diff --git a/ExpandTemplateGenerator/Components/ExecuteNoParameters.cxx.in b/ExpandTemplateGenerator/Components/ExecuteNoParameters.cxx.in index b72f3be6fa..bdef272f9a 100644 --- a/ExpandTemplateGenerator/Components/ExecuteNoParameters.cxx.in +++ b/ExpandTemplateGenerator/Components/ExecuteNoParameters.cxx.in @@ -20,7 +20,7 @@ for inum=2,number_of_inputs do end if inputs then for inum=2,#inputs do - if not inputs[inum].optional or not no_optional then + if inputs[inum].type == "Image" and (not inputs[inum].optional or not no_optional) then local currentInputName = inputs[inum].name:sub(1,1):lower()..inputs[inum].name:sub(2,-1) OUT=OUT..[[ CheckImageMatchingDimension( ]] .. inputName .. [[, ]] .. currentInputName .. [[, "]] .. currentInputName .. [[" ); diff --git a/Testing/Data/Baseline/BasicFilters_TransformGeometryImageFilter_defaults.nrrd.sha512 b/Testing/Data/Baseline/BasicFilters_TransformGeometryImageFilter_defaults.nrrd.sha512 new file mode 100644 index 0000000000..21c9769fb5 --- /dev/null +++ b/Testing/Data/Baseline/BasicFilters_TransformGeometryImageFilter_defaults.nrrd.sha512 @@ -0,0 +1 @@ +c6e50d21a32bd8f2aed059f95d92905b59e5a38949c991549d619c4398c6a78be3bc973700912aa372e3a32b03766276800580402b82db832367bf1dd01939d8 diff --git a/Testing/Unit/CMakeLists.txt b/Testing/Unit/CMakeLists.txt index bf85f81b62..636f7415d1 100644 --- a/Testing/Unit/CMakeLists.txt +++ b/Testing/Unit/CMakeLists.txt @@ -23,6 +23,7 @@ set ( SimpleITKUnitTestSource sitkBasicFiltersTests.cxx sitkLabelStatisticsTest.cxx sitkTransformToDisplacementFieldFilterTest.cxx + sitkTransformGeometryImageFilterTest.cxx sitkOperatorTests.cxx sitkExceptionsTests.cxx sitkTransformTests.cxx @@ -287,6 +288,7 @@ ExternalData_Expand_Arguments( SimpleITKData DATA{${SimpleITK_DATA_ROOT}/Input/xforms/versor_i_3.txt} DATA{${SimpleITK_DATA_ROOT}/Baseline/BasicFilters_TransformToDisplacementFieldFilter_defaults.nrrd} DATA{${SimpleITK_DATA_ROOT}/Baseline/BasicFilters_TransformToDisplacementFieldFilter_32.nrrd} + DATA{${SimpleITK_DATA_ROOT}/Baseline/BasicFilters_TransformGeometryImageFilter_defaults.nrrd} ) ExternalData_Expand_Arguments( SimpleITKData diff --git a/Testing/Unit/sitkImageFilterTestTemplate.cxx.in b/Testing/Unit/sitkImageFilterTestTemplate.cxx.in index 0d56e94878..2b12d45816 100644 --- a/Testing/Unit/sitkImageFilterTestTemplate.cxx.in +++ b/Testing/Unit/sitkImageFilterTestTemplate.cxx.in @@ -275,7 +275,7 @@ end) // This will fail if the filter is being run in-place EXPECT_EQ ( inputSHA1hash, itk::simple::Hash( inputs[0] ) ) << "Input was modified by filter."; - // Check that the input buffer is different that the output + // Check that the input buffer is different than the output // buffer, this does not check complex or label map pixel types. if(!isLabelType(output) && !isLabelType(inputs[0])) { diff --git a/Testing/Unit/sitkTransformGeometryImageFilterTest.cxx b/Testing/Unit/sitkTransformGeometryImageFilterTest.cxx new file mode 100644 index 0000000000..a364994dcd --- /dev/null +++ b/Testing/Unit/sitkTransformGeometryImageFilterTest.cxx @@ -0,0 +1,144 @@ +/*========================================================================= +* +* 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. +* +*=========================================================================*/ +/* + * WARNING: DO NOT EDIT THIS FILE! + * THIS FILE IS AUTOMATICALLY GENERATED BY THE SIMPLEITK BUILD PROCESS. + * Please look at sitkImageFilterTestTemplate.cxx.in to make changes. + */ + +#include + +#include +#include +#include +#include +#include +#include +#include + +#include + + +static bool isLabelType( const itk::simple::Image &img) +{ + static const std::array labelIDs{{ + itk::simple::sitkLabelUInt8, + itk::simple::sitkLabelUInt16, + itk::simple::sitkLabelUInt32, + itk::simple::sitkLabelUInt64}}; + + return std::find(labelIDs.begin(), labelIDs.end(), img.GetPixelID()) != labelIDs.end(); +} + +TEST(BasicFilters,TransformGeometryImageFilter) { + itk::simple::ImageFileReader reader; + itk::simple::TransformGeometryImageFilter filter; + itk::simple::Image inputA( 0, 0, itk::simple::sitkUInt8 ); + itk::simple::Image inputB( 0, 0, itk::simple::sitkUInt8 ); + itk::simple::Image output( 0, 0, itk::simple::sitkUInt8 ); + std::string inputSHA1hash; + + + + + EXPECT_NE ( filter.ToString(), "" ) << "empty ToString method!"; + EXPECT_EQ ( filter.GetName(), "TransformGeometryImageFilter" ) << "checking GetName method!"; + + // Test sets / gets + + + + // This block is to verify that the input images for named inputs are + // check if the sizes match for computation. + itk::simple::Image smallImage( 1,1,1,itk::simple::sitkUInt8 ); + itk::simple::Image largeImage( 10,10,10,itk::simple::sitkUInt8 ); + +} + +TEST(BasicFilters,TransformGeometryImageFilter_defaults) +{ // BEGIN FOR EACH TEST + /* TAG: defaults DESCRIPTION: run with some defaults */ + + itk::simple::ImageFileReader reader; + itk::simple::TransformGeometryImageFilter filter; + itk::simple::Image output; + itk::simple::HashImageFilter hasher; + std::string inputSHA1hash; + + std::vector inputFileNames; + + inputFileNames.push_back("Input/RA-Float.nrrd"); + inputFileNames.push_back("Input/xforms/affine_i_3.txt"); + + itk::simple::Image input1 = + reader.SetFileName(dataFinder.GetFile(inputFileNames[0])).Execute(); + itk::simple::Transform input2 = + itk::simple::ReadTransform(dataFinder.GetFile(inputFileNames[1])); + + inputSHA1hash = itk::simple::Hash(input1); + + // Do we get the same image back, if we use the functional interface? + itk::simple::Image fromFunctional(0, 0, itk::simple::sitkUInt8); + itk::simple::Image fromProcedural(0, 0, itk::simple::sitkUInt8); + EXPECT_NO_THROW(fromProcedural = filter.Execute(input1, input2)) + << "Procedural interface to TransformGeometryImageFilter"; + EXPECT_NO_THROW(fromFunctional = + itk::simple::TransformGeometry(input1, input2)) + << "Functional interface to TransformGeometryImageFilter"; + hasher.SetHashFunction(itk::simple::HashImageFilter::MD5); + EXPECT_EQ(hasher.Execute(fromProcedural), hasher.Execute(fromFunctional)) + << "procedural and functional are not the same!"; + + filter.DebugOn(); + ASSERT_NO_THROW(output = filter.Execute(input1, input2)); + + // Check that the input is not modified + // This will fail if the filter is being run in-place + EXPECT_EQ(inputSHA1hash, itk::simple::Hash(input1)) + << "Input was modified by filter."; + + // Check that the input buffer is different than the output + // buffer, this does not check complex or label map pixel types. + if (!isLabelType(output) && !isLabelType(input1)) { + EXPECT_NE(output.GetBufferAsVoid(), input1.GetBufferAsVoid()) + << "Input buffer was copyied to output!"; + } + + itk::simple::Image inPlaceOutput; + itk::simple::Image temp = input1; + temp.MakeUnique(); + ASSERT_NO_THROW(inPlaceOutput = filter.Execute(std::move(temp), input2)); + + ASSERT_NE(nullptr, inPlaceOutput.GetITKBase()); + EXPECT_EQ(itk::simple::Hash(output), itk::simple::Hash(inPlaceOutput)) + << "InPlace value does not match!"; + + ASSERT_NE(nullptr, input1.GetITKBase()); + if (!isLabelType(input1)) { + EXPECT_NE(nullptr, input1.GetBufferAsVoid()) + << "An input is missing it's buffer!"; + + if (!isLabelType(inPlaceOutput)) { + EXPECT_NE(inPlaceOutput.GetBufferAsVoid(), input1.GetBufferAsVoid()) + << "An input and output buffer matches."; + } + } + + IMAGECOMPAREWITHTOLERANCE(output, "", 0.001); + +} // END FOR EACH TEST