File: LayerIterator.h

package info (click to toggle)
itksnap 3.6.0-5
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 22,132 kB
  • sloc: cpp: 91,089; ansic: 1,994; sh: 327; makefile: 16
file content (99 lines) | stat: -rw-r--r-- 2,564 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#ifndef LAYERITERATOR_H
#define LAYERITERATOR_H

#include "SNAPCommon.h"
#include <map>
#include <vector>

class GenericImageData;
class ImageWrapperBase;
class ScalarImageWrapperBase;
class VectorImageWrapperBase;

/**
 * An iterator for moving through layers in the GenericImageData class
 */
class LayerIterator
{
public:

  LayerIterator(GenericImageData *data, int role_filter = ALL_ROLES);

  bool IsAtEnd() const;

  // Move to the end
  LayerIterator &MoveToBegin();

  // Move to the end
  LayerIterator &MoveToEnd();

  // Move to a specific layer, or end if the layer is not found
  LayerIterator &Find(ImageWrapperBase *value);

  LayerIterator &Find(unsigned long layer_id);

  LayerIterator & operator++();

  LayerIterator & operator+=(int k);

  /** Get the layer being pointed to */
  ImageWrapperBase *GetLayer() const;

  /** Get the layer being pointed to, cast as Scalar (or NULL) */
  ScalarImageWrapperBase *GetLayerAsScalar() const;

  /** Get the layer being pointed to, cast as Gray (or NULL) */
  VectorImageWrapperBase *GetLayerAsVector() const;

  /** Get the role of the current layer */
  LayerRole GetRole() const;

  /** Get the position of the current layer within its role */
  int GetPositionInRole() const;

  /** Get the number of layers in the role of current layer */
  int GetNumberOfLayersInRole();

  /** Check if this is the first/last layer in its role */
  bool IsFirstInRole() const;
  bool IsLastInRole() const;

  void Print(const char *) const;

  /** Compare two iterators */
  bool operator == (const LayerIterator &it);
  bool operator != (const LayerIterator &it);

private:

  typedef std::vector<SmartPtr<ImageWrapperBase> > WrapperList;
  typedef WrapperList::const_iterator WrapperListIterator;

  typedef std::map<LayerRole, WrapperList> WrapperRoleMap;
  typedef WrapperRoleMap::iterator WrapperRoleIterator;

  // Pointer to the parent data
  GenericImageData *m_ImageData;

  // The filter defining which roles to iterate
  int m_RoleFilter;

  // A pair of iterators that define the state of this iterator
  WrapperRoleIterator m_RoleIter;
  WrapperListIterator m_WrapperInRoleIter;

  // Internal method that advances the internal iterators by one step,
  // regardless of whether that makes the iterator point to a valid layer
  // or not
  void MoveToNextTrialPosition();

  // Check if the iterator is pointing to a valid layer
  bool IsPointingToListableLayer() const;

  // Default names for wrappers
  static std::map<LayerRole, std::string> m_RoleDefaultNames;
};



#endif // LAYERITERATOR_H