Commit ebff465f authored by Jim Miller's avatar Jim Miller
Browse files

ENH: allow sorting order to be specified

parent 5a105d43
......@@ -71,6 +71,26 @@ struct lt_pair_float_string
};
struct gt_pair_int_string
{
bool operator()(const dicom_stl::pair<int, dicom_stl::string> s1,
const dicom_stl::pair<int, dicom_stl::string> s2) const
{
return s1.first > s2.first;
}
};
struct gt_pair_float_string
{
bool operator()(const dicom_stl::pair<float, dicom_stl::string> s1,
const dicom_stl::pair<float, dicom_stl::string> s2) const
{
return s1.first > s2.first;
}
};
DICOMAppHelper::DICOMAppHelper()
{
this->BitsAllocated = 8;
......@@ -1069,7 +1089,7 @@ bool DICOMAppHelper::RescaledImageDataIsSigned()
void DICOMAppHelper::GetSliceNumberFilenamePairs(const dicom_stl::string &seriesUID,
dicom_stl::vector<dicom_stl::pair<int, dicom_stl::string> >& v)
dicom_stl::vector<dicom_stl::pair<int, dicom_stl::string> >& v, bool ascending)
{
v.clear();
......@@ -1099,15 +1119,22 @@ void DICOMAppHelper::GetSliceNumberFilenamePairs(const dicom_stl::string &series
v.push_back(p);
}
}
dicom_stl::sort(v.begin(), v.end(), lt_pair_int_string());
if (ascending)
{
dicom_stl::sort(v.begin(), v.end(), lt_pair_int_string());
}
else
{
dicom_stl::sort(v.begin(), v.end(), gt_pair_int_string());
}
}
void DICOMAppHelper::GetSliceNumberFilenamePairs(dicom_stl::vector<dicom_stl::pair<int, dicom_stl::string> >& v)
void DICOMAppHelper::GetSliceNumberFilenamePairs(dicom_stl::vector<dicom_stl::pair<int, dicom_stl::string> >& v, bool ascending)
{
// Default to using the first series
if (this->Implementation->SeriesUIDMap.size() > 0)
{
this->GetSliceNumberFilenamePairs( (*this->Implementation->SeriesUIDMap.begin()).first, v );
this->GetSliceNumberFilenamePairs( (*this->Implementation->SeriesUIDMap.begin()).first, v, ascending );
}
else
{
......@@ -1116,7 +1143,7 @@ void DICOMAppHelper::GetSliceNumberFilenamePairs(dicom_stl::vector<dicom_stl::pa
}
void DICOMAppHelper::GetSliceLocationFilenamePairs(const dicom_stl::string &seriesUID,
dicom_stl::vector<dicom_stl::pair<float, dicom_stl::string> >& v)
dicom_stl::vector<dicom_stl::pair<float, dicom_stl::string> >& v, bool ascending)
{
v.clear();
......@@ -1146,16 +1173,23 @@ void DICOMAppHelper::GetSliceLocationFilenamePairs(const dicom_stl::string &seri
v.push_back(p);
}
}
dicom_stl::sort(v.begin(), v.end(), lt_pair_float_string());
if (ascending)
{
dicom_stl::sort(v.begin(), v.end(), lt_pair_float_string());
}
else
{
dicom_stl::sort(v.begin(), v.end(), gt_pair_float_string());
}
}
void DICOMAppHelper::GetSliceLocationFilenamePairs(dicom_stl::vector<dicom_stl::pair<float, dicom_stl::string> >& v)
void DICOMAppHelper::GetSliceLocationFilenamePairs(dicom_stl::vector<dicom_stl::pair<float, dicom_stl::string> >& v, bool ascending)
{
// Default to using the first series
if (this->Implementation->SeriesUIDMap.size() > 0)
{
this->GetSliceLocationFilenamePairs( (*this->Implementation->SeriesUIDMap.begin()).first,
v );
v , ascending);
}
else
{
......@@ -1163,7 +1197,7 @@ void DICOMAppHelper::GetSliceLocationFilenamePairs(dicom_stl::vector<dicom_stl::
}
}
void DICOMAppHelper::GetImagePositionPatientFilenamePairs(const dicom_stl::string &seriesUID, dicom_stl::vector<dicom_stl::pair<float, dicom_stl::string> >& v)
void DICOMAppHelper::GetImagePositionPatientFilenamePairs(const dicom_stl::string &seriesUID, dicom_stl::vector<dicom_stl::pair<float, dicom_stl::string> >& v, bool ascending)
{
v.clear();
......@@ -1214,16 +1248,23 @@ void DICOMAppHelper::GetImagePositionPatientFilenamePairs(const dicom_stl::strin
v.push_back(p);
}
}
dicom_stl::sort(v.begin(), v.end(), lt_pair_float_string());
if (ascending)
{
dicom_stl::sort(v.begin(), v.end(), lt_pair_float_string());
}
else
{
dicom_stl::sort(v.begin(), v.end(), gt_pair_float_string());
}
}
void DICOMAppHelper::GetImagePositionPatientFilenamePairs(dicom_stl::vector<dicom_stl::pair<float, dicom_stl::string> >& v)
void DICOMAppHelper::GetImagePositionPatientFilenamePairs(dicom_stl::vector<dicom_stl::pair<float, dicom_stl::string> >& v, bool ascending)
{
// Default to using the first series
if (this->Implementation->SeriesUIDMap.size() > 0)
{
this->GetImagePositionPatientFilenamePairs( (*this->Implementation->SeriesUIDMap.begin()).first, v );
this->GetImagePositionPatientFilenamePairs( (*this->Implementation->SeriesUIDMap.begin()).first, v, ascending);
}
else
{
......
......@@ -376,30 +376,30 @@ public:
/** Get the filenames for a series ordered by slice number. */
void GetSliceNumberFilenamePairs(const dicom_stl::string &seriesUID,
dicom_stl::vector<dicom_stl::pair<int, dicom_stl::string> > &v);
dicom_stl::vector<dicom_stl::pair<int, dicom_stl::string> > &v, bool ascending = true);
/** Get the filenames for a series order by slice number. Use the
first series by default. */
void GetSliceNumberFilenamePairs(dicom_stl::vector<dicom_stl::pair<int, dicom_stl::string> > &v);
void GetSliceNumberFilenamePairs(dicom_stl::vector<dicom_stl::pair<int, dicom_stl::string> > &v, bool ascending = true);
/* Get the filenames for a series ordered by slice location. */
void GetSliceLocationFilenamePairs(const dicom_stl::string &seriesUID,
dicom_stl::vector<dicom_stl::pair<float, dicom_stl::string> > &v);
dicom_stl::vector<dicom_stl::pair<float, dicom_stl::string> > &v, bool ascending = true);
/* Get the filenames for a series ordered by slice location. Use the
* first series by default. */
void GetSliceLocationFilenamePairs(dicom_stl::vector<dicom_stl::pair<float, dicom_stl::string> > &v);
void GetSliceLocationFilenamePairs(dicom_stl::vector<dicom_stl::pair<float, dicom_stl::string> > &v, bool ascending = true);
/* Get the filenames for a series ordered by image position
patient. This is the most reliable way to order the images in a
series. */
void GetImagePositionPatientFilenamePairs(const dicom_stl::string &seriesUID,
dicom_stl::vector<dicom_stl::pair<float, dicom_stl::string> > &v);
dicom_stl::vector<dicom_stl::pair<float, dicom_stl::string> > &v, bool ascending = true);
/* Get the filenames for a series ordered by image position
patient. This is the most reliable way to order the images in a
series. Use the first series by default. */
void GetImagePositionPatientFilenamePairs(dicom_stl::vector<dicom_stl::pair<float, dicom_stl::string> > &v);
void GetImagePositionPatientFilenamePairs(dicom_stl::vector<dicom_stl::pair<float, dicom_stl::string> > &v, bool ascending = true);
float GetRescaleSlope()
{
......
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