// file: $USFS/util/error_eval/v6.1/error_eval.cc
//

// isip include files
//
#include "error_eval.h"
#include "error_eval_constants.h"

// driver program to error evaluation for the USFS sbe/segmentation system
//
int main(int argc, char** argv) {
  
  // declare local variables
  //
  char_1** input_file = (char_1**)NULL;
  char_1** output_file = (char_1**)NULL;
  int_4 no_of_input = 0;
  int_4 no_of_output = 0;
  
  // declare the class
  //
  Sbe_eval sbe;
  
  // declare local variables
  //
  int_4 num_images, option;
  int_4 debug_level = 0;

  // parse the command line
  //
  if (get_parameters_cc(input_file, output_file, debug_level, num_images,
			option, argc, argv, no_of_input, no_of_output)
      == ISIP_FALSE) {
    fprintf(stdout, "%s: error reading the arguments\n", argv[0]);
    return ISIP_ERROR;
  }

  // check for the option of image segmentation evaluation
  //
  if (option == (int_4)4) {

    // do segmentation evaluation
    //
    if (eval_seg_cc(input_file[0], input_file[1]) == ISIP_FALSE) {
      fprintf(stdout, "%s: error evaluating the segmentation results\n",
	      argv[0]);
      return ISIP_ERROR;
    }
    else {

      // release memory
      //
      if (input_file != (char_1**)NULL) {
	for (int_4 i=0; i<no_of_input; i++) {
	  if (input_file[i] != (char_1*)NULL) {
	    delete [] input_file[i];
	  }
	}
	delete [] input_file;
      }
      if (output_file != (char_1**)NULL) {
	for (int_4 i=0; i<no_of_output; i++) {
	  if (output_file[i] != (char_1*)NULL) {
	    delete [] output_file[i];
	  }
	}
	delete [] output_file;
      }
	
      // exit gracefully
      //
      return ISIP_NO_ERROR;
    }
  }

  // check for the option of line detection evaluation
  //
  if (option == (int_4)5) {

    // do line detection evaluation
    //
    if (eval_line_cc(input_file[0], input_file[1]) == ISIP_FALSE) {
      fprintf(stdout, "%s: error evaluating the line detection results\n",
	      argv[0]);
      return ISIP_ERROR;
    }
    else {

      // release memory
      //
      if (input_file != (char_1**)NULL) {
	for (int_4 i=0; i<no_of_input; i++) {
	  if (input_file[i] != (char_1*)NULL) {
	    delete [] input_file[i];
	  }
	}
	delete [] input_file;
      }
      if (output_file != (char_1**)NULL) {
	for (int_4 i=0; i<no_of_output; i++) {
	  if (output_file[i] != (char_1*)NULL) {
	    delete [] output_file[i];
	  }
	}
	delete [] output_file;
      }

      // exit gracefully
      //
      return ISIP_NO_ERROR;
    }
  }
  
  // otherwise, do evaluation for sbe experiments
  //
  // initializing the parameters
  //
  if (sbe.init_cc(num_images, option) == ISIP_FALSE) {
    fprintf(stdout, "%s: error initialising the data\n", argv[0]);
    return ISIP_ERROR;
  }
  
  // compute the required option
  //
  if (sbe.compute_cc(input_file, output_file, option) == ISIP_FALSE) {
    fprintf(stdout, "%s: error computing the %s\n", argv[0], argv[1]);
    return ISIP_ERROR;
  }

  // release memory
  //
  if (input_file != (char_1**)NULL) {
    for (int_4 i=0; i<no_of_input; i++) {
      if (input_file[i] != (char_1*)NULL) {
	delete [] input_file[i];
      }
    }
    delete [] input_file;
  }
  if (output_file != (char_1**)NULL) {
    for (int_4 i=0; i<no_of_output; i++) {
      if (output_file[i] != (char_1*)NULL) {
	delete [] output_file[i];
      }
    }
    delete [] output_file;
  }

  // exit gracefully
  //
  return ISIP_NO_ERROR;
}
