DGtal 1.3.0
Searching...
No Matches
testShapesFromPoints.cpp
1
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
48using namespace std;
49using namespace DGtal;
50
52// testing Functions
54
59template <typename Coordinate>
60bool testCircleFrom3Points()
61{
62
63 trace.beginBlock("Simple test for CircleFrom3Points");
64
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
127template <typename Coordinate>
128bool testCircleFrom2Points()
129{
130
131 trace.beginBlock("Simple test for CircleFrom2Points");
132
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
155int 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#ifdef WITH_BIGINTEGER
167 && testCircleFrom3Points<BigInteger>()
168#endif
169 && testCircleFrom2Points<int>()
170;
171
172
173 trace.emphase() << ( res ? "Passed." : "Error." ) << endl;
174 trace.endBlock();
175
176 return res ? 0 : 1;
177}
178// //
Aim: This class specializes a 'Board' class so as to display DGtal objects more naturally (with <<)....
Definition: Board2D.h:71
Aim: Represents a circle that passes through a given point and that is thus uniquely defined by two o...
Aim: Represents a circle uniquely defined by three 2D points and that is able to return for any given...
Aim: Implements basic operations that will be used in Point and Vector classes.
Definition: PointVector.h:593
void beginBlock(const std::string &keyword="")
std::ostream & emphase()
std::ostream & info()
double endBlock()
void saveEPS(const char *filename, PageSize size=Board::BoundingBox, double margin=10.0) const
Definition: Board.cpp:805
DGtal is the top-level namespace which contains all DGtal functions and types.
Trace trace
Definition: Common.h:154
STL namespace.
static void draw(DGtal::Board2D &board, const DGtal::DiscreteExteriorCalculus< dimEmbedded, dimAmbient, TLinearAlgebraBackend, TInteger > &calculus)
Modifier class in a Board2D stream. Useful to choose your own mode for a given class....
Definition: Board2D.h:247
int main()
Definition: testBits.cpp:56
MyPointD Point
Definition: testClone2.cpp:383