ITK  4.13.0
Insight Segmentation and Registration Toolkit
itkImportImageContainer.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 itkImportImageContainer_h
19 #define itkImportImageContainer_h
20 
21 #include "itkObject.h"
22 #include "itkObjectFactory.h"
23 #include <utility>
24 
25 namespace itk
26 {
44 template< typename TElementIdentifier, typename TElement >
45 class ITK_TEMPLATE_EXPORT ImportImageContainer:public Object
46 {
47 public:
50  typedef Object Superclass;
53 
55  typedef TElementIdentifier ElementIdentifier;
56  typedef TElement Element;
57 
59  itkNewMacro(Self);
60 
62  itkTypeMacro(ImportImageContainer, Object);
63 
65  TElement * GetImportPointer() { return m_ImportPointer; }
66 
73  void SetImportPointer(TElement *ptr, TElementIdentifier num,
74  bool LetContainerManageMemory = false);
75 
77  TElement & operator[](const ElementIdentifier id)
78  { return m_ImportPointer[id]; }
79 
81  const TElement & operator[](const ElementIdentifier id) const
82  { return m_ImportPointer[id]; }
83 
86  TElement * GetBufferPointer()
87  { return m_ImportPointer; }
88 
91  { return m_Capacity; }
92 
94  ElementIdentifier Size(void) const
95  { return m_Size; }
96 
112  void Reserve(ElementIdentifier num, const bool UseDefaultConstructor = false);
113 
120  void Squeeze();
121 
123  void Initialize();
124 
134  itkSetMacro(ContainerManageMemory, bool);
135  itkGetConstMacro(ContainerManageMemory, bool);
136  itkBooleanMacro(ContainerManageMemory);
138 
139 protected:
141  virtual ~ImportImageContainer() ITK_OVERRIDE;
142 
146  virtual void PrintSelf(std::ostream & os, Indent indent) const ITK_OVERRIDE;
147 
153  virtual TElement * AllocateElements(ElementIdentifier size, bool UseDefaultConstructor = false) const;
154 
155  virtual void DeallocateManagedMemory();
156 
157  /* Set the m_Size member that represents the number of elements
158  * currently stored in the container. Use this function with great
159  * care since it only changes the m_Size member and not the actual size
160  * of the import pointer m_ImportPointer. It should typically
161  * be used only to override AllocateElements and
162  * DeallocateManagedMemory. */
163  itkSetMacro(Size, TElementIdentifier);
164 
165  /* Set the m_Capacity member that represents the capacity of
166  * the current container. Use this function with great care
167  * since it only changes the m_Capacity member and not the actual
168  * capacity of the import pointer m_ImportPointer. It should typically
169  * be used only to override AllocateElements and
170  * DeallocateManagedMemory. */
171  itkSetMacro(Capacity, TElementIdentifier);
172 
173  /* Set the m_ImportPointer member. Use this function with great care
174  * since it only changes the m_ImportPointer member but not the m_Size
175  * and m_Capacity members. It should typically be used only to override
176  * AllocateElements and DeallocateManagedMemory. */
177  void SetImportPointer(TElement *ptr){ m_ImportPointer = ptr; }
178 
179 private:
180  ITK_DISALLOW_COPY_AND_ASSIGN(ImportImageContainer);
181 
182  TElement * m_ImportPointer;
183  TElementIdentifier m_Size;
184  TElementIdentifier m_Capacity;
186 };
187 } // end namespace itk
188 
189 #ifndef ITK_MANUAL_INSTANTIATION
190 #include "itkImportImageContainer.hxx"
191 #endif
192 
193 #endif
TElement & operator[](const ElementIdentifier id)
SmartPointer< const Self > ConstPointer
Represent the size (bounds) of a n-dimensional image.
Definition: itkSize.h:52
ElementIdentifier Capacity(void) const
const TElement & operator[](const ElementIdentifier id) const
ElementIdentifier Size(void) const
Control indentation during Print() invocation.
Definition: itkIndent.h:49
Base class for most ITK classes.
Definition: itkObject.h:59
Defines an itk::Image front-end to a standard C-array.
TElementIdentifier ElementIdentifier