DCM图--按SeriesNumber进行分类
2015-11-20 17:15
537 查看
留后面参考。------将文件中的DCM图按照序列号进行分类,将相同序列号的DCM图移动到与序列号同名的文件中
#include "stdafx.h" #include <vector> #include <map> #include <string> #include <winsock2.h> #include <string> #include <iostream> #include <algorithm> #include <math.h> #include "dcmtk/dcmdata/dctk.h" #include "dcmtk/dcmdata/dcxfer.h" #include "dcmtk/dcmdata/dcrledrg.h" #include "dcmtk/dcmjpeg/djdecode.h" /* for dcmjpeg decoders */ #include "dcmtk/dcmimgle/dcmimage.h" /* for DicomImage */ #include "dcmtk/dcmjpeg/dipijpeg.h" /* for dcmimage JPEG plugin */ #include <Windows.h> #include <io.h> #include <direct.h> #include <sstream> extern "C" { #include "jpeglib.h" } #pragma comment(lib,"Netapi32.lib") #pragma comment(lib, "ws2_32.lib") using namespace std; void SplitEx(const string& strOrignal , char ch , vector<string>& vctString) { istringstream iss(strOrignal); string item; while(getline(iss , item , ch)) vctString.push_back(item); return; } DcmFileFormat *pFileFormat = new DcmFileFormat(); bool MoveDcmFile(string strPath) { if(NULL == pFileFormat) { cout<<"NULL == pFileFormat"<<endl; return false; } OFCondition oc = pFileFormat->loadFile(strPath.c_str()); if(oc.bad()) { cout<<"no tag: "<<strPath<<endl; return false; } DcmDataset* pDataset = pFileFormat->getDataset(); int nSeriesNumber = 0; OFString strSeriesNumber; pDataset->findAndGetOFString(DCM_SeriesNumber, strSeriesNumber); nSeriesNumber = atoi(strSeriesNumber.c_str()); vector<string> vctPathBlock; SplitEx(strPath, '\\', vctPathBlock); ostringstream oss;//创建一个流 if(vctPathBlock.size() < 0) { cout<<"路程错误"<<endl; return 0; } for(int i = 0; i < vctPathBlock.size() - 1; i++) { oss<<vctPathBlock[i]<<"\\"; } oss<<nSeriesNumber<<"\\"; //创建保存文件夹 char *strSaveFilePath = new(std::nothrow)char[oss.str().length() + 1]; memset(strSaveFilePath, 0, oss.str().length() + 1); memcpy(strSaveFilePath, oss.str().c_str(), oss.str().length()); char *fileName = strSaveFilePath, *tag; for(tag=fileName;*tag;tag++) { if (*tag=='\\') { char buf[1000],path[1000]; strcpy(buf,fileName); buf[strlen(fileName)-strlen(tag)+1]=NULL; strcpy(path,buf); if (access(path,6)==-1) { int npot = 99; npot = mkdir(path);//创建成功返回0 不成功返回-1 } } } delete strSaveFilePath; //将DCM图按序列号,移到对应的文件中 oss<<vctPathBlock[vctPathBlock.size() - 1]; string strSavePath = oss.str(); bool bMove = false; bMove = MoveFile(strPath.c_str(), strSavePath.c_str()); //cout<<bMove<<endl; } //读取目录下所有的文件 void getFiles( string path, vector<string>& files ) { //文件句柄 long hFile = 0; //文件信息 struct _finddata_t fileinfo; string p; if((hFile = _findfirst(p.assign(path).append("\\*").c_str(),&fileinfo)) != -1) { do { //如果是目录,迭代之 //如果不是,加入列表 if((fileinfo.attrib & _A_SUBDIR)) { if(strcmp(fileinfo.name,".") != 0 && strcmp(fileinfo.name,"..") != 0) getFiles( p.assign(path).append("\\").append(fileinfo.name), files ); } else { files.push_back(p.assign(path).append("\\").append(fileinfo.name) ); } }while(_findnext(hFile, &fileinfo) == 0); _findclose(hFile); } } int _tmain(int argc, _TCHAR* argv[]) { string strPath = "D:\\Dtest16\\DICOM\\CT"; //1 vector<string> vctFilePath; getFiles(strPath, vctFilePath); for(int i = 0; i < vctFilePath.size(); i++) { MoveDcmFile(vctFilePath[i]); } if(NULL != pFileFormat) { delete pFileFormat; } return 0; }
相关文章推荐
- [推荐]移动兼容性测试平台
- Java分页查询工具类
- selenium webdriver python 开始
- 【转】使用 JMeter 完成常用的压力测试
- 【转】利用 Apache JMeter 测试 WebSphere 性能
- pthread_cond_wait() 前使用 while 讲解
- Android基础记录
- 机器学习之Python安装和numpy配置
- mongodb主从环境搭建(包含keepalive)
- STM32之MDK硬件仿真
- i++ 和 ++i 效率的分析
- 勾股定理
- 【转】用JMeter来测试Tomcat的性能
- C++中声明和定义的区别
- 持续集成:TestNG中case之间的关系
- 快速掌握 Android Studio 中 Gradle 的使用方法
- SAXBuilder解析applicationConfig.config配置文件
- 利用jQuery无插件创建可扩展目录树
- Srping - bean的依赖注入(Dependency injection)
- Android框架层之音频管理器AudioManager的使用