-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathbg_test_1.cpp
61 lines (47 loc) · 1.76 KB
/
bg_test_1.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
/**
\file
\brief test of importing a polygon from Boost Geometry
\note 20230216: preliminar feature, will be expanded
run with `$ make test-bg`
*/
#define HOMOG2D_USE_BOOSTGEOM
#define HOMOG2D_USE_OPENCV
#include "../../homog2d.hpp"
int main()
{
namespace bg = boost::geometry;
std::cout << "Boost version:" << BOOST_VERSION << '\n';
std::cout << "Boost lib version:" << BOOST_LIB_VERSION << '\n';
// two types of boost points
using point_t1 = bg::model::point<double, 2, bg::cs::cartesian>;
using point_t2 = bg::model::d2::point_xy<double>;
// build two boost geometry polygons, one open, one closed
using cpolygon_t1 = bg::model::polygon<point_t1,true,true>;
using opolygon_t1 = bg::model::polygon<point_t1,true,false>;
cpolygon_t1 cpoly1{{ {0.0, 0.0}, {0.0, 5.0}, {5.0, 5.0}, {5.0, 0.0}, {0.0, 0.0} }};
opolygon_t1 opoly1{{ {0.0, 0.0}, {0.0, 5.0}, {5.0, 5.0}, {5.0, 0.0} }};
// importing the polygons
h2d::CPolyline p1a( cpoly1 );
h2d::OPolyline p1b( opoly1 );
std::cout << "p1a=" << p1a << "p1b=" << p1b << '\n';
using cpolygon_t2 = bg::model::polygon<point_t2,true,true>;
using opolygon_t2 = bg::model::polygon<point_t2,true,false>;
cpolygon_t2 cpoly2{{ {0.0, 0.0}, {0.0, 5.0}, {5.0, 5.0}, {5.0, 0.0}, {0.0, 0.0} }};
opolygon_t2 opoly2{{ {0.0, 0.0}, {0.0, 5.0}, {5.0, 5.0}, {5.0, 0.0} }};
h2d::CPolyline p2a( cpoly2 );
h2d::OPolyline p2b( opoly2 );
std::cout << "p2a=" << p2a << "p2b=" << p2b << '\n';
point_t1 ptb1(3,4);
point_t2 ptb2(8,9);
h2d::Point2d p1(ptb1);
h2d::Point2d p2(ptb2);
std::cout << "p1=" << p1 << " p2=" << p2 << '\n';
p1.set(ptb2);
p2.set(ptb1);
std::cout << "p1=" << p1 << " p2=" << p2 << '\n';
p1 = ptb2;
p2 = ptb1;
// convert to bg type
point_t1 bpt1a = p1.getPt<point_t1>();
point_t1 bpt1b = h2d::getPt<point_t1>(p2);
}