Merge branch 'Triangulation_3-faster_incident_edges-GF'

Approved by the release manager
This commit is contained in:
Andreas Fabri 2014-05-14 17:03:41 +02:00
commit 7e00af50f5
3 changed files with 122 additions and 9 deletions

View File

@ -0,0 +1,40 @@
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/Delaunay_triangulation_3.h>
#include <CGAL/Timer.h>
#include <iostream>
typedef CGAL::Exact_predicates_inexact_constructions_kernel K;
typedef CGAL::Delaunay_triangulation_3<K> DT;
typedef K::Point_3 Point_3;
typedef CGAL::Timer Timer;
int main()
{
std::vector<Point_3> points;
Point_3 p;
while(std::cin >> p){
points.push_back(p);
}
DT dt;
dt.insert(points.begin(), points.end());
Timer timer;
timer.start();
int N = 0;
for(int i = 0; i < 5; i++){
for(DT::Vertex_iterator vit = dt.vertices_begin(); vit!= dt.vertices_end(); ++vit){
std::vector<DT::Edge> E;
E.reserve(64);
dt.incident_edges(vit,std::back_inserter(E));
N += E.size();
}
}
timer.stop();
std::cerr << N << std::endl << timer.time() << " sec" << std::endl;
return 0;
}

View File

@ -33,6 +33,7 @@
#include <vector> #include <vector>
#include <stack> #include <stack>
#include <boost/unordered_set.hpp>
#include <CGAL/utility.h> #include <CGAL/utility.h>
#include <CGAL/iterator.h> #include <CGAL/iterator.h>
@ -814,30 +815,44 @@ public:
} }
}; };
template<class Treatment, class OutputIterator, class Filter, bool hasVisited>
class Vertex_extractor;
// Visitor for visit_incident_cells: // Visitor for visit_incident_cells:
// outputs the result of Treatment applied to the vertices // outputs the result of Treatment applied to the vertices
template<class Treatment, class OutputIterator, class Filter> template<class Treatment, class OutputIterator, class Filter>
class Vertex_extractor { class Vertex_extractor<Treatment,OutputIterator,Filter,false> {
Vertex_handle v; Vertex_handle v;
std::set<Vertex_handle> tmp_vertices;
boost::unordered_set<Vertex_handle, Handle_hash_function> tmp_vertices;
Treatment treat; Treatment treat;
const Tds* t; const Tds* t;
Filter filter; Filter filter;
public: public:
Vertex_extractor(Vertex_handle _v, OutputIterator _output, const Tds* _t, Filter _filter): Vertex_extractor(Vertex_handle _v, OutputIterator _output, const Tds* _t, Filter _filter):
v(_v), treat(_output), t(_t), filter(_filter) {} v(_v), treat(_output), t(_t), filter(_filter)
{
#if ( BOOST_VERSION >= 105000 )
tmp_vertices.reserve(64);
#endif
}
void operator()(Cell_handle c) { void operator()(Cell_handle c) {
for (int j=0; j<= t->dimension(); ++j) { for (int j=0; j<= t->dimension(); ++j) {
Vertex_handle w = c->vertex(j); Vertex_handle w = c->vertex(j);
if(filter(w)) if(filter(w))
continue; continue;
if (w != v) if (w != v){
if(tmp_vertices.insert(w).second) { if(tmp_vertices.insert(w).second) {
treat(c, v, j); treat(c, v, j);
} }
} }
} }
}
CGAL::Emptyset_iterator facet_it() {return CGAL::Emptyset_iterator();} CGAL::Emptyset_iterator facet_it() {return CGAL::Emptyset_iterator();}
OutputIterator result() { OutputIterator result() {
@ -845,6 +860,52 @@ public:
} }
}; };
template<class Treatment, class OutputIterator, class Filter>
class Vertex_extractor<Treatment,OutputIterator,Filter,true> {
Vertex_handle v;
std::vector<Vertex_handle> tmp_vertices;
Treatment treat;
const Tds* t;
Filter filter;
public:
Vertex_extractor(Vertex_handle _v, OutputIterator _output, const Tds* _t, Filter _filter):
v(_v), treat(_output), t(_t), filter(_filter) {
tmp_vertices.reserve(64);
}
void operator()(Cell_handle c) {
for (int j=0; j<= t->dimension(); ++j) {
Vertex_handle w = c->vertex(j);
if(filter(w))
continue;
if (w != v){
if(! w->visited_for_vertex_extractor){
w->visited_for_vertex_extractor = true;
tmp_vertices.push_back(w);
treat(c, v, j);
}
}
}
}
~Vertex_extractor()
{
for(std::size_t i=0; i < tmp_vertices.size(); ++i){
tmp_vertices[i]->visited_for_vertex_extractor = false;
}
}
CGAL::Emptyset_iterator facet_it() {return CGAL::Emptyset_iterator();}
OutputIterator result() {
return treat.result();
}
};
// Treatment for Vertex_extractor: // Treatment for Vertex_extractor:
// outputs the vertices // outputs the vertices
template<class OutputIterator> template<class OutputIterator>
@ -922,6 +983,8 @@ public:
return incident_facets<False_filter>(v, facets); return incident_facets<False_filter>(v, facets);
} }
BOOST_MPL_HAS_XXX_TRAIT_NAMED_DEF(Has_member_visited,Has_visited_for_vertex_extractor,false)
template <class Filter, class OutputIterator> template <class Filter, class OutputIterator>
OutputIterator OutputIterator
incident_edges(Vertex_handle v, OutputIterator edges, Filter f = Filter()) const incident_edges(Vertex_handle v, OutputIterator edges, Filter f = Filter()) const
@ -944,7 +1007,7 @@ public:
return edges; return edges;
} }
return visit_incident_cells<Vertex_extractor<Edge_feeder_treatment<OutputIterator>, return visit_incident_cells<Vertex_extractor<Edge_feeder_treatment<OutputIterator>,
OutputIterator, Filter>, OutputIterator, Filter, Has_member_visited<Vertex>::value>,
OutputIterator>(v, edges, f); OutputIterator>(v, edges, f);
} }
@ -987,7 +1050,7 @@ public:
return vertices; return vertices;
} }
return visit_incident_cells<Vertex_extractor<Vertex_feeder_treatment<OutputIterator>, return visit_incident_cells<Vertex_extractor<Vertex_feeder_treatment<OutputIterator>,
OutputIterator, Filter>, OutputIterator, Filter, Has_member_visited<Vertex>::value>,
OutputIterator>(v, vertices, f); OutputIterator>(v, vertices, f);
} }
@ -1034,6 +1097,7 @@ public:
(*cit)->tds_data().clear(); (*cit)->tds_data().clear();
visit(*cit); visit(*cit);
} }
return visit.result(); return visit.result();
} }

View File

@ -37,10 +37,12 @@ public:
struct Rebind_TDS { typedef Triangulation_ds_vertex_base_3<TDS2> Other; }; struct Rebind_TDS { typedef Triangulation_ds_vertex_base_3<TDS2> Other; };
Triangulation_ds_vertex_base_3() Triangulation_ds_vertex_base_3()
: _c() {} : _c(), visited_for_vertex_extractor(false)
{}
Triangulation_ds_vertex_base_3(Cell_handle c) Triangulation_ds_vertex_base_3(Cell_handle c)
: _c(c) {} : _c(c), visited_for_vertex_extractor(false)
{}
Cell_handle cell() const Cell_handle cell() const
{ return _c; } { return _c; }
@ -64,6 +66,13 @@ public:
private: private:
Cell_handle _c; Cell_handle _c;
// The typedef and the bool are used by Triangulation_data_structure::Vertex_extractor
// The names are chooses complicated so that we do not have to document them
// (privacy by obfuscation)
public:
typedef bool Has_visited_for_vertex_extractor;
bool visited_for_vertex_extractor;
}; };
template < class TDS > template < class TDS >