I've learnt the loop subdivision recently and I implemented some of it by Qt. I want to subdivide "the triangle" by calculating the position of the new point, splitting the edge and flip the edge.But it seems that there are some problems about my own "splitEdge()" .
I don't know why.many thanks.
// definition.
struct HalfEdge{
bool old;
Vertex * origin;
HalfEdge * pair;
HalfEdge * prev;
HalfEdge * next;
Face * face;
};
struct Vertex{
bool old;
QVector3D pos, newPos;
HalfEdge * edge;
};
struct Face{
HalfEdge * edge;
};
// the problem splitEgde()
void Mesh::splitEdge(HalfEdge *e){
HalfEdge * prev = e->prev;
HalfEdge * next = e->next;
HalfEdge * p = e->pair;
Vertex * v = new Vertex();
v->pos = v->newPos = newVertexPosition[e];
v->old = false;
HalfEdge * eNext = new HalfEdge();
HalfEdge * vOut = new HalfEdge();
HalfEdge * vIn = new HalfEdge();
Face * vFace = new Face();
/******** face A *******/
// edge
e->next = eNext;
eNext->old = false;
eNext->origin = v;
eNext->pair = vIn;
eNext->prev = e;
eNext->next = prev;
eNext->face = e->face;
prev->prev = eNext;
// vertex
// face
e->face->edge = e;
/******** face A *******/
/******** face B *******/
// edge
vOut->old = true; // !!
vOut->origin = v;
vOut->pair = NULL;
vOut->prev = vIn;
vOut->next = next;
vOut->face = vFace;
next->prev = vOut;
next->next = vIn;
next->face = vFace;
vIn->old = false;
vIn->origin = prev->origin;
vIn->pair = eNext;
vIn->prev = next;
vIn->next = vOut;
vIn->face = vFace;
// vertex
v->edge = eNext;
// face
vFace->edge = vOut;
/******** face B *******/
//the rest is updating the data
}
And the error:build-Subdivision-Desktop_Qt_5_12_1_MinGW_64_bit-Debug/debug/SubdivisionWithLighting.exe crashed.
I've already done,it's a stupid mistake.I forgot to deal with the situation that the edge inside the graph.Now I've implemented it perfectly.