hedart.h 4.5 KB
Newer Older
Maciej Suminski's avatar
Maciej Suminski committed
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
/*
 * Copyright (C) 1998, 2000-2007, 2010, 2011, 2012, 2013 SINTEF ICT,
 * Applied Mathematics, Norway.
 *
 * Contact information: E-mail: tor.dokken@sintef.no                      
 * SINTEF ICT, Department of Applied Mathematics,                         
 * P.O. Box 124 Blindern,                                                 
 * 0314 Oslo, Norway.                                                     
 *
 * This file is part of TTL.
 *
 * TTL is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version. 
 *
 * TTL is distributed in the hope that it will be useful,        
 * but WITHOUT ANY WARRANTY; without even the implied warranty of         
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public
 * License along with TTL. If not, see
 * <http://www.gnu.org/licenses/>.
 *
 * In accordance with Section 7(b) of the GNU Affero General Public
 * License, a covered work must retain the producer line in every data
 * file that is created or manipulated using TTL.
 *
 * Other Usage
 * You can be released from the requirements of the license by purchasing
 * a commercial license. Buying such a license is mandatory as soon as you
 * develop commercial activities involving the TTL library without
 * disclosing the source code of your own applications.
 *
 * This file may be used in accordance with the terms contained in a
 * written agreement between you and SINTEF ICT. 
 */

#ifndef _HALF_EDGE_DART_
#define _HALF_EDGE_DART_

#include <ttl/halfedge/hetriang.h>

45 46 47 48 49 50 51 52 53 54 55 56
namespace hed
{
/**
 * \class Dart
 * \brief \b %Dart class for the half-edge data structure.
 *
 * See \ref api for a detailed description of how the member functions
 * should be implemented.
 */
class DART
{
    EDGE_PTR m_edge;
Maciej Suminski's avatar
Maciej Suminski committed
57

58 59
    /// Dart direction: true if dart is counterclockwise in face
    bool m_dir;
Maciej Suminski's avatar
Maciej Suminski committed
60

61
public:
Maciej Suminski's avatar
Maciej Suminski committed
62
    /// Default constructor
63 64 65 66
    DART()
    {
        m_dir = true;
    }
Maciej Suminski's avatar
Maciej Suminski committed
67 68

    /// Constructor
69 70 71 72 73
    DART( const EDGE_PTR& aEdge, bool aDir = true )
    {
        m_edge = aEdge;
        m_dir = aDir;
    }
Maciej Suminski's avatar
Maciej Suminski committed
74 75

    /// Copy constructor
76 77 78 79 80
    DART( const DART& aDart )
    {
        m_edge = aDart.m_edge;
        m_dir  = aDart.m_dir;
    }
Maciej Suminski's avatar
Maciej Suminski committed
81 82

    /// Destructor
83 84 85
    ~DART()
    {
    }
Maciej Suminski's avatar
Maciej Suminski committed
86 87

    /// Assignment operator
88 89 90 91 92 93 94 95
    DART& operator=( const DART& aDart )
    {
        if( this == &aDart )
            return *this;

        m_edge = aDart.m_edge;
        m_dir = aDart.m_dir;

Maciej Suminski's avatar
Maciej Suminski committed
96 97 98 99
        return *this;
    }

    /// Comparing dart objects
100 101 102
    bool operator==( const DART& aDart ) const
    {
        return ( aDart.m_edge == m_edge && aDart.m_dir == m_dir );
Maciej Suminski's avatar
Maciej Suminski committed
103 104 105
    }

    /// Comparing dart objects
106 107 108
    bool operator!=( const DART& aDart ) const
    {
        return !( aDart == *this );
Maciej Suminski's avatar
Maciej Suminski committed
109 110 111
    }

    /// Maps the dart to a different node
112 113 114 115 116
    DART& Alpha0()
    {
        m_dir = !m_dir;
        return *this;
    }
Maciej Suminski's avatar
Maciej Suminski committed
117 118

    /// Maps the dart to a different edge
119 120 121 122 123 124 125 126 127 128 129 130 131 132
    DART& Alpha1()
    {
        if( m_dir )
        {
            m_edge = m_edge->GetNextEdgeInFace()->GetNextEdgeInFace();
            m_dir = false;
        }
        else
        {
            m_edge = m_edge->GetNextEdgeInFace();
            m_dir = true;
        }

        return *this;
Maciej Suminski's avatar
Maciej Suminski committed
133 134 135
    }

    /// Maps the dart to a different triangle. \b Note: the dart is not changed if it is at the boundary!
136 137 138 139 140 141 142 143 144 145
    DART& Alpha2()
    {
        if( m_edge->GetTwinEdge() )
        {
            m_edge = m_edge->GetTwinEdge();
            m_dir = !m_dir;
        }

        // else, the dart is at the boundary and should not be changed
        return *this;
Maciej Suminski's avatar
Maciej Suminski committed
146 147 148 149
    }

    /** @name Utilities not required by TTL */
    //@{
150 151 152 153 154
    void Init( const EDGE_PTR& aEdge, bool aDir = true )
    {
        m_edge = aEdge;
        m_dir = aDir;
    }
Maciej Suminski's avatar
Maciej Suminski committed
155

156 157 158 159
    double X() const
    {
        return GetNode()->GetX();
    }
Maciej Suminski's avatar
Maciej Suminski committed
160

161 162 163 164
    double Y() const
    {
        return GetNode()->GetY();
    }
Maciej Suminski's avatar
Maciej Suminski committed
165

166 167 168 169
    bool IsCCW() const
    {
        return m_dir;
    }
Maciej Suminski's avatar
Maciej Suminski committed
170

171 172 173 174
    const NODE_PTR& GetNode() const
    {
        return m_dir ? m_edge->GetSourceNode() : m_edge->GetTargetNode();
    }
Maciej Suminski's avatar
Maciej Suminski committed
175

176 177 178 179
    const NODE_PTR& GetOppositeNode() const
    {
        return m_dir ? m_edge->GetTargetNode() : m_edge->GetSourceNode();
    }
Maciej Suminski's avatar
Maciej Suminski committed
180

181 182 183 184 185 186 187
    EDGE_PTR& GetEdge()
    {
        return m_edge;
    }

    //@} // End of Utilities not required by TTL
};
Maciej Suminski's avatar
Maciej Suminski committed
188

189
} // End of hed namespace
Maciej Suminski's avatar
Maciej Suminski committed
190 191

#endif