#include <gdcmSerieHelper.h>
Public Types | |
| typedef std::map< std::string, GdcmFileList * > | CoherentFileListmap |
| typedef std::vector< File * > | GdcmFileVector |
Public Member Functions | |
| SerieHelper () | |
| Constructor from a given SerieHelper. | |
| ~SerieHelper () | |
| Canonical destructor. | |
| void | Print (std::ostream &os=std::cout, std::string const &indent="") |
| Canonical printer. | |
| void | AddFileName (std::string const &filename) |
| add a gdcm::File to the list corresponding to its Serie UID | |
| void | SetDirectory (std::string const &dir, bool recursive=false) |
| Sets the root Directory. | |
| void | OrderGdcmFileList (GdcmFileList *CoherentGdcmFileList) |
| Sorts the given File List. | |
| const GdcmFileList & | GetGdcmFileList () |
| Gets the FIRST *coherent* File List. Deprecated; kept not to break the API. | |
| GdcmFileList * | GetFirstCoherentFileList () |
| Get the first List while visiting the CoherentFileListHT. | |
| GdcmFileList * | GetNextCoherentFileList () |
| Get the next List while visiting the CoherentFileListHT. | |
| GdcmFileList * | GetCoherentFileList (std::string SerieUID) |
| Get the Coherent Files list according to its Serie UID. | |
Private Member Functions | |
| bool | ImagePositionPatientOrdering (GdcmFileList *CoherentGdcmFileList) |
| sorts the images, according to their Patient Position We may order, considering : -Image Position Patient -Image Number -More to come :-) | |
| bool | ImageNumberOrdering (GdcmFileList *CoherentGdcmFileList) |
| sorts the images, according to their Image Number | |
| bool | FileNameOrdering (GdcmFileList *CoherentGdcmFileList) |
| sorts the images, according to their File Name | |
Static Private Member Functions | |
| bool | ImageNumberLessThan (File *file1, File *file2) |
| bool | FileNameLessThan (File *file1, File *file2) |
Private Attributes | |
| CoherentFileListmap | CoherentGdcmFileListHT |
| CoherentFileListmap::iterator | ItListHt |
Definition at line 41 of file gdcmSerieHelper.h.
|
|
Definition at line 44 of file gdcmSerieHelper.h. |
|
|
Definition at line 45 of file gdcmSerieHelper.h. Referenced by ImagePositionPatientOrdering(). |
|
|
Constructor from a given SerieHelper.
Definition at line 36 of file gdcmSerieHelper.cxx. References gdcm::GdcmFileList, GetFirstCoherentFileList(), and GetNextCoherentFileList().
00037 {
00038 // For all the File lists of the gdcm::Serie
00039 GdcmFileList *l = GetFirstCoherentFileList();
00040 while (l)
00041 {
00042 // For all the files of a File list
00043 for (GdcmFileList::iterator it = l->begin();
00044 it != l->end();
00045 ++it)
00046 {
00047 delete *it;
00048 }
00049 l->clear();
00050 delete l;;
00051 l = GetNextCoherentFileList();
00052 }
00053 }
|
|
|
Canonical destructor.
Definition at line 58 of file gdcmSerieHelper.cxx. References gdcm::GdcmFileList, GetFirstCoherentFileList(), and GetNextCoherentFileList().
00059 {
00060 // For all the Coherent File lists of the gdcm::Serie
00061 GdcmFileList *l = GetFirstCoherentFileList();
00062 while (l)
00063 {
00064 // For all the files of a Coherent File list
00065 for (GdcmFileList::iterator it = l->begin();
00066 it != l->end();
00067 ++it)
00068 {
00069 delete *it;
00070 }
00071 l->clear();
00072 delete l;
00073 l = GetNextCoherentFileList();
00074 }
00075 }
|
|
|
add a gdcm::File to the list corresponding to its Serie UID
Definition at line 86 of file gdcmSerieHelper.cxx. References CoherentGdcmFileListHT, gdcm::GdcmFileList, gdcmWarningMacro, gdcm::DocEntrySet::GetEntryValue(), and gdcm::File::IsReadable(). Referenced by SetDirectory().
00087 {
00088 //directly use string and not const char*:
00089 File *header = new File( filename );
00090 if( header->IsReadable() )
00091 {
00092 // 0020 000e UI REL Series Instance UID
00093 std::string uid = header->GetEntryValue (0x0020, 0x000e);
00094 // if uid == GDCM_UNFOUND then consistently we should find GDCM_UNFOUND
00095 // no need here to do anything special
00096
00097 if ( CoherentGdcmFileListHT.count(uid) == 0 )
00098 {
00099 gdcmWarningMacro(" New Serie UID :[" << uid << "]");
00100 // create a std::list in 'uid' position
00101 CoherentGdcmFileListHT[uid] = new GdcmFileList;
00102 }
00103 // Current Serie UID and DICOM header seems to match add the file:
00104 CoherentGdcmFileListHT[uid]->push_back( header );
00105 }
00106 else
00107 {
00108 gdcmWarningMacro("Could not read file: " << filename );
00109 delete header;
00110 }
00111 }
|
|
||||||||||||
|
Definition at line 365 of file gdcmSerieHelper.cxx. References gdcm::Document::GetFileName().
00366 {
00367 return file1->GetFileName() < file2->GetFileName();
00368 }
|
|
|
sorts the images, according to their File Name
Definition at line 375 of file gdcmSerieHelper.cxx. References gdcm::GdcmFileList. Referenced by OrderGdcmFileList().
00376 {
00377 std::sort(fileList->begin(), fileList->end(), SerieHelper::FileNameLessThan);
00378 return true;
00379 }
|
|
|
Get the Coherent Files list according to its Serie UID.
Definition at line 184 of file gdcmSerieHelper.cxx. References CoherentGdcmFileListHT, and gdcm::GdcmFileList.
00185 {
00186 if ( CoherentGdcmFileListHT.count(SerieUID) == 0 )
00187 return 0;
00188 return CoherentGdcmFileListHT[SerieUID];
00189 }
|
|
|
Get the first List while visiting the CoherentFileListHT.
Definition at line 156 of file gdcmSerieHelper.cxx. References CoherentGdcmFileListHT, gdcm::GdcmFileList, and ItListHt. Referenced by SerieHelper(), and ~SerieHelper().
00157 {
00158 ItListHt = CoherentGdcmFileListHT.begin();
00159 if( ItListHt != CoherentGdcmFileListHT.end() )
00160 return ItListHt->second;
00161 return NULL;
00162 }
|
|
|
Gets the FIRST *coherent* File List. Deprecated; kept not to break the API.
Definition at line 60 of file gdcmSerieHelper.h. References gdcm::GdcmFileList.
00060 { return
00061 *CoherentGdcmFileListHT.begin()->second; }
|
|
|
Get the next List while visiting the CoherentFileListHT.
Definition at line 169 of file gdcmSerieHelper.cxx. References CoherentGdcmFileListHT, gdcmAssertMacro, gdcm::GdcmFileList, and ItListHt. Referenced by SerieHelper(), and ~SerieHelper().
00170 {
00171 gdcmAssertMacro (ItListHt != CoherentGdcmFileListHT.end());
00172
00173 ++ItListHt;
00174 if ( ItListHt != CoherentGdcmFileListHT.end() )
00175 return ItListHt->second;
00176 return NULL;
00177 }
|
|
||||||||||||
|
Definition at line 328 of file gdcmSerieHelper.cxx. References gdcm::File::GetImageNumber().
00329 {
00330 return file1->GetImageNumber() < file2->GetImageNumber();
00331 }
|
|
|
sorts the images, according to their Image Number
Definition at line 341 of file gdcmSerieHelper.cxx. References gdcm::GdcmFileList. Referenced by OrderGdcmFileList().
00342 {
00343 int min, max, pos;
00344 int n = fileList->size();
00345
00346 GdcmFileList::const_iterator it = fileList->begin();
00347 min = max = (*it)->GetImageNumber();
00348
00349 for (; it != fileList->end(); ++it, ++n)
00350 {
00351 pos = (*it)->GetImageNumber();
00352 min = (min < pos) ? min : pos;
00353 max = (max > pos) ? max : pos;
00354 }
00355
00356 // Find out if image numbers are coherent (consecutive)
00357 if( min == max || max == 0 || max >= (n+min))
00358 return false;
00359
00360 std::sort(fileList->begin(), fileList->end(), SerieHelper::ImageNumberLessThan );
00361
00362 return true;
00363 }
|
|
|
sorts the images, according to their Patient Position We may order, considering : -Image Position Patient -Image Number -More to come :-)
Definition at line 205 of file gdcmSerieHelper.cxx. References gdcm::GdcmFileList, GdcmFileVector, and gdcmWarningMacro. Referenced by OrderGdcmFileList().
00207 {
00208 //iop is calculated based on the file file
00209 float cosines[6];
00210 float normal[3];
00211 float ipp[3];
00212 float dist;
00213 float min = 0, max = 0;
00214 bool first = true;
00215 int n=0;
00216 std::vector<float> distlist;
00217
00219 for ( GdcmFileList::const_iterator
00220 it = fileList->begin();
00221 it != fileList->end(); ++it )
00222 {
00223 if( first )
00224 {
00225 (*it)->GetImageOrientationPatient( cosines );
00226
00227 // You only have to do this once for all slices in the volume. Next,
00228 // for each slice, calculate the distance along the slice normal
00229 // using the IPP tag ("dist" is initialized to zero before reading
00230 // the first slice) :
00231 normal[0] = cosines[1]*cosines[5] - cosines[2]*cosines[4];
00232 normal[1] = cosines[2]*cosines[3] - cosines[0]*cosines[5];
00233 normal[2] = cosines[0]*cosines[4] - cosines[1]*cosines[3];
00234
00235 ipp[0] = (*it)->GetXOrigin();
00236 ipp[1] = (*it)->GetYOrigin();
00237 ipp[2] = (*it)->GetZOrigin();
00238
00239 dist = 0;
00240 for ( int i = 0; i < 3; ++i )
00241 {
00242 dist += normal[i]*ipp[i];
00243 }
00244
00245 if( dist == 0 )
00246 {
00247 return false;
00248 }
00249
00250 distlist.push_back( dist );
00251
00252 max = min = dist;
00253 first = false;
00254 }
00255 else
00256 {
00257 ipp[0] = (*it)->GetXOrigin();
00258 ipp[1] = (*it)->GetYOrigin();
00259 ipp[2] = (*it)->GetZOrigin();
00260
00261 dist = 0;
00262 for ( int i = 0; i < 3; ++i )
00263 {
00264 dist += normal[i]*ipp[i];
00265 }
00266
00267 if( dist == 0 )
00268 {
00269 return false;
00270 }
00271
00272 distlist.push_back( dist );
00273
00274 min = (min < dist) ? min : dist;
00275 max = (max > dist) ? max : dist;
00276 }
00277 ++n;
00278 }
00279
00280 // Then I order the slices according to the value "dist". Finally, once
00281 // I've read in all the slices, I calculate the z-spacing as the difference
00282 // between the "dist" values for the first two slices.
00283 GdcmFileVector CoherentGdcmFileVector(n);
00284 // CoherentGdcmFileVector.reserve( n );
00285 CoherentGdcmFileVector.resize( n );
00286 // gdcmAssertMacro( CoherentGdcmFileVector.capacity() >= n );
00287
00288 float step = (max - min)/(n - 1);
00289 int pos;
00290 n = 0;
00291
00292 //VC++ don't understand what scope is !! it -> it2
00293 for (GdcmFileList::const_iterator it2 = fileList->begin();
00294 it2 != fileList->end(); ++it2, ++n)
00295 {
00296 //2*n sort algo !!
00297 //Assumption: all files are present (no one missing)
00298 pos = (int)( fabs( (distlist[n]-min)/step) + .5 );
00299
00300 // a Dicom 'Serie' may contain scout views
00301 // and images may have differents directions
00302 // -> More than one may have the same 'pos'
00303 // Sorting has then NO meaning !
00304 if (CoherentGdcmFileVector[pos]==NULL)
00305 CoherentGdcmFileVector[pos] = *it2;
00306 else
00307 {
00308 gdcmWarningMacro( "2 files same position");
00309 return false;
00310 }
00311 }
00312
00313 fileList->clear(); // doesn't delete list elements, only node
00314
00315 //VC++ don't understand what scope is !! it -> it3
00316 for (GdcmFileVector::const_iterator it3 = CoherentGdcmFileVector.begin();
00317 it3 != CoherentGdcmFileVector.end(); ++it3)
00318 {
00319 fileList->push_back( *it3 );
00320 }
00321
00322 distlist.clear();
00323 CoherentGdcmFileVector.clear();
00324
00325 return true;
00326 }
|
|
|
Sorts the given File List.
Definition at line 136 of file gdcmSerieHelper.cxx. References FileNameOrdering(), gdcm::GdcmFileList, ImageNumberOrdering(), and ImagePositionPatientOrdering().
00137 {
00138 if( ImagePositionPatientOrdering( CoherentGdcmFileList ) )
00139 {
00140 return ;
00141 }
00142 else if( ImageNumberOrdering(CoherentGdcmFileList ) )
00143 {
00144 return ;
00145 }
00146 else
00147 {
00148 FileNameOrdering(CoherentGdcmFileList );
00149 }
00150 }
|
|
||||||||||||
|
Canonical printer.
Definition at line 386 of file gdcmSerieHelper.cxx. References CoherentGdcmFileListHT, and gdcmWarningMacro.
00387 {
00388 // For all the Coherent File lists of the gdcm::Serie
00389 CoherentFileListmap::iterator itl = CoherentGdcmFileListHT.begin();
00390 if ( itl == CoherentGdcmFileListHT.end() )
00391 {
00392 gdcmWarningMacro( "No Coherent File list found" );
00393 return;
00394 }
00395 while (itl != CoherentGdcmFileListHT.end())
00396 {
00397 os << "Serie UID :[" << itl->first << "]" << std::endl;
00398
00399 // For all the files of a Coherent File list
00400 for (GdcmFileList::iterator it = (itl->second)->begin();
00401 it != (itl->second)->end();
00402 ++it)
00403 {
00404 os << indent << " --- " << (*it)->GetFileName() << std::endl;
00405 }
00406 ++itl;
00407 }
00408 }
|
|
||||||||||||
|
Sets the root Directory.
Definition at line 118 of file gdcmSerieHelper.cxx. References AddFileName(), gdcm::DirListType, and gdcm::DirList::GetFilenames().
00119 {
00120 DirList dirList(dir, recursive); // OS specific
00121
00122 DirListType filenames_list = dirList.GetFilenames();
00123 for( DirListType::const_iterator it = filenames_list.begin();
00124 it != filenames_list.end(); ++it)
00125 {
00126 AddFileName( *it );
00127 }
00128 }
|
|
|
Definition at line 74 of file gdcmSerieHelper.h. Referenced by AddFileName(), GetCoherentFileList(), GetFirstCoherentFileList(), GetNextCoherentFileList(), and Print(). |
|
|
Definition at line 75 of file gdcmSerieHelper.h. Referenced by GetFirstCoherentFileList(), and GetNextCoherentFileList(). |
1.3.6