homog2d library
Classes | Typedefs | Enumerations | Functions
h2d::detail Namespace Reference

This namespace holds some private stuff, types here are not to be used directly by end-user code. More...

Classes

struct  AlwaysFalse
 A trick used in static_assert, so it aborts only if function is instanciated. More...
 
struct  BaseHelper
 Helper class for Root (Point/Line) type, used as a trick to allow partial specialization of member functions. More...
 
class  Common
 Common templated class for all the geometric primitives. More...
 
struct  DataFpType
 Helper class for used to get the underlying floating-point type, see Dtype and Common::dtype() More...
 
struct  EllParams
 Holds 9 parameters of Ellipse_. More...
 
struct  HelperPL
 
struct  HelperPL< typ::IsLine >
 
struct  HelperPL< typ::IsPoint >
 
class  Inters_1
 
class  Inters_2
 
class  Intersect
 Base class for intersection, gets specialized. More...
 
class  Intersect< Inters_1, FPT >
 One point intersection. More...
 
class  Intersect< Inters_2, FPT >
 Two points intersection. More...
 
struct  IntersectCommon
 Common stuff for intersection code. More...
 
class  IntersectM
 Multiple points intersections. More...
 
class  Matrix_
 A simple wrapper over a 3x3 matrix, provides root functionalities. More...
 
struct  PlHelper
 Helper class for PolylineBase, used as a trick to allow partial specialization of member functions. More...
 
class  RectArea
 Helper class, holds result of intersections of two FRect_. More...
 

Typedefs

template<typename T >
using matrix_t = std::array< std::array< T, 3 >, 3 >
 An alias used to hold data of a 3x3 matrix, see detail::Matrix_. More...
 

Enumerations

enum  PtTag : uint8_t { PtTag::Inside, PtTag::Outside, PtTag::OnEdge }
 See getPtLabel( const Point2d_<FPT>& pt, const Circle_<FPT2>& circle ) More...
 

Functions

template<typename FPT >
Homogr_< FPT > buildFrom4Points_Opencv (const std::vector< Point2d_< FPT >> &vpt1, const std::vector< Point2d_< FPT >> &vpt2)
 Build Homography from 2 sets of 4 points, using Opencv. More...
 
template<typename T1 , typename T2 , typename FPT1 , typename FPT2 >
base::LPBase< T1, FPT1 > crossProduct (const base::LPBase< T2, FPT1 > &, const base::LPBase< T2, FPT2 > &)
 
template<typename Out , typename In , typename FPT1 , typename FPT2 >
base::LPBase< Out, FPT1 > crossProduct (const base::LPBase< In, FPT1 > &r1, const base::LPBase< In, FPT2 > &r2)
 Cross product of points * points or line * line. More...
 
template<typename FPT1 , typename FPT2 >
HOMOG2D_INUMTYPE crossProductV (const base::SegVec< typ::IsOSeg, FPT1 > &v1, const base::SegVec< typ::IsOSeg, FPT2 > &v2)
 Cross product of two oriented segments, return a scalar. More...
 
template<typename T >
void drawPt (img::Image< T > &img, img::PtStyle ps, std::vector< Point2d_< float >> vpt, const img::DrawParams &dp, bool drawDiag=false)
 Private helper function, used by LPBase<IsPoint>::draw(). Draw point on image. More...
 
template<typename FPT >
PointPair_< FPT > getCorrectPoints (const Point2d_< FPT > &p0, const Point2d_< FPT > &p1)
 Private free function, get top-left and bottom-right points from two arbitrary points. More...
 
template<typename FPT , typename FPT2 >
PtTag getPtLabel (const Point2d_< FPT > &pt, const Circle_< FPT2 > &circle)
 Returns a label characterizing point pt, related to circle: inside, outside, or on edge of circle. More...
 
template<typename T1 , typename T2 >
Matrix_< T1 > operator* (const Matrix_< T1 > &h1, const Matrix_< T2 > &h2)
 
template<typename U >
std::ostream & operator<< (std::ostream &f, const EllParams< U > &par)
 
template<typename FPT1 , typename FPT2 , typename FPT3 >
void product (Matrix_< FPT1 > &out, const Matrix_< FPT2 > &h1, const Matrix_< FPT3 > &h2)
 Implementation of product 3x3 by 3x3. More...
 
template<typename T1 , typename T2 , typename FPT1 , typename FPT2 >
void product (base::LPBase< T1, FPT1 > &out, const Matrix_< FPT2 > &h, const base::LPBase< T2, FPT1 > &in)
 Implementation of product 3x3 by 3x1. More...
 
template<typename FPT1 , typename FPT2 >
bool ptIsInside (const Point2d_< FPT1 > &pt, const Point2d_< FPT2 > &p00, const Point2d_< FPT2 > &p11)
 Private free function, returns true if point pt is inside the rectangle defined by (p00 , p11) More...
 
template<typename FPT1 , typename FPT2 >
bool shareCommonCoord (const Point2d_< FPT1 > &p1, const Point2d_< FPT2 > &p2)
 Returns true if one of the points share a common coordinate (thus making them unable to define a bounding box) More...
 
template<typename FPT1 , typename FPT2 >
bool shareCommonCoord (const std::pair< Point2d_< FPT1 >, Point2d_< FPT2 >> &ppts)
 Returns true if one of the points share a common coordinate (thus making them unable to define a bounding box) More...
 

Detailed Description

This namespace holds some private stuff, types here are not to be used directly by end-user code.

Inner implementation details.

Typedef Documentation

◆ matrix_t

template<typename T >
using h2d::detail::matrix_t = typedef std::array<std::array<T,3>,3>

An alias used to hold data of a 3x3 matrix, see detail::Matrix_.

Enumeration Type Documentation

◆ PtTag

enum h2d::detail::PtTag : uint8_t
strong

Function Documentation

◆ buildFrom4Points_Opencv()

template<typename FPT >
Homogr_<FPT> h2d::detail::buildFrom4Points_Opencv ( const std::vector< Point2d_< FPT >> &  vpt1,
const std::vector< Point2d_< FPT >> &  vpt2 
)

Build Homography from 2 sets of 4 points, using Opencv.

Note
With current Opencv installed on current machine, it seems that cv::getPerspectiveTransform() requires that the points are "CV_32F" (float), and NOT double.
Parameters
vpt1source points
vpt2destination points
4755 {
4756  const auto& src = getPts<cv::Point2f>( vpt1 );
4757  const auto& dst = getPts<cv::Point2f>( vpt2 );
4758  return cv::getPerspectiveTransform( src, dst ); // automatic type conversion to Hmatrix_
4759 }
Here is the caller graph for this function:

◆ crossProduct() [1/2]

template<typename T1 , typename T2 , typename FPT1 , typename FPT2 >
base::LPBase<T1,FPT1> h2d::detail::crossProduct ( const base::LPBase< T2, FPT1 > &  ,
const base::LPBase< T2, FPT2 > &   
)

◆ crossProduct() [2/2]

template<typename Out , typename In , typename FPT1 , typename FPT2 >
base::LPBase<Out,FPT1> h2d::detail::crossProduct ( const base::LPBase< In, FPT1 > &  r1,
const base::LPBase< In, FPT2 > &  r2 
)

Cross product of points * points or line * line.

9058 {
9059  auto r1_a = static_cast<HOMOG2D_INUMTYPE>(r1._v[0]);
9060  auto r1_b = static_cast<HOMOG2D_INUMTYPE>(r1._v[1]);
9061  auto r1_c = static_cast<HOMOG2D_INUMTYPE>(r1._v[2]);
9062  auto r2_a = static_cast<HOMOG2D_INUMTYPE>(r2._v[0]);
9063  auto r2_b = static_cast<HOMOG2D_INUMTYPE>(r2._v[1]);
9064  auto r2_c = static_cast<HOMOG2D_INUMTYPE>(r2._v[2]);
9065 
9066  base::LPBase<Out,FPT1> res;
9067  res._v[0] = static_cast<FPT1>( r1_b * r2_c - r1_c * r2_b );
9068  res._v[1] = static_cast<FPT1>( r1_c * r2_a - r1_a * r2_c );
9069  res._v[2] = static_cast<FPT1>( r1_a * r2_b - r1_b * r2_a );
9070 
9071  return res;
9072 }
#define HOMOG2D_INUMTYPE
Definition: homog2d.hpp:66
Here is the caller graph for this function:

◆ crossProductV()

template<typename FPT1 , typename FPT2 >
HOMOG2D_INUMTYPE h2d::detail::crossProductV ( const base::SegVec< typ::IsOSeg, FPT1 > &  v1,
const base::SegVec< typ::IsOSeg, FPT2 > &  v2 
)

Cross product of two oriented segments, return a scalar.

9081 {
9082  auto ppts1 = v1.getPts();
9083  auto ppts2 = v2.getPts();
9084 
9085  auto dx1 =
9086  static_cast<HOMOG2D_INUMTYPE>( ppts1.second.getX() )
9087  - static_cast<HOMOG2D_INUMTYPE>( ppts1.first.getX() );
9088  auto dy1 =
9089  static_cast<HOMOG2D_INUMTYPE>( ppts1.second.getY() )
9090  - static_cast<HOMOG2D_INUMTYPE>( ppts1.first.getY() );
9091  auto dx2 =
9092  static_cast<HOMOG2D_INUMTYPE>( ppts2.second.getX() )
9093  - static_cast<HOMOG2D_INUMTYPE>( ppts2.first.getX() );
9094  auto dy2 =
9095  static_cast<HOMOG2D_INUMTYPE>( ppts2.second.getY() )
9096  - static_cast<HOMOG2D_INUMTYPE>( ppts2.first.getY() );
9097 
9098  return dx1 * dy2 - dy1 * dx2;
9099 }
#define HOMOG2D_INUMTYPE
Definition: homog2d.hpp:66
Here is the call graph for this function:
Here is the caller graph for this function:

◆ drawPt()

template<typename T >
void h2d::detail::drawPt ( img::Image< T > &  img,
img::PtStyle  ps,
std::vector< Point2d_< float >>  vpt,
const img::DrawParams dp,
bool  drawDiag = false 
)

Private helper function, used by LPBase<IsPoint>::draw(). Draw point on image.

11384 {
11385  auto delta = dp._dpValues._ptDelta;
11386  auto delta2 = std::round( 0.7 * delta);
11387  switch( ps )
11388  {
11389  case img::PtStyle::Times:
11390  case img::PtStyle::Squ:
11391  vpt[0].translate( -delta2, +delta2 );
11392  vpt[1].translate( +delta2, -delta2 );
11393  vpt[2].translate( +delta2, +delta2 );
11394  vpt[3].translate( -delta2, -delta2 );
11395  break;
11396 
11397  case img::PtStyle::Plus:
11398  case img::PtStyle::Diam:
11399  vpt[0].translate( -delta, 0. );
11400  vpt[1].translate( +delta, 0. );
11401  vpt[2].translate( 0., -delta );
11402  vpt[3].translate( 0., +delta );
11403  break;
11404  default: assert(0);
11405  }
11406  auto dp2(dp); // we need to do this, because this is called by the
11407  dp2.showPoints(false); // segment drawing function. If not, infinite recursion
11408  if( !drawDiag )
11409  {
11410  if( ps == img::PtStyle::Squ )
11411  {
11412  std::vector<Segment_<float>> vseg{
11413  {vpt[0], vpt[1]},
11414  {vpt[2], vpt[1]},
11415  {vpt[2], vpt[3]},
11416  {vpt[0], vpt[3]}
11417  };
11418  for( const auto& s:vseg )
11419  s.draw( img, dp2 );
11420  }
11421  else
11422  {
11423  Segment_<float> s1( vpt[0], vpt[1] );
11424  Segment_<float> s2( vpt[2], vpt[3] );
11425  s1.draw( img, dp2 );
11426  s2.draw( img, dp2 );
11427  }
11428  }
11429  else // draw 4 diagonal lines
11430  {
11431  Segment_<float>( vpt[0], vpt[2] ).draw( img, dp2 );
11432  Segment_<float>( vpt[2], vpt[1] ).draw( img, dp2 );
11433  Segment_<float>( vpt[1], vpt[3] ).draw( img, dp2 );
11434  Segment_<float>( vpt[0], vpt[3] ).draw( img, dp2 );
11435  }
11436 }
void draw(Data &data)
Definition: precision_test_opencv.cpp:184
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getCorrectPoints()

template<typename FPT >
PointPair_<FPT> h2d::detail::getCorrectPoints ( const Point2d_< FPT > &  p0,
const Point2d_< FPT > &  p1 
)

Private free function, get top-left and bottom-right points from two arbitrary points.

Throws if one of the coordinates is equal to the other (x1=x2 or y1=y2)

1347 {
1348 #ifndef HOMOG2D_NOCHECKS
1349  if( shareCommonCoord( p0, p1 ) )
1351  "a coordinate of the 2 points is identical, does not define a rectangle:\n p0=" << p0 << " p1=" << p1
1352  );
1353 #endif
1354  Point2d_<FPT> p00( std::min(p0.getX(), p1.getX()), std::min(p0.getY(), p1.getY()) );
1355  Point2d_<FPT> p11( std::max(p0.getX(), p1.getX()), std::max(p0.getY(), p1.getY()) );
1356  return std::make_pair( p00, p11 );
1357 }
#define HOMOG2D_THROW_ERROR_1(msg)
Error throw wrapper macro.
Definition: homog2d.hpp:181
bool shareCommonCoord(const std::pair< Point2d_< FPT1 >, Point2d_< FPT2 >> &ppts)
Returns true if one of the points share a common coordinate (thus making them unable to define a boun...
Definition: homog2d.hpp:1336
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getPtLabel()

template<typename FPT , typename FPT2 >
PtTag h2d::detail::getPtLabel ( const Point2d_< FPT > &  pt,
const Circle_< FPT2 > &  circle 
)

Returns a label characterizing point pt, related to circle: inside, outside, or on edge of circle.

8169 {
8170  if( pt.isInside( circle ) )
8171  return PtTag::Inside;
8172  if(
8173  homog2d_abs( pt.distTo( circle.center() ) - circle.radius() )
8174  < thr::nullDistance()
8175  )
8176  return PtTag::OnEdge;
8177  return PtTag::Outside;
8178 }
static HOMOG2D_INUMTYPE & nullDistance()
Definition: homog2d.hpp:1229
#define homog2d_abs
Definition: homog2d.hpp:69
Point2d pt
Definition: homog2d_test.cpp:4034
Here is the call graph for this function:
Here is the caller graph for this function:

◆ operator*()

template<typename T1 , typename T2 >
Matrix_<T1> h2d::detail::operator* ( const Matrix_< T1 > &  h1,
const Matrix_< T2 > &  h2 
)
1674 {
1675 // HOMOG2D_START;
1676  Matrix_<T1> out;
1677  product( out, h1, h2 );
1678  return out;
1679 }
void product(base::LPBase< T1, FPT1 > &, const detail::Matrix_< FPT2 > &, const base::LPBase< T2, FPT1 > &)
Implementation of product 3x3 by 3x1.
Definition: homog2d.hpp:9605
Here is the call graph for this function:

◆ operator<<()

template<typename U >
std::ostream& h2d::detail::operator<< ( std::ostream &  f,
const EllParams< U > &  par 
)
2167 {
2168  f << "EllParams: origin=" << par.x0 << "," << par.y0
2169  << " angle=" << par.theta *180./M_PI
2170  << " a=" << par.a << " b=" << par.b
2171  << ' ';
2172  return f;
2173 }
#define M_PI
Definition: homog2d.hpp:235

◆ product() [1/2]

template<typename FPT1 , typename FPT2 , typename FPT3 >
void h2d::detail::product ( Matrix_< FPT1 > &  out,
const Matrix_< FPT2 > &  h1,
const Matrix_< FPT3 > &  h2 
)

Implementation of product 3x3 by 3x3.

9590 {
9591  out.p_fillZero();
9592  for( int i=0; i<3; i++ )
9593  for( int j=0; j<3; j++ )
9594  for( int k=0; k<3; k++ )
9595  out.value(i,j) +=
9596  static_cast<HOMOG2D_INUMTYPE>( h1.value(i,k) ) * h2.value(k,j);
9597 }
#define HOMOG2D_INUMTYPE
Definition: homog2d.hpp:66
Here is the caller graph for this function:

◆ product() [2/2]

template<typename T1 , typename T2 , typename FPT1 , typename FPT2 >
void h2d::detail::product ( base::LPBase< T1, FPT1 > &  out,
const Matrix_< FPT2 > &  h,
const base::LPBase< T2, FPT1 > &  in 
)

Implementation of product 3x3 by 3x1.

9610 {
9611  for( int i=0; i<3; i++ )
9612  {
9613  auto sum = static_cast<HOMOG2D_INUMTYPE>(h._mdata[i][0]) * in._v[0];
9614  sum += h._mdata[i][1] * in._v[1];
9615  sum += h._mdata[i][2] * in._v[2];
9616  out._v[i] = sum;
9617  }
9618 }
#define HOMOG2D_INUMTYPE
Definition: homog2d.hpp:66
Here is the caller graph for this function:

◆ ptIsInside()

template<typename FPT1 , typename FPT2 >
bool h2d::detail::ptIsInside ( const Point2d_< FPT1 > &  pt,
const Point2d_< FPT2 > &  p00,
const Point2d_< FPT2 > &  p11 
)

Private free function, returns true if point pt is inside the rectangle defined by (p00 , p11)

4680 {
4681  if( pt.getX() > p00.getX() && pt.getX() < p11.getX() )
4682  if( pt.getY() > p00.getY() && pt.getY() < p11.getY() )
4683  return true;
4684  return false;
4685 }
Point2d pt
Definition: homog2d_test.cpp:4034
Here is the call graph for this function:
Here is the caller graph for this function:

◆ shareCommonCoord() [1/2]

template<typename FPT1 , typename FPT2 >
bool h2d::detail::shareCommonCoord ( const Point2d_< FPT1 > &  p1,
const Point2d_< FPT2 > &  p2 
)

Returns true if one of the points share a common coordinate (thus making them unable to define a bounding box)

1322 {
1323  if(
1324  homog2d_abs( p1.getX() - p2.getX() ) < thr::nullOrthogDistance()
1325  || homog2d_abs( p1.getY() - p2.getY() ) < thr::nullOrthogDistance()
1326  )
1327  return true;
1328  return false;
1329 }
#define homog2d_abs
Definition: homog2d.hpp:69
static HOMOG2D_INUMTYPE & nullOrthogDistance()
Definition: homog2d.hpp:1234
Here is the call graph for this function:

◆ shareCommonCoord() [2/2]

template<typename FPT1 , typename FPT2 >
bool h2d::detail::shareCommonCoord ( const std::pair< Point2d_< FPT1 >, Point2d_< FPT2 >> &  ppts)

Returns true if one of the points share a common coordinate (thus making them unable to define a bounding box)

1337 {
1338  return shareCommonCoord( ppts.first , ppts.second );
1339 }
bool shareCommonCoord(const std::pair< Point2d_< FPT1 >, Point2d_< FPT2 >> &ppts)
Returns true if one of the points share a common coordinate (thus making them unable to define a boun...
Definition: homog2d.hpp:1336
Here is the caller graph for this function: