From 37024bf6e0331b22269a3d32de4c6a59c8185010 Mon Sep 17 00:00:00 2001 From: Matt McCormick Date: Tue, 14 Nov 2017 18:15:21 -0500 Subject: [PATCH 01/46] ENH: Initial commit Output of ITKModuleTemplate --- .../Filtering/PolarTransform/CMakeLists.txt | 6 + Modules/Filtering/PolarTransform/LICENSE | 202 ++++++++++++++++++ ...itkMinimalStandardRandomVariateGenerator.h | 94 ++++++++ .../itkNormalDistributionImageSource.h | 92 ++++++++ .../itkNormalDistributionImageSource.hxx | 79 +++++++ .../Filtering/PolarTransform/itk-module.cmake | 27 +++ ...stributionImageSourceTestOutput.mha.sha512 | 1 + .../PolarTransform/test/CMakeLists.txt | 28 +++ ...imalStandardRandomVariateGeneratorTest.cxx | 37 ++++ .../itkNormalDistributionImageSourceTest.cxx | 67 ++++++ .../PolarTransform/wrapping/CMakeLists.txt | 3 + ...MinimalStandardRandomVariateGenerator.wrap | 1 + .../itkNormalDistributionImageSource.wrap | 7 + 13 files changed, 644 insertions(+) create mode 100644 Modules/Filtering/PolarTransform/CMakeLists.txt create mode 100644 Modules/Filtering/PolarTransform/LICENSE create mode 100644 Modules/Filtering/PolarTransform/include/itkMinimalStandardRandomVariateGenerator.h create mode 100644 Modules/Filtering/PolarTransform/include/itkNormalDistributionImageSource.h create mode 100644 Modules/Filtering/PolarTransform/include/itkNormalDistributionImageSource.hxx create mode 100644 Modules/Filtering/PolarTransform/itk-module.cmake create mode 100644 Modules/Filtering/PolarTransform/test/Baseline/itkNormalDistributionImageSourceTestOutput.mha.sha512 create mode 100644 Modules/Filtering/PolarTransform/test/CMakeLists.txt create mode 100644 Modules/Filtering/PolarTransform/test/itkMinimalStandardRandomVariateGeneratorTest.cxx create mode 100644 Modules/Filtering/PolarTransform/test/itkNormalDistributionImageSourceTest.cxx create mode 100644 Modules/Filtering/PolarTransform/wrapping/CMakeLists.txt create mode 100644 Modules/Filtering/PolarTransform/wrapping/itkMinimalStandardRandomVariateGenerator.wrap create mode 100644 Modules/Filtering/PolarTransform/wrapping/itkNormalDistributionImageSource.wrap diff --git a/Modules/Filtering/PolarTransform/CMakeLists.txt b/Modules/Filtering/PolarTransform/CMakeLists.txt new file mode 100644 index 000000000000..a536b2ae233c --- /dev/null +++ b/Modules/Filtering/PolarTransform/CMakeLists.txt @@ -0,0 +1,6 @@ +cmake_minimum_required(VERSION 2.8.12) +project(PolarTransform) + +set(PolarTransform_LIBRARIES PolarTransform) + +itk_module_impl() diff --git a/Modules/Filtering/PolarTransform/LICENSE b/Modules/Filtering/PolarTransform/LICENSE new file mode 100644 index 000000000000..d64569567334 --- /dev/null +++ b/Modules/Filtering/PolarTransform/LICENSE @@ -0,0 +1,202 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + 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 + + http://www.apache.org/licenses/LICENSE-2.0 + + 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. diff --git a/Modules/Filtering/PolarTransform/include/itkMinimalStandardRandomVariateGenerator.h b/Modules/Filtering/PolarTransform/include/itkMinimalStandardRandomVariateGenerator.h new file mode 100644 index 000000000000..54a49f462456 --- /dev/null +++ b/Modules/Filtering/PolarTransform/include/itkMinimalStandardRandomVariateGenerator.h @@ -0,0 +1,94 @@ +/*========================================================================= + * + * Copyright Insight Software Consortium + * + * 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 + * + * http://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. + * + *=========================================================================*/ +#ifndef itkMinimalStandardRandomVariateGenerator_h +#define itkMinimalStandardRandomVariateGenerator_h + +#include "itkIntTypes.h" +#include "itkObjectFactory.h" +#include "itkRandomVariateGeneratorBase.h" +#include "PolarTransformExport.h" +#include "itkNormalVariateGenerator.h" + +namespace itk +{ +namespace Statistics +{ +/** \class MinimalStandardRandomVariateGenerator + * \brief Linear congruential random random variate generator. + * + * This is a pseudo-random number generator for unsigned integers following + * + * \f[ + * X_{n+1} = (a X_n + c) \mod m + * \f] + * + * where \f$a\f$ is the Multiplier \f$c\f$ is the Increment and \f$m\f$ is + * the Modulus. + * + * http://en.wikipedia.com/wiki/Linear_congruential_generator + * + * The random numbers generated have a period \f$m\f$. + * + * This class uses \f$a = 48271\f$, \f$c = 0\f$, \f$m = 2^31 -1 = + * 2147483647\f$, the Minimial Standard configuration recommended by Park, + * Miller and Stockmeyer in 1993. + * + * \ingroup PolarTransform + */ +class PolarTransform_EXPORT MinimalStandardRandomVariateGenerator : public RandomVariateGeneratorBase +{ +public: + /** Standard class typedefs. */ + typedef MinimalStandardRandomVariateGenerator Self; + typedef RandomVariateGeneratorBase Superclass; + typedef SmartPointer Pointer; + typedef SmartPointer ConstPointer; + + typedef uint32_t IntegerType; + + typedef itk::Statistics::NormalVariateGenerator NormalGeneratorType; + + /** Run-time type information (and related methods). */ + itkTypeMacro(MinimalStandardRandomVariateGenerator, RandomVariateGeneratorBase); + + /** Method for creation through the object factory. */ + itkNewMacro(Self); + + /** initialize with a simple IntegerType */ + void + Initialize(int randomSeed); + + /** Get a variate in the range [0, 1] */ + virtual double + GetVariate() ITK_OVERRIDE; + +protected: + MinimalStandardRandomVariateGenerator(); + virtual ~MinimalStandardRandomVariateGenerator() {} + + virtual void + PrintSelf(std::ostream & os, Indent indent) const ITK_OVERRIDE; + +private: + NormalGeneratorType::Pointer m_NormalGenerator; +}; + +} // end of namespace Statistics +} // end of namespace itk + +#endif // itkMinimalStandardRandomVariateGenerator_h diff --git a/Modules/Filtering/PolarTransform/include/itkNormalDistributionImageSource.h b/Modules/Filtering/PolarTransform/include/itkNormalDistributionImageSource.h new file mode 100644 index 000000000000..d63b4f09aa64 --- /dev/null +++ b/Modules/Filtering/PolarTransform/include/itkNormalDistributionImageSource.h @@ -0,0 +1,92 @@ +/*========================================================================= + * + * Copyright Insight Software Consortium + * + * 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 + * + * http://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. + * + *=========================================================================*/ +#ifndef itkNormalDistributionImageSource_h +#define itkNormalDistributionImageSource_h + +#include "itkGenerateImageSource.h" + +namespace itk +{ + +/** \class NormalDistributionImageSource + * + * \brief Generate a image of pixels sampled from a normal distribution. + * + * Real-valued pixels are sampled from a normal distribution. + * + * The pixels, \f$x > 0\f$ follow + * + * \f[ + * f(x) = \frac{1}{sx\sqrt{2 \pi}} e^{\left( \frac{-(ln x - m)^2}{2s^2} \right)} + * \f] + * + * where \f$s\f$ is the StandardDeviation and \f$m\f$ is the Mean of the + * underlying normal distribution. + * + * \ingroup PolarTransform + * + */ +template +class NormalDistributionImageSource : public GenerateImageSource +{ +public: + typedef TImage ImageType; + typedef typename ImageType::PixelType PixelType; + + /** Standard class typedefs. */ + typedef NormalDistributionImageSource Self; + typedef GenerateImageSource Superclass; + typedef SmartPointer Pointer; + typedef SmartPointer ConstPointer; + + itkStaticConstMacro(ImageDimension, unsigned int, ImageType::ImageDimension); + + /** Run-time type information. */ + itkTypeMacro(NormalDistributionImageSource, GenerateImageSource); + + /** Standard New macro. */ + itkNewMacro(Self); + +protected: + NormalDistributionImageSource(); + virtual ~NormalDistributionImageSource() {} + + void + PrintSelf(std::ostream & os, Indent indent) const ITK_OVERRIDE; + + typedef typename ImageType::RegionType OutputRegionType; + + virtual void + ThreadedGenerateData(const OutputRegionType & outputRegion, ThreadIdType threadId) ITK_OVERRIDE; + +private: + NormalDistributionImageSource(const Self &); // purposely not implemented + void + operator=(const Self &); // purposely not implemented + +#ifdef ITK_USE_CONCEPT_CHECKING + itkConceptMacro(FloatingPointPixel, (itk::Concept::IsFloatingPoint)); +#endif +}; +} // namespace itk + +#ifndef ITK_MANUAL_INSTANTIATION +# include "itkNormalDistributionImageSource.hxx" +#endif + +#endif // itkNormalDistributionImageSource_h diff --git a/Modules/Filtering/PolarTransform/include/itkNormalDistributionImageSource.hxx b/Modules/Filtering/PolarTransform/include/itkNormalDistributionImageSource.hxx new file mode 100644 index 000000000000..d406348805d4 --- /dev/null +++ b/Modules/Filtering/PolarTransform/include/itkNormalDistributionImageSource.hxx @@ -0,0 +1,79 @@ +/*========================================================================= + * + * Copyright Insight Software Consortium + * + * 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 + * + * http://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. + * + *=========================================================================*/ +#ifndef itkNormalDistributionImageSource_hxx +#define itkNormalDistributionImageSource_hxx + +#include "itkNormalDistributionImageSource.h" +#include "itkNormalVariateGenerator.h" + +#include "itkImageScanlineIterator.h" +#include "itkProgressReporter.h" + +namespace itk +{ + +template +NormalDistributionImageSource::NormalDistributionImageSource() +{} + + +template +void +NormalDistributionImageSource::PrintSelf(std::ostream & os, Indent indent) const +{ + Superclass::PrintSelf(os, indent); +} + + +template +void +NormalDistributionImageSource::ThreadedGenerateData(const OutputRegionType & outputRegion, + ThreadIdType threadId) +{ + ImageType * output = this->GetOutput(); + + typedef itk::Statistics::NormalVariateGenerator NormalGeneratorType; + NormalGeneratorType::Pointer normalGenerator = NormalGeneratorType::New(); + normalGenerator->Initialize(101); + + const SizeValueType size0 = outputRegion.GetSize(0); + if (size0 == 0) + { + return; + } + const SizeValueType numberOfLinesToProcess = outputRegion.GetNumberOfPixels() / size0; + + typedef ImageScanlineIterator IteratorType; + IteratorType it(output, outputRegion); + ProgressReporter progress(this, threadId, numberOfLinesToProcess); + + while (!it.IsAtEnd()) + { + while (!it.IsAtEndOfLine()) + { + it.Set(normalGenerator->GetVariate()); + ++it; + } + it.NextLine(); + progress.CompletedPixel(); + } +} + +} // end namespace itk + +#endif // itkNormalDistributionImageSource_hxx diff --git a/Modules/Filtering/PolarTransform/itk-module.cmake b/Modules/Filtering/PolarTransform/itk-module.cmake new file mode 100644 index 000000000000..2aba3625edf0 --- /dev/null +++ b/Modules/Filtering/PolarTransform/itk-module.cmake @@ -0,0 +1,27 @@ +# the top-level README is used for describing this module, just +# re-used it for documentation here +get_filename_component(MY_CURRENT_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH) +file(READ "${MY_CURRENT_DIR}/README.md" DOCUMENTATION) + +# itk_module() defines the module dependencies in PolarTransform +# PolarTransform depends on ITKCommon +# The testing module in PolarTransform depends on ITKTestKernel +# and ITKMetaIO(besides PolarTransform and ITKCore) +# By convention those modules outside of ITK are not prefixed with +# ITK. + +# define the dependencies of the include module and the tests +itk_module( + PolarTransform + DEPENDS + ITKCommon + ITKStatistics + COMPILE_DEPENDS + ITKImageSources + TEST_DEPENDS + ITKTestKernel + ITKMetaIO + DESCRIPTION "${DOCUMENTATION}" + EXCLUDE_FROM_DEFAULT + ENABLE_SHARED +) diff --git a/Modules/Filtering/PolarTransform/test/Baseline/itkNormalDistributionImageSourceTestOutput.mha.sha512 b/Modules/Filtering/PolarTransform/test/Baseline/itkNormalDistributionImageSourceTestOutput.mha.sha512 new file mode 100644 index 000000000000..a4017ad18cd9 --- /dev/null +++ b/Modules/Filtering/PolarTransform/test/Baseline/itkNormalDistributionImageSourceTestOutput.mha.sha512 @@ -0,0 +1 @@ +38a102c75d4e30f57834fd3dc1ba61e30943714da9a9d27e4b77ee5fb58c1e34269a44c2af3cfd3a0b738de0f5ea293f0f609b8a66eede3f299703548ed57608 diff --git a/Modules/Filtering/PolarTransform/test/CMakeLists.txt b/Modules/Filtering/PolarTransform/test/CMakeLists.txt new file mode 100644 index 000000000000..4154c70480b1 --- /dev/null +++ b/Modules/Filtering/PolarTransform/test/CMakeLists.txt @@ -0,0 +1,28 @@ +itk_module_test() + +set( + PolarTransformTests + itkMinimalStandardRandomVariateGeneratorTest.cxx + itkNormalDistributionImageSourceTest.cxx +) + +createtestdriver(PolarTransform "${PolarTransform-Test_LIBRARIES}" "${PolarTransformTests}") + +itk_add_test( + NAME itkMinimalStandardRandomVariateGeneratorTest + COMMAND + PolarTransformTestDriver + itkMinimalStandardRandomVariateGeneratorTest +) + +itk_add_test( + NAME itkNormalDistributionImageSourceTest + COMMAND + PolarTransformTestDriver + --without-threads + --compare + ${ITK_TEST_OUTPUT_DIR}/itkNormalDistributionImageSourceTestOutput.mha + DATA{Baseline/itkNormalDistributionImageSourceTestOutput.mha} + itkNormalDistributionImageSourceTest + ${ITK_TEST_OUTPUT_DIR}/itkNormalDistributionImageSourceTestOutput.mha +) diff --git a/Modules/Filtering/PolarTransform/test/itkMinimalStandardRandomVariateGeneratorTest.cxx b/Modules/Filtering/PolarTransform/test/itkMinimalStandardRandomVariateGeneratorTest.cxx new file mode 100644 index 000000000000..0ef8f379160a --- /dev/null +++ b/Modules/Filtering/PolarTransform/test/itkMinimalStandardRandomVariateGeneratorTest.cxx @@ -0,0 +1,37 @@ +/*========================================================================= + * + * Copyright Insight Software Consortium + * + * 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 + * + * http://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 "itkMinimalStandardRandomVariateGenerator.h" + +#include "itkTestingMacros.h" +#include "itkMath.h" + +int +itkMinimalStandardRandomVariateGeneratorTest(int, char *[]) +{ + typedef itk::Statistics::MinimalStandardRandomVariateGenerator GeneratorType; + GeneratorType::Pointer generator = GeneratorType::New(); + + EXERCISE_BASIC_OBJECT_METHODS(generator, MinimalStandardRandomVariateGenerator, RandomVariateGeneratorBase); + + generator->Initialize(324); + + TEST_EXPECT_TRUE(itk::Math::FloatAlmostEqual(generator->GetVariate(), 1.35581, 4, 0.0001)); + + return EXIT_SUCCESS; +} diff --git a/Modules/Filtering/PolarTransform/test/itkNormalDistributionImageSourceTest.cxx b/Modules/Filtering/PolarTransform/test/itkNormalDistributionImageSourceTest.cxx new file mode 100644 index 000000000000..e2914a75273e --- /dev/null +++ b/Modules/Filtering/PolarTransform/test/itkNormalDistributionImageSourceTest.cxx @@ -0,0 +1,67 @@ +/*========================================================================= + * + * Copyright Insight Software Consortium + * + * 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 + * + * http://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 "itkNormalDistributionImageSource.h" + +#include "itkImageFileWriter.h" +#include "itkTestingMacros.h" + +int +itkNormalDistributionImageSourceTest(int argc, char * argv[]) +{ + if (argc < 2) + { + std::cerr << "Usage: " << argv[0]; + std::cerr << " outputImage"; + std::cerr << std::endl; + return EXIT_FAILURE; + } + const char * outputImageFileName = argv[1]; + + const unsigned int Dimension = 2; + typedef float PixelType; + typedef itk::Image ImageType; + + typedef itk::NormalDistributionImageSource DistributionSourceType; + DistributionSourceType::Pointer distributionSource = DistributionSourceType::New(); + + EXERCISE_BASIC_OBJECT_METHODS(distributionSource, NormalDistributionImageSource, GenerateImageSource); + + + ImageType::SizeType size; + size.Fill(128); + distributionSource->SetSize(size); + + std::cout << distributionSource << std::endl; + + typedef itk::ImageFileWriter WriterType; + WriterType::Pointer writer = WriterType::New(); + writer->SetFileName(outputImageFileName); + writer->SetInput(distributionSource->GetOutput()); + try + { + writer->Update(); + } + catch (itk::ExceptionObject & error) + { + std::cerr << "Error: " << error << std::endl; + return EXIT_FAILURE; + } + + return EXIT_SUCCESS; +} diff --git a/Modules/Filtering/PolarTransform/wrapping/CMakeLists.txt b/Modules/Filtering/PolarTransform/wrapping/CMakeLists.txt new file mode 100644 index 000000000000..fbd29bfcc775 --- /dev/null +++ b/Modules/Filtering/PolarTransform/wrapping/CMakeLists.txt @@ -0,0 +1,3 @@ +itk_wrap_module(PolarTransform) +itk_auto_load_submodules() +itk_end_wrap_module() diff --git a/Modules/Filtering/PolarTransform/wrapping/itkMinimalStandardRandomVariateGenerator.wrap b/Modules/Filtering/PolarTransform/wrapping/itkMinimalStandardRandomVariateGenerator.wrap new file mode 100644 index 000000000000..e13dd73db38f --- /dev/null +++ b/Modules/Filtering/PolarTransform/wrapping/itkMinimalStandardRandomVariateGenerator.wrap @@ -0,0 +1 @@ +itk_wrap_simple_class("itk::Statistics::MinimalStandardRandomVariateGenerator" POINTER) diff --git a/Modules/Filtering/PolarTransform/wrapping/itkNormalDistributionImageSource.wrap b/Modules/Filtering/PolarTransform/wrapping/itkNormalDistributionImageSource.wrap new file mode 100644 index 000000000000..70e93ecf2702 --- /dev/null +++ b/Modules/Filtering/PolarTransform/wrapping/itkNormalDistributionImageSource.wrap @@ -0,0 +1,7 @@ +itk_wrap_class("itk::NormalDistributionImageSource" POINTER) +foreach(d ${ITK_WRAP_IMAGE_DIMS}) + itk_wrap_template("${ITKM_I${ITKM_F}${d}}" + "${ITKT_I${ITKM_F}${d}}" + ) +endforeach() +itk_end_wrap_class() From 88ba49996743c92a2cb979f2047adf76ce1be8b7 Mon Sep 17 00:00:00 2001 From: Matt McCormick Date: Tue, 14 Nov 2017 21:50:40 -0500 Subject: [PATCH 02/46] ENH: Import headers and test from IJ --- .../include/itkCartesianToPolarTransform.h | 146 +++++++++++++++++ .../include/itkCartesianToPolarTransform.txx | 61 ++++++++ ...itkMinimalStandardRandomVariateGenerator.h | 94 ----------- .../itkNormalDistributionImageSource.h | 92 ----------- .../itkNormalDistributionImageSource.hxx | 79 ---------- .../include/itkPolarToCartesianTransform.h | 147 ++++++++++++++++++ .../include/itkPolarToCartesianTransform.txx | 57 +++++++ ...stributionImageSourceTestOutput.mha.sha512 | 1 - .../PolarTransform/test/CMakeLists.txt | 22 +-- ...imalStandardRandomVariateGeneratorTest.cxx | 37 ----- .../itkNormalDistributionImageSourceTest.cxx | 67 -------- .../test/itkPolarTransformTest.cxx | 78 ++++++++++ ...wrap => itkCartesianToPolarTransform.wrap} | 0 ...wrap => itkPolarToCartesianTransform.wrap} | 0 14 files changed, 492 insertions(+), 389 deletions(-) create mode 100644 Modules/Filtering/PolarTransform/include/itkCartesianToPolarTransform.h create mode 100644 Modules/Filtering/PolarTransform/include/itkCartesianToPolarTransform.txx delete mode 100644 Modules/Filtering/PolarTransform/include/itkMinimalStandardRandomVariateGenerator.h delete mode 100644 Modules/Filtering/PolarTransform/include/itkNormalDistributionImageSource.h delete mode 100644 Modules/Filtering/PolarTransform/include/itkNormalDistributionImageSource.hxx create mode 100644 Modules/Filtering/PolarTransform/include/itkPolarToCartesianTransform.h create mode 100644 Modules/Filtering/PolarTransform/include/itkPolarToCartesianTransform.txx delete mode 100644 Modules/Filtering/PolarTransform/test/Baseline/itkNormalDistributionImageSourceTestOutput.mha.sha512 delete mode 100644 Modules/Filtering/PolarTransform/test/itkMinimalStandardRandomVariateGeneratorTest.cxx delete mode 100644 Modules/Filtering/PolarTransform/test/itkNormalDistributionImageSourceTest.cxx create mode 100644 Modules/Filtering/PolarTransform/test/itkPolarTransformTest.cxx rename Modules/Filtering/PolarTransform/wrapping/{itkNormalDistributionImageSource.wrap => itkCartesianToPolarTransform.wrap} (100%) rename Modules/Filtering/PolarTransform/wrapping/{itkMinimalStandardRandomVariateGenerator.wrap => itkPolarToCartesianTransform.wrap} (100%) diff --git a/Modules/Filtering/PolarTransform/include/itkCartesianToPolarTransform.h b/Modules/Filtering/PolarTransform/include/itkCartesianToPolarTransform.h new file mode 100644 index 000000000000..03efaa99655e --- /dev/null +++ b/Modules/Filtering/PolarTransform/include/itkCartesianToPolarTransform.h @@ -0,0 +1,146 @@ + + +#ifndef __itkCartesianToPolarTransform_h +#define __itkCartesianToPolarTransform_h + +#include +#include "itkTransform.h" +#include "itkExceptionObject.h" +#include "itkMatrix.h" + + +namespace itk +{ + +/** \brief Polar transformation of a vector space (e.g. space coordinates). + * + * Transforms first two coordinates form cartesian coordinates to polar + * coordinates . Other dimensions are left unchanges. In fact + * this is generalized cylindric transform: + * \f[ r = \sqrt{ x_0^2 + x_1^2 } \f] + * \f[ \alpha = \left\{ \begin{array}{ll} + * arccos( \frac{x_0}{r} ) & \mbox{$x_1 >= 0$} \\ + * \mbox{2 \pi} - arccos( \frac{x_0}{r} ) & \mbox{$x_1 < 0$} + * \end{array}\right. \f] + * \f[ x_n = x_n, \mbox{n >= 2} \f] + * + * + * \par + * Center of the polar transform is a center of coordinate system <0,0>. + * + * Dimension must be at least 2 or an exception is thrown during transform. + * + * \author Jakub Bican, Department of Image Processing, Institute of Information Theory and Automation, Academy of + * Sciences of the Czech Republic. + * + * \ingroup Transforms + */ +template // Number of dimensions +class ITK_EXPORT CartesianToPolarTransform : public Transform +{ +public: + /** Standard class typedefs. */ + typedef CartesianToPolarTransform Self; + typedef Transform Superclass; + typedef SmartPointer Pointer; + typedef SmartPointer ConstPointer; + + /** New macro for creation of through the object factory.*/ + itkNewMacro(Self); + + /** Run-time type information (and related methods). */ + itkTypeMacro(CartesianToPolarTransform, Transform); + + /** Dimension of the domain space. */ + itkStaticConstMacro(SpaceDimension, unsigned int, NDimensions); + itkStaticConstMacro(ParametersDimension, unsigned int, 0); + + /** Standard scalar type for this class. */ + typedef typename Superclass::ScalarType ScalarType; + + /** Standard Jacobian container. */ + typedef typename Superclass::JacobianType JacobianType; + + /** Standard vector type for this class. */ + typedef Vector InputVectorType; + typedef Vector OutputVectorType; + + /** Standard covariant vector type for this class. */ + typedef CovariantVector InputCovariantVectorType; + typedef CovariantVector OutputCovariantVectorType; + + /** Standard vnl_vector type for this class. */ + typedef vnl_vector_fixed InputVnlVectorType; + typedef vnl_vector_fixed OutputVnlVectorType; + + /** Standard coordinate point type for this class. */ + typedef Point InputPointType; + typedef Point OutputPointType; + + /** Method to transform a point. + * This method transforms first two dimensions of a point from cartesian + * coordinates to polar coordinates . + */ + OutputPointType + TransformPoint(const InputPointType & point) const; + + /** Method to transform a vector - not applicable for this type of transform. */ + virtual OutputVectorType + TransformVector(const InputVectorType &) const + { + itkExceptionMacro(<< "Method not applicable for polar transform."); + return OutputVectorType(); + } + + /** Method to transform a vnl_vector - not applicable for this type of + transform. */ + virtual OutputVnlVectorType + TransformVector(const InputVnlVectorType &) const + { + itkExceptionMacro(<< "Method not applicable for polar transform. "); + return OutputVnlVectorType(); + } + + /** Method to transform a CovariantVector - not applicable for this type of + transform. */ + virtual OutputCovariantVectorType + TransformCovariantVector(const InputCovariantVectorType &) const + { + itkExceptionMacro(<< "Method not applicable for polar transfrom. "); + return OutputCovariantVectorType(); + } + + /** Compute the Jacobian Matrix of the transformation at one point - not + applicable for this type of transform. */ + virtual const JacobianType & + GetJacobian(const InputPointType & point) const + { + itkExceptionMacro(<< "Method not applicable for polar transform. "); + return m_Jacobian; + } + +protected: + CartesianToPolarTransform(); + ~CartesianToPolarTransform(); + + /** Print contents of an CartesianToPolarTransform. */ + void + PrintSelf(std::ostream & os, Indent indent) const; + +private: + CartesianToPolarTransform(const Self &); // purposely not implemented + void + operator=(const Self &); // purposely not implemented + +}; // class CartesianToPolarTransform + + +} // namespace itk + + +#ifndef ITK_MANUAL_INSTANTIATION +# include "itkCartesianToPolarTransform.txx" +#endif + +#endif /* __itkCartesianToPolarTransform_h */ diff --git a/Modules/Filtering/PolarTransform/include/itkCartesianToPolarTransform.txx b/Modules/Filtering/PolarTransform/include/itkCartesianToPolarTransform.txx new file mode 100644 index 000000000000..b795196d207d --- /dev/null +++ b/Modules/Filtering/PolarTransform/include/itkCartesianToPolarTransform.txx @@ -0,0 +1,61 @@ + +#ifndef _itkCartesianToPolarTransform_txx +#define _itkCartesianToPolarTransform_txx + +#include "itkCartesianToPolarTransform.h" +#include "vnl/vnl_math.h" + +namespace itk +{ + +// Constructor with default arguments +template +CartesianToPolarTransform::CartesianToPolarTransform() + : Superclass(NDimensions, 0) +{ + return; +} + + +// Destructor +template +CartesianToPolarTransform::~CartesianToPolarTransform() +{ + return; +} + + +// Print self +template +void +CartesianToPolarTransform::PrintSelf(std::ostream & os, Indent indent) const +{ + Superclass::PrintSelf(os, indent); +} + + +// Transform a point +template +typename CartesianToPolarTransform::OutputPointType +CartesianToPolarTransform::TransformPoint(const InputPointType & point) const +{ + + if (NDimensions < 2) + { + itkExceptionMacro(<< "Method not applicable for dimension lower than 2."); + return OutputPointType(); + } + + OutputPointType opoint(point); + + opoint[1] = sqrt(point[0] * point[0] + point[1] * point[1]); + opoint[0] = acos(point[0] / opoint[1]); + if (point[1] < 0) + opoint[0] = 2 * vnl_math::pi - opoint[0]; + + return opoint; +} + +} // namespace itk + +#endif diff --git a/Modules/Filtering/PolarTransform/include/itkMinimalStandardRandomVariateGenerator.h b/Modules/Filtering/PolarTransform/include/itkMinimalStandardRandomVariateGenerator.h deleted file mode 100644 index 54a49f462456..000000000000 --- a/Modules/Filtering/PolarTransform/include/itkMinimalStandardRandomVariateGenerator.h +++ /dev/null @@ -1,94 +0,0 @@ -/*========================================================================= - * - * Copyright Insight Software Consortium - * - * 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 - * - * http://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. - * - *=========================================================================*/ -#ifndef itkMinimalStandardRandomVariateGenerator_h -#define itkMinimalStandardRandomVariateGenerator_h - -#include "itkIntTypes.h" -#include "itkObjectFactory.h" -#include "itkRandomVariateGeneratorBase.h" -#include "PolarTransformExport.h" -#include "itkNormalVariateGenerator.h" - -namespace itk -{ -namespace Statistics -{ -/** \class MinimalStandardRandomVariateGenerator - * \brief Linear congruential random random variate generator. - * - * This is a pseudo-random number generator for unsigned integers following - * - * \f[ - * X_{n+1} = (a X_n + c) \mod m - * \f] - * - * where \f$a\f$ is the Multiplier \f$c\f$ is the Increment and \f$m\f$ is - * the Modulus. - * - * http://en.wikipedia.com/wiki/Linear_congruential_generator - * - * The random numbers generated have a period \f$m\f$. - * - * This class uses \f$a = 48271\f$, \f$c = 0\f$, \f$m = 2^31 -1 = - * 2147483647\f$, the Minimial Standard configuration recommended by Park, - * Miller and Stockmeyer in 1993. - * - * \ingroup PolarTransform - */ -class PolarTransform_EXPORT MinimalStandardRandomVariateGenerator : public RandomVariateGeneratorBase -{ -public: - /** Standard class typedefs. */ - typedef MinimalStandardRandomVariateGenerator Self; - typedef RandomVariateGeneratorBase Superclass; - typedef SmartPointer Pointer; - typedef SmartPointer ConstPointer; - - typedef uint32_t IntegerType; - - typedef itk::Statistics::NormalVariateGenerator NormalGeneratorType; - - /** Run-time type information (and related methods). */ - itkTypeMacro(MinimalStandardRandomVariateGenerator, RandomVariateGeneratorBase); - - /** Method for creation through the object factory. */ - itkNewMacro(Self); - - /** initialize with a simple IntegerType */ - void - Initialize(int randomSeed); - - /** Get a variate in the range [0, 1] */ - virtual double - GetVariate() ITK_OVERRIDE; - -protected: - MinimalStandardRandomVariateGenerator(); - virtual ~MinimalStandardRandomVariateGenerator() {} - - virtual void - PrintSelf(std::ostream & os, Indent indent) const ITK_OVERRIDE; - -private: - NormalGeneratorType::Pointer m_NormalGenerator; -}; - -} // end of namespace Statistics -} // end of namespace itk - -#endif // itkMinimalStandardRandomVariateGenerator_h diff --git a/Modules/Filtering/PolarTransform/include/itkNormalDistributionImageSource.h b/Modules/Filtering/PolarTransform/include/itkNormalDistributionImageSource.h deleted file mode 100644 index d63b4f09aa64..000000000000 --- a/Modules/Filtering/PolarTransform/include/itkNormalDistributionImageSource.h +++ /dev/null @@ -1,92 +0,0 @@ -/*========================================================================= - * - * Copyright Insight Software Consortium - * - * 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 - * - * http://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. - * - *=========================================================================*/ -#ifndef itkNormalDistributionImageSource_h -#define itkNormalDistributionImageSource_h - -#include "itkGenerateImageSource.h" - -namespace itk -{ - -/** \class NormalDistributionImageSource - * - * \brief Generate a image of pixels sampled from a normal distribution. - * - * Real-valued pixels are sampled from a normal distribution. - * - * The pixels, \f$x > 0\f$ follow - * - * \f[ - * f(x) = \frac{1}{sx\sqrt{2 \pi}} e^{\left( \frac{-(ln x - m)^2}{2s^2} \right)} - * \f] - * - * where \f$s\f$ is the StandardDeviation and \f$m\f$ is the Mean of the - * underlying normal distribution. - * - * \ingroup PolarTransform - * - */ -template -class NormalDistributionImageSource : public GenerateImageSource -{ -public: - typedef TImage ImageType; - typedef typename ImageType::PixelType PixelType; - - /** Standard class typedefs. */ - typedef NormalDistributionImageSource Self; - typedef GenerateImageSource Superclass; - typedef SmartPointer Pointer; - typedef SmartPointer ConstPointer; - - itkStaticConstMacro(ImageDimension, unsigned int, ImageType::ImageDimension); - - /** Run-time type information. */ - itkTypeMacro(NormalDistributionImageSource, GenerateImageSource); - - /** Standard New macro. */ - itkNewMacro(Self); - -protected: - NormalDistributionImageSource(); - virtual ~NormalDistributionImageSource() {} - - void - PrintSelf(std::ostream & os, Indent indent) const ITK_OVERRIDE; - - typedef typename ImageType::RegionType OutputRegionType; - - virtual void - ThreadedGenerateData(const OutputRegionType & outputRegion, ThreadIdType threadId) ITK_OVERRIDE; - -private: - NormalDistributionImageSource(const Self &); // purposely not implemented - void - operator=(const Self &); // purposely not implemented - -#ifdef ITK_USE_CONCEPT_CHECKING - itkConceptMacro(FloatingPointPixel, (itk::Concept::IsFloatingPoint)); -#endif -}; -} // namespace itk - -#ifndef ITK_MANUAL_INSTANTIATION -# include "itkNormalDistributionImageSource.hxx" -#endif - -#endif // itkNormalDistributionImageSource_h diff --git a/Modules/Filtering/PolarTransform/include/itkNormalDistributionImageSource.hxx b/Modules/Filtering/PolarTransform/include/itkNormalDistributionImageSource.hxx deleted file mode 100644 index d406348805d4..000000000000 --- a/Modules/Filtering/PolarTransform/include/itkNormalDistributionImageSource.hxx +++ /dev/null @@ -1,79 +0,0 @@ -/*========================================================================= - * - * Copyright Insight Software Consortium - * - * 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 - * - * http://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. - * - *=========================================================================*/ -#ifndef itkNormalDistributionImageSource_hxx -#define itkNormalDistributionImageSource_hxx - -#include "itkNormalDistributionImageSource.h" -#include "itkNormalVariateGenerator.h" - -#include "itkImageScanlineIterator.h" -#include "itkProgressReporter.h" - -namespace itk -{ - -template -NormalDistributionImageSource::NormalDistributionImageSource() -{} - - -template -void -NormalDistributionImageSource::PrintSelf(std::ostream & os, Indent indent) const -{ - Superclass::PrintSelf(os, indent); -} - - -template -void -NormalDistributionImageSource::ThreadedGenerateData(const OutputRegionType & outputRegion, - ThreadIdType threadId) -{ - ImageType * output = this->GetOutput(); - - typedef itk::Statistics::NormalVariateGenerator NormalGeneratorType; - NormalGeneratorType::Pointer normalGenerator = NormalGeneratorType::New(); - normalGenerator->Initialize(101); - - const SizeValueType size0 = outputRegion.GetSize(0); - if (size0 == 0) - { - return; - } - const SizeValueType numberOfLinesToProcess = outputRegion.GetNumberOfPixels() / size0; - - typedef ImageScanlineIterator IteratorType; - IteratorType it(output, outputRegion); - ProgressReporter progress(this, threadId, numberOfLinesToProcess); - - while (!it.IsAtEnd()) - { - while (!it.IsAtEndOfLine()) - { - it.Set(normalGenerator->GetVariate()); - ++it; - } - it.NextLine(); - progress.CompletedPixel(); - } -} - -} // end namespace itk - -#endif // itkNormalDistributionImageSource_hxx diff --git a/Modules/Filtering/PolarTransform/include/itkPolarToCartesianTransform.h b/Modules/Filtering/PolarTransform/include/itkPolarToCartesianTransform.h new file mode 100644 index 000000000000..9b4b3344fb36 --- /dev/null +++ b/Modules/Filtering/PolarTransform/include/itkPolarToCartesianTransform.h @@ -0,0 +1,147 @@ + + +#ifndef __itkPolarToCartesianTransform_h +#define __itkPolarToCartesianTransform_h + + +#include +#include "itkTransform.h" +#include "itkExceptionObject.h" +#include "itkMatrix.h" + + +namespace itk +{ + +/** \brief Polar transformation of a vector space (e.g. space coordinates). + * + * Transforms first two coordinates form polar space to cartesian + * coordinates. Other dimensions are left unchanges. In fact this is generalized + * cylindric transform: + * \f[ x_1 = r cos( \alpha ) \f] + * \f[ x_2 = r sin( \alpha ) \f] + * \f[ x_n = x_n, \mbox{ n>=2 } \f] + * + * + * \par + * Center of the polar transform is a center of coordinate system < 0, 0 >. + * + * Dimension must be at least 2 or an exception is thrown during transform. + * + * Extent of input in first dimension (alpha) should be only < 0, 2*pi ). + * + * \author Jakub Bican, Department of Image Processing, Institute of Information Theory and Automation, Academy of + * Sciences of the Czech Republic. + * + * \ingroup Transforms + */ +template // Number of dimensions +class ITK_EXPORT PolarToCartesianTransform : public Transform +{ +public: + /** Standard class typedefs. */ + typedef PolarToCartesianTransform Self; + typedef Transform Superclass; + typedef SmartPointer Pointer; + typedef SmartPointer ConstPointer; + + /** New macro for creation of through the object factory.*/ + itkNewMacro(Self); + + /** Run-time type information (and related methods). */ + itkTypeMacro(PolarToCartesianTransform, Transform); + + /** Dimension of the domain space. */ + itkStaticConstMacro(SpaceDimension, unsigned int, NDimensions); + itkStaticConstMacro(ParametersDimension, unsigned int, 0); + + /** Standard scalar type for this class. */ + typedef typename Superclass::ScalarType ScalarType; + + /** Standard Jacobian container. */ + typedef typename Superclass::JacobianType JacobianType; + + /** Standard vector type for this class. */ + typedef Vector InputVectorType; + typedef Vector OutputVectorType; + + /** Standard covariant vector type for this class. */ + typedef CovariantVector InputCovariantVectorType; + typedef CovariantVector OutputCovariantVectorType; + + /** Standard vnl_vector type for this class. */ + typedef vnl_vector_fixed InputVnlVectorType; + typedef vnl_vector_fixed OutputVnlVectorType; + + /** Standard coordinate point type for this class. */ + typedef Point InputPointType; + typedef Point OutputPointType; + + /** Method to transform a point. + * This method transforms first two dimensions of a point from polar + * coordinates to cartesian coordinates. + */ + OutputPointType + TransformPoint(const InputPointType & point) const; + + /** Method to transform a vector - not applicable for this type of + transform. */ + virtual OutputVectorType + TransformVector(const InputVectorType &) const + { + itkExceptionMacro(<< "Method not applicable for polar transform."); + return OutputVectorType(); + } + + /** Method to transform a vnl_vector - not applicable for this type of + transform. */ + virtual OutputVnlVectorType + TransformVector(const InputVnlVectorType &) const + { + itkExceptionMacro(<< "Method not applicable for polar transform. "); + return OutputVnlVectorType(); + } + + /** Method to transform a CovariantVector - not applicable for this type of + transform */ + virtual OutputCovariantVectorType + TransformCovariantVector(const InputCovariantVectorType &) const + { + itkExceptionMacro(<< "Method not applicable for polar transfrom. "); + return OutputCovariantVectorType(); + } + + /** Compute the Jacobian Matrix of the transformation at one point - not + applicable for this type of transform */ + virtual const JacobianType & + GetJacobian(const InputPointType & point) const + { + itkExceptionMacro(<< "Method not applicable for polar transform. "); + return m_Jacobian; + } + +protected: + PolarToCartesianTransform(); + ~PolarToCartesianTransform(); + + /** Print contents of an PolarToCartesianTransform. */ + void + PrintSelf(std::ostream & os, Indent indent) const; + +private: + PolarToCartesianTransform(const Self &); // purposely not implemented + void + operator=(const Self &); // purposely not implemented + +}; // class PolarToCartesianTransform + + +} // namespace itk + + +#ifndef ITK_MANUAL_INSTANTIATION +# include "itkPolarToCartesianTransform.txx" +#endif + +#endif /* __itkPolarToCartesianTransform_h */ diff --git a/Modules/Filtering/PolarTransform/include/itkPolarToCartesianTransform.txx b/Modules/Filtering/PolarTransform/include/itkPolarToCartesianTransform.txx new file mode 100644 index 000000000000..7f45fb10a918 --- /dev/null +++ b/Modules/Filtering/PolarTransform/include/itkPolarToCartesianTransform.txx @@ -0,0 +1,57 @@ + +#ifndef _itkPolarToCartesianTransform_txx +#define _itkPolarToCartesianTransform_txx + +#include "itkPolarToCartesianTransform.h" + + +namespace itk +{ + +// Constructor with default arguments +template +PolarToCartesianTransform::PolarToCartesianTransform() + : Superclass(NDimensions, 0) +{ + return; +} + + +// Destructor +template +PolarToCartesianTransform::~PolarToCartesianTransform() +{ + return; +} + + +// Print self +template +void +PolarToCartesianTransform::PrintSelf(std::ostream & os, Indent indent) const +{ + Superclass::PrintSelf(os, indent); +} + + +// Transform a point +template +typename PolarToCartesianTransform::OutputPointType +PolarToCartesianTransform::TransformPoint(const InputPointType & point) const +{ + + if (NDimensions < 2) + { + itkExceptionMacro(<< "Method not applicable for dimension lower than 2."); + return OutputPointType(); + } + + OutputPointType opoint(point); + opoint[0] = point[1] * cos(point[0]); // r*cos(alpha) + opoint[1] = point[1] * sin(point[0]); // r*sin(alpha) + return opoint; +} + +} // namespace itk + +#endif diff --git a/Modules/Filtering/PolarTransform/test/Baseline/itkNormalDistributionImageSourceTestOutput.mha.sha512 b/Modules/Filtering/PolarTransform/test/Baseline/itkNormalDistributionImageSourceTestOutput.mha.sha512 deleted file mode 100644 index a4017ad18cd9..000000000000 --- a/Modules/Filtering/PolarTransform/test/Baseline/itkNormalDistributionImageSourceTestOutput.mha.sha512 +++ /dev/null @@ -1 +0,0 @@ -38a102c75d4e30f57834fd3dc1ba61e30943714da9a9d27e4b77ee5fb58c1e34269a44c2af3cfd3a0b738de0f5ea293f0f609b8a66eede3f299703548ed57608 diff --git a/Modules/Filtering/PolarTransform/test/CMakeLists.txt b/Modules/Filtering/PolarTransform/test/CMakeLists.txt index 4154c70480b1..ba5738813895 100644 --- a/Modules/Filtering/PolarTransform/test/CMakeLists.txt +++ b/Modules/Filtering/PolarTransform/test/CMakeLists.txt @@ -1,28 +1,12 @@ itk_module_test() -set( - PolarTransformTests - itkMinimalStandardRandomVariateGeneratorTest.cxx - itkNormalDistributionImageSourceTest.cxx -) +set(PolarTransformTests itkPolarTransformTest.cxx) createtestdriver(PolarTransform "${PolarTransform-Test_LIBRARIES}" "${PolarTransformTests}") itk_add_test( - NAME itkMinimalStandardRandomVariateGeneratorTest - COMMAND - PolarTransformTestDriver - itkMinimalStandardRandomVariateGeneratorTest -) - -itk_add_test( - NAME itkNormalDistributionImageSourceTest + NAME itkPolarTransformTest COMMAND PolarTransformTestDriver - --without-threads - --compare - ${ITK_TEST_OUTPUT_DIR}/itkNormalDistributionImageSourceTestOutput.mha - DATA{Baseline/itkNormalDistributionImageSourceTestOutput.mha} - itkNormalDistributionImageSourceTest - ${ITK_TEST_OUTPUT_DIR}/itkNormalDistributionImageSourceTestOutput.mha + itkPolarTransformTest ) diff --git a/Modules/Filtering/PolarTransform/test/itkMinimalStandardRandomVariateGeneratorTest.cxx b/Modules/Filtering/PolarTransform/test/itkMinimalStandardRandomVariateGeneratorTest.cxx deleted file mode 100644 index 0ef8f379160a..000000000000 --- a/Modules/Filtering/PolarTransform/test/itkMinimalStandardRandomVariateGeneratorTest.cxx +++ /dev/null @@ -1,37 +0,0 @@ -/*========================================================================= - * - * Copyright Insight Software Consortium - * - * 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 - * - * http://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 "itkMinimalStandardRandomVariateGenerator.h" - -#include "itkTestingMacros.h" -#include "itkMath.h" - -int -itkMinimalStandardRandomVariateGeneratorTest(int, char *[]) -{ - typedef itk::Statistics::MinimalStandardRandomVariateGenerator GeneratorType; - GeneratorType::Pointer generator = GeneratorType::New(); - - EXERCISE_BASIC_OBJECT_METHODS(generator, MinimalStandardRandomVariateGenerator, RandomVariateGeneratorBase); - - generator->Initialize(324); - - TEST_EXPECT_TRUE(itk::Math::FloatAlmostEqual(generator->GetVariate(), 1.35581, 4, 0.0001)); - - return EXIT_SUCCESS; -} diff --git a/Modules/Filtering/PolarTransform/test/itkNormalDistributionImageSourceTest.cxx b/Modules/Filtering/PolarTransform/test/itkNormalDistributionImageSourceTest.cxx deleted file mode 100644 index e2914a75273e..000000000000 --- a/Modules/Filtering/PolarTransform/test/itkNormalDistributionImageSourceTest.cxx +++ /dev/null @@ -1,67 +0,0 @@ -/*========================================================================= - * - * Copyright Insight Software Consortium - * - * 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 - * - * http://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 "itkNormalDistributionImageSource.h" - -#include "itkImageFileWriter.h" -#include "itkTestingMacros.h" - -int -itkNormalDistributionImageSourceTest(int argc, char * argv[]) -{ - if (argc < 2) - { - std::cerr << "Usage: " << argv[0]; - std::cerr << " outputImage"; - std::cerr << std::endl; - return EXIT_FAILURE; - } - const char * outputImageFileName = argv[1]; - - const unsigned int Dimension = 2; - typedef float PixelType; - typedef itk::Image ImageType; - - typedef itk::NormalDistributionImageSource DistributionSourceType; - DistributionSourceType::Pointer distributionSource = DistributionSourceType::New(); - - EXERCISE_BASIC_OBJECT_METHODS(distributionSource, NormalDistributionImageSource, GenerateImageSource); - - - ImageType::SizeType size; - size.Fill(128); - distributionSource->SetSize(size); - - std::cout << distributionSource << std::endl; - - typedef itk::ImageFileWriter WriterType; - WriterType::Pointer writer = WriterType::New(); - writer->SetFileName(outputImageFileName); - writer->SetInput(distributionSource->GetOutput()); - try - { - writer->Update(); - } - catch (itk::ExceptionObject & error) - { - std::cerr << "Error: " << error << std::endl; - return EXIT_FAILURE; - } - - return EXIT_SUCCESS; -} diff --git a/Modules/Filtering/PolarTransform/test/itkPolarTransformTest.cxx b/Modules/Filtering/PolarTransform/test/itkPolarTransformTest.cxx new file mode 100644 index 000000000000..1058c8326a6a --- /dev/null +++ b/Modules/Filtering/PolarTransform/test/itkPolarTransformTest.cxx @@ -0,0 +1,78 @@ +#if defined(_MSC_VER) +# pragma warning(disable : 4786) +#endif + +#include + +#include "itkPolarToCartesianTransform.h" +#include "itkCartesianToPolarTransform.h" +#include "vnl/vnl_math.h" + +int +main(int, char *[]) +{ + const unsigned int Dimension = 6; + const double epsilon = 1e-10; + + int i; + + /* Create 3D polar transforms and print them. */ + typedef itk::PolarToCartesianTransform P2CTransformType; + typedef itk::CartesianToPolarTransform C2PTransformType; + P2CTransformType::Pointer p2c = P2CTransformType::New(); + C2PTransformType::Pointer c2p = C2PTransformType::New(); + + std::cout << "Polar to cartesian transform: " << p2c << std::endl; + std::cout << "Cartesian to polar transform: " << c2p << std::endl; + + + /* Create testing points in cartesian and polar space. */ + itk::Point c, p, tmp; + c[0] = 1; + c[1] = sqrt(3.0); + p[0] = vnl_math::pi / 3.0; + p[1] = 2; + for (i = 2; i < Dimension; i++) + { + c[i] = 3; + p[i] = c[i]; + } + + /* Transform point from polar to cartesian space. */ + tmp = p2c->TransformPoint(p); + for (i = 0; i < Dimension; i++) + if (abs(tmp[i] - c[i]) > epsilon) + { + std::cout << "Invalid polar to cartesian computed." << std::endl; + return EXIT_FAILURE; + } + + /* Transform point from cartesian to polar space. */ + tmp = c2p->TransformPoint(c); + for (i = 0; i < Dimension; i++) + if (abs(tmp[i] - p[i]) > epsilon) + { + std::cout << "Invalid cartesian to polar computed." << std::endl; + return EXIT_FAILURE; + } + + /* Transform point from polar to cartesian space and back. */ + tmp = c2p->TransformPoint(p2c->TransformPoint(p)); + for (i = 0; i < Dimension; i++) + if (abs(tmp[i] - p[i]) > epsilon) + { + std::cout << "Invalid polar to cartesian and back computed." << std::endl; + return EXIT_FAILURE; + } + + /* Transform point from cartesian to polar space and back. */ + tmp = p2c->TransformPoint(c2p->TransformPoint(c)); + for (i = 0; i < Dimension; i++) + if (abs(tmp[i] - c[i]) > epsilon) + { + std::cout << "Invalid cartesian to polar and back computed." << std::endl; + return EXIT_FAILURE; + } + + return EXIT_SUCCESS; +} diff --git a/Modules/Filtering/PolarTransform/wrapping/itkNormalDistributionImageSource.wrap b/Modules/Filtering/PolarTransform/wrapping/itkCartesianToPolarTransform.wrap similarity index 100% rename from Modules/Filtering/PolarTransform/wrapping/itkNormalDistributionImageSource.wrap rename to Modules/Filtering/PolarTransform/wrapping/itkCartesianToPolarTransform.wrap diff --git a/Modules/Filtering/PolarTransform/wrapping/itkMinimalStandardRandomVariateGenerator.wrap b/Modules/Filtering/PolarTransform/wrapping/itkPolarToCartesianTransform.wrap similarity index 100% rename from Modules/Filtering/PolarTransform/wrapping/itkMinimalStandardRandomVariateGenerator.wrap rename to Modules/Filtering/PolarTransform/wrapping/itkPolarToCartesianTransform.wrap From e4659b3940bcfca47b9a0a63b5ea448af23f89db Mon Sep 17 00:00:00 2001 From: Matt McCormick Date: Tue, 14 Nov 2017 21:59:37 -0500 Subject: [PATCH 03/46] BUG: Trim module dependencies --- Modules/Filtering/PolarTransform/CMakeLists.txt | 2 -- Modules/Filtering/PolarTransform/itk-module.cmake | 6 +----- 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/Modules/Filtering/PolarTransform/CMakeLists.txt b/Modules/Filtering/PolarTransform/CMakeLists.txt index a536b2ae233c..b224f4fec93a 100644 --- a/Modules/Filtering/PolarTransform/CMakeLists.txt +++ b/Modules/Filtering/PolarTransform/CMakeLists.txt @@ -1,6 +1,4 @@ cmake_minimum_required(VERSION 2.8.12) project(PolarTransform) -set(PolarTransform_LIBRARIES PolarTransform) - itk_module_impl() diff --git a/Modules/Filtering/PolarTransform/itk-module.cmake b/Modules/Filtering/PolarTransform/itk-module.cmake index 2aba3625edf0..3385c1af928f 100644 --- a/Modules/Filtering/PolarTransform/itk-module.cmake +++ b/Modules/Filtering/PolarTransform/itk-module.cmake @@ -13,14 +13,10 @@ file(READ "${MY_CURRENT_DIR}/README.md" DOCUMENTATION) # define the dependencies of the include module and the tests itk_module( PolarTransform - DEPENDS - ITKCommon - ITKStatistics COMPILE_DEPENDS - ITKImageSources + ITKTransform TEST_DEPENDS ITKTestKernel - ITKMetaIO DESCRIPTION "${DOCUMENTATION}" EXCLUDE_FROM_DEFAULT ENABLE_SHARED From c0605120253336cf298e4166d3d8992f5b053341 Mon Sep 17 00:00:00 2001 From: Matt McCormick Date: Tue, 14 Nov 2017 22:02:58 -0500 Subject: [PATCH 04/46] BUG: Add fixes from David Doria in IJ review comments --- .../include/itkCartesianToPolarTransform.h | 13 ++++++++++++- .../include/itkPolarToCartesianTransform.h | 12 +++++++++++- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/Modules/Filtering/PolarTransform/include/itkCartesianToPolarTransform.h b/Modules/Filtering/PolarTransform/include/itkCartesianToPolarTransform.h index 03efaa99655e..e3bd8d8adb53 100644 --- a/Modules/Filtering/PolarTransform/include/itkCartesianToPolarTransform.h +++ b/Modules/Filtering/PolarTransform/include/itkCartesianToPolarTransform.h @@ -62,6 +62,9 @@ class ITK_EXPORT CartesianToPolarTransform : public Transform InputVectorType; typedef Vector OutputVectorType; @@ -117,9 +120,17 @@ class ITK_EXPORT CartesianToPolarTransform : public Transformm_Jacobian; } + void + SetParameters(const ParametersType & parameters) + {} + + void + SetFixedParameters(const ParametersType &) + {} + protected: CartesianToPolarTransform(); ~CartesianToPolarTransform(); diff --git a/Modules/Filtering/PolarTransform/include/itkPolarToCartesianTransform.h b/Modules/Filtering/PolarTransform/include/itkPolarToCartesianTransform.h index 9b4b3344fb36..abe21d3c1ed0 100644 --- a/Modules/Filtering/PolarTransform/include/itkPolarToCartesianTransform.h +++ b/Modules/Filtering/PolarTransform/include/itkPolarToCartesianTransform.h @@ -62,6 +62,9 @@ class ITK_EXPORT PolarToCartesianTransform : public Transform InputVectorType; typedef Vector OutputVectorType; @@ -118,8 +121,15 @@ class ITK_EXPORT PolarToCartesianTransform : public Transformm_Jacobian; } + void + SetParameters(const ParametersType & parameters) + {} + + void + SetFixedParameters(const ParametersType &) + {} protected: PolarToCartesianTransform(); From 9807540677af1ded5d6126bc71e75d40f93da104 Mon Sep 17 00:00:00 2001 From: Matt McCormick Date: Tue, 14 Nov 2017 22:15:57 -0500 Subject: [PATCH 05/46] COMP: Address build errors in itkPolarTransformTest --- .../test/itkPolarTransformTest.cxx | 49 +++++++++++++------ 1 file changed, 34 insertions(+), 15 deletions(-) diff --git a/Modules/Filtering/PolarTransform/test/itkPolarTransformTest.cxx b/Modules/Filtering/PolarTransform/test/itkPolarTransformTest.cxx index 1058c8326a6a..a98e7a795a11 100644 --- a/Modules/Filtering/PolarTransform/test/itkPolarTransformTest.cxx +++ b/Modules/Filtering/PolarTransform/test/itkPolarTransformTest.cxx @@ -1,7 +1,20 @@ -#if defined(_MSC_VER) -# pragma warning(disable : 4786) -#endif - +/*========================================================================= + * + * Copyright Insight Software Consortium + * + * 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 + * + * http://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 #include "itkPolarToCartesianTransform.h" @@ -14,8 +27,6 @@ main(int, char *[]) const unsigned int Dimension = 6; const double epsilon = 1e-10; - int i; - /* Create 3D polar transforms and print them. */ typedef itk::PolarToCartesianTransform P2CTransformType; typedef itk::CartesianToPolarTransform C2PTransformType; @@ -32,7 +43,7 @@ main(int, char *[]) c[1] = sqrt(3.0); p[0] = vnl_math::pi / 3.0; p[1] = 2; - for (i = 2; i < Dimension; i++) + for (unsigned int i = 2; i < Dimension; ++i) { c[i] = 3; p[i] = c[i]; @@ -40,39 +51,47 @@ main(int, char *[]) /* Transform point from polar to cartesian space. */ tmp = p2c->TransformPoint(p); - for (i = 0; i < Dimension; i++) - if (abs(tmp[i] - c[i]) > epsilon) + for (unsigned int i = 0; i < Dimension; ++i) + { + if (std::abs(tmp[i] - c[i]) > epsilon) { std::cout << "Invalid polar to cartesian computed." << std::endl; return EXIT_FAILURE; } + } /* Transform point from cartesian to polar space. */ tmp = c2p->TransformPoint(c); - for (i = 0; i < Dimension; i++) - if (abs(tmp[i] - p[i]) > epsilon) + for (unsigned int i = 0; i < Dimension; ++i) + { + if (std::abs(tmp[i] - p[i]) > epsilon) { std::cout << "Invalid cartesian to polar computed." << std::endl; return EXIT_FAILURE; } + } /* Transform point from polar to cartesian space and back. */ tmp = c2p->TransformPoint(p2c->TransformPoint(p)); - for (i = 0; i < Dimension; i++) - if (abs(tmp[i] - p[i]) > epsilon) + for (unsigned int i = 0; i < Dimension; ++i) + { + if (std::abs(tmp[i] - p[i]) > epsilon) { std::cout << "Invalid polar to cartesian and back computed." << std::endl; return EXIT_FAILURE; } + } /* Transform point from cartesian to polar space and back. */ tmp = p2c->TransformPoint(c2p->TransformPoint(c)); - for (i = 0; i < Dimension; i++) - if (abs(tmp[i] - c[i]) > epsilon) + for (unsigned int i = 0; i < Dimension; ++i) + { + if (std::abs(tmp[i] - c[i]) > epsilon) { std::cout << "Invalid cartesian to polar and back computed." << std::endl; return EXIT_FAILURE; } + } return EXIT_SUCCESS; } From 6ea69208aecf89d51352e4b3b1cba416831144cd Mon Sep 17 00:00:00 2001 From: Matt McCormick Date: Tue, 14 Nov 2017 22:55:32 -0500 Subject: [PATCH 06/46] COMP: Code cleanup, wrapping --- .../include/itkCartesianToPolarTransform.h | 96 ++++++++++-------- .../include/itkCartesianToPolarTransform.hxx | 63 ++++++++++++ .../include/itkCartesianToPolarTransform.txx | 61 ------------ .../include/itkPolarToCartesianTransform.h | 98 +++++++++++-------- .../include/itkPolarToCartesianTransform.hxx | 56 +++++++++++ .../include/itkPolarToCartesianTransform.txx | 57 ----------- .../test/itkPolarTransformTest.cxx | 4 +- .../itkCartesianToPolarTransform.wrap | 6 +- .../itkPolarToCartesianTransform.wrap | 6 +- 9 files changed, 242 insertions(+), 205 deletions(-) create mode 100644 Modules/Filtering/PolarTransform/include/itkCartesianToPolarTransform.hxx delete mode 100644 Modules/Filtering/PolarTransform/include/itkCartesianToPolarTransform.txx create mode 100644 Modules/Filtering/PolarTransform/include/itkPolarToCartesianTransform.hxx delete mode 100644 Modules/Filtering/PolarTransform/include/itkPolarToCartesianTransform.txx diff --git a/Modules/Filtering/PolarTransform/include/itkCartesianToPolarTransform.h b/Modules/Filtering/PolarTransform/include/itkCartesianToPolarTransform.h index e3bd8d8adb53..eb075d87dcad 100644 --- a/Modules/Filtering/PolarTransform/include/itkCartesianToPolarTransform.h +++ b/Modules/Filtering/PolarTransform/include/itkCartesianToPolarTransform.h @@ -1,14 +1,28 @@ - - -#ifndef __itkCartesianToPolarTransform_h -#define __itkCartesianToPolarTransform_h +/*========================================================================= + * + * Copyright Insight Software Consortium + * + * 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 + * + * http://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. + * + *=========================================================================*/ +#ifndef itkCartesianToPolarTransform_h +#define itkCartesianToPolarTransform_h #include #include "itkTransform.h" #include "itkExceptionObject.h" #include "itkMatrix.h" - namespace itk { @@ -35,16 +49,16 @@ namespace itk * * \ingroup Transforms */ -template // Number of dimensions -class ITK_EXPORT CartesianToPolarTransform : public Transform +template // Number of dimensions +class ITK_TEMPLATE_EXPORT CartesianToPolarTransform : public Transform { public: /** Standard class typedefs. */ - typedef CartesianToPolarTransform Self; - typedef Transform Superclass; - typedef SmartPointer Pointer; - typedef SmartPointer ConstPointer; + typedef CartesianToPolarTransform Self; + typedef Transform Superclass; + typedef SmartPointer Pointer; + typedef SmartPointer ConstPointer; /** New macro for creation of through the object factory.*/ itkNewMacro(Self); @@ -66,92 +80,94 @@ class ITK_EXPORT CartesianToPolarTransform : public Transform InputVectorType; - typedef Vector OutputVectorType; + typedef Vector InputVectorType; + typedef Vector OutputVectorType; /** Standard covariant vector type for this class. */ - typedef CovariantVector InputCovariantVectorType; - typedef CovariantVector OutputCovariantVectorType; + typedef CovariantVector InputCovariantVectorType; + typedef CovariantVector OutputCovariantVectorType; /** Standard vnl_vector type for this class. */ - typedef vnl_vector_fixed InputVnlVectorType; - typedef vnl_vector_fixed OutputVnlVectorType; + typedef vnl_vector_fixed InputVnlVectorType; + typedef vnl_vector_fixed OutputVnlVectorType; /** Standard coordinate point type for this class. */ - typedef Point InputPointType; - typedef Point OutputPointType; + typedef Point InputPointType; + typedef Point OutputPointType; /** Method to transform a point. * This method transforms first two dimensions of a point from cartesian * coordinates to polar coordinates . */ OutputPointType - TransformPoint(const InputPointType & point) const; + TransformPoint(const InputPointType & point) const ITK_OVERRIDE; /** Method to transform a vector - not applicable for this type of transform. */ virtual OutputVectorType - TransformVector(const InputVectorType &) const + TransformVector(const InputVectorType &) const ITK_OVERRIDE { - itkExceptionMacro(<< "Method not applicable for polar transform."); + itkExceptionMacro(<< "Method not implemented yet."); return OutputVectorType(); } /** Method to transform a vnl_vector - not applicable for this type of transform. */ virtual OutputVnlVectorType - TransformVector(const InputVnlVectorType &) const + TransformVector(const InputVnlVectorType &) const ITK_OVERRIDE { - itkExceptionMacro(<< "Method not applicable for polar transform. "); + itkExceptionMacro(<< "Method not implemented yet."); return OutputVnlVectorType(); } /** Method to transform a CovariantVector - not applicable for this type of transform. */ virtual OutputCovariantVectorType - TransformCovariantVector(const InputCovariantVectorType &) const + TransformCovariantVector(const InputCovariantVectorType &) const ITK_OVERRIDE { - itkExceptionMacro(<< "Method not applicable for polar transfrom. "); + itkExceptionMacro(<< "Method not implemented yet."); return OutputCovariantVectorType(); } /** Compute the Jacobian Matrix of the transformation at one point - not applicable for this type of transform. */ virtual const JacobianType & - GetJacobian(const InputPointType & point) const + GetJacobian(const InputPointType & point) const ITK_OVERRIDE + { + itkExceptionMacro(<< "Method not implemented yet."); + } + + virtual void + ComputeJacobianWithRespectToParameters(const InputPointType &, JacobianType &) const ITK_OVERRIDE { - itkExceptionMacro(<< "Method not applicable for polar transform. "); - return this->m_Jacobian; + itkExceptionMacro(<< "Method not implemented yet."); } void - SetParameters(const ParametersType & parameters) + SetParameters(const ParametersType & parameters) ITK_OVERRIDE {} void - SetFixedParameters(const ParametersType &) + SetFixedParameters(const ParametersType &) ITK_OVERRIDE {} protected: CartesianToPolarTransform(); - ~CartesianToPolarTransform(); + virtual ~CartesianToPolarTransform() ITK_OVERRIDE; /** Print contents of an CartesianToPolarTransform. */ void - PrintSelf(std::ostream & os, Indent indent) const; + PrintSelf(std::ostream & os, Indent indent) const ITK_OVERRIDE; private: - CartesianToPolarTransform(const Self &); // purposely not implemented - void - operator=(const Self &); // purposely not implemented + ITK_DISALLOW_COPY_AND_ASSIGN(CartesianToPolarTransform); }; // class CartesianToPolarTransform - } // namespace itk #ifndef ITK_MANUAL_INSTANTIATION -# include "itkCartesianToPolarTransform.txx" +# include "itkCartesianToPolarTransform.hxx" #endif -#endif /* __itkCartesianToPolarTransform_h */ +#endif diff --git a/Modules/Filtering/PolarTransform/include/itkCartesianToPolarTransform.hxx b/Modules/Filtering/PolarTransform/include/itkCartesianToPolarTransform.hxx new file mode 100644 index 000000000000..12639c0f1778 --- /dev/null +++ b/Modules/Filtering/PolarTransform/include/itkCartesianToPolarTransform.hxx @@ -0,0 +1,63 @@ +/*========================================================================= + * + * Copyright Insight Software Consortium + * + * 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 + * + * http://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. + * + *=========================================================================*/ +#ifndef itkCartesianToPolarTransform_hxx +#define itkCartesianToPolarTransform_hxx + +#include "itkCartesianToPolarTransform.h" +#include "itkMath.h" + +namespace itk +{ + +template +CartesianToPolarTransform::CartesianToPolarTransform() +{} + + +template +CartesianToPolarTransform::~CartesianToPolarTransform() +{} + + +template +void +CartesianToPolarTransform::PrintSelf(std::ostream & os, Indent indent) const +{ + Superclass::PrintSelf(os, indent); +} + + +template +typename CartesianToPolarTransform::OutputPointType +CartesianToPolarTransform::TransformPoint(const InputPointType & inputPoint) const +{ + OutputPointType outputPoint(inputPoint); + + outputPoint[1] = std::sqrt(inputPoint[0] * inputPoint[0] + inputPoint[1] * inputPoint[1]); + outputPoint[0] = std::acos(inputPoint[0] / outputPoint[1]); + if (inputPoint[1] < 0) + { + outputPoint[0] = Math::twopi - outputPoint[0]; + } + + return outputPoint; +} + +} // namespace itk + +#endif diff --git a/Modules/Filtering/PolarTransform/include/itkCartesianToPolarTransform.txx b/Modules/Filtering/PolarTransform/include/itkCartesianToPolarTransform.txx deleted file mode 100644 index b795196d207d..000000000000 --- a/Modules/Filtering/PolarTransform/include/itkCartesianToPolarTransform.txx +++ /dev/null @@ -1,61 +0,0 @@ - -#ifndef _itkCartesianToPolarTransform_txx -#define _itkCartesianToPolarTransform_txx - -#include "itkCartesianToPolarTransform.h" -#include "vnl/vnl_math.h" - -namespace itk -{ - -// Constructor with default arguments -template -CartesianToPolarTransform::CartesianToPolarTransform() - : Superclass(NDimensions, 0) -{ - return; -} - - -// Destructor -template -CartesianToPolarTransform::~CartesianToPolarTransform() -{ - return; -} - - -// Print self -template -void -CartesianToPolarTransform::PrintSelf(std::ostream & os, Indent indent) const -{ - Superclass::PrintSelf(os, indent); -} - - -// Transform a point -template -typename CartesianToPolarTransform::OutputPointType -CartesianToPolarTransform::TransformPoint(const InputPointType & point) const -{ - - if (NDimensions < 2) - { - itkExceptionMacro(<< "Method not applicable for dimension lower than 2."); - return OutputPointType(); - } - - OutputPointType opoint(point); - - opoint[1] = sqrt(point[0] * point[0] + point[1] * point[1]); - opoint[0] = acos(point[0] / opoint[1]); - if (point[1] < 0) - opoint[0] = 2 * vnl_math::pi - opoint[0]; - - return opoint; -} - -} // namespace itk - -#endif diff --git a/Modules/Filtering/PolarTransform/include/itkPolarToCartesianTransform.h b/Modules/Filtering/PolarTransform/include/itkPolarToCartesianTransform.h index abe21d3c1ed0..9e47f0a66cc5 100644 --- a/Modules/Filtering/PolarTransform/include/itkPolarToCartesianTransform.h +++ b/Modules/Filtering/PolarTransform/include/itkPolarToCartesianTransform.h @@ -1,15 +1,28 @@ - - -#ifndef __itkPolarToCartesianTransform_h -#define __itkPolarToCartesianTransform_h - +/*========================================================================= + * + * Copyright Insight Software Consortium + * + * 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 + * + * http://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. + * + *=========================================================================*/ +#ifndef itkPolarToCartesianTransform_h +#define itkPolarToCartesianTransform_h #include #include "itkTransform.h" #include "itkExceptionObject.h" #include "itkMatrix.h" - namespace itk { @@ -34,17 +47,18 @@ namespace itk * Sciences of the Czech Republic. * * \ingroup Transforms + * \ingroup PolarTransform */ -template // Number of dimensions -class ITK_EXPORT PolarToCartesianTransform : public Transform +template // Number of dimensions +class ITK_TEMPLATE_EXPORT PolarToCartesianTransform : public Transform { public: /** Standard class typedefs. */ - typedef PolarToCartesianTransform Self; - typedef Transform Superclass; - typedef SmartPointer Pointer; - typedef SmartPointer ConstPointer; + typedef PolarToCartesianTransform Self; + typedef Transform Superclass; + typedef SmartPointer Pointer; + typedef SmartPointer ConstPointer; /** New macro for creation of through the object factory.*/ itkNewMacro(Self); @@ -66,83 +80,87 @@ class ITK_EXPORT PolarToCartesianTransform : public Transform InputVectorType; - typedef Vector OutputVectorType; + typedef Vector InputVectorType; + typedef Vector OutputVectorType; /** Standard covariant vector type for this class. */ - typedef CovariantVector InputCovariantVectorType; - typedef CovariantVector OutputCovariantVectorType; + typedef CovariantVector InputCovariantVectorType; + typedef CovariantVector OutputCovariantVectorType; /** Standard vnl_vector type for this class. */ - typedef vnl_vector_fixed InputVnlVectorType; - typedef vnl_vector_fixed OutputVnlVectorType; + typedef vnl_vector_fixed InputVnlVectorType; + typedef vnl_vector_fixed OutputVnlVectorType; /** Standard coordinate point type for this class. */ - typedef Point InputPointType; - typedef Point OutputPointType; + typedef Point InputPointType; + typedef Point OutputPointType; /** Method to transform a point. * This method transforms first two dimensions of a point from polar * coordinates to cartesian coordinates. */ OutputPointType - TransformPoint(const InputPointType & point) const; + TransformPoint(const InputPointType & point) const ITK_OVERRIDE; /** Method to transform a vector - not applicable for this type of transform. */ virtual OutputVectorType - TransformVector(const InputVectorType &) const + TransformVector(const InputVectorType &) const ITK_OVERRIDE { - itkExceptionMacro(<< "Method not applicable for polar transform."); + itkExceptionMacro(<< "Method not implemented yet."); return OutputVectorType(); } /** Method to transform a vnl_vector - not applicable for this type of transform. */ virtual OutputVnlVectorType - TransformVector(const InputVnlVectorType &) const + TransformVector(const InputVnlVectorType &) const ITK_OVERRIDE { - itkExceptionMacro(<< "Method not applicable for polar transform. "); + itkExceptionMacro(<< "Method not implemented yet."); return OutputVnlVectorType(); } /** Method to transform a CovariantVector - not applicable for this type of transform */ virtual OutputCovariantVectorType - TransformCovariantVector(const InputCovariantVectorType &) const + TransformCovariantVector(const InputCovariantVectorType &) const ITK_OVERRIDE { - itkExceptionMacro(<< "Method not applicable for polar transfrom. "); + itkExceptionMacro(<< "Method not implemented yet."); return OutputCovariantVectorType(); } /** Compute the Jacobian Matrix of the transformation at one point - not applicable for this type of transform */ virtual const JacobianType & - GetJacobian(const InputPointType & point) const + GetJacobian(const InputPointType & point) const ITK_OVERRIDE + { + itkExceptionMacro(<< "Method not implemented yet."); + } + + virtual void + ComputeJacobianWithRespectToParameters(const InputPointType &, JacobianType &) const ITK_OVERRIDE { - itkExceptionMacro(<< "Method not applicable for polar transform. "); - return this->m_Jacobian; + itkExceptionMacro(<< "Method not implemented yet."); } + void - SetParameters(const ParametersType & parameters) + SetParameters(const ParametersType & parameters) ITK_OVERRIDE {} void - SetFixedParameters(const ParametersType &) + SetFixedParameters(const ParametersType &) ITK_OVERRIDE {} protected: PolarToCartesianTransform(); - ~PolarToCartesianTransform(); + virtual ~PolarToCartesianTransform() ITK_OVERRIDE; /** Print contents of an PolarToCartesianTransform. */ void - PrintSelf(std::ostream & os, Indent indent) const; + PrintSelf(std::ostream & os, Indent indent) const ITK_OVERRIDE; private: - PolarToCartesianTransform(const Self &); // purposely not implemented - void - operator=(const Self &); // purposely not implemented + ITK_DISALLOW_COPY_AND_ASSIGN(PolarToCartesianTransform); }; // class PolarToCartesianTransform @@ -151,7 +169,7 @@ class ITK_EXPORT PolarToCartesianTransform : public Transform +PolarToCartesianTransform::PolarToCartesianTransform() +{} + + +template +PolarToCartesianTransform::~PolarToCartesianTransform() +{} + + +template +void +PolarToCartesianTransform::PrintSelf(std::ostream & os, Indent indent) const +{ + Superclass::PrintSelf(os, indent); +} + + +template +typename PolarToCartesianTransform::OutputPointType +PolarToCartesianTransform::TransformPoint(const InputPointType & inputPoint) const +{ + OutputPointType outputPoint(inputPoint); + outputPoint[0] = inputPoint[1] * std::cos(inputPoint[0]); // r*cos(alpha) + outputPoint[1] = inputPoint[1] * std::sin(inputPoint[0]); // r*sin(alpha) + return outputPoint; +} + +} // namespace itk + +#endif diff --git a/Modules/Filtering/PolarTransform/include/itkPolarToCartesianTransform.txx b/Modules/Filtering/PolarTransform/include/itkPolarToCartesianTransform.txx deleted file mode 100644 index 7f45fb10a918..000000000000 --- a/Modules/Filtering/PolarTransform/include/itkPolarToCartesianTransform.txx +++ /dev/null @@ -1,57 +0,0 @@ - -#ifndef _itkPolarToCartesianTransform_txx -#define _itkPolarToCartesianTransform_txx - -#include "itkPolarToCartesianTransform.h" - - -namespace itk -{ - -// Constructor with default arguments -template -PolarToCartesianTransform::PolarToCartesianTransform() - : Superclass(NDimensions, 0) -{ - return; -} - - -// Destructor -template -PolarToCartesianTransform::~PolarToCartesianTransform() -{ - return; -} - - -// Print self -template -void -PolarToCartesianTransform::PrintSelf(std::ostream & os, Indent indent) const -{ - Superclass::PrintSelf(os, indent); -} - - -// Transform a point -template -typename PolarToCartesianTransform::OutputPointType -PolarToCartesianTransform::TransformPoint(const InputPointType & point) const -{ - - if (NDimensions < 2) - { - itkExceptionMacro(<< "Method not applicable for dimension lower than 2."); - return OutputPointType(); - } - - OutputPointType opoint(point); - opoint[0] = point[1] * cos(point[0]); // r*cos(alpha) - opoint[1] = point[1] * sin(point[0]); // r*sin(alpha) - return opoint; -} - -} // namespace itk - -#endif diff --git a/Modules/Filtering/PolarTransform/test/itkPolarTransformTest.cxx b/Modules/Filtering/PolarTransform/test/itkPolarTransformTest.cxx index a98e7a795a11..70b9b1ce0714 100644 --- a/Modules/Filtering/PolarTransform/test/itkPolarTransformTest.cxx +++ b/Modules/Filtering/PolarTransform/test/itkPolarTransformTest.cxx @@ -19,10 +19,10 @@ #include "itkPolarToCartesianTransform.h" #include "itkCartesianToPolarTransform.h" -#include "vnl/vnl_math.h" +#include "itkMath.h" int -main(int, char *[]) +itkPolarTransformTest(int, char *[]) { const unsigned int Dimension = 6; const double epsilon = 1e-10; diff --git a/Modules/Filtering/PolarTransform/wrapping/itkCartesianToPolarTransform.wrap b/Modules/Filtering/PolarTransform/wrapping/itkCartesianToPolarTransform.wrap index 70e93ecf2702..2f6ffd22efd3 100644 --- a/Modules/Filtering/PolarTransform/wrapping/itkCartesianToPolarTransform.wrap +++ b/Modules/Filtering/PolarTransform/wrapping/itkCartesianToPolarTransform.wrap @@ -1,7 +1,5 @@ -itk_wrap_class("itk::NormalDistributionImageSource" POINTER) +itk_wrap_class("itk::CartesianToPolarTransform" POINTER) foreach(d ${ITK_WRAP_IMAGE_DIMS}) - itk_wrap_template("${ITKM_I${ITKM_F}${d}}" - "${ITKT_I${ITKM_F}${d}}" - ) + itk_wrap_template("${ITKM_D}${d}" "${ITKT_D},${d}") endforeach() itk_end_wrap_class() diff --git a/Modules/Filtering/PolarTransform/wrapping/itkPolarToCartesianTransform.wrap b/Modules/Filtering/PolarTransform/wrapping/itkPolarToCartesianTransform.wrap index e13dd73db38f..4a338d885249 100644 --- a/Modules/Filtering/PolarTransform/wrapping/itkPolarToCartesianTransform.wrap +++ b/Modules/Filtering/PolarTransform/wrapping/itkPolarToCartesianTransform.wrap @@ -1 +1,5 @@ -itk_wrap_simple_class("itk::Statistics::MinimalStandardRandomVariateGenerator" POINTER) +itk_wrap_class("itk::PolarToCartesianTransform" POINTER) +foreach(d ${ITK_WRAP_IMAGE_DIMS}) + itk_wrap_template("${ITKM_D}${d}" "${ITKT_D},${d}") +endforeach() +itk_end_wrap_class() From 1c753d183f7427964c6fcbf95ee9e870b2e9af00 Mon Sep 17 00:00:00 2001 From: Matt McCormick Date: Tue, 14 Nov 2017 23:04:17 -0500 Subject: [PATCH 07/46] STYLE: Fix KWStyle and Doxygen tests --- .../include/itkCartesianToPolarTransform.h | 11 +++++++---- .../include/itkPolarToCartesianTransform.h | 10 ++++++---- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/Modules/Filtering/PolarTransform/include/itkCartesianToPolarTransform.h b/Modules/Filtering/PolarTransform/include/itkCartesianToPolarTransform.h index eb075d87dcad..fee6a60f56d7 100644 --- a/Modules/Filtering/PolarTransform/include/itkCartesianToPolarTransform.h +++ b/Modules/Filtering/PolarTransform/include/itkCartesianToPolarTransform.h @@ -26,17 +26,19 @@ namespace itk { -/** \brief Polar transformation of a vector space (e.g. space coordinates). +/** \class CartesianToPolarTransform + * + * \brief Polar transformation of a vector space (e.g. space coordinates). * * Transforms first two coordinates form cartesian coordinates to polar * coordinates . Other dimensions are left unchanges. In fact * this is generalized cylindric transform: - * \f[ r = \sqrt{ x_0^2 + x_1^2 } \f] - * \f[ \alpha = \left\{ \begin{array}{ll} + * \f[ r = \sqrt{ x_0^2 + x_1^2 } \f] + * \f[ \alpha = \left\{ \begin{array}{ll} * arccos( \frac{x_0}{r} ) & \mbox{$x_1 >= 0$} \\ * \mbox{2 \pi} - arccos( \frac{x_0}{r} ) & \mbox{$x_1 < 0$} * \end{array}\right. \f] - * \f[ x_n = x_n, \mbox{n >= 2} \f] + * \f[ x_n = x_n, \mbox{n >= 2} \f] * * * \par @@ -48,6 +50,7 @@ namespace itk * Sciences of the Czech Republic. * * \ingroup Transforms + * \ingroup PolarTransform */ template // Number of dimensions diff --git a/Modules/Filtering/PolarTransform/include/itkPolarToCartesianTransform.h b/Modules/Filtering/PolarTransform/include/itkPolarToCartesianTransform.h index 9e47f0a66cc5..efb54d2e0588 100644 --- a/Modules/Filtering/PolarTransform/include/itkPolarToCartesianTransform.h +++ b/Modules/Filtering/PolarTransform/include/itkPolarToCartesianTransform.h @@ -26,14 +26,16 @@ namespace itk { -/** \brief Polar transformation of a vector space (e.g. space coordinates). +/** \class PolarToCartesianTransform + * + * \brief Polar transformation of a vector space (e.g. space coordinates). * * Transforms first two coordinates form polar space to cartesian * coordinates. Other dimensions are left unchanges. In fact this is generalized * cylindric transform: - * \f[ x_1 = r cos( \alpha ) \f] - * \f[ x_2 = r sin( \alpha ) \f] - * \f[ x_n = x_n, \mbox{ n>=2 } \f] + * \f[ x_1 = r cos( \alpha ) \f] + * \f[ x_2 = r sin( \alpha ) \f] + * \f[ x_n = x_n, \mbox{ n>=2 } \f] * * * \par From 764502e36b17efd96b8a7b996ea866e94318ee16 Mon Sep 17 00:00:00 2001 From: Matt McCormick Date: Wed, 15 Nov 2017 00:13:22 -0500 Subject: [PATCH 08/46] COMP: Remove deprecated GetJacobian methods that do not override --- .../PolarTransform/include/itkCartesianToPolarTransform.h | 8 -------- .../PolarTransform/include/itkPolarToCartesianTransform.h | 8 -------- 2 files changed, 16 deletions(-) diff --git a/Modules/Filtering/PolarTransform/include/itkCartesianToPolarTransform.h b/Modules/Filtering/PolarTransform/include/itkCartesianToPolarTransform.h index fee6a60f56d7..876d6e8d4c8a 100644 --- a/Modules/Filtering/PolarTransform/include/itkCartesianToPolarTransform.h +++ b/Modules/Filtering/PolarTransform/include/itkCartesianToPolarTransform.h @@ -131,14 +131,6 @@ class ITK_TEMPLATE_EXPORT CartesianToPolarTransform : public Transform Date: Wed, 15 Nov 2017 13:37:02 -0500 Subject: [PATCH 09/46] ENH: Add support for polar coordinate system center --- .../include/itkCartesianToPolarTransform.h | 11 ++++++++-- .../include/itkCartesianToPolarTransform.hxx | 13 +++++++---- .../include/itkPolarToCartesianTransform.h | 11 +++++++--- .../include/itkPolarToCartesianTransform.hxx | 12 +++++++++- .../test/itkPolarTransformTest.cxx | 22 +++++++++++-------- 5 files changed, 50 insertions(+), 19 deletions(-) diff --git a/Modules/Filtering/PolarTransform/include/itkCartesianToPolarTransform.h b/Modules/Filtering/PolarTransform/include/itkCartesianToPolarTransform.h index 876d6e8d4c8a..b156e87622e9 100644 --- a/Modules/Filtering/PolarTransform/include/itkCartesianToPolarTransform.h +++ b/Modules/Filtering/PolarTransform/include/itkCartesianToPolarTransform.h @@ -42,9 +42,10 @@ namespace itk * * * \par - * Center of the polar transform is a center of coordinate system <0,0>. + * Center of the polar transform is can be specified with SetCenter(). + * The default is center of coordinate system < 0, 0 >. * - * Dimension must be at least 2 or an exception is thrown during transform. + * Dimension must be at least 2. * * \author Jakub Bican, Department of Image Processing, Institute of Information Theory and Automation, Academy of * Sciences of the Czech Republic. @@ -145,6 +146,10 @@ class ITK_TEMPLATE_EXPORT CartesianToPolarTransform : public Transform CartesianToPolarTransform::CartesianToPolarTransform() -{} +{ + this->m_Center.Fill(0.0); +} template @@ -39,6 +41,7 @@ void CartesianToPolarTransform::PrintSelf(std::ostream & os, Indent indent) const { Superclass::PrintSelf(os, indent); + os << indent << "Center: " << m_Center << std::endl; } @@ -48,9 +51,11 @@ CartesianToPolarTransform::TransformPoint(con { OutputPointType outputPoint(inputPoint); - outputPoint[1] = std::sqrt(inputPoint[0] * inputPoint[0] + inputPoint[1] * inputPoint[1]); - outputPoint[0] = std::acos(inputPoint[0] / outputPoint[1]); - if (inputPoint[1] < 0) + const InputPointType vector = inputPoint - this->m_Center; + + outputPoint[1] = std::sqrt(vector[0] * vector[0] + vector[1] * vector[1]); + outputPoint[0] = std::acos(vector[0] / outputPoint[1]); + if (vector[1] < 0.0) { outputPoint[0] = Math::twopi - outputPoint[0]; } diff --git a/Modules/Filtering/PolarTransform/include/itkPolarToCartesianTransform.h b/Modules/Filtering/PolarTransform/include/itkPolarToCartesianTransform.h index 44fa1006ac1b..8374fc13b6be 100644 --- a/Modules/Filtering/PolarTransform/include/itkPolarToCartesianTransform.h +++ b/Modules/Filtering/PolarTransform/include/itkPolarToCartesianTransform.h @@ -37,11 +37,11 @@ namespace itk * \f[ x_2 = r sin( \alpha ) \f] * \f[ x_n = x_n, \mbox{ n>=2 } \f] * - * * \par - * Center of the polar transform is a center of coordinate system < 0, 0 >. + * Center of the polar transform is can be specified with SetCenter(). + * The default is center of coordinate system < 0, 0 >. * - * Dimension must be at least 2 or an exception is thrown during transform. + * Dimension must be at least 2. * * Extent of input in first dimension (alpha) should be only < 0, 2*pi ). * @@ -145,6 +145,10 @@ class ITK_TEMPLATE_EXPORT PolarToCartesianTransform : public Transform PolarToCartesianTransform::PolarToCartesianTransform() -{} +{ + this->m_Center.Fill(0.0); +} template @@ -38,6 +40,7 @@ void PolarToCartesianTransform::PrintSelf(std::ostream & os, Indent indent) const { Superclass::PrintSelf(os, indent); + os << indent << "Center: " << m_Center << std::endl; } @@ -46,8 +49,15 @@ typename PolarToCartesianTransform::OutputPoi PolarToCartesianTransform::TransformPoint(const InputPointType & inputPoint) const { OutputPointType outputPoint(inputPoint); + outputPoint[0] = inputPoint[1] * std::cos(inputPoint[0]); // r*cos(alpha) outputPoint[1] = inputPoint[1] * std::sin(inputPoint[0]); // r*sin(alpha) + + for (unsigned int ii = 0; ii < SpaceDimension; ++ii) + { + outputPoint[ii] = this->m_Center[ii] + outputPoint[ii]; + } + return outputPoint; } diff --git a/Modules/Filtering/PolarTransform/test/itkPolarTransformTest.cxx b/Modules/Filtering/PolarTransform/test/itkPolarTransformTest.cxx index 70b9b1ce0714..4fcf30fc8948 100644 --- a/Modules/Filtering/PolarTransform/test/itkPolarTransformTest.cxx +++ b/Modules/Filtering/PolarTransform/test/itkPolarTransformTest.cxx @@ -15,8 +15,6 @@ * limitations under the License. * *=========================================================================*/ -#include - #include "itkPolarToCartesianTransform.h" #include "itkCartesianToPolarTransform.h" #include "itkMath.h" @@ -24,7 +22,7 @@ int itkPolarTransformTest(int, char *[]) { - const unsigned int Dimension = 6; + const unsigned int Dimension = 4; const double epsilon = 1e-10; /* Create 3D polar transforms and print them. */ @@ -33,19 +31,26 @@ itkPolarTransformTest(int, char *[]) P2CTransformType::Pointer p2c = P2CTransformType::New(); C2PTransformType::Pointer c2p = C2PTransformType::New(); + P2CTransformType::InputPointType center; + center.Fill(0.0); + center[0] = -1.0; + + p2c->SetCenter(center); + c2p->SetCenter(center); + std::cout << "Polar to cartesian transform: " << p2c << std::endl; std::cout << "Cartesian to polar transform: " << c2p << std::endl; /* Create testing points in cartesian and polar space. */ itk::Point c, p, tmp; - c[0] = 1; - c[1] = sqrt(3.0); - p[0] = vnl_math::pi / 3.0; - p[1] = 2; + c[0] = 0.0; + c[1] = std::sqrt(3.0); + p[0] = itk::Math::pi / 3.0; + p[1] = 2.0; for (unsigned int i = 2; i < Dimension; ++i) { - c[i] = 3; + c[i] = 3.0; p[i] = c[i]; } @@ -55,7 +60,6 @@ itkPolarTransformTest(int, char *[]) { if (std::abs(tmp[i] - c[i]) > epsilon) { - std::cout << "Invalid polar to cartesian computed." << std::endl; return EXIT_FAILURE; } } From a3f8971cfdf93cfec9a349c71efd015ab1e04fa6 Mon Sep 17 00:00:00 2001 From: Matt McCormick Date: Thu, 21 Dec 2017 19:21:49 -0500 Subject: [PATCH 10/46] ENH: Add Python wrapper instantiation tests --- Modules/Filtering/PolarTransform/test/CMakeLists.txt | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Modules/Filtering/PolarTransform/test/CMakeLists.txt b/Modules/Filtering/PolarTransform/test/CMakeLists.txt index ba5738813895..a6c8d09960bc 100644 --- a/Modules/Filtering/PolarTransform/test/CMakeLists.txt +++ b/Modules/Filtering/PolarTransform/test/CMakeLists.txt @@ -10,3 +10,12 @@ itk_add_test( PolarTransformTestDriver itkPolarTransformTest ) + +itk_python_expression_add_test( + NAME itkPolarToCartesianTransformPythonTest + EXPRESSION "instance = itk.PolarToCartesianTransform.New()" +) +itk_python_expression_add_test( + NAME itkCartesianToPolarTransformPythonTest + EXPRESSION "instance = itk.CartesianToPolarTransform.New()" +) From 8b39b90782c66d88427c7f7f833567d7f74f2c73 Mon Sep 17 00:00:00 2001 From: Matt McCormick Date: Thu, 21 Dec 2017 19:27:45 -0500 Subject: [PATCH 11/46] BUG: Pass ParametersDimension to Transform constructor Addresses: 4: WARNING: In /home/matt/src/ITK/Modules/Core/Transform/include/itkTransform.hxx, line 40 4: Transform (0x2661eb0): Using default transform constructor. Should specify NOutputDims and NParameters as args to constructor. --- .../PolarTransform/include/itkCartesianToPolarTransform.hxx | 1 + .../PolarTransform/include/itkPolarToCartesianTransform.hxx | 1 + 2 files changed, 2 insertions(+) diff --git a/Modules/Filtering/PolarTransform/include/itkCartesianToPolarTransform.hxx b/Modules/Filtering/PolarTransform/include/itkCartesianToPolarTransform.hxx index 5e5404afe8c7..77c18760c342 100644 --- a/Modules/Filtering/PolarTransform/include/itkCartesianToPolarTransform.hxx +++ b/Modules/Filtering/PolarTransform/include/itkCartesianToPolarTransform.hxx @@ -26,6 +26,7 @@ namespace itk template CartesianToPolarTransform::CartesianToPolarTransform() + : Superclass(ParametersDimension) { this->m_Center.Fill(0.0); } diff --git a/Modules/Filtering/PolarTransform/include/itkPolarToCartesianTransform.hxx b/Modules/Filtering/PolarTransform/include/itkPolarToCartesianTransform.hxx index 7ad586841f4d..c57cc585cda5 100644 --- a/Modules/Filtering/PolarTransform/include/itkPolarToCartesianTransform.hxx +++ b/Modules/Filtering/PolarTransform/include/itkPolarToCartesianTransform.hxx @@ -25,6 +25,7 @@ namespace itk template PolarToCartesianTransform::PolarToCartesianTransform() + : Superclass(ParametersDimension) { this->m_Center.Fill(0.0); } From 4ee8b4d58174db3eb11e9feb1a95981d0f35fc2d Mon Sep 17 00:00:00 2001 From: Matt McCormick Date: Wed, 27 Dec 2017 01:21:28 -0500 Subject: [PATCH 12/46] COMP: Unused parameters argument to SetParameters These transforms dod not have optimizable parameters. --- .../PolarTransform/include/itkCartesianToPolarTransform.h | 2 +- .../PolarTransform/include/itkPolarToCartesianTransform.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Modules/Filtering/PolarTransform/include/itkCartesianToPolarTransform.h b/Modules/Filtering/PolarTransform/include/itkCartesianToPolarTransform.h index b156e87622e9..64db37eea408 100644 --- a/Modules/Filtering/PolarTransform/include/itkCartesianToPolarTransform.h +++ b/Modules/Filtering/PolarTransform/include/itkCartesianToPolarTransform.h @@ -139,7 +139,7 @@ class ITK_TEMPLATE_EXPORT CartesianToPolarTransform : public Transform Date: Wed, 27 Dec 2017 10:14:08 -0500 Subject: [PATCH 13/46] COMP: no need to repeat virtual specifier for inherited overridden methods --- .../include/itkCartesianToPolarTransform.h | 10 +++++----- .../include/itkPolarToCartesianTransform.h | 10 +++++----- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/Modules/Filtering/PolarTransform/include/itkCartesianToPolarTransform.h b/Modules/Filtering/PolarTransform/include/itkCartesianToPolarTransform.h index 64db37eea408..601441331c99 100644 --- a/Modules/Filtering/PolarTransform/include/itkCartesianToPolarTransform.h +++ b/Modules/Filtering/PolarTransform/include/itkCartesianToPolarTransform.h @@ -107,7 +107,7 @@ class ITK_TEMPLATE_EXPORT CartesianToPolarTransform : public Transform Date: Wed, 27 Dec 2017 12:50:46 -0500 Subject: [PATCH 14/46] COMP: explicitly overriding TransformVector at point --- .../include/itkCartesianToPolarTransform.h | 15 ++++++++++----- .../include/itkPolarToCartesianTransform.h | 18 +++++++++++------- 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/Modules/Filtering/PolarTransform/include/itkCartesianToPolarTransform.h b/Modules/Filtering/PolarTransform/include/itkCartesianToPolarTransform.h index 601441331c99..13d1728cd640 100644 --- a/Modules/Filtering/PolarTransform/include/itkCartesianToPolarTransform.h +++ b/Modules/Filtering/PolarTransform/include/itkCartesianToPolarTransform.h @@ -114,8 +114,7 @@ class ITK_TEMPLATE_EXPORT CartesianToPolarTransform : public Transform Date: Wed, 27 Dec 2017 13:12:23 -0500 Subject: [PATCH 15/46] DOC: changing exception messages to not applicable --- .../PolarTransform/include/itkCartesianToPolarTransform.h | 8 ++++---- .../PolarTransform/include/itkPolarToCartesianTransform.h | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Modules/Filtering/PolarTransform/include/itkCartesianToPolarTransform.h b/Modules/Filtering/PolarTransform/include/itkCartesianToPolarTransform.h index 13d1728cd640..39a12593dc20 100644 --- a/Modules/Filtering/PolarTransform/include/itkCartesianToPolarTransform.h +++ b/Modules/Filtering/PolarTransform/include/itkCartesianToPolarTransform.h @@ -110,7 +110,7 @@ class ITK_TEMPLATE_EXPORT CartesianToPolarTransform : public Transform Date: Wed, 27 Dec 2017 16:44:30 -0500 Subject: [PATCH 16/46] COMP: taking care of remaining warnings --- .../PolarTransform/include/itkCartesianToPolarTransform.h | 4 ++++ .../PolarTransform/include/itkPolarToCartesianTransform.h | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/Modules/Filtering/PolarTransform/include/itkCartesianToPolarTransform.h b/Modules/Filtering/PolarTransform/include/itkCartesianToPolarTransform.h index 39a12593dc20..98b945fd3493 100644 --- a/Modules/Filtering/PolarTransform/include/itkCartesianToPolarTransform.h +++ b/Modules/Filtering/PolarTransform/include/itkCartesianToPolarTransform.h @@ -130,6 +130,8 @@ class ITK_TEMPLATE_EXPORT CartesianToPolarTransform : public Transform Date: Wed, 17 Jan 2018 18:16:59 +0100 Subject: [PATCH 17/46] ENH: Require cmake minimum version to be 3.9.5. Require CMake minimum version to be 3.9.5 following ITKv5 requiring C++11: https://discourse.itk.org/t/minimum-cmake-version-update/585 --- Modules/Filtering/PolarTransform/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Modules/Filtering/PolarTransform/CMakeLists.txt b/Modules/Filtering/PolarTransform/CMakeLists.txt index b224f4fec93a..fe8ee73cbe95 100644 --- a/Modules/Filtering/PolarTransform/CMakeLists.txt +++ b/Modules/Filtering/PolarTransform/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 2.8.12) +cmake_minimum_required(VERSION 3.9.5) project(PolarTransform) itk_module_impl() From 022d332a698c500abb7b00071b09d5eec3f5ee76 Mon Sep 17 00:00:00 2001 From: Hans Johnson Date: Mon, 12 Feb 2018 21:04:18 -0600 Subject: [PATCH 18/46] STYLE: Replace itkStaticConstMacro with static constexpr Use static constexpr directly now that C++11 conformance is required by all compilers. :%s/itkStaticConstMacro *( *\([^,]*\),[ \_s]*\([^,]*\),\_s*\([^)]*\)) */static constexpr \2 \1 = \3/ge --- .../PolarTransform/include/itkCartesianToPolarTransform.h | 4 ++-- .../PolarTransform/include/itkPolarToCartesianTransform.h | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Modules/Filtering/PolarTransform/include/itkCartesianToPolarTransform.h b/Modules/Filtering/PolarTransform/include/itkCartesianToPolarTransform.h index 98b945fd3493..92eb0a87a371 100644 --- a/Modules/Filtering/PolarTransform/include/itkCartesianToPolarTransform.h +++ b/Modules/Filtering/PolarTransform/include/itkCartesianToPolarTransform.h @@ -71,8 +71,8 @@ class ITK_TEMPLATE_EXPORT CartesianToPolarTransform : public Transform Date: Mon, 12 Feb 2018 23:30:48 -0600 Subject: [PATCH 19/46] STYLE: Prefer C++11 type alias over typedef == http://en.cppreference.com/w/cpp/language/type_alias == Type alias is a name that refers to a previously defined type (similar to typedef). A type alias declaration introduces a name which can be used as a synonym for the type denoted by type-id. It does not introduce a new type and it cannot change the meaning of an existing type name. There is no difference between a type alias declaration and typedef declaration. This declaration may appear in block scope, class scope, or namespace scope. == https://www.quora.com/Is-using-typedef-in-C++-considered-a-bad-practice == While typedef is still available for backward compatibility, the new Type Alias syntax 'using Alias = ExistingLongName;' is more consistent with the flow of C++ than the old typedef syntax 'typedef ExistingLongName Alias;', and it also works for templates (Type alias, alias template (since C++11)), so leftover 'typedef' aliases will differ in style from any alias templates. --- .../include/itkCartesianToPolarTransform.h | 32 +++++++++---------- .../include/itkPolarToCartesianTransform.h | 32 +++++++++---------- .../test/itkPolarTransformTest.cxx | 8 ++--- 3 files changed, 36 insertions(+), 36 deletions(-) diff --git a/Modules/Filtering/PolarTransform/include/itkCartesianToPolarTransform.h b/Modules/Filtering/PolarTransform/include/itkCartesianToPolarTransform.h index 92eb0a87a371..ff2de81194ae 100644 --- a/Modules/Filtering/PolarTransform/include/itkCartesianToPolarTransform.h +++ b/Modules/Filtering/PolarTransform/include/itkCartesianToPolarTransform.h @@ -58,11 +58,11 @@ template { public: - /** Standard class typedefs. */ - typedef CartesianToPolarTransform Self; - typedef Transform Superclass; - typedef SmartPointer Pointer; - typedef SmartPointer ConstPointer; + /** Standard class type alias. */ + using Self = CartesianToPolarTransform; + using Superclass = Transform; + using Pointer = SmartPointer; + using ConstPointer = SmartPointer; /** New macro for creation of through the object factory.*/ itkNewMacro(Self); @@ -75,29 +75,29 @@ class ITK_TEMPLATE_EXPORT CartesianToPolarTransform : public Transform InputVectorType; - typedef Vector OutputVectorType; + using InputVectorType = Vector; + using OutputVectorType = Vector; /** Standard covariant vector type for this class. */ - typedef CovariantVector InputCovariantVectorType; - typedef CovariantVector OutputCovariantVectorType; + using InputCovariantVectorType = CovariantVector; + using OutputCovariantVectorType = CovariantVector; /** Standard vnl_vector type for this class. */ - typedef vnl_vector_fixed InputVnlVectorType; - typedef vnl_vector_fixed OutputVnlVectorType; + using InputVnlVectorType = vnl_vector_fixed; + using OutputVnlVectorType = vnl_vector_fixed; /** Standard coordinate point type for this class. */ - typedef Point InputPointType; - typedef Point OutputPointType; + using InputPointType = Point; + using OutputPointType = Point; /** Method to transform a point. * This method transforms first two dimensions of a point from cartesian diff --git a/Modules/Filtering/PolarTransform/include/itkPolarToCartesianTransform.h b/Modules/Filtering/PolarTransform/include/itkPolarToCartesianTransform.h index 4746c1117672..a33323757654 100644 --- a/Modules/Filtering/PolarTransform/include/itkPolarToCartesianTransform.h +++ b/Modules/Filtering/PolarTransform/include/itkPolarToCartesianTransform.h @@ -56,11 +56,11 @@ template { public: - /** Standard class typedefs. */ - typedef PolarToCartesianTransform Self; - typedef Transform Superclass; - typedef SmartPointer Pointer; - typedef SmartPointer ConstPointer; + /** Standard class type alias. */ + using Self = PolarToCartesianTransform; + using Superclass = Transform; + using Pointer = SmartPointer; + using ConstPointer = SmartPointer; /** New macro for creation of through the object factory.*/ itkNewMacro(Self); @@ -73,29 +73,29 @@ class ITK_TEMPLATE_EXPORT PolarToCartesianTransform : public Transform InputVectorType; - typedef Vector OutputVectorType; + using InputVectorType = Vector; + using OutputVectorType = Vector; /** Standard covariant vector type for this class. */ - typedef CovariantVector InputCovariantVectorType; - typedef CovariantVector OutputCovariantVectorType; + using InputCovariantVectorType = CovariantVector; + using OutputCovariantVectorType = CovariantVector; /** Standard vnl_vector type for this class. */ - typedef vnl_vector_fixed InputVnlVectorType; - typedef vnl_vector_fixed OutputVnlVectorType; + using InputVnlVectorType = vnl_vector_fixed; + using OutputVnlVectorType = vnl_vector_fixed; /** Standard coordinate point type for this class. */ - typedef Point InputPointType; - typedef Point OutputPointType; + using InputPointType = Point; + using OutputPointType = Point; /** Method to transform a point. * This method transforms first two dimensions of a point from polar diff --git a/Modules/Filtering/PolarTransform/test/itkPolarTransformTest.cxx b/Modules/Filtering/PolarTransform/test/itkPolarTransformTest.cxx index 4fcf30fc8948..785c7cc26e76 100644 --- a/Modules/Filtering/PolarTransform/test/itkPolarTransformTest.cxx +++ b/Modules/Filtering/PolarTransform/test/itkPolarTransformTest.cxx @@ -26,10 +26,10 @@ itkPolarTransformTest(int, char *[]) const double epsilon = 1e-10; /* Create 3D polar transforms and print them. */ - typedef itk::PolarToCartesianTransform P2CTransformType; - typedef itk::CartesianToPolarTransform C2PTransformType; - P2CTransformType::Pointer p2c = P2CTransformType::New(); - C2PTransformType::Pointer c2p = C2PTransformType::New(); + using P2CTransformType = itk::PolarToCartesianTransform; + using C2PTransformType = itk::CartesianToPolarTransform; + P2CTransformType::Pointer p2c = P2CTransformType::New(); + C2PTransformType::Pointer c2p = C2PTransformType::New(); P2CTransformType::InputPointType center; center.Fill(0.0); From 760b9cbc644dcdf6c6d4ba81ee97b56b0cf77cee Mon Sep 17 00:00:00 2001 From: Hans Johnson Date: Tue, 13 Feb 2018 08:15:40 -0600 Subject: [PATCH 20/46] COMP: Use C++11 override directly git grep -l "ITK_OVERRIDE" | fgrep -v itk_compiler_detection.h | fgrep -v CMakeLists.txt |fgrep -v .cmake | xargs sed -i '' -e "s/ITK_OVERRIDE/override/g" --- .../include/itkCartesianToPolarTransform.h | 20 +++++++++---------- .../include/itkPolarToCartesianTransform.h | 20 +++++++++---------- 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/Modules/Filtering/PolarTransform/include/itkCartesianToPolarTransform.h b/Modules/Filtering/PolarTransform/include/itkCartesianToPolarTransform.h index ff2de81194ae..47fc1d4f328c 100644 --- a/Modules/Filtering/PolarTransform/include/itkCartesianToPolarTransform.h +++ b/Modules/Filtering/PolarTransform/include/itkCartesianToPolarTransform.h @@ -104,11 +104,11 @@ class ITK_TEMPLATE_EXPORT CartesianToPolarTransform : public Transform. */ OutputPointType - TransformPoint(const InputPointType & point) const ITK_OVERRIDE; + TransformPoint(const InputPointType & point) const override; /** Method to transform a vector - not applicable for this type of transform. */ OutputVectorType - TransformVector(const InputVectorType &) const ITK_OVERRIDE + TransformVector(const InputVectorType &) const override { itkExceptionMacro(<< "Method not applicable for this type of transform."); return OutputVectorType(); @@ -116,7 +116,7 @@ class ITK_TEMPLATE_EXPORT CartesianToPolarTransform : public Transform to cartesian coordinates. */ OutputPointType - TransformPoint(const InputPointType & point) const ITK_OVERRIDE; + TransformPoint(const InputPointType & point) const override; /** Method to transform a vector - not applicable for this type of transform. */ OutputVectorType - TransformVector(const InputVectorType &) const ITK_OVERRIDE + TransformVector(const InputVectorType &) const override { itkExceptionMacro(<< "Method not applicable for this type of transform."); return OutputVectorType(); @@ -114,7 +114,7 @@ class ITK_TEMPLATE_EXPORT PolarToCartesianTransform : public Transform Date: Tue, 13 Feb 2018 08:25:14 -0600 Subject: [PATCH 21/46] STYLE: Prefer constexpr for const numeric literals Use constexpr for constant numeric literals. --- .../Filtering/PolarTransform/test/itkPolarTransformTest.cxx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Modules/Filtering/PolarTransform/test/itkPolarTransformTest.cxx b/Modules/Filtering/PolarTransform/test/itkPolarTransformTest.cxx index 785c7cc26e76..f2bf79daf810 100644 --- a/Modules/Filtering/PolarTransform/test/itkPolarTransformTest.cxx +++ b/Modules/Filtering/PolarTransform/test/itkPolarTransformTest.cxx @@ -22,8 +22,8 @@ int itkPolarTransformTest(int, char *[]) { - const unsigned int Dimension = 4; - const double epsilon = 1e-10; + constexpr unsigned int Dimension = 4; + const double epsilon = 1e-10; /* Create 3D polar transforms and print them. */ using P2CTransformType = itk::PolarToCartesianTransform; From 8e426ac22052c78d1fbe0e2cb953933dc3260093 Mon Sep 17 00:00:00 2001 From: Jon Haitz Legarreta Date: Sat, 14 Apr 2018 19:26:46 +0200 Subject: [PATCH 22/46] COMP: Move ITK_DISALLOW_COPY_AND_ASSIGN calls to public section. Move `ITK_DISALLOW_COPY_AND_ASSIGN` calls to public section following the discussion in https://discourse.itk.org/t/noncopyable If legacy (pre-macro) copy and assing methods existed, subsitute them for the `ITK_DISALLOW_COPY_AND_ASSIGN` macro. --- .../PolarTransform/include/itkCartesianToPolarTransform.h | 4 ++-- .../PolarTransform/include/itkPolarToCartesianTransform.h | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Modules/Filtering/PolarTransform/include/itkCartesianToPolarTransform.h b/Modules/Filtering/PolarTransform/include/itkCartesianToPolarTransform.h index 47fc1d4f328c..43c9cdc4206e 100644 --- a/Modules/Filtering/PolarTransform/include/itkCartesianToPolarTransform.h +++ b/Modules/Filtering/PolarTransform/include/itkCartesianToPolarTransform.h @@ -58,6 +58,8 @@ template { public: + ITK_DISALLOW_COPY_AND_ASSIGN(CartesianToPolarTransform); + /** Standard class type alias. */ using Self = CartesianToPolarTransform; using Superclass = Transform; @@ -169,8 +171,6 @@ class ITK_TEMPLATE_EXPORT CartesianToPolarTransform : public Transform { public: + ITK_DISALLOW_COPY_AND_ASSIGN(PolarToCartesianTransform); + /** Standard class type alias. */ using Self = PolarToCartesianTransform; using Superclass = Transform; @@ -167,8 +169,6 @@ class ITK_TEMPLATE_EXPORT PolarToCartesianTransform : public Transform Date: Sat, 5 May 2018 12:30:49 +0200 Subject: [PATCH 23/46] COMP: Set the minimum required CMake version to 3.10.2. As agreed in: https://discourse.itk.org/t/cmake-update/870/ Set the `cmake_minimum_required` to version **3.10.2**. --- Modules/Filtering/PolarTransform/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Modules/Filtering/PolarTransform/CMakeLists.txt b/Modules/Filtering/PolarTransform/CMakeLists.txt index fe8ee73cbe95..24fe943fdf64 100644 --- a/Modules/Filtering/PolarTransform/CMakeLists.txt +++ b/Modules/Filtering/PolarTransform/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.9.5) +cmake_minimum_required(VERSION 3.10.2) project(PolarTransform) itk_module_impl() From d03cccb256b2093aa0410cca10260927c274f593 Mon Sep 17 00:00:00 2001 From: Roman Grothausmann Date: Wed, 19 Feb 2020 12:06:23 +0100 Subject: [PATCH 24/46] COMP: replace itkExceptionObject.h with itkMacro.h: find -type f -exec sed -i s/itkExceptionObject/itkMacro/g {} \; to avoid: itkExceptionObject.h:19:4: error: #error "Do not include itkExceptionObject.h directly, include itkMacro.h instead." --- .../PolarTransform/include/itkCartesianToPolarTransform.h | 2 +- .../PolarTransform/include/itkPolarToCartesianTransform.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Modules/Filtering/PolarTransform/include/itkCartesianToPolarTransform.h b/Modules/Filtering/PolarTransform/include/itkCartesianToPolarTransform.h index 43c9cdc4206e..00b3ce7bd91b 100644 --- a/Modules/Filtering/PolarTransform/include/itkCartesianToPolarTransform.h +++ b/Modules/Filtering/PolarTransform/include/itkCartesianToPolarTransform.h @@ -20,7 +20,7 @@ #include #include "itkTransform.h" -#include "itkExceptionObject.h" +#include "itkMacro.h" #include "itkMatrix.h" namespace itk diff --git a/Modules/Filtering/PolarTransform/include/itkPolarToCartesianTransform.h b/Modules/Filtering/PolarTransform/include/itkPolarToCartesianTransform.h index 271bbabe87dc..6e55d2afd29c 100644 --- a/Modules/Filtering/PolarTransform/include/itkPolarToCartesianTransform.h +++ b/Modules/Filtering/PolarTransform/include/itkPolarToCartesianTransform.h @@ -20,7 +20,7 @@ #include #include "itkTransform.h" -#include "itkExceptionObject.h" +#include "itkMacro.h" #include "itkMatrix.h" namespace itk From 8c0e1aa55251bce7692a8d78bd4ce05030f170b5 Mon Sep 17 00:00:00 2001 From: Roman Grothausmann Date: Wed, 19 Feb 2020 13:23:17 +0100 Subject: [PATCH 25/46] ENH: option to use arc increment instead of constant angular increment --- .../include/itkCartesianToPolarTransform.h | 9 +++++++++ .../include/itkCartesianToPolarTransform.hxx | 9 +++++++-- .../include/itkPolarToCartesianTransform.h | 9 +++++++++ .../include/itkPolarToCartesianTransform.hxx | 10 ++++++++-- 4 files changed, 33 insertions(+), 4 deletions(-) diff --git a/Modules/Filtering/PolarTransform/include/itkCartesianToPolarTransform.h b/Modules/Filtering/PolarTransform/include/itkCartesianToPolarTransform.h index 00b3ce7bd91b..a3a84623f5e7 100644 --- a/Modules/Filtering/PolarTransform/include/itkCartesianToPolarTransform.h +++ b/Modules/Filtering/PolarTransform/include/itkCartesianToPolarTransform.h @@ -162,6 +162,14 @@ class ITK_TEMPLATE_EXPORT CartesianToPolarTransform : public Transform::TransformPoint(con const InputPointType vector = inputPoint - this->m_Center; - outputPoint[1] = std::sqrt(vector[0] * vector[0] + vector[1] * vector[1]); - outputPoint[0] = std::acos(vector[0] / outputPoint[1]); + outputPoint[1] = std::sqrt(vector[0] * vector[0] + vector[1] * vector[1]); // r= sqrt(x^2 + y^2) + outputPoint[0] = std::acos(vector[0] / outputPoint[1]); // alpha = acos(x/r) if (vector[1] < 0.0) { outputPoint[0] = Math::twopi - outputPoint[0]; } + if (m_ConstArcIncr) + { + outputPoint[0] *= outputPoint[1]; // arc= r*alpha + } + return outputPoint; } diff --git a/Modules/Filtering/PolarTransform/include/itkPolarToCartesianTransform.h b/Modules/Filtering/PolarTransform/include/itkPolarToCartesianTransform.h index 6e55d2afd29c..0beff3a20739 100644 --- a/Modules/Filtering/PolarTransform/include/itkPolarToCartesianTransform.h +++ b/Modules/Filtering/PolarTransform/include/itkPolarToCartesianTransform.h @@ -160,6 +160,14 @@ class ITK_TEMPLATE_EXPORT PolarToCartesianTransform : public Transform::TransformPoint(con { OutputPointType outputPoint(inputPoint); - outputPoint[0] = inputPoint[1] * std::cos(inputPoint[0]); // r*cos(alpha) - outputPoint[1] = inputPoint[1] * std::sin(inputPoint[0]); // r*sin(alpha) + double alpha = inputPoint[0]; + if (m_ConstArcIncr) + { + alpha /= inputPoint[1]; // alpha = arc/r + } + + outputPoint[0] = inputPoint[1] * std::cos(alpha); // r*cos(alpha) + outputPoint[1] = inputPoint[1] * std::sin(alpha); // r*sin(alpha) for (unsigned int ii = 0; ii < SpaceDimension; ++ii) { From 016302f77a429eeb0dd1587560a3090dc0050f06 Mon Sep 17 00:00:00 2001 From: Roman Grothausmann Date: Wed, 19 Feb 2020 17:34:17 +0100 Subject: [PATCH 26/46] ENH: option to return NaN in case alpha is outside [-pi,pi]: No changes needed for itkCartesianToPolarTransform, because acos is only defined for [0, pi] --- .../include/itkPolarToCartesianTransform.h | 9 +++++++++ .../include/itkPolarToCartesianTransform.hxx | 8 ++++++++ 2 files changed, 17 insertions(+) diff --git a/Modules/Filtering/PolarTransform/include/itkPolarToCartesianTransform.h b/Modules/Filtering/PolarTransform/include/itkPolarToCartesianTransform.h index 0beff3a20739..db2c2c4e92b4 100644 --- a/Modules/Filtering/PolarTransform/include/itkPolarToCartesianTransform.h +++ b/Modules/Filtering/PolarTransform/include/itkPolarToCartesianTransform.h @@ -168,6 +168,14 @@ class ITK_TEMPLATE_EXPORT PolarToCartesianTransform : public Transform::TransformPoint(con alpha /= inputPoint[1]; // alpha = arc/r } + if (m_ReturnNaN && (alpha < -Math::pi || Math::pi < alpha)) + { + using PointNumericTraits = NumericTraits; + outputPoint[0] = PointNumericTraits::quiet_NaN(); + outputPoint[1] = PointNumericTraits::quiet_NaN(); + return outputPoint; + } + outputPoint[0] = inputPoint[1] * std::cos(alpha); // r*cos(alpha) outputPoint[1] = inputPoint[1] * std::sin(alpha); // r*sin(alpha) From 2771d18192bc8b8c5a7950cd46d9393babe9d13f Mon Sep 17 00:00:00 2001 From: Roman Grothausmann Date: Fri, 21 Feb 2020 11:32:10 +0100 Subject: [PATCH 27/46] ENH: option for angular offset --- .../include/itkCartesianToPolarTransform.h | 12 ++++++++++-- .../include/itkCartesianToPolarTransform.hxx | 1 + .../include/itkPolarToCartesianTransform.h | 14 +++++++++++--- .../include/itkPolarToCartesianTransform.hxx | 2 ++ 4 files changed, 24 insertions(+), 5 deletions(-) diff --git a/Modules/Filtering/PolarTransform/include/itkCartesianToPolarTransform.h b/Modules/Filtering/PolarTransform/include/itkCartesianToPolarTransform.h index a3a84623f5e7..58286ddbf6b5 100644 --- a/Modules/Filtering/PolarTransform/include/itkCartesianToPolarTransform.h +++ b/Modules/Filtering/PolarTransform/include/itkCartesianToPolarTransform.h @@ -162,6 +162,13 @@ class ITK_TEMPLATE_EXPORT CartesianToPolarTransform : public Transform::TransformPoint(con outputPoint[1] = std::sqrt(vector[0] * vector[0] + vector[1] * vector[1]); // r= sqrt(x^2 + y^2) outputPoint[0] = std::acos(vector[0] / outputPoint[1]); // alpha = acos(x/r) + outputPoint[0] += m_AngleOffset; // add offset before 2*pi adjustment to keep values within [-pi,pi] if (vector[1] < 0.0) { outputPoint[0] = Math::twopi - outputPoint[0]; diff --git a/Modules/Filtering/PolarTransform/include/itkPolarToCartesianTransform.h b/Modules/Filtering/PolarTransform/include/itkPolarToCartesianTransform.h index db2c2c4e92b4..38b594d8a47e 100644 --- a/Modules/Filtering/PolarTransform/include/itkPolarToCartesianTransform.h +++ b/Modules/Filtering/PolarTransform/include/itkPolarToCartesianTransform.h @@ -160,6 +160,13 @@ class ITK_TEMPLATE_EXPORT PolarToCartesianTransform : public Transform::TransformPoint(con return outputPoint; } + alpha += m_AngleOffset; // add offset after NaN return to keep values within [-pi,pi] + outputPoint[0] = inputPoint[1] * std::cos(alpha); // r*cos(alpha) outputPoint[1] = inputPoint[1] * std::sin(alpha); // r*sin(alpha) From 84bdfa3e49bcd70f0471a416ff5cd09064c6319b Mon Sep 17 00:00:00 2001 From: Hans Johnson Date: Sun, 16 Feb 2020 10:50:46 -0600 Subject: [PATCH 28/46] COMP: Enable building without python. --- .../PolarTransform/test/CMakeLists.txt | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/Modules/Filtering/PolarTransform/test/CMakeLists.txt b/Modules/Filtering/PolarTransform/test/CMakeLists.txt index a6c8d09960bc..0b5ab93f4739 100644 --- a/Modules/Filtering/PolarTransform/test/CMakeLists.txt +++ b/Modules/Filtering/PolarTransform/test/CMakeLists.txt @@ -11,11 +11,13 @@ itk_add_test( itkPolarTransformTest ) -itk_python_expression_add_test( - NAME itkPolarToCartesianTransformPythonTest - EXPRESSION "instance = itk.PolarToCartesianTransform.New()" -) -itk_python_expression_add_test( - NAME itkCartesianToPolarTransformPythonTest - EXPRESSION "instance = itk.CartesianToPolarTransform.New()" -) +if(ITK_WRAP_PYTHON) + itk_python_expression_add_test( + NAME itkPolarToCartesianTransformPythonTest + EXPRESSION "instance = itk.PolarToCartesianTransform.New()" + ) + itk_python_expression_add_test( + NAME itkCartesianToPolarTransformPythonTest + EXPRESSION "instance = itk.CartesianToPolarTransform.New()" + ) +endif() From 39f40bff9d8a09806d8ee6f3a1d93c435b318a55 Mon Sep 17 00:00:00 2001 From: Hans Johnson Date: Mon, 17 Feb 2020 14:29:56 -0600 Subject: [PATCH 29/46] STYLE: Prefer = default to explicitly trivial implementations This check replaces default bodies of special member functions with = default;. The explicitly defaulted function declarations enable more opportunities in optimization, because the compiler might treat explicitly defaulted functions as trivial. Additionally, the C++11 use of = default more clearly expreses the intent for the special member functions. --- .../PolarTransform/include/itkCartesianToPolarTransform.hxx | 3 +-- .../PolarTransform/include/itkPolarToCartesianTransform.hxx | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/Modules/Filtering/PolarTransform/include/itkCartesianToPolarTransform.hxx b/Modules/Filtering/PolarTransform/include/itkCartesianToPolarTransform.hxx index 0b6268749240..4aee83980c03 100644 --- a/Modules/Filtering/PolarTransform/include/itkCartesianToPolarTransform.hxx +++ b/Modules/Filtering/PolarTransform/include/itkCartesianToPolarTransform.hxx @@ -33,8 +33,7 @@ CartesianToPolarTransform::CartesianToPolarTr template -CartesianToPolarTransform::~CartesianToPolarTransform() -{} +CartesianToPolarTransform::~CartesianToPolarTransform() = default; template diff --git a/Modules/Filtering/PolarTransform/include/itkPolarToCartesianTransform.hxx b/Modules/Filtering/PolarTransform/include/itkPolarToCartesianTransform.hxx index 16ab9836d07e..1195fa3d2321 100644 --- a/Modules/Filtering/PolarTransform/include/itkPolarToCartesianTransform.hxx +++ b/Modules/Filtering/PolarTransform/include/itkPolarToCartesianTransform.hxx @@ -32,8 +32,7 @@ PolarToCartesianTransform::PolarToCartesianTr template -PolarToCartesianTransform::~PolarToCartesianTransform() -{} +PolarToCartesianTransform::~PolarToCartesianTransform() = default; template From 453ddff7344743b5d854bb82a95a39263b16c33f Mon Sep 17 00:00:00 2001 From: Hans Johnson Date: Wed, 19 Feb 2020 10:45:26 -0600 Subject: [PATCH 30/46] DOC: Update copyright assignment to NumFOCUS The mission of NumFOCUS is to promote open practices in research, data, and scientific computing. https://numfocus.org --- .../PolarTransform/include/itkCartesianToPolarTransform.h | 2 +- .../PolarTransform/include/itkCartesianToPolarTransform.hxx | 2 +- .../PolarTransform/include/itkPolarToCartesianTransform.h | 2 +- .../PolarTransform/include/itkPolarToCartesianTransform.hxx | 2 +- Modules/Filtering/PolarTransform/test/itkPolarTransformTest.cxx | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Modules/Filtering/PolarTransform/include/itkCartesianToPolarTransform.h b/Modules/Filtering/PolarTransform/include/itkCartesianToPolarTransform.h index 58286ddbf6b5..407ec3b9fdb2 100644 --- a/Modules/Filtering/PolarTransform/include/itkCartesianToPolarTransform.h +++ b/Modules/Filtering/PolarTransform/include/itkCartesianToPolarTransform.h @@ -1,6 +1,6 @@ /*========================================================================= * - * Copyright Insight Software Consortium + * Copyright NumFOCUS * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/Modules/Filtering/PolarTransform/include/itkCartesianToPolarTransform.hxx b/Modules/Filtering/PolarTransform/include/itkCartesianToPolarTransform.hxx index 4aee83980c03..cf67d6f2d2cf 100644 --- a/Modules/Filtering/PolarTransform/include/itkCartesianToPolarTransform.hxx +++ b/Modules/Filtering/PolarTransform/include/itkCartesianToPolarTransform.hxx @@ -1,6 +1,6 @@ /*========================================================================= * - * Copyright Insight Software Consortium + * Copyright NumFOCUS * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/Modules/Filtering/PolarTransform/include/itkPolarToCartesianTransform.h b/Modules/Filtering/PolarTransform/include/itkPolarToCartesianTransform.h index 38b594d8a47e..7e6def53ef15 100644 --- a/Modules/Filtering/PolarTransform/include/itkPolarToCartesianTransform.h +++ b/Modules/Filtering/PolarTransform/include/itkPolarToCartesianTransform.h @@ -1,6 +1,6 @@ /*========================================================================= * - * Copyright Insight Software Consortium + * Copyright NumFOCUS * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/Modules/Filtering/PolarTransform/include/itkPolarToCartesianTransform.hxx b/Modules/Filtering/PolarTransform/include/itkPolarToCartesianTransform.hxx index 1195fa3d2321..f605081b5940 100644 --- a/Modules/Filtering/PolarTransform/include/itkPolarToCartesianTransform.hxx +++ b/Modules/Filtering/PolarTransform/include/itkPolarToCartesianTransform.hxx @@ -1,6 +1,6 @@ /*========================================================================= * - * Copyright Insight Software Consortium + * Copyright NumFOCUS * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/Modules/Filtering/PolarTransform/test/itkPolarTransformTest.cxx b/Modules/Filtering/PolarTransform/test/itkPolarTransformTest.cxx index f2bf79daf810..c22c3e1aca97 100644 --- a/Modules/Filtering/PolarTransform/test/itkPolarTransformTest.cxx +++ b/Modules/Filtering/PolarTransform/test/itkPolarTransformTest.cxx @@ -1,6 +1,6 @@ /*========================================================================= * - * Copyright Insight Software Consortium + * Copyright NumFOCUS * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. From 285a28f13458008fb7f36df4f12ef0788ca112cb Mon Sep 17 00:00:00 2001 From: Mathew Seng Date: Wed, 14 Oct 2020 12:03:07 -0500 Subject: [PATCH 31/46] STYLE: Rename ITK_DISALLOW_COPY_AND_ASSIGN to ITK_DISALLOW_COPY_AND_MOVE Fixes changes made in #2053. ITK_DISALLOW_COPY_AND_ASSIGN will be used if ITK_FUTURE_LEGACY_REMOVE=OFF. --- .../PolarTransform/include/itkCartesianToPolarTransform.h | 2 +- .../PolarTransform/include/itkPolarToCartesianTransform.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Modules/Filtering/PolarTransform/include/itkCartesianToPolarTransform.h b/Modules/Filtering/PolarTransform/include/itkCartesianToPolarTransform.h index 407ec3b9fdb2..8dc7377895e0 100644 --- a/Modules/Filtering/PolarTransform/include/itkCartesianToPolarTransform.h +++ b/Modules/Filtering/PolarTransform/include/itkCartesianToPolarTransform.h @@ -58,7 +58,7 @@ template { public: - ITK_DISALLOW_COPY_AND_ASSIGN(CartesianToPolarTransform); + ITK_DISALLOW_COPY_AND_MOVE(CartesianToPolarTransform); /** Standard class type alias. */ using Self = CartesianToPolarTransform; diff --git a/Modules/Filtering/PolarTransform/include/itkPolarToCartesianTransform.h b/Modules/Filtering/PolarTransform/include/itkPolarToCartesianTransform.h index 7e6def53ef15..dfd41f14537d 100644 --- a/Modules/Filtering/PolarTransform/include/itkPolarToCartesianTransform.h +++ b/Modules/Filtering/PolarTransform/include/itkPolarToCartesianTransform.h @@ -56,7 +56,7 @@ template { public: - ITK_DISALLOW_COPY_AND_ASSIGN(PolarToCartesianTransform); + ITK_DISALLOW_COPY_AND_MOVE(PolarToCartesianTransform); /** Standard class type alias. */ using Self = PolarToCartesianTransform; From a06dbdf625e3fad6a666900639577f165d2f4f70 Mon Sep 17 00:00:00 2001 From: Hans Johnson Date: Fri, 17 Dec 2021 09:41:04 -0600 Subject: [PATCH 32/46] COMP: Remove inclusion of .hxx files as headers The ability to include either .h or .hxx files as header files required recursively reading the .h files twice. The added complexity is unnecessary, costly, and can confuse static analysis tools that monitor header guardes (due to reaching the maximum depth of recursion limits for nested #ifdefs in checking). --- .../PolarTransform/include/itkCartesianToPolarTransform.hxx | 1 - .../PolarTransform/include/itkPolarToCartesianTransform.hxx | 1 - 2 files changed, 2 deletions(-) diff --git a/Modules/Filtering/PolarTransform/include/itkCartesianToPolarTransform.hxx b/Modules/Filtering/PolarTransform/include/itkCartesianToPolarTransform.hxx index cf67d6f2d2cf..109e3bc269ea 100644 --- a/Modules/Filtering/PolarTransform/include/itkCartesianToPolarTransform.hxx +++ b/Modules/Filtering/PolarTransform/include/itkCartesianToPolarTransform.hxx @@ -18,7 +18,6 @@ #ifndef itkCartesianToPolarTransform_hxx #define itkCartesianToPolarTransform_hxx -#include "itkCartesianToPolarTransform.h" #include "itkMath.h" namespace itk diff --git a/Modules/Filtering/PolarTransform/include/itkPolarToCartesianTransform.hxx b/Modules/Filtering/PolarTransform/include/itkPolarToCartesianTransform.hxx index f605081b5940..70160eee1e3a 100644 --- a/Modules/Filtering/PolarTransform/include/itkPolarToCartesianTransform.hxx +++ b/Modules/Filtering/PolarTransform/include/itkPolarToCartesianTransform.hxx @@ -18,7 +18,6 @@ #ifndef itkPolarToCartesianTransform_hxx #define itkPolarToCartesianTransform_hxx -#include "itkPolarToCartesianTransform.h" namespace itk { From cb86db60582d43ce7067d7a1e8bd63a4cbdc30d5 Mon Sep 17 00:00:00 2001 From: Hans Johnson Date: Fri, 17 Dec 2021 12:26:00 -0600 Subject: [PATCH 33/46] STYLE: Prefer itk::Math::abs for consistency. --- .../PolarTransform/test/itkPolarTransformTest.cxx | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Modules/Filtering/PolarTransform/test/itkPolarTransformTest.cxx b/Modules/Filtering/PolarTransform/test/itkPolarTransformTest.cxx index c22c3e1aca97..34e4af9926fb 100644 --- a/Modules/Filtering/PolarTransform/test/itkPolarTransformTest.cxx +++ b/Modules/Filtering/PolarTransform/test/itkPolarTransformTest.cxx @@ -58,7 +58,7 @@ itkPolarTransformTest(int, char *[]) tmp = p2c->TransformPoint(p); for (unsigned int i = 0; i < Dimension; ++i) { - if (std::abs(tmp[i] - c[i]) > epsilon) + if (itk::Math::abs(tmp[i] - c[i]) > epsilon) { return EXIT_FAILURE; } @@ -68,7 +68,7 @@ itkPolarTransformTest(int, char *[]) tmp = c2p->TransformPoint(c); for (unsigned int i = 0; i < Dimension; ++i) { - if (std::abs(tmp[i] - p[i]) > epsilon) + if (itk::Math::abs(tmp[i] - p[i]) > epsilon) { std::cout << "Invalid cartesian to polar computed." << std::endl; return EXIT_FAILURE; @@ -79,7 +79,7 @@ itkPolarTransformTest(int, char *[]) tmp = c2p->TransformPoint(p2c->TransformPoint(p)); for (unsigned int i = 0; i < Dimension; ++i) { - if (std::abs(tmp[i] - p[i]) > epsilon) + if (itk::Math::abs(tmp[i] - p[i]) > epsilon) { std::cout << "Invalid polar to cartesian and back computed." << std::endl; return EXIT_FAILURE; @@ -90,7 +90,7 @@ itkPolarTransformTest(int, char *[]) tmp = p2c->TransformPoint(c2p->TransformPoint(c)); for (unsigned int i = 0; i < Dimension; ++i) { - if (std::abs(tmp[i] - c[i]) > epsilon) + if (itk::Math::abs(tmp[i] - c[i]) > epsilon) { std::cout << "Invalid cartesian to polar and back computed." << std::endl; return EXIT_FAILURE; From 3890184623586a75473915f94e6c7d15aa7ff54f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jon=20Haitz=20Legarreta=20Gorro=C3=B1o?= Date: Wed, 5 Feb 2025 21:15:55 -0500 Subject: [PATCH 34/46] STYLE: Prefer using `https` instead of `http` in copyright notice Prefer using `https` instead of `http` in copyright notice license link. Changed in InsightSoftwareConsortium/ITK#3428 Fixes: ``` /home/runner/work/ITKPolarTransform/ITKPolarTransform/include/itkCartesianToPolarTransform.h:9: error: Header mismatch: ://www.apache.org/licenses/LICENSE-2.0.txt (s://www.apache.org/licenses/LICENSE-2.0.txt) : Utilities/KWStyle/ITKHeader.h /home/runner/work/ITKPolarTransform/ITKPolarTransform/include/itkCartesianToPolarTransform.hxx:9: error: Header mismatch: ://www.apache.org/licenses/LICENSE-2.0.txt (s://www.apache.org/licenses/LICENSE-2.0.txt) : Utilities/KWStyle/ITKHeader.h /home/runner/work/ITKPolarTransform/ITKPolarTransform/include/itkPolarToCartesianTransform.h:9: error: Header mismatch: ://www.apache.org/licenses/LICENSE-2.0.txt (s://www.apache.org/licenses/LICENSE-2.0.txt) : Utilities/KWStyle/ITKHeader.h /home/runner/work/ITKPolarTransform/ITKPolarTransform/include/itkPolarToCartesianTransform.hxx:9: error: Header mismatch: ://www.apache.org/licenses/LICENSE-2.0.txt (s://www.apache.org/licenses/LICENSE-2.0.txt) : Utilities/KWStyle/ITKHeader.h /home/runner/work/ITKPolarTransform/ITKPolarTransform/test/itkPolarTransformTest.cxx:9: error: Header mismatch: ://www.apache.org/licenses/LICENSE-2.0.txt (s://www.apache.org/licenses/LICENSE-2.0.txt) : Utilities/KWStyle/ITKHeader.h ``` raised for example in: https://github.com/InsightSoftwareConsortium/ITKPolarTransform/actions/runs/13094200407/job/36534462910#step:14:60 --- .../PolarTransform/include/itkCartesianToPolarTransform.h | 2 +- .../PolarTransform/include/itkCartesianToPolarTransform.hxx | 2 +- .../PolarTransform/include/itkPolarToCartesianTransform.h | 2 +- .../PolarTransform/include/itkPolarToCartesianTransform.hxx | 2 +- Modules/Filtering/PolarTransform/test/itkPolarTransformTest.cxx | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Modules/Filtering/PolarTransform/include/itkCartesianToPolarTransform.h b/Modules/Filtering/PolarTransform/include/itkCartesianToPolarTransform.h index 8dc7377895e0..a4b80e6d7095 100644 --- a/Modules/Filtering/PolarTransform/include/itkCartesianToPolarTransform.h +++ b/Modules/Filtering/PolarTransform/include/itkCartesianToPolarTransform.h @@ -6,7 +6,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0.txt + * 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, diff --git a/Modules/Filtering/PolarTransform/include/itkCartesianToPolarTransform.hxx b/Modules/Filtering/PolarTransform/include/itkCartesianToPolarTransform.hxx index 109e3bc269ea..047c5dce70f3 100644 --- a/Modules/Filtering/PolarTransform/include/itkCartesianToPolarTransform.hxx +++ b/Modules/Filtering/PolarTransform/include/itkCartesianToPolarTransform.hxx @@ -6,7 +6,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0.txt + * 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, diff --git a/Modules/Filtering/PolarTransform/include/itkPolarToCartesianTransform.h b/Modules/Filtering/PolarTransform/include/itkPolarToCartesianTransform.h index dfd41f14537d..c5de1e3dbef4 100644 --- a/Modules/Filtering/PolarTransform/include/itkPolarToCartesianTransform.h +++ b/Modules/Filtering/PolarTransform/include/itkPolarToCartesianTransform.h @@ -6,7 +6,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0.txt + * 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, diff --git a/Modules/Filtering/PolarTransform/include/itkPolarToCartesianTransform.hxx b/Modules/Filtering/PolarTransform/include/itkPolarToCartesianTransform.hxx index 70160eee1e3a..f7b5f0a2e2bb 100644 --- a/Modules/Filtering/PolarTransform/include/itkPolarToCartesianTransform.hxx +++ b/Modules/Filtering/PolarTransform/include/itkPolarToCartesianTransform.hxx @@ -6,7 +6,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0.txt + * 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, diff --git a/Modules/Filtering/PolarTransform/test/itkPolarTransformTest.cxx b/Modules/Filtering/PolarTransform/test/itkPolarTransformTest.cxx index 34e4af9926fb..edbd46f99068 100644 --- a/Modules/Filtering/PolarTransform/test/itkPolarTransformTest.cxx +++ b/Modules/Filtering/PolarTransform/test/itkPolarTransformTest.cxx @@ -6,7 +6,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0.txt + * 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, From 40039855ea26229b252b2aaeb578654c8902d682 Mon Sep 17 00:00:00 2001 From: Tom Birdsong Date: Tue, 31 May 2022 11:54:00 -0400 Subject: [PATCH 35/46] ENH: Bump ITK and replace http with https using script --- Modules/Filtering/PolarTransform/LICENSE | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Modules/Filtering/PolarTransform/LICENSE b/Modules/Filtering/PolarTransform/LICENSE index d64569567334..62589edd12a3 100644 --- a/Modules/Filtering/PolarTransform/LICENSE +++ b/Modules/Filtering/PolarTransform/LICENSE @@ -1,7 +1,7 @@ Apache License Version 2.0, January 2004 - http://www.apache.org/licenses/ + https://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION @@ -193,7 +193,7 @@ you may not use this file except in compliance with the License. You may obtain a copy of the License at - http://www.apache.org/licenses/LICENSE-2.0 + https://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, From fb900f2a4a6c056a3ab45b245f325c0b322d95d0 Mon Sep 17 00:00:00 2001 From: Hans Johnson Date: Sun, 26 Jan 2025 09:00:12 -0600 Subject: [PATCH 36/46] STYLE: Add itkVirtualGetNameOfClassMacro + itkOverrideGetNameOfClassMacro Added two new macro's, intended to replace the old 'itkTypeMacro' and 'itkTypeMacroNoParent'. The main aim is to be clearer about what those macro's do: add a virtual 'GetNameOfClass()' member function and override it. Unlike 'itkTypeMacro', 'itkOverrideGetNameOfClassMacro' does not have a 'superclass' parameter, as it was not used anyway. Note that originally 'itkTypeMacro' did not use its 'superclass' parameter either, looking at commit 699b66cb04d410e555656828e8892107add38ccb, Will Schroeder, June 27, 2001: https://github.com/InsightSoftwareConsortium/ITK/blob/699b66cb04d410e555656828e8892107add38ccb/Code/Common/itkMacro.h#L331-L337 --- .../PolarTransform/include/itkCartesianToPolarTransform.h | 2 +- .../PolarTransform/include/itkPolarToCartesianTransform.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Modules/Filtering/PolarTransform/include/itkCartesianToPolarTransform.h b/Modules/Filtering/PolarTransform/include/itkCartesianToPolarTransform.h index a4b80e6d7095..4cb997c61780 100644 --- a/Modules/Filtering/PolarTransform/include/itkCartesianToPolarTransform.h +++ b/Modules/Filtering/PolarTransform/include/itkCartesianToPolarTransform.h @@ -70,7 +70,7 @@ class ITK_TEMPLATE_EXPORT CartesianToPolarTransform : public Transform Date: Sun, 26 Jan 2025 10:54:57 -0600 Subject: [PATCH 37/46] STYLE: Replace itkStaticConstMacro with static constexpr Use static constexpr directly now that C++11 conformance is required by all compilers. :%s/itkStaticConstMacro *( *\([^,]*\),[ \_s]*\([^,]*\),\_s*\([^)]*\)) */static constexpr \2 \1 = \3/ge 'itkStaticConstMacro(name, type, value)' became unconditionally identical to 'static constexpr type name = value' with ITK commit 4b8692634063038eb3845343cf55d408a75b9405 "ENH: Update compiler macros (#810)", maekclena, 7 May 2019. 'itkGetStaticConstMacro(name)' became unconditionally identical to '(Self::name)' with ITK commit 84e490b81e3f3c2b0edb89ae7b9de53bfc52f2b2 "Removing some outdated compiler conditionals", Hans Johnson, 31 July 2010. Most 'itkStaticConstMacro' calls were removed by ITK commit 70e34ee82ce2229ddbd151db081a0641ac729115 --- .../include/itkCartesianToPolarTransform.h | 16 ++++++++-------- .../include/itkPolarToCartesianTransform.h | 16 ++++++++-------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/Modules/Filtering/PolarTransform/include/itkCartesianToPolarTransform.h b/Modules/Filtering/PolarTransform/include/itkCartesianToPolarTransform.h index 4cb997c61780..1be4b3289427 100644 --- a/Modules/Filtering/PolarTransform/include/itkCartesianToPolarTransform.h +++ b/Modules/Filtering/PolarTransform/include/itkCartesianToPolarTransform.h @@ -86,20 +86,20 @@ class ITK_TEMPLATE_EXPORT CartesianToPolarTransform : public Transform; - using OutputVectorType = Vector; + using InputVectorType = Vector; + using OutputVectorType = Vector; /** Standard covariant vector type for this class. */ - using InputCovariantVectorType = CovariantVector; - using OutputCovariantVectorType = CovariantVector; + using InputCovariantVectorType = CovariantVector; + using OutputCovariantVectorType = CovariantVector; /** Standard vnl_vector type for this class. */ - using InputVnlVectorType = vnl_vector_fixed; - using OutputVnlVectorType = vnl_vector_fixed; + using InputVnlVectorType = vnl_vector_fixed; + using OutputVnlVectorType = vnl_vector_fixed; /** Standard coordinate point type for this class. */ - using InputPointType = Point; - using OutputPointType = Point; + using InputPointType = Point; + using OutputPointType = Point; /** Method to transform a point. * This method transforms first two dimensions of a point from cartesian diff --git a/Modules/Filtering/PolarTransform/include/itkPolarToCartesianTransform.h b/Modules/Filtering/PolarTransform/include/itkPolarToCartesianTransform.h index c7f199e18ad5..d841bc35548f 100644 --- a/Modules/Filtering/PolarTransform/include/itkPolarToCartesianTransform.h +++ b/Modules/Filtering/PolarTransform/include/itkPolarToCartesianTransform.h @@ -84,20 +84,20 @@ class ITK_TEMPLATE_EXPORT PolarToCartesianTransform : public Transform; - using OutputVectorType = Vector; + using InputVectorType = Vector; + using OutputVectorType = Vector; /** Standard covariant vector type for this class. */ - using InputCovariantVectorType = CovariantVector; - using OutputCovariantVectorType = CovariantVector; + using InputCovariantVectorType = CovariantVector; + using OutputCovariantVectorType = CovariantVector; /** Standard vnl_vector type for this class. */ - using InputVnlVectorType = vnl_vector_fixed; - using OutputVnlVectorType = vnl_vector_fixed; + using InputVnlVectorType = vnl_vector_fixed; + using OutputVnlVectorType = vnl_vector_fixed; /** Standard coordinate point type for this class. */ - using InputPointType = Point; - using OutputPointType = Point; + using InputPointType = Point; + using OutputPointType = Point; /** Method to transform a point. * This method transforms first two dimensions of a point from polar From 9f551ba7a123a5fe09bbbd8f91d06969f253a4a9 Mon Sep 17 00:00:00 2001 From: "Hans J. Johnson" Date: Sun, 12 Apr 2026 21:13:23 -0500 Subject: [PATCH 38/46] BUG: Fix Vector-to-Point implicit conversion in CartesianToPolarTransform In recent ITK versions, the implicit conversion from itk::Vector to itk::Point was removed. Point::operator-(Point) returns a VectorType, not a PointType, so the local variable must be declared as InputVectorType rather than InputPointType. itkCartesianToPolarTransform.hxx:53 - const InputPointType vector = inputPoint - this->m_Center; + const InputVectorType vector = inputPoint - this->m_Center; Co-Authored-By: Claude Opus 4.6 (1M context) --- .../PolarTransform/include/itkCartesianToPolarTransform.hxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Modules/Filtering/PolarTransform/include/itkCartesianToPolarTransform.hxx b/Modules/Filtering/PolarTransform/include/itkCartesianToPolarTransform.hxx index 047c5dce70f3..e053547da14a 100644 --- a/Modules/Filtering/PolarTransform/include/itkCartesianToPolarTransform.hxx +++ b/Modules/Filtering/PolarTransform/include/itkCartesianToPolarTransform.hxx @@ -50,7 +50,7 @@ CartesianToPolarTransform::TransformPoint(con { OutputPointType outputPoint(inputPoint); - const InputPointType vector = inputPoint - this->m_Center; + const InputVectorType vector = inputPoint - this->m_Center; outputPoint[1] = std::sqrt(vector[0] * vector[0] + vector[1] * vector[1]); // r= sqrt(x^2 + y^2) outputPoint[0] = std::acos(vector[0] / outputPoint[1]); // alpha = acos(x/r) From 1df15453c6f6debd08d1553885a7072b201666b4 Mon Sep 17 00:00:00 2001 From: "Hans J. Johnson" Date: Tue, 5 May 2026 06:52:11 -0500 Subject: [PATCH 39/46] DOC: Add PolarTransform module README pointing at archived upstream --- Modules/Filtering/PolarTransform/README.md | 40 ++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 Modules/Filtering/PolarTransform/README.md diff --git a/Modules/Filtering/PolarTransform/README.md b/Modules/Filtering/PolarTransform/README.md new file mode 100644 index 000000000000..106c3572debf --- /dev/null +++ b/Modules/Filtering/PolarTransform/README.md @@ -0,0 +1,40 @@ +# PolarTransform + +In-tree ITK module providing forward and inverse Cartesian↔polar +coordinate transforms (`itk::CartesianToPolarTransform` and +`itk::PolarToCartesianTransform`) for use in registration, resampling, +and geometric reasoning over polar / cylindrical images. + +## Origin + +Ingested from the standalone remote module +[**InsightSoftwareConsortium/ITKPolarTransform**](https://github.com/InsightSoftwareConsortium/ITKPolarTransform) +on 2026-05-05, at upstream commit +[`65b3c950`](https://github.com/InsightSoftwareConsortium/ITKPolarTransform/commit/65b3c9509a8c8570a262e02ca283e412f77bafaa). +The upstream repository will be archived read-only after this PR +merges; it remains reachable at the URL above. + +## What lives here + +Per the v4 ingestion strategy (see +`Utilities/Maintenance/RemoteModuleIngest/INGESTION_STRATEGY_v4.md`), +only paths matching the narrow whitelist +(`Utilities/Maintenance/RemoteModuleIngest/whitelists/PolarTransform.list`) +crossed the merge boundary: + +- `include/` — public C++ headers (header-only module; no `src/`). +- `test/` — CTest drivers and content-link stubs. +- `wrapping/` — Python wrapping descriptors. +- `CMakeLists.txt`, `itk-module.cmake` — module metadata. +- `LICENSE` — original Apache-2.0 license text. + +Upstream-only artifacts (CI dashboards, packaging, +`.github/`, Docker scaffolding, `pyproject.toml`, etc.) were +explicitly excluded; the upstream commit graph and authorship history +are otherwise preserved through a `--no-ff --allow-unrelated-histories` +Mode-A merge. + +## Building + +PolarTransform is enabled by default once `Module_PolarTransform=ON` +is set; in CI it is enabled via `pixi.toml`'s `configure-ci` task. From d1cb157e2d6b39ab499100a8d32476a2a9e05108 Mon Sep 17 00:00:00 2001 From: "Hans J. Johnson" Date: Tue, 5 May 2026 06:52:14 -0500 Subject: [PATCH 40/46] COMP: Remove PolarTransform remote-fetch cmake (now in-tree) The module now lives under Modules/Filtering/PolarTransform/. Drop the configure-time fetch entry; consumers enable the module via Module_PolarTransform=ON like any other in-tree module. --- Modules/Remote/PolarTransform.remote.cmake | 59 ---------------------- 1 file changed, 59 deletions(-) delete mode 100644 Modules/Remote/PolarTransform.remote.cmake diff --git a/Modules/Remote/PolarTransform.remote.cmake b/Modules/Remote/PolarTransform.remote.cmake deleted file mode 100644 index dd03dfd5aba3..000000000000 --- a/Modules/Remote/PolarTransform.remote.cmake +++ /dev/null @@ -1,59 +0,0 @@ -#-- # Grading Level Criteria Report -#-- EVALUATION DATE: 2020-03-01 -#-- EVALUATORS: [<>,<>] -#-- -#-- ## Compliance level 5 star (AKA ITK main modules, or remote modules that could become core modules) -#-- - [ ] Widespread community dependance -#-- - [ ] Above 90% code coverage -#-- - [ ] CI dashboards and testing monitored rigorously -#-- - [ ] Key API features are exposed in wrapping interface -#-- - [ ] All requirements of Levels 4,3,2,1 -#-- -#-- ## Compliance Level 4 star (Very high-quality code, perhaps small community dependance) -#-- - [ ] Meets all ITK code style standards -#-- - [ ] No external requirements beyond those needed by ITK proper -#-- - [ ] Builds and passes tests on all supported platforms within 1 month of each core tagged release -#-- - [ ] Windows Shared Library Build with Visual Studio -#-- - [ ] Mac with clang compiller -#-- - [ ] Linux with gcc compiler -#-- - [ ] Active developer community dedicated to maintaining code-base -#-- - [ ] 75% code coverage demonstrated for testing suite -#-- - [ ] Continuous integration testing performed -#-- - [ ] All requirements of Levels 3,2,1 -#-- -#-- ## Compliance Level 3 star (Quality beta code) -#-- - [ ] API | executable interface is considered mostly stable and feature complete -#-- - [ ] 10% C0-code coverage demonstrated for testing suite -#-- - [ ] Some tests exist and pass on at least some platform -#-- - [X] All requirements of Levels 2,1 -#-- -#-- ## Compliance Level 2 star (Alpha code feature API development or niche community/execution environment dependance ) -#-- - [X] Compiles for at least 1 niche set of execution envirionments, and perhaps others -#-- (may depend on specific external tools like a java environment, or specific external libraries to work ) -#-- - [X] All requirements of Levels 1 -#-- -#-- ## Compliance Level 1 star (Pre-alpha features under development and code of unknown quality) -#-- - [X] Code complies on at least 1 platform -#-- -#-- ## Compliance Level 0 star ( Code/Feature of known poor-quality or deprecated status ) -#-- - [ ] Code reviewed and explicitly identified as not recommended for use -#-- -#-- ### Please document here any justification for the criteria above -# Code style enforced by clang-format on 2020-02-19, and clang-tidy modernizations completed - -# Contact: Matt McCormick -itk_fetch_module( - PolarTransform - "This is a module to transform from cartesian to polar coordinate systems and back. - -For more information, see the Insight Journal article: - - Bican J. - Polar Transforms for ITK - The Insight Journal. July-December. 2006. - https://doi.org/10.54294/t8t3j2 - " - MODULE_COMPLIANCE_LEVEL 2 - GIT_REPOSITORY https://github.com/InsightSoftwareConsortium/ITKPolarTransform.git - GIT_TAG 6967f9bebbc28af8c8983f9130b8663e0b3aac60 - ) From 2f27b54dce6cb6af42377959b7c2317500bff28f Mon Sep 17 00:00:00 2001 From: "Hans J. Johnson" Date: Tue, 5 May 2026 06:52:47 -0500 Subject: [PATCH 41/46] ENH: Enable Module_PolarTransform in configure-ci pixi task Now that PolarTransform is in-tree under Modules/Filtering/PolarTransform/, exercise it on every pixi configure-ci run (Linux / macOS / Windows GitHub Actions matrix). --- pyproject.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/pyproject.toml b/pyproject.toml index 9f1dd62bf5ba..5cf81f247832 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -61,6 +61,7 @@ cmd = '''cmake -DModule_LabelErodeDilate:BOOL=ON -DModule_MeshNoise:BOOL=ON -DModule_MGHIO:BOOL=ON + -DModule_PolarTransform:BOOL=ON -DModule_SplitComponents:BOOL=ON -DModule_IOMeshMZ3:BOOL=ON -DModule_IOFDF:BOOL=ON From 1807367d112d0e5adb8cf8231db3ca732997b06b Mon Sep 17 00:00:00 2001 From: "Hans J. Johnson" Date: Tue, 5 May 2026 11:27:25 -0500 Subject: [PATCH 42/46] COMP: Drop dead cmake_minimum_required from PolarTransform CMakeLists In-tree, ITK's top-level CMakeLists pins the CMake minimum, so the per-module declaration is dead code. Matches the v4 ingest-pipeline rule in PR #6204 (sanitize-history.py:patch_drop_cmake_minimum_required). --- Modules/Filtering/PolarTransform/CMakeLists.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/Modules/Filtering/PolarTransform/CMakeLists.txt b/Modules/Filtering/PolarTransform/CMakeLists.txt index 24fe943fdf64..a00b4028b496 100644 --- a/Modules/Filtering/PolarTransform/CMakeLists.txt +++ b/Modules/Filtering/PolarTransform/CMakeLists.txt @@ -1,4 +1,3 @@ -cmake_minimum_required(VERSION 3.10.2) project(PolarTransform) itk_module_impl() From 0dc2ce5dfeb562893e7e6e75edf25921263b3615 Mon Sep 17 00:00:00 2001 From: "Hans J. Johnson" Date: Tue, 5 May 2026 18:00:50 -0500 Subject: [PATCH 43/46] BUG: Guard division-by-zero at r=0 in CartesianToPolarTransform When inputPoint equals m_Center, vector=(0,0) so r=0, and the unguarded vector[0]/r evaluates to 0/0 (NaN), silently propagating through std::acos. Set alpha=0 in that branch since alpha is undefined at r=0. --- .../include/itkCartesianToPolarTransform.hxx | 22 +++++++++++++------ 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/Modules/Filtering/PolarTransform/include/itkCartesianToPolarTransform.hxx b/Modules/Filtering/PolarTransform/include/itkCartesianToPolarTransform.hxx index e053547da14a..2cc907e4aa6a 100644 --- a/Modules/Filtering/PolarTransform/include/itkCartesianToPolarTransform.hxx +++ b/Modules/Filtering/PolarTransform/include/itkCartesianToPolarTransform.hxx @@ -53,16 +53,24 @@ CartesianToPolarTransform::TransformPoint(con const InputVectorType vector = inputPoint - this->m_Center; outputPoint[1] = std::sqrt(vector[0] * vector[0] + vector[1] * vector[1]); // r= sqrt(x^2 + y^2) - outputPoint[0] = std::acos(vector[0] / outputPoint[1]); // alpha = acos(x/r) - outputPoint[0] += m_AngleOffset; // add offset before 2*pi adjustment to keep values within [-pi,pi] - if (vector[1] < 0.0) + if (outputPoint[1] == 0.0) { - outputPoint[0] = Math::twopi - outputPoint[0]; + // alpha is undefined at r=0; choose 0 to avoid 0/0 NaN propagating through std::acos. + outputPoint[0] = 0.0; } - - if (m_ConstArcIncr) + else { - outputPoint[0] *= outputPoint[1]; // arc= r*alpha + outputPoint[0] = std::acos(vector[0] / outputPoint[1]); // alpha = acos(x/r) + outputPoint[0] += m_AngleOffset; // add offset before 2*pi adjustment to keep values within [-pi,pi] + if (vector[1] < 0.0) + { + outputPoint[0] = Math::twopi - outputPoint[0]; + } + + if (m_ConstArcIncr) + { + outputPoint[0] *= outputPoint[1]; // arc= r*alpha + } } return outputPoint; From 09c86d36cd97519fea29e58c1f548f2f2394fb9e Mon Sep 17 00:00:00 2001 From: "Hans J. Johnson" Date: Tue, 5 May 2026 18:01:19 -0500 Subject: [PATCH 44/46] BUG: Guard division-by-zero at r=0 in PolarToCartesianTransform When ConstArcIncr is true and inputPoint[1] (radius) is 0, alpha /= 0 yields inf and downstream cos/sin(inf) is implementation-defined. Short-circuit alpha=0 in that branch since the output collapses to the center anyway. --- .../include/itkPolarToCartesianTransform.hxx | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/Modules/Filtering/PolarTransform/include/itkPolarToCartesianTransform.hxx b/Modules/Filtering/PolarTransform/include/itkPolarToCartesianTransform.hxx index f7b5f0a2e2bb..b211f7d7e5e0 100644 --- a/Modules/Filtering/PolarTransform/include/itkPolarToCartesianTransform.hxx +++ b/Modules/Filtering/PolarTransform/include/itkPolarToCartesianTransform.hxx @@ -52,7 +52,15 @@ PolarToCartesianTransform::TransformPoint(con double alpha = inputPoint[0]; if (m_ConstArcIncr) { - alpha /= inputPoint[1]; // alpha = arc/r + if (inputPoint[1] == 0.0) + { + // r=0: output collapses to the center; alpha is undefined, avoid arc/r = 0/0 or arc/0. + alpha = 0.0; + } + else + { + alpha /= inputPoint[1]; // alpha = arc/r + } } if (m_ReturnNaN && (alpha < -Math::pi || Math::pi < alpha)) From db97ae33954fed1d1236493e91092ed13254e8df Mon Sep 17 00:00:00 2001 From: "Hans J. Johnson" Date: Tue, 5 May 2026 18:02:11 -0500 Subject: [PATCH 45/46] BUG: Stop adding center to pass-through dims in PolarToCartesianTransform CartesianToPolarTransform leaves dims >= 2 as raw inputPoint values (no center subtraction), but PolarToCartesianTransform was adding m_Center to every dim including pass-through ones. The asymmetry broke round-trip when m_Center had non-zero components in dims >= 2. --- .../include/itkPolarToCartesianTransform.hxx | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/Modules/Filtering/PolarTransform/include/itkPolarToCartesianTransform.hxx b/Modules/Filtering/PolarTransform/include/itkPolarToCartesianTransform.hxx index b211f7d7e5e0..57ce37cd33ec 100644 --- a/Modules/Filtering/PolarTransform/include/itkPolarToCartesianTransform.hxx +++ b/Modules/Filtering/PolarTransform/include/itkPolarToCartesianTransform.hxx @@ -73,13 +73,9 @@ PolarToCartesianTransform::TransformPoint(con alpha += m_AngleOffset; // add offset after NaN return to keep values within [-pi,pi] - outputPoint[0] = inputPoint[1] * std::cos(alpha); // r*cos(alpha) - outputPoint[1] = inputPoint[1] * std::sin(alpha); // r*sin(alpha) - - for (unsigned int ii = 0; ii < SpaceDimension; ++ii) - { - outputPoint[ii] = this->m_Center[ii] + outputPoint[ii]; - } + // Pass-through dims (ii >= 2) keep inputPoint values to match CartesianToPolar's round-trip. + outputPoint[0] = this->m_Center[0] + inputPoint[1] * std::cos(alpha); // m_Center[0] + r*cos(alpha) + outputPoint[1] = this->m_Center[1] + inputPoint[1] * std::sin(alpha); // m_Center[1] + r*sin(alpha) return outputPoint; } From 47baab7d1855aea8cf12a40f8da6283104acb159 Mon Sep 17 00:00:00 2001 From: "Hans J. Johnson" Date: Tue, 5 May 2026 18:03:08 -0500 Subject: [PATCH 46/46] ENH: Add regression cases for r=0 and pass-through-dim center Covers the three Greptile findings on PR #6211: r=0 NaN guard (CartesianToPolar), r=0 with ConstArcIncr divide-by-zero (PolarToCartesian), and round-trip with non-zero center in pass-through dim. --- .../test/itkPolarTransformTest.cxx | 58 +++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/Modules/Filtering/PolarTransform/test/itkPolarTransformTest.cxx b/Modules/Filtering/PolarTransform/test/itkPolarTransformTest.cxx index edbd46f99068..13f3f47c72d9 100644 --- a/Modules/Filtering/PolarTransform/test/itkPolarTransformTest.cxx +++ b/Modules/Filtering/PolarTransform/test/itkPolarTransformTest.cxx @@ -18,6 +18,7 @@ #include "itkPolarToCartesianTransform.h" #include "itkCartesianToPolarTransform.h" #include "itkMath.h" +#include int itkPolarTransformTest(int, char *[]) @@ -97,5 +98,62 @@ itkPolarTransformTest(int, char *[]) } } + /* Regression: r=0 (input at center) must not produce NaN in CartesianToPolar. */ + { + itk::Point atCenter(center); + tmp = c2p->TransformPoint(atCenter); + for (unsigned int i = 0; i < Dimension; ++i) + { + if (std::isnan(tmp[i])) + { + std::cout << "NaN produced when input equals center (CartesianToPolar)." << std::endl; + return EXIT_FAILURE; + } + } + if (tmp[1] != 0.0) + { + std::cout << "r should be 0 when input equals center." << std::endl; + return EXIT_FAILURE; + } + } + + /* Regression: ConstArcIncr=true with r=0 must not divide by zero. */ + { + P2CTransformType::Pointer p2cArc = P2CTransformType::New(); + p2cArc->SetConstArcIncr(true); + itk::Point rZero; + rZero.Fill(0.0); + tmp = p2cArc->TransformPoint(rZero); + for (unsigned int i = 0; i < Dimension; ++i) + { + if (std::isnan(tmp[i]) || std::isinf(tmp[i])) + { + std::cout << "NaN/Inf produced for r=0 with ConstArcIncr (PolarToCartesian)." << std::endl; + return EXIT_FAILURE; + } + } + } + + /* Regression: round-trip through pass-through dims with non-zero center in dim >= 2. */ + { + P2CTransformType::InputPointType offsetCenter; + offsetCenter.Fill(0.0); + offsetCenter[2] = 5.0; + P2CTransformType::Pointer p2cOff = P2CTransformType::New(); + C2PTransformType::Pointer c2pOff = C2PTransformType::New(); + p2cOff->SetCenter(offsetCenter); + c2pOff->SetCenter(offsetCenter); + + tmp = p2cOff->TransformPoint(c2pOff->TransformPoint(c)); + for (unsigned int i = 0; i < Dimension; ++i) + { + if (itk::Math::abs(tmp[i] - c[i]) > epsilon) + { + std::cout << "Round-trip failed with non-zero center in pass-through dim." << std::endl; + return EXIT_FAILURE; + } + } + } + return EXIT_SUCCESS; }