Shapeworks Studio  2.1
Shape analysis software suite
itkPSMContainer.h
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 __itkPSMContainer_h
19 #define __itkPSMContainer_h
20 
21 #include "itkDataObject.h"
22 #include "itkPoint.h"
23 #include "itkWeakPointer.h"
24 #include "itkCommand.h"
25 #include "itkPSMAttribute.h"
26 #include <map>
27 
28 namespace itk
29 {
41 template <class T>
42 class ITK_EXPORT PSMContainer : public DataObject
43 {
44 public:
46  typedef T DataType;
47  typedef PSMContainer Self;
48  typedef DataObject Superclass;
49  typedef SmartPointer<Self> Pointer;
50  typedef SmartPointer<const Self> ConstPointer;
51  typedef WeakPointer<const Self> ConstWeakPointer;
52 
54  itkNewMacro(Self);
55 
57  itkTypeMacro(PSMContainer, DataObject);
58 
62  struct ltcmp
63  {
64  inline bool operator()(unsigned int a, unsigned int b) const
65  { return a < b; }
66  };
67 
69  typedef std::map<unsigned int, T, ltcmp> MapType;
70 
73  class ConstIterator : public MapType::const_iterator
74  {
75  public:
76  typedef typename MapType::const_iterator Superclass;
77  ConstIterator( const typename MapType::const_iterator &o) : Superclass(o) {}
78  ConstIterator() : Superclass() {}
79 
80  inline const T &operator*() const
81  { return Superclass::operator*().second; }
82  inline unsigned long int GetIndex() const
83  { return Superclass::operator*().first; }
84  };
85 
88  class Iterator : public MapType::iterator
89  {
90  public:
91  typedef typename MapType::iterator Superclass;
92  Iterator( const typename MapType::iterator &o) : Superclass(o) {}
93  Iterator() : Superclass() {}
94 
95  inline T &operator*() const
96  { return Superclass::operator*().second; }
97 
98  inline unsigned long int GetIndex() const
99  { return Superclass::operator*().first; }
100  };
101 
103  inline ConstIterator GetBegin() const
104  { return ConstIterator( m_Map.begin()); }
105  inline ConstIterator GetEnd() const
106  { return ConstIterator( m_Map.end()); }
107 
109  inline typename MapType::const_iterator GetMapBegin() const
110  { return m_Map.begin(); }
111  inline typename MapType::const_iterator GetMapEnd() const
112  { return m_Map.end(); }
113  inline typename MapType::iterator GetMapBegin()
114  { return m_Map.begin(); }
115  inline typename MapType::iterator GetMapEnd()
116  { return m_Map.end(); }
117 
120  inline T &operator[](const unsigned long int &k) { return m_Map[k]; }
121  inline const T&operator[](const unsigned long int &k) const { return m_Map[k]; }
122 
124  bool HasIndex(unsigned long int k) const
125  {
126  if ( m_Map.find(k) != m_Map.end()) return true;
127  else return false;
128  }
129 
131  unsigned long int GetSize() const { return m_Map.size(); }
132 
135  typename MapType::size_type Erase( const unsigned int &k )
136  { return m_Map.erase(k); }
137 
138 protected:
139  PSMContainer() { }
140  void PrintSelf(std::ostream& os, Indent indent) const
141  {
142  Superclass::PrintSelf(os,indent);
143 
144  os << indent << "PSMContainer: " << std::endl;
145  // for (typename MapType::const_iterator it= this->GetMapBegin();
146  // it != this->GetMapEnd(); it++)
147  // { os << it->first << " " << it->second << std::endl; }
148  }
149  virtual ~PSMContainer() {};
150 
151  private:
152  PSMContainer(const Self&); //purposely not implemented
153  void operator=(const Self&); //purposely not implemented
154 
156  MapType m_Map;
157 };
158 
159 } // end namespace itk
160 
161 #endif
MapType::size_type Erase(const unsigned int &k)
bool HasIndex(unsigned long int k) const
ConstIterator GetBegin() const
unsigned long int GetSize() const
MapType::const_iterator GetMapBegin() const
T & operator[](const unsigned long int &k)
A container class that holds particle position information for the PSMParticleSystem class...
std::map< unsigned int, T, ltcmp > MapType