00001 #include <list>
00002 #include <algorithm>
00003
00004
00005 namespace poly_cut {
00006
00007 typedef std::list<Polyhedron::Facet*> Facet_list;
00008
00009
00015 template <typename Plane_const_iterator>
00016 void
00017 cut( Polyhedron& poly,
00018 Facet_list& f_list,
00019 Plane_const_iterator planes_begin,
00020 Plane_const_iterator planes_end )
00021 {
00022 for( Plane_const_iterator planes_it = planes_begin;
00023 planes_it != planes_end;
00024 ++planes_it )
00025 {
00026 for( std::list<Polyhedron::Facet*>::iterator fi = f_list.begin();
00027 fi != f_list.end();
00028 ++fi )
00029 {
00030 Polyhedron::Facet* f_new = cut( poly, **fi, *planes_it );
00031 if ( f_new )
00032 f_list.push_front( f_new );
00033 }
00034 }
00035 }
00036
00037
00038 }
00039
00040
00048 template <typename Plane_const_iterator>
00049 int
00050 cut( Polyhedron& poly,
00051 Polyhedron::Facet& facet,
00052 Plane_const_iterator planes_begin,
00053 Plane_const_iterator planes_end )
00054 {
00055 std::list<Polyhedron::Facet*> f_list;
00056 f_list.push_back( &facet );
00057
00058 poly_cut::cut( poly, f_list, planes_begin, planes_end );
00059
00060 return f_list.size();
00061 }
00062
00063
00064
00075 template <typename Plane_const_iterator, typename Facet_out_iterator>
00076 int
00077 cut( Polyhedron& poly,
00078 Polyhedron::Facet& facet,
00079 Plane_const_iterator planes_begin,
00080 Plane_const_iterator planes_end,
00081 Facet_out_iterator facets_out )
00082 {
00083 std::list<Polyhedron::Facet*> f_list;
00084 f_list.push_back( &facet );
00085
00086 poly_cut::cut( poly, f_list, planes_begin, planes_end );
00087
00088 std::copy( f_list.begin(), f_list.end(), facets_out );
00089
00090 return f_list.size();
00091 }
00092
00093
00094
00095
00096
00097
00098
00105 template <typename Facet_input_iterator>
00106 int
00107 cut( Polyhedron& poly,
00108 Facet_input_iterator facets_begin,
00109 Facet_input_iterator facets_end,
00110 const CGAL::Plane_3<Exact_rep>& plane )
00111 {
00112 std::list<Polyhedron::Facet*> f_list;
00113
00114 while( facets_begin != facets_end ) {
00115 f_list.push_back( &(*facets_begin++) );
00116 }
00117
00118 const CGAL::Plane_3<Exact_rep>* planes_begin = &plane;
00119 const CGAL::Plane_3<Exact_rep>* planes_end = planes_begin + 1;
00120
00121 poly_cut::cut( poly, f_list, planes_begin, planes_end );
00122
00123 return f_list.size();
00124 }
00125
00126
00127
00139 template <typename Plane_input_iterator, typename Facet_input_iterator>
00140 int
00141 cut( Polyhedron& poly,
00142 Facet_input_iterator facets_begin,
00143 Facet_input_iterator facets_end,
00144 Plane_input_iterator planes_begin,
00145 Plane_input_iterator planes_end )
00146 {
00147 std::list<Polyhedron::Facet*> f_list;
00148
00149 while( facets_begin != facets_end ) {
00150 f_list.push_back( &(*facets_begin++) );
00151 }
00152
00153 poly_cut::cut( poly, f_list, planes_begin, planes_end );
00154
00155 return f_list.size();
00156 }
00157
00158
00170 template <typename Plane_input_iterator,
00171 typename Facet_input_iterator,
00172 typename Facet_output_iterator>
00173 int
00174 cut( Polyhedron& poly,
00175 Facet_input_iterator facets_begin,
00176 Facet_input_iterator facets_end,
00177 Plane_input_iterator planes_begin,
00178 Plane_input_iterator planes_end,
00179 Facet_output_iterator facets_out )
00180 {
00181 std::list<Polyhedron::Facet*> f_list;
00182
00183 while( facets_begin != facets_end ) {
00184 f_list.push_back( &(*facets_begin++) );
00185 }
00186
00187 poly_cut::cut( poly, f_list, planes_begin, planes_end );
00188
00189 std::copy( f_list.begin(), f_list.end(), facets_out );
00190
00191 return f_list.size();
00192 }