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

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

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

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

◆ operator<<() [4/5]

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

◆ operator<<() [5/5]

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