You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
88 lines
2.9 KiB
88 lines
2.9 KiB
3 years ago
|
#define _USE_MATH_DEFINES
|
||
|
|
||
|
#include <iostream>
|
||
|
#include "CVT/CVTGenerator.h"
|
||
|
//#include "CVT/utils.h"
|
||
|
#include <igl/readOBJ.h>
|
||
|
#include <igl/writeOBJ.h>
|
||
|
#include <igl/writeSTL.h>
|
||
|
#include <tetwild/tetwild.h>
|
||
|
|
||
|
#include "mex.hpp"
|
||
|
#include "mexAdapter.hpp"
|
||
|
#include "MatlabDataArray.hpp"
|
||
|
#include <omp.h>
|
||
|
|
||
|
class MexFunction : public matlab::mex::Function {
|
||
|
public:
|
||
|
void operator()(matlab::mex::ArgumentList outputs, matlab::mex::ArgumentList inputs) {
|
||
|
|
||
|
checkArguments(outputs, inputs);
|
||
|
|
||
|
matlab::data::TypedArray<double> seeds = std::move(inputs[0]);
|
||
|
//matlab::data::TypedArray<double> query_pnts = std::move(inputs[1]); // points need to be projected
|
||
|
|
||
|
mexVoronoi(seeds);
|
||
|
|
||
|
matlab::data::ArrayFactory factory;
|
||
|
matlab::data::TypedArray<double> m_edges = factory.createArray<double>({ 1, 1 });
|
||
|
m_edges[0][0] = 0;
|
||
|
|
||
|
// for each patch: return projected center cbns, orignal boundary cbns
|
||
|
// return each cell, each patch
|
||
|
outputs[0] = m_edges;
|
||
|
}
|
||
|
|
||
|
// TODO:
|
||
|
void checkArguments(matlab::mex::ArgumentList outputs, matlab::mex::ArgumentList inputs) {
|
||
|
std::shared_ptr<matlab::engine::MATLABEngine> matlabPtr = getEngine();
|
||
|
matlab::data::ArrayFactory factory;
|
||
|
|
||
|
if (inputs.size() != 1) {
|
||
|
matlabPtr->feval(u"error",
|
||
|
0, std::vector<matlab::data::Array>({ factory.createScalar("Four inputs required") }));
|
||
|
}
|
||
|
|
||
|
if (inputs[0].getDimensions()[1] != 3) {
|
||
|
matlabPtr->feval(u"error",
|
||
|
0, std::vector<matlab::data::Array>({ factory.createScalar("Seeds input 1 must be NX2 dimension") }));
|
||
|
}
|
||
|
|
||
|
if (inputs[0].getType() != matlab::data::ArrayType::DOUBLE ||
|
||
|
inputs[0].getType() == matlab::data::ArrayType::COMPLEX_DOUBLE) {
|
||
|
matlabPtr->feval(u"error",
|
||
|
0, std::vector<matlab::data::Array>({ factory.createScalar("Seeds Input 1 must be a noncomplex scalar double") }));
|
||
|
}
|
||
|
if (outputs.size() > 1) {
|
||
|
matlabPtr->feval(u"error", 0,
|
||
|
std::vector<matlab::data::Array>({ factory.createScalar("Only one output is returned") }));
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void mexVoronoi(matlab::data::TypedArray<double> seeds)
|
||
|
{
|
||
|
Eigen::MatrixXd V;
|
||
|
Eigen::MatrixXi F;
|
||
|
igl::readOBJ("F:\\project\\7-current_opt\\opt-cvt-3D\\data\\model\\cylinder.obj", V, F);
|
||
|
std::cout << "V: " << V.rows() << " " << V.cols() << std::endl;
|
||
|
std::cout << "F: " << F.rows() << " " << F.cols() << std::endl;
|
||
|
CVTGenerator generator(V, F);
|
||
|
|
||
|
int p_n = 10;
|
||
|
std::vector<Eigen::Vector3d> samples;
|
||
|
Eigen::AlignedBox3d box;
|
||
|
box.min() = V.colwise().minCoeff();
|
||
|
box.max() = V.colwise().maxCoeff();
|
||
|
// random sample in bounding box
|
||
|
for (int i = 0; i < p_n; ++i) {
|
||
|
Eigen::Vector3d p;
|
||
|
p.x() = box.min().x() + (box.max().x() - box.min().x()) * rand() / (RAND_MAX + 1.0);
|
||
|
p.y() = box.min().y() + (box.max().y() - box.min().y()) * rand() / (RAND_MAX + 1.0);
|
||
|
p.z() = box.min().z() + (box.max().z() - box.min().z()) * rand() / (RAND_MAX + 1.0);
|
||
|
samples.push_back(p);
|
||
|
std::cout << p.transpose() << std::endl;
|
||
|
}
|
||
|
|
||
|
std::vector<cvt::VoronoiCell> cells = generator.get_patched_cvt(samples, 10);
|
||
|
}
|
||
|
};
|