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
|
// Copyright (c) 2000, 2006 ETH Zurich (Switzerland).
// All rights reserved.
//
// This file is part of CGAL (www.cgal.org).
// You can redistribute it and/or modify it under the terms of the GNU
// General Public License as published by the Free Software Foundation,
// either version 3 of the License, or (at your option) any later version.
//
// Licensees holding a valid commercial license may use this file in
// accordance with the commercial license agreement provided with the software.
//
// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
//
// $URL: svn+ssh://scm.gforge.inria.fr/svn/cgal/branches/next/Polyhedron/include/CGAL/polyhedron_cut_plane_3.h $
// $Id: polyhedron_cut_plane_3.h 67117 2012-01-13 18:14:48Z lrineau $
//
//
// Author(s) : Lutz Kettner <kettner@mpi-sb.mpg.de>)
// Cuts a connected piece off a Polyhedral Surfaces.
#ifndef CGAL_POLYHEDRON_CUT_PLANE_3_H
#define CGAL_POLYHEDRON_CUT_PLANE_3_H 1
#include <CGAL/basic.h>
#include <CGAL/Kernel_traits.h>
#include <CGAL/Modifier_base.h>
#include <CGAL/halfedgeDS_cut_component.h>
#include <CGAL/intersections.h>
namespace CGAL {
// Auxiliary classes and functions to make polyhedron_cut_plane_3 work.
// See below for the implementations of polyhedron_cut_plane_3.
template < class HDS, class Predicate>
class Polyhedron_cut_component_3 : public Modifier_base<HDS> {
public:
typedef typename HDS::Halfedge_handle Halfedge_handle;
private:
Halfedge_handle h;
Predicate pred;
public:
Polyhedron_cut_component_3( Halfedge_handle hh, const Predicate& p)
: h(hh), pred(p) {}
void operator()( HDS& target) {
h = halfedgeDS_cut_component( target, h, pred);
}
Halfedge_handle halfedge() const { return h; }
};
template < class Poly, class Predicate >
typename Poly::Halfedge_handle
I_polyhedron_cut_component( Poly& poly,
typename Poly::Halfedge_handle h,
Predicate pred) {
typedef typename Poly::HalfedgeDS HDS;
typedef Polyhedron_cut_component_3<HDS,Predicate> Modifier;
Modifier modifier( h, pred);
poly.delegate( modifier);
return modifier.halfedge();
}
template < class Poly, class Plane, class Traits>
class I_Polyhedron_cut_plane_predicate {
const Plane& plane;
const Traits& traits;
public:
typedef typename Poly::Vertex_const_handle Vertex_const_handle;
I_Polyhedron_cut_plane_predicate( const Plane& pl, const Traits& tr)
: plane(pl), traits(tr) {}
bool operator()( Vertex_const_handle v) const {
return traits.has_on_negative_side_3_object()( plane, v->point());
}
};
template <class Kernel>
struct I_Construct_point_3 {
typedef typename Kernel::Point_3 Point_3;
typedef typename Kernel::Plane_3 Plane_3;
typedef typename Kernel::Line_3 Line_3;
Point_3
operator()( const Plane_3& p, const Plane_3& q, const Plane_3& r) const {
Object obj = intersection( p, q);
Line_3 line;
if ( assign( line, obj)) {
obj = intersection( r, line);
Point_3 pt;
if ( assign( pt, obj)) {
return pt;
}
}
std::cerr << "ERROR: coplanar planes used for computing "
"intersecting point." << std::endl;
std::cerr << " Return ORIGIN. Don't trust result." << std::endl;
return ORIGIN;
}
};
template < class Poly, class Plane, class Traits>
typename Poly::Halfedge_handle
polyhedron_cut_plane_3( Poly& poly,
typename Poly::Halfedge_handle h,
const Plane& plane,
const Traits& traits)
// Cuts the polyhedron `poly' at plane `plane' starting at halfedge `h'.
// Traces the intersection curve of `plane' with `poly' starting at `h',
// cuts `poly' along that intersection curve and deletes the (connected)
// component on the negative side of the plane. The hole created along
// the intersection curve is filled with a new face containing the plane
// and the points in the vertices are computed.
{
typedef typename Poly::Halfedge_handle Halfedge_handle;
typedef I_Polyhedron_cut_plane_predicate< Poly, Plane, Traits> Predicate;
typedef I_Construct_point_3< Traits> Construct_point;
Predicate pred( plane, traits);
Construct_point construct_point; // replace this with kernel one day.
CGAL_precondition( poly.is_valid());
CGAL_precondition( pred( h->vertex()));
CGAL_precondition( ! pred( h->opposite()->vertex()));
h = I_polyhedron_cut_component( poly, h, pred);
// Assign geometry
h->facet()->plane() = plane;
Halfedge_handle start = h;
do {
h->vertex()->point() =
construct_point( plane,
h->next()->opposite()->facet()->plane(),
h->opposite()->facet()->plane());
h = h->next();
} while ( h != start);
CGAL_postcondition( poly.is_valid());
return h;
}
template < class Poly, class Plane>
typename Poly::Halfedge_handle
polyhedron_cut_plane_3( Poly& poly,
typename Poly::Halfedge_handle h,
const Plane& plane)
// Same function as above using the kernel that comes with the plane.
{
typedef CGAL::Kernel_traits<Plane> KTraits;
typedef typename KTraits::Kernel Kernel;
return polyhedron_cut_plane_3( poly, h, plane, Kernel());
}
} //namespace CGAL
#endif // CGAL_POLYHEDRON_CUT_PLANE_3_H //
// EOF //
|