00001
00002
00003
00004
00005 #if !defined (AQSENSE_SAL3DPP_MATCH3D_HPP)
00006 #define AQSENSE_SAL3DPP_MATCH3D_HPP
00007
00008 #if defined (_MSC_VER) && (_MSC_VER >= 1020)
00009 #pragma once
00010 #endif // _MSC_VER && _MSC_VER >= 1020
00011
00012 #include <sal3d/match3d.h>
00013 #include <sal3dpp/COP.hpp>
00014 #include <vector>
00015
00016 namespace
00017 {
00018 const int defaultMaxIterations = 100;
00019 const float defaultMaxTranslationError = 0.005f;
00020 const float defaultMaxRotationError = 0.001f;
00021 const bool defaultExtractFeatures = true;
00022 }
00023
00024 namespace sal3d
00025 {
00027 typedef sal3d_surface_point SurfacePoint;
00030 typedef std::vector<SurfacePoint> SurfacePoints;
00031
00042 struct Match3DParameters
00043 {
00044 Match3DParameters():
00045 maxIterations(defaultMaxIterations),
00046 maxTranslationError(defaultMaxTranslationError),
00047 maxRotationError(defaultMaxRotationError),
00048 extractFeatures(defaultExtractFeatures)
00049 {}
00050
00056 int maxIterations;
00057
00067 float maxTranslationError;
00068
00079 float maxRotationError;
00080
00083 bool extractFeatures;
00084 };
00085
00156 class Match3D
00157 {
00158 public:
00172 explicit Match3D (const sal3d::COP &cop)
00173 {
00174 _match3d.p = 0;
00175 Error e;
00176 sal3d_match3d_new_with_cop (cop.c_cop (), &_match3d, &e.e);
00177 if (e.e.value < 0)
00178 throw e;
00179 }
00180
00194 explicit Match3D (const SurfacePoints &points)
00195 {
00196 _match3d.p = 0;
00197 Error e;
00198 sal3d_match3d_new_with_surface_points (&points[0], points.size(), &_match3d,
00199 &e.e);
00200 if (e.e.value < 0)
00201 throw e;
00202 }
00203
00209 Match3D (const Match3D &match3d):
00210 _match3d (match3d._match3d)
00211 {
00212 Error e;
00213 sal3d_match3d_share (_match3d, &e.e);
00214 if (e.e.value < 0)
00215 throw e;
00216 }
00217
00221 ~Match3D ()
00222 {
00223 sal3d_match3d_release (_match3d);
00224 }
00225
00240 Movement3D
00241 operator() (const sal3d::COP &cop) const
00242 {
00243 float quality;
00244 int iters;
00245 Match3DParameters params;
00246
00247 return this->operator()(cop, params, quality, iters);
00248 }
00249
00268 Movement3D
00269 operator() (const sal3d::COP &cop, float &quality) const
00270 {
00271 int iters;
00272 Match3DParameters params;
00273
00274 return this->operator()(cop, params, quality, iters);
00275 }
00276
00304 Movement3D
00305 operator() (const sal3d::COP &cop, const Match3DParameters ¶ms,
00306 float &quality, int &iterations) const
00307 {
00308 sal3d_movement_3d movement;
00309 Error e;
00310 sal3d_match3d_align (_match3d, cop.c_cop (),
00311 params.maxIterations, params.maxTranslationError,
00312 params.maxRotationError, params.extractFeatures,
00313 &movement, &quality, &iterations, &e.e);
00314 if (e.e.value < 0)
00315 throw e;
00316
00317 return Movement3D (movement);
00318 }
00319
00338 Movement3D
00339 operator() (const sal3d::COP &cop,
00340 const Movement3D &prealign) const
00341 {
00342 float quality;
00343 int iters;
00344 Match3DParameters params;
00345
00346 return this->operator()(cop, prealign, params, quality, iters);
00347 }
00348
00370 Movement3D
00371 operator() (const sal3d::COP &cop,
00372 const Movement3D &prealign, float &quality) const
00373 {
00374 int iters;
00375 Match3DParameters params;
00376
00377 return this->operator()(cop, prealign, params, quality, iters);
00378 }
00379
00410 Movement3D
00411 operator() (const sal3d::COP &cop, const Movement3D &prealign,
00412 const Match3DParameters ¶ms, float &quality,
00413 int &iterations) const
00414 {
00415 sal3d_movement_3d movement;
00416 Error e;
00417 sal3d_match3d_align_moved(_match3d, cop.c_cop(),
00418 &prealign.c_movement_3d(), params.maxIterations,
00419 params.maxTranslationError,
00420 params.maxRotationError, params.extractFeatures,
00421 &movement, &quality, &iterations, &e.e);
00422
00423 if (e.e.value < 0)
00424 throw e;
00425
00426 return Movement3D (movement);
00427 }
00428
00436 Match3D &
00437 operator= (const Match3D &rhs)
00438 {
00439 Error e;
00440 sal3d_match3d_share (rhs._match3d, &e.e);
00441 if (e.e.value < 0)
00442 throw e;
00443 sal3d_match3d_release (_match3d);
00444 _match3d = rhs._match3d;
00445
00446 return *this;
00447 }
00448
00449 private:
00451 sal3d_match3d _match3d;
00452 };
00453 }
00454
00455 #endif // !AQSENSE_SAL3DPP_MATCH3D_HPP