Fix data orientation, spacing and position sort.
This commit is contained in:
@@ -441,6 +441,7 @@ void DICOMHeaderHelper::ArrangeSeriesProperty() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
//sort every image set
|
//sort every image set
|
||||||
|
int imageSetNumber = 0;
|
||||||
int beginOffset = 0;
|
int beginOffset = 0;
|
||||||
for (int j = 0; j < splitIndex.size(); ++j) {
|
for (int j = 0; j < splitIndex.size(); ++j) {
|
||||||
std::sort(item.second.begin() + beginOffset, item.second.begin() + splitIndex[j],
|
std::sort(item.second.begin() + beginOffset, item.second.begin() + splitIndex[j],
|
||||||
@@ -448,17 +449,23 @@ void DICOMHeaderHelper::ArrangeSeriesProperty() {
|
|||||||
return v1.image_position < v2.image_position;
|
return v1.image_position < v2.image_position;
|
||||||
});
|
});
|
||||||
auto p = createProperty(item.second, splitIndex[j], beginOffset);
|
auto p = createProperty(item.second, splitIndex[j], beginOffset);
|
||||||
|
p->SetImageSetNumber(imageSetNumber);
|
||||||
|
p->GenerateUniqueID();
|
||||||
if (p)seriesProperties.push_back(p);
|
if (p)seriesProperties.push_back(p);
|
||||||
beginOffset = splitIndex[j];
|
beginOffset = splitIndex[j];
|
||||||
|
imageSetNumber++;
|
||||||
}
|
}
|
||||||
|
printf("first file:%s",item.second[0].FilePath.c_str());
|
||||||
//sort the last image set
|
//sort the last image set
|
||||||
std::sort(item.second.begin() + beginOffset, item.second.end(),
|
std::sort(item.second.begin() + beginOffset, item.second.end(),
|
||||||
[](auto v1, auto v2) {
|
[](auto v1, auto v2) {
|
||||||
return v1.image_position < v2.image_position;
|
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);
|
auto p = createProperty(item.second, item.second.size(), beginOffset);
|
||||||
|
p->SetImageSetNumber(imageSetNumber);
|
||||||
|
p->GenerateUniqueID();
|
||||||
if (p)seriesProperties.push_back(p);
|
if (p)seriesProperties.push_back(p);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -524,6 +531,8 @@ ExtendMedicalImageProperties* DICOMHeaderHelper::createProperty(const std::vecto
|
|||||||
property->SetRescaleOffset(RescaleOffset);
|
property->SetRescaleOffset(RescaleOffset);
|
||||||
property->SetBitsAllocated(bitsAllocated);
|
property->SetBitsAllocated(bitsAllocated);
|
||||||
property->SetPixelRepresentation(PixelRepresentation);
|
property->SetPixelRepresentation(PixelRepresentation);
|
||||||
|
property->SetDirectionCosine((double*)header.Orientation);
|
||||||
|
property->ComputeTransformMatrix();
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
printf( " file:%s load error!\r\b", header.FilePath.c_str() );
|
printf( " file:%s load error!\r\b", header.FilePath.c_str() );
|
||||||
|
|||||||
@@ -42,9 +42,9 @@ struct DICOMFileHeader {
|
|||||||
normal[0] = (Orientation[1] * Orientation[5]) - (Orientation[2] * Orientation[4]);
|
normal[0] = (Orientation[1] * Orientation[5]) - (Orientation[2] * Orientation[4]);
|
||||||
normal[1] = (Orientation[2] * Orientation[3]) - (Orientation[0] * Orientation[5]);
|
normal[1] = (Orientation[2] * Orientation[3]) - (Orientation[0] * Orientation[5]);
|
||||||
normal[2] = (Orientation[0] * Orientation[4]) - (Orientation[1] * Orientation[3]);
|
normal[2] = (Orientation[0] * Orientation[4]) - (Orientation[1] * Orientation[3]);
|
||||||
image_position = (normal[0] * Orientation[0])
|
image_position = (normal[0] * Position[0])
|
||||||
+ (normal[1] * Orientation[1])
|
+ (normal[1] * Position[1])
|
||||||
+ (normal[2] * Orientation[2]);
|
+ (normal[2] * Position[2]);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -84,3 +84,25 @@ bool ExtendMedicalImageProperties::RescaledImageDataIsSigned()
|
|||||||
return (rescaleSigned || pixelRepSigned || offsetSigned);
|
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));
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -30,6 +30,9 @@ public:
|
|||||||
vtkGetMacro(AcquisitionNumber, long)
|
vtkGetMacro(AcquisitionNumber, long)
|
||||||
vtkSetMacro(AcquisitionNumber, long)
|
vtkSetMacro(AcquisitionNumber, long)
|
||||||
|
|
||||||
|
vtkGetMacro(ImageSetNumber, long)
|
||||||
|
vtkSetMacro(ImageSetNumber, long)
|
||||||
|
|
||||||
vtkGetMacro(Rows, long)
|
vtkGetMacro(Rows, long)
|
||||||
vtkSetMacro(Rows, long)
|
vtkSetMacro(Rows, long)
|
||||||
|
|
||||||
@@ -66,9 +69,6 @@ public:
|
|||||||
void SetFileNames(std::vector<std::string>& files){
|
void SetFileNames(std::vector<std::string>& files){
|
||||||
FileNames = std::move(files);
|
FileNames = std::move(files);
|
||||||
}
|
}
|
||||||
void SetSplitIndex(std::vector<int>& index){
|
|
||||||
SplitIndex = std::move(index);
|
|
||||||
}
|
|
||||||
|
|
||||||
long GetSeriesNumberAsLong(){
|
long GetSeriesNumberAsLong(){
|
||||||
if (this->SeriesNumber){
|
if (this->SeriesNumber){
|
||||||
@@ -97,6 +97,8 @@ public:
|
|||||||
void SetUniqueID(const std::string& id){
|
void SetUniqueID(const std::string& id){
|
||||||
uniqueID = id;
|
uniqueID = id;
|
||||||
}
|
}
|
||||||
|
void GenerateUniqueID();
|
||||||
|
|
||||||
vtkMatrix4x4* GetOrientationMatrix(){
|
vtkMatrix4x4* GetOrientationMatrix(){
|
||||||
return OrientationMatrix.Get();
|
return OrientationMatrix.Get();
|
||||||
}
|
}
|
||||||
@@ -123,13 +125,13 @@ protected:
|
|||||||
double RescaleSlope = .0;
|
double RescaleSlope = .0;
|
||||||
double RescaleOffset = .0;
|
double RescaleOffset = .0;
|
||||||
long AcquisitionNumber = 0;
|
long AcquisitionNumber = 0;
|
||||||
|
long ImageSetNumber = 0;
|
||||||
long Rows = 0;
|
long Rows = 0;
|
||||||
long Columns = 0;
|
long Columns = 0;
|
||||||
unsigned short SamplePerPixel;
|
unsigned short SamplePerPixel;
|
||||||
unsigned short BitsAllocated;
|
unsigned short BitsAllocated;
|
||||||
unsigned short PixelRepresentation;
|
unsigned short PixelRepresentation;
|
||||||
std::vector<std::string> FileNames;
|
std::vector<std::string> FileNames;
|
||||||
std::vector<int> SplitIndex;
|
|
||||||
std::string uniqueID;
|
std::string uniqueID;
|
||||||
vtkNew<vtkMatrix4x4> OrientationMatrix;
|
vtkNew<vtkMatrix4x4> OrientationMatrix;
|
||||||
vtkNew<vtkMatrix4x4> WorldToModelMatrix;
|
vtkNew<vtkMatrix4x4> WorldToModelMatrix;
|
||||||
|
|||||||
Reference in New Issue
Block a user