summaryrefslogtreecommitdiff
path: root/thirdparty/thekla_atlas/nvmesh/halfedge/Edge.h
blob: 25c47f48606805c7ddbdc04e393254037df3b1d8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
// This code is in the public domain -- castanyo@yahoo.es

#pragma once
#ifndef NV_MESH_HALFEDGE_EDGE_H
#define NV_MESH_HALFEDGE_EDGE_H

#include "nvmath/Vector.h"

namespace nv
{
    namespace HalfEdge { class Vertex; class Face; class Edge; }

    /// Half edge edge. 
    class HalfEdge::Edge
    {
        NV_FORBID_COPY(Edge);
    public:

        uint id;

        Edge * next;
        Edge * prev;	// This is not strictly half-edge, but makes algorithms easier and faster.
        Edge * pair;
        Vertex * vertex;
        Face * face;


        // Default constructor.
        Edge(uint id) : id(id), next(NULL), prev(NULL), pair(NULL), vertex(NULL), face(NULL)
        {
        }


        // Vertex queries.
        const Vertex * from() const { return vertex; }
        Vertex * from() { return vertex; }

        const Vertex * to() const { return pair->vertex; }  // This used to be 'next->vertex', but that changed often when the connectivity of the mesh changes.
        Vertex * to() { return pair->vertex; }


        // Edge queries.
        void setNext(Edge * e) { next = e; if (e != NULL) e->prev = this; }
        void setPrev(Edge * e) { prev = e; if (e != NULL) e->next = this; }

        // @@ Add these helpers:
        //Edge * nextBoundary();
        //Edge * prevBoundary();


        // @@ It would be more simple to only check m_pair == NULL
        // Face queries.
        bool isBoundary() const { return !(face && pair->face); }

        // @@ This is not exactly accurate, we should compare the texture coordinates...
        bool isSeam() const { return vertex != pair->next->vertex || next->vertex != pair->vertex; }

        bool isValid() const;

        // Geometric queries.
        Vector3 midPoint() const;
        float length() const;
        float angle() const;

    };

} // nv namespace


#endif // NV_MESH_HALFEDGE_EDGE_H