29 , m_ITKAssumedSliceSpacing(0.0)
30 , m_NumberOfSlicesApart(0)
35 #define doublepoint(x) \
42 #define doublevector(x) \
51 unsigned int numberOfSlicesApart)
55 , m_NumberOfSlicesApart(numberOfSlicesApart)
57 assert(numberOfSlicesApart);
81 Vector3Dd normal = itk::CrossProduct(right, up);
82 Point3Dd pointAlongNormal = origin2 + normal;
84 double numerator = itk::CrossProduct( pointAlongNormal - origin2 , origin2 - origin1 ).GetSquaredNorm();
85 double denominator = (pointAlongNormal - origin2).GetSquaredNorm();
87 double distance = sqrt(numerator / denominator);
89 if ( distance > 0.001 )
91 MITK_DEBUG <<
" Series seems to contain a tilted (or sheared) geometry";
92 MITK_DEBUG <<
" Distance of expected slice origin from actual slice origin: " << distance;
93 MITK_DEBUG <<
" ==> storing this shift for later analysis:";
100 Point3Dd projectionRight = projectPointOnLine( origin1, origin2, right );
101 Point3Dd projectionNormal = projectPointOnLine( origin1, origin2, normal );
103 m_ShiftRight = (projectionRight - origin2).GetNorm();
104 m_ShiftNormal = (projectionNormal - origin2).GetNorm();
116 double signedDistance = (
117 planeNormal[0] * testPoint[0]
118 + planeNormal[1] * testPoint[1]
119 + planeNormal[2] * testPoint[2]
121 planeNormal[0] * origin2[0]
122 + planeNormal[1] * origin2[1]
123 + planeNormal[2] * origin2[2]
127 sqrt( planeNormal[0] * planeNormal[0]
128 + planeNormal[1] * planeNormal[1]
129 + planeNormal[2] * planeNormal[2]
132 m_ShiftUp = signedDistance;
134 m_ITKAssumedSliceSpacing = (origin2 - origin1).GetNorm();
138 MITK_DEBUG <<
" calculated from slices " << m_NumberOfSlicesApart <<
" slices apart";
139 MITK_DEBUG <<
" shift normal: " << m_ShiftNormal;
140 MITK_DEBUG <<
" shift normal assumed by ITK: " << m_ITKAssumedSliceSpacing;
142 MITK_DEBUG <<
" shift right: " << m_ShiftRight;
144 MITK_DEBUG <<
" tilt angle (deg): " << atan( m_ShiftUp / m_ShiftNormal ) * 180.0 / 3.1415926535;
151 const std::string& origin1String,
152 const std::string& origin2String,
153 const std::string orientationString,
154 unsigned int numberOfSlicesApart)
158 bool orientationConversion(
false);
161 if (orientationConversion
162 && !origin1String.empty() && !origin2String.empty()
165 bool firstOriginConversion(
false);
166 bool lastOriginConversion(
false);
171 if (firstOriginConversion && lastOriginConversion)
177 std::stringstream ss;
178 ss <<
"Invalid tag values when constructing tilt information from origin1 '" << origin1String
179 <<
"', origin2 '" << origin2String
180 <<
"', and orientation '" << orientationString <<
"'";
182 throw std::invalid_argument(ss.str());
189 os <<
" calculated from slices " << m_NumberOfSlicesApart <<
" slices apart" << std::endl;
190 os <<
" shift normal: " << m_ShiftNormal << std::endl;
191 os <<
" shift normal assumed by ITK: " << m_ITKAssumedSliceSpacing << std::endl;
192 os <<
" shift up: " << m_ShiftUp << std::endl;
193 os <<
" shift right: " << m_ShiftRight << std::endl;
195 os <<
" tilt angle (deg): " << atan( m_ShiftUp / m_ShiftNormal ) * 180.0 / 3.1415926535 << std::endl;
199 mitk::GantryTiltInformation::projectPointOnLine( Point3Dd p, Point3Dd lineOrigin, Vector3Dd lineDirection )
207 Vector3Dd lineOriginToP = p - lineOrigin;
208 double innerProduct = lineOriginToP * lineDirection;
210 double factor = innerProduct / lineDirection.GetSquaredNorm();
211 Point3Dd projection = lineOrigin + factor * lineDirection;
219 return fabs(m_ShiftUp / static_cast<double>(m_NumberOfSlicesApart) * static_cast<double>(imageSizeZ-1));
225 return atan( fabs(m_ShiftUp) / m_ShiftNormal ) * 180.0 / 3.1415926535;
232 return m_ShiftUp /
static_cast<double>(m_NumberOfSlicesApart);
238 return m_ShiftNormal /
static_cast<double>(m_NumberOfSlicesApart);
245 return m_NumberOfSlicesApart &&
246 ( fabs(m_ShiftRight) > 0.001
247 || fabs(m_ShiftUp) > 0.001);
254 return m_NumberOfSlicesApart &&
255 ( fabs(m_ShiftRight) < 0.001
256 && fabs(m_ShiftUp) > 0.001);
void DICOMStringToOrientationVectors(const std::string &s, Vector3D &right, Vector3D &up, bool &successful)
Convert DICOM string describing a point two Vector3D.
Point3D DICOMStringToPoint3D(const std::string &s, bool &successful)
Convert DICOM string describing a point to Point3D.