Skip to content

Commit 05cf6d0

Browse files
author
Ramon Emiliani
committed
test: add test for image interface handling negative indices
1 parent 8946707 commit 05cf6d0

File tree

4 files changed

+92
-0
lines changed

4 files changed

+92
-0
lines changed

test/CMakeLists.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ ExternalData_Expand_Arguments(
3030
DATA{Input/sphere.fsa}
3131
DATA{Input/sphere.fsb}
3232
DATA{Input/box.obj}
33+
DATA{Input/negative_idx_base.mha}
34+
DATA{Input/negative_idx_padded.mha}
3335
DATA{Input/octa.off}
3436
DATA{Input/sphere.stl}
3537
DATA{Input/cthead1.iwi.cbor}
@@ -54,6 +56,7 @@ ExternalData_Expand_Arguments(
5456

5557
set(WebAssemblyInterfaceTests
5658
itkWasmImageInterfaceTest.cxx
59+
itkWasmImageInterfaceWithNegativeIndexTest.cxx
5760
itkWasmMeshInterfaceTest.cxx
5861
itkWasmPolyDataInterfaceTest.cxx
5962
itkWasmImageIOTest.cxx
@@ -84,6 +87,15 @@ itk_add_test(NAME itkWasmImageInterfaceTest
8487
${ITK_TEST_OUTPUT_DIR}/itkWasmImageInterfaceTest.mha
8588
)
8689

90+
itk_add_test(NAME itkWasmImageInterfaceWithNegativeIndexTest
91+
COMMAND WebAssemblyInterfaceTestDriver
92+
--compare DATA{Input/negative_idx_padded.mha}
93+
${ITK_TEST_OUTPUT_DIR}/itkWasmImageInterfaceWithNegativeIndexTest.mha
94+
itkWasmImageInterfaceWithNegativeIndexTest
95+
DATA{Input/negative_idx_base.mha}
96+
${ITK_TEST_OUTPUT_DIR}/itkWasmImageInterfaceWithNegativeIndexTest.mha
97+
)
98+
8799
itk_add_test(NAME itkWasmMeshInterfaceTest
88100
COMMAND WebAssemblyInterfaceTestDriver
89101
itkWasmMeshInterfaceTest
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
bafkreiec2npcdz52d6gjmod7f4cfckgqcmizch3dpujxhjpxxqggxlkemy
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
bafkreifzpwttltw372hen6ouewhpqwodxs4zo4kjk7ekyclzcoshfnxq3u
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
/*=========================================================================
2+
*
3+
* Copyright NumFOCUS
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* https://www.apache.org/licenses/LICENSE-2.0.txt
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*
17+
*=========================================================================*/
18+
#include "itkImageToWasmImageFilter.h"
19+
#include "itkWasmImageToImageFilter.h"
20+
21+
#include "itkConstantPadImageFilter.h"
22+
#include "itkImageFileReader.h"
23+
#include "itkImageFileWriter.h"
24+
#include "itkTestingMacros.h"
25+
26+
int
27+
itkWasmImageInterfaceWithNegativeIndexTest(int argc, char * argv[])
28+
{
29+
if (argc < 3)
30+
{
31+
std::cerr << "Missing parameters" << std::endl;
32+
std::cerr << "Usage: " << itkNameOfTestExecutableMacro(argv) << " InputImage OutputImage" << std::endl;
33+
return EXIT_FAILURE;
34+
}
35+
const char * inputImageFile = argv[1];
36+
const char * outputImageFile = argv[2];
37+
38+
constexpr unsigned int Dimension = 3;
39+
using PixelType = unsigned char;
40+
using ImageType = itk::Image<PixelType, Dimension>;
41+
using ImagePointer = ImageType::Pointer;
42+
43+
ImagePointer inputImage = nullptr;
44+
ITK_TRY_EXPECT_NO_EXCEPTION(inputImage = itk::ReadImage<ImageType>(inputImageFile));
45+
std::cout << "inputImage: " << inputImage << std::endl;
46+
47+
ImageType::SizeType lowerExtendRegion;
48+
lowerExtendRegion.Fill(1);
49+
50+
ImageType::SizeType upperExtendRegion;
51+
upperExtendRegion.Fill(1);
52+
53+
using ConstantPadImageFilterType = itk::ConstantPadImageFilter<ImageType,ImageType>;
54+
auto constantPad = ConstantPadImageFilterType::New();
55+
constantPad->SetInput(inputImage);
56+
constantPad->SetPadLowerBound(lowerExtendRegion);
57+
constantPad->SetPadUpperBound(upperExtendRegion);
58+
constantPad->SetConstant(0);
59+
60+
using ImageToWasmImageFilterType = itk::ImageToWasmImageFilter<ImageType>;
61+
auto imageToJSON = ImageToWasmImageFilterType::New();
62+
imageToJSON->SetInput(constantPad->GetOutput());
63+
imageToJSON->Update();
64+
auto imageJSON = imageToJSON->GetOutput();
65+
std::cout << "Image JSON: " << imageJSON->GetJSON() << std::endl;
66+
67+
using WasmImageToImageFilterType = itk::WasmImageToImageFilter<ImageType>;
68+
auto jsonToImage = WasmImageToImageFilterType::New();
69+
jsonToImage->SetInput(imageToJSON->GetOutput());
70+
jsonToImage->Update();
71+
ImageType::Pointer convertedImage = jsonToImage->GetOutput();
72+
73+
std::cout << "convertedImage: " << convertedImage << std::endl;
74+
75+
ITK_TRY_EXPECT_NO_EXCEPTION(itk::WriteImage(convertedImage, outputImageFile));
76+
77+
return EXIT_SUCCESS;
78+
}

0 commit comments

Comments
 (0)