diff --git a/src/src/IO/DICOM/DICOMDirectoryHelper.cpp b/src/src/IO/DICOM/DICOMDirectoryHelper.cpp index 455e5cf..558c738 100644 --- a/src/src/IO/DICOM/DICOMDirectoryHelper.cpp +++ b/src/src/IO/DICOM/DICOMDirectoryHelper.cpp @@ -258,26 +258,9 @@ void DICOMDirectoryHelper::readImageProperty(ExtendMedicalImageProperties* prope dataset->findAndGetFloat64(DcmTagKey(0x0020, 0x0032), position[1], 1); dataset->findAndGetFloat64(DcmTagKey(0x0020, 0x0032), position[2], 2); property->SetPosition(position); + // get orientation transform matrix and MToW WToM transform matrix + property->ComputeTransformMatrix(); } - double *d = property->GetDirectionCosine(); - double xVector[3] = {d[0], d[1], d[2]}; - double yVector[3] = {d[3], d[4], d[5]}; - double zVector[3] = {0, 0, 0}; - vtkMath::Cross(xVector, yVector, zVector); - auto matrix = property->GetModelToWorldMatrix(); - matrix->Identity(); - matrix->SetElement( 0,0, xVector[0]); - matrix->SetElement( 1,0, xVector[1]); - matrix->SetElement( 2,0, xVector[2]); - matrix->SetElement( 0,1, yVector[0]); - matrix->SetElement( 1,1, yVector[1]); - matrix->SetElement( 2,1, yVector[2]); - matrix->SetElement( 0,2, zVector[0]); - matrix->SetElement( 1,2, zVector[1]); - matrix->SetElement( 2,2, zVector[2]); - - vtkMatrix4x4::Invert(matrix, property->GetWorldToModelMatrix() ); - matrix = property->GetWorldToModelMatrix(); if (files.size()>1){ DcmFileFormat file2; diff --git a/src/src/IO/DICOM/ExtendMedicalImageProperties.cpp b/src/src/IO/DICOM/ExtendMedicalImageProperties.cpp index 0805c90..631e7a4 100644 --- a/src/src/IO/DICOM/ExtendMedicalImageProperties.cpp +++ b/src/src/IO/DICOM/ExtendMedicalImageProperties.cpp @@ -2,9 +2,12 @@ // Created by Krad on 2022/2/10. // -#include #include "ExtendMedicalImageProperties.h" +#include +#include +#include + //---------------------------------------------------------------------------- vtkStandardNewMacro(ExtendMedicalImageProperties) @@ -21,3 +24,33 @@ void ExtendMedicalImageProperties::Clear() { this->SetStudyUID(nullptr); this->SetSeriesUID(nullptr); } + +void ExtendMedicalImageProperties::ComputeTransformMatrix() { + double *d = GetDirectionCosine(); + //通过orientation的数值,计算Z轴方向向量,并记录 + double xVector[3] = {d[0], d[1], d[2]}; + double yVector[3] = {d[3], d[4], d[5]}; + vtkMath::Cross(xVector, yVector, ZVector); + + //根据三轴向量构建矩阵 + OrientationMatrix->Zero(); + OrientationMatrix->SetElement(0, 0, xVector[0]); + OrientationMatrix->SetElement(1, 0, xVector[1]); + OrientationMatrix->SetElement(2, 0, xVector[2]); + OrientationMatrix->SetElement(0, 1, yVector[0]); + OrientationMatrix->SetElement(1, 1, yVector[1]); + OrientationMatrix->SetElement(2, 1, yVector[2]); + OrientationMatrix->SetElement(0, 2, ZVector[0]); + OrientationMatrix->SetElement(1, 2, ZVector[1]); + OrientationMatrix->SetElement(2, 2, ZVector[2]); + OrientationMatrix->SetElement(3, 3, 1); + //计算MToW变换矩阵和逆矩阵WToM + vtkNew transform; + transform->PostMultiply(); + transform->SetMatrix(OrientationMatrix); + transform->Translate(GetPosition()); + transform->GetMatrix(ModelToWorldMatrix); + WorldToModelMatrix->DeepCopy(ModelToWorldMatrix); + WorldToModelMatrix->Invert(); +} + diff --git a/src/src/IO/DICOM/ExtendMedicalImageProperties.h b/src/src/IO/DICOM/ExtendMedicalImageProperties.h index 3ab0eb0..c1fabe1 100644 --- a/src/src/IO/DICOM/ExtendMedicalImageProperties.h +++ b/src/src/IO/DICOM/ExtendMedicalImageProperties.h @@ -39,6 +39,8 @@ public: vtkSetVector3Macro(Position,double); vtkGetVector3Macro(Position,double); + vtkGetVector3Macro(ZVector,double); + const std::vector& GetFileNames(){ return FileNames; } @@ -74,12 +76,16 @@ public: void SetUniqueID(const std::string& id){ uniqueID = id; } + vtkMatrix4x4* GetOrientationMatrix(){ + return OrientationMatrix.Get(); + } vtkMatrix4x4* GetWorldToModelMatrix(){ - return worldToModelMatrix.Get(); + return WorldToModelMatrix.Get(); } vtkMatrix4x4* GetModelToWorldMatrix(){ - return modelToWorldMatrix.Get(); + return ModelToWorldMatrix.Get(); } + void ComputeTransformMatrix(); protected: ExtendMedicalImageProperties(); @@ -88,12 +94,14 @@ protected: char * SeriesUID = nullptr; double Spacing[3] ={1.0,1.0,1.0}; double Position[3] ={.0,.0,.0}; + double ZVector[3] ={.0,.0,.0}; long AcquisitionNumber = 0; unsigned short SamplePerPixel; std::vector FileNames; std::string uniqueID; - vtkNew worldToModelMatrix; - vtkNew modelToWorldMatrix; + vtkNew OrientationMatrix; + vtkNew WorldToModelMatrix; + vtkNew ModelToWorldMatrix; private: ExtendMedicalImageProperties(const ExtendMedicalImageProperties&) = delete; void operator=(const ExtendMedicalImageProperties&) = delete;