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 if (_verbose) cout <<
"DnnPlane about to set _supervertex["<< index<<
"].vertex to NULL" << endl;
263 _supervertex[index].vertex = NULL;
264 if (_verbose) cout <<
" value is " << (_is_not_null(_supervertex[index].vertex)) << endl;
289 if (NeighbourUnion.size() > 0) {
291 face = _TR.incident_faces(
292 _supervertex[*NeighbourUnion.begin()].vertex);}
294 indices_added.clear();
295 indices_of_updated_neighbours.clear();
296 for (
size_t ia = 0; ia < points_to_add.size(); ia++) {
298 _supervertex.push_back(sv);
299 int index = _supervertex.size()-1;
300 indices_added.push_back(index);
301 if (_verbose) cout <<
" adding " << index <<
" at "
302 << points_to_add[ia].first<<
" " << points_to_add[ia].second << endl;
305 if (NeighbourUnion.size() > 0) {
307 _supervertex[index].vertex = _TR.insert(Point(points_to_add[ia].first,
308 points_to_add[ia].second),face);}
310 _supervertex[index].vertex = _TR.insert(Point(points_to_add[ia].first,
311 points_to_add[ia].second));
315 int coinciding_index = _CheckIfVertexPresent(_supervertex[index].vertex, index);
316 if (coinciding_index == index){
320 _supervertex[index].vertex->info() = _supervertex[index].coincidence = index;
322 if (_verbose) cout <<
" coinciding with vertex " << coinciding_index << endl;
331 _supervertex[coinciding_index].NNindex = index;
332 _supervertex[coinciding_index].NNdistance = 0.0;
333 indices_of_updated_neighbours.push_back(coinciding_index);
339 _supervertex[index].coincidence = _supervertex[coinciding_index].coincidence;
340 _supervertex[coinciding_index].coincidence = index;
351 indices_of_updated_neighbours.push_back(index);
352 _SetAndUpdateNearest(index, indices_of_updated_neighbours);
363 set<int>::iterator it2 = NeighbourUnion.begin();
364 for ( ; it2 != NeighbourUnion.end(); ++it2 ) {
367 if( j != INFINITE_VERTEX ) {
370 if (indices_removed.count(_supervertex[j].NNindex)) {
371 if (_verbose) cout <<
"j " << j << endl;
373 indices_of_updated_neighbours.push_back(j);
374 if (_verbose) cout <<
"NN of " << j <<
" : "
375 << _supervertex[j].NNindex
376 <<
", dist = " << _supervertex[j].NNdistance <<endl;
381 if (_verbose) cout <<
"Leaving DnnPlane::RemoveAndAddPoints" << endl;
387 void DnnPlane::_SetNearest (
const int j) {
389 if (_supervertex[j].coincidence != j){
390 _supervertex[j].NNindex = _supervertex[j].coincidence;
391 _supervertex[j].NNdistance = 0.0;
454 Vertex_handle current = _supervertex[j].vertex;
458 double mindist = HUGE_DOUBLE;
459 Vertex_handle nearest = _TR.infinite_vertex();
467 if ( vc->info().val() != INFINITE_VERTEX) {
469 if (_verbose) cout << current->info().val() <<
" " << vc->info().val() << endl;
473 if (_is_closer_to(current->point(), vc->point(), nearest, dist, mindist)){
475 if (_verbose) cout <<
"nearer ";
477 if (_verbose) cout << vc->point() <<
"; "<< dist << endl;
479 }
while (++vc != done);
482 _supervertex[j].NNindex = nearest->info().val();
483 _supervertex[j].NNdistance = mindist;
504 void DnnPlane::_SetAndUpdateNearest(
506 vector<int> & indices_of_updated_neighbours) {
509 if (_supervertex[j].coincidence != j){
510 _supervertex[j].NNindex = _supervertex[j].coincidence;
511 _supervertex[j].NNdistance = 0.0;
516 Vertex_handle current = _supervertex[j].vertex;
520 double mindist = HUGE_DOUBLE;
521 Vertex_handle nearest = _TR.infinite_vertex();
529 if (vc->info().val() != INFINITE_VERTEX) {
530 if (_verbose) cout << current->info().val() <<
" " << vc->info().val() << endl;
533 if (_is_closer_to(current->point(), vc->point(), nearest, dist, mindist)){
535 if (_verbose) cout <<
"nearer ";
539 int vcindx = vc->info().val();
540 if (_verbose) cout << vc->point() <<
"; "<< dist << endl;
542 if (_is_closer_to_with_hint(vc->point(), current->point(),
543 _supervertex[_supervertex[vcindx].NNindex].vertex,
544 dist, _supervertex[vcindx].NNdistance)){
545 if (_verbose) cout << vcindx <<
"'s NN becomes " << current->info().val() << endl;
546 _supervertex[vcindx].NNindex = j;
547 indices_of_updated_neighbours.push_back(vcindx);
569 }
while (++vc != done);
572 _supervertex[j].NNindex = nearest->info().val();
573 _supervertex[j].NNdistance = mindist;
576 FASTJET_END_NAMESPACE
Triangulation::Vertex_circulator Vertex_circulator
CGAL Point structure.