简体   繁体   中英

How to split the edge in C++

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.

我已经做完了,这是一个愚蠢的错误。我忘了处理图形中边缘的情况。现在,我已经完美实现了。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM