DGtal  1.2.0
pattern.cpp
Go to the documentation of this file.
1 
34 #include <cstdlib>
35 #include <cmath>
36 #include <iostream>
37 #include <iomanip>
38 #include <string>
39 #include "DGtal/arithmetic/LighterSternBrocot.h"
40 #include "DGtal/arithmetic/Pattern.h"
42 
44 
45 using namespace DGtal;
46 
48 
49 void usage( int, char** argv )
50 {
51  std::cerr << "Usage: " << argv[ 0 ] << " <p> <q> [SUB]" << std::endl;
52  std::cerr << "\t - computes the pattern of slope p / q and displays it." << std::endl;
53  std::cerr << "\t - the optional [SUB] parameter displays the pattern with its recursive Berstel decomposition." << std::endl;
54 }
55 
59 int main( int argc, char** argv )
60 {
61  if ( argc < 3 )
62  {
63  usage( argc, argv );
64  return 1;
65  }
66 
68  typedef DGtal::int32_t Integer;
69  typedef DGtal::int32_t Quotient;
70  typedef LighterSternBrocot<Integer, Quotient, StdMapRebinder> SB; // the type of the Stern-Brocot tree
71  typedef SB::Fraction Fraction; // the type for fractions
72  typedef Pattern<Fraction> MyPattern; // the type for patterns
74 
76  DGtal::int32_t p = atoi( argv[ 1 ] );
77  DGtal::int32_t q = atoi( argv[ 2 ] );
78  MyPattern pattern( p, q );
80 
82  bool sub = ( argc > 3 ) && ( std::string( argv[ 3 ] ) == "SUB" );
83  std::cout << ( ! sub ? pattern.rE() : pattern.rEs( "(|)" ) ) << std::endl;
85  return 0;
86 }
87 
Aim: The Stern-Brocot tree is the tree of irreducible fractions. This class allows to construct it pr...
DGtal is the top-level namespace which contains all DGtal functions and types.
boost::int32_t int32_t
signed 32-bit integer.
Definition: BasicTypes.h:72
void usage(int, char **argv)
Definition: pattern.cpp:49
int main(int argc, char **argv)
Definition: pattern.cpp:59