Medical Imaging Interaction Toolkit  2026.06.00
Medical Imaging Interaction Toolkit
mitkImageAccessorBase.h
Go to the documentation of this file.
1 /*============================================================================
2 
3 The Medical Imaging Interaction Toolkit (MITK)
4 
5 Copyright (c) German Cancer Research Center (DKFZ)
6 All rights reserved.
7 
8 Use of this source code is governed by a 3-clause BSD license that can be
9 found in the LICENSE file.
10 
11 ============================================================================*/
12 
13 #ifndef mitkImageAccessorBase_h
14 #define mitkImageAccessorBase_h
15 
16 #include <itkImageRegion.h>
17 #include <itkIndex.h>
18 #include <itkSmartPointer.h>
19 
20 #include <mitkImageDataItem.h>
21 
22 #include <mutex>
23 
24 namespace mitk
25 {
43  class Image;
44 
53  {
55  unsigned int m_WaiterCount;
56 
58  std::mutex m_Mutex;
59  };
60 
61 // Defs to assure dead lock prevention only in case of possible thread handling.
62 #if defined(ITK_USE_SPROC) || defined(ITK_USE_PTHREADS) || defined(ITK_USE_WIN32_THREADS)
63 #define MITK_USE_RECURSIVE_MUTEX_PREVENTION
64 #endif
65 
67  {
68  friend class Image;
69 
70  friend class ImageReadAccessor;
71  friend class ImageWriteAccessor;
72 
73  template <class TPixel, unsigned int VDimension>
74  friend class ImagePixelReadAccessor;
75 
76  template <class TPixel, unsigned int VDimension>
78 
79  public:
82 
89  enum Options
90  {
92  DefaultBehavior = 0,
94  ExceptionIfLocked = 1,
97  ForceCoherentMemory = 2,
99  IgnoreLock = 4
100  };
101 
104 
110  inline const void *GetData() const { return m_AddressBegin; }
111  protected:
112 // Define type of thread id
113 #ifdef ITK_USE_SPROC
114  typedef int ThreadIDType;
115 #endif
116 
117 #ifdef ITK_USE_WIN32_THREADS
118  typedef DWORD ThreadIDType;
119 #endif
120 
121 #ifdef ITK_USE_PTHREADS
122  typedef pthread_t ThreadIDType;
123 #endif
124 
127  ImageAccessorBase(ImageConstPointer iP, const ImageDataItem *iDI = nullptr, int OptionFlags = DefaultBehavior);
128 
130  // ImagePointer m_Image;
131 
133  itk::ImageRegion<4> *m_SubRegion;
134 
137 
140 
145 
148 
151 
154  inline void Increment() { m_WaitLock->m_WaiterCount += 1; }
159  bool Overlap(const ImageAccessorBase *iAB);
160 
163 
164  ThreadIDType m_Thread;
165 
168 
169  virtual const Image *GetImage() const = 0;
170 
171  private:
173  ThreadIDType CurrentThreadHandle();
175  inline bool CompareThreadHandles(ThreadIDType, ThreadIDType);
176  };
177 
179  {
180  public:
182  };
183 }
184 
185 #endif
#define MITKCORE_EXPORT
Base class for all MITK exceptions.
Definition: mitkException.h:53
virtual ~ImageAccessorBase()
Virtual destructor. Releases the wait lock if no other accessors are waiting.
void Increment()
Increments m_WaiterCount. A call of this method is prohibited unless the Mutex m_ReadWriteLock in the...
bool Overlap(const ImageAccessorBase *iAB)
Computes if there is an Overlap of the image part between this instantiation and another ImageAccesso...
const void * GetData() const
Get const access to the raw image data.
void WaitForReleaseOf(ImageAccessorWaitLock *wL)
Uses the WaitLock to wait for another ImageAccessor.
ImageAccessorWaitLock * m_WaitLock
Pointer to a WaitLock struct, that allows other ImageAccessors to wait for this ImageAccessor.
ImageAccessorBase(ImageConstPointer iP, const ImageDataItem *iDI=nullptr, int OptionFlags=DefaultBehavior)
Checks validity of given parameters from inheriting classes and stores those parameters in member var...
itk::SmartPointer< const mitk::Image > ImageConstPointer
Const smart pointer type for the associated Image.
itk::ImageRegion< 4 > * m_SubRegion
void PreventRecursiveMutexLock(ImageAccessorBase *iAB)
Prevents a recursive mutex lock by comparing thread ids of competing image accessors.
Options
Option flags that control ImageAccessor behavior.
int m_Options
Stores all extended properties of an ImageAccessor. The different flags in mitk::ImageAccessorBase::O...
virtual const Image * GetImage() const =0
Internal container for image data used by mitk::Image.
Gives locked and index-based read access for a particular image part.
Gives locked and index-based write access for a particular image part.
Provides locked read-only access to a particular region of image data.
Provides locked write access to a particular region of image data.
Image class for storing multi-dimensional medical image data.
Definition: mitkImage.h:76
#define mitkExceptionClassMacro(ClassName, SuperClassName)
Convenience macro for defining MITK exception subclasses.
class ITK_EXPORT Image
Find image slices visible on a given plane.
Wait-lock structure allowing ImageAccessors to wait for each other.
std::mutex m_Mutex
Mutex that other ImageAccessors lock on to wait for this accessor.
unsigned int m_WaiterCount
Number of ImageAccessors waiting for this accessor to be released.