| 671 | |
| 672 | template <typename T> |
| 673 | void validate_and_populate_arg ( |
| 674 | long arg_idx, |
| 675 | const mxArray *prhs, |
| 676 | T& arg |
| 677 | ) |
| 678 | { |
| 679 | using namespace mex_binding; |
| 680 | if (is_built_in_scalar_type<T>::value || is_same_type<T,bool>::value) |
| 681 | { |
| 682 | if( !(mxIsDouble(prhs) || mxIsSingle(prhs) || mxIsLogical(prhs) ) || |
| 683 | mxIsComplex(prhs) || |
| 684 | mxGetNumberOfElements(prhs)!=1 ) |
| 685 | { |
| 686 | std::ostringstream sout; |
| 687 | sout << "Input argument " << arg_idx+1 << " must be a scalar"; |
| 688 | throw invalid_args_exception(sout); |
| 689 | } |
| 690 | |
| 691 | assign_scalar(arg_idx, arg , mxGetScalar(prhs)); |
| 692 | } |
| 693 | else if (is_matrix<T>::value || is_array2d<T>::value) |
| 694 | { |
| 695 | if (prhs == NULL) |
| 696 | { |
| 697 | clear_mat(arg); |
| 698 | return; |
| 699 | } |
| 700 | |
| 701 | typedef typename inner_type<T>::type type; |
| 702 | |
| 703 | const int num_dims = mxGetNumberOfDimensions(prhs); |
| 704 | const long nr = mxGetM(prhs); |
| 705 | const long nc = mxGetN(prhs); |
| 706 | |
| 707 | if (is_same_type<type,dlib::rgb_pixel>::value) |
| 708 | { |
| 709 | if (!(num_dims == 3 && mxGetDimensions(prhs)[2] == 3 && mxIsUint8(prhs))) |
| 710 | { |
| 711 | std::ostringstream sout; |
| 712 | sout << "Input argument " << arg_idx+1 << " must be a 3-D NxMx3 image matrix of uint8"; |
| 713 | throw invalid_args_exception(sout); |
| 714 | } |
| 715 | |
| 716 | const long rows = mxGetDimensions(prhs)[0]; |
| 717 | const long cols = mxGetDimensions(prhs)[1]; |
| 718 | assign_image(arg_idx, arg , (const dlib::uint8*)mxGetData(prhs), rows, cols); |
| 719 | return; |
| 720 | } |
| 721 | |
| 722 | if (num_dims != 2) |
| 723 | { |
| 724 | std::ostringstream sout; |
| 725 | sout << "Input argument " << arg_idx+1 << " must be a 2-D matrix (got a " << num_dims << "-D matrix)"; |
| 726 | throw invalid_args_exception(sout); |
| 727 | } |
| 728 | |
| 729 | |
| 730 | if (is_same_type<type,double>::value) |
no test coverage detected