BWAPI
SPAR/AIModule/BWTA/vendors/CGAL/CGAL/Nef_3/bounded_side_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/Nef_3/bounded_side_3.h $
00015 // $Id: bounded_side_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_BOUNDED_SIDE_3_H
00023 #define CGAL_BOUNDED_SIDE_3_H
00024 
00025 #include <CGAL/basic.h>
00026 #include <CGAL/Polygon_2_algorithms.h>
00027 #include <CGAL/Iterator_project.h>
00028 #include <vector>
00029 
00030 #undef CGAL_NEF_DEBUG
00031 #define CGAL_NEF_DEBUG 17
00032 #include <CGAL/Nef_2/debug.h>
00033 
00034 CGAL_BEGIN_NAMESPACE
00035 
00036 template <class Point_2, class Point_3> 
00037 Point_2 point_3_get_x_y_point_2(Point_3 p) {
00038   return( Point_2(p.hx(), p.hy(), p.hw()) );
00039 }
00040 
00041 template <class Point_2, class Point_3> 
00042 Point_2 point_3_get_y_z_point_2(Point_3 p) {
00043   return( Point_2(p.hy(), p.hz(), p.hw()) );
00044 }
00045 
00046 template <class Point_2, class Point_3> 
00047 Point_2 point_3_get_z_x_point_2(Point_3 p) {
00048   return( Point_2(p.hz(), p.hx(), p.hw()) );
00049 }
00050 
00051 template <class IteratorForward, class R>
00052 Bounded_side bounded_side_3(IteratorForward first,
00053                             IteratorForward last,
00054                             const Point_3<R>& point,
00055                             typename R::Plane_3 plane = typename R::Plane_3(0,0,0,0)) {
00056   typedef typename R::Point_2 Point_2;
00057   typedef typename R::Point_3 Point_3;
00058   typedef typename R::Vector_3 Vector_3;
00059   typedef typename R::Plane_3 Plane_3;
00060   
00061   if(plane == Plane_3(0,0,0,0)) {
00062     // TO TEST: code never tested
00063     IteratorForward p(first);
00064     Point_3 p0(*(p++));
00065     CGAL_assertion(p != last);
00066     Point_3 p1(*(p++));
00067     CGAL_assertion(p != last);
00068     Point_3 p2(*(p++));
00069     plane = Plane_3(p0, p1, p2);
00070 
00071     /* since we just need to project the points to a non-perpendicular plane
00072        we don't need to care about the plane orientation */
00073   }
00074 
00075 
00076 
00077   CGAL_assertion(!plane.is_degenerate());
00078   Point_2 (*t)(Point_3);
00079   Vector_3 pv(plane.orthogonal_vector()), pxy(0,0,1), pyz(1,0,0), pzx(0,1,0);
00080   CGAL_NEF_TRACEN("pv*pxz: "<<pv*pzx);
00081   CGAL_NEF_TRACEN("pv*pyz: "<<pv*pyz);
00082   CGAL_NEF_TRACEN("pv*pxy: "<<pv*pxy);
00083   if( !CGAL_NTS is_zero(pv*pzx) )
00084     /* the plane is not perpendicular to the ZX plane */
00085     t = &point_3_get_z_x_point_2< Point_2, Point_3>;
00086   else if( !CGAL_NTS is_zero(pv*pyz) )
00087     /* the plane is not perpendicular to the YZ plane */
00088     t = &point_3_get_y_z_point_2< Point_2, Point_3>;
00089   else {
00090     CGAL_assertion( !CGAL_NTS is_zero(pv*pxy) );
00091     /* the plane is not perpendicular to the XY plane */
00092     t = &point_3_get_x_y_point_2< Point_2, Point_3>;
00093   }
00094 
00095   std::vector< Point_2> points;
00096   CGAL_NEF_TRACEN("facet:");
00097   for( ; first != last; ++first ) {
00098     CGAL_NEF_TRACEN(t(*first)<<" "<<*first);
00099     points.push_back( t(*first));
00100   }
00101   Bounded_side side = bounded_side_2( points.begin(), points.end(), t(point));
00102   points.clear();
00103   return side;  
00104 }
00105 
00106 CGAL_END_NAMESPACE
00107 
00108 #ifdef WRONG_IMPLEMENTATION
00109 /* The following code is wrong since Proyector_.. structures must not return
00110    references to temporal objects */
00111 template < class Point_2, class Point_3> 
00112 struct Project_XY {
00113   typedef Point_3                  argument_type;
00114   typedef Point_2                  result_type;
00115   Point_2 operator()( Point_3& p) const { 
00116     return Point_2(p.hx(), p.hy(), p.hw());
00117   }
00118   const Point_2 operator()( const Point_3& p) const { 
00119     return Point_2(p.hx(), p.hy(), p.hw());
00120   }
00121 };
00122 
00123 template < class Point_2, class Point_3> 
00124 struct Project_YZ {
00125   typedef Point_3                  argument_type;
00126   typedef Point_2                  result_type;
00127   Point_2 operator()( Point_3& p) const { 
00128     return Point_2(p.hy(), p.hz(), p.hw());
00129   }
00130   const Point_2 operator()( const Point_3& p) const { 
00131     return Point_2(p.hy(), p.hz(), p.hw());
00132   }
00133 };
00134 
00135 template < class Point_2, class Point_3> 
00136 struct Project_XZ {
00137   typedef Point_3                  argument_type;
00138   typedef Point_2                  result_type;
00139   Point_2 operator()( Point_3& p) const { 
00140     return Point_2(p.hx(), p.hz(), p.hw());
00141   }
00142   const Point_2 operator()( const Point_3& p) const { 
00143     return Point_2(p.hx(), p.hz(), p.hw());
00144   }
00145 };
00146 
00147 template <class IC, class R>
00148 Bounded_side bounded_side_3(IC first,
00149                             IC last,
00150                             const Point_3<R>& point,
00151                             Plane_3<R> plane = Plane_3<R>(0,0,0,0)) {
00152 
00153   typedef typename R::Point_2 Point_2;
00154   typedef typename R::Point_3 Point_3;
00155   typedef typename R::Vector_3 Vector_3;
00156   typedef typename R::Plane_3 Plane_3;
00157 
00158   CGAL_assertion( !CGAL::is_empty_range( first, last));
00159 
00160   if(plane == Plane_3(0,0,0,0)) {
00161     Vector_3 hv;
00162     normal_vector_newell_3( first, last, hv);
00163     plane = Plane_3( *first, Vector_3(hv));
00164   }
00165   CGAL_assertion(!plane.is_degenerate());
00166   Vector_3 pd(plane.orthogonal_vector()), pyz(1,0,0), pxz(0,1,0);
00167   if(pd == pyz || pd == -pyz) {
00168     /* the plane is parallel to the YZ plane */
00169     typedef Project_YZ< Point_2, Point_3>                  Project_YZ;
00170     typedef Iterator_project< IC, Project_YZ> Iterator_YZ;
00171     Project_YZ project;
00172     Point_2 p = project(point);
00173     Iterator_YZ pfirst(first), plast(last);
00174     return bounded_side_2(pfirst, plast, p);
00175   }
00176   else if(pd == pxz || pd ==- pxz) {
00177     /* the plane is parallel to the XZ plane */
00178     typedef Project_XZ< Point_2, Point_3>                  Project_XZ;
00179     typedef Iterator_project< IC, Project_XZ> Iterator_XZ;
00180     Project_XZ project;
00181     Point_2 p = project(point);
00182     Iterator_XZ pfirst(first), plast(last);
00183     return bounded_side_2(pfirst, plast, p);
00184   }
00185   else {
00186     CGAL_assertion(cross_product(pd.vector(), Vector_3(0,0,1)) == NULL_VECTOR);
00187     /* the plane is not perpendicular to the XY plane */
00188     typedef Project_XY< Point_2, Point_3>                  Project_XY;
00189     typedef Iterator_project< IC, Project_XY> Iterator_XY;
00190     Project_XY project;
00191     Point_2 p = project(point);
00192     Iterator_XY pfirst(first), plast(last);
00193     return bounded_side_2(pfirst, plast, p);
00194   }
00195 }
00196 #endif // WRONG_IMPLEMENTATION
00197 
00198 #endif // CGAL_BOUNDED_SIDE_3_H
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines