DGtal
2.1.0
Loading...
Searching...
No Matches
testDGtalBigInteger.cpp
Go to the documentation of this file.
1
31
#include <iostream>
32
#include "DGtal/base/Common.h"
33
#include "DGtal/io/boards/Board2D.h"
34
#include "DGtal/kernel/SpaceND.h"
35
#include "DGtal/geometry/curves/ArithmeticalDSSComputer.h"
36
#include "DGtal/geometry/curves/FreemanChain.h"
37
#include "DGtal/geometry/curves/GreedySegmentation.h"
38
#include "DGtal/kernel/domains/HyperRectDomain.h"
39
#include "DGtal/images/ImageContainerBySTLVector.h"
40
42
43
using namespace
std
;
44
using namespace
DGtal
;
45
47
// Functions for testing class DGtalBIGINTEGER.
49
53
bool
testDGtalBIGINTEGER
()
54
{
55
unsigned
int
nbok = 0;
56
unsigned
int
nb = 0;
57
58
trace
.
beginBlock
(
"BIGINTEGER linking test..."
);
59
60
DGtal::BigInteger
a(1234);
61
DGtal::BigInteger
b(
"-5678"
);
62
DGtal::BigInteger
c = a + b;
63
64
trace
.
info
() <<
"sum is "
<< c <<
"\n"
;
65
trace
.
info
() <<
"absolute value is "
<< abs(c) <<
"\n"
;
66
67
nbok += (abs(c)==4444) ? 1 : 0;
68
nb++;
69
trace
.
info
() <<
"("
<< nbok <<
"/"
<< nb <<
") "
70
<<
"true == true"
<< std::endl;
71
trace
.
endBlock
();
72
73
return
nbok == nb;
74
}
75
76
81
bool
testBIGINTEGERSpace
()
82
{
83
unsigned
int
nbok = 0;
84
unsigned
int
nb = 0;
85
86
trace
.
beginBlock
(
"BIGINTEGER Space test..."
);
87
88
//This space is weird...
89
typedef
SpaceND<2, DGtal::BigInteger>
Space2;
90
typedef
Space2::Point
Point
;
91
typedef
Space2::Point::Coordinate Coordinate;
92
typedef
HyperRectDomain<Space2>
Domain
;
93
94
DGtal::BigInteger
a(1234);
95
DGtal::BigInteger
b(
"-5678"
);
96
Point
p(a,b);
97
98
typedef
FreemanChain<Coordinate>
Contour
;
99
100
// Construct the Freeman chain
101
std::stringstream ss(stringstream::in | stringstream::out);
102
ss <<
"31 16 11121212121212212121212212122122222322323233323333333323333323303330330030300000100010010010001000101010101111"
<< endl;
103
Contour
theContour( ss );
104
105
Point
p1( 0, 0 );
106
Point
p2( 31, 31 );
107
108
trace
.
info
() <<
"p2.norm()= "
<< p2.
norm
()<<endl;
109
110
Domain
domain
( p1, p2 );
111
Board2D
aBoard;
112
aBoard <<
SetMode
(
domain
.
className
(),
"Grid"
)
113
<<
domain
114
<< theContour;
115
116
aBoard.
saveSVG
(
"testbigintcontour.svg"
);
117
118
119
nbok +=
true
? 1 : 0;
120
nb++;
121
trace
.
info
() <<
"("
<< nbok <<
"/"
<< nb <<
") "
122
<<
"true == true"
<< std::endl;
123
trace
.
endBlock
();
124
125
return
nbok == nb;
126
}
127
129
// Standard services - public :
130
131
int
main
(
int
argc,
char
** argv )
132
{
133
trace
.
beginBlock
(
"Testing class DGtalBIGINTEGER"
);
134
trace
.
info
() <<
"Args:"
;
135
for
(
int
i = 0; i < argc; ++i )
136
trace
.
info
() <<
" "
<< argv[ i ];
137
trace
.
info
() << endl;
138
139
bool
res =
testDGtalBIGINTEGER
() &&
testBIGINTEGERSpace
();
// && ... other tests
140
trace
.
emphase
() << ( res ?
"Passed."
:
"Error."
) << endl;
141
trace
.
endBlock
();
142
return
res ? 0 : 1;
143
}
144
// //
DGtal::Board2D
Aim: This class specializes a 'Board' class so as to display DGtal objects more naturally (with <<)....
Definition
Board2D.h:71
DGtal::FreemanChain
Definition
FreemanChain.h:116
DGtal::HyperRectDomain
Aim: Parallelepidec region of a digital space, model of a 'CDomain'.
Definition
HyperRectDomain.h:100
DGtal::HyperRectDomain::className
std::string className() const
DGtal::SpaceND
Definition
SpaceND.h:96
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::saveSVG
void saveSVG(const char *filename, PageSize size=Board::BoundingBox, double margin=10.0) const
Definition
Board.cpp:1011
MyPointD
Definition
testClone2.cpp:346
MyPointD::norm
double norm() const
Definition
testClone2.cpp:361
DGtal
DGtal is the top-level namespace which contains all DGtal functions and types.
Definition
ClosedIntegerHalfPlane.h:49
DGtal::trace
Trace trace
DGtal::BigInteger
boost::multiprecision::number< boost::multiprecision::cpp_int_backend<>, boost::multiprecision::et_off > BigInteger
Definition
BasicTypes.h:75
std
STL namespace.
DGtal::SetMode
Modifier class in a Board2D stream. Useful to choose your own mode for a given class....
Definition
Board2D.h:247
main
int main()
Definition
testBits.cpp:56
Point
MyPointD Point
Definition
testClone2.cpp:381
Contour
FreemanChain< int > Contour
Definition
testCombinDSS.cpp:59
testDGtalBIGINTEGER
bool testDGtalBIGINTEGER()
Definition
testDGtalBigInteger.cpp:53
testBIGINTEGERSpace
bool testBIGINTEGERSpace()
Definition
testDGtalBigInteger.cpp:81
domain
Domain domain
Definition
testProjection.cpp:88
Domain
HyperRectDomain< Space > Domain
Definition
testSimpleRandomAccessRangeFromPoint.cpp:44
tests
kernel
testDGtalBigInteger.cpp
Generated on Tue Aug 26 2025 14:28:23 for DGtal by
1.9.8