Commit 5a105d43 authored by Jim Miller's avatar Jim Miller
Browse files

FIX: handle invalid ImagePositionPatient and ImageOrientationPatient

parent 05056ddc
......@@ -543,10 +543,21 @@ void DICOMAppHelper::ImagePositionPatientCallback(DICOMParser *parser,
{
// file not found, create a new entry
DICOMOrderingElements ord;
sscanf( (char*)(val), "%f\\%f\\%f",
&ord.ImagePositionPatient[0],
&ord.ImagePositionPatient[1],
&ord.ImagePositionPatient[2] );
if (val)
{
sscanf( (char*)(val), "%f\\%f\\%f",
&ord.ImagePositionPatient[0],
&ord.ImagePositionPatient[1],
&ord.ImagePositionPatient[2] );
}
else
{
// no actual position specified, default to the origin
ord.ImagePositionPatient[0] = 0.0;
ord.ImagePositionPatient[1] = 0.0;
ord.ImagePositionPatient[2] = 0.0;
}
// insert into the map
this->Implementation->SliceOrderingMap.insert(dicom_stl::pair<const dicom_stl::string, DICOMOrderingElements>(parser->GetFileName(), ord));
......@@ -557,12 +568,22 @@ void DICOMAppHelper::ImagePositionPatientCallback(DICOMParser *parser,
}
else
{
// file found, add new values
sscanf( (char*)(val), "%f\\%f\\%f",
&(*it).second.ImagePositionPatient[0],
&(*it).second.ImagePositionPatient[1],
&(*it).second.ImagePositionPatient[2] );
if (val)
{
// file found, add new values
sscanf( (char*)(val), "%f\\%f\\%f",
&(*it).second.ImagePositionPatient[0],
&(*it).second.ImagePositionPatient[1],
&(*it).second.ImagePositionPatient[2] );
}
else
{
// no actual position specified, default to the origin
(*it).second.ImagePositionPatient[0] = 0.0;
(*it).second.ImagePositionPatient[1] = 0.0;
(*it).second.ImagePositionPatient[2] = 0.0;
}
// cache the value
memcpy( this->ImagePositionPatient, (*it).second.ImagePositionPatient,
3*sizeof(float) );
......@@ -584,13 +605,26 @@ void DICOMAppHelper::ImageOrientationPatientCallback(DICOMParser *parser,
{
// file not found, create a new entry
DICOMOrderingElements ord;
sscanf( (char*)(val), "%f\\%f\\%f\\%f\\%f\\%f",
&ord.ImageOrientationPatient[0],
&ord.ImageOrientationPatient[1],
&ord.ImageOrientationPatient[2],
&ord.ImageOrientationPatient[3],
&ord.ImageOrientationPatient[4],
&ord.ImageOrientationPatient[5] );
if (val)
{
sscanf( (char*)(val), "%f\\%f\\%f\\%f\\%f\\%f",
&ord.ImageOrientationPatient[0],
&ord.ImageOrientationPatient[1],
&ord.ImageOrientationPatient[2],
&ord.ImageOrientationPatient[3],
&ord.ImageOrientationPatient[4],
&ord.ImageOrientationPatient[5] );
}
else
{
// no orientation defined, default to an standard axial orientation
ord.ImageOrientationPatient[0] = 1.0;
ord.ImageOrientationPatient[1] = 0.0;
ord.ImageOrientationPatient[2] = 0.0;
ord.ImageOrientationPatient[3] = 0.0;
ord.ImageOrientationPatient[4] = 1.0;
ord.ImageOrientationPatient[5] = 0.0;
}
// insert into the map
this->Implementation->SliceOrderingMap.insert(dicom_stl::pair<const dicom_stl::string, DICOMOrderingElements>(parser->GetFileName(), ord));
......@@ -598,13 +632,26 @@ void DICOMAppHelper::ImageOrientationPatientCallback(DICOMParser *parser,
else
{
// file found, add new values
sscanf( (char*)(val), "%f\\%f\\%f\\%f\\%f\\%f",
&(*it).second.ImageOrientationPatient[0],
&(*it).second.ImageOrientationPatient[1],
&(*it).second.ImageOrientationPatient[2],
&(*it).second.ImageOrientationPatient[3],
&(*it).second.ImageOrientationPatient[4],
&(*it).second.ImageOrientationPatient[5] );
if (val)
{
sscanf( (char*)(val), "%f\\%f\\%f\\%f\\%f\\%f",
&(*it).second.ImageOrientationPatient[0],
&(*it).second.ImageOrientationPatient[1],
&(*it).second.ImageOrientationPatient[2],
&(*it).second.ImageOrientationPatient[3],
&(*it).second.ImageOrientationPatient[4],
&(*it).second.ImageOrientationPatient[5] );
}
else
{
// no orientation defined, default to an standard axial orientation
(*it).second.ImageOrientationPatient[0] = 1.0;
(*it).second.ImageOrientationPatient[1] = 0.0;
(*it).second.ImageOrientationPatient[2] = 0.0;
(*it).second.ImageOrientationPatient[3] = 0.0;
(*it).second.ImageOrientationPatient[4] = 1.0;
(*it).second.ImageOrientationPatient[5] = 0.0;
}
}
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment