HeTraits.h

Go to the documentation of this file.
00001 //===========================================================================
00002 //
00003 // File: HeTraits.h
00004 //
00005 // Created: March 1 2001
00006 //
00007 // Author: Øyvind Hjelle <oyvind.hjelle@math.sintef.no>
00008 //
00009 // Revision: $Id: HeTraits.h,v 1.2 2006/07/26 12:08:44 oyvindhj Exp $
00010 //
00011 // Description:
00012 //
00013 //===========================================================================
00014 // Copyright (C) 2000-2003 SINTEF Applied Mathematics.  All rights reserved.
00015 //
00016 // This file may be distributed under the terms of the Q Public License
00017 // as defined by Trolltech AS of Norway and appearing in the file
00018 // LICENSE.QPL included in the packaging of this file.
00019 // 
00020 // This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00021 // WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00022 //
00023 //===========================================================================
00024 
00025 
00026 #ifndef _HALF_EDGE_TRAITS_
00027 #define _HALF_EDGE_TRAITS_
00028 
00029 
00030 #include <ttl/halfedge/HeTriang.h>
00031 #include <ttl/halfedge/HeDart.h>
00032 
00033 
00034 namespace hed {
00035 
00036 
00037   //------------------------------------------------------------------------------------------------
00038   // Traits class for the half-edge data structure
00039   //------------------------------------------------------------------------------------------------
00040   
00056   struct TTLtraits {
00057     
00058     // The actual triangulation object
00059     static Triangulation* triang_;
00060     
00064     typedef double real_type;
00065 
00066 
00067     //----------------------------------------------------------------------------------------------
00068     // ------------------------------- Geometric Predicates Group ---------------------------------
00069     //----------------------------------------------------------------------------------------------
00070 
00073 
00074     //----------------------------------------------------------------------------------------------
00079     static real_type scalarProduct2d(const Dart& v1, const Dart& v2) {
00080       Dart v10 = v1; v10.alpha0();
00081       Dart v20 = v2; v20.alpha0();
00082       return ttl_util::scalarProduct2d(v10.x()-v1.x(), v10.y()-v1.y(),
00083                                        v20.x()-v2.x(), v20.y()-v2.y());
00084     }
00085 
00086 
00087     //----------------------------------------------------------------------------------------------
00094     static real_type scalarProduct2d(const Dart& v, const Node& p) {
00095       Dart d0 = v; d0.alpha0();
00096       return ttl_util::scalarProduct2d(d0.x() - v.x(), d0.y() - v.y(),
00097                                        p.x() - v.x(), p.y() - v.y());
00098     }
00099 
00100 
00101     //----------------------------------------------------------------------------------------------
00107     static real_type crossProduct2d(const Dart& v1, const Dart& v2) {
00108       Dart v10 = v1; v10.alpha0();
00109       Dart v20 = v2; v20.alpha0();
00110       return ttl_util::crossProduct2d(v10.x()-v1.x(), v10.y()-v1.y(), 
00111                                       v20.x()-v2.x(), v20.y()-v2.y());
00112     }
00113 
00114 
00115     //----------------------------------------------------------------------------------------------
00123     static real_type crossProduct2d(const Dart& v, const Node& p) {
00124       Dart d0 = v; d0.alpha0();
00125       return ttl_util::crossProduct2d(d0.x() - v.x(), d0.y() - v.y(),
00126                                       p.x() - v.x(), p.y() - v.y());
00127     }
00128 
00129 
00130     //----------------------------------------------------------------------------------------------
00136     static real_type orient2d(const Dart& n1, const Dart& n2, const Node& p) {
00137       real_type pa[2]; real_type pb[2]; real_type pc[2];
00138       pa[0] = n1.x(); pa[1] = n1.y();
00139       pb[0] = n2.x(); pb[1] = n2.y();
00140       pc[0] =  p.x(); pc[1] =  p.y();
00141       return ttl_util::orient2dfast(pa, pb, pc);
00142     }
00143 
00144 
00145     //----------------------------------------------------------------------------------------------
00152     static real_type orient2d(const Dart& n1, const Dart& n2, const Dart& p) {
00153       real_type pa[2]; real_type pb[2]; real_type pc[2];
00154       pa[0] = n1.x(); pa[1] = n1.y();
00155       pb[0] = n2.x(); pb[1] = n2.y();
00156       pc[0] =  p.x(); pc[1] =  p.y();
00157       return ttl_util::orient2dfast(pa, pb, pc);
00158     }
00159 
00161 
00162 
00163     // A rationale for directing these functions to traits is:
00164     // e.g., constraints
00165 
00166     //----------------------------------------------------------------------------------------------
00167     /* Checks if the edge associated with \e dart should be swapped
00168     *   according to the Delaunay criterion.<br>
00169     *
00170     *   \note
00171     *   This function is also present in the TTL as ttl::swapTestDelaunay.<br>
00172     *   Thus, the function can be implemented simply as:
00173     *   \code
00174     *   { return ttl::swapTestDelaunay<TTLtraits>(dart); }
00175     *   \endcode
00176     */
00177     //static bool swapTestDelaunay(const Dart& dart) {
00178     //  return ttl::swapTestDelaunay<TTLtraits>(dart);
00179     //}
00180 
00181 
00182     //----------------------------------------------------------------------------------------------
00183     /* Checks if the edge associated with \e dart can be swapped, i.e.,
00184     *   if the edge is a diagonal in a (strictly) convex quadrilateral.
00185     *   This function is also present as ttl::swappableEdge.
00186     */
00187     //static bool swappableEdge(const Dart& dart) {
00188     //  return ttl::swappableEdge<TTLtraits>(dart);
00189     //}
00190 
00191 
00192     //----------------------------------------------------------------------------------------------
00193     /* Checks if the edge associated with \e dart should be \e fixed, meaning
00194     *   that it should never be swapped. ??? Use when constraints.
00195     */
00196     //static bool fixedEdge(const Dart& dart) {
00197     //  return dart.getEdge()->isConstrained();
00198     //}
00199 
00200 
00201     //----------------------------------------------------------------------------------------------
00202     // ----------------------- Functions for Delaunay Triangulation Group -------------------------
00203     //----------------------------------------------------------------------------------------------
00204 
00207 
00208     //----------------------------------------------------------------------------------------------
00227     static void swapEdge(Dart& dart) {
00228       if (!dart.getEdge()->isConstrained()) triang_->swapEdge(*dart.getEdge());
00229     }
00230 
00231 
00232     //----------------------------------------------------------------------------------------------
00243     static void splitTriangle(Dart& dart, Node& point) {
00244       Edge* edge = triang_->splitTriangle(*dart.getEdge(), point);
00245       dart.init(edge);
00246     }
00247     
00249 
00250 
00251     //----------------------------------------------------------------------------------------------
00252     // --------------------------- Functions for removing nodes Group -----------------------------
00253     //----------------------------------------------------------------------------------------------
00254 
00257 
00258     //----------------------------------------------------------------------------------------------
00267     static void reverse_splitTriangle(Dart& dart) {
00268       triang_->reverse_splitTriangle(*dart.getEdge());
00269     }
00270 
00271 
00272     //----------------------------------------------------------------------------------------------
00276     static void removeBoundaryTriangle(Dart& d) {
00277       triang_->removeTriangle(*d.getEdge());
00278     }
00279 
00281 
00282   };
00283 
00284 }; // End of hed namespace
00285 
00286 #endif

Generated on Wed Nov 17 17:44:27 2010 for TTL by  doxygen 1.6.1