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 154 155 156 157 158 159 160
|
// Copyright (c) 2011 CNRS and LIRIS' Establishments (France).
// 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 Lesser 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$
// $Id$
//
// Author(s) : Guillaume Damiand <guillaume.damiand@liris.cnrs.fr>
//
#ifndef CGAL_LINEAR_CELL_COMPLEX_INCREMENTAL_BUILDER_H
#define CGAL_LINEAR_CELL_COMPLEX_INCREMENTAL_BUILDER_H 1
#include <CGAL/Linear_cell_complex.h>
#include <vector>
#include <cstddef>
namespace CGAL {
template < class LCC_ >
class Linear_cell_complex_incremental_builder_3
{
public:
typedef LCC_ LCC;
typedef typename LCC::Dart_handle Dart_handle;
typedef typename LCC::Vertex_attribute_handle Vertex_attribute_handle;
typedef typename LCC::Point Point_3;
typedef typename LCC::size_type size_type;
Linear_cell_complex_incremental_builder_3(LCC & alcc) :
lcc(alcc)
{}
Vertex_attribute_handle add_vertex (const Point_3& p)
{
Vertex_attribute_handle res = lcc.create_vertex_attribute(p);
vertex_map.push_back(res);
vertex_to_dart_map.push_back(std::vector<Dart_handle>());
++new_vertices;
return res;
}
void begin_facet()
{
CGAL_assertion( first_dart==NULL && prev_dart==NULL );
// std::cout<<"Begin facet: "<<std::flush;
}
void add_vertex_to_facet(size_type i)
{
CGAL_assertion( i<new_vertices );
// std::cout<<i<<" "<<std::flush;
Dart_handle cur = lcc.create_dart(vertex_map[i]);
if ( prev_dart!=NULL )
{
lcc.template link_beta<1>(prev_dart, cur);
Dart_handle opposite =
find_dart_between(i,LCC::vertex_attribute(prev_dart));
if ( opposite!=NULL )
{
CGAL_assertion( opposite->is_free(2) );
lcc.template link_beta<2>(prev_dart, opposite);
}
add_dart_in_vertex_to_dart_map( prev_dart, prev_vertex );
}
else
{
first_dart = cur;
first_vertex = i;
}
prev_dart = cur;
prev_vertex = i;
}
void end_facet()
{
CGAL_assertion( first_dart!=NULL && prev_dart!=NULL );
lcc.template link_beta<1>(prev_dart, first_dart);
Dart_handle opposite =
find_dart_between(first_vertex,LCC::vertex_attribute(prev_dart));
if ( opposite!=NULL )
{
CGAL_assertion( opposite->is_free(2) );
lcc.template link_beta<2>(prev_dart, opposite);
}
add_dart_in_vertex_to_dart_map( prev_dart, prev_vertex );
first_dart = NULL;
prev_dart = NULL;
// std::cout<<" end facet."<<std::endl;
}
void begin_surface( std::size_t v, std::size_t f, std::size_t h)
{
new_vertices = 0;
first_dart = NULL;
prev_dart = NULL;
vertex_map.clear();
vertex_to_dart_map.clear();
vertex_map.reserve(v);
vertex_to_dart_map.reserve(v);
// lcc.reserve(v,h);
}
void end_surface()
{}
protected:
Dart_handle find_dart_between(size_type i, Vertex_attribute_handle vh)
{
typename std::vector<Dart_handle>::reverse_iterator
it(vertex_to_dart_map[i].rbegin());
typename std::vector<Dart_handle>::reverse_iterator
itend(vertex_to_dart_map[i].rend());
for ( ; it!=itend; ++it )
{
if ( LCC::vertex_attribute((*it)->beta(1))==vh ) return (*it);
}
return NULL;
}
void add_dart_in_vertex_to_dart_map( Dart_handle adart, size_type i )
{
CGAL_assertion( adart!=NULL );
CGAL_assertion( !adart->is_free(1) );
vertex_to_dart_map[i].push_back(adart);
}
private:
std::vector<Vertex_attribute_handle> vertex_map;
std::vector<std::vector<Dart_handle> > vertex_to_dart_map;
LCC& lcc;
Dart_handle first_dart;
Dart_handle prev_dart;
size_type first_vertex;
size_type prev_vertex;
size_type new_vertices;
};
} //namespace CGAL
#endif // CGAL_LINEAR_CELL_COMPLEX_INCREMENTAL_BUILDER_H //
// EOF //
|