1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123
|
/*=========================================================================
*
* 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
*
* https://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.
*
*=========================================================================*/
#include "itkPowImageFilter.h"
#include "itkTestingMacros.h"
int
itkPowImageFilterTest(int, char *[])
{
using ImageType = itk::Image<float, 1>;
using myImageType1 = itk::Image<short, 2>;
using myImageType2 = itk::Image<int, 3>;
using myImageType3 = itk::Image<float, 3>;
using FilterType = itk::PowImageFilter<ImageType>;
// The following is to ensure that the filter can be instantiated
// with these types without warning
itk::PowImageFilter<myImageType1>::New();
itk::PowImageFilter<myImageType2>::New();
itk::PowImageFilter<myImageType3>::New();
itk::PowImageFilter<myImageType2, myImageType3>::New();
using SizeType = itk::Size<1>;
using IndexType = itk::Index<1>;
auto inputImageA = ImageType::New();
auto inputImageB = ImageType::New();
SizeType size;
size[0] = 2;
ImageType::RegionType region(size);
// Initialize Image A
inputImageA->SetRegions(region);
inputImageA->Allocate();
// Initialize Image B
inputImageB->SetRegions(region);
inputImageB->Allocate();
// set some initial pixel values
IndexType idx;
for (unsigned int i = 0; i < size[0]; ++i)
{
idx[0] = i;
inputImageA->SetPixel(idx, i + 1);
inputImageB->SetPixel(idx, 1.0);
}
// Create a PowFilter
auto filter = FilterType::New();
ITK_EXERCISE_BASIC_OBJECT_METHODS(filter, PowImageFilter, BinaryGeneratorImageFilter);
// Check == and != operators
// FilterType::FunctorType func2;
// Connect the input images
filter->SetInput1(inputImageA);
filter->SetInput2(inputImageB);
// Get the Smart Pointer to the Filter Output
ImageType::Pointer outputImage = filter->GetOutput();
// Execute the filter
filter->Update();
IndexType idx0;
idx0[0] = 0;
IndexType idx1;
idx1[0] = 1;
// Values should be 1.0^1.0 and 2.0^1.0
ITK_TEST_EXPECT_EQUAL(outputImage->GetPixel(idx0), 1.0);
ITK_TEST_EXPECT_EQUAL(outputImage->GetPixel(idx1), 2.0);
filter->SetInput1(inputImageA);
filter->SetConstant2(2.0);
filter->Update();
// Values should be 1.0^2.0 and 2.0^2.0
ITK_TEST_EXPECT_EQUAL(outputImage->GetPixel(idx0), 1.0);
ITK_TEST_EXPECT_EQUAL(outputImage->GetPixel(idx1), 4.0);
filter->SetConstant1(2.0);
filter->SetInput2(inputImageA);
filter->Update();
// Values should be 2.0^1.0 and 2.0^2.0
ITK_TEST_EXPECT_EQUAL(outputImage->GetPixel(idx0), 2.0);
ITK_TEST_EXPECT_EQUAL(outputImage->GetPixel(idx1), 4.0);
{
using complexFloatFilterType =
itk::PowImageFilter<itk::Image<float>, itk::Image<std::complex<float>>, itk::Image<std::complex<float>>>;
auto tFilter = complexFloatFilterType::New();
ITK_TEST_EXPECT_TRUE(!tFilter.IsNull());
}
// All objects should be automatically destroyed at this point
return EXIT_SUCCESS;
}
|