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

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

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

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

1313 {
1314 #ifndef HOMOG2D_NOCHECKS
1315  if( shareCommonCoord( p0, p1 ) )
1317  "a coordinate of the 2 points is identical, does not define a rectangle:\n p0=" << p0 << " p1=" << p1
1318  );
1319 #endif
1320  Point2d_<FPT> p00( std::min(p0.getX(), p1.getX()), std::min(p0.getY(), p1.getY()) );
1321  Point2d_<FPT> p11( std::max(p0.getX(), p1.getX()), std::max(p0.getY(), p1.getY()) );
1322  return std::make_pair( p00, p11 );
1323 }
#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:1302
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.

8168 {
8169  if( pt.isInside( circle ) )
8170  return PtTag::Inside;
8171  if(
8172  homog2d_abs( pt.distTo( circle.center() ) - circle.radius() )
8173  < thr::nullDistance()
8174  )
8175  return PtTag::OnEdge;
8176  return PtTag::Outside;
8177 }
static HOMOG2D_INUMTYPE & nullDistance()
Definition: homog2d.hpp:1195
#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 
)
1640 {
1641 // HOMOG2D_START;
1642  Matrix_<T1> out;
1643  product( out, h1, h2 );
1644  return out;
1645 }
void product(base::LPBase< T1, FPT1 > &, const detail::Matrix_< FPT2 > &, const base::LPBase< T2, FPT1 > &)
Implementation of product 3x3 by 3x1.
Definition: homog2d.hpp:9604
Here is the call graph for this function:

◆ operator<<()

template<typename U >
std::ostream& h2d::detail::operator<< ( std::ostream &  f,
const EllParams< U > &  par 
)
2133 {
2134  f << "EllParams: origin=" << par.x0 << "," << par.y0
2135  << " angle=" << par.theta *180./M_PI
2136  << " a=" << par.a << " b=" << par.b
2137  << ' ';
2138  return f;
2139 }
#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.

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

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

4679 {
4680  if( pt.getX() > p00.getX() && pt.getX() < p11.getX() )
4681  if( pt.getY() > p00.getY() && pt.getY() < p11.getY() )
4682  return true;
4683  return false;
4684 }
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)

1288 {
1289  if(
1290  homog2d_abs( p1.getX() - p2.getX() ) < thr::nullOrthogDistance()
1291  || homog2d_abs( p1.getY() - p2.getY() ) < thr::nullOrthogDistance()
1292  )
1293  return true;
1294  return false;
1295 }
#define homog2d_abs
Definition: homog2d.hpp:69
static HOMOG2D_INUMTYPE & nullOrthogDistance()
Definition: homog2d.hpp:1200
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)

1303 {
1304  return shareCommonCoord( ppts.first , ppts.second );
1305 }
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:1302
Here is the caller graph for this function: