/** 
 * @file LFPatches.h
 * @brief simple patch based approach
 * @author Erik Rodner
 * @date 02/06/2008

 */
#ifndef LFPATCHESINCLUDE
#define LFPATCHESINCLUDE

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

#include "core/basics/Config.h"
#include "vislearning/image/ImagePyramid.h"
#include "LocalFeatureRepresentation.h"
#include "vislearning/features/localfeatures/InterestDetector.h"

namespace OBJREC
{

/** simple patch based approach */
class LFPatches: public LocalFeatureRepresentation
{

  protected:
	enum
	{
		NORMALIZE_N01 = 0, NORMALIZE_NONE, NORMALIZE_STDDEV, NORMALIZE_MEAN
	};

	int xsize;
	int ysize;
	int normalization;
	InterestDetector * id;
	int maxLevels;
	double scaleSpacing;
	int detectormode;
	int numPatches;


	void calcDescriptors(const ImagePyramid & imp, NICE::VVector & positions,
			NICE::VVector & features) const;
                        
        void setDetector ( const int & _detectormode, const NICE::Config * conf);
        void setNormalization( const std::string & _normalization_s) ;

  public:
  
    ///////////////////// ///////////////////// /////////////////////
    //                   CONSTRUCTORS / DESTRUCTORS
    ///////////////////// ///////////////////// /////////////////////
    
    /** 
     * @brief default constructor
     * @date 10-02-2014 (dd-mm-yyyy )
     * @author Alexander Freytag
     */
    LFPatches();    

    /** simple constructor */
    LFPatches(const NICE::Config *conf, int numPatches);

    /** simple destructor */
    virtual ~LFPatches();
      
    ///////////////////// ///////////////////// /////////////////////
    //                      FEATURE STUFF
    ///////////////////// ///////////////////// //////////////////        

    int getDescSize() const;

    int extractFeatures(const NICE::Image & img, NICE::VVector & features,
                    NICE::VVector & positions) const;
    void correctPositions(const ImagePyramid & imp, NICE::VVector & positions,
                    NICE::VVector & positions_corrected) const;

    void visualize(NICE::Image & img, const NICE::Vector & feature) const;

    void visualizeFeatures(NICE::Image & mark, const NICE::VVector & positions,
                    size_t color) const;
//DIRTY for bofCreationSingleImage
    int calcDescriptor(const ImagePyramid & imp, const NICE::Vector & position,
                            NICE::Vector & desc) 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
