⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 lxdcmfileout.cpp.svn-base

📁 dicom 文件读写
💻 SVN-BASE
字号:
#include "LXDcmFileOut.hpp"
#include "LXDcmIodXray.hpp"
#include "LXDcmUtil.hpp"
#include "LXDcmImage.hpp"
#include <stdio.h>
#include <algorithm>


CLXDcmFileOut::CLXDcmFileOut()
{

}

bool CLXDcmFileOut::Save( const char* fileName )
{
	FILE *fp=fopen(fileName,"wb");
	if(fp==NULL)
	{
		return false;
	}		
	char *tmpData=new char[128+4];
	memset(tmpData,0,128);
	tmpData[128]='D';
	tmpData[129]='I';
	tmpData[130]='C';
	tmpData[131]='M';
	fwrite(tmpData,sizeof(char),132,fp);
	FillMetaHeader();
	if( (!m_hasImage) || (!m_hasDataset))
	{
		return false;
	}

	std::sort(m_EleList.begin(),m_EleList.end());
	for(unsigned int i=0;i<m_EleList.size();i++)
	{	
		m_EleList.at(i).Write(fp);
	}
	fclose(fp);
	return true;
}

void CLXDcmFileOut::FillMetaHeader()
{
	InsertStringVR(DCM_TransferSyntaxUID,UID_LittleEndianExplicitTransferSyntax,(new CLXDcmVR("UI")));
	InsertUint16(DCM_FileMetaInformationVersion,0x0001,(new CLXDcmVR("OB")));
	InsertUint16(DCM_MetaElementGroupLength,0x00c2,(new CLXDcmVR("UL")));

	InsertStringVR(DCM_ImplementationVersionName,"test this version name",(new CLXDcmVR("SH")));

	char uid[128];
	InsertStringVR(DCM_SOPInstanceUID,CLXDcmUtil::GenerateUniqueIdentifier(uid,SITE_INSTANCE_UID_ROOT)); 
	InsertStringVR(DCM_MediaStorageSOPClassUID,UID_MultiframeTrueColorSecondaryCaptureImageStorage,(new CLXDcmVR("UI")));
	InsertStringVR(DCM_MediaStorageSOPInstanceUID,CLXDcmUtil::GenerateUniqueIdentifier(uid,SITE_INSTANCE_UID_ROOT),(new CLXDcmVR("UI")));
	InsertStringVR(DCM_ImplementationClassUID,CLXDcmUtil::GenerateUniqueIdentifier(uid,SITE_INSTANCE_UID_ROOT),(new CLXDcmVR("UI")));

	//InsertString(DCM_UID,UID_MultiframeTrueColorSecondaryCaptureImageStorage);//other tag

}


bool CLXDcmFileOut::AddImage(lstuint16 width,lstuint16 height,lstuint16 depth,lstuint16 channel,lstuint8 *data)
{

	lstuint16 numBytes=depth*channel/8;
	InsertStringNormal(DCM_PhotometricInterpretation,"RGB"); 
	InsertUint16(DCM_SamplesPerPixel,numBytes);
	InsertUint16(DCM_BitsAllocated,depth);
	InsertUint16(DCM_BitsStored,depth); 
	InsertUint16(DCM_HighBit,7);
	InsertUint16(DCM_PixelRepresentation,0);
	InsertUint16(DCM_PlanarConfiguration,0);
	InsertUint16(DCM_Rows,height);
	InsertUint16(DCM_Columns,width);

	if(numBytes>0)
	{
		m_hasImage=true;
	}
	InsertUint8Array(DCM_PixelData,data,width*height*numBytes);//有可能出错,待检测
	return true;
}

bool CLXDcmFileOut::AddImage( CLXDcmImage& image ) //to do:auto
{
	switch (image.m_imageType)
	{
	case LX_RGB:
		InsertStringVR(DCM_PhotometricInterpretation,"RGB"); 
		break;
	case LX_CMYK:
		InsertStringVR(DCM_PhotometricInterpretation,"CMYK"); 
		break;
		//...

	}
	InsertUint16(DCM_SamplesPerPixel,image.m_numBytes);
	InsertUint16(DCM_Rows,image.m_heith);
	InsertUint16(DCM_Columns,image.m_width);
	InsertUint8Array(DCM_PixelData,(lstuint8*)image.m_data,image.m_width*image.m_heith*image.m_numBytes);
	InsertUint16(DCM_BitsAllocated,8);
	InsertUint16(DCM_BitsStored,8); 
	InsertUint16(DCM_HighBit,7);
	InsertUint16(DCM_PixelRepresentation,0);
	InsertUint16(DCM_PlanarConfiguration,0);

	m_hasImage=true;
	return true;

}
bool CLXDcmFileOut::AddInformation(CLXDcmIodXray& dataset)
{

	LX_STUDYIMAGEINFO* sii=dataset.GetstudyImageInfo();
	if(sii)
	{
		lstuint16 windowWidth=sii->nWindow;
		lstuint16 windowCenter=sii->nLevel;
		InsertUint16(DCM_WindowWidth,windowWidth);
		InsertUint16(DCM_WindowCenter,windowCenter);
	}

	LX_STUDYINFO*	si=dataset.GetStudyInfo();
	if (si)
	{
		InsertUint16(DCM_PatientID,si->nPatientID);
		InsertUint16(DCM_StudyID,si->nStudyID);
		//InsertStringNormal(DCM_StudyTime,si->tmStudyTime,(new CLXDcmVR("UL")));
	}

	LX_PATIENXTINFO* pi=dataset.GetPatientInfo();
	if (pi)
	{
		InsertStringNormal(DCM_PatientsName,pi->szPatientName);
	}

	m_hasDataset=true;
	return true;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -