5#include "../_cexports/c_foundation.h"
6#include "cvb/area_2d.hpp"
7#include "cvb/line_2d.hpp"
8#include "cvb/matrix_2d.hpp"
40 Internal::DoResCall([&]() {
41 return CVB_CALL_CAPI(CVFResampleCurve2D(
42 reinterpret_cast<const CExports::CVIPointD *
>(curve.data()),
43 static_cast<CExports::cvbdim_t
>(curve.size()),
44 static_cast<CExports::cvbdim_t
>(resampledCurve.size()),
45 reinterpret_cast<CExports::CVIPointD *
>(resampledCurve.data()));
47 return resampledCurve;
72 , minImprovement_(1e-3)
89 : maxIterations_(maxIterations)
90 , tolerance_(tolerance)
91 , minImprovement_(minImprovement)
92 , correspondence_(correspondence)
110 return maxIterations_;
120 maxIterations_ = maxIterations;
143 tolerance_ = tolerance;
156 return minImprovement_;
166 minImprovement_ = minImprovement;
178 return correspondence_;
190 correspondence_ = correspondence;
214 size_t maxIterations_;
216 double minImprovement_;
217 double correspondence_;
260 return meanDistance_;
270 return numIterations_;
276 , numIterations_(0){};
280 double meanDistance_;
281 size_t numIterations_;
310 Internal::DoResCall([&]() {
311 return CVB_CALL_CAPI(CVFAlignCurves2D(
reinterpret_cast<const CExports::CVIPointD *
>(curve.data()),
312 static_cast<CExports::cvbdim_t
>(curve.size()),
313 reinterpret_cast<const CExports::CVIPointD *
>(curveToBeAligned.data()),
314 static_cast<CExports::cvbdim_t
>(curveToBeAligned.size()),
315 reinterpret_cast<const CExports::CVFAlignmentConfiguration &
>(config),
316 reinterpret_cast<CExports::CVFAlignment2DResult &
>(result)));
340 Internal::DoResCall([&]() {
341 return CVB_CALL_CAPI(
342 CVFCalculateSignedDifferences(
reinterpret_cast<const CExports::CVIPointD *
>(curve.data()),
343 static_cast<CExports::cvbdim_t
>(curve.size()),
344 reinterpret_cast<const CExports::CVIPointD *
>(points.data()),
345 static_cast<CExports::cvbdim_t
>(points.size()), differences.data()));
377 auto intersectionPointsCalculatedLength = intersectionPoints.size();
378 auto normal = line.
Normal();
379 Internal::DoResCall([&]() {
380 return CVB_CALL_CAPI(CVFIntersectCurve2DWithLine(
381 reinterpret_cast<const CExports::CVIPointD *
>(curve.data()),
382 static_cast<CExports::cvbdim_t
>(curve.size()), *
reinterpret_cast<const CExports::CVIPointD *
>(&normal),
383 line.
Distance(),
static_cast<CExports::cvbdim_t
>(intersectionPoints.size()),
384 reinterpret_cast<CExports::CVIPointD *
>(intersectionPoints.data()),
385 reinterpret_cast<CExports::cvbdim_t &
>(intersectionPointsCalculatedLength)));
387 intersectionPoints.resize(intersectionPointsCalculatedLength);
388 return intersectionPoints;
418 double enclosedArea = 0;
419 Internal::DoResCall([&]() {
420 return CVB_CALL_CAPI(CVFCalculateEnclosedArea(
reinterpret_cast<const CExports::CVIPointD *
>(curve.data()),
421 static_cast<CExports::cvbdim_t
>(curve.size()), &enclosedArea));
444 Internal::DoResCall([&]() {
445 return CVB_CALL_CAPI(CVFCalculateQuadraticDifferencesToClosestPoint(
446 reinterpret_cast<const CExports::CVIPointD *
>(curve.data()),
447 static_cast<CExports::cvbdim_t
>(curve.size()),
448 reinterpret_cast<const CExports::CVIPointD *
>(points.data()),
449 static_cast<CExports::cvbdim_t
>(points.size()),
reinterpret_cast<double *
>(&distance)));
505 int mergedLength = 0;
506 Internal::DoResCall([&]() {
507 return CVB_CALL_CAPI(CVFMerge2Curves(
reinterpret_cast<const CExports::CVIPointD *
>(curveLHS.data()),
508 static_cast<CExports::cvbdim_t
>(curveLHS.size()),
509 reinterpret_cast<const CExports::CVIPointD *
>(curveRHS.data()),
510 static_cast<CExports::cvbdim_t
>(curveRHS.size()),
512 static_cast<CExports::cvbdim_t
>(mergedCurve.size()),
513 reinterpret_cast<CExports::CVIPointD *
>(mergedCurve.data()),
514 reinterpret_cast<CExports::cvbdim_t &
>(mergedLength)));
516 if (mergedLength !=
static_cast<int>(mergedCurve.size()))
517 mergedCurve.resize(mergedLength);
523 using Curve::AlignmentConfiguration;
524 using Curve::AlignmentResult2D;
A set of parameters that configures an alignment operation.
Definition: curve.hpp:67
AlignmentConfiguration(size_t maxIterations, double tolerance, double minImprovement, double correspondence, PreAlignmentMode mode) noexcept
Constructor for an alignment configuration.
Definition: curve.hpp:87
double Tolerance() const noexcept
Gets the value for early stopping criteria.
Definition: curve.hpp:131
PreAlignmentMode Mode() const noexcept
Gets the pre-align mode.
Definition: curve.hpp:198
void SetTolerance(double tolerance) noexcept
Sets the value for early stopping criteria.
Definition: curve.hpp:141
size_t MaxIterations() const noexcept
Gets the maximum iterations of ICP.
Definition: curve.hpp:108
void SetMode(PreAlignmentMode mode) noexcept
Sets the pre-align mode.
Definition: curve.hpp:208
void SetCorrespondence(double correspondence) noexcept
Sets the minimum value for correspondence of two points to be considered for alignment.
Definition: curve.hpp:188
double MinImprovement() const noexcept
Gets the value for early stopping criteria.
Definition: curve.hpp:154
void SetMinImprovement(double minImprovement) noexcept
Sets the value for early stopping criteria.
Definition: curve.hpp:164
void SetMaxIterations(size_t maxIterations) noexcept
Sets the maximum iterations of ICP.
Definition: curve.hpp:118
double Correspondence() const noexcept
Gets the minimum value for correspondence of two points to be considered for alignment.
Definition: curve.hpp:176
A set of parameters that stores the result of alignment operation.
Definition: curve.hpp:225
size_t NumIterations() const noexcept
Gets the number of iterations needed for alignment.
Definition: curve.hpp:268
const Matrix2D & Rotation() const noexcept
Gets the estimated rotation.
Definition: curve.hpp:238
friend AlignmentResult2D AlignCurve(const std::vector< Point2D< double > > &, const std::vector< Point2D< double > > &, const AlignmentConfiguration &)
Aligns two 2D curves via an iterative closest point method considering consensus correspondence for b...
Definition: curve.hpp:305
double MeanDistance() const noexcept
Gets the mean distance between reference and aligned curve.
Definition: curve.hpp:258
const Vector2D< double > & Translation() const noexcept
Gets the estimated translation.
Definition: curve.hpp:248
Object representing an infinite line in 2 dimensional space.
Definition: line_2d.hpp:16
double Distance() const noexcept
Gets the distance of the line from the origin.
Definition: line_2d.hpp:73
Point2D< double > Normal() const noexcept
Gets the normal vector of the line.
Definition: line_2d.hpp:52
Double precision 2x2 matrix class.
Definition: matrix_2d.hpp:16
double CalculateEnclosedArea(const std::vector< Point2D< double > > &curve)
Calculates the enclosed area of the given curve.
Definition: curve.hpp:416
Matrix2D CalculateQuadraticDifferencesToClosestPoint(const std::vector< Point2D< double > > &curve, const std::vector< Point2D< double > > &points)
Calculates the quadratic distance of the points to the closest point of the given curve.
Definition: curve.hpp:440
std::vector< double > CalculateSignedDifferences(const std::vector< Point2D< double > > &curve, const std::vector< Point2D< double > > &points)
Calculates signed differences along the y axis of given points to curve (curve - points).
Definition: curve.hpp:336
AlignmentResult2D AlignCurve(const std::vector< Point2D< double > > &curve, const std::vector< Point2D< double > > &curveToBeAligned, const AlignmentConfiguration &config=AlignmentConfiguration())
Aligns two 2D curves via an iterative closest point method considering consensus correspondence for b...
Definition: curve.hpp:305
std::vector< Point2D< double > > IntersectWithLine(const std::vector< Point2D< double > > &curve, const Line2D &line)
Intersects a 2D curve with a line.
Definition: curve.hpp:373
StartSelectionMode
Decides which start point should be used for the new curve.
Definition: curve.hpp:456
std::vector< Point2D< double > > ResampleCurve(const std::vector< Point2D< double > > &curve, int resampledCurveLength)
Resamples a 2-dimensional curve via linear interpolation assuming that the "speed" of the time mappin...
Definition: curve.hpp:37
PreAlignmentMode
Specifies if the pre-alignment is required.
Definition: curve.hpp:52
std::vector< Point2D< double > > MergeTwoCurves(const std::vector< Point2D< double > > &curveLHS, const std::vector< Point2D< double > > &curveRHS, const StartSelectionMode &mode)
Merges two curves into one curve with interpolation.
Definition: curve.hpp:500
Root namespace for the Image Manager interface.
Definition: c_barcode.h:24