#include <sys/types.h>
#include <errno.h>
+#include <unistd.h>
//-----------------------------------------------------------------------------
// For full DICOMDIR description, see:
// et quelle que soit la valeur de parseDir,
// on a lance gdcmParser
+ cout << "---------------------------------------------- " << Name <<endl;
+
+
+
startMethod= NULL;
progressMethod= NULL;
endMethod= NULL;
metaElems=NULL;
-// Si on passe un root directory, on est assuré de n'avoir rien ramené
+// gdcmParser already executed
+// Si on a passe un root directory, on est assuré de n'avoir rien ramené
if( GetListEntry().begin()==GetListEntry().end() )
{
// Si, en plus, parseDir == false, ca devrait etre une erreur
dbg.Verbose(0, "gdcmDicomDir::gdcmDicomDir : entry list empty");
+ if(strlen(Name)==1 && Name[0]=='.') { // user passed '.' as Name
+ // we get current directory name
+ char*dummy=(char*) malloc(1000); // TODO : check with Windoze
+ getcwd(dummy,(size_t)1000);
+ SetFileName(dummy); // will be converted into a string
+ free(dummy); // no longer needed
+ }
+
if(parseDir)
{
dbg.Verbose(0, "gdcmDicomDir::gdcmDicomDir : Parse directory and create the DicomDir");
- ParseDirectory();
+ ParseDirectory();
}
}
else
/*
* \ingroup gdcmDicomDir
* \brief This predicate, based on hopefully reasonable heuristics,
- * decides whether or not the current gdcmParser was properly parsed
+ * decides whether or not the current header was properly parsed
* and contains the mandatory information for being considered as
* a well formed and usable DicomDir.
* @return true when gdcmParser is the one of a reasonable DicomDir,
/*
* \ingroup gdcmDicomDir
- * \brief fills whole the structure
+ * \brief fills the whole structure, starting from a root Directory
*/
void gdcmDicomDir::ParseDirectory(void)
{
- CreateDicomDirChainedList(GetPath());
+ CreateDicomDirChainedList(GetFileName());
CreateDicomDir();
}
/*
* \ingroup gdcmDicomDir
* \brief Set the method to delete the argument
- * The argument is destroyed when the method is changed or when the class
- * is destroyed
+ * The argument is destroyed when the method is changed or when the
+ * class is destroyed
* @param method Method to call to delete the argument
*/
void gdcmDicomDir::SetStartMethodArgDelete(gdcmMethod *method)
/*
* \ingroup gdcmDicomDir
* \brief Set the method to delete the argument
- * The argument is destroyed when the method is changed or when the class
- * is destroyed
+ * The argument is destroyed when the method is changed or when the
+ * class is destroyed
* @param method Method to call to delete the argument
*/
void gdcmDicomDir::SetProgressMethodArgDelete(gdcmMethod *method)
WriteDicomDirEntries(fp1);
fclose(fp1);
-
return true;
}
/**
* \ingroup gdcmParser
* \brief writes on disc according to the DICOMDIR format
- * using the Chained List
- * \todo a reecrire en utilisant la structure arborescente
+ * using the tree-like structure
* @param _fp already open file pointer
*/
patients.clear();
for(gdcmDirList::iterator it=fileList.begin();
- it!=fileList.end(); ++it)
+ it!=fileList.end();
+ ++it)
{
progress=(float)(count+1)/(float)fileList.size();
CallProgressMethod();
elemList=gdcmGlobal::GetDicomDirElements()->GetDicomDirPatientElements();
std::list<gdcmHeaderEntry *>::iterator debInsertion, finInsertion, i,j;
-
-
+
debInsertion = metaElems->fin();
++debInsertion;
finInsertion=debInsertion;
return p;
}
-/*
- * \ingroup gdcmDicomDir
- * \brief Get the DicomDir path
- */
-std::string gdcmDicomDir::GetPath(void)
-{
- std::string path=GetFileName();
-
- int pos1=path.rfind("/");
- int pos2=path.rfind("\\");
- if(pos1>pos2)
- path.resize(pos1);
- else
- path.resize(pos2);
-
- return(path);
-}
/*
* \ingroup gdcmDicomDir
* \brief CallStartMethod
/*
* \ingroup gdcmDicomDir
* \brief for each Header of the chained list, add/update the Patient/Study/Serie/Image info
- * @param path
- * @param list
+ * @param path path of the root directory
+ * @param list chained list of Headers
*/
void gdcmDicomDir::SetElements(std::string &path, ListHeader &list)
{
* \ingroup gdcmDicomDir
* \brief adds to the HTable and at the end of the Chained List
* the gdcmEntries (Dicom Elements) corresponding to the given type
- * @param path file Path (only used when type = GDCM_DICOMDIR_IMAGE
+ * @param path full path file name(only used when type = GDCM_DICOMDIR_IMAGE
* @param type gdcmObject type to create (GDCM_DICOMDIR_PATIENT, GDCM_DICOMDIR_STUDY, GDCM_DICOMDIR_SERIE ...)
* @param header gdcmHeader of the current file
*/
{
tmpGr=it->group;
tmpEl=it->elem;
-
dictEntry=GetPubDict()->GetDictEntryByNumber(tmpGr,tmpEl);
entry=new gdcmHeaderEntry(dictEntry);
entry->SetOffset(0); // just to avoid missprinting
if(val==GDCM_UNFOUND)
{
- if((tmpGr==0x0004) &&(tmpEl==0x1130) )
- {
- // TODO force the *end* File Name(remove path)
- val=path;
+ if((tmpGr==0x0004) &&(tmpEl==0x1130) ) // File-set ID
+ {
+ // force to the *end* File Name
+ val=GetName(path);
}
else if( (tmpGr==0x0004) && (tmpEl==0x1500) ) // Only used for image
{
dbg.Verbose(0, "gdcmDicomDir::SetElement : the base path of file name is incorrect");
val=header->GetFileName();
}
- else
- val=&(header->GetFileName()[path.length()]);
+ else {
+ val=&(header->GetFileName().c_str()[path.length()]);
+ }
}
else
{
{
if(dictEntry->GetGroup()==0xfffe)
{
- entry->SetLength(entry->GetValue().length()); //JPR
+ entry->SetLength(entry->GetValue().length());
}
else if( (dictEntry->GetVR()=="UL") || (dictEntry->GetVR()=="SL") )
{
return(str);
}
+
+///////////////////////////////////////////////////////////////////////////
+/*
+ * \brief Add a SEPARATOR to the end of the name is necessary
+ * @param
+ */
+void NormalizePath(std::string &name)
+{
+const char SEPARATOR_X = '/';
+const char SEPARATOR_WIN = '\\';
+const std::string SEPARATOR = "/";
+ int size=name.size();
+ if((name[size-1]!=SEPARATOR_X)&&(name[size-1]!=SEPARATOR_WIN))
+ {
+ name+=SEPARATOR;
+ }
+}
+
+///////////////////////////////////////////////////////////////////////////
+/*
+ * \brief Get the (directory) path from a full path file name
+ */
+std::string GetPath(std::string fullName)
+{
+ int pos1=fullName.rfind("/");
+ int pos2=fullName.rfind("\\");
+ if(pos1>pos2)
+ fullName.resize(pos1);
+ else
+ fullName.resize(pos2);
+ return(fullName);
+}
+
+///////////////////////////////////////////////////////////////////////////
+/*
+ * \brief Get the (last) name of a full path file name
+ */
+std::string GetName(std::string fullName)
+{
+ int fin=fullName.length()-1;
+ char a =fullName.c_str()[fin];
+ if (a == '/' || a == '\\') {
+ fin--;
+ }
+ int deb;
+ for (int i=fin;i!=0;i--) {
+ if (fullName.c_str()[i] == '/' || fullName.c_str()[i] == '\\')
+ break;
+ deb = i;
+ }
+ std::string lastName;
+ for (int i=deb;i<fin+1;i++)
+ lastName=lastName+fullName.c_str()[i];
+ return(lastName);
+}