DGtal  0.9.3beta
pattern.cpp
1 
14 #include <cstdlib>
17 #include <cmath>
18 #include <iostream>
19 #include <iomanip>
20 #include <string>
21 #include "DGtal/arithmetic/LighterSternBrocot.h"
22 #include "DGtal/arithmetic/Pattern.h"
24 
26 
27 using namespace DGtal;
28 
30 
31 void usage( int, char** argv )
32 {
33  std::cerr << "Usage: " << argv[ 0 ] << " <p> <q> [SUB]" << std::endl;
34  std::cerr << "\t - computes the pattern of slope p / q and displays it." << std::endl;
35  std::cerr << "\t - the optional [SUB] parameter displays the pattern with its recursive Berstel decomposition." << std::endl;
36 }
37 
41 int main( int argc, char** argv )
42 {
43  if ( argc < 3 )
44  {
45  usage( argc, argv );
46  return 1;
47  }
48 
50  typedef DGtal::int32_t Integer;
51  typedef DGtal::int32_t Quotient;
52  typedef LighterSternBrocot<Integer, Quotient, StdMapRebinder> SB; // the type of the Stern-Brocot tree
53  typedef SB::Fraction Fraction; // the type for fractions
54  typedef Pattern<Fraction> MyPattern; // the type for patterns
56 
58  DGtal::int32_t p = atoi( argv[ 1 ] );
59  DGtal::int32_t q = atoi( argv[ 2 ] );
60  MyPattern pattern( p, q );
62 
64  bool sub = ( argc > 3 ) && ( std::string( argv[ 3 ] ) == "SUB" );
65  std::cout << ( ! sub ? pattern.rE() : pattern.rEs( "(|)" ) ) << std::endl;
67  return 0;
68 }
69 
DGtal::int32_t Integer
Definition: StdDefs.h:74
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
Aim: The Stern-Brocot tree is the tree of irreducible fractions. This class allows to construct it pr...