-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathshowcase19.cpp
64 lines (53 loc) · 1.55 KB
/
showcase19.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/**
\file
\brief Generates random segments
\todo 20240421 switch all showcases to Svg images, much nicer!
*/
#include "../../homog2d.hpp"
using namespace h2d;
using namespace h2d::img;
auto im_h = 300;
auto im_w = 400;
std::vector<Segment>
generateSegments( int nbSegs )
{
int delta = 40;
int width = im_w-delta;
int height = im_h-delta;
std::vector<Segment> vseg;
for( auto i=0; i<nbSegs; i++ )
{
auto len = 1.0*rand() / RAND_MAX * 40 + 10;
auto p1x = 1.0*rand() / RAND_MAX * width + 20;
auto p2x = 1.0*rand() / RAND_MAX * width + 20;;
auto p1y = 1.0*rand() / RAND_MAX * height + 20;
auto p2y = 1.0*rand() / RAND_MAX * height + 20;
auto line = Line2d( p1x, p1y, p2x, p2y );
auto ppts = line.getPoints( Point2d( p1x, p1y) , len );
vseg.push_back( Segment( ppts ) );
}
return vseg;
}
int main( int, const char** )
{
auto nbim = 5; // nb images
int nbSegs = 40;
auto vcol = img::genRandomColors( nbSegs );
auto func = [&](int i) // lambda, needed to fetch color from index
{
return img::DrawParams().setColor(vcol[i]).showPoints();
// return img::DrawParams().showIndex().setColor(vcol[i]).showPoints();
};
std::function<img::DrawParams(int)> f(func);
for( int i=0; i<nbim; i++ )
{
auto vseg = generateSegments( nbSegs );
// Image<SvgImage> im( im_w, im_h );
Image<img::SvgImage> im( im_w, im_h );
draw( im, vseg, f );
std::ostringstream ossa;
// ossa << "showcase19_" << std::setfill('0') << std::setw(2) << i << ".svg";
ossa << "showcase19_" << std::setfill('0') << std::setw(2) << i << ".svg";
im.write( ossa.str() );
}
}