I was trying to draw the HalfEdge Data Structure solid with openGL, and I have to subdivision face which may have holes and turn the face to triangles. I use the poly2tri lib. Relate Code is blow.
void Renderer::Poly2Triangles(Face* face)
{
Plane2D plane(face);
std::vector<p2t::Point*> all_points;
std::vector<p2t::Point*> out_points;
std::vector<p2t::Point*> in_points;
//outter loop
Loop* outerLoop = face->fLoops;
while (outerLoop->IsInnerLoop) outerLoop = outerLoop->lNext;
glm::vec3 firstEdge = (outerLoop->lHEdge->destination->Pos).position - (outerLoop->lHEdge->origin->Pos).position;
glm::vec3 secondEdge = (outerLoop->lHEdge->Next->destination->Pos).position - (outerLoop->lHEdge->Next->origin->Pos).position;
glm::vec3 norm = glm::normalize(glm::cross(firstEdge, secondEdge));
HalfEdge* he = outerLoop->lHEdge;
do {
glm::vec2 p = plane.Space3DToPlane2D((he->origin->Pos).position);
p2t::Point* point = new p2t::Point(p.x, p.y);
all_points.push_back(point);
out_points.push_back(point);
he = he->Next;
} while (he != outerLoop->lHEdge);
p2t::CDT cdt(std::move(out_points)); //-----------first link error here---------------
//inner loop
Loop* innerLoop = face->fLoops;
do {
if (!(innerLoop->IsInnerLoop)) {
innerLoop = innerLoop->lNext;
continue;
}
HalfEdge* he = innerLoop->lHEdge;
do {
glm::vec2 p = plane.Space3DToPlane2D((he->origin->Pos).position);
p2t::Point* point = new p2t::Point(p.x, p.y);
in_points.push_back(point);
all_points.push_back(point);
he = he->Next;
} while (he != innerLoop->lHEdge);
cdt.AddHole(std::move(in_points));//----------------link error-------------
innerLoop = innerLoop->lNext;
} while (innerLoop != face->fLoops);
cdt.Triangulate();//-----------------------link error------------------------
auto tris = cdt.GetTriangles();//------------------------link error----------------------
for (auto tri : tris) {
Triangle triangle;
for (int i = 0; i < 3; i++) {
auto _p = tri->GetPoint(i);
triangle.vertex[i] = plane.Plane2DToSpace3D(glm::vec2(_p->x, _p->y));
triangle.normal[i] = norm;
}
triangles.push_back(triangle);
}
for (auto p : all_points)
delete p;
}
When I try to run it, it shows five link error:
-
Renderer.obj : error LNK2019: 无法解析的外部符号 “public: __thiscall p2t::CDT::CDT(class std::vector<struct p2t::Point *,class std::allocator<struct p2t::Point *> >)” (??0CDT@p2t@@QAE@V?$vector@PAUPoint@p2t@@V?$allocator@PAUPoint@p2t@@@std@@@std@@@Z),函数 “private: void __thiscall Renderer::Poly2Triangles(class Face *)” (?Poly2Triangles@Renderer@@AAEXPAVFace@@@Z) 中引用了该符号
-
1>Renderer.obj : error LNK2019: 无法解析的外部符号 “public: __thiscall p2t::CDT::~CDT(void)” (??1CDT@p2t@@QAE@XZ),函数 “private: void __thiscall Renderer::Poly2Triangles(class Face *)” (?Poly2Triangles@Renderer@@AAEXPAVFace@@@Z) 中引用了该符号
-
1>Renderer.obj : error LNK2019: 无法解析的外部符号 “public: void __thiscall p2t::CDT::AddHole(class std::vector<struct p2t::Point *,class std::allocator<struct p2t::Point *> >)” (?AddHole@CDT@p2t@@QAEXV?$vector@PAUPoint@p2t@@V?$allocator@PAUPoint@p2t@@@std@@@std@@@Z),函数 “private: void __thiscall Renderer::Poly2Triangles(class Face *)” (?Poly2Triangles@Renderer@@AAEXPAVFace@@@Z) 中引用了该符号
-
1>Renderer.obj : error LNK2019: 无法解析的外部符号 “public: void __thiscall p2t::CDT::Triangulate(void)” (?Triangulate@CDT@p2t@@QAEXXZ),函数 “private: void __thiscall Renderer::Poly2Triangles(class Face *)” (?Poly2Triangles@Renderer@@AAEXPAVFace@@@Z) 中引用了该符号
-
1>Renderer.obj : error LNK2019: 无法解析的外部符号 “public: class std::vector<class p2t::Triangle *,class std::allocator<class p2t::Triangle *> > __thiscall p2t::CDT::GetTriangles(void)” (?GetTriangles@CDT@p2t@@QAE?AV?$vector@PAVTriangle@p2t@@V?$allocator@PAVTriangle@p2t@@@std@@@std@@XZ),函数 “private: void __thiscall Renderer::Poly2Triangles(class Face *)” (?Poly2Triangles@Renderer@@AAEXPAVFace@@@Z) 中引用了该符号
just all the p2t::CDT class member was unresolved external symbol: CDT、~CDT、CDT::AddHole、 CDT::Triangulate、CDT::GetTriangles
I use VS2022 build this project, I add the poly2tri header file to the include file path in project properties. the file structure is blow and I just #include "poly2tri.h"
. it actually pass the compile.
I have no idea what’s going on, I want to find errors and correct them. Or I’m happy to know other way to subdivision polygon to triangles.
1