| 191 | } |
| 192 | |
| 193 | int mitk::PointSet::SearchPoint(Point3D point, ScalarType distance, int t) const |
| 194 | { |
| 195 | if (t >= (int)m_PointSetSeries.size()) |
| 196 | { |
| 197 | return -1; |
| 198 | } |
| 199 | |
| 200 | // Out is the point which is checked to be the searched point |
| 201 | PointType out; |
| 202 | out.Fill(0); |
| 203 | PointType indexPoint; |
| 204 | |
| 205 | this->GetGeometry(t)->WorldToIndex(point, indexPoint); |
| 206 | |
| 207 | // Searching the first point in the Set, that is +- distance far away from |
| 208 | // the given point |
| 209 | unsigned int i; |
| 210 | PointsContainer::Iterator it, end; |
| 211 | end = m_PointSetSeries[t]->GetPoints()->End(); |
| 212 | int bestIndex = -1; |
| 213 | distance = distance * distance; |
| 214 | |
| 215 | // To correct errors from converting index to world and world to index |
| 216 | if (distance == 0.0) |
| 217 | { |
| 218 | distance = 0.000001; |
| 219 | } |
| 220 | |
| 221 | ScalarType bestDist = distance; |
| 222 | ScalarType dist, tmp; |
| 223 | |
| 224 | for (it = m_PointSetSeries[t]->GetPoints()->Begin(), i = 0; it != end; ++it, ++i) |
| 225 | { |
| 226 | bool ok = m_PointSetSeries[t]->GetPoints()->GetElementIfIndexExists(it->Index(), &out); |
| 227 | |
| 228 | if (!ok) |
| 229 | { |
| 230 | return -1; |
| 231 | } |
| 232 | else if (indexPoint == out) // if totally equal |
| 233 | { |
| 234 | return it->Index(); |
| 235 | } |
| 236 | |
| 237 | // distance calculation |
| 238 | tmp = out[0] - indexPoint[0]; |
| 239 | dist = tmp * tmp; |
| 240 | tmp = out[1] - indexPoint[1]; |
| 241 | dist += tmp * tmp; |
| 242 | tmp = out[2] - indexPoint[2]; |
| 243 | dist += tmp * tmp; |
| 244 | |
| 245 | if (dist < bestDist) |
| 246 | { |
| 247 | bestIndex = it->Index(); |
| 248 | bestDist = dist; |
| 249 | } |
| 250 | } |
no test coverage detected