vl_imintegral.c
Go to the documentation of this file.
00001 
00007 /*
00008 Copyright (C) 2007-12 Andrea Vedaldi and Brian Fulkerson.
00009 All rights reserved.
00010 
00011 This file is part of the VLFeat library and is made available under
00012 the terms of the BSD license (see the COPYING file).
00013 */
00014 
00015 #include <mexutils.h>
00016 
00017 #include <vl/generic.h>
00018 #include <vl/imopv.h>
00019 
00020 #include <stdlib.h>
00021 #include <string.h>
00022 #include <math.h>
00023 
00024 void
00025 mexFunction(int nout, mxArray *out[],
00026             int nin, const mxArray *in[])
00027 {
00028   vl_size numDimensions, numChannels ;
00029   mwSize const *dimensions ;
00030   mxClassID classId ;
00031   void * integral ;
00032   void const * image ;
00033   vl_uindex k ;
00034   enum {IN_I=0} ;
00035   enum {OUT_J=0} ;
00036 
00037   /* -----------------------------------------------------------------
00038    *                                               Check the arguments
00039    * -------------------------------------------------------------- */
00040 
00041   if (nin > 1) {
00042     vlmxError(vlmxErrTooManyInputArguments, NULL) ;
00043   }
00044   if (nin < 1) {
00045     vlmxError(vlmxErrNotEnoughInputArguments, NULL) ;
00046   }
00047   if (nout > 1) {
00048     vlmxError(vlmxErrTooManyOutputArguments, NULL) ;
00049   }
00050 
00051   if (! mxIsNumeric(IN(I))) {
00052     vlmxError(vlmxErrInvalidArgument,
00053               "I is not numeric.") ;
00054   }
00055 
00056   dimensions = mxGetDimensions(IN(I)) ;
00057   numDimensions = mxGetNumberOfDimensions(IN(I)) ;
00058   if (numDimensions > 3) {
00059     vlmxError(vlmxErrInvalidArgument,
00060               "I has more than 3 dimensions (%d).", numDimensions) ;
00061   }
00062   if (numDimensions > 2) {
00063     numChannels = dimensions [2] ;
00064   } else {
00065     numChannels = 1 ;
00066   }
00067 
00068   classId = mxGetClassID(IN(I)) ;
00069   if (classId != mxSINGLE_CLASS &&
00070       classId != mxDOUBLE_CLASS &&
00071       classId != mxUINT32_CLASS &&
00072       classId != mxINT32_CLASS) {
00073     vlmxError(vlmxErrInvalidArgument,
00074               "I is not of a supported storage class.") ;
00075   }
00076 
00077   OUT(J) = mxCreateNumericArray(numDimensions, dimensions,
00078                                 classId, mxREAL) ;
00079 
00080   image = mxGetData(IN(I)) ;
00081   integral = mxGetData(OUT(J)) ;
00082 
00083   /* -----------------------------------------------------------------
00084    *                                                        Do the job
00085    * -------------------------------------------------------------- */
00086 
00087 #define DO(CLASS, T, SFX) \
00088 case mx ## CLASS ## _CLASS : \
00089 vl_imintegral_ ## SFX (integral, dimensions[0], \
00090   image, dimensions[0], dimensions[1], dimensions[0]) ; \
00091   integral = ((T *) integral) + dimensions[0]*dimensions[1] ; \
00092   image = ((T const *) image) + dimensions[0]*dimensions[1] ; \
00093 break
00094 
00095   for (k = 0 ; k < numChannels ; ++k) {
00096     switch (classId) {
00097         DO(SINGLE, float, f) ;
00098         DO(DOUBLE, double, d) ;
00099         DO(UINT32, vl_uint32, ui32) ;
00100         DO(INT32, vl_int32, i32) ;
00101       default:
00102         abort() ;
00103     }
00104   }
00105 }


libvlfeat
Author(s): Andrea Vedaldi
autogenerated on Thu Jun 6 2019 20:25:51