MCPcopy Create free account
hub / github.com/MITK/MITK / ImagePixelWriteAccessor

Class ImagePixelWriteAccessor

Modules/Core/include/mitkImagePixelWriteAccessor.h:33–141  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

31 */
32 template <class TPixel, unsigned int VDimension = 3>
33 class ImagePixelWriteAccessor : public ImagePixelAccessor<TPixel, VDimension>
34 {
35 friend class Image;
36
37 public:
38 typedef ImagePixelAccessor<TPixel, VDimension> ImagePixelAccessorType;
39 typedef itk::SmartPointer<mitk::Image> ImagePointer;
40
41 /** \brief Instantiates a mitk::ImageWriteAccessor (see its doxygen page for more details)
42 * \param iP specifies the associated Image
43 * \param iDI specifies the allocated image part
44 * \param OptionFlags properties from mitk::ImageAccessorBase::Options can be chosen and assembled with bitwise
45 * unification.
46 * \throws mitk::Exception if the Constructor was created inappropriately
47 * \throws mitk::MemoryIsLockedException if requested image area is exclusively locked and
48 * mitk::ImageAccessorBase::ExceptionIfLocked is set in OptionFlags
49 *
50 * Includes a check if typeid of PixelType coincides with templated TPixel
51 * and a check if VDimension equals to the Dimension of the Image.
52 *
53 * \note
54 * To avoid intermittent Update() calls to a predecessing filter pipeline, a call to Modified() method after the
55 * access is finished is left to the developer.
56 */
57 ImagePixelWriteAccessor(ImagePointer iP,
58 const ImageDataItem *iDI = nullptr,
59 int OptionFlags = ImageAccessorBase::DefaultBehavior)
60 : ImagePixelAccessor<TPixel, VDimension>(iP.GetPointer(), iDI), m_WriteAccessor(iP, iDI, OptionFlags)
61 {
62 }
63
64 /** \brief Gives full data access. */
65 virtual inline TPixel *GetData() const { return static_cast<TPixel *>(m_WriteAccessor.m_AddressBegin); }
66 /** \brief Sets a pixel value at the given index. */
67 void SetPixelByIndex(const itk::Index<VDimension> &idx, const TPixel &value)
68 {
69 unsigned int offset = ImagePixelAccessor<TPixel, VDimension>::GetOffset(idx);
70
71 *(((TPixel *)m_WriteAccessor.m_AddressBegin) + offset) = value;
72 }
73
74 /** Extends SetPixel by integrating index validation to prevent overflow. */
75 void SetPixelByIndexSafe(const itk::Index<VDimension> &idx, const TPixel &value)
76 {
77 unsigned int offset = ImagePixelAccessorType::GetOffset(idx);
78
79 TPixel *targetAddress = ((TPixel *)m_WriteAccessor.m_AddressBegin) + offset;
80
81 if (targetAddress >= m_WriteAccessor.m_AddressBegin && targetAddress < m_WriteAccessor.m_AddressEnd)
82 {
83 *targetAddress = value;
84 }
85 else
86 {
87 // printf("image dimensions = %d, %d, %d\n", imageDims[0], imageDims[1], imageDims[2]);
88 // printf("m_AddressBegin: %p, m_AddressEnd: %p, offset: %u\n", m_WriteAccessor.m_AddressBegin,
89 // m_WriteAccessor.m_AddressEnd, offset);
90 mitkThrow() << "ImageAccessor Overflow: image access exceeds the requested image area at " << idx << ".";

Callers

nothing calls this directly

Calls 4

GetOffsetFunction · 0.85
GetGeometryMethod · 0.80
WorldToIndexMethod · 0.45
GetImageMethod · 0.45

Tested by

no test coverage detected