/** 
* @file KMeansMatlab.h
* @brief K-Means using a matlab implementation
* @author Erik Rodner
* @date 10/29/2007

*/
#ifndef KMeansMatlabINCLUDE
#define KMeansMatlabINCLUDE

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

#include "core/basics/Config.h"
#include "ClusterAlgorithm.h"


namespace OBJREC {

/** 
* @class KMeansMatlab
* @brief K-Means using a matlab implementation
* @author Erik Rodner
*/

class KMeansMatlab : public ClusterAlgorithm
{

  protected:
    
      /************************
      * 
      *   protected variables
      * 
      **************************/     
      int noClusters;
      // refactor-nice.pl: check this substitution
      // old: string kmeansDir;
      std::string kmeansDir;
      // refactor-nice.pl: check this substitution
      // old: string matlabExec;
      std::string matlabExec;
      // refactor-nice.pl: check this substitution
      // old: string matlabArgs;
      std::string matlabArgs;

      // refactor-nice.pl: check this substitution
      // old: string inputFN;
      std::string inputFN;
      // refactor-nice.pl: check this substitution
      // old: string outputFN;
      std::string outputFN;

      FILE *matlabPipe;
      
      /************************
      * 
      *   protected methods
      * 
      **************************/        
      
      int compute_prototypes ( const NICE::VVector & features,
              NICE::VVector & prototypes,
              std::vector<double> & weights,
              const std::vector<int>    & assignment );


  public:
        
    ///////////////////// ///////////////////// /////////////////////
    //                   CONSTRUCTORS / DESTRUCTORS
    ///////////////////// ///////////////////// /////////////////////        
        
    /** 
     * @brief default constructor
     * @date 13-02-2014 (dd-mm-yyyy )
     * @author Alexander Freytag
     */
    KMeansMatlab ( );        
    
    /** 
    * @brief simple constructor
    * @author Erik Rodner, Alexander Freytag
    * Among others, you can specify for "section" the following attributes: "source_root", "tmpInput", "tmpOutput", "matlab_exec", "matlab_args"
    */
    KMeansMatlab( const NICE::Config * _conf,  const std::string & _confSection = "KMeansMatlab" );
        
    /** simple destructor */
    virtual ~KMeansMatlab();
        
    /** 
     * @brief Jobs previously performed in the config-version of the constructor, read settings etc.
     * @author Alexander Freytag
     * @date 13-02-2014 ( dd-mm-yyyy )
     */    
    void initFromConfig ( const NICE::Config * _conf, const std::string & _confSection = "KMeansMatlab");         
        
    ///////////////////// ///////////////////// /////////////////////
    //                      CLUSTERING STUFF
    ///////////////////// ///////////////////// //////////////////         
          
    void cluster ( const NICE::VVector & features,
            NICE::VVector & prototypes,
            std::vector<double> & weights,
            std::vector<int>    & assignment );
      
    ///////////////////// INTERFACE PERSISTENT /////////////////////
    // interface specific methods for store and restore
    ///////////////////// INTERFACE PERSISTENT /////////////////////      
    
    /**
    * @brief Load object from external file (stream)
    * @author Alexander Freytag
    * @date 13-02-2014 ( dd-mm-yyyy )
    */
    void restore ( std::istream & is, int format = 0 );

    /**
    * @brief Save object to external file (stream)
    * @author Alexander Freytag
    * @date 13-02-2014 ( dd-mm-yyyy )
    */
    void store ( std::ostream & os, int format = 0 ) const;

    /**
    * @brief Clear object
    * @author Alexander Freytag
    * @date 13-02-2014 ( dd-mm-yyyy )
    */
    void clear ();            

  };


} // namespace

#endif
