/** 
* @file LFWriteCache.h
* @brief Write local features to file (whenever a descriptor is computed, it will be checked whether a corresponding file already exists. If not, we save the descriptor)
* @author Erik Rodner, Alexander Freytag
* @date 02/14/2008

*/
#ifndef LFWriteCacheINCLUDE
#define LFWriteCacheINCLUDE

#include "core/vector/VectorT.h"
#include "core/vector/MatrixT.h"
#include "core/image/ImageT.h"
 
#include "LocalFeatureRepresentation.h"
#include "core/basics/Config.h"


namespace OBJREC {

/** @class LFWriteCache
* @brief Write local features to file (whenever a descriptor is computed, it will be checked whether a corresponding file already exists. If not, we save the descriptor)
*
*/  
class LFWriteCache : public LocalFeatureRepresentation
{

  protected:
    
    LocalFeatureRepresentation *lfrep;

    std::string cachedir;

    int descFormat;
    
    int cachemode;
    
    void setDescFormat ( const std::string & _descFormat_s );    


  public:
    
    ///////////////////// ///////////////////// /////////////////////
    //                   CONSTRUCTORS / DESTRUCTORS
    ///////////////////// ///////////////////// /////////////////////
    
    /**     
     * @brief default constructor
     * @date 10-02-2014 (dd-mm-yyyy )
     * @author Alexander Freytag
     */
    LFWriteCache ( );
    
    /** 
     * @brief standard constructor 
     * @date 10-02-2014 (dd-mm-yyyy )
     * @author Alexander Freytag
     * @param conf Configuration
     * @param _section specify the block in the config object we read 
     */
    LFWriteCache( const NICE::Config * _conf, 
          const std::string & _confSection = "LFWriteCache" /*NOTE previous default: "cache"*/          
              );       
  
    /** simple constructor */
    LFWriteCache( const NICE::Config *conf, 
        LocalFeatureRepresentation *lfrep,
        const std::string & _section = "cache"
                ); 
    
    /** simple destructor */
    virtual ~LFWriteCache();
    
    /** 
     * @brief Jobs previously performed in the config-version of the constructor, read settings etc.
     * @author Alexander Freytag
     * @date 10-02-2014 ( dd-mm-yyyy )
     */    
    void initFromConfig ( const NICE::Config * _conf, const std::string & _confSection = "LFWriteCache");     
    
    ///////////////////// ///////////////////// /////////////////////
    //                      FEATURE STUFF
    ///////////////////// ///////////////////// //////////////////       
  
    int getDescSize () const;
  
    /**
    * extract features for gray images
    * @param img input image
    * @param features output features
    * @param positions position of the features
    * @return 
    */
    int extractFeatures ( const NICE::Image & img, 
          NICE::VVector & features, 
          NICE::VVector & positions ) const;
    
    /**
    * extract features for color images
    * @param img input image
    * @param features output features
    * @param positions position of the features
    * @return 
    */
    int extractFeatures ( const NICE::ColorImage & img, 
          NICE::VVector & features, 
          NICE::VVector & positions ) const;
  
    void visualize ( NICE::Image & img, 
      const NICE::Vector & feature ) const;
  
    void visualizeFeatures ( NICE::Image & mark,
          const NICE::VVector & positions,
          size_t color ) const;
              
    ///////////////////// INTERFACE PERSISTENT /////////////////////
    // interface specific methods for store and restore
    ///////////////////// INTERFACE PERSISTENT /////////////////////   
    
    /** 
     * @brief Load object from external file (stream)
     * @author Alexander Freytag
     * @date 10-02-2014 ( dd-mmyyyy)
     */     
    virtual void restore ( std::istream & is, int format = 0 );
    
    /** 
     * @brief Save object to external file (stream)
     * @author Alexander Freytag
     * @date 10-02-2014 ( dd-mmyyyy)
     */       
    virtual void store( std::ostream & os, int format = 0 ) const;
    
    /** 
     * @brief Clear  object
     * @author Alexander Freytag
     * @date 10-02-2014 ( dd-mmyyyy)
     */    
    virtual void clear ();               
};


} // namespace

#endif
