ITK  5.0.0
Insight Segmentation and Registration Toolkit
itkMultipleImageIterator.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 itkMultipleImageIterator_h
20 #define itkMultipleImageIterator_h
21 #include <vector>
22 #include <itkImageRegionIterator.h>
23 
24 
25 namespace itk {
32 template<typename TIterator>
34 public:
36  using IteratorType = TIterator;
37  using ImageType = typename IteratorType::ImageType;
39  IteratorType& operator[](const int i) {return m_Iterators[i];}
41  void AddIterator(const IteratorType& it) {m_Iterators.push_back(it);}
44  for (auto it = m_Iterators.begin();
45  it != m_Iterators.end(); ++it) {
46  ++(*it);
47  }
48  return *this;
49  }
51  void GoToBegin() {
52  for (auto it = m_Iterators.begin();
53  it != m_Iterators.end(); ++it) {
54  it->GoToBegin();
55  }
56  }
60  bool IsAtEnd() {
61 #ifdef NDEBUG
62  return m_Iterators[0].IsAtEnd();
63 #else
64  assert(m_Iterators.size());
65  bool retval = m_Iterators[0].IsAtEnd();
66  for (unsigned int i=0; i<m_Iterators.size();++i)
67  assert(m_Iterators[i].IsAtEnd() == retval);
68  return retval;
69 #endif
70  }
72  unsigned int Size () const { return m_Iterators.size(); }
73 protected:
74  std::vector<IteratorType> m_Iterators;
76 
77 };
78 }
79 #endif //itkMultipleImageIterator_h
Self & operator++()
Advance all iterators.
typename IteratorType::ImageType ImageType
unsigned int Size() const
Returns the number of iterators.
void AddIterator(const IteratorType &it)
Add a new iterator.
IteratorType & operator[](const int i)
Access one of the iterators.
std::vector< IteratorType > m_Iterators
An wrapper around image iterators to iterate over several images simultaneously All iterators must...
void GoToBegin()
Rewind all iterators.