DGtal  0.6.devel
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
testDGtalGMP.cpp
1 
30 
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/ArithmeticalDSS.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, b, c;
61 
62  a = 1234;
63  b = "-5678";
64  c = a+b;
65  trace.info() << "sum is " << c << "\n";
66  trace.info() << "absolute value is " << abs(c) << "\n";
67 
68  nbok += (abs(c)==4444) ? 1 : 0;
69  nb++;
70  trace.info() << "(" << nbok << "/" << nb << ") "
71  << "true == true" << std::endl;
72  trace.endBlock();
73 
74  return nbok == nb;
75 }
76 
77 
82 bool testBIGINTEGERSpace()
83 {
84  unsigned int nbok = 0;
85  unsigned int nb = 0;
86 
87  trace.beginBlock ( "BIGINTEGER Space test..." );
88 
89  //This space is weird...
90  typedef SpaceND<2, DGtal::BigInteger> Space2;
91  typedef Space2::Point Point;
92  typedef Space2::Point::Coordinate Coordinate;
94 
95  DGtal::BigInteger a, b, c;
96 
97  a = 1234;
98  b = "-5678";
99  Point p(a,b);
100 
103  typedef GreedySegmentation<DSS4> Decomposition;
104 
105  // Construct the Freeman chain
106  std::stringstream ss(stringstream::in | stringstream::out);
107  ss << "31 16 11121212121212212121212212122122222322323233323333333323333323303330330030300000100010010010001000101010101111" << endl;
108  Contour theContour( ss );
109  //Segmentation
110  Decomposition theDecomposition( theContour.begin(),theContour.end(),DSS4() );
111  Decomposition::SegmentComputerIterator i = theDecomposition.begin();
112  DSS4 segment(*i);
113 
114  Point p1( 0, 0 );
115  Point p2( 31, 31 );
116 
117  trace.info() <<"p2.norm()= "<< p2.norm()<<endl;
118 
119  Domain domain( p1, p2 );
120  Board2D aBoard;
121  aBoard << SetMode( domain.className(), "Grid" )
122  << domain
123  << theContour
124  << segment;
125 
126  aBoard.saveSVG("testgmpcontour.svg");
127 
128 
129  nbok += true ? 1 : 0;
130  nb++;
131  trace.info() << "(" << nbok << "/" << nb << ") "
132  << "true == true" << std::endl;
133  trace.endBlock();
134 
135  return nbok == nb;
136 }
137 
139 // Standard services - public :
140 
141 int main( int argc, char** argv )
142 {
143  trace.beginBlock ( "Testing class DGtalBIGINTEGER" );
144  trace.info() << "Args:";
145  for ( int i = 0; i < argc; ++i )
146  trace.info() << " " << argv[ i ];
147  trace.info() << endl;
148 
149  bool res = testDGtalBIGINTEGER() && testBIGINTEGERSpace(); // && ... other tests
150  trace.emphase() << ( res ? "Passed." : "Error." ) << endl;
151  trace.endBlock();
152  return res ? 0 : 1;
153 }
154 // //