Skip to content
2 changes: 1 addition & 1 deletion pyTest/testBrowse.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def testBrowse():
if item.getType() == sequenceParser.eTypeSequence:
seq = item.getSequence()
print("item seq:", seq.getFirstFilename())
print("item seq:", seq.getFirstTime(), seq.getLastTime(), seq.getDuration(), seq.getStandardPattern())
print("item seq:", seq.getFirstTime(), seq.getLastTime(), seq.getDuration(), seq.getFilenameWithStandardPattern())
for f in seq.getFramesIterable():
print("file:", seq.getFilenameAt(f))

4 changes: 2 additions & 2 deletions src/Item.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,15 @@ class Item
, _path(folder)
, _sequence(sequence)
{
_path /= sequence.getStandardPattern();
_path /= sequence.getFilenameWithStandardPattern();
}

Item( const Sequence& sequence, const std::string& folder )
: _type(eTypeSequence)
, _path(folder)
, _sequence(sequence)
{
_path /= sequence.getStandardPattern();
_path /= sequence.getFilenameWithStandardPattern();
}

EType getType() const { return _type; }
Expand Down
88 changes: 23 additions & 65 deletions src/Sequence.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ std::size_t extractStep( const std::vector<detail::FileNumbers>::const_iterator&
}


std::size_t getPaddingFromStringNumber( const std::string& timeStr )
std::size_t getFixedPaddingFromStringNumber( const std::string& timeStr )
{
if( timeStr.size() > 1 )
{
Expand All @@ -144,11 +144,11 @@ std::size_t getPaddingFromStringNumber( const std::string& timeStr )
std::size_t extractPadding( const std::vector<std::string>& timesStr )
{
BOOST_ASSERT( timesStr.size() > 0 );
const std::size_t padding = getPaddingFromStringNumber( timesStr.front() );
const std::size_t padding = getFixedPaddingFromStringNumber( timesStr.front() );

BOOST_FOREACH( const std::string& s, timesStr )
{
if( padding != getPaddingFromStringNumber( s ) )
if( padding != getFixedPaddingFromStringNumber( s ) )
{
return 0;
}
Expand All @@ -162,14 +162,14 @@ std::size_t extractPadding( const std::vector<detail::FileNumbers>::const_iterat
BOOST_ASSERT( timesBegin != timesEnd );

std::set<std::size_t> padding;
std::set<std::size_t> nbDigits;
std::set<std::size_t> maxPadding;

for( std::vector<detail::FileNumbers>::const_iterator s = timesBegin;
s != timesEnd;
++s )
{
padding.insert( s->getPadding(i) );
nbDigits.insert( s->getNbDigits(i) );
padding.insert( s->getFixedPadding(i) );
maxPadding.insert( s->getMaxPadding(i) );
}

std::set<std::size_t> pad = padding;
Expand All @@ -189,69 +189,27 @@ std::size_t extractPadding( const std::vector<detail::FileNumbers>::const_iterat
return 0;
}


/**
* @brief return if the padding is strict (at least one frame begins with a '0' padding character).
* @param[in] timesStr vector of frame numbers in string format
* @param[in] padding previously detected padding
*/
bool extractIsStrictPadding( const std::vector<std::string>& timesStr, const std::size_t padding )
{
if( padding == 0 )
{
return false;
}

BOOST_FOREACH( const std::string& s, timesStr )
{
if( s[0] == '0' )
{
return true;
}
}
return false;
}


bool extractIsStrictPadding( const std::vector<detail::FileNumbers>& times, const std::size_t i, const std::size_t padding )
{
if( padding == 0 )
{
return false;
}

BOOST_FOREACH( const detail::FileNumbers& s, times )
{
if( s.getString( i )[0] == '0' )
{
return true;
}
}
return false;
}


std::string Sequence::getFilenameAt( const Time time ) const
{
std::ostringstream o;
if( time >= 0 )
{
// "prefix.0001.jpg"
o << _prefix << std::setw( _padding ) << std::setfill( _fillCar ) << time << _suffix;
o << _prefix << std::setw( _fixedPadding ) << std::setfill( _fillCar ) << time << _suffix;
}
else
{
// "prefix.-0001.jpg" (and not "prefix.000-1.jpg")
o << _prefix << "-" << std::setw( _padding ) << std::setfill( _fillCar ) << std::abs( (int) time ) << _suffix;
o << _prefix << "-" << std::setw( _fixedPadding ) << std::setfill( _fillCar ) << std::abs( (int) time ) << _suffix;
}
return o.str();
}


std::string Sequence::getCStylePattern() const
{
if( getPadding() )
return getPrefix() + "%0" + boost::lexical_cast<std::string > ( getPadding() ) + "d" + getSuffix();
if( getFixedPadding() )
return getPrefix() + "%0" + boost::lexical_cast<std::string > ( getFixedPadding() ) + "d" + getSuffix();
else
return getPrefix() + "%d" + getSuffix();
}
Expand Down Expand Up @@ -322,32 +280,32 @@ EPattern Sequence::checkPattern( const std::string& pattern, const EDetection de
bool Sequence::initFromPattern( const std::string& filePattern, const EPattern& accept )
{
boost::cmatch matches;
//std::cout << filePattern << " / " << _prefix << " + " << _padding << " + " << _suffix << std::endl;
//std::cout << filePattern << " / " << _prefix << " + " << _fixedPadding << " + " << _suffix << std::endl;
if( ( accept & ePatternStandard ) && regex_match( filePattern.c_str(), matches, regexPatternStandard ) )
{
std::string paddingStr( matches[2].first, matches[2].second );
_padding = paddingStr.size();
_strictPadding = ( paddingStr[0] == '#' );
_fixedPadding = paddingStr.size();
_maxPadding = _fixedPadding;
}
else if( ( accept & ePatternCStyle ) && regex_match( filePattern.c_str(), matches, regexPatternCStyle ) )
{
std::string paddingStr( matches[2].first, matches[2].second );
_padding = paddingStr.size() == 0 ? 0 : boost::lexical_cast<std::size_t > ( paddingStr ); // if no _padding value: %d -> _padding = 0
_strictPadding = false;
_fixedPadding = paddingStr.size() == 0 ? 0 : boost::lexical_cast<std::size_t > ( paddingStr ); // if no padding value: %d -> _fixedPadding = 0
_maxPadding = _fixedPadding;
}
else if( ( accept & ePatternFrame ) && regex_match( filePattern.c_str(), matches, regexPatternFrame ) )
{
std::string frame( matches[2].first, matches[2].second );
// Time t = boost::lexical_cast<Time>( frame );
_padding = frame.size();
_strictPadding = false;
_fixedPadding = frame.size();
_maxPadding = _fixedPadding;
}
else if( ( accept & ePatternFrameNeg ) && regex_match( filePattern.c_str(), matches, regexPatternFrameNeg ) )
{
std::string frame( matches[2].first, matches[2].second );
// Time t = boost::lexical_cast<Time>( frame );
_padding = frame.size();
_strictPadding = false;
_fixedPadding = frame.size();
_maxPadding = _fixedPadding;
}
else
{
Expand All @@ -360,14 +318,14 @@ bool Sequence::initFromPattern( const std::string& filePattern, const EPattern&
}


void Sequence::init( const std::string& prefix, const std::size_t padding, const std::string& suffix, const Time firstTime, const Time lastTime, const Time step, const bool strictPadding )
void Sequence::init( const std::string& prefix, const std::size_t padding, const std::size_t maxPadding, const std::string& suffix, const Time firstTime, const Time lastTime, const Time step )
{
_prefix = prefix;
_padding = padding;
_fixedPadding = padding;
_maxPadding = maxPadding;
_suffix = suffix;
_ranges.clear();
_ranges.push_back(FrameRange(firstTime, lastTime, step));
_strictPadding = strictPadding;
}

std::vector<boost::filesystem::path> Sequence::getFiles() const
Expand Down Expand Up @@ -404,7 +362,7 @@ std::string Sequence::string() const

std::ostream& operator<<(std::ostream& os, const Sequence& sequence)
{
os << sequence.getStandardPattern() << " [" << sequence.getFrameRanges() << "]";
os << sequence.getFilenameWithStandardPattern() << " [" << sequence.getFrameRanges() << "]";
return os;
}

Expand Down
63 changes: 39 additions & 24 deletions src/Sequence.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#include "common.hpp"
#include "FrameRange.hpp"

#include <boost/lexical_cast.hpp>

#include <iomanip>
#include <set>

Expand Down Expand Up @@ -41,9 +43,9 @@ class Sequence
clear();
}

Sequence( const std::string& prefix, const std::size_t padding, const std::string& suffix, const Time firstTime, const Time lastTime, const Time step = 1, const bool strictPadding = false )
Sequence( const std::string& prefix, const std::size_t padding, const size_t maxPadding, const std::string& suffix, const Time firstTime, const Time lastTime, const Time step = 1 )
{
init( prefix, padding, suffix, firstTime, lastTime, step, strictPadding );
init( prefix, padding, maxPadding, suffix, firstTime, lastTime, step );
}

Sequence( const std::string& pattern, const std::vector<FrameRange>& frameRanges, const EPattern accept = ePatternDefault )
Expand All @@ -68,8 +70,8 @@ class Sequence
{
_prefix = other._prefix;
_suffix = other._suffix;
_strictPadding = other._strictPadding;
_padding = other._padding;
_maxPadding = other._maxPadding;
_fixedPadding = other._fixedPadding;
_ranges = other._ranges;
return *this;
}
Expand All @@ -81,7 +83,7 @@ class Sequence
* @brief Construct a sequence from a pattern and given informations.
* @warning No check on your filesystem.
*/
void init( const std::string& prefix, const std::size_t padding, const std::string& suffix, const Time firstTime, const Time lastTime, const Time step = 1, const bool strictPadding = false );
void init( const std::string& prefix, const std::size_t padding, const size_t maxPadding, const std::string& suffix, const Time firstTime, const Time lastTime, const Time step = 1 );

public:
std::string getFilenameAt( const Time time ) const;
Expand All @@ -92,7 +94,10 @@ class Sequence
inline char getPatternCharacter() const;

/// @return a string pattern using standard style
inline std::string getStandardPattern() const;
inline std::string getFilenameWithStandardPattern() const;

/// @return a string pattern using printf style
inline std::string getFilenameWithPrintfPattern() const;

/// @return a string pattern using C Style
std::string getCStylePattern() const;
Expand All @@ -107,9 +112,9 @@ class Sequence

Time getNbFiles() const;

inline std::size_t getPadding() const;
inline std::size_t getFixedPadding() const;

inline bool isStrictPadding() const;
inline std::size_t getMaxPadding() const;

inline bool hasMissingFile() const;

Expand All @@ -135,15 +140,16 @@ class Sequence

bool operator<(const Sequence& other ) const
{
return getStandardPattern() < other.getStandardPattern();
return getFilenameWithStandardPattern() < other.getFilenameWithStandardPattern();
}

bool operator==(const Sequence& other ) const
{
return
( _prefix == other._prefix ) &&
( _suffix == other._suffix ) &&
( _padding == other._padding ) &&
( _maxPadding == other._maxPadding ) &&
( _fixedPadding == other._fixedPadding ) &&
( _ranges == other._ranges );
}

Expand Down Expand Up @@ -183,8 +189,8 @@ class Sequence
{
_prefix.clear();
_suffix.clear();
_strictPadding = false;
_padding = 0;
_maxPadding = 0;
_fixedPadding = 0;
_ranges.clear();
}

Expand All @@ -193,8 +199,26 @@ class Sequence
public:
std::string _prefix; ///< filename prefix
std::string _suffix; ///< filename suffix
bool _strictPadding; ///<
std::size_t _padding; ///< padding, no padding if 0, fixed padding otherwise
/**
* @brief Number max of common padding used to enumerate the sequence
* @note For fixed sequences, it is equal to the padding
* @note Useful for sequence with a variable or an unknown padding
* unknown padding = when no frame begins with a '0' padding character
* seq.101.jpg
* seq.102.jpg
* seq.102.jpg
* variable padding = when not all frames have the same padding
* seq.0101.jpg
* seq.0100.jpg
* seq.099.jpg
*/
std::size_t _maxPadding;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe better to have min/max padding.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed it could be great to have the two info.. For an other release...? =D

/**
* @brief Fixed padding
* @note if 0, variable padding
* @see _maxPadding
*/
std::size_t _fixedPadding;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add an example for the ambiguous case.

std::vector<FrameRange> _ranges;
static const char _fillCar = '0'; ///< Filling character
};
Expand All @@ -213,7 +237,7 @@ std::size_t extractStep( const std::vector<Time>& times );
*/
std::size_t extractStep( const std::vector<detail::FileNumbers>::const_iterator& timesBegin, const std::vector<detail::FileNumbers>::const_iterator& timesEnd, const std::size_t i );

std::size_t getPaddingFromStringNumber( const std::string& timeStr );
std::size_t getFixedPaddingFromStringNumber( const std::string& timeStr );

/**
* @brief extract the padding from a vector of frame numbers
Expand All @@ -223,15 +247,6 @@ std::size_t extractPadding( const std::vector<std::string>& timesStr );

std::size_t extractPadding( const std::vector<detail::FileNumbers>::const_iterator& timesBegin, const std::vector<detail::FileNumbers>::const_iterator& timesEnd, const std::size_t i );

/**
* @brief return if the padding is strict (at least one frame begins with a '0' padding character).
* @param[in] timesStr vector of frame numbers in string format
* @param[in] padding previously detected padding
*/
bool extractIsStrictPadding( const std::vector<std::string>& timesStr, const std::size_t padding );

bool extractIsStrictPadding( const std::vector<detail::FileNumbers>& times, const std::size_t i, const std::size_t padding );

#endif

#include <Sequence.tcc>
Expand Down
Loading