#include <boost/filesystem/operations.hpp>
#ifndef PATH_MAX // If not defined yet : do it
- #define PATH_MAX 2048
+ #define PATH_MAX 2048
#endif
BrukerFieldData b_name=br_subject.GetFieldData("SUBJECT_name_string");
std::string subject_name = b_name.GetStringValue()[0];
- strPatientName = subject_name;
+ strPatientName = subject_name;
cleanString(subject_name);
-
+
BrukerFieldData b_entry=br_subject.GetFieldData("SUBJECT_entry");
std::string subject_entry = b_entry.GetStringValue()[0];
//cleanString(subject_entry);
- subject_entry = subject_entry.substr(11, subject_entry.size()-11);
-
+ subject_entry = subject_entry.substr(11, subject_entry.size()-11);
+
BrukerFieldData b_position=br_subject.GetFieldData("SUBJECT_position");
std::string subject_position = b_position.GetStringValue()[0];
//cleanString(subject_position);
- subject_position = subject_position.substr(9, subject_position.size()-9);
-
+ subject_position = subject_position.substr(9, subject_position.size()-9);
+
BrukerFieldData b_date=br_subject.GetFieldData("SUBJECT_date");
std::string subject_date = b_date.GetStringValue()[0];
- strStudyTimeDate = subject_date;
+ strStudyTimeDate = subject_date;
cleanString(subject_date);
-
+
BrukerFieldData b_study_name=br_subject.GetFieldData("SUBJECT_study_name");
std::string subject_study_name = b_study_name.GetStringValue()[0];
- subject_study_name = subject_study_name.substr(1, subject_study_name.size()-2);
+ subject_study_name = subject_study_name.substr(1, subject_study_name.size()-2);
cleanString(subject_date);
-
- strStudyDescr = subject_name + "." + subject_study_name + "." + subject_entry + "." + subject_position + "." + subject_date;
+
+ // subject_name is already in 'Patient Name'
+ strStudyDescr = /*subject_name + "." + */ subject_study_name + "." + subject_entry + "." + subject_position + "." + subject_date;
char outputDirName[(unsigned int) PATH_MAX+2];
strStudyUID = GDCM_NAME_SPACE::Util::CreateUniqueUID();
-
+ serieNumber = 0;
// -----------------------------------------------------
// Iterate to ALL the objets(files/directories) found in the input directory
// (this is level ZERO)
nbSlices = b_list_size.GetIntValue()[0];
strSerieDescr = GDCM_NAME_SPACE::Util::GetName(*it)
- + "." + acqp_protocol_location
+ /* + "." + acqp_protocol_location */ // always the same (in each acquisition)
+ "." + acqp_scan_name
+ "." + acqp_method.c_str();
sprintf(outputDirName, "%s%c%s", OutputDirName.c_str(),
GDCM_NAME_SPACE::GDCM_FILESEPARATOR,
strSerieDescr.c_str() );
-
+
std::cout << " ================================================================================\n"
- << " === [" << GDCM_NAME_SPACE::Util::GetName(*it) << "] -> [" << strSerieDescr << "]\n"
+ << " === [" << GDCM_NAME_SPACE::Util::GetName(*it) << "] -> [" << strSerieDescr << "]\n"
<< " ================================================================================"
<< std::endl;
-/*
- std::cout << " ================================================================================\n"
- << " ========================= [" << GDCM_NAME_SPACE::Util::GetName(*it).c_str()
- << acqp_protocol_location.c_str()
- << acqp_scan_name.c_str()
- << acqp_method.c_str()
- << "]\n"
- << " ================================================================================"
- << std::endl;
-*/
+
if (verbose)
printf ("outputDirName [%s]\n", outputDirName);
// ---------------------------
imageSet = CreateImageSet ( );
+ serieNumber++;
strSerieUID = GDCM_NAME_SPACE::Util::CreateUniqueUID();
if (nbInstants==1) // creer un seul fichier .mhd pour toutes les Slices! (images natives)
{
fwrite( buffer_2dseq, NX*NY*pixelSize, nbSlices, fp);
}
fclose(fp);
+ serieNumber ++;
strSerieUID = GDCM_NAME_SPACE::Util::CreateUniqueUID();
} // end if mhd
if (dicom)
day,
strStudyUID,
strSerieUID,
- strStudyDescr,
+ strStudyDescr,
strSerieDescr,
- strStudyTimeDate,
+ strStudyTimeDate,
0,// index frame number
GDCM_NAME_SPACE::UNMODIFIED_PIXELS_IMAGE
);
k = 0;
for (sliceNb=0; sliceNb<nbSlices; sliceNb++)
{
- if (mhd)
- {
+ if (mhd)
+ {
sprintf(outputMhdFileName, "%s%cMhdData_%03d.mhd", currentOutputMhdDirName,
GDCM_NAME_SPACE::GDCM_FILESEPARATOR, k );
if (verbose)
fclose(fp);
// std::cout << "end writting[" << output2dseqSliceFileName << "]" << std::endl;
} // end if mhd
-
- if (dicom)
- {
+
+ if (dicom)
+ {
// desperate try !
- /*
+ /*
sprintf(output2dseqSliceFileName, "%sdummy_buffer",
currentOutputDirName.c_str(), GDCM_NAME_SPACE::GDCM_FILESEPARATOR);
fp=fopen(output2dseqSliceFileName, "wb");
1, fp);
}
fclose(fp);
-
+
fp=fopen(output2dseqSliceFileName, "rb");
if (!fp)
{
std::cout << "Cannot open [" << output2dseqSliceFileName << "] for reading" << std::endl;
exit (0);
- }
+ }
fread( pixelsForCurrentSlice,
frameSize*nbInstants,
1, fp);
fclose(fp);
// end of desperate try !
- */
+ */
/* ----------- Write Dicom Image ---------------*/
-
- int frameSize = NX*NY*pixelSize;
+
+ int frameSize = NX*NY*pixelSize;
for (instantNb=0; instantNb<nbInstants; instantNb++)
{
memcpy(pixelsForCurrentSlice + frameSize*instantNb, buffer_2dseq +(nbSlices*instantNb + sliceNb)*frameSize, frameSize);
day,
strStudyUID,
strSerieUID,
- strStudyDescr,
+ strStudyDescr,
strSerieDescr,
- strStudyTimeDate,
+ strStudyTimeDate,
sliceNb*nbInstants,
GDCM_NAME_SPACE::UNMODIFIED_PIXELS_IMAGE
);
if (verbose)
std::cout << "--- Output DCM file [" << output2dseqSliceFileName << "]" << std::endl;
- } // en if dicom
+ } // en if dicom
k++;
}
void Bruker2Dicom::dealWithCarto(GDCM_NAME_SPACE::DirListType &fileNames, int NX, int NY, int nbSlices,
double fovX, double fovY, double sliceDistance,
char *copyFile, std::string ¤tOutputDirName,
- char *outputMhdFileName, char *output2dseqCartoName)
+ char *outputMhdFileName, char *output2dseqCartoName)
{
// -----------------------------------------------------
// deal with MatLab-generated Carto file.
<< NX*NY*sizeof(double)*nbSlices << std::endl;
std::string lastFileName = GDCM_NAME_SPACE::Util::GetName((*it).c_str());
if (mhd)
- {
+ {
// Copy the data file in the new directory
sprintf(copyFile, "cp %s %s%c%s", (*it).c_str() ,
currentOutputDirName.c_str(),GDCM_NAME_SPACE::GDCM_FILESEPARATOR, lastFileName.c_str());
fclose(fp);
}
if (verbose)
- std::cout << "--- end write Carto MHD file [" << outputMhdFileName << "]" << std::endl;
+ std::cout << "--- end write Carto MHD file [" << outputMhdFileName << "]" << std::endl;
} // end if mhd
// ----------- Write Dicom Image ---------------
if (dicom)
- {
+ {
sprintf(output2dseqCartoName, "%s%c%s%s",
currentOutputDirName.c_str(),GDCM_NAME_SPACE::GDCM_FILESEPARATOR, lastFileName.c_str(), ".dcm" );
if (verbose)
- std::cout << "--- end create name output2dseqCartoName file [" << output2dseqCartoName << "]" << std::endl;
+ std::cout << "--- end create name output2dseqCartoName file [" << output2dseqCartoName << "]" << std::endl;
strSerieUID = GDCM_NAME_SPACE::Util::CreateUniqueUID(); //New SerieUID for each carto.
std::string strNewSerieDescr(strSerieDescr+ "_" +GDCM_NAME_SPACE::Util::GetName((*it).c_str()));
day,
strStudyUID,
strSerieUID,
- strStudyDescr,
+ strStudyDescr,
strNewSerieDescr,
- strStudyTimeDate,
+ strStudyTimeDate,
0,
GDCM_NAME_SPACE::CREATED_IMAGE
);
delete [] buffer_carto;
if (verbose)
- std::cout << "--- End writing Carto DICOM file [" << output2dseqCartoName << "]" << std::endl;
+ std::cout << "--- End writing Carto DICOM file [" << output2dseqCartoName << "]" << std::endl;
break; // don't check for more ident on same file name!
- }
+ }
icode++;
}
}
if (verbose)
std::cout << "Check for output directory :[" << OutputDirName << "]."
- <<std::endl;
+ <<std::endl;
if ( ! boost::filesystem::is_directory(OutputDirName) ) // dirout not found
{
std::string strDirNameout(OutputDirName); // to please gcc 4
std::string &serieUID,
std::string &studyDescr,
std::string &serieDescr,
- std::string &strStudyTimeDate,
+ std::string &strStudyTimeDate,
int imgNum,
GDCM_NAME_SPACE::ImageContentType contentType
)