homog2d library
Classes | Functions
h2d::base Namespace Reference

Holds base classes, not part of API. More...

Classes

class  LPBase
 Base class, will be instanciated as Point2d_ or Line2d_. More...
 
class  PolylineBase
 Polyline, will be instanciated either as OPolyline_ (open polyline) or CPolyline_. More...
 
class  SegVec
 A line segment, oriented (OSegment_) or not (Segment_). Holds the two points. More...
 

Functions

template<typename FPT >
CPolyline_< FPT > convexHull (const std::vector< Point2d_< FPT >> &input)
 Computes and returns the convex hull of a set of points (free function) More...
 
template<typename LP , typename FPT >
auto operator<< (std::ostream &, const h2d::base::LPBase< LP, FPT > &) -> std::ostream &
 Stream operator, free function, call member function pseudo operator impl_op_stream() More...
 
template<typename T1 , typename T2 >
auto operator<< (std::ostream &, const h2d::base::PolylineBase< T1, T2 > &) -> std::ostream &
 
template<typename LP , typename FPT >
std::ostream & operator<< (std::ostream &f, const h2d::base::LPBase< LP, FPT > &pl)
 Stream operator, free function, call member function pseudo operator impl_op_stream() More...
 
template<typename SV , typename T >
std::ostream & operator<< (std::ostream &f, const h2d::base::SegVec< SV, T > &seg)
 
template<typename PLT , typename FPT >
std::ostream & operator<< (std::ostream &f, const h2d::base::PolylineBase< PLT, FPT > &pl)
 

Detailed Description

Holds base classes, not part of API.

Draw Segment / OSegment (SVG implementation)

Draw Segment / OSegment (Opencv implementation)

Todo:
20250201: why do we need this and why isn't the same required for OSegment_ ?
Todo:
20250127: implement arrows for the Opencv/png version, and share the code between the two versions

Function Documentation

◆ convexHull()

template<typename FPT >
CPolyline_<FPT> h2d::base::convexHull ( const std::vector< Point2d_< FPT >> &  input)

Computes and returns the convex hull of a set of points (free function)

Todo:
20230728: make this function accept also std::array and std::list (using Sfinae alogn with trait::IsContainer)
11553 {
11554  if( input.size() < 4 ) // if 3 pts or less, then the hull is equal to input set
11555  return CPolyline_<FPT>( input );
11556 
11557 // step 1: find pivot (point with smallest Y coord)
11558  auto pivot_idx = priv::chull::getPivotPoint( input );
11559 
11560 // step 2: sort points by angle of lines between the current point and pivot point
11561  auto v2 = priv::chull::sortPoints( input, pivot_idx );
11562 
11563  std::stack<size_t> firstPoint;
11564  priv::chull::Mystack hull;
11565  hull.push( v2[0] );
11566  hull.push( v2[1] );
11567  hull.push( v2[2] );
11568 
11569  firstPoint.push( 0 );
11570  firstPoint.push( 1 );
11571 
11572 // step 3: iterate
11573  size_t idx1 = 1;
11574  size_t idx2 = 2;
11575  size_t idx3 = 3;
11576  do
11577  {
11578 // HOMOG2D_LOG( "** loop start, idx1=" << idx1 << ", idx2=" << idx2 << ", idx3=" << idx3 << ", hull " << hull.getVect() );
11579  auto p = input.at( v2[idx1] );
11580  auto q = input.at( v2[idx2] );
11581  auto r = input.at( v2[idx3] );
11582  auto orient = priv::chull::orientation( p, q, r );
11583 // HOMOG2D_LOG( "considering pts: " << v2[idx1] << "," << v2[idx2] << "," << v2[idx3] << ": or = " << orient );
11584  if( orient != 1 )
11585  {
11586  hull.push( v2[idx3] );
11587  idx1 = idx2;
11588  idx2 = idx3;
11589  idx3++;
11590  firstPoint.push( idx1 );
11591  }
11592  else
11593  {
11594  hull.pop();
11595  idx2=idx1; // idx3 stays the same
11596  firstPoint.pop();
11597  idx1 = firstPoint.top();
11598  }
11599  }
11600  while( idx3 < v2.size() );
11601 
11602 // final step: copy hull indexes to vector of points
11603  const auto v = hull.getVect();
11604  std::vector<Point2d_<FPT>> vout( v.size() );
11606  v.begin(),
11607  v.end(),
11608  vout.begin(),
11609  [&input] // lambda
11610  (size_t idx)
11611  {
11612  return input.at( idx );
11613  }
11614  );
11615 
11616  return CPolyline_<FPT>( vout );
11617 }
std::vector< size_t > sortPoints(const std::vector< Point2d_< FPT >> &in, size_t piv_idx)
Sorts points by angle between the lines with horizontal axis.
Definition: homog2d.hpp:11459
int orientation(Point2d_< T > p, Point2d_< T > q, Point2d_< T > r)
To find orientation of ordered triplet of points (p, q, r).
Definition: homog2d.hpp:11500
CommonType_< FPT > transform(const Homogr_< FPT > &h, const T &elem)
Apply homography to primitive.
Definition: homog2d.hpp:10379
size_t getPivotPoint(const std::vector< Point2d_< FPT >> &in)
Used int the convex hull algorithm.
Definition: homog2d.hpp:11449
Here is the call graph for this function:

◆ operator<<() [1/5]

template<typename LP , typename FPT >
auto h2d::base::operator<< ( std::ostream &  ,
const h2d::base::LPBase< LP, FPT > &   
) -> std::ostream &

Stream operator, free function, call member function pseudo operator impl_op_stream()

8363 {
8364  if constexpr( std::is_same_v<LP,typ::IsLine> )
8365  f << '[' << pl._v[0] << ',' << pl._v[1] << ',' << pl._v[2] << "]";
8366  else
8367  {
8368  if( pl.isInf() )
8369  f << '[' << pl._v[0] << ',' << pl._v[1] << ',' << pl._v[2] << "]";
8370  else
8371  f
8372  // << std::scientific << std::setprecision(25)
8373  << '[' << pl.getX() << ',' << pl.getY() << "]";
8374  }
8375 
8376  return f;
8377 }

◆ operator<<() [2/5]

template<typename T1 , typename T2 >
auto h2d::base::operator<< ( std::ostream &  ,
const h2d::base::PolylineBase< T1, T2 > &   
) -> std::ostream &

◆ operator<<() [3/5]

template<typename LP , typename FPT >
std::ostream& h2d::base::operator<< ( std::ostream &  f,
const h2d::base::LPBase< LP, FPT > &  pl 
)

Stream operator, free function, call member function pseudo operator impl_op_stream()

8363 {
8364  if constexpr( std::is_same_v<LP,typ::IsLine> )
8365  f << '[' << pl._v[0] << ',' << pl._v[1] << ',' << pl._v[2] << "]";
8366  else
8367  {
8368  if( pl.isInf() )
8369  f << '[' << pl._v[0] << ',' << pl._v[1] << ',' << pl._v[2] << "]";
8370  else
8371  f
8372  // << std::scientific << std::setprecision(25)
8373  << '[' << pl.getX() << ',' << pl.getY() << "]";
8374  }
8375 
8376  return f;
8377 }
bool isInf() const
Returns true if point is at infinity (third value less than thr::nullDenom() )
Definition: homog2d.hpp:4254
HOMOG2D_INUMTYPE getX() const
Definition: homog2d.hpp:4130
HOMOG2D_INUMTYPE getY() const
Definition: homog2d.hpp:4135

◆ operator<<() [4/5]

template<typename SV , typename T >
std::ostream& h2d::base::operator<< ( std::ostream &  f,
const h2d::base::SegVec< SV, T > &  seg 
)
8431 {
8432  f << seg._ptS1;
8433  if constexpr( std::is_same_v<SV,typ::IsOSeg> )
8434  f << "=>";
8435  else
8436  f << "-";
8437  f << seg._ptS2;
8438  return f;
8439 }

◆ operator<<() [5/5]

template<typename PLT , typename FPT >
std::ostream& h2d::base::operator<< ( std::ostream &  f,
const h2d::base::PolylineBase< PLT, FPT > &  pl 
)
8444 {
8445  f << (pl.isClosed() ? 'C' : 'O' ) << "Polyline: ";
8446  if( !pl.size() )
8447  f << "empty";
8448  else
8449  {
8450  for( const auto& pt: pl._plinevec )
8451  f << pt << "-";
8452  }
8453  return f;
8454 }
constexpr bool isClosed() const
Definition: homog2d.hpp:6214
size_t size() const
Returns the number of points.
Definition: homog2d.hpp:6212
Point2d pt
Definition: homog2d_test.cpp:4034