From 250fdc0cdd803c1f1ec038beb6fb18f3d622c9b8 Mon Sep 17 00:00:00 2001 From: gokhangg Date: Fri, 10 Apr 2020 14:11:21 +0200 Subject: [PATCH] ADD: Addition of point to surface metric to Elastix. In this commit addition of point to surface metric is done. This metric essentially considers how surface of an masked organ is aligned with the points provided from the surface of the organ. Therefore, it is used to improve alignment of the organ under interest. --- .../elxPointToSurfaceDistanceMetric.cxx | 30 ++++--- .../elxPointToSurfaceDistanceMetric.h | 43 +++++----- .../elxPointToSurfaceDistanceMetric.hxx | 38 +++++---- .../itkPointToSurfaceDistanceMetric.h | 48 ++++++----- .../itkPointToSurfaceDistanceMetric.hxx | 82 ++++++++++--------- 5 files changed, 127 insertions(+), 114 deletions(-) diff --git a/Components/Metrics/PointToSurfaceDistance/elxPointToSurfaceDistanceMetric.cxx b/Components/Metrics/PointToSurfaceDistance/elxPointToSurfaceDistanceMetric.cxx index 3e6ba55e9..d6be492a1 100644 --- a/Components/Metrics/PointToSurfaceDistance/elxPointToSurfaceDistanceMetric.cxx +++ b/Components/Metrics/PointToSurfaceDistance/elxPointToSurfaceDistanceMetric.cxx @@ -1,16 +1,20 @@ -/*====================================================================== - - This file is part of the elastix software. - - Copyright (c) University Medical Center Utrecht. All rights reserved. - See src/CopyrightElastix.txt or http://elastix.isi.uu.nl/legal.php 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. - -======================================================================*/ +/*========================================================================= + * + * Copyright UMC Utrecht and contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0.txt + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + *=========================================================================*/ #include "elxPointToSurfaceDistanceMetric.h" diff --git a/Components/Metrics/PointToSurfaceDistance/elxPointToSurfaceDistanceMetric.h b/Components/Metrics/PointToSurfaceDistance/elxPointToSurfaceDistanceMetric.h index 8c397b05b..51d0bdbee 100644 --- a/Components/Metrics/PointToSurfaceDistance/elxPointToSurfaceDistanceMetric.h +++ b/Components/Metrics/PointToSurfaceDistance/elxPointToSurfaceDistanceMetric.h @@ -1,16 +1,20 @@ -/*====================================================================== - - This file is part of the elastix software. - - Copyright (c) University Medical Center Utrecht. All rights reserved. - See src/CopyrightElastix.txt or http://elastix.isi.uu.nl/legal.php 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. - -======================================================================*/ +/*========================================================================= + * + * Copyright UMC Utrecht and contributors + * + * 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 __elxPointToSurfaceDistanceMetric_H__ #define __elxPointToSurfaceDistanceMetric_H__ @@ -21,8 +25,6 @@ namespace elastix { /** - * \class TransformRigidityPenalty - * \brief A penalty term based on non-rigidity. * * For more information check the paper:\n * Gunay, G. , Luu, M. H., Moelker, A. , Walsum, T. and Klein, S. (2017), @@ -61,10 +63,6 @@ class PointToSurfaceDistanceMetric : public: using Self = PointToSurfaceDistanceMetric; - /** The private constructor. */ - PointToSurfaceDistanceMetric(const Self &) = delete; - /** The private copy constructor. */ - void operator=(const Self &) = delete; /** Standard ITK-stuff. */ using Superclass1 = itk::PointToSurfaceDistanceMetric::FixedPointSetType, typename MetricBase< TElastix >::MovingPointSetType >; @@ -72,6 +70,7 @@ class PointToSurfaceDistanceMetric : using Pointer = itk::SmartPointer< Self >; using ConstPointer = itk::SmartPointer< const Self >; + ITK_DISALLOW_COPY_AND_ASSIGN(PointToSurfaceDistanceMetric); /** Method for creation through the object factory. */ itkNewMacro( Self ); @@ -143,8 +142,6 @@ class PointToSurfaceDistanceMetric : */ virtual void BeforeRegistration(); -/** Function to read the corresponding points. */ -/** Function to read the corresponding points. */ using ImageConstPointer = typename Superclass1::ImageType::ConstPointer; unsigned int ReadLandmarks( const std::string & landmarkFileName, typename PointSetType::Pointer & pointSet, typename FixedImageType::ConstPointer image ); @@ -155,9 +152,9 @@ class PointToSurfaceDistanceMetric : protected: /** The constructor. */ - PointToSurfaceDistanceMetric(){} + PointToSurfaceDistanceMetric() = default; /** The destructor. */ - virtual ~PointToSurfaceDistanceMetric() {} + virtual ~PointToSurfaceDistanceMetric() = default; }; diff --git a/Components/Metrics/PointToSurfaceDistance/elxPointToSurfaceDistanceMetric.hxx b/Components/Metrics/PointToSurfaceDistance/elxPointToSurfaceDistanceMetric.hxx index 21a3fb64f..13da14198 100644 --- a/Components/Metrics/PointToSurfaceDistance/elxPointToSurfaceDistanceMetric.hxx +++ b/Components/Metrics/PointToSurfaceDistance/elxPointToSurfaceDistanceMetric.hxx @@ -1,16 +1,20 @@ -/*====================================================================== - - This file is part of the elastix software. - - Copyright (c) University Medical Center Utrecht. All rights reserved. - See src/CopyrightElastix.txt or http://elastix.isi.uu.nl/legal.php 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. - -======================================================================*/ +/*========================================================================= + * + * Copyright UMC Utrecht and contributors + * + * 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 __elxPointToSurfaceDistanceMetric_HXX__ #define __elxPointToSurfaceDistanceMetric_HXX__ @@ -57,15 +61,15 @@ PointToSurfaceDistanceMetric< TElastix > /** Check for appearance of parameter "PointToSurfaceDistanceAverage". */ std::string PointToSurfaceDistanceAverageStr = "true"; - this->m_AvPointWeigh=true; - if (this->m_Configuration->CountNumberOfParameterEntries( "PointToSurfaceDistanceAverage" )==1) + this->m_AvPointWeigh = true; + if (this->m_Configuration->CountNumberOfParameterEntries( "PointToSurfaceDistanceAverage" ) == 1) { this->m_Configuration->ReadParameter( PointToSurfaceDistanceAverageStr, "PointToSurfaceDistanceAverage", 0 ); - if (PointToSurfaceDistanceAverageStr=="false") this->m_AvPointWeigh=false; + if (PointToSurfaceDistanceAverageStr == "false") this->m_AvPointWeigh = false; } elxout << "\nAverage of points in annotation set : " - << PointToSurfaceDistanceAverageStr<<"\n" + << PointToSurfaceDistanceAverageStr <<"\n" << std::endl; /** Check for appearance of "-fp". */ diff --git a/Components/Metrics/PointToSurfaceDistance/itkPointToSurfaceDistanceMetric.h b/Components/Metrics/PointToSurfaceDistance/itkPointToSurfaceDistanceMetric.h index d99fffcdd..4cf61117e 100644 --- a/Components/Metrics/PointToSurfaceDistance/itkPointToSurfaceDistanceMetric.h +++ b/Components/Metrics/PointToSurfaceDistance/itkPointToSurfaceDistanceMetric.h @@ -1,16 +1,20 @@ -/*====================================================================== - - This file is part of the elastix software. - - Copyright (c) University Medical Center Utrecht. All rights reserved. - See src/CopyrightElastix.txt or http://elastix.isi.uu.nl/legal.php 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. - -======================================================================*/ +/*========================================================================= + * + * Copyright UMC Utrecht and contributors + * + * 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 __itkPointToSurfaceDistanceMetric_h #define __itkPointToSurfaceDistanceMetric_h @@ -79,16 +83,16 @@ class PointToSurfaceDistanceMetric : /** Run-time type information (and related methods). */ itkTypeMacro( PointToSurfaceDistanceMetric, SingleValuedPointSetToPointSetMetric );//OK /** Initialize. */ - virtual void Initialize() noexcept(false); + virtual void Initialize(); /** Get the value for single valued optimizers. */ - MeasureType GetValue( const TransformParametersType & parameters ) const noexcept(false); + MeasureType GetValue( const TransformParametersType & parameters ) const; /** Get the derivatives of the match measure. */ - void GetDerivative( const TransformParametersType & parameters, DerivativeType & Derivative ) const noexcept(false); + void GetDerivative( const TransformParametersType & parameters, DerivativeType & Derivative ) const; /** Get value and derivatives for multiple valued optimizers. */ - void GetValueAndDerivative( const TransformParametersType & parameters, MeasureType & Value, DerivativeType & Derivative ) const noexcept(false); + void GetValueAndDerivative( const TransformParametersType & parameters, MeasureType & Value, DerivativeType & Derivative ) const; /** Set input Segmented Image File **/ void SetSegImageIn( const std::string str ) ; @@ -105,15 +109,15 @@ class PointToSurfaceDistanceMetric : protected: PointToSurfaceDistanceMetric(); - virtual ~PointToSurfaceDistanceMetric() {} - bool m_AvPointWeigh; + virtual ~PointToSurfaceDistanceMetric() = default; + bool m_AvPointWeigh{true}; private: PointToSurfaceDistanceMetric( const Self & ); - std::string m_SegFileIn,m_DTFileIn,m_DTFileOut; - typename ImageType::Pointer m_ADTimage; - typename InterpolatorType::Pointer m_interpolator; + std::string m_segmentationFileIn, m_distanceTransformFileIn, m_distanceTransformFileOut; + typename ImageType::Pointer m_internalDistanceTransformImage; + typename InterpolatorType::Pointer m_interpolator; }; diff --git a/Components/Metrics/PointToSurfaceDistance/itkPointToSurfaceDistanceMetric.hxx b/Components/Metrics/PointToSurfaceDistance/itkPointToSurfaceDistanceMetric.hxx index 395b293f6..abce21dec 100644 --- a/Components/Metrics/PointToSurfaceDistance/itkPointToSurfaceDistanceMetric.hxx +++ b/Components/Metrics/PointToSurfaceDistance/itkPointToSurfaceDistanceMetric.hxx @@ -1,16 +1,20 @@ -/*====================================================================== - - This file is part of the elastix software. - - Copyright (c) University Medical Center Utrecht. All rights reserved. - See src/CopyrightElastix.txt or http://elastix.isi.uu.nl/legal.php 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. - -======================================================================*/ +/*========================================================================= + * + * Copyright UMC Utrecht and contributors + * + * 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 __itkPointToSurfaceDistanceMetric_hxx #define __itkPointToSurfaceDistanceMetric_hxx @@ -27,7 +31,7 @@ namespace itk template< class TFixedPointSet, class TMovingPointSet > PointToSurfaceDistanceMetric< TFixedPointSet, TMovingPointSet > ::PointToSurfaceDistanceMetric() - : m_ADTimage{ nullptr } + : m_internalDistanceTransformImage{ nullptr } , m_interpolator{ nullptr } { @@ -35,7 +39,7 @@ PointToSurfaceDistanceMetric< TFixedPointSet, TMovingPointSet > template< class TFixedPointSet, class TMovingPointSet > void PointToSurfaceDistanceMetric< TFixedPointSet, TMovingPointSet > -::Initialize() noexcept(false) +::Initialize() { /** Initialize transform, interpolator, etc. Superclass::Initialize(); @@ -43,22 +47,22 @@ void PointToSurfaceDistanceMetric< TFixedPointSet, TMovingPointSet > /***********************ITK Stuffs******************************/ /** Sanity checks. */ - if ((m_SegFileIn.length() <= 0) && (m_DTFileIn.length() <= 0)) + if ((m_segmentationFileIn.length() <= 0) && (m_distanceTransformFileIn.length() <= 0)) { itkExceptionMacro( << "Neither Distance Transform nor Segmentation file is not found" ); } - if ((m_SegFileIn.length() > 0) && (m_DTFileIn.length() > 0)) + if ((m_segmentationFileIn.length() > 0) && (m_distanceTransformFileIn.length() > 0)) { itkExceptionMacro( << "Distance Transform and Segmentation files can not be loaded at the same time" ); } /***********************ITK Stuffs******************************/ try { - if ((m_SegFileIn.length() > 0)) + if ((m_segmentationFileIn.length() > 0)) { /***********************Absolute DT computation*****************/ - m_ADTimage = ImageType::New(); + m_internalDistanceTransformImage = ImageType::New(); auto DTfilter = DtFilterType::New(); auto DTfilter2 = DtFilterType::New(); auto NegateFilter = NegateFilterType::New(); @@ -66,8 +70,8 @@ void PointToSurfaceDistanceMetric< TFixedPointSet, TMovingPointSet > auto AddImage = AddImageFilt::New(); auto segReader = SegReaderType::New(); auto segReader2 = SegReaderType::New(); - segReader->SetFileName( m_SegFileIn ); - segReader2->SetFileName( m_SegFileIn ); + segReader->SetFileName( m_segmentationFileIn ); + segReader2->SetFileName( m_segmentationFileIn ); /******This values for rescaling were put trivially***********/ scaler->SetOutputMaximum( 10L );//These values should be changed after comprehensive experiments @@ -88,27 +92,27 @@ void PointToSurfaceDistanceMetric< TFixedPointSet, TMovingPointSet > scaler->SetInput( AddImage->GetOutput() ); scaler->Update(); - m_ADTimage = scaler->GetOutput(); - m_ADTimage->DisconnectPipeline(); + m_internalDistanceTransformImage = scaler->GetOutput(); + m_internalDistanceTransformImage->DisconnectPipeline(); /***********************Absolute DT computation*****************/ } // Read an ADT image outside. - if ((m_DTFileIn.length()>0)) + if ((m_distanceTransformFileIn.length()>0)) { - m_ADTimage = ImageType::New(); + m_internalDistanceTransformImage = ImageType::New(); auto dtReader = DTReaderType::New(); - dtReader->SetFileName( m_DTFileIn ); + dtReader->SetFileName( m_distanceTransformFileIn ); dtReader->Update(); - m_ADTimage = dtReader->GetOutput(); + m_internalDistanceTransformImage = dtReader->GetOutput(); } // Write an ADT image outside, just for checking. - if (m_DTFileOut.length()>0) + if (m_distanceTransformFileOut.length()>0) { auto writer = WriterType::New(); - writer->SetFileName( m_DTFileOut); - writer->SetInput( m_ADTimage ); + writer->SetFileName( m_distanceTransformFileOut); + writer->SetInput( m_internalDistanceTransformImage ); writer->Update(); } } @@ -117,11 +121,11 @@ void PointToSurfaceDistanceMetric< TFixedPointSet, TMovingPointSet > itkExceptionMacro(<< "There is a problem in the creation of distance transform image."); } - if (m_ADTimage) + if (m_internalDistanceTransformImage) { m_interpolator = InterpolatorType::New(); m_interpolator->SetSplineOrder(3); - m_interpolator->SetInputImage(m_ADTimage); + m_interpolator->SetInputImage(m_internalDistanceTransformImage); } else { @@ -136,7 +140,7 @@ void PointToSurfaceDistanceMetric< TFixedPointSet, TMovingPointSet > template< class TFixedPointSet, class TMovingPointSet > auto PointToSurfaceDistanceMetric< TFixedPointSet, TMovingPointSet > -::GetValue( const TransformParametersType & parameters ) const noexcept(false)-> MeasureType +::GetValue( const TransformParametersType & parameters ) const -> MeasureType { /***********************ITK Stuffs******************************/ /** Sanity checks. */ @@ -188,7 +192,7 @@ PointToSurfaceDistanceMetric< TFixedPointSet, TMovingPointSet > template< class TFixedPointSet, class TMovingPointSet > void PointToSurfaceDistanceMetric< TFixedPointSet, TMovingPointSet > -::GetDerivative( const TransformParametersType & parameters, DerivativeType & derivative ) const noexcept(false) +::GetDerivative( const TransformParametersType & parameters, DerivativeType & derivative ) const { MeasureType dummyvalue = NumericTraits< MeasureType >::Zero; this->GetValueAndDerivative( parameters, dummyvalue, derivative ); @@ -201,7 +205,7 @@ PointToSurfaceDistanceMetric< TFixedPointSet, TMovingPointSet > template< class TFixedPointSet, class TMovingPointSet > void PointToSurfaceDistanceMetric< TFixedPointSet, TMovingPointSet > -::GetValueAndDerivative( const TransformParametersType & parameters, MeasureType & value, DerivativeType & derivative ) const noexcept(false) +::GetValueAndDerivative( const TransformParametersType & parameters, MeasureType & value, DerivativeType & derivative ) const { /***********************ITK Stuffs******************************/ /** Sanity checks. */ @@ -302,7 +306,7 @@ void PointToSurfaceDistanceMetric< TFixedPointSet, TMovingPointSet > ::SetSegImageIn( const std::string str ) { - this->m_SegFileIn = str; + this->m_segmentationFileIn = str; } /** Set input Distance Transform Image File **/ @@ -311,7 +315,7 @@ void PointToSurfaceDistanceMetric< TFixedPointSet, TMovingPointSet > ::SetDTImageIn( const std::string str ) { - this->m_DTFileIn = str; + this->m_distanceTransformFileIn = str; } /** Set output Distance Transform File **/ @@ -320,7 +324,7 @@ void PointToSurfaceDistanceMetric< TFixedPointSet, TMovingPointSet > ::SetDTImageOut( const std::string str ) { - this->m_DTFileOut = str; + this->m_distanceTransformFileOut = str; } /** Get Distance Transform Image*/ @@ -329,7 +333,7 @@ auto PointToSurfaceDistanceMetric< TFixedPointSet, TMovingPointSet > ::GetDTImage() const -> ConstDTimage { - return static_cast::ImageType::ConstPointer>(m_ADTimage); + return static_cast::ImageType::ConstPointer>(m_internalDistanceTransformImage); } } // end namespace itk