Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

COMP: Add coverage IsCongruentImageGeometry IsSameImageGeometryAs #4592

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions Modules/Core/Common/include/itkImageBase.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -347,14 +347,13 @@ template <unsigned int VImageDimension>
bool
ImageBase<VImageDimension>::RequestedRegionIsOutsideOfTheBufferedRegion()
{
unsigned int i;
const IndexType & requestedRegionIndex = this->GetRequestedRegion().GetIndex();
const IndexType & bufferedRegionIndex = this->GetBufferedRegion().GetIndex();

const SizeType & requestedRegionSize = this->GetRequestedRegion().GetSize();
const SizeType & bufferedRegionSize = this->GetBufferedRegion().GetSize();

for (i = 0; i < VImageDimension; ++i)
for (unsigned int i = 0; i < VImageDimension; ++i)
{
if ((requestedRegionIndex[i] < bufferedRegionIndex[i]) ||
((requestedRegionIndex[i] + static_cast<OffsetValueType>(requestedRegionSize[i])) >
Expand All @@ -372,8 +371,7 @@ template <unsigned int VImageDimension>
bool
ImageBase<VImageDimension>::VerifyRequestedRegion()
{
bool retval = true;
unsigned int i;
bool retval = true;

// Is the requested region within the LargestPossibleRegion?
// Note that the test is indeed against the largest possible region
Expand All @@ -384,7 +382,7 @@ ImageBase<VImageDimension>::VerifyRequestedRegion()
const SizeType & requestedRegionSize = this->GetRequestedRegion().GetSize();
const SizeType & largestPossibleRegionSize = this->GetLargestPossibleRegion().GetSize();

for (i = 0; i < VImageDimension; ++i)
for (unsigned int i = 0; i < VImageDimension; ++i)
{
if ((requestedRegionIndex[i] < largestPossibleRegionIndex[i]) ||
((requestedRegionIndex[i] + static_cast<OffsetValueType>(requestedRegionSize[i])) >
Expand Down
14 changes: 12 additions & 2 deletions Modules/Core/Common/test/itkImageTest.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,7 @@ itkImageTest(int, char *[])
{

using Image = itk::Image<float, 2>;
auto image = Image::New();
Image::ConstPointer myconstptr = image;
auto image = Image::New();
image->DebugOn();
const char * const knownStringName = "My First Image For Testing.";
image->SetObjectName(knownStringName);
Expand Down Expand Up @@ -234,5 +233,16 @@ itkImageTest(int, char *[])
return EXIT_FAILURE;
}

// Test that a const pointer can be instantiated from a non-const pointer
Image::ConstPointer myconstptr = image;
if (!image->IsCongruentImageGeometry(myconstptr, 0.0, 0.0))
{
std::cerr << "Image compare to self fails IsCongruentImageGeometry" << std::endl;
}
if (!image->IsSameImageGeometryAs(myconstptr, 0.0, 0.0))
{
std::cerr << "Image compare to self fails IsSameImageGeometryAs" << std::endl;
}

return (EXIT_SUCCESS);
Comment on lines +236 to 247
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technically, your test does not fail when IsCongruentImageGeometry returns false! It reaches return (EXIT_SUCCESS) anyway.

Please 🙏 consider using GoogleTest for tests like this. With GTest, it would just be:

EXPECT_TRUE(image->IsSameImageGeometryAs(myconstptr, 0.0, 0.0));

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just added these methods for SimpleITK and took full advantage of things for testing:
https://github.com/SimpleITK/SimpleITK/pull/2097/files#diff-b59e3fb36168b499154d941782889660f04ab0c66ed5a31f4a994ca88764b17d

@hjmjohnson I'llI see what I can do in the itkImageGTest.cxx file.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ITK_TEST_EXPECT_TRUE can do the job.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jhlegarreta I agree, if you want to keep using the old ITK test framework (instead of GoogleTest), you can do something like:

ITK_TEST_EXPECT_TRUE(image->IsSameImageGeometryAs(myconstptr, 0.0, 0.0));

FYI, there's a small difference between ITK_TEST_EXPECT_TRUE and GTest EXPECT_TRUE: ITK_TEST_EXPECT_TRUE will exit the test immediately if it fails, whereas with a GTest EXPECT_TRUE failure, the unit test will not exit immediately. (Even though it will be reported as a test failure, by GTest.)

}