简体   繁体   English

如何在C ++中分割边缘

[英]How to split the edge in C++

I've learnt the loop subdivision recently and I implemented some of it by Qt. 我最近了解了循环细分,并通过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()" . 我想通过计算新点的位置,分割边缘并翻转边缘来细分“三角形”。但是似乎我自己的“ 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. 并且错误:build-Subdivision-Desktop_Qt_5_12_1_MinGW_64_bit-Debug / debug / SubdivisionWithLighting.exe崩溃了。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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