| 1 |
|
/*========================================================================= |
| 2 |
|
|
| 3 |
|
Program: Insight Segmentation & Registration Toolkit |
| 4 |
|
Module: $RCSfile: itkImportImageContainer.h.html,v $ |
| 5 |
|
Language: C++ |
| 6 |
|
Date: $Date: 2006/01/17 19:15:40 $ |
| 7 |
|
Version: $Revision: 1.4 $ |
| 8 |
|
|
| 9 |
|
Copyright (c) Insight Software Consortium. All rights reserved. |
| 10 |
|
See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details. |
| 11 |
|
|
| 12 |
|
This software is distributed WITHOUT ANY WARRANTY; without even |
| 13 |
|
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 14 |
|
PURPOSE. See the above copyright notices for more information. |
| 15 |
|
|
| 16 |
|
=========================================================================*/ |
| 17 |
|
#ifndef __itkImportImageContainer_h |
| 18 |
|
#define __itkImportImageContainer_h |
| 19 |
|
|
| 20 |
|
#include "itkObject.h" |
| 21 |
|
#include "itkObjectFactory.h" |
| 22 |
|
#include <utility> |
| 23 |
|
|
| 24 |
|
namespace itk |
| 25 |
|
{ |
| 26 |
|
|
| 27 |
|
/** \class ImportImageContainer |
| 28 |
|
* Defines an itk::Image front-end to a standard C-array. This container |
| 29 |
|
* conforms to the ImageContainerInterface. This is a full-fleged Object, |
| 30 |
|
* so there is modification time, debug, and reference count information. |
| 31 |
|
* |
| 32 |
|
* Template parameters for ImportImageContainer: |
| 33 |
|
* |
| 34 |
|
* TElementIdentifier = |
| 35 |
|
* An INTEGRAL type for use in indexing the imported buffer. |
| 36 |
|
* |
| 37 |
|
* TElement = |
| 38 |
|
* The element type stored in the container. |
| 39 |
|
* |
| 40 |
|
* \ingroup ImageObjects |
| 41 |
|
* \ingroup IOFilters |
| 42 |
|
*/ |
| 43 |
|
|
| 44 |
|
template <typename TElementIdentifier, typename TElement> |
| 45 |
|
class ImportImageContainer: public Object |
| 46 |
|
{ |
| 47 |
|
public: |
| 48 |
|
/** Standard class typedefs. */ |
| 49 |
|
typedef ImportImageContainer Self; |
| 50 |
TDA |
typedef Object Superclass; |
| 51 |
TDA |
typedef SmartPointer<Self> Pointer; |
| 52 |
TDA |
typedef SmartPointer<const Self> ConstPointer; |
| 53 |
|
|
| 54 |
|
/** Save the template parameters. */ |
| 55 |
|
typedef TElementIdentifier ElementIdentifier; |
| 56 |
|
typedef TElement Element; |
| 57 |
|
|
| 58 |
|
/** Method for creation through the object factory. */ |
| 59 |
|
itkNewMacro(Self); |
| 60 |
|
|
| 61 |
|
/** Standard part of every itk Object. */ |
| 62 |
|
itkTypeMacro(ImportImageContainer, Object); |
| 63 |
|
|
| 64 |
|
/** Get the pointer from which the image data is imported. */ |
| 65 |
|
TElement *GetImportPointer() {return m_ImportPointer;}; |
| 66 |
|
|
| 67 |
|
/** Set the pointer from which the image data is imported. "num" is |
| 68 |
|
* the number of pixels in the block of memory. If |
| 69 |
|
* "LetContainerManageMemory" is false, then the application retains |
| 70 |
|
* the responsibility of freeing the memory for this image data. If |
| 71 |
|
* "LetContainerManageMemory" is true, then this class will free the |
| 72 |
|
* memory when this object is destroyed. */ |
| 73 |
|
void SetImportPointer(TElement *ptr, TElementIdentifier num, |
| 74 |
|
bool LetContainerManageMemory = false); |
| 75 |
|
|
| 76 |
|
/** Index operator. This version can be an lvalue. */ |
| 77 |
|
TElement & operator[](const ElementIdentifier id) |
| 78 |
|
{ return m_ImportPointer[id]; }; |
| 79 |
|
|
| 80 |
|
/** Index operator. This version can only be an rvalue */ |
| 81 |
|
const TElement & operator[](const ElementIdentifier id) const |
| 82 |
|
{ return m_ImportPointer[id]; }; |
| 83 |
|
|
| 84 |
|
/** Return a pointer to the beginning of the buffer. This is used by |
| 85 |
|
* the image iterator class. */ |
| 86 |
|
TElement *GetBufferPointer() |
| 87 |
|
{ return m_ImportPointer; }; |
| 88 |
|
|
| 89 |
|
/** Get the number of elements currently stored in the container. */ |
| 90 |
|
unsigned long Size(void) const |
| 91 |
|
{ return (unsigned long) m_Size; }; |
| 92 |
|
|
| 93 |
|
/** Tell the container to allocate enough memory to allow at least |
| 94 |
|
* as many elements as the size given to be stored. If new memory |
| 95 |
|
* needs to be allocated, the contents of the old buffer are copied |
| 96 |
|
* to the new area. The old buffer is deleted if the original pointer |
| 97 |
|
* was passed in using "LetContainerManageMemory"=true. The new buffer's |
| 98 |
|
* memory management will be handled by the container from that point on. |
| 99 |
|
* |
| 100 |
|
* \sa SetImportPointer() */ |
| 101 |
|
void Reserve(ElementIdentifier num); |
| 102 |
|
|
| 103 |
|
/** Tell the container to try to minimize its memory usage for |
| 104 |
|
* storage of the current number of elements. If new memory is |
| 105 |
|
* allocated, the contents of old buffer are copied to the new area. |
| 106 |
|
* The previous buffer is deleted if the original pointer was in |
| 107 |
|
* using "LetContainerManageMemory"=true. The new buffer's memory |
| 108 |
|
* management will be handled by the container from that point on. */ |
| 109 |
|
void Squeeze(void); |
| 110 |
|
|
| 111 |
|
/** Tell the container to release any of its allocated memory. */ |
| 112 |
|
void Initialize(void); |
| 113 |
|
|
| 114 |
|
|
| 115 |
|
/** These methods allow to define whether upon destruction of this class |
| 116 |
|
* the memory buffer should be released or not. Setting it to true |
| 117 |
|
* (or ON) makes that this class will take care of memory release. |
| 118 |
|
* Setting it to false (or OFF) will prevent the destructor from |
| 119 |
|
* deleting the memory buffer. This is desirable only when the data |
| 120 |
|
* is intended to be used by external applications. |
| 121 |
|
* Note that the normal logic of this class set the value of the boolean |
| 122 |
|
* flag. This may override your setting if you call this methods prematurely. |
| 123 |
|
* \warning Improper use of these methods will result in memory leaks */ |
| 124 |
|
itkSetMacro(ContainerManageMemory,bool); |
| 125 |
|
itkGetMacro(ContainerManageMemory,bool); |
| 126 |
|
itkBooleanMacro(ContainerManageMemory); |
| 127 |
|
|
| 128 |
|
|
| 129 |
|
protected: |
| 130 |
|
ImportImageContainer(); |
| 131 |
|
virtual ~ImportImageContainer(); |
| 132 |
|
|
| 133 |
|
/** PrintSelf routine. Normally this is a protected internal method. It is |
| 134 |
|
* made public here so that Image can call this method. Users should not |
| 135 |
|
* call this method but should call Print() instead. */ |
| 136 |
|
void PrintSelf(std::ostream& os, Indent indent) const; |
| 137 |
|
|
| 138 |
|
TElement* AllocateElements(ElementIdentifier size) const; |
| 139 |
|
private: |
| 140 |
|
ImportImageContainer(const Self&); //purposely not implemented |
| 141 |
|
void operator=(const Self&); //purposely not implemented |
| 142 |
|
|
| 143 |
|
TElement *m_ImportPointer; |
| 144 |
|
TElementIdentifier m_Size; |
| 145 |
|
TElementIdentifier m_Capacity; |
| 146 |
|
bool m_ContainerManageMemory; |
| 147 |
|
|
| 148 |
|
}; |
| 149 |
|
|
| 150 |
|
} // end namespace itk |
| 151 |
|
|
| 152 |
|
#ifndef ITK_MANUAL_INSTANTIATION |
| 153 |
|
#include "itkImportImageContainer.txx" |
| 154 |
|
#endif |
| 155 |
|
|
| 156 |
|
#endif |
| 157 |
|
|