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
4758 {
4759  const auto& src = getPts<cv::Point2f>( vpt1 );
4760  const auto& dst = getPts<cv::Point2f>( vpt2 );
4761  return cv::getPerspectiveTransform( src, dst ); // automatic type conversion to Hmatrix_
4762 }
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.

9061 {
9062  auto r1_a = static_cast<HOMOG2D_INUMTYPE>(r1._v[0]);
9063  auto r1_b = static_cast<HOMOG2D_INUMTYPE>(r1._v[1]);
9064  auto r1_c = static_cast<HOMOG2D_INUMTYPE>(r1._v[2]);
9065  auto r2_a = static_cast<HOMOG2D_INUMTYPE>(r2._v[0]);
9066  auto r2_b = static_cast<HOMOG2D_INUMTYPE>(r2._v[1]);
9067  auto r2_c = static_cast<HOMOG2D_INUMTYPE>(r2._v[2]);
9068 
9069  base::LPBase<Out,FPT1> res;
9070  res._v[0] = static_cast<FPT1>( r1_b * r2_c - r1_c * r2_b );
9071  res._v[1] = static_cast<FPT1>( r1_c * r2_a - r1_a * r2_c );
9072  res._v[2] = static_cast<FPT1>( r1_a * r2_b - r1_b * r2_a );
9073 
9074  return res;
9075 }
#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.

9084 {
9085  auto ppts1 = v1.getPts();
9086  auto ppts2 = v2.getPts();
9087 
9088  auto dx1 =
9089  static_cast<HOMOG2D_INUMTYPE>( ppts1.second.getX() )
9090  - static_cast<HOMOG2D_INUMTYPE>( ppts1.first.getX() );
9091  auto dy1 =
9092  static_cast<HOMOG2D_INUMTYPE>( ppts1.second.getY() )
9093  - static_cast<HOMOG2D_INUMTYPE>( ppts1.first.getY() );
9094  auto dx2 =
9095  static_cast<HOMOG2D_INUMTYPE>( ppts2.second.getX() )
9096  - static_cast<HOMOG2D_INUMTYPE>( ppts2.first.getX() );
9097  auto dy2 =
9098  static_cast<HOMOG2D_INUMTYPE>( ppts2.second.getY() )
9099  - static_cast<HOMOG2D_INUMTYPE>( ppts2.first.getY() );
9100 
9101  return dx1 * dy2 - dy1 * dx2;
9102 }
#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.

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

8172 {
8173  if( pt.isInside( circle ) )
8174  return PtTag::Inside;
8175  if(
8176  homog2d_abs( pt.distTo( circle.center() ) - circle.radius() )
8177  < thr::nullDistance()
8178  )
8179  return PtTag::OnEdge;
8180  return PtTag::Outside;
8181 }
static HOMOG2D_INUMTYPE & nullDistance()
Definition: homog2d.hpp:1229
#define homog2d_abs
Definition: homog2d.hpp:69
Point2d pt
Definition: homog2d_test.cpp:4052
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:9608
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.

9593 {
9594  out.p_fillZero();
9595  for( int i=0; i<3; i++ )
9596  for( int j=0; j<3; j++ )
9597  for( int k=0; k<3; k++ )
9598  out.value(i,j) +=
9599  static_cast<HOMOG2D_INUMTYPE>( h1.value(i,k) ) * h2.value(k,j);
9600 }
#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.

9613 {
9614  for( int i=0; i<3; i++ )
9615  {
9616  auto sum = static_cast<HOMOG2D_INUMTYPE>(h._mdata[i][0]) * in._v[0];
9617  sum += h._mdata[i][1] * in._v[1];
9618  sum += h._mdata[i][2] * in._v[2];
9619  out._v[i] = sum;
9620  }
9621 }
#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)

4683 {
4684  if( pt.getX() > p00.getX() && pt.getX() < p11.getX() )
4685  if( pt.getY() > p00.getY() && pt.getY() < p11.getY() )
4686  return true;
4687  return false;
4688 }
Point2d pt
Definition: homog2d_test.cpp:4052
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: