BOOL CDcmAssit::MultibmpConvertToDCM(
const char * filename ,
const char *
outputfilename )
{
OFCondition status;
DcmFileFormat fileformat;
DcmDataset* mydatasete=
fileformat.getDataset();
DicomUtils::AddDicomElements((DcmDataset*&
)mydatasete);
Uint16 rows,cols,samplePerPixel,bitsAlloc,bitsStored,highBit,pixelRpr,planConf,pixAspectH,pixAspectV;
OFString photoMetrInt;
Uint32 length;
E_TransferSyntax ts;
char* mydata=
new char[
1024*
1024*
10];
memset(mydata,0,
sizeof(
char)*
1024*
1024*
10);
char* tmpData=
mydata;
//拆分文件名
OFList<OFString>
inputFiles;
if(filename !=
NULL)
{
char * bufFileNames =
new char[strlen(filename)+
1];
strcpy_s(bufFileNames,strlen(filename)+
1,filename);
char * p1,*
p2;
p1 = p2=
bufFileNames;
while(
1)
{
p1 = strchr(p2,
'|');
if(p1 !=
NULL)
{
*p1=
'\0';
inputFiles.push_back(p2);
p2 = ++
p1;
}
else
{
inputFiles.push_back(p2);
break;
}
}
delete[] bufFileNames;
}
OFListIterator(OFString) if_iter =
inputFiles.begin();
OFListIterator(OFString) if_last =
inputFiles.end();
OFBool ignoreName;
const char * currentfilename =
NULL;
while (if_iter !=
if_last)
{
ignoreName =
OFFalse;
currentfilename = (*
if_iter).c_str();
if (OFStandard::fileExists(currentfilename))
{
OFString offilename = (*
if_iter).c_str();
I2DBmpSource* bmpSource=
new I2DBmpSource();
bmpSource->
setImageFile(offilename);
char *pixData =
NULL;
bmpSource->
readPixelData(rows,cols,samplePerPixel,photoMetrInt,bitsAlloc,bitsStored,highBit,pixelRpr,planConf,pixAspectH,pixAspectV,pixData,length,ts);
memcpy(tmpData,pixData,length);
tmpData+=
length;
delete bmpSource;
}
++
if_iter;
}
mydatasete->
putAndInsertUint16(DCM_SamplesPerPixel,samplePerPixel);
mydatasete->putAndInsertString(DCM_NumberOfFrames,
"4");
mydatasete->
putAndInsertUint16(DCM_Rows,rows);
mydatasete->
putAndInsertUint16(DCM_Columns,cols);
mydatasete->
putAndInsertUint16(DCM_BitsAllocated,bitsAlloc);
mydatasete->
putAndInsertUint16(DCM_BitsStored,bitsStored);
mydatasete->
putAndInsertUint16(DCM_HighBit,highBit);
mydatasete->putAndInsertUint8Array(DCM_PixelData,(Uint8*)mydata,
4*
length);
mydatasete->
putAndInsertOFStringArray(DCM_PhotometricInterpretation,photoMetrInt);
mydatasete->putAndInsertUint16(DCM_PlanarConfiguration,
0);
status=
fileformat.saveFile(outputfilename,ts);
if(status.bad())
{
return FALSE;
}
return TRUE;
}
void DicomUtils::AddDicomElements(DcmDataset*&
dataset)
{
//构建测试数据
/* 添加患者信息 */
dataset->putAndInsertUint16(DCM_AccessionNumber,
0);
dataset->putAndInsertString(DCM_PatientName,
"zssure",
true);
dataset->putAndInsertString(DCM_PatientID,
"2234");
dataset->putAndInsertString(DCM_PatientBirthDate,
"20141221");
dataset->putAndInsertString(DCM_PatientSex,
"M");
/* 添加Study信息 */
dataset->putAndInsertString(DCM_StudyDate,
"20141221");
dataset->putAndInsertString(DCM_StudyTime,
"195411");
char uid[
100];
dcmGenerateUniqueIdentifier(uid,SITE_STUDY_UID_ROOT);
dataset->
putAndInsertString(DCM_StudyInstanceUID,uid);
dataset->putAndInsertString(DCM_StudyID,
"1111");
/* 添加Series信息 */
dataset->putAndInsertString(DCM_SeriesDate,
"20141221");
dataset->putAndInsertString(DCM_SeriesTime,
"195411");
memset(uid,0,
sizeof(
char)*
100);
dcmGenerateUniqueIdentifier(uid,SITE_SERIES_UID_ROOT);
dataset->
putAndInsertString(DCM_SeriesInstanceUID,uid);
/* 添加Image信息 */
dataset->putAndInsertString(DCM_ImageType,
"ORIGINAL\PRIMARY\AXIAL");
dataset->putAndInsertString(DCM_ContentDate,
"20141221");
dataset->putAndInsertString(DCM_ContentTime,
"200700");
dataset->putAndInsertString(DCM_InstanceNumber,
"1");
dataset->putAndInsertString(DCM_SamplesPerPixel,
"1");
dataset->putAndInsertString(DCM_PhotometricInterpretation,
"MONOCHROME2");
dataset->putAndInsertString(DCM_PixelSpacing,
"0.3\0.3");
dataset->putAndInsertString(DCM_BitsAllocated,
"16");
dataset->putAndInsertString(DCM_BitsStored,
"16");
dataset->putAndInsertString(DCM_HighBit,
"15");
dataset->putAndInsertString(DCM_WindowCenter,
"600");
dataset->putAndInsertString(DCM_WindowWidth,
"800");
dataset->putAndInsertString(DCM_RescaleIntercept,
"0");
dataset->putAndInsertString(DCM_RescaleSlope,
"1");
}
转载于:https://www.cnblogs.com/luyuxibaby/p/5217246.html
相关资源:各显卡算力对照表!