| 52 | // Update the 4x4 matrix. Updates are only done as necessary. |
| 53 | |
| 54 | void vtkLandmarkTransform::InternalUpdate() |
| 55 | { |
| 56 | vtkIdType i; |
| 57 | int j; |
| 58 | |
| 59 | if (this->SourceLandmarks == nullptr || this->TargetLandmarks == nullptr) |
| 60 | { |
| 61 | this->Matrix->Identity(); |
| 62 | return; |
| 63 | } |
| 64 | |
| 65 | // --- compute the necessary transform to match the two sets of landmarks --- |
| 66 | |
| 67 | /* |
| 68 | The solution is based on |
| 69 | Berthold K. P. Horn (1987), |
| 70 | "Closed-form solution of absolute orientation using unit quaternions," |
| 71 | Journal of the Optical Society of America A, 4:629-642 |
| 72 | */ |
| 73 | |
| 74 | // Original python implementation by David G. Gobbi |
| 75 | |
| 76 | const vtkIdType N_PTS = this->SourceLandmarks->GetNumberOfPoints(); |
| 77 | if (N_PTS != this->TargetLandmarks->GetNumberOfPoints()) |
| 78 | { |
| 79 | vtkErrorMacro("Update: Source and Target Landmarks contain a different number of points"); |
| 80 | return; |
| 81 | } |
| 82 | |
| 83 | // -- if no points, stop here |
| 84 | |
| 85 | if (N_PTS == 0) |
| 86 | { |
| 87 | this->Matrix->Identity(); |
| 88 | return; |
| 89 | } |
| 90 | |
| 91 | // -- find the centroid of each set -- |
| 92 | |
| 93 | double source_centroid[3] = { 0, 0, 0 }; |
| 94 | double target_centroid[3] = { 0, 0, 0 }; |
| 95 | double p[3]; |
| 96 | for (i = 0; i < N_PTS; i++) |
| 97 | { |
| 98 | this->SourceLandmarks->GetPoint(i, p); |
| 99 | source_centroid[0] += p[0]; |
| 100 | source_centroid[1] += p[1]; |
| 101 | source_centroid[2] += p[2]; |
| 102 | this->TargetLandmarks->GetPoint(i, p); |
| 103 | target_centroid[0] += p[0]; |
| 104 | target_centroid[1] += p[1]; |
| 105 | target_centroid[2] += p[2]; |
| 106 | } |
| 107 | source_centroid[0] /= N_PTS; |
| 108 | source_centroid[1] /= N_PTS; |
| 109 | source_centroid[2] /= N_PTS; |
| 110 | target_centroid[0] /= N_PTS; |
| 111 | target_centroid[1] /= N_PTS; |
nothing calls this directly
no test coverage detected