Add some comment.

This commit is contained in:
Krad
2022-09-20 15:44:13 +08:00
parent 9e9f4d37fc
commit 6873e69571
7 changed files with 86 additions and 41 deletions

View File

@@ -187,10 +187,12 @@ void DICOMHeaderHelper::readHeaderFromFile(const char * filePath){
frameHeader.FrameIndex = i;
DcmItem *perFrameGroup = nullptr;
if (dataset->findAndGetSequenceItem(DCM_PerFrameFunctionalGroupsSequence, perFrameGroup, i).good()) {
if (dataset->findAndGetSequenceItem(DCM_PerFrameFunctionalGroupsSequence,
perFrameGroup, i).good()) {
//calc instance number for frame
DcmItem *frameContent = nullptr;
if (perFrameGroup->findAndGetSequenceItem(DCM_FrameContentSequence, frameContent, 0).good()) {
if (perFrameGroup->findAndGetSequenceItem(DCM_FrameContentSequence,
frameContent, 0).good()) {
unsigned long frameNumber = 0;
frameContent->findAndGetUint32(DCM_InStackPositionNumber, frameNumber);
frameHeader.InstanceNumber = frameNumber + fileHeader.InstanceNumber;
@@ -198,10 +200,14 @@ void DICOMHeaderHelper::readHeaderFromFile(const char * filePath){
// try to get frame position
DcmItem *framePosition = nullptr;
if (perFrameGroup->findAndGetSequenceItem(DCM_PlanePositionSequence, framePosition, 0).good()) {
if(framePosition->findAndGetFloat64(DCM_ImagePositionPatient, frameHeader.Position[0], 0).good()){
framePosition->findAndGetFloat64(DCM_ImagePositionPatient, frameHeader.Position[1], 1);
framePosition->findAndGetFloat64(DCM_ImagePositionPatient, frameHeader.Position[2], 2);
if (perFrameGroup->findAndGetSequenceItem(DCM_PlanePositionSequence,
framePosition, 0).good()) {
if(framePosition->findAndGetFloat64(DCM_ImagePositionPatient,
frameHeader.Position[0], 0).good()){
framePosition->findAndGetFloat64(DCM_ImagePositionPatient,
frameHeader.Position[1], 1);
framePosition->findAndGetFloat64(DCM_ImagePositionPatient,
frameHeader.Position[2], 2);
}else{
//restore value
frameHeader.Position[0] = fileHeader.Position[0];
@@ -214,16 +220,16 @@ void DICOMHeaderHelper::readHeaderFromFile(const char * filePath){
0).good()) {
if (frameOrientation->findAndGetFloat64(DCM_ImageOrientationPatient,
frameHeader.Orientation[0], 0).good()) {
frameOrientation->findAndGetFloat64(DCM_ImageOrientationPatient, frameHeader.Orientation[1],
1);
frameOrientation->findAndGetFloat64(DCM_ImageOrientationPatient, frameHeader.Orientation[2],
2);
frameOrientation->findAndGetFloat64(DCM_ImageOrientationPatient, frameHeader.Orientation[3],
3);
frameOrientation->findAndGetFloat64(DCM_ImageOrientationPatient, frameHeader.Orientation[4],
4);
frameOrientation->findAndGetFloat64(DCM_ImageOrientationPatient, frameHeader.Orientation[5],
5);
frameOrientation->findAndGetFloat64(DCM_ImageOrientationPatient,
frameHeader.Orientation[1],1);
frameOrientation->findAndGetFloat64(DCM_ImageOrientationPatient,
frameHeader.Orientation[2],2);
frameOrientation->findAndGetFloat64(DCM_ImageOrientationPatient,
frameHeader.Orientation[3],3);
frameOrientation->findAndGetFloat64(DCM_ImageOrientationPatient,
frameHeader.Orientation[4],4);
frameOrientation->findAndGetFloat64(DCM_ImageOrientationPatient,
frameHeader.Orientation[5],5);
}else{
//restore value
frameHeader.Orientation[0] = fileHeader.Orientation[0];
@@ -317,7 +323,9 @@ void DICOMHeaderHelper::ArrangeSeriesProperty() {
}
}
ExtendMedicalImageProperties* DICOMHeaderHelper::createProperty(const std::vector<DICOMFileHeader>& headerList, int splitIndex, int beginOffset) {
ExtendMedicalImageProperties* DICOMHeaderHelper::createProperty(const std::vector<DICOMFileHeader>& headerList,
int splitIndex, int beginOffset) {
const DICOMFileHeader& header = headerList[beginOffset];
// create ExtendMedicalImageProperties and set values

View File

@@ -151,7 +151,7 @@ void DICOMPixelDataHelper::GetRGBPixelData(const char *path, void *data, unsigne
delete fileFormat;
}
int DICOMPixelDataHelper::GetOverLayCount(const char *path) {
int DICOMPixelDataHelper::GetOverlayCount(const char *path) {
int ret =0;
DcmFileFormat fileFormat;
if (fileFormat.loadFile(path).good()) {
@@ -230,7 +230,7 @@ void DICOMPixelDataHelper::GetFramePixelData(const char *path, void *data, unsig
}
}
bool DICOMPixelDataHelper::StoreFileObject(const char *path) {
bool DICOMPixelDataHelper::CacheFileObject(const char *path) {
DcmFileFormat *fileFormat = new DcmFileFormat();//读取文件获取传输语法
if (fileFormat->loadFile(path).good() && fileFormat->loadAllDataIntoMemory().good()) {
DICOMFileObjectCache::getInstance()->store(path,fileFormat);
@@ -241,7 +241,7 @@ bool DICOMPixelDataHelper::StoreFileObject(const char *path) {
}
}
void DICOMPixelDataHelper::ClearFileObject() {
void DICOMPixelDataHelper::ClearFileObjectCache() {
DICOMFileObjectCache::getInstance()->clear();
}

View File

@@ -26,18 +26,39 @@ public:
*/
static void GetPixelData(const char * path, void* data, unsigned long& length);
/**
* Check whether FileObject with path in cache
* @param path dcm file absolute path, and the cache key
* @return is in cache
*/
static bool CheckFileObjectCache(const char * path);
static bool StoreFileObject(const char * path);
/**
* Create a DcmFileFormat object with input path, and
* store it into the cache map.
* @param path dcm file absolute path, and the cache key
* @return cache success
*/
static bool CacheFileObject(const char * path);
static void ClearFileObject();
/**
* Clear all object cache in the store map
*/
static void ClearFileObjectCache();
/**
* Get multi-frame format dicom file Pixel Data
* @param path dcm file absolute path
* @param data output data pointer, must have been allocated.
* @param length output data length
* @param frameIndex frame index in pixel data
*/
static void GetFramePixelData(const char * path, void* data, unsigned long& length, const long& frameIndex);
/**
* Get Pixel Data with Rescaled, result is calculate as Float, and arrange as Float.
* @param path dcm file absolute path
* @param data output data buffer pointer
* @param data output data buffer pointer, must have been allocated.
* @param length output data length
*/
static void GetPixelDataFloat(const char * path, void* data, unsigned long& length);
@@ -45,13 +66,25 @@ public:
/**
* Get colorful Pixel Data as three component R,G,B color value.
* @param path dcm file absolute path
* @param data output data buffer pointer
* @param data output data buffer pointer, must have been allocated.
* @param length output data length
*/
static void GetRGBPixelData(const char * path, void* data, unsigned long& length);
static int GetOverLayCount(const char *path);
/**
* Get Overlay data count
* @param path dcm file absolute path
* @return Overlay data count
*/
static int GetOverlayCount(const char *path);
/**
* Get Overlay data
* @param path dcm file absolute path
* @param data output data buffer pointer, must have been allocated.
* @param width output overlay width, usually same as image columns
* @param height output overlay height, usually same as image rows
*/
static void GetOverlayData(const char * path, void* data,
unsigned int& width, unsigned int& height);

View File

@@ -5,10 +5,12 @@
#include <string>
#include <vtkSmartPointer.h>
#include "IO/Defines/DIDKitExport.h"
class ExtendMedicalImageProperties;
class vtkImageData;
class DicomLoader {
class DIDKIT_EXPORT DicomLoader {
public:
static void InitCodecs();

View File

@@ -10,7 +10,9 @@
#include <vtkNew.h>
#include <vtkMatrix4x4.h>
class ExtendMedicalImageProperties: public vtkMedicalImageProperties{
#include "IO/Defines/DIDKitExport.h"
class DIDKIT_EXPORT ExtendMedicalImageProperties: public vtkMedicalImageProperties{
public:
static ExtendMedicalImageProperties *New();
vtkTypeMacro(ExtendMedicalImageProperties,vtkMedicalImageProperties);

View File

@@ -98,25 +98,23 @@ void vtkDCMTKImageReader::ExecuteDataWithInformation(vtkDataObject *output,
// init codes to support compressed file
DICOMPixelDataHelper::InitCodecs();
if (properties->GetHasOverlay()){
HasOverlay = true;
OverLayData = vtkImageData::New();
OverLayData->SetExtent(data->GetExtent());
OverLayData->SetSpacing(data->GetSpacing());
OverLayData->SetOrigin(data->GetOrigin());
OverLayData->AllocateScalars(VTK_UNSIGNED_CHAR,1);
}
for (int i = 0; i < properties->GetFileNames().size(); ++i) {
const std::string &path = properties->GetFileNames()[i].first;
const long &frameIndex = properties->GetFileNames()[i].second;
if (properties->GetHasOverlay()){
if (!OverLayData){
HasOverlay = true;
OverLayData = vtkImageData::New();
OverLayData->SetExtent(data->GetExtent());
OverLayData->SetSpacing(data->GetSpacing());
OverLayData->SetOrigin(data->GetOrigin());
OverLayData->AllocateScalars(VTK_UNSIGNED_CHAR,1);
}
unsigned int width = 0;
unsigned int height = 0;
void* overlayBuffer = OverLayData->GetScalarPointer(0, 0, i);
DICOMPixelDataHelper::GetOverlayData(path.c_str(), overlayBuffer, width, height);
}
unsigned long imageDataLength;
@@ -132,9 +130,9 @@ void vtkDCMTKImageReader::ExecuteDataWithInformation(vtkDataObject *output,
} else {
if (frameIndex>=0){
if (!DICOMPixelDataHelper::CheckFileObjectCache(path.c_str())){
if(!DICOMPixelDataHelper::StoreFileObject(path.c_str())){
if(!DICOMPixelDataHelper::CacheFileObject(path.c_str())){
vtkErrorMacro(<< "Fail to read file:"<<path.c_str());
DICOMPixelDataHelper::ClearFileObject();
DICOMPixelDataHelper::ClearFileObjectCache();
// finalize codecs
DICOMPixelDataHelper::FinalizeCodecs();
return;
@@ -149,7 +147,7 @@ void vtkDCMTKImageReader::ExecuteDataWithInformation(vtkDataObject *output,
buffer = ((char *) buffer) + imageDataLength;
}
DICOMPixelDataHelper::ClearFileObject();
DICOMPixelDataHelper::ClearFileObjectCache();
// finalize codecs
DICOMPixelDataHelper::FinalizeCodecs();
}

View File

@@ -10,9 +10,11 @@
#include <vector>
#include <string>
#include "IO/Defines/DIDKitExport.h"
class ExtendMedicalImageProperties;
class vtkDCMTKImageReader: public vtkImageReader2 {
class DIDKIT_EXPORT vtkDCMTKImageReader: public vtkImageReader2 {
public:
//@{
/**