SAF
Loading...
Searching...
No Matches
safmex_getSHcomplex.c
Go to the documentation of this file.
1/*
2 * Copyright 2020 Leo McCormack
3 *
4 * Permission to use, copy, modify, and/or distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
9 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
10 * AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
11 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
12 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
13 * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
14 * PERFORMANCE OF THIS SOFTWARE.
15 */
16
25#include "safmex.h"
26
27/* ===================================================================== */
28/* Config */
29/* ===================================================================== */
30
31#define NUM_INPUT_ARGS ( 2 )
32#define NUM_OUTPUT_ARGS ( 1 )
33const MEX_DATA_TYPES inputDataTypes[NUM_INPUT_ARGS] = {
36};
37const MEX_DATA_TYPES outputDataTypes[NUM_OUTPUT_ARGS] = {
39};
40
41
42/* ===================================================================== */
43/* MEX Wrapper */
44/* ===================================================================== */
45
46void mexFunction
47(
48 int nlhs, /* Number of output argments */
49 mxArray *plhs[], /* Pointers for output arguments */
50 int nrhs, /* Number of input argments */
51 const mxArray *prhs[] /* Pointers for input arguments */
52)
53{
54 /* check for proper number of arguments and input argument datatypes */
55 checkNumInOutArgs(nrhs, nlhs, NUM_INPUT_ARGS, NUM_OUTPUT_ARGS);
56 checkArgDataTypes((mxArray**)prhs, (MEX_DATA_TYPES*)inputDataTypes, NUM_INPUT_ARGS);
57
58 /* mex variables */
59 int nDims;
60 int *pDims = NULL;
61
62 /* saf variables */
63 float* dirs_rad = NULL;
64 float_complex* Y = NULL;
65 int order, nSH, nDirs;
66
67 /* prep */
68 order = (int)mxGetScalar(prhs[0]);
69 nSH = ORDER2NSH(order);
70 MEXdouble2SAFsingle(prhs[1], &dirs_rad, &nDims, &pDims);
71 nDirs = pDims[0];
72 Y = malloc1d(nSH*nDirs*sizeof(float_complex));
73
74 /* any extra checks */
75 if(pDims[1]!=2)
76 mexErrMsgIdAndTxt("MyToolbox:inputError","the second dimension of the second argument should be of size: 2");
77
78 /* call SAF function */
79 getSHcomplex(order, dirs_rad, nDirs, Y);
80
81 /* output */
82 nDims = 2;
83 pDims = realloc1d(pDims, 2*sizeof(int));
84 pDims[0] = nSH;
85 pDims[1] = nDirs;
86 SAFsingle2MEXdouble_complex(Y, nDims, pDims, &plhs[0]);
87
88 /* clean-up */
89 free(dirs_rad);
90 free(pDims);
91 free(Y);
92
93 /* check output argument datatypes */
94 checkArgDataTypes((mxArray**)plhs, (MEX_DATA_TYPES*)outputDataTypes, NUM_OUTPUT_ARGS);
95}
#define ORDER2NSH(order)
Converts spherical harmonic order to number of spherical harmonic components i.e: (order+1)^2.
Definition saf_sh.h:51
void getSHcomplex(int order, float *dirs_rad, int nDirs, float_complex *Y)
Computes complex-valued spherical harmonics [1] for each given direction on the unit sphere.
Definition saf_sh.c:440
void * malloc1d(size_t dim1_data_size)
1-D malloc (same as malloc, but with error checking)
Definition md_malloc.c:59
void * realloc1d(void *ptr, size_t dim1_data_size)
1-D realloc (same as realloc, but with error checking)
Definition md_malloc.c:79
Main include header for safmex.
void MEXdouble2SAFsingle(const mxArray *in, float **out, int *nDims, int **pDims)
Convert a mex double-precision array into single precision array for SAF.
Definition safmex.h:151
MEX_DATA_TYPES
Supported SAF/MEX data conversions.
Definition safmex.h:33
@ SM_INT32
Integer; 1 x 1.
Definition safmex.h:34
@ SM_DOUBLE_REAL_1D_OR_2D
Real 2-D matrix or 1-D vector; N x M | N x 1.
Definition safmex.h:41
@ SM_DOUBLE_COMPLEX_1D_OR_2D
Complex 2-D matrix or 1-D vector; N x M | N x 1.
Definition safmex.h:42
void checkNumInOutArgs(int nInputs, int nOutputs, int nInputs_expected, int nOutputs_expected)
Helper function to check number of inputs/outputs arguments are as expected.
Definition safmex.h:51
void SAFsingle2MEXdouble_complex(float_complex *in, int nDims, int *dims, mxArray **out)
Convert a single precision array used by SAF to mex double-precision array (complex valued)
Definition safmex.h:343
void checkArgDataTypes(mxArray **hData, MEX_DATA_TYPES *dataTypes, int nArgs)
Helper function to check the format of the input/output arguments are as expected.
Definition safmex.h:64