1 /*========================================================================= 2 * 3 * Copyright Insight Software Consortium 4 * 5 * Licensed under the Apache License, Version 2.0 (the "License"); 6 * you may not use this file except in compliance with the License. 7 * You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0.txt 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 * 17 *=========================================================================*/ 18 19 #ifndef itkLevelSetDomainMapImageFilter_h 20 #define itkLevelSetDomainMapImageFilter_h 21 22 #include "itkImageToImageFilter.h" 23 #include "itkImageRegionIterator.h" 24 #include "itkImageRegionIteratorWithIndex.h" 25 #include <list> 26 #include <utility> 27 #include <vector> 28 29 namespace itk 30 { 31 /** 32 \class LevelSetDomainMapImageFilter 33 \tparam TInputImage Image where the pixel type is a container (e.g. std::list) of level set ids 34 \tparam TOutputImage Image where the pixel type is an identifier integer to associate with each subdomain 35 36 Every subdomain (image region) has a consistent set of level sets ids associated with every pixel. 37 \ingroup ITKLevelSetsv4 38 */ 39 template < typename TInputImage, typename TOutputImage > 40 class ITK_TEMPLATE_EXPORT LevelSetDomainMapImageFilter : public ImageToImageFilter< TInputImage, TOutputImage > 41 { 42 public: 43 using Self = LevelSetDomainMapImageFilter; 44 using Superclass = ImageToImageFilter< TInputImage,TOutputImage >; 45 using Pointer = SmartPointer< Self >; 46 using ConstPointer = SmartPointer< const Self >; 47 48 static constexpr unsigned int ImageDimension = TInputImage::ImageDimension; 49 50 /** Method for creation through object factory */ 51 itkNewMacro ( Self ); 52 53 /** Run-time type information */ 54 itkTypeMacro ( LevelSetDomainMapImageFilter, ImageToImageFilter ); 55 56 using InputImageType = TInputImage; 57 using InputImageConstPointer = typename InputImageType::ConstPointer; 58 using InputImagePixelType = typename InputImageType::PixelType; 59 using InputImageRegionType = typename InputImageType::RegionType; 60 using InputImageSizeType = typename InputImageType::SizeType; 61 using InputImageSizeValueType = typename InputImageSizeType::SizeValueType; 62 using InputImageIndexType = typename InputImageType::IndexType; 63 64 using OutputImageType = TOutputImage; 65 using OutputImagePointer = typename OutputImageType::Pointer; 66 using OutputImageIndexType = typename OutputImageType::IndexType; 67 using OutputImagePixelType = typename OutputImageType::PixelType; 68 69 using InputConstIteratorType = ImageRegionConstIteratorWithIndex< InputImageType >; 70 using InputIndexIteratorType = ImageRegionIteratorWithIndex< InputImageType >; 71 using InputIteratorType = ImageRegionIterator< InputImageType >; 72 73 using OutputConstIteratorType = ImageRegionConstIteratorWithIndex< OutputImageType >; 74 using OutputIndexIteratorType = ImageRegionIteratorWithIndex< OutputImageType >; 75 using OutputIteratorType = ImageRegionIterator< OutputImageType >; 76 77 /** \class LevelSetDomain 78 * \brief Specifies an image region where an unique std::list of level sets Id's are defined. 79 * \ingroup ITKLevelSetsv4 */ 80 class LevelSetDomain 81 { 82 public: 83 LevelSetDomain() = default; 84 LevelSetDomain(const InputImageRegionType & reg,InputImagePixelType iList)85 LevelSetDomain( const InputImageRegionType& reg, 86 InputImagePixelType iList ) : 87 m_Region( reg ), m_IdList(std::move( iList )) {} 88 GetRegion()89 const InputImageRegionType * GetRegion() const 90 { 91 return &(this->m_Region); 92 } 93 GetIdList()94 const InputImagePixelType * GetIdList() const 95 { 96 return &(this->m_IdList); 97 } 98 99 private: 100 InputImageRegionType m_Region; 101 InputImagePixelType m_IdList; 102 }; 103 104 /** Map from a integer identifier to the level set list image domain. */ 105 using DomainMapType = std::map< IdentifierType, LevelSetDomain >; 106 107 /** Get a map from the identifier for the domains with consistent level set ids 108 * * struct containing an (int, string, etc) identifier and the ImageRegion that 109 * specifies the domain. */ 110 const DomainMapType & GetDomainMap() const; 111 112 protected: 113 LevelSetDomainMapImageFilter(); 114 ~LevelSetDomainMapImageFilter() override = default; 115 116 /** Computes a consistent region for the same set of overlapping 117 * level set support. */ 118 InputImageRegionType ComputeConsistentRegion( const InputImageRegionType & subRegion ) const; 119 120 /** Identify image partitions where each partition has the same overlapping 121 * level set support */ 122 void GenerateData() override; 123 124 /** Display */ 125 void PrintSelf ( std::ostream& os, Indent indent ) const override; 126 127 private: 128 DomainMapType m_DomainMap; 129 130 LevelSetDomainMapImageFilter ( Self& ) = delete; 131 void operator= ( const Self& ) = delete; 132 133 const InputImageType *m_InputImage; 134 OutputImageType *m_OutputImage; 135 }; 136 137 } /* namespace itk */ 138 139 #ifndef ITK_MANUAL_INSTANTIATION 140 #include "itkLevelSetDomainMapImageFilter.hxx" 141 #endif 142 143 #endif 144