hetraits.h 6.95 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 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 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176
/*
 * 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_TRAITS_
#define _HALF_EDGE_TRAITS_


#include <ttl/halfedge/hetriang.h>
#include <ttl/halfedge/hedart.h>


namespace hed {


  //------------------------------------------------------------------------------------------------
  // Traits class for the half-edge data structure
  //------------------------------------------------------------------------------------------------
  
  /** \struct TTLtraits
  *   \brief \b Traits class (static struct) for the half-edge data structure.
  *
  *   The member functions are those required by different function templates
  *   in the TTL. Documentation is given here to explain what actions
  *   should be carried out on the actual data structure as required by the functions
  *   in the \ref ttl namespace.
  *
  *   The source code of \c %HeTraits.h shows how the traits class is implemented for the
  *   half-edge data structure.
  * 
  *   \see \ref api
  *
  */

  struct TTLtraits {
    
    /** The floating point type used in calculations
    *   involving scalar products and cross products.
    */
    typedef double real_type;


    //----------------------------------------------------------------------------------------------
    // ------------------------------- Geometric Predicates Group ---------------------------------
    //----------------------------------------------------------------------------------------------

    /** @name Geometric Predicates */
    //@{

    //----------------------------------------------------------------------------------------------
    /** Scalar product between two 2D vectors represented as darts.\n
    *
    *   ttl_util::scalarProduct2d can be used.
    */
    static real_type scalarProduct2d(const Dart& v1, const Dart& v2) {
      Dart v10 = v1; v10.alpha0();
      Dart v20 = v2; v20.alpha0();
      return ttl_util::scalarProduct2d(v10.x()-v1.x(), v10.y()-v1.y(),
                                       v20.x()-v2.x(), v20.y()-v2.y());
    }


    //----------------------------------------------------------------------------------------------
    /** Scalar product between two 2D vectors.
    *   The first vector is represented by a dart \e v, and the second
    *   vector has direction from the source node of \e v to the point \e p.\n
    *
    *   ttl_util::scalarProduct2d can be used.
    */
    static real_type scalarProduct2d(const Dart& v, const NodePtr& p) {
      Dart d0 = v; d0.alpha0();
      return ttl_util::scalarProduct2d(d0.x() - v.x(), d0.y() - v.y(),
                                       p->GetX() - v.x(), p->GetY() - v.y());
    }


    //----------------------------------------------------------------------------------------------
    /** Cross product between two vectors in the plane represented as darts.
    *   The z-component of the cross product is returned.\n
    *
    *   ttl_util::crossProduct2d can be used.
    */
    static real_type crossProduct2d(const Dart& v1, const Dart& v2) {
      Dart v10 = v1; v10.alpha0();
      Dart v20 = v2; v20.alpha0();
      return ttl_util::crossProduct2d(v10.x()-v1.x(), v10.y()-v1.y(), 
                                      v20.x()-v2.x(), v20.y()-v2.y());
    }


    //----------------------------------------------------------------------------------------------
    /** Cross product between two vectors in the plane.
    *   The first vector is represented by a dart \e v, and the second
    *   vector has direction from the source node of \e v to the point \e p.
    *   The z-component of the cross product is returned.\n
    *
    *   ttl_util::crossProduct2d can be used.
    */
    static real_type crossProduct2d(const Dart& v, const NodePtr& p) {
      Dart d0 = v; d0.alpha0();
      return ttl_util::crossProduct2d(d0.x() - v.x(), d0.y() - v.y(),
                                      p->GetX() - v.x(), p->GetY() - v.y());
    }


    //----------------------------------------------------------------------------------------------
    /** Let \e n1 and \e n2 be the nodes associated with two darts, and let \e p
    *   be a point in the plane. Return a positive value if \e n1, \e n2,
    *   and \e p occur in counterclockwise order; a negative value if they occur
    *   in clockwise order; and zero if they are collinear.
    */
    static real_type orient2d(const Dart& n1, const Dart& n2, const NodePtr& p) {
      real_type pa[2]; real_type pb[2]; real_type pc[2];
      pa[0] = n1.x(); pa[1] = n1.y();
      pb[0] = n2.x(); pb[1] = n2.y();
      pc[0] = p->GetX(); pc[1] = p->GetY();
      return ttl_util::orient2dfast(pa, pb, pc);
    }


    //----------------------------------------------------------------------------------------------
    /** This is the same predicate as represented with the function above,
    *   but with a slighty different interface:
    *   The last parameter is given as a dart where the source node of the dart
    *   represents a point in the plane.
    *   This function is required for constrained triangulation. 
    */
    static real_type orient2d(const Dart& n1, const Dart& n2, const Dart& p) {
      real_type pa[2]; real_type pb[2]; real_type pc[2];
      pa[0] = n1.x(); pa[1] = n1.y();
      pb[0] = n2.x(); pb[1] = n2.y();
      pc[0] =  p.x(); pc[1] =  p.y();
      return ttl_util::orient2dfast(pa, pb, pc);
    }

    //@} // End of Geometric Predicates Group
  };

}; // End of hed namespace

#endif