homog2d library
Functions | Variables
showcase19.cpp File Reference

Generates random segments. More...

#include "../../homog2d.hpp"
Include dependency graph for showcase19.cpp:

Functions

std::vector< SegmentgenerateSegments (int nbSegs)
 
int main (int, const char **)
 

Variables

auto im_h = 300
 
auto im_w = 400
 

Detailed Description

Generates random segments.

Todo:
20240421 switch all showcases to Svg images, much nicer!

Function Documentation

◆ generateSegments()

std::vector<Segment> generateSegments ( int  nbSegs)
18 {
19  int delta = 40;
20  int width = im_w-delta;
21  int height = im_h-delta;
22 
23  std::vector<Segment> vseg;
24  for( auto i=0; i<nbSegs; i++ )
25  {
26  auto len = 1.0*rand() / RAND_MAX * 40 + 10;
27  auto p1x = 1.0*rand() / RAND_MAX * width + 20;
28  auto p2x = 1.0*rand() / RAND_MAX * width + 20;;
29  auto p1y = 1.0*rand() / RAND_MAX * height + 20;
30  auto p2y = 1.0*rand() / RAND_MAX * height + 20;
31  auto line = Line2d( p1x, p1y, p2x, p2y );
32  auto ppts = line.getPoints( Point2d( p1x, p1y) , len );
33  vseg.push_back( Segment( ppts ) );
34  }
35  return vseg;
36 }
HOMOG2D_INUMTYPE height(const FRect_< FPT > &rect)
Free function.
Definition: homog2d.hpp:10874
Segment_< HOMOG2D_INUMTYPE > Segment
Default segment type.
Definition: homog2d.hpp:12388
Line2d_< HOMOG2D_INUMTYPE > Line2d
Default line type, uses double as numerical type.
Definition: homog2d.hpp:12376
HOMOG2D_INUMTYPE width(const FRect_< FPT > &rect)
Free function.
Definition: homog2d.hpp:10882
auto im_w
Definition: showcase19.cpp:14
auto im_h
Definition: showcase19.cpp:13
Point2d_< HOMOG2D_INUMTYPE > Point2d
Default point type, uses double as numerical type.
Definition: homog2d.hpp:12379
size_t nbSegs(const base::PolylineBase< PLT, FPT > &pl)
Returns the number of segments (free function)
Definition: homog2d.hpp:9927
Here is the call graph for this function:
Here is the caller graph for this function:

◆ main()

int main ( int  ,
const char **   
)
39 {
40  auto nbim = 5; // nb images
41  int nbSegs = 40;
42  auto vcol = img::genRandomColors( nbSegs );
43 
44  auto func = [&](int i) // lambda, needed to fetch color from index
45  {
46  return img::DrawParams().setColor(vcol[i]).showPoints();
47 // return img::DrawParams().showIndex().setColor(vcol[i]).showPoints();
48  };
49  std::function<img::DrawParams(int)> f(func);
50 
51  for( int i=0; i<nbim; i++ )
52  {
53  auto vseg = generateSegments( nbSegs );
54 // Image<SvgImage> im( im_w, im_h );
56  draw( im, vseg, f );
57 
58  std::ostringstream ossa;
59 // ossa << "showcase19_" << std::setfill('0') << std::setw(2) << i << ".svg";
60  ossa << "showcase19_" << std::setfill('0') << std::setw(2) << i << ".svg";
61  im.write( ossa.str() );
62  }
63 }
void draw(Data &data)
Definition: precision_test_opencv.cpp:184
auto im_w
Definition: showcase19.cpp:14
std::vector< Segment > generateSegments(int nbSegs)
Definition: showcase19.cpp:17
Draw parameters, independent of back-end library.
Definition: homog2d.hpp:514
auto im_h
Definition: showcase19.cpp:13
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
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
Opaque data structure, will hold the image type, depending on back-end library. This type is the one ...
Definition: homog2d.hpp:712
size_t nbSegs(const base::PolylineBase< PLT, FPT > &pl)
Returns the number of segments (free function)
Definition: homog2d.hpp:9927
DrawParams & setColor(uint8_t r, uint8_t g, uint8_t b)
Definition: homog2d.hpp:605
Here is the call graph for this function:

Variable Documentation

◆ im_h

auto im_h = 300

◆ im_w

auto im_w = 400