Medical Imaging Interaction Toolkit  2024.12.00
Medical Imaging Interaction Toolkit
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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 {
26  //##Documentation
27  //## @brief The ImageAccessorBase class provides a lock mechanism for all inheriting image accessors.
28  //##
29  //## @ingroup Data
30 
31  class Image;
32 
35  {
37  unsigned int m_WaiterCount;
38 
40  std::mutex m_Mutex;
41  };
42 
43 // Defs to assure dead lock prevention only in case of possible thread handling.
44 #if defined(ITK_USE_SPROC) || defined(ITK_USE_PTHREADS) || defined(ITK_USE_WIN32_THREADS)
45 #define MITK_USE_RECURSIVE_MUTEX_PREVENTION
46 #endif
47 
49  {
50  friend class Image;
51 
52  friend class ImageReadAccessor;
53  friend class ImageWriteAccessor;
54 
55  template <class TPixel, unsigned int VDimension>
56  friend class ImagePixelReadAccessor;
57 
58  template <class TPixel, unsigned int VDimension>
60 
61  public:
63 
66  enum Options
67  {
69  DefaultBehavior = 0,
72  ExceptionIfLocked = 1,
77  ForceCoherentMemory = 2,
79  IgnoreLock = 4
80  };
81 
82  virtual ~ImageAccessorBase();
83 
85  inline const void *GetData() const { return m_AddressBegin; }
86  protected:
87 // Define type of thread id
88 #ifdef ITK_USE_SPROC
89  typedef int ThreadIDType;
90 #endif
91 
92 #ifdef ITK_USE_WIN32_THREADS
93  typedef DWORD ThreadIDType;
94 #endif
95 
96 #ifdef ITK_USE_PTHREADS
97  typedef pthread_t ThreadIDType;
98 #endif
99 
102  ImageAccessorBase(ImageConstPointer iP, const ImageDataItem *iDI = nullptr, int OptionFlags = DefaultBehavior);
103 
105  // ImagePointer m_Image;
106 
108  itk::ImageRegion<4> *m_SubRegion;
109 
112 
115 
120 
123 
126 
129  inline void Increment() { m_WaitLock->m_WaiterCount += 1; }
134  bool Overlap(const ImageAccessorBase *iAB);
135 
137  void WaitForReleaseOf(ImageAccessorWaitLock *wL);
138 
139  ThreadIDType m_Thread;
140 
142  void PreventRecursiveMutexLock(ImageAccessorBase *iAB);
143 
144  virtual const Image *GetImage() const = 0;
145 
146  private:
148  ThreadIDType CurrentThreadHandle();
150  inline bool CompareThreadHandles(ThreadIDType, ThreadIDType);
151  };
152 
154  {
155  public:
157  };
158 }
159 
160 #endif
mitk::Exception
An object of this class represents an exception of MITK. Please don't instantiate exceptions manually...
Definition: mitkException.h:45
mitk::ImageAccessorBase::m_CoherentMemory
bool m_CoherentMemory
Definition: mitkImageAccessorBase.h:122
mitk::ImageAccessorBase::m_Thread
ThreadIDType m_Thread
Definition: mitkImageAccessorBase.h:139
mitk::ImageWriteAccessor
ImageWriteAccessor class to get locked write-access for a particular image part.
Definition: mitkImageWriteAccessor.h:25
mitk::ImageDataItem
Internal class for managing references on sub-images.
Definition: mitkImageDataItem.h:43
mitk::ImageAccessorWaitLock::m_Mutex
std::mutex m_Mutex
A mutex that allows other ImageAccessors to wait for the represented ImageAccessor.
Definition: mitkImageAccessorBase.h:40
mitk::ImageAccessorBase::Increment
void Increment()
Increments m_WaiterCount. A call of this method is prohibited unless the Mutex m_ReadWriteLock in the...
Definition: mitkImageAccessorBase.h:129
mitk::ImageAccessorBase
Definition: mitkImageAccessorBase.h:48
mitk::Image
Image class for storing images.
Definition: mitkImage.h:69
itk::SmartPointer
Definition: mitkIFileReader.h:30
mitk::ImagePixelReadAccessor
Gives locked and index-based read access for a particular image part. The class provides several set-...
Definition: mitkImagePixelReadAccessor.h:32
mitk::ImageAccessorWaitLock::m_WaiterCount
unsigned int m_WaiterCount
Holds the number of ImageAccessors, which are waiting until the represented ImageAccessor is released...
Definition: mitkImageAccessorBase.h:37
mitk
Find image slices visible on a given plane.
Definition: RenderingTests.dox:1
mitk::ImageReadAccessor
ImageReadAccessor class to get locked read access for a particular image part.
Definition: mitkImageReadAccessor.h:27
mitk::ImageAccessorWaitLock
This struct allows to make ImageAccessors wait for this particular ImageAccessor object.
Definition: mitkImageAccessorBase.h:34
mitk::MemoryIsLockedException
Definition: mitkImageAccessorBase.h:153
mitk::ImageAccessorBase::m_Options
int m_Options
Stores all extended properties of an ImageAccessor. The different flags in mitk::ImageAccessorBase::O...
Definition: mitkImageAccessorBase.h:119
mitk::ImageAccessorBase::m_AddressEnd
void * m_AddressEnd
Definition: mitkImageAccessorBase.h:114
mitkImageDataItem.h
mitk::ImageAccessorBase::m_WaitLock
ImageAccessorWaitLock * m_WaitLock
Pointer to a WaitLock struct, that allows other ImageAccessors to wait for this ImageAccessor.
Definition: mitkImageAccessorBase.h:125
mitk::ImagePixelWriteAccessor
Gives locked and index-based write access for a particular image part. The class provides several set...
Definition: mitkImagePixelWriteAccessor.h:30
mitkExceptionClassMacro
#define mitkExceptionClassMacro(ClassName, SuperClassName)
Definition: mitkExceptionMacro.h:62
mitk::ImageAccessorBase::ImageConstPointer
itk::SmartPointer< const mitk::Image > ImageConstPointer
Definition: mitkImageAccessorBase.h:62
itk::Image
class ITK_EXPORT Image
Definition: mitkGeometryClipImageFilter.h:25
mitk::ImageAccessorBase::m_SubRegion
itk::ImageRegion< 4 > * m_SubRegion
Definition: mitkImageAccessorBase.h:108
mitk::ImageAccessorBase::m_AddressBegin
void * m_AddressBegin
Definition: mitkImageAccessorBase.h:111
MITKCORE_EXPORT
#define MITKCORE_EXPORT
Definition: MitkCoreExports.h:15
mitk::ImageAccessorBase::Options
Options
defines different flags for the ImageAccessor constructors
Definition: mitkImageAccessorBase.h:66
mitk::ImageAccessorBase::GetData
const void * GetData() const
Gives const access to the data.
Definition: mitkImageAccessorBase.h:85