Mexing chai3d

조회 수: 4 (최근 30일)
Carlos Martinez Suarez
Carlos Martinez Suarez 2021년 12월 13일
답변: Carlos Martinez Suarez 2021년 12월 14일
Hi! I have tried to create a .cpp using chai3d libraries and compile it in MATLAB via mex engine. But it looks like MATLAB connot recognise every chai3d file because it returns import errors. I am very lost with this task and any help will be really greatful.
  댓글 수: 1
Jan
Jan 2021년 12월 13일
You forgot to mention any details. Which input files cause which error? Which libraries are you using?

댓글을 달려면 로그인하십시오.

답변 (1개)

Carlos Martinez Suarez
Carlos Martinez Suarez 2021년 12월 14일
Hello, thanks for answering and sorry for not giving enough details, I'll try to explain it better.
I have downloaded the chai3d libraries from its official page: https://www.chai3d.org/download/releases
Then I have taken an example from MATLAB that compiles and works perfectly when using mex with Microsoft Visual 2017 c++ compiler (the compiler needed for chai3d).
Then I copy that example (called "prueba.cpp") in the folder where the chai3d libraries are downloaded:
Finally, I just add a line including the chai3d.h file: #include "chai3d.h". Here is where the problems come. When I try compiling after adding that line, MATLAB returns an error saying that chai3d.h cannot be found. This is solved changing the include sentence into #include "src/chai3d.h" as long as it is the right path. I do not really understand why I have to specify the full path when I added every folder to MATLAB paths.
When compiling with "src/chai3d.h", it returns another error that says that in one of the files of the library it cannot be found some files and this happens over and over when fixing the previous errors.
Thanks for answering so fast and I hope you can help me.
Example:
#include "mex.hpp"
#include "mexAdapter.hpp"
using namespace matlab::data;
using matlab::mex::ArgumentList;
using namespace std;
class MexFunction : public matlab::mex::Function {
public:
void operator()(ArgumentList outputs, ArgumentList inputs) {
checkArguments(outputs, inputs);
const double offSet = inputs[0][0];
TypedArray<double> doubleArray = std::move(inputs[1]);
for (auto& elem : doubleArray) {
elem += offSet;
}
outputs[0] = doubleArray;
}
void checkArguments(ArgumentList outputs, ArgumentList inputs) {
// Get pointer to engine
std::shared_ptr<matlab::engine::MATLABEngine> matlabPtr = getEngine();
// Get array factory
ArrayFactory factory;
// Check first input argument
if (inputs[0].getType() != ArrayType::DOUBLE ||
inputs[0].getType() == ArrayType::COMPLEX_DOUBLE ||
inputs[0].getNumberOfElements() != 1)
{
matlabPtr->feval(u"error",
0,
std::vector<Array>({ factory.createScalar("First input must scalar double") }));
}
// Check second input argument
if (inputs[1].getType() != ArrayType::DOUBLE ||
inputs[1].getType() == ArrayType::COMPLEX_DOUBLE)
{
matlabPtr->feval(u"error",
0,
std::vector<Array>({ factory.createScalar("Input must double array") }));
}
// Check number of outputs
if (outputs.size() > 1) {
matlabPtr->feval(u"error",
0,
std::vector<Array>({ factory.createScalar("Only one output is returned") }));
}
}
};

카테고리

Help CenterFile Exchange에서 Write C++ Functions Callable from MATLAB (MEX Files)에 대해 자세히 알아보기

태그

제품


릴리스

R2021a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by