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 #ifndef itkFastMarchingExtensionImageFilterBase_h
19 #define itkFastMarchingExtensionImageFilterBase_h
20 
21 #include "itkFastMarchingImageFilterBase.h"
22 #include "itkVectorContainer.h"
23 
24 namespace itk
25 {
26 /** \class FastMarchingExtensionImageFilterBase
27  * \brief Extend auxiliary variables smoothly using Fast Marching.
28  *
29  * Fast marching can be used to extend auxiliary variables smoothly
30  * from the zero level set. Starting from an initial position on the
31  * front, this class simultaneously calculate the signed distance and
32  * extend a set of auxiliary values.
33  *
34  * This class is templated over the level set image type, the auxiliary
35  * variable type and the number of auxiliary variables to extended. The initial
36  * front is specified by two containers: one containing the known points
37  * and one containing the trial points. The auxiliary variables on the front
38  * are represented by two auxiliary variable containers: one containing
39  * the value of the variables at the know points and on containing the
40  * value of the variables at the trail points.
41  *
42  * Implementation of this class is based on Chapter 11 of
43  * "Level Set Methods and Fast Marching Methods", J.A. Sethian,
44  * Cambridge Press, Second edition, 1999.
45  *
46  * For an alternative implementation, see itk::FastMarchingExtensionImageFilter.
47  *
48  * \sa FastMarchingExtensionImageFilter
49  * \sa FastMarchingImageFilter
50  * \sa LevelSetTypeDefault
51  * \sa AuxVarTypeDefault
52  *
53  * \ingroup LevelSetSegmentation
54  * \ingroup ITKFastMarching
55  */
56 template< typename TInput, typename TOutput,
57          typename TAuxValue,
58          unsigned int VAuxDimension >
59 class ITK_TEMPLATE_EXPORT FastMarchingExtensionImageFilterBase:
60   public FastMarchingImageFilterBase< TInput, TOutput >
61 {
62 public:
63   ITK_DISALLOW_COPY_AND_ASSIGN(FastMarchingExtensionImageFilterBase);
64 
65   /** Standard class typdedefs. */
66   using Self = FastMarchingExtensionImageFilterBase;
67   using Superclass = FastMarchingImageFilterBase< TInput, TOutput >;
68   using Pointer = SmartPointer< Self >;
69   using ConstPointer = SmartPointer< const Self >;
70   using Traits = typename Superclass::Traits;
71 
72   /** Method for creation through the object factory. */
73   itkNewMacro(Self);
74 
75   /** Run-time type information (and related methods). */
76   itkTypeMacro(FastMarchingExtensionImageFilterBase,
77                FastMarchingImageFilterBase);
78 
79   /** The dimension of the level set. */
80   static constexpr unsigned int ImageDimension = Superclass::ImageDimension;
81 
82   /** Number of auxiliary variables to be extended. */
83   static constexpr unsigned int AuxDimension = VAuxDimension;
84 
85   /** AuxVarType type alias support */
86   using AuxValueType = TAuxValue;
87   using AuxValueVectorType = Vector< AuxValueType, AuxDimension >;
88   using AuxValueContainerType = VectorContainer< IdentifierType, AuxValueVectorType >;
89 
90   using AuxValueContainerPointer = typename AuxValueContainerType::Pointer;
91   using AuxValueContainerConstIterator = typename AuxValueContainerType::ConstIterator;
92 
93   using AuxImageType = Image< AuxValueType, ImageDimension >;
94   using AuxImagePointer = typename AuxImageType::Pointer;
95 
96 
97   /** Index type alias support */
98   using NodeType = typename Superclass::NodeType;
99   using NodePairType = typename Superclass::NodePairType;
100 
101 //  using NodeContainerType = typename Superclass::NodeContainerType;
102 //  using NodeContainerPointer = typename Superclass::NodeContainerPointer;
103 //  using NodeContainerConstIterator = typename Superclass::NodeContainerConstIterator;
104 
105   using NodePairContainerType = typename Superclass::NodePairContainerType;
106   using NodePairContainerPointer = typename Superclass::NodePairContainerPointer;
107   using NodePairContainerConstIterator = typename Superclass::NodePairContainerConstIterator;
108 
109   using OutputImageType = typename Superclass::OutputImageType;
110   using OutputPixelType = typename Superclass::OutputPixelType;
111   using InternalNodeStructure = typename Superclass::InternalNodeStructure;
112 
113   /** Get one of the extended auxiliary variable image. */
114   AuxImageType * GetAuxiliaryImage( const unsigned int& idx );
115 
116   /** Set the container auxiliary values at the initial alive points. */
117   itkSetObjectMacro(AuxiliaryAliveValues, AuxValueContainerType );
118   itkGetModifiableObjectMacro(AuxiliaryAliveValues, AuxValueContainerType );
119 
120   /** Set the container of auxiliary values at the initial trial points. */
121   itkSetObjectMacro(AuxiliaryTrialValues, AuxValueContainerType );
122   itkGetModifiableObjectMacro(AuxiliaryTrialValues, AuxValueContainerType );
123 
124 #ifdef ITK_USE_CONCEPT_CHECKING
125   // Begin concept checking
126   itkConceptMacro( AuxValueHasNumericTraitsCheck,
127                    ( Concept::HasNumericTraits< TAuxValue > ) );
128   // End concept checking
129 #endif
130 
131 protected:
132   FastMarchingExtensionImageFilterBase();
133   ~FastMarchingExtensionImageFilterBase() override = default;
134   void PrintSelf(std::ostream & os, Indent indent) const override;
135 
136   void InitializeOutput(OutputImageType *) override;
137 
138   void UpdateValue( OutputImageType* oImage, const NodeType& iValue ) override;
139 
140   /** Generate the output image meta information */
141   void GenerateOutputInformation() override;
142 
143   void EnlargeOutputRequestedRegion(DataObject *output) override;
144 
145   AuxValueContainerPointer m_AuxiliaryAliveValues;
146   AuxValueContainerPointer m_AuxiliaryTrialValues;
147 
148 private:
149   AuxImageType * m_AuxImages[VAuxDimension];
150 };
151 } // namespace itk
152 
153 #ifndef ITK_MANUAL_INSTANTIATION
154 #include "itkFastMarchingExtensionImageFilterBase.hxx"
155 #endif
156 
157 #endif
158