Fork me on GitHub

Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • external/fastjet/internal/DnnPlane.hh

    rd7d2da3 r35cdc46  
    1 //STARTHEADER
    2 // $Id: DnnPlane.hh 2577 2011-09-13 15:11:38Z salam $
    3 //
    4 // Copyright (c) 2005-2011, Matteo Cacciari, Gavin P. Salam and Gregory Soyez
     1//FJSTARTHEADER
     2// $Id: DnnPlane.hh 3442 2014-07-24 07:20:49Z salam $
     3//
     4// Copyright (c) 2005-2014, Matteo Cacciari, Gavin P. Salam and Gregory Soyez
    55//
    66//----------------------------------------------------------------------
     
    1313//
    1414//  The algorithms that underlie FastJet have required considerable
    15 //  development and are described in hep-ph/0512210. If you use
     15//  development. They are described in the original FastJet paper,
     16//  hep-ph/0512210 and in the manual, arXiv:1111.6097. If you use
    1617//  FastJet as part of work towards a scientific publication, please
    17 //  include a citation to the FastJet paper.
     18//  quote the version you use and include a citation to the manual and
     19//  optionally also to hep-ph/0512210.
    1820//
    1921//  FastJet is distributed in the hope that it will be useful,
     
    2527//  along with FastJet. If not, see <http://www.gnu.org/licenses/>.
    2628//----------------------------------------------------------------------
    27 //ENDHEADER
     29//FJENDHEADER
    2830
    2931
     
    4446/// class derived from DynamicNearestNeighbours that provides an
    4547/// implementation for the Euclidean plane
     48///
     49/// This class that uses CGAL Delaunay triangulation for most of the
     50/// work (it allows for easy and efficient removal and addition of
     51/// points and circulation over a point's neighbours). The treatment
     52/// of coincident points is not supported by CGAL and is implemented
     53/// according to the method specified in
     54/// issue-tracker/2012-02-CGAL-coincident/METHOD
    4655/// \endif
    4756class DnnPlane : public DynamicNearestNeighbours {
     
    5766  /// Returns the index of  the nearest neighbour of point labelled
    5867  /// by ii (assumes ii is valid)
    59   int NearestNeighbourIndex(const int & ii) const ;
     68  int NearestNeighbourIndex(const int ii) const ;
    6069
    6170  /// Returns the distance to the nearest neighbour of point labelled
    6271  /// by index ii (assumes ii is valid)
    63   double NearestNeighbourDistance(const int & ii) const ;
     72  double NearestNeighbourDistance(const int ii) const ;
    6473
    6574  /// Returns true iff the given index corresponds to a point that
    6675  /// exists in the DNN structure (meaning that it has been added, and
    6776  /// not removed in the meantime)
    68   bool Valid(const int & index) const;
     77  bool Valid(const int index) const;
    6978
    7079  void RemoveAndAddPoints(const std::vector<int> & indices_to_remove,
     
    8089  double phi(const int i) const;
    8190
    82  private:
     91private:
    8392
    8493  /// Structure containing a vertex_handle and cached information on
     
    8897    double NNdistance;
    8998    int NNindex;
     99    int coincidence;  // ==vertex->info.val() if no coincidence
     100                      // points to the coinciding SV in case of coincidence
    90101    // later on for cylinder put a second vertex?
    91102  };
     
    95106  bool _verbose;
    96107
    97   static const bool _crash_on_coincidence = true;
    98   //static const bool _crash_on_coincidence = false;
     108  //static const bool _crash_on_coincidence = true;
     109  static const bool _crash_on_coincidence = false;
    99110
    100111  Triangulation _TR; /// CGAL object for dealing with triangulations
     
    111122  /// Determines the index and distance of the nearest neighbour to
    112123  /// point j and puts the information into the _supervertex entry for j
    113   void _SetNearest(const int & j);
     124  void _SetNearest(const int j);
    114125
    115126  //----------------------------------------------------------------------
     
    123134  /// Note that j is NOT pushed onto indices_of_updated_neighbours --
    124135  /// if you want it there, put it there yourself.
    125   void _SetAndUpdateNearest(const int & j,
     136  void _SetAndUpdateNearest(const int j,
    126137                            std::vector<int> & indices_of_updated_neighbours);
    127138
    128139  /// given a vertex_handle returned by CGAL on insertion of a new
    129   /// points, crash if it turns out that it corresponds to a vertex
    130   /// that we already knew about (usually because two points coincide)
    131   void _CrashIfVertexPresent(const Vertex_handle & vertex,
    132                              const int & its_index);
    133 
     140  /// points, returns the coinciding vertex's value if it turns out
     141  /// that it corresponds to a vertex that we already knew about
     142  /// (usually because two points coincide)
     143  int _CheckIfVertexPresent(const Vertex_handle & vertex,
     144                            const int its_index);
     145
     146  //----------------------------------------------------------------------
     147  /// if the distance between 'pref' and 'candidate' is smaller (or
     148  /// equal) than the one between 'pref' and 'near', return true and
     149  /// set 'mindist' to that distance. Note that it is assumed that
     150  /// 'mindist' is the euclidian distance between 'pref' and 'near'
     151  ///
     152  /// Note that the 'near' point is passed through its vertex rather
     153  /// than as a point. This allows us to handle cases where we have no min
     154  /// yet (near is the infinite vertex)
     155  inline bool _is_closer_to(const Point &pref,
     156                            const Point &candidate,
     157                            const Vertex_handle &near,
     158                            double & dist,
     159                            double & mindist){
     160    dist = _euclid_distance(pref, candidate);
     161    return _is_closer_to_with_hint(pref, candidate, near, dist, mindist);
     162  }
     163
     164  /// same as '_is_closer_to' except that 'dist' already contains the
     165  /// distance between 'pref' and 'candidate'
     166  inline bool _is_closer_to_with_hint(const Point &pref,
     167                                      const Point &candidate,
     168                                      const Vertex_handle &near,
     169                                      const double & dist,
     170                                      double & mindist){
     171   
     172    // check if 'dist', the pre-computed distance between 'candidate'
     173    // and 'pref' is smaller than the distance between 'pref' and its
     174    // currently registered nearest neighbour 'near' (and update
     175    // things if it is)
     176    //
     177    // Interestingly enough, it has to be pointed out that the use of
     178    // 'abs' instead of 'std::abs' returns wrong results (apparently
     179    // ints without any compiler warning)
     180    //
     181    // The (near != NULL) test is there for one single reason: when
     182    // checking that a newly inserted point is not closer than a
     183    // previous NN, if that distance comparison involves a "nearly
     184    // degenerate" distance we need to access near->point. But
     185    // sometimes, in the course of RemoveAndAddPoints, its previous NN
     186    // has been deleted and its vertex (corresponding to 'near') set
     187    // to NULL. This is not a problem as all points having a deleted
     188    // point as NN will have their NN explicitly recomputed at the end
     189    // of RemoveAndAddPoints so here we should just make sure there is
     190    // no crash... that's done by checking (near != NULL)
     191    if ((std::abs(dist-mindist)<DISTANCE_FOR_CGAL_CHECKS) &&
     192        (near != NULL) &&
     193        (_euclid_distance(candidate, near->point())<DISTANCE_FOR_CGAL_CHECKS)){
     194      // we're in a situation where there might be a rounding issue,
     195      // use CGAL's distance computation to get it right
     196      //
     197      // Note that in the test right above,
     198      // (abs(dist-mindist)<1e-12) guarantees that the current
     199      // nearest point is not the infinite vertex and thus
     200      // nearest->point() is not ill-defined
     201      if (_verbose) std::cout << "using CGAL's distance ordering" << std::endl;
     202      if (CGAL::compare_distance_to_point(pref, candidate, near->point())!=CGAL::LARGER){
     203        mindist = dist;
     204        return true;
     205      }
     206    } else if (dist <= mindist) {
     207      // Note that the use of a <= in the above expression (instead of
     208      // a strict ordering <) is important in one case: when checking
     209      // if a new point is the new NN of one of the points in its
     210      // neighbourhood, in case of distances being ==, we are sure
     211      // that 'candidate' is in a cell adjacent to 'pref' while it may
     212      // no longer be the case for 'near'
     213      mindist = dist;
     214      return true;
     215    }
     216   
     217    return false;
     218  }
     219
     220  /// if a distance between a point and 2 others is smaller than this
     221  /// and the distance between the two points is also smaller than this
     222  /// then use CGAL to compare the distances.
     223  static const double DISTANCE_FOR_CGAL_CHECKS; 
     224 
    134225};
    135226
     
    138229// functions defined above
    139230
    140 inline int DnnPlane::NearestNeighbourIndex(const int & ii) const {
     231inline int DnnPlane::NearestNeighbourIndex(const int ii) const {
    141232  return _supervertex[ii].NNindex;}
    142233
    143 inline double DnnPlane::NearestNeighbourDistance(const int & ii) const {
     234inline double DnnPlane::NearestNeighbourDistance(const int ii) const {
    144235  return _supervertex[ii].NNdistance;}
    145236
    146 inline bool DnnPlane::Valid(const int & index) const {
     237inline bool DnnPlane::Valid(const int index) const {
    147238  if (index >= 0 && index < static_cast<int>(_supervertex.size())) {
    148239    return (_supervertex[index].vertex != NULL);} else {return false;} }
Note: See TracChangeset for help on using the changeset viewer.