ITK 6.0.0
Insight Toolkit
 
Loading...
Searching...
No Matches
itkImage.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 itkImage_h
19#define itkImage_h
20
21#include "itkImageRegion.h"
25#include "itkPoint.h"
26#include "itkFixedArray.h"
27#include "itkWeakPointer.h"
29
30#include <type_traits> // For is_same
31
32namespace itk
33{
87template <typename TPixel, unsigned int VImageDimension = 2>
88class ITK_TEMPLATE_EXPORT Image : public ImageBase<VImageDimension>
89{
90public:
91 ITK_DISALLOW_COPY_AND_MOVE(Image);
92
94 using Self = Image;
99
101 itkNewMacro(Self);
102
104 itkOverrideGetNameOfClassMacro(Image);
105
108 using PixelType = TPixel;
109
111 using ValueType = TPixel;
112
117 using InternalPixelType = TPixel;
118
120
125
129
131 using typename Superclass::ImageDimensionType;
132
134 using typename Superclass::IndexType;
135 using typename Superclass::IndexValueType;
136
138 using typename Superclass::OffsetType;
139
141 using typename Superclass::SizeType;
142 using typename Superclass::SizeValueType;
143
146
148 using typename Superclass::DirectionType;
149
152 using typename Superclass::RegionType;
153
156 using typename Superclass::SpacingType;
157 using typename Superclass::SpacingValueType;
158
161 using typename Superclass::PointType;
162
166
168 using typename Superclass::OffsetValueType;
169
176 template <typename UPixelType, unsigned int VUImageDimension = VImageDimension>
181
182
183 template <typename UPixelType, unsigned int VUImageDimension = VImageDimension>
185
186
189 void
190 Allocate(bool initializePixels = false) override;
191
193 static Pointer
195 {
196 const auto image = Image::New();
197 image->SetRegions(region);
198 image->AllocateInitialized();
199 return image;
200 }
201
204 void
205 Initialize() override;
206
209 void
210 FillBuffer(const TPixel & value);
211
217 void
218 SetPixel(const IndexType & index, const TPixel & value)
219 {
220 const OffsetValueType offset = this->FastComputeOffset(index);
221 (*m_Buffer)[offset] = value;
222 }
223
228 const TPixel &
229 GetPixel(const IndexType & index) const
230 {
231 const OffsetValueType offset = this->FastComputeOffset(index);
232 return (*m_Buffer)[offset];
233 }
234
239 TPixel &
240 GetPixel(const IndexType & index)
241 {
242 const OffsetValueType offset = this->FastComputeOffset(index);
243 return (*m_Buffer)[offset];
244 }
245
250 TPixel &
251 operator[](const IndexType & index)
252 {
253 return this->GetPixel(index);
254 }
255
260 const TPixel &
261 operator[](const IndexType & index) const
262 {
263 return this->GetPixel(index);
264 }
265
269 virtual TPixel *
271 {
272 return m_Buffer ? m_Buffer->GetBufferPointer() : nullptr;
273 }
274 virtual const TPixel *
276 {
277 return m_Buffer ? m_Buffer->GetBufferPointer() : nullptr;
278 }
279
281 PixelContainer *
283 {
284 return m_Buffer.GetPointer();
285 }
286
287 const PixelContainer *
289 {
290 return m_Buffer.GetPointer();
291 }
292
295 void
297
308 virtual void
309 Graft(const Self * image);
310
314 {
315 return AccessorType();
316 }
317
319 const AccessorType
321 {
322 return AccessorType();
323 }
324
326 NeighborhoodAccessorFunctorType
331
333 const NeighborhoodAccessorFunctorType
338
339 [[nodiscard]] unsigned int
341
347 template <typename TEqualityComparable>
348 friend std::enable_if_t<std::is_same_v<TEqualityComparable, TPixel>, bool>
351 {
352 if ((lhs.GetBufferedRegion() != rhs.GetBufferedRegion()) || (lhs.m_Spacing != rhs.m_Spacing) ||
353 (lhs.m_Origin != rhs.m_Origin) || (lhs.m_Direction != rhs.m_Direction) ||
355 {
356 return false;
357 }
358
359 if (lhs.m_Buffer == rhs.m_Buffer)
360 {
361 return true;
362 }
363
364 if ((lhs.m_Buffer == nullptr) || (rhs.m_Buffer == nullptr))
365 {
366 return false;
367 }
368
369 auto & lhsBuffer = *(lhs.m_Buffer);
370 auto & rhsBuffer = *(rhs.m_Buffer);
371
372 const auto bufferSize = lhsBuffer.Size();
373
374 if (bufferSize != rhsBuffer.Size())
375 {
376 return false;
377 }
378
379 const TEqualityComparable * const lhsBufferPointer = lhsBuffer.GetBufferPointer();
380 const TEqualityComparable * const rhsBufferPointer = rhsBuffer.GetBufferPointer();
381
382 return (lhsBufferPointer == rhsBufferPointer) ||
383 std::equal(lhsBufferPointer, lhsBufferPointer + bufferSize, rhsBufferPointer);
384 }
385
387 template <typename TEqualityComparable>
388 friend std::enable_if_t<std::is_same_v<TEqualityComparable, TPixel>, bool>
391 {
392 return !(lhs == rhs);
393 }
394
395protected:
396 Image() = default;
397 void
398 PrintSelf(std::ostream & os, Indent indent) const override;
399 void
400 Graft(const DataObject * data) override;
401
402 ~Image() override = default;
403
409 void
411 using Superclass::Graft;
412
413private:
416};
417} // end namespace itk
418
419#ifndef ITK_MANUAL_INSTANTIATION
420# include "itkImage.hxx"
421#endif
422
423#endif
Base class for all data objects in ITK.
Provides a common API for pixel accessors for Image and VectorImage.
Give access to partial aspects a type.
Vector< SpacingValueType, VImageDimension > SpacingType
ImageRegion< VImageDimension > RegionType
SpacePrecisionType SpacingValueType
PointType m_Origin
virtual const RegionType & GetBufferedRegion() const
Index< VImageDimension > IndexType
Offset< VImageDimension > OffsetType
DirectionType m_Direction
OffsetValueType FastComputeOffset(const IndexType &ind) const
typename OffsetType::OffsetValueType OffsetValueType
typename IndexType::IndexValueType IndexValueType
virtual void Graft(const Self *image)
Matrix< SpacePrecisionType, VImageDimension, VImageDimension > DirectionType
Size< VImageDimension > SizeType
Point< PointValueType, VImageDimension > PointType
SpacingType m_Spacing
DirectionType m_InverseDirection
typename SizeType::SizeValueType SizeValueType
Templated n-dimensional image class.
Definition itkImage.h:89
void PrintSelf(std::ostream &os, Indent indent) const override
const AccessorType GetPixelAccessor() const
Definition itkImage.h:320
unsigned int GetNumberOfComponentsPerPixel() const override
AccessorType GetPixelAccessor()
Definition itkImage.h:313
SmartPointer< const Self > ConstPointer
Definition itkImage.h:97
friend std::enable_if_t< std::is_same_v< TEqualityComparable, TPixel >, bool > operator==(const Image< TEqualityComparable, VImageDimension > &lhs, const Image< TEqualityComparable, VImageDimension > &rhs)
Definition itkImage.h:349
virtual void Graft(const Self *image)
const PixelContainer * GetPixelContainer() const
Definition itkImage.h:288
static Pointer New()
friend std::enable_if_t< std::is_same_v< TEqualityComparable, TPixel >, bool > operator!=(const Image< TEqualityComparable, VImageDimension > &lhs, const Image< TEqualityComparable, VImageDimension > &rhs)
Definition itkImage.h:389
WeakPointer< const Self > ConstWeakPointer
Definition itkImage.h:98
ImageBase< VImageDimension > Superclass
Definition itkImage.h:95
Image()=default
const TPixel & operator[](const IndexType &index) const
Access a pixel. This version can only be an rvalue.
Definition itkImage.h:261
void SetPixel(const IndexType &index, const TPixel &value)
Set a pixel value.
Definition itkImage.h:218
TPixel & GetPixel(const IndexType &index)
Get a reference to a pixel (e.g. for editing).
Definition itkImage.h:240
virtual const TPixel * GetBufferPointer() const
Definition itkImage.h:275
ImageRegion< VImageDimension > RegionType
virtual TPixel * GetBufferPointer()
Definition itkImage.h:270
void Graft(const DataObject *data) override
void SetPixelContainer(PixelContainer *container)
NeighborhoodAccessorFunctor< Self > NeighborhoodAccessorFunctorType
Definition itkImage.h:128
static Pointer CreateInitialized(const RegionType &region)
Definition itkImage.h:194
DefaultPixelAccessor< PixelType > AccessorType
Definition itkImage.h:123
typename PixelContainer::ConstPointer PixelContainerConstPointer
Definition itkImage.h:165
const NeighborhoodAccessorFunctorType GetNeighborhoodAccessor() const
Definition itkImage.h:334
void Allocate(bool initializePixels=false) override
itk::Image< UPixelType, VUImageDimension > RebindImageType
Definition itkImage.h:184
void FillBuffer(const TPixel &value)
typename PixelContainer::Pointer PixelContainerPointer
Definition itkImage.h:164
NeighborhoodAccessorFunctorType GetNeighborhoodAccessor()
Definition itkImage.h:327
void Initialize() override
~Image() override=default
ImportImageContainer< SizeValueType, PixelType > PixelContainer
Definition itkImage.h:145
DefaultPixelAccessorFunctor< Self > AccessorFunctorType
Definition itkImage.h:124
PixelContainer * GetPixelContainer()
Definition itkImage.h:282
const TPixel & GetPixel(const IndexType &index) const
Get a pixel (read only version).
Definition itkImage.h:229
void ComputeIndexToPhysicalPointMatrices() override
typename OffsetType::OffsetValueType OffsetValueType
TPixel & operator[](const IndexType &index)
Access a pixel. This version can be an lvalue.
Definition itkImage.h:251
Defines an itk::Image front-end to a standard C-array.
Control indentation during Print() invocation.
Definition itkIndent.h:51
Provides accessor interfaces to Get pixels and is meant to be used on pointers contained within Neigh...
Implements transparent reference counting.
Implements a weak reference to an object.
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
itk::Image< UPixelType, VUImageDimension > Type
Definition itkImage.h:179