Medical Imaging Interaction Toolkit  2016.11.0
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,
6 Division of Medical and Biological Informatics.
7 All rights reserved.
8 
9 This software is distributed WITHOUT ANY WARRANTY; without
10 even the implied warranty of MERCHANTABILITY or FITNESS FOR
11 A PARTICULAR PURPOSE.
12 
13 See LICENSE.txt or http://www.mitk.org for details.
14 
15 ===================================================================*/
16 
17 #ifndef MITKIMAGEACCESSORBASE_H
18 #define MITKIMAGEACCESSORBASE_H
19 
20 #include <itkImageRegion.h>
21 #include <itkIndex.h>
22 #include <itkMultiThreader.h>
23 #include <itkSimpleFastMutexLock.h>
24 #include <itkSmartPointer.h>
25 
26 #include "mitkImageDataItem.h"
27 
28 namespace mitk
29 {
30  //##Documentation
31  //## @brief The ImageAccessorBase class provides a lock mechanism for all inheriting image accessors.
32  //##
33  //## @ingroup Data
34 
35  class Image;
36 
39  {
41  unsigned int m_WaiterCount;
42 
44  itk::SimpleFastMutexLock m_Mutex;
45  };
46 
47 // Defs to assure dead lock prevention only in case of possible thread handling.
48 #if defined(ITK_USE_SPROC) || defined(ITK_USE_PTHREADS) || defined(ITK_USE_WIN32_THREADS)
49 #define MITK_USE_RECURSIVE_MUTEX_PREVENTION
50 #endif
51 
53  {
54  friend class Image;
55 
56  friend class ImageReadAccessor;
57  friend class ImageWriteAccessor;
58 
59  template <class TPixel, unsigned int VDimension>
60  friend class ImagePixelReadAccessor;
61 
62  template <class TPixel, unsigned int VDimension>
64 
65  public:
67 
70  enum Options
71  {
73  DefaultBehavior = 0,
76  ExceptionIfLocked = 1,
81  ForceCoherentMemory = 2,
83  IgnoreLock = 4
84  };
85 
86  virtual ~ImageAccessorBase();
87 
89  inline const void *GetData() const { return m_AddressBegin; }
90  protected:
91 // Define type of thread id
92 #ifdef ITK_USE_SPROC
93  typedef int ThreadIDType;
94 #endif
95 
96 #ifdef ITK_USE_WIN32_THREADS
97  typedef DWORD ThreadIDType;
98 #endif
99 
100 #ifdef ITK_USE_PTHREADS
101  typedef pthread_t ThreadIDType;
102 #endif
103 
106  ImageAccessorBase(ImageConstPointer iP, const ImageDataItem *iDI = nullptr, int OptionFlags = DefaultBehavior);
107 
109  // ImagePointer m_Image;
110 
112  itk::ImageRegion<4> *m_SubRegion;
113 
116 
119 
124 
127 
130 
133  inline void Increment() { m_WaitLock->m_WaiterCount += 1; }
138  bool Overlap(const ImageAccessorBase *iAB);
139 
141  void WaitForReleaseOf(ImageAccessorWaitLock *wL);
142 
143  ThreadIDType m_Thread;
144 
146  void PreventRecursiveMutexLock(ImageAccessorBase *iAB);
147 
148  virtual const Image *GetImage() const = 0;
149 
150  private:
152  ThreadIDType CurrentThreadHandle();
154  inline bool CompareThreadHandles(ThreadIDType, ThreadIDType);
155  };
156 
158  {
159  public:
161  };
162 }
163 
164 #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...
const void * GetData() const
Gives const access to the data.
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't instantiate exceptions manually...
Definition: mitkException.h:49
Image class for storing images.
Definition: mitkImage.h:76
#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.