Medical Imaging Interaction Toolkit  2018.4.99-12ad79a3
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 <itkMultiThreader.h>
19 #include <itkSimpleFastMutexLock.h>
20 #include <itkSmartPointer.h>
21 
22 #include "mitkImageDataItem.h"
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  itk::SimpleFastMutexLock 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
Gives locked and index-based write access for a particular image part. The class provides several set...
Gives locked and index-based read access for a particular image part. The class provides several set-...
#define MITKCORE_EXPORT
Options
defines different flags for the ImageAccessor constructors
itk::ImageRegion< 4 > * m_SubRegion
unsigned int m_WaiterCount
Holds the number of ImageAccessors, which are waiting until the represented ImageAccessor is released...
DataCollection - Class to facilitate loading/accessing structured data.
class ITK_EXPORT Image
ImageAccessorWaitLock * m_WaitLock
Pointer to a WaitLock struct, that allows other ImageAccessors to wait for this ImageAccessor.
itk::SmartPointer< const mitk::Image > ImageConstPointer
An object of this class represents an exception of MITK. Please don&#39;t instantiate exceptions manually...
Definition: mitkException.h:45
Image class for storing images.
Definition: mitkImage.h:72
#define mitkExceptionClassMacro(ClassName, SuperClassName)
void Increment()
Increments m_WaiterCount. A call of this method is prohibited unless the Mutex m_ReadWriteLock in the...
int m_Options
Stores all extended properties of an ImageAccessor. The different flags in mitk::ImageAccessorBase::O...
itk::SimpleFastMutexLock m_Mutex
A mutex that allows other ImageAccessors to wait for the represented ImageAccessor.
This struct allows to make ImageAccessors wait for this particular ImageAccessor object.
ImageWriteAccessor class to get locked write-access for a particular image part.
Internal class for managing references on sub-images.
ImageReadAccessor class to get locked read access for a particular image part.
const void * GetData() const
Gives const access to the data.