ITK  5.0.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:
48  ITK_DISALLOW_COPY_AND_ASSIGN(ImportImageContainer);
49 
52  using Superclass = Object;
55 
57  using ElementIdentifier = TElementIdentifier;
58  using Element = TElement;
59 
61  itkNewMacro(Self);
62 
64  itkTypeMacro(ImportImageContainer, Object);
65 
67  TElement * GetImportPointer() { return m_ImportPointer; }
68 
75  void SetImportPointer(TElement *ptr, TElementIdentifier num,
76  bool LetContainerManageMemory = false);
77 
79  TElement & operator[](const ElementIdentifier id)
80  { return m_ImportPointer[id]; }
81 
83  const TElement & operator[](const ElementIdentifier id) const
84  { return m_ImportPointer[id]; }
85 
88  TElement * GetBufferPointer()
89  { return m_ImportPointer; }
90 
93  { return m_Capacity; }
94 
97  { return m_Size; }
98 
114  void Reserve(ElementIdentifier num, const bool UseDefaultConstructor = false);
115 
122  void Squeeze();
123 
125  void Initialize();
126 
136  itkSetMacro(ContainerManageMemory, bool);
137  itkGetConstMacro(ContainerManageMemory, bool);
138  itkBooleanMacro(ContainerManageMemory);
140 
141 protected:
143  ~ImportImageContainer() override;
144 
148  void PrintSelf(std::ostream & os, Indent indent) const override;
149 
155  virtual TElement * AllocateElements(ElementIdentifier size, bool UseDefaultConstructor = false) const;
156 
157  virtual void DeallocateManagedMemory();
158 
159  /* Set the m_Size member that represents the number of elements
160  * currently stored in the container. Use this function with great
161  * care since it only changes the m_Size member and not the actual size
162  * of the import pointer m_ImportPointer. It should typically
163  * be used only to override AllocateElements and
164  * DeallocateManagedMemory. */
165  itkSetMacro(Size, TElementIdentifier);
166 
167  /* Set the m_Capacity member that represents the capacity of
168  * the current container. Use this function with great care
169  * since it only changes the m_Capacity member and not the actual
170  * capacity of the import pointer m_ImportPointer. It should typically
171  * be used only to override AllocateElements and
172  * DeallocateManagedMemory. */
173  itkSetMacro(Capacity, TElementIdentifier);
174 
175  /* Set the m_ImportPointer member. Use this function with great care
176  * since it only changes the m_ImportPointer member but not the m_Size
177  * and m_Capacity members. It should typically be used only to override
178  * AllocateElements and DeallocateManagedMemory. */
179  void SetImportPointer(TElement *ptr){ m_ImportPointer = ptr; }
180 
181 private:
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)
void SetImportPointer(TElement *ptr)
const TElement & operator[](const ElementIdentifier id) const
Represent a n-dimensional size (bounds) of a n-dimensional image.
Definition: itkSize.h:68
TElementIdentifier ElementIdentifier
Control indentation during Print() invocation.
Definition: itkIndent.h:49
ElementIdentifier Size() const
Base class for most ITK classes.
Definition: itkObject.h:60
Defines an itk::Image front-end to a standard C-array.
ElementIdentifier Capacity() const