I'm trying for a while to define an edge in CDT. Below is my code. The first function works fine, but the compilation of the second function throws this error: no matching function for call to CDT::Edge::Edge(). I also attempted numerous other trials, with no luck.
typedef CDT::V2d<double> Vertex;
typedef CDT::Edge Edge;
typedef CDT::Triangulation<double> Triangulation;
arma::umat Rcpp_delaunay(const arma::mat & points){
Triangulation cdt(CDT::VertexInsertionOrder::AsProvided);
size_t npoints = points.n_rows;
std::vector<Vertex> vertices(npoints);
for (size_t i = 0; i < npoints; i) {
const arma::rowvec row_i = points.row(i);
vertices[i] = Vertex::make(row_i(0), row_i(1));
}
cdt.insertVertices(vertices);
cdt.eraseSuperTriangle();
const CDT::TriangleVec triangles = cdt.triangles;
arma::umat out(triangles.size(), 3);
for(size_t i = 0; i < triangles.size(); i){
const CDT::VerticesArr3 trgl = triangles[i].vertices;
out(i, 0) = trgl[0];
out(i, 1) = trgl[1];
out(i, 2) = trgl[2];
}
return out;
}
arma::umat Rcpp_constrained_delaunay(
const arma::mat & points, const arma::umat & edges
){
Triangulation cdt(CDT::VertexInsertionOrder::AsProvided);
size_t npoints = points.n_rows;
std::vector<Vertex> vertices(npoints);
for (size_t i = 0; i < npoints; i) {
const arma::rowvec row_i = points.row(i);
vertices[i] = Vertex::make(row_i(0), row_i(1));
}
size_t nedges = edges.n_rows;
std::vector<Edge> Edges(nedges);
for (size_t i = 0; i < nedges; i) {
const arma::urowvec row_i = edges.row(i);
Edge edge = Edge(row_i(0), row_i(1));
Edges[i] = edge;
}
cdt.insertVertices(vertices);
cdt.insertEdges(Edges);
cdt.eraseOuterTrianglesAndHoles();
const CDT::TriangleVec triangles = cdt.triangles;
arma::umat out(triangles.size(), 3);
for(size_t i = 0; i < triangles.size(); i){
const CDT::VerticesArr3 trgl = triangles[i].vertices;
out(i, 0) = trgl[0];
out(i, 1) = trgl[1];
out(i, 2) = trgl[2];
}
return out;
}
CodePudding user response:
Edge
does not have a default constructor, so you can’t give a vector<Edge>
an initial size (since that would require each element to be initially default-constructed). Instead, make the vector empty to begin with (you can reserve()
capacity for it if you like) and then add edge
with push_back()
… or, better yet, construct it in-place with emplace_back()
.