Loading...
Searching...
No Matches
itkAdvancedImageMomentsCalculator.h
Go to the documentation of this file.
/*=========================================================================
*
* Copyright Insight Software Consortium
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0.txt
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*=========================================================================*/
#ifndef itkAdvancedImageMomentsCalculator_h
#define itkAdvancedImageMomentsCalculator_h
#include "itkInPlaceImageFilter.h"
#include "itkBinaryThresholdImageFilter.h"
#include "itkAffineTransform.h"
#include "itkImage.h"
#include "itkImageMaskSpatialObject.h"
#include "itkImageGridSampler.h"
#include "itkImageFullSampler.h"
#include <vnl/vnl_vector_fixed.h>
#include <vnl/vnl_matrix_fixed.h>
#include <vnl/vnl_diag_matrix.h>
#include "itkMultiThreaderBase.h"
#include <vector>
namespace itk
{
template <typename TImage>
class ITK_TEMPLATE_EXPORT AdvancedImageMomentsCalculator : public Object
{
public:
using Self = AdvancedImageMomentsCalculator<TImage>;
using Superclass = Object;
using Pointer = SmartPointer<Self>;
using ConstPointer = SmartPointer<const Self>;
itkNewMacro(Self);
itkTypeMacro(AdvancedImageMomentsCalculator, Object);
itkStaticConstMacro(ImageDimension, unsigned int, TImage::ImageDimension);
using ScalarType = double;
using VectorType = Vector<ScalarType, Self::ImageDimension>;
using SpatialObjectType = ImageMaskSpatialObject<Self::ImageDimension>;
using SpatialObjectPointer = typename SpatialObjectType::Pointer;
using SpatialObjectConstPointer = typename SpatialObjectType::ConstPointer;
using MatrixType = Matrix<ScalarType, Self::ImageDimension, Self::ImageDimension>;
using ImageType = TImage;
using ImagePointer = typename ImageType::Pointer;
using ImageConstPointer = typename ImageType::ConstPointer;
using AffineTransformType = AffineTransform<double, Self::ImageDimension>;
using AffineTransformPointer = typename AffineTransformType::Pointer;
virtual void
SetImage(const ImageType * image)
{
if (m_Image != image)
{
m_Image = image;
this->Modified();
m_Valid = false;
}
}
virtual void
SetSpatialObjectMask(const ImageMaskSpatialObject<Self::ImageDimension> * so)
{
if (m_SpatialObjectMask != so)
{
m_SpatialObjectMask = so;
this->Modified();
m_Valid = false;
}
}
void
Compute();
void
ComputeSingleThreaded();
ScalarType
GetTotalMass() const;
VectorType
GetFirstMoments() const;
MatrixType
GetSecondMoments() const;
VectorType
GetCenterOfGravity() const;
MatrixType
GetCentralMoments() const;
VectorType
GetPrincipalMoments() const;
MatrixType
GetPrincipalAxes() const;
AffineTransformPointer
GetPrincipalAxesToPhysicalAxesTransform() const;
AffineTransformPointer
GetPhysicalAxesToPrincipalAxesTransform() const;
void
SetNumberOfWorkUnits(ThreadIdType numberOfThreads)
{
this->m_Threader->SetNumberOfWorkUnits(numberOfThreads);
}
virtual void
BeforeThreadedCompute();
virtual void
AfterThreadedCompute();
using ImageGridSamplerType = itk::ImageGridSampler<ImageType>;
// using ImageGridSamplerType = itk::ImageFullSampler< ImageType > ;
using ImageGridSamplerPointer = typename ImageGridSamplerType::Pointer;
using ImageSampleContainerType = typename ImageGridSamplerType ::ImageSampleContainerType;
using ImageSampleContainerPointer = typename ImageSampleContainerType::Pointer;
virtual void
SampleImage(ImageSampleContainerPointer & sampleContainer);
using BinaryThresholdImageFilterType = itk::BinaryThresholdImageFilter<TImage, TImage>;
using InputPixelType = typename TImage::PixelType;
itkSetMacro(NumberOfSamplesForCenteredTransformInitialization, SizeValueType);
itkSetMacro(LowerThresholdForCenterGravity, InputPixelType);
itkSetMacro(CenterOfGravityUsesLowerThreshold, bool);
protected:
AdvancedImageMomentsCalculator();
~AdvancedImageMomentsCalculator() override = default;
void
PrintSelf(std::ostream & os, Indent indent) const override;
using ThreadInfoType = MultiThreaderBase::WorkUnitInfo;
void
LaunchComputeThreaderCallback() const;
static ITK_THREAD_RETURN_FUNCTION_CALL_CONVENTION
ComputeThreaderCallback(void * arg);
virtual void
ThreadedCompute(ThreadIdType threadID);
virtual void
InitializeThreadingParameters();
struct MultiThreaderParameterType
{
Self * st_Self;
};
struct ComputePerThreadStruct
{
ScalarType st_M0; // Zeroth moment for threading
VectorType st_M1; // First moments about origin for threading
MatrixType st_M2; // Second moments about origin for threading
VectorType st_Cg; // Center of gravity (physical units) for threading
MatrixType st_Cm; // Second central moments (physical) for threading
SizeValueType st_NumberOfPixelsCounted;
};
itkPadStruct(ITK_CACHE_LINE_ALIGNMENT, ComputePerThreadStruct, PaddedComputePerThreadStruct);
itkAlignedTypedef(ITK_CACHE_LINE_ALIGNMENT, PaddedComputePerThreadStruct, AlignedComputePerThreadStruct);
using ThreadRegionType = typename ImageType::RegionType;
private:
void
DoPostProcessing();
AdvancedImageMomentsCalculator(const Self &);
void
operator=(const Self &);
MultiThreaderBase::Pointer m_Threader{};
mutable MultiThreaderParameterType m_ThreaderParameters{};
mutable std::vector<AlignedComputePerThreadStruct> m_ComputePerThreadVariables{};
bool m_UseMultiThread{};
SizeValueType m_NumberOfPixelsCounted{};
SizeValueType m_NumberOfSamplesForCenteredTransformInitialization{};
InputPixelType m_LowerThresholdForCenterGravity{};
bool m_CenterOfGravityUsesLowerThreshold{};
ImageSampleContainerPointer m_SampleContainer{};
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)
ImageConstPointer m_Image{};
SpatialObjectConstPointer m_SpatialObjectMask{};
}; // class AdvancedImageMomentsCalculator
} // end namespace itk
#ifndef ITK_MANUAL_INSTANTIATION
# include "itkAdvancedImageMomentsCalculator.hxx"
#endif
#endif /* itkAdvancedImageMomentsCalculator_h */
AffineTransform
double
itk::AdvancedImageMomentsCalculator::ThreadRegionType
typename ImageType::RegionType ThreadRegionType
Definition itkAdvancedImageMomentsCalculator.h:298
itk::AdvancedImageMomentsCalculator::ImageSampleContainerType
typename ImageGridSamplerType ::ImageSampleContainerType ImageSampleContainerType
Definition itkAdvancedImageMomentsCalculator.h:239
itk::AdvancedImageMomentsCalculator::SetImage
virtual void SetImage(const ImageType *image)
Definition itkAdvancedImageMomentsCalculator.h:115
itk::AdvancedImageMomentsCalculator::itkAlignedTypedef
itkAlignedTypedef(ITK_CACHE_LINE_ALIGNMENT, PaddedComputePerThreadStruct, AlignedComputePerThreadStruct)
itk::AdvancedImageMomentsCalculator::GetPrincipalAxesToPhysicalAxesTransform
AffineTransformPointer GetPrincipalAxesToPhysicalAxesTransform() const
itk::AdvancedImageMomentsCalculator::ImageType
TImage ImageType
Definition itkAdvancedImageMomentsCalculator.h:103
itk::AdvancedImageMomentsCalculator::DoPostProcessing
void DoPostProcessing()
itk::AdvancedImageMomentsCalculator< FixedImageType >::m_Pm
VectorType m_Pm
Definition itkAdvancedImageMomentsCalculator.h:329
itk::AdvancedImageMomentsCalculator< FixedImageType >::m_NumberOfPixelsCounted
SizeValueType m_NumberOfPixelsCounted
Definition itkAdvancedImageMomentsCalculator.h:316
itk::AdvancedImageMomentsCalculator< FixedImageType >::m_NumberOfSamplesForCenteredTransformInitialization
SizeValueType m_NumberOfSamplesForCenteredTransformInitialization
Definition itkAdvancedImageMomentsCalculator.h:318
itk::AdvancedImageMomentsCalculator::GetTotalMass
ScalarType GetTotalMass() const
itk::AdvancedImageMomentsCalculator::~AdvancedImageMomentsCalculator
~AdvancedImageMomentsCalculator() override=default
itk::AdvancedImageMomentsCalculator::BinaryThresholdImageFilterType
itk::BinaryThresholdImageFilter< TImage, TImage > BinaryThresholdImageFilterType
Definition itkAdvancedImageMomentsCalculator.h:245
itk::AdvancedImageMomentsCalculator::itkPadStruct
itkPadStruct(ITK_CACHE_LINE_ALIGNMENT, ComputePerThreadStruct, PaddedComputePerThreadStruct)
itk::AdvancedImageMomentsCalculator::itkStaticConstMacro
itkStaticConstMacro(ImageDimension, unsigned int, TImage::ImageDimension)
itk::AdvancedImageMomentsCalculator::GetCenterOfGravity
VectorType GetCenterOfGravity() const
itk::AdvancedImageMomentsCalculator::SetNumberOfWorkUnits
void SetNumberOfWorkUnits(ThreadIdType numberOfThreads)
Definition itkAdvancedImageMomentsCalculator.h:225
itk::AdvancedImageMomentsCalculator::SetSpatialObjectMask
virtual void SetSpatialObjectMask(const ImageMaskSpatialObject< Self::ImageDimension > *so)
Definition itkAdvancedImageMomentsCalculator.h:127
itk::AdvancedImageMomentsCalculator::PrintSelf
void PrintSelf(std::ostream &os, Indent indent) const override
itk::AdvancedImageMomentsCalculator< FixedImageType >::m_Pa
MatrixType m_Pa
Definition itkAdvancedImageMomentsCalculator.h:330
itk::AdvancedImageMomentsCalculator::ImageConstPointer
typename ImageType::ConstPointer ImageConstPointer
Definition itkAdvancedImageMomentsCalculator.h:107
itk::AdvancedImageMomentsCalculator::GetPhysicalAxesToPrincipalAxesTransform
AffineTransformPointer GetPhysicalAxesToPrincipalAxesTransform() const
itk::AdvancedImageMomentsCalculator::Superclass
Object Superclass
Definition itkAdvancedImageMomentsCalculator.h:73
itk::AdvancedImageMomentsCalculator::ThreadInfoType
MultiThreaderBase::WorkUnitInfo ThreadInfoType
Definition itkAdvancedImageMomentsCalculator.h:260
itk::AdvancedImageMomentsCalculator< FixedImageType >::m_Valid
bool m_Valid
Definition itkAdvancedImageMomentsCalculator.h:323
itk::AdvancedImageMomentsCalculator::ImageSampleContainerPointer
typename ImageSampleContainerType::Pointer ImageSampleContainerPointer
Definition itkAdvancedImageMomentsCalculator.h:240
itk::AdvancedImageMomentsCalculator::AdvancedImageMomentsCalculator
AdvancedImageMomentsCalculator(const Self &)
itk::AdvancedImageMomentsCalculator::operator=
void operator=(const Self &)
itk::AdvancedImageMomentsCalculator::GetPrincipalAxes
MatrixType GetPrincipalAxes() const
itk::AdvancedImageMomentsCalculator< FixedImageType >::m_M0
ScalarType m_M0
Definition itkAdvancedImageMomentsCalculator.h:324
itk::AdvancedImageMomentsCalculator::AfterThreadedCompute
virtual void AfterThreadedCompute()
itk::AdvancedImageMomentsCalculator< FixedImageType >::m_Threader
MultiThreaderBase::Pointer m_Threader
Definition itkAdvancedImageMomentsCalculator.h:310
itk::AdvancedImageMomentsCalculator< FixedImageType >::m_Cm
MatrixType m_Cm
Definition itkAdvancedImageMomentsCalculator.h:328
itk::AdvancedImageMomentsCalculator::Compute
void Compute()
itk::AdvancedImageMomentsCalculator::ComputeThreaderCallback
static ITK_THREAD_RETURN_FUNCTION_CALL_CONVENTION ComputeThreaderCallback(void *arg)
itk::AdvancedImageMomentsCalculator::VectorType
Vector< ScalarType, Self::ImageDimension > VectorType
Definition itkAdvancedImageMomentsCalculator.h:90
itk::AdvancedImageMomentsCalculator::Pointer
SmartPointer< Self > Pointer
Definition itkAdvancedImageMomentsCalculator.h:74
itk::AdvancedImageMomentsCalculator::MatrixType
Matrix< ScalarType, Self::ImageDimension, Self::ImageDimension > MatrixType
Definition itkAdvancedImageMomentsCalculator.h:100
itk::AdvancedImageMomentsCalculator::GetPrincipalMoments
VectorType GetPrincipalMoments() const
itk::AdvancedImageMomentsCalculator< FixedImageType >::m_ThreaderParameters
MultiThreaderParameterType m_ThreaderParameters
Definition itkAdvancedImageMomentsCalculator.h:312
itk::AdvancedImageMomentsCalculator::SpatialObjectPointer
typename SpatialObjectType::Pointer SpatialObjectPointer
Definition itkAdvancedImageMomentsCalculator.h:96
itk::AdvancedImageMomentsCalculator::ImageGridSamplerPointer
typename ImageGridSamplerType::Pointer ImageGridSamplerPointer
Definition itkAdvancedImageMomentsCalculator.h:238
itk::AdvancedImageMomentsCalculator::ScalarType
double ScalarType
Definition itkAdvancedImageMomentsCalculator.h:87
itk::AdvancedImageMomentsCalculator< FixedImageType >::m_ComputePerThreadVariables
std::vector< AlignedComputePerThreadStruct > m_ComputePerThreadVariables
Definition itkAdvancedImageMomentsCalculator.h:314
itk::AdvancedImageMomentsCalculator< FixedImageType >::m_SampleContainer
ImageSampleContainerPointer m_SampleContainer
Definition itkAdvancedImageMomentsCalculator.h:321
itk::AdvancedImageMomentsCalculator::GetSecondMoments
MatrixType GetSecondMoments() const
itk::AdvancedImageMomentsCalculator< FixedImageType >::m_Image
ImageConstPointer m_Image
Definition itkAdvancedImageMomentsCalculator.h:332
itk::AdvancedImageMomentsCalculator< FixedImageType >::m_Cg
VectorType m_Cg
Definition itkAdvancedImageMomentsCalculator.h:327
itk::AdvancedImageMomentsCalculator::AffineTransformPointer
typename AffineTransformType::Pointer AffineTransformPointer
Definition itkAdvancedImageMomentsCalculator.h:111
itk::AdvancedImageMomentsCalculator::SpatialObjectType
ImageMaskSpatialObject< Self::ImageDimension > SpatialObjectType
Definition itkAdvancedImageMomentsCalculator.h:93
itk::AdvancedImageMomentsCalculator::BeforeThreadedCompute
virtual void BeforeThreadedCompute()
itk::AdvancedImageMomentsCalculator< FixedImageType >::m_CenterOfGravityUsesLowerThreshold
bool m_CenterOfGravityUsesLowerThreshold
Definition itkAdvancedImageMomentsCalculator.h:320
itk::AdvancedImageMomentsCalculator::SampleImage
virtual void SampleImage(ImageSampleContainerPointer &sampleContainer)
itk::AdvancedImageMomentsCalculator::LaunchComputeThreaderCallback
void LaunchComputeThreaderCallback() const
itk::AdvancedImageMomentsCalculator::ThreadedCompute
virtual void ThreadedCompute(ThreadIdType threadID)
itk::AdvancedImageMomentsCalculator::SpatialObjectConstPointer
typename SpatialObjectType::ConstPointer SpatialObjectConstPointer
Definition itkAdvancedImageMomentsCalculator.h:97
itk::AdvancedImageMomentsCalculator< FixedImageType >::m_M2
MatrixType m_M2
Definition itkAdvancedImageMomentsCalculator.h:326
itk::AdvancedImageMomentsCalculator< FixedImageType >::m_M1
VectorType m_M1
Definition itkAdvancedImageMomentsCalculator.h:325
itk::AdvancedImageMomentsCalculator::GetFirstMoments
VectorType GetFirstMoments() const
itk::AdvancedImageMomentsCalculator::ConstPointer
SmartPointer< const Self > ConstPointer
Definition itkAdvancedImageMomentsCalculator.h:75
itk::AdvancedImageMomentsCalculator::AdvancedImageMomentsCalculator
AdvancedImageMomentsCalculator()
itk::AdvancedImageMomentsCalculator::ImagePointer
typename ImageType::Pointer ImagePointer
Definition itkAdvancedImageMomentsCalculator.h:106
itk::AdvancedImageMomentsCalculator< FixedImageType >::m_LowerThresholdForCenterGravity
InputPixelType m_LowerThresholdForCenterGravity
Definition itkAdvancedImageMomentsCalculator.h:319
itk::AdvancedImageMomentsCalculator::AffineTransformType
AffineTransform< double, Self::ImageDimension > AffineTransformType
Definition itkAdvancedImageMomentsCalculator.h:110
itk::AdvancedImageMomentsCalculator::ComputeSingleThreaded
void ComputeSingleThreaded()
itk::AdvancedImageMomentsCalculator::ImageGridSamplerType
itk::ImageGridSampler< ImageType > ImageGridSamplerType
Definition itkAdvancedImageMomentsCalculator.h:236
itk::AdvancedImageMomentsCalculator< FixedImageType >::m_SpatialObjectMask
SpatialObjectConstPointer m_SpatialObjectMask
Definition itkAdvancedImageMomentsCalculator.h:333
itk::AdvancedImageMomentsCalculator::InputPixelType
typename TImage::PixelType InputPixelType
Definition itkAdvancedImageMomentsCalculator.h:246
itk::AdvancedImageMomentsCalculator::Self
AdvancedImageMomentsCalculator< TImage > Self
Definition itkAdvancedImageMomentsCalculator.h:72
itk::AdvancedImageMomentsCalculator::InitializeThreadingParameters
virtual void InitializeThreadingParameters()
itk::AdvancedImageMomentsCalculator::GetCentralMoments
MatrixType GetCentralMoments() const
itk::AdvancedImageMomentsCalculator< FixedImageType >::m_UseMultiThread
bool m_UseMultiThread
Definition itkAdvancedImageMomentsCalculator.h:315
itk::ImageGridSampler
Samples image voxels on a regular grid.
Definition itkImageGridSampler.h:46
itk::ImageGridSampler< ImageType >::Pointer
SmartPointer< Self > Pointer
Definition itkImageGridSampler.h:53
itkImageFullSampler.h
itkImageGridSampler.h
itk
Definition itkAdvancedImageToImageMetric.h:43
itk::AdvancedImageMomentsCalculator::ComputePerThreadStruct
Definition itkAdvancedImageMomentsCalculator.h:285
itk::AdvancedImageMomentsCalculator::ComputePerThreadStruct::st_M2
MatrixType st_M2
Definition itkAdvancedImageMomentsCalculator.h:289
itk::AdvancedImageMomentsCalculator::ComputePerThreadStruct::st_M0
ScalarType st_M0
Definition itkAdvancedImageMomentsCalculator.h:287
itk::AdvancedImageMomentsCalculator::ComputePerThreadStruct::st_Cg
VectorType st_Cg
Definition itkAdvancedImageMomentsCalculator.h:290
itk::AdvancedImageMomentsCalculator::ComputePerThreadStruct::st_M1
VectorType st_M1
Definition itkAdvancedImageMomentsCalculator.h:288
itk::AdvancedImageMomentsCalculator::ComputePerThreadStruct::st_NumberOfPixelsCounted
SizeValueType st_NumberOfPixelsCounted
Definition itkAdvancedImageMomentsCalculator.h:292
itk::AdvancedImageMomentsCalculator::ComputePerThreadStruct::st_Cm
MatrixType st_Cm
Definition itkAdvancedImageMomentsCalculator.h:291
itk::AdvancedImageMomentsCalculator::MultiThreaderParameterType
Definition itkAdvancedImageMomentsCalculator.h:280
itk::AdvancedImageMomentsCalculator::MultiThreaderParameterType::st_Self
Self * st_Self
Definition itkAdvancedImageMomentsCalculator.h:281

Generated on 1768596610 for elastix by 1.15.0 |