DGtal  1.5.beta
testAngleLinearMinimizer.cpp File Reference
#include <iostream>
#include "DGtal/base/Common.h"
#include "DGtal/math/AngleLinearMinimizer.h"
#include "DGtal/io/boards/Board2D.h"
Include dependency graph for testAngleLinearMinimizer.cpp:

Go to the source code of this file.

Functions

bool testAngleLinearMinimizer ()
 
int main (int argc, char **argv)
 

Detailed Description

This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

Author
Bertrand Kerautret (kerau.nosp@m.tre@.nosp@m.loria.nosp@m..fr ) LORIA (CNRS, UMR 7503), University of Nancy, France
Date
2011/09/01

Functions for testing class AngleLinearMinimizer.

This file is part of the DGtal library.

Definition in file testAngleLinearMinimizer.cpp.

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 108 of file testAngleLinearMinimizer.cpp.

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 }
void beginBlock(const std::string &keyword="")
std::ostream & emphase()
std::ostream & info()
double endBlock()
Trace trace
Definition: Common.h:153
bool testAngleLinearMinimizer()

References DGtal::Trace::beginBlock(), DGtal::Trace::emphase(), DGtal::Trace::endBlock(), DGtal::Trace::info(), testAngleLinearMinimizer(), and DGtal::trace.

◆ testAngleLinearMinimizer()

bool testAngleLinearMinimizer ( )

Example of a test. To be completed.

[optimization]

[optimization]

Definition at line 47 of file testAngleLinearMinimizer.cpp.

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");
98  trace.endBlock();
99  return nbok == nb;
100 }
Aim: Used to minimize the angle variation between different angles while taking into accounts min and...
const ValueInfo & ro(unsigned int i) const
void setIsCurveOpen(bool is_curve_open=false)
void init(unsigned int nbMax)
ValueInfo & rw(unsigned int i)
Aim: This class specializes a 'Board' class so as to display DGtal objects more naturally (with <<)....
Definition: Board2D.h:71
void saveEPS(const char *filename, PageSize size=Board::BoundingBox, double margin=10.0) const
Definition: Board.cpp:804

References DGtal::Trace::beginBlock(), DGtal::AngleLinearMinimizer::ValueInfo::distToNext, DGtal::Trace::endBlock(), DGtal::Trace::info(), DGtal::AngleLinearMinimizer::init(), DGtal::AngleLinearMinimizer::ValueInfo::max, DGtal::AngleLinearMinimizer::ValueInfo::min, DGtal::AngleLinearMinimizer::ValueInfo::oldValue, DGtal::AngleLinearMinimizer::optimize(), DGtal::AngleLinearMinimizer::ro(), DGtal::AngleLinearMinimizer::rw(), LibBoard::Board::saveEPS(), DGtal::AngleLinearMinimizer::setIsCurveOpen(), DGtal::trace, and DGtal::AngleLinearMinimizer::ValueInfo::value.

Referenced by main().