ITK  4.13.0
Insight Segmentation and Registration Toolkit
itkNarrowBandImageFilterBase.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 #ifndef itkNarrowBandImageFilterBase_h
19 #define itkNarrowBandImageFilterBase_h
20 
22 #include "itkMultiThreader.h"
23 #include "itkNarrowBand.h"
24 #include "itkBarrier.h"
25 #include "itkObjectStore.h"
26 
27 namespace itk
28 {
67 template< typename TInputImage, typename TOutputImage >
68 class ITK_TEMPLATE_EXPORT NarrowBandImageFilterBase:
69  public FiniteDifferenceImageFilter< TInputImage, TOutputImage >
70 {
71 public:
72 
78 
81 
83  typedef typename Superclass::InputImageType InputImageType;
84  typedef typename Superclass::OutputImageType OutputImageType;
85  typedef typename Superclass::FiniteDifferenceFunctionType FiniteDifferenceFunctionType;
86 
89  itkStaticConstMacro(ImageDimension, unsigned int, Superclass::ImageDimension);
90 
93  typedef typename Superclass::PixelType PixelType;
94 
96  typedef typename Superclass::TimeStepType TimeStepType;
97 
100 
104 
107 
113 
115  itkSetMacro(IsoSurfaceValue, ValueType);
116  itkGetConstMacro(IsoSurfaceValue, ValueType);
118 
120  // itkGetConstMacro( RMSChange, ValueType);
121 
127  {
128  m_NarrowBand->PushBack(node); // add new node
129  this->Modified();
130  }
132 
133  void InsertNarrowBandNode(const IndexType & index)
134  {
135  BandNodeType tmpnode;
136 
137  tmpnode.m_Index = index;
138  m_NarrowBand->PushBack(tmpnode);
139  this->Modified();
140  }
141 
142  void InsertNarrowBandNode(const IndexType & index,
143  const PixelType & value,
144  const signed char & nodestate)
145  {
146  BandNodeType tmpnode;
147 
148  tmpnode.m_Data = value;
149  tmpnode.m_Index = index;
150  tmpnode.m_NodeState = nodestate;
151 
152  m_NarrowBand->PushBack(tmpnode);
153  this->Modified();
154  }
155 
159  void SetNarrowBandTotalRadius(const float& val)
160  {
161  if ( m_NarrowBand->GetTotalRadius() != val )
162  {
163  m_NarrowBand->SetTotalRadius(val);
164  this->Modified();
165  }
166  }
168 
171  {
172  return m_NarrowBand->GetTotalRadius();
173  }
174 
177  void SetNarrowBandInnerRadius(const float& val)
178  {
179  if ( m_NarrowBand->GetInnerRadius() != val )
180  {
181  m_NarrowBand->SetInnerRadius(val);
182  this->Modified();
183  }
184  }
186 
189  {
190  return m_NarrowBand->GetInnerRadius();
191  }
192 
198  virtual void CreateNarrowBand(){}
199 
200  virtual void SetNarrowBand(NarrowBandType *ptr)
201  {
202  if ( m_NarrowBand != ptr )
203  {
204  m_NarrowBand = ptr;
205  this->Modified();
206  }
207  }
208 
209  virtual void CopyInputToOutput() ITK_OVERRIDE;
210 
211 protected:
213  {
214  m_NarrowBand = NarrowBandType::New();
215  m_NarrowBand->SetTotalRadius(4);
216  m_NarrowBand->SetInnerRadius(2);
217  m_ReinitializationFrequency = 6;
218  m_IsoSurfaceValue = 0.0;
219  m_Step = 0;
220  m_Touched = false;
221  m_Barrier = Barrier::New();
222  }
223 
224  virtual ~NarrowBandImageFilterBase() ITK_OVERRIDE {}
225  void PrintSelf(std::ostream & os, Indent indent) const ITK_OVERRIDE;
226 
228 
233 
236 
239  };
240 
243  std::vector< RegionType > m_RegionList;
244 
247  void GetSplitRegion(const size_t& i, ThreadRegionType & splitRegion);
248 
253  virtual void Initialize() ITK_OVERRIDE;
254 
259  virtual void InitializeIteration() ITK_OVERRIDE;
260 
263  virtual void PostProcessOutput() ITK_OVERRIDE;
264 
265  /* This function clears all pixels from the narrow band */
266  void ClearNarrowBand();
267 
269  void WaitForAll();
270 
274  virtual void GenerateData() ITK_OVERRIDE;
275 
276  /* Variables to control reinitialization */
277  IdentifierType m_ReinitializationFrequency;
279 
280  bool m_Touched;
281 
282  std::vector< bool > m_TouchedForThread;
283 
284  ValueType m_IsoSurfaceValue;
285 
286  typename Barrier::Pointer m_Barrier;
287 
288 private:
289  ITK_DISALLOW_COPY_AND_ASSIGN(NarrowBandImageFilterBase);
290 
294  NarrowBandImageFilterBase *Filter;
296  std::vector< TimeStepType > TimeStepList;
297  std::vector< bool > ValidTimeStepList;
298  };
299 
300  /* This class does not use AllocateUpdateBuffer to allocate memory for its
301  * narrow band. This is taken care of in SetNarrowBand, and InsertNarrowBandNode
302  * functions. This function is here for compatibility with the
303  * FiniteDifferenceSolver framework.
304  */
305  virtual void AllocateUpdateBuffer() ITK_OVERRIDE {}
306 
308  static ITK_THREAD_RETURN_TYPE IterateThreaderCallback(void *arg);
309 
313  virtual void ThreadedIterate(void *arg, ThreadIdType threadId);
314 
318  virtual void ThreadedApplyUpdate(const TimeStepType& dt,
319  const ThreadRegionType & regionToProcess,
320  ThreadIdType threadId);
321 
322  virtual void ApplyUpdate(const TimeStepType&) ITK_OVERRIDE {}
323 
327  virtual TimeStepType ThreadedCalculateChange(const ThreadRegionType & regionToProcess,
328  ThreadIdType threadId);
329 
330  virtual TimeStepType CalculateChange() ITK_OVERRIDE { return 0; }
331 };
332 } // end namespace itk
333 
334 #ifndef ITK_MANUAL_INSTANTIATION
335 #include "itkNarrowBandImageFilterBase.hxx"
336 #endif
337 
338 #endif
virtual void ApplyUpdate(const TimeStepType &) override
virtual void SetNarrowBand(NarrowBandType *ptr)
Superclass::InputImageType InputImageType
TDataType m_Data
Definition: itkNarrowBand.h:38
TPixel ValueType
Definition: itkImage.h:96
#define ITK_THREAD_RETURN_TYPE
Superclass::FiniteDifferenceFunctionType FiniteDifferenceFunctionType
void InsertNarrowBandNode(const BandNodeType &node)
SizeValueType IdentifierType
Definition: itkIntTypes.h:147
FiniteDifferenceImageFilter< TInputImage, TOutputImage > Superclass
void InsertNarrowBandNode(const IndexType &index, const PixelType &value, const signed char &nodestate)
NodeContainerType::iterator Iterator
Definition: itkNarrowBand.h:69
void InsertNarrowBandNode(const IndexType &index)
signed char m_NodeState
Definition: itkNarrowBand.h:40
Narrow Band class.
Definition: itkNarrowBand.h:51
unsigned int ThreadIdType
Definition: itkIntTypes.h:159
TIndexType m_Index
Definition: itkNarrowBand.h:39
FiniteDifferenceFunctionType::TimeStepType TimeStepType
This class implements a multi-threaded finite difference image to image solver that can be applied to...
Base class for filters that take an image as input and produce an image as output.
Control indentation during Print() invocation.
Definition: itkIndent.h:49
static Pointer New()
virtual TimeStepType CalculateChange() override
Superclass::OutputImageType OutputImageType
BandNode< IndexType, PixelType > BandNodeType
Standard barrier class implementation for synchronizing the execution of threads. ...
Definition: itkBarrier.h:41