diff --git a/src/src/IO/DICOM/DICOMHeaderHelper.cpp b/src/src/IO/DICOM/DICOMHeaderHelper.cpp index d7ea9ad..a2e0aed 100644 --- a/src/src/IO/DICOM/DICOMHeaderHelper.cpp +++ b/src/src/IO/DICOM/DICOMHeaderHelper.cpp @@ -441,24 +441,31 @@ void DICOMHeaderHelper::ArrangeSeriesProperty() { } } //sort every image set + int imageSetNumber = 0; int beginOffset = 0; for (int j = 0; j < splitIndex.size(); ++j) { - std::sort(item.second.begin()+beginOffset,item.second.begin()+splitIndex[j], - [](auto v1,auto v2){ - return v1.image_positionSetImageSetNumber(imageSetNumber); + p->GenerateUniqueID(); if (p)seriesProperties.push_back(p); - + beginOffset = splitIndex[j]; + imageSetNumber++; + } + printf("first file:%s",item.second[0].FilePath.c_str()); + //sort the last image set + std::sort(item.second.begin() + beginOffset, item.second.end(), + [](auto v1, auto v2) { + return v1.image_position < v2.image_position; + }); +// printf("new first file:%s\r\n",item.second[0].FilePath.c_str()); + auto p = createProperty(item.second, item.second.size(), beginOffset); + p->SetImageSetNumber(imageSetNumber); + p->GenerateUniqueID(); + if (p)seriesProperties.push_back(p); } } @@ -524,6 +531,8 @@ ExtendMedicalImageProperties* DICOMHeaderHelper::createProperty(const std::vecto property->SetRescaleOffset(RescaleOffset); property->SetBitsAllocated(bitsAllocated); property->SetPixelRepresentation(PixelRepresentation); + property->SetDirectionCosine((double*)header.Orientation); + property->ComputeTransformMatrix(); } else{ printf( " file:%s load error!\r\b", header.FilePath.c_str() ); diff --git a/src/src/IO/DICOM/DICOMHeaderHelper.h b/src/src/IO/DICOM/DICOMHeaderHelper.h index a317285..fa50439 100644 --- a/src/src/IO/DICOM/DICOMHeaderHelper.h +++ b/src/src/IO/DICOM/DICOMHeaderHelper.h @@ -42,9 +42,9 @@ struct DICOMFileHeader { normal[0] = (Orientation[1] * Orientation[5]) - (Orientation[2] * Orientation[4]); normal[1] = (Orientation[2] * Orientation[3]) - (Orientation[0] * Orientation[5]); normal[2] = (Orientation[0] * Orientation[4]) - (Orientation[1] * Orientation[3]); - image_position = (normal[0] * Orientation[0]) - + (normal[1] * Orientation[1]) - + (normal[2] * Orientation[2]); + image_position = (normal[0] * Position[0]) + + (normal[1] * Position[1]) + + (normal[2] * Position[2]); } }; diff --git a/src/src/IO/DICOM/ExtendMedicalImageProperties.cpp b/src/src/IO/DICOM/ExtendMedicalImageProperties.cpp index 545a62e..204c150 100644 --- a/src/src/IO/DICOM/ExtendMedicalImageProperties.cpp +++ b/src/src/IO/DICOM/ExtendMedicalImageProperties.cpp @@ -84,3 +84,25 @@ bool ExtendMedicalImageProperties::RescaledImageDataIsSigned() return (rescaleSigned || pixelRepSigned || offsetSigned); } +void ExtendMedicalImageProperties::GenerateUniqueID() { + std::string uniqueID; + uniqueID.append(PatientName); + uniqueID.append("_"); + uniqueID.append(StudyUID); + uniqueID.append("_"); + uniqueID.append(SeriesUID); + uniqueID.append("_"); + char img[200]={0}; + sprintf(img,"%ld", ImageSetNumber); + uniqueID.append(img); + this->SetUniqueID(uniqueID.c_str()); +} + +bool ExtendMedicalImageProperties::RescaledImageDataIsUnsignedChar() { + bool charData = BitsAllocated == 8; + bool noScale = ((int)(this->RescaleOffset) == 0) && ((int)(this->RescaleSlope) == 1); + bool unSign = (this->PixelRepresentation == 0); + bool color = SamplePerPixel == 3; + return (color || (charData && unSign && noScale)); +} + diff --git a/src/src/IO/DICOM/ExtendMedicalImageProperties.h b/src/src/IO/DICOM/ExtendMedicalImageProperties.h index 9fa1124..825b2cf 100644 --- a/src/src/IO/DICOM/ExtendMedicalImageProperties.h +++ b/src/src/IO/DICOM/ExtendMedicalImageProperties.h @@ -30,6 +30,9 @@ public: vtkGetMacro(AcquisitionNumber, long) vtkSetMacro(AcquisitionNumber, long) + vtkGetMacro(ImageSetNumber, long) + vtkSetMacro(ImageSetNumber, long) + vtkGetMacro(Rows, long) vtkSetMacro(Rows, long) @@ -66,9 +69,6 @@ public: void SetFileNames(std::vector& files){ FileNames = std::move(files); } - void SetSplitIndex(std::vector& index){ - SplitIndex = std::move(index); - } long GetSeriesNumberAsLong(){ if (this->SeriesNumber){ @@ -97,6 +97,8 @@ public: void SetUniqueID(const std::string& id){ uniqueID = id; } + void GenerateUniqueID(); + vtkMatrix4x4* GetOrientationMatrix(){ return OrientationMatrix.Get(); } @@ -123,13 +125,13 @@ protected: double RescaleSlope = .0; double RescaleOffset = .0; long AcquisitionNumber = 0; + long ImageSetNumber = 0; long Rows = 0; long Columns = 0; unsigned short SamplePerPixel; unsigned short BitsAllocated; unsigned short PixelRepresentation; std::vector FileNames; - std::vector SplitIndex; std::string uniqueID; vtkNew OrientationMatrix; vtkNew WorldToModelMatrix;