/* * main_import.cpp * * Matlab interface for importing AU results xml files. * Input: filename * Output: frequency matrix * * Created by Andrew Salamon on Tue Jan 30, 2007 * * Copyright (c) 2007 Machine Perception Laboratory * University of California San Diego. * Please read the license information at the end of this file. */ #include #include #include #include #include //#include //#include //#include #include #include #include "mp_AUResults.h" using namespace std; mxArray *resultsFromAUResults( const mp_AUResults &aus ); /** A mex file for creating BHAT weights files for use by CERT. * This function requires one arguments: * -# string: Source file name * and returns a matrix with 72 frequencies (doubles) per AU. */ void mexFunction(int nlhs,mxArray*plhs[],int nrhs, const mxArray*prhs[]) { // check number of input/output variables if( nlhs != 1 ) mexErrMsgTxt("AUResultImport requires one output: a matrix with 72 frequencies per column, and one column per AU."); if( nrhs != 1 ) mexErrMsgTxt("AUResultImport: requires one input: a filename for the AUResults xml file."); string filename( mxArrayToString( prhs[0] ) ); ifstream ifs( filename.c_str() ); mp_AUResults aus; if( !ifs.good() ) { mexErrMsgTxt("AUResultImport: Unable to read file."); } aus.restore( ifs ); mxArray *res = resultsFromAUResults( aus ); plhs[0] = res; } mxArray *resultsFromAUResults( const mp_AUResults &aus ) { mxArray *result = NULL; std::vector finalAus = aus.getAUResults(); unsigned int count = finalAus.size(); if( 0 == count ) { result = mxCreateDoubleMatrix(0,0,mxREAL); } else { int cols = count; int rows = 72; result = mxCreateDoubleMatrix( rows, cols, mxREAL ); double *plx = mxGetPr( result ); for (int c = 0; c < cols; c++) { std::vector freq = aus.frequenciesForAUIndex( c ); for(int r = 0; r < rows; r++) { // plx[cols*r+c] = *(resPtr++); plx[rows*c+r] = freq[r]; } } } return result; } /* * Copyright (c) 2006 Machine Perception Laboratory * University of California San Diego. * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * 3. The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */