homog2d library
Macros | Functions
demo_opencv.cpp File Reference

demo of interfacing with Opencv. Try it with $ make demo. More...

#include "homog2d.hpp"
#include "opencv2/highgui.hpp"
Include dependency graph for demo_opencv.cpp:

Macros

#define HOMOG2D_ENABLE_VRTP
 
#define HOMOG2D_USE_OPENCV
 

Functions

void action_1 (void *param)
 
void action_6 (void *param)
 
void action_BB (void *param)
 
void action_C (void *param)
 
void action_CH (void *param)
 
void action_CIR (void *param)
 
void action_ELL (void *param)
 action for Ellipse demo (run on keyboard hit) More...
 
void action_H (void *param)
 
void action_NFP (void *param)
 
void action_ORS (void *param)
 
void action_OSegAngle (void *param)
 
void action_PL (void *param)
 
void action_PO (void *param)
 Polygon Offset demo action. More...
 
void action_polRot (void *param)
 
void action_RCP (void *param)
 
void action_RI (void *param)
 
void action_SEG (void *param)
 
void action_SI (void *param)
 
double action_SI_drawDist (const Segment &seg, void *param)
 
void demo_1 (int demidx)
 
void demo_6 (int demidx)
 
void demo_B (int demidx)
 Build H from R,T,S (no mouse) More...
 
void demo_BB (int demidx)
 
void demo_C (int demidx)
 
void demo_CH (int demidx)
 
void demo_CIR (int demidx)
 
void demo_ELL (int demidx)
 Ellipse demo. More...
 
void demo_H (int demidx)
 Demo of computing a homography from two sets of 4 points. More...
 
void demo_NFP (int demidx)
 
void demo_orthSeg (int demidx)
 
void demo_OSegAngle (int demidx)
 
void demo_PL (int demidx)
 
void demo_PO (int demidx)
 Polygon Offset demo start. More...
 
void demo_polRot (int demidx)
 
void demo_RCP (int demidx)
 
void demo_RI (int demidx)
 
void demo_SEG (int demidx)
 
void demo_SI (int demidx)
 Segment intersection demo. More...
 
int main (int argc, const char **argv)
 Demo program, using Opencv. More...
 
void myMouseCB (int event, int x, int y, int, void *param)
 Mouse callback functions, checks if one of the points is selected. More...
 
template<typename IM , typename POL >
void process_PO (IM &im, const POL &pol, Param_PO &data)
 
std::vector< Point2dremoveDupes (const std::vector< Point2d > &vec)
 Helper function. Only removes duplicates if there are consecutive. More...
 
void toggle (bool &b, std::string msg)
 

Detailed Description

demo of interfacing with Opencv. Try it with $ make demo.

precision evaluation, using Opencv

precision evaluation

(requires OpenCv)

To run a specific demo, give its number as first argument, i.e.:

$ BUILD/demo_opencv 4.

Each demo is defined by three code blocks:

To enable the mouse callback, the function demo_something( int ) must first instanciate the Params_something class then assign the action_something() function to the mouse callback:

void demo_something( int demo_index)
{
Param_something data( demo_index, "what-is-this-about" );
action_something( &data ); // initial call of the "action" stuff
data.setMouseCB( action_something ) // assign to mouse callback
...
}

Computation of the line passed through H^{-T} and computation of the distance between the resulting line and the transformed point. Should be 0, always.

We do this for multiple random transformation, in random order, and with multiple random points

Macro Definition Documentation

◆ HOMOG2D_ENABLE_VRTP

#define HOMOG2D_ENABLE_VRTP

◆ HOMOG2D_USE_OPENCV

#define HOMOG2D_USE_OPENCV

Function Documentation

◆ action_1()

void action_1 ( void *  param)
397 {
398  auto& data = *reinterpret_cast<Data*>(param);
399  data.drawLines();
400 
401  Line2d l_mouse = data._pt_mouse * Point2d();
402  auto p_lines = l_mouse.getParallelLines( 30 );
403 
404  auto ppts = l_mouse.getPoints( Point2d(), 200 );
405  Line2d l_mouse_o = l_mouse.getOrthogLine( ppts.second );
406  l_mouse.draw( data.img );
407  l_mouse_o.draw( data.img );
408 
409  auto p_lines_o = l_mouse_o.getParallelLines( 10 );
410 
411 
412  img::DrawParams dp;
413  dp.setColor(100,250,100);
414  p_lines.first.draw( data.img, dp );
415  p_lines.second.draw( data.img, dp );
416 
417  p_lines_o.first.draw( data.img, dp );
418  p_lines_o.second.draw( data.img, dp );
419 }
Line2d_< FPT > getOrthogLine(GivenCoord gc, FPT2 other) const
Returns an orthogonal line to the one it is called on, at a point on the line defined by one of its c...
Definition: homog2d.hpp:8878
std::pair< Line2d_< FPT >, Line2d_< FPT > > getParallelLines(T dist) const
Returns the pair of parallel lines at a distance dist from line.
Definition: homog2d.hpp:8984
PointPair_< FPT > getPoints(GivenCoord gc, FPT2 coord, FPT3 dist) const
Returns a pair of points that are lying on line at distance dist from a point defined by one of its c...
Definition: homog2d.hpp:4085
void draw(img::Image< img::SvgImage > &im, img::DrawParams dp=img::DrawParams()) const
SVG draw function.
Definition: homog2d.hpp:4414
Draw parameters, independent of back-end library.
Definition: homog2d.hpp:514
Point2d_< HOMOG2D_INUMTYPE > Point2d
Default point type, uses double as numerical type.
Definition: homog2d.hpp:12379
DrawParams & setColor(uint8_t r, uint8_t g, uint8_t b)
Definition: homog2d.hpp:605
Base class, will be instanciated as Point2d_ or Line2d_.
Definition: homog2d.hpp:365
Here is the call graph for this function:
Here is the caller graph for this function:

◆ action_6()

void action_6 ( void *  param)
726 {
727  auto& data = *reinterpret_cast<Param_6*>(param);
728 
729  data.clearImage();
730  double K = M_PI / 180.;
731  auto tx = data._pt_mouse.getX();
732  auto ty = data._pt_mouse.getY();
733 
734  auto mouse_pos = std::make_pair(
735  Line2d( LineDir::H, ty ),
736  Line2d( LineDir::V, tx )
737  );
738  draw( data.img, mouse_pos, img::DrawParams().setColor( 200,200,200) );
739 
740 /* auto org = std::make_pair(
741  Line2d( LineDir::H, ty ),
742  Line2d( LineDir::V, tx )
743  );
744  draw( data.img, org );
745 */
746  Homogr H = Homogr().addTranslation(-tx,-ty).addRotation( data.angle * K ).addTranslation(tx,ty);
747 
748  draw( data.img, data.vpt[0] );
749  draw( data.img, data.vpt[1] );
750  Line2d l1( data.vpt[0], data.vpt[1] );
751  Line2d l2 = l1.getRotatedLine( data.vpt[0], data.angle * K );
752 
753  auto dpar = img::DrawParams();
754  l1.draw( data.img, dpar.setColor( 250,0,0) );
755  l2.draw( data.img, dpar.setColor( 0,250,0) );
756 
757  Segment s1( data.vpt[2], data.vpt[3] );
758  Segment s2 = H*s1;
759  s1.draw( data.img, dpar.setColor( 250,0,0) );
760  s2.draw( data.img, dpar.setColor( 0,0,250) );
761  s1.getPts().first.draw( data.img, dpar.selectPoint() );
762  s1.getPts().second.draw( data.img, dpar.selectPoint() );
763 }
Homogr_< HOMOG2D_INUMTYPE > Homogr
Default homography (3x3 matrix) type, uses double as numerical type.
Definition: homog2d.hpp:12382
void draw(Data &data)
Definition: precision_test_opencv.cpp:184
Line2d_< HOMOG2D_INUMTYPE > Line2d
Default line type, uses double as numerical type.
Definition: homog2d.hpp:12376
#define M_PI
Definition: homog2d.hpp:235
A 2D homography, defining a planar transformation.
Definition: homog2d.hpp:369
void draw(img::Image< img::SvgImage > &im, img::DrawParams dp=img::DrawParams()) const
SVG draw function.
Definition: homog2d.hpp:4414
void draw(img::Image< cv::Mat > &, img::DrawParams dp=img::DrawParams()) const
Definition: homog2d.hpp:11868
Draw parameters, independent of back-end library.
Definition: homog2d.hpp:514
Line2d_< FPT > getRotatedLine(const Point2d_< FPT2 > &pt, T theta) const
Returns a line rotated at point pt with angle theta.
Definition: homog2d.hpp:8915
A line segment, oriented (OSegment_) or not (Segment_). Holds the two points.
Definition: homog2d.hpp:366
DrawParams & setColor(uint8_t r, uint8_t g, uint8_t b)
Definition: homog2d.hpp:605
Base class, will be instanciated as Point2d_ or Line2d_.
Definition: homog2d.hpp:365
Here is the call graph for this function:
Here is the caller graph for this function:

◆ action_BB()

void action_BB ( void *  param)
1816 {
1817  auto& data = *reinterpret_cast<Param_BB*>(param);
1818  data.clearImage();
1819  auto style = img::DrawParams().setPointStyle( img::PtStyle::Dot ).showPoints();
1820  auto style0 = style.setColor(0,250,0);
1821  auto style1 = style.setColor(250,0,0);
1822  auto style2 = style.setColor(0,0,250);
1823 
1824  data.initElemsAll(); // first initialize objects
1825 
1826  fct::DrawFunct vde1( data.img, style1 ); // then draw the current ones
1827  fct::DrawFunct vde2( data.img, style2 );
1828  const auto& curr1 = data.getCurrent(0);
1829  const auto& curr2 = data.getCurrent(1);
1830  std::visit( vde1, curr1 );
1831  std::visit( vde2, curr2 );
1832 
1833  auto pp1 = std::visit( fct::PtPairFunct{}, curr1 ); // get their "pseudo" bounding box (as pair of points)
1834  auto pp2 = std::visit( fct::PtPairFunct{}, curr2 );
1835 
1836  try {
1837  getBB( pp1, pp2 ).draw( data.img, style0 );
1838  }
1839  catch( std::runtime_error& err )
1840  {
1841  std::cout << "Unable: " << err.what() << '\n';
1842  }
1843 
1844  data._pt_mouse.draw( data.img );
1845 
1846  int y0=30;
1847  int dy=30;
1848 
1849  auto l1 = length(curr1);
1850  auto l2 = length(curr2);
1851  auto a1 = area(curr1);
1852  auto a2 = area(curr2);
1853  data.img.drawText( "[w]->red: " + data._name[0], Point2d( 20,y0), style1 );
1854  data.img.drawText( " length=" + std::to_string(l1) + " area=" + std::to_string(a1), Point2d( 20,y0+dy), style1 );
1855  data.img.drawText( "[x]->blue: " + data._name[1], Point2d( 20,y0+2*dy), style2 );
1856  data.img.drawText( " length=" + std::to_string(l2) + " area=" + std::to_string(a2), Point2d( 20,y0+3*dy), style2 );
1857 
1858  data.showImage();
1859 }
1860 
HOMOG2D_INUMTYPE length(const T &elem)
Returns length of element or variant (free function)
Definition: homog2d.hpp:10223
A functor used to draw objects. To use with std::variant and std::visit()
Definition: homog2d.hpp:1068
Draw parameters, independent of back-end library.
Definition: homog2d.hpp:514
Point2d_< HOMOG2D_INUMTYPE > Point2d
Default point type, uses double as numerical type.
Definition: homog2d.hpp:12379
DrawParams & setPointStyle(PtStyle ps)
Definition: homog2d.hpp:585
A functor to get pair of points englobing the element.
Definition: homog2d.hpp:10138
DrawParams & showPoints(bool b=true)
Set or unset the drawing of points (useful only for Segment_ and Polyline_)
Definition: homog2d.hpp:621
HOMOG2D_INUMTYPE area(const T &elem)
Returns area of element or variant (free function)
Definition: homog2d.hpp:10238
FRect_< HOMOG2D_INUMTYPE > getBB(const T &t)
Return Bounding Box of primitive or container holding primitives (free function)
Definition: homog2d.hpp:10312
DrawParams & setColor(uint8_t r, uint8_t g, uint8_t b)
Definition: homog2d.hpp:605
Base class, will be instanciated as Point2d_ or Line2d_.
Definition: homog2d.hpp:365
Here is the call graph for this function:
Here is the caller graph for this function:

◆ action_C()

void action_C ( void *  param)
524 {
525  auto& data = *reinterpret_cast<Param_C*>(param);
526  data.clearImage();
527  data.drawLines();
528 
529  Circle c1( data.vpt[0], data.radius );
530  Circle c2( data.vpt[1], 100 );
531 
532  img::DrawParams dpc2;
533  dpc2.setColor(150,0,150);
534  if( c2.isInside( c1 ) )
535  dpc2.setColor(250,100,0);
536  c2.draw( data.img, dpc2 );
537 
538  img::DrawParams dp;
539  dp.setColor(150,0,150);
540  if( data.rect.isInside( c1 ) )
541  dp.setColor(250,100,0);
542  data.rect.draw( data.img, dp );
543 
544  img::DrawParams dpc1;
545  dpc1.setColor(0,250,0);
546  if( c1.isInside( data.rect ) )
547  dpc1.setColor(250,100,0);
548  if( c1.isInside( c2 ) )
549  dpc1.setColor(250,100,0);
550  c1.draw( data.img, dpc1 );
551 
552  data._pt_mouse.draw( data.img, img::DrawParams().setColor(250,50,20) );
553 
554 // circle - circle intersections
555  auto cci = c1.intersects( c2 );
556  if( cci() )
557  draw( data.img, cci.get(), img::DrawParams().setColor(0,150,0).setPointStyle(img::PtStyle::Diam) );
558 
559 
560 // circle - rectangle intersections
561  auto cr1 = c1.intersects( data.rect );
562  auto cr2 = c2.intersects( data.rect );
563  if( cr1() )
564  draw( data.img, cr1.get(), img::DrawParams().setColor(0,20,220).setPointStyle(img::PtStyle::Diam) );
565  if( cr2() )
566  draw( data.img, cr2.get(), img::DrawParams().setColor(0,20,220).setPointStyle(img::PtStyle::Diam) );
567 
568 // circle - lines intersections
569  for( size_t i=0; i<data.li.size(); i++ )
570  {
571  auto ri = data.li[i].intersects( c1 );
572  if( ri() )
573  {
574  auto inter = ri.get();
575  inter.first.draw( data.img, img::DrawParams().setColor(250, 0, 0) );
576  inter.second.draw( data.img, img::DrawParams().setColor(250, 0, 0) );
577  }
578  }
579 
580  auto seg = getSegment( c1, c2 );
581  seg.draw( data.img, img::DrawParams().setColor(250, 0, 0) );
582 
583  auto pseg = getTanSegs( c1, c2 );
584  pseg.first.draw( data.img, img::DrawParams().setColor(250, 250, 0) );
585  pseg.second.draw( data.img, img::DrawParams().setColor(0, 250, 250) );
586  data.showImage();
587 }
A circle.
Definition: homog2d.hpp:378
void draw(Data &data)
Definition: precision_test_opencv.cpp:184
Segment seg
Definition: homog2d_test.cpp:4033
void draw(img::Image< cv::Mat > &, img::DrawParams dp=img::DrawParams()) const
Definition: homog2d.hpp:11868
Draw parameters, independent of back-end library.
Definition: homog2d.hpp:514
std::pair< Segment_< FPT1 >, Segment_< FPT1 > > getTanSegs(const Circle_< FPT1 > &c1, const Circle_< FPT2 > &c2)
Free function, returns the pair of segments tangential to the two circles.
Definition: homog2d.hpp:10793
Segment_< typename T1::FType > getSegment(const T1 &c1, const T2 &c2)
Free function, returns segment between two circle centers (or ellipse)
Definition: homog2d.hpp:10688
DrawParams & setPointStyle(PtStyle ps)
Definition: homog2d.hpp:585
DrawParams & setColor(uint8_t r, uint8_t g, uint8_t b)
Definition: homog2d.hpp:605
Here is the call graph for this function:
Here is the caller graph for this function:

◆ action_CH()

void action_CH ( void *  param)
1284 {
1285  static size_t old_size = 0;
1286  auto& data = *reinterpret_cast<Param_CH*>(param);
1287 
1288  data.clearImage();
1289  draw( data.img, data.vpt, img::DrawParams().showIndex() );
1290 
1291  data._cpoly = convexHull( data.vpt );
1292  Circle cir;
1293  cir.set( data.vpt );
1294 
1295  auto vlines = getLines( data._cpoly.getSegs() );
1296  if( old_size != vlines.size() )
1297  {
1298  data.vcol = img::genRandomColors( vlines.size() );
1299  old_size = vlines.size();
1300  }
1301 
1302  auto func = [&](int i) // lambda, needed to fetch color from index
1303  {
1304  return img::DrawParams().setColor(data.vcol[i]);
1305  };
1306  std::function<img::DrawParams(int)> f(func);
1307 
1308  if( data._mode )
1309  draw( data.img, vlines, f );
1310  if( !data._mode )
1311  data._cpoly.draw( data.img, img::DrawParams().setColor(250,0,0) );
1312  cir.draw( data.img, img::DrawParams().setColor(0,0,250) );
1313 
1314  auto dp = img::DrawParams().setColor(0,0,0).setPointStyle( img::PtStyle::Dot ).setPointSize(5).setThickness(2);
1315  data._cpoly.getLmPoint().draw( data.img, dp );
1316  data._cpoly.getRmPoint().draw( data.img, dp );
1317  data._cpoly.getTmPoint().draw( data.img, dp );
1318  data._cpoly.getBmPoint().draw( data.img, dp );
1319  data.showImage();
1320 }
A circle.
Definition: homog2d.hpp:378
void draw(Data &data)
Definition: precision_test_opencv.cpp:184
DrawParams & setThickness(uint8_t t)
Definition: homog2d.hpp:600
Draw parameters, independent of back-end library.
Definition: homog2d.hpp:514
void draw(img::Image< cv::Mat > &, img::DrawParams=img::DrawParams()) const
Draw Circle (Opencv implementation)
Definition: homog2d.hpp:11907
auto getLines(const T &vsegs)
Free function, returns a set of lines from a set of segments.
Definition: homog2d.hpp:10765
std::vector< img::Color > genRandomColors(size_t nb, int minval=20, int maxval=250)
Helper function, will generate a vector of nb random RGB colors.
Definition: homog2d.hpp:453
void set(const Point2d_< PT > &center)
Set circle center point, radius unchanged.
Definition: homog2d.hpp:3297
DrawParams & setPointStyle(PtStyle ps)
Definition: homog2d.hpp:585
CPolyline_< FPT > convexHull(const base::PolylineBase< CT, FPT > &input)
Compute Convex Hull of a Polyline (free function)
Definition: homog2d.hpp:11536
DrawParams & showIndex(bool b=true)
Set or unset the drawing of points (useful only for Segment_ and Polyline_)
Definition: homog2d.hpp:634
DrawParams & setColor(uint8_t r, uint8_t g, uint8_t b)
Definition: homog2d.hpp:605
DrawParams & setPointSize(uint8_t ps)
Definition: homog2d.hpp:592
Circle cir
Definition: homog2d_test.cpp:4036
Here is the call graph for this function:
Here is the caller graph for this function:

◆ action_CIR()

void action_CIR ( void *  param)
1236 {
1237  auto& data = *reinterpret_cast<Param_CIR*>(param);
1238  data.clearImage();
1239  data.setAndDraw();
1240  data.showImage();
1241 }
Here is the caller graph for this function:

◆ action_ELL()

void action_ELL ( void *  param)

action for Ellipse demo (run on keyboard hit)

1114 {
1115  auto& data = *reinterpret_cast<Param_ELL*>(param);
1116  data.H.init();
1117  data.H.addTranslation(-data.x0, -data.y0).addRotation( data.angle * M_PI/180.).addTranslation(data.x0+data.tx, data.y0+data.ty);
1118  data.draw();
1119 }
#define M_PI
Definition: homog2d.hpp:235
Here is the caller graph for this function:

◆ action_H()

void action_H ( void *  param)
824 {
825  auto& data = *reinterpret_cast<Param_H*>(param);
826 
827  data.clearImage();
828 
829  std::vector<Point2d> v1(4);
830  std::vector<Point2d> v2(4);
831  std::copy( data.vpt.begin(), data.vpt.begin()+4, v1.begin() );
832  std::copy( data.vpt.begin()+4, data.vpt.end(), v2.begin() );
833  for( int i=0; i<4; i++ )
834  {
835  Segment s1( v1[i], v1[i==3?0:i+1] );
836  Segment s2( v2[i], v2[i==3?0:i+1] );
837  s1.draw( data.img, img::DrawParams().setColor( 0,0,250) );
838  s2.draw( data.img, img::DrawParams().setColor( 250,0,0) );
839 
840  s1.draw( data.img2, img::DrawParams().setColor( 0,0,250) );
841 
842  Segment( v1[i], v2[i] ).draw( data.img );
843 
844  v1[i].draw( data.img );
845  v2[i].draw( data.img );
846  }
847 
848  std::vector<Point2d> vseg;
849  auto center_x = 160;
850  auto center_y = 220;
851  auto size_v = 40;
852  auto size_h = 60;
853  vseg.emplace_back( Point2d(center_x+size_h, center_y) );
854  vseg.emplace_back( Point2d(center_x-size_h, center_y) );
855  vseg.emplace_back( Point2d(center_x, center_y+size_v) );
856  vseg.emplace_back( Point2d(center_x, center_y-size_v) );
857 
858  Segment sa1( vseg[0], vseg[1] );
859  Segment sb1( vseg[2], vseg[3] );
860 
861  sa1.draw( data.img, img::DrawParams().setColor( 0,100,100) );
862  sb1.draw( data.img, img::DrawParams().setColor( 0,100,100) );
863 
864  cv::putText( data.img.getReal(), "source points", cv::Point2i( v1[0].getX(), v1[0].getY() ), 0, 0.8, cv::Scalar( 250,0,0 ), 2 );
865  cv::putText( data.img.getReal(), "dest points", cv::Point2i( v2[0].getX(), v2[0].getY() ), 0, 0.8, cv::Scalar( 0,0,250 ), 2 );
866 
867  Homogr H;
868  H.buildFrom4Points( v1, v2, data.hmethod );
869  std::cout << "Computed Homography:\n" << H << '\n';
870 
871  std::vector<Point2d> vpt3;
872  for( int i=0; i<4; i++ )
873  vpt3.push_back( H * data.vpt[i] );
874 
875  for( int i=0; i<4; i++ )
876  {
877  Segment s1( vpt3[i], vpt3[i==3?0:i+1] );
878  s1.draw( data.img2, img::DrawParams().setColor( 0,250,0) );
879  }
880 
881  auto vsegH = H * vseg;
882  Segment sa2( vsegH[0], vsegH[1] );
883  Segment sb2( vsegH[2], vsegH[3] );
884 
885  sa2.draw( data.img2, img::DrawParams().setColor( 0,100,100) );
886  sb2.draw( data.img2, img::DrawParams().setColor( 0,100,100) );
887 
888 
889  FRect rect( Point2d(200,160), Point2d(330,250));
890  rect.draw( data.img );
891  auto rect2 = H * rect;
892  rect2.draw( data.img2 );
893 
894  auto e_x = 320.;
895  auto e_y = 360.;
896  auto e_h = 70.;
897 
898  Circle c_ell( e_x, e_y, e_h );
899  c_ell.draw( data.img );
900  auto ell = H * c_ell;
901  ell.draw( data.img2 );
902  auto ecenter = ell.getCenter();
903  ecenter.draw( data.img2 );
904 
905  auto ell_bb = ell.getBB();
906  ell_bb.draw( data.img2 );
907 
908  data.showImage();
909 }
A circle.
Definition: homog2d.hpp:378
void draw(img::Image< cv::Mat > &, img::DrawParams dp=img::DrawParams()) const
Draw FRect (Opencv implementation)
Definition: homog2d.hpp:11845
auto getBB() const
Returns axis-aligned bounding box of ellipse.
Definition: homog2d.hpp:8652
Segment_< HOMOG2D_INUMTYPE > Segment
Default segment type.
Definition: homog2d.hpp:12388
Point2d_< FPT > getCenter() const
Returns center of ellipse.
Definition: homog2d.hpp:8581
A 2D homography, defining a planar transformation.
Definition: homog2d.hpp:369
FRect rect
Definition: homog2d_test.cpp:4038
FPT getY(const Point2d_< FPT > &pt)
Definition: homog2d.hpp:9823
Draw parameters, independent of back-end library.
Definition: homog2d.hpp:514
Point2d_< HOMOG2D_INUMTYPE > Point2d
Default point type, uses double as numerical type.
Definition: homog2d.hpp:12379
Ellipse ell
Definition: homog2d_test.cpp:4037
void draw(img::Image< cv::Mat > &, img::DrawParams dp=img::DrawParams()) const
Draw Ellipse (Opencv implementation)
Definition: homog2d.hpp:11929
A Flat Rectangle, modeled by its two opposite points.
Definition: homog2d.hpp:379
A line segment, oriented (OSegment_) or not (Segment_). Holds the two points.
Definition: homog2d.hpp:366
FPT getX(const Point2d_< FPT > &pt)
Definition: homog2d.hpp:9820
DrawParams & setColor(uint8_t r, uint8_t g, uint8_t b)
Definition: homog2d.hpp:605
Here is the call graph for this function:
Here is the caller graph for this function:

◆ action_NFP()

void action_NFP ( void *  param)
1635 {
1636  auto& data = *reinterpret_cast<Param_NFP*>(param);
1637  data.clearImage();
1638  draw( data.img, data.vpt );
1639  data._pt_mouse.draw( data.img, img::DrawParams().setColor( 250,0,0) );
1640  switch( data._mode )
1641  {
1642  case 0:
1643  {
1644  auto idx = findNearestPoint( data._pt_mouse, data.vpt );
1645  Segment(data.vpt[idx], data._pt_mouse).draw( data.img, img::DrawParams().setColor( 250,0,0) );
1646  }
1647  break;
1648  case 1:
1649  {
1650  auto idx = findFarthestPoint( data._pt_mouse, data.vpt );
1651  Segment(data.vpt[idx], data._pt_mouse).draw( data.img, img::DrawParams().setColor( 0,250,0) );
1652  }
1653  break;
1654  case 2:
1655  {
1656  auto pidx = findNearestFarthestPoint( data._pt_mouse, data.vpt );
1657  Segment(data.vpt[pidx.first], data._pt_mouse).draw( data.img, img::DrawParams().setColor( 250,0,0) );
1658  Segment(data.vpt[pidx.second], data._pt_mouse).draw( data.img, img::DrawParams().setColor( 0,250,0) );
1659  }
1660  break;
1661  default: assert(0);
1662  }
1663 
1664  data.showImage();
1665 }
auto findNearestFarthestPoint(const Point2d_< FPT > &pt, const T &cont)
Returns indexes of points in container cont that are nearest/farthest.
Definition: homog2d.hpp:11167
void draw(Data &data)
Definition: precision_test_opencv.cpp:184
Segment_< HOMOG2D_INUMTYPE > Segment
Default segment type.
Definition: homog2d.hpp:12388
size_t findFarthestPoint(const Point2d_< FPT > &pt, const T &cont)
Returns index of point in container cont that is the farthest to pt.
Definition: homog2d.hpp:11156
Draw parameters, independent of back-end library.
Definition: homog2d.hpp:514
size_t findNearestPoint(const Point2d_< FPT > &pt, const T &cont)
Returns index of point in container cont that is the nearest to pt.
Definition: homog2d.hpp:11148
DrawParams & setColor(uint8_t r, uint8_t g, uint8_t b)
Definition: homog2d.hpp:605
Here is the call graph for this function:
Here is the caller graph for this function:

◆ action_ORS()

void action_ORS ( void *  param)
1698 {
1699  auto& data = *reinterpret_cast<Param_ORS*>(param);
1700  data.clearImage();
1701 
1702  auto fl = [&](int i) // lambda
1703  {
1704  return img::DrawParams().setPointStyle(img::PtStyle::Dot).setColor( data._vcol[i] );
1705  };
1706  std::function<img::DrawParams(int)> style(fl);
1707 
1708  Segment seg( data.vpt[0], data.vpt[1] );
1709  seg.draw( data.img, img::DrawParams().setColor( 250,0,0) );
1710  if( data._ptsOrSegs )
1711  draw( data.img, seg.getOrthogSegs(), style );
1712  else
1713  {
1714  auto opts = seg.getOrthogPts();
1715  draw( data.img, opts, style );
1716  if( data._drawPolyg )
1717  CPolyline( opts ).draw( data.img, img::DrawParams().setColor( 125,125,0) );
1718  }
1719  data._pt_mouse.draw( data.img, img::DrawParams().setColor( 250,0,0) );
1720  data.showImage();
1721 }
void draw(Data &data)
Definition: precision_test_opencv.cpp:184
Segment seg
Definition: homog2d_test.cpp:4033
void draw(img::Image< cv::Mat > &, img::DrawParams dp=img::DrawParams()) const
Definition: homog2d.hpp:11868
Draw parameters, independent of back-end library.
Definition: homog2d.hpp:514
std::array< Segment_< FPT >, 4 > getOrthogSegs() const
Returns the 4 segments/vectors orthogonal to the segment.
Definition: homog2d.hpp:5239
CPolyline_< HOMOG2D_INUMTYPE > CPolyline
Default polyline type.
Definition: homog2d.hpp:12398
DrawParams & setPointStyle(PtStyle ps)
Definition: homog2d.hpp:585
std::array< Point2d_< FPT >, 4 > getOrthogPts() const
Returns the 4 points orthogonal to the segment/vector.
Definition: homog2d.hpp:5232
A line segment, oriented (OSegment_) or not (Segment_). Holds the two points.
Definition: homog2d.hpp:366
DrawParams & setColor(uint8_t r, uint8_t g, uint8_t b)
Definition: homog2d.hpp:605
Here is the call graph for this function:
Here is the caller graph for this function:

◆ action_OSegAngle()

void action_OSegAngle ( void *  param)
2089 {
2090  auto& data = *reinterpret_cast<Param_OSegAngle*>(param);
2091  data.clearImage();
2092  drawText( data.img, "Warning: flipped image on x axis: Left/Right reversed!", Point2d( 170, 20 ) );
2093  OSegment s1( data.vpt[0], data.vpt[1] );
2094  OSegment s2( data.vpt[1], data.vpt[2] );
2095 
2096  if( data._reverseS2 )
2097  s2 = -s2;
2098  if( data._reverseS1 )
2099  s1 = -s1;
2100  auto col1 = img::DrawParams().setColor(200,0,0);
2101  auto col2 = img::DrawParams().setColor(0,0,200);
2102 
2103  data.img.draw( s1, col1 );
2104  data.img.draw( s2, col2 );
2105  draw( data.img, data.vpt, img::DrawParams().setColor(0,200,0).setPointStyle(img::PtStyle::Dot) );
2106 
2107  if( data._showParallel )
2108  {
2109  auto psegs = s1.getParallelSegs( 25 );
2110  draw( data.img, psegs.first, img::DrawParams().setColor(250,100,0) );
2111  draw( data.img, psegs.second, img::DrawParams().setColor(250,0,100) );
2112  drawText( data.img, "L", psegs.first.getCenter() );
2113  drawText( data.img, "R", psegs.second.getCenter() );
2114  }
2115 
2116  auto angle = getAngle( s1, s2 );
2117  drawText( data.img, std::to_string(angle*180./M_PI), data.vpt[1] );
2118 
2119  drawText( data.img, "S1", s1.getCenter() );
2120  drawText( data.img, "S2", s2.getCenter() );
2121 
2122  draw( data.img, data._pt_mouse, img::DrawParams().setColor(150,150,0).setPointSize(7) );
2123  drawText(
2124  data.img,
2125  std::string("S1:") + getString( s1.getPointSide(data._pt_mouse) )
2126  + " S2:" + getString( s2.getPointSide(data._pt_mouse) ),
2127  data._pt_mouse
2128  );
2129 
2130  data.showImage();
2131 }
2132 
void drawText(img::Image< U > &im, std::string str, Point2d_< FPT > pt, img::DrawParams dp=img::DrawParams())
Free function, draws text str at position pt.
Definition: homog2d.hpp:11260
void draw(Data &data)
Definition: precision_test_opencv.cpp:184
HOMOG2D_INUMTYPE getAngle(const T1 &, const T2 &)
Free function, returns angle between two segments/lines.
Definition: homog2d.hpp:9204
#define M_PI
Definition: homog2d.hpp:235
Draw parameters, independent of back-end library.
Definition: homog2d.hpp:514
HOMOG2D_INUMTYPE angle(const Ellipse_< FPT > &ell)
Return angle of ellipse (free function)
Definition: homog2d.hpp:10993
DrawParams & setPointStyle(PtStyle ps)
Definition: homog2d.hpp:585
A line segment, oriented (OSegment_) or not (Segment_). Holds the two points.
Definition: homog2d.hpp:366
DrawParams & setColor(uint8_t r, uint8_t g, uint8_t b)
Definition: homog2d.hpp:605
DrawParams & setPointSize(uint8_t ps)
Definition: homog2d.hpp:592
const char * getString(PtStyle t)
Definition: homog2d.hpp:496
Base class, will be instanciated as Point2d_ or Line2d_.
Definition: homog2d.hpp:365
Here is the call graph for this function:
Here is the caller graph for this function:

◆ action_PL()

void action_PL ( void *  param)
958 {
959  auto& data = *reinterpret_cast<Param_PL*>(param);
960 
961  data.clearImage();
962  data.polyline_o.set( data.vpt );
963  data.polyline_c.set( data.vpt );
964 
965  auto color = img::DrawParams().setColor( 0,10,200);
966  if( data.polyline_c.isSimple() )
967  color = img::DrawParams().setColor( 250,10,20);
968 
969  auto len = data.showClosedPoly ? data.polyline_c.length() : data.polyline_o.length();
970  if( data.showClosedPoly )
971  data.polyline_c.draw( data.img, color );
972  else
973  data.polyline_o.draw( data.img, color );
974 
975  auto col_green = img::DrawParams().setColor(10,250,10);
976  Line2d li( Point2d( 10,60), Point2d( 400,270) );
977  li.draw( data.img, col_green );
978 
979  data.putTextLine( std::string("Nb pts=") + std::to_string( data.polyline_c.size() ), 0 );
980  data.putTextLine( std::string("length=") + std::to_string(len) );
981 
982  auto intersPts_o = li.intersects(data.polyline_o).get();
983  auto intersPts_c = li.intersects(data.polyline_c).get();;
984 
985  auto intersPts = ( data.showClosedPoly ? intersPts_c : intersPts_o );
986  for( const auto& pt: intersPts )
987  pt.draw( data.img );
988 
989  Circle cir( 350,180,85);
990  cir.draw( data.img, col_green );
991  auto i_cir_o = cir.intersects( data.polyline_o );
992  auto i_cir_c = cir.intersects( data.polyline_c );
993 
994  FRect rect( 90,160,205,245);
995  rect.draw( data.img, col_green );
996  auto i_rect_o = rect.intersects( data.polyline_o );
997  auto i_rect_c = rect.intersects( data.polyline_c );
998 
999  std::string str_ispoly{"Polygon: N"};
1000  if( data.showClosedPoly )
1001  {
1002  draw( data.img, i_cir_c.get() );
1003  draw( data.img, i_rect_c.get() );
1004  if( data.polyline_c.isSimple() )
1005  str_ispoly = "Polygon: Y";
1006  }
1007  else
1008  {
1009  draw( data.img, i_cir_o.get() );
1010  draw( data.img, i_rect_o.get() );
1011  }
1012  data.putTextLine( str_ispoly );
1013  auto bb = data.polyline_c.getBB();
1014  bb.draw( data.img );
1015 
1016  if( data.showClosedPoly && data.polyline_c.isSimple() )
1017  {
1018  auto centroid = data.polyline_c.centroid();
1019  centroid.draw( data.img, img::DrawParams().setColor(40,20,250) );
1020  cv::putText(
1021  data.img.getReal(),
1022  "centroid",
1023  centroid.getCvPti(),
1024  0, 0.6,
1025  cv::Scalar( 250,0,0 )
1026  );
1027 
1028  data.putTextLine( std::string("area=") + std::to_string(data.polyline_c.area()) );
1029 
1030  auto isC = "Convex: Y";
1031  if( !data.polyline_c.isConvex() )
1032  isC = "Convex: N";
1033  data.putTextLine( isC );
1034 
1035  auto isInside = data._pt_mouse.isInside(data.polyline_c);
1036  data.putTextLine( std::string("IsInside=") + std::string( isInside?"Y":"N" ) );
1037  if( isInside )
1038  drawText( data.img, "Inside", data._pt_mouse );
1039  else
1040  drawText( data.img, "Outside", data._pt_mouse );
1041  }
1042  data._pt_mouse.draw( data.img, img::DrawParams().setPointStyle( img::PtStyle::Dot ).setColor(0,220,0) );
1043  data.showImage();
1044  data._cpoly = data.polyline_c;
1045 }
A circle.
Definition: homog2d.hpp:378
void drawText(img::Image< U > &im, std::string str, Point2d_< FPT > pt, img::DrawParams dp=img::DrawParams())
Free function, draws text str at position pt.
Definition: homog2d.hpp:11260
void draw(img::Image< cv::Mat > &, img::DrawParams dp=img::DrawParams()) const
Draw FRect (Opencv implementation)
Definition: homog2d.hpp:11845
void draw(Data &data)
Definition: precision_test_opencv.cpp:184
FRect rect
Definition: homog2d_test.cpp:4038
void draw(img::Image< img::SvgImage > &im, img::DrawParams dp=img::DrawParams()) const
SVG draw function.
Definition: homog2d.hpp:4414
Draw parameters, independent of back-end library.
Definition: homog2d.hpp:514
void draw(img::Image< cv::Mat > &, img::DrawParams=img::DrawParams()) const
Draw Circle (Opencv implementation)
Definition: homog2d.hpp:11907
Line2d li
Definition: homog2d_test.cpp:4035
detail::IntersectM< FPT > intersects(const Line2d_< FPT2 > &line) const
FRect/Line intersection.
Definition: homog2d.hpp:3012
detail::Intersect< detail::Inters_1, FPT > intersects(const Line2d_< FPT2 > &other) const
Line/Line intersection.
Definition: homog2d.hpp:4285
base::LPBase< typ::IsPoint, FPT > centroid(const base::PolylineBase< PLT, FPT > &pl)
Returns centroid of Polyline (free function)
Definition: homog2d.hpp:10907
Point2d_< HOMOG2D_INUMTYPE > Point2d
Default point type, uses double as numerical type.
Definition: homog2d.hpp:12379
DrawParams & setPointStyle(PtStyle ps)
Definition: homog2d.hpp:585
A Flat Rectangle, modeled by its two opposite points.
Definition: homog2d.hpp:379
DrawParams & setColor(uint8_t r, uint8_t g, uint8_t b)
Definition: homog2d.hpp:605
detail::Intersect< detail::Inters_2, FPT > intersects(const Line2d_< FPT2 > &li) const
Circle/Line intersection.
Definition: homog2d.hpp:3434
Point2d pt
Definition: homog2d_test.cpp:4034
Circle cir
Definition: homog2d_test.cpp:4036
Base class, will be instanciated as Point2d_ or Line2d_.
Definition: homog2d.hpp:365
Here is the call graph for this function:
Here is the caller graph for this function:

◆ action_PO()

void action_PO ( void *  param)

Polygon Offset demo action.

2032 {
2033  auto& data = *reinterpret_cast<Param_PO*>(param);
2034  data.clearImage();
2035 
2036  auto withoutDupes = removeDupes( data.vpt );
2037  data._cpoly = CPolyline( withoutDupes );
2038  data._cpol = CPolyline( withoutDupes );
2039  data._opol = OPolyline( withoutDupes );
2040 
2041  if( data._closedPol )
2042  process_PO( data.img, data._cpol, data );
2043  else
2044  process_PO( data.img, data._opol, data );
2045 
2046 /* data.img.draw( debug.pt1, img::DrawParams().setColor(0,250,0).setPointSize(7) );
2047  data.img.draw( debug.ptnew, img::DrawParams().setColor(0,250,0).setPointSize(7) );
2048  data.img.draw( debug.plines, img::DrawParams().setColor(0,250,0) );
2049  data.img.draw( debug.seg, img::DrawParams().setColor(0,250,0) );
2050 */
2051  data.showImage();
2052 }
2053 
OPolyline_< HOMOG2D_INUMTYPE > OPolyline
Definition: homog2d.hpp:12399
CPolyline_< HOMOG2D_INUMTYPE > CPolyline
Default polyline type.
Definition: homog2d.hpp:12398
std::vector< Point2d > removeDupes(const std::vector< Point2d > &vec)
Helper function. Only removes duplicates if there are consecutive.
Definition: demo_opencv.cpp:1991
void process_PO(IM &im, const POL &pol, Param_PO &data)
Definition: demo_opencv.cpp:2001
Here is the call graph for this function:
Here is the caller graph for this function:

◆ action_polRot()

void action_polRot ( void *  param)
1557 {
1558  auto& data = *reinterpret_cast<Param_polRot*>(param);
1559  data.clearImage();
1560 
1561  if( data._doIt )
1562  {
1563  if( data._item )
1564  data._cpoly.rotate( data._rotateType, data._cpoly.getPoint( data._refPt_p ) );
1565  else
1566  data._rect.rotate( data._rotateType, data._pt_mouse );
1567  data._doIt = false;
1568  }
1569 
1570  if( data._item )
1571  {
1572  data._cpoly.draw( data.img, img::DrawParams().setColor(250,0,0).showPoints() );
1573  data._cpoly.getPoint( data._refPt_p ).draw( data.img, img::DrawParams().setColor(0,0,250).setPointStyle(img::PtStyle::Dot) );
1574  }
1575  else
1576  {
1577  data._rect.draw( data.img, img::DrawParams().setColor(0,0,250).showPoints() );
1578  draw( data.img, data._pt_mouse, img::DrawParams().setColor(250,0,0).setPointStyle(img::PtStyle::Dot) );
1579  }
1580  data.showImage();
1581 }
void draw(Data &data)
Definition: precision_test_opencv.cpp:184
Draw parameters, independent of back-end library.
Definition: homog2d.hpp:514
DrawParams & setPointStyle(PtStyle ps)
Definition: homog2d.hpp:585
DrawParams & showPoints(bool b=true)
Set or unset the drawing of points (useful only for Segment_ and Polyline_)
Definition: homog2d.hpp:621
DrawParams & setColor(uint8_t r, uint8_t g, uint8_t b)
Definition: homog2d.hpp:605
Here is the call graph for this function:
Here is the caller graph for this function:

◆ action_RCP()

void action_RCP ( void *  param)
1902 {
1903  auto& data = *reinterpret_cast<Param_RCP*>(param);
1904  data.clearImage();
1905 
1906  Point2d ptCenter( data._trans_x, data._trans_y );
1907  Line2d lih( Point2d(data._imWidth,data._trans_y), Point2d(0,data._trans_y) );
1908  Line2d liv( Point2d(data._trans_x,data._imHeight), Point2d(data._trans_x,0) );
1909  lih.draw( data.img, img::DrawParams().setColor(220,220,220) );
1910  liv.draw( data.img, img::DrawParams().setColor(220,220,220) );
1911 
1912  Point2d(data._trans_x,data._trans_y).draw( data.img, img::DrawParams().setColor(100,0,100) );
1913  auto values = data._cpoly.set( data._radius, data._nbPts );
1914  std::cout << " -Building Regular Convex Polygon with " << data._nbPts << " points\n";
1915 
1916  data._cpoly.moveTo( Point2d(data._trans_x+data._radius,data._trans_y) );
1917  data._cpoly.draw( data.img );
1918  {
1919  Segment s1( ptCenter, data._cpoly.getPts().front() );
1920  s1.draw( data.img ) ;
1921  drawText( data.img, std::to_string(int(data._radius)), s1.getCenter() );
1922  }
1923  {
1924  auto s1 = data._cpoly.getSegs().at(0);
1925  auto spara1 = s1.getParallelSegs(20).second;
1926  std::ostringstream oss1;
1927  oss1 << std::fixed << std::setprecision(1) << values.first;
1928  drawText( data.img, oss1.str(), spara1.getCenter() );
1929  }
1930  {
1931  Segment s1( ptCenter, data._cpoly.getPts().back() );
1932  Circle c1( ptCenter, values.second );
1933  auto it1 = c1.intersects(s1);
1934 
1935  Segment ss1( ptCenter, it1.get()[0] );
1936  ss1.draw( data.img ) ;
1937 
1938  std::ostringstream oss1;
1939  oss1 << std::fixed << std::setprecision(1) << values.second;
1940  drawText( data.img, oss1.str(), ss1.getCenter() );
1941  }
1942  data.putTextLine( "NbPts=" + std::to_string(data._nbPts) );
1943  data.putTextLine( "segment dist=" + std::to_string(values.first) );
1944  data.putTextLine( "red circle radius=" + std::to_string(values.second) );
1945 
1946  Circle c1( data._trans_x,data._trans_y,data._radius);
1947  Circle c2( data._trans_x,data._trans_y,values.second);
1948  c1.draw( data.img, img::DrawParams().setColor(0,0,250) );
1949  c2.draw( data.img, img::DrawParams().setColor(250,0,0) );
1950  data.showImage();
1951 }
1952 
A circle.
Definition: homog2d.hpp:378
void drawText(img::Image< U > &im, std::string str, Point2d_< FPT > pt, img::DrawParams dp=img::DrawParams())
Free function, draws text str at position pt.
Definition: homog2d.hpp:11260
void draw(img::Image< cv::Mat > &, img::DrawParams dp=img::DrawParams()) const
Definition: homog2d.hpp:11868
Draw parameters, independent of back-end library.
Definition: homog2d.hpp:514
Point2d_< HOMOG2D_INUMTYPE > Point2d
Default point type, uses double as numerical type.
Definition: homog2d.hpp:12379
A line segment, oriented (OSegment_) or not (Segment_). Holds the two points.
Definition: homog2d.hpp:366
DrawParams & setColor(uint8_t r, uint8_t g, uint8_t b)
Definition: homog2d.hpp:605
Base class, will be instanciated as Point2d_ or Line2d_.
Definition: homog2d.hpp:365
Here is the call graph for this function:
Here is the caller graph for this function:

◆ action_RI()

void action_RI ( void *  param)
1348 {
1349  auto& data = *reinterpret_cast<Param_RI*>(param);
1350 
1351  data.clearImage();
1352  draw( data.img, data.vpt );
1353  try
1354  {
1355  FRect r1( data.vpt[0], data.vpt[1] );
1356  FRect r2( data.vpt[2], data.vpt[3] );
1357  r1.draw( data.img, img::DrawParams().setColor(250,0,0) );
1358  r2.draw( data.img, img::DrawParams().setColor(0,250,0) );
1359  auto c1a = r1.getBoundingCircle();
1360  auto c1b = r1.getInscribedCircle();
1361  c1a.draw( data.img );
1362  c1b.draw( data.img );
1363  if( data.doUnion )
1364  {
1365  auto res = r1 & r2;
1366  if( res() )
1367  res.get().draw( data.img, img::DrawParams().setColor(0,0,250) );
1368  }
1369  else
1370  {
1371  auto res = r1 | r2;
1372  res.draw( data.img, img::DrawParams().setColor(0,0,250) );
1373  }
1374  }
1375  catch( std::exception& err )
1376  {
1377  std::cout << "Unable, points do not define a rectangle\n";
1378  }
1379  data.showImage();
1380 }
void draw(Data &data)
Definition: precision_test_opencv.cpp:184
Draw parameters, independent of back-end library.
Definition: homog2d.hpp:514
A Flat Rectangle, modeled by its two opposite points.
Definition: homog2d.hpp:379
DrawParams & setColor(uint8_t r, uint8_t g, uint8_t b)
Definition: homog2d.hpp:605
Here is the call graph for this function:
Here is the caller graph for this function:

◆ action_SEG()

void action_SEG ( void *  param)
1436 {
1437  auto& data = *reinterpret_cast<Param_SEG*>(param);
1438 
1439  data.clearImage();
1440  if( data.regen )
1441  data.generateSegments();
1442 
1443  auto func = [&](int i) // lambda, needed to fetch color from index
1444  {
1445  return img::DrawParams().showIndex(data.showIndexes).setColor(data.vcol[i]);
1446  };
1447  std::function<img::DrawParams(int)> f(func);
1448  draw( data.img, data.vseg, f );
1449 
1450  if( data.showIntersection )
1451  {
1452  size_t c_intersect = 0;
1453  for( size_t i=0; i<data.vseg.size()-1; i++ )
1454  {
1455  auto s1 = data.vseg[i];
1456  for( size_t j=i+1; j<data.vseg.size(); j++ )
1457  {
1458  auto s2 = data.vseg[j];
1459  auto pi = s1.intersects( s2 );
1460  if( pi() )
1461  {
1462  draw( data.img, pi.get(), img::DrawParams().setColor( 250,0,0) );
1463  c_intersect++;
1464  }
1465  }
1466  }
1467  std::cout << "- # intersection points=" << c_intersect << '\n';
1468  }
1469  if( data.showMiddlePoint )
1470  {
1471  for( const auto& seg: data.vseg )
1472  seg.getCenter().draw( data.img, img::DrawParams().setColor( 0,0,250) );
1473  }
1474  if( data.showBisector )
1475  {
1476  std::vector<Line2d> v_bisect( data.vseg.size() );
1477  std::transform( // To draw bisector lines with the same
1478  data.vseg.begin(), // color as the segments,
1479  data.vseg.end(), // we need to store them in a vector.
1480  v_bisect.begin(),
1481  [](const Segment& s){ return s.getBisector(); }
1482  );
1483  draw( data.img, v_bisect, f );
1484  }
1485  data.showImage();
1486 }
auto getCenter() const
Returns point at middle distance between p1 and p2.
Definition: homog2d.hpp:5288
void draw(Data &data)
Definition: precision_test_opencv.cpp:184
Segment seg
Definition: homog2d_test.cpp:4033
Draw parameters, independent of back-end library.
Definition: homog2d.hpp:514
CommonType_< FPT > transform(const Homogr_< FPT > &h, const T &elem)
Apply homography to primitive.
Definition: homog2d.hpp:10378
A line segment, oriented (OSegment_) or not (Segment_). Holds the two points.
Definition: homog2d.hpp:366
DrawParams & showIndex(bool b=true)
Set or unset the drawing of points (useful only for Segment_ and Polyline_)
Definition: homog2d.hpp:634
DrawParams & setColor(uint8_t r, uint8_t g, uint8_t b)
Definition: homog2d.hpp:605
Here is the call graph for this function:
Here is the caller graph for this function:

◆ action_SI()

void action_SI ( void *  param)
647 {
648  auto& data = *reinterpret_cast<Param_SI*>(param);
649 
650  data.clearImage();
651  data.seg1.set( data.vpt[0], data.vpt[1] );
652  data.seg2.set( data.vpt[2], data.vpt[3] );
653 
654  data.seg1.draw( data.img, img::DrawParams().setColor( 0,0,250).setThickness(2) );
655  data.seg2.draw( data.img, img::DrawParams().setColor( 250,0,0).setThickness(2) );
656  data.seg1.getLine().draw( data.img, img::DrawParams().setColor( 200,200,200) );
657  data.seg2.getLine().draw( data.img, img::DrawParams().setColor( 200,200,200) );
658  draw( data.img, data.vpt );
659 
660  auto psegs = data.seg1.getParallelSegs( 40 );
661  draw( data.img, psegs.first, img::DrawParams().setColor( 0,250,200) );
662  draw( data.img, psegs.second, img::DrawParams().setColor( 200,0,250) );
663 
664 
665  if( data._selected != -1 )
666  data.vpt[data._selected].draw( data.img, img::DrawParams().selectPoint() );
667 
668  auto inters = data.seg1.intersects( data.seg2 );
669  if( inters() )
670  {
671  auto pti = inters.get();
672  pti.draw( data.img );
673  Line2d l1 = data.seg1.getLine().getOrthogLine( pti );
674  l1.draw( data.img, img::DrawParams().setColor( 0,0,100) );
675 
676  Line2d l2 = data.seg2.getLine().getOrthogLine( pti );
677  l2.draw( data.img, img::DrawParams().setColor( 100,0,0) );
678  }
679 
680  Line2d li2( Point2d(350,120),Point2d(20,50));
681  li2.draw( data.img );
682 
683  auto inters1 = data.seg1.intersects( li2 );
684  if( inters1() )
685  inters1.get().draw( data.img, img::DrawParams().setPointStyle(img::PtStyle::Diam).setColor( 250,0,0));
686  auto inters2 = data.seg2.intersects( li2 );
687  if( inters2() )
688  inters2.get().draw( data.img, img::DrawParams().setPointStyle(img::PtStyle::Diam).setColor( 250,0,0));
689 
690  auto segDist1 = action_SI_drawDist( data.seg1, param );
691  auto segDist2 = action_SI_drawDist( data.seg2, param );
692  data.putTextLine( "distance mouse/s1=" + std::to_string(segDist1) + " mouse/s2=" + std::to_string(segDist2) ,0 );
693  data.showImage();
694 }
Line2d_< FPT > getOrthogLine(GivenCoord gc, FPT2 other) const
Returns an orthogonal line to the one it is called on, at a point on the line defined by one of its c...
Definition: homog2d.hpp:8878
void draw(Data &data)
Definition: precision_test_opencv.cpp:184
double action_SI_drawDist(const Segment &seg, void *param)
Definition: demo_opencv.cpp:620
DrawParams & setThickness(uint8_t t)
Definition: homog2d.hpp:600
void draw(img::Image< img::SvgImage > &im, img::DrawParams dp=img::DrawParams()) const
SVG draw function.
Definition: homog2d.hpp:4414
Draw parameters, independent of back-end library.
Definition: homog2d.hpp:514
Point2d_< HOMOG2D_INUMTYPE > Point2d
Default point type, uses double as numerical type.
Definition: homog2d.hpp:12379
DrawParams & setPointStyle(PtStyle ps)
Definition: homog2d.hpp:585
DrawParams & selectPoint()
Definition: homog2d.hpp:615
DrawParams & setColor(uint8_t r, uint8_t g, uint8_t b)
Definition: homog2d.hpp:605
Base class, will be instanciated as Point2d_ or Line2d_.
Definition: homog2d.hpp:365
Here is the call graph for this function:
Here is the caller graph for this function:

◆ action_SI_drawDist()

double action_SI_drawDist ( const Segment seg,
void *  param 
)
621 {
622  auto& data = *reinterpret_cast<Param_SI*>(param);
623 
624  int segDistCase;
625  auto segDist = seg.distTo( data._pt_mouse, &segDistCase );
626 
627  auto col_A = img::DrawParams().setColor( 0,200,200 );
628  auto col_B = img::DrawParams().setColor( 200,200,0 );
629  switch( segDistCase )
630  {
631  case -1:
632  draw( data.img, Segment( data._pt_mouse, seg.getPts().first ), col_B );
633  break;
634  case +1:
635  draw( data.img, Segment( data._pt_mouse, seg.getPts().second ), col_B );
636  break;
637  default:
638  if( data._pt_mouse.distTo( seg.getLine() ) > 3. )
639  {
640  auto orthog_seg = seg.getLine().getOrthogSegment( data._pt_mouse );
641  orthog_seg.draw( data.img, col_A );
642  }
643  }
644  return segDist;
645 }
void draw(Data &data)
Definition: precision_test_opencv.cpp:184
Draw parameters, independent of back-end library.
Definition: homog2d.hpp:514
HOMOG2D_INUMTYPE distTo(const Point2d_< FPT2 > &, int *segDistCase=0) const
Distance from point to segment.
Definition: homog2d.hpp:5509
PointPair_< FPT > getPts() const
Returns the points of segment as a std::pair.
Definition: homog2d.hpp:5197
A line segment, oriented (OSegment_) or not (Segment_). Holds the two points.
Definition: homog2d.hpp:366
DrawParams & setColor(uint8_t r, uint8_t g, uint8_t b)
Definition: homog2d.hpp:605
auto getLine() const
Returns supporting line.
Definition: homog2d.hpp:5252
Here is the call graph for this function:
Here is the caller graph for this function:

◆ demo_1()

void demo_1 ( int  demidx)
422 {
423  Data data( demidx, "lines" );
424  std::cout << "Demo " << demidx << ": click on points and move them\n";
425 
426  data.setMouseCB( action_1 );
427 
428  int n=5;
429  data.vpt[0].set( data._imWidth/2, data._imHeight/n );
430  data.vpt[1].set( data._imWidth/2, data._imHeight*(n-1)/n );
431  data.vpt[2].set( data._imWidth/n, data._imHeight/2 );
432  data.vpt[3].set( data._imWidth*(n-1)/n, data._imHeight/2 );
433 
434  data.clearImage();
435  action_1( &data );
436  data.showImage();
437 
438  auto k = cv::waitKey(0);
439  if( k == 27 )
440  std::exit(0);
441 }
void action_1(void *param)
Definition: demo_opencv.cpp:396
Here is the call graph for this function:
Here is the caller graph for this function:

◆ demo_6()

void demo_6 ( int  demidx)
766 {
767  Param_6 data( demidx, "homography_lines_seg",
768  "Apply homography to lines and segments\n Hit [lm] to change angle, \
769  and select points of blue segment with mouse" );
770 
771  double angle_delta = 5.; // degrees
772 
773  data.setMouseCB( action_6 );
774  action_6( &data );
775 
776  data.showImage();
777 
778  KeyboardLoop kbloop;
779  kbloop.addKeyAction( 'm', [&](void*){ data.angle += angle_delta; std::cout << "val=" <<data.angle<<'\n'; }, "increment angle" );
780  kbloop.addKeyAction( 'l', [&](void*){ data.angle -= angle_delta; std::cout << "val=" <<data.angle<<'\n'; }, "decrement angle" );
781  kbloop.addCommonAction( [&](void*){ action_6(&data);} );
782  kbloop.start( data );
783 }
void action_6(void *param)
Definition: demo_opencv.cpp:725
Here is the call graph for this function:
Here is the caller graph for this function:

◆ demo_B()

void demo_B ( int  demidx)

Build H from R,T,S (no mouse)

460 {
461  Param_B data( demidx, "build Homography", "build Homography from Rotation, Translation, Scale \
462  Hit a key: scale:[op], angle:[lm], translation:[gh,yb], reset: r" );
463 
464  double angle = 0.;
465  double angle_delta = 5.;
466  double scale = 1.;
467  double scale_delta = 1.2;
468  double tx = 0;
469  double ty = 0;
470  double trans_delta = 20;
471  double K = M_PI/180.;
472 
473  data.clearImage();
474  data.initPts();
475  data.drawLines();
476  data.showImage();
477 
478  KeyboardLoop kbloop;
479  kbloop.addKeyAction( 'r', [&](void*){ scale = 1.; angle = tx = ty = 0.; }, "reset" );
480  kbloop.addKeyAction( 'm', [&](void*){ angle += angle_delta; }, "increment angle" );
481  kbloop.addKeyAction( 'l', [&](void*){ angle -= angle_delta; }, "decrement angle" );
482  kbloop.addKeyAction( 'z', [&](void*){ tx += trans_delta; }, "increment tx" );
483  kbloop.addKeyAction( 'a', [&](void*){ tx -= trans_delta; }, "decrement tx" );
484  kbloop.addKeyAction( 'b', [&](void*){ ty += trans_delta; }, "increment ty" );
485  kbloop.addKeyAction( 'y', [&](void*){ ty -= trans_delta; }, "decrement ty" );
486  kbloop.addKeyAction( 'p', [&](void*){ scale *= scale_delta; }, "increment scale" );
487  kbloop.addKeyAction( 'o', [&](void*){ scale /= scale_delta; }, "reduce scale" );
488  kbloop.addCommonAction( [&](void*)
489  {
490  data.clearImage();
491  Homogr H;
492  H.addRotation( angle*K ).addTranslation( tx, ty ).addScale( scale );
493  data.initPts();
494  H.applyTo(data.vpt);
495  data.drawLines();
496  data.showImage();
497  }
498  );
499 
500  kbloop.start( data );
501 }
void applyTo(T &) const
Apply homography to a vector/array/list (type T) of points or lines.
Definition: homog2d.hpp:9563
#define M_PI
Definition: homog2d.hpp:235
A 2D homography, defining a planar transformation.
Definition: homog2d.hpp:369
Hmatrix_ & addScale(T k)
Adds the same scale factor to the matrix.
Definition: homog2d.hpp:1878
Hmatrix_ & addTranslation(T tx, T ty)
Adds a translation tx,ty to the matrix.
Definition: homog2d.hpp:1830
HOMOG2D_INUMTYPE angle(const Ellipse_< FPT > &ell)
Return angle of ellipse (free function)
Definition: homog2d.hpp:10993
Hmatrix_ & addRotation(T theta)
Adds a rotation with an angle theta (radians) to the matrix.
Definition: homog2d.hpp:1854
Here is the call graph for this function:
Here is the caller graph for this function:

◆ demo_BB()

void demo_BB ( int  demidx)
1862 {
1863  Param_BB data( demidx, "Generalized Bounding Box demo", ": Bounding Box demo\n \
1864  Move the points to see the common bounding box of the two elements. hit [w] and [x] to change." );
1865 
1866  action_BB( &data );
1867  data.setMouseCB( action_BB );
1868 
1869  KeyboardLoop kbloop;
1870  kbloop.addKeyAction( 'w', [&](void*){ std::cout << "red: " << data.switchToNext(0) << '\n'; }, "Switch to next 1" );
1871  kbloop.addKeyAction( 'x', [&](void*){ std::cout << "blue: " << data.switchToNext(1) << '\n'; }, "Switch to next 2" );
1872  kbloop.addCommonAction( action_BB );
1873 
1874  kbloop.start( data );
1875 }
1876 
void action_BB(void *param)
Definition: demo_opencv.cpp:1815
Here is the call graph for this function:
Here is the caller graph for this function:

◆ demo_C()

void demo_C ( int  demidx)
590 {
591  Param_C data( demidx, "circle demo", "move circle over line, hit [lm] to change circle radius" );
592 
593  data.li[0] = Point2d() * Point2d(200,100);
594  data.li[1] = Point2d(200,0) * Point2d(200,200);
595  data.li[2] = Point2d(0,200) * Point2d(200,200);
596 
597  data.clearImage();
598  data.drawLines();
599  action_C( &data );
600  data.showImage();
601 
602  data.setMouseCB( action_C );
603 
604  KeyboardLoop kbloop;
605  kbloop.addKeyAction( 'l', [&](void*){ data.radius += 10; }, "increment radius" );
606  kbloop.addKeyAction( 'm', [&](void*){ data.radius -= 10; }, "decrement radius" );
607  kbloop.addKeyAction( 'r', [&](void*){ data.radius = 80; }, "reset radius" );
608  kbloop.start( data );
609 }
Point2d_< HOMOG2D_INUMTYPE > Point2d
Default point type, uses double as numerical type.
Definition: homog2d.hpp:12379
void action_C(void *param)
Definition: demo_opencv.cpp:523
Here is the call graph for this function:
Here is the caller graph for this function:

◆ demo_CH()

void demo_CH ( int  demidx)
1323 {
1324  Param_CH data( demidx, "Convex Hull + MEC demo",
1325  "Convex hull + Minimum Enclosing Circle. Lclick to add points, Rclick to remove" );
1326  action_CH( &data );
1327  data.setMouseCB( action_CH );
1328 
1329  data.leftClicAddPoint=true;
1330 
1331  KeyboardLoop kbloop;
1332  kbloop.addKeyAction( 'a', [&](void*){ data._mode = !data._mode; }, "Toggle drawing mode (Hull, or hull lines)" );
1333  kbloop.addCommonAction( action_CH );
1334  action_CH( &data );
1335  kbloop.start( data );
1336 }
void action_CH(void *param)
Definition: demo_opencv.cpp:1283
Here is the call graph for this function:
Here is the caller graph for this function:

◆ demo_CIR()

void demo_CIR ( int  demidx)
1244 {
1245  Param_CIR data( demidx, "Circle demo", "Compute circle from 3 points/2 points\n \
1246  Colors: green if inside, blue if not\n \
1247  if 3 points, also computes the corresponding parallelogram" );
1248 
1249  action_CIR( &data );
1250  data.setMouseCB( action_CIR );
1251 
1252  KeyboardLoop kbloop;
1253  kbloop.addCommonAction( action_CIR );
1254 
1255  kbloop.addKeyAction( 'a', [&](void*)
1256  {
1257  data._buildFrom3Pts = !data._buildFrom3Pts;
1258  },
1259  "switch circle from 2 pts / 3 pts"
1260  );
1261  kbloop.addKeyAction( 'w', [&](void*)
1262  {
1263  data._drawRect = !data._drawRect;
1264  },
1265  "switch circle/rectangle"
1266  );
1267 
1268  kbloop.start( data ); // blocking function
1269 }
void action_CIR(void *param)
Definition: demo_opencv.cpp:1235
Here is the call graph for this function:
Here is the caller graph for this function:

◆ demo_ELL()

void demo_ELL ( int  demidx)

Ellipse demo.

1123 {
1124  Param_ELL data( demidx, "Ellipse demo",
1125  "Ellipse (no mouse, enter 'h' for valid keys)\n \
1126  -blue rectangle: ellipse bounding box\n \
1127  -green rectangle: blue rectangle bounding box" );
1128 
1129  double trans_delta = 20;
1130  double angle_delta = 5.;
1131 
1132  KeyboardLoop kbloop;
1133  kbloop.addKeyAction( 'z', [&](void*){ data.tx += trans_delta; }, "increment tx" );
1134  kbloop.addKeyAction( 'a', [&](void*){ data.tx -= trans_delta; }, "decrement tx" );
1135  kbloop.addKeyAction( 'b', [&](void*){ data.ty += trans_delta; }, "increment ty" );
1136  kbloop.addKeyAction( 'y', [&](void*){ data.ty -= trans_delta; }, "decrement ty" );
1137  kbloop.addKeyAction( 'm', [&](void*){ data.angle += angle_delta; }, "increment angle" );
1138  kbloop.addKeyAction( 'l', [&](void*){ data.angle -= angle_delta; }, "decrement angle" );
1139  kbloop.addKeyAction( 'o', [&](void*){ data.ratio_mm = std::min(data.ratio_mm*1.1, 1.00); }, "inc ratio" );
1140  kbloop.addKeyAction( 'p', [&](void*){ data.ratio_mm = std::max(data.ratio_mm/1.1, 0.05); }, "dec ratio" );
1141 
1142  kbloop.addCommonAction( action_ELL );
1143  action_ELL( &data );
1144  kbloop.start( data );
1145 }
void action_ELL(void *param)
action for Ellipse demo (run on keyboard hit)
Definition: demo_opencv.cpp:1113
Here is the call graph for this function:
Here is the caller graph for this function:

◆ demo_H()

void demo_H ( int  demidx)

Demo of computing a homography from two sets of 4 points.

913 {
914  Param_H data( demidx, "Compute Homography from 4 points" );
915  data.vpt.resize(8);
916  data.reset();
917  std::cout << "Demo " << demidx << ": compute homography from two sets of 4 points\n"
918  << " - usage: move points with mouse in left window, right window will show source rectangle (blue)\n"
919  << "and computed projected rectangle (green)\n"
920  << " - keys:\n -a: switch backend computing library\n -r: reset points\n";
921 
922  data.setMouseCB( action_H );
923  action_H( &data );
924 
925  KeyboardLoop kbloop;
926  kbloop.addKeyAction( 'r', [&](void*){ data.reset(); } );
927  kbloop.addKeyAction( 'a', [&](void*)
928  {
929  data.hmethod = data.hmethod?0:1;
930 #if !defined(HOMOG2D_USE_EIGEN)
931  if( data.hmethod == 0 )
932  {
933  std::cout << "Unable, build without Eigen support, see manual, switch to Opencv\n";
934  data.hmethod = 1;
935  }
936 #endif
937  }
938  );
939  kbloop.start( data );
940 }
void action_H(void *param)
Definition: demo_opencv.cpp:823
Here is the call graph for this function:
Here is the caller graph for this function:

◆ demo_NFP()

void demo_NFP ( int  demidx)
1668 {
1669  Param_NFP data( demidx, "Closest/Farthest Point" );
1670 
1671  KeyboardLoop kbloop;
1672  kbloop.addKeyAction( 'a', [&](void*){ data._mode==2? data._mode=0: data._mode++; }, "switch mode (nearest/farthest/both)" );
1673  kbloop.addKeyAction( 'b', [&](void*){ data.genRandomPoints(); }, "Re-generate random points" );
1674 
1675  kbloop.addCommonAction( action_NFP );
1676  action_NFP( &data );
1677  data.setMouseCB( action_NFP );
1678 
1679  kbloop.start( data );
1680 }
void action_NFP(void *param)
Definition: demo_opencv.cpp:1634
Here is the call graph for this function:
Here is the caller graph for this function:

◆ demo_orthSeg()

void demo_orthSeg ( int  demidx)
1724 {
1725  Param_ORS data( demidx, "Orthogonal segments", "Orthogonal segments\n(Move the segment with mouse)" );
1726 
1727  KeyboardLoop kbloop;
1728  kbloop.addKeyAction( 'a', [&](void*){ data._ptsOrSegs=!data._ptsOrSegs; }, "switch mode: points or segments" );
1729  kbloop.addKeyAction( 'w', [&](void*){ data._drawPolyg=!data._drawPolyg; }, "switch mode: draw polygon in points mode" );
1730 
1731  kbloop.addCommonAction( action_ORS );
1732  action_ORS( &data );
1733  data.setMouseCB( action_ORS );
1734 
1735  kbloop.start( data );
1736 }
void action_ORS(void *param)
Definition: demo_opencv.cpp:1697
Here is the call graph for this function:
Here is the caller graph for this function:

◆ demo_OSegAngle()

void demo_OSegAngle ( int  demidx)
2134 {
2135  Param_OSegAngle data( demidx, "OSegment angle", "move the 3 points with mouse" );
2136  data.setMouseCB( action_OSegAngle );
2137  data.vpt.resize(3);
2138  KeyboardLoop kbloop;
2139  kbloop.addKeyAction( 'a', [&](void*){ toggle(data._reverseS1,"reverse S1"); }, "reverse S1" );
2140  kbloop.addKeyAction( 'z', [&](void*){ toggle(data._reverseS2,"reverse S2"); }, "reverse S2" );
2141  kbloop.addKeyAction( 'w', [&](void*){ toggle(data._showParallel,"showParallel lines"); }, "showParallel lines" );
2142 
2143  kbloop.addCommonAction( action_OSegAngle );
2144  action_OSegAngle( &data );
2145  kbloop.start( data );
2146 }
2147 
void action_OSegAngle(void *param)
Definition: demo_opencv.cpp:2089
void toggle(bool &b, std::string msg)
Definition: demo_opencv.cpp:390
Here is the call graph for this function:
Here is the caller graph for this function:

◆ demo_PL()

void demo_PL ( int  demidx)
1048 {
1049  Param_PL data( demidx, "Polyline demo",
1050  "polyline\n-Colors\n -Red: polygon (needs to be closed)\n -Blue: intersections\n \
1051  Lclick to add point, Rclick to remove" );
1052 
1053  data.leftClicAddPoint=true;
1054  data.setMouseCB( action_PL );
1055 
1056  action_PL( &data );
1057 
1058  KeyboardLoop kbloop;
1059  kbloop.addKeyAction( 'a', [&](void*)
1060  {
1061  data.showClosedPoly = !data.showClosedPoly;
1062  },
1063  "switch open/close"
1064  );
1065 // kbloop.addCommonAction( [&] { action_PL(&data); } );
1066  kbloop.start( data );
1067 }
void action_PL(void *param)
Definition: demo_opencv.cpp:957
Here is the call graph for this function:
Here is the caller graph for this function:

◆ demo_PO()

void demo_PO ( int  demidx)

Polygon Offset demo start.

2056 {
2057  Param_PO data( demidx, "Polygon Offset" );
2058  data.leftClicAddPoint=true;
2059 
2060  data.setMouseCB( action_PO );
2061  KeyboardLoop kbloop;
2062  kbloop.addKeyAction( 'w', [&](void*){ data._offsetDist += 2; }, "Increase distance" );
2063  kbloop.addKeyAction( 'x', [&](void*){ data._offsetDist = std::max(1,data._offsetDist-2); }, "Reduce distance" );
2064  kbloop.addKeyAction( 'a', [&](void*){ toggle(data._showSegs, "showSegs"); }, "Toggle segments to centroid" );
2065  kbloop.addKeyAction( 'q', [&](void*){ toggle(data._side, "side"); }, "Reverse side" );
2066  kbloop.addKeyAction( 'b', [&](void*){ toggle(data._drawBisectorLines, "drawBisectorLines"); }, "toggle draw bisector lines" );
2067  kbloop.addKeyAction( 'v', [&](void*){ toggle(data._params._angleSplit, "angleSplit"); }, "switch angles cut" );
2068  kbloop.addKeyAction( 'f', [&](void*){ toggle(data._showPolyAngles, "showPolyAngles"); }, "toggle angles" );
2069  kbloop.addKeyAction( 'g', [&](void*){ toggle(data._showPolyIdx, "showPolyIdx"); }, "toggle indexes" );
2070  kbloop.addKeyAction( 'k', [&](void*){ toggle(data._closedPol, "closedPol"); }, "toggle open/closed" );
2071 
2072  kbloop.addCommonAction( action_PO );
2073  action_PO( &data );
2074  kbloop.start( data );
2075 }
2076 
void toggle(bool &b, std::string msg)
Definition: demo_opencv.cpp:390
void action_PO(void *param)
Polygon Offset demo action.
Definition: demo_opencv.cpp:2032
Here is the call graph for this function:
Here is the caller graph for this function:

◆ demo_polRot()

void demo_polRot ( int  demidx)
1584 {
1585  Param_polRot data( demidx, "Polyline/Rectangle full step rotate demo",
1586  "Polyline/Rectangle full step rotate demo\n \
1587  - Polyline: center point is one of the points\n \
1588  - Rectangle: center point is free, use mouse\n \
1589  Warning: as images as shown here with vertical axis reversed, what appears as a CW is actually a CCW rotation!" );
1590 
1591  data.setMouseCB( action_polRot );
1592 
1593  KeyboardLoop kbloop;
1594  kbloop.addKeyAction( 'a', [&](void*){ data._rotateType=Rotate::CW; data.doIt(); }, "rotate CW" );
1595  kbloop.addKeyAction( 'z', [&](void*){ data._rotateType=Rotate::CCW; data.doIt(); }, "rotate CCW" );
1596  kbloop.addKeyAction( 'e', [&](void*){ data._rotateType=Rotate::Full; data.doIt(); }, "rotate Full" );
1597  kbloop.addKeyAction( 'o', [&](void*){ data._rotateType=Rotate::VMirror; data.doIt(); }, "VMirror" );
1598  kbloop.addKeyAction( 'p', [&](void*){ data._rotateType=Rotate::HMirror; data.doIt(); }, "HMirror" );
1599  kbloop.addKeyAction( 'w', [&](void*){ data.nextRefPt(); data.doIt(false); }, "move to next reference point" );
1600  kbloop.addKeyAction( 'r', [&](void*){ data._item = !data._item; data.doIt(false); }, "toggle poly/rectangle" );
1601 
1602  kbloop.addCommonAction( action_polRot );
1603  action_polRot( &data );
1604 
1605  kbloop.start( data );
1606 }
void action_polRot(void *param)
Definition: demo_opencv.cpp:1556
Here is the call graph for this function:
Here is the caller graph for this function:

◆ demo_RCP()

void demo_RCP ( int  demidx)
1954 {
1955  Param_RCP data( demidx, "Regular Convex Polygon" );
1956 
1957  KeyboardLoop kbloop;
1958  kbloop.addKeyAction( 'w', [&](void*){ data._nbPts++; }, "more points" );
1959  kbloop.addKeyAction( 'x', [&](void*){ data.nbPts_less(); }, "less points" );
1960  kbloop.addKeyAction( 'a', [&](void*){ data._radius += data._radiusStep; }, "increase radius" );
1961  kbloop.addKeyAction( 'z', [&](void*){ data.radius_less(); }, "decrease radius" );
1962 
1963  kbloop.addCommonAction( action_RCP );
1964  action_RCP( &data );
1965  kbloop.start( data );
1966 }
1967 
void action_RCP(void *param)
Definition: demo_opencv.cpp:1902
Here is the call graph for this function:
Here is the caller graph for this function:

◆ demo_RI()

void demo_RI ( int  demidx)
1383 {
1384  Param_RI data( demidx, "Rectangle intersection demo" );
1385 
1386  data.setMouseCB( action_RI );
1387  KeyboardLoop kbloop;
1388  kbloop.addKeyAction( 'a', [&](void*){ data.doUnion = !data.doUnion; }, "Toggle union/intersection" );
1389  kbloop.addCommonAction( action_RI );
1390  action_RI( &data );
1391  kbloop.start( data );
1392 }
void action_RI(void *param)
Definition: demo_opencv.cpp:1347
Here is the call graph for this function:
Here is the caller graph for this function:

◆ demo_SEG()

void demo_SEG ( int  demidx)
1489 {
1490  Param_SEG data( demidx, "Segments demo" );
1491  data.generateSegments();
1492 
1493  KeyboardLoop kbloop;
1494  kbloop.addKeyAction( 'm', [&](void*){ data.showMiddlePoint = !data.showMiddlePoint; }, "show middle point" );
1495  kbloop.addKeyAction( 'n', [&](void*){ data.showIndexes = !data.showIndexes; }, "show indexes" );
1496  kbloop.addKeyAction( 'i', [&](void*){ data.showIntersection = !data.showIntersection; }, "show intersection points" );
1497  kbloop.addKeyAction( 'b', [&](void*){ data.showBisector = !data.showBisector; }, "show bisector lines" );
1498 
1499  kbloop.addKeyAction( 'r', [&](void*){ data.regen = true; }, "Re-generate" );
1500  kbloop.addKeyAction( 'w', [&](void*){ data.nbSegs = data.nbSegs*2; data.regen = true; }, "double nb points" );
1501  kbloop.addKeyAction( 'x', [&](void*){ data.nbSegs = data.nbSegs/2; data.regen = true; }, "half nb points" );
1502 
1503  kbloop.addCommonAction( action_SEG );
1504  action_SEG( &data );
1505 
1506  kbloop.start( data );
1507 }
void action_SEG(void *param)
Definition: demo_opencv.cpp:1435
Here is the call graph for this function:
Here is the caller graph for this function:

◆ demo_SI()

void demo_SI ( int  demidx)

Segment intersection demo.

698 {
699  Param_SI data( demidx, "segment_intersection",
700  "Intersection of segments\n Select a point and move it around. \
701  When they intersect, you get the orthogonal lines of the two segments, at the intersection point.\n \
702  Also shows parallel segments" );
703 
704  data.vpt[0] = Point2d(100,200);
705  data.vpt[1] = Point2d(200,300);
706  data.vpt[2] = Point2d(150,50);
707  data.vpt[3] = Point2d(300,250);
708 
709  action_SI( &data );
710  data.setMouseCB( action_SI );
711 
712  if( 27 == cv::waitKey(0) )
713  std::exit(0);
714 }
Point2d_< HOMOG2D_INUMTYPE > Point2d
Default point type, uses double as numerical type.
Definition: homog2d.hpp:12379
void action_SI(void *param)
Definition: demo_opencv.cpp:646
Here is the call graph for this function:
Here is the caller graph for this function:

◆ main()

int main ( int  argc,
const char **  argv 
)

Demo program, using Opencv.

  • if called with no arguments, will switch through all the demos, with SPC
  • if called with an (integer) argument, will launch only that demo
2219 {
2220  std::cout << "homog2d graphical demo using Opencv"
2221  << "\n - homog version: " << HOMOG2D_VERSION
2222  << "\n - build with OpenCV version: " << CV_VERSION << '\n';
2223 
2224  Point2dF pt1;
2225  std::cout << "float: size=" << pt1.dsize().first << "-" << pt1.dsize().second << '\n';
2226 
2227  Point2dL pt2;
2228  std::cout << "long: size=" << pt2.dsize().first << "-" << pt2.dsize().second << '\n';
2229 
2230  Point2dD pt3;
2231  std::cout << "double: size=" << pt3.dsize().first << "-" << pt3.dsize().second << '\n';
2232 
2233  img::DrawParams dp;
2234  std::cout << "Default draw parameters: " << dp;
2235 
2236  std::vector<std::function<void(int)>> v_demo{
2237 #ifdef HOMOG2D_PRELIMINAR
2238  demo_Square,
2239 #endif
2241  demo_PO,
2242  demo_BB,
2243  demo_RCP,
2244  demo_orthSeg, // Perpendicular segment
2245  demo_NFP, // Nearest/Farthest Point
2246  demo_RI, // rectangle intersection
2247  demo_CIR,
2248  demo_CH, // Convex Hull + Minimum Enclosing Circle (MEC)
2249  demo_SEG,
2250  demo_B,
2251  demo_ELL,
2252  demo_H,
2253  demo_PL,
2254  demo_1,
2255  demo_C,
2256  demo_SI,
2257  demo_6,
2258  demo_polRot // full step rotation of Polyline and rectangle
2259  };
2260 
2261  if( argc > 1 )
2262  {
2263  int d = std::atoi( argv[1] );
2264  assert( d>0 && d<=(int)v_demo.size() );
2265  std:: cout << " - calling demo " << d << "\n";
2266  v_demo[d-1](d);
2267  return 0;
2268  }
2269 
2270  std::cout << " - currently " << v_demo.size() << " demo cases available\n"
2271  << " - to switch to next demo, hit [SPC]\n - to exit, hit [ESC]\n";
2272  for( size_t i=0; i<v_demo.size(); i++ )
2273  {
2274  std::cout << "----------------------------------\n";
2275  v_demo[i](i+1);
2276  }
2277  std::cout << "Demo end\n";
2278 }
2279 
#define HOMOG2D_VERSION
Definition: homog2d.hpp:231
void demo_B(int demidx)
Build H from R,T,S (no mouse)
Definition: demo_opencv.cpp:459
void demo_NFP(int demidx)
Definition: demo_opencv.cpp:1667
void demo_6(int demidx)
Definition: demo_opencv.cpp:765
void demo_PO(int demidx)
Polygon Offset demo start.
Definition: demo_opencv.cpp:2056
void demo_ELL(int demidx)
Ellipse demo.
Definition: demo_opencv.cpp:1122
std::pair< int, int > dsize() const
Get data size expressed as number of bits for, respectively, mantissa and exponent.
Definition: homog2d.hpp:1345
void demo_RCP(int demidx)
Definition: demo_opencv.cpp:1954
void demo_1(int demidx)
Definition: demo_opencv.cpp:421
void demo_BB(int demidx)
Definition: demo_opencv.cpp:1862
void demo_H(int demidx)
Demo of computing a homography from two sets of 4 points.
Definition: demo_opencv.cpp:912
Draw parameters, independent of back-end library.
Definition: homog2d.hpp:514
void demo_SEG(int demidx)
Definition: demo_opencv.cpp:1488
void demo_RI(int demidx)
Definition: demo_opencv.cpp:1382
void demo_SI(int demidx)
Segment intersection demo.
Definition: demo_opencv.cpp:697
void demo_polRot(int demidx)
Definition: demo_opencv.cpp:1583
void demo_CIR(int demidx)
Definition: demo_opencv.cpp:1243
void demo_PL(int demidx)
Definition: demo_opencv.cpp:1047
void demo_C(int demidx)
Definition: demo_opencv.cpp:589
void demo_CH(int demidx)
Definition: demo_opencv.cpp:1322
Base class, will be instanciated as Point2d_ or Line2d_.
Definition: homog2d.hpp:365
void demo_orthSeg(int demidx)
Definition: demo_opencv.cpp:1723
void demo_OSegAngle(int demidx)
Definition: demo_opencv.cpp:2134
Here is the call graph for this function:

◆ myMouseCB()

void myMouseCB ( int  event,
int  x,
int  y,
int  ,
void *  param 
)

Mouse callback functions, checks if one of the points is selected.

  • If so, that point gets moved by the mouse, and the function action is called (if it has been assigned)
209 {
210  auto& data = *reinterpret_cast<Data*>(param);
211 
212  data.setMousePos(x,y);
213  bool doSomething = true;
214 
215  switch( event )
216  {
217  case cv::EVENT_LBUTTONUP:
218  data._selected = -1;
219  break;
220 
221  case cv::EVENT_LBUTTONDOWN:
222  data._selected = -1;
223  for( int i=0; i<data.nbPts(); i++ )
224  if( data._pt_mouse.distTo( data.vpt[i]) < 10 ) // if mouse is less than 10 pixel away
225  {
226  data._selected = i;
227  data.vpt[i].draw( data.img, img::DrawParams().setPointStyle(img::PtStyle::Diam) );
228  }
229  if( data._selected == -1 )
230  if( data.leftClicAddPoint )
231  data.addMousePoint();
232  break;
233 
234  case cv::EVENT_MOUSEMOVE:
235  if( data._selected != -1 )
236  {
237  data.vpt[data._selected] = data._pt_mouse;
238  data.vpt[data._selected].draw( data.img, img::DrawParams().selectPoint() );
239  }
240  break;
241 
242  case cv::EVENT_RBUTTONDOWN:
243  data._selected = -1;
244  for( int i=0; i<data.nbPts(); i++ )
245  if( data._pt_mouse.distTo( data.vpt[i]) < 10 ) // if mouse is less than 10 pixel away
246  data._selected = i;
247  if( data._selected != -1 )
248  {
249  data.vpt.erase( std::begin(data.vpt) + data._selected );
250  data._selected = -1;
251  }
252  break;
253 
254  default: doSomething = false; break;
255  }
256  if( doSomething )
257  {
258  data.clearImage();
259  if( data._mouseCB )
260  {
261  data._mouseCB( param );
262  }
263  data.showImage();
264  }
265 }
Draw parameters, independent of back-end library.
Definition: homog2d.hpp:514
DrawParams & setPointStyle(PtStyle ps)
Definition: homog2d.hpp:585
DrawParams & selectPoint()
Definition: homog2d.hpp:615
Here is the call graph for this function:

◆ process_PO()

template<typename IM , typename POL >
void process_PO ( IM &  im,
const POL &  pol,
Param_PO &  data 
)
2001 {
2002  if( data._drawBisectorLines )
2003  draw( im, pol.getBisectorLines() );
2004 
2005  if( pol.isSimple() )
2006  {
2007  auto cpoly_off = pol.getOffsetPoly( (data._side?1:-1)*data._offsetDist, data._params );
2008  draw( im, cpoly_off , img::DrawParams().showPoints(false).setColor(0,0,250) );
2009 
2010 // draw( im, dbg.psegs );
2011  auto centr = pol.centroid();
2012  draw( im, centr, img::DrawParams().showPoints().setColor(0,0,250) );
2013 
2014  draw( im, pol.centroid(), img::DrawParams().showPoints().setColor(0,0,250) );
2015 
2016  if( data._showSegs )
2017  {
2018  for( const auto& seg: pol.getSegs() )
2019  {
2020  auto mid= seg.getCenter();
2021  im.draw( Segment(mid, centr), img::DrawParams().setColor(0,150,0) );
2022  }
2023  }
2024  }
2025  draw( im, pol,
2026  img::DrawParams().showPoints().setColor(250,0,0).showAngles(data._showPolyAngles).showIndex(data._showPolyIdx) );
2027 }
2028 
std::vector< Segment_< FPT > > getSegs() const
Returns (as a copy) the segments of the polyline.
Definition: homog2d.hpp:6314
auto getCenter() const
Returns point at middle distance between p1 and p2.
Definition: homog2d.hpp:5288
void draw(Data &data)
Definition: precision_test_opencv.cpp:184
PolylineBase< typ::IsClosed, FPT > getOffsetPoly(T value, OffsetPolyParams p=OffsetPolyParams{}) const
Return an "offsetted" closed polyline, requires simple polygon (CPolyline AND no crossings) as input...
Definition: homog2d.hpp:6673
Segment seg
Definition: homog2d_test.cpp:4033
Segment_< HOMOG2D_INUMTYPE > Segment
Default segment type.
Definition: homog2d.hpp:12388
bool isSimple() const
Returns true if object is a polygon (closed, and no segment crossing)
Definition: homog2d.hpp:7381
CPolyline pol(5, 5u)
Draw parameters, independent of back-end library.
Definition: homog2d.hpp:514
std::vector< Line2d_< HOMOG2D_INUMTYPE > > getBisectorLines() const
Definition: homog2d.hpp:6649
img::Image< img::SvgImage > im(300, 400)
DrawParams & showPoints(bool b=true)
Set or unset the drawing of points (useful only for Segment_ and Polyline_)
Definition: homog2d.hpp:621
DrawParams & showIndex(bool b=true)
Set or unset the drawing of points (useful only for Segment_ and Polyline_)
Definition: homog2d.hpp:634
DrawParams & setColor(uint8_t r, uint8_t g, uint8_t b)
Definition: homog2d.hpp:605
LPBase< typ::IsPoint, HOMOG2D_INUMTYPE > centroid() const
Compute centroid of polygon.
Definition: homog2d.hpp:7518
Here is the call graph for this function:
Here is the caller graph for this function:

◆ removeDupes()

std::vector<Point2d> removeDupes ( const std::vector< Point2d > &  vec)

Helper function. Only removes duplicates if there are consecutive.

1991 {
1992  std::vector<Point2d> out( vec );
1993  out.erase( std::unique( out.begin(), out.end() ), out.end() );
1994  if( out.front() == out.back() ) // if first == last, remove last element
1995  out.pop_back();
1996  return out;
1997 }
1998 
Here is the caller graph for this function:

◆ toggle()

void toggle ( bool &  b,
std::string  msg 
)
391 {
392  b = !b;
393  std::cout << "toogle " << msg << "=" << b << '\n';
394 }
Here is the caller graph for this function: