matlabinterface.cc

Go to the documentation of this file.
00001 
00004 
00005 //
00006 // Copyright (c) 2004-2007 University of Southern California
00007 // Rob Peters <rjpeters at usc dot edu>
00008 //
00009 // created: Tue Dec 21 11:10:52 2004
00010 // commit: $Id: matlabinterface.cc 10065 2007-04-12 05:54:56Z rjpeters $
00011 // $HeadURL: file:///lab/rjpeters/svnrepo/code/trunk/groovx/src/mtx/matlabinterface.cc $
00012 //
00014 
00015 #ifndef GROOVX_PKGS_MTX_MATLABINTERFACE_CC_UTC20050626084022_DEFINED
00016 #define GROOVX_PKGS_MTX_MATLABINTERFACE_CC_UTC20050626084022_DEFINED
00017 
00018 #include "matlabinterface.h"
00019 
00020 #ifndef GVX_NO_MATLAB
00021 
00022 #include "mtx/mtx.h"
00023 
00024 #include "rutz/error.h"
00025 
00026 #include "rutz/trace.h"
00027 
00028 namespace
00029 {
00030   data_block* new_data_block(mxArray* a,
00031                              mtx_policies::storage_policy s)
00032   {
00033     if (!mxIsDouble(a))
00034       throw rutz::error("cannot construct a mtx "
00035                         "with a non-'double' mxArray", SRC_POS);
00036 
00037     return data_block::make(mxGetPr(a), mxGetM(a), mxGetN(a), s);
00038   }
00039 
00040   data_block* new_data_block(const mxArray* a,
00041                              mtx_policies::storage_policy s)
00042   {
00043     if (!mxIsDouble(a))
00044       throw rutz::error("cannot construct a mtx "
00045                         "with a non-'double' mxArray", SRC_POS);
00046 
00047     if (s != mtx_policies::BORROW && s != mtx_policies::COPY)
00048       throw rutz::error("cannot construct a mtx from a const mxArray* "
00049                         "unless the storage_policy is COPY or BORROW",
00050                         SRC_POS);
00051 
00052     return data_block::make(mxGetPr(a), mxGetM(a), mxGetN(a), s);
00053   }
00054 }
00055 
00056 mtx make_mtx(mxArray* a, mtx_policies::storage_policy s)
00057 {
00058 GVX_TRACE("make_mtx(mxArray*, storage_policy)");
00059   return mtx(mtx_specs(mxGetM(a), mxGetN(a)),
00060              data_holder(new_data_block(a, s)));
00061 }
00062 
00063 mtx make_mtx(const mxArray* a, mtx_policies::storage_policy s)
00064 {
00065 GVX_TRACE("make_mtx(const mxArray*, storage_policy)");
00066   return mtx(mtx_specs(mxGetM(a), mxGetN(a)),
00067              data_holder(new_data_block(a, s)));
00068 }
00069 
00070 mxArray* make_mxarray(const mtx& m)
00071 {
00072 GVX_TRACE("make_mxarray");
00073   mxArray* result_mx =
00074     mxCreateDoubleMatrix(m.mrows(), m.ncols(), mxREAL);
00075 
00076   std::copy(m.colmaj_begin(), m.colmaj_end(), mxGetPr(result_mx));
00077 
00078   return result_mx;
00079 }
00080 
00081 #endif // HAVE_MATLAB
00082 
00083 static const char __attribute__((used)) vcid_groovx_pkgs_mtx_matlabinterface_cc_utc20050626084022[] = "$Id: matlabinterface.cc 10065 2007-04-12 05:54:56Z rjpeters $ $HeadURL: file:
00084 #endif // !GROOVX_PKGS_MTX_MATLABINTERFACE_CC_UTC20050626084022_DEFINED

The software described here is Copyright (c) 1998-2005, Rob Peters.
This page was generated Wed Dec 3 06:49:39 2008 by Doxygen version 1.5.5.