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)
11556 {
11557  if( input.size() < 4 ) // if 3 pts or less, then the hull is equal to input set
11558  return CPolyline_<FPT>( input );
11559 
11560 // step 1: find pivot (point with smallest Y coord)
11561  auto pivot_idx = priv::chull::getPivotPoint( input );
11562 
11563 // step 2: sort points by angle of lines between the current point and pivot point
11564  auto v2 = priv::chull::sortPoints( input, pivot_idx );
11565 
11566  std::stack<size_t> firstPoint;
11567  priv::chull::Mystack hull;
11568  hull.push( v2[0] );
11569  hull.push( v2[1] );
11570  hull.push( v2[2] );
11571 
11572  firstPoint.push( 0 );
11573  firstPoint.push( 1 );
11574 
11575 // step 3: iterate
11576  size_t idx1 = 1;
11577  size_t idx2 = 2;
11578  size_t idx3 = 3;
11579  do
11580  {
11581 // HOMOG2D_LOG( "** loop start, idx1=" << idx1 << ", idx2=" << idx2 << ", idx3=" << idx3 << ", hull " << hull.getVect() );
11582  auto p = input.at( v2[idx1] );
11583  auto q = input.at( v2[idx2] );
11584  auto r = input.at( v2[idx3] );
11585  auto orient = priv::chull::orientation( p, q, r );
11586 // HOMOG2D_LOG( "considering pts: " << v2[idx1] << "," << v2[idx2] << "," << v2[idx3] << ": or = " << orient );
11587  if( orient != 1 )
11588  {
11589  hull.push( v2[idx3] );
11590  idx1 = idx2;
11591  idx2 = idx3;
11592  idx3++;
11593  firstPoint.push( idx1 );
11594  }
11595  else
11596  {
11597  hull.pop();
11598  idx2=idx1; // idx3 stays the same
11599  firstPoint.pop();
11600  idx1 = firstPoint.top();
11601  }
11602  }
11603  while( idx3 < v2.size() );
11604 
11605 // final step: copy hull indexes to vector of points
11606  const auto v = hull.getVect();
11607  std::vector<Point2d_<FPT>> vout( v.size() );
11609  v.begin(),
11610  v.end(),
11611  vout.begin(),
11612  [&input] // lambda
11613  (size_t idx)
11614  {
11615  return input.at( idx );
11616  }
11617  );
11618 
11619  return CPolyline_<FPT>( vout );
11620 }
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:11462
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:11503
CommonType_< FPT > transform(const Homogr_< FPT > &h, const T &elem)
Apply homography to primitive.
Definition: homog2d.hpp:10382
size_t getPivotPoint(const std::vector< Point2d_< FPT >> &in)
Used int the convex hull algorithm.
Definition: homog2d.hpp:11452
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()

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

◆ 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()

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

◆ operator<<() [4/5]

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

◆ operator<<() [5/5]

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