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 itkFastMarchingTraits_h
20 #define itkFastMarchingTraits_h
21 
22 #include "itkIntTypes.h"
23 #include "itkVectorContainer.h"
24 #include "itkConceptChecking.h"
25 #include "itkImage.h"
26 #include "itkQuadEdgeMesh.h"
27 #include "itkQuadEdgeMeshToQuadEdgeMeshFilter.h"
28 #include "itkImageToImageFilter.h"
29 #include "itkNodePair.h"
30 
31 namespace itk
32 {
33 /**  \class FastMarchingTraits
34   \brief Base class traits to be used by the FastMarchingBase
35 
36   \tparam TInputDomain Input Domain type (e.g. itk::Image or itk::QuadEdgeMesh)
37   \tparam TNode Node type where the front propagates
38   \tparam TOutputDomain Output Domain type (similar to TInputDomain)
39   \tparam TSuperclass Superclass. When dealing with itk::Image, the Superclass
40   will be itk::ImageToImageFilter; and itk::QuadEdgeMeshToQuadEdgeMeshFilter
41   when dealing with itk::QuadEdgeMesh
42 
43   \ingroup ITKFastMarching
44   */
45 template< typename TInputDomain,
46           typename TNode,
47           typename TOutputDomain,
48           typename TSuperclass >
49 class FastMarchingTraitsBase
50   {
51 public:
52   /** Input Domain Type */
53   using InputDomainType = TInputDomain;
54   using InputDomainPointer = typename InputDomainType::Pointer;
55   using InputPixelType = typename InputDomainType::PixelType;
56 
57   /** Node type */
58   using NodeType = TNode;
59 
60   /** Output Domain Type */
61   using OutputDomainType = TOutputDomain;
62   using OutputDomainPointer = typename OutputDomainType::Pointer;
63   using OutputPixelType = typename OutputDomainType::PixelType;
64 
65   using NodePairType = NodePair< NodeType, OutputPixelType >;
66   using NodePairContainerType = VectorContainer< IdentifierType, NodePairType >;
67   using NodePairContainerPointer = typename NodePairContainerType::Pointer;
68   using NodePairContainerIterator = typename NodePairContainerType::Iterator;
69   using NodePairContainerConstIterator = typename NodePairContainerType::ConstIterator;
70 
71   /*
72   using NodeContainerType = VectorContainer< IdentifierType, NodeType >;
73   using NodeContainerPointer = typename NodeContainerType::Pointer;
74   using NodeContainerIterator = typename NodeContainerType::Iterator;
75   using NodeContainerConstIterator = typename NodeContainerType::ConstIterator;
76   */
77 
78   using SuperclassType = TSuperclass;
79 
80   /** \enum LabelType Fast Marching algorithm nodes types. */
81   enum LabelType {
82     /** \c Far represent far away nodes*/
83     Far = 0,
84     /** \c Alive represent nodes which have already been processed*/
85     Alive,
86     /** \c Trial represent nodes within a narrowband of the propagating front */
87     Trial,
88     /** \c InitialTrial represent nodes from where the propagation is initiated */
89     InitialTrial,
90     /** \c Forbidden represent nodes where the front can not propagate */
91     Forbidden,
92     /** \c Topology represent trial nodes but their inclusion would have
93     violated topology checks. */
94     Topology };
95 
96 #ifdef ITK_USE_CONCEPT_CHECKING
97   itkConceptMacro( DoubleConvertibleOutputCheck,
98                   ( Concept::Convertible< double, OutputPixelType > ) );
99 
100   itkConceptMacro( OutputOStreamWritableCheck,
101                   ( Concept::OStreamWritable< OutputPixelType > ) );
102 #endif
103   };
104 
105 
106 template< typename TInput, typename TOutput >
107 class FastMarchingTraits
108 {
109 };
110 
111 template<unsigned int VDimension,
112          typename TInputPixel,
113          typename TOutputPixel > // = TInputPixel >
114 class FastMarchingTraits<Image<TInputPixel, VDimension>, Image<TOutputPixel, VDimension> > :
115     public FastMarchingTraitsBase<
116       Image< TInputPixel, VDimension >,
117       Index< VDimension >,
118       Image< TOutputPixel, VDimension >,
119       ImageToImageFilter< Image< TInputPixel, VDimension >,
120                           Image< TOutputPixel, VDimension > >
121     >
122   {
123 public:
124   static constexpr unsigned int ImageDimension = VDimension;
125   };
126 
127 
128 template< unsigned int VDimension,
129           typename TInputPixel,
130           typename TInputMeshTraits, //= QuadEdgeMeshTraits< TInputPixel, VDimension, bool, bool >,
131           typename TOutputPixel, //= TInputPixel,
132           class TOutputMeshTraits //= QuadEdgeMeshTraits< TOutputPixel, VDimension, bool, bool >
133          >
134 class FastMarchingTraits<QuadEdgeMesh< TInputPixel, VDimension, TInputMeshTraits >, QuadEdgeMesh< TOutputPixel, VDimension, TOutputMeshTraits > > :
135     public FastMarchingTraitsBase<
136       QuadEdgeMesh< TInputPixel, VDimension, TInputMeshTraits >,
137       typename TInputMeshTraits::PointIdentifier,
138       QuadEdgeMesh< TOutputPixel, VDimension, TOutputMeshTraits >,
139       QuadEdgeMeshToQuadEdgeMeshFilter<
140         QuadEdgeMesh< TInputPixel, VDimension, TInputMeshTraits >,
141         QuadEdgeMesh< TOutputPixel, VDimension, TOutputMeshTraits > >
142     >
143   {
144 public:
145   static constexpr unsigned int PointDimension = VDimension;
146   };
147 
148 }
149 #endif // itkFastMarchingTraits_h
150