#ifndef Init_para_h_DEFINED
#define Init_para_h_DEFINED

#include "../const.h"
#include <stdio.h>

#ifdef AIBO_YES
#include <OPENR/OSyslog.h>
#endif

struct Init_para {
       
       // skin color intervals
       int cr_min;
       int cr_max;
       int cb_min;
       int cb_max;
       int y_min;

       // Face parameters
       double perc_face;
       int debug_face;
       char file_debug_face[MAX_LENGTH_FILE];

       // Mouth parameters
       int extr_mouth_th_min;
       int extr_mouth_th_max;
       double extr_mouth_perc;
       double perc_mouth;
       double mouth_bb;
       double mouth_bl_dim;
       int debug_mouth;
       char file_debug_mouth[MAX_LENGTH_FILE];

       // Eyes parameters
       double perc_eye_min_y;
       double perc_eye_max_y;
       double perc_eye_min_x;
       double perc_eye_max_x;
       double eye_offset;
       int debug_eyes;
       char file_debug_eyes[MAX_LENGTH_FILE];

       // Eyebrow parameters
       int eyebr_th_min;
       int eyebr_th_max;
       double edges_eyebr_perc;
       double perc_eyebr_min;
       double perc_eyebr_max;
       double eyebr_offset;
       double eyebr_bb;
       int debug_eyebr;
       char file_debug_eyebr[MAX_LENGTH_FILE];
       
       // Optical Flow parameters
       double correl_th;
       
       // Block Placing parameters
       int debug_blocks;
       char file_debug_blocks[MAX_LENGTH_FILE];
       
       // Block Matching parameters
       double add_w_mouth;
       double add_h_mouth;
       double add_w_eyebr;
       double add_h_up_eyebr;
       double add_h_down_eyebr;
       double max_shift;
       double min_mov;
       int debug_corr;
       char file_debug_corr[MAX_LENGTH_FILE];
       int debug_blmatch;
       char file_debug_blmatch[MAX_LENGTH_FILE];
       
       // Eyes aperture parameters
       double add_eye;
       double perc_eye_th;
       double eye_status_thres;
       int debug_eyesap;
       char file_debug_eyesap[MAX_LENGTH_FILE];
       
       // AUs recognition parameters
       double au_thres;
       int debug_au;

       // Emotions recognition parameters
       double emo_thres;
       int debug_emo;



       Init_para() {

           char name[MAX_LENGTH_FILE];
           FILE* f;

           sprintf(name, "%s%s", INIT_FOLDER, INIT_FILE);
           f = fopen(name, "r+");
           if (f == 0) {
               PRN(("can't open %s\n", name));
           }
           else {

               fscanf(f, "#####SEGMENTATION_PARAMETERS\n");
               fscanf(f, "CR_MIN %d\n", &cr_min);
               fscanf(f, "CR_MAX %d\n", &cr_max);
               fscanf(f, "CB_MIN %d\n", &cb_min);
               fscanf(f, "CB_MAX %d\n", &cb_max);
               fscanf(f, "Y_MIN %d\n", &y_min);
    
               fscanf(f, "#####FACE_PARAMETERS\n");
               fscanf(f, "Face_Area::PERC_FACE %lf\n", &perc_face);
               fscanf(f, "DebugFace %d\n", &debug_face);
               fscanf(f, "FileDebugFace %s\n", file_debug_face);
    
               fscanf(f, "#####MOUTH_PARAMETERS\n");
               fscanf(f, "Mouth_Extremes::EXTR_MOUTH_TH_MIN %d\n", &extr_mouth_th_min);
               fscanf(f, "Mouth_Extremes::EXTR_MOUTH_TH_MAX %d\n", &extr_mouth_th_max);
               fscanf(f, "Mouth_Extremes::EXTR_MOUTH_PERC %lf\n", &extr_mouth_perc);
               fscanf(f, "Mouth_Area::PERC_MOUTH %lf\n", &perc_mouth);
               fscanf(f, "Mouth_BoundingBox::MOUTH_BB %lf\n", &mouth_bb);
               fscanf(f, "Mouth_Block::MOUTH_BL_DIM %lf\n", &mouth_bl_dim);
               fscanf(f, "DebugMouth %d\n", &debug_mouth);
               fscanf(f, "FileDebugMouth %s\n", file_debug_mouth);
               
               fscanf(f, "#####EYES_PARAMETERS\n");
               fscanf(f, "Eye_SearchArea::PERC_EYE_MIN_Y %lf\n", &perc_eye_min_y);
               fscanf(f, "Eye_SearchArea::PERC_EYE_MAX_Y %lf\n", &perc_eye_max_y);
               fscanf(f, "Eye_SearchArea::PERC_EYE_MIN_X %lf\n", &perc_eye_min_x);
               fscanf(f, "Eye_SearchArea::PERC_EYE_MAX_X %lf\n", &perc_eye_max_x);
               fscanf(f, "Eye_SearchArea::EYE_OFFSET %lf\n", &eye_offset);
               fscanf(f, "DebugEyes %d\n", &debug_eyes);
               fscanf(f, "FileDebugEyes %s\n", file_debug_eyes);
               
               fscanf(f, "#####EYEBROWS_PARAMETERS\n");
               fscanf(f, "Eyebrow_Edges::EYEBR_TH_MIN %d\n", &eyebr_th_min);
               fscanf(f, "Eyebrow_Edges::EYEBR_TH_MAX %d\n", &eyebr_th_max);
               fscanf(f, "Eyebrow_Edges::EDGES_EYEBR_PERC %lf\n", &edges_eyebr_perc);
               fscanf(f, "Eyebrow_Area::PERC_EYEBR_MIN %lf\n", &perc_eyebr_min);
               fscanf(f, "Eyebrow_Area::PERC_EYEBR_MAX %lf\n", &perc_eyebr_max);
               fscanf(f, "Eyebrow_SearchArea::EYEBR_OFFSET %lf\n", &eyebr_offset);
               fscanf(f, "Eyebrow_BoundingBox::EYEBR_BB %lf\n", &eyebr_bb);
               fscanf(f, "DebugEyebrows %d\n", &debug_eyebr);
               fscanf(f, "FileDebugEyebrows %s\n", file_debug_eyebr);
    
               fscanf(f, "#####OPTICAL_FLOW_PARAMETERS\n");
               fscanf(f, "Template_locations::CORREL_TH %lf\n", &correl_th);
    
               fscanf(f, "#####BLOCK_PLACING_PARAMETERS\n");
               fscanf(f, "DebugBlocks %d\n", &debug_blocks);
               fscanf(f, "FileDebugBlocks %s\n", file_debug_blocks);
               
               fscanf(f, "#####BLOCK_MATCHING_PARAMETERS\n");
               fscanf(f, "Search_Area::ADD_W_MOUTH %lf\n", &add_w_mouth);
               fscanf(f, "Search_Area::ADD_H_MOUTH %lf\n", &add_h_mouth);
               fscanf(f, "Search_Area::ADD_W_EYEBR %lf\n", &add_w_eyebr);
               fscanf(f, "Search_Area::ADD_H_UP_EYEBR %lf\n", &add_h_up_eyebr);
               fscanf(f, "Search_Area::ADD_H_DOWN_EYEBR %lf\n", &add_h_down_eyebr);
               fscanf(f, "Face_Movement_Shift::MAX_SHIFT %lf\n", &max_shift);
               fscanf(f, "Movement_Threshold::MIN_MOV %lf\n", &min_mov);
               fscanf(f, "DebugCorr %d\n", &debug_corr);
               fscanf(f, "FileDebugCorr %s\n", file_debug_corr);
               fscanf(f, "DebugBlMatch %d\n", &debug_blmatch);
               fscanf(f, "FileDebugBlMatch %s\n", file_debug_blmatch);
    
               fscanf(f, "#####EYES_APERTURE_PARAMETERS\n");
               fscanf(f, "Search_Area::ADD_EYE %lf\n", &add_eye);
               fscanf(f, "Threshold::PERC_EYE_TH %lf\n", &perc_eye_th);
               fscanf(f, "Threshold::EYE_STATUS_THRES %lf\n", &eye_status_thres);
               fscanf(f, "DebugEyesAp %d\n", &debug_eyesap);
               fscanf(f, "FileDebugEyesAp %s\n", file_debug_eyesap);
               
               fscanf(f, "######AUS_RECOGNITION\n");
               fscanf(f, "Threshold::AU_THRES %lf\n", &au_thres);
               fscanf(f, "DebugAU %d\n", &debug_au);
               
               fscanf(f, "######EMOTIONS_RECOGNITION\n");
               fscanf(f, "Threshold::EMO_THRES %lf\n", &emo_thres);
               fscanf(f, "DebugEmo %d\n", &debug_emo);


               fclose(f);
           }

       }



};


#endif // Init_para_h_DEFINED
