23 :m_PreviousCLocale(nullptr)
27 void mitk::TestDICOMLoading::SetDefaultLocale()
30 if (m_PreviousCLocale ==
nullptr)
32 m_PreviousCLocale = setlocale(LC_NUMERIC,
nullptr);
35 setlocale(LC_NUMERIC,
"C");
37 m_PreviousCppLocale = std::cin.getloc();
45 void mitk::TestDICOMLoading::ResetUserLocale()
47 if (m_PreviousCLocale)
49 setlocale(LC_NUMERIC, m_PreviousCLocale);
51 std::cin.imbue(m_PreviousCppLocale);
52 std::cout.imbue(m_PreviousCppLocale);
54 m_PreviousCLocale =
nullptr;
64 for (
auto iter = files.begin();
74 reader->SetInputFiles( files );
75 reader->AnalyzeInputFiles();
76 reader->PrintOutputs(std::cout,
true);
79 unsigned int numberOfImages = reader->GetNumberOfOutputs();
80 for (
unsigned imageIndex = 0; imageIndex < numberOfImages; ++imageIndex)
90 mitk::TestDICOMLoading
94 reader->SetFixTiltByShearing(
true);
105 for (
auto iter = files.begin();
125 reader->SetInputFiles( files );
126 reader->AnalyzeInputFiles();
132 if ( reader->GetNumberOfOutputs() != 1 )
134 MITK_ERROR <<
"Reader produce " << reader->GetNumberOfOutputs() <<
" images instead of 1 expected..";
144 mitk::TestDICOMLoading::ComponentTypeToString(
int type)
146 if (type == itk::ImageIOBase::UCHAR)
148 else if (type == itk::ImageIOBase::CHAR)
150 else if (type == itk::ImageIOBase::USHORT)
152 else if (type == itk::ImageIOBase::SHORT)
154 else if (type == itk::ImageIOBase::UINT)
156 else if (type == itk::ImageIOBase::INT)
158 else if (type == itk::ImageIOBase::ULONG)
160 else if (type == itk::ImageIOBase::LONG)
162 else if (type == itk::ImageIOBase::FLOAT)
164 else if (type == itk::ImageIOBase::DOUBLE)
172 #define DumpLine(field, data) DumpILine(0, field, data)
175 #define DumpILine(indent, field, data) \
177 std::string DumpLine_INDENT; DumpLine_INDENT.resize(indent, ' ' ); \
178 result << DumpLine_INDENT << field << ": " << data << "\n"; \
184 std::stringstream result;
186 if (image ==
nullptr)
return result.str();
195 result <<
"Dimensions: ";
196 for (
unsigned int dim = 0; dim < image->
GetDimension(); ++dim)
201 result <<
"Geometry: \n";
209 result <<
" " <<
"Matrix: ";
210 const AffineTransform3D::MatrixType& matrix = transform->GetMatrix();
211 for (
unsigned int i = 0; i < 3; ++i)
212 for (
unsigned int j = 0; j < 3; ++j)
213 result << matrix[i][j] <<
" ";
216 result <<
" " <<
"Offset: ";
217 const AffineTransform3D::OutputVectorType&
offset = transform->GetOffset();
218 for (
unsigned int i = 0; i < 3; ++i)
219 result << offset[i] <<
" ";
222 result <<
" " <<
"Center: ";
223 const AffineTransform3D::InputPointType& center = transform->GetCenter();
224 for (
unsigned int i = 0; i < 3; ++i)
225 result << center[i] <<
" ";
228 result <<
" " <<
"Translation: ";
229 const AffineTransform3D::OutputVectorType& translation = transform->GetTranslation();
230 for (
unsigned int i = 0; i < 3; ++i)
231 result << translation[i] <<
" ";
234 result <<
" " <<
"Scale: ";
235 const double* scale = transform->GetScale();
236 for (
unsigned int i = 0; i < 3; ++i)
237 result << scale[i] <<
" ";
240 result <<
" " <<
"Origin: ";
242 for (
unsigned int i = 0; i < 3; ++i)
243 result << origin[i] <<
" ";
246 result <<
" " <<
"Spacing: ";
248 for (
unsigned int i = 0; i < 3; ++i)
249 result << spacing[i] <<
" ";
252 result <<
" " <<
"TimeBounds: ";
254 for (
unsigned int i = 0; i < 2; ++i)
255 result << timeBounds[i] <<
" ";
268 mitk::TestDICOMLoading::trim(
const std::string& pString,
269 const std::string& pWhitespace)
271 const size_t beginStr = pString.find_first_not_of(pWhitespace);
272 if (beginStr == std::string::npos)
278 const size_t endStr = pString.find_last_not_of(pWhitespace);
279 const size_t range = endStr - beginStr + 1;
281 return pString.substr(beginStr, range);
285 mitk::TestDICOMLoading::reduce(
const std::string& pString,
286 const std::string& pFill,
287 const std::string& pWhitespace)
290 std::string result(trim(pString, pWhitespace));
293 size_t beginSpace = result.find_first_of(pWhitespace);
294 while (beginSpace != std::string::npos)
296 const size_t endSpace =
297 result.find_first_not_of(pWhitespace, beginSpace);
298 const size_t range = endSpace - beginSpace;
300 result.replace(beginSpace, range, pFill);
302 const size_t newStart = beginSpace + pFill.length();
303 beginSpace = result.find_first_of(pWhitespace, newStart);
311 mitk::TestDICOMLoading::CompareSpacedValueFields(
const std::string& reference,
312 const std::string&
test,
318 std::stringstream referenceStream(reduce(reference));
319 std::stringstream testStream(reduce(test));
321 std::string refToken;
322 std::string testToken;
323 while ( std::getline( referenceStream, refToken,
' ' ) &&
324 std::getline ( testStream, testToken,
' ' ) )
328 if ( this->StringToNumber(refToken, refNumber) )
330 if ( this->StringToNumber(testToken, testNumber) )
333 MITK_DEBUG <<
"Reference Token '" << refToken <<
"'" <<
" value " << refNumber
334 <<
", test Token '" << testToken <<
"'" <<
" value " << testNumber;
336 bool old_result = result;
338 result &= ( std::abs(refNumber - testNumber) < 0.0001f );
340 if( old_result != result)
342 MITK_ERROR << std::setprecision(16) <<
"Reference Token '" << refToken <<
"'" <<
" value " << refNumber
343 <<
", test Token '" << testToken <<
"'" <<
" value " << testNumber;
345 MITK_ERROR <<
"[FALSE] - difference: " << std::setprecision(16) << std::abs(refNumber - testNumber) <<
" EPS: " << 0.0001f;
350 MITK_ERROR << refNumber <<
" cannot be compared to '" << testToken <<
"'";
355 MITK_DEBUG <<
"Token '" << refToken <<
"'" <<
" handled as string";
356 result &= refToken == testToken;
360 if ( std::getline( referenceStream, refToken,
' ' ) )
362 MITK_ERROR <<
"Reference string still had values when test string was already parsed: ref '" << reference <<
"', test '" << test <<
"'";
365 else if ( std::getline( testStream, testToken,
' ' ) )
367 MITK_ERROR <<
"Test string still had values when reference string was already parsed: ref '" << reference <<
"', test '" << test <<
"'";
376 const std::string& testDump )
378 KeyValueMap reference = ParseDump(referenceDump);
379 KeyValueMap test = ParseDump(testDump);
381 bool testResult(
true);
384 for (KeyValueMap::const_iterator refIter = reference.begin();
385 refIter != reference.end();
388 const std::string& refKey = refIter->first;
389 const std::string& refValue = refIter->second;
391 if ( test.find(refKey) != test.end() )
393 const std::string& testValue = test[refKey];
395 bool thisTestResult = CompareSpacedValueFields( refValue, testValue );
396 testResult &= thisTestResult;
398 MITK_DEBUG << refKey <<
": '" << refValue <<
"' == '" << testValue <<
"' ? " << (thisTestResult?
"YES":
"NO");
402 MITK_ERROR <<
"Reference dump contains a key'" << refKey <<
"' (value '" << refValue <<
"')." ;
403 MITK_ERROR <<
"This key is expected to be generated for tests (but was not). Most probably you need to update your test data.";
409 for (KeyValueMap::const_iterator testIter = test.begin();
410 testIter != test.end();
413 const std::string& key = testIter->first;
414 const std::string& value = testIter->second;
416 if ( reference.find(key) == reference.end() )
418 MITK_ERROR <<
"Test dump contains an unexpected key'" << key <<
"' (value '" << value <<
"')." ;
419 MITK_ERROR <<
"This key is not expected. Most probably you need to update your test data.";
427 mitk::TestDICOMLoading::KeyValueMap
428 mitk::TestDICOMLoading::ParseDump(
const std::string& dump )
430 KeyValueMap parsedResult;
432 std::string shredder(dump);
434 std::stack<std::string> surroundingKeys;
436 std::stack<std::string::size_type> expectedIndents;
437 expectedIndents.push(0);
441 std::string::size_type newLinePos = shredder.find(
'\n' );
442 if (newLinePos == std::string::npos || newLinePos == 0)
break;
444 std::string
line = shredder.substr( 0, newLinePos );
445 shredder = shredder.erase( 0, newLinePos+1 );
447 std::string::size_type keyPosition = line.find_first_not_of(
' ' );
448 std::string::size_type colonPosition = line.find(
':' );
450 std::string key = line.substr(keyPosition, colonPosition - keyPosition);
451 std::string::size_type firstSpacePosition = key.find_first_of(
" ");
452 if (firstSpacePosition != std::string::npos)
454 key.erase(firstSpacePosition);
457 if ( keyPosition > expectedIndents.top() )
460 expectedIndents.push(keyPosition);
462 else if (keyPosition == expectedIndents.top() )
464 if (!surroundingKeys.empty())
466 surroundingKeys.pop();
472 do expectedIndents.pop();
473 while (expectedIndents.top() != keyPosition);
476 if (!surroundingKeys.empty())
478 key = surroundingKeys.top() +
"." + key;
481 surroundingKeys.push(key);
483 std::string value = line.substr(colonPosition+1);
485 MITK_DEBUG <<
" Key: '" << key <<
"' value '" << value <<
"'" ;
487 parsedResult[key] = value;
const Point3D GetOrigin() const
Get the origin, e.g. the upper-left corner of the plane.
itk::SmartPointer< Self > Pointer
itk::FixedArray< ScalarType, 2 > TimeBounds
Standard typedef for time-bounds.
Follow Up Storage - Class to facilitate loading/accessing structured follow-up data.
const mitk::Vector3D GetSpacing() const
Get the spacing (size of a pixel).
const mitk::TimeGeometry * GetTimeGeometry() const
Return the TimeGeometry of the data as const pointer.
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)
void SetMitkImage(Image::Pointer image)
The 3D mitk::Image that is loaded from the DICOM files of a DICOMImageFrameList.
std::list< Image::Pointer > ImageList
vcl_size_t GetBpe() const
Get the number of bits per element (of an element)
virtual TimeBounds GetTimeBounds() const =0
Get the time bounds (in ms)
std::vector< DICOMImageFrameInfo::Pointer > DICOMImageFrameList
Image class for storing images.
Output descriptor for DICOMFileReader.
void SetTagCache(DICOMTagCache *privateCache)
#define DumpLine(field, data)
int GetComponentType() const
Get the component type (the scalar (!) type). Each element may contain m_NumberOfComponents (more tha...
itk::AffineGeometryFrame< ScalarType, 3 >::TransformType AffineTransform3D
const mitk::PixelType GetPixelType(int n=0) const
Returns the PixelType of channel n.
std::vector< std::string > StringList
Image::Pointer GetMitkImage() const
the 3D mitk::Image that is loaded from the DICOM files of a DICOMImageFrameList
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)
unsigned int GetDimension() const
Get dimension of the image.
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.
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.