MCPcopy Create free account
hub / github.com/MITK/MITK / Sort

Method Sort

Modules/DICOM/src/mitkNormalDirectionConsistencySorter.cpp:74–162  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

72}
73
74void
75mitk::NormalDirectionConsistencySorter
76::Sort()
77{
78 DICOMDatasetList datasets = GetInput();
79
80 if (datasets.size() > 1)
81 {
82 // at some point in the code, there is the expectation that
83 // the direction of the slice normals is the same as the direction between
84 // first and last slice origin. We need to make this sure here, because
85 // we want to feed the files into itk::ImageSeriesReader with the consistent
86 // setting of ReverseOrderOff.
87
88 static const DICOMTag tagImagePositionPatient = DICOMTag(0x0020,0x0032); // Image Position (Patient)
89 static const DICOMTag tagImageOrientation = DICOMTag(0x0020, 0x0037); // Image Orientation
90
91 DICOMDatasetAccess* firstDS = datasets.front();
92 DICOMDatasetAccess* lastDS = datasets.back();
93
94 // make sure here that the direction from slice to slice is the direction of
95 // image normals...
96 const std::string imageOrientationString = firstDS->GetTagValueAsString( tagImageOrientation ).value;
97 const std::string imagePositionPatientFirst = firstDS->GetTagValueAsString(tagImagePositionPatient).value;
98 const std::string imagePositionPatientLast = lastDS->GetTagValueAsString(tagImagePositionPatient).value;
99
100 Vector3D right; right.Fill(0.0);
101 Vector3D up; up.Fill(0.0);
102 bool hasOrientation(false);
103 DICOMStringToOrientationVectors( imageOrientationString,
104 right, up, hasOrientation );
105
106 Point3D firstOrigin; firstOrigin.Fill(0.0f);
107 bool firstHasOrigin(false);
108 firstOrigin = DICOMStringToPoint3D( imagePositionPatientFirst, firstHasOrigin );
109
110 Point3D lastOrigin; lastOrigin.Fill(0.0f);
111 bool lastHasOrigin(false);
112 lastOrigin = DICOMStringToPoint3D( imagePositionPatientLast, lastHasOrigin );
113
114 Vector3D normal;
115 normal[0] = right[1] * up[2] - right[2] * up[1];
116 normal[1] = right[2] * up[0] - right[0] * up[2];
117 normal[2] = right[0] * up[1] - right[1] * up[0];
118 normal.Normalize();
119
120 Vector3D directionOfSlices;
121 directionOfSlices = lastOrigin - firstOrigin;
122 directionOfSlices.Normalize();
123
124 double projection = normal * directionOfSlices;
125
126 MITK_DEBUG << "Making sense of \norientation '" << imageOrientationString
127 << "'\nfirst position '" << imagePositionPatientFirst
128 << "'\nlast position '" << imagePositionPatientLast << "'";
129 MITK_DEBUG << "Normal: " << normal;
130 MITK_DEBUG << "Direction of slices: " << directionOfSlices;
131 MITK_DEBUG << "Projection of direction onto slice normal: " << projection;

Callers

nothing calls this directly

Calls 11

frontMethod · 0.80
backMethod · 0.80
NormalizeMethod · 0.80
sizeMethod · 0.45
GetTagValueAsStringMethod · 0.45
FillMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
SetNumberOfOutputsMethod · 0.45
SetOutputMethod · 0.45

Tested by

no test coverage detected