BWAPI
SPAR/AIModule/BWTA/vendors/CGAL/CGAL/normal_vector_newell_3.h
Go to the documentation of this file.
00001 // Copyright (c) 1997-2002  Max-Planck-Institute Saarbruecken (Germany).
00002 // All rights reserved.
00003 //
00004 // This file is part of CGAL (www.cgal.org); you may redistribute it under
00005 // the terms of the Q Public License version 1.0.
00006 // See the file LICENSE.QPL distributed with CGAL.
00007 //
00008 // Licensees holding a valid commercial license may use this file in
00009 // accordance with the commercial license agreement provided with the software.
00010 //
00011 // This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00012 // WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00013 //
00014 // $URL: svn+ssh://scm.gforge.inria.fr/svn/cgal/branches/CGAL-3.5-branch/Nef_3/include/CGAL/normal_vector_newell_3.h $
00015 // $Id: normal_vector_newell_3.h 28567 2006-02-16 14:30:13Z lsaboret $
00016 // 
00017 //
00018 // Author(s)     : Michael Seel    <seel@mpi-sb.mpg.de>
00019 //                 Miguel Granados <granados@mpi-sb.mpg.de>
00020 //                 Susan Hert      <hert@mpi-sb.mpg.de>
00021 //                 Lutz Kettner    <kettner@mpi-sb.mpg.de>
00022 #ifndef CGAL_NORMAL_VECTOR_NEWELL_3_H
00023 #define CGAL_NORMAL_VECTOR_NEWELL_3_H 1
00024 
00025 #include <CGAL/iterator.h>
00026 
00027 #undef CGAL_NEF_DEBUG
00028 #define CGAL_NEF_DEBUG 79
00029 #include <CGAL/Nef_2/debug.h>
00030 
00031 CGAL_BEGIN_NAMESPACE
00032 
00033 template <class Handle, class Vector>
00034 CGAL_MEDIUM_INLINE
00035 void newell_single_step_3( Handle p, Handle q, Vector& n )
00036 {
00037   n = Vector(
00038     n.hx()
00039         * p->hw() * p->hw()
00040         * q->hw() * q->hw()
00041       +   n.hw()
00042         * ( p->hy() * q->hw() - q->hy() * p->hw())
00043         * ( p->hz() * q->hw() + q->hz() * p->hw()),
00044     n.hy()
00045         * p->hw() * p->hw()
00046         * q->hw() * q->hw()
00047       +   n.hw()
00048         * ( p->hz() * q->hw() - q->hz() * p->hw())
00049         * ( p->hx() * q->hw() + q->hx() * p->hw()),
00050     n.hz()
00051         * p->hw() * p->hw()
00052         * q->hw() * q->hw()
00053       +   n.hw()
00054         * ( p->hx() * q->hw() - q->hx() * p->hw())
00055         * ( p->hy() * q->hw() + q->hy() * p->hw()),
00056     n.hw()
00057         * p->hw() * p->hw()
00058         * q->hw() * q->hw()
00059     );
00060 }
00061 
00062 template <class IC, class Vector>
00063 void normal_vector_newell_3( IC first, IC last, Vector& n )
00064     // compute a facet normal n via the Newell-method for the facet
00065     // surrounded by the points in the range [`h', `last'), where `IC'
00066     // denotes either an iterator or a circulator with a point type as
00067     // value type. The Newell-method computes for non-planar facets the
00068     // best least-square-fit normal of the plane equation. Precondition:
00069     // The numbertype for the points and the vector n must be compatible
00070     // with `double'. The points and the vector n must have dimension
00071     // three.
00072 {
00073     CGAL_assertion( !CGAL::is_empty_range( first, last));
00074     // Compute facet normals via the Newell-method as described in
00075     // Filippo Tampieri: Newell's Method for Computing the Plane
00076     // Equation of a Polygon. Graphics Gems III, David Kirk,
00077     // AP Professional, 1992.
00078     // The code works with cartesian and with semi-rational points.
00079     n = Vector( 0, 0, 0);        // init current normal to 0
00080     IC start_point = first;
00081     IC prev = first;
00082     ++first;
00083     while( first != last) {
00084         newell_single_step_3( prev, first, n);
00085         prev = first;
00086         ++first;
00087     }
00088     newell_single_step_3( prev, start_point, n);
00089     CGAL_NEF_TRACEN("newell normal vector "<<n);
00090 }
00091 
00092 CGAL_END_NAMESPACE
00093 
00094 #endif // CGAL_NORMAL_VECTOR_NEWELL_3_H
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines