From ef72833add679b4248db4ee5a90e314dc016239a Mon Sep 17 00:00:00 2001 From: "Stephen R. Aylward" Date: Thu, 30 Sep 2021 22:19:21 -0400 Subject: [PATCH] ENH: Improve radius estimation and refactor tube-to-image registration framework (#82) Radius estimation is now performed by fitting a sigmoid to the radius-vs-intensity profile. TubeToImageRegistration framework is an adaption of the ImageToImageRegistration framework used by TubeTK. It is easily extended to support additional transforms and metrics. --- .github/workflows/build-test-package.yml | 8 +- examples/Applications/CMakeLists.txt | 4 +- .../CMakeLists.txt | 36 - .../ComputeImageToTubeRigidMetricImage.cxx | 205 --- .../ComputeImageToTubeRigidMetricImage.xml | 47 - .../tubePreProcessRegistrationInputs.h | 50 - .../tubePreProcessRegistrationInputs.hxx | 176 --- .../ConvertTubesToSurface.cxx | 3 +- .../ConvertTubesToTubeTree.cxx | 3 +- .../ExtractMetricImageSlice.cxx | 104 -- .../ExtractMetricImageSlice.xml | 48 - .../Testing/CMakeLists.txt | 32 - .../ExtractMetricImageSlice/Testing/README.md | 5 - .../CMakeLists.txt | 34 - ...egisterImageToTubesUsingRigidTransform.cxx | 176 --- ...egisterImageToTubesUsingRigidTransform.xml | 55 - .../Testing/CMakeLists.txt | 53 - .../Testing/README.md | 5 - .../tubePreProcessRegistrationInputs.h | 50 - .../tubePreProcessRegistrationInputs.hxx | 176 --- .../CMakeLists.txt | 2 +- .../README.md | 0 .../RegisterSpatialObjectsToImage.cxx | 501 ++++++++ .../RegisterSpatialObjectsToImage.xml | 231 ++++ .../Testing/CMakeLists.txt | 5 +- .../Testing/README.md | 0 .../ResampleTubes/ResampleTubes.cxx | 59 +- .../ResampleTubes/Testing/CMakeLists.txt | 3 +- .../SegmentTubeUsingMinimalPath.cxx | 1 - .../SegmentTubeUsingMinimalPath.xml | 7 - examples/CTP-Head/1-GenerateCTAFromCTP.ipynb | 37 +- .../CTP-Head/2-SegmentBrainFromCTPCTA.ipynb | 32 +- .../3-CreateBinaryVesselsFromCTPCTA.ipynb | 76 +- ...SegmentVesselsUsingDiffEnhancedImage.ipynb | 43 +- ...emo-SegmentBrightVesselsFromBrainMRA.ipynb | 49 +- examples/MRA-Head/SupportingNotes.ipynb | 164 +++ include/tubeSegmentTubeUsingMinimalPath.h | 1 - include/tubeSegmentTubes.h | 16 +- setup.py | 2 +- src/Filtering.cmake | 6 +- src/Filtering/itktubeCropTubesFilter.hxx | 2 + .../itktubeLimitedMinimumMaximumImageFilter.h | 165 +++ ...tktubeLimitedMinimumMaximumImageFilter.hxx | 145 +++ ...imumSpanningTreeVesselConnectivityFilter.h | 8 +- ...umSpanningTreeVesselConnectivityFilter.hxx | 75 +- src/Filtering/itktubeResampleTubesFilter.h | 46 +- src/Filtering/itktubeResampleTubesFilter.hxx | 219 ++-- src/Filtering/itktubeSpatialObjectFilter.h | 83 ++ src/Filtering/itktubeSpatialObjectFilter.hxx | 70 + src/Filtering/itktubeSpatialObjectSource.h | 3 +- src/Filtering/itktubeSpatialObjectSource.hxx | 5 +- ...tktubeSpatialObjectToSpatialObjectFilter.h | 3 +- ...tubeSpatialObjectToSpatialObjectFilter.hxx | 7 +- .../itktubeSubSampleSpatialObjectFilter.h | 102 ++ .../itktubeSubSampleSpatialObjectFilter.hxx | 133 ++ .../itktubeSubSampleTubeSpatialObjectFilter.h | 24 +- ...tktubeSubSampleTubeSpatialObjectFilter.hxx | 30 +- ...tubeSubSampleTubeTreeSpatialObjectFilter.h | 110 -- ...beSubSampleTubeTreeSpatialObjectFilter.hxx | 143 --- src/Numerics/itktubeNJetImageFunction.h | 3 +- src/Numerics/itktubeNJetImageFunction.hxx | 2 +- src/Registration.cmake | 62 +- ...tubeSpatialObjectRegionMomentsCalculator.h | 225 ++++ ...beSpatialObjectRegionMomentsCalculator.hxx | 388 ++++++ .../itkAffineImageToImageRegistrationMethod.h | 26 +- ...tkAffineImageToImageRegistrationMethod.hxx | 29 +- .../itkAnisotropicSimilarity3DTransform.h | 26 +- .../itkAnisotropicSimilarity3DTransform.hxx | 26 +- ...ilarityLandmarkBasedTransformInitializer.h | 26 +- ...arityLandmarkBasedTransformInitializer.hxx | 26 +- ...itkBSplineImageToImageRegistrationMethod.h | 29 +- ...kBSplineImageToImageRegistrationMethod.hxx | 26 +- .../itkImageRegionMomentsCalculator.h | 26 +- .../itkImageRegionMomentsCalculator.hxx | 26 +- src/Registration/itkImageRegionSplitter.h | 37 +- src/Registration/itkImageRegionSplitter.hxx | 37 +- .../itkImageToImageRegistrationHelper.h | 29 +- .../itkImageToImageRegistrationHelper.hxx | 28 +- .../itkImageToImageRegistrationMethod.h | 29 +- .../itkImageToImageRegistrationMethod.hxx | 29 +- ...itkInitialImageToImageRegistrationMethod.h | 29 +- ...kOptimizedImageToImageRegistrationMethod.h | 29 +- ...ptimizedImageToImageRegistrationMethod.hxx | 29 +- ...kewAngle2DImageToImageRegistrationMethod.h | 26 +- ...wAngle2DImageToImageRegistrationMethod.hxx | 29 +- .../itkScaleSkewAngle2DTransform.h | 37 +- .../itkScaleSkewAngle2DTransform.hxx | 37 +- ...ewVersor3DImageToImageRegistrationMethod.h | 26 +- ...Versor3DImageToImageRegistrationMethod.hxx | 29 +- src/Registration/itkSimilarity2DTransform.h | 37 +- src/Registration/itkSimilarity2DTransform.hxx | 37 +- ...eSpatialObjectToImageRegistrationMethod.h} | 65 +- ...patialObjectToImageRegistrationMethod.hxx} | 81 +- ...beAnisotropicDiffusiveRegistrationFilter.h | 3 +- ...AnisotropicDiffusiveRegistrationFilter.hxx | 3 +- ...AnisotropicDiffusiveRegistrationFunction.h | 3 +- ...isotropicDiffusiveRegistrationFunction.hxx | 3 +- ...otropicDiffusiveSparseRegistrationFilter.h | 3 +- .../itktubeDiffusiveRegistrationFilter.h | 3 +- .../itktubeDiffusiveRegistrationFilter.hxx | 3 +- .../itktubeDiffusiveRegistrationFilterUtils.h | 3 +- ...tktubeDiffusiveRegistrationFilterUtils.hxx | 3 +- .../itktubeImageToTubeRigidMetric.h | 229 ---- .../itktubeImageToTubeRigidMetric.hxx | 662 ---------- .../itktubeImageToTubeRigidRegistration.h | 140 -- .../itktubeImageToTubeRigidRegistration.hxx | 178 --- ...alSpatialObjectToImageRegistrationMethod.h | 144 +++ ...SpatialObjectToImageRegistrationMethod.hxx | 413 ++++++ .../itktubeMeanSquareRegistrationFunction.h | 3 +- .../itktubeMeanSquareRegistrationFunction.hxx | 3 +- .../itktubeMergeAdjacentImagesFilter.h | 3 +- .../itktubeMergeAdjacentImagesFilter.hxx | 3 +- ...edSpatialObjectToImageRegistrationMethod.h | 182 +++ ...SpatialObjectToImageRegistrationMethod.hxx | 446 +++++++ ...tubePointBasedSpatialObjectToImageMetric.h | 239 ++++ ...bePointBasedSpatialObjectToImageMetric.hxx | 800 ++++++++++++ ...bePointBasedSpatialObjectTransformFilter.h | 152 +++ ...PointBasedSpatialObjectTransformFilter.hxx | 356 ++++++ ...idSpatialObjectToImageRegistrationMethod.h | 148 +++ ...SpatialObjectToImageRegistrationMethod.hxx | 214 ++++ ...2DSpatialObjectToImageRegistrationMethod.h | 143 +++ ...SpatialObjectToImageRegistrationMethod.hxx | 143 +++ ...3DSpatialObjectToImageRegistrationMethod.h | 142 +++ ...SpatialObjectToImageRegistrationMethod.hxx | 156 +++ .../itktubeSpatialObjectToImageMetric.h | 209 +++ .../itktubeSpatialObjectToImageMetric.hxx | 211 +++ ...beSpatialObjectToImageRegistrationHelper.h | 472 +++++++ ...SpatialObjectToImageRegistrationHelper.hxx | 1133 +++++++++++++++++ ...beSpatialObjectToImageRegistrationMethod.h | 185 +++ ...SpatialObjectToImageRegistrationMethod.hxx | 323 +++++ ...tktubeTubeAngleOfIncidenceWeightFunction.h | 144 --- ...eTubeExponentialResolutionWeightFunction.h | 99 -- ...etricExponentialResolutionWeightFunction.h | 124 -- ...entialWithBoundsResolutionWeightFunction.h | 131 -- .../itktubeTubePointWeightsCalculator.h | 120 -- .../itktubeTubePointWeightsCalculator.hxx | 147 --- .../itktubeTubeToTubeTransformFilter.h | 127 -- .../itktubeTubeToTubeTransformFilter.hxx | 255 ---- src/Segmentation/itktubeRadiusExtractor3.h | 59 +- src/Segmentation/itktubeRadiusExtractor3.hxx | 819 +++++++----- src/Segmentation/itktubeRidgeExtractor.hxx | 133 +- ...itktubeSegmentTubeUsingMinimalPathFilter.h | 3 - ...ktubeSegmentTubeUsingMinimalPathFilter.hxx | 3 - src/Segmentation/itktubeTubeExtractor.h | 4 + src/Segmentation/itktubeTubeExtractor.hxx | 19 +- ...onvertTubesToTubeTreeTest1-Tree.tre.sha512 | 2 +- ...onvertTubesToTubeTreeTest2-Tree.tre.sha512 | 2 +- .../CropTubes-Test1_NotCropped.tre.sha512 | 2 +- .../CropTubes-Test2_Cropped.tre.sha512 | 2 +- test/Baseline/ResampleTubesTest1.tre.sha512 | 2 +- test/Baseline/ResampleTubesTest2.tre.sha512 | 2 +- test/Baseline/ResampleTubesTest3.tre.sha512 | 2 +- test/Baseline/SegmentTubesTest1.mha.sha512 | 2 +- test/Baseline/SegmentTubesTest2.mha.sha512 | 2 +- test/Baseline/TubeMath-Test1.tre.sha512 | 2 +- test/Baseline/TubeMath-Test2.tre.sha512 | 2 +- ...edSpatialObjectTransformFilter.mha.sha512} | 0 ...edSpatialObjectTransformFilter.tre.sha512} | 0 test/Filtering/CMakeLists.txt | 8 +- ...ktubeSubSampleSpatialObjectFilterTest.cxx} | 26 +- ...beSubSampleTubeSpatialObjectFilterTest.cxx | 15 +- test/Registration/CMakeLists.txt | 92 +- ...BasedSpatialObjectTransformFilterTest.cxx} | 29 +- ...ialObjectToImageMetricPerformanceTest.cxx} | 42 +- ...itktubeSpatialObjectToImageMetricTest.cxx} | 49 +- ...ectToImageRegistrationPerformanceTest.cxx} | 107 +- ...eSpatialObjectToImageRegistrationTest.cxx} | 127 +- ...tktubeSyntheticTubeImageGenerationTest.cxx | 16 +- ...TubeAngleOfIncidenceWeightFunctionTest.cxx | 187 --- ...xponentialResolutionWeightFunctionTest.cxx | 80 -- ...xponentialResolutionWeightFunctionTest.cxx | 129 -- ...WithBoundsResolutionWeightFunctionTest.cxx | 146 --- .../itktubeTubePointWeightsCalculatorTest.cxx | 108 -- .../tubeRegistrationHeaderTest.cxx | 19 +- .../tubeRegistrationPrintTest.cxx | 13 +- .../Segmentation/itktubeTubeExtractorTest.cxx | 11 +- 176 files changed, 10226 insertions(+), 6150 deletions(-) delete mode 100644 examples/Applications/ComputeImageToTubeRigidMetricImage/CMakeLists.txt delete mode 100644 examples/Applications/ComputeImageToTubeRigidMetricImage/ComputeImageToTubeRigidMetricImage.cxx delete mode 100644 examples/Applications/ComputeImageToTubeRigidMetricImage/ComputeImageToTubeRigidMetricImage.xml delete mode 100644 examples/Applications/ComputeImageToTubeRigidMetricImage/tubePreProcessRegistrationInputs.h delete mode 100644 examples/Applications/ComputeImageToTubeRigidMetricImage/tubePreProcessRegistrationInputs.hxx delete mode 100644 examples/Applications/ExtractMetricImageSlice/ExtractMetricImageSlice.cxx delete mode 100644 examples/Applications/ExtractMetricImageSlice/ExtractMetricImageSlice.xml delete mode 100644 examples/Applications/ExtractMetricImageSlice/Testing/CMakeLists.txt delete mode 100644 examples/Applications/ExtractMetricImageSlice/Testing/README.md delete mode 100644 examples/Applications/RegisterImageToTubesUsingRigidTransform/CMakeLists.txt delete mode 100644 examples/Applications/RegisterImageToTubesUsingRigidTransform/RegisterImageToTubesUsingRigidTransform.cxx delete mode 100644 examples/Applications/RegisterImageToTubesUsingRigidTransform/RegisterImageToTubesUsingRigidTransform.xml delete mode 100644 examples/Applications/RegisterImageToTubesUsingRigidTransform/Testing/CMakeLists.txt delete mode 100644 examples/Applications/RegisterImageToTubesUsingRigidTransform/Testing/README.md delete mode 100644 examples/Applications/RegisterImageToTubesUsingRigidTransform/tubePreProcessRegistrationInputs.h delete mode 100644 examples/Applications/RegisterImageToTubesUsingRigidTransform/tubePreProcessRegistrationInputs.hxx rename examples/Applications/{ExtractMetricImageSlice => RegisterSpatialObjectsToImage}/CMakeLists.txt (95%) rename examples/Applications/{RegisterImageToTubesUsingRigidTransform => RegisterSpatialObjectsToImage}/README.md (100%) create mode 100644 examples/Applications/RegisterSpatialObjectsToImage/RegisterSpatialObjectsToImage.cxx create mode 100644 examples/Applications/RegisterSpatialObjectsToImage/RegisterSpatialObjectsToImage.xml rename examples/Applications/{ComputeImageToTubeRigidMetricImage => RegisterSpatialObjectsToImage}/Testing/CMakeLists.txt (88%) rename examples/Applications/{ComputeImageToTubeRigidMetricImage => RegisterSpatialObjectsToImage}/Testing/README.md (100%) create mode 100644 examples/MRA-Head/SupportingNotes.ipynb create mode 100644 src/Filtering/itktubeLimitedMinimumMaximumImageFilter.h create mode 100644 src/Filtering/itktubeLimitedMinimumMaximumImageFilter.hxx create mode 100644 src/Filtering/itktubeSpatialObjectFilter.h create mode 100644 src/Filtering/itktubeSpatialObjectFilter.hxx create mode 100644 src/Filtering/itktubeSubSampleSpatialObjectFilter.h create mode 100644 src/Filtering/itktubeSubSampleSpatialObjectFilter.hxx delete mode 100644 src/Filtering/itktubeSubSampleTubeTreeSpatialObjectFilter.h delete mode 100644 src/Filtering/itktubeSubSampleTubeTreeSpatialObjectFilter.hxx create mode 100644 src/Registration/Deprecated/itktubeSpatialObjectRegionMomentsCalculator.h create mode 100644 src/Registration/Deprecated/itktubeSpatialObjectRegionMomentsCalculator.hxx rename src/Registration/{itkAffine3DImageToImageRegistrationMethod.h => itktubeAffineSpatialObjectToImageRegistrationMethod.h} (60%) rename src/Registration/{itkAffine3DImageToImageRegistrationMethod.hxx => itktubeAffineSpatialObjectToImageRegistrationMethod.hxx} (53%) delete mode 100644 src/Registration/itktubeImageToTubeRigidMetric.h delete mode 100644 src/Registration/itktubeImageToTubeRigidMetric.hxx delete mode 100644 src/Registration/itktubeImageToTubeRigidRegistration.h delete mode 100644 src/Registration/itktubeImageToTubeRigidRegistration.hxx create mode 100644 src/Registration/itktubeInitialSpatialObjectToImageRegistrationMethod.h create mode 100644 src/Registration/itktubeInitialSpatialObjectToImageRegistrationMethod.hxx create mode 100644 src/Registration/itktubeOptimizedSpatialObjectToImageRegistrationMethod.h create mode 100644 src/Registration/itktubeOptimizedSpatialObjectToImageRegistrationMethod.hxx create mode 100644 src/Registration/itktubePointBasedSpatialObjectToImageMetric.h create mode 100644 src/Registration/itktubePointBasedSpatialObjectToImageMetric.hxx create mode 100644 src/Registration/itktubePointBasedSpatialObjectTransformFilter.h create mode 100644 src/Registration/itktubePointBasedSpatialObjectTransformFilter.hxx create mode 100644 src/Registration/itktubeRigidSpatialObjectToImageRegistrationMethod.h create mode 100644 src/Registration/itktubeRigidSpatialObjectToImageRegistrationMethod.hxx create mode 100644 src/Registration/itktubeScaleSkewAngle2DSpatialObjectToImageRegistrationMethod.h create mode 100644 src/Registration/itktubeScaleSkewAngle2DSpatialObjectToImageRegistrationMethod.hxx create mode 100644 src/Registration/itktubeScaleSkewVersor3DSpatialObjectToImageRegistrationMethod.h create mode 100644 src/Registration/itktubeScaleSkewVersor3DSpatialObjectToImageRegistrationMethod.hxx create mode 100644 src/Registration/itktubeSpatialObjectToImageMetric.h create mode 100644 src/Registration/itktubeSpatialObjectToImageMetric.hxx create mode 100644 src/Registration/itktubeSpatialObjectToImageRegistrationHelper.h create mode 100644 src/Registration/itktubeSpatialObjectToImageRegistrationHelper.hxx create mode 100644 src/Registration/itktubeSpatialObjectToImageRegistrationMethod.h create mode 100644 src/Registration/itktubeSpatialObjectToImageRegistrationMethod.hxx delete mode 100644 src/Registration/itktubeTubeAngleOfIncidenceWeightFunction.h delete mode 100644 src/Registration/itktubeTubeExponentialResolutionWeightFunction.h delete mode 100644 src/Registration/itktubeTubeParametricExponentialResolutionWeightFunction.h delete mode 100644 src/Registration/itktubeTubeParametricExponentialWithBoundsResolutionWeightFunction.h delete mode 100644 src/Registration/itktubeTubePointWeightsCalculator.h delete mode 100644 src/Registration/itktubeTubePointWeightsCalculator.hxx delete mode 100644 src/Registration/itktubeTubeToTubeTransformFilter.h delete mode 100644 src/Registration/itktubeTubeToTubeTransformFilter.hxx rename test/Baseline/{itktubeTubeToTubeTransformFilter.mha.sha512 => itktubePointBasedSpatialObjectTransformFilter.mha.sha512} (100%) rename test/Baseline/{itktubeTubeToTubeTransformFilter.tre.sha512 => itktubePointBasedSpatialObjectTransformFilter.tre.sha512} (100%) rename test/Filtering/{itktubeSubSampleTubeTreeSpatialObjectFilterTest.cxx => itktubeSubSampleSpatialObjectFilterTest.cxx} (76%) rename test/Registration/{itktubeTubeToTubeTransformFilterTest.cxx => itktubePointBasedSpatialObjectTransformFilterTest.cxx} (85%) rename test/Registration/{itktubeImageToTubeRigidMetricPerformanceTest.cxx => itktubeSpatialObjectToImageMetricPerformanceTest.cxx} (75%) rename test/Registration/{itktubeImageToTubeRigidMetricTest.cxx => itktubeSpatialObjectToImageMetricTest.cxx} (70%) rename test/Registration/{itktubeImageToTubeRigidRegistrationPerformanceTest.cxx => itktubeSpatialObjectToImageRegistrationPerformanceTest.cxx} (68%) rename test/Registration/{itktubeImageToTubeRigidRegistrationTest.cxx => itktubeSpatialObjectToImageRegistrationTest.cxx} (62%) delete mode 100644 test/Registration/itktubeTubeAngleOfIncidenceWeightFunctionTest.cxx delete mode 100644 test/Registration/itktubeTubeExponentialResolutionWeightFunctionTest.cxx delete mode 100644 test/Registration/itktubeTubeParametricExponentialResolutionWeightFunctionTest.cxx delete mode 100644 test/Registration/itktubeTubeParametricExponentialWithBoundsResolutionWeightFunctionTest.cxx delete mode 100644 test/Registration/itktubeTubePointWeightsCalculatorTest.cxx diff --git a/.github/workflows/build-test-package.yml b/.github/workflows/build-test-package.yml index bea9b1a58..d13ca266f 100644 --- a/.github/workflows/build-test-package.yml +++ b/.github/workflows/build-test-package.yml @@ -5,7 +5,7 @@ on: [push,pull_request] env: ITKMinimalPathExtraction-git-tag: v1.2.0 vtk-git-tag: "1681cee3489800373c2e183af2d3ca8552e05940" - itk-git-tag: v5.2.0 + itk-git-tag: v5.2.1 jobs: build-test-cxx: @@ -203,7 +203,7 @@ jobs: matrix: python-version: [36, 37, 38, 39] include: - - itk-python-git-tag: "v5.2.0.post2" + - itk-python-git-tag: "v5.2.1.post1" c-compiler: "gcc" cxx-compiler: "g++" cmake-build-type: "Release" @@ -312,7 +312,7 @@ jobs: max-parallel: 1 matrix: include: - - itk-python-git-tag: "v5.2.0.post2" + - itk-python-git-tag: "v5.2.1.post1" c-compiler: "clang" cxx-compiler: "clang++" cmake-build-type: "Release" @@ -395,7 +395,7 @@ jobs: matrix: python-version-minor: [6, 7, 8, 9] include: - - itk-python-git-tag: "v5.2.0.post2" + - itk-python-git-tag: "v5.2.1.post1" c-compiler: "cl.exe" cxx-compiler: "cl.exe" cmake-build-type: "Release" diff --git a/examples/Applications/CMakeLists.txt b/examples/Applications/CMakeLists.txt index 5850f4680..9a28c8386 100644 --- a/examples/Applications/CMakeLists.txt +++ b/examples/Applications/CMakeLists.txt @@ -53,7 +53,6 @@ add_subdirectory( AtlasBuilderUsingIntensity ) add_subdirectory( ComputeBinaryImageSimilarityMetrics ) add_subdirectory( ComputeImageSimilarityMetrics ) add_subdirectory( ComputeImageStatistics ) -add_subdirectory( ComputeImageToTubeRigidMetricImage ) add_subdirectory( ComputeTrainingMask ) add_subdirectory( ComputeTubeFlyThroughImage ) add_subdirectory( ComputeTubeGraphProbability ) @@ -83,14 +82,13 @@ add_subdirectory( EnhanceTubesUsingDiffusion ) add_subdirectory( EnhanceTubesUsingDiscriminantAnalysis ) add_subdirectory( EnhanceUsingDiscriminantAnalysis ) add_subdirectory( EnhanceUsingNJetDiscriminantAnalysis ) -add_subdirectory( ExtractMetricImageSlice ) add_subdirectory( ImageMath ) add_subdirectory( MergeAdjacentImages ) add_subdirectory( MergeTubeGraphs ) add_subdirectory( ResampleImage ) add_subdirectory( ResampleTubes ) add_subdirectory( RegisterImages ) -add_subdirectory( RegisterImageToTubesUsingRigidTransform ) +add_subdirectory( RegisterSpatialObjectsToImage ) add_subdirectory( SampleCLIApplication ) add_subdirectory( SegmentBinaryImageSkeleton3D ) add_subdirectory( SegmentConnectedComponents ) diff --git a/examples/Applications/ComputeImageToTubeRigidMetricImage/CMakeLists.txt b/examples/Applications/ComputeImageToTubeRigidMetricImage/CMakeLists.txt deleted file mode 100644 index 846343247..000000000 --- a/examples/Applications/ComputeImageToTubeRigidMetricImage/CMakeLists.txt +++ /dev/null @@ -1,36 +0,0 @@ -############################################################################## -# -# Library: TubeTK -# -# Copyright Kitware Inc. -# -# All rights reserved. -# -# 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. -# -############################################################################## - -set( MODULE_NAME ComputeImageToTubeRigidMetricImage ) - -SEMMacroBuildCLI( - NAME - ${MODULE_NAME} - LOGO_HEADER - ${TubeTK_SOURCE_DIR}/docs/TubeTKLogo.h - TARGET_LIBRARIES - TubeTK ${ITK_LIBRARIES} - ) - -if( BUILD_TESTING ) - add_subdirectory( Testing ) -endif( BUILD_TESTING ) diff --git a/examples/Applications/ComputeImageToTubeRigidMetricImage/ComputeImageToTubeRigidMetricImage.cxx b/examples/Applications/ComputeImageToTubeRigidMetricImage/ComputeImageToTubeRigidMetricImage.cxx deleted file mode 100644 index 2b6471904..000000000 --- a/examples/Applications/ComputeImageToTubeRigidMetricImage/ComputeImageToTubeRigidMetricImage.cxx +++ /dev/null @@ -1,205 +0,0 @@ -/*========================================================================= - -Library: TubeTK - -Copyright 2010 Kitware Inc. 28 Corporate Drive, -Clifton Park, NY, 12065, USA. - -All rights reserved. - -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. - -=========================================================================*/ - -#include "../CLI/tubeCLIFilterWatcher.h" -#include "../CLI/tubeCLIProgressReporter.h" - -#include "itktubeImageToTubeRigidMetric.h" -#include "itktubeImageToTubeRigidRegistration.h" -#include "itktubeSingleValuedCostFunctionImageSource.h" -#include "itktubeTubeToTubeTransformFilter.h" -#include "tubeMessage.h" - - -#include -#include -#include - -#include "ComputeImageToTubeRigidMetricImageCLP.h" -#include "tubePreProcessRegistrationInputs.h" - -template< class TPixel, unsigned int VDimension > -int DoIt( int argc, char * argv[] ); - -// Does not currently use TPixel -#define PARSE_ARGS_FLOAT_ONLY 1 - -// Must follow include of "...CLP.h" and forward declaration of int DoIt( ... ). -#include "../CLI/tubeCLIHelperFunctions.h" - -template< class TPixel, unsigned int VDimension > -int DoIt( int argc, char * argv[] ) -{ - PARSE_ARGS; - - // The timeCollector is used to perform basic profiling of the components - // of your algorithm. - itk::TimeProbesCollectorBase timeCollector; - - // CLIProgressReporter is used to communicate progress with the Slicer GUI - tube::CLIProgressReporter progressReporter( - "RegisterImageToTubesUsingRigidTransform", CLPProcessInformation ); - progressReporter.Start(); - - const unsigned int Dimension = 3; - typedef double FloatType; - - typedef itk::TubeSpatialObject< Dimension > TubeType; - typedef itk::GroupSpatialObject< Dimension > TubeNetType; - typedef itk::Image< FloatType, Dimension > ImageType; - typedef itk::tube::ImageToTubeRigidRegistration< ImageType, TubeNetType, - TubeType > RegistrationMethodType; - - typedef typename RegistrationMethodType::TransformType TransformType; - typedef RegistrationMethodType::FeatureWeightsType PointWeightsType; - - typename ImageType::Pointer currentImage; - typename TubeNetType::Pointer tubeNet; - PointWeightsType pointWeights; - - if( tube::PreProcessRegistrationInputs< Dimension, - FloatType, - TubeType, - TubeNetType, - ImageType, - RegistrationMethodType >( argc, - argv, - timeCollector, - currentImage, - tubeNet, - pointWeights ) == EXIT_FAILURE ) - { - return EXIT_FAILURE; - } - - - timeCollector.Start( "Sample parameter space" ); - - typedef itk::tube::ImageToTubeRigidMetric< ImageType, - TubeNetType, - TubeType > CostFunctionType; - CostFunctionType::Pointer costFunction = CostFunctionType::New(); - costFunction->SetFixedImage( currentImage ); - costFunction->SetMovingSpatialObject( tubeNet ); - costFunction->SetFeatureWeights( pointWeights ); - TransformType::Pointer transform = TransformType::New(); - costFunction->SetTransform( transform ); - costFunction->Initialize(); - - const unsigned int NumberOfParameters = 6; - typedef itk::tube::SingleValuedCostFunctionImageSource< CostFunctionType, - NumberOfParameters > CostFunctionImageSourceType; - CostFunctionImageSourceType::Pointer costFunctionImageSource = - CostFunctionImageSourceType::New(); - costFunctionImageSource->SetCostFunction( costFunction ); - - typedef CostFunctionImageSourceType::ParametersType ParametersType; - - ParametersType parametersLowerBound( NumberOfParameters ); - parametersLowerBound[0] = -0.3; - parametersLowerBound[1] = -0.3; - parametersLowerBound[2] = -0.3; - parametersLowerBound[3] = -5.0; - parametersLowerBound[4] = -5.0; - parametersLowerBound[5] = -5.0; - - ParametersType parametersUpperBound( NumberOfParameters ); - parametersUpperBound[0] = 0.3; - parametersUpperBound[1] = 0.3; - parametersUpperBound[2] = 0.3; - parametersUpperBound[3] = 5.0; - parametersUpperBound[4] = 5.0; - parametersUpperBound[5] = 5.0; - - ParametersType parametersStep( NumberOfParameters ); - parametersStep[0] = 0.3; - parametersStep[1] = 0.3; - parametersStep[2] = 0.3; - parametersStep[3] = 5.0; - parametersStep[4] = 5.0; - parametersStep[5] = 5.0; - - costFunctionImageSource->SetParametersLowerBound( parametersLowerBound ); - costFunctionImageSource->SetParametersUpperBound( parametersUpperBound ); - costFunctionImageSource->SetParametersStep( parametersStep ); - - try - { - costFunctionImageSource->Update(); - } - catch( itk::ExceptionObject & err ) - { - tube::ErrorMessage( "Sampling parameter space: Exception caught: " - + std::string( err.GetDescription() ) ); - timeCollector.Report(); - return EXIT_FAILURE; - } - double progress = 0.9; - progressReporter.Report( progress ); - - timeCollector.Stop( "Sample parameter space" ); - - - timeCollector.Start( "Save data" ); - - typedef itk::Image< float, NumberOfParameters > OutputImageType; - typedef itk::CastImageFilter< CostFunctionImageSourceType::OutputImageType, - OutputImageType > CasterType; - CasterType::Pointer caster = CasterType::New(); - caster->SetInput( costFunctionImageSource->GetOutput() ); - - typedef itk::ImageFileWriter< OutputImageType > - WriterType; - WriterType::Pointer writer = WriterType::New(); - writer->SetFileName( outputMetricImage.c_str() ); - writer->SetInput( caster->GetOutput() ); - try - { - writer->Update(); - } - catch( itk::ExceptionObject & err ) - { - tube::ErrorMessage( "Writing output image: Exception caught: " - + std::string( err.GetDescription() ) ); - timeCollector.Report(); - return EXIT_FAILURE; - } - timeCollector.Stop( "Save data" ); - - progress = 1.0; - progressReporter.Report( progress ); - progressReporter.End(); - - timeCollector.Report(); - return EXIT_SUCCESS; -} - -// Main -int main( int argc, char * argv[] ) -{ - PARSE_ARGS; - - // You may need to update this line if, in the project's .xml CLI file, - // you change the variable name for the inputVolume. - return tube::ParseArgsAndCallDoIt( inputVolume, argc, argv ); -} diff --git a/examples/Applications/ComputeImageToTubeRigidMetricImage/ComputeImageToTubeRigidMetricImage.xml b/examples/Applications/ComputeImageToTubeRigidMetricImage/ComputeImageToTubeRigidMetricImage.xml deleted file mode 100644 index 8797163eb..000000000 --- a/examples/Applications/ComputeImageToTubeRigidMetricImage/ComputeImageToTubeRigidMetricImage.xml +++ /dev/null @@ -1,47 +0,0 @@ - - - TubeTK - Compute Image To Tubes Rigid Metric Image (TubeTK) - Evaluate the image to tubes matching metric with a dense, uniformly spaced sampling of the rigid transformation parameters - 0.1.0.$Revision: 2104 $(alpha) - http://public.kitware.com/Wiki/TubeTK - Apache 2.0 - Matthew McCormick (Kitware) - This work is part of the TubeTK project at Kitware. - - - Input/output parameters. - - inputVolume - - input - 0 - Input volume. - - - inputVessel - - input - 1 - Input vessel (tube). - - - outputMetricImage - - output - 2 - Densely sampled metric image over the transform parameters. - - - - - - gaussianBlurStdDev - - Standard deviation of the Gaussian kernel used to blur input volume. This increases the likelihood that the vessel spatial object overlaps with the vessel image at their initial alignment and enlarges the convergence zone. - gaussianBlurStdDev - g - 3.0 - - - diff --git a/examples/Applications/ComputeImageToTubeRigidMetricImage/tubePreProcessRegistrationInputs.h b/examples/Applications/ComputeImageToTubeRigidMetricImage/tubePreProcessRegistrationInputs.h deleted file mode 100644 index 3429d7ed8..000000000 --- a/examples/Applications/ComputeImageToTubeRigidMetricImage/tubePreProcessRegistrationInputs.h +++ /dev/null @@ -1,50 +0,0 @@ -/*========================================================================= - -Library: TubeTK - -Copyright 2010 Kitware Inc. 28 Corporate Drive, -Clifton Park, NY, 12065, USA. - -All rights reserved. - -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. - -=========================================================================*/ - -#ifndef __tubePreProcessRegistrationInputs_h -#define __tubePreProcessRegistrationInputs_h - -namespace tube { - -template< - unsigned int VDimension, - typename TFloat, - typename TTube, - typename TTubeNet, - typename TImage, - typename TRegistrationMethod > -int -PreProcessRegistrationInputs( int argc, - char * argv[], - itk::TimeProbesCollectorBase & timeCollector, - typename TImage::Pointer & currentImage, - typename TTubeNet::Pointer & tubeNet, - typename TRegistrationMethod::FeatureWeightsType & pointWeights ); - -} // namespace - -#ifndef ITK_MANUAL_INSTANTIATION -#include "tubePreProcessRegistrationInputs.hxx" -#endif - -#endif // End !defined( __tubePreProcessRegistrationInputs_h ) diff --git a/examples/Applications/ComputeImageToTubeRigidMetricImage/tubePreProcessRegistrationInputs.hxx b/examples/Applications/ComputeImageToTubeRigidMetricImage/tubePreProcessRegistrationInputs.hxx deleted file mode 100644 index dc353eccd..000000000 --- a/examples/Applications/ComputeImageToTubeRigidMetricImage/tubePreProcessRegistrationInputs.hxx +++ /dev/null @@ -1,176 +0,0 @@ -/*========================================================================= - -Library: TubeTK - -Copyright Kitware Inc. - -All rights reserved. - -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. - -=========================================================================*/ - -#ifndef __tubePreProcessRegistrationInputs_hxx -#define __tubePreProcessRegistrationInputs_hxx - -#include "tubePreProcessRegistrationInputs.h" - -#include "itktubeSubSampleTubeTreeSpatialObjectFilter.h" -#include "itktubeTubeAngleOfIncidenceWeightFunction.h" -#include "itktubeTubeExponentialResolutionWeightFunction.h" -#include "itktubeTubePointWeightsCalculator.h" - -#include -#include -#include -#include - -namespace tube { - -template< - unsigned int VDimension, - typename TFloat, - typename TTube, - typename TTubeNet, - typename TImage, - typename TRegistrationMethod > -int -PreProcessRegistrationInputs( int argc, - char * argv[], - itk::TimeProbesCollectorBase & timeCollector, - typename TImage::Pointer & currentImage, - typename TTubeNet::Pointer & tubeNet, - typename TRegistrationMethod::FeatureWeightsType & pointWeights ) -{ - const unsigned int Dimension = VDimension; - typedef TFloat FloatType; - typedef TTube TubeType; - typedef TTubeNet TubeNetType; - typedef TImage ImageType; - typedef TRegistrationMethod RegistrationMethodType; - - PARSE_ARGS; - - timeCollector.Start( "Load data" ); - typedef itk::ImageFileReader< ImageType > ImageReaderType; - typename ImageReaderType::Pointer reader = ImageReaderType::New(); - reader->SetFileName( inputVolume.c_str() ); - try - { - reader->Update(); - } - catch( itk::ExceptionObject & err ) - { - tube::ErrorMessage( "Reading volume: Exception caught: " - + std::string( err.GetDescription() ) ); - timeCollector.Report(); - return EXIT_FAILURE; - } - - typedef itk::SpatialObjectReader< Dimension > TubeNetReaderType; - typename TubeNetReaderType::Pointer vesselReader = - TubeNetReaderType::New(); - vesselReader->SetFileName( inputVessel ); - try - { - vesselReader->Update(); - } - catch( itk::ExceptionObject & err ) - { - tube::ErrorMessage( "Reading vessel: Exception caught: " - + std::string( err.GetDescription() ) ); - timeCollector.Report(); - return EXIT_FAILURE; - } - timeCollector.Stop( "Load data" ); - - timeCollector.Start( "Sub-sample data" ); - typedef itk::tube::SubSampleTubeTreeSpatialObjectFilter< TubeNetType, - TubeType > - SubSampleTubeTreeFilterType; - typename SubSampleTubeTreeFilterType::Pointer subSampleTubeTreeFilter = - SubSampleTubeTreeFilterType::New(); - subSampleTubeTreeFilter->SetInput( vesselReader->GetGroup() ); - subSampleTubeTreeFilter->SetSampling( 100 ); - try - { - subSampleTubeTreeFilter->Update(); - } - catch( itk::ExceptionObject & err ) - { - tube::ErrorMessage( "Sub-sampling vessel: Exception caught: " - + std::string( err.GetDescription() ) ); - timeCollector.Report(); - return EXIT_FAILURE; - } - tubeNet = subSampleTubeTreeFilter->GetOutput(); - - timeCollector.Stop( "Sub-sample data" ); - - - currentImage = reader->GetOutput(); - if( gaussianBlurStdDev > 0.0 ) - { - timeCollector.Start( "Gaussian Blur" ); - - typedef itk::RecursiveGaussianImageFilter< ImageType, ImageType > - GaussianFilterType; - typename GaussianFilterType::Pointer gaussianFilter; - - for( unsigned int ii = 0; ii < Dimension; ++ii ) - { - gaussianFilter = GaussianFilterType::New(); - gaussianFilter->SetInput( currentImage ); - gaussianFilter->SetSigma( gaussianBlurStdDev ); - - gaussianFilter->SetOrder( itk::GaussianOrderEnum::ZeroOrder ); - gaussianFilter->SetDirection( ii ); - - gaussianFilter->Update(); - currentImage = gaussianFilter->GetOutput(); - } - - timeCollector.Stop( "Gaussian Blur" ); - } - - timeCollector.Start( "Compute Model Feature Weights" ); - - typedef itk::tube::Function::TubeExponentialResolutionWeightFunction< - typename TubeType::TubePointType, FloatType > - WeightFunctionType; - typedef typename RegistrationMethodType::FeatureWeightsType - PointWeightsType; - typedef itk::tube::TubePointWeightsCalculator< Dimension, - TubeType, WeightFunctionType, PointWeightsType > - PointWeightsCalculatorType; - - typename WeightFunctionType::Pointer weightFunction = - WeightFunctionType::New(); - typename PointWeightsCalculatorType::Pointer resolutionWeightsCalculator = - PointWeightsCalculatorType::New(); - - resolutionWeightsCalculator->SetTubeTreeSpatialObject( - subSampleTubeTreeFilter->GetOutput() ); - resolutionWeightsCalculator->SetPointWeightFunction( weightFunction ); - resolutionWeightsCalculator->Compute(); - - pointWeights = resolutionWeightsCalculator->GetPointWeights(); - - timeCollector.Stop( "Compute Model Feature Weights" ); - - return EXIT_SUCCESS; -} - -} //namespace - -#endif // End !defined( __tubePreProcessRegistrationInputs_hxx ) diff --git a/examples/Applications/ConvertTubesToSurface/ConvertTubesToSurface.cxx b/examples/Applications/ConvertTubesToSurface/ConvertTubesToSurface.cxx index 59451acf0..03c9d494d 100644 --- a/examples/Applications/ConvertTubesToSurface/ConvertTubesToSurface.cxx +++ b/examples/Applications/ConvertTubesToSurface/ConvertTubesToSurface.cxx @@ -2,8 +2,7 @@ Library: TubeTK -Copyright 2010 Kitware Inc. 28 Corporate Drive, -Clifton Park, NY, 12065, USA. +Copyright Kitware Inc. All rights reserved. diff --git a/examples/Applications/ConvertTubesToTubeTree/ConvertTubesToTubeTree.cxx b/examples/Applications/ConvertTubesToTubeTree/ConvertTubesToTubeTree.cxx index 0f393f2a8..eb2a3c0be 100644 --- a/examples/Applications/ConvertTubesToTubeTree/ConvertTubesToTubeTree.cxx +++ b/examples/Applications/ConvertTubesToTubeTree/ConvertTubesToTubeTree.cxx @@ -2,8 +2,7 @@ Library: TubeTK - Copyright 2010 Kitware Inc. 28 Corporate Drive, - Clifton Park, NY, 12065, USA. + Copyright Kitware Inc. All rights reserved. diff --git a/examples/Applications/ExtractMetricImageSlice/ExtractMetricImageSlice.cxx b/examples/Applications/ExtractMetricImageSlice/ExtractMetricImageSlice.cxx deleted file mode 100644 index d7b8efa1a..000000000 --- a/examples/Applications/ExtractMetricImageSlice/ExtractMetricImageSlice.cxx +++ /dev/null @@ -1,104 +0,0 @@ -/*========================================================================= - -Library: TubeTK - -Copyright 2010 Kitware Inc. 28 Corporate Drive, -Clifton Park, NY, 12065, USA. - -All rights reserved. - -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. - -=========================================================================*/ - -#include "../CLI/tubeCLIFilterWatcher.h" -#include "tubeMessage.h" - -#include -#include -#include - -#include "ExtractMetricImageSliceCLP.h" - -int main( int argc, char * argv[] ) -{ - PARSE_ARGS; - - const unsigned int MetricDimension = 6; - const unsigned int SliceDimension = 2; - typedef double FloatType; - - typedef itk::Image< FloatType, MetricDimension > MetricImageType; - typedef itk::Image< FloatType, SliceDimension > SliceImageType; - - typedef itk::ImageFileReader< MetricImageType > ReaderType; - ReaderType::Pointer reader = ReaderType::New(); - reader->SetFileName( inputMetricImage ); - try - { - reader->UpdateOutputInformation(); - } - catch( itk::ExceptionObject & err ) - { - tube::ErrorMessage( "Reading input image information: Exception caught: " - + std::string( err.GetDescription() ) ); - return EXIT_FAILURE; - } - - typedef itk::ExtractImageFilter< MetricImageType, SliceImageType > - ExtractFilterType; - ExtractFilterType::Pointer extractor = ExtractFilterType::New(); - extractor->SetInput( reader->GetOutput() ); - extractor->SetDirectionCollapseToIdentity(); - - MetricImageType::RegionType extractionRegion = - reader->GetOutput()->GetLargestPossibleRegion(); - MetricImageType::SizeType extractionSize = - extractionRegion.GetSize(); - MetricImageType::IndexType extractionIndex = - extractionRegion.GetIndex(); - unsigned int indexCount = 0; - for( int ii = 0; ii < static_cast< int >( MetricDimension ); ++ii ) - { - if( ii != sliceDirections[0] && ii != sliceDirections[1] ) - { - extractionSize[ii] = 0; - extractionIndex[ii] = indices[indexCount]; - ++indexCount; - } - } - - extractionRegion.SetSize( extractionSize ); - extractionRegion.SetIndex( extractionIndex ); - extractor->SetExtractionRegion( extractionRegion ); - - typedef itk::ImageFileWriter< SliceImageType > WriterType; - WriterType::Pointer writer = WriterType::New(); - writer->SetFileName( outputMetricSlice ); - writer->SetInput( extractor->GetOutput() ); - - tube::CLIFilterWatcher watcher( writer, "Writing Slice" ); - - try - { - writer->Update(); - } - catch( itk::ExceptionObject & err ) - { - tube::ErrorMessage( "Writing output image: Exception caught: " - + std::string( err.GetDescription() ) ); - return EXIT_FAILURE; - } - - return EXIT_SUCCESS; -} diff --git a/examples/Applications/ExtractMetricImageSlice/ExtractMetricImageSlice.xml b/examples/Applications/ExtractMetricImageSlice/ExtractMetricImageSlice.xml deleted file mode 100644 index a32307262..000000000 --- a/examples/Applications/ExtractMetricImageSlice/ExtractMetricImageSlice.xml +++ /dev/null @@ -1,48 +0,0 @@ - - - TubeTK - Extract Metric Image Slice (TubeTK) - Extract a 2D slice from the 6D metric image - 0.1.0.$Revision: 2104 $(alpha) - http://public.kitware.com/Wiki/TubeTK - Apache 2.0 - Matthew McCormick (Kitware) - This work is part of the TubeTK project at Kitware. - - - Input/output parameters. - - inputMetricImage - - input - 0 - Input metric image. - - - outputMetricSlice - - output - 1 - Output 2D metric image slice. - - - - - - sliceDirections - - The two directions from which the slice will be extracted - sliceDirections - d - 0,1 - - - indices - - Indices in the other four directions where the slice should be extracted - indices - i - 0,0,0,0 - - - diff --git a/examples/Applications/ExtractMetricImageSlice/Testing/CMakeLists.txt b/examples/Applications/ExtractMetricImageSlice/Testing/CMakeLists.txt deleted file mode 100644 index 979e80258..000000000 --- a/examples/Applications/ExtractMetricImageSlice/Testing/CMakeLists.txt +++ /dev/null @@ -1,32 +0,0 @@ -############################################################################## -# -# Library: TubeTK -# -# Copyright 2010 Kitware Inc. 28 Corporate Drive, -# Clifton Park, NY, 12065, USA. -# -# All rights reserved. -# -# 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. -# -############################################################################## - -include_regular_expression( "^.*$" ) - -set( PROJ_EXE ${TubeTK_LAUNCHER} $ ) - -#itk_add_test( - #NAME ${METRIC_EXTRACTOR}-Test1 - #COMMAND ${PROJ_EXE} - #DATA{${TubeTK_DATA_ROOT}/${MODULE_NAME}-Sampler.nrrd} - #${ITK_TEST_OUTPUT_DIR}/${MODULE_NAME}Test1.mha ) diff --git a/examples/Applications/ExtractMetricImageSlice/Testing/README.md b/examples/Applications/ExtractMetricImageSlice/Testing/README.md deleted file mode 100644 index 2341f91d3..000000000 --- a/examples/Applications/ExtractMetricImageSlice/Testing/README.md +++ /dev/null @@ -1,5 +0,0 @@ -TubeTK Register Image to Tubes Using Rigid Transform Application Tests -====================================================================== - ---- -*This file is part of [TubeTK](http://www.tubetk.org). TubeTK is developed by [Kitware, Inc.](http://www.kitware.com) and licensed under the [Apache License, Version 2.0](http://www.apache.org/licenses/LICENSE-2.0).* diff --git a/examples/Applications/RegisterImageToTubesUsingRigidTransform/CMakeLists.txt b/examples/Applications/RegisterImageToTubesUsingRigidTransform/CMakeLists.txt deleted file mode 100644 index 30c019782..000000000 --- a/examples/Applications/RegisterImageToTubesUsingRigidTransform/CMakeLists.txt +++ /dev/null @@ -1,34 +0,0 @@ -############################################################################## -# -# Library: TubeTK -# -# Copyright Kitware Inc. -# -# All rights reserved. -# -# 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. -# -############################################################################## - -set( MODULE_NAME RegisterImageToTubesUsingRigidTransform ) - -SEMMacroBuildCLI( - NAME ${MODULE_NAME} - LOGO_HEADER ${TubeTK_SOURCE_DIR}/docs/TubeTKLogo.h - TARGET_LIBRARIES - TubeTK ${ITK_LIBRARIES} - ) - -if( BUILD_TESTING ) - add_subdirectory( Testing ) -endif( BUILD_TESTING ) diff --git a/examples/Applications/RegisterImageToTubesUsingRigidTransform/RegisterImageToTubesUsingRigidTransform.cxx b/examples/Applications/RegisterImageToTubesUsingRigidTransform/RegisterImageToTubesUsingRigidTransform.cxx deleted file mode 100644 index 7076b1f4e..000000000 --- a/examples/Applications/RegisterImageToTubesUsingRigidTransform/RegisterImageToTubesUsingRigidTransform.cxx +++ /dev/null @@ -1,176 +0,0 @@ -/*========================================================================= - -Library: TubeTK - -Copyright Kitware Inc. - -All rights reserved. - -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. - -=========================================================================*/ - -#include "itktubeImageToTubeRigidRegistration.h" -#include "itktubeTubeToTubeTransformFilter.h" -#include "../CLI/tubeCLIFilterWatcher.h" -#include "../CLI/tubeCLIProgressReporter.h" -#include "tubeMessage.h" - -#include -#include - - -#include "RegisterImageToTubesUsingRigidTransformCLP.h" -#include "tubePreProcessRegistrationInputs.h" - -template< class TPixel, unsigned int VDimension > -int DoIt( int argc, char * argv[] ); - -// Does not currently use TPixel -#define PARSE_ARGS_FLOAT_ONLY 1 - -// Must follow include of "...CLP.h" and forward declaration of int DoIt( ... ). -#include "../CLI/tubeCLIHelperFunctions.h" - -template< class TPixel, unsigned int VDimension > -int DoIt( int argc, char * argv[] ) -{ - PARSE_ARGS; - - // The timeCollector is used to perform basic profiling of the components - // of your algorithm. - itk::TimeProbesCollectorBase timeCollector; - - // CLIProgressReporter is used to communicate progress with the Slicer GUI - tube::CLIProgressReporter progressReporter( - "RegisterImageToTubesUsingRigidTransform", - CLPProcessInformation ); - progressReporter.Start(); - - const unsigned int Dimension = 3; - typedef double FloatType; - - typedef itk::TubeSpatialObject< Dimension > TubeType; - typedef itk::GroupSpatialObject< Dimension > TubeNetType; - typedef itk::Image< FloatType, Dimension > ImageType; - - typedef itk::tube::ImageToTubeRigidRegistration< ImageType, TubeNetType, - TubeType > RegistrationMethodType; - - typedef typename RegistrationMethodType::TransformType TransformType; - - typedef RegistrationMethodType::FeatureWeightsType PointWeightsType; - - typename ImageType::Pointer currentImage; - typename TubeNetType::Pointer tubeNet; - PointWeightsType pointWeights; - - if( tube::PreProcessRegistrationInputs< Dimension, FloatType, TubeType, - TubeNetType, ImageType, RegistrationMethodType >( argc, argv, - timeCollector, currentImage, tubeNet, pointWeights ) - == EXIT_FAILURE ) - { - return EXIT_FAILURE; - } - - - timeCollector.Start( "Register image to tube" ); - - typename RegistrationMethodType::Pointer registrationMethod = - RegistrationMethodType::New(); - - registrationMethod->SetFixedImage( currentImage ); - registrationMethod->SetMovingSpatialObject( tubeNet ); - registrationMethod->SetFeatureWeights( pointWeights ); - - // Set Optimizer parameters. - typename RegistrationMethodType::OptimizerType::Pointer optimizer = - registrationMethod->GetOptimizer(); - itk::GradientDescentOptimizer * gradientDescentOptimizer = dynamic_cast< - itk::GradientDescentOptimizer * >( optimizer.GetPointer() ); - if( gradientDescentOptimizer ) - { - gradientDescentOptimizer->SetLearningRate( 0.1 ); - gradientDescentOptimizer->SetNumberOfIterations( 1000 ); - } - - // TODO: This is hard-coded now, which is sufficient since - // ImageToTubeRigidMetric only uses a Euler3DTransform. Will need to - // adjust - // to the transform parameters in the future at compile time. - const unsigned int NumberOfParameters = 6; - - try - { - registrationMethod->Initialize(); - registrationMethod->Update(); - } - catch( itk::ExceptionObject & err ) - { - tube::ErrorMessage( "Performing registration: Exception caught: " - + std::string( err.GetDescription() ) ); - timeCollector.Report(); - return EXIT_FAILURE; - } - double progress = 0.9; - progressReporter.Report( progress ); - - TransformType* registrationTransform = - dynamic_cast( registrationMethod->GetTransform() ); - registrationTransform->SetParameters( - registrationMethod->GetLastTransformParameters() ); - std::ostringstream parametersMessage; - parametersMessage << "Transform Parameters: " << - registrationMethod->GetLastTransformParameters(); - tube::InformationMessage( parametersMessage.str() ); - parametersMessage.str( "" ); - parametersMessage << "Transform Center Of Rotation: " << - registrationTransform->GetFixedParameters(); - tube::InformationMessage( parametersMessage.str() ); - timeCollector.Stop( "Register image to tube" ); - - timeCollector.Start( "Save data" ); - - itk::TransformFileWriter::Pointer writer = - itk::TransformFileWriter::New(); - writer->SetFileName( outputTransform.c_str() ); - writer->SetInput( registrationTransform ); - try - { - writer->Update(); - } - catch( itk::ExceptionObject & err ) - { - tube::ErrorMessage( "Writing transform: Exception caught: " - + std::string( err.GetDescription() ) ); - timeCollector.Report(); - return EXIT_FAILURE; - } - timeCollector.Stop( "Save data" ); - progress = 1.0; - progressReporter.Report( progress ); - progressReporter.End(); - - timeCollector.Report(); - return EXIT_SUCCESS; -} - -// Main -int main( int argc, char * argv[] ) -{ - PARSE_ARGS; - - // You may need to update this line if, in the project's .xml CLI file, - // you change the variable name for the inputVolume. - return tube::ParseArgsAndCallDoIt( inputVolume, argc, argv ); -} diff --git a/examples/Applications/RegisterImageToTubesUsingRigidTransform/RegisterImageToTubesUsingRigidTransform.xml b/examples/Applications/RegisterImageToTubesUsingRigidTransform/RegisterImageToTubesUsingRigidTransform.xml deleted file mode 100644 index 257297f40..000000000 --- a/examples/Applications/RegisterImageToTubesUsingRigidTransform/RegisterImageToTubesUsingRigidTransform.xml +++ /dev/null @@ -1,55 +0,0 @@ - - - TubeTK - Register Image to Tubes Using Rigid Transform (TubeTK) - Registration of a vessel to its location within an image. - 0.1.0.$Revision: 2104 $(alpha) - http://public.kitware.com/Wiki/TubeTK - Apache 2.0 - Matthew McCormick (Kitware) - This work is part of the TubeTK project at Kitware. - - - Input/output parameters. - - inputVolume - - input - 0 - Input volume. - - - inputVessel - - input - 1 - Input vessel (tube). - - - outputTransform - - output - 2 - Transform that aligns the input vessels and input image. - - - parameterProgression - - output - Output optimization parameter progression file. - p - parameterProgression - - - - - - gaussianBlurStdDev - - Standard deviation of the Gaussian kernel used to blur input volume. This increases the likelihood that the vessel spatial object overlaps with the vessel image at their initial alignment and enlarges the convergence zone. - gaussianBlurStdDev - g - 3.0 - - - diff --git a/examples/Applications/RegisterImageToTubesUsingRigidTransform/Testing/CMakeLists.txt b/examples/Applications/RegisterImageToTubesUsingRigidTransform/Testing/CMakeLists.txt deleted file mode 100644 index 3a9519c4f..000000000 --- a/examples/Applications/RegisterImageToTubesUsingRigidTransform/Testing/CMakeLists.txt +++ /dev/null @@ -1,53 +0,0 @@ -############################################################################## -# -# Library: TubeTK -# -# Copyright Kitware Inc. -# -# All rights reserved. -# -# 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. -# -############################################################################## - -include_regular_expression( "^.*$" ) - -set( PROJ_EXE ${TubeTK_LAUNCHER} $ ) - -itk_add_test( - NAME ${MODULE_NAME}-Test1 - COMMAND ${PROJ_EXE} - DATA{${TubeTK_DATA_ROOT}/Branch.n020.mha} - DATA{${TubeTK_DATA_ROOT}/tube.tre} - ${ITK_TEST_OUTPUT_DIR}/${MODULE_NAME}Test1.h5 ) - -set( METRIC_SAMPLER ComputeImageToTubeRigidMetricImage ) -set( METRIC_SAMPLER_EXE ${TubeTK_LAUNCHER} $ ) - -itk_add_test( - NAME ${MODULE_NAME}-MetricSampler-Test1 - COMMAND ${METRIC_SAMPLER_EXE} - DATA{${TubeTK_DATA_ROOT}/Branch.n020.mha} - DATA{${TubeTK_DATA_ROOT}/tube.tre} - ${ITK_TEST_OUTPUT_DIR}/${MODULE_NAME}-MetricSampler-Test1.nrrd ) - -set( METRIC_EXTRACTOR ExtractMetricImageSlice ) -set( METRIC_EXTRACTOR_EXE ${TubeTK_LAUNCHER} $ ) - -itk_add_test( - NAME ${MODULE_NAME}-MetricExtractor-Test1 - COMMAND ${METRIC_EXTRACTOR_EXE} - ${ITK_TEST_OUTPUT_DIR}/${MODULE_NAME}-MetricSampler-Test1.nrrd - ${ITK_TEST_OUTPUT_DIR}/${MODULE_NAME}-MetricExtractor-Test1.mha ) -set_tests_properties( ${MODULE_NAME}-MetricExtractor-Test1 - PROPERTIES DEPENDS ${MODULE_NAME}-MetricSampler-Test1 ) diff --git a/examples/Applications/RegisterImageToTubesUsingRigidTransform/Testing/README.md b/examples/Applications/RegisterImageToTubesUsingRigidTransform/Testing/README.md deleted file mode 100644 index 2341f91d3..000000000 --- a/examples/Applications/RegisterImageToTubesUsingRigidTransform/Testing/README.md +++ /dev/null @@ -1,5 +0,0 @@ -TubeTK Register Image to Tubes Using Rigid Transform Application Tests -====================================================================== - ---- -*This file is part of [TubeTK](http://www.tubetk.org). TubeTK is developed by [Kitware, Inc.](http://www.kitware.com) and licensed under the [Apache License, Version 2.0](http://www.apache.org/licenses/LICENSE-2.0).* diff --git a/examples/Applications/RegisterImageToTubesUsingRigidTransform/tubePreProcessRegistrationInputs.h b/examples/Applications/RegisterImageToTubesUsingRigidTransform/tubePreProcessRegistrationInputs.h deleted file mode 100644 index 3429d7ed8..000000000 --- a/examples/Applications/RegisterImageToTubesUsingRigidTransform/tubePreProcessRegistrationInputs.h +++ /dev/null @@ -1,50 +0,0 @@ -/*========================================================================= - -Library: TubeTK - -Copyright 2010 Kitware Inc. 28 Corporate Drive, -Clifton Park, NY, 12065, USA. - -All rights reserved. - -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. - -=========================================================================*/ - -#ifndef __tubePreProcessRegistrationInputs_h -#define __tubePreProcessRegistrationInputs_h - -namespace tube { - -template< - unsigned int VDimension, - typename TFloat, - typename TTube, - typename TTubeNet, - typename TImage, - typename TRegistrationMethod > -int -PreProcessRegistrationInputs( int argc, - char * argv[], - itk::TimeProbesCollectorBase & timeCollector, - typename TImage::Pointer & currentImage, - typename TTubeNet::Pointer & tubeNet, - typename TRegistrationMethod::FeatureWeightsType & pointWeights ); - -} // namespace - -#ifndef ITK_MANUAL_INSTANTIATION -#include "tubePreProcessRegistrationInputs.hxx" -#endif - -#endif // End !defined( __tubePreProcessRegistrationInputs_h ) diff --git a/examples/Applications/RegisterImageToTubesUsingRigidTransform/tubePreProcessRegistrationInputs.hxx b/examples/Applications/RegisterImageToTubesUsingRigidTransform/tubePreProcessRegistrationInputs.hxx deleted file mode 100644 index dc353eccd..000000000 --- a/examples/Applications/RegisterImageToTubesUsingRigidTransform/tubePreProcessRegistrationInputs.hxx +++ /dev/null @@ -1,176 +0,0 @@ -/*========================================================================= - -Library: TubeTK - -Copyright Kitware Inc. - -All rights reserved. - -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. - -=========================================================================*/ - -#ifndef __tubePreProcessRegistrationInputs_hxx -#define __tubePreProcessRegistrationInputs_hxx - -#include "tubePreProcessRegistrationInputs.h" - -#include "itktubeSubSampleTubeTreeSpatialObjectFilter.h" -#include "itktubeTubeAngleOfIncidenceWeightFunction.h" -#include "itktubeTubeExponentialResolutionWeightFunction.h" -#include "itktubeTubePointWeightsCalculator.h" - -#include -#include -#include -#include - -namespace tube { - -template< - unsigned int VDimension, - typename TFloat, - typename TTube, - typename TTubeNet, - typename TImage, - typename TRegistrationMethod > -int -PreProcessRegistrationInputs( int argc, - char * argv[], - itk::TimeProbesCollectorBase & timeCollector, - typename TImage::Pointer & currentImage, - typename TTubeNet::Pointer & tubeNet, - typename TRegistrationMethod::FeatureWeightsType & pointWeights ) -{ - const unsigned int Dimension = VDimension; - typedef TFloat FloatType; - typedef TTube TubeType; - typedef TTubeNet TubeNetType; - typedef TImage ImageType; - typedef TRegistrationMethod RegistrationMethodType; - - PARSE_ARGS; - - timeCollector.Start( "Load data" ); - typedef itk::ImageFileReader< ImageType > ImageReaderType; - typename ImageReaderType::Pointer reader = ImageReaderType::New(); - reader->SetFileName( inputVolume.c_str() ); - try - { - reader->Update(); - } - catch( itk::ExceptionObject & err ) - { - tube::ErrorMessage( "Reading volume: Exception caught: " - + std::string( err.GetDescription() ) ); - timeCollector.Report(); - return EXIT_FAILURE; - } - - typedef itk::SpatialObjectReader< Dimension > TubeNetReaderType; - typename TubeNetReaderType::Pointer vesselReader = - TubeNetReaderType::New(); - vesselReader->SetFileName( inputVessel ); - try - { - vesselReader->Update(); - } - catch( itk::ExceptionObject & err ) - { - tube::ErrorMessage( "Reading vessel: Exception caught: " - + std::string( err.GetDescription() ) ); - timeCollector.Report(); - return EXIT_FAILURE; - } - timeCollector.Stop( "Load data" ); - - timeCollector.Start( "Sub-sample data" ); - typedef itk::tube::SubSampleTubeTreeSpatialObjectFilter< TubeNetType, - TubeType > - SubSampleTubeTreeFilterType; - typename SubSampleTubeTreeFilterType::Pointer subSampleTubeTreeFilter = - SubSampleTubeTreeFilterType::New(); - subSampleTubeTreeFilter->SetInput( vesselReader->GetGroup() ); - subSampleTubeTreeFilter->SetSampling( 100 ); - try - { - subSampleTubeTreeFilter->Update(); - } - catch( itk::ExceptionObject & err ) - { - tube::ErrorMessage( "Sub-sampling vessel: Exception caught: " - + std::string( err.GetDescription() ) ); - timeCollector.Report(); - return EXIT_FAILURE; - } - tubeNet = subSampleTubeTreeFilter->GetOutput(); - - timeCollector.Stop( "Sub-sample data" ); - - - currentImage = reader->GetOutput(); - if( gaussianBlurStdDev > 0.0 ) - { - timeCollector.Start( "Gaussian Blur" ); - - typedef itk::RecursiveGaussianImageFilter< ImageType, ImageType > - GaussianFilterType; - typename GaussianFilterType::Pointer gaussianFilter; - - for( unsigned int ii = 0; ii < Dimension; ++ii ) - { - gaussianFilter = GaussianFilterType::New(); - gaussianFilter->SetInput( currentImage ); - gaussianFilter->SetSigma( gaussianBlurStdDev ); - - gaussianFilter->SetOrder( itk::GaussianOrderEnum::ZeroOrder ); - gaussianFilter->SetDirection( ii ); - - gaussianFilter->Update(); - currentImage = gaussianFilter->GetOutput(); - } - - timeCollector.Stop( "Gaussian Blur" ); - } - - timeCollector.Start( "Compute Model Feature Weights" ); - - typedef itk::tube::Function::TubeExponentialResolutionWeightFunction< - typename TubeType::TubePointType, FloatType > - WeightFunctionType; - typedef typename RegistrationMethodType::FeatureWeightsType - PointWeightsType; - typedef itk::tube::TubePointWeightsCalculator< Dimension, - TubeType, WeightFunctionType, PointWeightsType > - PointWeightsCalculatorType; - - typename WeightFunctionType::Pointer weightFunction = - WeightFunctionType::New(); - typename PointWeightsCalculatorType::Pointer resolutionWeightsCalculator = - PointWeightsCalculatorType::New(); - - resolutionWeightsCalculator->SetTubeTreeSpatialObject( - subSampleTubeTreeFilter->GetOutput() ); - resolutionWeightsCalculator->SetPointWeightFunction( weightFunction ); - resolutionWeightsCalculator->Compute(); - - pointWeights = resolutionWeightsCalculator->GetPointWeights(); - - timeCollector.Stop( "Compute Model Feature Weights" ); - - return EXIT_SUCCESS; -} - -} //namespace - -#endif // End !defined( __tubePreProcessRegistrationInputs_hxx ) diff --git a/examples/Applications/ExtractMetricImageSlice/CMakeLists.txt b/examples/Applications/RegisterSpatialObjectsToImage/CMakeLists.txt similarity index 95% rename from examples/Applications/ExtractMetricImageSlice/CMakeLists.txt rename to examples/Applications/RegisterSpatialObjectsToImage/CMakeLists.txt index e4545eaa4..19427477c 100644 --- a/examples/Applications/ExtractMetricImageSlice/CMakeLists.txt +++ b/examples/Applications/RegisterSpatialObjectsToImage/CMakeLists.txt @@ -20,7 +20,7 @@ # ############################################################################## -set( MODULE_NAME ExtractMetricImageSlice ) +set( MODULE_NAME RegisterSpatialObjectsToImage ) SEMMacroBuildCLI( NAME ${MODULE_NAME} diff --git a/examples/Applications/RegisterImageToTubesUsingRigidTransform/README.md b/examples/Applications/RegisterSpatialObjectsToImage/README.md similarity index 100% rename from examples/Applications/RegisterImageToTubesUsingRigidTransform/README.md rename to examples/Applications/RegisterSpatialObjectsToImage/README.md diff --git a/examples/Applications/RegisterSpatialObjectsToImage/RegisterSpatialObjectsToImage.cxx b/examples/Applications/RegisterSpatialObjectsToImage/RegisterSpatialObjectsToImage.cxx new file mode 100644 index 000000000..3d419cede --- /dev/null +++ b/examples/Applications/RegisterSpatialObjectsToImage/RegisterSpatialObjectsToImage.cxx @@ -0,0 +1,501 @@ +/*========================================================================= + +Library: TubeTK + +Copyright Kitware Inc. + +All rights reserved. + +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. + +=========================================================================*/ + +#include "RegisterSpatialObjectsToImageCLP.h" + +#include "itktubeSpatialObjectToImageRegistrationHelper.h" + +#include "itkImage.h" +#include "itkImageFileReader.h" +#include "itkSpatialObjectReader.h" +#include "itkSpatialObjectWriter.h" +#include "itkMultiThreaderBase.h" + +template< class TPixel, unsigned int VDimension > +int DoIt( int argc, char * argv[] ); + +// Must follow include of "...CLP.h" and forward declaration of int DoIt( ... ). +#include "../CLI/tubeCLIHelperFunctions.h" + + +template < class TPixelType, unsigned int TDimension > +int DoIt( int argc, char * argv[] ) +{ + + PARSE_ARGS; + + + enum VerboseLevelEnum { SILENT, STANDARD, VERBOSE }; + VerboseLevelEnum verbosity = SILENT; + if( verbosityLevel == "Standard" ) + { + verbosity = STANDARD; + } + else if( verbosityLevel == "Verbose" ) + { + verbosity = VERBOSE; + } + + typedef typename itk::Image< TPixelType, TDimension > ImageType; + + typedef itk::ImageFileReader< ImageType > ImageReaderType; + typedef itk::SpatialObjectReader< TDimension, float > SpatialObjectReaderType; + + typedef typename itk::tube::SpatialObjectToImageRegistrationHelper< + TDimension, ImageType > RegistrationType; + + typename RegistrationType::Pointer reger = RegistrationType::New(); + + typedef typename RegistrationType::SpatialObjectType SpatialObjectType; + + reger->SetReportProgress( true ); + + if( verbosity >= STANDARD ) + { + std::cout << "###Loading fixed image..."; + } + typename ImageReaderType::Pointer imgReader = ImageReaderType::New(); + imgReader->SetFileName( fixedImage ); + imgReader->Update(); + reger->SetFixedImage( imgReader->GetOutput() ); + if( verbosity >= STANDARD ) + { + std::cout << "###DONE" << std::endl; + } + + if( verbosity >= STANDARD ) + { + std::cout << "###Loading moving spatial object..."; + } + typename SpatialObjectReaderType::Pointer soReader = + SpatialObjectReaderType::New(); + soReader->SetFileName( movingSpatialObject ); + soReader->Update(); + reger->SetMovingSpatialObject( soReader->GetOutput() ); + if( verbosity >= STANDARD ) + { + std::cout << "###DONE" << std::endl; + } + + if( loadTransform.size() > 1 ) + { + if( verbosity >= STANDARD ) + { + std::cout << "###Loading transform..."; + } + reger->LoadTransform( loadTransform, invertLoadedTransform ); + if( verbosity >= STANDARD ) + { + std::cout << "###DONE" << std::endl; + } + } + + if( fixedLandmarks.size() > 1 || movingLandmarks.size() > 1 ) + { + if( initialization != "Landmarks" ) + { + std::cout << "WARNING: Landmarks specified, but initialization " + << "process was not told to use landmarks. " << std::endl; + std::cout << "Changing initialization to use landmarks." << std::endl; + reger->SetInitialMethodEnum( RegistrationType::INIT_WITH_LANDMARKS ); + } + } + if( skipInitialRandomSearch ) + { + reger->SetUseEvolutionaryOptimization( false ); + } + else + { + reger->SetUseEvolutionaryOptimization( true ); + } + + if( initialization == "Landmarks" ) + { + reger->SetInitialMethodEnum( RegistrationType::INIT_WITH_LANDMARKS ); + reger->SetFixedLandmarks( fixedLandmarks ); + reger->SetMovingLandmarks( movingLandmarks ); + } + else if( initialization == "ImageCenters" ) + { + if( verbosity >= STANDARD ) + { + std::cout << "###Initialization: ImageCenters" << std::endl; + } + reger->SetInitialMethodEnum( + RegistrationType::INIT_WITH_IMAGE_CENTERS ); + } + else if( initialization == "CentersOfMass" ) + { + if( verbosity >= STANDARD ) + { + std::cout << "###Initialization: CentersOfMass" << std::endl; + } + reger->SetInitialMethodEnum( + RegistrationType::INIT_WITH_CENTERS_OF_MASS ); + } + else // if( initialization == "None" ) + { + if( verbosity >= STANDARD ) + { + std::cout << "###Initialization: None" << std::endl; + } + reger->SetInitialMethodEnum( RegistrationType::INIT_WITH_NONE ); + } + + if( registration == "None" ) + { + if( verbosity >= STANDARD ) + { + std::cout << "###Registration: None" << std::endl; + } + reger->SetEnableInitialRegistration( false ); + reger->SetEnableRigidRegistration( false ); + reger->SetEnableAffineRegistration( false ); + } + else if( registration == "Initial" ) + { + if( verbosity >= STANDARD ) + { + std::cout << "###Registration: Initial" << std::endl; + } + reger->SetEnableInitialRegistration( true ); + reger->SetEnableRigidRegistration( false ); + reger->SetEnableAffineRegistration( false ); + } + else if( registration == "Rigid" ) + { + if( verbosity >= STANDARD ) + { + std::cout << "###Registration: Rigid" << std::endl; + } + reger->SetEnableInitialRegistration( false ); + reger->SetEnableRigidRegistration( true ); + reger->SetEnableAffineRegistration( false ); + } + else if( registration == "Affine" ) + { + if( verbosity >= STANDARD ) + { + std::cout << "###Registration: Affine" << std::endl; + } + reger->SetEnableInitialRegistration( false ); + reger->SetEnableRigidRegistration( false ); + reger->SetEnableAffineRegistration( true ); + } + else if( registration == "PipelineRigid" ) + { + if( verbosity >= STANDARD ) + { + std::cout << "###Registration: PipelineRigid" << std::endl; + } + reger->SetEnableInitialRegistration( true ); + reger->SetEnableRigidRegistration( true ); + reger->SetEnableAffineRegistration( false ); + } + else if( registration == "PipelineAffine" ) + { + if( verbosity >= STANDARD ) + { + std::cout << "###Registration: PipelineAffine" << std::endl; + } + reger->SetEnableInitialRegistration( true ); + reger->SetEnableRigidRegistration( true ); + reger->SetEnableAffineRegistration( true ); + } + + if( metric == "ImageIntensityMetric" ) + { + if( verbosity >= STANDARD ) + { + std::cout << "###Metric: ImageIntensityMetric" << std::endl; + } + reger->SetRigidMetricMethodEnum( RegistrationType + ::OptimizedRegistrationMethodType + ::IMAGE_INTENSITY_METRIC ); + reger->SetAffineMetricMethodEnum( RegistrationType + ::OptimizedRegistrationMethodType + ::IMAGE_INTENSITY_METRIC ); + } + + typedef typename itk::ImageFileReader< + itk::Image< unsigned char, TDimension > > ImageReader; + typedef typename itk::ImageMaskSpatialObject< TDimension > + ImageMaskSpatialObject; + + if( fixedImageMask != "" ) + { + reger->SetUseFixedImageMaskObject( true ); + + typename ImageReader::Pointer reader = ImageReader::New(); + reader->SetFileName( fixedImageMask ); + try + { + reader->Update(); + } + catch( itk::ExceptionObject & exception ) + { + std::cerr << "Exception caught while loading fixed image mask." + << std::endl; + std::cerr << exception << std::endl; + return EXIT_FAILURE; + } + + typename ImageMaskSpatialObject::Pointer mask = + ImageMaskSpatialObject::New(); + mask->SetImage( reader->GetOutput() ); + reger->SetFixedImageMaskObject( mask ); + + if( verbosity >= STANDARD ) + { + std::cout << "###useFixedImageMaskObject: true" << std::endl; + } + } + else + { + reger->SetUseFixedImageMaskObject( false ); + if( verbosity >= STANDARD ) + { + std::cout << "###useFixedImageMaskObject: false" << std::endl; + } + } + + + if( movingSpatialObjectMask != "" ) + { + reger->SetUseMovingSpatialObjectMaskObject( true ); + + typename ImageReader::Pointer reader = ImageReader::New(); + reader->SetFileName( movingSpatialObjectMask ); + try + { + reader->Update(); + } + catch( itk::ExceptionObject & exception ) + { + std::cerr << "Exception caught while loading moving image mask." + << std::endl; + std::cerr << exception << std::endl; + return EXIT_FAILURE; + } + + typename ImageMaskSpatialObject::Pointer mask = + ImageMaskSpatialObject::New(); + mask->SetImage( reader->GetOutput() ); + reger->SetMovingSpatialObjectMaskObject( mask ); + + if( verbosity >= STANDARD ) + { + std::cout << "###useMovingSpatialObjectMaskObject: true" << std::endl; + } + } + else + { + reger->SetUseMovingSpatialObjectMaskObject( false ); + if( verbosity >= STANDARD ) + { + std::cout << "###useMovingSpatialObjectMaskObject: false" << std::endl; + } + } + + reger->SetRandomNumberSeed( randomNumberSeed ); + + reger->SetRigidMaxIterations( rigidMaxIterations ); + if( verbosity >= STANDARD ) + { + std::cout << "###RigidMaxIterations: " << rigidMaxIterations + << std::endl; + } + + reger->SetAffineMaxIterations( affineMaxIterations ); + if( verbosity >= STANDARD ) + { + std::cout << "###AffineMaxIterations: " << affineMaxIterations + << std::endl; + } + + reger->SetRigidSamplingRatio( rigidSamplingRatio ); + if( verbosity >= STANDARD ) + { + std::cout << "###RigidSamplingRatio: " << rigidSamplingRatio + << std::endl; + } + reger->SetAffineSamplingRatio( affineSamplingRatio ); + if( verbosity >= STANDARD ) + { + std::cout << "###AffineSamplingRatio: " << affineSamplingRatio + << std::endl; + } + + reger->SetExpectedOffsetMagnitude( expectedOffset ); + if( verbosity >= STANDARD ) + { + std::cout << "###ExpectedOffsetPixelMagnitude: " << expectedOffset + << std::endl; + } + + reger->SetExpectedRotationMagnitude( expectedRotation ); + if( verbosity >= STANDARD ) + { + std::cout << "###ExpectedRotationMagnitude: " << expectedRotation + << std::endl; + } + + reger->SetExpectedScaleMagnitude( expectedScale ); + if( verbosity >= STANDARD ) + { + std::cout << "###ExpectedScaleMagnitude: " << expectedScale + << std::endl; + } + + reger->SetExpectedSkewMagnitude( expectedSkew ); + if( verbosity >= STANDARD ) + { + std::cout << "###ExpectedSkewMagnitude: " << expectedSkew + << std::endl; + } + + try + { + if( verbosity >= STANDARD ) + { + std::cout << "###Starting registration..." << std::endl; + } + reger->Update(); + } + catch( itk::ExceptionObject & exception ) + { + std::cerr << "Exception caught during helper class registration." + << exception << std::endl; + std::cerr << "Current Matrix Transform = " << std::endl; + reger->GetCurrentMatrixTransform()->Print( std::cerr, 2 ); + return EXIT_FAILURE; + } + catch( ... ) + { + std::cerr << "Uncaught exception during helper class registration." + << std::endl; + return EXIT_FAILURE; + } + + if( resampledSpatialObject.size() > 1 ) + { + if( verbosity >= STANDARD ) + { + std::cout << "###Resampling..." << std::endl; + } + typename SpatialObjectType::ConstPointer resultSpatialObject; + try + { + resultSpatialObject = reger->ResampleSpatialObject( NULL, NULL, + resampledPortion ); + } + catch( itk::ExceptionObject & exception ) + { + std::cerr << "Exception caught during helper class resampling." + << exception << std::endl; + std::cerr << "Current Matrix Transform = " << std::endl; + reger->GetCurrentMatrixTransform()->Print( std::cerr, 2 ); + return EXIT_FAILURE; + } + catch( ... ) + { + std::cerr << "Uncaught exception during helper class resampling." + << std::endl; + return EXIT_FAILURE; + } + + try + { + typedef itk::SpatialObjectWriter< TDimension > SOWriterType; + typename SOWriterType::Pointer soWriter = + SOWriterType::New(); + soWriter->SetFileName( resampledSpatialObject ); + soWriter->SetInput( resultSpatialObject ); + soWriter->Update(); + } + catch( itk::ExceptionObject & exception ) + { + std::cerr << + "Exception caught during helper class resampled image saving." + << exception << std::endl; + return EXIT_FAILURE; + } + catch( ... ) + { + std::cerr << + "Uncaught exception during helper class resampled image saving." + << std::endl; + return EXIT_FAILURE; + } + } + + if( saveTransform.size() > 1 ) + { + try + { + reger->SaveTransform( saveTransform ); + } + catch( itk::ExceptionObject & exception ) + { + std::cerr << "Exception caught during helper class transform saving." + << exception << std::endl; + return EXIT_FAILURE; + } + catch( ... ) + { + std::cerr << "Uncaught exception during helper class saving." + << std::endl; + return EXIT_FAILURE; + } + } + + return EXIT_SUCCESS; +} + +int main( int argc, char * argv[] ) +{ + PARSE_ARGS; + + enum VerboseLevelEnum { SILENT, STANDARD, VERBOSE }; + VerboseLevelEnum verbosity = SILENT; + if( verbosityLevel == "Standard" ) + { + verbosity = STANDARD; + } + else if( verbosityLevel == "Verbose" ) + { + verbosity = VERBOSE; + } + + if( numberOfThreads != 0 ) + { + if( verbosity >= STANDARD ) + { + std::cout << "###numberOfThreads: " << numberOfThreads << std::endl; + } + itk::MultiThreaderBase::SetGlobalDefaultNumberOfThreads( numberOfThreads ); + } + + tube::ParseArgsAndCallDoIt( fixedImage, argc, argv ); + + return EXIT_SUCCESS; +} diff --git a/examples/Applications/RegisterSpatialObjectsToImage/RegisterSpatialObjectsToImage.xml b/examples/Applications/RegisterSpatialObjectsToImage/RegisterSpatialObjectsToImage.xml new file mode 100644 index 000000000..272748f6b --- /dev/null +++ b/examples/Applications/RegisterSpatialObjectsToImage/RegisterSpatialObjectsToImage.xml @@ -0,0 +1,231 @@ + + + TubeTK + RegisterSpatialObjectsToImage (TubeTK) + Provides rigid and affine registration methods for aligning Tubes, Surfaces, and Points with an image + Stephen R Aylward (Kitware) + + + Input and output parameters + + fixedImage + + input + 0 + Image which defines the space into which the moving image is registered + + + movingSpatialObject + + input + 1 + The objects to be registered to the fixed image + + + resampledSpatialObject + + output + resampledSpatialObject + Registration results + + + + resampledPortion + + input + resampledPortion + Only apply a portion of the transform. This scalar enables, for example, 1/2 of the transform magnitude to be applied. + 1.0 + + + + + Common parameters + + loadTransform + + Load a transform that is immediately applied to the moving spatial object + loadTransform + input + + + + invertLoadedTransform + + Invert the loaded transform before applying it to the moving spatial object + invertLoadedTransform + input + false + + + saveTransform + + Save the transform that results from registration + saveTransform + output + + + + skipInitialRandomSearch + Skips initial random search (skips the evolutionary optimizer) during the registration process and uses only the gradient optimizer + + skipInitialRandomSearch + + + initialization + Method to prime the registration process + + initialization + None + Landmarks + ImageCenters + CentersOfMass + CentersOfMass + + + registration + Method for the registration process + + registration + None + Initial + Rigid + Affine + PipelineRigid + PipelineAffine + PipelineAffine + + + metric + Method to quantify object-to-image match + + metric + ImageIntensityMetric + ImageIntensityMetric + + + expectedOffset + Expected misalignment after initialization + + expectedOffset + 10 + + + expectedRotation + Expected misalignment after initialization + + expectedRotation + 0.1 + + + expectedScale + Expected misalignment after initialization + + expectedScale + 0.05 + + + expectedSkew + Expected misalignment after initialization + + expectedSkew + 0.01 + + + + + Parameters that determine how registration is performed + + verbosityLevel + Level of detail of reporting progress + + verbosityLevel + Silent + Standard + Verbose + Standard + + + fixedImageMask + + input + fixedImageMask + Image which defines a mask for the fixed image + + + movingSpatialObjectMask + + input + movingSpatialObjectMask + Image which defines a mask for the moving image + + + randomNumberSeed + Seed to generate a consistent random number sequence + + randomNumberSeed + 0 + + + numberOfThreads + Number of CPU threads to use + + numberOfThreads + 0 + + + + + Parameters that determine how initial registration is performed + + fixedLandmarks + Ordered list of landmarks in the fixed image + + fixedLandmarks + + + + movingLandmarks + Ordered list of landmarks in the moving image + + movingLandmarks + + + + + + Parameters that determine how registration is performed + + rigidMaxIterations + Maximum number of rigid optimization iterations + + rigidMaxIterations + 100 + + + rigidSamplingRatio + Portion of the image to use in computing the metric during rigid registration + + rigidSamplingRatio + 0.01 + + + + + Parameters that determine how registration is performed + + affineMaxIterations + Maximum number of affine optimization iterations + + affineMaxIterations + 50 + + + affineSamplingRatio + Portion of the image to use in computing the metric during affine registration + + affineSamplingRatio + 0.02 + + + diff --git a/examples/Applications/ComputeImageToTubeRigidMetricImage/Testing/CMakeLists.txt b/examples/Applications/RegisterSpatialObjectsToImage/Testing/CMakeLists.txt similarity index 88% rename from examples/Applications/ComputeImageToTubeRigidMetricImage/Testing/CMakeLists.txt rename to examples/Applications/RegisterSpatialObjectsToImage/Testing/CMakeLists.txt index 13f049699..19b91986e 100644 --- a/examples/Applications/ComputeImageToTubeRigidMetricImage/Testing/CMakeLists.txt +++ b/examples/Applications/RegisterSpatialObjectsToImage/Testing/CMakeLists.txt @@ -2,8 +2,7 @@ # # Library: TubeTK # -# Copyright 2010 Kitware Inc. 28 Corporate Drive, -# Clifton Park, NY, 12065, USA. +# Copyright Kitware Inc. # # All rights reserved. # @@ -30,4 +29,4 @@ itk_add_test( COMMAND ${PROJ_EXE} DATA{${TubeTK_DATA_ROOT}/Branch.n020.mha} DATA{${TubeTK_DATA_ROOT}/tube.tre} - ${ITK_TEST_OUTPUT_DIR}/${MODULE_NAME}Test1.mha ) + ${ITK_TEST_OUTPUT_DIR}/${MODULE_NAME}Test1.h5 ) diff --git a/examples/Applications/ComputeImageToTubeRigidMetricImage/Testing/README.md b/examples/Applications/RegisterSpatialObjectsToImage/Testing/README.md similarity index 100% rename from examples/Applications/ComputeImageToTubeRigidMetricImage/Testing/README.md rename to examples/Applications/RegisterSpatialObjectsToImage/Testing/README.md diff --git a/examples/Applications/ResampleTubes/ResampleTubes.cxx b/examples/Applications/ResampleTubes/ResampleTubes.cxx index 9e338d98f..7a11d3430 100644 --- a/examples/Applications/ResampleTubes/ResampleTubes.cxx +++ b/examples/Applications/ResampleTubes/ResampleTubes.cxx @@ -2,8 +2,7 @@ Library: TubeTK -Copyright 2010 Kitware Inc. 28 Corporate Drive, -Clifton Park, NY, 12065, USA. +Copyright Kitware Inc. All rights reserved. @@ -39,14 +38,16 @@ limitations under the License. #include "ResampleTubesCLP.h" template< unsigned int Dimension > -void WriteOutput( typename itk::GroupSpatialObject::Pointer - tubesGroup, const char * fileName ) +void WriteOutput( const itk::SpatialObject * soOutputP, + const char * fileName ) { typedef itk::SpatialObjectWriter< Dimension > SpatialObjectWriterType; + typename itk::SpatialObject::ConstPointer soOutput = soOutputP; + typename SpatialObjectWriterType::Pointer writer = SpatialObjectWriterType::New(); - writer->SetInput( tubesGroup ); + writer->SetInput( soOutput ); writer->SetFileName( fileName ); writer->Update(); } @@ -56,9 +57,10 @@ int DoIt( int argc, char * argv[] ) { PARSE_ARGS; - typedef itk::tube::ResampleTubesFilter< Dimension > FilterType; + typedef itk::tube::ResampleTubesFilter FilterType; + typedef itk::GroupSpatialObject GroupType; + typename FilterType::Pointer filter = FilterType::New(); - typedef typename FilterType::TubeGroupType GroupSpatialObjectType; double progress = 0.0; itk::TimeProbesCollectorBase timeCollector; @@ -70,8 +72,7 @@ int DoIt( int argc, char * argv[] ) // Read in the tubes timeCollector.Start( "Read tubes" ); - typename GroupSpatialObjectType::Pointer tubesGroup = - GroupSpatialObjectType::New(); + typename GroupType::Pointer inputGroup = GroupType::New(); typedef itk::SpatialObjectReader< Dimension > SpatialObjectReaderType; typename SpatialObjectReaderType::Pointer reader = @@ -79,39 +80,12 @@ int DoIt( int argc, char * argv[] ) reader->SetFileName( inputTubeFile.c_str() ); reader->Update(); - tubesGroup = reader->GetGroup(); - if( tubesGroup.IsNotNull() ) - { - /* - if( true ) - { - typedef typename FilterType::TubeSpatialObjectType TubeSpatialObjectType; - char soTypeName[80]; - strcpy( soTypeName, "TubeSpatialObject" ); - typename TubeSpatialObjectType::ChildrenListPointer tubeList = - tubesGroup->GetChildren( tubesGroup->GetMaximumDepth(), - soTypeName ); - typename TubeSpatialObjectType::ChildrenListType::iterator it = - tubeList->begin(); - while( it != tubeList->end() ) - { - auto itP = static_cast(it->GetPointer()) - ->GetPoints().rbegin(); - std::cout << "o1 " << itP->GetPositionInObjectSpace() << std::endl; - ++itP; - std::cout << "o2 " << itP->GetPositionInObjectSpace() << std::endl; - ++itP; - std::cout << "o3 " << itP->GetPositionInObjectSpace() << std::endl; - ++it; - } - tubeList->clear(); - delete tubeList; - } - */ + inputGroup = reader->GetGroup(); + inputGroup->Update(); - tubesGroup->Update(); - filter->SetInput( tubesGroup ); - filter->SetInputSpatialObject( tubesGroup ); + if( inputGroup.IsNotNull() ) + { + filter->SetInput( inputGroup ); } else { @@ -172,9 +146,6 @@ int DoIt( int argc, char * argv[] ) filter->Update(); timeCollector.Stop( "Run Filter" ); - //std::cout << "Output # of children = " - //<< filter->GetOutput()->GetNumberOfChildren() << std::endl; - progress = 0.9; progressReporter.Report( progress ); diff --git a/examples/Applications/ResampleTubes/Testing/CMakeLists.txt b/examples/Applications/ResampleTubes/Testing/CMakeLists.txt index 1ee9de6e2..8ffb915b2 100644 --- a/examples/Applications/ResampleTubes/Testing/CMakeLists.txt +++ b/examples/Applications/ResampleTubes/Testing/CMakeLists.txt @@ -2,8 +2,7 @@ # # Library: TubeTK # -# Copyright 2010 Kitware Inc. 28 Corporate Drive, -# Clifton Park, NY, 12065, USA. +# Copyright Kitware Inc. # # All rights reserved. # diff --git a/examples/Applications/SegmentTubeUsingMinimalPath/SegmentTubeUsingMinimalPath.cxx b/examples/Applications/SegmentTubeUsingMinimalPath/SegmentTubeUsingMinimalPath.cxx index e0c512627..d8a52dcaf 100644 --- a/examples/Applications/SegmentTubeUsingMinimalPath/SegmentTubeUsingMinimalPath.cxx +++ b/examples/Applications/SegmentTubeUsingMinimalPath/SegmentTubeUsingMinimalPath.cxx @@ -99,7 +99,6 @@ int DoIt( int argc, char * argv[] ) filter->SetRadiusImage( reader->GetOutput() ); filter->SetStartRadius( StartRadius ); filter->SetMaxRadius( MaxRadius ); - filter->SetStepSizeForRadiusEstimation( StepRadius ); } catch( itk::ExceptionObject & err ) { diff --git a/examples/Applications/SegmentTubeUsingMinimalPath/SegmentTubeUsingMinimalPath.xml b/examples/Applications/SegmentTubeUsingMinimalPath/SegmentTubeUsingMinimalPath.xml index 59435f29a..8b6267a5d 100644 --- a/examples/Applications/SegmentTubeUsingMinimalPath/SegmentTubeUsingMinimalPath.xml +++ b/examples/Applications/SegmentTubeUsingMinimalPath/SegmentTubeUsingMinimalPath.xml @@ -89,13 +89,6 @@ maxRadius 6 - - StepRadius - - Step size for radius estimation. - stepRadius - 0.05 - diff --git a/examples/CTP-Head/1-GenerateCTAFromCTP.ipynb b/examples/CTP-Head/1-GenerateCTAFromCTP.ipynb index 3fdd441d1..a52dcde9e 100644 --- a/examples/CTP-Head/1-GenerateCTAFromCTP.ipynb +++ b/examples/CTP-Head/1-GenerateCTAFromCTP.ipynb @@ -84,7 +84,7 @@ { "data": { "application/vnd.jupyter.widget-view+json": { - "model_id": "d0d8810fe64f495ab36b98153319c547", + "model_id": "de9a85c79a9441d3a095648c155472fd", "version_major": 2, "version_minor": 0 }, @@ -111,22 +111,21 @@ "name": "stdout", "output_type": "stream", "text": [ - - "*** 7% : 55s : CTP04.mha ***\n", - "*** 13% : 57s : CTP06.mha ***\n", - "*** 20% : 56s : CTP08.mha ***\n", - "*** 27% : 55s : CTP10.mha ***\n", - "*** 33% : 54s : CTP12.mha ***\n", - "*** 40% : 53s : CTP14.mha ***\n", - "*** 47% : 58s : CTP16.mha ***\n", - "*** 53% : 56s : CTP18.mha ***\n", - "*** 60% : 56s : CTP20.mha ***\n", - "*** 67% : 54s : CTP22.mha ***\n", - "*** 73% : 55s : CTP24.mha ***\n", - "*** 80% : 54s : CTP26.mha ***\n", - "*** 87% : 54s : CTP28.mha ***\n", + "*** 7% : 64s : CTP04.mha ***\n", + "*** 13% : 65s : CTP06.mha ***\n", + "*** 20% : 63s : CTP08.mha ***\n", + "*** 27% : 64s : CTP10.mha ***\n", + "*** 33% : 60s : CTP12.mha ***\n", + "*** 40% : 60s : CTP14.mha ***\n", + "*** 47% : 62s : CTP16.mha ***\n", + "*** 53% : 62s : CTP18.mha ***\n", + "*** 60% : 61s : CTP20.mha ***\n", + "*** 67% : 60s : CTP22.mha ***\n", + "*** 73% : 61s : CTP24.mha ***\n", + "*** 80% : 61s : CTP26.mha ***\n", + "*** 87% : 59s : CTP28.mha ***\n", "*** 93% : 60s : CTP30.mha ***\n", - "*** 100% : 59s : CTP32.mha ***\n", + "*** 100% : 61s : CTP32.mha ***\n", "Done\n" ] } @@ -236,13 +235,13 @@ }, { "cell_type": "code", - "execution_count": 10, + "execution_count": 7, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { - "model_id": "857ab11b9b1b41d4ba016f6761a1247d", + "model_id": "460952a317fa4680865b999f6140752c", "version_major": 2, "version_minor": 0 }, @@ -284,7 +283,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.8.3" + "version": "3.7.10" } }, "nbformat": 4, diff --git a/examples/CTP-Head/2-SegmentBrainFromCTPCTA.ipynb b/examples/CTP-Head/2-SegmentBrainFromCTPCTA.ipynb index a84aa43fc..5d37634b3 100644 --- a/examples/CTP-Head/2-SegmentBrainFromCTPCTA.ipynb +++ b/examples/CTP-Head/2-SegmentBrainFromCTPCTA.ipynb @@ -68,7 +68,7 @@ { "data": { "application/vnd.jupyter.widget-view+json": { - "model_id": "00a2aaa203384f1c955d2ef4e35bf32f", + "model_id": "7ed590ddbcca46fd83bad59a9e77a2bc", "version_major": 2, "version_minor": 0 }, @@ -94,7 +94,7 @@ { "data": { "application/vnd.jupyter.widget-view+json": { - "model_id": "2e30260b8b6d4970bde69d81ce6c3610", + "model_id": "89ef2dcf99b340288cdfb0afb972ed53", "version_major": 2, "version_minor": 0 }, @@ -129,14 +129,14 @@ "name": "stdout", "output_type": "stream", "text": [ - "*** 0 : 12% : 35s ***\n", - "*** 1 : 25% : 33s ***\n", - "*** 2 : 38% : 30s ***\n", - "*** 3 : 50% : 33s ***\n", - "*** 4 : 62% : 37s ***\n", - "*** 5 : 75% : 32s ***\n", - "*** 6 : 88% : 34s ***\n", - "*** 7 : 100% : 32s ***\n" + "*** 0 : 12% : 46s ***\n", + "*** 1 : 25% : 44s ***\n", + "*** 2 : 38% : 40s ***\n", + "*** 3 : 50% : 49s ***\n", + "*** 4 : 62% : 47s ***\n", + "*** 5 : 75% : 43s ***\n", + "*** 6 : 88% : 48s ***\n", + "*** 7 : 100% : 53s ***\n" ] } ], @@ -211,7 +211,7 @@ { "data": { "application/vnd.jupyter.widget-view+json": { - "model_id": "e6f60a0ba2d54ddea21e6d28dee73ed4", + "model_id": "e1c404d1c0d846f7ad5029a9d2cd64db", "version_major": 2, "version_minor": 0 }, @@ -238,7 +238,7 @@ { "data": { "application/vnd.jupyter.widget-view+json": { - "model_id": "845f58d02dd7433bb522cbae5b84b1f6", + "model_id": "2512e876f4f8406e970cb70a03bd0deb", "version_major": 2, "version_minor": 0 }, @@ -301,7 +301,7 @@ { "data": { "application/vnd.jupyter.widget-view+json": { - "model_id": "2883c7aaea894cf19617c2edcc58ed0b", + "model_id": "dff680f41432432aa992de800ecb5823", "version_major": 2, "version_minor": 0 }, @@ -351,7 +351,7 @@ { "data": { "application/vnd.jupyter.widget-view+json": { - "model_id": "83328456ed7944b095c4d1ec429fe679", + "model_id": "00157849c43444d0a9d98cfd17581643", "version_major": 2, "version_minor": 0 }, @@ -397,7 +397,7 @@ { "data": { "application/vnd.jupyter.widget-view+json": { - "model_id": "65e2d378f0b04194bc46bc76e610b24b", + "model_id": "0227eed105ce49379cc92afb2ab57c7c", "version_major": 2, "version_minor": 0 }, @@ -453,7 +453,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.8.3" + "version": "3.7.10" } }, "nbformat": 4, diff --git a/examples/CTP-Head/3-CreateBinaryVesselsFromCTPCTA.ipynb b/examples/CTP-Head/3-CreateBinaryVesselsFromCTPCTA.ipynb index 61a84db97..4c8ccdfc9 100644 --- a/examples/CTP-Head/3-CreateBinaryVesselsFromCTPCTA.ipynb +++ b/examples/CTP-Head/3-CreateBinaryVesselsFromCTPCTA.ipynb @@ -11,7 +11,7 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 1, "metadata": {}, "outputs": [], "source": [ @@ -25,7 +25,7 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 2, "metadata": {}, "outputs": [], "source": [ @@ -42,13 +42,13 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { - "model_id": "8a4d0906aa3a4316ae1a7a00d9add363", + "model_id": "2130778f5f2d4b17aa7e2da544406563", "version_major": 2, "version_minor": 0 }, @@ -66,7 +66,7 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 4, "metadata": {}, "outputs": [], "source": [ @@ -88,7 +88,7 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 5, "metadata": {}, "outputs": [ { @@ -121,13 +121,13 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": 6, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { - "model_id": "463bd6c9c9114629988b0937d5a3ad81", + "model_id": "8273ce1297bf48f7bb5815995a744c44", "version_major": 2, "version_minor": 0 }, @@ -145,7 +145,7 @@ }, { "cell_type": "code", - "execution_count": 9, + "execution_count": 7, "metadata": { "scrolled": true }, @@ -154,8 +154,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "[[ -11.42652893 -149.88652039 357.57658386]\n", - " [ -4.23602295 -145.46159363 296.73384094]\n", + "[[ -4.23602295 -145.46159363 296.73384094]\n", " [ -33.55116272 -160.39572144 298.94630432]\n", " [ -52.35710144 -206.85745239 296.73384094]\n", " [ -25.80754089 -144.90847778 278.48101807]\n", @@ -168,7 +167,8 @@ " [ -43.50724792 -140.48355103 327.70832825]\n", " [ 26.18534851 -133.29304504 285.1184082 ]\n", " [ -46.82594299 -157.63014221 276.82167053]\n", - " [ -18.61703491 -128.86811829 290.64956665]]\n" + " [ -18.61703491 -128.86811829 290.64956665]\n", + " [ -31.33869934 -128.86811829 297.28695679]]\n" ] } ], @@ -199,28 +199,28 @@ }, { "cell_type": "code", - "execution_count": 10, + "execution_count": 8, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "**** Processing seed 0 : [ -11.42652893 -149.88652039 357.57658386]\n", - "**** Processing seed 1 : [ -4.23602295 -145.46159363 296.73384094]\n", - "**** Processing seed 2 : [ -33.55116272 -160.39572144 298.94630432]\n", - "**** Processing seed 3 : [ -52.35710144 -206.85745239 296.73384094]\n", - "**** Processing seed 4 : [ -25.80754089 -144.90847778 278.48101807]\n", - "**** Processing seed 5 : [ -48.48529053 -193.02955627 305.03057861]\n", - "**** Processing seed 6 : [ 0.74201965 -167.03311157 264.1000061 ]\n", - "**** Processing seed 7 : [ -45.16659546 -175.88296509 317.75224304]\n", - "**** Processing seed 8 : [ -5.34225464 -133.29304504 307.24304199]\n", - "**** Processing seed 9 : [ -58.44137573 -155.97079468 292.86203003]\n", - "**** Processing seed 10 : [ -6.44848633 -155.41767883 264.1000061 ]\n", - "**** Processing seed 11 : [ -43.50724792 -140.48355103 327.70832825]\n", - "**** Processing seed 12 : [ 26.18534851 -133.29304504 285.1184082 ]\n", - "**** Processing seed 13 : [ -46.82594299 -157.63014221 276.82167053]\n", - "**** Processing seed 14 : [ -18.61703491 -128.86811829 290.64956665]\n" + "**** Processing seed 0 : [ -4.23602295 -145.46159363 296.73384094]\n", + "**** Processing seed 1 : [ -33.55116272 -160.39572144 298.94630432]\n", + "**** Processing seed 2 : [ -52.35710144 -206.85745239 296.73384094]\n", + "**** Processing seed 3 : [ -25.80754089 -144.90847778 278.48101807]\n", + "**** Processing seed 4 : [ -48.48529053 -193.02955627 305.03057861]\n", + "**** Processing seed 5 : [ 0.74201965 -167.03311157 264.1000061 ]\n", + "**** Processing seed 6 : [ -45.16659546 -175.88296509 317.75224304]\n", + "**** Processing seed 7 : [ -5.34225464 -133.29304504 307.24304199]\n", + "**** Processing seed 8 : [ -58.44137573 -155.97079468 292.86203003]\n", + "**** Processing seed 9 : [ -6.44848633 -155.41767883 264.1000061 ]\n", + "**** Processing seed 10 : [ -43.50724792 -140.48355103 327.70832825]\n", + "**** Processing seed 11 : [ 26.18534851 -133.29304504 285.1184082 ]\n", + "**** Processing seed 12 : [ -46.82594299 -157.63014221 276.82167053]\n", + "**** Processing seed 13 : [ -18.61703491 -128.86811829 290.64956665]\n", + "**** Processing seed 14 : [ -31.33869934 -128.86811829 297.28695679]\n" ] } ], @@ -240,13 +240,13 @@ }, { "cell_type": "code", - "execution_count": 11, + "execution_count": 9, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { - "model_id": "7a45792b565448dfa5e16439bf2b7091", + "model_id": "6cf4e97b23284babbbea303ca890486a", "version_major": 2, "version_minor": 0 }, @@ -267,7 +267,7 @@ }, { "cell_type": "code", - "execution_count": 12, + "execution_count": 10, "metadata": {}, "outputs": [], "source": [ @@ -284,13 +284,13 @@ }, { "cell_type": "code", - "execution_count": 13, + "execution_count": 11, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { - "model_id": "406d101cb39e42c6b8e7d3dacfd9d593", + "model_id": "1c076e7382c44780af543f9ac8aa9882", "version_major": 2, "version_minor": 0 }, @@ -308,7 +308,7 @@ }, { "cell_type": "code", - "execution_count": 14, + "execution_count": 12, "metadata": {}, "outputs": [], "source": [ @@ -327,7 +327,7 @@ }, { "cell_type": "code", - "execution_count": 15, + "execution_count": 13, "metadata": { "scrolled": true }, @@ -335,7 +335,7 @@ { "data": { "application/vnd.jupyter.widget-view+json": { - "model_id": "45e5ababc0544b768eb05f835431d9c2", + "model_id": "4c4cced2556c430d970025baaaad9545", "version_major": 2, "version_minor": 0 }, @@ -364,7 +364,7 @@ }, { "cell_type": "code", - "execution_count": 16, + "execution_count": 14, "metadata": {}, "outputs": [], "source": [ @@ -397,7 +397,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.8.3" + "version": "3.7.10" } }, "nbformat": 4, diff --git a/examples/CTP-Head/4-SegmentVesselsUsingDiffEnhancedImage.ipynb b/examples/CTP-Head/4-SegmentVesselsUsingDiffEnhancedImage.ipynb index 91190e67b..4b3e21cdb 100644 --- a/examples/CTP-Head/4-SegmentVesselsUsingDiffEnhancedImage.ipynb +++ b/examples/CTP-Head/4-SegmentVesselsUsingDiffEnhancedImage.ipynb @@ -9,7 +9,7 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 1, "metadata": {}, "outputs": [], "source": [ @@ -23,7 +23,7 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 2, "metadata": {}, "outputs": [], "source": [ @@ -35,7 +35,7 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 3, "metadata": {}, "outputs": [], "source": [ @@ -52,13 +52,13 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { - "model_id": "2577d750013c415b999f82502021b6b0", + "model_id": "c8ca5598d82749859909aa31a22420cd", "version_major": 2, "version_minor": 0 }, @@ -76,7 +76,7 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": 5, "metadata": {}, "outputs": [], "source": [ @@ -99,7 +99,7 @@ }, { "cell_type": "code", - "execution_count": 10, + "execution_count": 6, "metadata": { "scrolled": false }, @@ -107,7 +107,7 @@ { "data": { "application/vnd.jupyter.widget-view+json": { - "model_id": "6ea5fdbeb44f4a6998d6c34125bc9bc2", + "model_id": "18607326b3d14f3dab19ce042f2e7ca9", "version_major": 2, "version_minor": 0 }, @@ -125,7 +125,7 @@ }, { "cell_type": "code", - "execution_count": 11, + "execution_count": 7, "metadata": { "scrolled": true }, @@ -133,7 +133,7 @@ { "data": { "application/vnd.jupyter.widget-view+json": { - "model_id": "7cfead2576424c218a27ddcb3cb897bc", + "model_id": "acd2c6ba7aa64166b5c4b0dbe7d8ffe3", "version_major": 2, "version_minor": 0 }, @@ -159,7 +159,7 @@ }, { "cell_type": "code", - "execution_count": 12, + "execution_count": 15, "metadata": {}, "outputs": [], "source": [ @@ -174,8 +174,8 @@ "vSeg.SetRadiusInObjectSpace( 0.8 )\n", "vSeg.SetBorderInIndexSpace(3)\n", "vSeg.SetSeedMask( im1SeedRadius )\n", - "vSeg.SetSeedRadiusMask( im1SeedRadius )\n", - "vSeg.SetOptimizeRadius(False)\n", + "#vSeg.SetSeedRadiusMask( im1SeedRadius )\n", + "vSeg.SetOptimizeRadius(True)\n", "vSeg.SetUseSeedMaskAsProbabilities(True)\n", "vSeg.SetSeedExtractionMinimumProbability(0.4)\n", "#vSeg.SetSeedMaskMaximumNumberOfPoints( numSeeds )\n", @@ -184,7 +184,7 @@ }, { "cell_type": "code", - "execution_count": 13, + "execution_count": 16, "metadata": { "scrolled": true }, @@ -192,7 +192,7 @@ { "data": { "application/vnd.jupyter.widget-view+json": { - "model_id": "e5c06e1274324785ab238529bf08a4d7", + "model_id": "f5266bea3f1244a0a992831ffdb63189", "version_major": 2, "version_minor": 0 }, @@ -211,7 +211,7 @@ }, { "cell_type": "code", - "execution_count": 14, + "execution_count": 17, "metadata": {}, "outputs": [], "source": [ @@ -224,10 +224,15 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 18, "metadata": {}, "outputs": [], - "source": [] + "source": [ + "VTPWriter = itk.WriteTubesAsPolyData.New()\n", + "VTPWriter.SetInput(vSeg.GetTubeGroup())\n", + "VTPWriter.SetFileName(dir+\"diff3-Vessels.vtp\")\n", + "VTPWriter.Update()" + ] } ], "metadata": { @@ -246,7 +251,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.8.3" + "version": "3.7.10" } }, "nbformat": 4, diff --git a/examples/MRA-Head/Demo-SegmentBrightVesselsFromBrainMRA.ipynb b/examples/MRA-Head/Demo-SegmentBrightVesselsFromBrainMRA.ipynb index 37023815a..32d9e084c 100644 --- a/examples/MRA-Head/Demo-SegmentBrightVesselsFromBrainMRA.ipynb +++ b/examples/MRA-Head/Demo-SegmentBrightVesselsFromBrainMRA.ipynb @@ -4,7 +4,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "This notebook is intended to demonstrate how vessel segmentation methods of ITKTubeTK can be applied to multi-channel MRI (MRA + T1, T2, etc)." + "This notebook is intended to demonstrate how vessel segmentation methods of ITKTubeTK can be applied to multi-channel MRA." ] }, { @@ -40,31 +40,16 @@ "cell_type": "code", "execution_count": 3, "metadata": { - "scrolled": false + "scrolled": true }, - "outputs": [ - { - "data": { - "application/vnd.jupyter.widget-view+json": { - "model_id": "a6c14e58af794d9ab7862ab18d4d4389", - "version_major": 2, - "version_minor": 0 - }, - "text/plain": [ - "Viewer(geometries=[], gradient_opacity=0.22, point_sets=[], rendered_image=m_Filter->SetDataMinMaxLimits( minLimit, maxLimit ); }; + tubeWrapForceSetMacro( BorderInIndexSpace, int, Filter ); tubeWrapSetConstReferenceMacro( ExtractBoundMinInIndexSpace, IndexType, @@ -258,26 +261,17 @@ class SegmentTubes: tubeWrapSetMacro( RadiusStart, double, RadiusFilter ); tubeWrapGetMacro( RadiusStart, double, RadiusFilter ); - tubeWrapSetMacro( RadiusStep, double, RadiusFilter ); - tubeWrapGetMacro( RadiusStep, double, RadiusFilter ); - - tubeWrapSetMacro( RadiusTolerance, double, RadiusFilter ); - tubeWrapGetMacro( RadiusTolerance, double, RadiusFilter ); - tubeWrapSetMacro( MinMedialness, double, RadiusFilter ); tubeWrapGetMacro( MinMedialness, double, RadiusFilter ); tubeWrapSetMacro( MinMedialnessStart, double, RadiusFilter ); tubeWrapGetMacro( MinMedialnessStart, double, RadiusFilter ); - tubeWrapSetMacro( NumKernelPoints, unsigned int, RadiusFilter ); - tubeWrapGetMacro( NumKernelPoints, unsigned int, RadiusFilter ); + tubeWrapSetMacro( KernelNumberOfPoints, unsigned int, RadiusFilter ); + tubeWrapGetMacro( KernelNumberOfPoints, unsigned int, RadiusFilter ); tubeWrapSetMacro( KernelPointStep, unsigned int, RadiusFilter ); tubeWrapGetMacro( KernelPointStep, unsigned int, RadiusFilter ); - tubeWrapSetMacro( KernelExtent, double, RadiusFilter ); - tubeWrapGetMacro( KernelExtent, double, RadiusFilter ); - bool ExtractRadii( TubeType * tube ) { return m_RadiusFilter->ExtractRadii( tube ); }; diff --git a/setup.py b/setup.py index 0d297a0a0..7c5c367a0 100644 --- a/setup.py +++ b/setup.py @@ -45,7 +45,7 @@ keywords='ITK InsightToolkit', url=r'https://itk.org/', install_requires=[ - r'itk>=5.2.0.post2', + r'itk>=5.2.1.post1', r'itk-minimalpathextraction>=1.2.0' ] ) diff --git a/src/Filtering.cmake b/src/Filtering.cmake index ca04ae444..df2b643ec 100644 --- a/src/Filtering.cmake +++ b/src/Filtering.cmake @@ -42,6 +42,7 @@ set( TubeTK_Filtering_H_Files Filtering/itktubeGaussianDerivativeFilter.h Filtering/itktubeGaussianDerivativeImageSource.h Filtering/itktubeInverseIntensityImageFilter.h + Filtering/itktubeLimitedMinimumMaximumImageFilter.h Filtering/itktubeMinimumSpanningTreeVesselConnectivityFilter.h Filtering/itktubePadImageFilter.h Filtering/itktubeRegionFromReferenceImageFilter.h @@ -52,7 +53,7 @@ set( TubeTK_Filtering_H_Files Filtering/itktubeSpatialObjectToSpatialObjectFilter.h Filtering/itktubeStructureTensorRecursiveGaussianImageFilter.h Filtering/itktubeSubSampleTubeSpatialObjectFilter.h - Filtering/itktubeSubSampleTubeTreeSpatialObjectFilter.h + Filtering/itktubeSubSampleSpatialObjectFilter.h Filtering/itktubeSymmetricEigenVectorAnalysisImageFilter.h Filtering/itktubeTortuositySpatialObjectFilter.h Filtering/itktubeTubeEnhancingDiffusion2DImageFilter.h @@ -84,6 +85,7 @@ set( TubeTK_Filtering_HXX_Files Filtering/itktubeGaussianDerivativeFilter.hxx Filtering/itktubeGaussianDerivativeImageSource.hxx Filtering/itktubeInverseIntensityImageFilter.hxx + Filtering/itktubeLimitedMinimumMaximumImageFilter.hxx Filtering/itktubeMinimumSpanningTreeVesselConnectivityFilter.hxx Filtering/itktubePadImageFilter.hxx Filtering/itktubeRegionFromReferenceImageFilter.hxx @@ -94,7 +96,7 @@ set( TubeTK_Filtering_HXX_Files Filtering/itktubeSpatialObjectToSpatialObjectFilter.hxx Filtering/itktubeStructureTensorRecursiveGaussianImageFilter.hxx Filtering/itktubeSubSampleTubeSpatialObjectFilter.hxx - Filtering/itktubeSubSampleTubeTreeSpatialObjectFilter.hxx + Filtering/itktubeSubSampleSpatialObjectFilter.hxx Filtering/itktubeTortuositySpatialObjectFilter.h Filtering/itktubeTubeEnhancingDiffusion2DImageFilter.hxx Filtering/itktubeTubeSpatialObjectToDensityImageFilter.hxx diff --git a/src/Filtering/itktubeCropTubesFilter.hxx b/src/Filtering/itktubeCropTubesFilter.hxx index 1d9f37591..cdac2e810 100644 --- a/src/Filtering/itktubeCropTubesFilter.hxx +++ b/src/Filtering/itktubeCropTubesFilter.hxx @@ -64,6 +64,8 @@ CropTubesFilter< VDimension > TubeGroupType* pTargetTubeGroup = this->GetOutput(); pTargetTubeGroup->CopyInformation( pSourceTubeGroup ); + pTargetTubeGroup->SetId( pSourceTubeGroup->GetId() ); + pTargetTubeGroup->SetParentId( pSourceTubeGroup->GetParentId() ); pTargetTubeGroup->Update(); int targetTubeId=0; diff --git a/src/Filtering/itktubeLimitedMinimumMaximumImageFilter.h b/src/Filtering/itktubeLimitedMinimumMaximumImageFilter.h new file mode 100644 index 000000000..4ef51f1cb --- /dev/null +++ b/src/Filtering/itktubeLimitedMinimumMaximumImageFilter.h @@ -0,0 +1,165 @@ +/*========================================================================= + * + * Copyright NumFOCUS + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * 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 itktubeLimitedMinimumMaximumImageFilter_h +#define itktubeLimitedMinimumMaximumImageFilter_h + +#include "itkImageSink.h" +#include "itkSimpleDataObjectDecorator.h" +#include + +#include + +#include "itkNumericTraits.h" + +namespace itk +{ + +namespace tube +{ +/** \class LimitedMinimumMaximumImageFilter + * \brief Computes the minimum and the maximum intensity values of + * an image. + * + * It is templated over input image type only. + * + * This filter is automatically multi-threaded and can stream its + * input when NumberOfStreamDivisions is set to more than + * 1. The extrema are independently computed for each streamed and + * threaded region then merged. + * + * + * \ingroup Operators + * \sa StatisticsImageFilter + * \ingroup ITKImageStatistics + */ +template +class ITK_TEMPLATE_EXPORT LimitedMinimumMaximumImageFilter : public ImageSink +{ +public: + ITK_DISALLOW_COPY_AND_MOVE(LimitedMinimumMaximumImageFilter); + + /** Extract dimension from input image. */ + static constexpr unsigned int InputImageDimension = TInputImage::ImageDimension; + + /** Standard class type aliases. */ + using Self = LimitedMinimumMaximumImageFilter; + using Superclass = ImageSink; + using Pointer = SmartPointer; + using ConstPointer = SmartPointer; + + /** Image related type alias. */ + using InputImagePointer = typename TInputImage::Pointer; + + using RegionType = typename TInputImage::RegionType; + using SizeType = typename TInputImage::SizeType; + using IndexType = typename TInputImage::IndexType; + using PixelType = typename TInputImage::PixelType; + + /** Smart Pointer type to a DataObject. */ + using DataObjectPointer = typename DataObject::Pointer; + + /** Method for creation through the object factory. */ + itkNewMacro(Self); + + /** Run-time type information (and related methods). */ + itkTypeMacro(LimitedMinimumMaximumImageFilter, ImageToImageFilter); + + /** Image type alias support */ + using InputImageType = TInputImage; + + /** Type of DataObjects used for scalar outputs */ + using PixelObjectType = SimpleDataObjectDecorator; + + /** Return the computed Minimum. */ + itkGetDecoratedOutputMacro(Minimum, PixelType); + + /** Return the computed Maximum. */ + itkGetDecoratedOutputMacro(Maximum, PixelType); + + itkSetMacro( MinimumLimit, PixelType ); + itkGetMacro( MinimumLimit, PixelType ); + itkSetMacro( MaximumLimit, PixelType ); + itkGetMacro( MaximumLimit, PixelType ); + + /** Make a DataObject of the correct type to be used as the specified + * output. */ + using DataObjectIdentifierType = ProcessObject::DataObjectIdentifierType; + using Superclass::MakeOutput; + DataObjectPointer + MakeOutput(const DataObjectIdentifierType & name) override; + + + // Change the access from protected to public to expose streaming option, a using statement can not be used due to + // limitations of wrapping. + void + SetNumberOfStreamDivisions(const unsigned int n) override + { + Superclass::SetNumberOfStreamDivisions(n); + } + unsigned int + GetNumberOfStreamDivisions() const override + { + return Superclass::GetNumberOfStreamDivisions(); + } + +#ifdef ITK_USE_CONCEPT_CHECKING + // Begin concept checking + itkConceptMacro(LessThanComparableCheck, (Concept::LessThanComparable)); + itkConceptMacro(GreaterThanComparableCheck, (Concept::GreaterThanComparable)); + itkConceptMacro(OStreamWritableCheck, (Concept::OStreamWritable)); + // End concept checking +#endif + +protected: + LimitedMinimumMaximumImageFilter(); + ~LimitedMinimumMaximumImageFilter() override = default; + void + PrintSelf(std::ostream & os, Indent indent) const override; + + /** Initialize some accumulators before any chunks are processes */ + void + BeforeStreamedGenerateData() override; + + /** Do final mean and variance computation from data accumulated in threads. + */ + void + AfterStreamedGenerateData() override; + + void + ThreadedStreamedGenerateData(const RegionType &) override; + + itkSetDecoratedOutputMacro(Minimum, PixelType); + itkSetDecoratedOutputMacro(Maximum, PixelType); + +private: + PixelType m_ThreadMin; + PixelType m_ThreadMax; + + PixelType m_MinimumLimit; + PixelType m_MaximumLimit; + + std::mutex m_Mutex; +}; +} // end namespace tube +} // end namespace itk + +#ifndef ITK_MANUAL_INSTANTIATION +# include "itktubeLimitedMinimumMaximumImageFilter.hxx" +#endif + +#endif diff --git a/src/Filtering/itktubeLimitedMinimumMaximumImageFilter.hxx b/src/Filtering/itktubeLimitedMinimumMaximumImageFilter.hxx new file mode 100644 index 000000000..c344b4741 --- /dev/null +++ b/src/Filtering/itktubeLimitedMinimumMaximumImageFilter.hxx @@ -0,0 +1,145 @@ +/*========================================================================= + * + * Copyright NumFOCUS + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * 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 itktubeLimitedMinimumMaximumImageFilter_hxx +#define itktubeLimitedMinimumMaximumImageFilter_hxx +#include "itktubeLimitedMinimumMaximumImageFilter.h" + + +#include "itkImageScanlineIterator.h" +#include + +#include + +namespace itk +{ + +namespace tube +{ + +template +LimitedMinimumMaximumImageFilter::LimitedMinimumMaximumImageFilter() +{ + Self::SetMinimumLimit(NumericTraits::NonpositiveMin()); + Self::SetMaximumLimit(NumericTraits::max()); + + Self::SetMinimum(NumericTraits::max()); + Self::SetMaximum(NumericTraits::NonpositiveMin()); +} + +template +DataObject::Pointer +LimitedMinimumMaximumImageFilter::MakeOutput(const DataObjectIdentifierType & name) +{ + if (name == "Minimum" || name == "Maximum") + { + return PixelObjectType::New(); + } + return Superclass::MakeOutput(name); +} + +template +void +LimitedMinimumMaximumImageFilter::BeforeStreamedGenerateData() +{ + Superclass::BeforeStreamedGenerateData(); + + m_ThreadMin = m_MaximumLimit; + m_ThreadMax = m_MinimumLimit; +} + +template +void +LimitedMinimumMaximumImageFilter::AfterStreamedGenerateData() +{ + Superclass::AfterStreamedGenerateData(); + + this->SetMinimum(m_ThreadMin); + this->SetMaximum(m_ThreadMax); +} + +template +void +LimitedMinimumMaximumImageFilter::ThreadedStreamedGenerateData(const RegionType & regionForThread) +{ + if (regionForThread.GetNumberOfPixels() == 0) + { + return; + } + + PixelType localMin = m_MaximumLimit; + PixelType localMax = m_MinimumLimit; + + ImageScanlineConstIterator it(this->GetInput(), regionForThread); + + + // do the work + while (!it.IsAtEnd()) + { + // Handle the odd pixel separately + if (regionForThread.GetSize(0) % 2 == 1) + { + const PixelType value = it.Get(); + localMin = std::min(value, localMin); + localMax = std::max(value, localMax); + ++it; + } + + while (!it.IsAtEndOfLine()) + { + const PixelType value1 = it.Get(); + ++it; + const PixelType value2 = it.Get(); + ++it; + + if (value1 > value2) + { + localMax = std::max(value1, localMax); + localMin = std::min(value2, localMin); + } + else + { + localMax = std::max(value2, localMax); + localMin = std::min(value1, localMin); + } + } + it.NextLine(); + } + + std::lock_guard mutexHolder(m_Mutex); + m_ThreadMin = std::min(localMin, m_ThreadMin); + m_ThreadMax = std::max(localMax, m_ThreadMax); +} + +template +void +LimitedMinimumMaximumImageFilter::PrintSelf(std::ostream & os, Indent indent) const +{ + Superclass::PrintSelf(os, indent); + + os << indent << "Minimum Limit: " << static_cast::PrintType>(m_MinimumLimit) + << std::endl; + os << indent << "Maximum Limit: " << static_cast::PrintType>(m_MaximumLimit) + << std::endl; + os << indent << "Minimum: " << static_cast::PrintType>(this->GetMinimum()) + << std::endl; + os << indent << "Maximum: " << static_cast::PrintType>(this->GetMaximum()) + << std::endl; +} +} // end namespace tube +} // end namespace itk +#endif diff --git a/src/Filtering/itktubeMinimumSpanningTreeVesselConnectivityFilter.h b/src/Filtering/itktubeMinimumSpanningTreeVesselConnectivityFilter.h index 4ea0bf72c..642d6681f 100644 --- a/src/Filtering/itktubeMinimumSpanningTreeVesselConnectivityFilter.h +++ b/src/Filtering/itktubeMinimumSpanningTreeVesselConnectivityFilter.h @@ -45,14 +45,14 @@ namespace tube * \brief Computes connectivity between tubes in a TRE file * */ -template< unsigned int VDimension > +template< unsigned int ObjectDimension > class MinimumSpanningTreeVesselConnectivityFilter : public SpatialObjectToSpatialObjectFilter< - GroupSpatialObject< VDimension >, GroupSpatialObject< VDimension > > + GroupSpatialObject< ObjectDimension >, GroupSpatialObject< ObjectDimension > > { public: /** Standard class typedefs. */ - typedef GroupSpatialObject< VDimension > TubeGroupType; + typedef GroupSpatialObject< ObjectDimension > TubeGroupType; typedef MinimumSpanningTreeVesselConnectivityFilter Self; @@ -61,7 +61,7 @@ class MinimumSpanningTreeVesselConnectivityFilter typedef SmartPointer< Self > Pointer; typedef SmartPointer< const Self > ConstPointer; - typedef TubeSpatialObject< VDimension > TubeType; + typedef TubeSpatialObject< ObjectDimension > TubeType; typedef typename TubeType::Pointer TubePointerType; typedef typename TubeType::ConstPointer TubeConstPointerType; typedef itk::IndexValueType TubeIdType; diff --git a/src/Filtering/itktubeMinimumSpanningTreeVesselConnectivityFilter.hxx b/src/Filtering/itktubeMinimumSpanningTreeVesselConnectivityFilter.hxx index 1f9e07420..ad6a6c6fd 100644 --- a/src/Filtering/itktubeMinimumSpanningTreeVesselConnectivityFilter.hxx +++ b/src/Filtering/itktubeMinimumSpanningTreeVesselConnectivityFilter.hxx @@ -39,8 +39,8 @@ namespace tube { //---------------------------------------------------------------------------- -template< unsigned int VDimension > -MinimumSpanningTreeVesselConnectivityFilter< VDimension > +template< unsigned int ObjectDimension > +MinimumSpanningTreeVesselConnectivityFilter< ObjectDimension > ::MinimumSpanningTreeVesselConnectivityFilter( void ) { m_MaxTubeDistanceToRadiusRatio = 2.0; @@ -50,8 +50,8 @@ MinimumSpanningTreeVesselConnectivityFilter< VDimension > } //---------------------------------------------------------------------------- -template< unsigned int VDimension > -MinimumSpanningTreeVesselConnectivityFilter< VDimension > +template< unsigned int ObjectDimension > +MinimumSpanningTreeVesselConnectivityFilter< ObjectDimension > ::~MinimumSpanningTreeVesselConnectivityFilter( void ) { m_RootTubeIdList.clear(); @@ -59,18 +59,18 @@ MinimumSpanningTreeVesselConnectivityFilter< VDimension > m_TubeIdToObjectMap.clear(); } -template< unsigned int VDimension > +template< unsigned int ObjectDimension > bool -MinimumSpanningTreeVesselConnectivityFilter< VDimension > +MinimumSpanningTreeVesselConnectivityFilter< ObjectDimension > ::GraphEdgeType ::operator>( const GraphEdgeType & rhs ) const { return weight > rhs.weight; } -template< unsigned int VDimension > +template< unsigned int ObjectDimension > bool -MinimumSpanningTreeVesselConnectivityFilter< VDimension > +MinimumSpanningTreeVesselConnectivityFilter< ObjectDimension > ::ConnectionPointType ::operator>( const ConnectionPointType & rhs ) const { @@ -84,9 +84,9 @@ MinimumSpanningTreeVesselConnectivityFilter< VDimension > } } -template< unsigned int VDimension > +template< unsigned int ObjectDimension > bool -MinimumSpanningTreeVesselConnectivityFilter< VDimension > +MinimumSpanningTreeVesselConnectivityFilter< ObjectDimension > ::TubePQElementType ::operator<( const TubePQElementType & rhs ) const { @@ -100,26 +100,26 @@ MinimumSpanningTreeVesselConnectivityFilter< VDimension > } } -template< unsigned int VDimension > +template< unsigned int ObjectDimension > void -MinimumSpanningTreeVesselConnectivityFilter< VDimension > +MinimumSpanningTreeVesselConnectivityFilter< ObjectDimension > ::SetRootTubeIdList( const TubeIdListType & rootTubeIdList ) { m_RootTubeIdList = rootTubeIdList; } -template< unsigned int VDimension > -const typename MinimumSpanningTreeVesselConnectivityFilter< VDimension >:: +template< unsigned int ObjectDimension > +const typename MinimumSpanningTreeVesselConnectivityFilter< ObjectDimension >:: TubeIdListType & -MinimumSpanningTreeVesselConnectivityFilter< VDimension > +MinimumSpanningTreeVesselConnectivityFilter< ObjectDimension > ::GetRootTubeIdList( void ) const { return m_RootTubeIdList; } -template< unsigned int VDimension > +template< unsigned int ObjectDimension > void -MinimumSpanningTreeVesselConnectivityFilter< VDimension > +MinimumSpanningTreeVesselConnectivityFilter< ObjectDimension > ::BuildTubeGraph( void ) { const TubeGroupType * inputTubeGroup = this->GetInput(); @@ -334,9 +334,9 @@ MinimumSpanningTreeVesselConnectivityFilter< VDimension > delete pTubeList; } -template< unsigned int VDimension > +template< unsigned int ObjectDimension > void -MinimumSpanningTreeVesselConnectivityFilter< VDimension > +MinimumSpanningTreeVesselConnectivityFilter< ObjectDimension > ::VisitTube( TubePointerType pTube ) { TubeIdType tubeId = pTube->GetId(); @@ -359,9 +359,9 @@ MinimumSpanningTreeVesselConnectivityFilter< VDimension > } } -template< unsigned int VDimension > +template< unsigned int ObjectDimension > void -MinimumSpanningTreeVesselConnectivityFilter< VDimension > +MinimumSpanningTreeVesselConnectivityFilter< ObjectDimension > ::RunMinimumSpanningTree( TubeIdType rootTubeId ) { TubeGroupType * outputTubeGroup = this->GetOutput(); @@ -376,7 +376,6 @@ MinimumSpanningTreeVesselConnectivityFilter< VDimension > TubePointerType inputRootTube = m_TubeIdToObjectMap[rootTubeId]; TubePointerType rootTube = inputRootTube->Clone(); - // TODO: make CopyInformation of itk::SpatialObject do this rootTube->GetObjectToParentTransform()->SetFixedParameters( inputRootTube->GetObjectToParentTransform()->GetFixedParameters() ); rootTube->GetObjectToParentTransform()->SetParameters( @@ -399,6 +398,7 @@ MinimumSpanningTreeVesselConnectivityFilter< VDimension > } } outputTubeGroup->AddChild( rootTube ); + rootTube->Update(); // recusrively process all children in increasing order of connection weight int numChildren = 0; @@ -424,7 +424,6 @@ MinimumSpanningTreeVesselConnectivityFilter< VDimension > // get tube object TubePointerType curTube = eTop.targetTube->Clone(); - // TODO: make CopyInformation of itk::SpatialObject do this curTube->GetObjectToParentTransform()->SetFixedParameters( eTop.targetTube->GetObjectToParentTransform()->GetFixedParameters() ); curTube->GetObjectToParentTransform()->SetParameters( @@ -478,9 +477,9 @@ MinimumSpanningTreeVesselConnectivityFilter< VDimension > ++m_numOutputConnectedComponents; } -template< unsigned int VDimension > +template< unsigned int ObjectDimension > void -MinimumSpanningTreeVesselConnectivityFilter< VDimension > +MinimumSpanningTreeVesselConnectivityFilter< ObjectDimension > ::ComputeTubeConnectivity( void ) { const TubeGroupType * inputTubeGroup = this->GetInput(); @@ -488,10 +487,9 @@ MinimumSpanningTreeVesselConnectivityFilter< VDimension > // initialize output and copy metadata from input outputTubeGroup->Clear(); - outputTubeGroup->CopyInformation( inputTubeGroup ); + outputTubeGroup->SetId( inputTubeGroup->GetId() ); - // TODO: make CopyInformation of itk::SpatialObject do this outputTubeGroup->GetObjectToParentTransform()->SetFixedParameters( inputTubeGroup->GetObjectToParentTransform()->GetFixedParameters() ); outputTubeGroup->GetObjectToParentTransform()->SetParameters( @@ -523,7 +521,7 @@ MinimumSpanningTreeVesselConnectivityFilter< VDimension > TubePQElementType epTube; epTube.tubeId = *itRootTubeId; epTube.outDegree = m_TubeGraph[epTube.tubeId].size(); - ::tube::TubeMathFilters< VDimension > tubeMath; + ::tube::TubeMathFilters< ObjectDimension > tubeMath; tubeMath.SetInputTube( m_TubeIdToObjectMap[epTube.tubeId] ); epTube.tubeLength = tubeMath.ComputeTubeLength(); maxpqVOutDegree.push( epTube ); @@ -531,14 +529,14 @@ MinimumSpanningTreeVesselConnectivityFilter< VDimension > } else { - // push all tubes into a priority queue with outDegree as priotiry + // push all tubes into a priority queue with outDegree as priority for( typename TubeAdjacencyListGraphType::const_iterator itV = m_TubeGraph.begin(); itV != m_TubeGraph.end(); ++itV ) { TubePQElementType epTube; epTube.tubeId = itV->first; epTube.outDegree = itV->second.size(); - ::tube::TubeMathFilters< VDimension > tubeMath; + ::tube::TubeMathFilters< ObjectDimension > tubeMath; tubeMath.SetInputTube( m_TubeIdToObjectMap[epTube.tubeId] ); epTube.tubeLength = tubeMath.ComputeTubeLength(); if( m_RemoveOrphanTubes && epTube.outDegree == 0 ) @@ -566,11 +564,13 @@ MinimumSpanningTreeVesselConnectivityFilter< VDimension > tubeDebugMacro( << "Number of output connected components = " << m_numOutputConnectedComponents ); + outputTubeGroup->FixIdValidity(); + this->GraftOutput(outputTubeGroup); } -template< unsigned int VDimension > +template< unsigned int ObjectDimension > void -MinimumSpanningTreeVesselConnectivityFilter< VDimension > +MinimumSpanningTreeVesselConnectivityFilter< ObjectDimension > ::AddRemainingTubes( void ) { const TubeGroupType * inputTubeGroup = this->GetInput(); @@ -597,7 +597,6 @@ MinimumSpanningTreeVesselConnectivityFilter< VDimension > { TubePointerType curTube = pCurSourceTube->Clone(); - // TODO: make CopyInformation of itk::SpatialObject do this curTube->GetObjectToParentTransform()->SetFixedParameters( pCurSourceTube->GetObjectToParentTransform()->GetFixedParameters() ); curTube->GetObjectToParentTransform()->SetParameters( @@ -609,11 +608,13 @@ MinimumSpanningTreeVesselConnectivityFilter< VDimension > outputTubeGroup->AddChild( curTube ); } } + outputTubeGroup->FixIdValidity(); + this->GraftOutput(outputTubeGroup); } -template< unsigned int VDimension > +template< unsigned int ObjectDimension > void -MinimumSpanningTreeVesselConnectivityFilter< VDimension > +MinimumSpanningTreeVesselConnectivityFilter< ObjectDimension > ::GenerateData( void ) { BuildTubeGraph(); @@ -624,9 +625,9 @@ MinimumSpanningTreeVesselConnectivityFilter< VDimension > } } -template< unsigned int VDimension > +template< unsigned int ObjectDimension > void -MinimumSpanningTreeVesselConnectivityFilter< VDimension > +MinimumSpanningTreeVesselConnectivityFilter< ObjectDimension > ::PrintSelf( std::ostream & os, Indent indent ) const { this->Superclass::PrintSelf( os, indent ); diff --git a/src/Filtering/itktubeResampleTubesFilter.h b/src/Filtering/itktubeResampleTubesFilter.h index 43b02020c..51ba2e088 100644 --- a/src/Filtering/itktubeResampleTubesFilter.h +++ b/src/Filtering/itktubeResampleTubesFilter.h @@ -2,8 +2,7 @@ Library: TubeTK - Copyright 2010 Kitware Inc. 28 Corporate Drive, - Clifton Park, NY, 12065, USA. + Copyright Kitware Inc. All rights reserved. @@ -24,12 +23,11 @@ #ifndef __itktubeResampleTubesFilter_h #define __itktubeResampleTubesFilter_h -#include "itkGroupSpatialObject.h" +#include "itkSpatialObject.h" #include "itkImage.h" #include -#include "itktubeSpatialObjectToSpatialObjectFilter.h" -#include "itkTubeSpatialObject.h" -#include "itktubeTubeToTubeTransformFilter.h" +#include "itktubeSpatialObjectFilter.h" +#include "itktubePointBasedSpatialObjectTransformFilter.h" #include "itkTransformBase.h" namespace itk { @@ -40,27 +38,24 @@ namespace tube * \brief resamples a given tube spatial object. * */ -template< unsigned int VDimension > +template< unsigned int ObjectDimension > class ResampleTubesFilter - : public SpatialObjectToSpatialObjectFilter< - GroupSpatialObject< VDimension >, GroupSpatialObject< VDimension > > + : public SpatialObjectFilter< ObjectDimension > { public: /** Standard class typedefs. */ - typedef itk::GroupSpatialObject< VDimension > TubeGroupType; - typedef itk::TubeSpatialObject< VDimension > TubeSpatialObjectType; + typedef itk::SpatialObject< ObjectDimension > SpatialObjectType; - typedef ResampleTubesFilter< VDimension > Self; - typedef SpatialObjectToSpatialObjectFilter< TubeGroupType, TubeGroupType > - Superclass; + typedef ResampleTubesFilter< ObjectDimension > Self; + typedef SpatialObjectFilter< ObjectDimension > Superclass; typedef SmartPointer< Self > Pointer; typedef SmartPointer< const Self > ConstPointer; typedef char PixelType; - typedef itk::Image< PixelType, VDimension > ImageType; + typedef itk::Image< PixelType, ObjectDimension > ImageType; /** Typedefs for Displacement field tranform. */ - typedef itk::DisplacementFieldTransform< double, VDimension > + typedef itk::DisplacementFieldTransform< double, ObjectDimension > DisplacementFieldTransformType; typedef typename DisplacementFieldTransformType::DisplacementFieldType DisplacementFieldType; @@ -71,7 +66,7 @@ class ResampleTubesFilter /** Run-time type information ( and related methods ). */ itkTypeMacro( ResampleTubesFilter, - SpatialObjectToSpatialObjectFilter ); + SpatialObjectFilter ); /** Method for creation through the object factory. */ itkNewMacro( Self ); @@ -88,8 +83,6 @@ class ResampleTubesFilter itkSetMacro( UseInverseTransform, bool ); itkGetMacro( UseInverseTransform, bool ); - itkSetObjectMacro( InputSpatialObject, TubeGroupType ); - void SetDisplacementField( DisplacementFieldType* field ); void SetReadTransformList( const BaseTransformListType* tList ); @@ -112,16 +105,15 @@ class ResampleTubesFilter bool m_UseInverseTransform; const BaseTransformListType* m_ReadTransformList; typename DisplacementFieldType::Pointer m_DisplacementField; - typename TubeGroupType::Pointer m_InputSpatialObject; void ReadImageTransform - ( typename TubeGroupType::TransformType::Pointer &outputTransform ); - typename TubeGroupType::Pointer ApplyDisplacementFieldTransform - ( typename TubeGroupType::TransformType::Pointer outputTransform ); - typename TubeGroupType::Pointer ApplyInputTransform - ( typename TubeGroupType::TransformType::Pointer outputTransform ); - typename TubeGroupType::Pointer ApplyIdentityAffineTransform - ( typename TubeGroupType::TransformType::Pointer outputTransform ); + ( typename SpatialObjectType::TransformType::Pointer & outputTransform ); + typename SpatialObjectType::Pointer ApplyDisplacementFieldTransform + ( typename SpatialObjectType::TransformType::ConstPointer & outputTransform ); + typename SpatialObjectType::Pointer ApplyInputTransform + ( typename SpatialObjectType::TransformType::ConstPointer & outputTransform ); + typename SpatialObjectType::Pointer ApplyIdentityAffineTransform + ( typename SpatialObjectType::TransformType::ConstPointer & outputTransform ); }; // End class ResampleTubesFilter } // End namespace tube diff --git a/src/Filtering/itktubeResampleTubesFilter.hxx b/src/Filtering/itktubeResampleTubesFilter.hxx index 95e551d97..f5dd27815 100644 --- a/src/Filtering/itktubeResampleTubesFilter.hxx +++ b/src/Filtering/itktubeResampleTubesFilter.hxx @@ -2,8 +2,7 @@ Library: TubeTK - Copyright 2010 Kitware Inc. 28 Corporate Drive, - Clifton Park, NY, 12065, USA. + Copyright Kitware Inc. All rights reserved. @@ -31,10 +30,9 @@ #include "itkMath.h" #include "tubeMacro.h" -#include "tubeTubeMathFilters.h" -#include "tubeMatrixMath.h" -#include "itktubeSubSampleTubeTreeSpatialObjectFilter.h" +#include "itkTubeSpatialObject.h" +#include "itktubeSubSampleSpatialObjectFilter.h" namespace itk { @@ -42,56 +40,56 @@ namespace tube { //-------------------------------------------------------------------------- -template< unsigned int VDimension > -ResampleTubesFilter< VDimension > +template< unsigned int ObjectDimension > +ResampleTubesFilter< ObjectDimension > ::ResampleTubesFilter( void ) { m_UseInverseTransform = false; - m_MatchImage = NULL; - m_DisplacementField = NULL; - m_ReadTransformList = NULL; + m_MatchImage = nullptr; + m_DisplacementField = nullptr; + m_ReadTransformList = nullptr; } //-------------------------------------------------------------------------- -template< unsigned int VDimension > -ResampleTubesFilter< VDimension > +template< unsigned int ObjectDimension > +ResampleTubesFilter< ObjectDimension > ::~ResampleTubesFilter( void ) { } //-------------------------------------------------------------------------- -template< unsigned int VDimension > +template< unsigned int ObjectDimension > void -ResampleTubesFilter< VDimension > +ResampleTubesFilter< ObjectDimension > ::SetDisplacementField( DisplacementFieldType * field ) { m_DisplacementField = field; } //-------------------------------------------------------------------------- -template< unsigned int VDimension > +template< unsigned int ObjectDimension > void -ResampleTubesFilter< VDimension > +ResampleTubesFilter< ObjectDimension > ::SetReadTransformList( const BaseTransformListType * tList ) { m_ReadTransformList = tList; } //-------------------------------------------------------------------------- -template< unsigned int VDimension > +template< unsigned int ObjectDimension > void -ResampleTubesFilter< VDimension > -::ReadImageTransform( typename TubeGroupType::TransformType::Pointer & +ResampleTubesFilter< ObjectDimension > +::ReadImageTransform( typename SpatialObjectType::TransformType::Pointer & outputTransform ) { typename ImageType::PointType origin = m_MatchImage->GetOrigin(); typename ImageType::DirectionType directions = m_MatchImage->GetDirection(); - outputTransform = TubeGroupType::TransformType::New(); + outputTransform = SpatialObjectType::TransformType::New(); outputTransform->SetIdentity(); - itk::Vector< double, VDimension > offset; - for( unsigned int i = 0; i < VDimension; ++i ) + itk::Vector< double, ObjectDimension > offset; + for( unsigned int i = 0; i < ObjectDimension; ++i ) { offset[i] = origin[i]; } @@ -100,17 +98,17 @@ ResampleTubesFilter< VDimension > } //-------------------------------------------------------------------------- -template< unsigned int VDimension > -typename itk::GroupSpatialObject< VDimension >::Pointer -ResampleTubesFilter< VDimension > +template< unsigned int ObjectDimension > +typename itk::SpatialObject< ObjectDimension >::Pointer +ResampleTubesFilter< ObjectDimension > ::ApplyDisplacementFieldTransform( typename - TubeGroupType::TransformType::Pointer outputTransform ) + SpatialObjectType::TransformType::ConstPointer & outputTransform ) { - const TubeGroupType * inputTubeGroup = this->GetInput(); + typename SpatialObjectType::ConstPointer inSO = this->GetInput(); /** Typedefs for Displacement field tranform filter. */ - typedef itk::tube::TubeToTubeTransformFilter< - DisplacementFieldTransformType, VDimension > + typedef itk::tube::PointBasedSpatialObjectTransformFilter< + DisplacementFieldTransformType, ObjectDimension > DisplacementFieldTransformFilterType; // Create new transform @@ -121,36 +119,37 @@ ResampleTubesFilter< VDimension > // Create the filter and apply typename DisplacementFieldTransformFilterType::Pointer filter = DisplacementFieldTransformFilterType::New(); - filter->SetInput( inputTubeGroup ); + filter->SetInput( inSO ); filter->SetTransform( transform ); filter->SetOutputObjectToParentTransform( outputTransform.GetPointer() ); - filter->GraftOutput( this->GetOutput() ); filter->Update(); - return filter->GetOutput(); + this->GraftOutput( filter->GetOutput() ); + + return this->GetOutput(); } //-------------------------------------------------------------------------- -template< unsigned int VDimension > -typename itk::GroupSpatialObject< VDimension >::Pointer -ResampleTubesFilter< VDimension > -::ApplyInputTransform( typename TubeGroupType::TransformType::Pointer +template< unsigned int ObjectDimension > +typename itk::SpatialObject< ObjectDimension >::Pointer +ResampleTubesFilter< ObjectDimension > +::ApplyInputTransform( typename SpatialObjectType::TransformType::ConstPointer & outputTransform ) { - typename TubeGroupType::Pointer tmpTubes; - tmpTubes = m_InputSpatialObject; + typename SpatialObjectType::ConstPointer inSO = this->GetInput(); /** Typedefs for transform read from a file */ - typedef itk::MatrixOffsetTransformBase< double, VDimension, VDimension > + typedef itk::MatrixOffsetTransformBase< double, ObjectDimension, ObjectDimension > MatrixOffsetTransformType; - typedef itk::tube::TubeToTubeTransformFilter< MatrixOffsetTransformType, - VDimension > + typedef itk::tube::PointBasedSpatialObjectTransformFilter< + MatrixOffsetTransformType, + ObjectDimension > MatrixOffsetTransformFilterType; BaseTransformListType::const_iterator tListIt; - for( tListIt = m_ReadTransformList->begin(); - tListIt != m_ReadTransformList->end(); ++tListIt ) + tListIt = m_ReadTransformList->begin(); + while( tListIt != m_ReadTransformList->end() ) { typename MatrixOffsetTransformType::Pointer transform = dynamic_cast< MatrixOffsetTransformType * >( ( *tListIt ).GetPointer() ); @@ -163,30 +162,34 @@ ResampleTubesFilter< VDimension > transform = ( MatrixOffsetTransformType * )ivT.GetPointer(); } - filter->SetInput( tmpTubes ); + filter->SetInput( inSO ); filter->SetTransform( transform ); filter->SetOutputObjectToParentTransform( outputTransform ); - filter->GraftOutput( this->GetOutput() ); filter->Update(); - tmpTubes = filter->GetOutput(); + + inSO = filter->GetOutput(); + this->GraftOutput( filter->GetOutput() ); + ++tListIt; } - return tmpTubes; + + return this->GetOutput(); } //-------------------------------------------------------------------------- -template< unsigned int VDimension > -typename itk::GroupSpatialObject< VDimension >::Pointer -ResampleTubesFilter< VDimension > +template< unsigned int ObjectDimension > +typename itk::SpatialObject< ObjectDimension >::Pointer +ResampleTubesFilter< ObjectDimension > ::ApplyIdentityAffineTransform( typename - TubeGroupType::TransformType::Pointer outputTransform ) + SpatialObjectType::TransformType::ConstPointer & outputTransform ) { - const TubeGroupType * inputTubeGroup = this->GetInput(); + typename SpatialObjectType::ConstPointer inSO = this->GetInput(); /** Typedefs for Affine Transform */ - typedef itk::AffineTransform< double, VDimension > + typedef itk::AffineTransform< double, ObjectDimension > AffineTransformType; - typedef itk::tube::TubeToTubeTransformFilter< AffineTransformType, - VDimension > + typedef itk::tube::PointBasedSpatialObjectTransformFilter< + AffineTransformType, + ObjectDimension > AffineTransformFilterType; typename AffineTransformType::Pointer identityAffineTransform = @@ -195,129 +198,93 @@ ResampleTubesFilter< VDimension > typename AffineTransformFilterType::Pointer filter = AffineTransformFilterType::New(); - filter->SetInput( inputTubeGroup ); + filter->SetInput( inSO ); filter->SetTransform( identityAffineTransform ); filter->SetOutputObjectToParentTransform( outputTransform ); - filter->GraftOutput( this->GetOutput() ); filter->Update(); - return filter->GetOutput(); + this->GraftOutput( filter->GetOutput() ); + + return this->GetOutput(); } //-------------------------------------------------------------------------- -template< unsigned int VDimension > +template< unsigned int ObjectDimension > void -ResampleTubesFilter< VDimension > +ResampleTubesFilter< ObjectDimension > ::GenerateData( void ) { - const TubeGroupType * inputTubeGroup = this->GetInput(); - typename TubeGroupType::Pointer tmpTubeGroup = nullptr; - /* - if( true ) - { - char soTypeName[80]; - strcpy( soTypeName, "TubeSpatialObject" ); - typename TubeSpatialObjectType::ChildrenListPointer tubeList = - inputTubeGroup->GetChildren( inputTubeGroup->GetMaximumDepth(), - soTypeName ); - typename TubeSpatialObjectType::ChildrenListType::iterator it = - tubeList->begin(); - while( it != tubeList->end() ) - { - auto itP = static_cast(it->GetPointer()) - ->GetPoints().rbegin(); - std::cout << "o1 " << itP->GetPositionInObjectSpace() << std::endl; - ++itP; - std::cout << "o2 " << itP->GetPositionInObjectSpace() << std::endl; - ++itP; - std::cout << "o3 " << itP->GetPositionInObjectSpace() << std::endl; - ++it; - } - tubeList->clear(); - delete tubeList; - } - */ + typename SpatialObjectType::ConstPointer inSO = this->GetInput(); + + typename SpatialObjectType::Pointer outSO = this->GetOutput(); - typename TubeGroupType::TransformType::Pointer outputTransform; + typename SpatialObjectType::TransformType::ConstPointer outputTransformConst; if( m_MatchImage ) { + typename SpatialObjectType::TransformType::Pointer outputTransform; this->ReadImageTransform( outputTransform ); + outputTransformConst = outputTransform.GetPointer(); } else { - char soTypeName[80]; - strcpy( soTypeName, "TubeSpatialObject" ); - typename TubeSpatialObjectType::ChildrenListPointer tubeList = - inputTubeGroup->GetChildren( inputTubeGroup->GetMaximumDepth(), - soTypeName ); - ( *( tubeList->begin() ) )->Update(); - outputTransform = ( *( tubeList->begin() ) )-> - GetObjectToWorldTransform(); - tubeList->clear(); - delete tubeList; + outputTransformConst = inSO->GetObjectToWorldTransform(); } + bool outSOUpdated = false; if( m_DisplacementField ) { - tmpTubeGroup = this->ApplyDisplacementFieldTransform( outputTransform ); + outSO = this->ApplyDisplacementFieldTransform( outputTransformConst ); + outSOUpdated = true; } else if( m_ReadTransformList ) { - tmpTubeGroup = this->ApplyInputTransform( outputTransform ); + outSO = this->ApplyInputTransform( outputTransformConst ); + outSOUpdated = true; } else if( m_MatchImage ) { - tmpTubeGroup = this->ApplyIdentityAffineTransform( outputTransform ); + outSO = this->ApplyIdentityAffineTransform( outputTransformConst ); + outSOUpdated = true; } if( m_SamplingFactor != 1 ) { /** Typedefs for Sub samppling filter */ - typedef itk::tube::SubSampleTubeTreeSpatialObjectFilter< TubeGroupType, - TubeSpatialObjectType > SubSampleTubeTreeFilterType; + typedef itk::tube::SubSampleSpatialObjectFilter + SubSampleFilterType; - typename SubSampleTubeTreeFilterType::Pointer subSampleTubeTreeFilter = - SubSampleTubeTreeFilterType::New(); - if( tmpTubeGroup.IsNotNull() ) + typename SubSampleFilterType::Pointer subSampleFilter = + SubSampleFilterType::New(); + if(outSOUpdated) { - subSampleTubeTreeFilter->SetInput( tmpTubeGroup ); + subSampleFilter->SetInput( outSO ); } else { - subSampleTubeTreeFilter->SetInput( inputTubeGroup ); + subSampleFilter->SetInput( inSO ); + subSampleFilter->GraftOutput( outSO ); } + subSampleFilter->SetSampling( m_SamplingFactor ); - subSampleTubeTreeFilter->SetSampling( m_SamplingFactor ); - - subSampleTubeTreeFilter->GraftOutput( this->GetOutput() ); try { - subSampleTubeTreeFilter->Update(); + subSampleFilter->Update(); } catch( const std::exception &e ) { std::cout << e.what(); return; } - //this->GraftOutput( subSampleTubeTreeFilter->GetOutput() ); - tmpTubeGroup = subSampleTubeTreeFilter->GetOutput(); + + this->GraftOutput( subSampleFilter->GetOutput() ); + outSO = subSampleFilter->GetOutput(); } - this->GraftOutput( tmpTubeGroup ); - /* - char soTypeName[80]; - strcpy( soTypeName, "TubeSpatialObject" ); - typename TubeSpatialObjectType::ChildrenListPointer inTubeList = - inputTubeGroup->GetChildren( inputTubeGroup->GetMaximumDepth(), - soTypeName ); - typename TubeSpatialObjectType::ChildrenListPointer outTubeList = - tmpTubeGroup->GetChildren( tmpTubeGroup->GetMaximumDepth(), - soTypeName );*/ } //-------------------------------------------------------------------------- -template< unsigned int VDimension > +template< unsigned int ObjectDimension > void -ResampleTubesFilter< VDimension > +ResampleTubesFilter< ObjectDimension > ::PrintSelf( std::ostream & os, Indent indent ) const { this->Superclass::PrintSelf( os, indent ); diff --git a/src/Filtering/itktubeSpatialObjectFilter.h b/src/Filtering/itktubeSpatialObjectFilter.h new file mode 100644 index 000000000..19faefb56 --- /dev/null +++ b/src/Filtering/itktubeSpatialObjectFilter.h @@ -0,0 +1,83 @@ +/*========================================================================= + +Library: TubeTK + +Copyright Kitware Inc. + +All rights reserved. + +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. + +=========================================================================*/ + +#ifndef __itktubeSpatialObjectFilter_h +#define __itktubeSpatialObjectFilter_h + +#include "itktubeSpatialObjectToSpatialObjectFilter.h" + +namespace itk +{ + +namespace tube +{ +/** \class SpatialObjectFilter + * + * \brief Base class for filters that take a SpatialObject as input + * and produce a SpatialObject as output. + */ +template< unsigned int ObjectDimension > +class SpatialObjectFilter + : public SpatialObjectToSpatialObjectFilter< SpatialObject, + SpatialObject > +{ +public: + /** Standard class typedefs */ + typedef SpatialObjectFilter Self; + typedef SpatialObjectToSpatialObjectFilter< SpatialObject, + SpatialObject > Superclass; + typedef SmartPointer< Self > Pointer; + typedef SmartPointer< const Self > ConstPointer; + + /** Run-time type information ( and related methods ). */ + itkTypeMacro( SpatialObjectFilter, SpatialObjectSource ); + + typedef SpatialObject SpatialObjectType; + + virtual void SetInput( const SpatialObjectType * spatialObject ) override; + + using Superclass::MakeOutput; + virtual ProcessObject::DataObjectPointer + MakeOutput( ProcessObject::DataObjectPointerArraySizeType idx ) override; + +protected: + SpatialObjectFilter( void ); + virtual ~SpatialObjectFilter( void ) {} + +private: + // purposely not implemented + SpatialObjectFilter( const Self & ); + + // purposely not implemented + void operator=( const Self & ); + +}; // End class SpatialObjectFilter + +} // End namespace tube + +} // End namespace itk + +#ifndef ITK_MANUAL_INSTANTIATION +#include "itktubeSpatialObjectFilter.hxx" +#endif + +#endif // End !defined( __itktubeSpatialObjectFilter_h ) diff --git a/src/Filtering/itktubeSpatialObjectFilter.hxx b/src/Filtering/itktubeSpatialObjectFilter.hxx new file mode 100644 index 000000000..20dad1e03 --- /dev/null +++ b/src/Filtering/itktubeSpatialObjectFilter.hxx @@ -0,0 +1,70 @@ +/*========================================================================= + +Library: TubeTK + +Copyright Kitware Inc. + +All rights reserved. + +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. + +=========================================================================*/ + +#ifndef __itktubeSpatialObjectFilter_hxx +#define __itktubeSpatialObjectFilter_hxx + +#include "itktubeSpatialObjectFilter.h" + +namespace itk +{ + +namespace tube +{ + +template< unsigned int ObjectDimension > +SpatialObjectFilter< ObjectDimension > +::SpatialObjectFilter( void ) +{ +} + +template< unsigned int ObjectDimension > +void +SpatialObjectFilter< ObjectDimension > +::SetInput( const SpatialObject * input ) +{ + // Process object is not const-correct so the const_cast is required here + this->SpatialObjectSource< SpatialObject >::SetNthInput( 0, + const_cast *>(input) ); + + typename SpatialObject::Pointer output = + static_cast *>(this->MakeOutput( 0 ).GetPointer()); + this->ProcessObject::SetNumberOfRequiredOutputs( 1 ); + this->ProcessObject::SetNthOutput( 0, output.GetPointer() ); +} + +template< unsigned int ObjectDimension > +ProcessObject::DataObjectPointer +SpatialObjectFilter< ObjectDimension > +::MakeOutput( ProcessObject::DataObjectPointerArraySizeType itkNotUsed( + idx ) ) +{ + return this->GetInput()->Clone().GetPointer(); +} + + + +} // End namespace tube + +} // End namespace itk + +#endif // End !defined( __itktubeSpatialObjectFilter_hxx ) diff --git a/src/Filtering/itktubeSpatialObjectSource.h b/src/Filtering/itktubeSpatialObjectSource.h index 2c98e70d1..10705ba20 100644 --- a/src/Filtering/itktubeSpatialObjectSource.h +++ b/src/Filtering/itktubeSpatialObjectSource.h @@ -2,8 +2,7 @@ Library: TubeTK -Copyright 2010 Kitware Inc. 28 Corporate Drive, -Clifton Park, NY, 12065, USA. +Copyright Kitware Inc. All rights reserved. diff --git a/src/Filtering/itktubeSpatialObjectSource.hxx b/src/Filtering/itktubeSpatialObjectSource.hxx index 980242df3..cb52f9fce 100644 --- a/src/Filtering/itktubeSpatialObjectSource.hxx +++ b/src/Filtering/itktubeSpatialObjectSource.hxx @@ -2,8 +2,7 @@ Library: TubeTK -Copyright 2010 Kitware Inc. 28 Corporate Drive, -Clifton Park, NY, 12065, USA. +Copyright Kitware Inc. All rights reserved. @@ -45,8 +44,6 @@ SpatialObjectSource< TOutputSpatialObject > this->MakeOutput( 0 ).GetPointer() ); this->ProcessObject::SetNumberOfRequiredOutputs( 1 ); this->ProcessObject::SetNthOutput( 0, output.GetPointer() ); - - itk::OutputWindow::SetInstance( itk::TextOutput::New() ); } diff --git a/src/Filtering/itktubeSpatialObjectToSpatialObjectFilter.h b/src/Filtering/itktubeSpatialObjectToSpatialObjectFilter.h index eade6bb66..85615a56e 100644 --- a/src/Filtering/itktubeSpatialObjectToSpatialObjectFilter.h +++ b/src/Filtering/itktubeSpatialObjectToSpatialObjectFilter.h @@ -2,8 +2,7 @@ Library: TubeTK -Copyright 2010 Kitware Inc. 28 Corporate Drive, -Clifton Park, NY, 12065, USA. +Copyright Kitware Inc. All rights reserved. diff --git a/src/Filtering/itktubeSpatialObjectToSpatialObjectFilter.hxx b/src/Filtering/itktubeSpatialObjectToSpatialObjectFilter.hxx index 3726d1c9a..ea5226270 100644 --- a/src/Filtering/itktubeSpatialObjectToSpatialObjectFilter.hxx +++ b/src/Filtering/itktubeSpatialObjectToSpatialObjectFilter.hxx @@ -2,8 +2,7 @@ Library: TubeTK -Copyright 2010 Kitware Inc. 28 Corporate Drive, -Clifton Park, NY, 12065, USA. +Copyright Kitware Inc. All rights reserved. @@ -26,8 +25,6 @@ limitations under the License. #include "itktubeSpatialObjectToSpatialObjectFilter.h" -#include - namespace itk { @@ -40,8 +37,6 @@ TOutputSpatialObject > ::SpatialObjectToSpatialObjectFilter( void ) { this->SetNumberOfRequiredInputs( 1 ); - - itk::OutputWindow::SetInstance( itk::TextOutput::New() ); } diff --git a/src/Filtering/itktubeSubSampleSpatialObjectFilter.h b/src/Filtering/itktubeSubSampleSpatialObjectFilter.h new file mode 100644 index 000000000..0f3433d77 --- /dev/null +++ b/src/Filtering/itktubeSubSampleSpatialObjectFilter.h @@ -0,0 +1,102 @@ +/*========================================================================= + +Library: TubeTK + +Copyright Kitware Inc. + +All rights reserved. + +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. + +=========================================================================*/ + +#ifndef __itktubeSubSampleSpatialObjectFilter_h +#define __itktubeSubSampleSpatialObjectFilter_h + +#include "itktubeSpatialObjectFilter.h" +#include "itkTubeSpatialObject.h" + +namespace itk +{ + +namespace tube +{ + +/** \class SubSampleSpatialObjectFilter + * \brief Sub-sample objects within a SpatialObject hierarchy. + * + * The input to this SpatialObjectFilter can be a single SpatialObject + * or a hierarchy of SpatialObject's that contain objects to be sub-sampled. + * All supported SpatialObjects in the output hierarchy will be sub-sampled by + * the \c Sampling factor. Non-supported spatial objects are passed to the + * output unchanged. + */ +template< unsigned int ObjectDimension=3 > +class SubSampleSpatialObjectFilter + : public SpatialObjectFilter< ObjectDimension > +{ +public: + /** Standard class typedefs. */ + typedef SubSampleSpatialObjectFilter Self; + typedef SpatialObjectFilter< ObjectDimension > Superclass; + typedef SmartPointer< Self > Pointer; + typedef SmartPointer< const Self > ConstPointer; + + typedef SpatialObject SpatialObjectType; + + /** Run-time type information ( and related methods ). */ + itkTypeMacro( SubSampleSpatialObjectFilter, + SpatialObjectFilter ); + + /** Method for creation through the object factory. */ + itkNewMacro( Self ); + + /** Set the sampling factor. The output points taken every sampling + * factor from the input points. */ + itkSetClampMacro( Sampling, SizeValueType, 1, NumericTraits< + SizeValueType >::max() ); + itkGetConstMacro( Sampling, SizeValueType ); + +protected: + typedef TubeSpatialObject< ObjectDimension > TubeSpatialObjectType; + + SubSampleSpatialObjectFilter( void ); + virtual ~SubSampleSpatialObjectFilter( void ); + + virtual void GenerateData( void ) override; + + /** Sub-sample at the at a given level, then sub-sample their + * children. */ + virtual void SubSampleLevel( const SpatialObjectType * input, + typename SpatialObjectType::Pointer output, bool graftOutput=false ); + +private: + // purposely not implemented + SubSampleSpatialObjectFilter( const Self & ); + + // purposely not implemented + void operator=( const Self & ); + + SizeValueType m_Sampling; + +}; // End class SubSampleSpatialObjectFilter + +} // End namespace tube + +} // End namespace itk + +#ifndef ITK_MANUAL_INSTANTIATION +#include "itktubeSubSampleSpatialObjectFilter.hxx" +#endif + +#endif // End !defined( __itktubeSubSampleSpatialObjectFilter_h ) \ No newline at end of file diff --git a/src/Filtering/itktubeSubSampleSpatialObjectFilter.hxx b/src/Filtering/itktubeSubSampleSpatialObjectFilter.hxx new file mode 100644 index 000000000..3af515d75 --- /dev/null +++ b/src/Filtering/itktubeSubSampleSpatialObjectFilter.hxx @@ -0,0 +1,133 @@ +/*========================================================================= + +Library: TubeTK + +Copyright Kitware Inc. + +All rights reserved. + +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. + +=========================================================================*/ + +#ifndef __itktubeSubSampleSpatialObjectFilter_hxx +#define __itktubeSubSampleSpatialObjectFilter_hxx + +#include "itktubeSubSampleSpatialObjectFilter.h" + +#include "itktubeSubSampleTubeSpatialObjectFilter.h" + +#include + +namespace itk +{ + +namespace tube +{ + +template< unsigned int ObjectDimension > +SubSampleSpatialObjectFilter< ObjectDimension > +::SubSampleSpatialObjectFilter( void ) + : m_Sampling( 1 ) +{ + SpatialObjectFactoryBase::RegisterDefaultSpatialObjects(); + SpatialObjectFactory< SpatialObjectType >::RegisterSpatialObject(); + SpatialObjectFactory< TubeSpatialObjectType >::RegisterSpatialObject(); +} + +template< unsigned int ObjectDimension > +SubSampleSpatialObjectFilter< ObjectDimension > +::~SubSampleSpatialObjectFilter( void ) +{ +} + +template< unsigned int ObjectDimension > +void +SubSampleSpatialObjectFilter< ObjectDimension > +::SubSampleLevel( const SpatialObjectType * input, + typename SpatialObjectType::Pointer output, bool graftOutput ) +{ + // We make the copy and sub-sample if it is a tube. + const TubeSpatialObjectType * inputAsTube = + dynamic_cast< const TubeSpatialObjectType * >( input ); + typename SpatialObjectType::Pointer newParent; + if( inputAsTube != NULL ) + { + typedef SubSampleTubeSpatialObjectFilter< ObjectDimension > + SubSampleTubeFilterType; + typename SubSampleTubeFilterType::Pointer subSampleTubeFilter + = SubSampleTubeFilterType::New(); + + subSampleTubeFilter->SetSampling( this->GetSampling() ); + subSampleTubeFilter->SetInput( inputAsTube ); + if( graftOutput ) + { + TubeSpatialObjectType * outputAsTube = + dynamic_cast< TubeSpatialObjectType * >( output.GetPointer() ); + subSampleTubeFilter->GraftOutput( outputAsTube ); + subSampleTubeFilter->Update(); + newParent = subSampleTubeFilter->GetOutput(); + this->GraftOutput( newParent ); + } + else + { + subSampleTubeFilter->Update(); + newParent = subSampleTubeFilter->GetOutput(); + output->AddChild( newParent ); + } + } + else + { + if( graftOutput ) + { + // Output = Input in baseclass + newParent = dynamic_cast< SpatialObjectType * >( this->GetOutput() ); + } + else + { + newParent = input->Clone(); + output->AddChild( newParent ); + } + } + + typedef typename SpatialObjectType::ChildrenListType ChildrenListType; + ChildrenListType *children = input->GetChildren(); + typename ChildrenListType::const_iterator it = children->begin(); + while( it != children->end() ) + { + this->SubSampleLevel( *it, newParent ); + ++it; + } + delete children; +} + + +template< unsigned int ObjectDimension > +void +SubSampleSpatialObjectFilter< ObjectDimension > +::GenerateData( void ) +{ + const SpatialObjectType * input = this->GetInput(); + + typename SpatialObjectType::Pointer output = this->GetOutput(); + + this->SubSampleLevel( input, output, true ); + + this->GraftOutput(output); +} + +} // End namespace tube + +} // End namespace itk + +#endif // End !defined( __itktubeSubSampleSpatialObjectFilter_hxx ) diff --git a/src/Filtering/itktubeSubSampleTubeSpatialObjectFilter.h b/src/Filtering/itktubeSubSampleTubeSpatialObjectFilter.h index eae9bb2d8..e6ab61add 100644 --- a/src/Filtering/itktubeSubSampleTubeSpatialObjectFilter.h +++ b/src/Filtering/itktubeSubSampleTubeSpatialObjectFilter.h @@ -2,8 +2,7 @@ Library: TubeTK -Copyright 2010 Kitware Inc. 28 Corporate Drive, -Clifton Park, NY, 12065, USA. +Copyright Kitware Inc. All rights reserved. @@ -24,7 +23,8 @@ limitations under the License. #ifndef __itktubeSubSampleTubeSpatialObjectFilter_h #define __itktubeSubSampleTubeSpatialObjectFilter_h -#include "itktubeSpatialObjectToSpatialObjectFilter.h" +#include "itkTubeSpatialObject.h" +#include "itktubeSpatialObjectFilter.h" namespace itk { @@ -41,24 +41,22 @@ namespace tube * * \sa SubSampleTubeTreeSpatialObjectFilter */ -template< class TTubeSpatialObject > +template< unsigned int ObjectDimension > class SubSampleTubeSpatialObjectFilter - : public SpatialObjectToSpatialObjectFilter< TTubeSpatialObject, - TTubeSpatialObject > + : public SpatialObjectFilter< ObjectDimension > { public: /** Standard class typedefs. */ - typedef SubSampleTubeSpatialObjectFilter Self; - typedef SpatialObjectToSpatialObjectFilter< TTubeSpatialObject, - TTubeSpatialObject > Superclass; - typedef SmartPointer< Self > Pointer; - typedef SmartPointer< const Self > ConstPointer; + typedef SubSampleTubeSpatialObjectFilter Self; + typedef SpatialObjectFilter< ObjectDimension > Superclass; + typedef SmartPointer< Self > Pointer; + typedef SmartPointer< const Self > ConstPointer; - typedef TTubeSpatialObject TubeSpatialObjectType; + typedef TubeSpatialObject TubeSpatialObjectType; /** Run-time type information ( and related methods ). */ itkTypeMacro( SubSampleTubeSpatialObjectFilter, - SpatialObjectToSpatialObjectFilter ); + SpatialObjectFilter ); /** Method for creation through the object factory. */ itkNewMacro( Self ); diff --git a/src/Filtering/itktubeSubSampleTubeSpatialObjectFilter.hxx b/src/Filtering/itktubeSubSampleTubeSpatialObjectFilter.hxx index ec7c7ce2f..30c1d5bb3 100644 --- a/src/Filtering/itktubeSubSampleTubeSpatialObjectFilter.hxx +++ b/src/Filtering/itktubeSubSampleTubeSpatialObjectFilter.hxx @@ -2,8 +2,7 @@ Library: TubeTK -Copyright 2010 Kitware Inc. 28 Corporate Drive, -Clifton Park, NY, 12065, USA. +Copyright Kitware Inc. All rights reserved. @@ -32,32 +31,39 @@ namespace itk namespace tube { -template< class TTubeSpatialObject > -SubSampleTubeSpatialObjectFilter< TTubeSpatialObject > +template< unsigned int ObjectDimension > +SubSampleTubeSpatialObjectFilter< ObjectDimension > ::SubSampleTubeSpatialObjectFilter( void ) : m_Sampling( 1 ) { } -template< class TTubeSpatialObject > -SubSampleTubeSpatialObjectFilter< TTubeSpatialObject > +template< unsigned int ObjectDimension > +SubSampleTubeSpatialObjectFilter< ObjectDimension > ::~SubSampleTubeSpatialObjectFilter( void ) { } -template< class TTubeSpatialObject > +template< unsigned int ObjectDimension > void -SubSampleTubeSpatialObjectFilter< TTubeSpatialObject > +SubSampleTubeSpatialObjectFilter< ObjectDimension > ::GenerateData( void ) { - TubeSpatialObjectType * output = this->GetOutput(); - const TubeSpatialObjectType * input = this->GetInput(); - output->CopyInformation( input ); + typename const TubeSpatialObjectType * input = + dynamic_cast( this->GetInput() ); + if (input == nullptr) + { + std::cerr << "Error: tube passed to SubSampleTubes is not a tube." << std::endl; + return; + } + typename TubeSpatialObjectType::Pointer output = + dynamic_cast( this->GetOutput() ); typedef typename TubeSpatialObjectType::TubePointListType TubePointListType; const TubePointListType & inputPoints = input->GetPoints(); TubePointListType & outputPoints = output->GetPoints(); + const unsigned int numberOfInputPoints = inputPoints.size(); unsigned int numberOfOutputPoints; if( this->m_Sampling == 1 ) @@ -82,6 +88,8 @@ SubSampleTubeSpatialObjectFilter< TTubeSpatialObject > outputPoints[numberOfOutputPoints - 1] = inputPoints[numberOfInputPoints - 1]; output->RemoveDuplicatePointsInObjectSpace(); + + this->GraftOutput( output ); } } // End namespace tube diff --git a/src/Filtering/itktubeSubSampleTubeTreeSpatialObjectFilter.h b/src/Filtering/itktubeSubSampleTubeTreeSpatialObjectFilter.h deleted file mode 100644 index a6da265a5..000000000 --- a/src/Filtering/itktubeSubSampleTubeTreeSpatialObjectFilter.h +++ /dev/null @@ -1,110 +0,0 @@ -/*========================================================================= - -Library: TubeTK - -Copyright 2010 Kitware Inc. 28 Corporate Drive, -Clifton Park, NY, 12065, USA. - -All rights reserved. - -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. - -=========================================================================*/ - -#ifndef __itktubeSubSampleTubeTreeSpatialObjectFilter_h -#define __itktubeSubSampleTubeTreeSpatialObjectFilter_h - -#include "itktubeSpatialObjectToSpatialObjectFilter.h" - -namespace itk -{ - -namespace tube -{ - -/** \class SubSampleTubeTreeSpatialObjectFilter - * \brief Sub-sample tubes within a SpatialObject hierarchy. - * - * The input to this SpatialObjectFilter can be a single TubeSpatialObject - * or a hierarchy of SpatialObject's that contain tubes to be sub-sampled. - * All TubeSpatialObjects in the output hierarchy will be sub-sampled by - * the \c Sampling factor. Non-Tube spatial objects are passed to the - * output unchanged. - * - * \sa SubSampleTubeSpatialObjectFilter - */ -template< class TSpatialObject, class TTubeSpatialObject > -class SubSampleTubeTreeSpatialObjectFilter - : public SpatialObjectToSpatialObjectFilter< TSpatialObject, - TSpatialObject > -{ -public: - /** Standard class typedefs. */ - typedef SubSampleTubeTreeSpatialObjectFilter Self; - typedef SpatialObjectToSpatialObjectFilter< TSpatialObject, - TSpatialObject > Superclass; - typedef SmartPointer< Self > Pointer; - typedef SmartPointer< const Self > ConstPointer; - - typedef TSpatialObject SpatialObjectType; - typedef TTubeSpatialObject TubeSpatialObjectType; - - /** Run-time type information ( and related methods ). */ - itkTypeMacro( SubSampleTubeTreeSpatialObjectFilter, - SpatialObjectToSpatialObjectFilter ); - - /** Method for creation through the object factory. */ - itkNewMacro( Self ); - - itkStaticConstMacro( ObjectDimension, unsigned int, - SpatialObjectType::ObjectDimension ); - - /** Set the sampling factor. The output points taken every sampling - * factor from the input points. */ - itkSetClampMacro( Sampling, SizeValueType, 1, NumericTraits< - SizeValueType >::max() ); - itkGetConstMacro( Sampling, SizeValueType ); - -protected: - typedef SpatialObject< ObjectDimension > SpatialObjectBaseType; - - SubSampleTubeTreeSpatialObjectFilter( void ); - virtual ~SubSampleTubeTreeSpatialObjectFilter( void ); - - virtual void GenerateData( void ) override; - - /** Sub-sample at the tubes at a given level, then sub-sample their - * children. */ - virtual void SubSampleLevel( const SpatialObjectBaseType * input, - SpatialObjectBaseType * output, bool graftOutput=false ); - -private: - // purposely not implemented - SubSampleTubeTreeSpatialObjectFilter( const Self & ); - - // purposely not implemented - void operator=( const Self & ); - - SizeValueType m_Sampling; - -}; // End class SubSampleTubeTreeSpatialObjectFilter - -} // End namespace tube - -} // End namespace itk - -#ifndef ITK_MANUAL_INSTANTIATION -#include "itktubeSubSampleTubeTreeSpatialObjectFilter.hxx" -#endif - -#endif // End !defined( __itktubeSubSampleTubeTreeSpatialObjectFilter_h ) diff --git a/src/Filtering/itktubeSubSampleTubeTreeSpatialObjectFilter.hxx b/src/Filtering/itktubeSubSampleTubeTreeSpatialObjectFilter.hxx deleted file mode 100644 index 18ac5a19c..000000000 --- a/src/Filtering/itktubeSubSampleTubeTreeSpatialObjectFilter.hxx +++ /dev/null @@ -1,143 +0,0 @@ -/*========================================================================= - -Library: TubeTK - -Copyright 2010 Kitware Inc. 28 Corporate Drive, -Clifton Park, NY, 12065, USA. - -All rights reserved. - -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. - -=========================================================================*/ - -#ifndef __itktubeSubSampleTubeTreeSpatialObjectFilter_hxx -#define __itktubeSubSampleTubeTreeSpatialObjectFilter_hxx - -#include "itktubeSubSampleTubeTreeSpatialObjectFilter.h" - -#include "itktubeSubSampleTubeSpatialObjectFilter.h" - -#include - -namespace itk -{ - -namespace tube -{ - -template< class TSpatialObject, class TTubeSpatialObject > -SubSampleTubeTreeSpatialObjectFilter< TSpatialObject, TTubeSpatialObject > -::SubSampleTubeTreeSpatialObjectFilter( void ) - : m_Sampling( 1 ) -{ - //! \todo fix this system. - SpatialObjectFactoryBase::RegisterDefaultSpatialObjects(); - SpatialObjectFactory< SpatialObjectType >::RegisterSpatialObject(); - SpatialObjectFactory< TubeSpatialObjectType >::RegisterSpatialObject(); -} - -template< class TSpatialObject, class TTubeSpatialObject > -SubSampleTubeTreeSpatialObjectFilter< TSpatialObject, TTubeSpatialObject > -::~SubSampleTubeTreeSpatialObjectFilter( void ) -{ -} - -template< class TSpatialObject, class TTubeSpatialObject > -void -SubSampleTubeTreeSpatialObjectFilter< TSpatialObject, TTubeSpatialObject > -::SubSampleLevel( const SpatialObjectBaseType * input, - SpatialObjectBaseType * output, bool graftOutput ) -{ - // We make the copy and sub-sample if it is a tube. - const TubeSpatialObjectType * inputAsTube = - dynamic_cast< const TubeSpatialObjectType * >( input ); - typename SpatialObjectBaseType::Pointer newParent; - if( inputAsTube != NULL ) - { - typedef SubSampleTubeSpatialObjectFilter< TubeSpatialObjectType > - SubSampleTubeFilterType; - typename SubSampleTubeFilterType::Pointer subSampleTubeFilter - = SubSampleTubeFilterType::New(); - subSampleTubeFilter->SetSampling( this->GetSampling() ); - subSampleTubeFilter->SetInput( const_cast< TubeSpatialObjectType * >( - inputAsTube ) ); - subSampleTubeFilter->Update(); - if( graftOutput ) - { - output->CopyInformation( subSampleTubeFilter->GetOutput() ); - } - else - { - output->AddChild( subSampleTubeFilter->GetOutput() ); - } - newParent = dynamic_cast< SpatialObjectBaseType * >( output ); - } - else - { - if( graftOutput ) - { - output->CopyInformation( input ); - newParent = dynamic_cast< SpatialObjectBaseType * >( output ); - } - else - { - //const std::string spatialObjectType = input-> - //GetSpatialClassNameAndDimension(); - LightObject::Pointer newSpatialObject = input->Clone(); - //ObjectFactoryBase::CreateInstance( spatialObjectType.c_str() ); - - typename SpatialObjectBaseType::Pointer newSpatialObjectBase = - dynamic_cast< SpatialObjectBaseType * >( - newSpatialObject.GetPointer() ); - if( newSpatialObjectBase.IsNull() ) - { - itkExceptionMacro( << "Could not create an instance of " - << input->GetTypeName() << ". The usual cause of this error is not" - << "registering the SpatialObject with SpatialFactory." ); - } - - output->AddChild( newSpatialObjectBase ); - newParent = newSpatialObjectBase; - } - } - - typedef typename SpatialObjectType::ChildrenListType ChildrenListType; - ChildrenListType *children = input->GetChildren(); - typename ChildrenListType::const_iterator it = children->begin(); - while( it != children->end() ) - { - this->SubSampleLevel( *it, newParent ); - ++it; - } - delete children; -} - - -template< class TSpatialObject, class TTubeSpatialObject > -void -SubSampleTubeTreeSpatialObjectFilter< TSpatialObject, TTubeSpatialObject > -::GenerateData( void ) -{ - const SpatialObjectType * input = this->GetInput(); - - typename SpatialObjectBaseType::Pointer output = this->GetOutput(); - - this->SubSampleLevel( input, output, true ); -} - -} // End namespace tube - -} // End namespace itk - -#endif // End !defined( __itktubeSubSampleTubeTreeSpatialObjectFilter_hxx ) diff --git a/src/Numerics/itktubeNJetImageFunction.h b/src/Numerics/itktubeNJetImageFunction.h index 78aa0293b..bc0e0bca7 100644 --- a/src/Numerics/itktubeNJetImageFunction.h +++ b/src/Numerics/itktubeNJetImageFunction.h @@ -2,8 +2,7 @@ Library: TubeTK -Copyright 2010 Kitware Inc. 28 Corporate Drive, -Clifton Park, NY, 12065, USA. +Copyright Kitware Inc. All rights reserved. diff --git a/src/Numerics/itktubeNJetImageFunction.hxx b/src/Numerics/itktubeNJetImageFunction.hxx index 37b4ff4d2..f21372306 100644 --- a/src/Numerics/itktubeNJetImageFunction.hxx +++ b/src/Numerics/itktubeNJetImageFunction.hxx @@ -734,7 +734,7 @@ Derivative( const PointType& point, const VectorType & v1, if( !m_InputImage->TransformPhysicalPointToContinuousIndex( point, cIndex ) ) { - itkWarningMacro( << "Cannot convert point to continuous index." ); + itkWarningMacro( << "Point is outside of image: " << point ); d.Fill( 0 ); return 0.0; } diff --git a/src/Registration.cmake b/src/Registration.cmake index a51cef4a0..77ee880fb 100644 --- a/src/Registration.cmake +++ b/src/Registration.cmake @@ -21,17 +21,38 @@ ############################################################################## set( TubeTK_Registration_H_Files + Registration/itkAffineImageToImageRegistrationMethod.h + Registration/itkAnisotropicSimilarity3DTransform.h + Registration/itkAnisotropicSimilarityLandmarkBasedTransformInitializer.h + Registration/itkBSplineImageToImageRegistrationMethod.h + Registration/itkImageRegionMomentsCalculator.h + Registration/itkImageRegionSplitter.h + Registration/itkImageToImageRegistrationHelper.h + Registration/itkImageToImageRegistrationMethod.h + Registration/itkInitialImageToImageRegistrationMethod.h + Registration/itkOptimizedImageToImageRegistrationMethod.h + Registration/itkRigidImageToImageRegistrationMethod.h + Registration/itkScaleSkewAngle2DImageToImageRegistrationMethod.h + Registration/itkScaleSkewAngle2DTransform.h + Registration/itkScaleSkewVersor3DImageToImageRegistrationMethod.h + Registration/itkSimilarity2DTransform.h + Registration/itktubeAffineSpatialObjectToImageRegistrationMethod.h Registration/itktubeAnisotropicDiffusiveRegistrationFunction.h Registration/itktubeDiffusiveRegistrationFilter.h Registration/itktubeDiffusiveRegistrationFilterUtils.h - Registration/itktubeImageToTubeRigidMetric.h - Registration/itktubeImageToTubeRigidRegistration.h + Registration/itktubeInitialSpatialObjectToImageRegistrationMethod.h Registration/itktubeMeanSquareRegistrationFunction.h Registration/itktubeMergeAdjacentImagesFilter.h - Registration/itktubeTubeExponentialResolutionWeightFunction.h - Registration/itktubeTubeParametricExponentialResolutionWeightFunction.h - Registration/itktubeTubeParametricExponentialWithBoundsResolutionWeightFunction.h - Registration/itktubeTubeToTubeTransformFilter.h ) + Registration/itktubeOptimizedSpatialObjectToImageRegistrationMethod.h + Registration/itktubePointBasedSpatialObjectToImageMetric.h + Registration/itktubePointBasedSpatialObjectTransformFilter.h + Registration/itktubeRigidSpatialObjectToImageRegistrationMethod.h + Registration/itktubeScaleSkewAngle2DSpatialObjectToImageRegistrationMethod.h + Registration/itktubeScaleSkewVersor3DSpatialObjectToImageRegistrationMethod.h + Registration/itktubeSpatialObjectToImageMetric.h + Registration/itktubeSpatialObjectToImageRegistrationHelper.h + Registration/itktubeSpatialObjectToImageRegistrationMethod.h + ) if( TubeTK_USE_VTK ) list( APPEND TubeTK_Registration_H_Files @@ -40,14 +61,37 @@ if( TubeTK_USE_VTK ) endif() set( TubeTK_Registration_HXX_Files + Registration/itkAffineImageToImageRegistrationMethod.hxx + Registration/itkAnisotropicSimilarity3DTransform.hxx + Registration/itkAnisotropicSimilarityLandmarkBasedTransformInitializer.hxx + Registration/itkBSplineImageToImageRegistrationMethod.hxx + Registration/itkImageRegionMomentsCalculator.hxx + Registration/itkImageRegionSplitter.hxx + Registration/itkImageToImageRegistrationHelper.hxx + Registration/itkImageToImageRegistrationMethod.hxx + Registration/itkInitialImageToImageRegistrationMethod.hxx + Registration/itkOptimizedImageToImageRegistrationMethod.hxx + Registration/itkRigidImageToImageRegistrationMethod.hxx + Registration/itkScaleSkewAngle2DImageToImageRegistrationMethod.hxx + Registration/itkScaleSkewAngle2DTransform.hxx + Registration/itkScaleSkewVersor3DImageToImageRegistrationMethod.hxx + Registration/itkSimilarity2DTransform.hxx + Registration/itktubeAffineSpatialObjectToImageRegistrationMethod.hxx Registration/itktubeAnisotropicDiffusiveRegistrationFunction.hxx Registration/itktubeDiffusiveRegistrationFilter.hxx Registration/itktubeDiffusiveRegistrationFilterUtils.hxx - Registration/itktubeImageToTubeRigidMetric.hxx - Registration/itktubeImageToTubeRigidRegistration.hxx + Registration/itktubeInitialSpatialObjectToImageRegistrationMethod.hxx Registration/itktubeMeanSquareRegistrationFunction.hxx Registration/itktubeMergeAdjacentImagesFilter.hxx - Registration/itktubeTubeToTubeTransformFilter.hxx ) + Registration/itktubeOptimizedSpatialObjectToImageRegistrationMethod.hxx + Registration/itktubePointBasedSpatialObjectToImageMetric.hxx + Registration/itktubePointBasedSpatialObjectTransformFilter.hxx + Registration/itktubeRigidSpatialObjectToImageRegistrationMethod.hxx + Registration/itktubeScaleSkewAngle2DSpatialObjectToImageRegistrationMethod.hxx + Registration/itktubeScaleSkewVersor3DSpatialObjectToImageRegistrationMethod.hxx + Registration/itktubeSpatialObjectToImageRegistrationHelper.hxx + Registration/itktubeSpatialObjectToImageRegistrationMethod.hxx + ) if( TubeTK_USE_VTK ) list( APPEND TubeTK_Registration_HXX_Files diff --git a/src/Registration/Deprecated/itktubeSpatialObjectRegionMomentsCalculator.h b/src/Registration/Deprecated/itktubeSpatialObjectRegionMomentsCalculator.h new file mode 100644 index 000000000..fb31242e1 --- /dev/null +++ b/src/Registration/Deprecated/itktubeSpatialObjectRegionMomentsCalculator.h @@ -0,0 +1,225 @@ +/*========================================================================= + +Library: TubeTK + +Copyright Kitware Inc. + +All rights reserved. + +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. + +=========================================================================*/ + +#ifndef __itktubeSpatialObjectMomentsCalculator_h +#define __itktubeSpatialObjectMomentsCalculator_h + +#include "itkAffineTransform.h" +#include "itkMacro.h" +#include "itkSpatialObject.h" + +#include "vnl/vnl_vector_fixed.h" +#include "vnl/vnl_matrix_fixed.h" +#include "vnl/vnl_diag_matrix.h" + +namespace itk +{ + +namespace tube +{ + +/** \class SpatialObjectMomentsCalculator + * \brief Compute moments of an n-dimensional image. + * + * This class provides methods for computing the moments and related + * properties of a single-echo image. Computing the ( non-central ) + * moments of a large image can easily take a million times longer + * than computing the various other values derived from them, so we + * compute the moments only on explicit request, and save their values + * ( in an SpatialObjectMomentsCalculator object ) for later retrieval by + * the user. + * + * The methods that return values return the values themselves rather + * than references because the cost is small compared to the cost of + * computing the moments and doing so simplifies memory management for + * the caller. + * + * \ingroup Operators + */ +template +class SpatialObjectMomentsCalculator : public Object +{ +public: + /** Standard class typedefs. */ + typedef SpatialObjectMomentsCalculator Self; + typedef Object Superclass; + typedef SmartPointer Pointer; + typedef SmartPointer ConstPointer; + + /** Method for creation through the object factory. */ + itkNewMacro( Self ); + + /** Run-time type information ( and related methods ). */ + itkTypeMacro( SpatialObjectMomentsCalculator, Object ); + + /** Standard scalar type within this class. */ + typedef double ScalarType; + + typedef typename TImage::PointType PointType; + + /** Standard vector type within this class. */ + typedef Vector VectorType; + + /** Spatial Object type within this class. */ + typedef SpatialObject SpatialObjectType; + + /** Spatial Object member types used within this class. */ + typedef typename SpatialObjectType::Pointer SpatialObjectPointer; + typedef typename SpatialObjectType::ConstPointer SpatialObjectConstPointer; + + /** Standard matrix type within this class. */ + typedef Matrix MatrixType; + + /** Affine transform for mapping to and from principal axis */ + typedef AffineTransform AffineTransformType; + typedef typename AffineTransformType::Pointer AffineTransformPointer; + + /** Set the spatial object. */ + virtual void SetSpatialObject( const SpatialObject * so ) + { + if( m_SpatialObject != so ) + { + m_SpatialObject = so; + this->Modified(); + m_Valid = false; + } + } + + /** Set the spatial object mask - which defines the ROI over which + * moments are computed from the input spatial object. */ + virtual void SetSpatialObjectMask( const SpatialObject * so ) + { + if( m_SpatialObjectMask != so ) + { + m_SpatialObjectMask = so; + this->Modified(); + m_Valid = false; + } + } + + /** Compute moments of a new or modified image. + * This method computes the moments of the image given as a + * parameter and stores them in the object. The values of these + * moments and related parameters can then be retrieved by using + * other methods of this object. */ + void Compute( void ); + + /** Return the total mass ( or zeroth moment ) of an image. + * This method returns the sum of pixel intensities ( also known as + * the zeroth moment or the total mass ) of the image whose moments + * were last computed by this object. */ + ScalarType GetTotalMass() const; + + /** Return first moments about origin, in index coordinates. + * This method returns the first moments around the origin of the + * image whose moments were last computed by this object. For + * simplicity, these moments are computed in index coordinates + * rather than physical coordinates. */ + VectorType GetFirstMoments() const; + + /** Return second moments about origin, in index coordinates. + * This method returns the second moments around the origin + * of the image whose moments were last computed by this object. + * For simplicity, these moments are computed in index coordinates + * rather than physical coordinates. */ + MatrixType GetSecondMoments() const; + + /** Return center of gravity, in physical coordinates. + * This method returns the center of gravity of the image whose + * moments were last computed by this object. The center of + * gravity is computed in physical coordinates. */ + VectorType GetCenterOfGravity() const; + + /** Return second central moments, in physical coordinates. + * This method returns the central second moments of the image + * whose moments were last computed by this object. The central + * moments are computed in physical coordinates. */ + MatrixType GetCentralMoments() const; + + /** Return principal moments, in physical coordinates. + * This method returns the principal moments of the image whose + * moments were last computed by this object. The moments are + * returned as a vector, with the principal moments ordered from + * smallest to largest. The moments are computed in physical + * coordinates. */ + VectorType GetPrincipalMoments() const; + + /** Return principal axes, in physical coordinates. + * This method returns the principal axes of the image whose + * moments were last computed by this object. The moments are + * returned as an orthogonal matrix, each row of which corresponds + * to one principal moment; for example, the principal axis + * corresponding to the smallest principal moment is the vector + * m[0], where m is the value returned by this method. The matrix + * of principal axes is guaranteed to be a proper rotation; that + * is, to have determinant +1 and to preserve parity. ( Unless you + * have foolishly made one or more of the spacing values negative; + * in that case, _you_ get to figure out the consequences. ) The + * moments are computed in physical coordinates. */ + MatrixType GetPrincipalAxes() const; + + /** Get the affine transform from principal axes to physical axes + * This method returns an affine transform which transforms from + * the principal axes coordinate system to physical coordinates. */ + AffineTransformPointer GetPrincipalAxesToPhysicalAxesTransform( + void ) const; + + /** Get the affine transform from physical axes to principal axes + * This method returns an affine transform which transforms from + * the physical coordinate system to the principal axes coordinate + * system. */ + AffineTransformPointer GetPhysicalAxesToPrincipalAxesTransform( + void ) const; + +protected: + SpatialObjectMomentsCalculator(); + virtual ~SpatialObjectMomentsCalculator(); + + void PrintSelf( std::ostream& os, Indent indent ) const override; + +private: + SpatialObjectMomentsCalculator( const Self & ); // purposely not implemented + void operator=( const Self & ); // purposely not implemented + + bool m_Valid; // Have moments been computed yet? + ScalarType m_M0; // Zeroth moment + VectorType m_M1; // First moments about origin + MatrixType m_M2; // Second moments about origin + VectorType m_Cg; // Center of gravity ( physical units ) + MatrixType m_Cm; // Second central moments ( physical ) + VectorType m_Pm; // Principal moments ( physical ) + MatrixType m_Pa; // Principal axes ( physical ) + + SpatialObjectConstPointer m_SpatialObject; + SpatialObjectConstPointer m_SpatialObjectMask; + +}; // class SpatialObjectMomentsCalculator + +} // end namespace tube + +} // end namespace itk + +#ifndef ITK_MANUAL_INSTANTIATION +#include "itktubeSpatialObjectMomentsCalculator.hxx" +#endif + +#endif /* __itkSpatialObjectMomentsCalculator_h */ diff --git a/src/Registration/Deprecated/itktubeSpatialObjectRegionMomentsCalculator.hxx b/src/Registration/Deprecated/itktubeSpatialObjectRegionMomentsCalculator.hxx new file mode 100644 index 000000000..b23850b07 --- /dev/null +++ b/src/Registration/Deprecated/itktubeSpatialObjectRegionMomentsCalculator.hxx @@ -0,0 +1,388 @@ +/*========================================================================= + +Library: TubeTK + +Copyright Kitware Inc. + +All rights reserved. + +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. + +=========================================================================*/ + +#ifndef _itktubeSpatialObjectRegionMomentsCalculator_txx +#define _itktubeSpatialObjectRegionMomentsCalculator_txx + +#include "vnl/algo/vnl_real_eigensystem.h" +#include "vnl/algo/vnl_symmetric_eigensystem.h" +#include "itkImageRegionConstIteratorWithIndex.h" + +namespace itk +{ + +namespace tube +{ + +class InvalidSpatialObjectRegionMomentsError : public ExceptionObject +{ +public: + /* + * Constructor. Needed to ensure the exception object can be copied. + */ + InvalidSpatialObjectRegionMomentsError(const char *file, + unsigned int lineNumber) : ExceptionObject(file, lineNumber) + { + this->SetDescription("No valid spatial object moments are availble."); + } + + /* + * Constructor. Needed to ensure the exception object can be copied. + */ + InvalidSpatialObjectRegionMomentsError(const std::string& file, + unsigned int lineNumber) : ExceptionObject(file, lineNumber) + { + this->SetDescription("No valid spatial Object moments are availble."); + } + + itkTypeMacro(InvalidSpatialObjectRegionMomentsError, ExceptionObject); +}; + +// ---------------------------------------------------------------------- +// Construct without computing moments +template +SpatialObjectRegionMomentsCalculator::SpatialObjectRegionMomentsCalculator(void) +{ + m_Valid = false; + m_Region = + m_Origin + m_Spacing + m_Direction = + m_SpatialObject = nullptr; + m_SpatialObjectMask = nullptr; + m_M0 = NumericTraits::Zero; + m_M1.Fill(NumericTraits::Zero); + m_M2.Fill(NumericTraits::Zero); + m_Cg.Fill(NumericTraits::Zero); + m_Cm.Fill(NumericTraits::Zero); + m_Pm.Fill(NumericTraits::Zero); + m_Pa.Fill(NumericTraits::Zero); +} + +// ---------------------------------------------------------------------- +// Destructor +template +SpatialObjectRegionMomentsCalculator:: +~SpatialObjectRegionMomentsCalculator() +{ +} + +template +void +SpatialObjectRegionMomentsCalculator +::PrintSelf( std::ostream& os, Indent indent ) const +{ + Superclass::PrintSelf(os, indent); + os << indent << "SpatialObject: " << m_SpatialObject.GetPointer() << std::endl; + os << indent << "SpatialObjectMask: " << m_SpatialObjectMask.GetPointer() << std::endl; + os << indent << "Valid: " << m_Valid << std::endl; + os << indent << "Zeroth Moment about origin: " << m_M0 << std::endl; + os << indent << "First Moment about origin: " << m_M1 << std::endl; + os << indent << "Second Moment about origin: " << m_M2 << std::endl; + os << indent << "Center of Gravity: " << m_Cg << std::endl; + os << indent << "Second central moments: " << m_Cm << std::endl; + os << indent << "Principal Moments: " << m_Pm << std::endl; + os << indent << "Principal axes: " << m_Pa << std::endl; +} + +// ---------------------------------------------------------------------- +// Compute moments for a new or modified image +template +void +SpatialObjectRegionMomentsCalculator::Compute() +{ + m_M0 = NumericTraits::Zero; + m_M1.Fill(NumericTraits::Zero); + m_M2.Fill(NumericTraits::Zero); + m_Cg.Fill(NumericTraits::Zero); + m_Cm.Fill(NumericTraits::Zero); + + typedef typename ImageType::IndexType IndexType; + + if( !m_Image ) + { + return; + } + + SpatialObjectRegionConstIteratorWithIndex it( m_Image, + m_Image->GetRequestedRegion() ); + + while( !it.IsAtEnd() ) + { + double value = it.Value(); + + IndexType indexPosition = it.GetIndex(); + + Point physicalPosition; + m_Image->TransformIndexToPhysicalPoint(indexPosition, physicalPosition); + + bool isInsideRegionOfInterest = true; + if( m_UseRegionOfInterest ) + { + for( unsigned int i = 0; i < ImageDimension; i++ ) + { + if( !( (physicalPosition[i] <= m_RegionOfInterestPoint1[i] + && physicalPosition[i] >= m_RegionOfInterestPoint2[i]) + || (physicalPosition[i] <= m_RegionOfInterestPoint2[i] + && physicalPosition[i] >= m_RegionOfInterestPoint1[i]) ) ) + { + isInsideRegionOfInterest = false; + break; + } + } + } + + if( isInsideRegionOfInterest && + (m_SpatialObjectMask.IsNull() + || m_SpatialObjectMask->IsInsideInWorldSpace(physicalPosition) ) ) + { + m_M0 += value; + for( unsigned int i = 0; i < ImageDimension; i++ ) + { + m_M1[i] += static_cast( indexPosition[i] ) * value; + for( unsigned int j = 0; j < ImageDimension; j++ ) + { + double weight = value * static_cast( indexPosition[i] ) + * static_cast( indexPosition[j] ); + m_M2[i][j] += weight; + } + } + for( unsigned int i = 0; i < ImageDimension; i++ ) + { + m_Cg[i] += physicalPosition[i] * value; + for( unsigned int j = 0; j < ImageDimension; j++ ) + { + double weight = value * physicalPosition[i] * physicalPosition[j]; + m_Cm[i][j] += weight; + } + + } + } + + ++it; + } + + // Throw an error if the total mass is zero + if( m_M0 == 0.0 ) + { + itkExceptionMacro( + << "Compute(): Total Mass of the image was zero. Aborting here to prevent division by zero later on."); + } + // Normalize using the total mass + for( unsigned int i = 0; i < ImageDimension; i++ ) + { + m_Cg[i] /= m_M0; + m_M1[i] /= m_M0; + for( unsigned int j = 0; j < ImageDimension; j++ ) + { + m_M2[i][j] /= m_M0; + m_Cm[i][j] /= m_M0; + } + } + // Center the second order moments + for( unsigned int i = 0; i < ImageDimension; i++ ) + { + for( unsigned int j = 0; j < ImageDimension; j++ ) + { + m_M2[i][j] -= m_M1[i] * m_M1[j]; + m_Cm[i][j] -= m_Cg[i] * m_Cg[j]; + } + } + + // Compute principal moments and axes + vnl_symmetric_eigensystem eigen( m_Cm.GetVnlMatrix().as_ref() ); + vnl_diag_matrix pm = eigen.D; + for( unsigned int i = 0; i < ImageDimension; i++ ) + { + m_Pm[i] = pm(i, i) * m_M0; + } + m_Pa = eigen.V.transpose(); + + // Add a final reflection if needed for a proper rotation, + // by multiplying the last row by the determinant + vnl_real_eigensystem eigenrot( m_Pa.GetVnlMatrix().as_ref() ); + vnl_diag_matrix > eigenval = eigenrot.D; + std::complex det( 1.0, 0.0 ); + for( unsigned int i = 0; i < ImageDimension; i++ ) + { + det *= eigenval( i, i ); + } + for( unsigned int i = 0; i < ImageDimension; i++ ) + { + m_Pa[ImageDimension - 1][i] *= std::real( det ); + } + + /* Remember that the moments are valid */ + m_Valid = 1; + +} + +// --------------------------------------------------------------------- +// Get sum of intensities +template +typename SpatialObjectRegionMomentsCalculator::ScalarType +SpatialObjectRegionMomentsCalculator::GetTotalMass() const +{ + if( !m_Valid ) + { + itkExceptionMacro( << "GetTotalMass() invoked, but the moments have not been computed. Call Compute() first."); + } + return m_M0; +} + +// -------------------------------------------------------------------- +// Get first moments about origin, in index coordinates +template +typename SpatialObjectRegionMomentsCalculator::VectorType +SpatialObjectRegionMomentsCalculator::GetFirstMoments() const +{ + if( !m_Valid ) + { + itkExceptionMacro( << "GetFirstMoments() invoked, but the moments have not been computed. Call Compute() first."); + } + return m_M1; +} + +// -------------------------------------------------------------------- +// Get second moments about origin, in index coordinates +template +typename SpatialObjectRegionMomentsCalculator::MatrixType +SpatialObjectRegionMomentsCalculator::GetSecondMoments() const +{ + if( !m_Valid ) + { + itkExceptionMacro( << "GetSecondMoments() invoked, but the moments have not been computed. Call Compute() first."); + } + return m_M2; +} + +// -------------------------------------------------------------------- +// Get center of gravity, in physical coordinates +template +typename SpatialObjectRegionMomentsCalculator::VectorType +SpatialObjectRegionMomentsCalculator::GetCenterOfGravity() const +{ + if( !m_Valid ) + { + itkExceptionMacro( << "GetCenterOfGravity() invoked, but the moments have not been computed. Call Compute() first."); + } + return m_Cg; +} + +// -------------------------------------------------------------------- +// Get second central moments, in physical coordinates +template +typename SpatialObjectRegionMomentsCalculator::MatrixType +SpatialObjectRegionMomentsCalculator::GetCentralMoments() const +{ + if( !m_Valid ) + { + itkExceptionMacro( << "GetCentralMoments() invoked, but the moments have not been computed. Call Compute() first."); + } + return m_Cm; +} + +// -------------------------------------------------------------------- +// Get principal moments, in physical coordinates +template +typename SpatialObjectRegionMomentsCalculator::VectorType +SpatialObjectRegionMomentsCalculator::GetPrincipalMoments() const +{ + if( !m_Valid ) + { + itkExceptionMacro( + << "GetPrincipalMoments() invoked, but the moments have not been computed. Call Compute() first."); + } + return m_Pm; +} + +// -------------------------------------------------------------------- +// Get principal axes, in physical coordinates +template +typename SpatialObjectRegionMomentsCalculator::MatrixType +SpatialObjectRegionMomentsCalculator::GetPrincipalAxes() const +{ + if( !m_Valid ) + { + itkExceptionMacro( << "GetPrincipalAxes() invoked, but the moments have not been computed. Call Compute() first."); + } + return m_Pa; +} + +// -------------------------------------------------------------------- +// Get principal axes to physical axes transform +template +typename SpatialObjectRegionMomentsCalculator::AffineTransformPointer +SpatialObjectRegionMomentsCalculator::GetPrincipalAxesToPhysicalAxesTransform(void) const +{ + typename AffineTransformType::MatrixType matrix; + typename AffineTransformType::OffsetType offset; + for( unsigned int i = 0; i < ImageDimension; i++ ) + { + offset[i] = m_Cg[i]; + for( unsigned int j = 0; j < ImageDimension; j++ ) + { + matrix[j][i] = m_Pa[i][j]; // Note the transposition + } + } + + AffineTransformPointer result = AffineTransformType::New(); + + result->SetMatrix(matrix); + result->SetOffset(offset); + + return result; +} + +// -------------------------------------------------------------------- +// Get physical axes to principal axes transform + +template +typename SpatialObjectRegionMomentsCalculator::AffineTransformPointer +SpatialObjectRegionMomentsCalculator::GetPhysicalAxesToPrincipalAxesTransform(void) const +{ + typename AffineTransformType::MatrixType matrix; + typename AffineTransformType::OffsetType offset; + for( unsigned int i = 0; i < ImageDimension; i++ ) + { + offset[i] = m_Cg[i]; + for( unsigned int j = 0; j < ImageDimension; j++ ) + { + matrix[j][i] = m_Pa[i][j]; // Note the transposition + } + } + + AffineTransformPointer result = AffineTransformType::New(); + result->SetMatrix(matrix); + result->SetOffset(offset); + + AffineTransformPointer inverse = AffineTransformType::New(); + result->GetInverse(inverse); + + return inverse; +} + +} // end namespace tube + +} // end namespace itk + +#endif diff --git a/src/Registration/itkAffineImageToImageRegistrationMethod.h b/src/Registration/itkAffineImageToImageRegistrationMethod.h index 0e296a51c..57171f092 100644 --- a/src/Registration/itkAffineImageToImageRegistrationMethod.h +++ b/src/Registration/itkAffineImageToImageRegistrationMethod.h @@ -1,19 +1,25 @@ /*========================================================================= - Program: Insight Segmentation & Registration Toolkit - Module: $RCSfile: ITKHeader.h,v $ - Language: C++ - Date: $Date: 2007-07-10 11:35:36 -0400 ( Tue, 10 Jul 2007 ) $ - Version: $Revision: 0 $ +Library: TubeTK - Copyright ( c ) 2002 Insight Consortium. All rights reserved. - See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details. +Copyright Kitware Inc. - This software is distributed WITHOUT ANY WARRANTY; without even - the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - PURPOSE. See the above copyright notices for more information. +All rights reserved. + +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. =========================================================================*/ + #ifndef __itkAffineImageToImageRegistrationMethod_h #define __itkAffineImageToImageRegistrationMethod_h diff --git a/src/Registration/itkAffineImageToImageRegistrationMethod.hxx b/src/Registration/itkAffineImageToImageRegistrationMethod.hxx index 92a2e8278..1d22245e7 100644 --- a/src/Registration/itkAffineImageToImageRegistrationMethod.hxx +++ b/src/Registration/itkAffineImageToImageRegistrationMethod.hxx @@ -1,17 +1,22 @@ /*========================================================================= - Program: Insight Segmentation & Registration Toolkit - Module: $RCSfile: ITKHeader.h,v $ - Language: C++ - Date: $Date: 2007-07-10 11:35:36 -0400 (Tue, 10 Jul 2007) $ - Version: $Revision: 0 $ - - Copyright (c) 2002 Insight Consortium. All rights reserved. - See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details. - - This software is distributed WITHOUT ANY WARRANTY; without even - the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - PURPOSE. See the above copyright notices for more information. +Library: TubeTK + +Copyright Kitware Inc. + +All rights reserved. + +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/src/Registration/itkAnisotropicSimilarity3DTransform.h b/src/Registration/itkAnisotropicSimilarity3DTransform.h index 0ea6929af..384fec236 100644 --- a/src/Registration/itkAnisotropicSimilarity3DTransform.h +++ b/src/Registration/itkAnisotropicSimilarity3DTransform.h @@ -1,19 +1,25 @@ /*========================================================================= - Program: Insight Segmentation & Registration Toolkit - Module: $RCSfile: ITKHeader.h,v $ - Language: C++ - Date: $Date: 2007-07-10 11:35:36 -0400 ( Tue, 10 Jul 2007 ) $ - Version: $Revision: 0 $ +Library: TubeTK - Copyright ( c ) 2002 Insight Consortium. All rights reserved. - See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details. +Copyright Kitware Inc. - This software is distributed WITHOUT ANY WARRANTY; without even - the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - PURPOSE. See the above copyright notices for more information. +All rights reserved. + +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. =========================================================================*/ + #ifndef __itkAnisotropicSimilarity3DTransform_h #define __itkAnisotropicSimilarity3DTransform_h diff --git a/src/Registration/itkAnisotropicSimilarity3DTransform.hxx b/src/Registration/itkAnisotropicSimilarity3DTransform.hxx index 1cb1c4771..d9e7fcdf3 100644 --- a/src/Registration/itkAnisotropicSimilarity3DTransform.hxx +++ b/src/Registration/itkAnisotropicSimilarity3DTransform.hxx @@ -1,19 +1,25 @@ /*========================================================================= - Program: Insight Segmentation & Registration Toolkit - Module: $RCSfile: ITKHeader.h,v $ - Language: C++ - Date: $Date: 2007-07-10 11:35:36 -0400 (Tue, 10 Jul 2007) $ - Version: $Revision: 0 $ +Library: TubeTK - Copyright (c) 2002 Insight Consortium. All rights reserved. - See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details. +Copyright Kitware Inc. - This software is distributed WITHOUT ANY WARRANTY; without even - the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - PURPOSE. See the above copyright notices for more information. +All rights reserved. + +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. =========================================================================*/ + #ifndef __itkAnisotropicSimilarity3DTransform_txx #define __itkAnisotropicSimilarity3DTransform_txx diff --git a/src/Registration/itkAnisotropicSimilarityLandmarkBasedTransformInitializer.h b/src/Registration/itkAnisotropicSimilarityLandmarkBasedTransformInitializer.h index 79c257e80..7c775b5fa 100644 --- a/src/Registration/itkAnisotropicSimilarityLandmarkBasedTransformInitializer.h +++ b/src/Registration/itkAnisotropicSimilarityLandmarkBasedTransformInitializer.h @@ -1,19 +1,25 @@ /*========================================================================= - Program: Insight Segmentation & Registration Toolkit - Module: $RCSfile: ITKHeader.h,v $ - Language: C++ - Date: $Date: 2007-07-10 11:35:36 -0400 ( Tue, 10 Jul 2007 ) $ - Version: $Revision: 0 $ +Library: TubeTK - Copyright ( c ) 2002 Insight Consortium. All rights reserved. - See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details. +Copyright Kitware Inc. - This software is distributed WITHOUT ANY WARRANTY; without even - the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - PURPOSE. See the above copyright notices for more information. +All rights reserved. + +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. =========================================================================*/ + #ifndef __itkAnisotropicSimilarityLandmarkBasedTransformInitializer_h #define __itkAnisotropicSimilarityLandmarkBasedTransformInitializer_h diff --git a/src/Registration/itkAnisotropicSimilarityLandmarkBasedTransformInitializer.hxx b/src/Registration/itkAnisotropicSimilarityLandmarkBasedTransformInitializer.hxx index 17dcbf977..d58b7f47d 100644 --- a/src/Registration/itkAnisotropicSimilarityLandmarkBasedTransformInitializer.hxx +++ b/src/Registration/itkAnisotropicSimilarityLandmarkBasedTransformInitializer.hxx @@ -1,19 +1,25 @@ /*========================================================================= - Program: Insight Segmentation & Registration Toolkit - Module: $RCSfile: ITKHeader.h,v $ - Language: C++ - Date: $Date: 2007-07-10 11:35:36 -0400 ( Tue, 10 Jul 2007 ) $ - Version: $Revision: 0 $ +Library: TubeTK - Copyright ( c ) 2002 Insight Consortium. All rights reserved. - See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details. +Copyright Kitware Inc. - This software is distributed WITHOUT ANY WARRANTY; without even - the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - PURPOSE. See the above copyright notices for more information. +All rights reserved. + +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. =========================================================================*/ + #ifndef __itkAnisotropicSimilarityLandmarkBasedTransformInitializer_txx #define __itkAnisotropicSimilarityLandmarkBasedTransformInitializer_txx diff --git a/src/Registration/itkBSplineImageToImageRegistrationMethod.h b/src/Registration/itkBSplineImageToImageRegistrationMethod.h index 2ed68f9aa..78626193f 100644 --- a/src/Registration/itkBSplineImageToImageRegistrationMethod.h +++ b/src/Registration/itkBSplineImageToImageRegistrationMethod.h @@ -1,17 +1,22 @@ /*========================================================================= - Program: Insight Segmentation & Registration Toolkit - Module: $RCSfile: ITKHeader.h,v $ - Language: C++ - Date: $Date: 2007-07-10 11:35:36 -0400 ( Tue, 10 Jul 2007 ) $ - Version: $Revision: 0 $ - - Copyright ( c ) 2002 Insight Consortium. All rights reserved. - See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details. - - This software is distributed WITHOUT ANY WARRANTY; without even - the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - PURPOSE. See the above copyright notices for more information. +Library: TubeTK + +Copyright Kitware Inc. + +All rights reserved. + +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/src/Registration/itkBSplineImageToImageRegistrationMethod.hxx b/src/Registration/itkBSplineImageToImageRegistrationMethod.hxx index 44859daa7..45cb04c58 100644 --- a/src/Registration/itkBSplineImageToImageRegistrationMethod.hxx +++ b/src/Registration/itkBSplineImageToImageRegistrationMethod.hxx @@ -1,19 +1,25 @@ /*========================================================================= - Program: Insight Segmentation & Registration Toolkit - Module: $RCSfile: ITKHeader.h,v $ - Language: C++ - Date: $Date: 2007-07-10 11:35:36 -0400 (Tue, 10 Jul 2007) $ - Version: $Revision: 0 $ +Library: TubeTK - Copyright (c) 2002 Insight Consortium. All rights reserved. - See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details. +Copyright Kitware Inc. - This software is distributed WITHOUT ANY WARRANTY; without even - the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - PURPOSE. See the above copyright notices for more information. +All rights reserved. + +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. =========================================================================*/ + #ifndef __itkBSplineImageToImageRegistrationMethod_txx #define __itkBSplineImageToImageRegistrationMethod_txx diff --git a/src/Registration/itkImageRegionMomentsCalculator.h b/src/Registration/itkImageRegionMomentsCalculator.h index 84a8cb89a..cbe60ce7e 100644 --- a/src/Registration/itkImageRegionMomentsCalculator.h +++ b/src/Registration/itkImageRegionMomentsCalculator.h @@ -1,19 +1,25 @@ /*========================================================================= - Program: Insight Segmentation & Registration Toolkit - Module: $RCSfile: ITKHeader.h,v $ - Language: C++ - Date: $Date: 2007-07-10 11:35:36 -0400 ( Tue, 10 Jul 2007 ) $ - Version: $Revision: 0 $ +Library: TubeTK - Copyright ( c ) 2002 Insight Consortium. All rights reserved. - See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details. +Copyright Kitware Inc. - This software is distributed WITHOUT ANY WARRANTY; without even - the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - PURPOSE. See the above copyright notices for more information. +All rights reserved. + +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. =========================================================================*/ + #ifndef __itkImageRegionMomentsCalculator_h #define __itkImageRegionMomentsCalculator_h diff --git a/src/Registration/itkImageRegionMomentsCalculator.hxx b/src/Registration/itkImageRegionMomentsCalculator.hxx index b184ebdcf..96e183a4b 100644 --- a/src/Registration/itkImageRegionMomentsCalculator.hxx +++ b/src/Registration/itkImageRegionMomentsCalculator.hxx @@ -1,19 +1,25 @@ /*========================================================================= - Program: Insight Segmentation & Registration Toolkit - Module: $RCSfile: itkImageRegionMomentsCalculator.txx,v $ - Language: C++ - Date: $Date: 2008-10-06 08:54:44 $ - Version: $Revision: 1.56 $ +Library: TubeTK - Copyright (c) Insight Software Consortium. All rights reserved. - See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details. +Copyright Kitware Inc. - This software is distributed WITHOUT ANY WARRANTY; without even - the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - PURPOSE. See the above copyright notices for more information. +All rights reserved. + +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. =========================================================================*/ + #ifndef _itkImageRegionMomentsCalculator_txx #define _itkImageRegionMomentsCalculator_txx #include "itkImageRegionMomentsCalculator.h" diff --git a/src/Registration/itkImageRegionSplitter.h b/src/Registration/itkImageRegionSplitter.h index 6ef62d911..4554aaf4b 100644 --- a/src/Registration/itkImageRegionSplitter.h +++ b/src/Registration/itkImageRegionSplitter.h @@ -1,20 +1,25 @@ /*========================================================================= - * - * 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. - * -*=========================================================================*/ + +Library: TubeTK + +Copyright Kitware Inc. + +All rights reserved. + +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. + +=========================================================================*/ + #ifndef __itkImageRegionSplitter_h #define __itkImageRegionSplitter_h diff --git a/src/Registration/itkImageRegionSplitter.hxx b/src/Registration/itkImageRegionSplitter.hxx index cc65365d3..e24663fd1 100644 --- a/src/Registration/itkImageRegionSplitter.hxx +++ b/src/Registration/itkImageRegionSplitter.hxx @@ -1,20 +1,25 @@ /*========================================================================= - * - * 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. - * -*=========================================================================*/ + +Library: TubeTK + +Copyright Kitware Inc. + +All rights reserved. + +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. + +=========================================================================*/ + #ifndef __itkImageRegionSplitter_hxx #define __itkImageRegionSplitter_hxx diff --git a/src/Registration/itkImageToImageRegistrationHelper.h b/src/Registration/itkImageToImageRegistrationHelper.h index 43f474f81..f96aab3d7 100644 --- a/src/Registration/itkImageToImageRegistrationHelper.h +++ b/src/Registration/itkImageToImageRegistrationHelper.h @@ -1,17 +1,22 @@ /*========================================================================= - Program: Insight Segmentation & Registration Toolkit - Module: $RCSfile: ITKHeader.h,v $ - Language: C++ - Date: $Date: 2007-07-10 11:35:36 -0400 ( Tue, 10 Jul 2007 ) $ - Version: $Revision: 0 $ - - Copyright ( c ) 2002 Insight Consortium. All rights reserved. - See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details. - - This software is distributed WITHOUT ANY WARRANTY; without even - the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - PURPOSE. See the above copyright notices for more information. +Library: TubeTK + +Copyright Kitware Inc. + +All rights reserved. + +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/src/Registration/itkImageToImageRegistrationHelper.hxx b/src/Registration/itkImageToImageRegistrationHelper.hxx index 1cfc524be..c09f67180 100644 --- a/src/Registration/itkImageToImageRegistrationHelper.hxx +++ b/src/Registration/itkImageToImageRegistrationHelper.hxx @@ -1,19 +1,25 @@ /*========================================================================= - Program: Insight Segmentation & Registration Toolkit - Module: $RCSfile: ITKHeader.h,v $ - Language: C++ - Date: $Date: 2007-07-10 11:35:36 -0400 (Tue, 10 Jul 2007) $ - Version: $Revision: 0 $ +Library: TubeTK - Copyright (c) 2002 Insight Consortium. All rights reserved. - See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details. +Copyright Kitware Inc. - This software is distributed WITHOUT ANY WARRANTY; without even - the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - PURPOSE. See the above copyright notices for more information. +All rights reserved. + +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. =========================================================================*/ + #ifndef __itkImageToImageRegistrationHelper_txx #define __itkImageToImageRegistrationHelper_txx @@ -113,7 +119,7 @@ ImageToImageRegistrationHelper m_LoadedBSplineTransform = NULL; // Initial - m_InitialMethodEnum = INIT_WITH_CENTERS_OF_MASS; + m_InitialMethodEnum = INIT_WITH_NONE; m_InitialTransform = NULL; // Rigid diff --git a/src/Registration/itkImageToImageRegistrationMethod.h b/src/Registration/itkImageToImageRegistrationMethod.h index b2a4c4c24..b4e5e60eb 100644 --- a/src/Registration/itkImageToImageRegistrationMethod.h +++ b/src/Registration/itkImageToImageRegistrationMethod.h @@ -1,17 +1,22 @@ /*========================================================================= - Program: Insight Segmentation & Registration Toolkit - Module: $RCSfile: ITKHeader.h,v $ - Language: C++ - Date: $Date: 2007-07-10 11:35:36 -0400 ( Tue, 10 Jul 2007 ) $ - Version: $Revision: 0 $ - - Copyright ( c ) 2002 Insight Consortium. All rights reserved. - See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details. - - This software is distributed WITHOUT ANY WARRANTY; without even - the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - PURPOSE. See the above copyright notices for more information. +Library: TubeTK + +Copyright Kitware Inc. + +All rights reserved. + +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/src/Registration/itkImageToImageRegistrationMethod.hxx b/src/Registration/itkImageToImageRegistrationMethod.hxx index feb9ca042..ec4f2f05a 100644 --- a/src/Registration/itkImageToImageRegistrationMethod.hxx +++ b/src/Registration/itkImageToImageRegistrationMethod.hxx @@ -1,17 +1,22 @@ /*========================================================================= - Program: Insight Segmentation & Registration Toolkit - Module: $RCSfile: MomentRegistrator.txx,v $ - Language: C++ - Date: $Date: 2007/03/29 17:52:55 $ - Version: $Revision: 1.6 $ - - Copyright (c) Insight Software Consortium. All rights reserved. - See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details. - - This software is distributed WITHOUT ANY WARRANTY; without even - the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - PURPOSE. See the above copyright notices for more information. +Library: TubeTK + +Copyright Kitware Inc. + +All rights reserved. + +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/src/Registration/itkInitialImageToImageRegistrationMethod.h b/src/Registration/itkInitialImageToImageRegistrationMethod.h index 6826e8520..05b4917bb 100644 --- a/src/Registration/itkInitialImageToImageRegistrationMethod.h +++ b/src/Registration/itkInitialImageToImageRegistrationMethod.h @@ -1,17 +1,22 @@ /*========================================================================= - Program: Insight Segmentation & Registration Toolkit - Module: $RCSfile: ITKHeader.h,v $ - Language: C++ - Date: $Date: 2007-07-10 11:35:36 -0400 ( Tue, 10 Jul 2007 ) $ - Version: $Revision: 0 $ - - Copyright ( c ) 2002 Insight Consortium. All rights reserved. - See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details. - - This software is distributed WITHOUT ANY WARRANTY; without even - the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - PURPOSE. See the above copyright notices for more information. +Library: TubeTK + +Copyright Kitware Inc. + +All rights reserved. + +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/src/Registration/itkOptimizedImageToImageRegistrationMethod.h b/src/Registration/itkOptimizedImageToImageRegistrationMethod.h index 58acd39ac..c1d4b699d 100644 --- a/src/Registration/itkOptimizedImageToImageRegistrationMethod.h +++ b/src/Registration/itkOptimizedImageToImageRegistrationMethod.h @@ -1,17 +1,22 @@ /*========================================================================= - Program: Insight Segmentation & Registration Toolkit - Module: $RCSfile: ITKHeader.h,v $ - Language: C++ - Date: $Date: 2007-07-10 11:35:36 -0400 ( Tue, 10 Jul 2007 ) $ - Version: $Revision: 0 $ - - Copyright ( c ) 2002 Insight Consortium. All rights reserved. - See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details. - - This software is distributed WITHOUT ANY WARRANTY; without even - the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - PURPOSE. See the above copyright notices for more information. +Library: TubeTK + +Copyright Kitware Inc. + +All rights reserved. + +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/src/Registration/itkOptimizedImageToImageRegistrationMethod.hxx b/src/Registration/itkOptimizedImageToImageRegistrationMethod.hxx index a947ffbe7..cba04adad 100644 --- a/src/Registration/itkOptimizedImageToImageRegistrationMethod.hxx +++ b/src/Registration/itkOptimizedImageToImageRegistrationMethod.hxx @@ -1,17 +1,22 @@ /*========================================================================= - Program: Insight Segmentation & Registration Toolkit - Module: $RCSfile: MomentRegistrator.txx,v $ - Language: C++ - Date: $Date: 2007/03/29 17:52:55 $ - Version: $Revision: 1.6 $ - - Copyright (c) Insight Software Consortium. All rights reserved. - See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details. - - This software is distributed WITHOUT ANY WARRANTY; without even - the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - PURPOSE. See the above copyright notices for more information. +Library: TubeTK + +Copyright Kitware Inc. + +All rights reserved. + +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/src/Registration/itkScaleSkewAngle2DImageToImageRegistrationMethod.h b/src/Registration/itkScaleSkewAngle2DImageToImageRegistrationMethod.h index feb2209bd..e7ba9afa6 100644 --- a/src/Registration/itkScaleSkewAngle2DImageToImageRegistrationMethod.h +++ b/src/Registration/itkScaleSkewAngle2DImageToImageRegistrationMethod.h @@ -1,19 +1,25 @@ /*========================================================================= - Program: Insight Segmentation & Registration Toolkit - Module: $RCSfile: ITKHeader.h,v $ - Language: C++ - Date: $Date: 2007-07-10 11:35:36 -0400 ( Tue, 10 Jul 2007 ) $ - Version: $Revision: 0 $ +Library: TubeTK - Copyright ( c ) 2002 Insight Consortium. All rights reserved. - See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details. +Copyright Kitware Inc. - This software is distributed WITHOUT ANY WARRANTY; without even - the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - PURPOSE. See the above copyright notices for more information. +All rights reserved. + +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. =========================================================================*/ + #ifndef __itkScaleSkewAngle2DImageToImageRegistrationMethod_h #define __itkScaleSkewAngle2DImageToImageRegistrationMethod_h diff --git a/src/Registration/itkScaleSkewAngle2DImageToImageRegistrationMethod.hxx b/src/Registration/itkScaleSkewAngle2DImageToImageRegistrationMethod.hxx index d2a4158e8..36d370b2b 100644 --- a/src/Registration/itkScaleSkewAngle2DImageToImageRegistrationMethod.hxx +++ b/src/Registration/itkScaleSkewAngle2DImageToImageRegistrationMethod.hxx @@ -1,17 +1,22 @@ /*========================================================================= - Program: Insight Segmentation & Registration Toolkit - Module: $RCSfile: ITKHeader.h,v $ - Language: C++ - Date: $Date: 2007-07-10 11:35:36 -0400 (Tue, 10 Jul 2007) $ - Version: $Revision: 0 $ - - Copyright (c) 2002 Insight Consortium. All rights reserved. - See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details. - - This software is distributed WITHOUT ANY WARRANTY; without even - the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - PURPOSE. See the above copyright notices for more information. +Library: TubeTK + +Copyright Kitware Inc. + +All rights reserved. + +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/src/Registration/itkScaleSkewAngle2DTransform.h b/src/Registration/itkScaleSkewAngle2DTransform.h index 4e8b2a696..71e4afd24 100644 --- a/src/Registration/itkScaleSkewAngle2DTransform.h +++ b/src/Registration/itkScaleSkewAngle2DTransform.h @@ -1,20 +1,25 @@ /*========================================================================= - * - * 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. - * - *=========================================================================*/ + +Library: TubeTK + +Copyright Kitware Inc. + +All rights reserved. + +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. + +=========================================================================*/ + #ifndef itkScaleSkewAngle2DTransform_h #define itkScaleSkewAngle2DTransform_h diff --git a/src/Registration/itkScaleSkewAngle2DTransform.hxx b/src/Registration/itkScaleSkewAngle2DTransform.hxx index bc7eeea0e..4a5b30ecb 100644 --- a/src/Registration/itkScaleSkewAngle2DTransform.hxx +++ b/src/Registration/itkScaleSkewAngle2DTransform.hxx @@ -1,20 +1,25 @@ /*========================================================================= - * - * 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. - * - *=========================================================================*/ + +Library: TubeTK + +Copyright Kitware Inc. + +All rights reserved. + +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. + +=========================================================================*/ + #ifndef itkScaleSkewAngle2DTransform_hxx #define itkScaleSkewAngle2DTransform_hxx diff --git a/src/Registration/itkScaleSkewVersor3DImageToImageRegistrationMethod.h b/src/Registration/itkScaleSkewVersor3DImageToImageRegistrationMethod.h index 5494af756..5ea8c565c 100644 --- a/src/Registration/itkScaleSkewVersor3DImageToImageRegistrationMethod.h +++ b/src/Registration/itkScaleSkewVersor3DImageToImageRegistrationMethod.h @@ -1,19 +1,25 @@ /*========================================================================= - Program: Insight Segmentation & Registration Toolkit - Module: $RCSfile: ITKHeader.h,v $ - Language: C++ - Date: $Date: 2007-07-10 11:35:36 -0400 ( Tue, 10 Jul 2007 ) $ - Version: $Revision: 0 $ +Library: TubeTK - Copyright ( c ) 2002 Insight Consortium. All rights reserved. - See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details. +Copyright Kitware Inc. - This software is distributed WITHOUT ANY WARRANTY; without even - the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - PURPOSE. See the above copyright notices for more information. +All rights reserved. + +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. =========================================================================*/ + #ifndef __itkScaleSkewVersor3DImageToImageRegistrationMethod_h #define __itkScaleSkewVersor3DImageToImageRegistrationMethod_h diff --git a/src/Registration/itkScaleSkewVersor3DImageToImageRegistrationMethod.hxx b/src/Registration/itkScaleSkewVersor3DImageToImageRegistrationMethod.hxx index 02ef2d8fb..fb1e4bd75 100644 --- a/src/Registration/itkScaleSkewVersor3DImageToImageRegistrationMethod.hxx +++ b/src/Registration/itkScaleSkewVersor3DImageToImageRegistrationMethod.hxx @@ -1,17 +1,22 @@ /*========================================================================= - Program: Insight Segmentation & Registration Toolkit - Module: $RCSfile: ITKHeader.h,v $ - Language: C++ - Date: $Date: 2007-07-10 11:35:36 -0400 (Tue, 10 Jul 2007) $ - Version: $Revision: 0 $ - - Copyright (c) 2002 Insight Consortium. All rights reserved. - See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details. - - This software is distributed WITHOUT ANY WARRANTY; without even - the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - PURPOSE. See the above copyright notices for more information. +Library: TubeTK + +Copyright Kitware Inc. + +All rights reserved. + +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/src/Registration/itkSimilarity2DTransform.h b/src/Registration/itkSimilarity2DTransform.h index b482e8061..b01f6d93a 100644 --- a/src/Registration/itkSimilarity2DTransform.h +++ b/src/Registration/itkSimilarity2DTransform.h @@ -1,20 +1,25 @@ /*========================================================================= - * - * 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. - * - *=========================================================================*/ + +Library: TubeTK + +Copyright Kitware Inc. + +All rights reserved. + +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. + +=========================================================================*/ + #ifndef itkSimilarity2DTransform_h #define itkSimilarity2DTransform_h diff --git a/src/Registration/itkSimilarity2DTransform.hxx b/src/Registration/itkSimilarity2DTransform.hxx index f0ca3918b..a6d6efe1b 100644 --- a/src/Registration/itkSimilarity2DTransform.hxx +++ b/src/Registration/itkSimilarity2DTransform.hxx @@ -1,20 +1,25 @@ /*========================================================================= - * - * 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. - * - *=========================================================================*/ + +Library: TubeTK + +Copyright Kitware Inc. + +All rights reserved. + +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. + +=========================================================================*/ + #ifndef itkSimilarity2DTransform_hxx #define itkSimilarity2DTransform_hxx diff --git a/src/Registration/itkAffine3DImageToImageRegistrationMethod.h b/src/Registration/itktubeAffineSpatialObjectToImageRegistrationMethod.h similarity index 60% rename from src/Registration/itkAffine3DImageToImageRegistrationMethod.h rename to src/Registration/itktubeAffineSpatialObjectToImageRegistrationMethod.h index 8ce445d09..3b55dd8d2 100644 --- a/src/Registration/itkAffine3DImageToImageRegistrationMethod.h +++ b/src/Registration/itktubeAffineSpatialObjectToImageRegistrationMethod.h @@ -1,44 +1,53 @@ /*========================================================================= - Program: Insight Segmentation & Registration Toolkit - Module: $RCSfile: ITKHeader.h,v $ - Language: C++ - Date: $Date: 2007-07-10 11:35:36 -0400 ( Tue, 10 Jul 2007 ) $ - Version: $Revision: 0 $ +Library: TubeTK - Copyright ( c ) 2002 Insight Consortium. All rights reserved. - See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details. +Copyright Kitware Inc. - This software is distributed WITHOUT ANY WARRANTY; without even - the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - PURPOSE. See the above copyright notices for more information. +All rights reserved. + +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. =========================================================================*/ -#ifndef __itkAffineImageToImageRegistrationMethod_h -#define __itkAffineImageToImageRegistrationMethod_h + +#ifndef __itktubeAffineSpatialObjectToImageRegistrationMethod_h +#define __itktubeAffineSpatialObjectToImageRegistrationMethod_h #include "itkImage.h" #include "itkAffineTransform.h" -#include "itkOptimizedImageToImageRegistrationMethod.h" +#include "itktubeOptimizedSpatialObjectToImageRegistrationMethod.h" namespace itk { -template -class AffineImageToImageRegistrationMethod - : public OptimizedImageToImageRegistrationMethod +namespace tube +{ + +template +class AffineSpatialObjectToImageRegistrationMethod + : public OptimizedSpatialObjectToImageRegistrationMethod { public: - typedef AffineImageToImageRegistrationMethod Self; - typedef OptimizedImageToImageRegistrationMethod Superclass; + typedef AffineSpatialObjectToImageRegistrationMethod Self; + typedef OptimizedSpatialObjectToImageRegistrationMethod Superclass; typedef SmartPointer Pointer; typedef SmartPointer ConstPointer; - itkTypeMacro( AffineImageToImageRegistrationMethod, - OptimizedImageToImageRegistrationMethod ); + itkTypeMacro( AffineSpatialObjectToImageRegistrationMethod, + OptimizedSpatialObjectToImageRegistrationMethod ); itkNewMacro( Self ); @@ -59,7 +68,7 @@ class AffineImageToImageRegistrationMethod // Superclass Methods // - void GenerateData( void ); + void GenerateData( void ) override; // // Custom Methods @@ -92,7 +101,7 @@ class AffineImageToImageRegistrationMethod * SetInitialTransformParameters() and * SetInitialTransformFixedParameters(). The method below facilitates to * use the AffineTransform returned by the - * InitialImageToImageRegistrationMethod + * InitialSpatialObjectToImageRegistrationMethod * to directly initialize this rigid registration method. */ void SetInitialTransformParametersFromAffineTransform( @@ -100,24 +109,26 @@ class AffineImageToImageRegistrationMethod protected: - AffineImageToImageRegistrationMethod( void ); - virtual ~AffineImageToImageRegistrationMethod( void ); + AffineSpatialObjectToImageRegistrationMethod( void ); + virtual ~AffineSpatialObjectToImageRegistrationMethod( void ); void PrintSelf( std::ostream & os, Indent indent ) const override; private: // Purposely not implemented - AffineImageToImageRegistrationMethod( const Self & ); + AffineSpatialObjectToImageRegistrationMethod( const Self & ); // Purposely not implemented void operator =( const Self & ); }; +} // end namespace tube + } // end namespace itk #ifndef ITK_MANUAL_INSTANTIATION -#include "itkAffineImageToImageRegistrationMethod.hxx" +#include "itktubeAffineSpatialObjectToImageRegistrationMethod.hxx" #endif -#endif // __ImageToImageRegistrationMethod_h +#endif // __SpatialObjectToImageRegistrationMethod_h diff --git a/src/Registration/itkAffine3DImageToImageRegistrationMethod.hxx b/src/Registration/itktubeAffineSpatialObjectToImageRegistrationMethod.hxx similarity index 53% rename from src/Registration/itkAffine3DImageToImageRegistrationMethod.hxx rename to src/Registration/itktubeAffineSpatialObjectToImageRegistrationMethod.hxx index 2d129df9f..f5e21d90a 100644 --- a/src/Registration/itkAffine3DImageToImageRegistrationMethod.hxx +++ b/src/Registration/itktubeAffineSpatialObjectToImageRegistrationMethod.hxx @@ -1,31 +1,39 @@ /*========================================================================= - Program: Insight Segmentation & Registration Toolkit - Module: $RCSfile: ITKHeader.h,v $ - Language: C++ - Date: $Date: 2007-07-10 11:35:36 -0400 (Tue, 10 Jul 2007) $ - Version: $Revision: 0 $ +Library: TubeTK - Copyright (c) 2002 Insight Consortium. All rights reserved. - See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details. +Copyright Kitware Inc. - This software is distributed WITHOUT ANY WARRANTY; without even - the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - PURPOSE. See the above copyright notices for more information. +All rights reserved. + +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. =========================================================================*/ -#ifndef __itkAffineImageToImageRegistrationMethod_txx -#define __itkAffineImageToImageRegistrationMethod_txx +#ifndef __itktubeAffineSpatialObjectToImageRegistrationMethod_hxx +#define __itktubeAffineSpatialObjectToImageRegistrationMethod_hxx -#include "itkAffineImageToImageRegistrationMethod.h" +#include "itktubeAffineSpatialObjectToImageRegistrationMethod.h" namespace itk { -template -AffineImageToImageRegistrationMethod -::AffineImageToImageRegistrationMethod( void ) +namespace tube +{ + +template +AffineSpatialObjectToImageRegistrationMethod +::AffineSpatialObjectToImageRegistrationMethod( void ) { this->SetTransform( AffineTransformType::New() ); this->GetTypedTransform()->SetIdentity(); @@ -41,7 +49,6 @@ AffineImageToImageRegistrationMethod { std::cerr << "ERROR: number of parameters not standard for affine transform" << std::endl; - std::cout << " # = " << scales.size() << ", expecting 12" << std::endl; } unsigned int scaleNum = 0; for( unsigned int d1 = 0; d1 < ImageDimension; d1++ ) @@ -72,15 +79,15 @@ AffineImageToImageRegistrationMethod this->SetNumberOfSamples( 150000 ); } -template -AffineImageToImageRegistrationMethod -::~AffineImageToImageRegistrationMethod( void ) +template +AffineSpatialObjectToImageRegistrationMethod +::~AffineSpatialObjectToImageRegistrationMethod( void ) { } -template +template void -AffineImageToImageRegistrationMethod +AffineSpatialObjectToImageRegistrationMethod ::GenerateData( void ) { // Set the center of rotation @@ -89,25 +96,25 @@ AffineImageToImageRegistrationMethod Superclass::GenerateData(); } -template -typename AffineImageToImageRegistrationMethod::TransformType -* AffineImageToImageRegistrationMethod +template +typename AffineSpatialObjectToImageRegistrationMethod::TransformType +* AffineSpatialObjectToImageRegistrationMethod ::GetTypedTransform( void ) { return static_cast( Superclass::GetTransform() ); } -template -const typename AffineImageToImageRegistrationMethod::TransformType -* AffineImageToImageRegistrationMethod +template +const typename AffineSpatialObjectToImageRegistrationMethod::TransformType +* AffineSpatialObjectToImageRegistrationMethod ::GetTypedTransform( void ) const { return static_cast( Superclass::GetTransform() ); } -template -typename AffineImageToImageRegistrationMethod::AffineTransformPointer -AffineImageToImageRegistrationMethod +template +typename AffineSpatialObjectToImageRegistrationMethod::AffineTransformPointer +AffineSpatialObjectToImageRegistrationMethod ::GetAffineTransform( void ) const { AffineTransformPointer trans = AffineTransformType::New(); @@ -122,23 +129,25 @@ AffineImageToImageRegistrationMethod return trans; } -template +template void -AffineImageToImageRegistrationMethod +AffineSpatialObjectToImageRegistrationMethod ::SetInitialTransformParametersFromAffineTransform( const AffineTransformType * affine ) { this->SetInitialTransformFixedParameters( affine->GetFixedParameters() ); this->SetInitialTransformParameters( affine->GetParameters() ); } -template +template void -AffineImageToImageRegistrationMethod +AffineSpatialObjectToImageRegistrationMethod ::PrintSelf( std::ostream & os, Indent indent ) const { Superclass::PrintSelf(os, indent); } -} +} // tube + +} // itk #endif diff --git a/src/Registration/itktubeAnisotropicDiffusiveRegistrationFilter.h b/src/Registration/itktubeAnisotropicDiffusiveRegistrationFilter.h index a914cc8f5..a719114bd 100644 --- a/src/Registration/itktubeAnisotropicDiffusiveRegistrationFilter.h +++ b/src/Registration/itktubeAnisotropicDiffusiveRegistrationFilter.h @@ -2,8 +2,7 @@ Library: TubeTK -Copyright 2010 Kitware Inc. 28 Corporate Drive, -Clifton Park, NY, 12065, USA. +Copyright Kitware Inc. All rights reserved. diff --git a/src/Registration/itktubeAnisotropicDiffusiveRegistrationFilter.hxx b/src/Registration/itktubeAnisotropicDiffusiveRegistrationFilter.hxx index c4a0125a8..f920cffd3 100644 --- a/src/Registration/itktubeAnisotropicDiffusiveRegistrationFilter.hxx +++ b/src/Registration/itktubeAnisotropicDiffusiveRegistrationFilter.hxx @@ -2,8 +2,7 @@ Library: TubeTK -Copyright 2010 Kitware Inc. 28 Corporate Drive, -Clifton Park, NY, 12065, USA. +Copyright Kitware Inc. All rights reserved. diff --git a/src/Registration/itktubeAnisotropicDiffusiveRegistrationFunction.h b/src/Registration/itktubeAnisotropicDiffusiveRegistrationFunction.h index a89b6063e..97ae3a381 100644 --- a/src/Registration/itktubeAnisotropicDiffusiveRegistrationFunction.h +++ b/src/Registration/itktubeAnisotropicDiffusiveRegistrationFunction.h @@ -2,8 +2,7 @@ Library: TubeTK -Copyright 2010 Kitware Inc. 28 Corporate Drive, -Clifton Park, NY, 12065, USA. +Copyright Kitware Inc. All rights reserved. diff --git a/src/Registration/itktubeAnisotropicDiffusiveRegistrationFunction.hxx b/src/Registration/itktubeAnisotropicDiffusiveRegistrationFunction.hxx index ec6c48662..baf127991 100644 --- a/src/Registration/itktubeAnisotropicDiffusiveRegistrationFunction.hxx +++ b/src/Registration/itktubeAnisotropicDiffusiveRegistrationFunction.hxx @@ -2,8 +2,7 @@ Library: TubeTK -Copyright 2010 Kitware Inc. 28 Corporate Drive, -Clifton Park, NY, 12065, USA. +Copyright Kitware Inc. All rights reserved. diff --git a/src/Registration/itktubeAnisotropicDiffusiveSparseRegistrationFilter.h b/src/Registration/itktubeAnisotropicDiffusiveSparseRegistrationFilter.h index 8cafb4bbc..af8a96314 100644 --- a/src/Registration/itktubeAnisotropicDiffusiveSparseRegistrationFilter.h +++ b/src/Registration/itktubeAnisotropicDiffusiveSparseRegistrationFilter.h @@ -2,8 +2,7 @@ Library: TubeTK -Copyright 2010 Kitware Inc. 28 Corporate Drive, -Clifton Park, NY, 12065, USA. +Copyright Kitware Inc. All rights reserved. diff --git a/src/Registration/itktubeDiffusiveRegistrationFilter.h b/src/Registration/itktubeDiffusiveRegistrationFilter.h index 3021ecb0e..469045616 100644 --- a/src/Registration/itktubeDiffusiveRegistrationFilter.h +++ b/src/Registration/itktubeDiffusiveRegistrationFilter.h @@ -2,8 +2,7 @@ Library: TubeTK -Copyright 2010 Kitware Inc. 28 Corporate Drive, -Clifton Park, NY, 12065, USA. +Copyright Kitware Inc. All rights reserved. diff --git a/src/Registration/itktubeDiffusiveRegistrationFilter.hxx b/src/Registration/itktubeDiffusiveRegistrationFilter.hxx index aa1d732b2..4acc5435f 100644 --- a/src/Registration/itktubeDiffusiveRegistrationFilter.hxx +++ b/src/Registration/itktubeDiffusiveRegistrationFilter.hxx @@ -2,8 +2,7 @@ Library: TubeTK -Copyright 2010 Kitware Inc. 28 Corporate Drive, -Clifton Park, NY, 12065, USA. +Copyright Kitware Inc. All rights reserved. diff --git a/src/Registration/itktubeDiffusiveRegistrationFilterUtils.h b/src/Registration/itktubeDiffusiveRegistrationFilterUtils.h index dbcf1ea86..3e0b1231f 100644 --- a/src/Registration/itktubeDiffusiveRegistrationFilterUtils.h +++ b/src/Registration/itktubeDiffusiveRegistrationFilterUtils.h @@ -2,8 +2,7 @@ Library: TubeTK -Copyright 2010 Kitware Inc. 28 Corporate Drive, -Clifton Park, NY, 12065, USA. +Copyright Kitware Inc. All rights reserved. diff --git a/src/Registration/itktubeDiffusiveRegistrationFilterUtils.hxx b/src/Registration/itktubeDiffusiveRegistrationFilterUtils.hxx index 27cbe6b7f..211363187 100644 --- a/src/Registration/itktubeDiffusiveRegistrationFilterUtils.hxx +++ b/src/Registration/itktubeDiffusiveRegistrationFilterUtils.hxx @@ -2,8 +2,7 @@ Library: TubeTK -Copyright 2010 Kitware Inc. 28 Corporate Drive, -Clifton Park, NY, 12065, USA. +Copyright Kitware Inc. All rights reserved. diff --git a/src/Registration/itktubeImageToTubeRigidMetric.h b/src/Registration/itktubeImageToTubeRigidMetric.h deleted file mode 100644 index 4fa735f40..000000000 --- a/src/Registration/itktubeImageToTubeRigidMetric.h +++ /dev/null @@ -1,229 +0,0 @@ -/*========================================================================= - -Library: TubeTK - -Copyright 2010 Kitware Inc. 28 Corporate Drive, -Clifton Park, NY, 12065, USA. - -All rights reserved. - -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. - -=========================================================================*/ - -#ifndef __itktubeImageToTubeRigidMetric_h -#define __itktubeImageToTubeRigidMetric_h - -#include -#include -#include -#include - -namespace itk -{ - -namespace tube -{ - -/** \class ImageToTubeRigidMetric - * \brief Computes similarity between two objects to be registered - * The metric implemented here corresponds to the following paper: - * \link - * http://www.cs.unc.edu/Research/MIDAG/pubs/papers/MICCAI01-aylwardVReg.pdf - * The metric is based on the fact that vessel centerlines are scaled - * intensity ridges in the image. - * - * \tparam TFixedImage Type of the Image to register against. - * \tparam TMovingSpatialObject Type of the SpatialObject to register with, - * could be a Tube, Group, etc. - * \tparam TTubeSpatialObject Type of the tubes contained within the input - * TMovingSpatialObject to use for the registration. - * - * \warning ( Derivative ) - */ - -template< class TFixedImage, - class TMovingSpatialObject, - class TTubeSpatialObject > -class ImageToTubeRigidMetric - : public ImageToSpatialObjectMetric< TFixedImage, TMovingSpatialObject > -{ -public: - /** Standard class typedefs. */ - typedef ImageToTubeRigidMetric Self; - typedef ImageToSpatialObjectMetric< TFixedImage, TMovingSpatialObject > - Superclass; - typedef SmartPointer< Self > Pointer; - typedef SmartPointer< const Self > ConstPointer; - - /** Dimension of the image and tube. */ - itkStaticConstMacro( ImageDimension, unsigned int, - TFixedImage::ImageDimension ); - itkStaticConstMacro( TubeDimension, unsigned int, - TTubeSpatialObject::ObjectDimension ); - - typedef TFixedImage FixedImageType; - typedef TMovingSpatialObject TubeTreeType; - typedef TTubeSpatialObject TubeType; - typedef typename TubeType::TubePointType TubePointType; - - typedef double ScalarType; - typedef GaussianDerivativeImageFunction< TFixedImage > - DerivativeImageFunctionType; - typedef typename Superclass::DerivativeType DerivativeType; - typedef typename Superclass::ParametersType ParametersType; - typedef typename Superclass::MeasureType MeasureType; - - /** Run-time type information ( and related methods ). */ - itkTypeMacro( ImageToTubeRigidMetric, ImageToSpatialObjectMetric ); - - /** Method for creation through the object factory. */ - itkNewMacro( Self ); - - inline unsigned int GetNumberOfParameters( void ) const override - { - return this->m_Transform->GetNumberOfParameters(); - } - - /** Type used for representing point components */ - typedef typename Superclass::CoordinateRepresentationType - CoordinateRepresentationType; - - /** Type definition for the size */ - typedef typename TFixedImage::SizeType SizeType; - - /** Type definition for the pixel type */ - typedef typename TFixedImage::PixelType PixelType; - - /** Type of the Transform Base class */ - typedef Euler3DTransform< ScalarType > TransformType; - typedef typename TransformType::Pointer TransformPointer; - typedef typename TransformType::InputPointType InputPointType; - typedef typename TransformType::OutputPointType OutputPointType; - typedef typename TransformType::ParametersType TransformParametersType; - typedef typename TransformType::JacobianType TransformJacobianType; - typedef TransformType::ParametersType FeatureWeightsType; - - /** Get the Derivatives of the Match Measure */ - const DerivativeType & GetDerivative( const ParametersType & - parameters ) const; - void GetDerivative( const ParametersType & parameters, - DerivativeType & derivative ) const override; - - /** Get the Value for SingleValue Optimizers */ - MeasureType GetValue( const ParametersType & parameters ) const override; - - /** Get Value and Derivatives for MultipleValuedOptimizers */ - void GetValueAndDerivative( const ParametersType & parameters, - MeasureType & Value, DerivativeType & Derivative ) const override; - - /** Initialize the metric */ - void Initialize( void ) override; - - /** Control the radius scaling of the metric. */ - itkSetMacro( Kappa, ScalarType ); - itkGetConstMacro( Kappa, ScalarType ); - - /** Set/Get the minimum scaling radius. */ - itkSetMacro( MinimumScalingRadius, ScalarType ); - itkGetConstMacro( MinimumScalingRadius, ScalarType ); - - /** Set/Get the extent of the blurring calculation given in Gaussian - * sigma's. */ - itkSetMacro( Extent, ScalarType ); - itkGetConstMacro( Extent, ScalarType ); - - /** Set/Get the scalar weights associated with every point in the tube. - * The index of the point weights should correspond to "standard tube tree - * interation". */ - void SetFeatureWeights( FeatureWeightsType & featureWeights ); - itkGetConstReferenceMacro( FeatureWeights, FeatureWeightsType ); - - TransformPointer GetTransform( void ) const - { - return dynamic_cast( this->m_Transform.GetPointer() ); - } - - /** Downsample the tube points by this integer value. */ - -protected: - ImageToTubeRigidMetric( void ); - virtual ~ImageToTubeRigidMetric( void ); - - typedef CovariantVector< ScalarType, TubeDimension > CovariantVectorType; - typedef Vector< ScalarType, TubeDimension > VectorType; - - typedef Matrix< ScalarType, TubeDimension, TubeDimension > MatrixType; - - typedef typename TubePointType::PointType PointType; - typedef vnl_vector< ScalarType > VnlVectorType; - typedef vnl_matrix< ScalarType > VnlMatrixType; - typedef CompensatedSummation< ScalarType > CompensatedSummationType; - - virtual void ComputeCenterOfRotation( void ); - SizeValueType CountTubePoints( void ); - - void GetDeltaAngles( const OutputPointType & x, - const VnlVectorType & dx, - const VectorType & offsets, - ScalarType angle[3] ) const; - -private: - ImageToTubeRigidMetric( const Self& ); // purposely not implemented - void operator=( const Self& ); // purposely not implemented - - typename DerivativeImageFunctionType::Pointer m_DerivativeImageFunction; - - ScalarType m_Kappa; - ScalarType m_MinimumScalingRadius; - ScalarType m_Extent; - - /** The center of rotation of the weighted tube points. */ - typedef PointType CenterOfRotationType; - CenterOfRotationType m_CenterOfRotation; - - /** Test whether the specified tube point is inside the Image. - * \param inputPoint the non-transformed tube point. - * \param outputPoint the transformed tube point. - * \param transform the transform to apply to the input point. */ - bool IsInside( const InputPointType & inputPoint, - OutputPointType & outputPoint, - const TransformType * transform ) const; - - ScalarType ComputeLaplacianMagnitude( - const typename TubePointType::CovariantVectorType & tubeNormal, - const ScalarType scale, - const OutputPointType & currentPoint ) const; - ScalarType ComputeThirdDerivatives( - const CovariantVectorType & v, - const ScalarType scale, - const OutputPointType & currentPoint ) const; - - /** - * \warning User is responsible for freeing the list, but not the elements - * of the list. - */ - typename TubeTreeType::ChildrenListType* GetTubes( void ) const; - - FeatureWeightsType m_FeatureWeights; -}; // End class ImageToTubeRigidMetric - -} // End namespace tube - -} // End namespace itk - -#ifndef ITK_MANUAL_INSTANTIATION -#include "itktubeImageToTubeRigidMetric.hxx" -#endif - -#endif // End !defined( __itktubeImageToTubeRigidMetric_h ) diff --git a/src/Registration/itktubeImageToTubeRigidMetric.hxx b/src/Registration/itktubeImageToTubeRigidMetric.hxx deleted file mode 100644 index 1b1008ed6..000000000 --- a/src/Registration/itktubeImageToTubeRigidMetric.hxx +++ /dev/null @@ -1,662 +0,0 @@ -/*========================================================================= - -Library: TubeTK - -Copyright Kitware Inc. - -All rights reserved. - -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. - -=========================================================================*/ - -#ifndef __itktubeImageToTubeRigidMetric_hxx -#define __itktubeImageToTubeRigidMetric_hxx - -#include "itktubeImageToTubeRigidMetric.h" - -#include - -namespace itk -{ - -namespace tube -{ - -template< class TFixedImage, class TMovingSpatialObject, - class TTubeSpatialObject > -ImageToTubeRigidMetric< TFixedImage, TMovingSpatialObject, - TTubeSpatialObject > -::ImageToTubeRigidMetric( void ) -{ - m_Kappa = 1.0; - m_MinimumScalingRadius = 0.1; - m_Extent = 3.0; - - m_CenterOfRotation.Fill( 0.0 ); - - m_DerivativeImageFunction = DerivativeImageFunctionType::New(); - - typedef LinearInterpolateImageFunction< FixedImageType > - DefaultInterpolatorType; - - this->m_Interpolator = DefaultInterpolatorType::New(); -} - - -template< class TFixedImage, class TMovingSpatialObject, - class TTubeSpatialObject > -ImageToTubeRigidMetric< TFixedImage, TMovingSpatialObject, - TTubeSpatialObject > -::~ImageToTubeRigidMetric( void ) -{ -} - - -template< class TFixedImage, class TMovingSpatialObject, - class TTubeSpatialObject > -void -ImageToTubeRigidMetric< TFixedImage, TMovingSpatialObject, - TTubeSpatialObject > -::SetFeatureWeights( FeatureWeightsType & featureWeights ) -{ - if( this->m_FeatureWeights.data_block() != featureWeights.data_block() || - this->m_FeatureWeights.GetSize() != featureWeights.GetSize() ) - { - // m_FeatureWeights should treated as const. - this->m_FeatureWeights.SetData( featureWeights.data_block(), - featureWeights.GetSize(), false ); - this->Modified(); - } -} - - -template< class TFixedImage, class TMovingSpatialObject, - class TTubeSpatialObject > -void -ImageToTubeRigidMetric< TFixedImage, TMovingSpatialObject, - TTubeSpatialObject > -::Initialize( void ) -{ - if( !this->m_MovingSpatialObject || !this->m_FixedImage ) - { - itkExceptionMacro( << "No tube/image net plugged in." ); - } - - const SizeValueType tubePoints = this->CountTubePoints(); - if( this->m_FeatureWeights.GetSize() == 0 ) - { - this->m_FeatureWeights.SetSize( tubePoints ); - this->m_FeatureWeights.Fill( NumericTraits< ScalarType >::One ); - } - if( this->m_FeatureWeights.GetSize() != tubePoints ) - { - itkExceptionMacro( - << "The number of FeatureWeights " - << "do not equal the number of tube points!" ); - } - this->ComputeCenterOfRotation(); - - this->m_Interpolator->SetInputImage( this->m_FixedImage ); - this->m_DerivativeImageFunction->SetInputImage( this->m_FixedImage ); -} - - -template< class TFixedImage, class TMovingSpatialObject, - class TTubeSpatialObject > -SizeValueType -ImageToTubeRigidMetric< TFixedImage, TMovingSpatialObject, - TTubeSpatialObject > -::CountTubePoints( void ) -{ - SizeValueType tubePoints = 0; - - typename TubeTreeType::ChildrenListType * tubeList = this->GetTubes(); - typename TubeTreeType::ChildrenListType::const_iterator tubeIterator; - for( tubeIterator = tubeList->begin(); - tubeIterator != tubeList->end(); - ++tubeIterator ) - { - TubeType* currentTube = dynamic_cast( - ( *tubeIterator ).GetPointer() ); - - if( currentTube != NULL ) - { - tubePoints += currentTube->GetNumberOfPoints(); - } - } - delete tubeList; - - return tubePoints; -} - - -template< class TFixedImage, class TMovingSpatialObject, - class TTubeSpatialObject > -void -ImageToTubeRigidMetric< TFixedImage, TMovingSpatialObject, TTubeSpatialObject > -::ComputeCenterOfRotation( void ) -{ - typename TubeTreeType::ChildrenListType* tubeList = this->GetTubes(); - - CompensatedSummationType featureWeightSum; - - SizeValueType weightCount = 0; - typedef typename TubeTreeType::ChildrenListType::iterator TubesIteratorType; - for( TubesIteratorType tubeIterator = tubeList->begin(); - tubeIterator != tubeList->end(); - ++tubeIterator ) - { - TubeType* currentTube = - dynamic_cast< TubeType * >( ( *tubeIterator ).GetPointer() ); - if( currentTube != NULL ) - { - currentTube->ComputeTangentsAndNormals(); - - const typename TubeType::TubePointListType & currentTubePoints - = currentTube->GetPoints(); - typedef typename TubeType::TubePointListType::const_iterator - TubePointIteratorType; - for( TubePointIteratorType tubePointIterator = - currentTubePoints.begin(); - tubePointIterator != currentTubePoints.end(); - ++tubePointIterator ) - { - const ScalarType weight = this->m_FeatureWeights[weightCount]; - ++weightCount; - - for( unsigned int ii = 0; ii < TubeDimension; ++ii ) - { - //! \todo CompensatedSummation - this->m_CenterOfRotation[ii] += - weight * ( tubePointIterator->GetPositionInObjectSpace() )[ii]; - } - featureWeightSum += weight; - } - } - } - delete tubeList; - - for( unsigned int ii = 0; ii < TubeDimension; ++ii ) - { - this->m_CenterOfRotation[ii] /= featureWeightSum.GetSum(); - } - - //! \todo partial template specialization for transforms with a center? - TransformType * transform = static_cast< TransformType * > - ( this->m_Transform.GetPointer() ); - transform->SetCenter( this->m_CenterOfRotation ); -} - - -template< class TFixedImage, class TMovingSpatialObject, - class TTubeSpatialObject > -typename ImageToTubeRigidMetric< TFixedImage, TMovingSpatialObject, - TTubeSpatialObject >::TubeTreeType::ChildrenListType* -ImageToTubeRigidMetric< TFixedImage, TMovingSpatialObject, TTubeSpatialObject > -::GetTubes( void ) const -{ - if( !this->m_MovingSpatialObject ) - { - return nullptr; - } - - char childName[] = "Tube"; - return this->m_MovingSpatialObject->GetChildren( - this->m_MovingSpatialObject->GetMaximumDepth(), childName ); -} - - -template< class TFixedImage, class TMovingSpatialObject, - class TTubeSpatialObject > -typename ImageToTubeRigidMetric< TFixedImage, TMovingSpatialObject, - TTubeSpatialObject >::MeasureType -ImageToTubeRigidMetric< TFixedImage, TMovingSpatialObject, TTubeSpatialObject > -::GetValue( const ParametersType & parameters ) const -{ - itkDebugMacro( << "**** Get Value ****" ); - itkDebugMacro( << "Parameters = " << parameters ); - - CompensatedSummationType matchMeasure; - CompensatedSummationType weightSum; - - // Create a copy of the transform to keep true const correctness ( - // thread-safe ) - // Set the parameters on the copy and uses the copy. - LightObject::Pointer anotherTransform = this->m_Transform->CreateAnother(); - TransformType * transformCopy = - static_cast< TransformType * >( anotherTransform.GetPointer() ); - transformCopy->SetFixedParameters( this->m_Transform->GetFixedParameters() ); - transformCopy->SetParameters( parameters ); - - typename TubeTreeType::ChildrenListType::iterator tubeIterator; - typename TubeTreeType::ChildrenListType * tubeList = GetTubes(); - SizeValueType weightCount = 0; - for( tubeIterator = tubeList->begin(); - tubeIterator != tubeList->end(); - ++tubeIterator ) - { - TubeType * currentTube = - dynamic_cast< TubeType * >( ( *tubeIterator ).GetPointer() ); - if( currentTube != NULL ) - { - typename TubeType::TubePointListType::iterator pointIterator; - for( pointIterator = currentTube->GetPoints().begin(); - pointIterator != currentTube->GetPoints().end(); - ++pointIterator ) - { - const InputPointType inputPoint = pointIterator->GetPositionInObjectSpace(); - OutputPointType currentPoint; - if( this->IsInside( inputPoint, currentPoint, transformCopy ) ) - { - weightSum += m_FeatureWeights[weightCount]; - ScalarType scalingRadius = pointIterator->GetRadiusInObjectSpace(); - scalingRadius = std::max( scalingRadius, m_MinimumScalingRadius ); - - const ScalarType scale = scalingRadius * m_Kappa; - - matchMeasure += m_FeatureWeights[weightCount] * std::fabs( - this->ComputeLaplacianMagnitude( - pointIterator->GetNormal1InObjectSpace(), - scale, - currentPoint ) ); - } - ++weightCount; - } - } // end is a tube - } - - if( weightSum.GetSum() == NumericTraits< ScalarType >::Zero ) - { - itkWarningMacro( - << "GetValue: All the transformed tube points are outside the image." ); - matchMeasure = NumericTraits< ScalarType >::min(); - } - else - { - const ScalarType normalizedMeasure = - static_cast< ScalarType >( matchMeasure.GetSum() / weightSum.GetSum() ); - matchMeasure = normalizedMeasure; - } - - itkDebugMacro( << "matchMeasure = " << matchMeasure.GetSum() ); - - delete tubeList; - return matchMeasure.GetSum(); -} - - -/** Compute the Laplacian magnitude */ -// TODO FACTORIZE CODE --> See ComputeThirdDerivative -template< class TFixedImage, class TMovingSpatialObject, - class TTubeSpatialObject > -typename ImageToTubeRigidMetric< TFixedImage, - TMovingSpatialObject, TTubeSpatialObject >::ScalarType -ImageToTubeRigidMetric< TFixedImage, TMovingSpatialObject, TTubeSpatialObject > -::ComputeLaplacianMagnitude( - const typename TubePointType::CovariantVectorType & tubeNormal, - const ScalarType scale, - const OutputPointType & currentPoint ) const -{ - // We convolve the 1D signal defined by the direction v at point - // currentPoint with a second derivative of a Gaussian - const ScalarType scaleSquared = scale * scale; - const ScalarType scaleExtentProduct = scale * m_Extent; - CompensatedSummationType kernelSum; - SizeValueType numberOfKernelPoints = 0; - - for( ScalarType distance = -scaleExtentProduct; - distance <= scaleExtentProduct; - //! \todo better calculation of the increment instead of just +1 - ++distance ) - { - typename FixedImageType::PointType point; - for( unsigned int ii = 0; ii < ImageDimension; ++ii ) - { - point[ii] = currentPoint[ii] + distance * tubeNormal.GetElement( ii ); - } - - if( this->m_Interpolator->IsInsideBuffer( point ) ) - { - const ScalarType distanceSquared = distance * distance; - //! \todo cache this value, so it can be used in the next loop - kernelSum += ( -1.0 + ( distanceSquared / scaleSquared ) ) - * std::exp( -0.5 * distanceSquared / scaleSquared ); - ++numberOfKernelPoints; - } - } - - //! \todo check this normalization - //( //where is the 1/( scale * sqrt( 2 pi ) ) - //term? - const ScalarType error = kernelSum.GetSum() / numberOfKernelPoints; - CompensatedSummationType result; - for( ScalarType distance = -scaleExtentProduct; - distance <= scaleExtentProduct; - //! \todo better calculation of the increment instead of just +1 - ++distance ) - { - const ScalarType distanceSquared = distance * distance; - const ScalarType kernelValue = - ( -1.0 + ( distanceSquared / scaleSquared ) ) - * std::exp( -0.5 * distanceSquared / scaleSquared ) - error; - - typename FixedImageType::PointType point; - for( unsigned int ii = 0; ii < ImageDimension; ++ii ) - { - point[ii] = currentPoint[ii] + distance * tubeNormal.GetElement( ii ); - } - - if( this->m_Interpolator->IsInsideBuffer( point ) ) - { - const ScalarType value = - static_cast< ScalarType >( - this->m_Interpolator->Evaluate( point ) ); - result += value * kernelValue; - } - } - - return result.GetSum(); -} - - -template< class TFixedImage, class TMovingSpatialObject, - class TTubeSpatialObject > -void -ImageToTubeRigidMetric< TFixedImage, TMovingSpatialObject, TTubeSpatialObject > -::GetDeltaAngles( const OutputPointType & tubePoint, - const VnlVectorType & dx, - const VectorType & offsets, - ScalarType dAngle[3] ) const -{ - VectorType radius = ( tubePoint - offsets ) - ( this->m_CenterOfRotation ); - radius.Normalize(); - - dAngle[0] = dx[1] * -radius[2] + dx[2] * radius[1]; - dAngle[1] = dx[0] * radius[2] + dx[2] * -radius[0]; - dAngle[2] = dx[0] * -radius[1] + dx[1] * radius[0]; -} - - -template< class TFixedImage, class TMovingSpatialObject, - class TTubeSpatialObject > -void -ImageToTubeRigidMetric< TFixedImage, TMovingSpatialObject, TTubeSpatialObject > -::GetDerivative( const ParametersType & parameters, - DerivativeType & derivative ) const -{ - derivative.SetSize( this->GetNumberOfParameters() ); - - // Create a copy of the transform to keep true const correctness - // ( thread-safe ) - // Set the parameters on the copy and uses the copy. - LightObject::Pointer anotherTransform = - this->m_Transform->CreateAnother(); - TransformType * transformCopy = - static_cast< TransformType * >( anotherTransform.GetPointer() ); - transformCopy->SetFixedParameters( this->m_Transform->GetFixedParameters() ); - transformCopy->SetParameters( parameters ); - - itkDebugMacro( << "**** Get Derivative ****" ); - itkDebugMacro( << "parameters = "<< parameters ); - - VnlMatrixType biasV( TubeDimension, TubeDimension, - NumericTraits< ScalarType >::Zero ); - VnlMatrixType biasVI( TubeDimension, TubeDimension, - NumericTraits< ScalarType >::Zero ); - - SizeValueType weightCount = 0; - - CompensatedSummationType dPosition[TubeDimension]; - - VnlMatrixType tM( TubeDimension, TubeDimension ); - VnlVectorType v1T( TubeDimension ); - VnlVectorType v2T( TubeDimension ); - - typedef std::vector< OutputPointType > TubePointsContainerType; - TubePointsContainerType transformedTubePoints; - transformedTubePoints.reserve( m_FeatureWeights.GetSize() ); - - typedef std::vector< VectorType > dTubePointsContainerType; - dTubePointsContainerType dtransformedTubePoints; - dtransformedTubePoints.reserve( m_FeatureWeights.GetSize() ); - - derivative.fill( 0.0 ); - - typename TubeTreeType::ChildrenListType * tubeList = GetTubes(); - typename TubeTreeType::ChildrenListType::const_iterator tubeIterator; - for( tubeIterator = tubeList->begin(); - tubeIterator != tubeList->end(); - ++tubeIterator ) - { - TubeType* currentTube = dynamic_cast( - ( *tubeIterator ).GetPointer() ); - - if( currentTube != NULL ) - { - typename TubeType::TubePointListType::const_iterator pointIterator; - for( pointIterator = currentTube->GetPoints().begin(); - pointIterator != currentTube->GetPoints().end(); - ++pointIterator ) - { - InputPointType inputPoint = pointIterator->GetPositionInObjectSpace(); - OutputPointType currentPoint; - if( this->IsInside( inputPoint, currentPoint, transformCopy ) ) - { - transformedTubePoints.push_back( currentPoint ); - - CovariantVectorType v1; - CovariantVectorType v2; - for( unsigned int ii = 0; ii < TubeDimension; ++ii ) - { - v1[ii] = pointIterator->GetNormal1InObjectSpace()[ii]; - v2[ii] = pointIterator->GetNormal2InObjectSpace()[ii]; - } - - for( unsigned int ii = 0; ii < TubeDimension; ++ii ) - { - v1T[ii] = transformCopy->TransformCovariantVector( v1 )[ii]; - v2T[ii] = transformCopy->TransformCovariantVector( v2 )[ii]; - } - tM = outer_product( v1T, v1T ); - tM = tM + outer_product( v2T, v2T ); - tM = m_FeatureWeights[weightCount] * tM; - biasV += tM; - - v1 = transformCopy->TransformCovariantVector( v1 ); - v2 = transformCopy->TransformCovariantVector( v2 ); - - ScalarType scalingRadius = pointIterator->GetRadiusInObjectSpace(); - scalingRadius = std::max( scalingRadius, m_MinimumScalingRadius ); - - const ScalarType scale = scalingRadius * m_Kappa; - - const ScalarType dXProj1 - = this->ComputeThirdDerivatives( v1, scale, currentPoint ); - const ScalarType dXProj2 - = this->ComputeThirdDerivatives( v2, scale, currentPoint ); - - VectorType dtransformedTubePoint; - for( unsigned int ii = 0; ii < TubeDimension; ++ii ) - { - dtransformedTubePoint[ii] = - ( dXProj1 * v1[ii] + dXProj2 * v2[ii] ); - dPosition[ii] += - m_FeatureWeights[weightCount] * ( dtransformedTubePoint[ii] ); - } - dtransformedTubePoints.push_back( dtransformedTubePoint ); - } - ++weightCount; - } - } - } - - biasVI = vnl_matrix_inverse< ScalarType >( biasV ).inverse(); - - VnlVectorType tV( TubeDimension ); - for( unsigned int ii = 0; ii < TubeDimension; ++ii ) - { - tV[ii] = dPosition[ii].GetSum(); - } - - tV *= biasVI; - - for( unsigned int ii = 0; ii < TubeDimension; ++ii ) - { - dPosition[ii] = tV[ii]; - } - - CompensatedSummationType dAngle[TubeDimension]; - VectorType offsets; - for( unsigned int ii = 0; ii < TubeDimension; ++ii ) - { - offsets[ii] = dPosition[ii].GetSum(); - } - typename TubePointsContainerType::const_iterator transformedTubePointsIt = - transformedTubePoints.begin(); - typename dTubePointsContainerType::const_iterator - dtransformedTubePointsIt = dtransformedTubePoints.begin(); - weightCount = 0; - for( tubeIterator = tubeList->begin(); - tubeIterator != tubeList->end(); - ++tubeIterator ) - { - TubeType* currentTube = dynamic_cast( - ( *tubeIterator ).GetPointer() ); - - if( currentTube != NULL ) - { - typename TubeType::TubePointListType::const_iterator pointIterator; - for( pointIterator = currentTube->GetPoints().begin(); - pointIterator != currentTube->GetPoints().end(); - ++pointIterator ) - { - InputPointType inputPoint = pointIterator->GetPositionInObjectSpace(); - OutputPointType currentPoint; - //! \todo this checking is not necessary, but we have to make sure - //have - //the corresponding weight -- should cache the result and use it - //here. - if( this->IsInside( inputPoint, currentPoint, transformCopy ) ) - { - VnlVectorType dXT( TubeDimension ); - for( unsigned int ii = 0; ii < TubeDimension; ++ii ) - { - dXT[ii] = ( *dtransformedTubePointsIt )[ii]; - } - - dXT = dXT * biasVI; - - ScalarType angleDelta[TubeDimension]; - this->GetDeltaAngles( *transformedTubePointsIt, dXT, offsets, - angleDelta ); - for( unsigned int ii = 0; ii < TubeDimension; ++ii ) - { - dAngle[ii] += m_FeatureWeights[weightCount] * angleDelta[ii]; - } - ++dtransformedTubePointsIt; - ++transformedTubePointsIt; - } - ++weightCount; - } - } - } - - derivative[0] = dAngle[0].GetSum(); - derivative[1] = dAngle[1].GetSum(); - derivative[2] = dAngle[2].GetSum(); - derivative[3] = dPosition[0].GetSum(); - derivative[4] = dPosition[1].GetSum(); - derivative[5] = dPosition[2].GetSum(); - - delete tubeList; -} - - -template< class TFixedImage, class TMovingSpatialObject, - class TTubeSpatialObject > -void -ImageToTubeRigidMetric< TFixedImage, TMovingSpatialObject, TTubeSpatialObject > -::GetValueAndDerivative( const ParametersType & parameters, - MeasureType & value, - DerivativeType & derivative ) const -{ - value = this->GetValue( parameters ); - this->GetDerivative( parameters, derivative ); -} - - -template< class TFixedImage, class TMovingSpatialObject, - class TTubeSpatialObject > -typename ImageToTubeRigidMetric< TFixedImage, TMovingSpatialObject, - TTubeSpatialObject >::ScalarType -ImageToTubeRigidMetric< TFixedImage, TMovingSpatialObject, TTubeSpatialObject > -::ComputeThirdDerivatives( - const CovariantVectorType & tubeNormal, - const ScalarType scale, - const OutputPointType & currentPoint ) const -{ - // We convolve the 1D signal defined by the direction v at point - // currentPoint with a second derivative of a Gaussian - CompensatedSummationType result; - CompensatedSummationType kernelSum; - - const ScalarType scaleSquared = scale * scale; - const ScalarType scaleExtentProduct = scale * m_Extent; - const ScalarType step = 0.1 * scaleExtentProduct; - for( ScalarType distance = -scaleExtentProduct; - distance <= scaleExtentProduct; - distance += step ) - { - const ScalarType distanceSquared = distance * distance; - const ScalarType kernelValue = - 2.0 * distance * std::exp( -0.5 * distanceSquared / scaleSquared ); - - kernelSum += std::fabs( kernelValue ); - - typename FixedImageType::PointType point; - for( unsigned int ii = 0; ii < ImageDimension; ++ii ) - { - point[ii] = currentPoint[ii] + distance * tubeNormal.GetElement( ii ); - } - - if( this->m_Interpolator->IsInsideBuffer( point ) ) - { - const ScalarType value = - static_cast< ScalarType >( - this->m_Interpolator->Evaluate( point ) ); - result += value * kernelValue; - } - } - - return result.GetSum() / kernelSum.GetSum(); -} - - -template< class TFixedImage, class TMovingSpatialObject, - class TTubeSpatialObject > -bool -ImageToTubeRigidMetric< TFixedImage, TMovingSpatialObject, TTubeSpatialObject > -::IsInside( const InputPointType & inputPoint, - OutputPointType & outputPoint, - const TransformType * transform ) const -{ - outputPoint = transform->TransformPoint( inputPoint ); - return ( this->m_Interpolator->IsInsideBuffer( outputPoint ) ); -} - -} // End namespace tube - -} // End namespace itk - -#endif // End !defined( __itktubeImageToTubeRigidMetric_hxx ) diff --git a/src/Registration/itktubeImageToTubeRigidRegistration.h b/src/Registration/itktubeImageToTubeRigidRegistration.h deleted file mode 100644 index 3f1b79bde..000000000 --- a/src/Registration/itktubeImageToTubeRigidRegistration.h +++ /dev/null @@ -1,140 +0,0 @@ -/*========================================================================= - -Library: TubeTK - -Copyright Kitware Inc. - -All rights reserved. - -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. - -=========================================================================*/ - -#ifndef __itktubeImageToTubeRigidRegistration_h -#define __itktubeImageToTubeRigidRegistration_h - -#include "itktubeImageToTubeRigidMetric.h" -#include "itktubeTubeExponentialResolutionWeightFunction.h" - -#include -#include -#include -#include -#include -#include -#include - -namespace itk -{ - -namespace tube -{ - -/** \class ImageToTubeRigidRegistration - * \brief Register a hierarchy of tubes to an image. - * - * This class provides basic registration of a hierarchy of tubes to an image. - * - * \tparam TFixedImage Type of the image to register against. - * \tparam TMovingSpatialObject Type of the moving spatial. This could be a - * TubeSpatialObject or perhaps a hierarchy of tubes contained in a - * GroupSpatialObject. - * \tparam TMovingTube Type of the tubes. Should be some type of - * TubeSpatialObject. - * - * The basic elements of a registration method are: - * - Metric to compare the image and the tubes. - * - Transformation used to register the image against the tubes. - * - * \ingroup AffineImageRegistration - */ - -template< class TFixedImage, class TMovingSpatialObject, class TMovingTube > -class ImageToTubeRigidRegistration - : public ImageToSpatialObjectRegistrationMethod< TFixedImage, - TMovingSpatialObject > -{ -public: - typedef ImageToTubeRigidRegistration Self; - typedef ImageToSpatialObjectRegistrationMethod< TFixedImage, - TMovingSpatialObject > - Superclass; - typedef SmartPointer< Self > Pointer; - typedef SmartPointer< const Self > ConstPointer; - - typedef typename Superclass::FixedImageType FixedImageType; - typedef typename Superclass::MovingSpatialObjectType MovingSpatialObjectType; - typedef TMovingTube MovingTubeType; - - /** Method for creation through the object factory. */ - itkNewMacro( Self ); - - /** Run-time type information ( and related methods ). */ - itkTypeMacro( ImageToTubeRigidRegistration, - ImageToSpatialObjectRegistrationMethod ); - - typedef typename Superclass::MetricType MetricType; - - typedef ImageToTubeRigidMetric< FixedImageType, - MovingSpatialObjectType, - MovingTubeType > - DefaultMetricType; - - typedef typename DefaultMetricType::TransformParametersType - ParametersType; - typedef typename DefaultMetricType::TransformType - TransformType; - typedef ParametersType - FeatureWeightsType; - - /** Dimension of the images. */ - enum { ImageDimension = FixedImageType::ImageDimension, - ParametersDimension = TransformType::ParametersDimension }; - - typedef typename Superclass::InterpolatorType InterpolatorType; - typedef typename Superclass::OptimizerType OptimizerType; - - /** Method that initiates the registration. */ - void StartRegistration( void ); - - /** Initialize the registration */ - void Initialize( void ); - - /** Set/Get the scalar weights associated with every point in the tube. - * The index of the point weights should correspond to "standard tube tree - * interation". */ - void SetFeatureWeights( FeatureWeightsType & featureWeights ); - itkGetConstReferenceMacro( FeatureWeights, FeatureWeightsType ); - -protected: - ImageToTubeRigidRegistration( void ); - virtual ~ImageToTubeRigidRegistration( void ) {} - -private: - ImageToTubeRigidRegistration( const Self& ); //purposely not implemented - void operator=( const Self& ); //purposely not implemented - - bool m_IsInitialized; - - FeatureWeightsType m_FeatureWeights; -}; // End class ImageToTubeRigidRegistration - -} // End namespace tube - -} // End namespace itk - -#ifndef ITK_MANUAL_INSTANTIATION -#include "itktubeImageToTubeRigidRegistration.hxx" -#endif - -#endif // End !defined( __itktubeImageToTubeRigidRegistration_h ) diff --git a/src/Registration/itktubeImageToTubeRigidRegistration.hxx b/src/Registration/itktubeImageToTubeRigidRegistration.hxx deleted file mode 100644 index f98b9d1c0..000000000 --- a/src/Registration/itktubeImageToTubeRigidRegistration.hxx +++ /dev/null @@ -1,178 +0,0 @@ -/*========================================================================= - -Library: TubeTK - -Copyright Kitware Inc. - -All rights reserved. - -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. - -=========================================================================*/ - -#ifndef __itktubeImageToTubeRigidRegistration_hxx -#define __itktubeImageToTubeRigidRegistration_hxx - -#include "itktubeImageToTubeRigidRegistration.h" - -#include "itktubeSubSampleTubeTreeSpatialObjectFilter.h" - -#include -#include -#include -#include -#include -#include - -namespace itk -{ - -namespace tube -{ - -template< class TFixedImage, class TMovingSpatialObject, class TMovingTube > -ImageToTubeRigidRegistration< TFixedImage, TMovingSpatialObject, TMovingTube > -::ImageToTubeRigidRegistration( void ) -{ - this->m_InitialTransformParameters = ParametersType( ParametersDimension ); - this->m_LastTransformParameters = ParametersType( ParametersDimension ); - - this->m_InitialTransformParameters.Fill( 0.0f ); - this->m_LastTransformParameters.Fill( 0.0f ); - - m_IsInitialized = false; - - typename DefaultMetricType::Pointer metric = DefaultMetricType::New(); - this->SetMetric( metric ); - - typedef LinearInterpolateImageFunction< FixedImageType > - DefaultInterpolatorType; - typename DefaultInterpolatorType::Pointer interpolator = - DefaultInterpolatorType::New(); - this->SetInterpolator( interpolator ); - - typename Superclass::OptimizerType::ParametersType parameterScales( 6 ); - parameterScales[0] = 30.; - parameterScales[1] = 30.; - parameterScales[2] = 30.; - parameterScales[3] = 1.; - parameterScales[4] = 1.; - parameterScales[5] = 1.; - - //typedef GradientDescentVariableStepOptimizer DefaultOptimizerType; - typedef GradientDescentOptimizer DefaultOptimizerType; - //typedef OnePlusOneEvolutionaryOptimizer DefaultOptimizerType; - typename DefaultOptimizerType::Pointer optimizer = - DefaultOptimizerType::New(); - - optimizer->MaximizeOn(); - optimizer->SetNumberOfIterations( 20 ); - optimizer->SetLearningRate( 0.1 ); - optimizer->SetScales( parameterScales ); - - //optimizer->SetMaximumIteration( m_NumberOfIteration ); - - //Statistics::NormalVariateGenerator::Pointer generator = - //Statistics::NormalVariateGenerator::New(); - //generator->SetReferenceCount( 2 ); - //generator->Initialize( std::time( NULL ) ); - - //optimizer->SetNormalVariateGenerator( generator ); - //optimizer->Initialize( 40 ); - - this->SetOptimizer( optimizer ); -} - - -template< class TFixedImage, class TMovingSpatialObject, class TMovingTube > -void -ImageToTubeRigidRegistration< TFixedImage, TMovingSpatialObject, TMovingTube > -::SetFeatureWeights( FeatureWeightsType & featureWeights ) -{ - if( this->m_FeatureWeights.data_block() != featureWeights.data_block() || - this->m_FeatureWeights.GetSize() != featureWeights.GetSize() ) - { - // m_FeatureWeights should treated as const. - this->m_FeatureWeights.SetData( featureWeights.data_block(), - featureWeights.GetSize(), false ); - this->Modified(); - } -} - - -template< class TFixedImage, class TMovingSpatialObject, class TMovingTube > -void -ImageToTubeRigidRegistration< TFixedImage, TMovingSpatialObject, TMovingTube > -::Initialize() -{ - typename TransformType::Pointer transform = TransformType::New(); - this->SetTransform( transform ); - - try - { - // initialize the interconnects between components - Superclass::Initialize(); - DefaultMetricType * defaultMetric - = dynamic_cast< DefaultMetricType * >( this->GetMetric() ); - if( defaultMetric != NULL ) - { - defaultMetric->SetFeatureWeights( this->m_FeatureWeights ); - } - } - catch( const ExceptionObject& ) - { - this->m_LastTransformParameters = ParametersType( 1 ); - this->m_LastTransformParameters.Fill( 0.0f ); - // pass exception to caller - throw; - } - - m_IsInitialized = true; -} - - -template< class TFixedImage, class TMovingSpatialObject, class TMovingTube > -void -ImageToTubeRigidRegistration< TFixedImage, TMovingSpatialObject, TMovingTube > -::StartRegistration( void ) -{ - if( !m_IsInitialized ) - { - this->Initialize(); - } - - try - { - // do the optimization - this->GetOptimizer()->StartOptimization(); - } - catch( const ExceptionObject& err ) - { - // An error has occurred in the optimization. - // Update the parameters - this->m_LastTransformParameters = this->GetOptimizer() - ->GetCurrentPosition(); - // Pass exception to caller - throw; - } - - // give the result to the superclass - this->m_LastTransformParameters = this->GetOptimizer() - ->GetCurrentPosition(); -} - -} // End namespace tube - -} // End namespace itk - -#endif // End !defined( __itktubeImageToTubeRigidRegistration_hxx ) diff --git a/src/Registration/itktubeInitialSpatialObjectToImageRegistrationMethod.h b/src/Registration/itktubeInitialSpatialObjectToImageRegistrationMethod.h new file mode 100644 index 000000000..8e6326f80 --- /dev/null +++ b/src/Registration/itktubeInitialSpatialObjectToImageRegistrationMethod.h @@ -0,0 +1,144 @@ +/*========================================================================= + +Library: TubeTK + +Copyright Kitware Inc. + +All rights reserved. + +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. + +=========================================================================*/ + +#ifndef __itktubeInitialSpatialObjectToImageRegistrationMethod_h +#define __itktubeInitialSpatialObjectToImageRegistrationMethod_h + +#include "itkImage.h" +#include "itkCommand.h" + +#include "itktubeSpatialObjectToImageRegistrationMethod.h" + +#include "itkAffineTransform.h" + +namespace itk +{ + +namespace tube +{ + +template +class InitialSpatialObjectToImageRegistrationMethod + : public SpatialObjectToImageRegistrationMethod +{ + +public: + + typedef InitialSpatialObjectToImageRegistrationMethod Self; + typedef SpatialObjectToImageRegistrationMethod Superclass; + typedef SmartPointer Pointer; + typedef SmartPointer ConstPointer; + + itkTypeMacro( InitialSpatialObjectToImageRegistrationMethod, + SpatialObjectToImageRegistrationMethod ); + + itkNewMacro( Self ); + + // + // Typedefs from Superclass + // + typedef Superclass::SpatialObjectType SpatialObjectType; + + itkStaticConstMacro( ImageDimension, unsigned int, + TImage::ImageDimension ); + + typedef AffineTransform + TransformType; + + typedef typename TransformType::Pointer TransformPointer; + + // + // Local Typedefs + // + typedef Point + LandmarkPointType; + typedef std::vector LandmarkPointContainer; + + // + // Custom Methods + // + + /** + * The function performs the casting. This function should only appear + * once in the class hierarchy. It is provided so that member + * functions that exist only in specific transforms ( e.g., SetIdentity ) + * can be called without the caller having to do the casting. */ + TransformType * GetTypedTransform( void ); + + const TransformType * GetTypedTransform( void ) const; + + /** This method creates, initializes and returns an Affine transform. The + * transform is initialized with the current results available in the + * GetTypedTransform() method. The returned transform is not a member + * variable, and therefore, must be received into a SmartPointer to prevent + * it from being destroyed by depletion of its reference counting. */ + TransformPointer GetAffineTransform( void ) const; + + itkSetMacro( NumberOfMoments, unsigned int ); + itkGetConstMacro( NumberOfMoments, unsigned int ); + + itkSetMacro( ComputeCenterOfRotationOnly, bool ); + itkGetConstMacro( ComputeCenterOfRotationOnly, bool ); + + itkSetMacro( UseLandmarks, bool ); + itkGetConstMacro( UseLandmarks, bool ); + + void SetFixedLandmarks( const LandmarkPointContainer& fixedLandmarks ); + + void SetMovingLandmarks( const LandmarkPointContainer& movingLandmarks ); + +protected: + + InitialSpatialObjectToImageRegistrationMethod( void ); + virtual ~InitialSpatialObjectToImageRegistrationMethod( void ); + + void PrintSelf( std::ostream & os, Indent indent ) const override; + + // + // Methods from Superclass. Only the GenerateData() method should be + // overloaded. The Update() method must not be overloaded. + // + void GenerateData() override; + +private: + + // Purposely not implemented + InitialSpatialObjectToImageRegistrationMethod( const Self & ); + // Purposely not implemented + void operator =( const Self & ); + + unsigned int m_NumberOfMoments; + bool m_ComputeCenterOfRotationOnly; + bool m_UseLandmarks; + LandmarkPointContainer m_FixedLandmarks; + LandmarkPointContainer m_MovingLandmarks; +}; + +} // end namespace tube + +} // end namespace itk + +#ifndef ITK_MANUAL_INSTANTIATION +#include "itktubeInitialSpatialObjectToImageRegistrationMethod.hxx" +#endif + +#endif // __InitialSpatialObjectToImageRegistrationMethod_h diff --git a/src/Registration/itktubeInitialSpatialObjectToImageRegistrationMethod.hxx b/src/Registration/itktubeInitialSpatialObjectToImageRegistrationMethod.hxx new file mode 100644 index 000000000..bd7acbc55 --- /dev/null +++ b/src/Registration/itktubeInitialSpatialObjectToImageRegistrationMethod.hxx @@ -0,0 +1,413 @@ +/*========================================================================= + +Library: TubeTK + +Copyright Kitware Inc. + +All rights reserved. + +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. + +=========================================================================*/ + +#ifndef __itktubeInitialSpatialObjectToImageRegistrationMethod_txx +#define __itktubeInitialSpatialObjectToImageRegistrationMethod_txx + +#include "itktubeInitialSpatialObjectToImageRegistrationMethod.h" + +//#include "itktubeSpatialObjectRegionMomentsCalculator.h" +#include "itkAnisotropicSimilarity3DTransform.h" +#include "itkAnisotropicSimilarityLandmarkBasedTransformInitializer.h" + +namespace itk +{ + +namespace tube +{ + +template +InitialSpatialObjectToImageRegistrationMethod +::InitialSpatialObjectToImageRegistrationMethod( void ) +{ + this->SetTransform( TransformType::New() ); + this->GetTypedTransform()->SetIdentity(); + + this->m_NumberOfMoments = 0; + + this->m_ComputeCenterOfRotationOnly = false; + + this->m_UseLandmarks = false; + +} + +template +InitialSpatialObjectToImageRegistrationMethod +::~InitialSpatialObjectToImageRegistrationMethod( void ) +{ +} + +template +void +InitialSpatialObjectToImageRegistrationMethod +::GenerateData( void ) +{ + Superclass::GenerateData(); + + if( this->m_UseLandmarks ) + { + typename TransformType::Pointer newTransform; + newTransform = TransformType::New(); + newTransform->SetIdentity(); + + typename TransformType::InputPointType center; + typename TransformType::MatrixType matrix; + typename TransformType::OffsetType offset; + + if( TImage::ImageDimension == 3 ) + { + typedef AnisotropicSimilarity3DTransform LandmarkTransformType; + typedef AnisotropicSimilarityLandmarkBasedTransformInitializer + LandmarkTransformCalculatorType; + + typename LandmarkTransformCalculatorType::Pointer landmarkCalc; + landmarkCalc = LandmarkTransformCalculatorType::New(); + landmarkCalc->SetFixedLandmarks( m_FixedLandmarks ); + landmarkCalc->SetMovingLandmarks( m_MovingLandmarks ); + + typename LandmarkTransformType::Pointer landmarkTransform; + landmarkTransform = LandmarkTransformType::New(); + landmarkTransform->SetIdentity(); + landmarkCalc->SetTransform(landmarkTransform); + landmarkCalc->InitializeTransform(); + for( unsigned int i = 0; i < TImage::ImageDimension; i++ ) + { + center[i] = landmarkTransform->GetCenter()[i]; + offset[i] = landmarkTransform->GetTranslation()[i]; + for( unsigned int j = 0; j < TImage::ImageDimension; j++ ) + { + matrix(i, j) = landmarkTransform->GetMatrix() (i, j); + } + } + } + else if( TImage::ImageDimension == 2 ) + { + typedef Rigid2DTransform LandmarkTransformType; + typedef AnisotropicSimilarityLandmarkBasedTransformInitializer + LandmarkTransformCalculatorType; + + typename LandmarkTransformCalculatorType::Pointer landmarkCalc; + landmarkCalc = LandmarkTransformCalculatorType::New(); + landmarkCalc->SetFixedLandmarks( m_FixedLandmarks ); + landmarkCalc->SetMovingLandmarks( m_MovingLandmarks ); + + typename LandmarkTransformType::Pointer landmarkTransform; + landmarkTransform = LandmarkTransformType::New(); + landmarkTransform->SetIdentity(); + landmarkCalc->SetTransform(landmarkTransform); + landmarkCalc->InitializeTransform(); + for( unsigned int i = 0; i < TImage::ImageDimension; i++ ) + { + center[i] = landmarkTransform->GetCenter()[i]; + offset[i] = landmarkTransform->GetTranslation()[i]; + for( unsigned int j = 0; j < TImage::ImageDimension; j++ ) + { + matrix(i, j) = landmarkTransform->GetMatrix() (i, j); + } + } + double tf; + double sizeFixed = 0; + for( int i = 1; i < (int)m_FixedLandmarks.size(); i++ ) + { + tf = (m_FixedLandmarks[i][0] - m_FixedLandmarks[i - 1][0]); + sizeFixed += tf * tf; + tf = (m_FixedLandmarks[i][1] - m_FixedLandmarks[i - 1][1]); + sizeFixed += tf * tf; + } + sizeFixed = sqrt(sizeFixed); + double sizeMoving = 0; + for( int i = 1; i < (int)m_MovingLandmarks.size(); i++ ) + { + tf = (m_MovingLandmarks[i][0] - m_MovingLandmarks[i - 1][0]); + sizeMoving += tf * tf; + tf = (m_MovingLandmarks[i][1] - m_MovingLandmarks[i - 1][1]); + sizeMoving += tf * tf; + } + sizeMoving = sqrt(sizeMoving); + double scale = sizeMoving / sizeFixed; + matrix *= scale; + } + else + { + std::cout << "Image type must be 3 or 2." << std::endl; + std::cout << "Initialization returning identity." << std::endl; + } + + newTransform->SetCenter( center ); + newTransform->SetMatrix( matrix ); + newTransform->SetTranslation( offset ); + this->SetTransform(newTransform); + + return; + } + + //typedef SpatialObjectRegionMomentsCalculator MomentsCalculatorType; + + typename TransformType::Pointer newTransform = TransformType::New(); + newTransform->SetIdentity(); + + if( this->m_ComputeCenterOfRotationOnly || + this->m_NumberOfMoments == 0 ) + { + // Moving image info + typedef SpatialObjectType::BoundingBoxType BoundingBoxType; + typename BoundingBoxType::ConstPointer bbox; + typename BoundingBoxType::PointType minPnt; + typename BoundingBoxType::PointType maxPnt; + Point movingCenterPoint; + + if( this->GetMovingSpatialObjectMaskObject() != nullptr ) + { + bbox = this->GetMovingSpatialObjectMaskObject()->GetMyBoundingBoxInWorldSpace(); + } + else + { + bbox = this->GetMovingSpatialObject()->GetMyBoundingBoxInWorldSpace(); + } + + minPnt = bbox->GetMinimum(); + maxPnt = bbox->GetMaximum(); + for( unsigned int i = 0; i < ObjectDimension; i++ ) + { + movingCenterPoint[i] = (maxPnt[i] + minPnt[i]) / 2.0; + } + + if( this->m_ComputeCenterOfRotationOnly ) + { + newTransform->SetCenter(movingCenterPoint); + } + else + { + // Fixed image info + Point fixedCenterPoint; + if( this->GetFixedImageMaskObject() != nullptr ) + { + typedef SpatialObjectType::BoundingBoxType BoundingBoxType; + typename BoundingBoxType::ConstPointer bbox; + typename BoundingBoxType::PointType minPnt; + typename BoundingBoxType::PointType maxPnt; + + bbox = this->GetFixedImageMaskObject()->GetMyBoundingBoxInWorldSpace(); + minPnt = bbox->GetMinimum(); + maxPnt = bbox->GetMaximum(); + for( unsigned int i = 0; i < ObjectDimension; i++ ) + { + fixedCenterPoint[i] = (maxPnt[i] + minPnt[i]) / 2.0; + } + } + else + { + typename TImage::IndexType fixedCenterIndex; + typename TImage::SizeType size; + + fixedCenterIndex = + this->GetFixedImage()->GetLargestPossibleRegion().GetIndex(); + size = this->GetFixedImage()->GetLargestPossibleRegion().GetSize(); + + for( unsigned int i = 0; i < ImageDimension; i++ ) + { + fixedCenterIndex[i] = (fixedCenterIndex[i] + size[i]) / 2; + } + this->GetFixedImage()->TransformIndexToPhysicalPoint(fixedCenterIndex, + fixedCenterPoint); + } + // Compute alignment + typename TransformType::OffsetType offset; + offset = movingCenterPoint - fixedCenterPoint; + + newTransform->SetCenter(movingCenterPoint); + newTransform->SetOffset(offset); + } + } + else + { + std::cerr << "SpatialObject moment calculator only supports 0th moments" + << std::endl; + /* + typename MomentsCalculatorType::Pointer momCalc; + momCalc = MomentsCalculatorType::New(); + + momCalc->SetImage( this->GetFixedImage() ); + if( this->GetUseFixedImageMaskObject() ) + { + if( this->GetFixedImageMaskObject() ) + { + momCalc->SetSpatialObjectMask( this->GetFixedImageMaskObject() ); + } + } + if( this->GetUseRegionOfInterest() ) + { + momCalc->SetRegionOfInterest( this->GetRegionOfInterestPoint1(), + this->GetRegionOfInterestPoint2() ); + } + + // HELP: ImageMomentsCalculator isn't multi-threaded :( + // momCalc->SetNumberOfWorkUnits( this->GetRegistrationNumberOfWorkUnits() ); + try + { + momCalc->Compute(); + } + catch( ... ) + { + std::cout << "Exception thrown when computing moments of fixed image." << std::endl; + std::cout << "Initialization returning identity." << std::endl; + newTransform->SetIdentity(); + this->SetTransform(newTransform); + return; + } + + typename MomentsCalculatorType::AffineTransformType::Pointer fixedImageAxesTransform; + + fixedImageAxesTransform = momCalc->GetPhysicalAxesToPrincipalAxesTransform(); + + typename TransformType::InputPointType fixedImageCenterOfMass; + for( unsigned int i = 0; i < this->ImageDimension; i++ ) + { + fixedImageCenterOfMass[i] = momCalc->GetCenterOfGravity()[i]; + } + + momCalc->SetImage( this->GetMovingSpatialObject() ); + + if( this->GetUseMovingSpatialObjectMaskObject() ) + { + if( this->GetMovingSpatialObjectMaskObject() ) + { + momCalc->SetSpatialObjectMask( this->GetMovingSpatialObjectMaskObject() ); + } + } + + try + { + momCalc->Compute(); + } + catch( ... ) + { + std::cout << "Exception thrown when computing moments of moving image." << std::endl; + std::cout << "Initialization returning identity." << std::endl; + newTransform->SetIdentity(); + this->SetTransform(newTransform); + return; + } + + typename MomentsCalculatorType::AffineTransformType::Pointer + movingSpatialObjectAxesTransform; + movingSpatialObjectAxesTransform = + momCalc->GetPrincipalAxesToPhysicalAxesTransform(); + + typename TransformType::InputPointType movingSpatialObjectCenterOfMass; + for( unsigned int i = 0; i < this->ImageDimension; i++ ) + { + movingSpatialObjectCenterOfMass[i] = momCalc->GetCenterOfGravity()[i]; + } + + typename TransformType::OffsetType offset; + offset = movingSpatialObjectCenterOfMass - fixedImageCenterOfMass; + + if( this->m_NumberOfMoments == 1 ) // Centers of mass + { + newTransform->SetCenter(movingSpatialObjectCenterOfMass); + newTransform->SetOffset(offset); + } + else // m_NumberOfMoments == 2 // Principle axes + { + newTransform->SetCenter(fixedImageCenterOfMass); + newTransform->SetMatrix(fixedImageAxesTransform->GetMatrix() ); + newTransform->SetOffset(fixedImageAxesTransform->GetOffset() ); + newTransform->Compose(movingSpatialObjectAxesTransform, true); + } + */ + } + this->SetTransform(newTransform); +} + +template +typename InitialSpatialObjectToImageRegistrationMethod::TransformType +* InitialSpatialObjectToImageRegistrationMethod +::GetTypedTransform( void ) + { + return static_cast( Superclass::GetTransform() ); + } + +template +const typename InitialSpatialObjectToImageRegistrationMethod::TransformType +* InitialSpatialObjectToImageRegistrationMethod +::GetTypedTransform( void ) const + { + return static_cast( this->Superclass::GetTransform() ); + } + +template +typename InitialSpatialObjectToImageRegistrationMethod::TransformPointer +InitialSpatialObjectToImageRegistrationMethod +::GetAffineTransform( void ) const +{ + typename TransformType::Pointer trans = TransformType::New(); + + const TransformType * typededTransform = this->GetTypedTransform(); + + trans->SetIdentity(); + trans->SetCenter( typededTransform->GetCenter() ); + trans->SetMatrix( typededTransform->GetMatrix() ); + trans->SetOffset( typededTransform->GetOffset() ); + + return trans; +} + +template +void +InitialSpatialObjectToImageRegistrationMethod +::SetFixedLandmarks( const LandmarkPointContainer& fixedLandmarks ) +{ + m_FixedLandmarks = fixedLandmarks; + this->Modified(); +} + +template +void +InitialSpatialObjectToImageRegistrationMethod +::SetMovingLandmarks( const LandmarkPointContainer& movingLandmarks ) +{ + m_MovingLandmarks = movingLandmarks; + this->Modified(); +} + +template +void +InitialSpatialObjectToImageRegistrationMethod +::PrintSelf( std::ostream & os, Indent indent ) const +{ + Superclass::PrintSelf( os, indent ); + + os << indent << "Number of moments = " << this->m_NumberOfMoments << std::endl; + + os << indent << "Compute Center Of Rotation Only = " << this->m_ComputeCenterOfRotationOnly << std::endl; + + os << indent << "Use Landmarks = " << this->m_UseLandmarks << std::endl; +} + +}; // tube + +}; // itk + +#endif diff --git a/src/Registration/itktubeMeanSquareRegistrationFunction.h b/src/Registration/itktubeMeanSquareRegistrationFunction.h index a8e476eea..a6f3d957c 100644 --- a/src/Registration/itktubeMeanSquareRegistrationFunction.h +++ b/src/Registration/itktubeMeanSquareRegistrationFunction.h @@ -2,8 +2,7 @@ Library: TubeTK -Copyright 2010 Kitware Inc. 28 Corporate Drive, -Clifton Park, NY, 12065, USA. +Copyright Kitware Inc. All rights reserved. diff --git a/src/Registration/itktubeMeanSquareRegistrationFunction.hxx b/src/Registration/itktubeMeanSquareRegistrationFunction.hxx index afa31bb8b..aeff1926b 100644 --- a/src/Registration/itktubeMeanSquareRegistrationFunction.hxx +++ b/src/Registration/itktubeMeanSquareRegistrationFunction.hxx @@ -2,8 +2,7 @@ Library: TubeTK -Copyright 2010 Kitware Inc. 28 Corporate Drive, -Clifton Park, NY, 12065, USA. +Copyright Kitware Inc. All rights reserved. diff --git a/src/Registration/itktubeMergeAdjacentImagesFilter.h b/src/Registration/itktubeMergeAdjacentImagesFilter.h index 7817a2e92..cb0d0a7e4 100644 --- a/src/Registration/itktubeMergeAdjacentImagesFilter.h +++ b/src/Registration/itktubeMergeAdjacentImagesFilter.h @@ -2,8 +2,7 @@ Library: TubeTK -Copyright 2010 Kitware Inc. 28 Corporate Drive, -Clifton Park, NY, 12065, USA. +Copyright Kitware Inc. All rights reserved. diff --git a/src/Registration/itktubeMergeAdjacentImagesFilter.hxx b/src/Registration/itktubeMergeAdjacentImagesFilter.hxx index bc88f7c23..7e0488ec1 100644 --- a/src/Registration/itktubeMergeAdjacentImagesFilter.hxx +++ b/src/Registration/itktubeMergeAdjacentImagesFilter.hxx @@ -2,8 +2,7 @@ Library: TubeTK -Copyright 2010 Kitware Inc. 28 Corporate Drive, -Clifton Park, NY, 12065, USA. +Copyright Kitware Inc. All rights reserved. diff --git a/src/Registration/itktubeOptimizedSpatialObjectToImageRegistrationMethod.h b/src/Registration/itktubeOptimizedSpatialObjectToImageRegistrationMethod.h new file mode 100644 index 000000000..467e1218d --- /dev/null +++ b/src/Registration/itktubeOptimizedSpatialObjectToImageRegistrationMethod.h @@ -0,0 +1,182 @@ +/*========================================================================= + +Library: TubeTK + +Copyright Kitware Inc. + +All rights reserved. + +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. + +=========================================================================*/ + +#ifndef __itktubeOptimizedSpatialObjectToImageRegistrationMethod_h +#define __itktubeOptimizedSpatialObjectToImageRegistrationMethod_h + +#include "itkImage.h" + +#include "itktubeSpatialObjectToImageRegistrationMethod.h" +#include "itktubePointBasedSpatialObjectToImageMetric.h" + +namespace itk +{ + +namespace tube +{ + +template +class OptimizedSpatialObjectToImageRegistrationMethod + : public SpatialObjectToImageRegistrationMethod +{ + +public: + + typedef OptimizedSpatialObjectToImageRegistrationMethod + Self; + typedef SpatialObjectToImageRegistrationMethod + Superclass; + typedef SmartPointer Pointer; + typedef SmartPointer ConstPointer; + + itkTypeMacro( OptimizedSpatialObjectToImageRegistrationMethod, + SpatialObjectToImageRegistrationMethod ); + + itkNewMacro( Self ); + + // + // Typedefs from Superclass + // + typedef TImage ImageType; + typedef SpatialObject SpatialObjectType; + + typedef typename ImageType::PixelType PixelType; + + typedef typename Superclass::TransformType TransformType; + + typedef typename TransformType::ParametersType TransformParametersType; + + typedef typename TransformType::ParametersType TransformParametersScalesType; + + itkStaticConstMacro( ImageDimension, unsigned int, + TImage::ImageDimension ); + + // + // Custom Typedefs + // + enum TransformMethodEnumType { RIGID_TRANSFORM, + AFFINE_TRANSFORM, + BSPLINE_TRANSFORM }; + + enum MetricMethodEnumType { IMAGE_INTENSITY_METRIC }; + + // + // Methods from Superclass + // + virtual void GenerateData( void ) override; + + // + // Custom Methods + // + itkSetMacro( InitialTransformParameters, TransformParametersType ); + itkGetConstMacro( InitialTransformParameters, TransformParametersType ); + + itkSetMacro( InitialTransformFixedParameters, TransformParametersType ); + itkGetConstMacro( InitialTransformFixedParameters, TransformParametersType ); + + itkSetMacro( LastTransformParameters, TransformParametersType ); + itkGetConstMacro( LastTransformParameters, TransformParametersType ); + + itkSetMacro( TransformParametersScales, TransformParametersScalesType ); + itkGetConstMacro( TransformParametersScales, TransformParametersScalesType ); + + itkSetMacro( MaxIterations, unsigned int ); + itkGetConstMacro( MaxIterations, unsigned int ); + + itkSetMacro( UseEvolutionaryOptimization, bool ); + itkGetConstMacro( UseEvolutionaryOptimization, bool ); + + itkSetMacro( NumberOfSamples, unsigned int ); + itkGetConstMacro( NumberOfSamples, unsigned int ); + + itkSetMacro( SamplingRatio, double ); + itkGetConstMacro( SamplingRatio, double ); + + itkSetMacro( TargetError, double ); + itkGetConstMacro( TargetError, double ); + + itkSetMacro( RandomNumberSeed, int ); + itkGetConstMacro( RandomNumberSeed, int ); + + itkGetConstMacro( TransformMethodEnum, TransformMethodEnumType ); + + itkSetMacro( MetricMethodEnum, MetricMethodEnumType ); + itkGetConstMacro( MetricMethodEnum, MetricMethodEnumType ); + + itkGetMacro( FinalMetricValue, double ); + +protected: + + OptimizedSpatialObjectToImageRegistrationMethod( void ); + virtual ~OptimizedSpatialObjectToImageRegistrationMethod( void ); + + itkSetMacro( FinalMetricValue, double ); + + itkSetMacro( TransformMethodEnum, TransformMethodEnumType ); + + typedef SpatialObjectToImageMetric MetricType; + + virtual void Optimize( MetricType * metric ); + + virtual void PrintSelf( std::ostream & os, Indent indent ) const override; + +private: + + // Purposely not implemented + OptimizedSpatialObjectToImageRegistrationMethod( const Self & ); + // Purposely not implemented + void operator =( const Self & ); + + TransformParametersType m_InitialTransformParameters; + TransformParametersType m_InitialTransformFixedParameters; + + TransformParametersType m_LastTransformParameters; + + TransformParametersScalesType m_TransformParametersScales; + + unsigned int m_MaxIterations; + + bool m_UseEvolutionaryOptimization; + + unsigned int m_NumberOfSamples; + double m_SamplingRatio; + + double m_TargetError; + + int m_RandomNumberSeed; + + TransformMethodEnumType m_TransformMethodEnum; + + MetricMethodEnumType m_MetricMethodEnum; + + double m_FinalMetricValue; +}; + +} // tube + +} // itk + +#ifndef ITK_MANUAL_INSTANTIATION +#include "itktubeOptimizedSpatialObjectToImageRegistrationMethod.hxx" +#endif + +#endif diff --git a/src/Registration/itktubeOptimizedSpatialObjectToImageRegistrationMethod.hxx b/src/Registration/itktubeOptimizedSpatialObjectToImageRegistrationMethod.hxx new file mode 100644 index 000000000..9b6812847 --- /dev/null +++ b/src/Registration/itktubeOptimizedSpatialObjectToImageRegistrationMethod.hxx @@ -0,0 +1,446 @@ +/*========================================================================= + +Library: TubeTK + +Copyright Kitware Inc. + +All rights reserved. + +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. + +=========================================================================*/ + +#ifndef __itktubeOptimizedSpatialObjectToImageRegistrationMethod_txx +#define __itktubeOptimizedSpatialObjectToImageRegistrationMethod_txx + +#include "itktubeSpatialObjectToImageRegistrationMethod.h" +#include "itktubeOptimizedSpatialObjectToImageRegistrationMethod.h" +#include "itktubePointBasedSpatialObjectToImageMetric.h" + +#include "itkRealTimeClock.h" + +#include "itkSingleValuedNonLinearOptimizer.h" +#include "itkOnePlusOneEvolutionaryOptimizer.h" +#include "itkNormalVariateGenerator.h" + +#include "itkRegularStepGradientDescentOptimizer.h" +#include "itkFRPROptimizer.h" +#include "itkImageMaskSpatialObject.h" + +#include "itkImage.h" +#include + +#include + +namespace itk +{ + +namespace tube +{ + +class SpatialObjectToImageRegistrationViewer + : public Command +{ +public: + typedef SpatialObjectToImageRegistrationViewer Self; + typedef Command Superclass; + typedef SmartPointer Pointer; + + itkTypeMacro( SpatialObjectToImageRegistrationViewer, Command ); + + itkNewMacro( SpatialObjectToImageRegistrationViewer ); + + typedef SingleValuedNonLinearOptimizer OptimizerType; + + itkSetMacro(DontShowParameters, bool); + itkSetMacro(UpdateInterval, int); + + void Execute( Object * caller, const EventObject & event ) override + { + Execute( (const Object *)caller, event ); + } + + void Execute( const Object * object, const EventObject & event ) override + { + if( typeid( event ) != typeid( IterationEvent ) || object == NULL ) + { + return; + } + + const OptimizerType * opt = dynamic_cast(object); + + if( ++m_Iteration % m_UpdateInterval == 0 ) + { + RealTimeClock::TimeStampType t = m_Clock->GetTimeInSeconds(); + if( !m_DontShowParameters ) + { + std::cout << " " << m_Iteration << " : " + << opt->GetCurrentPosition() << " = " + << opt->GetValue( opt->GetCurrentPosition() ) + << " (" << (t - m_LastTime) / m_UpdateInterval << "s)" + << std::endl; + } + else + { + std::cout << " " << m_Iteration << " : " + << opt->GetValue( opt->GetCurrentPosition() ) + << " (" << (t - m_LastTime) / m_UpdateInterval << "s)" + << std::endl; + } + m_LastTime = t; + } + } + + void Update() + { + this->Execute( (const Object *)NULL, IterationEvent() ); + } + +protected: + + RealTimeClock::Pointer m_Clock; + RealTimeClock::TimeStampType m_LastTime; + + int m_Iteration; + int m_UpdateInterval; + bool m_DontShowParameters; + + SpatialObjectToImageRegistrationViewer() + { + m_Clock = RealTimeClock::New(); + m_LastTime = m_Clock->GetTimeInSeconds(); + m_Iteration = 0; + m_UpdateInterval = 1; + m_DontShowParameters = false; + }; + ~SpatialObjectToImageRegistrationViewer() + { + }; + +}; + +template +OptimizedSpatialObjectToImageRegistrationMethod +::OptimizedSpatialObjectToImageRegistrationMethod( void ) +{ + m_InitialTransformParameters = TransformParametersType(1); + m_InitialTransformParameters.Fill( 0.0f ); + + m_InitialTransformFixedParameters = TransformParametersType(1); + m_InitialTransformFixedParameters.Fill( 0.0f ); + + m_LastTransformParameters = TransformParametersType(1); + m_LastTransformParameters.Fill( 0.0f ); + + m_TransformParametersScales = TransformParametersScalesType(1); + m_TransformParametersScales.Fill( 1.0f ); + + // The following MaxIterations value is a good default for rigid + // registration. Other derived registration methods should use + // their own default. + m_MaxIterations = 100; + + m_UseEvolutionaryOptimization = true; + + m_SamplingRatio = 0.01; + + m_TargetError = 0.00001; + + m_TransformMethodEnum = RIGID_TRANSFORM; + + m_MetricMethodEnum = IMAGE_INTENSITY_METRIC; + + m_FinalMetricValue = 0; + +} + +template +OptimizedSpatialObjectToImageRegistrationMethod +::~OptimizedSpatialObjectToImageRegistrationMethod( void ) +{ +} + +template +void +OptimizedSpatialObjectToImageRegistrationMethod +::GenerateData( void ) +{ + std::cout << "ORM: GenerateData" << std::endl; + if( this->GetReportProgress() ) + { + std::cout << "UPDATE START" << std::endl; + } + + this->Initialize(); + + this->GetTransform()->SetParametersByValue( + this->GetInitialTransformParameters() ); + + typename MetricType::Pointer metric; + + switch( this->GetMetricMethodEnum() ) + { + default: + case IMAGE_INTENSITY_METRIC: + { + typedef PointBasedSpatialObjectToImageMetric + TypedMetricType; + + typename TypedMetricType::Pointer typedMetric = TypedMetricType::New(); + typedMetric->SetSamplingRatio( m_SamplingRatio ); + metric = typedMetric; + } + break; + } + + typename ImageType::ConstPointer fixedImage = this->GetFixedImage(); + typename SpatialObjectType::ConstPointer movingSpatialObject = + this->GetMovingSpatialObject(); + + metric->SetFixedImage( fixedImage ); + metric->SetMovingSpatialObject( movingSpatialObject ); + metric->SetTransform(this->GetTransform()); + + metric->SetUseFixedImageMaskObject( this->GetUseFixedImageMaskObject() ); + if( this->GetUseFixedImageMaskObject() ) + { + metric->SetFixedImageMaskObject( this->GetFixedImageMaskObject() ); + } + + metric->SetUseMovingSpatialObjectMaskObject( + this->GetUseMovingSpatialObjectMaskObject() ); + if( this->GetUseMovingSpatialObjectMaskObject() ) + { + metric->SetMovingSpatialObjectMaskObject( + this->GetMovingSpatialObjectMaskObject() ); + } + + std::cout << "ORM: GenerateData: Metric Init" << std::endl; + metric->Initialize(); + + std::cout << "ORM: GenerateData: Optimize" << std::endl; + try + { + this->Optimize(metric); + } + catch( itk::ExceptionObject& exception ) + { + std::cerr << "Optimization threw an exception." << std::endl; + std::cerr << exception << std::endl ; + } + + if( this->GetReportProgress() ) + { + std::cout << "UPDATE END" << std::endl; + } +} + +template +void +OptimizedSpatialObjectToImageRegistrationMethod +::Optimize( MetricType * metric ) +{ + if( m_UseEvolutionaryOptimization && this->GetMaxIterations() > 0 ) + { + if( this->GetReportProgress() ) + { + std::cout << "EVOLUTIONARY START" << std::endl; + } + + typedef OnePlusOneEvolutionaryOptimizer EvoOptimizerType; + EvoOptimizerType::Pointer evoOpt = EvoOptimizerType::New(); + + evoOpt->SetNormalVariateGenerator( Statistics::NormalVariateGenerator + ::New() ); + evoOpt->SetEpsilon( this->GetTargetError() ); + evoOpt->Initialize( 0.1 ); + evoOpt->SetCatchGetValueException( true ); + evoOpt->SetMetricWorstPossibleValue( 9999999 ); + evoOpt->SetScales( this->GetTransformParametersScales() ); + evoOpt->SetMaximumIteration( this->GetMaxIterations() ); + evoOpt->SetMaximize( false ); + + if( this->GetObserver() ) + { + evoOpt->AddObserver( IterationEvent(), this->GetObserver() ); + } + + if( this->GetReportProgress() ) + { + typedef SpatialObjectToImageRegistrationViewer ViewerCommandType; + typename ViewerCommandType::Pointer command = ViewerCommandType::New(); + if( this->GetTransform()->GetNumberOfParameters() > 16 ) + { + command->SetDontShowParameters( true ); + } + evoOpt->AddObserver( IterationEvent(), command ); + } + + evoOpt->SetCostFunction(metric); + evoOpt->SetInitialPosition(m_InitialTransformParameters); + try + { + evoOpt->StartOptimization(); + } + catch (...) + { + std::cout << "Exception caught during evolutionary registration." + << std::endl; + std::cout << "Continuing using best values..." << std::endl; + std::cout << " Pos = " << evoOpt->GetCurrentPosition() + << std::endl << std::endl; + } + + if( evoOpt->GetCurrentPosition().size() != + this->GetTransform()->GetNumberOfParameters() ) + { + this->SetLastTransformParameters( this->GetInitialTransformParameters() ); + } + else + { + this->SetLastTransformParameters( evoOpt->GetCurrentPosition() ); + } + this->GetTransform()->SetParametersByValue( m_LastTransformParameters ); + m_FinalMetricValue = metric->GetValue( m_LastTransformParameters ); + } + else + { + this->SetLastTransformParameters( this->GetInitialTransformParameters() ); + this->GetTransform()->SetParametersByValue( m_LastTransformParameters ); + m_FinalMetricValue = 0; + } + + if( this->GetReportProgress() ) + { + std::cout << "EVOLUTIONARY END" << std::endl; + } + + if( this->GetMaxIterations() > 0 ) + { + //if( this->GetReportProgress() ) + { + std::cout << "GRADIENT START" << std::endl; + } + + typedef FRPROptimizer GradOptimizerType; + GradOptimizerType::Pointer gradOpt = GradOptimizerType::New(); + + gradOpt->SetMaximize( false ); + gradOpt->SetCatchGetValueException( true ); + gradOpt->SetMetricWorstPossibleValue( 9999999 ); + gradOpt->SetStepLength( 0.25 ); + gradOpt->SetStepTolerance( this->GetTargetError() ); + gradOpt->SetMaximumIteration( this->GetMaxIterations() ); + gradOpt->SetMaximumLineIteration( 10 ); + gradOpt->SetScales( this->GetTransformParametersScales() ); + gradOpt->SetUseUnitLengthGradient(true); + gradOpt->SetToFletchReeves(); + + //if( this->GetReportProgress() ) + { + typedef SpatialObjectToImageRegistrationViewer ViewerCommandType; + typename ViewerCommandType::Pointer command = ViewerCommandType::New(); + if( this->GetTransform()->GetNumberOfParameters() > 16 ) + { + command->SetDontShowParameters( true ); + } + gradOpt->AddObserver( IterationEvent(), command ); + } + if( this->GetObserver() ) + { + gradOpt->AddObserver( IterationEvent(), this->GetObserver() ); + } + + gradOpt->SetCostFunction(metric); + gradOpt->SetInitialPosition(m_InitialTransformParameters); + try + { + gradOpt->StartOptimization(); + } + catch( ... ) + { + std::cout << "Exception caught during gradient registration." + << std::endl; + std::cout << "Continuing using best values..." << std::endl; + std::cout << " Pos = " << gradOpt->GetCurrentPosition() + << std::endl << std::endl; + } + + if( gradOpt->GetCurrentPosition().size() != + this->GetTransform()->GetNumberOfParameters() ) + { + this->SetLastTransformParameters( this->GetInitialTransformParameters() ); + } + else + { + this->SetLastTransformParameters( gradOpt->GetCurrentPosition() ); + } + this->GetTransform()->SetParametersByValue( m_LastTransformParameters ); + m_FinalMetricValue = metric->GetValue( m_LastTransformParameters ); + } + else + { + this->SetLastTransformParameters( this->GetInitialTransformParameters() ); + this->GetTransform()->SetParametersByValue( m_LastTransformParameters ); + m_FinalMetricValue = 0; + } + + + if( this->GetReportProgress() ) + { + std::cout << "GRADIENT END" << std::endl; + } +} + +template +void +OptimizedSpatialObjectToImageRegistrationMethod +::PrintSelf( std::ostream & os, Indent indent ) const +{ + Superclass::PrintSelf(os, indent); + + os << indent << "Initial Transform Parameters = " << + m_InitialTransformParameters << std::endl; + + os << indent << "Initial Transform Fixed Parameters = " << + m_InitialTransformFixedParameters << std::endl; + + os << indent << "Last Transform Parameters = " << + m_LastTransformParameters << std::endl; + + os << indent << "Transform Parameter Scales = " << + m_TransformParametersScales << std::endl; + + os << indent << "Max Iterations = " << m_MaxIterations << std::endl; + + os << indent << "Use Evolutionary Optimization = " << + m_UseEvolutionaryOptimization << std::endl; + + os << indent << "Sampling Ratio = " << m_SamplingRatio << std::endl; + + os << indent << "Target Error = " << m_TargetError << std::endl; + + switch( m_MetricMethodEnum ) + { + default: + case IMAGE_INTENSITY_METRIC: + os << indent << "Metric method = image intensity metric" << std::endl; + break; + } +} + +}; // tube + +}; // itk + +#endif diff --git a/src/Registration/itktubePointBasedSpatialObjectToImageMetric.h b/src/Registration/itktubePointBasedSpatialObjectToImageMetric.h new file mode 100644 index 000000000..4b13fceb5 --- /dev/null +++ b/src/Registration/itktubePointBasedSpatialObjectToImageMetric.h @@ -0,0 +1,239 @@ +/*========================================================================= + +Library: TubeTK + +Copyright Kitware Inc. + +All rights reserved. + +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. + +=========================================================================*/ + +#ifndef __itktubePointBasedSpatialObjectToImageMetric_h +#define __itktubePointBasedSpatialObjectToImageMetric_h + +#include + +#include + +#include +#include +#include + +namespace itk +{ + +namespace tube +{ + +/** \class PointBasedSpatialObjectToImageMetric + * \brief Computes similarity between two objects to be registered + * The metric implemented here corresponds to the following paper: + * \link + * http://www.cs.unc.edu/Research/MIDAG/pubs/papers/MICCAI01-aylwardVReg.pdf + * The metric is based on the fact that vessel centerlines are scaled + * intensity ridges in the image. + * + * \warning ( Derivative ) + */ + +template< unsigned int ObjectDimension, class TFixedImage > +class PointBasedSpatialObjectToImageMetric + : public SpatialObjectToImageMetric< ObjectDimension, TFixedImage > +{ +public: + /** Standard class typedefs. */ + typedef PointBasedSpatialObjectToImageMetric Self; + typedef SpatialObjectToImageMetric< ObjectDimension, TFixedImage > + Superclass; + typedef SmartPointer< Self > Pointer; + typedef SmartPointer< const Self > ConstPointer; + + /** Dimension of the image and tube. */ + itkStaticConstMacro( ImageDimension, unsigned int, + TFixedImage::ImageDimension ); + + typedef TFixedImage FixedImageType; + typedef SpatialObject< ObjectDimension > MovingSpatialObjectType; + + /** Type of the Transform Base class */ + typedef typename Superclass::TransformType TransformType; + typedef typename TransformType::Pointer TransformPointer; + typedef typename TransformType::ParametersType TransformParametersType; + typedef typename TransformType::JacobianType TransformJacobianType; + + typedef typename Superclass::MovingPointType MovingPointType; + typedef typename Superclass::FixedPointType FixedPointType; + + typedef PointBasedSpatialObject< ObjectDimension > + PointBasedSpatialObjectType; + typedef typename PointBasedSpatialObjectType::SpatialObjectPointType + PointBasedSpatialObjectPointType; + + typedef PointBasedSpatialObject< ObjectDimension > + BlobType; + typedef typename BlobType::SpatialObjectPointType + BlobPointType; + typedef typename BlobType::SpatialObjectPointListType + BlobPointListType; + typedef std::vector< double > BlobPointWeightListType; + + typedef TubeSpatialObject< ObjectDimension > TubeType; + typedef typename TubeType::TubePointType TubePointType; + typedef typename TubeType::TubePointListType TubePointListType; + typedef std::vector< double > TubePointWeightListType; + + typedef SurfaceSpatialObject< ObjectDimension > SurfaceType; + typedef typename SurfaceType::SurfacePointType SurfacePointType; + typedef typename SurfaceType::SurfacePointListType SurfacePointListType; + typedef std::vector< double > SurfacePointWeightListType; + + typedef typename Superclass::ParametersType ParametersType; + typedef typename Superclass::MeasureType MeasureType; + typedef typename Superclass::FixedVectorType FixedVectorType; + typedef typename Superclass::MovingVectorType MovingVectorType; + typedef typename Superclass::DerivativeType DerivativeType; + + /** Run-time type information ( and related methods ). */ + itkTypeMacro( PointBasedSpatialObjectToImageMetric, + SpatialObjectToImageMetric ); + + /** Method for creation through the object factory. */ + itkNewMacro( Self ); + + /** Initialize the metric */ + void Initialize( void ) override; + + /** Get the Value for SingleValue Optimizers */ + MeasureType GetValue( const ParametersType & parameters ) const override; + + /** Get the Derivatives of the Match Measure */ + void GetDerivative( const ParametersType & parameters, + DerivativeType & derivative ) const override; + + /** Get the Value And Derivative for SingleValue Optimizers */ + void GetValueAndDerivative( const ParametersType & parameters, + MeasureType & Value, DerivativeType & Derivative ) const override; + + /** Set/Get the portion of points used to compute the match metric. */ + itkSetMacro( SamplingRatio, double ); + itkGetConstMacro( SamplingRatio, double ); + + /** The radius (for tube points) or image voxel size (for all other points) + * mulitplier used to define the scale of the Gaussian kernel + * used to make image measures in the metric. */ + itkSetMacro( Kappa, double ); + itkGetConstMacro( Kappa, double ); + + /** Set/Get the extent of the Gaussian kernel used for image measures. */ + itkSetMacro( Extent, double ); + itkGetConstMacro( Extent, double ); + + /** Set/Get the minimum tube radius used by the metric. */ + itkSetMacro( TubeSamplingRadiusMin, double ); + itkGetConstMacro( TubeSamplingRadiusMin, double ); + /** Set/Get the maximum tube radius used by the metric. */ + itkSetMacro( TubeSamplingRadiusMax, double ); + itkGetConstMacro( TubeSamplingRadiusMax, double ); + /** Set/Get the priority tube radius used in computing weights. */ + itkSetMacro( TubePriorityRadius, double ); + itkGetConstMacro( TubePriorityRadius, double ); + + void ComputeSubsampledPoints( void ); + void ComputeSubsampledPointsWeights( void ); + + //itkSetMacro( SubsampledBlobPoints, BlobPointListType ); + itkGetConstMacro( SubsampledBlobPoints, BlobPointListType ); + //itkSetMacro( SubsampledBlobPointsWeights, BlobPointWeightListType ); + itkGetConstMacro( SubsampledBlobPointsWeights, BlobPointWeightListType ); + + //itkSetMacro( SubsampledTubePoints, TubePointListType ); + itkGetConstMacro( SubsampledTubePoints, TubePointListType ); + //itkSetMacro( SubsampledTubePointsWeights, TubePointWeightListType ); + itkGetConstMacro( SubsampledTubePointsWeights, TubePointWeightListType ); + + //itkSetMacro( SubsampledSurfacePoints, SurfacePointListType ); + itkGetConstMacro( SubsampledSurfacePoints, SurfacePointListType ); + //itkSetMacro( SubsampledSurfacePointsWeights, SurfacePointWeightListType ); + itkGetConstMacro( SubsampledSurfacePointsWeights, SurfacePointWeightListType ); + + TransformPointer GetTransform( void ) const + { return dynamic_cast( this->m_Transform.GetPointer() ); } + + /** Get the number of transform parameters */ + inline unsigned int GetNumberOfParameters( void ) const override + { return this->m_Transform->GetNumberOfParameters(); } + +protected: + + // purposely not implemented + PointBasedSpatialObjectToImageMetric( const Self& ); + void operator=( const Self& ); + + unsigned int GetMaximumNumberOfPoints( void ); + + virtual void ComputeCenterOfRotation( void ); + + bool IsValidMovingPoint( const TubePointType & inputPoint ) const; + bool IsValidMovingPoint( const SurfacePointType & inputPoint ) const; + bool IsValidMovingPoint( const BlobPointType & inputPoint ) const; + bool IsValidFixedPoint( const FixedPointType & fixedPoint ) const; + + typename MovingSpatialObjectType::ChildrenConstListType * + GetPointBasedChildren( const MovingSpatialObjectType * parentSO, + typename MovingSpatialObjectType::ChildrenConstListType * childrenSO=nullptr ) const; + +private: + + PointBasedSpatialObjectToImageMetric( void ); + virtual ~PointBasedSpatialObjectToImageMetric( void ); + + unsigned int m_MaximumNumberOfPoints; + unsigned int m_MaximumNumberOfTubePoints; + unsigned int m_MaximumNumberOfSurfacePoints; + + double m_SamplingRatio; + + double m_Kappa; + double m_Extent; + + double m_TubePriorityRadius; + double m_TubeSamplingRadiusMin; + double m_TubeSamplingRadiusMax; + + MovingPointType m_CenterOfRotation; + + /** Points with no tangets or normals */ + BlobPointListType m_SubsampledBlobPoints; + BlobPointWeightListType m_SubsampledBlobPointsWeights; + + /** Points with one tangent and two normals */ + TubePointListType m_SubsampledTubePoints; + TubePointWeightListType m_SubsampledTubePointsWeights; + + /** Points with one normal */ + SurfacePointListType m_SubsampledSurfacePoints; + SurfacePointWeightListType m_SubsampledSurfacePointsWeights; + +}; // End class PointBasedSpatialObjectToImageMetric + +} // End namespace tube + +} // End namespace itk + +#ifndef ITK_MANUAL_INSTANTIATION +#include "itktubePointBasedSpatialObjectToImageMetric.hxx" +#endif + +#endif // End !defined( __itktubePointBasedSpatialObjectToImageMetric_h ) diff --git a/src/Registration/itktubePointBasedSpatialObjectToImageMetric.hxx b/src/Registration/itktubePointBasedSpatialObjectToImageMetric.hxx new file mode 100644 index 000000000..d63cc46ea --- /dev/null +++ b/src/Registration/itktubePointBasedSpatialObjectToImageMetric.hxx @@ -0,0 +1,800 @@ +/*========================================================================= + +Library: TubeTK + +Copyright Kitware Inc. + +All rights reserved. + +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. + +=========================================================================*/ + +#ifndef __itktubePointBasedSpatialObjectToImageMetric_hxx +#define __itktubePointBasedSpatialObjectToImageMetric_hxx + +#include "itktubePointBasedSpatialObjectToImageMetric.h" +#include "itktubeNJetImageFunction.h" + +namespace itk +{ + +namespace tube +{ + +template< unsigned int ObjectDimension, class TFixedImage > +PointBasedSpatialObjectToImageMetric< ObjectDimension, TFixedImage > +::PointBasedSpatialObjectToImageMetric( void ) +{ + m_SamplingRatio = 0.1; + + m_Kappa = 1.0; + m_Extent = 3.0; + + m_TubePriorityRadius = 0; + m_TubeSamplingRadiusMin = 0; + m_TubeSamplingRadiusMax = 0; + + m_CenterOfRotation.Fill( 0.0 ); + + m_SubsampledBlobPoints.clear(); + m_SubsampledBlobPointsWeights.clear(); + m_SubsampledTubePoints.clear(); + m_SubsampledTubePointsWeights.clear(); + m_SubsampledSurfacePoints.clear(); + m_SubsampledSurfacePointsWeights.clear(); +} + + +template< unsigned int ObjectDimension, class TFixedImage > +PointBasedSpatialObjectToImageMetric< ObjectDimension, TFixedImage > +::~PointBasedSpatialObjectToImageMetric( void ) +{ +} + +template< unsigned int ObjectDimension, class TFixedImage > +void +PointBasedSpatialObjectToImageMetric< ObjectDimension, TFixedImage > +::Initialize( void ) +{ + if( !this->m_MovingSpatialObject || !this->m_FixedImage ) + { + itkExceptionMacro( << "No tube/image net plugged in." ); + } + this->ComputeSubsampledPoints(); + this->ComputeSubsampledPointsWeights(); + this->ComputeCenterOfRotation(); +} + + +template< unsigned int ObjectDimension, class TFixedImage > +unsigned int +PointBasedSpatialObjectToImageMetric< ObjectDimension, TFixedImage > +::GetMaximumNumberOfPoints( void ) +{ + m_MaximumNumberOfPoints = 0; + m_MaximumNumberOfTubePoints = 0; + m_MaximumNumberOfSurfacePoints = 0; + + typename PointBasedSpatialObjectType::ChildrenConstListType * pbsoList = + this->GetPointBasedChildren( m_MovingSpatialObject ); + typename PointBasedSpatialObjectType::ChildrenConstListType::const_iterator + pbsoIter; + for( pbsoIter = pbsoList->begin(); pbsoIter != pbsoList->end(); + ++pbsoIter ) + { + const TubeType* currentTube = + dynamic_cast((*pbsoIter).GetPointer()); + const SurfaceType* currentSurface = + dynamic_cast((*pbsoIter).GetPointer()); + const PointBasedSpatialObjectType* currentBlob = + dynamic_cast((*pbsoIter).GetPointer()); + if( currentTube != nullptr ) + { + const typename TubeType::TubePointListType & currentPoints = + currentTube->GetPoints(); + auto pIter = currentPoints.begin(); + while( pIter != currentPoints.end() ) + { + if( this->IsValidMovingPoint( *pIter ) ) + { + ++m_MaximumNumberOfTubePoints; + } + ++pIter; + } + } + else if( currentSurface != NULL ) + { + const typename SurfaceType::SurfacePointListType & currentPoints = + currentSurface->GetPoints(); + auto pIter = currentPoints.begin(); + while( pIter != currentPoints.end() ) + { + if( this->IsValidMovingPoint( *pIter ) ) + { + ++m_MaximumNumberOfSurfacePoints; + } + ++pIter; + } + } + else + { + const typename BlobType::SpatialObjectPointListType & + currentPoints = currentBlob->GetPoints(); + auto pIter = currentPoints.begin(); + while( pIter != currentPoints.end() ) + { + if( this->IsValidMovingPoint( *pIter ) ) + { + ++m_MaximumNumberOfPoints; + } + ++pIter; + } + } + } + delete pbsoList; + + return m_MaximumNumberOfPoints + + m_MaximumNumberOfTubePoints + + m_MaximumNumberOfSurfacePoints; +} + + +template< unsigned int ObjectDimension, class TFixedImage > +void +PointBasedSpatialObjectToImageMetric< ObjectDimension, TFixedImage > +::ComputeCenterOfRotation( void ) +{ + unsigned int pointCount = 0; + + typename PointBasedSpatialObjectType::ChildrenConstListType * pbsoList = + this->GetPointBasedChildren( m_MovingSpatialObject ); + auto pbsoIter = pbsoList->begin(); + while( pbsoIter != pbsoList->end() ) + { + const TubeType* currentTube = + dynamic_cast((*pbsoIter).GetPointer()); + const SurfaceType* currentSurface = + dynamic_cast((*pbsoIter).GetPointer()); + const PointBasedSpatialObjectType* currentBlob = + dynamic_cast((*pbsoIter).GetPointer()); + if( currentTube != nullptr ) + { + const typename TubeType::TubePointListType & currentPoints = + currentTube->GetPoints(); + auto pIter = currentPoints.begin(); + while( pIter != currentPoints.end() ) + { + if( this->IsValidMovingPoint( *pIter ) ) + { + for( unsigned int ii = 0; ii < ObjectDimension; ++ii ) + { + this->m_CenterOfRotation[ii] += + pIter->GetPositionInWorldSpace()[ii]; + } + ++pointCount; + } + ++pIter; + } + } + else if( currentSurface != nullptr ) + { + const typename SurfaceType::SurfacePointListType & currentPoints = + currentSurface->GetPoints(); + auto pIter = currentPoints.begin(); + while( pIter != currentPoints.end() ) + { + if( this->IsValidMovingPoint( *pIter ) ) + { + for( unsigned int ii = 0; ii < ObjectDimension; ++ii ) + { + this->m_CenterOfRotation[ii] += + (pIter->GetPositionInWorldSpace())[ii]; + } + ++pointCount; + } + ++pIter; + } + } + else + { + const typename BlobType::SpatialObjectPointListType & + currentPoints = currentBlob->GetPoints(); + auto pIter = currentPoints.begin(); + while( pIter != currentPoints.end() ) + { + if( this->IsValidMovingPoint( *pIter ) ) + { + for( unsigned int ii = 0; ii < ObjectDimension; ++ii ) + { + this->m_CenterOfRotation[ii] += + pIter->GetPositionInWorldSpace()[ii]; + } + ++pointCount; + } + ++pIter; + } + } + ++pbsoIter; + } + delete pbsoList; + + for( unsigned int ii = 0; ii < ObjectDimension; ++ii ) + { + this->m_CenterOfRotation[ii] /= pointCount; + } +} + + +template< unsigned int ObjectDimension, class TFixedImage > +void +PointBasedSpatialObjectToImageMetric< ObjectDimension, TFixedImage > +::ComputeSubsampledPoints( void ) +{ + unsigned int maxPointCount = this->GetMaximumNumberOfPoints(); + + unsigned int targetPointCount = maxPointCount * m_SamplingRatio; + + m_SubsampledBlobPoints.clear(); + m_SubsampledBlobPointsWeights.clear(); + m_SubsampledTubePoints.clear(); + m_SubsampledTubePointsWeights.clear(); + m_SubsampledSurfacePoints.clear(); + m_SubsampledSurfacePointsWeights.clear(); + + unsigned int pointCount = 0; + typename PointBasedSpatialObjectType::ChildrenConstListType * pbsoList = + this->GetPointBasedChildren( m_MovingSpatialObject ); + std::string oName = m_MovingSpatialObject->GetTypeName(); + if (oName.find("Tube") != std::string::npos || + oName.find("Surface") != std::string::npos || + oName.find("Blob") != std::string::npos || + oName.find("Point") != std::string::npos) + { + pbsoList->push_front( m_MovingSpatialObject.GetPointer() ); + } + auto pbsoIter = pbsoList->begin(); + while( pbsoIter != pbsoList->end() ) + { + std::string cName = (*pbsoIter)->GetTypeName(); + const TubeType* currentTube = + dynamic_cast((*pbsoIter).GetPointer()); + const SurfaceType* currentSurface = + dynamic_cast((*pbsoIter).GetPointer()); + const PointBasedSpatialObjectType* currentBlob = + dynamic_cast((*pbsoIter).GetPointer()); + if( currentTube != nullptr ) + { + const TubePointListType & currentPoints = currentTube->GetPoints(); + TubeType * mutableTube = const_cast< TubeType * >( currentTube ); + mutableTube->ComputeTangentsAndNormals(); + double stepCount = currentPoints.size() * m_SamplingRatio; + double endCount = stepCount/2.0; + if (stepCount > currentPoints.size()/2) + { + stepCount = currentPoints.size()/2; + endCount = stepCount/2.0; + } + else if (stepCount < 1) + { + stepCount = 1; + endCount = 1; + } + unsigned int count = 0; + auto pointIter = currentPoints.begin(); + for (unsigned int count=0; pointIter!=currentPoints.end() + && count(count/stepCount) * stepCount + stepCount; + while( count < endCount && pointIter != currentPoints.end() ) + { + ++pointIter; + ++count; + } + } + } + else if( currentSurface != nullptr ) + { + const SurfacePointListType & currentPoints = currentSurface->GetPoints(); + double stepCount = currentPoints.size() * m_SamplingRatio; + double endCount = stepCount/2.0; + if (stepCount > currentPoints.size()/2) + { + stepCount = currentPoints.size()/2; + endCount = stepCount/2.0; + } + else if (stepCount < 1) + { + stepCount = 1; + endCount = 1; + } + unsigned int count = 0; + auto pointIter = currentPoints.begin(); + for (unsigned int count=0; pointIter!=currentPoints.end() + && count(count/stepCount) * stepCount + stepCount; + while( count < endCount && pointIter != currentPoints.end() ) + { + ++pointIter; + ++count; + } + } + } + else if( currentBlob != nullptr ) + { + const BlobPointListType & currentPoints = currentBlob->GetPoints(); + double stepCount = currentPoints.size() * m_SamplingRatio; + double endCount = stepCount/2.0; + if (stepCount > currentPoints.size()/2) + { + stepCount = currentPoints.size()/2; + endCount = stepCount/2.0; + } + else if (stepCount < 1) + { + stepCount = 1; + endCount = 1; + } + unsigned int count = 0; + auto pointIter = currentPoints.begin(); + for (unsigned int count=0; pointIter!=currentPoints.end() + && count(count/stepCount) * stepCount + stepCount; + while( count < endCount && pointIter != currentPoints.end() ) + { + ++pointIter; + ++count; + } + } + } + ++pbsoIter; + } + delete pbsoList; +} + +template< unsigned int ObjectDimension, class TFixedImage > +void +PointBasedSpatialObjectToImageMetric< ObjectDimension, TFixedImage > +::ComputeSubsampledPointsWeights( void ) +{ + m_SubsampledTubePointsWeights.clear(); + auto tubePointIter = m_SubsampledTubePoints.begin(); + while( tubePointIter != m_SubsampledTubePoints.end() ) + { + double radius = tubePointIter->GetRadiusInWorldSpace(); + if( m_TubePriorityRadius != 0 && + m_TubePriorityRadius > m_TubeSamplingRadiusMin) + { + if( radius > m_TubePriorityRadius ) + { + m_SubsampledTubePointsWeights.push_back(1); + } + else + { + double weight = ( radius - m_TubeSamplingRadiusMin ) / + (m_TubePriorityRadius - m_TubeSamplingRadiusMin); + m_SubsampledTubePointsWeights.push_back( weight ); + } + } + else + { + if( m_TubeSamplingRadiusMin < m_TubeSamplingRadiusMax ) + { + double weight = ( radius - m_TubeSamplingRadiusMin ) / + (m_TubeSamplingRadiusMax - m_TubeSamplingRadiusMin); + m_SubsampledTubePointsWeights.push_back( weight ); + } + else + { + m_SubsampledTubePointsWeights.push_back( 1 ); + } + } + ++tubePointIter; + } + m_SubsampledSurfacePointsWeights.clear(); + auto surfacePointIter = m_SubsampledSurfacePoints.begin(); + while( surfacePointIter != m_SubsampledSurfacePoints.end() ) + { + m_SubsampledSurfacePointsWeights.push_back( 1 ); + ++surfacePointIter; + } + m_SubsampledBlobPointsWeights.clear(); + auto pointIter = m_SubsampledBlobPoints.begin(); + while( pointIter != m_SubsampledBlobPoints.end() ) + { + m_SubsampledBlobPointsWeights.push_back( 1 ); + ++pointIter; + } +} + +template< unsigned int ObjectDimension, class TFixedImage > +typename +PointBasedSpatialObjectToImageMetric< ObjectDimension, TFixedImage >::MovingSpatialObjectType::ChildrenConstListType* +PointBasedSpatialObjectToImageMetric< ObjectDimension, TFixedImage > +::GetPointBasedChildren( const MovingSpatialObjectType * parentSO, + typename MovingSpatialObjectType::ChildrenConstListType * childrenSO ) const +{ + if( parentSO == nullptr ) + { + return childrenSO; + } + if( childrenSO == nullptr ) + { + childrenSO = new MovingSpatialObjectType::ChildrenConstListType; + } + + auto tmpChildren = parentSO->GetConstChildren(); + auto it = tmpChildren->begin(); + while (it != tmpChildren->end()) + { + std::string oName = (*it)->GetTypeName(); + if (oName.find("Tube") != std::string::npos || + oName.find("Surface") != std::string::npos || + oName.find("Blob") != std::string::npos || + oName.find("Point") != std::string::npos) + { + childrenSO->push_back(*it); + } + it++; + } + + it = tmpChildren->begin(); + while (it != tmpChildren->end()) + { + this->GetPointBasedChildren( *it, childrenSO ); + it++; + } + + delete tmpChildren; + + return childrenSO; +} + +template< unsigned int ObjectDimension, class TFixedImage > +typename PointBasedSpatialObjectToImageMetric< ObjectDimension, TFixedImage >::MeasureType +PointBasedSpatialObjectToImageMetric< ObjectDimension, TFixedImage > +::GetValue( const ParametersType & parameters ) const +{ + typedef vnl_matrix_fixed VnlMatrixType; + typedef vnl_vector_fixed VnlVectorType; + + itkDebugMacro( << "**** Get Value ****" ); + itkDebugMacro( << "Parameters = " << parameters ); + double value = 0; + + double weightSum = 0; + + // Create a copy of the transform to keep true const correctness ( + // thread-safe ) + // Set the parameters on the copy and uses the copy. + LightObject::Pointer anotherTransform = this->m_Transform->CreateAnother(); + TransformType * transformCopy = + static_cast< TransformType * >( anotherTransform.GetPointer() ); + transformCopy->SetFixedParameters( this->m_Transform->GetFixedParameters() ); + transformCopy->SetParameters( parameters ); + + NJetImageFunction< FixedImageType >::Pointer imFunc = + NJetImageFunction< FixedImageType >::New(); + imFunc->SetInputImage( m_FixedImage ); + + VnlVectorType n1T, n2T; + + typename TubePointWeightListType::const_iterator pointWeightIter + = m_SubsampledTubePointsWeights.begin(); + typename TubePointListType::const_iterator pointIter = + m_SubsampledTubePoints.begin(); + while( pointIter != m_SubsampledTubePoints.end() ) + { + MovingPointType movingPoint = pointIter->GetPositionInWorldSpace(); + FixedPointType fixedPoint = transformCopy->TransformPoint( movingPoint ); + if( this->IsValidFixedPoint( fixedPoint ) ) + { + double radius = pointIter->GetRadiusInWorldSpace(); + radius = radius * m_Kappa; + MovingPointType radiusPoint; + radiusPoint.Fill(radius); + FixedPointType fixedRadiusPoint = + transformCopy->TransformPoint( radiusPoint ); + double fixedScale = radiusPoint[0]; + for( unsigned int i=1; iGetNormal1InWorldSpace(); + n1 = transformCopy->TransformCovariantVector( n1 ); + Vector n1v; + n1v.SetVnlVector(n1.GetVnlVector()); + n1T = n1.GetVnlVector(); + if( ObjectDimension > 2 ) + { + typename TubeType::CovariantVectorType n2 = pointIter->GetNormal2InWorldSpace(); + n2 = transformCopy->TransformCovariantVector( n2 ); + Vector n2v; + n2v.SetVnlVector(n2.GetVnlVector()); + n2T = n2.GetVnlVector(); + value += *pointWeightIter * imFunc->Evaluate( fixedPoint, n1v, n2v, fixedScale ); + } + else + { + value += *pointWeightIter * imFunc->Evaluate( fixedPoint, n1v, fixedScale ); + } + weightSum += *pointWeightIter; + } + ++pointIter; + ++pointWeightIter; + } + + if( weightSum > 0 ) + { + value /= weightSum; + } + + std::cout << "GetValue : " << parameters << " = " << value << std::endl; + + return -value; +} + +template< unsigned int ObjectDimension, class TFixedImage > +void +PointBasedSpatialObjectToImageMetric< ObjectDimension, TFixedImage > +::GetDerivative( const ParametersType & parameters, DerivativeType & derivative ) const +{ + MeasureType value; + this->GetValueAndDerivative(parameters, value, derivative ); +} + +template< unsigned int ObjectDimension, class TFixedImage > +void +PointBasedSpatialObjectToImageMetric< ObjectDimension, TFixedImage > +::GetValueAndDerivative( const ParametersType & parameters, MeasureType & value, DerivativeType & derivative ) const +{ + typedef vnl_matrix_fixed VnlMatrixType; + typedef vnl_vector_fixed VnlVectorType; + + itkDebugMacro( << "**** Get Derivative ****" ); + itkDebugMacro( << "Parameters = " << parameters ); + + value = 0; + + double weightSum = 0; + + // Create a copy of the transform to keep true const correctness ( + // thread-safe ) + // Set the parameters on the copy and uses the copy. + LightObject::Pointer anotherTransform = this->m_Transform->CreateAnother(); + TransformType * transformCopy = + static_cast< TransformType * >( anotherTransform.GetPointer() ); + transformCopy->SetFixedParameters( this->m_Transform->GetFixedParameters() ); + transformCopy->SetParameters( parameters ); + + NJetImageFunction< FixedImageType >::Pointer imFunc = + NJetImageFunction< FixedImageType >::New(); + imFunc->SetInputImage( m_FixedImage ); + + VnlMatrixType biasV; + VnlVectorType n1T, n2T; + VnlMatrixType tM; + + std::list< FixedPointType > fixedPoints; + std::list< FixedVectorType > fixedPointsDerivs; + + typename TubePointWeightListType::const_iterator pointWeightIter + = m_SubsampledTubePointsWeights.begin(); + typename TubePointListType::const_iterator pointIter = + m_SubsampledTubePoints.begin(); + while( pointIter != m_SubsampledTubePoints.end() ) + { + MovingPointType movingPoint = pointIter->GetPositionInWorldSpace(); + FixedPointType fixedPoint = transformCopy->TransformPoint( movingPoint ); + if( this->IsValidFixedPoint( fixedPoint ) ) + { + fixedPoints.push_back( fixedPoint ); + + FixedVectorType fixedDeriv; + + double radius = pointIter->GetRadiusInWorldSpace(); + radius = radius * m_Kappa; + MovingPointType radiusPoint; + radiusPoint.Fill(radius); + FixedPointType fixedRadiusPoint = + transformCopy->TransformPoint( radiusPoint ); + double fixedScale = radiusPoint[0]; + for( unsigned int i=1; iGetNormal1InWorldSpace(); + n1 = transformCopy->TransformCovariantVector( n1 ); + Vector n1v; + n1v.SetVnlVector(n1.GetVnlVector()); + n1T = n1.GetVnlVector(); + tM = outer_product( n1T, n1T ); + if( ObjectDimension > 2 ) + { + typename TubeType::CovariantVectorType n2 = pointIter->GetNormal2InWorldSpace(); + n2 = transformCopy->TransformCovariantVector( n2 ); + Vector n2v; + n2v.SetVnlVector(n2.GetVnlVector()); + n2T = n2.GetVnlVector(); + tM = tM + outer_product( n2T, n2T ); + Vector tmpDeriv; + imFunc->Derivative( fixedPoint, n1v, n2v, fixedScale, tmpDeriv ); + fixedDeriv.fill(0); + for( unsigned int ii = 0; ii < ImageDimension; ++ii ) + { + fixedDeriv[ii] += tmpDeriv[0] * n1T[ii]; + fixedDeriv[ii] += tmpDeriv[1] * n2T[ii]; + } + } + else + { + Vector tmpDeriv; + imFunc->Derivative( fixedPoint, n1v, fixedScale, tmpDeriv ); + fixedDeriv.fill(0); + for( unsigned int ii = 0; ii < ImageDimension; ++ii ) + { + fixedDeriv[ii] += tmpDeriv[0] * n1T[ii]; + } + } + fixedPointsDerivs.push_back( fixedDeriv ); + + tM = *pointWeightIter * tM; + biasV += tM; + + value += *pointWeightIter * imFunc->GetMostRecentIntensity(); + + weightSum += *pointWeightIter; + } + ++pointIter; + ++pointWeightIter; + } + + if( weightSum > 0 ) + { + value = - value / weightSum; + + VnlMatrixType biasVI = vnl_matrix_inverse< double >( biasV ).inverse(); + + derivative.fill(0); + + auto fixedPointsIter = fixedPoints.begin(); + auto fixedPointsDerivsIter = fixedPointsDerivs.begin(); + while( fixedPointsIter != fixedPoints.end() ) + { + FixedPointType fixedPoint = *fixedPointsIter; + + VnlVectorType dXT = (*fixedPointsDerivsIter); + + dXT = dXT * biasVI; + + typename TransformType::JacobianType jacobian; + m_Transform->ComputeJacobianWithRespectToParameters( fixedPoint, + jacobian ); + + for( unsigned int p = 0; pGetNumberOfParameters(); ++p) + { + for( unsigned int d=0; d +bool +PointBasedSpatialObjectToImageMetric< ObjectDimension, TFixedImage > +::IsValidMovingPoint( const TubePointType & pnt ) const +{ + if( m_TubeSamplingRadiusMin != 0 || m_TubeSamplingRadiusMax != 0 ) + { + double radius = pnt.GetRadiusInWorldSpace(); + if( radius < m_TubeSamplingRadiusMin || radius > m_TubeSamplingRadiusMax ) + { + return false; + } + } + if( m_MovingSpatialObjectMaskObject.IsNotNull() && + m_UseMovingSpatialObjectMaskObject ) + { + if( !m_MovingSpatialObjectMaskObject->IsInsideInWorldSpace( + pnt.GetPositionInWorldSpace() ) ) + { + return false; + } + } + return true; +} + +template< unsigned int ObjectDimension, class TFixedImage > +bool +PointBasedSpatialObjectToImageMetric< ObjectDimension, TFixedImage > +::IsValidMovingPoint( const SurfacePointType & pnt ) const +{ + if( m_MovingSpatialObjectMaskObject.IsNotNull() && + m_UseMovingSpatialObjectMaskObject ) + { + if( !m_MovingSpatialObjectMaskObject->IsInsideInWorldSpace( + pnt.GetPositionInWorldSpace() ) ) + { + return false; + } + } + return true; +} + +template< unsigned int ObjectDimension, class TFixedImage > +bool +PointBasedSpatialObjectToImageMetric< ObjectDimension, TFixedImage > +::IsValidMovingPoint( const BlobPointType & pnt ) const +{ + if( m_MovingSpatialObjectMaskObject.IsNotNull() && + m_UseMovingSpatialObjectMaskObject ) + { + if( !m_MovingSpatialObjectMaskObject->IsInsideInWorldSpace( + pnt.GetPositionInWorldSpace() ) ) + { + return false; + } + } + return true; +} + +template< unsigned int ObjectDimension, class TFixedImage > +bool +PointBasedSpatialObjectToImageMetric< ObjectDimension, TFixedImage > +::IsValidFixedPoint( const FixedPointType & pnt ) const +{ + if( m_FixedImageMaskObject.IsNotNull() && m_UseFixedImageMaskObject ) + { + if( !m_FixedImageMaskObject->IsInsideInWorldSpace( pnt ) ) + { + return false; + } + } + return true; +} + +} // End namespace tube + +} // End namespace itk + +#endif // End !defined( __itktubePointBasedSpatialObjectToImageMetric_hxx ) diff --git a/src/Registration/itktubePointBasedSpatialObjectTransformFilter.h b/src/Registration/itktubePointBasedSpatialObjectTransformFilter.h new file mode 100644 index 000000000..04979461a --- /dev/null +++ b/src/Registration/itktubePointBasedSpatialObjectTransformFilter.h @@ -0,0 +1,152 @@ +/*========================================================================= + +Library: TubeTK + +Copyright Kitware Inc. + +All rights reserved. + +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. + +=========================================================================*/ + +#ifndef __itktubePointBasedSpatialObjectTransformFilter_h +#define __itktubePointBasedSpatialObjectTransformFilter_h + +#include "itktubeSpatialObjectFilter.h" + +#include + +#include +#include + +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace itk +{ + +namespace tube +{ + +/** + * This class applies a transformation to tubes in a group and returns + * a the group with transformed tubes. + * + * \warning Transform Class MUST have a proper implementation of + * ::TransformCovariantVector( void ) + * + * \warning The scale is applied before computing the transformation. + * + * The resulting tube could be cropped and/or a narrow band could be + * defined. + */ +template< class TTransformType, unsigned int TDimension > +class PointBasedSpatialObjectTransformFilter : + public SpatialObjectFilter< TDimension > +{ +public: + + typedef TTransformType TransformType; + + typedef SpatialObject< TDimension > SpatialObjectType; + + /** Standard class typedefs. */ + typedef PointBasedSpatialObjectTransformFilter< TTransformType, TDimension > + Self; + + typedef SpatialObjectFilter< TDimension > Superclass; + + typedef SmartPointer< Self > Pointer; + typedef SmartPointer< const Self > ConstPointer; + + typedef PointBasedSpatialObject< TDimension > PointBasedType; + typedef TubeSpatialObject< TDimension > TubeType; + typedef SurfaceSpatialObject< TDimension > SurfaceType; + typedef LineSpatialObject< TDimension > LineType; + typedef DTITubeSpatialObject< TDimension > DTITubeType; + typedef ContourSpatialObject< TDimension > ContourType; + + typedef typename SpatialObject< TDimension >::TransformType + SpatialObjectTransformType; + + /** Method for creation through the object factory. */ + itkNewMacro( Self ); + + /** Run-time type information ( and related methods ). */ + itkTypeMacro( PointBasedSpatialObjectTransformFilter, SpatialObjectFilter ); + + /** Set the Transformation */ + itkSetConstObjectMacro( Transform, TransformType ); + + /** Set the Object to Parent transform for the output tubes */ + itkSetConstObjectMacro( OutputObjectToParentTransform, SpatialObjectTransformType ); + +protected: + + PointBasedSpatialObjectTransformFilter( void ); + virtual ~PointBasedSpatialObjectTransformFilter( void ) {} + + void PrintSelf( std::ostream& os, Indent indent ) const override; + + /** Apply the transformation to the tube */ + void GenerateData( void ) override; + + +private: + + //purposely not implemented + PointBasedSpatialObjectTransformFilter( const Self& ); + void operator=( const Self& ); + + void UpdateLevel( const SpatialObject< TDimension > * inputSO, + SpatialObject< TDimension > * parentSO ); + + bool Transform( const SpatialObject< TDimension > * inputSO, + SpatialObject< TDimension > * outputSO ); + + void TransformPointBased( const PointBasedSpatialObject< TDimension > * inputSO, + PointBasedSpatialObject< TDimension > * outputSO ); + + void TransformTube( const TubeSpatialObject< TDimension > * inputSO, + TubeSpatialObject< TDimension > * outputSO ); + + void TransformSurface( const SurfaceSpatialObject< TDimension > * inputSO, + SurfaceSpatialObject< TDimension > * outputSO ); + + typename TransformType::ConstPointer m_Transform; + + typename SpatialObjectTransformType::ConstPointer m_OutputObjectToParentTransform; + +}; // End class PointBasedSpatialObjectTransformFilter + +} // End namespace tube + +} // End namespace itk + +#ifndef ITK_MANUAL_INSTANTIATION +#include "itktubePointBasedSpatialObjectTransformFilter.hxx" +#endif + +#endif // End !defined( __itktubePointBasedSpatialObjectTransformFilter_h ) diff --git a/src/Registration/itktubePointBasedSpatialObjectTransformFilter.hxx b/src/Registration/itktubePointBasedSpatialObjectTransformFilter.hxx new file mode 100644 index 000000000..6b0ce66ef --- /dev/null +++ b/src/Registration/itktubePointBasedSpatialObjectTransformFilter.hxx @@ -0,0 +1,356 @@ +/*========================================================================= + +Library: TubeTK + +Copyright Kitware Inc. + +All rights reserved. + +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. + +=========================================================================*/ + +#ifndef __itktubePointBasedSpatialObjectTransformFilter_hxx +#define __itktubePointBasedSpatialObjectTransformFilter_hxx + +#include "itktubePointBasedSpatialObjectTransformFilter.h" + +#include + +namespace itk +{ + +namespace tube +{ + +template< class TTransformType, unsigned int TDimension > +PointBasedSpatialObjectTransformFilter< TTransformType, TDimension > +::PointBasedSpatialObjectTransformFilter( void ) +{ + m_OutputObjectToParentTransform = 0; + m_Transform = 0; + + SpatialObjectFactoryBase::RegisterDefaultSpatialObjects(); + SpatialObjectFactory< SpatialObject< TDimension > >:: + RegisterSpatialObject(); + SpatialObjectFactory< TubeType >::RegisterSpatialObject(); + SpatialObjectFactory< SurfaceType >::RegisterSpatialObject(); + SpatialObjectFactory< LineType >::RegisterSpatialObject(); + SpatialObjectFactory< DTITubeType >::RegisterSpatialObject(); + SpatialObjectFactory< ContourType >::RegisterSpatialObject(); +} + +/** + * Apply the transformation to the tube + */ +template< class TTransformType, unsigned int TDimension > +void +PointBasedSpatialObjectTransformFilter< TTransformType, TDimension > +::GenerateData( void ) +{ + SpatialObject::ConstPointer inputSO = this->GetInput(); + SpatialObject::Pointer outputSO = this->GetOutput(); + + Transform(inputSO, outputSO); + + typedef typename SpatialObject< TDimension >::ChildrenConstListType + ChildrenConstListType; + ChildrenConstListType * children = this->GetInput()->GetConstChildren(); + typename ChildrenConstListType::iterator it = children->begin(); + while( it != children->end() ) + { + SpatialObject::Pointer tmpSO = (*it)->Clone(); + this->UpdateLevel( *it, outputSO ); + ++it; + } + delete children; + + this->GraftOutput( outputSO ); +} + +/** + * Apply the transformation to the tube + */ +template< class TTransformType, unsigned int TDimension > +void +PointBasedSpatialObjectTransformFilter< TTransformType, TDimension > +::UpdateLevel( const SpatialObject< TDimension > * inputSO, + SpatialObject< TDimension > * parentSO ) +{ + SpatialObject::Pointer outputSO = inputSO->Clone(); + + Transform(inputSO, outputSO); + + parentSO->AddChild( outputSO ); + + typedef typename SpatialObject< TDimension >::ChildrenListType + ChildrenListType; + ChildrenListType * children = inputSO->GetChildren(); + typename ChildrenListType::const_iterator it = children->begin(); + while( it != children->end() ) + { + this->UpdateLevel( *it, outputSO ); + ++it; + } + delete children; +} + +template< class TTransformType, unsigned int TDimension > +bool +PointBasedSpatialObjectTransformFilter< TTransformType, TDimension > +::Transform( const SpatialObject< TDimension > * inputSO, + SpatialObject< TDimension > * outputSO ) +{ + + const TubeType * inputSOAsTube = + dynamic_cast< const TubeSpatialObject * >(inputSO); + if( inputSOAsTube != nullptr ) + { + TubeSpatialObject< TDimension > * outputSOAsTube = + dynamic_cast*>(outputSO); + this->TransformTube( inputSOAsTube, outputSOAsTube ); + return true; + } + + const SurfaceType * inputSOAsSurface = + dynamic_cast< const SurfaceSpatialObject * >(inputSO); + if( inputSOAsSurface != nullptr ) + { + SurfaceSpatialObject< TDimension > * outputSOAsSurface = + dynamic_cast*>(outputSO); + this->TransformSurface( inputSOAsSurface, outputSOAsSurface ); + return true; + } + + const PointBasedType * inputSOAsPointBased = + dynamic_cast< const PointBasedSpatialObject * >(inputSO); + if( inputSOAsPointBased != nullptr ) + { + PointBasedSpatialObject< TDimension > * outputSOAsPointBased = + dynamic_cast*>(outputSO); + this->TransformPointBased( inputSOAsPointBased, outputSOAsPointBased ); + return true; + } + + return false; +} + +template< class TTransformType, unsigned int TDimension > +void +PointBasedSpatialObjectTransformFilter< TTransformType, TDimension > +::TransformPointBased( const PointBasedSpatialObject< TDimension > * inputSO, + PointBasedSpatialObject< TDimension > * outputSO ) +{ + Point objectPoint; + Point transformedObjectPoint; + + outputSO->CopyInformation( inputSO ); + outputSO->Clear(); + + if( m_OutputObjectToParentTransform.IsNotNull() ) + { + typename SpatialObjectTransformType::Pointer tfm = + SpatialObjectTransformType::New(); + tfm->SetIdentity(); + tfm->SetMatrix( m_OutputObjectToParentTransform->GetMatrix() ); + tfm->SetOffset( m_OutputObjectToParentTransform->GetOffset() ); + outputSO->SetObjectToParentTransform( tfm ); + } + + typedef typename PointBasedType::SpatialObjectPointListType SpatialObjectPointListType; + SpatialObjectPointListType pointBasedPointList = inputSO->GetPoints(); + typename SpatialObjectPointListType::const_iterator pointBasedPointIterator = + pointBasedPointList.begin(); + + while( pointBasedPointIterator != pointBasedPointList.end() ) + { + objectPoint = ( *pointBasedPointIterator ).GetPositionInObjectSpace(); + + transformedObjectPoint = m_Transform->TransformPoint( objectPoint ); + + SpatialObjectPoint pnt; + + pnt.SetId( pointBasedPointIterator->GetId() ); + pnt.SetColor( pointBasedPointIterator->GetColor() ); + + pnt.SetPositionInObjectSpace( transformedObjectPoint ); + + outputSO->AddPoint( pnt ); + + ++pointBasedPointIterator; + } +} + +template< class TTransformType, unsigned int TDimension > +void +PointBasedSpatialObjectTransformFilter< TTransformType, TDimension > +::TransformTube( const TubeSpatialObject< TDimension > * inputSO, + TubeSpatialObject< TDimension > * outputSO ) +{ + Point objectPoint; + Point transformedObjectPoint; + + outputSO->Clear(); + outputSO->CopyInformation( inputSO ); + + if( m_OutputObjectToParentTransform.IsNotNull() ) + { + typename SpatialObjectTransformType::Pointer tfm = + SpatialObjectTransformType::New(); + tfm->SetIdentity(); + tfm->SetMatrix( m_OutputObjectToParentTransform->GetMatrix() ); + tfm->SetOffset( m_OutputObjectToParentTransform->GetOffset() ); + outputSO->SetObjectToParentTransform( tfm ); + } + + typedef typename TubeType::TubePointListType TubePointListType; + TubePointListType tubePointList = inputSO->GetPoints(); + typename TubePointListType::const_iterator tubePointIterator = + tubePointList.begin(); + + while( tubePointIterator != tubePointList.end() ) + { + objectPoint = ( *tubePointIterator ).GetPositionInObjectSpace(); + + transformedObjectPoint = m_Transform->TransformPoint( objectPoint ); + + TubeSpatialObjectPoint pnt; + + pnt.SetId( tubePointIterator->GetId() ); + pnt.SetColor( tubePointIterator->GetColor() ); + + pnt.SetSpatialObject(outputSO); + + pnt.SetPositionInObjectSpace( transformedObjectPoint ); + + // get both normals + typename TubeType::CovariantVectorType n1 = tubePointIterator + ->GetNormal1InObjectSpace(); + typename TubeType::CovariantVectorType n2 = tubePointIterator + ->GetNormal2InObjectSpace(); + + // only try transformation of normals if both are non-zero + if( !n1.GetVnlVector().is_zero() && !n2.GetVnlVector().is_zero() ) + { + n1 = m_Transform->TransformCovariantVector( n1, objectPoint ); + n2 = m_Transform->TransformCovariantVector( n2, objectPoint ); + n1.Normalize(); + n2.Normalize(); + pnt.SetNormal1InObjectSpace( n1 ); + pnt.SetNormal2InObjectSpace( n2 ); + } + + typename TubeType::VectorType tang = tubePointIterator-> + GetTangentInObjectSpace(); + if( !tang.GetVnlVector().is_zero() ) + { + tang = m_Transform->TransformVector( tang, objectPoint ); + tang.Normalize(); + pnt.SetTangentInObjectSpace( tang ); + } + + typename TubeType::VectorType radi; + for( unsigned int i=0; iGetRadiusInObjectSpace(); + } + radi = m_Transform->TransformVector( radi, objectPoint ); + pnt.SetRadiusInObjectSpace( radi[0] ); + + pnt.SetMedialness( ( *tubePointIterator ).GetMedialness() ); + pnt.SetRidgeness( ( *tubePointIterator ).GetRidgeness() ); + pnt.SetBranchness( ( *tubePointIterator ).GetBranchness() ); + + outputSO->AddPoint( pnt ); + + ++tubePointIterator; + } +} + + +template< class TTransformType, unsigned int TDimension > +void +PointBasedSpatialObjectTransformFilter< TTransformType, TDimension > +::TransformSurface( const SurfaceSpatialObject< TDimension > * inputSO, + SurfaceSpatialObject< TDimension > * outputSO ) +{ + // We make the copy and sub-sample if it is a tube. + Point objectPoint; + Point transformedObjectPoint; + + outputSO->CopyInformation( inputSO ); + outputSO->Clear(); + + if( m_OutputObjectToParentTransform.IsNotNull() ) + { + typename SpatialObjectTransformType::Pointer tfm = + SpatialObjectTransformType::New(); + tfm->SetIdentity(); + tfm->SetMatrix( m_OutputObjectToParentTransform->GetMatrix() ); + tfm->SetOffset( m_OutputObjectToParentTransform->GetOffset() ); + outputSO->SetObjectToParentTransform( tfm ); + } + + typedef typename SurfaceType::SurfacePointListType SurfacePointListType; + SurfacePointListType surfacePointList = inputSO->GetPoints(); + typename SurfacePointListType::const_iterator surfacePointIterator = + surfacePointList.begin(); + + while( surfacePointIterator != surfacePointList.end() ) + { + objectPoint = ( *surfacePointIterator ).GetPositionInObjectSpace(); + + transformedObjectPoint = m_Transform->TransformPoint( objectPoint ); + + SurfaceSpatialObjectPoint pnt; + + pnt.SetId( surfacePointIterator->GetId() ); + pnt.SetColor( surfacePointIterator->GetColor() ); + + pnt.SetPositionInObjectSpace( transformedObjectPoint ); + + // get normals + typename SurfaceType::CovariantVectorType n1 = surfacePointIterator + ->GetNormalInObjectSpace(); + + // only try transformation of normals if both are non-zero + if( !n1.GetVnlVector().is_zero() ) + { + n1 = m_Transform->TransformCovariantVector( n1, objectPoint ); + n1.Normalize(); + pnt.SetNormalInObjectSpace( n1 ); + } + + outputSO->AddPoint( pnt ); + + ++surfacePointIterator; + } +} + +template< class TTransformType, unsigned int TDimension > +void +PointBasedSpatialObjectTransformFilter< TTransformType, TDimension > +::PrintSelf( std::ostream& os, Indent indent ) const +{ + Superclass::PrintSelf( os, indent ); + + os << indent << "Transformation: " << m_Transform << std::endl; + os << indent << "OutputObjectToParent Transform: " << + m_OutputObjectToParentTransform << std::endl; +} + +} // End namespace tube + +} // End namespace itk + +#endif // End !defined( __itktubePointBasedSpatialObjectTransformFilter_hxx ) diff --git a/src/Registration/itktubeRigidSpatialObjectToImageRegistrationMethod.h b/src/Registration/itktubeRigidSpatialObjectToImageRegistrationMethod.h new file mode 100644 index 000000000..a777e7cbf --- /dev/null +++ b/src/Registration/itktubeRigidSpatialObjectToImageRegistrationMethod.h @@ -0,0 +1,148 @@ +/*========================================================================= + +Library: TubeTK + +Copyright Kitware Inc. + +All rights reserved. + +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. + +=========================================================================*/ + +#ifndef __itktubeRigidSpatialObjectToImageRegistrationMethod_h +#define __itktubeRigidSpatialObjectToImageRegistrationMethod_h + +#include "itkImage.h" +#include "itkAffineTransform.h" +#include "itkVersorRigid3DTransform.h" +#include "itkRigid2DTransform.h" + +#include "itktubeOptimizedSpatialObjectToImageRegistrationMethod.h" + +namespace itk +{ + +namespace tube +{ + +template +class RigidSpatialObjectToImageRegistrationMethod + : public OptimizedSpatialObjectToImageRegistrationMethod +{ + +public: + + typedef RigidSpatialObjectToImageRegistrationMethod Self; + typedef OptimizedSpatialObjectToImageRegistrationMethod Superclass; + typedef SmartPointer Pointer; + typedef SmartPointer ConstPointer; + + itkTypeMacro( RigidSpatialObjectToImageRegistrationMethod, + OptimizedSpatialObjectToImageRegistrationMethod ); + + itkNewMacro( Self ); + + // + // Typedefs from Superclass + // + + itkStaticConstMacro( ImageDimension, unsigned int, + TImage::ImageDimension ); + + // Overrides the superclass' TransformType typedef + // We must use MatrixOffsetTransformBase since no itk rigid transform is + // templated over ImageDimension. + typedef MatrixOffsetTransformBase + RigidTransformType; + typedef RigidTransformType TransformType; + + // + // Custom Typedefs + // + typedef Rigid2DTransform Rigid2DTransformType; + typedef VersorRigid3DTransform Rigid3DTransformType; + + typedef AffineTransform + AffineTransformType; + + typedef typename AffineTransformType::Pointer AffineTransformPointer; + + // + // Superclass Methods + // + void GenerateData( void ) override; + + // + // Custom Methods + // + + /** + * The function performs the casting. This function should only appear + * once in the class hierarchy. It is provided so that member + * functions that exist only in specific transforms ( e.g., SetIdentity ) + * can be called without the caller having to do the casting. */ + TransformType * GetTypedTransform( void ); + + const TransformType * GetTypedTransform( void ) const; + + /** + * This function creates a new affine transforms that implements the + * current registration transform. Provided to help with transform + * composition. The transform is initialized with the current results + * available in the GetTypedTransform() method. The returned transform is + * not a member variable, and therefore, must be received into a + * SmartPointer to prevent it from being destroyed by depletion of its + * reference counting. */ + AffineTransformPointer GetAffineTransform( void ) const; + + /** Initialize the transform parameters from an AffineTransform This method + * is intended as an alternative to calling SetInitialTransformParameters() + * and SetInitialTransformFixedParameters(). These later methods require + * you to have a rigid transform at hand, and this is not always the case, + * specially when a transform initializer is being used. The method below + * facilitates to use the AffineTransform returned by the + * InitialSpatialObjectToImageRegistrationMethod to directly initialize this rigid + * registration method. The received Affine transform will be approximated + * to its closest rigid transform by using Polar decomposition. */ + void SetInitialTransformParametersFromAffineTransform( + const AffineTransformType * affine ); + +protected: + + RigidSpatialObjectToImageRegistrationMethod( void ); + virtual ~RigidSpatialObjectToImageRegistrationMethod( void ); + + void PrintSelf( std::ostream & os, Indent indent ) const override; + +private: + + // Purposely not implemented + RigidSpatialObjectToImageRegistrationMethod( const Self & ); + // Purposely not implemented + void operator =( const Self & ); + +}; + +} // end namespace tube + +} // end namespace itk + +#ifndef ITK_MANUAL_INSTANTIATION +#include "itktubeRigidSpatialObjectToImageRegistrationMethod.hxx" +#endif + +#endif // __SpatialObjectToImageRegistrationMethod_h diff --git a/src/Registration/itktubeRigidSpatialObjectToImageRegistrationMethod.hxx b/src/Registration/itktubeRigidSpatialObjectToImageRegistrationMethod.hxx new file mode 100644 index 000000000..db3d06fcc --- /dev/null +++ b/src/Registration/itktubeRigidSpatialObjectToImageRegistrationMethod.hxx @@ -0,0 +1,214 @@ +/*========================================================================= + +Library: TubeTK + +Copyright Kitware Inc. + +All rights reserved. + +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. + +=========================================================================*/ + +#ifndef __tubeRigidSpatialObjectToImageRegistrationMethod_hxx +#define __tubeRigidSpatialObjectToImageRegistrationMethod_hxx + +#include "itktubeRigidSpatialObjectToImageRegistrationMethod.h" + +#include "vnl/vnl_inverse.h" + +namespace itk +{ + +namespace tube +{ + +template +RigidSpatialObjectToImageRegistrationMethod +::RigidSpatialObjectToImageRegistrationMethod( void ) +{ + if( ImageDimension == 2 ) + { + typename Rigid2DTransformType::Pointer tmpTrans = + Rigid2DTransformType::New(); + this->SetTransform( dynamic_cast( + tmpTrans.GetPointer() ) ); + tmpTrans->Register(); + } + else if( ImageDimension == 3 ) + { + typename Rigid3DTransformType::Pointer tmpTrans = + Rigid3DTransformType::New(); + this->SetTransform( dynamic_cast( + tmpTrans.GetPointer() ) ); + tmpTrans->Register(); + } + else + { + std::cerr << "ERROR: Rigid registration only supported for 2D & 3D images." + << std::endl; + } + + this->GetTypedTransform()->SetIdentity(); + + this->SetInitialTransformParameters( this->GetTypedTransform() + ->GetParameters() ); + this->SetInitialTransformFixedParameters( this->GetTypedTransform() + ->GetFixedParameters() ); + this->SetLastTransformParameters( this->GetTypedTransform() + ->GetParameters() ); + + typename Superclass::TransformParametersScalesType scales; + scales.set_size( this->GetTypedTransform()->GetNumberOfParameters() ); + if( ImageDimension == 2 ) + { + scales[0] = 10; + scales[1] = 0.1; + scales[2] = 0.1; + } + else if( ImageDimension == 3 ) + { + scales[0] = 10; + scales[1] = 10; + scales[2] = 10; + scales[3] = 0.1; + scales[4] = 0.1; + scales[5] = 0.1; + } + + this->SetTransformParametersScales( scales ); + + this->SetTransformMethodEnum( Superclass::RIGID_TRANSFORM ); +} + +template +RigidSpatialObjectToImageRegistrationMethod +::~RigidSpatialObjectToImageRegistrationMethod( void ) +{ + this->m_Transform->UnRegister(); +} + +template +typename RigidSpatialObjectToImageRegistrationMethod::TransformType +* RigidSpatialObjectToImageRegistrationMethod +::GetTypedTransform( void ) + { + return dynamic_cast( Superclass::GetTransform() ); + } + +template +const typename RigidSpatialObjectToImageRegistrationMethod::TransformType +* RigidSpatialObjectToImageRegistrationMethod +::GetTypedTransform( void ) const + { + return dynamic_cast( Superclass::GetTransform() ); + } + +template +typename RigidSpatialObjectToImageRegistrationMethod::AffineTransformPointer +RigidSpatialObjectToImageRegistrationMethod +::GetAffineTransform( void ) const +{ + typename AffineTransformType::Pointer trans = AffineTransformType::New(); + + trans->SetIdentity(); + trans->SetCenter( this->GetTypedTransform()->GetCenter() ); + trans->SetMatrix( this->GetTypedTransform()->GetMatrix() ); + trans->SetOffset( this->GetTypedTransform()->GetOffset() ); + + return trans; +} + +template +void +RigidSpatialObjectToImageRegistrationMethod +::SetInitialTransformParametersFromAffineTransform( const AffineTransformType * affine ) +{ + RigidTransformType * rigidTransform = + dynamic_cast( this->GetTransform() ); + + if( !rigidTransform ) + { + itkExceptionMacro("GetTransform() didn't return a Rigid Transform"); + } + + rigidTransform->SetCenter( affine->GetCenter() ); + rigidTransform->SetTranslation( affine->GetTranslation() ); + + typedef vnl_matrix VnlMatrixType; + + VnlMatrixType M = affine->GetMatrix().GetVnlMatrix(); + + // + // Polar decomposition algorithm proposed by [Higham 86] + // SIAM J. Sci. Stat. Comput. Vol. 7, Num. 4, October 1986. + // "Computing the Polar Decomposition - with Applications" + // by Nicholas Higham. + // + // recommended by + // Shoemake in the paper "Matrix Animation and Polar Decomposition". + // + VnlMatrixType PQ = M; + VnlMatrixType NQ = M; + VnlMatrixType PQNQDiff; + + const unsigned int maximumIterations = 100; + for( unsigned int ni = 0; ni < maximumIterations; ni++ ) + { + // Average current Qi with its inverse transpose + NQ = ( PQ + vnl_inverse_transpose( PQ ) ) / 2.0; + PQNQDiff = NQ - PQ; + if( PQNQDiff.frobenius_norm() < 1e-7 ) + { + break; + } + else + { + PQ = NQ; + } + } + + typename AffineTransformType::MatrixType QMatrix; + + QMatrix = NQ; + + rigidTransform->SetMatrix( QMatrix ); + + this->SetInitialTransformFixedParameters( rigidTransform->GetFixedParameters() ); + this->SetInitialTransformParameters( rigidTransform->GetParameters() ); +} + +template +void +RigidSpatialObjectToImageRegistrationMethod +::GenerateData( void ) +{ + // Set the center of rotation + this->GetTransform()->SetFixedParameters( this->GetInitialTransformFixedParameters() ); + + Superclass::GenerateData(); +} + +template +void +RigidSpatialObjectToImageRegistrationMethod +::PrintSelf( std::ostream & os, Indent indent ) const +{ + this->Superclass::PrintSelf(os, indent); +} + +}; // tube + +}; // itk + +#endif diff --git a/src/Registration/itktubeScaleSkewAngle2DSpatialObjectToImageRegistrationMethod.h b/src/Registration/itktubeScaleSkewAngle2DSpatialObjectToImageRegistrationMethod.h new file mode 100644 index 000000000..5dc4e6e50 --- /dev/null +++ b/src/Registration/itktubeScaleSkewAngle2DSpatialObjectToImageRegistrationMethod.h @@ -0,0 +1,143 @@ +/*========================================================================= + +Library: TubeTK + +Copyright Kitware Inc. + +All rights reserved. + +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. + +=========================================================================*/ + +#ifndef __itktubeScaleSkewAngle2DSpatialObjectToImageRegistrationMethod_h +#define __itktubeScaleSkewAngle2DSpatialObjectToImageRegistrationMethod_h + +#include "itkImage.h" +#include "itkScaleSkewAngle2DTransform.h" + +#include "itktubeOptimizedSpatialObjectToImageRegistrationMethod.h" + +namespace itk +{ + +namespace tube +{ + +template +class ScaleSkewAngle2DSpatialObjectToImageRegistrationMethod + : public OptimizedSpatialObjectToImageRegistrationMethod< + 2, Image< typename TImage::PixelType, 2 > > +{ + +public: + + typedef ScaleSkewAngle2DSpatialObjectToImageRegistrationMethod Self; + typedef OptimizedSpatialObjectToImageRegistrationMethod< + 2, Image< typename TImage::PixelType, 2 > > Superclass; + typedef SmartPointer Pointer; + typedef SmartPointer ConstPointer; + + itkTypeMacro( ScaleSkewAngle2DSpatialObjectToImageRegistrationMethod, + OptimizedSpatialObjectToImageRegistrationMethod ); + + itkNewMacro( Self ); + + itkStaticConstMacro( ImageDimension, unsigned int, 2 ); + itkStaticConstMacro( ObjectDimension, unsigned int, 2 ); + + // + // Typedefs from Superclass + // + + // Overrides the superclass' TransformType typedef + typedef ::itk::ScaleSkewAngle2DTransform< double > + ScaleSkewAngle2DTransformType; + typedef typename ScaleSkewAngle2DTransformType::Pointer + ScaleSkewAngle2DTransformPointer; + typedef ScaleSkewAngle2DTransformType + TransformType; + + typedef AffineTransform + AffineTransformType; + typedef typename AffineTransformType::Pointer + AffineTransformPointer; + + // + // Superclass Methods + // + + void GenerateData( void ) override; + + // + // Custom Methods + // + + /** + * The function performs the casting. This function should only appear + * once in the class hierarchy. It is provided so that member + * functions that exist only in specific transforms + * ( e.g., SetIdentity ) + * can be called without the caller having to do the casting. + */ + TransformType * GetTypedTransform( void ); + + const TransformType * GetTypedTransform( void ) const; + + /** + * This function creates a new affine transforms that implements the + * current registration transform. Provided to help with transform + * composition. The transform is initialized with the current results + * available in the GetTypedTransform() method. The returned transform is + * not a member variable, and therefore, must be received into a + * SmartPointer to prevent it from being destroyed by depletion of its + * reference counting. + */ + AffineTransformPointer GetAffineTransform( void ) const; + + /** Initialize the transform parameters from an AffineTransform. + * This method is intended as an alternative to calling + * SetInitialTransformParameters() and + * SetInitialTransformFixedParameters(). The method below facilitates to + * use the AffineTransform returned by the + * InitialSpatialObjectToImageRegistrationMethod + * to directly initialize this registration method. + */ + void SetInitialTransformParametersFromAffineTransform( + const AffineTransformType * transform ); + +protected: + + ScaleSkewAngle2DSpatialObjectToImageRegistrationMethod( void ); + virtual ~ScaleSkewAngle2DSpatialObjectToImageRegistrationMethod( void ); + + void PrintSelf( std::ostream & os, Indent indent ) const override; + +private: + + // Purposely not implemented + ScaleSkewAngle2DSpatialObjectToImageRegistrationMethod( const Self & ); + // Purposely not implemented + void operator =( const Self & ); + +}; + +} // end namespace tube + +} // end namespace itk + +#ifndef ITK_MANUAL_INSTANTIATION +#include "itktubeScaleSkewAngle2DSpatialObjectToImageRegistrationMethod.hxx" +#endif + +#endif // __SpatialObjectToImageRegistrationMethod_h diff --git a/src/Registration/itktubeScaleSkewAngle2DSpatialObjectToImageRegistrationMethod.hxx b/src/Registration/itktubeScaleSkewAngle2DSpatialObjectToImageRegistrationMethod.hxx new file mode 100644 index 000000000..d0319ff3b --- /dev/null +++ b/src/Registration/itktubeScaleSkewAngle2DSpatialObjectToImageRegistrationMethod.hxx @@ -0,0 +1,143 @@ +/*========================================================================= + +Library: TubeTK + +Copyright Kitware Inc. + +All rights reserved. + +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. + +=========================================================================*/ + +#ifndef __itktubeScaleSkewAngle2DSpatialObjectToImageRegistrationMethod_txx +#define __itktubeScaleSkewAngle2DSpatialObjectToImageRegistrationMethod_txx + +#include "itktubeScaleSkewAngle2DSpatialObjectToImageRegistrationMethod.h" + +namespace itk +{ + +namespace tube +{ + +template < class TImage> +ScaleSkewAngle2DSpatialObjectToImageRegistrationMethod +::ScaleSkewAngle2DSpatialObjectToImageRegistrationMethod( void ) +{ + this->SetTransform( ScaleSkewAngle2DTransformType::New() ); + this->GetTypedTransform()->SetUseSingleScale( true ); + this->GetTypedTransform()->SetIdentity(); + + this->SetInitialTransformParameters( this->GetTypedTransform() + ->GetParameters() ); + this->SetInitialTransformFixedParameters( this->GetTypedTransform() + ->GetFixedParameters() ); + + typename Superclass::TransformParametersScalesType scales; + scales.set_size( this->GetTypedTransform()->GetNumberOfParameters() ); + if( scales.size() != 6 ) + { + std::cerr << "ERROR: number of parameters not standard for transform" + << std::endl; + } + unsigned int scaleNum = 0; + // Angle + scales[scaleNum++] = 1000; + // Offset + scales[scaleNum++] = 1; + scales[scaleNum++] = 1; + // Scale + scales[scaleNum++] = 100; + scales[scaleNum++] = 100; + // Skew + scales[scaleNum++] = 1000; + this->SetTransformParametersScales( scales ); + + this->SetTransformMethodEnum( Superclass::AFFINE_TRANSFORM ); +} + +template < class TImage> +ScaleSkewAngle2DSpatialObjectToImageRegistrationMethod +::~ScaleSkewAngle2DSpatialObjectToImageRegistrationMethod( void ) +{ +} + +template < class TImage> +void +ScaleSkewAngle2DSpatialObjectToImageRegistrationMethod +::GenerateData( void ) +{ + // Set the center of rotation + this->GetTransform()->SetFixedParameters( + this->GetInitialTransformFixedParameters() ); + + Superclass::GenerateData(); +} + +template < class TImage> +typename ScaleSkewAngle2DSpatialObjectToImageRegistrationMethod::TransformType +* ScaleSkewAngle2DSpatialObjectToImageRegistrationMethod +::GetTypedTransform( void ) +{ + return static_cast( Superclass::GetTransform() ); +} + +template < class TImage> +const typename ScaleSkewAngle2DSpatialObjectToImageRegistrationMethod::TransformType +* ScaleSkewAngle2DSpatialObjectToImageRegistrationMethod +::GetTypedTransform( void ) const +{ + return static_cast( Superclass::GetTransform() ); +} + +template < class TImage> +typename ScaleSkewAngle2DSpatialObjectToImageRegistrationMethod::AffineTransformPointer +ScaleSkewAngle2DSpatialObjectToImageRegistrationMethod +::GetAffineTransform( void ) const +{ + AffineTransformPointer trans = AffineTransformType::New(); + + const TransformType * typedTransform = this->GetTypedTransform(); + + trans->SetIdentity(); + trans->SetCenter( typedTransform->GetCenter() ); + trans->SetMatrix( typedTransform->GetMatrix() ); + trans->SetOffset( typedTransform->GetOffset() ); + + return trans; +} + +template < class TImage> +void +ScaleSkewAngle2DSpatialObjectToImageRegistrationMethod +::SetInitialTransformParametersFromAffineTransform( + const AffineTransformType * tfm ) +{ + this->SetInitialTransformFixedParameters( tfm->GetFixedParameters() ); + this->SetInitialTransformParameters( tfm->GetParameters() ); +} + +template < class TImage> +void +ScaleSkewAngle2DSpatialObjectToImageRegistrationMethod +::PrintSelf( std::ostream & os, Indent indent ) const +{ + Superclass::PrintSelf(os, indent); +} + +} // tube + +} // itk + +#endif diff --git a/src/Registration/itktubeScaleSkewVersor3DSpatialObjectToImageRegistrationMethod.h b/src/Registration/itktubeScaleSkewVersor3DSpatialObjectToImageRegistrationMethod.h new file mode 100644 index 000000000..4d86c03ec --- /dev/null +++ b/src/Registration/itktubeScaleSkewVersor3DSpatialObjectToImageRegistrationMethod.h @@ -0,0 +1,142 @@ +/*========================================================================= + +Library: TubeTK + +Copyright Kitware Inc. + +All rights reserved. + +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. + +=========================================================================*/ + +#ifndef __itktubeScaleSkewVersor3DSpatialObjectToImageRegistrationMethod_h +#define __itktubeScaleSkewVersor3DSpatialObjectToImageRegistrationMethod_h + +#include "itkImage.h" +#include "itkComposeScaleSkewVersor3DTransform.h" + +#include "itktubeOptimizedSpatialObjectToImageRegistrationMethod.h" + +namespace itk +{ + +namespace tube +{ + +template +class ScaleSkewVersor3DSpatialObjectToImageRegistrationMethod + : public OptimizedSpatialObjectToImageRegistrationMethod< + 3, Image< typename TImage::PixelType, 3 > > +{ + +public: + + typedef ScaleSkewVersor3DSpatialObjectToImageRegistrationMethod Self; + typedef OptimizedSpatialObjectToImageRegistrationMethod< + 3, Image< typename TImage::PixelType, 3 > > Superclass; + typedef SmartPointer Pointer; + typedef SmartPointer ConstPointer; + + itkTypeMacro( ScaleSkewVersor3DSpatialObjectToImageRegistrationMethod, + OptimizedSpatialObjectToImageRegistrationMethod ); + + itkNewMacro( Self ); + + itkStaticConstMacro( ImageDimension, unsigned int, 3 ); + itkStaticConstMacro( ObjectDimension, unsigned int, 3 ); + + // + // Typedefs from Superclass + // + // Overrides the superclass' TransformType typedef + typedef ::itk::ComposeScaleSkewVersor3DTransform< double > + ScaleSkewVersor3DTransformType; + typedef typename ScaleSkewVersor3DTransformType::Pointer + ScaleSkewVersor3DTransformPointer; + typedef ScaleSkewVersor3DTransformType + TransformType; + + typedef AffineTransform + AffineTransformType; + typedef typename AffineTransformType::Pointer + AffineTransformPointer; + + // + // Superclass Methods + // + + void GenerateData( void ) override; + + // + // Custom Methods + // + + /** + * The function performs the casting. This function should only appear + * once in the class hierarchy. It is provided so that member + * functions that exist only in specific transforms + * ( e.g., SetIdentity ) + * can be called without the caller having to do the casting. + */ + TransformType * GetTypedTransform( void ); + + const TransformType * GetTypedTransform( void ) const; + + /** + * This function creates a new affine transforms that implements the + * current registration transform. Provided to help with transform + * composition. The transform is initialized with the current results + * available in the GetTypedTransform() method. The returned transform is + * not a member variable, and therefore, must be received into a + * SmartPointer to prevent it from being destroyed by depletion of its + * reference counting. + */ + AffineTransformPointer GetAffineTransform( void ) const; + + /** Initialize the transform parameters from an AffineTransform. + * This method is intended as an alternative to calling + * SetInitialTransformParameters() and + * SetInitialTransformFixedParameters(). The method below facilitates to + * use the AffineTransform returned by the + * InitialSpatialObjectToImageRegistrationMethod + * to directly initialize this registration method. + */ + void SetInitialTransformParametersFromAffineTransform( + const AffineTransformType * transform ); + +protected: + + ScaleSkewVersor3DSpatialObjectToImageRegistrationMethod( void ); + virtual ~ScaleSkewVersor3DSpatialObjectToImageRegistrationMethod( void ); + + void PrintSelf( std::ostream & os, Indent indent ) const override; + +private: + + // Purposely not implemented + ScaleSkewVersor3DSpatialObjectToImageRegistrationMethod( const Self & ); + // Purposely not implemented + void operator =( const Self & ); + +}; + +} // end namespace tube + +} // end namespace itk + +#ifndef ITK_MANUAL_INSTANTIATION +#include "itktubeScaleSkewVersor3DSpatialObjectToImageRegistrationMethod.hxx" +#endif + +#endif // __SpatialObjectToImageRegistrationMethod_h diff --git a/src/Registration/itktubeScaleSkewVersor3DSpatialObjectToImageRegistrationMethod.hxx b/src/Registration/itktubeScaleSkewVersor3DSpatialObjectToImageRegistrationMethod.hxx new file mode 100644 index 000000000..f737550b9 --- /dev/null +++ b/src/Registration/itktubeScaleSkewVersor3DSpatialObjectToImageRegistrationMethod.hxx @@ -0,0 +1,156 @@ +/*========================================================================= + +Library: TubeTK + +Copyright Kitware Inc. + +All rights reserved. + +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. + +=========================================================================*/ + + +#ifndef __itktubeScaleSkewVersor3DSpatialObjectToImageRegistrationMethod_txx +#define __itktubeScaleSkewVersor3DSpatialObjectToImageRegistrationMethod_txx + +#include "itktubeScaleSkewVersor3DSpatialObjectToImageRegistrationMethod.h" + +namespace itk +{ + +namespace tube +{ + +template +ScaleSkewVersor3DSpatialObjectToImageRegistrationMethod +::ScaleSkewVersor3DSpatialObjectToImageRegistrationMethod( void ) +{ + this->SetTransform( ScaleSkewVersor3DTransformType::New() ); + this->GetTypedTransform()->SetIdentity(); + + this->SetInitialTransformParameters( this->GetTypedTransform() + ->GetParameters() ); + this->SetInitialTransformFixedParameters( this->GetTypedTransform() + ->GetFixedParameters() ); + + typename Superclass::TransformParametersScalesType scales; + scales.set_size( this->GetTypedTransform()->GetNumberOfParameters() ); + if( scales.size() != 12 ) + { + std::cerr << "ERROR: number of parameters not standard for transform" + << std::endl; + std::cout << " # = " << scales.size() << ", expecting 12" << std::endl; + } + unsigned int scaleNum = 0; + // Versor + for( unsigned int d1 = 0; d1 < ImageDimension; d1++ ) + { + scales[scaleNum] = 1000; + ++scaleNum; + } + // Offset + for( unsigned int d1 = 0; d1 < ImageDimension; d1++ ) + { + scales[scaleNum] = 1; + ++scaleNum; + } + // Scale + for( unsigned int d1 = 0; d1 < ImageDimension; d1++ ) + { + scales[scaleNum] = 100; + ++scaleNum; + } + // Skew + for( unsigned int d1 = 0; d1 < ImageDimension; d1++ ) + { + scales[scaleNum] = 1000; + ++scaleNum; + } + this->SetTransformParametersScales( scales ); + this->SetTransformMethodEnum( Superclass::AFFINE_TRANSFORM ); +} + +template +ScaleSkewVersor3DSpatialObjectToImageRegistrationMethod +::~ScaleSkewVersor3DSpatialObjectToImageRegistrationMethod( void ) +{ +} + +template +void +ScaleSkewVersor3DSpatialObjectToImageRegistrationMethod +::GenerateData( void ) +{ + // Set the center of rotation + this->GetTransform()->SetFixedParameters( this->GetInitialTransformFixedParameters() ); + + Superclass::GenerateData(); +} + +template +typename ScaleSkewVersor3DSpatialObjectToImageRegistrationMethod::TransformType +* ScaleSkewVersor3DSpatialObjectToImageRegistrationMethod +::GetTypedTransform( void ) +{ + return static_cast( Superclass::GetTransform() ); +} + +template +const typename ScaleSkewVersor3DSpatialObjectToImageRegistrationMethod::TransformType +* ScaleSkewVersor3DSpatialObjectToImageRegistrationMethod +::GetTypedTransform( void ) const +{ + return static_cast( Superclass::GetTransform() ); +} + +template +typename ScaleSkewVersor3DSpatialObjectToImageRegistrationMethod::AffineTransformPointer +ScaleSkewVersor3DSpatialObjectToImageRegistrationMethod +::GetAffineTransform( void ) const +{ + AffineTransformPointer trans = AffineTransformType::New(); + + const TransformType * typedTransform = this->GetTypedTransform(); + + trans->SetIdentity(); + trans->SetCenter( typedTransform->GetCenter() ); + trans->SetMatrix( typedTransform->GetMatrix() ); + trans->SetOffset( typedTransform->GetOffset() ); + + return trans; +} + +template +void +ScaleSkewVersor3DSpatialObjectToImageRegistrationMethod +::SetInitialTransformParametersFromAffineTransform( + const AffineTransformType * tfm ) +{ + this->SetInitialTransformFixedParameters( tfm->GetFixedParameters() ); + this->SetInitialTransformParameters( tfm->GetParameters() ); +} + +template +void +ScaleSkewVersor3DSpatialObjectToImageRegistrationMethod +::PrintSelf( std::ostream & os, Indent indent ) const +{ + Superclass::PrintSelf(os, indent); +} + +} // tube + +} // itk + +#endif diff --git a/src/Registration/itktubeSpatialObjectToImageMetric.h b/src/Registration/itktubeSpatialObjectToImageMetric.h new file mode 100644 index 000000000..a7d7b5f8d --- /dev/null +++ b/src/Registration/itktubeSpatialObjectToImageMetric.h @@ -0,0 +1,209 @@ +/*========================================================================= + +Library: TubeTK + +Copyright Kitware Inc. + +All rights reserved. + +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. + +=========================================================================*/ + +#ifndef itktubeSpatialObjectToImageMetric_h +#define itktubeSpatialObjectToImageMetric_h + +#include "itkTransform.h" + +#include "itkSpatialObject.h" + +#include "itkSingleValuedCostFunction.h" + +#include "vnl/vnl_vector_fixed.h" + +namespace itk +{ + +namespace tube +{ +/** \class SpatialObjectToImageMetric + * \brief Computes similarity between a moving spatial object + * and an Image to be registered + * + * The SpatialObjectToImageMetric is different from the rest of the + * registration framework in ITK regarding the interpretation of the Transform + * with respect to the Fixed and Moving objects. In most of the ITK + * registration framework, the Transform computed by the optimizer is the one + * that maps points from the space of the Fixed object into the space of the + * Moving object. This direction of the transform is the one that makes easier + * to resample the Moving object into the space of the Fixed object. + * + * In the particular case of SpatialObjectToImage registration, the + * Transform to be computed is the one mapping points from the SpatialObject + * into the Image. This allows the SpatialObject to drive the location and + * geometry of the measurements made in the image - thereby if the spatial + * object is sparse and/or contains varying geometric features, the metric + * applied to measure how well that object matches with the image can be + * rapidly computed only at the sparse locations and using measures that + * match the local geometry that should be at those locations in the image. + * This is particularly useful for fast intra-operative registration when the + * pre-operative data is used to define a SpatialObject and can anticipate + * how that object will appear in the intra-operative images. + * + * A full discussion of the Transform directions in the ITK registration + * framework can be found in the ITK Software Guide. + * + * \ingroup ITKRegistrationCommon + */ + +template +class ITK_TEMPLATE_EXPORT SpatialObjectToImageMetric : public SingleValuedCostFunction +{ +public: + ITK_DISALLOW_COPY_AND_MOVE(SpatialObjectToImageMetric); + + using Self = SpatialObjectToImageMetric; + using Superclass = SingleValuedCostFunction; + using Pointer = SmartPointer; + using ConstPointer = SmartPointer; + + /** Type of the fixed image */ + using FixedImageType = TFixedImage; + + /** Type of the MovingSpatialObject */ + using MovingSpatialObjectType = SpatialObject; + + /** Type used for representing point components */ + using CoordinateRepresentationType = Superclass::ParametersValueType; + + /** Image dimension enumeration. */ + static constexpr unsigned int ImageDimension = FixedImageType::ImageDimension; + + typedef SpatialObject + ImageMaskObjectType; + + typedef SpatialObject< ObjectDimension > SpatialObjectMaskObjectType; + + /** Type of the Transform Base class */ + using TransformType = Transform; + + using TransformPointer = typename TransformType::Pointer; + using MovingPointType = typename TransformType::InputPointType; + using FixedPointType = typename TransformType::OutputPointType; + using TransformParametersType = typename TransformType::ParametersType; + using TransformJacobianType = typename TransformType::JacobianType; + + using MovingVectorType = vnl_vector_fixed; + using FixedVectorType = vnl_vector_fixed; + + /** Type of the match measure */ + using MeasureType = Superclass::MeasureType; + + /** Type of the derivative of the match measure */ + using DerivativeType = Superclass::DerivativeType; + + /** Pointer type for the FixedImage */ + using FixedImagePointer = typename FixedImageType::Pointer; + + /** Pointer type for the MovingSpatialObject */ + using MovingSpatialObjectPointer = typename MovingSpatialObjectType::Pointer; + + /** Const pointer type for the FixedImage */ + using FixedImageConstPointer = typename FixedImageType::ConstPointer; + + /** Const pointer type for the MovingSpatialObject */ + using MovingSpatialObjectConstPointer = typename MovingSpatialObjectType::ConstPointer; + + /** ParametersType type alias. + * It defines a position in the optimization search space. */ + using ParametersType = Superclass::ParametersType; + + /** Run-time type information (and related methods). */ + itkTypeMacro(SpatialObjectToImageMetric, Object); + + /** Get/Set the FixedImage. */ + void SetFixedImage( const FixedImageType * fixedImage ); + itkGetConstObjectMacro(FixedImage, FixedImageType); + + /** Get/Set the MovingSpatialObject */ + void SetMovingSpatialObject( const MovingSpatialObjectType * + movingSpatialObject ); + itkGetConstObjectMacro(MovingSpatialObject, MovingSpatialObjectType); + + void SetFixedImageMaskObject( const ImageMaskObjectType * maskObject ); + itkGetConstObjectMacro( FixedImageMaskObject, ImageMaskObjectType ); + itkSetMacro( UseFixedImageMaskObject, bool ); + itkGetMacro( UseFixedImageMaskObject, bool ); + + void SetMovingSpatialObjectMaskObject( + const SpatialObjectMaskObjectType * maskObject ); + itkGetConstObjectMacro( MovingSpatialObjectMaskObject, + SpatialObjectMaskObjectType ); + itkSetMacro( UseMovingSpatialObjectMaskObject, bool ); + itkGetMacro( UseMovingSpatialObjectMaskObject, bool ); + + /** Get Value and Derivatives for MultipleValuedOptimizers */ + void + GetValueAndDerivative(const ParametersType & parameters, + MeasureType & Value, + DerivativeType & Derivative) const override = 0; + + /** Return the number of parameters required by the Transform */ + unsigned int + GetNumberOfParameters() const override; + + /** Initialize the metric */ + virtual void + Initialize(); + + /** Get the last transformation parameters visited by + * the optimizer. This function overload the superclass's one */ + itkGetConstReferenceMacro(LastTransformParameters, ParametersType); + + /** Set/Get the Transform. */ + itkSetObjectMacro(Transform, TransformType); + +protected: + SpatialObjectToImageMetric(); + ~SpatialObjectToImageMetric() override = default; + + void + PrintSelf(std::ostream & os, Indent indent) const override; + + MovingSpatialObjectConstPointer m_MovingSpatialObject; + + FixedImageConstPointer m_FixedImage; + + mutable TransformPointer m_Transform; + + ParametersType m_LastTransformParameters; + + bool m_UseFixedImageMaskObject; + typename ImageMaskObjectType::ConstPointer m_FixedImageMaskObject; + + bool m_UseMovingSpatialObjectMaskObject; + typename SpatialObjectMaskObjectType::ConstPointer + m_MovingSpatialObjectMaskObject; + +}; + +} // end namespace tube + +} // end namespace itk + +#ifndef ITK_MANUAL_INSTANTIATION +# include "itktubeSpatialObjectToImageMetric.hxx" +#endif + +#endif diff --git a/src/Registration/itktubeSpatialObjectToImageMetric.hxx b/src/Registration/itktubeSpatialObjectToImageMetric.hxx new file mode 100644 index 000000000..1f573281b --- /dev/null +++ b/src/Registration/itktubeSpatialObjectToImageMetric.hxx @@ -0,0 +1,211 @@ +/*========================================================================= + +Library: TubeTK + +Copyright Kitware Inc. + +All rights reserved. + +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. + +=========================================================================*/ + +#ifndef itktubeSpatialObjectToImageMetric_hxx +#define itktubeSpatialObjectToImageMetric_hxx + +#include "itktubeSpatialObjectToImageMetric.h" + +namespace itk +{ + +namespace tube +{ + +/** Constructor */ +template +SpatialObjectToImageMetric::SpatialObjectToImageMetric() + +{ + m_FixedImage = nullptr; // has to be provided by the user. + + m_MovingSpatialObject = nullptr; // has to be provided by the user. + + m_Transform = nullptr; // has to be provided by the user. + + m_UseFixedImageMaskObject = false; + m_FixedImageMaskObject = nullptr; + + m_UseMovingSpatialObjectMaskObject = false; + m_MovingSpatialObjectMaskObject = nullptr; + + m_LastTransformParameters.fill(0); +} + +template +void +SpatialObjectToImageMetric +::SetFixedImage( const FixedImageType * fixedImage ) +{ + if( this->m_FixedImage.GetPointer() != fixedImage ) + { + this->m_FixedImage = fixedImage; + + //this->ProcessObject::SetNthInput(0, const_cast( fixedImage ) ); + + this->Modified(); + } +} + +template +void +SpatialObjectToImageMetric +::SetMovingSpatialObject( const MovingSpatialObjectType * movingSpatialObject ) +{ + this->m_MovingSpatialObject = movingSpatialObject; + + //this->ProcessObject::SetNthInput(1, const_cast( + //m_MovingSpatialObject ) ); + + this->Modified(); +} + +template +void +SpatialObjectToImageMetric +::SetFixedImageMaskObject( const ImageMaskObjectType * maskObject ) +{ + if( this->m_FixedImageMaskObject.GetPointer() != maskObject ) + { + this->m_FixedImageMaskObject = maskObject; + + this->Modified(); + + if( maskObject ) + { + m_UseFixedImageMaskObject = true; + } + else + { + m_UseFixedImageMaskObject = false; + } + } +} + +template +void +SpatialObjectToImageMetric +::SetMovingSpatialObjectMaskObject( + const SpatialObjectMaskObjectType * maskObject ) +{ + if( this->m_MovingSpatialObjectMaskObject.GetPointer() != maskObject ) + { + this->m_MovingSpatialObjectMaskObject = maskObject; + + this->Modified(); + + if( maskObject ) + { + m_UseMovingSpatialObjectMaskObject = true; + } + else + { + m_UseMovingSpatialObjectMaskObject = false; + } + } +} + +/** Return the number of parameters required by the Transform */ +template +unsigned int +SpatialObjectToImageMetric::GetNumberOfParameters() const +{ + if (!m_Transform) + { + itkExceptionMacro(<< "Transform is not present"); + } + return m_Transform->GetNumberOfParameters(); +} + +/** + * Initialize + */ + +template +void +SpatialObjectToImageMetric::Initialize() +{ + if (!m_Transform) + { + itkExceptionMacro(<< "Transform is not present"); + } + + if (!m_MovingSpatialObject) + { + itkExceptionMacro(<< "MovingSpatialObject is not present"); + } + + if (!m_FixedImage) + { + itkExceptionMacro(<< "FixedImage is not present"); + } + + // If the image is provided by a source, update the source. + if (m_FixedImage->GetSource()) + { + m_FixedImage->GetSource()->Update(); + } + + // If there are any observers on the metric, call them to give the + // user code a chance to set parameters on the metric + this->InvokeEvent(InitializeEvent()); +} + +/** PrintSelf */ +template +void +SpatialObjectToImageMetric::PrintSelf(std::ostream & os, Indent indent) const +{ + Superclass::PrintSelf(os, indent); + os << indent << "Moving Spatial Object: " + << m_MovingSpatialObject.GetPointer() << std::endl; + os << indent << "Fixed Image: " << m_FixedImage.GetPointer() << std::endl; + os << indent << "Transform: " << m_Transform.GetPointer() << std::endl; + os << indent << "Last Transform parameters = " << m_LastTransformParameters + << std::endl; + if(m_UseMovingSpatialObjectMaskObject) + { + os << indent << "Use Moving Spatial Object Mask Object: True" << std::endl; + } + else + { + os << indent << "Use Moving Spatial Object Mask Object: False" << std::endl; + } + os << indent << "Moving Spatial Object Mask Object: " + << m_MovingSpatialObjectMaskObject.GetPointer() << std::endl; + if(m_UseFixedImageMaskObject) + { + os << indent << "Use Fixed Image Mask Object: True" << std::endl; + } + else + { + os << indent << "Use Fixed Image Mask Object: False" << std::endl; + } + os << indent << "Fixed Image Mask Object: " + << m_FixedImageMaskObject.GetPointer() << std::endl; +} + +} // end namespace tube + +} // end namespace itk + +#endif diff --git a/src/Registration/itktubeSpatialObjectToImageRegistrationHelper.h b/src/Registration/itktubeSpatialObjectToImageRegistrationHelper.h new file mode 100644 index 000000000..e6e7b4a3d --- /dev/null +++ b/src/Registration/itktubeSpatialObjectToImageRegistrationHelper.h @@ -0,0 +1,472 @@ +/*========================================================================= + +Library: TubeTK + +Copyright Kitware Inc. + +All rights reserved. + +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. + +=========================================================================*/ + +#ifndef __itktubeSpatialObjectToImageRegistrationHelper_h +#define __itktubeSpatialObjectToImageRegistrationHelper_h + +#include "itkImage.h" +#include "itkCommand.h" + +#include "itktubeSpatialObjectToImageRegistrationMethod.h" +#include "itktubeInitialSpatialObjectToImageRegistrationMethod.h" +#include "itktubeOptimizedSpatialObjectToImageRegistrationMethod.h" +#include "itktubeRigidSpatialObjectToImageRegistrationMethod.h" +#include "itktubeAffineSpatialObjectToImageRegistrationMethod.h" +#include "itktubeScaleSkewAngle2DSpatialObjectToImageRegistrationMethod.h" +#include "itktubeScaleSkewVersor3DSpatialObjectToImageRegistrationMethod.h" + +namespace itk +{ + +namespace tube +{ + +template +class SpatialObjectToImageRegistrationHelper : public Object +{ + +public: + + typedef SpatialObjectToImageRegistrationHelper Self; + typedef Object Superclass; + typedef SmartPointer Pointer; + typedef SmartPointer ConstPointer; + + itkTypeMacro( SpatialObjectToImageRegistrationHelper, Object ); + + itkNewMacro( Self ); + + // + // Custom Typedefs + // + typedef TImage ImageType; + typedef typename TImage::PixelType PixelType; + + typedef SpatialObject< ObjectDimension > SpatialObjectType; + + itkStaticConstMacro( ImageDimension, unsigned int, + TImage::ImageDimension ); + + // + // Available Registration Methods + // + typedef SpatialObjectToImageRegistrationMethod + RegistrationMethodType; + + typedef InitialSpatialObjectToImageRegistrationMethod + InitialRegistrationMethodType; + + typedef OptimizedSpatialObjectToImageRegistrationMethod OptimizedRegistrationMethodType; + + typedef RigidSpatialObjectToImageRegistrationMethod + RigidRegistrationMethodType; + + typedef AffineSpatialObjectToImageRegistrationMethod + AffineRegistrationMethodType; + + typedef ScaleSkewAngle2DSpatialObjectToImageRegistrationMethod + Affine2DRegistrationMethodType; + + typedef ScaleSkewVersor3DSpatialObjectToImageRegistrationMethod + Affine3DRegistrationMethodType; + + // + // Typedefs for the parameters of the registration methods + // + typedef typename RegistrationMethodType::ImageMaskObjectType + ImageMaskObjectType; + + typedef typename RegistrationMethodType::SpatialObjectMaskObjectType + SpatialObjectMaskObjectType; + + typedef typename OptimizedRegistrationMethodType::MetricMethodEnumType + MetricMethodEnumType; + + enum InitialMethodEnumType { INIT_WITH_NONE, + INIT_WITH_CURRENT_RESULTS, + INIT_WITH_IMAGE_CENTERS, + INIT_WITH_CENTERS_OF_MASS, + INIT_WITH_LANDMARKS }; + + enum RegistrationStageEnumType { PRE_STAGE, + LOAD_STAGE, + INIT_STAGE, + RIGID_STAGE, + AFFINE_STAGE }; + + enum RegistrationMethodEnumType { NONE, + INITIAL, + RIGID, + AFFINE, + PIPELINE_RIGID, + PIPELINE_AFFINE }; + + typedef typename InitialRegistrationMethodType::TransformType + InitialTransformType; + + typedef std::vector > LandmarkVectorType; + + typedef typename TImage::PointType PointType; + + typedef typename RigidRegistrationMethodType::TransformType + RigidTransformType; + + typedef typename AffineRegistrationMethodType::TransformType + AffineTransformType; + + typedef typename Affine2DRegistrationMethodType::TransformType + Affine2DTransformType; + + typedef typename Affine3DRegistrationMethodType::TransformType + Affine3DTransformType; + + typedef AffineTransformType MatrixTransformType; + + // + // Custom Methods + // + + // ************** + // ************** + // Specify the fixed and moving images + // ************** + // ************** + void SetFixedImage( const TImage * fixedImage ); + itkGetConstObjectMacro( FixedImage, TImage ); + + void SetMovingSpatialObject( const SpatialObjectType * movingSpatialObject ); + itkGetConstObjectMacro( MovingSpatialObject, SpatialObjectType ); + + // ************** + // ************** + // Reproducibility + // ************** + // ************** + itkSetMacro( RandomNumberSeed, unsigned int ); + itkGetMacro( RandomNumberSeed, unsigned int ); + + // ************** + // ************** + // Specify how the fixed image should be sampled when computing the + // metric and what ROI of the moving image is valid + // ************** + // ************** + itkSetMacro( UseFixedImageMaskObject, bool ); + itkGetConstMacro( UseFixedImageMaskObject, bool ); + itkBooleanMacro( UseFixedImageMaskObject ); + void SetFixedImageMaskObject( const ImageMaskObjectType * mask ); + itkGetConstObjectMacro( FixedImageMaskObject, ImageMaskObjectType ); + + itkSetMacro( UseMovingSpatialObjectMaskObject, bool ); + itkGetConstMacro( UseMovingSpatialObjectMaskObject, bool ); + itkBooleanMacro( UseMovingSpatialObjectMaskObject ); + void SetMovingSpatialObjectMaskObject( + const SpatialObjectMaskObjectType * mask ); + itkGetConstObjectMacro( MovingSpatialObjectMaskObject, + SpatialObjectMaskObjectType ); + + // ************** + // ************** + // Update + // ************** + // ************** + void Initialize( void ); + + /** This class provides an Update() method to fit the appearance of a + * ProcessObject API, but it is not a ProcessObject. */ + void Update( void ); + + // ************** + // ************** + // Resample + // ************** + // ************** + const SpatialObjectType * ResampleSpatialObject( + const SpatialObjectType * movingSpatialObject = NULL, + const MatrixTransformType * matrixTransform = NULL, + double portion = 1.0 ); + + // Returns the moving image resampled into the space of the fixed image + const SpatialObjectType * GetFinalMovingSpatialObject( void ); + + // ************** + // ************** + // Process Control + // ************** + // ************** + + // ************** + // Control which steps of the registration pipeline are applied + // ************** + itkSetMacro( EnableLoadedRegistration, bool ); + itkGetConstMacro( EnableLoadedRegistration, bool ); + itkBooleanMacro( EnableLoadedRegistration ); + + itkSetMacro( EnableInitialRegistration, bool ); + itkGetConstMacro( EnableInitialRegistration, bool ); + itkBooleanMacro( EnableInitialRegistration ); + + itkSetMacro( EnableRigidRegistration, bool ); + itkGetConstMacro( EnableRigidRegistration, bool ); + itkBooleanMacro( EnableRigidRegistration ); + + itkSetMacro( EnableAffineRegistration, bool ); + itkGetConstMacro( EnableAffineRegistration, bool ); + itkBooleanMacro( EnableAffineRegistration ); + + void SetRegistration( RegistrationMethodEnumType reg ); + void SetMetric( MetricMethodEnumType metric ); + + // ************** + // Specify the optimizer + // ************** + itkSetMacro( UseEvolutionaryOptimization, bool ); + itkGetMacro( UseEvolutionaryOptimization, bool ); + + // ************** + // Specify the expected magnitudes within the transform. Used to + // guide the operating space of the optimizers + // ************** + itkSetMacro( ExpectedOffsetMagnitude, double ); + itkGetConstMacro( ExpectedOffsetMagnitude, double ); + + itkSetMacro( ExpectedRotationMagnitude, double ); + itkGetConstMacro( ExpectedRotationMagnitude, double ); + + itkSetMacro( ExpectedScaleMagnitude, double ); + itkGetConstMacro( ExpectedScaleMagnitude, double ); + + itkSetMacro( ExpectedSkewMagnitude, double ); + itkGetConstMacro( ExpectedSkewMagnitude, double ); + + // ************** + // Return the current product of the registration pipeline + // ************** + itkGetConstObjectMacro( CurrentMatrixTransform, MatrixTransformType ); + + // The image used for registration is updated at certain points in the + // registration pipeline for speed and transform composition. + // Specifically, the SpatialObject is resmpled using the loaded transforms + // prior to running the initial registration method and the spatialobject + // is resampled after the affine registration / prior to running bspline + // registration. The result of these resamplings is available as the + // CurrentMovingSpatialObject. + itkGetConstObjectMacro( CurrentMovingSpatialObject, SpatialObjectType ); + itkGetConstObjectMacro( LoadedTransformResampledSpatialObject, + SpatialObjectType ); + itkGetConstObjectMacro( MatrixTransformResampledSpatialObject, + SpatialObjectType ); + + // ************** + // Not implemented at this time :( + // ************** + void LoadParameters( const std::string & filename ); + + void SaveParameters( const std::string & filename ); + + // ************** + // Final metric value after the pipeline has completed + // ************** + itkGetMacro( FinalMetricValue, double ); + + // ************** + // Determine if progress messages should be sent to cout + // ************** + itkSetMacro( ReportProgress, bool ); + itkGetMacro( ReportProgress, bool ); + itkBooleanMacro( ReportProgress ); + + // + // Loaded transforms parameters + // + void LoadTransform( const std::string & filename, bool invert=false ); + + void SaveTransform( const std::string & filename ); + + void SetLoadedMatrixTransform( const MatrixTransformType & tfm, + bool invert=false ); + + itkGetConstObjectMacro( LoadedMatrixTransform, MatrixTransformType ); + + // + // Initial Parameters + // + itkSetMacro( InitialMethodEnum, InitialMethodEnumType ); + itkGetConstMacro( InitialMethodEnum, InitialMethodEnumType ); + + void SetFixedLandmarks( const LandmarkVectorType & fixedLandmarks ); + void SetMovingLandmarks( const LandmarkVectorType & movingLandmarks ); + + // + // Rigid Parameters + // + itkSetMacro( RigidSamplingRatio, double ); + itkGetConstMacro( RigidSamplingRatio, double ); + + itkSetMacro( RigidTargetError, double ); + itkGetConstMacro( RigidTargetError, double ); + + itkSetMacro( RigidMaxIterations, unsigned int ); + itkGetConstMacro( RigidMaxIterations, unsigned int ); + + itkSetMacro( RigidMetricMethodEnum, MetricMethodEnumType ); + itkGetConstMacro( RigidMetricMethodEnum, MetricMethodEnumType ); + + itkGetConstObjectMacro( RigidTransform, RigidTransformType ); + itkGetMacro( RigidMetricValue, double ); + + // + // Affine Parameters + // + itkSetMacro( AffineSamplingRatio, double ); + itkGetConstMacro( AffineSamplingRatio, double ); + + itkSetMacro( AffineTargetError, double ); + itkGetConstMacro( AffineTargetError, double ); + + itkSetMacro( AffineMaxIterations, unsigned int ); + itkGetConstMacro( AffineMaxIterations, unsigned int ); + + itkSetMacro( AffineMetricMethodEnum, MetricMethodEnumType ); + itkGetConstMacro( AffineMetricMethodEnum, MetricMethodEnumType ); + + itkGetConstObjectMacro( AffineTransform, AffineTransformType ); + itkGetMacro( AffineMetricValue, double ); + + itkSetObjectMacro( Observer, Command ); + itkGetModifiableObjectMacro( Observer, Command ); + +protected: + + SpatialObjectToImageRegistrationHelper( void ); + virtual ~SpatialObjectToImageRegistrationHelper( void ); + + void PrintSelfHelper( std::ostream & os, Indent indent, + const std::string & basename, MetricMethodEnumType metric ) const; + + void PrintSelf( std::ostream & os, Indent indent ) const override; + +private: + + template< int tmpImageDimension > + void AffineRegND() + { typename Image< double, tmpImageDimension >::Pointer t; AffineRegND( t ); } + + void AffineRegND( Image< double, 2 > * t ); + + void AffineRegND( Image< double, 3 > * t ); + + typedef typename InitialRegistrationMethodType::LandmarkPointType + LandmarkPointType; + typedef typename InitialRegistrationMethodType::LandmarkPointContainer + LandmarkPointContainer; + + // Purposely not implemented + SpatialObjectToImageRegistrationHelper( const Self & ); + // Purposely not implemented + void operator =( const Self & ); + + // Data + typename ImageType::ConstPointer m_FixedImage; + typename SpatialObjectType::ConstPointer m_MovingSpatialObject; + + bool m_UseFixedImageMaskObject; + typename ImageMaskObjectType::ConstPointer m_FixedImageMaskObject; + + bool m_UseMovingSpatialObjectMaskObject; + typename SpatialObjectMaskObjectType::ConstPointer + m_MovingSpatialObjectMaskObject; + + unsigned int m_RandomNumberSeed; + + // Process + bool m_EnableLoadedRegistration; + bool m_EnableInitialRegistration; + bool m_EnableRigidRegistration; + bool m_EnableAffineRegistration; + + double m_ExpectedOffsetMagnitude; + double m_ExpectedRotationMagnitude; + double m_ExpectedScaleMagnitude; + double m_ExpectedSkewMagnitude; + + bool m_CompletedInitialization; + RegistrationStageEnumType m_CompletedStage; + bool m_CompletedResampling; + + typename SpatialObjectType::ConstPointer m_CurrentMovingSpatialObject; + typename MatrixTransformType::Pointer m_CurrentMatrixTransform; + + typename SpatialObjectType::ConstPointer m_LoadedTransformResampledSpatialObject; + typename SpatialObjectType::ConstPointer m_MatrixTransformResampledSpatialObject; + + double m_FinalMetricValue; + + bool m_ReportProgress; + + // Optimizer + bool m_UseEvolutionaryOptimization; + + // Loaded Tansform + typename MatrixTransformType::Pointer m_LoadedMatrixTransform; + + // Initial Parameters + InitialMethodEnumType m_InitialMethodEnum; + typename InitialTransformType::Pointer m_InitialTransform; + + LandmarkPointContainer m_FixedLandmarks; + LandmarkPointContainer m_MovingLandmarks; + + // Rigid Parameters + double m_RigidSamplingRatio; + double m_RigidTargetError; + unsigned int m_RigidMaxIterations; + + typename RigidTransformType::Pointer m_RigidTransform; + MetricMethodEnumType m_RigidMetricMethodEnum; + + double m_RigidMetricValue; + + // Affine Parameters + double m_AffineSamplingRatio; + double m_AffineTargetError; + unsigned int m_AffineMaxIterations; + + typename AffineTransformType::Pointer m_AffineTransform; + MetricMethodEnumType m_AffineMetricMethodEnum; + + double m_AffineMetricValue; + + Command::Pointer m_Observer; + +}; + +} // tube + +} // itk + +#ifndef ITK_MANUAL_INSTANTIATION +#include "itktubeSpatialObjectToImageRegistrationHelper.hxx" +#endif + +#endif diff --git a/src/Registration/itktubeSpatialObjectToImageRegistrationHelper.hxx b/src/Registration/itktubeSpatialObjectToImageRegistrationHelper.hxx new file mode 100644 index 000000000..f19f4f798 --- /dev/null +++ b/src/Registration/itktubeSpatialObjectToImageRegistrationHelper.hxx @@ -0,0 +1,1133 @@ +/*========================================================================= + +Library: TubeTK + +Copyright Kitware Inc. + +All rights reserved. + +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. + +=========================================================================*/ + +#ifndef __itktubeSpatialObjectToImageRegistrationHelper_txx +#define __itktubeSpatialObjectToImageRegistrationHelper_txx + +#include "itktubeSpatialObjectToImageRegistrationHelper.h" + +#include "itktubePointBasedSpatialObjectTransformFilter.h" + +#include "itkTransformFileReader.h" +#include "itkTransformFileWriter.h" + +#include "itkVector.h" +#include "itkAffineTransform.h" + +namespace itk +{ + +namespace tube +{ + +template +SpatialObjectToImageRegistrationHelper +::SpatialObjectToImageRegistrationHelper() +{ + // Data + m_FixedImage = NULL; + m_MovingSpatialObject = NULL; + + // Masks + m_UseFixedImageMaskObject = false; + m_FixedImageMaskObject = NULL; + m_UseMovingSpatialObjectMaskObject = false; + m_MovingSpatialObjectMaskObject = NULL; + + m_RandomNumberSeed = 0; + + // Process + m_EnableLoadedRegistration = true; + m_EnableInitialRegistration = true; + m_EnableRigidRegistration = true; + m_EnableAffineRegistration = false; + + // Expected transform magnitude + m_ExpectedOffsetMagnitude = 5; + m_ExpectedRotationMagnitude = 0.01; + m_ExpectedScaleMagnitude = 0.01; + m_ExpectedSkewMagnitude = 0.0001; + + // Current state of the registration pipeline + m_CompletedInitialization = false; + m_CompletedStage = PRE_STAGE; + m_CompletedResampling = false; + + m_CurrentMovingSpatialObject = NULL; + m_CurrentMatrixTransform = NULL; + + m_LoadedTransformResampledSpatialObject = NULL; + m_MatrixTransformResampledSpatialObject = NULL; + + // Results + m_FinalMetricValue = 0.0; + + // Progress + m_ReportProgress = false; + + // Optimizer + m_UseEvolutionaryOptimization = true ; + + // Loaded + m_LoadedMatrixTransform = NULL; + + // Initial + m_InitialMethodEnum = INIT_WITH_NONE; + m_InitialTransform = NULL; + + // Rigid + m_RigidSamplingRatio = 0.05; + m_RigidTargetError = 0.0001; + m_RigidMaxIterations = 1000; + m_RigidTransform = NULL; + m_RigidMetricMethodEnum = + OptimizedRegistrationMethodType::IMAGE_INTENSITY_METRIC; + m_RigidMetricValue = 0.0; + + // Affine + m_AffineSamplingRatio = 0.1; + m_AffineTargetError = 0.0001; + m_AffineMaxIterations = 500; + m_AffineTransform = NULL; + m_AffineMetricMethodEnum = OptimizedRegistrationMethodType::IMAGE_INTENSITY_METRIC; + m_AffineMetricValue = 0.0; + + m_Observer = nullptr; +} + +template +SpatialObjectToImageRegistrationHelper +::~SpatialObjectToImageRegistrationHelper() +{ +} + +template +void +SpatialObjectToImageRegistrationHelper +::SetFixedImage( const TImage * fixedImage ) +{ + if( this->m_FixedImage.GetPointer() != fixedImage ) + { + this->m_FixedImage = fixedImage; + + this->Modified(); + + m_CompletedStage = PRE_STAGE; + + m_CompletedInitialization = false; + m_CompletedResampling = false; + } +} + +template +void +SpatialObjectToImageRegistrationHelper +::SetMovingSpatialObject( const SpatialObjectType * movingSpatialObject ) +{ + if( this->m_MovingSpatialObject.GetPointer() != movingSpatialObject ) + { + this->m_MovingSpatialObject = movingSpatialObject; + + this->Modified(); + + m_CompletedStage = PRE_STAGE; + + m_CompletedInitialization = false; + m_CompletedResampling = false; + } +} + +template +void +SpatialObjectToImageRegistrationHelper +::SetFixedImageMaskObject( const ImageMaskObjectType * maskObject ) +{ + if( this->m_FixedImageMaskObject.GetPointer() != maskObject ) + { + this->m_FixedImageMaskObject = maskObject; + + this->Modified(); + + if( maskObject != NULL ) + { + m_UseFixedImageMaskObject = true; + } + else + { + m_UseFixedImageMaskObject = false; + } + } +} + +template +void +SpatialObjectToImageRegistrationHelper +::SetMovingSpatialObjectMaskObject( const SpatialObjectMaskObjectType * + maskObject ) +{ + if( this->m_MovingSpatialObjectMaskObject.GetPointer() != maskObject ) + { + this->m_MovingSpatialObjectMaskObject = maskObject; + + this->Modified(); + + if( maskObject != NULL ) + { + m_UseMovingSpatialObjectMaskObject = true; + } + else + { + m_UseMovingSpatialObjectMaskObject = false; + } + } +} + +template +void +SpatialObjectToImageRegistrationHelper +::SetRegistration( RegistrationMethodEnumType reg ) +{ + switch(reg) + { + default: + case NONE: + { + this->SetEnableInitialRegistration(false); + this->SetEnableRigidRegistration(false); + this->SetEnableAffineRegistration(false); + break; + } + case INITIAL: + { + this->SetEnableInitialRegistration(true); + this->SetEnableRigidRegistration(false); + this->SetEnableAffineRegistration(false); + break; + } + case RIGID: + { + this->SetEnableInitialRegistration(false); + this->SetEnableRigidRegistration(true); + this->SetEnableAffineRegistration(false); + break; + } + case AFFINE: + { + this->SetEnableInitialRegistration(false); + this->SetEnableRigidRegistration(false); + this->SetEnableAffineRegistration(true); + break; + } + case PIPELINE_RIGID: + { + this->SetEnableInitialRegistration(true); + this->SetEnableRigidRegistration(true); + this->SetEnableAffineRegistration(false); + break; + } + case PIPELINE_AFFINE: + { + this->SetEnableInitialRegistration(true); + this->SetEnableRigidRegistration(true); + this->SetEnableAffineRegistration(true); + break; + } + } +} + +template +void +SpatialObjectToImageRegistrationHelper +::SetMetric( MetricMethodEnumType metric ) +{ + this->SetRigidMetricMethodEnum( metric ); + this->SetAffineMetricMethodEnum( metric ); +} + +template +void +SpatialObjectToImageRegistrationHelper +::Initialize( void ) +{ + // m_LoadedTransform = 0; Not Initialized - since it is a user parameter + m_InitialTransform = 0; + m_RigidTransform = 0; + m_AffineTransform = 0; + + m_CompletedStage = PRE_STAGE; + + m_CompletedInitialization = true; + m_CompletedResampling = false; + + m_CurrentMatrixTransform = 0; + + m_FinalMetricValue = 0; + m_RigidMetricValue = 0; + m_AffineMetricValue = 0; + + if( m_InitialMethodEnum == INIT_WITH_CURRENT_RESULTS ) + { + m_CurrentMovingSpatialObject = GetFinalMovingSpatialObject(); + } + else + { + m_CurrentMovingSpatialObject = m_MovingSpatialObject; + } + + m_LoadedTransformResampledSpatialObject = 0; + m_MatrixTransformResampledSpatialObject = 0; +} + +template +void +SpatialObjectToImageRegistrationHelper +::AffineRegND( Image< double, 2 > * itkNotUsed( tmpImage ) ) +{ + if( this->GetReportProgress() ) + { + std::cout << "*** AFFINE REGISTRATION ***" << std::endl; + } + + typename Affine2DRegistrationMethodType::Pointer regAff + = Affine2DRegistrationMethodType::New(); + if( this->GetObserver() ) + { + regAff->SetObserver( this->GetObserver() ); + } + regAff->SetRandomNumberSeed( m_RandomNumberSeed ); + regAff->SetReportProgress( m_ReportProgress ); + regAff->SetMovingSpatialObject( m_CurrentMovingSpatialObject ); + regAff->SetFixedImage( m_FixedImage ); + regAff->SetSamplingRatio( m_AffineSamplingRatio ); + regAff->SetMaxIterations( m_AffineMaxIterations ); + regAff->SetTargetError( m_AffineTargetError ); + if( m_EnableRigidRegistration || !m_UseEvolutionaryOptimization ) + { + regAff->SetUseEvolutionaryOptimization( false ); + } + regAff->SetTargetError( m_AffineTargetError ); + if( m_UseFixedImageMaskObject ) + { + if( m_FixedImageMaskObject.IsNotNull() ) + { + regAff->SetFixedImageMaskObject( m_FixedImageMaskObject ); + } + } + if( m_UseMovingSpatialObjectMaskObject ) + { + if( m_MovingSpatialObjectMaskObject.IsNotNull() ) + { + regAff->SetMovingSpatialObjectMaskObject( m_MovingSpatialObjectMaskObject ); + } + } + regAff->SetMetricMethodEnum( m_AffineMetricMethodEnum ); + + typename AffineTransformType::ParametersType scales; + scales.set_size( 7 ); + unsigned int scaleNum = 0; + scales[scaleNum++] = 1.0 / ( m_ExpectedRotationMagnitude ); + scales[scaleNum++] = 1.0 / ( m_ExpectedOffsetMagnitude ); + scales[scaleNum++] = 1.0 / ( m_ExpectedOffsetMagnitude ); + scales[scaleNum++] = 1.0 / ( m_ExpectedScaleMagnitude ); + scales[scaleNum++] = 1.0 / ( m_ExpectedScaleMagnitude ); + scales[scaleNum++] = 1.0 / ( m_ExpectedSkewMagnitude ); + scales[scaleNum++] = 1.0 / ( m_ExpectedSkewMagnitude ); + regAff->SetTransformParametersScales( scales ); + + if( m_CurrentMatrixTransform.IsNotNull() ) + { + regAff->GetTypedTransform()->SetCenter( + m_CurrentMatrixTransform->GetCenter() ); + regAff->GetTypedTransform()->SetMatrix( + m_CurrentMatrixTransform->GetMatrix() ); + regAff->GetTypedTransform()->SetOffset( + m_CurrentMatrixTransform->GetOffset() ); + regAff->SetInitialTransformFixedParameters( + regAff->GetTypedTransform()->GetFixedParameters() ); + regAff->SetInitialTransformParameters( + regAff->GetTypedTransform()->GetParameters() ); + } + + regAff->Update(); + + m_AffineTransform = regAff->GetAffineTransform(); + m_CurrentMatrixTransform = m_AffineTransform; + + m_FinalMetricValue = regAff->GetFinalMetricValue(); + m_AffineMetricValue = m_FinalMetricValue; + + m_CompletedStage = AFFINE_STAGE; + m_CompletedResampling = false; +} + +template +void +SpatialObjectToImageRegistrationHelper +::AffineRegND( Image< double, 3 > * itkNotUsed( tmpImage ) ) +{ + if( this->GetReportProgress() ) + { + std::cout << "*** AFFINE REGISTRATION ***" << std::endl; + } + + typename Affine3DRegistrationMethodType::Pointer regAff = + Affine3DRegistrationMethodType::New(); + if( this->GetObserver() ) + { + regAff->SetObserver( this->GetObserver() ); + } + regAff->SetRandomNumberSeed( m_RandomNumberSeed ); + regAff->SetReportProgress( m_ReportProgress ); + regAff->SetMovingSpatialObject( m_CurrentMovingSpatialObject ); + regAff->SetFixedImage( m_FixedImage ); + regAff->SetSamplingRatio( m_AffineSamplingRatio ); + regAff->SetMaxIterations( m_AffineMaxIterations ); + regAff->SetTargetError( m_AffineTargetError ); + if( m_EnableRigidRegistration || !m_UseEvolutionaryOptimization ) + { + regAff->SetUseEvolutionaryOptimization( false ); + } + regAff->SetTargetError( m_AffineTargetError ); + if( m_UseFixedImageMaskObject ) + { + if( m_FixedImageMaskObject.IsNotNull() ) + { + regAff->SetFixedImageMaskObject( m_FixedImageMaskObject ); + } + } + if( m_UseMovingSpatialObjectMaskObject ) + { + if( m_MovingSpatialObjectMaskObject.IsNotNull() ) + { + regAff->SetMovingSpatialObjectMaskObject( m_MovingSpatialObjectMaskObject ); + } + } + regAff->SetMetricMethodEnum( m_AffineMetricMethodEnum ); + + typename AffineTransformType::ParametersType scales; + scales.set_size( 12 ); + unsigned int scaleNum = 0; + scales[scaleNum++] = 1.0 / ( m_ExpectedRotationMagnitude ); + scales[scaleNum++] = 1.0 / ( m_ExpectedRotationMagnitude ); + scales[scaleNum++] = 1.0 / ( m_ExpectedRotationMagnitude ); + scales[scaleNum++] = 1.0 / ( m_ExpectedOffsetMagnitude ); + scales[scaleNum++] = 1.0 / ( m_ExpectedOffsetMagnitude ); + scales[scaleNum++] = 1.0 / ( m_ExpectedOffsetMagnitude ); + scales[scaleNum++] = 1.0 / ( m_ExpectedScaleMagnitude ); + scales[scaleNum++] = 1.0 / ( m_ExpectedScaleMagnitude ); + scales[scaleNum++] = 1.0 / ( m_ExpectedScaleMagnitude ); + scales[scaleNum++] = 1.0 / ( m_ExpectedSkewMagnitude ); + scales[scaleNum++] = 1.0 / ( m_ExpectedSkewMagnitude ); + scales[scaleNum++] = 1.0 / ( m_ExpectedSkewMagnitude ); + regAff->SetTransformParametersScales( scales ); + + if( m_CurrentMatrixTransform.IsNotNull() ) + { + regAff->GetTypedTransform()->SetCenter( + m_CurrentMatrixTransform->GetCenter() ); + regAff->GetTypedTransform()->SetMatrix( + m_CurrentMatrixTransform->GetMatrix() ); + regAff->GetTypedTransform()->SetOffset( + m_CurrentMatrixTransform->GetOffset() ); + regAff->SetInitialTransformFixedParameters( + regAff->GetTypedTransform()->GetFixedParameters() ); + regAff->SetInitialTransformParameters( + regAff->GetTypedTransform()->GetParameters() ); + } + + regAff->Update(); + + m_AffineTransform = regAff->GetAffineTransform(); + m_CurrentMatrixTransform = m_AffineTransform; + + m_FinalMetricValue = regAff->GetFinalMetricValue(); + m_AffineMetricValue = m_FinalMetricValue; + + m_CompletedStage = AFFINE_STAGE; + m_CompletedResampling = false; +} + +/** This class provides an Update() method to fit the appearance of a + * ProcessObject API, but it is not a ProcessObject. */ +template +void +SpatialObjectToImageRegistrationHelper +::Update( void ) +{ + if( !(this->m_CompletedInitialization) ) + { + this->Initialize(); + } + + std::cout << "HERE" << std::endl; + if( m_EnableLoadedRegistration + && m_LoadedMatrixTransform.IsNotNull() ) + { + if( m_LoadedTransformResampledSpatialObject.IsNotNull() ) + { + m_CurrentMovingSpatialObject = m_LoadedTransformResampledSpatialObject; + if( this->GetReportProgress() ) + { + std::cout << "*** Using existing loaded transform ***" << std::endl; + } + } + + m_MatrixTransformResampledSpatialObject = 0; + + m_CompletedStage = LOAD_STAGE; + m_CompletedResampling = true; + + m_CurrentMatrixTransform = 0; + } + + std::cout << "HERE1" << std::endl; + if( this->GetReportProgress() ) + { + std::cout << "*** INITIAL REGISTRATION ***" << std::endl; + } + + typename InitialRegistrationMethodType::Pointer regInit = + InitialRegistrationMethodType::New(); + if( this->GetObserver() ) + { + regInit->SetObserver( this->GetObserver() ); + } + regInit->SetReportProgress( m_ReportProgress ); + regInit->SetMovingSpatialObject( m_CurrentMovingSpatialObject ); + regInit->SetFixedImage( m_FixedImage ); + if( m_UseFixedImageMaskObject ) + { + if( m_FixedImageMaskObject.IsNotNull() ) + { + regInit->SetFixedImageMaskObject( m_FixedImageMaskObject ); + } + } + if( m_UseMovingSpatialObjectMaskObject ) + { + if( m_MovingSpatialObjectMaskObject.IsNotNull() ) + { + regInit->SetMovingSpatialObjectMaskObject( m_MovingSpatialObjectMaskObject ); + } + } + std::cout << "HERE2" << std::endl; + if( m_EnableInitialRegistration ) + { + switch( m_InitialMethodEnum ) + { + case INIT_WITH_NONE: + regInit->SetComputeCenterOfRotationOnly( true ); + break; + case INIT_WITH_IMAGE_CENTERS: + regInit->SetNumberOfMoments( 0 ); + break; + case INIT_WITH_CENTERS_OF_MASS: + regInit->SetNumberOfMoments( 1 ); + break; + case INIT_WITH_LANDMARKS: + regInit->SetUseLandmarks( true ); + regInit->SetFixedLandmarks( m_FixedLandmarks ); + regInit->SetMovingLandmarks( m_MovingLandmarks ); + break; + case INIT_WITH_CURRENT_RESULTS: + default: + break; + } + std::cout << "RH: Update: InitialReg" << std::endl; + regInit->Update(); + m_InitialTransform = regInit->GetAffineTransform(); + } + else + { + if( m_EnableLoadedRegistration + && m_LoadedMatrixTransform.IsNotNull() ) + { + m_InitialTransform = m_LoadedMatrixTransform; + } + else + { + regInit->SetComputeCenterOfRotationOnly( true ); + regInit->Update(); + m_InitialTransform = regInit->GetAffineTransform(); + } + } + + std::cout << "RH: Update: Init done" << std::endl; + m_CurrentMatrixTransform = m_InitialTransform; + + m_CompletedStage = INIT_STAGE; + m_CompletedResampling = false; + + if( m_EnableRigidRegistration ) + { + std::cout << "RH: Update: registration" << std::endl; + if( this->GetReportProgress() ) + { + std::cout << "*** RIGID REGISTRATION ***" << std::endl; + } + + typename RigidRegistrationMethodType::Pointer regRigid = + RigidRegistrationMethodType::New(); + if( this->GetObserver() ) + { + regRigid->SetObserver( this->GetObserver() ); + } + regRigid->SetRandomNumberSeed( m_RandomNumberSeed ); + if( !m_UseEvolutionaryOptimization ) + { + regRigid->SetUseEvolutionaryOptimization( false ); + } + regRigid->SetReportProgress( m_ReportProgress ); + regRigid->SetMovingSpatialObject( m_CurrentMovingSpatialObject ); + regRigid->SetFixedImage( m_FixedImage ); + regRigid->SetSamplingRatio( m_RigidSamplingRatio ); + regRigid->SetMaxIterations( m_RigidMaxIterations ); + regRigid->SetTargetError( m_RigidTargetError ); + if( m_UseFixedImageMaskObject ) + { + if( m_FixedImageMaskObject.IsNotNull() ) + { + regRigid->SetFixedImageMaskObject( m_FixedImageMaskObject ); + } + } + if( m_UseMovingSpatialObjectMaskObject ) + { + if( m_MovingSpatialObjectMaskObject.IsNotNull() ) + { + regRigid->SetMovingSpatialObjectMaskObject( m_MovingSpatialObjectMaskObject ); + } + } + regRigid->SetMetricMethodEnum( m_RigidMetricMethodEnum ); + typename RigidTransformType::ParametersType scales; + if( ImageDimension == 2 ) + { + scales.set_size( 3 ); + scales[0] = 1.0 / m_ExpectedRotationMagnitude; + scales[1] = 1.0 / m_ExpectedOffsetMagnitude; + scales[2] = 1.0 / m_ExpectedOffsetMagnitude; + } + else if( ImageDimension == 3 ) + { + scales.set_size( 6 ); + scales[0] = 1.0 / m_ExpectedRotationMagnitude; + scales[1] = 1.0 / m_ExpectedRotationMagnitude; + scales[2] = 1.0 / m_ExpectedRotationMagnitude; + scales[3] = 1.0 / m_ExpectedOffsetMagnitude; + scales[4] = 1.0 / m_ExpectedOffsetMagnitude; + scales[5] = 1.0 / m_ExpectedOffsetMagnitude; + } + else + { + std::cerr + << "ERROR: Only 2 and 3 dimensional images are supported." + << std::endl; + } + regRigid->SetTransformParametersScales( scales ); + + std::cout << "RH: Update: set transform parameters scales" << std::endl; + if( m_CurrentMatrixTransform.IsNotNull() ) + { + regRigid->GetTypedTransform()->SetCenter( + m_CurrentMatrixTransform->GetCenter() ); + regRigid->GetTypedTransform()->SetMatrix( + m_CurrentMatrixTransform->GetMatrix() ); + regRigid->GetTypedTransform()->SetOffset( + m_CurrentMatrixTransform->GetOffset() ); + regRigid->SetInitialTransformFixedParameters( + regRigid->GetTypedTransform()->GetFixedParameters() ); + regRigid->SetInitialTransformParameters( + regRigid->GetTypedTransform()->GetParameters() ); + } + + std::cout << "RH: Update: update" << std::endl; + regRigid->Update(); + std::cout << "RH: Update: update done" << std::endl; + + m_RigidTransform = RigidTransformType::New(); + m_RigidTransform->SetFixedParameters( + regRigid->GetTypedTransform()->GetFixedParameters() ); + // Rigid transform is stored as a matrix+offset (affine) transform + // because no rigid transform is templated over dimension. + // See itktubeRigidSpatialObjectToImageRegistrationMethod class. + m_RigidTransform->SetParametersByValue( + regRigid->GetAffineTransform()->GetParameters() ); + m_CurrentMatrixTransform = regRigid->GetAffineTransform(); + + m_FinalMetricValue = regRigid->GetFinalMetricValue(); + m_RigidMetricValue = m_FinalMetricValue; + + m_CompletedStage = RIGID_STAGE; + m_CompletedResampling = false; + } + + std::cout << "RH: Update: done" << std::endl; + + if( m_EnableAffineRegistration ) + { + std::cout << "RH: Update: affine" << std::endl; + this->AffineRegND(); + } +} + +template +const SpatialObject * +SpatialObjectToImageRegistrationHelper +::ResampleSpatialObject( const SpatialObjectType * movingSpatialObject, + const MatrixTransformType * matrixTransform, double portion) +{ + typedef PointBasedSpatialObjectTransformFilter ResampleFilterType; + + if( movingSpatialObject == NULL + && matrixTransform == NULL + && portion == 1.0 + && m_CompletedResampling ) + { + return m_CurrentMovingSpatialObject.GetPointer(); + } + + bool doLoaded = false; + bool doMatrix = false; + + switch( m_CompletedStage ) + { + default: + case PRE_STAGE: + break; + case LOAD_STAGE: + doLoaded = true; + break; + case INIT_STAGE: + case RIGID_STAGE: + case AFFINE_STAGE: + doMatrix = true; + break; + } + + typename SpatialObjectType::ConstPointer inputSO = + m_CurrentMovingSpatialObject; + if( movingSpatialObject != NULL ) + { + inputSO = movingSpatialObject; + + //doLoaded = true; + //doMatrix = true; + } + + typename AffineTransformType::ConstPointer aTrans = + m_CurrentMatrixTransform.GetPointer(); + if( matrixTransform != NULL ) + { + doLoaded = false; + doMatrix = false; + + if( matrixTransform != NULL ) + { + aTrans = matrixTransform; + doMatrix = true; + } + } + + if( doMatrix && aTrans.IsNotNull() ) + { + if( this->GetReportProgress() ) + { + std::cout << "Resampling using matrix." << std::endl; + } + // Register using Matrix + typename ResampleFilterType::Pointer resampler = ResampleFilterType::New(); + resampler->SetInput( inputSO ); + typename MatrixTransformType::Pointer tmpTrans = MatrixTransformType::New(); + tmpTrans->SetIdentity(); + tmpTrans->SetFixedParameters( aTrans->GetFixedParameters() ); + if( portion != 1.0 ) + { + typename MatrixTransformType::ParametersType aTransParams = + aTrans->GetParameters(); + typename MatrixTransformType::ParametersType tmpParams = + tmpTrans->GetParameters(); + std::cout << "Original params = " << aTransParams << std::endl; + for( unsigned int p=0; pSetParameters( tmpParams ); + std::cout << "portion params = " << tmpParams << std::endl; + } + else + { + tmpTrans->SetParameters( aTrans->GetParameters() ); + } + resampler->SetTransform( tmpTrans ); + resampler->Update(); + m_MatrixTransformResampledSpatialObject = resampler->GetOutput(); + if( movingSpatialObject == NULL + && matrixTransform == NULL + && portion == 1.0 ) + { + m_CurrentMovingSpatialObject = resampler->GetOutput(); + m_CompletedResampling = true; + } + } + + m_CurrentMovingSpatialObject->Register(); + return m_CurrentMovingSpatialObject.GetPointer(); +} + +template +const SpatialObject * +SpatialObjectToImageRegistrationHelper +::GetFinalMovingSpatialObject( void ) +{ + return ResampleSpatialObject(); +} + +template +void +SpatialObjectToImageRegistrationHelper +::LoadParameters( const std::string & itkNotUsed(filename) ) +{ +} + +template +void +SpatialObjectToImageRegistrationHelper +::SaveParameters( const std::string & itkNotUsed(filename) ) +{ +} + +template +void +SpatialObjectToImageRegistrationHelper +::LoadTransform( const std::string & filename, bool invert ) +{ + typedef TransformFileReader TransformReaderType; + typedef TransformReaderType::TransformListType TransformListType; + + TransformReaderType::Pointer transformReader = TransformReaderType::New(); + transformReader->SetFileName( filename ); + + transformReader->Update(); + + const TransformListType *transforms = transformReader->GetTransformList(); + TransformListType::const_iterator transformIt = transforms->begin(); + while( transformIt != transforms->end() ) + { + if( !strcmp( (*transformIt)->GetNameOfClass(), "AffineTransform") ) + { + typename MatrixTransformType::Pointer affine_read = + static_cast( (*transformIt).GetPointer() ); + typename MatrixTransformType::ConstPointer affine = + affine_read.GetPointer(); + SetLoadedMatrixTransform( *affine.GetPointer(), invert ); + } + + ++transformIt; + } +} + +template +void +SpatialObjectToImageRegistrationHelper +::SaveTransform( const std::string & filename ) +{ + typedef TransformFileWriter TransformWriterType; + + TransformWriterType::Pointer transformWriter = TransformWriterType::New(); + transformWriter->SetFileName( filename ); + + if( m_CurrentMatrixTransform.IsNotNull() ) + { + transformWriter->SetInput( m_CurrentMatrixTransform ); + transformWriter->Update(); + } +} + +template +void +SpatialObjectToImageRegistrationHelper +::SetLoadedMatrixTransform( const MatrixTransformType & tfm, bool invert ) +{ + m_LoadedMatrixTransform = MatrixTransformType::New(); + m_LoadedMatrixTransform->SetIdentity(); + m_LoadedMatrixTransform->SetFixedParameters( tfm.GetFixedParameters() ); + m_LoadedMatrixTransform->SetCenter( tfm.GetCenter() ); + m_LoadedMatrixTransform->SetMatrix( tfm.GetMatrix() ); + m_LoadedMatrixTransform->SetOffset( tfm.GetOffset() ); + if( invert ) + { + std::cout << "GetInverseTransform" << std::endl; + typename MatrixTransformType::Pointer invTfm = MatrixTransformType::New(); + m_LoadedMatrixTransform->GetInverse( invTfm ); + m_LoadedMatrixTransform = invTfm; + } + + m_EnableLoadedRegistration = true; + m_LoadedTransformResampledSpatialObject = 0; + m_CurrentMovingSpatialObject = m_MovingSpatialObject; +} + +template +void +SpatialObjectToImageRegistrationHelper +::SetFixedLandmarks( const std::vector > & fixedLandmarks ) +{ + m_FixedLandmarks.clear(); + for( std::vector >::const_iterator i = + fixedLandmarks.begin(); + i != fixedLandmarks.end(); ++i ) + { + LandmarkPointType landmark; + std::copy(i->begin(), i->end(), landmark.Begin() ); + m_FixedLandmarks.push_back(landmark); + } +} + +template +void +SpatialObjectToImageRegistrationHelper +::SetMovingLandmarks( const std::vector > & movingLandmarks ) +{ + m_MovingLandmarks.clear(); + for( std::vector >::const_iterator i = + movingLandmarks.begin(); + i != movingLandmarks.end(); ++i ) + { + LandmarkPointType landmark; + std::copy(i->begin(), i->end(), landmark.Begin() ); + m_MovingLandmarks.push_back(landmark); + } +} + +template +void +SpatialObjectToImageRegistrationHelper +::PrintSelfHelper( std::ostream & os, Indent indent, + const std::string & basename, + MetricMethodEnumType metric ) const +{ + switch( metric ) + { + case OptimizedRegistrationMethodType::IMAGE_INTENSITY_METRIC: + os << indent << basename << " Metric Method = IMAGE_INTENSITY_METRIC" + << std::endl; + break; + default: + os << indent << basename << " Metric Method = UNKNOWN" << std::endl; + break; + } + os << indent << std::endl; +} + +template +void +SpatialObjectToImageRegistrationHelper +::PrintSelf( std::ostream & os, Indent indent ) const +{ + Superclass::PrintSelf( os, indent ); + + if( m_FixedImage.IsNotNull() ) + { + os << indent << "Fixed Image = " << m_FixedImage << std::endl; + } + if( m_MovingSpatialObject.IsNotNull() ) + { + os << indent << "Moving SpatialObject = " << m_MovingSpatialObject << std::endl; + } + os << indent << std::endl; + os << indent << "Use Fixed Image Mask Object = " + << m_UseFixedImageMaskObject << std::endl; + os << indent << std::endl; + if( m_FixedImageMaskObject.IsNotNull() ) + { + os << indent << "Fixed Image Mask Object = " << m_FixedImageMaskObject + << std::endl; + } + os << indent << "Use Moving SpatialObject Mask Object = " + << m_UseMovingSpatialObjectMaskObject << std::endl; + os << indent << std::endl; + if( m_MovingSpatialObjectMaskObject.IsNotNull() ) + { + os << indent << "Moving SpatialObject Mask Object = " + << m_MovingSpatialObjectMaskObject << std::endl; + } + os << indent << std::endl; + os << indent << "Random Number Seed = " << m_RandomNumberSeed + << std::endl; + os << indent << std::endl; + os << indent << "Enable Loaded Registration = " + << m_EnableLoadedRegistration << std::endl; + os << indent << "Enable Initial Registration = " + << m_EnableInitialRegistration << std::endl; + os << indent << "Enable Rigid Registration = " + << m_EnableRigidRegistration << std::endl; + os << indent << "Enable Affine Registration = " + << m_EnableAffineRegistration << std::endl; + os << indent << std::endl; + os << indent << "Expected Offset (in Pixels) Magnitude = " + << m_ExpectedOffsetMagnitude << std::endl; + os << indent << "Expected Rotation Magnitude = " + << m_ExpectedRotationMagnitude << std::endl; + os << indent << "Expected Scale Magnitude = " << m_ExpectedScaleMagnitude + << std::endl; + os << indent << "Expected Skew Magnitude = " << m_ExpectedSkewMagnitude + << std::endl; + os << indent << "Completed Initialization = " + << m_CompletedInitialization << std::endl; + os << indent << "Completed Resampling = " << m_CompletedResampling + << std::endl; + os << indent << std::endl; + os << indent << "Rigid Metric Value = " << m_RigidMetricValue + << std::endl; + os << indent << "Affine Metric Value = " << m_AffineMetricValue + << std::endl; + os << indent << "Final Metric Value = " << m_FinalMetricValue + << std::endl; + os << indent << std::endl; + os << indent << "Report Progress = " << m_ReportProgress << std::endl; + os << indent << std::endl; + if( m_CurrentMovingSpatialObject.IsNotNull() ) + { + os << indent << "Current Moving SpatialObject = " << m_CurrentMovingSpatialObject + << std::endl; + } + else + { + os << indent << "Current Moving SpatialObject = NULL" << std::endl; + } + if( m_CurrentMatrixTransform.IsNotNull() ) + { + os << indent << "Current Matrix Transform = " + << m_CurrentMatrixTransform << std::endl; + } + else + { + os << indent << "Current Matrix Transform = NULL" << std::endl; + } + os << indent << std::endl; + if( m_LoadedTransformResampledSpatialObject.IsNotNull() ) + { + os << indent << "Loaded Transform Resampled SpatialObject = " + << m_LoadedTransformResampledSpatialObject << std::endl; + } + else + { + os << indent << "Loaded Transform Resampled SpatialObject = NULL" << std::endl; + } + if( m_MatrixTransformResampledSpatialObject.IsNotNull() ) + { + os << indent << "Matrix Transform Resampled SpatialObject = " + << m_MatrixTransformResampledSpatialObject << std::endl; + } + else + { + os << indent << "Matrix Transform Resampled SpatialObject = NULL" << std::endl; + } + os << indent << std::endl; + if( m_LoadedMatrixTransform.IsNotNull() ) + { + os << indent << "Loaded Matrix Transform = " << m_LoadedMatrixTransform + << std::endl; + } + else + { + os << indent << "Loaded Matrix Transform = NULL" << std::endl; + } + os << indent << std::endl; + + switch( m_InitialMethodEnum ) + { + case INIT_WITH_NONE: + os << indent << "Initial Registration Enum = INIT_WITH_NONE" + << std::endl; + break; + case INIT_WITH_CURRENT_RESULTS: + os << indent + << "Initial Registration Enum = INIT_WITH_CURRENT_RESULTS" + << std::endl; + break; + case INIT_WITH_IMAGE_CENTERS: + os << indent + << "Initial Registration Enum = INIT_WITH_IMAGE_CENTERS" + << std::endl; + break; + case INIT_WITH_CENTERS_OF_MASS: + os << indent + << "Initial Registration Enum = INIT_WITH_CENTERS_OF_MASS" + << std::endl; + break; + default: + os << indent << "Initial Registration Enum = UNKNOWN" << std::endl; + break; + } + if( m_InitialTransform.IsNotNull() ) + { + os << indent << "Initial Transform = " << m_InitialTransform + << std::endl; + } + else + { + os << indent << "Initial Transform = NULL" << std::endl; + } + os << indent << std::endl; + os << indent << "Rigid Sampling Ratio = " << m_RigidSamplingRatio + << std::endl; + os << indent << "Rigid Target Error = " << m_RigidTargetError + << std::endl; + os << indent << "Rigid Max Iterations = " << m_RigidMaxIterations + << std::endl; + PrintSelfHelper( os, indent, "Rigid", m_RigidMetricMethodEnum ); + os << indent << std::endl; + if( m_RigidTransform.IsNotNull() ) + { + os << indent << "Rigid Transform = " << m_RigidTransform << std::endl; + } + else + { + os << indent << "Rigid Transform = NULL" << std::endl; + } + os << indent << std::endl; + os << indent << "Affine Sampling Ratio = " << m_AffineSamplingRatio + << std::endl; + os << indent << "Affine Target Error = " << m_AffineTargetError + << std::endl; + os << indent << "Affine Max Iterations = " << m_AffineMaxIterations + << std::endl; + PrintSelfHelper( os, indent, "Affine", m_AffineMetricMethodEnum ); + os << indent << std::endl; + if( m_AffineTransform.IsNotNull() ) + { + os << indent << "Affine Transform = " << m_AffineTransform + << std::endl; + } + else + { + os << indent << "Affine Transform = NULL" << std::endl; + } + os << indent << std::endl; + +} + +}; // tube + +}; // itk + +#endif diff --git a/src/Registration/itktubeSpatialObjectToImageRegistrationMethod.h b/src/Registration/itktubeSpatialObjectToImageRegistrationMethod.h new file mode 100644 index 000000000..bdc4305d7 --- /dev/null +++ b/src/Registration/itktubeSpatialObjectToImageRegistrationMethod.h @@ -0,0 +1,185 @@ +/*========================================================================= + +Library: TubeTK + +Copyright Kitware Inc. + +All rights reserved. + +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. + +=========================================================================*/ + +#ifndef __itktubeSpatialObjectToImageRegistrationMethod_h +#define __itktubeSpatialObjectToImageRegistrationMethod_h + +#include "itkCommand.h" +#include "itkSpatialObject.h" +#include "itkDataobjectDecorator.h" + +namespace itk +{ + +namespace tube +{ + +/** \class SpatialObjectToImageRegistrationMethod base class for the registration + * methods. + * + * This class has a separate hierarchy from the ImageRegistrationMethod + * defined in ITK. The purpose of this class is to provide the common + * functionalities of a registration method in a context that is easy to + * use from the Registration Helper class that provides an even + * higher-level, user-friendly interface to a generic image registration + * problem. + * + */ +template +class SpatialObjectToImageRegistrationMethod + : public ProcessObject +{ + +public: + + typedef SpatialObjectToImageRegistrationMethod Self; + typedef ProcessObject Superclass; + typedef SmartPointer Pointer; + typedef SmartPointer ConstPointer; + + itkTypeMacro( SpatialObjectToImageRegistrationMethod, ProcessObject ); + + itkNewMacro( Self ); + + // + // Custom Typedefs + // + itkStaticConstMacro( ImageDimension, unsigned int, + TImage::ImageDimension ); + + typedef Transform TransformType; + + typedef DataObjectDecorator TransformOutputType; + + typedef typename DataObject::Pointer DataObjectPointer; + typedef Superclass::DataObjectPointerArraySizeType DataObjectPointerArraySizeType; + + typedef SpatialObject SpatialObjectType; + typedef TImage ImageType; + + typedef typename SpatialObjectType::PointType SpatialObjectPointType; + typedef typename ImageType::PointType PointType; + + typedef SpatialObject + ImageMaskObjectType; + + typedef SpatialObject< ObjectDimension > + SpatialObjectMaskObjectType; + + // + // Custom Methods + // + itkSetMacro( RegistrationNumberOfWorkUnits, unsigned int ); + itkGetMacro( RegistrationNumberOfWorkUnits, unsigned int ); + + itkSetObjectMacro( Observer, Command ); + itkGetModifiableObjectMacro( Observer, Command ); + + void SetFixedImage( const ImageType * fixedImage ); + itkGetConstObjectMacro( FixedImage, ImageType ); + + void SetMovingSpatialObject( const SpatialObjectType * movingSpatialObject ); + itkGetConstObjectMacro( MovingSpatialObject, SpatialObjectType ); + + void SetFixedImageMaskObject( const ImageMaskObjectType * maskObject ); + itkGetConstObjectMacro( FixedImageMaskObject, ImageMaskObjectType ); + itkSetMacro( UseFixedImageMaskObject, bool ); + itkGetMacro( UseFixedImageMaskObject, bool ); + + void SetMovingSpatialObjectMaskObject( + const SpatialObjectMaskObjectType * maskObject ); + itkGetConstObjectMacro( MovingSpatialObjectMaskObject, + SpatialObjectMaskObjectType ); + itkSetMacro( UseMovingSpatialObjectMaskObject, bool ); + itkGetMacro( UseMovingSpatialObjectMaskObject, bool ); + + itkSetMacro( ReportProgress, bool ); + itkGetMacro( ReportProgress, bool ); + itkBooleanMacro( ReportProgress ); + + /** Return the output of the registration process, which is a Transform */ + const TransformOutputType * GetOutput( void ) const; + +protected: + + SpatialObjectToImageRegistrationMethod( void ); + virtual ~SpatialObjectToImageRegistrationMethod( void ); + + virtual void Initialize( void ); + + /** Method that actually computes the registration. This method is + * intended to be overloaded by derived classes. Those overload, + * however, must invoke this method in the base class. */ + void GenerateData( void ) override; + + /** Provide derived classes with access to the Transform member + * variable. */ + itkSetObjectMacro( Transform, TransformType ); + itkGetModifiableObjectMacro( Transform, TransformType ); + + void PrintSelf( std::ostream & os, Indent indent ) const override; + + using Superclass::MakeOutput; + virtual DataObjectPointer MakeOutput( DataObjectPointerArraySizeType + idx ) override; + + ModifiedTimeType GetMTime( void ) const override; + +protected: + + typename TransformType::Pointer m_Transform; + +private: + + // Purposely not implemented + SpatialObjectToImageRegistrationMethod( const Self & ); + // Purposely not implemented + void operator =( const Self & ); + + unsigned int m_RegistrationNumberOfWorkUnits; + + Command::Pointer m_Observer; + + typename ImageType::ConstPointer m_FixedImage; + typename SpatialObjectType::ConstPointer m_MovingSpatialObject; + + bool m_UseFixedImageMaskObject; + typename ImageMaskObjectType::ConstPointer m_FixedImageMaskObject; + + bool m_UseMovingSpatialObjectMaskObject; + typename SpatialObjectMaskObjectType::ConstPointer + m_MovingSpatialObjectMaskObject; + + bool m_ReportProgress; + +}; + +} // tube + +} // itk + +#ifndef ITK_MANUAL_INSTANTIATION +#include "itktubeSpatialObjectToImageRegistrationMethod.hxx" +#endif + +#endif diff --git a/src/Registration/itktubeSpatialObjectToImageRegistrationMethod.hxx b/src/Registration/itktubeSpatialObjectToImageRegistrationMethod.hxx new file mode 100644 index 000000000..fa1270741 --- /dev/null +++ b/src/Registration/itktubeSpatialObjectToImageRegistrationMethod.hxx @@ -0,0 +1,323 @@ +/*========================================================================= + +Library: TubeTK + +Copyright Kitware Inc. + +All rights reserved. + +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. + +=========================================================================*/ + +#ifndef __itktubeSpatialObjectToImageRegistrationMethod_txx +#define __itktubeSpatialObjectToImageRegistrationMethod_txx + +#include "itktubeSpatialObjectToImageRegistrationMethod.h" + +namespace itk +{ + +namespace tube +{ + +template +SpatialObjectToImageRegistrationMethod +::SpatialObjectToImageRegistrationMethod( void ) +{ + this->SetNumberOfRequiredOutputs( 1 ); // the transform + + this->m_Transform = 0; + typename TransformOutputType::Pointer transformDecorator = + static_cast + ( this->MakeOutput(static_cast(0)).GetPointer() ); + + this->ProcessObject::SetNthOutput( 0, transformDecorator.GetPointer() ); + + this->m_RegistrationNumberOfWorkUnits = this->GetNumberOfWorkUnits(); + this->GetMultiThreader()->SetNumberOfWorkUnits( this->m_RegistrationNumberOfWorkUnits ); + + this->m_FixedImage = 0; + this->m_MovingSpatialObject = 0; + + this->m_UseFixedImageMaskObject = false; + this->m_FixedImageMaskObject = 0; + + this->m_UseMovingSpatialObjectMaskObject = false; + this->m_MovingSpatialObjectMaskObject = 0; + + this->m_Observer = 0; + this->m_ReportProgress = false; + +} + +template +SpatialObjectToImageRegistrationMethod +::~SpatialObjectToImageRegistrationMethod( void ) +{ +} + +template +void +SpatialObjectToImageRegistrationMethod +::SetFixedImage( const ImageType * fixedImage ) +{ + if( this->m_FixedImage.GetPointer() != fixedImage ) + { + this->m_FixedImage = fixedImage; + + this->ProcessObject::SetNthInput(0, const_cast( fixedImage ) ); + + this->Modified(); + } +} + +template +void +SpatialObjectToImageRegistrationMethod +::SetMovingSpatialObject( const SpatialObjectType * movingSpatialObject ) +{ + if( this->m_MovingSpatialObject != movingSpatialObject ) + { + this->m_MovingSpatialObject = movingSpatialObject; + + //this->ProcessObject::SetNthInput(1, m_MovingSpatialObject ); + + this->Modified(); + } +} + +template +void +SpatialObjectToImageRegistrationMethod +::SetFixedImageMaskObject( const ImageMaskObjectType * maskObject ) +{ + if( this->m_FixedImageMaskObject.GetPointer() != maskObject ) + { + this->m_FixedImageMaskObject = maskObject; + + this->Modified(); + + if( maskObject ) + { + m_UseFixedImageMaskObject = true; + } + else + { + m_UseFixedImageMaskObject = false; + } + } +} + +template +void +SpatialObjectToImageRegistrationMethod +::SetMovingSpatialObjectMaskObject( const SpatialObjectMaskObjectType * + maskObject ) +{ + if( this->m_MovingSpatialObjectMaskObject.GetPointer() != maskObject ) + { + this->m_MovingSpatialObjectMaskObject = maskObject; + + this->Modified(); + + if( maskObject ) + { + m_UseMovingSpatialObjectMaskObject = true; + } + else + { + m_UseMovingSpatialObjectMaskObject = false; + } + } +} + +template +const typename SpatialObjectToImageRegistrationMethod::TransformOutputType +* SpatialObjectToImageRegistrationMethod +::GetOutput() const + { + return static_cast( + this->ProcessObject::GetOutput( 0 ) ); + } + +template +DataObject::Pointer +SpatialObjectToImageRegistrationMethod +::MakeOutput( DataObjectPointerArraySizeType idx ) +{ + switch( idx ) + { + case 0: + return static_cast( + TransformOutputType::New().GetPointer() ); + break; + default: + itkExceptionMacro( + "MakeOutput request for an output number larger than the expected number of outputs" ); + return nullptr; + } +} + +template +ModifiedTimeType +SpatialObjectToImageRegistrationMethod +::GetMTime( void ) const +{ + unsigned long mtime = Superclass::GetMTime(); + unsigned long m; + + if( m_Transform.IsNotNull() ) + { + m = m_Transform->GetMTime(); + mtime = (m > mtime ? m : mtime); + } + + if( m_FixedImage.IsNotNull() ) + { + m = m_FixedImage->GetMTime(); + mtime = (m > mtime ? m : mtime); + } + + if( m_FixedImageMaskObject.IsNotNull() ) + { + m = m_FixedImageMaskObject->GetMTime(); + mtime = (m > mtime ? m : mtime); + } + + if( m_MovingSpatialObject.IsNotNull() ) + { + m = m_MovingSpatialObject->GetMTime(); + mtime = (m > mtime ? m : mtime); + } + + if( m_MovingSpatialObjectMaskObject.IsNotNull() ) + { + m = m_MovingSpatialObjectMaskObject->GetMTime(); + mtime = (m > mtime ? m : mtime); + } + + return mtime; +} + +template +void +SpatialObjectToImageRegistrationMethod +::Initialize( void ) +{ + this->GetMultiThreader()->SetNumberOfWorkUnits( m_RegistrationNumberOfWorkUnits ); + + if( m_Transform.IsNull() ) + { + itkExceptionMacro( << "Transform is not set" ); + } + + if( m_FixedImage.IsNull() ) + { + itkExceptionMacro( << "Fixed image is not set" ); + } + + if( m_MovingSpatialObject.IsNull() ) + { + itkExceptionMacro( << "Moving image is not set" ); + } + + TransformOutputType * transformOutput = + static_cast( this->ProcessObject::GetOutput( 0 ) ); + + transformOutput->Set( m_Transform.GetPointer() ); + +} + +template +void +SpatialObjectToImageRegistrationMethod +::GenerateData( void ) +{ + this->Update(); +} + +template +void +SpatialObjectToImageRegistrationMethod +::PrintSelf( std::ostream & os, Indent indent ) const +{ + Superclass::PrintSelf( os, indent ); + + os << indent << "Number of threads = " << this->m_RegistrationNumberOfWorkUnits + << std::endl; + if( this->m_Transform.IsNotNull() ) + { + os << indent << "Transform = " << this->m_Transform << std::endl; + } + else + { + os << indent << "Transform = 0" << std::endl; + } + + if( this->m_Observer.IsNotNull() ) + { + os << indent << "Observer = " << this->m_Observer << std::endl; + } + else + { + os << indent << "Observer = 0" << std::endl; + } + + if( this->m_FixedImage.IsNotNull() ) + { + os << indent << "Fixed Image = " << this->m_FixedImage << std::endl; + } + else + { + os << indent << "Fixed Image = 0" << std::endl; + } + + if( this->m_MovingSpatialObject.IsNotNull() ) + { + os << indent << "Moving Image = " << this->m_FixedImage << std::endl; + } + else + { + os << indent << "Moving Image = 0" << std::endl; + } + + if( this->m_FixedImageMaskObject.IsNotNull() ) + { + os << indent << "Fixed Image Mask Object = " << this->m_FixedImageMaskObject + << std::endl; + } + else + { + os << indent << "Fixed image mask = 0" << std::endl; + } + + if( this->m_MovingSpatialObjectMaskObject.IsNotNull() ) + { + os << indent << "Moving Image Mask Object = " << this->m_MovingSpatialObjectMaskObject + << std::endl; + } + else + { + os << indent << "Moving image mask = 0" << std::endl; + } + + os << indent << "Report progress = " << this->m_ReportProgress << std::endl; + +} + +}; // tube + +}; // itk + +#endif diff --git a/src/Registration/itktubeTubeAngleOfIncidenceWeightFunction.h b/src/Registration/itktubeTubeAngleOfIncidenceWeightFunction.h deleted file mode 100644 index c24e7a410..000000000 --- a/src/Registration/itktubeTubeAngleOfIncidenceWeightFunction.h +++ /dev/null @@ -1,144 +0,0 @@ -/*========================================================================= - -Library: TubeTK - -Copyright Kitware Inc. - -All rights reserved. - -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. - -=========================================================================*/ - -#ifndef __itktubeTubeAngleOfIncidenceWeightFunction_h -#define __itktubeTubeAngleOfIncidenceWeightFunction_h - -#include - -namespace itk -{ - -namespace tube -{ - -namespace Function -{ - -/** \class TubeAngleOfIncidenceWeightFunction - * - * \brief Weight tube points by their angle relative to a ultrasound beam. - * - * The tangent direction of a tube point is compared to the ultrasound beam - * direction. The output weight is given by: - * - * \f[ - * W( \mathbf{x} ) = - * 1 - \alpha ( 1 - \cos^n \theta ) - * \f] - * - * Where: - * - * \f{eqnarray*} - * W( \mathbf{x} ) &=& \mbox{output weight} - * n &=& \mbox{specifies angle dependence} - * \alpha &=& \mbox{fractional importance of the angle of incidence} - * \cos \theta &=& \mbox{angle of incidence with the tube} - * \f} - * - * \warning Make sure to set the UltrasoundProbeOrigin. - * - */ -template< class TTubePoint, class TWeight = double > -class TubeAngleOfIncidenceWeightFunction: - public FunctionBase< TTubePoint, TWeight > -{ -public: - /** Standard class typedefs. */ - typedef TubeAngleOfIncidenceWeightFunction< TTubePoint, TWeight > - Self; - typedef FunctionBase< TTubePoint, TWeight > Superclass; - typedef SmartPointer< Self > Pointer; - typedef SmartPointer< const Self > ConstPointer; - - /** Run-time type information ( and related methods ). */ - itkTypeMacro( TubeAngleOfIncidenceWeightFunction, FunctionBase ); - - /** Method for creation through the object factory. */ - itkNewMacro( Self ); - - typedef TWeight WeightType; - typedef TTubePoint TubePointType; - typedef typename TubePointType::PointType PointType; - - /** Set/Get the fractional importance of the angle of incicent an the tube - * point weight. */ - itkSetClampMacro( FractionalImportance, double, 0, 1.0 ); - itkGetConstMacro( FractionalImportance, double ); - - /** Set/Get the angle dependence. */ - itkSetMacro( AngleDependence, double ); - itkGetConstMacro( AngleDependence, double ); - - /** Set/Get the ultrasound probe origin ( assuming a phase array or - * curvilinear array transducer geometry. */ - itkSetMacro( UltrasoundProbeOrigin, PointType ); - itkGetConstReferenceMacro( UltrasoundProbeOrigin, PointType ); - - WeightType Evaluate( const TubePointType & tubePoint ) const override - { - const PointType & position = tubePoint.GetPositionInObjectSpace(); - typename TubePointType::VectorType beam = - ( position - m_UltrasoundProbeOrigin ); - beam.Normalize(); - typename TubePointType::VectorType tangent = - tubePoint.GetTangentInObjectSpace(); - tangent.Normalize(); - const double dotProduct = beam * tangent; - double cos_term = - std::fabs( std::sqrt( 1.0 - dotProduct * dotProduct ) ); - if( m_AngleDependence != 1.0 ) - { - cos_term = std::pow( cos_term, m_AngleDependence ); - } - return static_cast< WeightType >( 1.0 - - m_FractionalImportance * ( 1.0 - cos_term ) ); - } - -protected: - TubeAngleOfIncidenceWeightFunction( void ): - m_FractionalImportance( 0.5 ), - m_AngleDependence( 1.0 ) - { - m_UltrasoundProbeOrigin.Fill( 0.0 ); - } - ~TubeAngleOfIncidenceWeightFunction( void ) - {} - -private: - double m_FractionalImportance; - double m_AngleDependence; - PointType m_UltrasoundProbeOrigin; - - // purposely not implemented - TubeAngleOfIncidenceWeightFunction( const Self & ); - // purposely not implemented - void operator=( const Self & ); -}; // End class TubeAngleOfIncidenceWeightFunction - -} // End namespace Function - -} // End namespace tube - -} // End namespace itk - -#endif // End !defined( __itktubeTubeAngleOfIncidenceWeightFunction_h ) diff --git a/src/Registration/itktubeTubeExponentialResolutionWeightFunction.h b/src/Registration/itktubeTubeExponentialResolutionWeightFunction.h deleted file mode 100644 index 590c63705..000000000 --- a/src/Registration/itktubeTubeExponentialResolutionWeightFunction.h +++ /dev/null @@ -1,99 +0,0 @@ -/*========================================================================= - -Library: TubeTK - -Copyright 2010 Kitware Inc. 28 Corporate Drive, -Clifton Park, NY, 12065, USA. - -All rights reserved. - -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. - -=========================================================================*/ - -#ifndef __itktubeTubeExponentialResolutionWeightFunction_h -#define __itktubeTubeExponentialResolutionWeightFunction_h - -#include -#include - -namespace itk -{ - -namespace tube -{ - -namespace Function -{ - -/** \class TubeExponentialResolutionWeightFunction - * - * \brief Weight tube points exponentially by their radius. - * - * \f$ w_i = \frac{2}{1 + e^{-2 r_i}} \f$ - * - * As in Eqn. 2. Alyward, S. Weeks, S. and Bullitt, E. Analysis of the - * Parameter Space of a Metric for Registering 3D Vascular Images. - * MICCAI, 2001. - * - * \sa TubeExponentialResolutionWeightFunction - * \sa TubeExponentialWithBoundsResolutionWeightFunction - */ -template< class TTubePoint, class TWeight = double > -class TubeExponentialResolutionWeightFunction: - public FunctionBase< TTubePoint, TWeight > -{ -public: - /** Standard class typedefs. */ - typedef TubeExponentialResolutionWeightFunction< TTubePoint, TWeight > - Self; - typedef FunctionBase< TTubePoint, TWeight > Superclass; - typedef SmartPointer< Self > Pointer; - typedef SmartPointer< const Self > ConstPointer; - - /** Run-time type information ( and related methods ). */ - itkTypeMacro( TubeExponentialResolutionWeightFunction, FunctionBase ); - - /** Method for creation through the object factory. */ - itkNewMacro( Self ); - - typedef TWeight WeightType; - typedef TTubePoint TubePointType; - - WeightType Evaluate( const TubePointType & tubePoint ) const override - { - const WeightType radius = tubePoint.GetRadiusInObjectSpace(); - return static_cast< WeightType >( 2.0 / - ( 1.0 + std::exp( -2.0 * radius ) ) ); - } - -protected: - TubeExponentialResolutionWeightFunction( void ) - {} - ~TubeExponentialResolutionWeightFunction( void ) - {} - -private: - // purposely not implemented - TubeExponentialResolutionWeightFunction( const Self & ); - // purposely not implemented - void operator=( const Self & ); -}; // End class TubeExponentialResolutionWeightFunction - -} // End namespace Function - -} // End namespace tube - -} // End namespace itk - -#endif // End !defined( __itktubeTubeExponentialResolutionWeightFunction_h ) diff --git a/src/Registration/itktubeTubeParametricExponentialResolutionWeightFunction.h b/src/Registration/itktubeTubeParametricExponentialResolutionWeightFunction.h deleted file mode 100644 index 4c535ad1a..000000000 --- a/src/Registration/itktubeTubeParametricExponentialResolutionWeightFunction.h +++ /dev/null @@ -1,124 +0,0 @@ -/*========================================================================= - -Library: TubeTK - -Copyright 2010 Kitware Inc. 28 Corporate Drive, -Clifton Park, NY, 12065, USA. - -All rights reserved. - -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. - -=========================================================================*/ - -#ifndef __itktubeTubeParametricExponentialResolutionWeightFunction_h -#define __itktubeTubeParametricExponentialResolutionWeightFunction_h - -#include - -namespace itk -{ - -namespace tube -{ - -namespace Function -{ - -/** \class TubeParametricExponentialResolutionWeightFunction - * - * \brief Weight tube points exponentially by their radius. - * - * \f$ w_i = \frac{1}{1 + \delta ( e^{-\alpha r_i} - 1 )} \f$ - * - * where \f$\delta\ \in ( -1, 1 )f$ controls the amount of weighting. A - * positive Delta weighs large tubes higher than small tubes, and a - * negative Delta weighs small tubes higher than large tubes. - * \f$\alpha \in [0, \infty )\f$ controls transition in weights. - * \f$r\f$ is the tube radius at a point. - * - * \sa TubeParametricExponentialResolutionWeightFunction - * \sa TubeParametricExponentialWithBoundsResolutionWeightFunction - */ -template< class TTubePoint, class TOperatorValue = double > -class TubeParametricExponentialResolutionWeightFunction -{ -public: - typedef TubeParametricExponentialResolutionWeightFunction Self; - - typedef TOperatorValue OperatorValueType; - typedef TTubePoint TubePointType; - - TubeParametricExponentialResolutionWeightFunction( void ) - : m_Alpha( 2.0 ) - {} - ~TubeParametricExponentialResolutionWeightFunction( void ) - {} - - inline OperatorValueType operator()( const TubePointType & tubePoint ) - { - const OperatorValueType radius = tubePoint.GetRadiusInObjectSpace(); - return static_cast< OperatorValueType >( 1.0 / - ( 1.0 + this->m_Delta - * ( std::exp( -this->m_Alpha * radius ) - 1.0 ) ) ); - } - - void SetDelta( const OperatorValueType delta ) - { - this->m_Delta = delta; - } - - OperatorValueType GetDelta( void ) const - { - return this->m_Delta; - } - - void SetAlpha( const OperatorValueType alpha ) - { - this->m_Alpha = alpha; - } - - OperatorValueType GetAlpha( void ) const - { - return this->m_Alpha; - } - - bool operator!=( const Self & other ) const - { - if( this->m_Delta != other.m_Delta || - this->m_Alpha != other.m_Alpha ) - { - return true; - } - return false; - } - - bool operator==( const Self & other ) const - { - return !( *this != other ); - } - -private: - OperatorValueType m_Delta; - OperatorValueType m_Alpha; - -}; // End class TubeParametricExponentialResolutionWeightFunction - -} // End namespace Function - -} // End namespace tube - -} // End namespace itk - -// End !defined( __itktubeTubeParametricExponentialResolutionWeightFunction_h ) -#endif diff --git a/src/Registration/itktubeTubeParametricExponentialWithBoundsResolutionWeightFunction.h b/src/Registration/itktubeTubeParametricExponentialWithBoundsResolutionWeightFunction.h deleted file mode 100644 index b2599f69c..000000000 --- a/src/Registration/itktubeTubeParametricExponentialWithBoundsResolutionWeightFunction.h +++ /dev/null @@ -1,131 +0,0 @@ -/*========================================================================= - -Library: TubeTK - -Copyright 2010 Kitware Inc. 28 Corporate Drive, -Clifton Park, NY, 12065, USA. - -All rights reserved. - -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. - -=========================================================================*/ - -#ifndef __itktubeTubeParametricExponentialWithBoundsResolutionWeightFunction_h -#define __itktubeTubeParametricExponentialWithBoundsResolutionWeightFunction_h - -#include "itktubeTubeParametricExponentialResolutionWeightFunction.h" - -#include - -namespace itk -{ - -namespace tube -{ - -namespace Function -{ - -/** \class TubeParametricExponentialWithBoundsResolutionWeightFunction - * - * \brief Weight tube points exponentially by their radius if within bounds. - * - * This is similar to TubeParametricExponentialResolutionWeightFunction - * except that values outside the UpperBound or LowerBound are given a - * weight of zero. - */ -template< class TTubePoint, class TOperatorValue = double > -class TubeParametricExponentialWithBoundsResolutionWeightFunction - : public TubeParametricExponentialResolutionWeightFunction< TTubePoint, - TOperatorValue > -{ -public: - typedef TubeParametricExponentialWithBoundsResolutionWeightFunction - Self; - typedef TubeParametricExponentialResolutionWeightFunction< TTubePoint, - TOperatorValue > - Superclass; - - typedef typename Superclass::OperatorValueType OperatorValueType; - typedef typename Superclass::TubePointType TubePointType; - - TubeParametricExponentialWithBoundsResolutionWeightFunction( void ) - : m_LowerBound( NumericTraits< OperatorValueType >::min() ), - m_UpperBound( NumericTraits< OperatorValueType >::max() ) - {} - ~TubeParametricExponentialWithBoundsResolutionWeightFunction( void ) - {} - - inline OperatorValueType operator()( const TubePointType & tubePoint ) - { - const OperatorValueType radius = tubePoint.GetRadiusInObjectSpace(); - if( radius < this->m_LowerBound || radius > this->m_UpperBound ) - { - return NumericTraits< OperatorValueType >::Zero; - } - return static_cast< OperatorValueType >( 1.0 / - ( 1.0 + this->GetDelta() - * ( std::exp( -this->GetAlpha() * radius ) - 1.0 ) ) ); - } - - void SetLowerBound( const OperatorValueType lowerBound ) - { - this->m_LowerBound = lowerBound; - } - - OperatorValueType GetLowerBound( void ) const - { - return this->m_LowerBound; - } - - void SetUpperBound( const OperatorValueType upperBound ) - { - this->m_UpperBound = upperBound; - } - - OperatorValueType GetUpperBound( void ) const - { - return this->m_UpperBound; - } - - bool operator!=( const Self & other ) const - { - if( Superclass::operator!=( other ) || - this->m_LowerBound != other.m_LowerBound || - this->m_UpperBound != other.m_UpperBound ) - { - return true; - } - return false; - } - - bool operator==( const Self & other ) const - { - return !( *this != other ); - } - - -private: - OperatorValueType m_LowerBound; - OperatorValueType m_UpperBound; - -}; // End class TubeParametricExponentialWithBoundsResolutionWeightFunction - -} // End namespace Function - -} // End namespace tube - -} // End namespace itk - -#endif // End !defined( __itktub... diff --git a/src/Registration/itktubeTubePointWeightsCalculator.h b/src/Registration/itktubeTubePointWeightsCalculator.h deleted file mode 100644 index 790b359c1..000000000 --- a/src/Registration/itktubeTubePointWeightsCalculator.h +++ /dev/null @@ -1,120 +0,0 @@ -/*========================================================================= - -Library: TubeTK - -Copyright 2010 Kitware Inc. 28 Corporate Drive, -Clifton Park, NY, 12065, USA. - -All rights reserved. - -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. - -=========================================================================*/ - -#ifndef __itktubeTubePointWeightsCalculator_h -#define __itktubeTubePointWeightsCalculator_h - -#include -#include -#include - -namespace itk -{ - -namespace tube -{ - -/** - * This class computes scalar weights for every point in a tube tree - * based on - * the radius at that point. - * - * \tparam TTubeTreeSpatialObject input tube tree spatial object type. - * \tparam TPointWeightFunction type of the function used to compute the - * weights. - * \tparam TResolutionsWeights type of the output scalar resolution - * weights. - */ -template< unsigned int VDimension, class TTubeSpatialObject, - class TPointWeightFunction, - class TPointWeights > -class TubePointWeightsCalculator : public Object -{ -public: - /** Standard class typedefs. */ - typedef TubePointWeightsCalculator< VDimension, - TTubeSpatialObject, - TPointWeightFunction, - TPointWeights > Self; - typedef Object Superclass; - typedef SmartPointer< Self > Pointer; - typedef SmartPointer< const Self > ConstPointer; - - static const unsigned int Dimension = VDimension; - - typedef SpatialObject< Dimension > TubeTreeSpatialObjectType; - typedef TTubeSpatialObject TubeSpatialObjectType; - typedef TPointWeightFunction PointWeightFunctionType; - typedef TPointWeights PointWeightsType; - - /** Method for creation through the object factory. */ - itkNewMacro( Self ); - - /** Run-time type information ( and related methods ). */ - itkTypeMacro( TubePointWeightsCalculator, Object ); - - /** Compute the resolutions weights on the input TubeTreeSpatialObject - * using the - * PointWeightFunction. */ - void Compute( void ); - - /** Set the input TubeTreeSpatialObject. */ - itkSetObjectMacro( TubeTreeSpatialObject, TubeTreeSpatialObjectType ); - itkGetConstObjectMacro( TubeTreeSpatialObject, TubeTreeSpatialObjectType ); - - /** Set/Get the function used to determine the resolution weights. - * This function - * takes a tube point as an input and outputs a weight for that point. */ - itkSetObjectMacro( PointWeightFunction, PointWeightFunctionType ); - itkGetConstObjectMacro( PointWeightFunction, PointWeightFunctionType ); - - /** Get the output resolution weights. */ - itkGetConstReferenceMacro( PointWeights, PointWeightsType ); - -protected: - TubePointWeightsCalculator( void ); - virtual ~TubePointWeightsCalculator( void ) {} - - void PrintSelf( std::ostream& os, Indent indent ) const override; - - typename PointWeightFunctionType::ConstPointer m_PointWeightFunction; - - PointWeightsType m_PointWeights; - -private: - TubePointWeightsCalculator( const Self& ); //purposely not implemented - void operator=( const Self& ); //purposely not implemented - - typename TubeTreeSpatialObjectType::ConstPointer m_TubeTreeSpatialObject; - -}; // End class TubePointWeightsCalculator - -} // End namespace tube - -} // End namespace itk - -#ifndef ITK_MANUAL_INSTANTIATION -#include "itktubeTubePointWeightsCalculator.hxx" -#endif - -#endif // End !defined( __itktubeTubePointWeightsCalculator_h ) diff --git a/src/Registration/itktubeTubePointWeightsCalculator.hxx b/src/Registration/itktubeTubePointWeightsCalculator.hxx deleted file mode 100644 index 85903abf9..000000000 --- a/src/Registration/itktubeTubePointWeightsCalculator.hxx +++ /dev/null @@ -1,147 +0,0 @@ -/*========================================================================= - -Library: TubeTK - -Copyright Kitware Inc. - -All rights reserved. - -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. - -=========================================================================*/ - -#ifndef __itktubeTubePointWeightsCalculator_hxx -#define __itktubeTubePointWeightsCalculator_hxx - -#include "itktubeTubePointWeightsCalculator.h" - -namespace itk -{ - -namespace tube -{ - -template< unsigned int VDimension, - class TTubeSpatialObject, - class TPointWeightFunction, - class TPointWeights > -TubePointWeightsCalculator< VDimension, - TTubeSpatialObject, - TPointWeightFunction, - TPointWeights > -::TubePointWeightsCalculator( void ) -{ -} - - -template< unsigned int VDimension, - class TTubeSpatialObject, - class TPointWeightFunction, - class TPointWeights > -void -TubePointWeightsCalculator< VDimension, - TTubeSpatialObject, - TPointWeightFunction, - TPointWeights > -::Compute( void ) -{ - char childName[] = "Tube"; - typename TubeTreeSpatialObjectType::ChildrenListType * tubeList = - this->m_TubeTreeSpatialObject->GetChildren( - this->m_TubeTreeSpatialObject->GetMaximumDepth(), childName ); - - // Count the tube points. - SizeValueType tubePoints = 0; - typedef typename TubeTreeSpatialObjectType::ChildrenListType::iterator - TubesIteratorType; - for( TubesIteratorType tubeIterator = tubeList->begin(); - tubeIterator != tubeList->end(); - ++tubeIterator ) - { - TubeSpatialObjectType * currentTube = - dynamic_cast< TubeSpatialObjectType * >( - ( *tubeIterator ).GetPointer() ); - if( currentTube != NULL ) - { - tubePoints += currentTube->GetNumberOfPoints(); - } - } - this->m_PointWeights.SetSize( tubePoints ); - - SizeValueType tubeIndex = 0; - for( TubesIteratorType tubeIterator = tubeList->begin(); - tubeIterator != tubeList->end(); - ++tubeIterator ) - { - TubeSpatialObjectType * currentTube = - dynamic_cast< TubeSpatialObjectType * >( - ( *tubeIterator ).GetPointer() ); - if( currentTube != NULL ) - { - const typename TubeSpatialObjectType::TubePointListType & - currentTubePoints = currentTube->GetPoints(); - typedef typename TubeSpatialObjectType::TubePointListType::const_iterator - TubePointIteratorType; - for( TubePointIteratorType tubePointIterator = - currentTubePoints.begin(); - tubePointIterator != currentTubePoints.end(); - ++tubePointIterator ) - { - this->m_PointWeights[tubeIndex] - = this->m_PointWeightFunction->Evaluate( *tubePointIterator ); - ++tubeIndex; - } - } - } - delete tubeList; -} - - -template< unsigned int VDimension, - class TTubeSpatialObject, - class TPointWeightFunction, - class TPointWeights > -void -TubePointWeightsCalculator< VDimension, - TTubeSpatialObject, - TPointWeightFunction, - TPointWeights > -::PrintSelf( std::ostream& os, Indent indent ) const -{ - Superclass::PrintSelf( os, indent ); - if( ! m_TubeTreeSpatialObject.IsNull() ) - { - os << indent << "TubeTreeSpatialObject: " << m_TubeTreeSpatialObject - << std::endl; - } - else - { - os << indent << "TubeTreeSpatialObject: " << "( 0x0 )" << std::endl; - } - if( ! m_PointWeightFunction.IsNull() ) - { - os << indent << "PointWeightFunction: " - << m_PointWeightFunction << std::endl; - } - else - { - os << indent << "PointWeightFunction: " << "( 0x0 )" << std::endl; - } - os << indent << "PointWeights: " << m_PointWeights << std::endl; -} - -} // End namespace tube - -} // End namespace itk - -#endif // End !defined( __itktubeTubePointWeightsCalculator_hxx ) diff --git a/src/Registration/itktubeTubeToTubeTransformFilter.h b/src/Registration/itktubeTubeToTubeTransformFilter.h deleted file mode 100644 index 3dc283b4a..000000000 --- a/src/Registration/itktubeTubeToTubeTransformFilter.h +++ /dev/null @@ -1,127 +0,0 @@ -/*========================================================================= - -Library: TubeTK - -Copyright 2010 Kitware Inc. 28 Corporate Drive, -Clifton Park, NY, 12065, USA. - -All rights reserved. - -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. - -=========================================================================*/ - -#ifndef __itktubeTubeToTubeTransformFilter_h -#define __itktubeTubeToTubeTransformFilter_h - -#include "itktubeSpatialObjectToSpatialObjectFilter.h" - -#include -#include -#include -#include -#include - -namespace itk -{ - -namespace tube -{ - -/** - * This class applies a transformation to tubes in a group and returns - * a the group with transformed tubes. - * - * \warning Transform Class MUST have a proper implementation of - * ::TransformCovariantVector( void ) - * - * \warning The scale is applied before computing the transformation. - * - * The resulting tube could be cropped and/or a narrow band could be - * defined. - */ -template< class TTransformType, unsigned int TDimension > -class TubeToTubeTransformFilter : - public SpatialObjectToSpatialObjectFilter< - GroupSpatialObject< TDimension >, - GroupSpatialObject< TDimension > > -{ -public: - - typedef GroupSpatialObject< TDimension > GroupType; - - /** Standard class typedefs. */ - typedef TubeToTubeTransformFilter< TTransformType, TDimension > - Self; - - typedef SpatialObjectToSpatialObjectFilter< GroupType, GroupType > - Superclass; - - typedef SmartPointer< Self > Pointer; - typedef SmartPointer< const Self > ConstPointer; - - typedef TubeSpatialObject< TDimension > TubeType; - - typedef typename TubeSpatialObject< TDimension >::TransformType - TubeTransformType; - - /** Typedef for the transformations */ - typedef TTransformType TransformType; - - /** Method for creation through the object factory. */ - itkNewMacro( Self ); - - /** Run-time type information ( and related methods ). */ - itkTypeMacro( TubeToTubeTransformFilter, - SpatialObjectToSpatialObjectFilter ); - - /** Set the Transformation */ - itkSetObjectMacro( Transform, TransformType ); - - /** Set the Object to Parent transform for the output tubes */ - itkSetObjectMacro( OutputObjectToParentTransform, TubeTransformType ); - -protected: - - TubeToTubeTransformFilter( void ); - virtual ~TubeToTubeTransformFilter( void ) {} - - void PrintSelf( std::ostream& os, Indent indent ) const override; - - /** Apply the transformation to the tube */ - void GenerateData( void ) override; - - -private: - - TubeToTubeTransformFilter( const Self& ); //purposely not implemented - void operator=( const Self& ); //purposely not implemented - - void UpdateLevel( SpatialObject< TDimension > * inputSO, - SpatialObject< TDimension > * parentSO ); - - typename TransformType::Pointer m_Transform; - - typename TubeTransformType::Pointer m_OutputObjectToParentTransform; - -}; // End class TubeToTubeTransformFilter - -} // End namespace tube - -} // End namespace itk - -#ifndef ITK_MANUAL_INSTANTIATION -#include "itktubeTubeToTubeTransformFilter.hxx" -#endif - -#endif // End !defined( __itktubeTubeToTubeTransformFilter_h ) diff --git a/src/Registration/itktubeTubeToTubeTransformFilter.hxx b/src/Registration/itktubeTubeToTubeTransformFilter.hxx deleted file mode 100644 index 7c326a545..000000000 --- a/src/Registration/itktubeTubeToTubeTransformFilter.hxx +++ /dev/null @@ -1,255 +0,0 @@ -/*========================================================================= - -Library: TubeTK - -Copyright 2010 Kitware Inc. 28 Corporate Drive, -Clifton Park, NY, 12065, USA. - -All rights reserved. - -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. - -=========================================================================*/ - -#ifndef __itktubeTubeToTubeTransformFilter_hxx -#define __itktubeTubeToTubeTransformFilter_hxx - -#include "itktubeTubeToTubeTransformFilter.h" - -#include - -namespace itk -{ - -namespace tube -{ - -template< class TTransformType, unsigned int TDimension > -TubeToTubeTransformFilter< TTransformType, TDimension > -::TubeToTubeTransformFilter( void ) -{ - m_OutputObjectToParentTransform = 0; - m_Transform = 0; - - SpatialObjectFactoryBase::RegisterDefaultSpatialObjects(); - SpatialObjectFactory< SpatialObject< TDimension > >:: - RegisterSpatialObject(); - SpatialObjectFactory< GroupType >::RegisterSpatialObject(); - SpatialObjectFactory< TubeType >::RegisterSpatialObject(); -} - -/** - * Apply the transformation to the tube - */ -template< class TTransformType, unsigned int TDimension > -void -TubeToTubeTransformFilter< TTransformType, TDimension > -::GenerateData( void ) -{ - typename GroupType::Pointer output = this->GetOutput(); - output->CopyInformation( this->GetInput() ); - - typedef typename SpatialObject< TDimension >::ChildrenListType - ChildrenListType; - ChildrenListType * children = this->GetInput()->GetChildren(); - typename ChildrenListType::const_iterator it = children->begin(); - while( it != children->end() ) - { - this->UpdateLevel( *it, output ); - ++it; - } - delete children; -} - -/** - * Apply the transformation to the tube - */ -template< class TTransformType, unsigned int TDimension > -void -TubeToTubeTransformFilter< TTransformType, TDimension > -::UpdateLevel( SpatialObject< TDimension > * inputSO, - SpatialObject< TDimension > * parentSO ) -{ - typename SpatialObject< TDimension >::Pointer outputSO = - inputSO->Clone(); - if( outputSO.IsNull() ) - { - itkExceptionMacro( << "Could not create an instance of " - << outputSO->GetTypeName() << ". The usual cause of this error is not" - << "registering the SpatialObject with SpatialFactory." ); - } - - // Correct for extra reference count from CreateInstance(). - //outputSO->UnRegister(); - - // We make the copy and sub-sample if it is a tube. - TubeType * inputSOAsTube = dynamic_cast< TubeType * >( - inputSO ); - if( inputSOAsTube != NULL ) - { - TubeType * outputSOAsTube = dynamic_cast< TubeType * >( - outputSO.GetPointer() ); - - Point inputObjectPoint; - Point worldPoint; - Point transformedWorldPoint; - Point inputPoint; - Point outputPoint; - - inputSOAsTube->Update(); - - typename TubeType::TransformType::Pointer inputObjectToParentTransform = - inputSOAsTube->GetObjectToParentTransform(); - - typename TubeType::TransformType::Pointer inputObjectToWorldTransform = - inputSOAsTube->GetObjectToWorldTransform(); - - outputSOAsTube->CopyInformation( inputSOAsTube ); - outputSOAsTube->Clear(); - - if( m_OutputObjectToParentTransform.IsNotNull() ) - { - typename TubeType::TransformType::Pointer tfm = TubeType:: - TransformType::New(); - tfm->SetIdentity(); - tfm->SetMatrix( m_OutputObjectToParentTransform->GetMatrix() ); - tfm->SetOffset( m_OutputObjectToParentTransform->GetOffset() ); - outputSOAsTube->SetObjectToParentTransform( tfm ); - } - - outputSOAsTube->Update(); - - typename TubeType::TransformType::Pointer - outputInverseObjectToWorldTransform = TubeType::TransformType::New(); - outputSOAsTube->GetObjectToWorldTransform()->GetInverse( - outputInverseObjectToWorldTransform ); - - typedef typename TubeType::TubePointListType TubePointListType; - TubePointListType tubePointList = inputSOAsTube->GetPoints(); - typename TubePointListType::const_iterator tubePointIterator = - tubePointList.begin(); - - while( tubePointIterator != tubePointList.end() ) - { - inputPoint = ( *tubePointIterator ).GetPositionInObjectSpace(); - inputObjectPoint = inputObjectToParentTransform - ->TransformPoint( inputPoint ); - worldPoint = inputObjectToWorldTransform->TransformPoint( - inputPoint ); - - transformedWorldPoint = m_Transform->TransformPoint( worldPoint ); - - outputPoint = outputInverseObjectToWorldTransform-> - TransformPoint( transformedWorldPoint ); - - TubeSpatialObjectPoint pnt; - - pnt.SetId( tubePointIterator->GetId() ); - pnt.SetColor( tubePointIterator->GetColor() ); - - pnt.SetPositionInObjectSpace( outputPoint ); - - // get both normals - typename TubeType::CovariantVectorType n1 = tubePointIterator - ->GetNormal1InObjectSpace(); - typename TubeType::CovariantVectorType n2 = tubePointIterator - ->GetNormal2InObjectSpace(); - - // only try transformation of normals if both are non-zero - if( !n1.GetVnlVector().is_zero() && !n2.GetVnlVector().is_zero() ) - { - n1 = inputObjectToWorldTransform->TransformCovariantVector( - n1, inputObjectPoint ); - n2 = inputObjectToWorldTransform->TransformCovariantVector( - n2, inputObjectPoint ); - n1 = m_Transform->TransformCovariantVector( n1, worldPoint ); - n2 = m_Transform->TransformCovariantVector( n2, worldPoint ); - n1 = outputInverseObjectToWorldTransform - ->TransformCovariantVector( n1, transformedWorldPoint ); - n2 = outputInverseObjectToWorldTransform - ->TransformCovariantVector( n2, transformedWorldPoint ); - n1.Normalize(); - n2.Normalize(); - pnt.SetNormal1InObjectSpace( n1 ); - pnt.SetNormal2InObjectSpace( n2 ); - } - - typename TubeType::VectorType tang = tubePointIterator-> - GetTangentInObjectSpace(); - if( !tang.GetVnlVector().is_zero() ) - { - tang = inputObjectToWorldTransform->TransformVector( - tang, inputObjectPoint ); - tang = m_Transform->TransformVector( tang, worldPoint ); - tang = outputInverseObjectToWorldTransform-> - TransformVector( tang, transformedWorldPoint ); - tang.Normalize(); - pnt.SetTangentInObjectSpace( tang ); - } - - typename TubeType::VectorType radi; - for( unsigned int i=0; iGetRadiusInObjectSpace(); - } - radi = inputObjectToWorldTransform->TransformVector( radi, - inputPoint ); - radi = m_Transform->TransformVector( radi, worldPoint ); - radi = outputInverseObjectToWorldTransform-> - TransformVector( radi, worldPoint ); - pnt.SetRadiusInObjectSpace( radi[0] ); - - pnt.SetMedialness( ( *tubePointIterator ).GetMedialness() ); - pnt.SetRidgeness( ( *tubePointIterator ).GetRidgeness() ); - pnt.SetBranchness( ( *tubePointIterator ).GetBranchness() ); - - outputSOAsTube->AddPoint( pnt ); - - ++tubePointIterator; - } - } - else - { - outputSO = inputSO->Clone(); - } - parentSO->AddChild( outputSO ); - - typedef typename SpatialObject< TDimension >::ChildrenListType - ChildrenListType; - ChildrenListType * children = inputSO->GetChildren(); - typename ChildrenListType::const_iterator it = children->begin(); - while( it != children->end() ) - { - this->UpdateLevel( *it, outputSO ); - ++it; - } - delete children; -} - -template< class TTransformType, unsigned int TDimension > -void -TubeToTubeTransformFilter< TTransformType, TDimension > -::PrintSelf( std::ostream& os, Indent indent ) const -{ - Superclass::PrintSelf( os, indent ); - - os << indent << "Transformation: " << m_Transform << std::endl; - os << indent << "OutputObjectToParent Transform: " << - m_OutputObjectToParentTransform << std::endl; -} - -} // End namespace tube - -} // End namespace itk - -#endif // End !defined( __itktubeTubeToTubeTransformFilter_hxx ) diff --git a/src/Segmentation/itktubeRadiusExtractor3.h b/src/Segmentation/itktubeRadiusExtractor3.h index df098d889..3b9e39b8a 100644 --- a/src/Segmentation/itktubeRadiusExtractor3.h +++ b/src/Segmentation/itktubeRadiusExtractor3.h @@ -92,10 +92,6 @@ class RadiusExtractor3 : public Object typedef vnl_matrix< double > MatrixType; - typedef enum { RADIUS_CORRECTION_NONE, RADIUS_CORRECTION_FOR_BINARY_IMAGE, - RADIUS_CORRECTION_FOR_CTA, RADIUS_CORRECTION_FOR_MRA } - RadiusCorrectionFunctionType; - /** * Set the input image */ void SetInputImage( typename InputImageType::Pointer inputImage ); @@ -136,22 +132,6 @@ class RadiusExtractor3 : public Object double GetRadiusStart() { return this->GetRadiusStartInIndexSpace() * m_Spacing; } - /** Set Radius step size when searching */ - itkSetMacro( RadiusStepInIndexSpace, double ); - itkGetMacro( RadiusStepInIndexSpace, double ); - void SetRadiusStep( double r ) - { this->SetRadiusStepInIndexSpace( r / m_Spacing ); } - double GetRadiusStep() - { return this->GetRadiusStepInIndexSpace() * m_Spacing; } - - /** Set Radius tolerance when searching */ - itkSetMacro( RadiusToleranceInIndexSpace, double ); - itkGetMacro( RadiusToleranceInIndexSpace, double ); - void SetRadiusTolerance( double r ) - { this->SetRadiusToleranceInIndexSpace( r / m_Spacing ); } - double GetRadiusTolerance() - { return this->GetRadiusToleranceInIndexSpace() * m_Spacing; } - /** Set ThreshMedialness */ itkSetMacro( MinMedialness, double ); itkGetMacro( MinMedialness, double ); @@ -170,12 +150,10 @@ class RadiusExtractor3 : public Object bool GetPointVectorOptimalRadius( std::vector< TubePointType > & points, double & r0, double rMin, - double rMax, - double rStep, - double rTolerance ); + double rMax ); - void SetNumKernelPoints( unsigned int _numPoints ); - itkGetMacro( NumKernelPoints, unsigned int ); + void SetKernelNumberOfPoints( unsigned int _numPoints ); + itkGetMacro( KernelNumberOfPoints, unsigned int ); itkGetMacro( KernelPointStep, unsigned int ); itkSetMacro( KernelPointStep, unsigned int ); @@ -183,9 +161,6 @@ class RadiusExtractor3 : public Object itkGetMacro( KernelStep, unsigned int ); itkSetMacro( KernelStep, unsigned int ); - itkGetMacro( KernelExtent, double ); - itkSetMacro( KernelExtent, double ); - /** Calculate Radii */ bool ExtractRadii( TubeType * tube, bool verbose=false ); @@ -193,30 +168,29 @@ class RadiusExtractor3 : public Object void SetStatusCallBack( void ( *statusCallBack )( const char *, const char *, int ) ); - double GetKernelMedialness( double r ); - protected: RadiusExtractor3( void ); virtual ~RadiusExtractor3( void ); - void GenerateKernel( void ); + void GenerateKernelProfile( void ); void SetKernelTubePoints( const std::vector< TubePointType > & tubePoints ); std::vector< TubePointType > & GetKernelTubePoints( void ) { return m_KernelTube->GetPoints(); }; - itkGetMacro( KernelCount, std::vector< double > ); - itkGetMacro( KernelValue, std::vector< double > ); + double GetProfileMaxDistance(); + double GetProfileBinNumber( double x ); + double GetProfileBinRadius( double i ); - double GetKernelBranchness( double r ); + itkGetMacro( ProfileBinCount, std::vector< double > ); + itkGetMacro( ProfileBinValue, std::vector< double > ); - bool UpdateKernelOptimalRadius( void ); + bool OptimizeKernelRadius( void ); itkGetMacro( KernelOptimalRadius, double ); itkGetMacro( KernelOptimalRadiusMedialness, double ); itkGetMacro( KernelOptimalRadiusBranchness, double ); - void PrintSelf( std::ostream & os, Indent indent ) const override; void GenerateKernelTubePoints( unsigned int tubePointNum, @@ -238,24 +212,19 @@ class RadiusExtractor3 : public Object double m_RadiusStartInIndexSpace; double m_RadiusMinInIndexSpace; double m_RadiusMaxInIndexSpace; - double m_RadiusStepInIndexSpace; - double m_RadiusToleranceInIndexSpace; - - double m_RadiusCorrectionScale; - RadiusCorrectionFunctionType m_RadiusCorrectionFunction; double m_MinMedialness; double m_MinMedialnessStart; typename TubeType::Pointer m_KernelTube; - unsigned int m_NumKernelPoints; + unsigned int m_KernelNumberOfPoints; unsigned int m_KernelPointStep; unsigned int m_KernelStep; - double m_KernelExtent; - std::vector< double > m_KernelCount; - std::vector< double > m_KernelValue; + unsigned int m_ProfileNumberOfBins; + std::vector< double > m_ProfileBinCount; + std::vector< double > m_ProfileBinValue; double m_KernelOptimalRadius; double m_KernelOptimalRadiusMedialness; diff --git a/src/Segmentation/itktubeRadiusExtractor3.hxx b/src/Segmentation/itktubeRadiusExtractor3.hxx index 0a90d18bd..b2cca5fa4 100644 --- a/src/Segmentation/itktubeRadiusExtractor3.hxx +++ b/src/Segmentation/itktubeRadiusExtractor3.hxx @@ -28,23 +28,93 @@ limitations under the License. #ifndef __itktubeRadiusExtractor3_hxx #define __itktubeRadiusExtractor3_hxx +#include +#include + #include "itktubeRadiusExtractor3.h" #include "tubeMessage.h" #include "tubeMatrixMath.h" #include "tubeTubeMathFilters.h" -#include "tubeUserFunction.h" -#include "tubeGoldenMeanOptimizer1D.h" -#include "tubeSplineApproximation1D.h" -#include +#include "itkSingleValuedNonLinearOptimizer.h" +#include "itkFRPROptimizer.h" +#include "itkMinimumMaximumImageFilter.h" #include namespace itk { +class ProfileCurve : public SingleValuedCostFunction +{ +public: + ITK_DISALLOW_COPY_AND_MOVE(ProfileCurve); + + using Self = ProfileCurve; + using Superclass = SingleValuedCostFunction; + using Pointer = SmartPointer; + using ConstPointer = SmartPointer; + + itkNewMacro(Self); + + itkTypeMacro(ProfileCurve, SingleValuedCostFunction); + + typedef SingleValuedCostFunction::ParametersType ParametersType; + typedef SingleValuedCostFunction::DerivativeType DerivativeType; + + void SetData( std::vector * data ) + { + m_Data = data; + } + + double GetValue( const ParametersType & p ) const override + { + double err = 0; + for( unsigned int i=0; isize(); ++i ) + { + double tf = (*m_Data)[i] - (p[0]-(p[1]/(1+exp(-p[2]*(i-p[3]))))); + err += tf * tf; + } + err = std::sqrt(err/m_Data->size()); + return err; + } + + void GetDerivative( const ParametersType & p, DerivativeType & d ) const override + { + d[0] = 0; + d[1] = 0; + d[2] = 0; + d[3] = 0; + double v = this->GetValue(p); + for( unsigned int i=0; isize(); ++i ) + { + double expV = exp(-p[2]*(i-p[3])); + double denom = 1 + expV; + d[0] += - 2 * p[0] + (2 * p[1])/denom; + d[1] += 2 * (p[0]-(p[1]/denom)) / denom; + d[2] += -(2*p[1]*(p[0]-(p[1]/denom))*(p[3]-i)*expV)/(denom*denom); + d[3] += -(2*p[1]*p[2]*(p[0]-(p[1]/denom))*expV)/(denom*denom); + } + d[0] /= m_Data->size(); + d[1] /= m_Data->size(); + d[2] /= m_Data->size(); + d[3] /= m_Data->size(); + } + + unsigned int GetNumberOfParameters(void) const + { + return 4; + } + +protected: + ProfileCurve() {}; + ~ProfileCurve() override = default; + + std::vector * m_Data; +}; + namespace tube { @@ -53,41 +123,38 @@ template< class TInputImage > RadiusExtractor3 ::RadiusExtractor3( void ) { - m_InputImage = NULL; + m_InputImage = nullptr; m_Spacing = 1; m_DataMin = 0; m_DataMax = -1; - m_RadiusStartInIndexSpace = 1.0; // All values are in index space. - m_RadiusMinInIndexSpace = 0.708/2; - m_RadiusMaxInIndexSpace = 4.0; - m_RadiusStepInIndexSpace = 0.708/2; - m_RadiusToleranceInIndexSpace = 0.708/3; + m_RadiusStartInIndexSpace = 0.75; // All values are in index space. + m_RadiusMinInIndexSpace = 0.708/2.0; + m_RadiusMaxInIndexSpace = 8.0; - m_RadiusCorrectionScale = 1.0; - m_RadiusCorrectionFunction = RADIUS_CORRECTION_NONE; + m_MinMedialness = 0.10; // 0.015; larger = harder + m_MinMedialnessStart = 0.10; - m_MinMedialness = 0.3; // 0.015; larger = harder - m_MinMedialnessStart = 0.15; + m_KernelNumberOfPoints = 5; + m_KernelPointStep = 12; + m_KernelStep = 17; - m_NumKernelPoints = 7; m_KernelTube = TubeType::New(); - m_KernelTube->GetPoints().resize(7); + m_KernelTube->GetPoints().resize(m_KernelNumberOfPoints); - m_KernelPointStep = 7; - m_KernelStep = 13; - m_KernelExtent = 1.75; - - m_KernelValue.clear(); - m_KernelCount.clear(); + m_ProfileNumberOfBins = 20; + m_ProfileBinValue.resize( m_ProfileNumberOfBins ); + m_ProfileBinCount.resize( m_ProfileNumberOfBins ); + std::fill( m_ProfileBinValue.begin(), m_ProfileBinValue.end(), 0 ); + std::fill( m_ProfileBinCount.begin(), m_ProfileBinCount.end(), 0 ); m_KernelOptimalRadius = 0; m_KernelOptimalRadiusMedialness = 0; m_KernelOptimalRadiusBranchness = 0; - m_IdleCallBack = NULL; - m_StatusCallBack = NULL; + m_IdleCallBack = nullptr; + m_StatusCallBack = nullptr; } /** Destructor */ @@ -151,13 +218,13 @@ RadiusExtractor3 ::tube::DebugMessage( "Compute values at point" ); } - unsigned int tempNumPoints = this->GetNumKernelPoints(); + unsigned int tempNumPoints = this->GetKernelNumberOfPoints(); unsigned int numPoints = points.size(); - this->SetNumKernelPoints( numPoints ); + this->SetKernelNumberOfPoints( numPoints ); this->SetKernelTubePoints( points ); - this->GenerateKernel(); + this->GenerateKernelProfile(); mness = this->GetKernelMedialness( pntR ); if( doBNess ) @@ -165,7 +232,7 @@ RadiusExtractor3 bness = this->GetKernelBranchness( pntR ); } - this->SetNumKernelPoints( tempNumPoints ); + this->SetKernelNumberOfPoints( tempNumPoints ); } /** Compute the Optimal scale */ @@ -175,14 +242,12 @@ RadiusExtractor3 ::GetPointVectorOptimalRadius( std::vector< TubePointType > & points, double & r0, double rMin, - double rMax, - double rStep, - double rTolerance ) + double rMax ) { - unsigned int tempNumPoints = this->GetNumKernelPoints(); + unsigned int tempNumPoints = this->GetKernelNumberOfPoints(); unsigned int numPoints = points.size(); - this->SetNumKernelPoints( numPoints ); + this->SetKernelNumberOfPoints( numPoints ); this->SetKernelTubePoints( points ); double tempXStart = this->GetRadiusStart(); @@ -191,24 +256,18 @@ RadiusExtractor3 this->SetRadiusMin( rMin ); double tempXMax = this->GetRadiusMax(); this->SetRadiusMax( rMax ); - double tempXStep = this->GetRadiusStep(); - this->SetRadiusStep( rStep ); - double tempXTolerance = this->GetRadiusTolerance(); - this->SetRadiusTolerance( rTolerance ); - this->GenerateKernel(); + this->GenerateKernelProfile(); - this->UpdateKernelOptimalRadius(); + this->OptimizeKernelRadius(); this->SetRadiusStart( tempXStart ); this->SetRadiusMin( tempXMin ); this->SetRadiusMax( tempXMax ); - this->SetRadiusStep( tempXStep ); - this->SetRadiusTolerance( tempXTolerance ); - this->SetNumKernelPoints( tempNumPoints ); + this->SetKernelNumberOfPoints( tempNumPoints ); - r0 = this->GetKernelOptimalRadius() * m_Spacing; + r0 = this->GetKernelOptimalRadius(); return true; } @@ -216,141 +275,197 @@ RadiusExtractor3 template< class TInputImage > void RadiusExtractor3 -::SetNumKernelPoints( unsigned int _numPoints ) +::SetKernelNumberOfPoints( unsigned int _numPoints ) { - m_NumKernelPoints = _numPoints; - m_KernelTube->GetPoints().resize( m_NumKernelPoints ); + m_KernelNumberOfPoints = _numPoints; + m_KernelTube->GetPoints().resize( m_KernelNumberOfPoints ); } template< class TInputImage > -void +double RadiusExtractor3 -::GenerateKernel( void ) +::GetProfileMaxDistance() { + double maxR = this->GetRadiusMax() - this->GetRadiusMin(); + + double profileMaxDistance = maxR * pow(m_ProfileNumberOfBins, 1.6) + / pow(m_ProfileNumberOfBins-2, 1.6); + + profileMaxDistance += this->GetRadiusMin(); + + return profileMaxDistance; +} + +template< class TInputImage > +double +RadiusExtractor3 +::GetProfileBinRadius( double i ) +{ + i = fabs(i); + + double maxR = this->GetRadiusMax() - this->GetRadiusMin(); + double profileMaxDistance = this->GetProfileMaxDistance(); - IndexType minXI; - IndexType maxXI; + double x = pow( i, 1.6 ) / pow( m_ProfileNumberOfBins, 1.6 ) + * profileMaxDistance; - double maxKernelR = this->GetRadiusMaxInIndexSpace(); - double maxKernelDist = this->GetKernelExtent() * maxKernelR; + x += this->GetRadiusMin(); + + return x; +} + +template< class TInputImage > +double +RadiusExtractor3 +::GetProfileBinNumber( double x ) +{ + x = fabs(x); + + double maxR = this->GetRadiusMax() - this->GetRadiusMin(); + double profileMaxDistance = this->GetProfileMaxDistance(); + + x -= this->GetRadiusMin(); + + double i = pow( ( x * pow(m_ProfileNumberOfBins, 1.6 ) / profileMaxDistance ), + ( 1.0 / 1.6) ); + + return i; +} + +template< class TInputImage > +void +RadiusExtractor3 +::GenerateKernelProfile( void ) +{ + IndexType minXIndex; + IndexType maxXIndex; + + double maxR = this->GetRadiusMax(); + double profileMaxDistance = this->GetProfileMaxDistance(); + double profileMaxIndex = profileMaxDistance/m_Spacing; typename std::vector< TubePointType >::iterator pntIter; pntIter = m_KernelTube->GetPoints().begin(); - IndexType kernelPointI; - m_InputImage->TransformPhysicalPointToIndex( - m_KernelTube->GetPoints()[0].GetPositionInObjectSpace(), kernelPointI ); + PointType p = pntIter->GetPositionInObjectSpace(); + IndexType kernelPointIndex; + m_InputImage->TransformPhysicalPointToIndex( p, kernelPointIndex ); for( unsigned int i = 0; i < ImageDimension; ++i ) { - minXI[i] = static_cast< int >( kernelPointI[i] - (maxKernelDist + 0.5) ); - maxXI[i] = static_cast< int >( kernelPointI[i] + (maxKernelDist + 0.5) ); + minXIndex[i] = static_cast< int >( kernelPointIndex[i] - + (profileMaxIndex + 0.5) ); + maxXIndex[i] = static_cast< int >( kernelPointIndex[i] + + (profileMaxIndex + 0.5) ); } ++pntIter; - int tempI; + int tempIndex; while( pntIter != m_KernelTube->GetPoints().end() ) { - IndexType kernelPoint; - m_InputImage->TransformPhysicalPointToIndex( - pntIter->GetPositionInObjectSpace(), kernelPoint ); + p = pntIter->GetPositionInObjectSpace(); + m_InputImage->TransformPhysicalPointToIndex( p, kernelPointIndex ); for( unsigned int i = 0; i < ImageDimension; ++i ) { - tempI = static_cast< int >( kernelPoint[i] - (maxKernelDist + 0.5) ); - if( tempI < minXI[i] ) + tempIndex = static_cast< int >( kernelPointIndex[i] - + (profileMaxIndex + 0.5) ); + if( tempIndex < minXIndex[i] ) { - minXI[i] = tempI; + minXIndex[i] = tempIndex; } - tempI = static_cast< int >( kernelPoint[i] + (maxKernelDist + 0.5) ); - if( tempI > maxXI[i] ) + tempIndex = static_cast< int >( kernelPointIndex[i] + + (profileMaxIndex + 0.5) ); + if( tempIndex > maxXIndex[i] ) { - maxXI[i] = tempI; + maxXIndex[i] = tempIndex; } } ++pntIter; } - unsigned int kernelSize = static_cast( maxKernelDist*3 ); - m_KernelValue.resize( kernelSize ); - std::fill( m_KernelValue.begin(), m_KernelValue.end(), 0 ); - m_KernelCount.resize( kernelSize ); - std::fill( m_KernelCount.begin(), m_KernelCount.end(), 0 ); - IndexType xI = minXI; + std::fill( m_ProfileBinValue.begin(), m_ProfileBinValue.end(), 0 ); + std::fill( m_ProfileBinCount.begin(), m_ProfileBinCount.end(), 0 ); + IndexType xIndex = minXIndex; bool done = false; while( !done ) { - if( m_InputImage->GetLargestPossibleRegion().IsInside( xI ) ) + if( m_InputImage->GetLargestPossibleRegion().IsInside( xIndex ) ) { - double val = ( m_InputImage->GetPixel( xI ) - m_DataMin ) + double val = ( m_InputImage->GetPixel( xIndex ) - m_DataMin ) / ( m_DataMax - m_DataMin ); - if( val < 0 ) + if( val >= 0 && val < 1 ) { - val = 0; - } - else if( val > 1 ) - { - val = 1; - } - PointType p; - m_InputImage->TransformIndexToPhysicalPoint( xI, p ); - - unsigned int pntCount = 0; - pntIter = m_KernelTube->GetPoints().begin(); - - double pntTangentDistI = 0; - double minTangentDistI = maxKernelR; - double minNormalDist = -1; - while( pntIter != m_KernelTube->GetPoints().end() ) - { - VectorType pDiff = p - pntIter->GetPositionInObjectSpace(); - double d1 = 0; - for( unsigned int i = 0; i < ImageDimension; ++i ) + PointType p; + m_InputImage->TransformIndexToPhysicalPoint( xIndex, p ); + + unsigned int pntCount = 0; + pntIter = m_KernelTube->GetPoints().begin(); + + double pntTangentDistance = 0; + double minTangentDistance = 2*m_Spacing; + double minNormalDistance = -1; + typename std::vector< TubePointType >::iterator minTangentPnt; + minTangentPnt = m_KernelTube->GetPoints().end(); + while( pntIter != m_KernelTube->GetPoints().end() ) { - double tf = pDiff[i] * pntIter->GetTangentInObjectSpace()[i]; - d1 += tf * tf; + VectorType pDiff = p - pntIter->GetPositionInObjectSpace(); + double d1 = 0; + for( unsigned int i = 0; i < ImageDimension; ++i ) + { + double tf = pDiff[i] * pntIter->GetTangentInObjectSpace()[i]; + d1 += tf * tf; + } + pntTangentDistance = std::sqrt( d1 ); + if( pntTangentDistance < minTangentDistance ) + { + minTangentDistance = pntTangentDistance; + minTangentPnt = pntIter; + } + ++pntIter; + ++pntCount; } - pntTangentDistI = std::sqrt( d1 ) / m_Spacing; - if( pntTangentDistI < minTangentDistI ) + if( minTangentPnt != m_KernelTube->GetPoints().end()) { - minTangentDistI = pntTangentDistI; - d1 = 0; + double d1 = 0; + VectorType pDiff = p - minTangentPnt->GetPositionInObjectSpace(); for( unsigned int i = 0; i < ImageDimension; ++i ) { - double tf = pDiff[i] * pntIter->GetNormal1InObjectSpace()[i]; + double tf = pDiff[i] * minTangentPnt->GetNormal1InObjectSpace()[i]; d1 += tf * tf; } - minNormalDist = d1; + minNormalDistance = d1; if( ImageDimension == 3 ) { double d2 = 0; for( unsigned int i = 0; i < ImageDimension; ++i ) { - double tf = pDiff[i] * pntIter->GetNormal2InObjectSpace()[i]; + double tf = pDiff[i] * minTangentPnt->GetNormal2InObjectSpace()[i]; d2 += tf * tf; } - minNormalDist += d2; + minNormalDistance += d2; + } + + double dist = std::sqrt( minNormalDistance ); + double bin = this->GetProfileBinNumber( dist ); + if( bin >= 0 && bin < static_cast(m_ProfileNumberOfBins) ) + { + m_ProfileBinValue[ (int)bin ] += val; + m_ProfileBinCount[ (int)bin ]++; + if( bin > 0 ) + { + m_ProfileBinValue[ bin-1 ] += 0.5 * val * (1-(bin-(int)bin)); + m_ProfileBinCount[ bin-1 ] += 0.5 * (1-(bin-(int)bin)); + } + if( bin < static_cast(m_ProfileNumberOfBins)-1 ) + { + m_ProfileBinValue[ bin+1 ] += 0.5 * val * (bin-(int)bin); + m_ProfileBinCount[ bin+1 ] += 0.5 * (bin-(int)bin); + } } - } - ++pntIter; - ++pntCount; - } - if( minNormalDist != -1 ) - { - double distI = std::sqrt( minNormalDist ) / m_Spacing; - double count = (distI / maxKernelDist) * kernelSize; - // std::cout << distI << " : " << count << " : " << val << std::endl; - if( count < 0 ) - { - count = 0; - } - if( count < kernelSize ) - { - m_KernelValue[ count ] += val; - m_KernelCount[ count ]++; } } } unsigned int d = 0; - while( d < ImageDimension && ++xI[d] > maxXI[d] ) + while( d < ImageDimension && ++xIndex[d] > maxXIndex[d] ) { - xI[d] = minXI[d]; + xIndex[d] = minXIndex[d]; ++d; } if( d >= ImageDimension ) @@ -358,15 +473,41 @@ RadiusExtractor3 done = true; } } - for(unsigned int i=0; i 0 ) + if( m_ProfileBinCount[i] > 0 && m_ProfileBinValue[i] > 0 ) + { + m_ProfileBinValue[i] /= m_ProfileBinCount[i]; + } + else { - m_KernelValue[i] /= m_KernelCount[i]; + if( i>0 ) + { + m_ProfileBinValue[i] = m_ProfileBinValue[i-1]; + } } - //std::cout << m_KernelValue[i] << "(" << m_KernelCount[i] << ") "; } - //std::cout << std::endl; + int i=0; + while(i(m_ProfileNumberOfBins) && + m_ProfileBinValue[i]<=m_ProfileBinValue[i+1]) + { + ++i; + } + while(i>0) + { + m_ProfileBinValue[i-1] = m_ProfileBinValue[i]; + --i; + } + i = m_ProfileNumberOfBins-1; + while(i>0 && m_ProfileBinValue[i]>=m_ProfileBinValue[i-1]) + { + --i; + } + while(i(m_ProfileNumberOfBins)-1) + { + m_ProfileBinValue[i+1] = m_ProfileBinValue[i]; + ++i; + } } template< class TInputImage > @@ -374,189 +515,169 @@ void RadiusExtractor3 ::SetKernelTubePoints( const std::vector< TubePointType > & tubePoints ) { - if( tubePoints.size() != m_NumKernelPoints ) + if( tubePoints.size() != m_KernelNumberOfPoints ) { std::cerr << "Error: number of kernel points not equal to expected." << std::endl; std::cerr << " TubePointsSize = " << tubePoints.size() << std::endl; - std::cerr << " NumKernelPoints = " << m_NumKernelPoints << std::endl; + std::cerr << " KernelNumberOfPoints = " << m_KernelNumberOfPoints + << std::endl; } m_KernelTube->SetPoints( tubePoints ); - m_KernelTube->ComputeTangentsAndNormals(); -} - -template< class TInputImage > -double -RadiusExtractor3 -::GetKernelMedialness( double r ) -{ - int kernelSize = m_KernelValue.size(); - double maxKernelR = this->GetRadiusMaxInIndexSpace(); - double maxKernelDist = this->GetKernelExtent() * maxKernelR; - - double maxV = 0; - double minV = 1; - for( unsigned int i = 1; i 1 ) { - double val = 0; - unsigned int count = 0; - for( unsigned int j = i-1; jComputeTangentsAndNormals(); + } + + if( tubePoints.size() == 1 ) + { + auto kernPnt = m_KernelTube->GetPoints().begin(); + VectorType v; + v.Fill(0); + v[0] = 1; + CovariantVector cv; + cv.Fill(0); + cv[1] = 1; + double sum = 0; + for( unsigned int i=0; iGetTangentInObjectSpace()[i]); + } + if( sum == 0 ) { - if( m_KernelCount[i] > 0 ) + sum = 0; + for( unsigned int i=0; iGetNormal1InObjectSpace()[i]); + } + if( sum == 0 ) + { + std::cout << "WARNING: Single point kernel, setting tangent and normals." + << std::endl; + kernPnt->SetTangentInObjectSpace(v); + kernPnt->SetNormal1InObjectSpace(cv); + if( ImageDimension > 2 ) + { + cv.Fill(0); + cv[2] = 1; + kernPnt->SetNormal2InObjectSpace(cv); + } + } + else { - val += m_KernelValue[i]; - ++count; + std::cout << "WARNING: Single point kernel, setting tangent." + << std::endl; + kernPnt->SetTangentInObjectSpace(v); } } - if( count > 0 ) + sum = 0; + for( unsigned int i=0; iGetNormal1InObjectSpace()[i]); } - if( val > maxV ) + if( sum == 0 ) { - maxV = val; + std::cout << "WARNING: Single point kernel, resetting normal 1" + << std::endl; + kernPnt->SetNormal1InObjectSpace(cv); } - if( val < minV ) + if( ImageDimension > 2 ) { - minV = val; + sum = 0; + for( unsigned int i=0; iGetNormal2InObjectSpace()[i]); + } + if( sum == 0 ) + { + std::cout << "WARNING: Single point kernel, resetting normal 2" + << std::endl; + kernPnt->SetNormal2InObjectSpace(cv); + } } } - - double medialness = 0; - if( maxV > minV ) - { - medialness = minV + (maxV - minV) / 2; - } - - return medialness; -} - -template< class TInputImage > -double -RadiusExtractor3 -::GetKernelBranchness( double r ) -{ - return 0; } template< class TInputImage > bool RadiusExtractor3 -::UpdateKernelOptimalRadius( void ) +::OptimizeKernelRadius( void ) { - unsigned int kernelSize = m_KernelValue.size(); - double maxKernelR = this->GetRadiusMaxInIndexSpace(); - double maxKernelDist = this->GetKernelExtent() * maxKernelR; - - double maxV = 0; - double minV = 1; - unsigned int maxI = 0; - unsigned int minI = kernelSize-1; - for( unsigned int i = 1; iGetRadiusMin(); + double rMax = this->GetRadiusMax(); + + m_KernelOptimalRadius = this->GetRadiusStart(); + + typedef FRPROptimizer OptimizerType; + OptimizerType::Pointer opt = OptimizerType::New(); + + itk::ProfileCurve::Pointer curvFunc = itk::ProfileCurve::New(); + curvFunc->SetData( &m_ProfileBinValue ); + + OptimizerType::ParametersType params; + params.SetSize(4); + params[0] = ( m_ProfileBinValue[0] + m_ProfileBinValue[1] ) / 2; + params[1] = params[0] - (m_ProfileBinValue[m_ProfileNumberOfBins-2] + + m_ProfileBinValue[m_ProfileNumberOfBins-1])/2; + params[2] = 1; + params[3] = this->GetProfileBinNumber(m_KernelOptimalRadius); + + OptimizerType::ScalesType scales; + scales.SetSize(4); + scales[0] = 10.0; + scales[1] = 10.0; + scales[2] = 0.8; + scales[3] = 0.001; + + opt->SetCostFunction( curvFunc.GetPointer() ); + opt->SetScales( scales ); + opt->SetInitialPosition( params ); + opt->SetUseUnitLengthGradient(true); + opt->SetStepLength(1.0); + opt->SetCatchGetValueException( true ); + opt->SetMaximumIteration(200); + opt->SetMaximumLineIteration(100); + opt->SetStepTolerance(0.01); + opt->StartOptimization(); + + params = opt->GetCurrentPosition(); + + m_KernelOptimalRadius = this->GetProfileBinRadius(params[3]); + m_KernelOptimalRadiusMedialness = params[1]; + m_KernelOptimalRadiusBranchness = params[2]; + + if( this->GetKernelOptimalRadiusMedialness() < m_MinMedialness ) + { + m_KernelOptimalRadius = ( m_KernelOptimalRadius + this->GetRadiusStart() ) + / 2.0; + if(this->GetDebug()) { - if( m_KernelCount[j] > 0 ) - { - val += m_KernelValue[j]; - ++count; - } - } - if( count > 0 ) - { - val /= count; - if( val < minV) - { - minV = val; - minI = i; - } - } - } - for( unsigned int i = minI-1; i>0; --i ) - { - double val = 0; - unsigned int count = 0; - for( unsigned int j = i-1; j 0 ) - { - val += m_KernelValue[j]; - ++count; - } - } - if( count > 0 ) - { - val /= count; - if( val > maxV ) - { - maxV = val; - maxI = i; - } + std::cout << "r = " << m_KernelOptimalRadius << " : Medialness Limit = " + << m_KernelOptimalRadiusMedialness << std::endl; } } - double thresh = 0; - if( maxV > minV ) - { - thresh = minV + (maxV - minV) / 2; - for(unsigned int i = maxI+1; i 0 ) - { - val += m_KernelValue[j]; - ++count; - } - } - if( count > 0 ) - { - val /= count; - if( val < thresh ) - { - m_KernelOptimalRadius = ( (i-0.5) / (double)(kernelSize) ) * maxKernelDist; - break; - } - } - } - } - else - { - m_KernelOptimalRadius = 1; - } - //std::cout << " " << thresh << " : " << m_KernelOptimalRadius << std::endl; + if(m_KernelOptimalRadiusGetRadiusMin()) + { + m_KernelOptimalRadius = this->GetRadiusMin(); + } + else if(m_KernelOptimalRadius>this->GetRadiusMax()) + { + m_KernelOptimalRadius = this->GetRadiusMax(); + } - switch( m_RadiusCorrectionFunction ) + if( this->GetDebug() ) { - default: - case RADIUS_CORRECTION_NONE: - { - // Unchanged value: m_KernelOptimalRadius = m_KernelOptimalRadius; - break; - } - case RADIUS_CORRECTION_FOR_BINARY_IMAGE: - { - m_KernelOptimalRadius = ( m_KernelOptimalRadius * m_KernelOptimalRadius ) / 24 + 0.5; - break; - } - case RADIUS_CORRECTION_FOR_CTA: + std::cout << "Params = " << params << std::endl; + std::cout << "............ Kernel = "; + for(unsigned int i=0; i ::ExtractRadii( TubeType * tube, bool verbose ) { unsigned int tubeSize = tube->GetPoints().size(); - if( tubeSize < m_NumKernelPoints * m_KernelPointStep ) + if( tubeSize < m_KernelNumberOfPoints * m_KernelPointStep ) { return false; } @@ -598,11 +719,13 @@ RadiusExtractor3 ::tube::WarningMessage( "Warning: PointID 0 not found. Using mid-point of tube." ); } + pntCount = 0; pntIter = tube->GetPoints().begin(); unsigned int psize = tube->GetPoints().size(); for( unsigned int i=0; iGetDebug() ) @@ -619,34 +742,58 @@ RadiusExtractor3 { this->SetRadiusStart( rStart ); this->GenerateKernelTubePoints( p, tube ); - this->GenerateKernel(); - this->UpdateKernelOptimalRadius(); + this->GenerateKernelProfile(); + this->OptimizeKernelRadius(); this->RecordOptimaAtTubePoints( p, tube ); - rStart = this->GetKernelOptimalRadius() * m_Spacing; if( verbose ) { - std::cout << p << " : r = " << rStart << std::endl; + std::cout << p << " : x = " + << tube->GetPoints()[p].GetPositionInObjectSpace() + << " : r = " << tube->GetPoints()[p].GetRadiusInObjectSpace() + << std::endl; + if( this->GetDebug() ) + { + std::cout << "............ Kernel = "; + for(unsigned int i=0; iGetProfileBinRadius(i) + << " " << m_ProfileBinValue[i] + << " (" << m_ProfileBinCount[i] << ")" << std::endl; + } + std::cout << std::endl; + } } } rStart = rStart0; - for( int p = static_cast< int >( pntCount ) - - this->GetKernelPointStep(); p >= 0; + for( int p = static_cast< int >( pntCount ) + this->GetKernelStep()/2; p >= 0; p -= this->GetKernelStep() ) { this->SetRadiusStart( rStart ); this->GenerateKernelTubePoints( p, tube ); - this->GenerateKernel(); - this->UpdateKernelOptimalRadius(); + this->GenerateKernelProfile(); + this->OptimizeKernelRadius(); this->RecordOptimaAtTubePoints( p, tube ); - rStart = this->GetKernelOptimalRadius() * m_Spacing; if( verbose ) { - std::cout << p << " : r = " << rStart << std::endl; + std::cout << p << " : x = " + << tube->GetPoints()[p].GetPositionInObjectSpace() + << " : r = " << tube->GetPoints()[p].GetRadiusInObjectSpace() + << std::endl; + if(this->GetDebug()) + { + std::cout << "............ Kernel = "; + for(unsigned int i=0; iGetDebug() ) + if( this->GetDebug() ) { ::tube::DebugMessage( "Radius results:" ); pntIter = tube->GetPoints().begin(); @@ -668,50 +815,33 @@ RadiusExtractor3 TubeType * tube ) { unsigned int tubeSize = tube->GetPoints().size(); - if( tubeSize < m_NumKernelPoints * m_KernelPointStep ) + if( tubeSize < m_KernelNumberOfPoints * m_KernelPointStep ) { std::cerr << "RadiusExtractor: Tube length is too short" << std::endl; return; } - int startP = tubePointNum - ( m_NumKernelPoints / 2 ) * m_KernelPointStep; + int startP = tubePointNum - ( (m_KernelNumberOfPoints-1) / 2 ) * m_KernelPointStep; + int endP = startP + ( m_KernelNumberOfPoints - 1 ) * m_KernelPointStep; - int endP = startP + ( m_NumKernelPoints - 1 ) * m_KernelPointStep; + if( startP < 0 || endP >= static_cast(tubeSize)) + { + if( startP < 0) + { + startP = 0; + endP = startP + ( m_KernelNumberOfPoints - 1 ) * m_KernelPointStep; + } + else + { + endP = tubeSize-1; + startP = endP - ( m_KernelNumberOfPoints - 1 ) * m_KernelPointStep; + } + } unsigned int count = 0; for( int p = startP; p <= endP; p += m_KernelPointStep ) { - if( p < 0 ) - { - typename TubeType::PointType p1 = - tube->GetPoints()[ 0 ].GetPositionInObjectSpace(); - typename TubeType::PointType p2 = - tube->GetPoints()[ m_NumKernelPoints / 2 * - m_KernelPointStep ].GetPositionInObjectSpace(); - for( unsigned int i = 0; i < ImageDimension; ++i ) - { - p2[i] = p1[i] - ( ( p2[i] - p1[i] ) * ( -p / m_KernelPointStep ) ); - } - m_KernelTube->GetPoints()[ count ].SetPositionInObjectSpace( p2 ); - } - else if( p > static_cast< int >( tubeSize ) - 1 ) - { - typename TubeType::PointType p1 = - tube->GetPoints()[ tubeSize - 1 ].GetPositionInObjectSpace(); - typename TubeType::PointType p2 = - tube->GetPoints()[ tubeSize - 1 - m_NumKernelPoints / 2 * - m_KernelPointStep ].GetPositionInObjectSpace(); - for( unsigned int i = 0; i < ImageDimension; ++i ) - { - p2[i] = p1[i] - ( ( p2[i] - p1[i] ) * ( ( p - ( tubeSize-1 ) ) / - m_KernelPointStep ) ); - } - m_KernelTube->GetPoints()[ count ].SetPositionInObjectSpace( p2 ); - } - else - { - m_KernelTube->GetPoints()[ count ] = tube->GetPoints()[ p ]; - } + m_KernelTube->GetPoints()[ count ] = tube->GetPoints()[ p ]; ++count; } @@ -728,12 +858,18 @@ RadiusExtractor3 int midNum = static_cast(tubePointNum); - double r1 = this->GetKernelOptimalRadius() * m_Spacing; + double r1 = this->GetKernelOptimalRadius(); double m1 = this->GetKernelOptimalRadiusMedialness(); double b1 = this->GetKernelOptimalRadiusBranchness(); + if( tube->GetPoints()[midNum].GetRadiusInObjectSpace() != 0 ) + { + r1 = (r1 + tube->GetPoints()[midNum].GetRadiusInObjectSpace())/2.0; + m1 = (m1 + tube->GetPoints()[midNum].GetMedialness())/2.0; + b1 = (b1 + tube->GetPoints()[midNum].GetBranchness())/2.0; + } int startP = midNum - - ( m_NumKernelPoints / 2 ) * m_KernelPointStep - 1; + - ( m_KernelNumberOfPoints / 2 ) * m_KernelPointStep - 1; if( startP < 0 ) { startP = 0; @@ -748,7 +884,7 @@ RadiusExtractor3 b0 = b1; } - int endP = startP + ( m_NumKernelPoints ) * m_KernelPointStep + 1; + int endP = startP + ( m_KernelNumberOfPoints ) * m_KernelPointStep + 1; if( endP > tubeSize-1 ) { endP = tubeSize-1; @@ -763,6 +899,12 @@ RadiusExtractor3 b2 = b1; } + double rMax = this->GetRadiusMax(); + if( r0 > rMax || r1 > rMax || r2 > rMax ) + { + std::cout << "ERROR: Max r exceeded." << r0 << ", " << r1 << ", " << r2 + << std::endl; + } for( int p = startP; p <= endP; ++p ) { if( p < midNum ) @@ -787,6 +929,11 @@ RadiusExtractor3 tube->GetPoints()[ p ].SetMedialness( d * m2 + ( 1 - d ) * m1 ); tube->GetPoints()[ p ].SetBranchness( d * b2 + ( 1 - d ) * b1 ); } + if( tube->GetPoints()[p].GetRadiusInObjectSpace() > rMax ) + { + std::cout << "ERROR: Max r exceeded." + << tube->GetPoints()[p].GetRadiusInObjectSpace() << std::endl; + } } } @@ -815,21 +962,19 @@ RadiusExtractor3 << m_RadiusMinInIndexSpace << std::endl; os << indent << "RadiusMaxInIndexSpace = " << m_RadiusMaxInIndexSpace << std::endl; - os << indent << "RadiusStepInIndexSpace = " - << m_RadiusStepInIndexSpace << std::endl; - os << indent << "RadiusToleranceInIndexSpace = " - << m_RadiusToleranceInIndexSpace << std::endl; os << indent << "MinMedialness = " << m_MinMedialness << std::endl; os << indent << "MinMedialnessStart = " << m_MinMedialnessStart << std::endl; - os << indent << "NumKernelPoints = " << m_NumKernelPoints << std::endl; + os << indent << "KernelNumberOfPoints = " << m_KernelNumberOfPoints << std::endl; os << indent << "KernelPointStep = " << m_KernelPointStep << std::endl; os << indent << "KernelStep = " << m_KernelStep << std::endl; - os << indent << "KernelExtent = " << m_KernelExtent << std::endl; - os << indent << "KernelValue = " << m_KernelValue.size() << std::endl; - os << indent << "KernelCount = " << m_KernelCount.size() + + os << indent << "ProfileNumberOfBins = " << m_ProfileNumberOfBins + << std::endl; + os << indent << "ProfileBinValue = " << m_ProfileBinValue.size() << std::endl; + os << indent << "ProfileBinCount = " << m_ProfileBinCount.size() << std::endl; os << indent << "KernelOptimalRadius = " << m_KernelOptimalRadius diff --git a/src/Segmentation/itktubeRidgeExtractor.hxx b/src/Segmentation/itktubeRidgeExtractor.hxx index f547d8348..832750640 100644 --- a/src/Segmentation/itktubeRidgeExtractor.hxx +++ b/src/Segmentation/itktubeRidgeExtractor.hxx @@ -156,6 +156,7 @@ RidgeExtractor m_FailureCodeCount.fill( 0 ); m_Tube = nullptr; + m_TubeMaskImage == nullptr; } /** @@ -825,7 +826,7 @@ RidgeExtractor pnt.SetCurvature( curvature ); pnt.SetIntensity( intensity ); pnt.SetLevelness( levelness ); - pnt.SetRadiusInObjectSpace( this->GetScale() ); + pnt.SetRadiusInObjectSpace(0); pnt.SetMedialness( 0 ); pnt.SetBranchness( 0 ); pnts.push_back( pnt ); @@ -1236,31 +1237,27 @@ RidgeExtractor pnt.SetId( tubePointCount ); typename TubePointType::PointType tubeX; typename TubePointType::VectorType tubeT; - typename TubePointType::CovariantVectorType tubeN; + typename TubePointType::CovariantVectorType tubeN1; + typename TubePointType::CovariantVectorType tubeN2; ContinuousIndexType tubeXI; for( unsigned int i=0; i 2 ) { - for( unsigned int j=0; j 2 ) + { + pnt.SetNormal2InObjectSpace( tubeN2 ); + pnt.SetAlpha2( m_XHEVal[1] ); + } m_InputImage->TransformContinuousIndexToPhysicalPoint( tubeXI, tubeX ); pnt.SetPositionInObjectSpace( tubeX ); pnt.SetRidgeness( ridgeness ); @@ -1268,7 +1265,7 @@ RidgeExtractor pnt.SetCurvature( curvature ); pnt.SetIntensity( intensity ); pnt.SetLevelness( levelness ); - pnt.SetRadiusInObjectSpace( this->GetScale() ); + pnt.SetRadiusInObjectSpace(0); pnt.SetMedialness( 0 ); pnt.SetBranchness( 0 ); pnts.push_back( pnt ); @@ -1292,46 +1289,49 @@ RidgeExtractor std::cout << "Ridge: TraverseOW: DynamicScale" << std::endl; } - TubePointType tmpPoint; - tmpPoint.SetRadiusInObjectSpace( this->GetScale() ); - tmpPoint.SetTangentInObjectSpace( pnt.GetTangentInObjectSpace() ); - tmpPoint.SetNormal1InObjectSpace( pnt.GetNormal1InObjectSpace() ); - tmpPoint.SetNormal1InObjectSpace( pnt.GetNormal2InObjectSpace() ); - tmpPoint.SetRidgeness( ridgeness ); - tmpPoint.SetRoundness( roundness ); - tmpPoint.SetCurvature( curvature ); - tmpPoint.SetIntensity( intensity ); - tmpPoint.SetLevelness( levelness ); - m_RadiusExtractor->SetRadiusStart( this->GetScale() ); - double radiusMin = m_RadiusExtractor->GetRadiusMin(); - double radiusMax = m_RadiusExtractor->GetRadiusMax(); - double radiusStep = m_RadiusExtractor->GetRadiusStep(); - double radiusTolerance = m_RadiusExtractor->GetRadiusTolerance(); + int pntsSize = pnts.size(); + unsigned int minTubeSize = m_RadiusExtractor->GetKernelNumberOfPoints() + * m_RadiusExtractor->GetKernelPointStep(); + int startP = pntsSize - minTubeSize; + int endP = pntsSize - 1; + int stepP = m_RadiusExtractor->GetKernelPointStep(); + if( startP < 0 ) + { + if(pntsSize < + static_cast(m_RadiusExtractor->GetKernelNumberOfPoints()*3)) + { + startP = endP; + } + else + { + startP = 0; + endP = pntsSize-1; + stepP = pntsSize / (m_RadiusExtractor->GetKernelNumberOfPoints()-1); + } + } std::vector< TubePointType > points; - for( unsigned int i=0; iTransformContinuousIndexToPhysicalPoint( tubeXI, tubeX ); - tmpPoint.SetPositionInObjectSpace( tubeX ); - points.push_back( tmpPoint ); - for( unsigned int i=0; i2) + { + tmpPoint.SetNormal2InObjectSpace( pnts[p].GetNormal2InObjectSpace() ); + } + tmpPoint.SetRadiusInObjectSpace( m_DynamicScaleUsed ); + points.push_back( tmpPoint ); + p += stepP; } - m_InputImage->TransformContinuousIndexToPhysicalPoint( tubeXI, tubeX ); - tmpPoint.SetPositionInObjectSpace( tubeX ); - points.push_back( tmpPoint ); - points.push_back( pnt ); - typename TubeType::Pointer tmpTube = TubeType::New(); - tmpTube->SetPoints( points ); - tmpTube->ComputeTangentsAndNormals(); + double radiusMin = m_RadiusExtractor->GetRadiusMin(); + double radiusMax = m_RadiusExtractor->GetRadiusMax(); if( m_RadiusExtractor->GetPointVectorOptimalRadius( points, - m_DynamicScaleUsed, radiusMin, radiusMax, radiusStep, - radiusTolerance ) ) + m_DynamicScaleUsed, radiusMin, radiusMax ) ) { - m_DynamicScaleUsed = ( tmpPoint.GetRadiusInObjectSpace() - + m_DynamicScaleUsed ) / 2; + m_DynamicScaleUsed = ( this->GetScale() + m_DynamicScaleUsed ) / 2; } if( m_StatusCallBack ) { @@ -1340,7 +1340,7 @@ RidgeExtractor m_DynamicScaleUsed ); m_StatusCallBack( s, NULL, 0 ); } - else if( this->GetDebug() || verbose ) + if( this->GetDebug() || verbose ) { std::cout << "Dynamic Scale = " << m_DynamicScaleUsed << std::endl; @@ -1759,28 +1759,41 @@ RidgeExtractor TubePointType tmpPoint; typename TubePointType::PointType tubeX; typename TubePointType::VectorType tubeV; + typename TubePointType::CovariantVectorType tubeCV1; + typename TubePointType::CovariantVectorType tubeCV2; for( unsigned int i=0; i 2 ) + { + lN(i,1) = m_XHEVect( i, 1 ); + tubeCV2[i] = m_XHEVect( i, 1 ); + } } tmpPoint.SetPositionInObjectSpace( tubeX ); tmpPoint.SetTangentInObjectSpace( tubeV ); + tmpPoint.SetNormal1InObjectSpace( tubeCV1 ); + if( ImageDimension > 2 ) + { + tmpPoint.SetNormal2InObjectSpace( tubeCV2 ); + } tmpPoint.SetIntensity( m_XVal ); tmpPoint.SetRidgeness( m_XRidgeness ); tmpPoint.SetRoundness( m_XRoundness ); tmpPoint.SetCurvature( m_XCurvature ); tmpPoint.SetLevelness( m_XLevelness ); - tmpPoint.SetRadiusInObjectSpace( scale0 ); + tmpPoint.SetRadiusInObjectSpace( m_RadiusExtractor->GetRadiusStart() ); double radiusMin = m_RadiusExtractor->GetRadiusMin(); double radiusMax = m_RadiusExtractor->GetRadiusMax(); - double radiusStep = m_RadiusExtractor->GetRadiusStep(); - double radiusTolerance = m_RadiusExtractor->GetRadiusTolerance(); std::vector< TubePointType > points; points.push_back( tmpPoint ); + double r0 = m_RadiusExtractor->GetRadiusStart(); if( !m_RadiusExtractor->GetPointVectorOptimalRadius( points, - scale0, radiusMin, radiusMax, radiusStep, radiusTolerance ) ) + r0, radiusMin, radiusMax ) ) { if( this->GetDebug() && m_StatusCallBack ) { @@ -1791,7 +1804,7 @@ RidgeExtractor } else { - m_DynamicScaleUsed = ( tmpPoint.GetRadiusInObjectSpace() + this->GetScale() ) / 2; + m_DynamicScaleUsed = ( r0 + scale0 ) / 2; } SetScale( m_DynamicScaleUsed ); diff --git a/src/Segmentation/itktubeSegmentTubeUsingMinimalPathFilter.h b/src/Segmentation/itktubeSegmentTubeUsingMinimalPathFilter.h index d093c69f7..4865e1328 100644 --- a/src/Segmentation/itktubeSegmentTubeUsingMinimalPathFilter.h +++ b/src/Segmentation/itktubeSegmentTubeUsingMinimalPathFilter.h @@ -95,8 +95,6 @@ class SegmentTubeUsingMinimalPathFilter: public Object itkGetMacro( StartRadius, double ); itkSetMacro( MaxRadius, double ); itkGetMacro( MaxRadius, double ); - itkSetMacro( StepSizeForRadiusEstimation, double ); - itkGetMacro( StepSizeForRadiusEstimation, double ); itkGetMacro( CostAssociatedWithExtractedTube, double ); itkSetMacro( CostAssociatedWithExtractedTube, double ); /** Sets the input tubes */ @@ -135,7 +133,6 @@ class SegmentTubeUsingMinimalPathFilter: public Object double m_OptimizerStepLengthRelax; double m_StartRadius; double m_MaxRadius; - double m_StepSizeForRadiusEstimation; double m_CostAssociatedWithExtractedTube; TubeGroupPointer m_Output; diff --git a/src/Segmentation/itktubeSegmentTubeUsingMinimalPathFilter.hxx b/src/Segmentation/itktubeSegmentTubeUsingMinimalPathFilter.hxx index 4e9aa3e7e..181068192 100644 --- a/src/Segmentation/itktubeSegmentTubeUsingMinimalPathFilter.hxx +++ b/src/Segmentation/itktubeSegmentTubeUsingMinimalPathFilter.hxx @@ -44,7 +44,6 @@ SegmentTubeUsingMinimalPathFilter< Dimension, TInputPixel > m_OptimizerStepLengthRelax = 0.999; m_StartRadius = 1; m_MaxRadius = 6; - m_StepSizeForRadiusEstimation = 0.5; m_CostAssociatedWithExtractedTube = 0.0; m_Output = NULL; } @@ -244,8 +243,6 @@ SegmentTubeUsingMinimalPathFilter< Dimension, TInputPixel > radiusExtractor->SetRadiusStart( m_StartRadius ); radiusExtractor->SetRadiusMin( 0.2 ); radiusExtractor->SetRadiusMax( m_MaxRadius ); - radiusExtractor->SetRadiusStep( m_StepSizeForRadiusEstimation ); - radiusExtractor->SetRadiusTolerance( 0.025 ); radiusExtractor->SetDebug( false ); radiusExtractor->ExtractRadii( pTube ); } diff --git a/src/Segmentation/itktubeTubeExtractor.h b/src/Segmentation/itktubeTubeExtractor.h index b507dce43..3246bad0e 100644 --- a/src/Segmentation/itktubeTubeExtractor.h +++ b/src/Segmentation/itktubeTubeExtractor.h @@ -149,6 +149,10 @@ class TubeExtractor : public Object * Get Data Maximum */ double GetDataMax( void ); + /** + * Set Data Limits - values outside of these limits are ignored */ + void SetDataMinMaxLimits( double limitMin, double limitMax ); + /** * Set the border within the image edges that vessels cannot enter */ void SetBorderInIndexSpace( int border ); diff --git a/src/Segmentation/itktubeTubeExtractor.hxx b/src/Segmentation/itktubeTubeExtractor.hxx index cd1683927..9f7eef443 100644 --- a/src/Segmentation/itktubeTubeExtractor.hxx +++ b/src/Segmentation/itktubeTubeExtractor.hxx @@ -31,6 +31,8 @@ limitations under the License. #include "itktubeTubeExtractor.h" +#include + #include #include #include @@ -184,6 +186,22 @@ TubeExtractor return this->m_RidgeExtractor->GetDataMin(); } + +template< class TInputImage > +void +TubeExtractor +::SetDataMinMaxLimits( double limitMin, double limitMax ) +{ + typedef LimitedMinimumMaximumImageFilter MinMaxFilterType; + typename MinMaxFilterType::Pointer minMaxFilter = MinMaxFilterType::New(); + minMaxFilter->SetInput( this->GetInputImage() ); + minMaxFilter->SetMinimumLimit( limitMin ); + minMaxFilter->SetMaximumLimit( limitMax ); + minMaxFilter->Update(); + this->SetDataMin( minMaxFilter->GetMinimum() ); + this->SetDataMax( minMaxFilter->GetMaximum() ); +} + /** * Set Data Max value */ template< class TInputImage > @@ -692,7 +710,6 @@ TubeExtractor if( useRadiiList ) { this->SetRadiusInObjectSpace( *seedRadiusIter ); - std::cout << " Radius = " << *seedRadiusIter << std::endl; ++seedRadiusIter; } diff --git a/test/Baseline/ConvertTubesToTubeTreeTest1-Tree.tre.sha512 b/test/Baseline/ConvertTubesToTubeTreeTest1-Tree.tre.sha512 index 55658536d..25bb13d81 100644 --- a/test/Baseline/ConvertTubesToTubeTreeTest1-Tree.tre.sha512 +++ b/test/Baseline/ConvertTubesToTubeTreeTest1-Tree.tre.sha512 @@ -1 +1 @@ -14581e42f86946a5ae55303f65dc9e9319867da7a1b0a80ed21ebbd77f1ee65f854e69847ca3811b4a1e47fc85977b46002fb884c587963c70cc5402b30e3874 +c126b7f6193609c027e19156495498e97b6a663c449da7d25e135dd56d90c7f3f788c4a97e382dc2b815b0db0555d6a8693e3fc6b3883bfd87fef2d67f915509 diff --git a/test/Baseline/ConvertTubesToTubeTreeTest2-Tree.tre.sha512 b/test/Baseline/ConvertTubesToTubeTreeTest2-Tree.tre.sha512 index c44ccb447..cbcf769bc 100644 --- a/test/Baseline/ConvertTubesToTubeTreeTest2-Tree.tre.sha512 +++ b/test/Baseline/ConvertTubesToTubeTreeTest2-Tree.tre.sha512 @@ -1 +1 @@ -8a8d5a323fb0cac3869c5ead10ddc992c098e112f0fb6c2c9fe0e3349bea2d1b7e914fe6f8c72c96376f5b5a543be08f0e12f10f570acb9f9a03b91105e7ef3e +baab6852a989cc3b2befebf6449380fb288bbcf8ff3290939cee5ec4b87d4b583675a44766e0b02b8b431459443652ca3cf7a280feadad9248e2fd4675d22541 diff --git a/test/Baseline/CropTubes-Test1_NotCropped.tre.sha512 b/test/Baseline/CropTubes-Test1_NotCropped.tre.sha512 index 0c6f34f57..69c8ab312 100644 --- a/test/Baseline/CropTubes-Test1_NotCropped.tre.sha512 +++ b/test/Baseline/CropTubes-Test1_NotCropped.tre.sha512 @@ -1 +1 @@ -cd5438c18b13d66982745f34d1909917fc78289539c3d75b63b3e73d26f2c6474d6bac0b8aa23f7d728b4134399102d24442e8317fb576a016a24cd5ad64ad89 \ No newline at end of file +4b03fa825499583558dbe1e7c49f094dd4380f488b578320cbca980eea650aad39151fb6419716ddb703bf05c9aa0cef04c6aa3fe7f3a072a7ee7fa1c408ec77 diff --git a/test/Baseline/CropTubes-Test2_Cropped.tre.sha512 b/test/Baseline/CropTubes-Test2_Cropped.tre.sha512 index 366337452..9de6f4b3e 100644 --- a/test/Baseline/CropTubes-Test2_Cropped.tre.sha512 +++ b/test/Baseline/CropTubes-Test2_Cropped.tre.sha512 @@ -1 +1 @@ -66733d38391facdd43453adb065e87b5205b858a9563e8c9d2dbc7902818242b7247eebb7e25d0cbb27fe3d405ce4f0001833e43b8dcf88b421c489170e1bc0e \ No newline at end of file +13d3440385eb1d4c9c26b168389c8f9b515ef3c6dbe29219f422ffe4286d9d305428cbaf995d3056b3a11610f1a03e3dd05d44e47e0cd16b4537bf104eb8218d diff --git a/test/Baseline/ResampleTubesTest1.tre.sha512 b/test/Baseline/ResampleTubesTest1.tre.sha512 index 8dd12743e..59eef3ef3 100644 --- a/test/Baseline/ResampleTubesTest1.tre.sha512 +++ b/test/Baseline/ResampleTubesTest1.tre.sha512 @@ -1 +1 @@ -e9874132ab0c9150f320b765ef8f689f5db30a3244d8c193750d0aa905ff9f9667bbdccfd271fdea348483075e8eeb9001ea961eac521c8dd6efa0d9ee3a8984 +b280bcf2dfc8427f159dfa1eeec446a2e650b9b49c75c94bb0ba1a7c0731398c25e7661c013ab29d42772c15a225e83d95c02caf890ccf5eadd6d68367fef3a9 diff --git a/test/Baseline/ResampleTubesTest2.tre.sha512 b/test/Baseline/ResampleTubesTest2.tre.sha512 index 980e480b3..6a2b57add 100644 --- a/test/Baseline/ResampleTubesTest2.tre.sha512 +++ b/test/Baseline/ResampleTubesTest2.tre.sha512 @@ -1 +1 @@ -5da5cf0f2e05e25f7265b950e056a82152ea9427eb3996492c2b219f393f49b21f1a22801dddcaa63d5abfda095b58a31b7c703d974cccbfea6a1861ed53e7c7 +8b04c0548e18c6534883df6656d4cc485c9aae3d81a4e9c7a5218d6bb2e834b0da17cdd338e608014d018457bc06658adc5c3ea9a5f76a0c8fadc1e932592432 diff --git a/test/Baseline/ResampleTubesTest3.tre.sha512 b/test/Baseline/ResampleTubesTest3.tre.sha512 index 5b8b7a03e..537d2bbc9 100644 --- a/test/Baseline/ResampleTubesTest3.tre.sha512 +++ b/test/Baseline/ResampleTubesTest3.tre.sha512 @@ -1 +1 @@ -b6e330c05ccc9fe9163e497fca2a94454f4b7b61f191882e60a77f5ea59f8bc716f434cfcd1d44bdba1e2d0965a81980f00653647e4f8cd41f5aa91a0890bfff +07b7d30b82a803279112648e9544e1e2d0264d3732267fdb9171420ceaa92a80cab033ede9dc74dd9f97b7b7fc72f63973855422981c0982763a588c1b06a9be diff --git a/test/Baseline/SegmentTubesTest1.mha.sha512 b/test/Baseline/SegmentTubesTest1.mha.sha512 index c4f05982a..78a047cd1 100644 --- a/test/Baseline/SegmentTubesTest1.mha.sha512 +++ b/test/Baseline/SegmentTubesTest1.mha.sha512 @@ -1 +1 @@ -1ff6f5ee449a9f25d91096809e3a98118c8c464e77e09c7cffde371e4c0fe10ce8b8c194a56ecd5ce13b9b49c255a02fcea251fa6ec80f6b5bd47705246efcd2 +fa9f37ae6b56e7d066c740df173af3abc0c9bd5f290728fba42df1f13e8846e97184e355e23e47e807dd8c0ce98f536a7fdb69baadedf23d1d25561bd49651ba diff --git a/test/Baseline/SegmentTubesTest2.mha.sha512 b/test/Baseline/SegmentTubesTest2.mha.sha512 index d8c19d85c..1949cd073 100644 --- a/test/Baseline/SegmentTubesTest2.mha.sha512 +++ b/test/Baseline/SegmentTubesTest2.mha.sha512 @@ -1 +1 @@ -da9109a10a7c51c4ce70a5dad5246664e614e9eb9c7dc71de7acf9a0d00930ffbfc74216b9783439446e94baf0b6458456e9c16475c14386cf4674438c817d9d +53be27771ab40908e188312f9afaecab4fb3117ff6ca14bad904c0f87423f231daf1c63fde0741cb722f02e3e58ffa8959a580f21f08a8963d1d63c146fc06e5 diff --git a/test/Baseline/TubeMath-Test1.tre.sha512 b/test/Baseline/TubeMath-Test1.tre.sha512 index 04e70440d..41fe49885 100644 --- a/test/Baseline/TubeMath-Test1.tre.sha512 +++ b/test/Baseline/TubeMath-Test1.tre.sha512 @@ -1 +1 @@ -163fd4f765561f02cb03d1307ab3ac96cf96131b013649e2b538224f3a38d90e8670082bd31ac5ecffd0bf2d6e7abcd3d6c2649aa74abe63d3e234439be80e67 +9f1148efaca2e9cf41b379d204eafe3a1ad478b06c0bfe829e64f9e6d05cb591842c4745d24103919aefd62561a0fda7d60ca9af28f4e82361ba0f5611ed6c95 diff --git a/test/Baseline/TubeMath-Test2.tre.sha512 b/test/Baseline/TubeMath-Test2.tre.sha512 index 89ccc3873..ecd744d08 100644 --- a/test/Baseline/TubeMath-Test2.tre.sha512 +++ b/test/Baseline/TubeMath-Test2.tre.sha512 @@ -1 +1 @@ -004a043e15e6903b3e034b303c946a8836676089fff321b4a17e747eca9ee5f627001c8e3e6bfda50c0f3a16e60098f7aa842b95a94c1f463c9c2a5dab331c7f +cf5d8a87b1441e92c3ad5d8f6c6c7c5b59a84b0cfca137fb0a164486c2ac6248023b7fa9a9478209376bb38d28c34e04e54c040c3d8e2ad43bd34f66afb1ad0e diff --git a/test/Baseline/itktubeTubeToTubeTransformFilter.mha.sha512 b/test/Baseline/itktubePointBasedSpatialObjectTransformFilter.mha.sha512 similarity index 100% rename from test/Baseline/itktubeTubeToTubeTransformFilter.mha.sha512 rename to test/Baseline/itktubePointBasedSpatialObjectTransformFilter.mha.sha512 diff --git a/test/Baseline/itktubeTubeToTubeTransformFilter.tre.sha512 b/test/Baseline/itktubePointBasedSpatialObjectTransformFilter.tre.sha512 similarity index 100% rename from test/Baseline/itktubeTubeToTubeTransformFilter.tre.sha512 rename to test/Baseline/itktubePointBasedSpatialObjectTransformFilter.tre.sha512 diff --git a/test/Filtering/CMakeLists.txt b/test/Filtering/CMakeLists.txt index c0e7b113f..0329cadf2 100644 --- a/test/Filtering/CMakeLists.txt +++ b/test/Filtering/CMakeLists.txt @@ -48,7 +48,7 @@ set( tubeFilteringTests_SRCS itktubeStructureTensorRecursiveGaussianImageFilterTest.cxx itktubeStructureTensorRecursiveGaussianImageFilterTestNew.cxx itktubeSubSampleTubeSpatialObjectFilterTest.cxx - itktubeSubSampleTubeTreeSpatialObjectFilterTest.cxx + itktubeSubSampleSpatialObjectFilterTest.cxx itktubeTortuositySpatialObjectFilterTest.cxx itktubeTubeEnhancingDiffusion2DImageFilterTest.cxx tubeTubeMathFiltersTest.cxx ) @@ -179,11 +179,11 @@ itk_add_test( ${ITK_TEST_OUTPUT_DIR}/itkSubSampleTubeSpatialObjectFilterTest.tre ) itk_add_test( - NAME itktubeSubSampleTubeTreeSpatialObjectFilterTest + NAME itktubeSubSampleSpatialObjectFilterTest COMMAND tubeFilteringTestDriver - itktubeSubSampleTubeTreeSpatialObjectFilterTest + itktubeSubSampleSpatialObjectFilterTest DATA{${TubeTK_DATA_ROOT}/Branch-truth-new.tre} - ${ITK_TEST_OUTPUT_DIR}/itkSubSampleTubeTreeSpatialObjectFilterTest.tre ) + ${ITK_TEST_OUTPUT_DIR}/itkSubSampleSpatialObjectFilterTest.tre ) itk_add_test( NAME itktubeTubeEnhancingDiffusion2DImageFilterTest diff --git a/test/Filtering/itktubeSubSampleTubeTreeSpatialObjectFilterTest.cxx b/test/Filtering/itktubeSubSampleSpatialObjectFilterTest.cxx similarity index 76% rename from test/Filtering/itktubeSubSampleTubeTreeSpatialObjectFilterTest.cxx rename to test/Filtering/itktubeSubSampleSpatialObjectFilterTest.cxx index 0b314d40d..5c8ea89c5 100644 --- a/test/Filtering/itktubeSubSampleTubeTreeSpatialObjectFilterTest.cxx +++ b/test/Filtering/itktubeSubSampleSpatialObjectFilterTest.cxx @@ -2,8 +2,7 @@ Library: TubeTK -Copyright 2010 Kitware Inc. 28 Corporate Drive, -Clifton Park, NY, 12065, USA. +Copyright Kitware Inc. All rights reserved. @@ -21,12 +20,12 @@ limitations under the License. =========================================================================*/ -#include "itktubeSubSampleTubeTreeSpatialObjectFilter.h" +#include "itktubeSubSampleSpatialObjectFilter.h" #include #include -int itktubeSubSampleTubeTreeSpatialObjectFilterTest( int argc, char * argv[] ) +int itktubeSubSampleSpatialObjectFilterTest( int argc, char * argv[] ) { if( argc < 3 ) { @@ -62,16 +61,15 @@ int itktubeSubSampleTubeTreeSpatialObjectFilterTest( int argc, char * argv[] ) << std::endl; // Sub-sample the tube tree. - typedef itk::tube::SubSampleTubeTreeSpatialObjectFilter< GroupSpatialObjectType, - TubeSpatialObjectType > - SubSampleTubeTreeFilterType; - SubSampleTubeTreeFilterType::Pointer subSampleTubeTreeFilter = - SubSampleTubeTreeFilterType::New(); - subSampleTubeTreeFilter->SetInput( reader->GetGroup() ); + typedef itk::tube::SubSampleSpatialObjectFilter<> + SubSampleFilterType; + SubSampleFilterType::Pointer subSampleFilter = + SubSampleFilterType::New(); + subSampleFilter->SetInput( reader->GetGroup() ); const unsigned int sampling = 100; - subSampleTubeTreeFilter->SetSampling( sampling ); - if( subSampleTubeTreeFilter->GetSampling() != sampling ) + subSampleFilter->SetSampling( sampling ); + if( subSampleFilter->GetSampling() != sampling ) { std::cerr << "Sampling did not get set correctly." << std::endl; return EXIT_FAILURE; @@ -81,12 +79,12 @@ int itktubeSubSampleTubeTreeSpatialObjectFilterTest( int argc, char * argv[] ) typedef itk::SpatialObjectWriter< Dimension > WriterType; WriterType::Pointer writer = WriterType::New(); writer->SetFileName( outputTubeNetwork ); - writer->SetInput( subSampleTubeTreeFilter->GetOutput() ); + writer->SetInput( subSampleFilter->GetOutput() ); try { // Currently, there is a bug in the SpatialObjectWriter that it does not do // a pipeline update on its inputs. - subSampleTubeTreeFilter->Update(); + subSampleFilter->Update(); writer->Update(); } catch( itk::ExceptionObject & error ) diff --git a/test/Filtering/itktubeSubSampleTubeSpatialObjectFilterTest.cxx b/test/Filtering/itktubeSubSampleTubeSpatialObjectFilterTest.cxx index 8b21ce55a..712a9e655 100644 --- a/test/Filtering/itktubeSubSampleTubeSpatialObjectFilterTest.cxx +++ b/test/Filtering/itktubeSubSampleTubeSpatialObjectFilterTest.cxx @@ -2,8 +2,7 @@ Library: TubeTK -Copyright 2010 Kitware Inc. 28 Corporate Drive, -Clifton Park, NY, 12065, USA. +Copyright Kitware Inc. All rights reserved. @@ -39,11 +38,11 @@ int itktubeSubSampleTubeSpatialObjectFilterTest( int argc, char * argv[] ) const char * inputTubeNetwork = argv[1]; const char * outputTubeNetwork = argv[2]; - enum { Dimension = 3 }; - typedef itk::TubeSpatialObject< Dimension > TubeSpatialObjectType; - typedef itk::GroupSpatialObject< Dimension > GroupSpatialObjectType; + enum { ObjectDimension = 3 }; + typedef itk::TubeSpatialObject< ObjectDimension > TubeSpatialObjectType; + typedef itk::GroupSpatialObject< ObjectDimension > GroupSpatialObjectType; - typedef itk::SpatialObjectReader< Dimension > ReaderType; + typedef itk::SpatialObjectReader< ObjectDimension > ReaderType; ReaderType::Pointer reader = ReaderType::New(); reader->SetFileName( inputTubeNetwork ); try @@ -74,7 +73,7 @@ int itktubeSubSampleTubeSpatialObjectFilterTest( int argc, char * argv[] ) dynamic_cast< TubeSpatialObjectType * >( ( *it ).GetPointer() ); if( pointBasedSpatialObject ) { - typedef itk::tube::SubSampleTubeSpatialObjectFilter< TubeSpatialObjectType > + typedef itk::tube::SubSampleTubeSpatialObjectFilter< ObjectDimension > SubSampleFilterType; SubSampleFilterType::Pointer subSampleFilter = SubSampleFilterType::New(); const unsigned int samplingFactor = 5; @@ -95,7 +94,7 @@ int itktubeSubSampleTubeSpatialObjectFilterTest( int argc, char * argv[] ) } - typedef itk::SpatialObjectWriter< Dimension > WriterType; + typedef itk::SpatialObjectWriter< ObjectDimension > WriterType; WriterType::Pointer writer = WriterType::New(); writer->SetFileName( outputTubeNetwork ); writer->SetInput( output ); diff --git a/test/Registration/CMakeLists.txt b/test/Registration/CMakeLists.txt index 1c28265ed..51e328974 100644 --- a/test/Registration/CMakeLists.txt +++ b/test/Registration/CMakeLists.txt @@ -35,18 +35,13 @@ itk_add_test( NAME tubeRegistrationHeaderTest set( tubeRegistrationTests_SRCS tubeRegistrationPrintTest.cxx - itktubeImageToTubeRigidMetricPerformanceTest.cxx - itktubeImageToTubeRigidMetricTest.cxx - itktubeImageToTubeRigidRegistrationPerformanceTest.cxx - itktubeImageToTubeRigidRegistrationTest.cxx + itktubeSpatialObjectToImageMetricPerformanceTest.cxx + itktubeSpatialObjectToImageMetricTest.cxx + itktubeSpatialObjectToImageRegistrationPerformanceTest.cxx + itktubeSpatialObjectToImageRegistrationTest.cxx itktubePointsToImageTest.cxx itktubeSyntheticTubeImageGenerationTest.cxx - itktubeTubeAngleOfIncidenceWeightFunctionTest.cxx - itktubeTubeExponentialResolutionWeightFunctionTest.cxx - itktubeTubeParametricExponentialResolutionWeightFunctionTest.cxx - itktubeTubeParametricExponentialWithBoundsResolutionWeightFunctionTest.cxx - itktubeTubePointWeightsCalculatorTest.cxx - itktubeTubeToTubeTransformFilterTest.cxx ) + itktubePointBasedSpatialObjectTransformFilterTest.cxx ) if( TubeTK_USE_VTK ) list( APPEND tubeRegistrationTests_SRCS @@ -67,35 +62,35 @@ itk_add_test( NAME tubeRegistrationPrintTest tubeRegistrationPrintTest ) itk_add_test( - NAME itktubeTubeToTubeTransformFilterTest + NAME itktubePointBasedSpatialObjectTransformFilterTest COMMAND tubeRegistrationTestDriver --compare - DATA{${TubeTK_DATA_ROOT}/itktubeTubeToTubeTransformFilter.mha} - ${ITK_TEST_OUTPUT_DIR}/itktubeTubeToTubeTransformFilter.mha - itktubeTubeToTubeTransformFilterTest + DATA{${TubeTK_DATA_ROOT}/itktubePointBasedSpatialObjectTransformFilter.mha} + ${ITK_TEST_OUTPUT_DIR}/itktubePointBasedSpatialObjectTransformFilter.mha + itktubePointBasedSpatialObjectTransformFilterTest DATA{${TubeTK_DATA_ROOT}/Branch-truth-new.tre} - ${ITK_TEST_OUTPUT_DIR}/itktubeTubeToTubeTransformFilter.tre + ${ITK_TEST_OUTPUT_DIR}/itktubePointBasedSpatialObjectTransformFilter.tre DATA{${TubeTK_DATA_ROOT}/Branch.n020.mha} - ${ITK_TEST_OUTPUT_DIR}/itktubeTubeToTubeTransformFilter.mha + ${ITK_TEST_OUTPUT_DIR}/itktubePointBasedSpatialObjectTransformFilter.mha 0.2 0.1 0.1 5 -5 5 1 ) itk_add_test( - NAME itktubeImageToTubeRigidRegistrationTest + NAME itktubeSpatialObjectToImageRegistrationTest COMMAND tubeRegistrationTestDriver - itktubeImageToTubeRigidRegistrationTest + itktubeSpatialObjectToImageRegistrationTest DATA{${TubeTK_DATA_ROOT}/Branch.n020.mha} DATA{${TubeTK_DATA_ROOT}/Branch-truth-new.tre} - ${ITK_TEST_OUTPUT_DIR}/itktubeImageToTubeRigidRegistrationOutputTube.tre - ${ITK_TEST_OUTPUT_DIR}/itktubeImageToTubeRigidRegistrationOutputImage.mha ) + ${ITK_TEST_OUTPUT_DIR}/itktubeSpatialObjectToImageRegistrationOutputTube.tre + ${ITK_TEST_OUTPUT_DIR}/itktubeSpatialObjectToImageRegistrationOutputImage.mha ) itk_add_test( - NAME itktubeImageToTubeRigidRegistrationPerformanceTest + NAME itktubeSpatialObjectToImageRegistrationPerformanceTest COMMAND tubeRegistrationTestDriver - itktubeImageToTubeRigidRegistrationPerformanceTest + itktubeSpatialObjectToImageRegistrationPerformanceTest DATA{${TubeTK_DATA_ROOT}/Branch.n020.mha} DATA{${TubeTK_DATA_ROOT}/Branch-truth-new.tre} - ${ITK_TEST_OUTPUT_DIR}/itktubeImageToTubeRigidRegistrationPerformance ) + ${ITK_TEST_OUTPUT_DIR}/itktubeSpatialObjectToImageRegistrationPerformance ) if( TubeTK_USE_VTK ) itk_add_test( @@ -165,28 +160,28 @@ itk_add_test( ${ITK_TEST_OUTPUT_DIR}/Branch-truth-new-points.mha ) itk_add_test( - NAME itktubeImageToTubeRigidMetricTest1 + NAME itktubeSpatialObjectToImageMetricTest1 COMMAND tubeRegistrationTestDriver - itktubeImageToTubeRigidMetricTest + itktubeSpatialObjectToImageMetricTest DATA{${TubeTK_DATA_ROOT}/SyntheticVesselTubeImage.mha} DATA{${TubeTK_DATA_ROOT}/SyntheticVesselTubeManuallyModified.tre} - 2.30028 ) + -0.0801461 ) itk_add_test( - NAME itktubeImageToTubeRigidMetricTest2 + NAME itktubeSpatialObjectToImageMetricTest2 COMMAND tubeRegistrationTestDriver - itktubeImageToTubeRigidMetricTest + itktubeSpatialObjectToImageMetricTest DATA{${TubeTK_DATA_ROOT}/SyntheticTransformedVesselTubeImage.mha} DATA{${TubeTK_DATA_ROOT}/SyntheticVesselTubeManuallyModified.tre} - 0.0739628 ) + -0.00150666 ) itk_add_test( - NAME itktubeImageToTubeRigidMetricPerformanceTest + NAME itktubeSpatialObjectToImageMetricPerformanceTest COMMAND tubeRegistrationTestDriver - itktubeImageToTubeRigidMetricPerformanceTest + itktubeSpatialObjectToImageMetricPerformanceTest DATA{${TubeTK_DATA_ROOT}/SyntheticVesselTubeImage.mha} DATA{${TubeTK_DATA_ROOT}/SyntheticVesselTubeManuallyModified.tre} - ${ITK_TEST_OUTPUT_DIR}/itkImageToTubeRigidMetricPerformance.txt ) + ${ITK_TEST_OUTPUT_DIR}/itkSpatialObjectToImageMetricPerformance.txt ) itk_add_test( NAME itktubeSyntheticTubeImageGenerationTest @@ -197,36 +192,3 @@ itk_add_test( ${ITK_TEST_OUTPUT_DIR}/SyntheticVesselTubeImage.mha DATA{${TubeTK_DATA_ROOT}/SyntheticVesselTubeManuallyModified.tre} ${ITK_TEST_OUTPUT_DIR}/SyntheticTransformedVesselTubeImage.mha ) - -itk_add_test( - NAME itktubeTubeExponentialResolutionWeightFunctionTest - COMMAND tubeRegistrationTestDriver - itktubeTubeExponentialResolutionWeightFunctionTest - ${ITK_TEST_OUTPUT_DIR}/itktubeExponentialResolutionWeightFunctionTest.csv ) - -itk_add_test( - NAME - itktubeTubeParametricExponentialResolutionWeightFunctionTest - COMMAND tubeRegistrationTestDriver - itktubeTubeParametricExponentialResolutionWeightFunctionTest - ${ITK_TEST_OUTPUT_DIR}/itktubeParametricExponentialResolutionWeightFunctionTest.csv ) - -itk_add_test( - NAME - itktubeTubeParametricExponentialWithBoundsResolutionWeightFunctionTest - COMMAND tubeRegistrationTestDriver - itktubeTubeParametricExponentialWithBoundsResolutionWeightFunctionTest - ${ITK_TEST_OUTPUT_DIR}/itktubeParametricExponentialWithBoundsResolutionWeightFunctionTest.csv ) - -itk_add_test( - NAME itktubeTubePointWeightsCalculatorTest - COMMAND tubeRegistrationTestDriver - itktubeTubePointWeightsCalculatorTest - ${ITK_TEST_OUTPUT_DIR}/itktubePointWeightsCalculatorTest.csv ) - -itk_add_test( - NAME itktubeTubeAngleOfIncidenceWeightFunctionTest - COMMAND tubeRegistrationTestDriver - itktubeTubeAngleOfIncidenceWeightFunctionTest - DATA{${TubeTK_DATA_ROOT}/AlmostMaxInhale01.vessels.tre} - ${ITK_TEST_OUTPUT_DIR}/itktubeAngleOfIncidenceWeightFunctionTest ) diff --git a/test/Registration/itktubeTubeToTubeTransformFilterTest.cxx b/test/Registration/itktubePointBasedSpatialObjectTransformFilterTest.cxx similarity index 85% rename from test/Registration/itktubeTubeToTubeTransformFilterTest.cxx rename to test/Registration/itktubePointBasedSpatialObjectTransformFilterTest.cxx index 89c0325bb..020fd9b73 100644 --- a/test/Registration/itktubeTubeToTubeTransformFilterTest.cxx +++ b/test/Registration/itktubePointBasedSpatialObjectTransformFilterTest.cxx @@ -2,8 +2,7 @@ Library: TubeTK -Copyright 2010 Kitware Inc. 28 Corporate Drive, -Clifton Park, NY, 12065, USA. +Copyright Kitware Inc. All rights reserved. @@ -20,7 +19,7 @@ See the License for the specific language governing permissions and limitations under the License. =========================================================================*/ -#include "itktubeTubeToTubeTransformFilter.h" +#include "itktubePointBasedSpatialObjectTransformFilter.h" #include #include @@ -31,7 +30,7 @@ limitations under the License. #include #include -int itktubeTubeToTubeTransformFilterTest( int argc, char * argv[] ) +int itktubePointBasedSpatialObjectTransformFilterTest( int argc, char * argv[] ) { if( argc < 12 ) @@ -45,16 +44,16 @@ int itktubeTubeToTubeTransformFilterTest( int argc, char * argv[] ) return EXIT_FAILURE; } - typedef itk::GroupSpatialObject<3> TubeNetType; - typedef itk::SpatialObjectReader<3> TubeNetReaderType; - typedef itk::SpatialObjectWriter<3> TubeNetWriterType; + typedef itk::GroupSpatialObject<3> GroupType; + typedef itk::SpatialObjectReader<3> SOReaderType; + typedef itk::SpatialObjectWriter<3> SOWriterType; typedef itk::Euler3DTransform TransformType; - typedef itk::tube::TubeToTubeTransformFilter - TubeTransformFilterType; + typedef itk::tube::PointBasedSpatialObjectTransformFilter + TransformFilterType; // read in vessel - TubeNetReaderType::Pointer reader = TubeNetReaderType::New(); + SOReaderType::Pointer reader = SOReaderType::New(); reader->SetFileName( argv[1] ); try @@ -120,8 +119,8 @@ int itktubeTubeToTubeTransformFilterTest( int argc, char * argv[] ) translation[2] << std::endl; // create transform filter - TubeTransformFilterType::Pointer transformFilter = - TubeTransformFilterType::New(); + TransformFilterType::Pointer transformFilter = + TransformFilterType::New(); transformFilter->SetInput( reader->GetGroup() ); transformFilter->SetTransform( transform ); @@ -136,7 +135,7 @@ int itktubeTubeToTubeTransformFilterTest( int argc, char * argv[] ) } // write vessel - TubeNetWriterType::Pointer writer = TubeNetWriterType::New(); + SOWriterType::Pointer writer = SOWriterType::New(); writer->SetFileName( argv[2] ); writer->SetInput( transformFilter->GetOutput() ); @@ -161,12 +160,12 @@ int itktubeTubeToTubeTransformFilterTest( int argc, char * argv[] ) imageReader->SetFileName( argv[3] ); imageReader->Update(); - typedef itk::SpatialObjectToImageFilter + typedef itk::SpatialObjectToImageFilter SpatialObjectToImageFilterType; SpatialObjectToImageFilterType::Pointer vesselToImageFilter = SpatialObjectToImageFilterType::New(); - vesselToImageFilter->SetInput( transformFilter->GetOutput() ); + vesselToImageFilter->SetInput( dynamic_cast< GroupType * >(transformFilter->GetOutput()) ); vesselToImageFilter->SetSize( imageReader->GetOutput()->GetLargestPossibleRegion().GetSize() ); vesselToImageFilter->SetOrigin( imageReader->GetOutput()->GetOrigin() ); diff --git a/test/Registration/itktubeImageToTubeRigidMetricPerformanceTest.cxx b/test/Registration/itktubeSpatialObjectToImageMetricPerformanceTest.cxx similarity index 75% rename from test/Registration/itktubeImageToTubeRigidMetricPerformanceTest.cxx rename to test/Registration/itktubeSpatialObjectToImageMetricPerformanceTest.cxx index c37a6064f..ad8547f36 100644 --- a/test/Registration/itktubeImageToTubeRigidMetricPerformanceTest.cxx +++ b/test/Registration/itktubeSpatialObjectToImageMetricPerformanceTest.cxx @@ -2,8 +2,7 @@ Library: TubeTK -Copyright 2010 Kitware Inc. 28 Corporate Drive, -Clifton Park, NY, 12065, USA. +Copyright Kitware Inc. All rights reserved. @@ -21,13 +20,15 @@ limitations under the License. =========================================================================*/ -#include "itktubeImageToTubeRigidMetric.h" -#include "itktubeSubSampleTubeTreeSpatialObjectFilter.h" +#include "itktubePointBasedSpatialObjectToImageMetric.h" + +#include "itktubeSubSampleSpatialObjectFilter.h" #include #include #include #include +#include /** * This test exercised the metric evaluation methods in the @@ -35,7 +36,7 @@ limitations under the License. * a 3D binary images ( 32x32x32 ) and a .tre image is computed. */ -int itktubeImageToTubeRigidMetricPerformanceTest( int argc, char * argv[] ) +int itktubeSpatialObjectToImageMetricPerformanceTest( int argc, char * argv[] ) { if( argc < 4 ) { @@ -50,15 +51,14 @@ int itktubeImageToTubeRigidMetricPerformanceTest( int argc, char * argv[] ) typedef itk::Image Image3DType; typedef itk::TubeSpatialObject<3> TubeType; - typedef itk::GroupSpatialObject<3> TubeNetType; + typedef itk::GroupSpatialObject<3> GroupType; typedef itk::ImageFileReader ImageReaderType; - typedef itk::SpatialObjectReader<3> TubeNetReaderType; + typedef itk::SpatialObjectReader<3> SOReaderType; - typedef itk::tube::ImageToTubeRigidMetric + typedef itk::tube::PointBasedSpatialObjectToImageMetric<3, Image3DType > MetricType; - typedef MetricType::InterpolatorType InterpolatorType; - typedef MetricType::TransformType TransformType; + typedef itk::ComposeScaleSkewVersor3DTransform TransformType; // read image ( fixedImage ) ImageReaderType::Pointer imageReader = ImageReaderType::New(); @@ -74,7 +74,7 @@ int itktubeImageToTubeRigidMetricPerformanceTest( int argc, char * argv[] ) } // read tube ( spatialObject ) - TubeNetReaderType::Pointer tubeReader = TubeNetReaderType::New(); + SOReaderType::Pointer tubeReader = SOReaderType::New(); tubeReader->SetFileName( argv[2] ); try { @@ -87,15 +87,15 @@ int itktubeImageToTubeRigidMetricPerformanceTest( int argc, char * argv[] ) } // subsample points in vessel - typedef itk::tube::SubSampleTubeTreeSpatialObjectFilter< TubeNetType, TubeType > - SubSampleTubeNetFilterType; - SubSampleTubeNetFilterType::Pointer subSampleTubeNetFilter = - SubSampleTubeNetFilterType::New(); - subSampleTubeNetFilter->SetInput( tubeReader->GetGroup() ); - subSampleTubeNetFilter->SetSampling( 30 ); + typedef itk::tube::SubSampleSpatialObjectFilter<> + SubSampleFilterType; + SubSampleFilterType::Pointer subSampleFilter = + SubSampleFilterType::New(); + subSampleFilter->SetInput( tubeReader->GetGroup() ); + subSampleFilter->SetSampling( 30 ); try { - subSampleTubeNetFilter->Update(); + subSampleFilter->Update(); } catch( itk::ExceptionObject & err ) { @@ -109,14 +109,12 @@ int itktubeImageToTubeRigidMetricPerformanceTest( int argc, char * argv[] ) MetricType::Pointer metric = MetricType::New(); metric->SetExtent( 3 ); - InterpolatorType::Pointer interpolator = InterpolatorType::New(); TransformType::Pointer transform = TransformType::New(); TransformType::ParametersType parameters = transform->GetParameters(); metric->SetFixedImage( imageReader->GetOutput() ); - metric->SetMovingSpatialObject ( subSampleTubeNetFilter->GetOutput() ); - metric->SetInterpolator( interpolator ); - metric->SetTransform( transform ); + metric->SetMovingSpatialObject ( subSampleFilter->GetOutput() ); + metric->SetTransform( transform.GetPointer() ); // Add a time probe itk::TimeProbesCollectorBase chronometer; diff --git a/test/Registration/itktubeImageToTubeRigidMetricTest.cxx b/test/Registration/itktubeSpatialObjectToImageMetricTest.cxx similarity index 70% rename from test/Registration/itktubeImageToTubeRigidMetricTest.cxx rename to test/Registration/itktubeSpatialObjectToImageMetricTest.cxx index 557fee2bb..d536eb83f 100644 --- a/test/Registration/itktubeImageToTubeRigidMetricTest.cxx +++ b/test/Registration/itktubeSpatialObjectToImageMetricTest.cxx @@ -2,8 +2,7 @@ Library: TubeTK -Copyright 2010 Kitware Inc. 28 Corporate Drive, -Clifton Park, NY, 12065, USA. +Copyright Kitware Inc. All rights reserved. @@ -21,20 +20,21 @@ limitations under the License. =========================================================================*/ -#include "itktubeImageToTubeRigidMetric.h" -#include "itktubeSubSampleTubeTreeSpatialObjectFilter.h" +#include "itktubePointBasedSpatialObjectToImageMetric.h" +#include "itktubeSubSampleSpatialObjectFilter.h" #include #include +#include /** * This test exercised the metric evaluation methods in the - * itktubeImageToTubeRigidMetric class. The distance between + * itktubeSpatialObjectToImageMetric class. The distance between * a 3D binary images ( 32x32x32 ) and a .tre image is computed and check with * the reference for the metric. */ -int itktubeImageToTubeRigidMetricTest( int argc, char * argv[] ) +int itktubeSpatialObjectToImageMetricTest( int argc, char * argv[] ) { if( argc < 4 ) { @@ -49,18 +49,17 @@ int itktubeImageToTubeRigidMetricTest( int argc, char * argv[] ) typedef double FloatType; static const unsigned int ImageDimension = 3; - static const unsigned int TubeDimension = 3; + static const unsigned int ObjectDimension = 3; typedef itk::Image< FloatType, ImageDimension > ImageType; - typedef itk::TubeSpatialObject< TubeDimension > TubeType; - typedef itk::GroupSpatialObject< TubeDimension > TubeNetType; + typedef itk::GroupSpatialObject< ObjectDimension > GroupType; typedef itk::ImageFileReader< ImageType > ImageReaderType; - typedef itk::SpatialObjectReader< TubeDimension > TubeNetReaderType; + typedef itk::SpatialObjectReader< ObjectDimension > GroupReaderType; - typedef itk::tube::ImageToTubeRigidMetric< ImageType, TubeNetType, - TubeType > MetricType; - typedef MetricType::TransformType TransformType; + typedef itk::tube::PointBasedSpatialObjectToImageMetric< 3, ImageType > + MetricType; + typedef itk::ComposeScaleSkewVersor3DTransform< double > TransformType; // read image ( fixedImage ) ImageReaderType::Pointer imageReader = ImageReaderType::New(); @@ -75,12 +74,12 @@ int itktubeImageToTubeRigidMetricTest( int argc, char * argv[] ) return EXIT_FAILURE; } - // read tube ( spatialObject ) - TubeNetReaderType::Pointer tubeReader = TubeNetReaderType::New(); - tubeReader->SetFileName( argv[2] ); + // read group ( spatialObject ) + GroupReaderType::Pointer groupReader = GroupReaderType::New(); + groupReader->SetFileName( argv[2] ); try { - tubeReader->Update(); + groupReader->Update(); } catch( itk::ExceptionObject & err ) { @@ -89,15 +88,15 @@ int itktubeImageToTubeRigidMetricTest( int argc, char * argv[] ) } // subsample points in vessel - typedef itk::tube::SubSampleTubeTreeSpatialObjectFilter< TubeNetType, TubeType > - SubSampleTubeNetFilterType; - SubSampleTubeNetFilterType::Pointer subSampleTubeNetFilter = - SubSampleTubeNetFilterType::New(); - subSampleTubeNetFilter->SetInput( tubeReader->GetGroup() ); - subSampleTubeNetFilter->SetSampling( 30 ); + typedef itk::tube::SubSampleSpatialObjectFilter<> + SubSampleFilterType; + SubSampleFilterType::Pointer subSampleFilter = + SubSampleFilterType::New(); + subSampleFilter->SetInput( groupReader->GetGroup() ); + subSampleFilter->SetSampling( 30 ); try { - subSampleTubeNetFilter->Update(); + subSampleFilter->Update(); } catch( itk::ExceptionObject & err ) { @@ -115,7 +114,7 @@ int itktubeImageToTubeRigidMetricTest( int argc, char * argv[] ) TransformType::ParametersType parameters = transform->GetParameters(); metric->SetFixedImage( imageReader->GetOutput() ); - metric->SetMovingSpatialObject ( subSampleTubeNetFilter->GetOutput() ); + metric->SetMovingSpatialObject ( subSampleFilter->GetOutput() ); metric->SetTransform( transform ); try { diff --git a/test/Registration/itktubeImageToTubeRigidRegistrationPerformanceTest.cxx b/test/Registration/itktubeSpatialObjectToImageRegistrationPerformanceTest.cxx similarity index 68% rename from test/Registration/itktubeImageToTubeRigidRegistrationPerformanceTest.cxx rename to test/Registration/itktubeSpatialObjectToImageRegistrationPerformanceTest.cxx index 10ddc4c54..9648f3928 100644 --- a/test/Registration/itktubeImageToTubeRigidRegistrationPerformanceTest.cxx +++ b/test/Registration/itktubeSpatialObjectToImageRegistrationPerformanceTest.cxx @@ -20,15 +20,20 @@ limitations under the License. =========================================================================*/ -#include "itktubeImageToTubeRigidRegistration.h" +#include "itktubeSpatialObjectToImageRegistrationHelper.h" +#include "itktubeSubSampleSpatialObjectFilter.h" #include +#include + #include #include #include -#include #include +#include +#include + // The following section of code implements a Command observer // used to monitor the evolution of the registration process. // @@ -53,8 +58,8 @@ class CommandIterationUpdate : public itk::Command std::ofstream measuresFileStream; public: - typedef itk::GradientDescentOptimizer OptimizerType; - typedef const OptimizerType * OptimizerPointer; + typedef itk::OnePlusOneEvolutionaryOptimizer EvoOptimizerType; + typedef itk::GradientDescentOptimizer GradOptimizerType; void Execute( itk::Object *caller, const itk::EventObject & event ) override { @@ -64,8 +69,6 @@ class CommandIterationUpdate : public itk::Command void Execute( const itk::Object * object, const itk::EventObject & event ) override { - OptimizerPointer optimizer = - dynamic_cast< OptimizerPointer >( object ); if( !( itk::IterationEvent().CheckEvent( &event ) ) ) { return; @@ -73,8 +76,20 @@ class CommandIterationUpdate : public itk::Command if( measuresFileStream.is_open() ) { - measuresFileStream << optimizer->GetCurrentIteration() << ";"; - measuresFileStream << optimizer->GetValue() << std::endl; + typename EvoOptimizerType::ConstPointer evoOptimizer = + dynamic_cast< const EvoOptimizerType * >( object ); + typename GradOptimizerType::ConstPointer gradOptimizer = + dynamic_cast< const GradOptimizerType * >( object ); + if(evoOptimizer.IsNotNull()) + { + measuresFileStream << evoOptimizer->GetCurrentIteration() << ";"; + measuresFileStream << evoOptimizer->GetValue() << std::endl; + } + else if(gradOptimizer.IsNotNull()) + { + measuresFileStream << gradOptimizer->GetCurrentIteration() << ";"; + measuresFileStream << gradOptimizer->GetValue() << std::endl; + } } } @@ -85,24 +100,24 @@ class CommandIterationUpdate : public itk::Command }; // End class CommandIterationUpdate -int itktubeImageToTubeRigidRegistrationPerformanceTest( int argc, char * argv[] ) +int itktubeSpatialObjectToImageRegistrationPerformanceTest( int argc, char * argv[] ) { if( argc < 4 ) { std::cerr << "Missing Parameters: " << argv[0] - << " Input_Image " << "Input_Vessel " << "Output_Results" + << " Input_Image " << "Input_group " << "Output_Results" << std::endl; return EXIT_FAILURE; } typedef itk::TubeSpatialObject< 3 > TubeType; - typedef itk::GroupSpatialObject<3> TubeNetType; - typedef itk::SpatialObjectReader<3> TubeNetReaderType; + typedef itk::GroupSpatialObject<3> GroupType; + typedef itk::SpatialObjectReader<3> GroupReaderType; typedef itk::Image ImageType; typedef itk::ImageFileReader ImageReaderType; - typedef itk::tube::ImageToTubeRigidRegistration - RegistrationMethodType; + typedef itk::tube::SpatialObjectToImageRegistrationHelper<3, ImageType> + RegistrationHelperType; // read image ImageReaderType::Pointer imageReader = ImageReaderType::New(); @@ -146,12 +161,12 @@ int itktubeImageToTubeRigidRegistrationPerformanceTest( int argc, char * argv[] return EXIT_FAILURE; } - // read vessel - TubeNetReaderType::Pointer vesselReader = TubeNetReaderType::New(); - vesselReader->SetFileName( argv[2] ); + // read group + GroupReaderType::Pointer groupReader = GroupReaderType::New(); + groupReader->SetFileName( argv[2] ); try { - vesselReader->Update(); + groupReader->Update(); } catch( itk::ExceptionObject & err ) { @@ -159,16 +174,16 @@ int itktubeImageToTubeRigidRegistrationPerformanceTest( int argc, char * argv[] return EXIT_FAILURE; } - // subsample points in vessel - typedef itk::tube::SubSampleTubeTreeSpatialObjectFilter< TubeNetType, TubeType > - SubSampleTubeNetFilterType; - SubSampleTubeNetFilterType::Pointer subSampleTubeNetFilter = - SubSampleTubeNetFilterType::New(); - subSampleTubeNetFilter->SetInput( vesselReader->GetGroup() ); - subSampleTubeNetFilter->SetSampling( 30 ); + // subsample points in group + typedef itk::tube::SubSampleSpatialObjectFilter<> + SubSampleFilterType; + SubSampleFilterType::Pointer subSampleFilter = + SubSampleFilterType::New(); + subSampleFilter->SetInput( groupReader->GetGroup() ); + subSampleFilter->SetSampling( 30 ); try { - subSampleTubeNetFilter->Update(); + subSampleFilter->Update(); } catch( itk::ExceptionObject & err ) { @@ -176,36 +191,21 @@ int itktubeImageToTubeRigidRegistrationPerformanceTest( int argc, char * argv[] return EXIT_FAILURE; } - // register the vessel and the image + // register the group and the image itk::Statistics::MersenneTwisterRandomVariateGenerator::Pointer randGenerator = itk::Statistics::MersenneTwisterRandomVariateGenerator::New(); randGenerator->Initialize( 137593424 ); - RegistrationMethodType::Pointer registrationMethod = - RegistrationMethodType::New(); + RegistrationHelperType::Pointer registrationHelper = + RegistrationHelperType::New(); - registrationMethod->SetFixedImage( blurFilters[2]->GetOutput() ); - registrationMethod->SetMovingSpatialObject( subSampleTubeNetFilter->GetOutput() ); + registrationHelper->SetFixedImage( blurFilters[2]->GetOutput() ); + registrationHelper->SetMovingSpatialObject( subSampleFilter->GetOutput() ); // Set Optimizer parameters. - RegistrationMethodType::OptimizerType::Pointer optimizer = - registrationMethod->GetOptimizer(); - RegistrationMethodType::OptimizerType::ScalesType parameterScales( 6 ); - parameterScales[0] = 30.0; - parameterScales[1] = 30.0; - parameterScales[2] = 30.0; - parameterScales[3] = 1.0; - parameterScales[4] = 1.0; - parameterScales[5] = 1.0; - optimizer->SetScales( parameterScales ); - itk::GradientDescentOptimizer * gradientDescentOptimizer = - dynamic_cast< itk::GradientDescentOptimizer * >( optimizer.GetPointer() ); - if( gradientDescentOptimizer ) - { - gradientDescentOptimizer->SetLearningRate( 0.1 ); - gradientDescentOptimizer->SetNumberOfIterations( 1000 ); - } + registrationHelper->SetExpectedOffsetMagnitude(3); + registrationHelper->SetRigidMaxIterations(1000); // Add a time probe @@ -233,18 +233,17 @@ int itktubeImageToTubeRigidRegistrationPerformanceTest( int argc, char * argv[] memorymeter.Start( "Registration" ); chronometer.Start( "Registration" ); - registrationMethod->Initialize(); + registrationHelper->Initialize(); // Create the Command observer and register it with the optimizer. // CommandIterationUpdate::Pointer observer = CommandIterationUpdate::New(); observer->SetFileName( valuesFile ); - registrationMethod->GetOptimizer()-> - AddObserver( itk::IterationEvent(), observer ); + registrationHelper->SetObserver( observer ); // Launch Registration - registrationMethod->Update(); + registrationHelper->Update(); chronometer.Stop( "Registration" ); memorymeter.Stop( "Registration" ); @@ -252,10 +251,6 @@ int itktubeImageToTubeRigidRegistrationPerformanceTest( int argc, char * argv[] // Report the time and memory taken by the registration chronometer.Report( measuresFile ); memorymeter.Report( measuresFile ); - - std::cout << "Optimizer stop condition = " - << registrationMethod->GetOptimizer()->GetStopConditionDescription() - << std::endl; } catch( itk::ExceptionObject & err ) { diff --git a/test/Registration/itktubeImageToTubeRigidRegistrationTest.cxx b/test/Registration/itktubeSpatialObjectToImageRegistrationTest.cxx similarity index 62% rename from test/Registration/itktubeImageToTubeRigidRegistrationTest.cxx rename to test/Registration/itktubeSpatialObjectToImageRegistrationTest.cxx index 82f79c7f4..4a2a730e4 100644 --- a/test/Registration/itktubeImageToTubeRigidRegistrationTest.cxx +++ b/test/Registration/itktubeSpatialObjectToImageRegistrationTest.cxx @@ -20,10 +20,11 @@ limitations under the License. =========================================================================*/ -#include "itktubeImageToTubeRigidRegistration.h" -#include "itktubeTubeToTubeTransformFilter.h" -#include "itktubeTubeExponentialResolutionWeightFunction.h" -#include "itktubeTubePointWeightsCalculator.h" +#include "itktubeSpatialObjectToImageRegistrationHelper.h" + +#include "itktubePointBasedSpatialObjectTransformFilter.h" + +#include "itktubeSubSampleSpatialObjectFilter.h" #include #include @@ -31,38 +32,39 @@ limitations under the License. #include #include #include +#include -int itktubeImageToTubeRigidRegistrationTest( int argc, char * argv[] ) +int itktubeSpatialObjectToImageRegistrationTest( int argc, char * argv[] ) { if( argc < 4 ) { std::cerr << "Missing Parameters: " << argv[0] << " Input_Image " - << " Input_Vessel" + << " Input_Group" << " Output_Tubes" << " Output_Image" << std::endl; return EXIT_FAILURE; } const char * inputImage = argv[1]; - const char * inputVessel = argv[2]; + const char * inputGroup = argv[2]; const char * outputTubes = argv[3]; const char * outputImage = argv[4]; - enum { Dimension = 3 }; + enum { ObjectDimension = 3 }; typedef double FloatType; - typedef itk::TubeSpatialObject< Dimension > TubeType; - typedef itk::GroupSpatialObject< Dimension > TubeTreeType; - typedef itk::SpatialObjectReader< Dimension > TubeTreeReaderType; - typedef itk::Image< FloatType, Dimension > ImageType; + typedef itk::TubeSpatialObject< ObjectDimension > TubeType; + typedef itk::GroupSpatialObject< ObjectDimension > GroupType; + typedef itk::SpatialObjectReader< ObjectDimension > SOReaderType; + typedef itk::Image< FloatType, ObjectDimension > ImageType; typedef itk::ImageFileReader< ImageType > ImageReaderType; typedef itk::ImageFileWriter< ImageType > ImageWriterType; - typedef itk::tube::ImageToTubeRigidRegistration< ImageType, TubeTreeType, TubeType > - RegistrationMethodType; - typedef RegistrationMethodType::TransformType TransformType; - typedef itk::tube::TubeToTubeTransformFilter< TransformType, Dimension > + typedef itk::tube::SpatialObjectToImageRegistrationHelper< 3, ImageType > + RegistrationHelperType; + typedef RegistrationHelperType::MatrixTransformType TransformType; + typedef itk::tube::PointBasedSpatialObjectTransformFilter< TransformType, ObjectDimension > TubeTransformFilterType; std::cout << "start" << std::endl; @@ -75,8 +77,8 @@ int itktubeImageToTubeRigidRegistrationTest( int argc, char * argv[] ) // this enlarges the convergence zone. typedef itk::RecursiveGaussianImageFilter GaussianBlurFilterType; - GaussianBlurFilterType::Pointer blurFilters[Dimension]; - for( unsigned int ii = 0; ii < Dimension; ++ii ) + GaussianBlurFilterType::Pointer blurFilters[ObjectDimension]; + for( unsigned int ii = 0; ii < ObjectDimension; ++ii ) { blurFilters[ii] = GaussianBlurFilterType::New(); blurFilters[ii]->SetSigma( 2.0 ); @@ -96,12 +98,12 @@ int itktubeImageToTubeRigidRegistrationTest( int argc, char * argv[] ) return EXIT_FAILURE; } - // read vessel - TubeTreeReaderType::Pointer vesselReader = TubeTreeReaderType::New(); - vesselReader->SetFileName( inputVessel ); + // read group + SOReaderType::Pointer groupReader = SOReaderType::New(); + groupReader->SetFileName( inputGroup ); try { - vesselReader->Update(); + groupReader->Update(); } catch( itk::ExceptionObject & err ) { @@ -111,15 +113,14 @@ int itktubeImageToTubeRigidRegistrationTest( int argc, char * argv[] ) std::cout << "subsample" << std::endl; // subsample points in vessel - typedef itk::tube::SubSampleTubeTreeSpatialObjectFilter< TubeTreeType, TubeType > - SubSampleTubeTreeFilterType; - SubSampleTubeTreeFilterType::Pointer subSampleTubeTreeFilter = - SubSampleTubeTreeFilterType::New(); - subSampleTubeTreeFilter->SetInput( vesselReader->GetGroup() ); - subSampleTubeTreeFilter->SetSampling( 20 ); + typedef itk::tube::SubSampleSpatialObjectFilter< ObjectDimension > SubSampleFilterType; + SubSampleFilterType::Pointer subSampleFilter = + SubSampleFilterType::New(); + subSampleFilter->SetInput( groupReader->GetGroup() ); + subSampleFilter->SetSampling( 20 ); try { - subSampleTubeTreeFilter->Update(); + subSampleFilter->Update(); } catch( itk::ExceptionObject & err ) { @@ -128,44 +129,17 @@ int itktubeImageToTubeRigidRegistrationTest( int argc, char * argv[] ) } - std::cout << "weight func" << std::endl; - typedef itk::tube::Function::TubeExponentialResolutionWeightFunction< - TubeType::TubePointType, double > WeightFunctionType; - typedef RegistrationMethodType::FeatureWeightsType PointWeightsType; - WeightFunctionType::Pointer weightFunction = WeightFunctionType::New(); - typedef itk::tube::TubePointWeightsCalculator< Dimension, - TubeType, WeightFunctionType, - PointWeightsType > PointWeightsCalculatorType; - PointWeightsCalculatorType::Pointer resolutionWeightsCalculator - = PointWeightsCalculatorType::New(); - resolutionWeightsCalculator->SetTubeTreeSpatialObject( - subSampleTubeTreeFilter->GetOutput() ); - resolutionWeightsCalculator->SetPointWeightFunction( weightFunction ); - resolutionWeightsCalculator->Compute(); - PointWeightsType pointWeights = resolutionWeightsCalculator->GetPointWeights(); - - RegistrationMethodType::Pointer registrationMethod = - RegistrationMethodType::New(); - - registrationMethod->SetFixedImage( blurFilters[2]->GetOutput() ); - registrationMethod->SetMovingSpatialObject( subSampleTubeTreeFilter->GetOutput() ); - registrationMethod->SetFeatureWeights( pointWeights ); - - // Set Optimizer parameters. - RegistrationMethodType::OptimizerType::Pointer optimizer = - registrationMethod->GetOptimizer(); - itk::GradientDescentOptimizer * gradientDescentOptimizer = - dynamic_cast< itk::GradientDescentOptimizer * >( optimizer.GetPointer() ); - if( gradientDescentOptimizer ) - { - gradientDescentOptimizer->SetLearningRate( 0.1 ); - gradientDescentOptimizer->SetNumberOfIterations( 40 ); - } + RegistrationHelperType::Pointer registrationHelper = + RegistrationHelperType::New(); + + registrationHelper->SetFixedImage( blurFilters[2]->GetOutput() ); + registrationHelper->SetMovingSpatialObject( subSampleFilter->GetOutput() ); + registrationHelper->SetRegistration(RegistrationHelperType::RegistrationMethodEnumType::RIGID); try { - registrationMethod->Initialize(); - registrationMethod->Update(); + registrationHelper->Initialize(); + registrationHelper->Update(); } catch( itk::ExceptionObject & err ) { @@ -174,17 +148,16 @@ int itktubeImageToTubeRigidRegistrationTest( int argc, char * argv[] ) } // validate the registration result - TransformType::Pointer outputTransform = - dynamic_cast( registrationMethod->GetTransform() ); - const TransformType::ParametersType lastParameters = - registrationMethod->GetLastTransformParameters(); - outputTransform->SetParameters( lastParameters ); + TransformType::ConstPointer outputTransform = + registrationHelper->GetCurrentMatrixTransform(); + TransformType::ParametersType lastParameters = + outputTransform->GetParameters(); TransformType::Pointer inverseTransform = TransformType::New(); outputTransform->GetInverse( inverseTransform ); - itk::Matrix< double, Dimension, Dimension > rotationMatrix; - itk::Vector< double, Dimension > translation; + itk::Matrix< double, ObjectDimension, ObjectDimension > rotationMatrix; + itk::Vector< double, ObjectDimension > translation; rotationMatrix = outputTransform->GetMatrix(); translation = outputTransform->GetTranslation(); @@ -222,8 +195,8 @@ int itktubeImageToTubeRigidRegistrationTest( int argc, char * argv[] ) // Transform the input tubes. TubeTransformFilterType::Pointer transformFilter = TubeTransformFilterType::New(); - transformFilter->SetInput( vesselReader->GetGroup() ); - transformFilter->SetTransform( outputTransform ); + transformFilter->SetInput( groupReader->GetGroup() ); + transformFilter->SetTransform( outputTransform.GetPointer() ); std::cout << "Outputting transformed tubes..."; try { @@ -237,8 +210,8 @@ int itktubeImageToTubeRigidRegistrationTest( int argc, char * argv[] ) std::cout << " done.\n"; // Write the transformed tube to file. - typedef itk::SpatialObjectWriter< Dimension > TubeTreeWriterType; - TubeTreeWriterType::Pointer tubesWriter = TubeTreeWriterType::New(); + typedef itk::SpatialObjectWriter< ObjectDimension > SOWriterType; + SOWriterType::Pointer tubesWriter = SOWriterType::New(); tubesWriter->SetInput( transformFilter->GetOutput() ); tubesWriter->SetFileName( outputTubes ); try @@ -251,7 +224,7 @@ int itktubeImageToTubeRigidRegistrationTest( int argc, char * argv[] ) result = EXIT_FAILURE; } - typedef itk::SpatialObjectToImageFilter< TubeTreeType, ImageType> + typedef itk::SpatialObjectToImageFilter< GroupType, ImageType> SpatialObjectToImageFilterType; SpatialObjectToImageFilterType::Pointer vesselToImageFilter = SpatialObjectToImageFilterType::New(); @@ -270,7 +243,7 @@ int itktubeImageToTubeRigidRegistrationTest( int argc, char * argv[] ) spacing[2] = spacing[2] * decimationFactor; std::cout << "Converting transformed vessel model into a binary image ... "; - vesselToImageFilter->SetInput( transformFilter->GetOutput() ); + vesselToImageFilter->SetInput( dynamic_cast< const GroupType *>(transformFilter->GetOutput()) ); vesselToImageFilter->SetSize( size ); vesselToImageFilter->SetSpacing( spacing ); vesselToImageFilter->SetOrigin( img->GetOrigin() ); diff --git a/test/Registration/itktubeSyntheticTubeImageGenerationTest.cxx b/test/Registration/itktubeSyntheticTubeImageGenerationTest.cxx index ae710d259..086b81bf6 100644 --- a/test/Registration/itktubeSyntheticTubeImageGenerationTest.cxx +++ b/test/Registration/itktubeSyntheticTubeImageGenerationTest.cxx @@ -20,7 +20,7 @@ See the License for the specific language governing permissions and limitations under the License. =========================================================================*/ -#include "itktubeTubeToTubeTransformFilter.h" +#include "itktubePointBasedSpatialObjectTransformFilter.h" #include #include @@ -54,13 +54,13 @@ int itktubeSyntheticTubeImageGenerationTest( int argc, char * argv[] ) typedef itk::ImageRegionIteratorWithIndex< Image3DType > Image3DIteratorType; typedef itk::TubeSpatialObject<3> TubeType; typedef itk::TubeSpatialObjectPoint<3> TubePointType; - typedef itk::GroupSpatialObject<3> TubeNetType; + typedef itk::GroupSpatialObject<3> GroupType; - typedef itk::SpatialObjectToImageFilter< TubeNetType, Image3DType > + typedef itk::SpatialObjectToImageFilter< GroupType, Image3DType > SpatialObjectToImageFilterType; typedef itk::Euler3DTransform TransformType; - typedef itk::tube::TubeToTubeTransformFilter + typedef itk::tube::PointBasedSpatialObjectTransformFilter TubeTransformFilterType; typedef itk::ImageFileWriter ImageWriterType; @@ -166,7 +166,7 @@ int itktubeSyntheticTubeImageGenerationTest( int argc, char * argv[] ) tube->GetPoints().push_back( point ); } - TubeNetType::Pointer group = TubeNetType::New(); + GroupType::Pointer group = GroupType::New(); group->AddChild( tube ); std::cout << "Write tubeFile: " << argv[2] << std::endl; @@ -220,8 +220,8 @@ int itktubeSyntheticTubeImageGenerationTest( int argc, char * argv[] ) std::cout << "Transform and Convert the tube into an Image..." << std::endl; // read tube ( spatialObject ) - typedef itk::SpatialObjectReader<3> TubeNetReaderType; - TubeNetReaderType::Pointer tubeReader = TubeNetReaderType::New(); + typedef itk::SpatialObjectReader<3> SOReaderType; + SOReaderType::Pointer tubeReader = SOReaderType::New(); std::cout << "Read VesselTube: " << argv[4] << std::endl; tubeReader->SetFileName( argv[4] ); try @@ -282,7 +282,7 @@ int itktubeSyntheticTubeImageGenerationTest( int argc, char * argv[] ) SpatialObjectToImageFilterType::Pointer imageFilterTransform = SpatialObjectToImageFilterType::New(); - imageFilterTransform->SetInput( transformFilter->GetOutput() ); + imageFilterTransform->SetInput( static_cast(transformFilter->GetOutput()) ); imageFilterTransform->SetSize( imageSize ); imageFilterTransform->SetOrigin( origin ); imageFilterTransform->Update(); diff --git a/test/Registration/itktubeTubeAngleOfIncidenceWeightFunctionTest.cxx b/test/Registration/itktubeTubeAngleOfIncidenceWeightFunctionTest.cxx deleted file mode 100644 index e588a32cf..000000000 --- a/test/Registration/itktubeTubeAngleOfIncidenceWeightFunctionTest.cxx +++ /dev/null @@ -1,187 +0,0 @@ -/*========================================================================= - -Library: TubeTK - -Copyright 2010 Kitware Inc. 28 Corporate Drive, -Clifton Park, NY, 12065, USA. - -All rights reserved. - -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. - -=========================================================================*/ - -#include "itktubeSubSampleTubeTreeSpatialObjectFilter.h" -#include "itktubeTubeAngleOfIncidenceWeightFunction.h" -#include "itktubeTubePointWeightsCalculator.h" - -#include -#include -#include -#include - -#include - -int itktubeTubeAngleOfIncidenceWeightFunctionTest( int argc, char * argv[] ) -{ - if( argc < 3 ) - { - std::cerr << "Usage: " - << argv[0] - << " inputTubeNetwork.tre" - << " outputDirectory" - << std::endl; - return EXIT_FAILURE; - } - const char * inputTubeNetwork = argv[1]; - const char * outputDirectory = argv[2]; - - enum { Dimension = 3 }; - typedef itk::TubeSpatialObject< Dimension > TubeSpatialObjectType; - typedef itk::GroupSpatialObject< Dimension > GroupSpatialObjectType; - typedef itk::TubeSpatialObjectPoint< Dimension > TubePointType; - typedef float WeightType; - - // Read input tube tree. - typedef itk::SpatialObjectReader< Dimension > ReaderType; - ReaderType::Pointer reader = ReaderType::New(); - reader->SetFileName( inputTubeNetwork ); - try - { - reader->Update(); - } - catch( itk::ExceptionObject & error ) - { - std::cerr << "Error: " << error << std::endl; - return EXIT_FAILURE; - } - GroupSpatialObjectType::Pointer groupSpatialObject = reader->GetGroup(); - std::cout << "Number of children = " - << groupSpatialObject->GetNumberOfChildren() - << std::endl; - - // Sub-sample the tube tree. - typedef itk::tube::SubSampleTubeTreeSpatialObjectFilter< GroupSpatialObjectType, - TubeSpatialObjectType > - SubSampleTubeTreeFilterType; - SubSampleTubeTreeFilterType::Pointer subSampleTubeTreeFilter = - SubSampleTubeTreeFilterType::New(); - subSampleTubeTreeFilter->SetInput( reader->GetGroup() ); - subSampleTubeTreeFilter->SetSampling( 10 ); - try - { - subSampleTubeTreeFilter->Update(); - } - catch( itk::ExceptionObject & error ) - { - std::cerr << "Error: " << error << std::endl; - return EXIT_FAILURE; - } - - typedef itk::tube::Function::TubeAngleOfIncidenceWeightFunction< - TubePointType, WeightType > WeightFunctionType; - WeightFunctionType::Pointer weightFunction = WeightFunctionType::New(); - weightFunction->SetFractionalImportance( 0.8 ); - weightFunction->SetAngleDependence( 2.5 ); - WeightFunctionType::PointType probeOrigin; - probeOrigin[0] = 354.88; - probeOrigin[1] = -214.83; - probeOrigin[2] = 185.739; - weightFunction->SetUltrasoundProbeOrigin( probeOrigin ); - - typedef itk::OptimizerParameters< WeightType > PointWeightsType; - typedef itk::tube::TubePointWeightsCalculator< Dimension, - TubeSpatialObjectType, WeightFunctionType, - PointWeightsType > PointWeightsCalculatorType; - PointWeightsCalculatorType::Pointer weightsCalculator - = PointWeightsCalculatorType::New(); - weightsCalculator->SetTubeTreeSpatialObject( - subSampleTubeTreeFilter->GetOutput() ); - weightsCalculator->SetPointWeightFunction( weightFunction ); - weightsCalculator->Compute(); - const PointWeightsType & weights - = weightsCalculator->GetPointWeights(); - - itksys::SystemTools::MakeDirectory( outputDirectory ); - std::string outputPrefix( outputDirectory ); - outputPrefix += "/"; - - std::ostringstream ostrm; - char childName[] = "Tube"; - GroupSpatialObjectType::Pointer tubeTree - = subSampleTubeTreeFilter->GetOutput(); - GroupSpatialObjectType::ChildrenListType * tubeList = - tubeTree->GetChildren( tubeTree->GetMaximumDepth(), childName ); - itk::SizeValueType tubeIndex = 0; - typedef GroupSpatialObjectType::ChildrenListType::const_iterator - TubesIteratorType; - for( TubesIteratorType tubeIterator = tubeList->begin(); - tubeIterator != tubeList->end(); - ++tubeIterator ) - { - TubeSpatialObjectType * currentTube = - dynamic_cast< TubeSpatialObjectType * >( ( *tubeIterator ).GetPointer() ); - if( currentTube != NULL ) - { - const TubeSpatialObjectType::TubePointListType & currentTubePoints - = currentTube->GetPoints(); - typedef TubeSpatialObjectType::TubePointListType::const_iterator - TubePointIteratorType; - for( TubePointIteratorType tubePointIterator = currentTubePoints.begin(); - tubePointIterator != currentTubePoints.end(); - ++tubePointIterator ) - { - ostrm.str( "" ); - ostrm << outputPrefix; - ostrm << "Weight" << tubeIndex << ".acsv"; - - std::ofstream outputFile( ostrm.str().c_str() ); - if( !outputFile.is_open() ) - { - std::cerr << "Could not open output file: " << ostrm.str() << std::endl; - return EXIT_FAILURE; - } - - outputFile << "# Name = W" << tubeIndex << "\n"; - outputFile << "# pointColor = " - << weights[tubeIndex] << "," - << weights[tubeIndex] << "," - << 0.3 << "\n"; - outputFile << "# pointColumns = type|x|y|z|sel|vis\n"; - outputFile << "point|"; - const TubePointType::PointType & position - = tubePointIterator->GetPositionInObjectSpace(); - outputFile << position[0] << "|"; - outputFile << position[1] << "|"; - outputFile << position[2] << "|"; - outputFile << "1|1\n"; - std::cout << position << ": " << weights[tubeIndex] << '\n'; - - ++tubeIndex; - } - } - } - delete tubeList; - - // Regression test on a few points - WeightType tolerance = 0.01; - if( std::fabs( weights[3] - 0.818436 ) > tolerance || - std::fabs( weights[4] - 0.909169 ) > tolerance || - std::fabs( weights[5] - 0.951959 ) > tolerance ) - { - std::cerr << "Did not generate the expected weights." << std::endl; - return EXIT_FAILURE; - } - - return EXIT_SUCCESS; -} diff --git a/test/Registration/itktubeTubeExponentialResolutionWeightFunctionTest.cxx b/test/Registration/itktubeTubeExponentialResolutionWeightFunctionTest.cxx deleted file mode 100644 index 6f556a1cd..000000000 --- a/test/Registration/itktubeTubeExponentialResolutionWeightFunctionTest.cxx +++ /dev/null @@ -1,80 +0,0 @@ -/*========================================================================= - -Library: TubeTK - -Copyright 2010 Kitware Inc. 28 Corporate Drive, -Clifton Park, NY, 12065, USA. - -All rights reserved. - -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. - -=========================================================================*/ - -#include "itktubeTubeExponentialResolutionWeightFunction.h" - -#include - -#include - -int itktubeTubeExponentialResolutionWeightFunctionTest( int argc, char * argv[] ) -{ - if( argc < 2 ) - { - std::cerr << "Usage: " - << argv[0] - << " output.csv" - << std::endl; - return EXIT_FAILURE; - } - const char * outputCSV = argv[1]; - - enum { Dimension = 2 }; - typedef itk::TubeSpatialObjectPoint< Dimension > TubePointType; - typedef std::vector< TubePointType > TubePointContainerType; - - // Create tube points with increasing radius. - const unsigned int numberOfPoints = 100; - TubePointContainerType tubePointContainer( numberOfPoints ); - const double startingRadius = 0.00; - const double radiusIncrement = 0.01; - double radius = startingRadius; - for( unsigned int ii = 0; ii < numberOfPoints; ++ii ) - { - tubePointContainer[ii].SetRadiusInObjectSpace( radius ); - radius += radiusIncrement; - } - - // Write the tube point weights to file. - std::ofstream outputFile( outputCSV ); - if( !outputFile.is_open() ) - { - std::cerr << "Cannot open output file." << std::endl; - return EXIT_FAILURE; - } - - typedef itk::tube::Function::TubeExponentialResolutionWeightFunction< - TubePointType, float > WeightFunctionType; - WeightFunctionType::Pointer weightFunction = WeightFunctionType::New(); - - for( unsigned int ii = 0; ii < numberOfPoints; ++ii ) - { - const float pointWeight = weightFunction->Evaluate( tubePointContainer[ii] ); - outputFile << pointWeight << '\n'; - } - - outputFile.flush(); - outputFile.close(); - - return EXIT_SUCCESS; -} diff --git a/test/Registration/itktubeTubeParametricExponentialResolutionWeightFunctionTest.cxx b/test/Registration/itktubeTubeParametricExponentialResolutionWeightFunctionTest.cxx deleted file mode 100644 index 32483dccb..000000000 --- a/test/Registration/itktubeTubeParametricExponentialResolutionWeightFunctionTest.cxx +++ /dev/null @@ -1,129 +0,0 @@ -/*========================================================================= - -Library: TubeTK - -Copyright 2010 Kitware Inc. 28 Corporate Drive, -Clifton Park, NY, 12065, USA. - -All rights reserved. - -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. - -=========================================================================*/ - -#include "itktubeTubeParametricExponentialResolutionWeightFunction.h" - -#include - -#include - -template< class TWeightFunction, class TTubePoint > -void -writeElement( std::ofstream & outputFile, - TWeightFunction & weightFunction, - const TTubePoint & tubePoint, - float alpha, - float delta, - char delim=',' ) -{ - weightFunction.SetAlpha( alpha ); - weightFunction.SetDelta( delta ); - float pointWeight = weightFunction( tubePoint ); - outputFile << pointWeight << delim; -} - -int itktubeTubeParametricExponentialResolutionWeightFunctionTest( int argc, char * argv[] ) -{ - if( argc < 2 ) - { - std::cerr << "Usage: " - << argv[0] - << " output.csv" - << std::endl; - return EXIT_FAILURE; - } - const char * outputCSV = argv[1]; - - enum { Dimension = 2 }; - typedef itk::TubeSpatialObjectPoint< Dimension > TubePointType; - typedef std::vector< TubePointType > TubePointContainerType; - - // Create tube points with increasing radius. - const unsigned int numberOfPoints = 100; - TubePointContainerType tubePointContainer( numberOfPoints ); - const double startingRadius = 0.00; - const double radiusIncrement = 0.01; - double radius = startingRadius; - for( unsigned int ii = 0; ii < numberOfPoints; ++ii ) - { - tubePointContainer[ii].SetRadiusInObjectSpace( radius ); - radius += radiusIncrement; - } - - // Write the tube point weights to file. - std::ofstream outputFile( outputCSV ); - if( !outputFile.is_open() ) - { - std::cerr << "Cannot open output file." << std::endl; - return EXIT_FAILURE; - } - - typedef itk::tube::Function::TubeParametricExponentialResolutionWeightFunction< TubePointType, float > - WeightFunctionType; - WeightFunctionType weightFunction; - - weightFunction.SetAlpha( 2.0f ); - float alpha = weightFunction.GetAlpha(); - if( alpha != 2.0f ) - { - std::cerr << "Failure in GetAlpha." << std::endl; - return EXIT_FAILURE; - } - - weightFunction.SetDelta( 2.0f ); - float delta = weightFunction.GetDelta(); - if( delta != 2.0f ) - { - std::cerr << "Failure in GetDelta." << std::endl; - return EXIT_FAILURE; - } - - unsigned int numberOfAlphas = 5; - double alphas[] = { 5.0, 2.0, 1.0, 0.5, 0.0 }; - unsigned int numberOfDeltas = 5; - double deltas[] = { 0.7, 0.5, 0.0, -0.5, -0.7 }; - - for( unsigned int ii = 0; ii < numberOfPoints; ++ii ) - { - for( unsigned int jj = 0; jj < numberOfAlphas - 1; ++jj ) - { - for( unsigned int kk = 0; kk < numberOfDeltas; ++kk ) - { - writeElement( outputFile, weightFunction, - tubePointContainer[ii], alphas[jj], deltas[kk] ); - } - } - for( unsigned int kk = 0; kk < numberOfDeltas - 1; ++kk ) - { - writeElement( outputFile, weightFunction, - tubePointContainer[ii], alphas[numberOfAlphas-1], deltas[kk] ); - } - writeElement( outputFile, weightFunction, - tubePointContainer[ii], alphas[numberOfAlphas-1], deltas[numberOfDeltas-1], '\n' ); - } - - outputFile.flush(); - outputFile.close(); - - return EXIT_SUCCESS; -} diff --git a/test/Registration/itktubeTubeParametricExponentialWithBoundsResolutionWeightFunctionTest.cxx b/test/Registration/itktubeTubeParametricExponentialWithBoundsResolutionWeightFunctionTest.cxx deleted file mode 100644 index da9ea4b7a..000000000 --- a/test/Registration/itktubeTubeParametricExponentialWithBoundsResolutionWeightFunctionTest.cxx +++ /dev/null @@ -1,146 +0,0 @@ -/*========================================================================= - -Library: TubeTK - -Copyright 2010 Kitware Inc. 28 Corporate Drive, -Clifton Park, NY, 12065, USA. - -All rights reserved. - -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. - -=========================================================================*/ - -#include "itktubeTubeParametricExponentialWithBoundsResolutionWeightFunction.h" - -#include - -#include - -template< class TWeightFunction, class TTubePoint > -void -writeElement( std::ofstream & outputFile, - TWeightFunction & weightFunction, - const TTubePoint & tubePoint, - float alpha, - float delta, - char delim=',' ) -{ - weightFunction.SetAlpha( alpha ); - weightFunction.SetDelta( delta ); - float pointWeight = weightFunction( tubePoint ); - outputFile << pointWeight << delim; -} - - -int itktubeTubeParametricExponentialWithBoundsResolutionWeightFunctionTest( int argc, char * argv[] ) -{ - if( argc < 2 ) - { - std::cerr << "Usage: " - << argv[0] - << " output.csv" - << std::endl; - return EXIT_FAILURE; - } - const char * outputCSV = argv[1]; - - enum { Dimension = 2 }; - typedef itk::TubeSpatialObjectPoint< Dimension > TubePointType; - typedef std::vector< TubePointType > TubePointContainerType; - - // Create tube points with increasing radius. - const unsigned int numberOfPoints = 100; - TubePointContainerType tubePointContainer( numberOfPoints ); - const double startingRadius = 0.00; - const double radiusIncrement = 0.01; - double radius = startingRadius; - for( unsigned int ii = 0; ii < numberOfPoints; ++ii ) - { - tubePointContainer[ii].SetRadiusInObjectSpace( radius ); - radius += radiusIncrement; - } - - // Write the tube point weights to file. - std::ofstream outputFile( outputCSV ); - if( !outputFile.is_open() ) - { - std::cerr << "Cannot open output file." << std::endl; - return EXIT_FAILURE; - } - - typedef itk::tube::Function::TubeParametricExponentialWithBoundsResolutionWeightFunction< TubePointType, float > - WeightFunctionType; - WeightFunctionType weightFunction; - - weightFunction.SetAlpha( 2.0f ); - float alpha = weightFunction.GetAlpha(); - if( alpha != 2.0f ) - { - std::cerr << "Failure in GetAlpha." << std::endl; - return EXIT_FAILURE; - } - - weightFunction.SetDelta( 2.0f ); - float delta = weightFunction.GetDelta(); - if( delta != 2.0f ) - { - std::cerr << "Failure in GetDelta." << std::endl; - return EXIT_FAILURE; - } - - weightFunction.SetLowerBound( 0.2f ); - float lower = weightFunction.GetLowerBound(); - if( lower != 0.2f ) - { - std::cerr << "Failure in GetLowerBound." << std::endl; - return EXIT_FAILURE; - } - - weightFunction.SetUpperBound( 0.7f ); - float upper = weightFunction.GetUpperBound(); - if( upper != 0.7f ) - { - std::cerr << "Failure in GetUpperBound." << std::endl; - return EXIT_FAILURE; - } - - unsigned int numberOfAlphas = 5; - double alphas[] = { 5.0, 2.0, 1.0, 0.5, 0.0 }; - unsigned int numberOfDeltas = 5; - double deltas[] = { 0.7, 0.5, 0.0, -0.5, -0.7 }; - - for( unsigned int ii = 0; ii < numberOfPoints; ++ii ) - { - for( unsigned int jj = 0; jj < numberOfAlphas - 1; ++jj ) - { - for( unsigned int kk = 0; kk < numberOfDeltas; ++kk ) - { - writeElement( outputFile, weightFunction, - tubePointContainer[ii], alphas[jj], deltas[kk] ); - } - } - for( unsigned int kk = 0; kk < numberOfDeltas - 1; ++kk ) - { - writeElement( outputFile, weightFunction, - tubePointContainer[ii], alphas[numberOfAlphas-1], deltas[kk] ); - } - writeElement( outputFile, weightFunction, - tubePointContainer[ii], alphas[numberOfAlphas-1], deltas[numberOfDeltas-1], '\n' ); - } - - outputFile.flush(); - outputFile.close(); - - return EXIT_SUCCESS; -} diff --git a/test/Registration/itktubeTubePointWeightsCalculatorTest.cxx b/test/Registration/itktubeTubePointWeightsCalculatorTest.cxx deleted file mode 100644 index 4f6d18b8a..000000000 --- a/test/Registration/itktubeTubePointWeightsCalculatorTest.cxx +++ /dev/null @@ -1,108 +0,0 @@ -/*========================================================================= - -Library: TubeTK - -Copyright 2010 Kitware Inc. 28 Corporate Drive, -Clifton Park, NY, 12065, USA. - -All rights reserved. - -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. - -=========================================================================*/ - -#include "itktubeTubeExponentialResolutionWeightFunction.h" -#include "itktubeTubePointWeightsCalculator.h" - -#include -#include -#include - -#include - -int itktubeTubePointWeightsCalculatorTest( int argc, char * argv[] ) -{ - if( argc < 2 ) - { - std::cerr << "Usage: " - << argv[0] - << " output.csv" - << std::endl; - return EXIT_FAILURE; - } - const char * outputCSV = argv[1]; - - enum { Dimension = 2 }; - typedef itk::GroupSpatialObject< Dimension > GroupType; - typedef itk::TubeSpatialObject< Dimension > TubeType; - typedef TubeType::TubePointType TubePointType; - typedef TubeType::TubePointListType TubePointContainerType; - - // Create tube points with increasing radius. - const unsigned int numberOfPoints = 100; - TubePointContainerType tubePointContainer( numberOfPoints ); - const double startingRadius = 0.00; - const double radiusIncrement = 0.01; - double radius = startingRadius; - for( unsigned int ii = 0; ii < numberOfPoints; ++ii ) - { - tubePointContainer[ii].SetRadiusInObjectSpace( radius ); - radius += radiusIncrement; - } - TubeType::Pointer tubes = TubeType::New(); - tubes->SetPoints( tubePointContainer ); - - GroupType::Pointer group = GroupType::New(); - GroupType::ChildrenListType children; - children.push_back( tubes.GetPointer() ); - group->SetChildren( children ); - - // Write the tube point weights to file. - std::ofstream outputFile( outputCSV ); - if( !outputFile.is_open() ) - { - std::cerr << "Cannot open output file." << std::endl; - return EXIT_FAILURE; - } - - typedef itk::tube::Function::TubeExponentialResolutionWeightFunction< - TubePointType, float > WeightFunctionType; - WeightFunctionType::Pointer weightFunction = WeightFunctionType::New(); - - typedef itk::OptimizerParameters< float > PointWeightsType; - - typedef itk::tube::TubePointWeightsCalculator< Dimension, - TubeType, WeightFunctionType, - PointWeightsType > PointWeightsCalculatorType; - PointWeightsCalculatorType::Pointer resolutionWeightsCalculator - = PointWeightsCalculatorType::New(); - resolutionWeightsCalculator->SetTubeTreeSpatialObject( group ); - resolutionWeightsCalculator->SetPointWeightFunction( weightFunction ); - resolutionWeightsCalculator->Compute(); - const PointWeightsType & resolutionWeights - = resolutionWeightsCalculator->GetPointWeights(); - - for( unsigned int ii = 0; ii < numberOfPoints; ++ii ) - { - const float pointWeight = resolutionWeights[ii]; - outputFile << pointWeight << '\n'; - } - - outputFile.flush(); - outputFile.close(); - - // test PrintSelf - std::cout << resolutionWeightsCalculator << std::endl; - - return EXIT_SUCCESS; -} diff --git a/test/Registration/tubeRegistrationHeaderTest.cxx b/test/Registration/tubeRegistrationHeaderTest.cxx index 1b7e07517..9fccb78d0 100644 --- a/test/Registration/tubeRegistrationHeaderTest.cxx +++ b/test/Registration/tubeRegistrationHeaderTest.cxx @@ -23,7 +23,6 @@ limitations under the License. #include #include -#include "itkAffine3DImageToImageRegistrationMethod.h" #include "itkAffineImageToImageRegistrationMethod.h" #include "itkAnisotropicSimilarity3DTransform.h" #include "itkAnisotropicSimilarityLandmarkBasedTransformInitializer.h" @@ -44,16 +43,18 @@ limitations under the License. //#include "itktubeAnisotropicDiffusiveSparseRegistrationFilter.h" #include "itktubeDiffusiveRegistrationFilter.h" #include "itktubeDiffusiveRegistrationFilterUtils.h" -#include "itktubeImageToTubeRigidMetric.h" -#include "itktubeImageToTubeRigidRegistration.h" +#include "itktubeInitialSpatialObjectToImageRegistrationMethod.h" #include "itktubeMeanSquareRegistrationFunction.h" #include "itktubeMergeAdjacentImagesFilter.h" -#include "itktubeTubeAngleOfIncidenceWeightFunction.h" -#include "itktubeTubeExponentialResolutionWeightFunction.h" -#include "itktubeTubeParametricExponentialResolutionWeightFunction.h" -#include "itktubeTubeParametricExponentialWithBoundsResolutionWeightFunction.h" -#include "itktubeTubePointWeightsCalculator.h" -#include "itktubeTubeToTubeTransformFilter.h" +#include "itktubeOptimizedSpatialObjectToImageRegistrationMethod.h" +#include "itktubePointBasedSpatialObjectToImageMetric.h" +#include "itktubePointBasedSpatialObjectTransformFilter.h" +#include "itktubeRigidSpatialObjectToImageRegistrationMethod.h" +#include "itktubeScaleSkewAngle2DSpatialObjectToImageRegistrationMethod.h" +#include "itktubeScaleSkewVersor3DSpatialObjectToImageRegistrationMethod.h" +#include "itktubeSpatialObjectToImageMetric.h" +#include "itktubeSpatialObjectToImageRegistrationHelper.h" +#include "itktubeSpatialObjectToImageRegistrationMethod.h" int tubeRegistrationHeaderTest( int itkNotUsed( argc ), char * itkNotUsed( argv )[] ) diff --git a/test/Registration/tubeRegistrationPrintTest.cxx b/test/Registration/tubeRegistrationPrintTest.cxx index b7301feb3..dab8248c0 100644 --- a/test/Registration/tubeRegistrationPrintTest.cxx +++ b/test/Registration/tubeRegistrationPrintTest.cxx @@ -23,7 +23,6 @@ limitations under the License. #include #include -#include "itkAffine3DImageToImageRegistrationMethod.h" #include "itkAffineImageToImageRegistrationMethod.h" #include "itkAnisotropicSimilarity3DTransform.h" #include "itkAnisotropicSimilarityLandmarkBasedTransformInitializer.h" @@ -44,16 +43,12 @@ limitations under the License. //#include "itktubeAnisotropicDiffusiveSparseRegistrationFilter.h" #include "itktubeDiffusiveRegistrationFilter.h" #include "itktubeDiffusiveRegistrationFilterUtils.h" -#include "itktubeImageToTubeRigidMetric.h" -#include "itktubeImageToTubeRigidRegistration.h" +#include "itktubePointBasedSpatialObjectToImageMetric.h" +#include "itktubeSpatialObjectToImageRegistrationMethod.h" +#include "itktubeSpatialObjectToImageRegistrationHelper.h" #include "itktubeMeanSquareRegistrationFunction.h" #include "itktubeMergeAdjacentImagesFilter.h" -#include "itktubeTubeAngleOfIncidenceWeightFunction.h" -#include "itktubeTubeExponentialResolutionWeightFunction.h" -#include "itktubeTubeParametricExponentialResolutionWeightFunction.h" -#include "itktubeTubeParametricExponentialWithBoundsResolutionWeightFunction.h" -#include "itktubeTubePointWeightsCalculator.h" -#include "itktubeTubeToTubeTransformFilter.h" +#include "itktubePointBasedSpatialObjectTransformFilter.h" int tubeRegistrationPrintTest( int itkNotUsed( argc ), char * itkNotUsed( argv )[] ) diff --git a/test/Segmentation/itktubeTubeExtractorTest.cxx b/test/Segmentation/itktubeTubeExtractorTest.cxx index 01083a66f..64f3c3db5 100644 --- a/test/Segmentation/itktubeTubeExtractorTest.cxx +++ b/test/Segmentation/itktubeTubeExtractorTest.cxx @@ -74,6 +74,13 @@ int itktubeTubeExtractorTest( int argc, char * argv[] ) unsigned int numTubes = tubeList->size(); std::cout << "Number of tubes = " << numTubes << std::endl; + auto tubeIter = tubeList->begin(); + while(tubeIter != tubeList->end()) + { + static_cast(tubeIter->GetPointer())->ComputeTangentsAndNormals(); + ++tubeIter; + } + typedef itk::Statistics::MersenneTwisterRandomVariateGenerator RandGenType; RandGenType::Pointer rndGen = RandGenType::New(); @@ -160,6 +167,7 @@ int itktubeTubeExtractorTest( int argc, char * argv[] ) tubeOp->SetExtractBoundMinInIndexSpace( minX ); tubeOp->SetExtractBoundMaxInIndexSpace( maxX ); + /* if( pnt->GetRadiusInObjectSpace() > 1 ) { tubeOp->SetRadiusInObjectSpace( 0.8 * pnt->GetRadiusInObjectSpace() ); @@ -167,7 +175,7 @@ int itktubeTubeExtractorTest( int argc, char * argv[] ) else { tubeOp->SetRadiusInObjectSpace( 0.5 ); - } + } */ ImageType::PointType pntX1 = pntX; @@ -310,5 +318,6 @@ int itktubeTubeExtractorTest( int argc, char * argv[] ) return EXIT_FAILURE; } + std::cout << "SUCCESS" << std::endl; return EXIT_SUCCESS; }