src/Mesh/findMatchingVertex.cc
//------------------------------------------------------------------------------
// Find the vertex in the second list that best lines up with the first in 
// the first list.  Assumes that the two lists are the same vertices in opposite
// order with arbitrary starting points.
//------------------------------------------------------------------------------
Find the vertex in the second list that best lines up with the first in
the first list.  Assumes that the two lists are the same vertices in opposite
order with arbitrary starting points.
Find the vertex in the second list that best lines up with the first in the first list . Assumes that the two lists are the same vertices in opposite order with arbitrary starting points .
unsigned
findMatchingVertex(const std::vector<Dim<3>::Vector>& verticesi,
                   const std::vector<Dim<3>::Vector>& verticesj,
                   const std::vector<unsigned>& indicesi,
                   const std::vector<unsigned>& indicesj) {
  REQUIRE(indicesi.size() == indicesj.size());
  const unsigned n = indicesi.size();
  unsigned i, j, ji;
  vector<double> chi2;
  chi2.reserve(n);
  for (i = 0; i != n; ++i) {
    chi2.push_back(0.0);
    for (j = 0; j != n; ++j) {
      ji = (j <= i ? (i - j) : (n - (j - i)));
      CHECK(ji < n);
      CHECK(indicesi[j] < verticesi.size());
      CHECK(indicesj[ji] < verticesj.size());
      chi2.back() += (verticesi[indicesi[j]] -
                      verticesj[indicesj[ji]]).magnitude2();
    }
  }
  j = distance(chi2.begin(), min_element(chi2.begin(), chi2.end()));
  ENSURE2(j < n, "Unable to find matching vertex: " << j << " " << n);
  ENSURE2(chi2[j] < 1.0e-5, "Suspiciously large chi2 in findMatchingVertex!  " << chi2[j] << " : " << j);
  return j;
}
unsigned findMatchingVertex ( const std :: vector < Dim < 3 > :: Vector > & verticesi , const std :: vector < Dim < 3 > :: Vector > & verticesj , const std :: vector < unsigned > & indicesi , const std :: vector < unsigned > & indicesj ) { REQUIRE ( indicesi . size ( ) == indicesj . size ( ) ) ; const unsigned n = indicesi . size ( ) ; unsigned i , j , ji ; vector < double > chi2 ; chi2 . reserve ( n ) ; for ( i = 0 ; i != n ; ++ i ) { chi2 . push_back ( 0.0 ) ; for ( j = 0 ; j != n ; ++ j ) { ji = ( j <= i ? ( i - j ) : ( n - ( j - i ) ) ) ; CHECK ( ji < n ) ; CHECK ( indicesi [ j ] < verticesi . size ( ) ) ; CHECK ( indicesj [ ji ] < verticesj . size ( ) ) ; chi2 . back ( ) += ( verticesi [ indicesi [ j ] ] - verticesj [ indicesj [ ji ] ] ) . magnitude2 ( ) ; } } j = distance ( chi2 . begin ( ) , min_element ( chi2 . begin ( ) , chi2 . end ( ) ) ) ; ENSURE2 ( j < n , " " << j << " " << n ) ; ENSURE2 ( chi2 [ j ] < 1.0e-5 , " " << chi2 [ j ] << " " << j ) ; return j ; }
Find the vertex in the second list that best lines up with the first in
the first list.
Find the vertex in the second list that best lines up with the first in the first list .