コード例 #1
0
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{
  if(nrhs < 3)
    mexErrMsgTxt("Minimum of three inputs required.");
  if (nlhs > 1)
    mexErrMsgTxt("Too many output arguments.");

  for (int i = 1 ; i < nrhs-1 ; ++i)
  {
    if (mxIsEmpty(prhs[i]) || (!mxIsChar(prhs[i]) && ((mxGetClassID(prhs[i]) != mxDOUBLE_CLASS) || mxIsComplex(prhs[i]) || (mxGetNumberOfElements(prhs[i]) != 1))))
      mexErrMsgTxt("Metadata's label or index must be set by a non-empty string or an integer (double value) respectively.");
  }
  if (!mxIsChar(prhs[nrhs-1]))
    mexErrMsgTxt("Metadata's description must be set by a string");
  
  
  btk::Acquisition::Pointer acq = btk_MOH_get_object<btk::Acquisition>(prhs[0]);
  btk::MetaData::Iterator it;
  btk::MetaData::Pointer parent = btkMXExtractMetaDataIterator(&it, nrhs-2, prhs, acq->GetMetaData());
  
  size_t strlen_ = (mxGetM(prhs[nrhs-1]) * mxGetN(prhs[nrhs-1]) * sizeof(mxChar)) + 1;
  char* d = (char*)mxMalloc(strlen_);
  mxGetString(prhs[nrhs-1], d, strlen_);
  (*it)->SetDescription(d);
  mxFree(d);
  
  if (nlhs > 0)
    plhs[0] = btkMXCreateMetaDataStructure(acq->GetMetaData());
};
コード例 #2
0
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{
  if(nrhs < 2)
    mexErrMsgTxt("Two inputs required.");
  if (nlhs > 1)
    mexErrMsgTxt("Too many output arguments.");

  for (int i = 1 ; i < nrhs ; ++i)
  {
    if (mxIsEmpty(prhs[i]) || (!mxIsChar(prhs[i]) && ((mxGetClassID(prhs[i]) != mxDOUBLE_CLASS) || mxIsComplex(prhs[i]) || (mxGetNumberOfElements(prhs[i]) != 1))))
      mexErrMsgTxt("Metadata's label or index must be set by a non-empty string or an integer (double value) respectively.");
  }
  
  btk::Acquisition::Pointer acq = btk_MOH_get_object<btk::Acquisition>(prhs[0]);
  btk::MetaData::Iterator it;
  btk::MetaData::Pointer parent = btkMXExtractMetaDataIterator(&it, nrhs-1,  prhs, acq->GetMetaData());
  
  parent->RemoveChild(it);
  
  if (nlhs > 0)
    plhs[0] = btkMXCreateMetaDataStructure(acq->GetMetaData());
};
コード例 #3
0
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{
  if(nrhs < 3)
    mexErrMsgTxt("Minimum of three inputs required.");
  if (nlhs > 1)
    mexErrMsgTxt("Too many output arguments.");

  for (int i = 1 ; i < nrhs-2 ; ++i)
  {
    if (mxIsEmpty(prhs[i]) || (!mxIsChar(prhs[i]) && ((mxGetClassID(prhs[i]) != mxDOUBLE_CLASS) || mxIsComplex(prhs[i]) || (mxGetNumberOfElements(prhs[i]) != 1))))
      mexErrMsgTxt("Metadata's label or index must be set by a non-empty string or an integer respectively.");
  }
  if ((mxGetClassID(prhs[nrhs-2]) != mxDOUBLE_CLASS) || mxIsComplex(prhs[nrhs-2]) || (mxGetNumberOfElements(prhs[nrhs-2]) != 1))
    mexErrMsgTxt("The index for the metadata's value must be set by a single integer");
  bool invalidData = false;
  if (mxIsCell(prhs[nrhs-1]))
  {
    if (mxGetNumberOfElements(prhs[nrhs-1]) != 1)
      invalidData = true;
  }
  else if (mxIsChar(prhs[nrhs-1]))
  {
    if (mxGetM(prhs[nrhs-1]) != 1)
      invalidData = true;
  }
  else if ((mxGetClassID(prhs[nrhs-1]) != mxDOUBLE_CLASS) || mxIsComplex(prhs[nrhs-1]) || (mxGetNumberOfElements(prhs[nrhs-1]) != 1)) 
    invalidData = true;
  if (invalidData)
    mexErrMsgTxt("Unsupported metadata's value or the number of elements is greater than 1.");
  
  btk::Acquisition::Pointer acq = btk_MOH_get_object<btk::Acquisition>(prhs[0]);
  btk::MetaData::Iterator it;
  btk::MetaData::Pointer parent = btkMXExtractMetaDataIterator(&it, nrhs-3, prhs, acq->GetMetaData());
  
  if (!(*it)->HasInfo())
    mexErrMsgTxt("No metadata's info.");
  
  size_t index = static_cast<size_t>(mxGetScalar(prhs[nrhs-2])) - 1;
  if (index >= (*it)->GetInfo()->GetValues().size())
    mexErrMsgTxt("Invalid index to extract one metadata's value.");
    
  const mxArray* data = 0; 
  if (mxIsCell(prhs[nrhs-1]))
  {
    data = mxGetCell(prhs[nrhs-1], 0);
    if (!data || !mxIsChar(data))
      mexErrMsgTxt("Error in the value's format: only a string is accepted in cell.");
  }
  else
    data = prhs[nrhs-1];
  
  if (mxIsChar(data))
  {
    size_t strlen_ = (mxGetM(data) * mxGetN(data) * sizeof(mxChar)) + 1;
    char* d = (char*)mxMalloc(strlen_);
    mxGetString(data, d, strlen_);
    (*it)->GetInfo()->SetValue(static_cast<int>(index), d);
    mxFree(d);
  }
  else
    (*it)->GetInfo()->SetValue(static_cast<int>(index), mxGetScalar(data));
  
  if (nlhs > 0)
    plhs[0] = btkMXCreateMetaDataStructure(acq->GetMetaData());
};