Fix single file load bug.
This commit is contained in:
@@ -223,7 +223,6 @@ void DICOMDirectoryHelper::readImageProperty(ExtendMedicalImageProperties* prope
|
||||
const std::vector<std::string>& files = property->GetFileNames();
|
||||
DcmFileFormat file1;
|
||||
// read success!
|
||||
std::cout<<files.at(0)<<std::endl;
|
||||
if (file1.loadFile(files.at(0)).good()) {
|
||||
DcmDataset *dataset = file1.getDataset();
|
||||
|
||||
@@ -276,39 +275,48 @@ void DICOMDirectoryHelper::readImageProperty(ExtendMedicalImageProperties* prope
|
||||
|
||||
vtkMatrix4x4::Invert(matrix, property->GetWorldToModelMatrix() );
|
||||
matrix = property->GetWorldToModelMatrix();
|
||||
DcmFileFormat file2;
|
||||
std::cout<<files.at(1)<<std::endl;
|
||||
|
||||
// read success!
|
||||
if (file2.loadFile(files.at(1)).good()) {
|
||||
DcmDataset *dataset = file2.getDataset();
|
||||
std::string SeriesUID;
|
||||
dataset->findAndGetOFString(DcmTagKey(0x0020, 0x000e), SeriesUID);
|
||||
std::string SeriesDes;
|
||||
dataset->findAndGetOFString(DcmTagKey(0x0008, 0x103e), SeriesDes);
|
||||
long SeriesNumber = 0;
|
||||
dataset->findAndGetSint32(DcmTagKey(0x0020, 0x0011), SeriesNumber);
|
||||
long AcquisitionNumber = 0;
|
||||
dataset->findAndGetSint32(DcmTagKey(0x0020, 0x0012), AcquisitionNumber);
|
||||
long InstanceNumber = 0;
|
||||
dataset->findAndGetSint32(DcmTagKey(0x0020, 0x0013), InstanceNumber);
|
||||
double position[3] = {.0, .0, .0};
|
||||
dataset->findAndGetFloat64(DcmTagKey(0x0020, 0x0032), position[0], 0);
|
||||
dataset->findAndGetFloat64(DcmTagKey(0x0020, 0x0032), position[1], 1);
|
||||
dataset->findAndGetFloat64(DcmTagKey(0x0020, 0x0032), position[2], 2);
|
||||
double position0[3] ={property->GetPosition()[0], property->GetPosition()[1] , property->GetPosition()[2]};
|
||||
double zNormal[4] = { position[0] - position0[0],
|
||||
position[1] - position0[1],
|
||||
position[2] - position0[2], 1.0};
|
||||
double space2 = sqrt(vtkMath::Distance2BetweenPoints(position, property->GetPosition()));
|
||||
vtkMath::Normalize(zNormal);
|
||||
if (files.size()>1){
|
||||
DcmFileFormat file2;
|
||||
// read success!
|
||||
if (file2.loadFile(files.at(1)).good()) {
|
||||
DcmDataset *dataset = file2.getDataset();
|
||||
std::string SeriesUID;
|
||||
dataset->findAndGetOFString(DcmTagKey(0x0020, 0x000e), SeriesUID);
|
||||
std::string SeriesDes;
|
||||
dataset->findAndGetOFString(DcmTagKey(0x0008, 0x103e), SeriesDes);
|
||||
long SeriesNumber = 0;
|
||||
dataset->findAndGetSint32(DcmTagKey(0x0020, 0x0011), SeriesNumber);
|
||||
long AcquisitionNumber = 0;
|
||||
dataset->findAndGetSint32(DcmTagKey(0x0020, 0x0012), AcquisitionNumber);
|
||||
long InstanceNumber = 0;
|
||||
dataset->findAndGetSint32(DcmTagKey(0x0020, 0x0013), InstanceNumber);
|
||||
double position[3] = {.0, .0, .0};
|
||||
dataset->findAndGetFloat64(DcmTagKey(0x0020, 0x0032), position[0], 0);
|
||||
dataset->findAndGetFloat64(DcmTagKey(0x0020, 0x0032), position[1], 1);
|
||||
dataset->findAndGetFloat64(DcmTagKey(0x0020, 0x0032), position[2], 2);
|
||||
double position0[3] ={property->GetPosition()[0], property->GetPosition()[1] , property->GetPosition()[2]};
|
||||
double zNormal[4] = { position[0] - position0[0],
|
||||
position[1] - position0[1],
|
||||
position[2] - position0[2], 1.0};
|
||||
double space2 = sqrt(vtkMath::Distance2BetweenPoints(position, property->GetPosition()));
|
||||
vtkMath::Normalize(zNormal);
|
||||
double Spacing[3] = {.0, .0, .0};
|
||||
property->GetSpacing(Spacing);
|
||||
double zNormal2[4] = {.0,.0,.0,1.0};
|
||||
matrix->MultiplyPoint(zNormal, zNormal2);
|
||||
Spacing[2] = zNormal2[2]<0?(-1.0*space2):space2;
|
||||
property->SetSpacing(Spacing);
|
||||
}
|
||||
}
|
||||
else{
|
||||
double Spacing[3] = {.0, .0, .0};
|
||||
property->GetSpacing(Spacing);
|
||||
double zNormal2[4] = {.0,.0,.0,1.0};
|
||||
matrix->MultiplyPoint(zNormal, zNormal2);
|
||||
Spacing[2] = zNormal2[2]<0?(-1.0*space2):space2;
|
||||
Spacing[2] = 1.0;
|
||||
property->SetSpacing(Spacing);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user