template<typename TFraction>
class DGtal::Pattern< TFraction >
Aim: This class represents a pattern, i.e. the path between two consecutive upper leaning points on a digital straight line.
Description of template class 'Pattern'
A pattern is characterized by an irreducible fraction. The choice here is to use SternBrocot::Fraction so as to compute efficiently subpatterns.
- Parameters:
-
- Note:
- LighterSternBrocot::Fraction takes much less memory than SternBrocot::Fraction and is more efficient for large integers. It is 10% slower than SternBrocot::Fraction for small integers (<1000).
- See also:
- dgtal_digstraighness_sec2
Definition at line 78 of file Pattern.h.
template<typename TFraction>
Computes the greatest subpattern that is included in the segment [A,B], a subpart of the pattern. Points A and B are defined by their position with respect to the beginning of this pattern. The subpattern has a starting position startPos and may be repeated nb times.
- Parameters:
-
subpattern | (returns) the subpattern (a pattern that is some ascendant of 'this' in the Stern-Brocot tree). |
nb | (returns) the number of times subpattern is repeated so as to be included in [A,B] |
startPos | (returns) the starting position of the subpattern in this pattern. |
posA | the position of A (number of steps till A). |
posB | the position of B (number of steps till B), > posA. |
- Returns:
- 'true' iff the subpattern is not null.
Definition at line 369 of file Pattern.ih.
References DGtal::NumberTraits< T >::castToInt64_t(), DGtal::Pattern< TFraction >::length(), and DGtal::Pattern< TFraction >::v().
Referenced by DGtal::StandardDSLQ0< TFraction >::DSSWithinTwoPatterns().
{
bool null_pattern = false;
ASSERT( ( 0 <= posA ) && ( posA < posB ) && ( posB <= l ) );
{
ASSERT( posA == 0 && posB == 1 );
subpattern = *this;
nb = 1;
null_pattern = false;
}
else if ( reversed ?
slope().even() :
slope().odd() )
{
Integer k1 = ( posA + prevL - 1 ) / prevL;
if ( posB == l )
{
if ( posA >
slope().u() * prevL )
{
nb = 0;
null_pattern = true;
}
else
{
( NumberTraits<Quotient>::castToInt64_t(
slope().u() )
nb = 1;
startPos = prevP.v() * k1;
null_pattern = false;
}
}
else
{
if ( nb < 0 ) nb = 0;
subpattern = nb == 0 ?
Pattern() : prevP;
startPos = prevP.v() * k1;
null_pattern = nb == 0;
}
}
else
{
Integer k1 = ( l - posB + prevL - 1 ) / prevL;
if ( posA == 0 )
{
if ( ( l - posB ) >
slope().u() * prevL )
{
nb = 0;
null_pattern = true;
}
else
{
( NumberTraits<Quotient>::castToInt64_t(
slope().u() )
nb = 1;
null_pattern = false;
}
}
else
{
if ( nb < 0 ) nb = 0;
subpattern = nb == 0 ?
Pattern() : prevP;
startPos =
v() - prevP.v() * k2;
null_pattern = nb == 0;
}
}
return ! null_pattern;
}
template<typename TFraction>
Computes the smallest subpattern that contains the segment [A,B] included in the pattern. Points A and B are defined by their position with respect to the beginning of this pattern. The subpattern has a starting position startPos and may be repeated nb times.
- Parameters:
-
subpattern | (returns) the subpattern (a pattern that is some ascendant of 'this' in the Stern-Brocot tree). |
nb | (returns) the number of times subpattern is repeated so as to cover [A,B] |
startPos | (returns) the starting position of the subpattern in this pattern. |
posA | the position of A (number of steps till A). |
posB | the position of B (number of steps till B), > posA. |
reversed | when 'false' assume a usual pattern, otherwise assume a reversed pattern (i.e. a path between two lower leaning points). In this case, all positions are relative to the first lower leaning point L(0). Everything returned correspond to reversed pattern(s). |
- Returns:
- 'true' iff the subpattern is different from 'this'.
Definition at line 282 of file Pattern.ih.
References DGtal::NumberTraits< T >::castToInt64_t(), DGtal::Pattern< TFraction >::length(), and DGtal::Pattern< TFraction >::v().
Referenced by DGtal::StandardDSLQ0< TFraction >::DSSWithinTwoPatterns(), and DGtal::StandardDSLQ0< TFraction >::reversedSmartDSS().
{
bool different = false;
ASSERT( ( 0 <= posA ) && ( posA < posB ) && ( posB <= l ) );
{
ASSERT( posA == 0 && posB == 1 );
subpattern = *this;
nb = 1;
different = false;
}
else if ( reversed ?
slope().even() :
slope().odd() )
{
if ( posB >
slope().u() * prevL )
{
( NumberTraits<Quotient>::castToInt64_t(
slope().u() )
nb = 1;
startPos = prevP.v() * k1;
different = k1 != 0;
}
else
{
Integer k2 = ( posB + prevL - 1 ) / prevL;
ASSERT( nb > 0 );
subpattern = prevP;
startPos = prevP.v() * k1;
different = true;
}
}
else
{
if ( ( l - posA ) >
slope().u() * prevL )
{
( NumberTraits<Quotient>::castToInt64_t(
slope().u() )
nb = 1;
different = k1 != 0;
}
else
{
Integer k2 = ( l - posA + prevL - 1 ) / prevL;
ASSERT( nb > 0 );
subpattern = prevP;
startPos =
v() - prevP.v() * k2;
different = true;
}
}
return different;
}
template<typename TFraction >
std::string DGtal::Pattern< TFraction >::rEs |
( |
const std::string & |
seps = "(|)" | ) |
const |
|
inline |
The recursive mapping E, which gives the corresponding Christoffel word in {0,1}, but also shows the Berstel splits with "(|)".
- Parameters:
-
seps | the three separators. |
Definition at line 125 of file Pattern.ih.
References DGtal::Pattern< TFraction >::rEs().
Referenced by DGtal::Pattern< TFraction >::rEs().
{
if (
mySlope.null() )
return "eps";
{
return "0";
}
else if (
mySlope.k() == -NumberTraits<Quotient>::ONE )
{
return "1";
}
else if (
mySlope.k() == NumberTraits<Quotient>::ZERO )
{
std::string s( NumberTraits<Quotient>::castToInt64_t(
mySlope.p() ),
'1' );
return '0' + s;
}
else
{
mySlope.getSplitBerstel( f1, nb1, f2, nb2 );
std::string s( 1, seps[ 0 ] );
for (
Quotient i = 0; i < nb1; ++i ) s += p1.rEs( seps );
s += seps[ 1 ];
for (
Quotient i = 0; i < nb2; ++i ) s += p2.rEs( seps );
s += seps[ 2 ];
return s;
}
}