17 map<int,Ptr<Subdiv2D> > obj_;
21 (
"NextAroundOrg", cv::Subdiv2D::NEXT_AROUND_ORG)
22 (
"NextAroundDst", cv::Subdiv2D::NEXT_AROUND_DST)
23 (
"PrevAroundOrg", cv::Subdiv2D::PREV_AROUND_ORG)
24 (
"PrevAroundDst", cv::Subdiv2D::PREV_AROUND_DST)
25 (
"NextAroundLeft", cv::Subdiv2D::NEXT_AROUND_LEFT)
26 (
"NextAroundRight", cv::Subdiv2D::NEXT_AROUND_RIGHT)
27 (
"PrevAroundLeft", cv::Subdiv2D::PREV_AROUND_LEFT)
28 (
"PrevAroundRight", cv::Subdiv2D::PREV_AROUND_RIGHT);
32 (cv::Subdiv2D::PTLOC_ERROR,
"Error")
33 (cv::Subdiv2D::PTLOC_OUTSIDE_RECT,
"OutsideRect")
34 (cv::Subdiv2D::PTLOC_INSIDE,
"Inside")
35 (cv::Subdiv2D::PTLOC_VERTEX,
"Vertex")
36 (cv::Subdiv2D::PTLOC_ON_EDGE,
"OnEdge");
46 void mexFunction(
int nlhs, mxArray *plhs[],
int nrhs,
const mxArray *prhs[])
52 vector<MxArray> rhs(prhs, prhs+nrhs);
53 int id = rhs[0].toInt();
54 string method(rhs[1].toString());
57 if (method ==
"new") {
58 nargchk((nrhs==2 || nrhs==3) && nlhs<=1);
59 obj_[++last_id] = (nrhs == 3) ?
60 makePtr<Subdiv2D>(rhs[2].toRect()) : makePtr<Subdiv2D>();
66 Ptr<Subdiv2D> obj = obj_[id];
67 if (method ==
"delete") {
71 else if (method ==
"initDelaunay") {
73 obj->initDelaunay(rhs[2].toRect());
75 else if (method ==
"insert") {
77 if (rhs[2].isNumeric() && rhs[2].numel() == 2) {
79 int curr_point = obj->insert(rhs[2].toPoint2f());
84 obj->insert(rhs[2].toVector<Point2f>());
87 else if (method ==
"locate") {
89 Point2f pt(rhs[2].toPoint2f());
91 int location = obj->locate(pt, edge, vertex);
92 plhs[0] =
MxArray(PointLocationInvMap[location]);
98 else if (method ==
"findNearest") {
100 Point2f pt(rhs[2].toPoint2f()), nearestPt;
101 int vertex = obj->findNearest(pt, (nlhs>1) ? &nearestPt : NULL);
106 else if (method ==
"getEdgeList") {
108 vector<Vec4f> edgeList;
109 obj->getEdgeList(edgeList);
112 else if (method ==
"getTriangleList") {
114 vector<Vec6f> triangleList;
115 obj->getTriangleList(triangleList);
116 plhs[0] =
MxArray(triangleList);
118 else if (method ==
"getVoronoiFacetList") {
120 vector<int> idx(rhs[2].toVector<int>());
121 vector<vector<Point2f> > facetList;
122 vector<Point2f> facetCenters;
123 obj->getVoronoiFacetList(idx, facetList, facetCenters);
126 plhs[1] =
MxArray(facetCenters);
128 else if (method ==
"getVertex") {
130 int vertex = rhs[2].toInt();
132 Point2f pt = obj->getVertex(vertex, (nlhs>1) ? &firstEdge : NULL);
137 else if (method ==
"getEdge") {
139 int edge = rhs[2].toInt();
140 int nextEdgeType = EdgeTypeMap[rhs[3].toString()];
141 int e = obj->getEdge(edge, nextEdgeType);
144 else if (method ==
"nextEdge") {
146 int edge = rhs[2].toInt();
147 int e = obj->nextEdge(edge);
150 else if (method ==
"rotateEdge") {
152 int edge = rhs[2].toInt();
153 int rotate = rhs[3].toInt();
154 int e = obj->rotateEdge(edge, rotate);
157 else if (method ==
"symEdge") {
159 int edge = rhs[2].toInt();
160 int e = obj->symEdge(edge);
163 else if (method ==
"edgeOrg") {
165 int edge = rhs[2].toInt();
167 int e = obj->edgeOrg(edge, (nlhs>1) ? &orgpt : NULL);
172 else if (method ==
"edgeDst") {
174 int edge = rhs[2].toInt();
176 int e = obj->edgeDst(edge, (nlhs>1) ? &dstpt : NULL);
182 mexErrMsgIdAndTxt(
"mexopencv:error",
183 "Unrecognized operation %s", method.c_str());
mxArray object wrapper for data conversion and manipulation.
void nargchk(bool cond)
Alias for input/ouput arguments number check.
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
Main entry called from Matlab.
Global constant definitions.
std::map wrapper with one-line initialization and lookup method.