#ifndef FaceExpr_h_DEFINED
#define FaceExpr_h_DEFINED

#include "../const.h"

#ifdef AIBO_YES
#include "def.h"
#include "Init_para.h"
#include "Init_batch.h"
#include "Image.h"
#include "Blocks.h"
#include "Emotion.h"
#include "Interaction.h"
#include <OPENR/OObject.h>
#include <OPENR/OSubject.h>
#include <OPENR/OObserver.h>


enum States {
     IDLE,
     START,
     INTRO_NEUTRAL,
     PROCESSING_NEUTRAL,
     NEUTRAL_DONE,
     INTRO_EXPR,
     PROCESSING_EXPR,
     EXPR_DONE,
     ALL_DONE,
     WAITING_FOR_END
};

// From "ImageObserver" sample

static const char* const FBK_LOCATOR = "PRM:/r1/c1/c2/c3/i1-FbkImageSensor:F1";
static const char* const TINSW_LOCATOR = "PRM:/r1/c1/c2/c3/c4/s5-Sensor:s5";
static const char* const BACKSW_LOCATOR = "PRM:/r6/s1-Sensor:s1";
static const char* const BACKR7_LOCATOR = "PRM:/t2-Sensor:t2"; // REAR
static const char* const BACKM7_LOCATOR = "PRM:/t3-Sensor:t3"; // FRONT
static const char* const BACKF7_LOCATOR = "PRM:/t4-Sensor:t4"; // MID


class FaceExpr : public OObject {
public:
    FaceExpr();
    virtual ~FaceExpr() {}

    OSubject*    subject[numOfSubject];
    OObserver*   observer[numOfObserver];

    #ifndef ONLINE
    Init_batch ib;
    #endif
    
    Init_para parameters;

    bool motion;
    int eyes_status;
    Image im_cr, im_cb, im_clust, im_expanded,
          im_expr_clust, im_expression, im_expr_cb, im_expr_cr,
          mouth, eye_left, eye_right, mouth_exp, eye_left_exp,
          eye_right_exp, eyebrow_left, eyebrow_right;

    int* face_centroid;
    int* face_bb;
    int* rec_aus;

    Block* blocks;
    Emotion emotion;


    virtual OStatus DoInit   (const OSystemEvent& event);
    virtual OStatus DoStart  (const OSystemEvent& event);
    virtual OStatus DoStop   (const OSystemEvent& event);
    virtual OStatus DoDestroy(const OSystemEvent& event);

    void ProcessPicture(const ONotifyEvent& event);
    void ExecuteMoNetCommand(int command);
    void NotifyMoNetResult(const ONotifyEvent& event);


private:
    void OpenPrimitive();
    bool ExistData(int serialNumber);
    void SaveData(int serialNumber, OFbkImageVectorData* imageVec);

    void SetChannel();
    bool ReconstructImage(OFbkImageVectorData* imageVec,
                                OFbkImageLayer layer,
                                byte** image, int* width, int* height);
    bool ReconstructImageColor(OFbkImageVectorData* imageVec,
                                OFbkImageLayer layer,
                                byte** image, int* width, int* height);

    void FreeImage(byte* image);
    void SetCameraParameter();

    States              faceExprState;
    OPrimitiveID        fbkID;
    OPrimitiveID        tinswID;
    OPrimitiveID        backswID;
    OPrimitiveID        backf7ID;
    OPrimitiveID        backm7ID;
    OPrimitiveID        backr7ID;
    OPrimitiveID        speakerID;

    static const int ROBOT_UNDEF  = 0;
    static const int ROBOT_ERS200 = 1;
    static const int ROBOT_ERS7   = 2;
    int robot;
};

#endif


#endif // FaceExpr_h_DEFINED
