Skip to content

Commit

Permalink
Merge pull request #1619 from ANTsX/average_affine_doc
Browse files Browse the repository at this point in the history
ENH: Clarify usage and catch missing ImageDimension
  • Loading branch information
cookpa authored Nov 1, 2023
2 parents 9516f51 + 327bf12 commit fe3a0e3
Showing 1 changed file with 25 additions and 7 deletions.
32 changes: 25 additions & 7 deletions Examples/AverageAffineTransform.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -274,26 +274,30 @@ AverageAffineTransform(std::vector<std::string> args, std::ostream * /*out_strea
{
std::cerr
<< "AverageAffineTransform ImageDimension output_affine_transform [-R reference_affine_transform] "
<< "{[-i] affine_transform_txt [weight(=1)] ]}" << std::endl
<< "{[-i] affine_transform [weight(=1)] ]}" << std::endl
<< std::endl
<< " Usage: Compute weighted average of input affine transforms. " << std::endl
<< "For 2D and 3D transform, the affine transform is first decomposed into "
<< std::endl
<< " Usage: Compute weighted average of input affine transforms, either in text (.txt) or binary (.mat) format. "
<< std::endl
<< std::endl
<< "For 2D and 3D transforms, the affine transform is first decomposed into "
"scale x shearing x rotation. Then these parameters are averaged, using the weights if they provided. "
"For 3D transform, the rotation component is the quaternion. After averaging, the quaternion will also "
"be normalized to have unit norm. For 2D transform, the rotation component is the rotation angle. "
"The weight for each transform is a non-negative number. The sum of all weights will be normalized to 1 "
"before averaging. The default value for each weight is 1.0. "
<< std::endl
<< std::endl
<< "All affine transforms is a \"centerd\" transform, following ITK convention. A reference_affine_transform"
<< "All affine transforms are \"centered\" transforms, following ITK convention. A reference_affine_transform"
" defines the center for the output transform. The first provided transform is the default reference "
"transform"
<< std::endl
<< "Output affine transform is a MatrixOffsetBaseTransform." << std::endl
<< " -i option takes the inverse of the affine mapping." << std::endl
<< " For example: " << std::endl
<< " 2 output_affine.txt -R A.txt A1.txt 1.0 -i A2.txt 2.0 A3.txt A4.txt 6.0 A5.txt" << std::endl
<< "This computes: (1*A1 + 2*(A2)^-1 + A3 + A4*6 + A5 ) / (1+2+1+6+5)" << std::endl;
<< " AverageAffineTransform 2 output_affine.txt -R A.txt A1.txt 1.0 -i A2.txt 2.0 A3.txt A4.txt 6.0 A5.txt"
<< std::endl
<< "This computes: (1*A1 + 2*(A2)^{-1} + A3 + A4*6 + A5 ) / (1+2+1+6+5)" << std::endl;
return EXIT_SUCCESS;
}

Expand All @@ -302,7 +306,16 @@ AverageAffineTransform(std::vector<std::string> args, std::ostream * /*out_strea
char * output_transform_filename = nullptr;
char * reference_transform_filename = nullptr;

int kImageDim = std::stoi(argv[1]);
int kImageDim;
try
{
kImageDim = std::stoi(argv[1]);
}
catch (const std::invalid_argument & e)
{
std::cerr << "Invalid image dimension: " << argv[1] << std::endl;
return EXIT_FAILURE;
}

const bool is_parsing_ok = AverageAffineTransform_ParseInput(
argc - 2, argv + 2, output_transform_filename, reference_transform_filename, opt_queue);
Expand Down Expand Up @@ -335,6 +348,11 @@ AverageAffineTransform(std::vector<std::string> args, std::ostream * /*out_strea
AverageAffineTransform<3>(output_transform_filename, reference_transform_filename, opt_queue);
}
break;
default:
{
std::cerr << "Unsupported image dimension " << kImageDim << std::endl;
return EXIT_FAILURE;
}
}
}

Expand Down

0 comments on commit fe3a0e3

Please sign in to comment.