13 #include "itkBarrier.h" 22 #include <itkMultiThreader.h> 23 #include <itksys/SystemTools.hxx> 30 itk::Barrier::Pointer m_Barrier;
41 auto *pInfo = (
struct itk::MultiThreader::ThreadInfoStruct *)data;
46 return ITK_THREAD_RETURN_VALUE;
48 if (pInfo->UserData ==
nullptr)
50 return ITK_THREAD_RETURN_VALUE;
54 auto *threadData = (ThreadData *)pInfo->UserData;
56 srand(pInfo->ThreadID);
60 int nrSlices = im->GetDimension(2);
76 if ((im->GetPixelType().GetComponentTypeAsString() ==
"short") && (im->GetDimension() == 3))
80 int xlength = im->GetDimension(0);
81 int ylength = im->GetDimension(1);
86 for (
int i = 0; i < xlength; ++i)
88 for (
int j = 0; j < ylength; ++j)
112 if ((im->GetPixelType().GetComponentTypeAsString() ==
"short") && (im->GetDimension() == 3))
116 int xlength = im->GetDimension(0);
117 int ylength = im->GetDimension(1);
122 for (
int i = 0; i < xlength; ++i)
124 for (
int j = 0; j < ylength; ++j)
128 short newVal = rand() % 16000;
133 threadData->m_Successful =
false;
143 *((
char *)pointer) = 0;
149 threadData->m_Successful =
false;
154 threadData->m_Successful =
false;
159 threadData->m_Barrier->Wait();
160 return ITK_THREAD_RETURN_VALUE;
167 std::cout <<
"Loading file: ";
170 std::cout <<
"no file specified [FAILED]" << std::endl;
176 image = mitk::IOUtil::Load<mitk::Image>(std::string(argv[1]));
183 catch (
const itk::ExceptionObject &ex )
191 MITK_TEST_OUTPUT(<<
"Testing a recursive mutex lock attempt, should end in an exception ...");
212 image->GetGeometry()->Initialize();
214 itk::MultiThreader::Pointer threader = itk::MultiThreader::New();
215 unsigned int noOfThreads = 100;
218 itk::Barrier::Pointer barrier = itk::Barrier::New();
219 barrier->Initialize(noOfThreads + 1);
221 auto *threadData =
new ThreadData;
222 threadData->m_Barrier = barrier;
223 threadData->m_NoOfThreads = noOfThreads;
224 threadData->data =
image;
225 threadData->m_Successful =
true;
228 for (
unsigned int i = 0; i < noOfThreads; ++i)
236 for (
unsigned int j = 0; j < noOfThreads; ++j)
238 threader->TerminateThread(j);
241 bool TestSuccessful = threadData->m_Successful;
const TPixel & GetPixelByIndexSafe(const itk::Index< VDimension > &idx) const
Gives locked and index-based write access for a particular image part. The class provides several set...
itk::SimpleFastMutexLock testMutex
#define MITK_TEST_FOR_EXCEPTION_END(EXCEPTIONCLASS)
Gives locked and index-based read access for a particular image part. The class provides several set-...
void SetPixelByIndexSafe(const itk::Index< VDimension > &idx, const TPixel &value)
#define MITK_TEST_CONDITION_REQUIRED(COND, MSG)
ITK_THREAD_RETURN_TYPE ThreadMethod(void *data)
section GeneralTestsDeprecatedOldTestingStyle Deprecated macros All tests with MITK_TEST_BEGIN()
void * GetData()
Gives full data access.
const TPixel & GetPixelByIndexSafe(const itk::Index< VDimension > &idx) const
#define MITK_TEST_OUTPUT(x)
Output some text.
An object of this class represents an exception of MITK. Please don't instantiate exceptions manually...
#define MITK_TEST_FAILED_MSG(MSG)
Fail and finish test with message MSG.
#define MITK_TEST_FOR_EXCEPTION_BEGIN(EXCEPTIONCLASS)
Begin block which should be checked for exceptions.
mitk::Image::Pointer image
int mitkImageAccessorTest(int argc, char *argv[])
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.