DGtal 1.3.0
Loading...
Searching...
No Matches
arithmetic/pattern.cpp

Computes a pattern from a given slope p / q.

See also
Patterns
# Pattern 5 / 12
$ ./examples/arithmetic/pattern 5 12
00010010001001001

# Pattern 5 / 12 with its recursive subdivision
$ ./examples/arithmetic/pattern 5 12 SUB
((0|(00|1)(00|1))(0|(00|1)(00|1))|(00|1))
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <string>
#include "DGtal/arithmetic/LighterSternBrocot.h"
#include "DGtal/arithmetic/Pattern.h"
using namespace DGtal;
void usage( int, char** argv )
{
std::cerr << "Usage: " << argv[ 0 ] << " <p> <q> [SUB]" << std::endl;
std::cerr << "\t - computes the pattern of slope p / q and displays it." << std::endl;
std::cerr << "\t - the optional [SUB] parameter displays the pattern with its recursive Berstel decomposition." << std::endl;
}
int main( int argc, char** argv )
{
if ( argc < 3 )
{
usage( argc, argv );
return 1;
}
typedef DGtal::int32_t Quotient;
typedef LighterSternBrocot<Integer, Quotient, StdMapRebinder> SB; // the type of the Stern-Brocot tree
typedef SB::Fraction Fraction; // the type for fractions
typedef Pattern<Fraction> MyPattern; // the type for patterns
DGtal::int32_t p = atoi( argv[ 1 ] );
DGtal::int32_t q = atoi( argv[ 2 ] );
MyPattern pattern( p, q );
bool sub = ( argc > 3 ) && ( std::string( argv[ 3 ] ) == "SUB" );
std::cout << ( ! sub ? pattern.rE() : pattern.rEs( "(|)" ) ) << std::endl;
return 0;
}
Aim: The Stern-Brocot tree is the tree of irreducible fractions. This class allows to construct it pr...
Aim: This class represents a pattern, i.e. the path between two consecutive upper leaning points on a...
Definition: Pattern.h:79
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
int main()
Definition: testBits.cpp:56