/*
 * _coder_MLS_getDeform_api.c
 *
 * Code generation for function '_coder_MLS_getDeform_api'
 *
 */

/* Include files */
#include "rt_nonfinite.h"
#include "MLS_getDeform.h"
#include "_coder_MLS_getDeform_api.h"
#include "MLS_getDeform_emxutil.h"
#include "MLS_getDeform_mexutil.h"
#include "MLS_getDeform_data.h"

/* Variable Definitions */
static emlrtRTEInfo g_emlrtRTEI = { 1, /* lineNo */
  1,                                   /* colNo */
  "_coder_MLS_getDeform_api",          /* fName */
  ""                                   /* pName */
};

/* Function Declarations */
static const mxArray *b_emlrt_marshallOut(const emlrtStack *sp, const struct0_T
  u);
static void c_emlrt_marshallIn(const emlrtStack *sp, const mxArray
  *control_points, const char_T *identifier, emxArray_real_T *y);
static const mxArray *c_emlrt_marshallOut(const emxArray_real_T *u);
static void d_emlrt_marshallIn(const emlrtStack *sp, const mxArray *u, const
  emlrtMsgIdentifier *parentId, emxArray_real_T *y);
static void e_emlrt_marshallIn(const emlrtStack *sp, const mxArray *type, const
  char_T *identifier, emxArray_char_T *y);
static const mxArray *emlrt_marshallOut(const emxArray_real_T *u);
static void f_emlrt_marshallIn(const emlrtStack *sp, const mxArray *u, const
  emlrtMsgIdentifier *parentId, emxArray_char_T *y);
static void g_emlrt_marshallIn(const emlrtStack *sp, const mxArray *precomputed,
  const char_T *identifier, struct0_T *y);
static void h_emlrt_marshallIn(const emlrtStack *sp, const mxArray *u, const
  emlrtMsgIdentifier *parentId, struct0_T *y);
static void i_emlrt_marshallIn(const emlrtStack *sp, const mxArray *u, const
  emlrtMsgIdentifier *parentId, emxArray_real_T *y);
static void j_emlrt_marshallIn(const emlrtStack *sp, const mxArray *u, const
  emlrtMsgIdentifier *parentId, emxArray_real_T *y);
static void k_emlrt_marshallIn(const emlrtStack *sp, const mxArray *u, const
  emlrtMsgIdentifier *parentId, emxArray_real_T *y);
static real_T (*l_emlrt_marshallIn(const emlrtStack *sp, const mxArray
  *size_of_img, const char_T *identifier))[2];
static real_T (*m_emlrt_marshallIn(const emlrtStack *sp, const mxArray *u, const
  emlrtMsgIdentifier *parentId))[2];
static void o_emlrt_marshallIn(const emlrtStack *sp, const mxArray *src, const
  emlrtMsgIdentifier *msgId, emxArray_real_T *ret);
static void p_emlrt_marshallIn(const emlrtStack *sp, const mxArray *src, const
  emlrtMsgIdentifier *msgId, emxArray_char_T *ret);
static void q_emlrt_marshallIn(const emlrtStack *sp, const mxArray *src, const
  emlrtMsgIdentifier *msgId, emxArray_real_T *ret);
static void r_emlrt_marshallIn(const emlrtStack *sp, const mxArray *src, const
  emlrtMsgIdentifier *msgId, emxArray_real_T *ret);
static void s_emlrt_marshallIn(const emlrtStack *sp, const mxArray *src, const
  emlrtMsgIdentifier *msgId, emxArray_real_T *ret);
static real_T (*t_emlrt_marshallIn(const emlrtStack *sp, const mxArray *src,
  const emlrtMsgIdentifier *msgId))[2];

/* Function Definitions */
static const mxArray *b_emlrt_marshallOut(const emlrtStack *sp, const struct0_T
  u)
{
  const mxArray *y;
  emxArray_real_T *b_u;
  static const char * sv0[6] = { "w_i", "sum_w_i", "p_ast", "Similarity",
    "Affine", "Rigid" };

  int32_T i2;
  int32_T loop_ub;
  const mxArray *b_y;
  const mxArray *m3;
  real_T *pData;
  emxArray_real_T *c_u;
  int32_T i;
  emlrtHeapReferenceStackEnterFcnR2012b(sp);
  emxInit_real_T2(sp, &b_u, 1, (emlrtRTEInfo *)NULL, true);
  y = NULL;
  emlrtAssign(&y, emlrtCreateStructMatrix(1, 1, 6, sv0));
  emlrtSetFieldR2017b(y, 0, "w_i", c_emlrt_marshallOut(u.w_i), 0);
  i2 = b_u->size[0];
  b_u->size[0] = u.sum_w_i->size[0];
  emxEnsureCapacity_real_T1(sp, b_u, i2, (emlrtRTEInfo *)NULL);
  loop_ub = u.sum_w_i->size[0];
  for (i2 = 0; i2 < loop_ub; i2++) {
    b_u->data[i2] = u.sum_w_i->data[i2];
  }

  b_y = NULL;
  m3 = emlrtCreateNumericArray(1, *(int32_T (*)[3])b_u->size, mxDOUBLE_CLASS,
    mxREAL);
  pData = (real_T *)emlrtMxGetPr(m3);
  i2 = 0;
  loop_ub = 0;
  emxFree_real_T(&b_u);
  while (loop_ub < u.sum_w_i->size[0]) {
    pData[i2] = u.sum_w_i->data[loop_ub];
    i2++;
    loop_ub++;
  }

  emxInit_real_T1(sp, &c_u, 2, (emlrtRTEInfo *)NULL, true);
  emlrtAssign(&b_y, m3);
  emlrtSetFieldR2017b(y, 0, "sum_w_i", b_y, 1);
  i2 = c_u->size[0] * c_u->size[1];
  c_u->size[0] = u.p_ast->size[0];
  c_u->size[1] = 2;
  emxEnsureCapacity_real_T(sp, c_u, i2, (emlrtRTEInfo *)NULL);
  loop_ub = u.p_ast->size[0] * u.p_ast->size[1];
  for (i2 = 0; i2 < loop_ub; i2++) {
    c_u->data[i2] = u.p_ast->data[i2];
  }

  b_y = NULL;
  m3 = emlrtCreateNumericArray(2, *(int32_T (*)[3])c_u->size, mxDOUBLE_CLASS,
    mxREAL);
  pData = (real_T *)emlrtMxGetPr(m3);
  i2 = 0;
  emxFree_real_T(&c_u);
  for (loop_ub = 0; loop_ub < 2; loop_ub++) {
    for (i = 0; i < u.p_ast->size[0]; i++) {
      pData[i2] = u.p_ast->data[i + u.p_ast->size[0] * loop_ub];
      i2++;
    }
  }

  emlrtAssign(&b_y, m3);
  emlrtSetFieldR2017b(y, 0, "p_ast", b_y, 2);
  emlrtSetFieldR2017b(y, 0, "Similarity", c_emlrt_marshallOut(u.Similarity), 3);
  emlrtSetFieldR2017b(y, 0, "Affine", c_emlrt_marshallOut(u.Affine), 4);
  emlrtSetFieldR2017b(y, 0, "Rigid", c_emlrt_marshallOut(u.Rigid), 5);
  emlrtHeapReferenceStackLeaveFcnR2012b(sp);
  return y;
}

static void c_emlrt_marshallIn(const emlrtStack *sp, const mxArray
  *control_points, const char_T *identifier, emxArray_real_T *y)
{
  emlrtMsgIdentifier thisId;
  thisId.fIdentifier = (const char *)identifier;
  thisId.fParent = NULL;
  thisId.bParentIsCell = false;
  d_emlrt_marshallIn(sp, emlrtAlias(control_points), &thisId, y);
  emlrtDestroyArray(&control_points);
}

static const mxArray *c_emlrt_marshallOut(const emxArray_real_T *u)
{
  const mxArray *y;
  const mxArray *m4;
  real_T *pData;
  int32_T i3;
  int32_T i;
  int32_T b_i;
  y = NULL;
  m4 = emlrtCreateNumericArray(2, *(int32_T (*)[3])u->size, mxDOUBLE_CLASS,
    mxREAL);
  pData = (real_T *)emlrtMxGetPr(m4);
  i3 = 0;
  for (i = 0; i < u->size[1]; i++) {
    for (b_i = 0; b_i < u->size[0]; b_i++) {
      pData[i3] = u->data[b_i + u->size[0] * i];
      i3++;
    }
  }

  emlrtAssign(&y, m4);
  return y;
}

static void d_emlrt_marshallIn(const emlrtStack *sp, const mxArray *u, const
  emlrtMsgIdentifier *parentId, emxArray_real_T *y)
{
  o_emlrt_marshallIn(sp, emlrtAlias(u), parentId, y);
  emlrtDestroyArray(&u);
}

static void e_emlrt_marshallIn(const emlrtStack *sp, const mxArray *type, const
  char_T *identifier, emxArray_char_T *y)
{
  emlrtMsgIdentifier thisId;
  thisId.fIdentifier = (const char *)identifier;
  thisId.fParent = NULL;
  thisId.bParentIsCell = false;
  f_emlrt_marshallIn(sp, emlrtAlias(type), &thisId, y);
  emlrtDestroyArray(&type);
}

static const mxArray *emlrt_marshallOut(const emxArray_real_T *u)
{
  const mxArray *y;
  const mxArray *m2;
  static const int32_T iv3[3] = { 0, 0, 0 };

  y = NULL;
  m2 = emlrtCreateNumericArray(3, iv3, mxDOUBLE_CLASS, mxREAL);
  emlrtMxSetData((mxArray *)m2, (void *)&u->data[0]);
  emlrtSetDimensions((mxArray *)m2, u->size, 3);
  emlrtAssign(&y, m2);
  return y;
}

static void f_emlrt_marshallIn(const emlrtStack *sp, const mxArray *u, const
  emlrtMsgIdentifier *parentId, emxArray_char_T *y)
{
  p_emlrt_marshallIn(sp, emlrtAlias(u), parentId, y);
  emlrtDestroyArray(&u);
}

static void g_emlrt_marshallIn(const emlrtStack *sp, const mxArray *precomputed,
  const char_T *identifier, struct0_T *y)
{
  emlrtMsgIdentifier thisId;
  thisId.fIdentifier = (const char *)identifier;
  thisId.fParent = NULL;
  thisId.bParentIsCell = false;
  h_emlrt_marshallIn(sp, emlrtAlias(precomputed), &thisId, y);
  emlrtDestroyArray(&precomputed);
}

static void h_emlrt_marshallIn(const emlrtStack *sp, const mxArray *u, const
  emlrtMsgIdentifier *parentId, struct0_T *y)
{
  emlrtMsgIdentifier thisId;
  static const char * fieldNames[6] = { "w_i", "sum_w_i", "p_ast", "Similarity",
    "Affine", "Rigid" };

  static const int32_T dims = 0;
  thisId.fParent = parentId;
  thisId.bParentIsCell = false;
  emlrtCheckStructR2012b(sp, parentId, u, 6, fieldNames, 0U, &dims);
  thisId.fIdentifier = "w_i";
  i_emlrt_marshallIn(sp, emlrtAlias(emlrtGetFieldR2017b(sp, u, 0, 0, "w_i")),
                     &thisId, y->w_i);
  thisId.fIdentifier = "sum_w_i";
  j_emlrt_marshallIn(sp, emlrtAlias(emlrtGetFieldR2017b(sp, u, 0, 1, "sum_w_i")),
                     &thisId, y->sum_w_i);
  thisId.fIdentifier = "p_ast";
  k_emlrt_marshallIn(sp, emlrtAlias(emlrtGetFieldR2017b(sp, u, 0, 2, "p_ast")),
                     &thisId, y->p_ast);
  thisId.fIdentifier = "Similarity";
  i_emlrt_marshallIn(sp, emlrtAlias(emlrtGetFieldR2017b(sp, u, 0, 3,
    "Similarity")), &thisId, y->Similarity);
  thisId.fIdentifier = "Affine";
  i_emlrt_marshallIn(sp, emlrtAlias(emlrtGetFieldR2017b(sp, u, 0, 4, "Affine")),
                     &thisId, y->Affine);
  thisId.fIdentifier = "Rigid";
  i_emlrt_marshallIn(sp, emlrtAlias(emlrtGetFieldR2017b(sp, u, 0, 5, "Rigid")),
                     &thisId, y->Rigid);
  emlrtDestroyArray(&u);
}

static void i_emlrt_marshallIn(const emlrtStack *sp, const mxArray *u, const
  emlrtMsgIdentifier *parentId, emxArray_real_T *y)
{
  q_emlrt_marshallIn(sp, emlrtAlias(u), parentId, y);
  emlrtDestroyArray(&u);
}

static void j_emlrt_marshallIn(const emlrtStack *sp, const mxArray *u, const
  emlrtMsgIdentifier *parentId, emxArray_real_T *y)
{
  r_emlrt_marshallIn(sp, emlrtAlias(u), parentId, y);
  emlrtDestroyArray(&u);
}

static void k_emlrt_marshallIn(const emlrtStack *sp, const mxArray *u, const
  emlrtMsgIdentifier *parentId, emxArray_real_T *y)
{
  s_emlrt_marshallIn(sp, emlrtAlias(u), parentId, y);
  emlrtDestroyArray(&u);
}

static real_T (*l_emlrt_marshallIn(const emlrtStack *sp, const mxArray
  *size_of_img, const char_T *identifier))[2]
{
  real_T (*y)[2];
  emlrtMsgIdentifier thisId;
  thisId.fIdentifier = (const char *)identifier;
  thisId.fParent = NULL;
  thisId.bParentIsCell = false;
  y = m_emlrt_marshallIn(sp, emlrtAlias(size_of_img), &thisId);
  emlrtDestroyArray(&size_of_img);
  return y;
}
  static real_T (*m_emlrt_marshallIn(const emlrtStack *sp, const mxArray *u,
  const emlrtMsgIdentifier *parentId))[2]
{
  real_T (*y)[2];
  y = t_emlrt_marshallIn(sp, emlrtAlias(u), parentId);
  emlrtDestroyArray(&u);
  return y;
}

static void o_emlrt_marshallIn(const emlrtStack *sp, const mxArray *src, const
  emlrtMsgIdentifier *msgId, emxArray_real_T *ret)
{
  static const int32_T dims[2] = { -1, 2 };

  const boolean_T bv0[2] = { true, false };

  int32_T iv4[2];
  emlrtCheckVsBuiltInR2012b(sp, msgId, src, "double", false, 2U, dims, &bv0[0],
    iv4);
  ret->size[0] = iv4[0];
  ret->size[1] = iv4[1];
  ret->allocatedSize = ret->size[0] * ret->size[1];
  ret->data = (real_T *)emlrtMxGetData(src);
  ret->canFreeData = false;
  emlrtDestroyArray(&src);
}

static void p_emlrt_marshallIn(const emlrtStack *sp, const mxArray *src, const
  emlrtMsgIdentifier *msgId, emxArray_char_T *ret)
{
  static const int32_T dims[2] = { 1, -1 };

  const boolean_T bv1[2] = { false, true };

  int32_T iv5[2];
  int32_T i4;
  emlrtCheckVsBuiltInR2012b(sp, msgId, src, "char", false, 2U, dims, &bv1[0],
    iv5);
  i4 = ret->size[0] * ret->size[1];
  ret->size[0] = iv5[0];
  ret->size[1] = iv5[1];
  emxEnsureCapacity_char_T(sp, ret, i4, (emlrtRTEInfo *)NULL);
  emlrtImportArrayR2015b(sp, src, ret->data, 1, false);
  emlrtDestroyArray(&src);
}

static void q_emlrt_marshallIn(const emlrtStack *sp, const mxArray *src, const
  emlrtMsgIdentifier *msgId, emxArray_real_T *ret)
{
  static const int32_T dims[2] = { -1, -1 };

  const boolean_T bv2[2] = { true, true };

  int32_T iv6[2];
  int32_T i5;
  emlrtCheckVsBuiltInR2012b(sp, msgId, src, "double", false, 2U, dims, &bv2[0],
    iv6);
  i5 = ret->size[0] * ret->size[1];
  ret->size[0] = iv6[0];
  ret->size[1] = iv6[1];
  emxEnsureCapacity_real_T(sp, ret, i5, (emlrtRTEInfo *)NULL);
  emlrtImportArrayR2015b(sp, src, ret->data, 8, false);
  emlrtDestroyArray(&src);
}

static void r_emlrt_marshallIn(const emlrtStack *sp, const mxArray *src, const
  emlrtMsgIdentifier *msgId, emxArray_real_T *ret)
{
  static const int32_T dims[1] = { -1 };

  const boolean_T bv3[1] = { true };

  int32_T iv7[1];
  int32_T i6;
  emlrtCheckVsBuiltInR2012b(sp, msgId, src, "double", false, 1U, dims, &bv3[0],
    iv7);
  i6 = ret->size[0];
  ret->size[0] = iv7[0];
  emxEnsureCapacity_real_T1(sp, ret, i6, (emlrtRTEInfo *)NULL);
  emlrtImportArrayR2015b(sp, src, ret->data, 8, false);
  emlrtDestroyArray(&src);
}

static void s_emlrt_marshallIn(const emlrtStack *sp, const mxArray *src, const
  emlrtMsgIdentifier *msgId, emxArray_real_T *ret)
{
  static const int32_T dims[2] = { -1, 2 };

  const boolean_T bv4[2] = { true, false };

  int32_T iv8[2];
  int32_T i7;
  emlrtCheckVsBuiltInR2012b(sp, msgId, src, "double", false, 2U, dims, &bv4[0],
    iv8);
  i7 = ret->size[0] * ret->size[1];
  ret->size[0] = iv8[0];
  ret->size[1] = iv8[1];
  emxEnsureCapacity_real_T(sp, ret, i7, (emlrtRTEInfo *)NULL);
  emlrtImportArrayR2015b(sp, src, ret->data, 8, false);
  emlrtDestroyArray(&src);
}

static real_T (*t_emlrt_marshallIn(const emlrtStack *sp, const mxArray *src,
  const emlrtMsgIdentifier *msgId))[2]
{
  real_T (*ret)[2];
  static const int32_T dims[2] = { 1, 2 };

  emlrtCheckBuiltInR2012b(sp, msgId, src, "double", false, 2U, dims);
  ret = (real_T (*)[2])emlrtMxGetData(src);
  emlrtDestroyArray(&src);
  return ret;
}
  void MLS_getDeform_api(const mxArray * const prhs[7], const mxArray *plhs[2])
{
  emxArray_real_T *control_points;
  emxArray_real_T *c_deformed_position_of_control_;
  emxArray_real_T *points_of_evaluation;
  emxArray_char_T *type;
  struct0_T precomputed;
  emxArray_real_T *f;
  struct0_T pre;
  real_T alpha;
  real_T (*size_of_img)[2];
  emlrtStack st = { NULL,              /* site */
    NULL,                              /* tls */
    NULL                               /* prev */
  };

  st.tls = emlrtRootTLSGlobal;
  emlrtHeapReferenceStackEnterFcnR2012b(&st);
  emxInit_real_T1(&st, &control_points, 2, &g_emlrtRTEI, true);
  emxInit_real_T1(&st, &c_deformed_position_of_control_, 2, &g_emlrtRTEI, true);
  emxInit_real_T1(&st, &points_of_evaluation, 2, &g_emlrtRTEI, true);
  emxInit_char_T(&st, &type, 2, &g_emlrtRTEI, true);
  emxInitStruct_struct0_T(&st, &precomputed, &g_emlrtRTEI, true);
  emxInit_real_T(&st, &f, 3, &g_emlrtRTEI, true);
  emxInitStruct_struct0_T(&st, &pre, &g_emlrtRTEI, true);

  /* Marshall function inputs */
  c_emlrt_marshallIn(&st, emlrtAlias(prhs[0]), "control_points", control_points);
  c_emlrt_marshallIn(&st, emlrtAlias(prhs[1]),
                     "deformed_position_of_control_points",
                     c_deformed_position_of_control_);
  c_emlrt_marshallIn(&st, emlrtAlias(prhs[2]), "points_of_evaluation",
                     points_of_evaluation);
  alpha = emlrt_marshallIn(&st, emlrtAliasP(prhs[3]), "alpha");
  e_emlrt_marshallIn(&st, emlrtAliasP(prhs[4]), "type", type);
  g_emlrt_marshallIn(&st, emlrtAliasP(prhs[5]), "precomputed", &precomputed);
  size_of_img = l_emlrt_marshallIn(&st, emlrtAlias(prhs[6]), "size_of_img");

  /* Invoke the target function */
  MLS_getDeform(&st, control_points, c_deformed_position_of_control_,
                points_of_evaluation, alpha, type, &precomputed, *size_of_img, f,
                &pre);

  /* Marshall function outputs */
  plhs[0] = emlrt_marshallOut(f);
  plhs[1] = b_emlrt_marshallOut(&st, pre);
  emxFreeStruct_struct0_T(&pre);
  f->canFreeData = false;
  emxFree_real_T(&f);
  emxFreeStruct_struct0_T(&precomputed);
  emxFree_char_T(&type);
  points_of_evaluation->canFreeData = false;
  emxFree_real_T(&points_of_evaluation);
  c_deformed_position_of_control_->canFreeData = false;
  emxFree_real_T(&c_deformed_position_of_control_);
  control_points->canFreeData = false;
  emxFree_real_T(&control_points);
  emlrtHeapReferenceStackLeaveFcnR2012b(&st);
}

/* End of code generation (_coder_MLS_getDeform_api.c) */
