19 :m_PreviousCLocale(nullptr)
23 void mitk::TestDICOMLoading::SetDefaultLocale()
26 if (m_PreviousCLocale ==
nullptr)
28 m_PreviousCLocale = setlocale(LC_NUMERIC,
nullptr);
31 setlocale(LC_NUMERIC,
"C");
33 m_PreviousCppLocale = std::cin.getloc();
41 void mitk::TestDICOMLoading::ResetUserLocale()
43 if (m_PreviousCLocale)
45 setlocale(LC_NUMERIC, m_PreviousCLocale);
47 std::cin.imbue(m_PreviousCppLocale);
48 std::cout.imbue(m_PreviousCppLocale);
50 m_PreviousCLocale =
nullptr;
60 for (
auto iter = files.begin();
69 ClassicDICOMSeriesReader::Pointer reader = this->BuildDICOMReader();
70 reader->SetInputFiles( files );
71 reader->AnalyzeInputFiles();
72 reader->PrintOutputs(std::cout,
true);
75 unsigned int numberOfImages = reader->GetNumberOfOutputs();
76 for (
unsigned imageIndex = 0; imageIndex < numberOfImages; ++imageIndex)
85 mitk::ClassicDICOMSeriesReader::Pointer
86 mitk::TestDICOMLoading
90 reader->SetFixTiltByShearing(
true);
101 for (
auto iter = files.begin();
120 ClassicDICOMSeriesReader::Pointer reader = this->BuildDICOMReader();
121 reader->SetInputFiles( files );
122 reader->AnalyzeInputFiles();
128 if ( reader->GetNumberOfOutputs() != 1 )
130 MITK_ERROR <<
"Reader produce " << reader->GetNumberOfOutputs() <<
" images instead of 1 expected..";
140 mitk::TestDICOMLoading::ComponentTypeToString(
int type)
142 if (type == itk::ImageIOBase::UCHAR)
144 else if (type == itk::ImageIOBase::CHAR)
146 else if (type == itk::ImageIOBase::USHORT)
148 else if (type == itk::ImageIOBase::SHORT)
150 else if (type == itk::ImageIOBase::UINT)
152 else if (type == itk::ImageIOBase::INT)
154 else if (type == itk::ImageIOBase::ULONG)
156 else if (type == itk::ImageIOBase::LONG)
158 else if (type == itk::ImageIOBase::FLOAT)
160 else if (type == itk::ImageIOBase::DOUBLE)
168 #define DumpLine(field, data) DumpILine(0, field, data) 171 #define DumpILine(indent, field, data) \ 173 std::string DumpLine_INDENT; DumpLine_INDENT.resize(indent, ' ' ); \ 174 result << DumpLine_INDENT << field << ": " << data << "\n"; \ 180 std::stringstream result;
182 if (image ==
nullptr)
return result.str();
191 result <<
"Dimensions: ";
192 for (
unsigned int dim = 0; dim < image->
GetDimension(); ++dim)
197 result <<
"Geometry: \n";
205 result <<
" " <<
"Matrix: ";
206 const AffineTransform3D::MatrixType& matrix = transform->GetMatrix();
207 for (
unsigned int i = 0; i < 3; ++i)
208 for (
unsigned int j = 0; j < 3; ++j)
209 result << matrix[i][j] <<
" ";
212 result <<
" " <<
"Offset: ";
213 const AffineTransform3D::OutputVectorType&
offset = transform->GetOffset();
214 for (
unsigned int i = 0; i < 3; ++i)
215 result << offset[i] <<
" ";
218 result <<
" " <<
"Center: ";
219 const AffineTransform3D::InputPointType& center = transform->GetCenter();
220 for (
unsigned int i = 0; i < 3; ++i)
221 result << center[i] <<
" ";
224 result <<
" " <<
"Translation: ";
225 const AffineTransform3D::OutputVectorType& translation = transform->GetTranslation();
226 for (
unsigned int i = 0; i < 3; ++i)
227 result << translation[i] <<
" ";
230 result <<
" " <<
"Scale: ";
231 const double* scale = transform->GetScale();
232 for (
unsigned int i = 0; i < 3; ++i)
233 result << scale[i] <<
" ";
236 result <<
" " <<
"Origin: ";
238 for (
unsigned int i = 0; i < 3; ++i)
239 result << origin[i] <<
" ";
242 result <<
" " <<
"Spacing: ";
244 for (
unsigned int i = 0; i < 3; ++i)
245 result << spacing[i] <<
" ";
248 result <<
" " <<
"TimeBounds: ";
250 for (
unsigned int i = 0; i < 2; ++i)
251 result << timeBounds[i] <<
" ";
264 mitk::TestDICOMLoading::trim(
const std::string& pString,
265 const std::string& pWhitespace)
267 const size_t beginStr = pString.find_first_not_of(pWhitespace);
268 if (beginStr == std::string::npos)
274 const size_t endStr = pString.find_last_not_of(pWhitespace);
275 const size_t range = endStr - beginStr + 1;
277 return pString.substr(beginStr, range);
281 mitk::TestDICOMLoading::reduce(
const std::string& pString,
282 const std::string& pFill,
283 const std::string& pWhitespace)
286 std::string result(trim(pString, pWhitespace));
289 size_t beginSpace = result.find_first_of(pWhitespace);
290 while (beginSpace != std::string::npos)
292 const size_t endSpace =
293 result.find_first_not_of(pWhitespace, beginSpace);
294 const size_t range = endSpace - beginSpace;
296 result.replace(beginSpace, range, pFill);
298 const size_t newStart = beginSpace + pFill.length();
299 beginSpace = result.find_first_of(pWhitespace, newStart);
307 mitk::TestDICOMLoading::CompareSpacedValueFields(
const std::string& reference,
308 const std::string&
test,
314 std::stringstream referenceStream(reduce(reference));
315 std::stringstream testStream(reduce(
test));
317 std::string refToken;
318 std::string testToken;
319 while ( std::getline( referenceStream, refToken,
' ' ) &&
320 std::getline ( testStream, testToken,
' ' ) )
324 if ( this->StringToNumber(refToken, refNumber) )
326 if ( this->StringToNumber(testToken, testNumber) )
329 MITK_DEBUG <<
"Reference Token '" << refToken <<
"'" <<
" value " << refNumber
330 <<
", test Token '" << testToken <<
"'" <<
" value " << testNumber;
332 bool old_result = result;
334 result &= ( std::abs(refNumber - testNumber) < 0.0001f );
336 if( old_result != result)
338 MITK_ERROR << std::setprecision(16) <<
"Reference Token '" << refToken <<
"'" <<
" value " << refNumber
339 <<
", test Token '" << testToken <<
"'" <<
" value " << testNumber;
341 MITK_ERROR <<
"[FALSE] - difference: " << std::setprecision(16) << std::abs(refNumber - testNumber) <<
" EPS: " << 0.0001f;
346 MITK_ERROR << refNumber <<
" cannot be compared to '" << testToken <<
"'";
351 MITK_DEBUG <<
"Token '" << refToken <<
"'" <<
" handled as string";
352 result &= refToken == testToken;
356 if ( std::getline( referenceStream, refToken,
' ' ) )
358 MITK_ERROR <<
"Reference string still had values when test string was already parsed: ref '" << reference <<
"', test '" <<
test <<
"'";
361 else if ( std::getline( testStream, testToken,
' ' ) )
363 MITK_ERROR <<
"Test string still had values when reference string was already parsed: ref '" << reference <<
"', test '" <<
test <<
"'";
372 const std::string& testDump )
374 KeyValueMap reference = ParseDump(referenceDump);
375 KeyValueMap
test = ParseDump(testDump);
377 bool testResult(
true);
380 for (KeyValueMap::const_iterator refIter = reference.begin();
381 refIter != reference.end();
384 const std::string& refKey = refIter->first;
385 const std::string& refValue = refIter->second;
387 if ( test.find(refKey) != test.end() )
389 const std::string& testValue = test[refKey];
391 bool thisTestResult = CompareSpacedValueFields( refValue, testValue );
392 testResult &= thisTestResult;
394 MITK_DEBUG << refKey <<
": '" << refValue <<
"' == '" << testValue <<
"' ? " << (thisTestResult?
"YES":
"NO");
398 MITK_ERROR <<
"Reference dump contains a key'" << refKey <<
"' (value '" << refValue <<
"')." ;
399 MITK_ERROR <<
"This key is expected to be generated for tests (but was not). Most probably you need to update your test data.";
405 for (KeyValueMap::const_iterator testIter = test.begin();
406 testIter != test.end();
409 const std::string& key = testIter->first;
410 const std::string& value = testIter->second;
412 if ( reference.find(key) == reference.end() )
414 MITK_ERROR <<
"Test dump contains an unexpected key'" << key <<
"' (value '" << value <<
"')." ;
415 MITK_ERROR <<
"This key is not expected. Most probably you need to update your test data.";
423 mitk::TestDICOMLoading::KeyValueMap
424 mitk::TestDICOMLoading::ParseDump(
const std::string& dump )
426 KeyValueMap parsedResult;
428 std::string shredder(dump);
430 std::stack<std::string> surroundingKeys;
432 std::stack<std::string::size_type> expectedIndents;
433 expectedIndents.push(0);
437 std::string::size_type newLinePos = shredder.find(
'\n' );
438 if (newLinePos == std::string::npos || newLinePos == 0)
break;
440 std::string
line = shredder.substr( 0, newLinePos );
441 shredder = shredder.erase( 0, newLinePos+1 );
443 std::string::size_type keyPosition = line.find_first_not_of(
' ' );
444 std::string::size_type colonPosition = line.find(
':' );
446 std::string key = line.substr(keyPosition, colonPosition - keyPosition);
447 std::string::size_type firstSpacePosition = key.find_first_of(
" ");
448 if (firstSpacePosition != std::string::npos)
450 key.erase(firstSpacePosition);
453 if ( keyPosition > expectedIndents.top() )
456 expectedIndents.push(keyPosition);
458 else if (keyPosition == expectedIndents.top() )
460 if (!surroundingKeys.empty())
462 surroundingKeys.pop();
468 do expectedIndents.pop();
469 while (expectedIndents.top() != keyPosition);
472 if (!surroundingKeys.empty())
474 key = surroundingKeys.top() +
"." + key;
477 surroundingKeys.push(key);
479 std::string value = line.substr(colonPosition+1);
481 MITK_DEBUG <<
" Key: '" << key <<
"' value '" << value <<
"'" ;
483 parsedResult[key] = value;
itk::FixedArray< ScalarType, 2 > TimeBounds
Standard typedef for time-bounds.
const mitk::PixelType GetPixelType(int n=0) const
Returns the PixelType of channel n.
Follow Up Storage - Class to facilitate loading/accessing structured follow-up data.
Image::Pointer GetMitkImage() const
the 3D mitk::Image that is loaded from the DICOM files of a DICOMImageFrameList
std::string DumpImageInformation(const Image *image)
Dump relevant image information for later comparison.
void SetImageFrameList(const DICOMImageFrameList &framelist)
List of frames that constitute the mitk::Image (DICOMImageFrames)
vcl_size_t GetBpe() const
Get the number of bits per element (of an element)
void SetMitkImage(Image::Pointer image)
The 3D mitk::Image that is loaded from the DICOM files of a DICOMImageFrameList.
std::list< Image::Pointer > ImageList
int GetComponentType() const
Get the component type (the scalar (!) type). Each element may contain m_NumberOfComponents (more tha...
const mitk::TimeGeometry * GetTimeGeometry() const
Return the TimeGeometry of the data as const pointer.
virtual TimeBounds GetTimeBounds() const =0
Get the time bounds (in ms)
unsigned int GetDimension() const
Get dimension of the image.
std::vector< DICOMImageFrameInfo::Pointer > DICOMImageFrameList
Image class for storing images.
Output descriptor for DICOMFileReader.
void SetTagCache(DICOMTagCache *privateCache)
#define DumpLine(field, data)
itk::AffineGeometryFrame< ScalarType, 3 >::TransformType AffineTransform3D
mitk::Image::Pointer image
const Point3D GetOrigin() const
Get the origin, e.g. the upper-left corner of the plane.
std::vector< std::string > StringList
const mitk::Vector3D GetSpacing() const
Get the spacing (size of a pixel).
virtual BaseGeometry::Pointer GetGeometryForTimeStep(TimeStepType timeStep) const =0
Returns the geometry which corresponds to the given time step.
Image::Pointer DecorateVerifyCachedImage(const StringList &files, mitk::Image::Pointer cachedImage)
ImageList LoadFiles(const StringList &files)
BaseGeometry Describes the geometry of a data object.
mitk::AffineTransform3D * GetIndexToWorldTransform()
Get the transformation used to convert from index to world coordinates.
bool CompareImageInformationDumps(const std::string &reference, const std::string &test)
Compare two image information dumps.