BWAPI
SPAR/AIModule/BWTA/vendors/CGAL/CGAL/Nef_nary_union_3.h
Go to the documentation of this file.
00001 // Copyright (c) 1997-2007  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: 
00015 // $Id: 
00016 // 
00017 //
00018 // Author(s)     :     Peter Hachenberger  <hachenberger@mpi-sb.mpg.de>
00019 
00020 #ifndef CGAL_NEF_NARY_UNION_3_H
00021 #define CGAL_NEF_NARY_UNION_3_H
00022 
00023 #include <list>
00024 
00025 CGAL_BEGIN_NAMESPACE
00026 
00027 template<class Polyhedron>
00028 class Nef_nary_union_3 {
00029 
00030   int inserted;
00031   std::list<Polyhedron> queue;
00032   typedef typename std::list<Polyhedron>::iterator pit;
00033   Polyhedron empty;
00034 
00035  public:
00036   Nef_nary_union_3() : inserted(0) {}
00037   
00038   void unite() {
00039     pit i1(queue.begin()), i2(i1);
00040     ++i2;
00041 
00042     Polyhedron tmp(*i1 + *i2);
00043 
00044     queue.pop_front();
00045     queue.pop_front();
00046     queue.push_front(tmp);
00047   }
00048 
00049   void add_polyhedron(const Polyhedron& P) {
00050     queue.push_front(P);
00051     ++inserted;
00052     for(int i=2;(inserted%i) == 0; i*=2) {
00053       unite();
00054     }
00055   }
00056 
00057   Polyhedron get_union() {
00058 
00059     while(queue.size() > 1)
00060       unite();
00061     inserted = 0;
00062     return queue.front();
00063   }
00064 };
00065 
00066 CGAL_END_NAMESPACE
00067 #endif // CGAL_NEF_NARY_UNION_H
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines