stnava/ANTs — pull request #12 by aghayoor (2013-03-14 04:12:35+00:00)
Title: ENH: Add tests for CompositeTransformUtil tool

Recently we found out that "CompositeTransformUtil" returns segmentation fault when it is used by "--assemble" flag.

Before fixing this bug, I added two tests to the ANTS, so we can track the wrong changes on this tool.

The first test just makes sure that CompositeTransformUtil is run without any failure. This test is called "CompositeTransformUtilTest".

The second test compares the output composite transform of the "CompositeTransformUtil --assemble" with a baseline composite transform to make sure that CompositeTransformUtil generates valid results. The inputs of this test are 3 separate transforms that are the contents of the baseline composite transform. This test is called "CompositeTransformUtil_ComparisonTesting".

To do the comparison, a new program is added to the ANTS called "compareTwoCompositeTransforms". It is added to "Example/" directory.

These tests are failing now based on the current version of ANTs on the master branch.

I debugged the program to find the reason of the segfault. Here are my results:

As our input transforms for the assembling are 3 dimensional transforms, they should be processed by "Assemble<3>(CompositeName, transformNames, FirstTransform)" function in "CompositeTransformUtil.cxx" file. However in line 153, the "itk::ants::ReadTransform<2>" does not return a Null transform, so line 156 is run wrongly that cause a segmentation fault in line 138.

Why does "itk::ants::ReadTransform<2>" not return Null for an 3D input transform?

It happens because the following lines are added to "itkantsReadWriteTransform.h" file:

101: /** below is a bad thing but it's the only temporary fix i could find for ANTsR on unix --- B.A. */
102: if ( transform.IsNull() ) transform = static_cast( listOfTransforms->front().GetPointer() );

If we comment out the line 102, the segfault bug will be fixed, and the first test (CompositeTransformUtilTest) and all other ants' tests will be passed.

However, I should mention another point here. Even if we fix the segfault bug, the second test (CompositeTransformUtil_ComparisonTesting) keeps failing. It returns:
"The input composite transforms are not equal!".

It means if we disassemble a baseline composite transform and assemble again including transform files again, the CompositeTransformUtil tool cannot generate an output exactly the same as the baseline file.