Add compute transform matrix logic to ImageProperties.
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -2,9 +2,12 @@
|
||||
// Created by Krad on 2022/2/10.
|
||||
//
|
||||
|
||||
#include <vtkObjectFactory.h>
|
||||
#include "ExtendMedicalImageProperties.h"
|
||||
|
||||
#include <vtkObjectFactory.h>
|
||||
#include <vtkTransform.h>
|
||||
#include <vtkMath.h>
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
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<vtkTransform> transform;
|
||||
transform->PostMultiply();
|
||||
transform->SetMatrix(OrientationMatrix);
|
||||
transform->Translate(GetPosition());
|
||||
transform->GetMatrix(ModelToWorldMatrix);
|
||||
WorldToModelMatrix->DeepCopy(ModelToWorldMatrix);
|
||||
WorldToModelMatrix->Invert();
|
||||
}
|
||||
|
||||
|
||||
@@ -39,6 +39,8 @@ public:
|
||||
vtkSetVector3Macro(Position,double);
|
||||
vtkGetVector3Macro(Position,double);
|
||||
|
||||
vtkGetVector3Macro(ZVector,double);
|
||||
|
||||
const std::vector<std::string>& 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<std::string> FileNames;
|
||||
std::string uniqueID;
|
||||
vtkNew<vtkMatrix4x4> worldToModelMatrix;
|
||||
vtkNew<vtkMatrix4x4> modelToWorldMatrix;
|
||||
vtkNew<vtkMatrix4x4> OrientationMatrix;
|
||||
vtkNew<vtkMatrix4x4> WorldToModelMatrix;
|
||||
vtkNew<vtkMatrix4x4> ModelToWorldMatrix;
|
||||
private:
|
||||
ExtendMedicalImageProperties(const ExtendMedicalImageProperties&) = delete;
|
||||
void operator=(const ExtendMedicalImageProperties&) = delete;
|
||||
|
||||
Reference in New Issue
Block a user