Mercurial > hg > orthanc-stone
comparison Framework/Toolbox/CoordinateSystem3D.cpp @ 158:a053ca7fa5c6 wasm
LinearAlgebra toolbox
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 14 Feb 2018 08:58:31 +0100 |
parents | 2309e8d86efe |
children | fccffbf99ba1 |
comparison
equal
deleted
inserted
replaced
157:2309e8d86efe | 158:a053ca7fa5c6 |
---|---|
19 **/ | 19 **/ |
20 | 20 |
21 | 21 |
22 #include "CoordinateSystem3D.h" | 22 #include "CoordinateSystem3D.h" |
23 | 23 |
24 #include "LinearAlgebra.h" | |
24 #include "GeometryToolbox.h" | 25 #include "GeometryToolbox.h" |
25 | 26 |
26 #include <Core/Logging.h> | 27 #include <Core/Logging.h> |
27 #include <Core/Toolbox.h> | 28 #include <Core/Toolbox.h> |
28 #include <Core/OrthancException.h> | 29 #include <Core/OrthancException.h> |
34 // DICOM expects normal vectors to define the axes: "The row and | 35 // DICOM expects normal vectors to define the axes: "The row and |
35 // column direction cosine vectors shall be normal, i.e., the dot | 36 // column direction cosine vectors shall be normal, i.e., the dot |
36 // product of each direction cosine vector with itself shall be | 37 // product of each direction cosine vector with itself shall be |
37 // unity." | 38 // unity." |
38 // http://dicom.nema.org/medical/dicom/current/output/chtml/part03/sect_C.7.6.2.html | 39 // http://dicom.nema.org/medical/dicom/current/output/chtml/part03/sect_C.7.6.2.html |
39 if (!GeometryToolbox::IsNear(boost::numeric::ublas::norm_2(axisX_), 1.0) || | 40 if (!LinearAlgebra::IsNear(boost::numeric::ublas::norm_2(axisX_), 1.0) || |
40 !GeometryToolbox::IsNear(boost::numeric::ublas::norm_2(axisY_), 1.0)) | 41 !LinearAlgebra::IsNear(boost::numeric::ublas::norm_2(axisY_), 1.0)) |
41 { | 42 { |
42 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat); | 43 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat); |
43 } | 44 } |
44 | 45 |
45 // The vectors within "Image Orientation Patient" must be | 46 // The vectors within "Image Orientation Patient" must be |
46 // orthogonal, according to the DICOM specification: "The row and | 47 // orthogonal, according to the DICOM specification: "The row and |
47 // column direction cosine vectors shall be orthogonal, i.e., | 48 // column direction cosine vectors shall be orthogonal, i.e., |
48 // their dot product shall be zero." | 49 // their dot product shall be zero." |
49 // http://dicom.nema.org/medical/dicom/current/output/chtml/part03/sect_C.7.6.2.html | 50 // http://dicom.nema.org/medical/dicom/current/output/chtml/part03/sect_C.7.6.2.html |
50 if (!GeometryToolbox::IsCloseToZero(boost::numeric::ublas::inner_prod(axisX_, axisY_))) | 51 if (!LinearAlgebra::IsCloseToZero(boost::numeric::ublas::inner_prod(axisX_, axisY_))) |
51 { | 52 { |
52 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat); | 53 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat); |
53 } | 54 } |
54 | 55 |
55 GeometryToolbox::CrossProduct(normal_, axisX_, axisY_); | 56 LinearAlgebra::CrossProduct(normal_, axisX_, axisY_); |
56 | 57 |
57 d_ = -(normal_[0] * origin_[0] + normal_[1] * origin_[1] + normal_[2] * origin_[2]); | 58 d_ = -(normal_[0] * origin_[0] + normal_[1] * origin_[1] + normal_[2] * origin_[2]); |
58 | 59 |
59 // Just a sanity check, it should be useless by construction | 60 // Just a sanity check, it should be useless by construction |
60 assert(GeometryToolbox::IsNear(boost::numeric::ublas::norm_2(normal_), 1.0)); | 61 assert(LinearAlgebra::IsNear(boost::numeric::ublas::norm_2(normal_), 1.0)); |
61 } | 62 } |
62 | 63 |
63 | 64 |
64 void CoordinateSystem3D::SetupCanonical() | 65 void CoordinateSystem3D::SetupCanonical() |
65 { | 66 { |
66 GeometryToolbox::AssignVector(origin_, 0, 0, 0); | 67 LinearAlgebra::AssignVector(origin_, 0, 0, 0); |
67 GeometryToolbox::AssignVector(axisX_, 1, 0, 0); | 68 LinearAlgebra::AssignVector(axisX_, 1, 0, 0); |
68 GeometryToolbox::AssignVector(axisY_, 0, 1, 0); | 69 LinearAlgebra::AssignVector(axisY_, 0, 1, 0); |
69 CheckAndComputeNormal(); | 70 CheckAndComputeNormal(); |
70 } | 71 } |
71 | 72 |
72 | 73 |
73 CoordinateSystem3D::CoordinateSystem3D(const Vector& origin, | 74 CoordinateSystem3D::CoordinateSystem3D(const Vector& origin, |
86 { | 87 { |
87 std::string tmpPosition = Orthanc::Toolbox::StripSpaces(imagePositionPatient); | 88 std::string tmpPosition = Orthanc::Toolbox::StripSpaces(imagePositionPatient); |
88 std::string tmpOrientation = Orthanc::Toolbox::StripSpaces(imageOrientationPatient); | 89 std::string tmpOrientation = Orthanc::Toolbox::StripSpaces(imageOrientationPatient); |
89 | 90 |
90 Vector orientation; | 91 Vector orientation; |
91 if (!GeometryToolbox::ParseVector(origin_, tmpPosition) || | 92 if (!LinearAlgebra::ParseVector(origin_, tmpPosition) || |
92 !GeometryToolbox::ParseVector(orientation, tmpOrientation) || | 93 !LinearAlgebra::ParseVector(orientation, tmpOrientation) || |
93 origin_.size() != 3 || | 94 origin_.size() != 3 || |
94 orientation.size() != 6) | 95 orientation.size() != 6) |
95 { | 96 { |
96 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat); | 97 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat); |
97 } | 98 } |