DGtal 1.3.0
Loading...
Searching...
No Matches
testAngleLinearMinimizer.cpp
Go to the documentation of this file.
1
31#include <iostream>
32#include "DGtal/base/Common.h"
33#include "DGtal/math/AngleLinearMinimizer.h"
34#include "DGtal/io/boards/Board2D.h"
36
37using namespace std;
38using namespace DGtal;
39
41// Functions for testing class AngleLinearMinimizer.
43
48{
49 unsigned int nbok = 0;
50 unsigned int nb = 0;
51
52 trace.beginBlock ( "Testing AngleLinearMinimizer ." );
53
55 alm.init(10);
56 alm.setIsCurveOpen(true);
57 double valDec [10] = {0.8, 0.3, -0.2, -0.2, -0.1, -0.3, -3.0, -6.0, -7.0, -8.0};
58 double valDecMin [10] = {-0.5, -0.2, -0.5, -0.2, -0.1, -1.0, -1.2, -0.5, -0.3, -0.2};
59 double valDecMax [10] = {0.9, 0.3, 0.2, 1.2, 0.4, 1.0, 0.5, 0.2, 0.1, 0.3};
60
61 for(unsigned int i=0; i<10; i++){
63 double val = i + valDec[i];
64 vi.value = val;
65 vi.oldValue = val;
66 vi.min = val + valDecMin[i];
67 vi.max = val + valDecMax[i];
68 vi.distToNext = 4.0;
69 alm.rw(i)=vi;
70 }
72 double delta= alm.optimize();
73 double aPrecision=0.00001;
74 while(delta >aPrecision){
75 delta= alm.optimize();
76 cerr << "sum of displacements " << delta << endl;
77 }
79 cout << "# index distPos valInit valOpt valMin valMax " << endl;
80 double currentPos=0.0;
81 cout << -1 << " "<< -4 << " " << 9+valDec[9] << " " << alm.ro(9).value
82 << " " << alm.ro(9).min << " " << alm.ro(9).max << endl ;
83
84 for(unsigned int i=0; i<10; i++){
86 cout << i << " "<< currentPos << " " << i+ valDec[i] << " " << vi.value
87 << " " << vi.min << " " << vi.max << endl ;
88 currentPos+=vi.distToNext;
89 }
90 nbok += (abs(1.59999-alm.ro(0).value)<0.00001) && (abs(1.6-alm.ro(1).value)<0.00001) ? 1 : 0;
91 nb++;
92 trace.info() << "(" << nbok << "/" << nb << ") "
93 << "true == true" << std::endl;
94
95 Board2D aBoard;
96 aBoard << alm;
97 aBoard.saveEPS("tmp.eps");
99 return nbok == nb;
100}
101
102
103
104
106// Standard services - public :
107
108int main( int argc, char** argv )
109{
110 trace.beginBlock ( "Testing class AngleLinearMinimizer" );
111 trace.info() << "Args:";
112 for ( int i = 0; i < argc; ++i )
113 trace.info() << " " << argv[ i ];
114 trace.info() << endl;
115
116 bool res = testAngleLinearMinimizer(); // && ... other tests
117 trace.emphase() << ( res ? "Passed." : "Error." ) << endl;
118 trace.endBlock();
119 return res ? 0 : 1;
120}
121// //
Aim: Used to minimize the angle variation between different angles while taking into accounts min and...
ValueInfo & rw(unsigned int i)
void setIsCurveOpen(bool is_curve_open=false)
void init(unsigned int nbMax)
const ValueInfo & ro(unsigned int i) const
Aim: This class specializes a 'Board' class so as to display DGtal objects more naturally (with <<)....
Definition: Board2D.h:71
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.
bool testAngleLinearMinimizer()
int main()
Definition: testBits.cpp:56