23 std::vector<vnl_matrix_double> DataValues, vnl_vector<double> InterpolationPoints, std::string InterpolationMethod)
27 if (DataPoints.size() != DataValues.size())
29 std::cerr <<
"\n\n" << __FILE__ <<
"," << __LINE__ <<
"\n" <<
">>>>>>>> In " 30 <<
"::Number of input data points differs from number of input data values!!! Throw up ...\n";
34 std::vector<vnl_matrix_double> InterpolationData(InterpolationPoints.size());
36 if (InterpolationMethod.compare(
"closest point") == 0)
39 for (
unsigned int j = 0; j < InterpolationPoints.size(); j++)
41 while (DataPoints[i] < InterpolationPoints[j] && i < DataPoints.size() - 1)
46 if (std::abs(DataPoints[i - 1] - InterpolationPoints[j]) < std::abs(DataPoints[i] - InterpolationPoints[j]))
48 InterpolationData[j] = DataValues[i - 1];
52 InterpolationData[j] = DataValues[i];
58 else if (InterpolationMethod.compare(
"linear") == 0)
61 for (
unsigned int i = 0; i < InterpolationPoints.size(); i++)
63 while (DataPoints.get(j + 1) < InterpolationPoints.get(i) && j + 1 < DataPoints.size() - 1)
67 double t = (InterpolationPoints.get(i) - DataPoints.get(j)) / (DataPoints.get(j + 1) - DataPoints.get(j));
73 vnl_vector<double> InterpolatedTranslationComponent(4);
74 for (
int k = 0; k < 3; k++)
76 InterpolatedTranslationComponent.put(k, (1 - t) * DataValues.at(j).get(k, 3) + t * DataValues.at(j + 1).get(
80 InterpolatedTranslationComponent.put(3, 1);
91 vnl_matrix<double> P = DataValues.at(j).extract(3, 3);
92 vnl_matrix<double> Q = DataValues.at(j + 1).extract(3, 3);
93 vnl_matrix<double> R = P.transpose() * Q;
97 vnl_vector<double> A(3, 0);
98 double Argument = (R.get(0, 0) + R.get(1, 1) + R.get(2, 2) - 1) / 2;
108 double theta = acos(Argument);
116 else if (theta < 3.14159265)
118 A.put(0, R.get(2, 1) - R.get(1, 2));
119 A.put(1, R.get(0, 2) - R.get(2, 0));
120 A.put(2, R.get(1, 0) - R.get(0, 1));
125 if (R.get(0, 0) > R.get(1, 1) && R.get(0, 0) > R.get(2, 2))
127 A.put(0, sqrt(R.get(0, 0) - R.get(1, 1) - R.get(2, 2) + 1) / 2);
128 A.put(1, R.get(0, 1) / (2 * A.get(0)));
129 A.put(2, R.get(0, 2) / (2 * A.get(0)));
131 else if (R.get(1, 1) > R.get(0, 0) && R.get(0, 0) > R.get(2, 2))
133 A.put(1, sqrt(R.get(1, 1) - R.get(0, 0) - R.get(2, 2) + 1) / 2);
134 A.put(0, R.get(0, 1) / (2 * A.get(1)));
135 A.put(2, R.get(1, 2) / (2 * A.get(1)));
139 A.put(2, sqrt(R.get(2, 2) - R.get(1, 1) - R.get(0, 0) + 1) / 2);
140 A.put(1, R.get(1, 2) / (2 * A.get(2)));
141 A.put(0, R.get(0, 2) / (2 * A.get(2)));
148 vnl_matrix<double> S(3, 3, 0);
149 vnl_matrix<double> I(3, 3);
150 vnl_matrix<double> Rt(3, 3);
152 S.put(0, 1, -A.get(2));
153 S.put(0, 2, A.get(1));
154 S.put(1, 0, A.get(2));
155 S.put(1, 2, -A.get(0));
156 S.put(2, 0, -A.get(1));
157 S.put(2, 1, A.get(0));
161 Rt = I + sin(t * theta) * S + (1 - cos(t * theta)) * S * S;
166 vnl_matrix<double> InterpolatedRotationComponent = P * Rt;
173 InterpolationData.at(i).set_size(4, 4);
174 InterpolationData.at(i).fill(0);
175 for (
int r = 0; r < 3; r++)
177 for (
int c = 0; c < 3; c++)
179 InterpolationData.at(i).put(r, c, InterpolatedRotationComponent.get(r, c));
182 InterpolationData.at(i).set_column(3, InterpolatedTranslationComponent);
186 return InterpolationData;
190 std::cerr <<
"\n\n" << __FILE__ <<
"," << __LINE__ <<
"\n" <<
">>>>>>>> In " 191 <<
"::Failed to interpolate the given data!!! Throw up ...\n";
std::vector< vnl_matrix_double > matrixInterpolation(vnl_vector< double > DataPoints, std::vector< vnl_matrix_double > DataValues, vnl_vector< double > InterpolationPoints, std::string InterpolationMethod)
Operation: Interpolate transformation matrices.