src/readFMR.cpp
//' Read fingerprint minutiae records
//'
//' Read fingerprint minutiae records as specified in ANSI/INCITS 378-2004 and
//' ISO/IEC 19794-2:2005. The record is returned as a nested list structured as described
//' in the details section. Note that ANSI/INCITS 378-2004 and ISO/IEC 19794-2:2005
//' are older standards which may not be compatible with recent corrections.
//'
//' @usage readFMR(filepath, type)
//'
//' @param filepath character path to file containing the fingerprint minutiae
//' record (e.g. a "*.ist" file).
//' @param type character description of the record standard; one of the following:
//' - "ANSI_2004": ANSI/INCITS 378-2004 format
//' - "ANSI_2007": ANSI/INCITS 378-2007 format
//' - "ISO_2005": ISO/IEC 19794-2:2005 format
//' - "ISONC_2005": ISO/IEC 19794-2:2005 normal card format
//' - "ISOCC_2005": ISO/IEC 19794-2:2005 compact card format
//'
//' @return raw fingerprint minutiae record as a nested list with the following elements (raw, integer or string types):
//' - format_std
//' - product_identifier_owner
//' - product_identifier_type
//' - scanner_id
//' - compliance
//' - x_image_size
//' - y_image_size
//' - x_resolution
//' - y_resolution
//' - num_views
//' - finger_views: list of fingerprint views each structured as follows:
//'     - format_std
//'     - finger_number
//'     - view_number
//'     - impression_type
//'     - finger_quality
//'     - number_of_minutiae
//'     - x_image_size
//'     - y_image_size
//'     - x_resolution
//'     - y_resolution
//'     - algorithm_id
//'     - minutiae_data: list of minutiae data records each structured as follows:
//'         - format_std
//'         - index
//'         - type
//'         - x_coord
//'         - y_coord
//'         - angle
//'         - quality
//'
//' @note This R package is based on [NIST's BiomDI software](https://www.nist.gov/services-resources/software/biomdi-software-tools-supporting-standard-biometric-data-interchange) and includes the
//' libfmr C library. This function is adapted from the prfmr program.
//' 
//' @note The nested list contains elements of raw type. Make sure to use `as.integer()` in order to convert to integer values. 
//' 
//' @export
// [[Rcpp::export]]
' Read fingerprint minutiae records
'
' Read fingerprint minutiae records as specified in ANSI/INCITS 378-2004 and
' ISO/IEC 19794-2:2005. The record is returned as a nested list structured as described
' in the details section. Note that ANSI/INCITS 378-2004 and ISO/IEC 19794-2:2005
' are older standards which may not be compatible with recent corrections.
' Read fingerprint minutiae records ' ' Read fingerprint minutiae records as specified in ANSI / INCITS 378 - 2004 and ' ISO / IEC 19794 - 2 : 2005 . The record is returned as a nested list structured as described ' in the details section . Note that ANSI / INCITS 378 - 2004 and ISO / IEC 19794 - 2 : 2005 ' are older standards which may not be compatible with recent corrections .
Rcpp::List read_fmr_raw(std::string filepath, std::string type) {
  int in_type = stdstr_to_type(type);
  FILE *fp;
  struct stat sb;
  struct finger_minutiae_record *fmr;
  int ret;
  fp = fopen(filepath.c_str(), "rb");
  if (fp == NULL) {
    stop("open of file failed.\n");
  }
  if (new_fmr(in_type, &fmr) < 0) {
    stop("could not allocate FMR\n");
  }
  ret = read_fmr(fp, fmr);
  if (ret != READ_OK) {
    stop("Could not read fingerprint minutiae record");
  }
  if (validate_fmr(fmr) != VALIDATE_OK) {
    stop("Finger Minutiae Record is invalid.");
  }
  std::list<List> rcpp_finger_views;
  struct finger_view_minutiae_record *fvmr;
  int i = 1;
  TAILQ_FOREACH(fvmr, &fmr->finger_views, list) {
    rcpp_finger_views.push_back(rcpp_read_fvmr(fvmr));
  }
  List rcpp_fmr = List::create(Named("format_std") = fmr->format_std,
                               Named("format_id") = fmr->format_id,
                               Named("spec_version") = fmr->spec_version,
                               Named("record_length") = fmr->record_length,
                               Named("record_length_type") = fmr->record_length_type,
                               Named("product_identifier_owner") = fmr->product_identifier_owner,
                               Named("product_identifier_type") = fmr->product_identifier_type,
                               Named("scanner_id") = fmr->scanner_id,
                               Named("compliance") = fmr->compliance,
                               Named("x_image_size") = fmr->x_image_size,
                               Named("y_image_size") = fmr->y_image_size,
                               Named("x_resolution") = fmr->x_resolution,
                               Named("y_resolution") = fmr->y_resolution,
                               Named("num_views") = fmr->num_views,
                               Named("finger_views") = rcpp_finger_views);
  fclose(fp);
  return rcpp_fmr;
}
Rcpp :: List read_fmr_raw ( std :: string filepath , std :: string type ) { int in_type = stdstr_to_type ( type ) ; FILE * fp ; struct stat sb ; struct finger_minutiae_record * fmr ; int ret ; fp = fopen ( filepath . c_str ( ) , " " ) ; if ( fp == NULL ) { stop ( " \n " ) ; } if ( new_fmr ( in_type , & fmr ) < 0 ) { stop ( " \n " ) ; } ret = read_fmr ( fp , fmr ) ; if ( ret != READ_OK ) { stop ( " " ) ; } if ( validate_fmr ( fmr ) != VALIDATE_OK ) { stop ( " " ) ; } std :: list < List > rcpp_finger_views ; struct finger_view_minutiae_record * fvmr ; int i = 1 ; TAILQ_FOREACH ( fvmr , & fmr -> finger_views , list ) { rcpp_finger_views . push_back ( rcpp_read_fvmr ( fvmr ) ) ; } List rcpp_fmr = List :: create ( Named ( " " ) = fmr -> format_std , Named ( " " ) = fmr -> format_id , Named ( " " ) = fmr -> spec_version , Named ( " " ) = fmr -> record_length , Named ( " " ) = fmr -> record_length_type , Named ( " " ) = fmr -> product_identifier_owner , Named ( " " ) = fmr -> product_identifier_type , Named ( " " ) = fmr -> scanner_id , Named ( " " ) = fmr -> compliance , Named ( " " ) = fmr -> x_image_size , Named ( " " ) = fmr -> y_image_size , Named ( " " ) = fmr -> x_resolution , Named ( " " ) = fmr -> y_resolution , Named ( " " ) = fmr -> num_views , Named ( " " ) = rcpp_finger_views ) ; fclose ( fp ) ; return rcpp_fmr ; }
' Read fingerprint minutiae records
'
' Read fingerprint minutiae records as specified in ANSI/INCITS 378-2004 and
' ISO/IEC 19794-2:2005.
' Read fingerprint minutiae records ' ' Read fingerprint minutiae records as specified in ANSI / INCITS 378 - 2004 and ' ISO / IEC 19794 - 2 : 2005 .