File: itkNDImageBase.h

package info (click to toggle)
elastix 5.2.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 42,480 kB
  • sloc: cpp: 68,403; lisp: 4,118; python: 1,013; xml: 182; sh: 177; makefile: 33
file content (288 lines) | stat: -rw-r--r-- 8,445 bytes parent folder | download
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
/*=========================================================================
 *
 *  Copyright UMC Utrecht and contributors
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *        http://www.apache.org/licenses/LICENSE-2.0.txt
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 *
 *=========================================================================*/

#ifndef itkNDImageBase_h
#define itkNDImageBase_h

#include "itkImage.h"
#include "itkArray.h"
#include <string>
#include "itkImageFileWriter.h"

namespace itk
{

/**
 * \class NDImageBase
 * \brief An image whose dimension can be specified at runtime.
 *
 * The NDImageBase class is needed for the FullSearch optimizer.
 * It allows run-time construction of an N-dimensional image. It
 * has most of the functionality of a normal itk::Image. \todo not all!
 * An internal writer and reader are included for convenience.
 *
 * The NewNDImage function defines the dimension of the image.
 * CreateNewImage creates an instance of an itk::Image, with
 * dimension as specified by NewNDImage.
 * Note: the NewNDImage does not return an itk::Image, but an
 * elx::NDImageTemplate.
 *
 * Suggested way of using this class:\n
 * NDImageBase<short> var1 = NDImageBase::NewNDImage(3);\n
 * var1->CreateNewImage();\n
 * The result is similar as:\n
 * itk::Image<short,3>::Pointer var1 = itk::Image<short,3>::New();\n
 * except that the actual itk::Image is stored as member variable
 * in the NDImageTemplate.
 *
 * \sa FullSearchOptimizer, NDImageTemplate
 * \ingroup Miscellaneous
 */

template <class TPixel>
class ITK_TEMPLATE_EXPORT NDImageBase : public Object
{
public:
  ITK_DISALLOW_COPY_AND_MOVE(NDImageBase);

  /** Standard class typedefs.*/
  using Self = NDImageBase;
  using Superclass = Object;
  using Pointer = SmartPointer<Self>;
  using ConstPointer = SmartPointer<const Self>;

  /** Method for creation through the object factory. */
  // itkNewMacro( Self );
  // not declared, because instantiating an object of this
  // (abstract) type makes no sense.

  /** Run-time type information (and related methods). */
  itkTypeMacro(NDImageBase, Object);

  using DataObjectPointer = DataObject::Pointer;

  /** Type definitions like normal itkImages, independent of the dimension */
  using PixelType = typename Image<TPixel, 2>::PixelType;
  using ValueType = typename Image<TPixel, 2>::ValueType;
  using InternalPixelType = typename Image<TPixel, 2>::InternalPixelType;
  using AccessorType = typename Image<TPixel, 2>::AccessorType;
  using PixelContainer = typename Image<TPixel, 2>::PixelContainer;
  using PixelContainerPointer = typename Image<TPixel, 2>::PixelContainerPointer;
  using PixelContainerConstPointer = typename Image<TPixel, 2>::PixelContainerConstPointer;

  using Spacing2DType = typename ImageBase<2>::SpacingType;
  using Point2DType = typename ImageBase<2>::PointType;

  using SpacingValueType = typename Spacing2DType::ValueType;
  using PointValueType = typename Point2DType::ValueType;
  using OffsetValueType = typename ImageBase<2>::OffsetValueType;

  /** ND versions of the index and sizetypes. Unlike in
   * their counterparts in the itk::Image, their size
   * can be defined at runtime. The elx::NDImageTemplate
   * takes care of converting from/to these types to
   * to/from the corresponding types in itk::Image.*/
  using IndexType = Array<IndexValueType>;
  using SizeType = Array<SizeValueType>;
  using SpacingType = Array<SpacingValueType>;
  using PointType = Array<PointValueType>;
  using OffsetType = Array<OffsetValueType>;
  /** \todo: extend to direction cosines; but not needed for now in elastix */

  /** Region typedef support. A region is used to specify a subset of an image. */

  // using typename Superclass::RegionType;

  /** \todo an NDRegionType should first be declared, in the same way as NDImage
   * use SetRegions(size) for now. then knowlegde of the RegionType is not
   * necessary.
   * alternative: forget about the regiontype and add the functions
   * SetLargestPossibleRegion, SetRegions etc with arguments (index,size)
   * or maybe: ImageIORegion
   */

  // void SetRegions(RegionType region) = 0;
  virtual void
  SetRegions(SizeType size) = 0;

  virtual void
  SetRequestedRegion(DataObject * data) = 0;

  virtual void
  Allocate() = 0;

  virtual void
  Initialize() = 0;

  virtual void
  FillBuffer(const TPixel & value) = 0;

  virtual void
  SetPixel(const IndexType & index, const TPixel & value) = 0;

  virtual const TPixel &
  GetPixel(const IndexType & index) const = 0;

  virtual TPixel &
  GetPixel(const IndexType & index) = 0;

  TPixel &       operator[](const IndexType & index) { return this->GetPixel(index); }
  const TPixel & operator[](const IndexType & index) const { return this->GetPixel(index); }

  virtual TPixel *
  GetBufferPointer() = 0;

  virtual const TPixel *
  GetBufferPointer() const = 0;

  virtual PixelContainer *
  GetPixelContainer() = 0;

  virtual const PixelContainer *
  GetPixelContainer() const = 0;

  virtual void
  SetPixelContainer(PixelContainer * container) = 0;

  virtual AccessorType
  GetPixelAccessor() = 0;

  virtual const AccessorType
  GetPixelAccessor() const = 0;

  virtual void
  SetSpacing(const SpacingType & spacing) = 0;

  virtual void
  SetOrigin(const PointType & origin) = 0;

  /* Get Spacing/Origin return copies; not a const &, like
   * itkImage; necessary because of the conversion to arrays */
  virtual SpacingType
  GetSpacing() = 0;

  virtual PointType
  GetOrigin() = 0;

  /** \todo Transform IndexToPoint methods. */

  virtual void
  CopyInformation(const DataObject * data) = 0;

  virtual const OffsetValueType *
  GetOffsetTable() const = 0;

  virtual OffsetValueType
  ComputeOffset(const IndexType & ind) const = 0;

  virtual IndexType
  ComputeIndex(OffsetValueType offset) const = 0;

  /** Extra functions for NDImage. */

  /** Get the Dimension.*/
  virtual unsigned int
  ImageDimension() = 0;

  virtual unsigned int
  GetImageDimension() = 0;

  virtual void
  SetImageIOWriter(ImageIOBase * _arg) = 0;

  virtual ImageIOBase *
  GetImageIOWriter() = 0;

  virtual void
  SetImageIOReader(ImageIOBase * _arg) = 0;

  virtual ImageIOBase *
  GetImageIOReader() = 0;

  /** Write the actual image to file. */
  virtual void
  Write() = 0;

  /** Read image data from file into the actual image */
  virtual void
  Read() = 0;

  /** Use New method to create a new actual image */
  virtual void
  CreateNewImage() = 0;

  /** Set/Get the Input/OutputFileName */
  virtual void
  SetOutputFileName(const char *) = 0;

  virtual void
  SetInputFileName(const char *) = 0;

  virtual const char *
  GetOutputFileName() = 0;

  virtual const char *
  GetInputFileName() = 0;

  static Pointer
  NewNDImage(unsigned int dim);

protected:
  NDImageBase() = default;
  ~NDImageBase() override = default;

  // virtual void PrintSelf(std::ostream& os, Indent indent) const = 0;
};

} // end namespace itk

#include "itkNDImageTemplate.h"

namespace itk
{

template <class TPixel>
auto
NDImageBase<TPixel>::NewNDImage(unsigned int dim) -> Pointer
{
  switch (dim)
  {
    case 1:
      return dynamic_cast<NDImageBase<TPixel> *>(NDImageTemplate<TPixel, 1>::New().GetPointer());
    case 2:
      return dynamic_cast<NDImageBase<TPixel> *>(NDImageTemplate<TPixel, 2>::New().GetPointer());
    case 3:
      return dynamic_cast<NDImageBase<TPixel> *>(NDImageTemplate<TPixel, 3>::New().GetPointer());
    case 4:
      return dynamic_cast<NDImageBase<TPixel> *>(NDImageTemplate<TPixel, 4>::New().GetPointer());
    case 5:
      return dynamic_cast<NDImageBase<TPixel> *>(NDImageTemplate<TPixel, 5>::New().GetPointer());
    // add here more dimensions if needed...
    // we could do this also with a recursive
    // template and a #define MAXDIM,
    // or something like that....
    default:
      // Return a default-constructed SmartPointer (null).
      return typename NDImageBase<TPixel>::Pointer();
  }
}


} // end namespace itk

#endif // end #ifndef itkNDImageBase_h