Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Adding wrapping for TransformGeometryImageFilter
The test was initially generated from the code generation then
modified. The code generation only handles inputs of Image types.
  • Loading branch information
blowekamp committed Nov 23, 2021
1 parent 5ae2785 commit 2f1f240
Show file tree
Hide file tree
Showing 6 changed files with 177 additions and 2 deletions.
28 changes: 28 additions & 0 deletions 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<InputImageType, OutputImageType>",
"inputs" : [
{
"name" : "Image",
"type" : "Image"
},
{
"name" : "Transform",
"type" : "Transform",
"custom_itk_cast" : "const typename FilterType::TransformType *itkTx = dynamic_cast<const typename FilterType::TransformType *>(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
}
Expand Up @@ -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 .. [[" );
Expand Down
@@ -0,0 +1 @@
c6e50d21a32bd8f2aed059f95d92905b59e5a38949c991549d619c4398c6a78be3bc973700912aa372e3a32b03766276800580402b82db832367bf1dd01939d8
2 changes: 2 additions & 0 deletions Testing/Unit/CMakeLists.txt
Expand Up @@ -23,6 +23,7 @@ set ( SimpleITKUnitTestSource
sitkBasicFiltersTests.cxx
sitkLabelStatisticsTest.cxx
sitkTransformToDisplacementFieldFilterTest.cxx
sitkTransformGeometryImageFilterTest.cxx
sitkOperatorTests.cxx
sitkExceptionsTests.cxx
sitkTransformTests.cxx
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion Testing/Unit/sitkImageFilterTestTemplate.cxx.in
Expand Up @@ -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]))
{
Expand Down
144 changes: 144 additions & 0 deletions 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 <SimpleITKTestHarness.h>

#include <sitkTransformGeometryImageFilter.h>
#include <sitkImageFileReader.h>
#include <sitkImageFileWriter.h>
#include <sitkHashImageFilter.h>
#include <sitkCastImageFilter.h>
#include <sitkConditional.h>
#include <sitkVersion.h>

#include <array>


static bool isLabelType( const itk::simple::Image &img)
{
static const std::array<itk::simple::PixelIDValueEnum, 4> 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<std::string> 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

0 comments on commit 2f1f240

Please sign in to comment.