32 #ifndef DROP_CGAL // in case we do not have the code for CGAL 
   36 #include "fastjet/internal/DnnPlane.hh" 
   40 FASTJET_BEGIN_NAMESPACE      
 
   42 const double DnnPlane::DISTANCE_FOR_CGAL_CHECKS=1.0e-12;  
 
   47 DnnPlane::DnnPlane(
const vector<EtaPhi> & input_points, 
 
   48                    const bool & verbose ) {
 
   51   int n = input_points.size();
 
   56   for (
int i = 0; i < n; i++) {
 
   58        _TR.insert(Point(input_points[i].first, input_points[i].second));
 
   61     int coinciding_index = _CheckIfVertexPresent(sv.vertex, i);
 
   62     if (coinciding_index == i){
 
   66       sv.vertex->info() = sv.coincidence = i;
 
   90       sv.coincidence = _supervertex[coinciding_index].coincidence; 
 
   91       _supervertex[coinciding_index].coincidence = i;
 
   94     _supervertex.push_back(sv);    
 
   98   _TR.infinite_vertex()->info() = INFINITE_VERTEX;
 
  101   for (
int j = 0; j < n; j++) {_SetNearest(j);}
 
  109 int DnnPlane::_CheckIfVertexPresent(
 
  110         const Vertex_handle & vertex, 
const int its_index) {
 
  120   if (vertex->info().val() != NEW_VERTEX) {
 
  121     if (_crash_on_coincidence){
 
  123       err << 
"Error: DnnPlane::_CheckIfVertexPresent" 
  124           << 
"Point "<<its_index<<
" coincides with point " 
  125           <<vertex->info().val() << endl;
 
  126       throw DnnError(err.str());
 
  128     return vertex->info().val();
 
  146 void DnnPlane::RemoveAndAddPoints(
 
  147                           const vector<int> & indices_to_remove,
 
  148                           const vector<EtaPhi> & points_to_add,
 
  149                           vector<int> & indices_added,
 
  150                           vector<int> & indices_of_updated_neighbours) {
 
  152   if (_verbose) cout << 
"Starting  DnnPlane::RemoveAndAddPoints" << endl;
 
  156   set<int> NeighbourUnion;
 
  159   set<int> indices_removed;
 
  164   for (
size_t ir = 0; ir < indices_to_remove.size(); ir++) {
 
  165     int index = indices_to_remove[ir];
 
  166     indices_removed.insert(index);
 
  167     if (_verbose) cout << 
"  scheduling point " << index << 
" for removal" << endl;
 
  169     if (_supervertex[index].coincidence != index){
 
  175       int new_index = _supervertex[index].coincidence;
 
  176       while (_supervertex[new_index].coincidence != index)
 
  177         new_index = _supervertex[new_index].coincidence;
 
  178       if (_verbose) cout << 
"  inserted coinciding " << new_index << 
" to neighbours union" << endl;
 
  179       NeighbourUnion.insert(new_index);
 
  184       if (index != _supervertex[index].vertex->info().val()) 
continue;
 
  197         if (_verbose) cout << 
"examining " << vc->info().val() << endl;
 
  198         if (vc->info().val() != INFINITE_VERTEX) {
 
  202           NeighbourUnion.insert(vc->info().val());
 
  203           if (_verbose) cout << 
"  inserted " << vc->info().val() << 
" to neighbours union" << endl;
 
  205       } 
while (++vc != done);
 
  210     set<int>::iterator it = NeighbourUnion.begin();
 
  211     cout << 
"Union of neighbours of combined points" << endl;
 
  212     for ( ; it != NeighbourUnion.end(); ++it ) {
 
  218   for (
size_t ir = 0; ir < indices_to_remove.size(); ir++) {
 
  219     int index = indices_to_remove[ir];
 
  220     if (_verbose) cout << 
"  removing " << index << endl;
 
  224     NeighbourUnion.erase(indices_to_remove[ir]);
 
  227     if (_supervertex[index].coincidence != index){
 
  228       int new_index = _supervertex[index].coincidence;
 
  240       if (index == _supervertex[index].vertex->info().val())
 
  241         _supervertex[new_index].vertex->info() = new_index;
 
  246       while (_supervertex[new_index].coincidence != index)
 
  247         new_index = _supervertex[new_index].coincidence;
 
  248       _supervertex[new_index].coincidence = _supervertex[index].coincidence;
 
  252       _supervertex[index].coincidence = index;
 
  253       _supervertex[index].vertex = NULL;
 
  261     _TR.remove(_supervertex[index].vertex);
 
  262     _supervertex[index].vertex = NULL;
 
  287   if (NeighbourUnion.size() > 0) {
 
  289     face = _TR.incident_faces(
 
  290                            _supervertex[*NeighbourUnion.begin()].vertex);}
 
  292   indices_added.clear();
 
  293   indices_of_updated_neighbours.clear();
 
  294   for (
size_t ia = 0; ia < points_to_add.size(); ia++) {
 
  296     _supervertex.push_back(sv);
 
  297     int index = _supervertex.size()-1;
 
  298     indices_added.push_back(index);
 
  299     if (_verbose) cout << 
"  adding " << index << endl;
 
  302     if (NeighbourUnion.size() > 0) {
 
  304       _supervertex[index].vertex = _TR.insert(Point(points_to_add[ia].first, 
 
  305                                   points_to_add[ia].second),face);}
 
  307       _supervertex[index].vertex = _TR.insert(Point(points_to_add[ia].first, 
 
  308                                                     points_to_add[ia].second));
 
  312     int coinciding_index = _CheckIfVertexPresent(_supervertex[index].vertex, index);
 
  313     if (coinciding_index == index){
 
  317       _supervertex[index].vertex->info() = _supervertex[index].coincidence = index;
 
  319       if (_verbose) cout << 
"  coinciding with vertex " << coinciding_index << endl;
 
  328       _supervertex[coinciding_index].NNindex = index;
 
  329       _supervertex[coinciding_index].NNdistance = 0.0;
 
  330       indices_of_updated_neighbours.push_back(coinciding_index);
 
  336       _supervertex[index].coincidence = _supervertex[coinciding_index].coincidence; 
 
  337       _supervertex[coinciding_index].coincidence = index;
 
  348     indices_of_updated_neighbours.push_back(index);
 
  349     _SetAndUpdateNearest(index, indices_of_updated_neighbours);
 
  360   set<int>::iterator it2 = NeighbourUnion.begin();
 
  361   for ( ; it2 != NeighbourUnion.end(); ++it2 ) {
 
  364     if( j != INFINITE_VERTEX ) {
 
  367       if (indices_removed.count(_supervertex[j].NNindex)) {
 
  368         if (_verbose) cout << 
"j " << j << endl;
 
  370         indices_of_updated_neighbours.push_back(j);
 
  371         if (_verbose) cout << 
"NN of " << j << 
" : "  
  372                           << _supervertex[j].NNindex
 
  373                           << 
", dist = " << _supervertex[j].NNdistance <<endl;
 
  378   if (_verbose) cout << 
"Leaving  DnnPlane::RemoveAndAddPoints" << endl;
 
  384 void DnnPlane::_SetNearest (
const int j) {
 
  386   if (_supervertex[j].coincidence != j){
 
  387     _supervertex[j].NNindex = _supervertex[j].coincidence;
 
  388     _supervertex[j].NNdistance = 0.0;
 
  451   Vertex_handle current = _supervertex[j].vertex;
 
  455   double mindist = HUGE_DOUBLE; 
 
  456   Vertex_handle nearest = _TR.infinite_vertex();
 
  464     if ( vc->info().val() != INFINITE_VERTEX) {
 
  466       if (_verbose) cout << current->info().val() << 
" " << vc->info().val() << endl;
 
  470       if (_is_closer_to(current->point(), vc->point(), nearest, dist, mindist)){
 
  472         if (_verbose) cout << 
"nearer ";
 
  474       if (_verbose) cout << vc->point() << 
"; "<< dist << endl;
 
  476   } 
while (++vc != done); 
 
  479   _supervertex[j].NNindex = nearest->info().val();
 
  480   _supervertex[j].NNdistance = mindist;
 
  501 void DnnPlane::_SetAndUpdateNearest(
 
  503                           vector<int> & indices_of_updated_neighbours) {
 
  506   if (_supervertex[j].coincidence != j){
 
  507     _supervertex[j].NNindex = _supervertex[j].coincidence;
 
  508     _supervertex[j].NNdistance = 0.0;
 
  513   Vertex_handle current = _supervertex[j].vertex;
 
  517   double mindist = HUGE_DOUBLE; 
 
  518   Vertex_handle nearest = _TR.infinite_vertex();
 
  526     if (vc->info().val() != INFINITE_VERTEX) {
 
  527       if (_verbose) cout << current->info().val() << 
" " << vc->info().val() << endl;
 
  530       if (_is_closer_to(current->point(), vc->point(), nearest, dist, mindist)){
 
  532         if (_verbose) cout << 
"nearer ";
 
  536       int vcindx = vc->info().val();
 
  537       if (_verbose) cout << vc->point() << 
"; "<< dist << endl;
 
  539       if (_is_closer_to_with_hint(vc->point(), current->point(), 
 
  540                                   _supervertex[_supervertex[vcindx].NNindex].vertex,
 
  541                                   dist, _supervertex[vcindx].NNdistance)){
 
  542         if (_verbose) cout << vcindx << 
"'s NN becomes " << current->info().val() << endl;
 
  543         _supervertex[vcindx].NNindex = j;
 
  544         indices_of_updated_neighbours.push_back(vcindx);
 
  566   } 
while (++vc != done); 
 
  569   _supervertex[j].NNindex = nearest->info().val();
 
  570   _supervertex[j].NNdistance = mindist;
 
  573 FASTJET_END_NAMESPACE
 
Triangulation::Vertex_circulator Vertex_circulator
CGAL Point structure.