DGtal
2.2.0
Toggle main menu visibility
Loading...
Searching...
No Matches
testShapesFromPoints.cpp
1
16
31
33
#include <iostream>
34
#include <fstream>
35
#include <sstream>
36
#include <exception>
37
#include "DGtal/base/Common.h"
38
#include "DGtal/kernel/PointVector.h"
39
#include "DGtal/shapes/fromPoints/CircleFrom3Points.h"
40
#include "DGtal/shapes/fromPoints/CircleFrom2Points.h"
41
42
#include "DGtal/io/boards/Board2D.h"
43
44
#include "ConfigTest.h"
45
47
48
using namespace
std
;
49
using namespace
DGtal
;
50
52
// testing Functions
54
59
template
<
typename
Coordinate>
60
bool
testCircleFrom3Points()
61
{
62
63
trace
.
beginBlock
(
"Simple test for CircleFrom3Points"
);
64
65
typedef
PointVector<2,Coordinate>
Point
;
66
CircleFrom3Points<Point>
c;
67
Point
o(0,0);
68
69
{
70
c.
init
(
Point
(0,1),
Point
(150,18),
Point
(250,-48) );
71
trace
.
info
() << c << endl;
72
trace
.
info
() << o <<
" is at distance "
<< c.
signedDistance
(o) << endl;
73
if
(c.
signedDistance
(o) != -4026300)
return
false
;
74
}
75
{
76
c.
init
(
Point
(0,1),
Point
(150,18),
Point
(100,48) );
77
trace
.
info
() << c << endl;
78
trace
.
info
() << o <<
" is at distance "
<< c.
signedDistance
(o) << endl;
79
if
(c.
signedDistance
(o) != 442200)
return
false
;
80
}
81
{
82
c.
init
(
Point
(8,4),
Point
(9,3),
Point
(10,0) );
83
trace
.
info
() << c << endl;
84
trace
.
info
() << o <<
" is at distance "
<< c.
signedDistance
(o) << endl;
85
if
(c.
signedDistance
(o) != 0)
return
false
;
86
double
cx, cy, r;
87
c.
getParameters
(cx, cy, r);
88
if
( (cx != 5.0)||(cy != 0.0) )
89
{
90
trace
.
emphase
() <<
"error in returned center"
<< endl;
91
trace
.
info
() <<
"("
<< cx <<
","
<< cy <<
") "
<< endl;
92
trace
.
info
() <<
"instead of (5,0)"
<< endl;
93
return
false
;
94
}
95
}
96
{
97
c.
init
(
Point
(0,0),
Point
(150,20),
Point
(15,2) );
98
trace
.
info
() << c << endl;
99
trace
.
info
() << o <<
" is at distance "
<< c.
signedDistance
(o) << endl;
100
if
(c.
signedDistance
(o) != 0)
return
false
;
101
}
102
103
Board2D
board;
104
board <<
SetMode
(o.className(),
"Grid"
) << o;
105
{
106
c.
init
(
Point
(8,4),
Point
(9,3),
Point
(10,0) );
107
trace
.
info
() <<
"arc drawing"
<< endl;
108
109
board <<
SetMode
( c.
className
(),
"Arc"
);
110
Display2DFactory::draw
(board, c,
Point
(5,10),
Point
(8,4));
111
112
board <<
SetMode
( c.
className
(),
"Sector"
);
113
Display2DFactory::draw
(board, c,
Point
(9,3),
Point
(10,0) );
114
115
board <<
SetMode
( c.
className
(),
"Annulus"
);
116
Display2DFactory::draw
(board, c,
Point
(5,-10),
Point
(2,-4) );
117
118
board.
saveEPS
(
"arcDisplay.eps"
);
119
}
120
121
122
trace
.
endBlock
();
123
124
return
true
;
125
}
126
127
template
<
typename
Coordinate>
128
bool
testCircleFrom2Points()
129
{
130
131
trace
.
beginBlock
(
"Simple test for CircleFrom2Points"
);
132
133
typedef
PointVector<2,Coordinate>
Point
;
134
Point
o(0,0);
135
Point
pole(0,1);
136
CircleFrom2Points<Point>
c( pole );
137
138
{
139
c.
init
(
Point
(15,2),
Point
(10,5) );
140
trace
.
info
() << c << endl;
141
trace
.
info
() << o <<
" is at distance "
<< c.
signedDistance
(o) << endl;
142
if
(c.
signedDistance
(o) != 470)
return
false
;
143
144
}
145
146
trace
.
endBlock
();
147
148
return
true
;
149
}
150
151
153
// Standard services - public :
154
155
int
main
(
int
argc,
char
** argv )
156
{
157
trace
.
beginBlock
(
"Testing shapes from points"
);
158
trace
.
info
() <<
"Args:"
;
159
for
(
int
i = 0; i < argc; ++i )
160
trace
.
info
() <<
" "
<< argv[ i ];
161
trace
.
info
() << endl;
162
163
164
bool
res = testCircleFrom3Points<int>()
165
&& testCircleFrom3Points<double>()
166
&& testCircleFrom3Points<BigInteger>()
167
&& testCircleFrom2Points<int>()
168
;
169
170
171
trace
.
emphase
() << ( res ?
"Passed."
:
"Error."
) << endl;
172
trace
.
endBlock
();
173
174
return
res ? 0 : 1;
175
}
176
// //
DGtal::Board2D
Aim: This class specializes a 'Board' class so as to display DGtal objects more naturally (with <<)....
Definition
Board2D.h:71
DGtal::CircleFrom2Points
Aim: Represents a circle that passes through a given point and that is thus uniquely defined by two o...
Definition
CircleFrom2Points.h:68
DGtal::CircleFrom3Points
Aim: Represents a circle uniquely defined by three 2D points and that is able to return for any given...
Definition
CircleFrom3Points.h:67
DGtal::CircleFrom3Points::getParameters
void getParameters(double &cx, double &cy, double &rr) const
DGtal::CircleFrom3Points::signedDistance
Distance signedDistance(const Point &aP) const
DGtal::CircleFrom3Points::className
std::string className() const
DGtal::CircleFrom3Points::init
void init(const Point &aFirstPoint, const Point &aSecondPoint, const Point &aThirdPoint)
DGtal::PointVector
Aim: Implements basic operations that will be used in Point and Vector classes.
Definition
PointVector.h:593
DGtal::Point
DGtal::Trace::beginBlock
void beginBlock(const std::string &keyword="")
DGtal::Trace::emphase
std::ostream & emphase()
DGtal::Trace::info
std::ostream & info()
DGtal::Trace::endBlock
double endBlock()
LibBoard::Board::saveEPS
void saveEPS(const char *filename, PageSize size=Board::BoundingBox, double margin=10.0) const
Definition
Board.cpp:804
DGtal
DGtal is the top-level namespace which contains all DGtal functions and types.
Definition
ClosedIntegerHalfPlane.h:49
DGtal::trace
Trace trace
std
STL namespace.
DGtal::Display2DFactory::draw
static void draw(DGtal::Board2D &board, const DGtal::DiscreteExteriorCalculus< dimEmbedded, dimAmbient, TLinearAlgebraBackend, TInteger > &calculus)
DGtal::SetMode::SetMode
SetMode(std::string classname, std::string mode)
Definition
Board2D.h:254
main
int main(int, char **)
Definition
testIntegerComputer.cpp:331
tests
shapes
testShapesFromPoints.cpp
Generated on
for DGtal by
1.18.0