ITK  4.3.0
Insight Segmentation and Registration Toolkit
itkLevelSetEquationTermContainer.h
Go to the documentation of this file.
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 __itkLevelSetEquationTermContainer_h
20 #define __itkLevelSetEquationTermContainer_h
21 
23 #include "itkObject.h"
24 
25 #include "itksys/hash_map.hxx"
26 
27 #include <map>
28 #include <string>
29 
30 namespace itk
31 {
41 template< class TInputImage,
42  class TLevelSetContainer >
44 {
45 public:
49  typedef Object Superclass;
50 
52  itkNewMacro( Self );
53 
55  itkTypeMacro( LevelSetEquationTermContainer,
56  Object );
57 
58  typedef unsigned int TermIdType;
59 
60  typedef TInputImage InputImageType;
61  typedef typename InputImageType::Pointer InputImagePointer;
62 
63  typedef TLevelSetContainer LevelSetContainerType;
64  typedef typename LevelSetContainerType::Pointer LevelSetContainerPointer;
65 
66  typedef typename LevelSetContainerType::LevelSetType LevelSetType;
67  typedef typename LevelSetContainerType::LevelSetPointer LevelSetPointer;
68 
69  typedef typename LevelSetContainerType::LevelSetIdentifierType
71  typedef typename LevelSetContainerType::OutputType LevelSetOutputPixelType;
72  typedef typename LevelSetContainerType::OutputRealType LevelSetOutputRealType;
73  typedef typename LevelSetContainerType::LevelSetDataType LevelSetDataType;
74  typedef typename LevelSetContainerType::InputIndexType LevelSetInputIndexType;
75  typedef typename LevelSetContainerType::GradientType LevelSetGradientType;
76  typedef typename LevelSetContainerType::HessianType LevelSetHessianType;
77 
80  typedef typename TermType::Pointer TermPointer;
81 
83  itkSetObjectMacro( Input, InputImageType );
84  itkGetObjectMacro( Input, InputImageType );
86 
87  itkSetMacro( CurrentLevelSetId, LevelSetIdentifierType );
88  itkGetMacro( CurrentLevelSetId, LevelSetIdentifierType );
89 
90  itkSetObjectMacro( LevelSetContainer, LevelSetContainerType );
91  itkGetObjectMacro( LevelSetContainer, LevelSetContainerType );
92 
94  void PushTerm( TermType* iTerm );
95 
97  void AddTerm( const TermIdType& iId, TermType* iTerm );
98 
100  TermType* GetTerm( const TermIdType& iId );
101 
103  TermType* GetTerm( const std::string& iName );
104 
106  void Initialize( const LevelSetInputIndexType& iP );
107 
109  void UpdatePixel( const LevelSetInputIndexType& iP,
110  const LevelSetOutputRealType & oldValue,
111  const LevelSetOutputRealType & newValue );
112 
114  void InitializeParameters();
115 
118 
120  const LevelSetDataType& iData );
121 
123  void Update();
124 
127 
129  LevelSetDataType& ioData );
130 
131 protected:
132 
133  typedef std::map< TermIdType, TermPointer > MapTermContainerType;
134  typedef typename MapTermContainerType::iterator MapTermContainerIteratorType;
135  typedef typename MapTermContainerType::const_iterator MapTermContainerConstIteratorType;
136 
137 public:
138  class Iterator;
139  friend class Iterator;
140 
142  {
143  public:
147  ConstIterator( const Iterator& it ) : m_Iterator( it.m_Iterator ) {}
148  ConstIterator & operator * () { return *this; }
149  ConstIterator * operator->() { return this; }
151  {
152  ++m_Iterator;
153  return *this;
154  }
156  {
157  ConstIterator tmp( *this );
158  ++(*this);
159  return tmp;
160  }
162  {
163  --m_Iterator;
164  return *this;
165  }
167  {
168  ConstIterator tmp( *this );
169  --(*this);
170  return tmp;
171  }
172  bool operator == (const Iterator& it) const
173  {
174  return (m_Iterator == it.m_Iterator);
175  }
176  bool operator != (const Iterator& it) const
177  {
178  return (m_Iterator != it.m_Iterator);
179  }
180  bool operator == (const ConstIterator& it) const
181  {
182  return (m_Iterator == it.m_Iterator);
183  }
184  bool operator != (const ConstIterator& it) const
185  {
186  return (m_Iterator != it.m_Iterator);
187  }
189  {
190  return m_Iterator->first;
191  }
192 
193  TermType * GetTerm() const
194  {
195  return m_Iterator->second;
196  }
197  private:
199  friend class Iterator;
200  };
201 
202  class Iterator
203  {
204  public:
205  Iterator() {}
207  Iterator( const ConstIterator& it ) : m_Iterator( it.m_Iterator ) {}
209 
210  Iterator & operator * () { return *this; }
211  Iterator * operator ->() { return this; }
212 
214  {
215  ++m_Iterator;
216  return *this;
217  }
219  {
220  Iterator tmp( *this );
221  ++(*this);
222  return tmp;
223  }
225  {
226  --m_Iterator;
227  return *this;
228  }
230  {
231  Iterator tmp( *this );
232  --(*this);
233  return tmp;
234  }
235 
236  bool operator==(const Iterator& it) const
237  {
238  return (m_Iterator==it.m_Iterator);
239  }
240  bool operator!=(const Iterator& it) const
241  {
242  return (m_Iterator!=it.m_Iterator);
243  }
244  bool operator==(const ConstIterator& it)const
245  {
246  return (m_Iterator == it.m_Iterator);
247  }
248  bool operator!=(const ConstIterator& it)const
249  {
250  return (m_Iterator != it.m_Iterator);
251  }
253  {
254  return m_Iterator->first;
255  }
256 
257  TermType * GetTerm() const
258  {
259  return m_Iterator->second;
260  }
261  private:
263  friend class ConstIterator;
264  };
265 
266  Iterator Begin();
267  Iterator End();
268 
269  ConstIterator Begin() const;
270  ConstIterator End() const;
271 
272 protected:
274 
276 
279 
281 
282  typedef itksys::hash_map< std::string, TermPointer > HashMapStringTermContainerType;
283 
285 
288 
290 
291  typedef std::map< TermIdType, LevelSetOutputRealType > MapCFLContainerType;
292  typedef typename MapCFLContainerType::iterator MapCFLContainerIterator;
293  typedef typename MapCFLContainerType::const_iterator MapCFLContainerConstIterator;
294 
296 
297 private:
299  void operator = ( const Self& );
300 };
301 
302 }
303 #ifndef ITK_MANUAL_INSTANTIATION
304 #include "itkLevelSetEquationTermContainer.hxx"
305 #endif
306 
307 #endif // __itkLevelSetEquationTermContainer_h
308