ITK  6.0.0
Insight Toolkit
itkVectorImage.h
Go to the documentation of this file.
1/*=========================================================================
2 *
3 * Copyright NumFOCUS
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 * https://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 itkVectorImage_h
19#define itkVectorImage_h
20
21#include "itkImageRegion.h"
26#include "itkWeakPointer.h"
27
28namespace itk
29{
80template <typename TPixel, unsigned int VImageDimension = 3>
81class ITK_TEMPLATE_EXPORT VectorImage : public ImageBase<VImageDimension>
82{
83public:
84 ITK_DISALLOW_COPY_AND_MOVE(VectorImage);
85
92
94 itkNewMacro(Self);
95
97 itkOverrideGetNameOfClassMacro(VectorImage);
98
104
108 using InternalPixelType = TPixel;
109
112
114
118
122
126
131 static constexpr unsigned int ImageDimension = VImageDimension;
132
134 using typename Superclass::IndexType;
135 using typename Superclass::IndexValueType;
136
138 using typename Superclass::OffsetType;
139
141 using typename Superclass::SizeType;
142
145
147 using typename Superclass::DirectionType;
148
151 using typename Superclass::RegionType;
152
155 using typename Superclass::SpacingType;
156
159 using typename Superclass::PointType;
160
164
166 using typename Superclass::OffsetValueType;
167
168 using VectorLengthType = unsigned int;
169
186 template <typename UPixelType, unsigned int VUImageDimension = VImageDimension>
187 struct Rebind
188 {
190 };
191
193 template <typename UElementType, unsigned int VUImageDimension>
194 struct Rebind<VariableLengthVector<UElementType>, VUImageDimension>
195 {
197 };
199
200 template <typename UPixelType, unsigned int VUImageDimension = VImageDimension>
202
205 void
206 Allocate(bool UseValueInitialization = false) override;
207
210 void
211 Initialize() override;
212
215 void
216 FillBuffer(const PixelType & value);
217
223 void
224 SetPixel(const IndexType & index, const PixelType & value)
225 {
226 const OffsetValueType offset = m_VectorLength * this->FastComputeOffset(index);
227
228 for (VectorLengthType i = 0; i < m_VectorLength; ++i)
229 {
230 (*m_Buffer)[offset + i] = value[i];
231 }
232 }
233
239 const PixelType
240 GetPixel(const IndexType & index) const
241 {
242 const OffsetValueType offset = m_VectorLength * this->FastComputeOffset(index);
243
244 // Do not create a local for this method, to use return value
245 // optimization.
246 return PixelType(&((*m_Buffer)[offset]), m_VectorLength);
247 }
248
258 PixelType
259 GetPixel(const IndexType & index)
260 {
261 const OffsetValueType offset = m_VectorLength * this->FastComputeOffset(index);
262
263 // Correctness of this method relies of return value optimization, do
264 // not create a local for the value.
265 return PixelType(&((*m_Buffer)[offset]), m_VectorLength);
266 }
267
277 PixelType
278 operator[](const IndexType & index)
279 {
280 return this->GetPixel(index);
281 }
282
287 const PixelType
288 operator[](const IndexType & index) const
289 {
290 return this->GetPixel(index);
291 }
292
295 InternalPixelType *
297 {
298 return m_Buffer ? m_Buffer->GetBufferPointer() : nullptr;
299 }
300 const InternalPixelType *
302 {
303 return m_Buffer ? m_Buffer->GetBufferPointer() : nullptr;
304 }
308 PixelContainer *
310 {
311 return m_Buffer.GetPointer();
312 }
313
315 const PixelContainer *
317 {
318 return m_Buffer.GetPointer();
319 }
320
323 void
325
336 virtual void
337 Graft(const Self * image);
338
342 {
343 return AccessorType(m_VectorLength);
344 }
345
347 const AccessorType
349 {
350 return AccessorType(m_VectorLength);
351 }
352
354 NeighborhoodAccessorFunctorType
356 {
357 return NeighborhoodAccessorFunctorType(m_VectorLength);
358 }
359
361 const NeighborhoodAccessorFunctorType
363 {
364 return NeighborhoodAccessorFunctorType(m_VectorLength);
365 }
366
368 itkSetMacro(VectorLength, VectorLengthType);
369 itkGetConstReferenceMacro(VectorLength, VectorLengthType);
373 unsigned int
375
376 void
377 SetNumberOfComponentsPerPixel(unsigned int n) override;
378
379protected:
380 VectorImage() = default;
381 void
382 PrintSelf(std::ostream & os, Indent indent) const override;
383
384 ~VectorImage() override = default;
385 void
386 Graft(const DataObject * data) override;
387 using Superclass::Graft;
388
389private:
391 VectorLengthType m_VectorLength{ 0 };
392
395};
396} // end namespace itk
397
398#ifndef ITK_MANUAL_INSTANTIATION
399# include "itkVectorImage.hxx"
400#endif
401
402#endif
Base class for all data objects in ITK.
This class provides a common API for pixel accessors for Image and VectorImage. (between the DefaultV...
Give access to partial aspects of a type.
Base class for templated image classes.
Definition: itkImageBase.h:115
typename OffsetType::OffsetValueType OffsetValueType
Definition: itkImageBase.h:147
Defines an itk::Image front-end to a standard C-array.
Control indentation during Print() invocation.
Definition: itkIndent.h:50
Base class for most ITK classes.
Definition: itkObject.h:62
Provides accessor interfaces to Access pixels and is meant to be used on pointers to pixels held by t...
Templated n-dimensional vector image class.
void Initialize() override
typename PixelContainer::ConstPointer PixelContainerConstPointer
const AccessorType GetPixelAccessor() const
typename Rebind< UPixelType, VUImageDimension >::Type RebindImageType
const PixelType operator[](const IndexType &index) const
Access a pixel.
unsigned int VectorLengthType
InternalPixelType IOPixelType
const NeighborhoodAccessorFunctorType GetNeighborhoodAccessor() const
void SetPixelContainer(PixelContainer *container)
virtual void Graft(const Self *image)
void Graft(const DataObject *data) override
void FillBuffer(const PixelType &value)
const InternalPixelType * GetBufferPointer() const
PixelContainer * GetPixelContainer()
VectorImage()=default
NeighborhoodAccessorFunctorType GetNeighborhoodAccessor()
void SetNumberOfComponentsPerPixel(unsigned int n) override
unsigned int GetNumberOfComponentsPerPixel() const override
PixelType GetPixel(const IndexType &index)
Get a "reference" to a pixel. This result cannot be used as an lvalue because the pixel is converted ...
~VectorImage() override=default
void Allocate(bool UseValueInitialization=false) override
typename PixelContainer::Pointer PixelContainerPointer
const PixelType GetPixel(const IndexType &index) const
Get a pixel (read only version).
void SetPixel(const IndexType &index, const PixelType &value)
Set a pixel value.
AccessorType GetPixelAccessor()
PixelType operator[](const IndexType &index)
Access a pixel. This result cannot be used as an lvalue because the pixel is converted on the fly to ...
const PixelContainer * GetPixelContainer() const
void PrintSelf(std::ostream &os, Indent indent) const override
InternalPixelType * GetBufferPointer()
Implements a weak reference to an object.
SmartPointer< const Self > ConstPointer
static Pointer New()
SmartPointer< Self > Pointer
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
long IndexValueType
Definition: itkIntTypes.h:93
long OffsetValueType
Definition: itkIntTypes.h:97
A structure which enable changing any image class' pixel type to another.