Question about Normalized Cross Correlation

hello, does anyone know a little about Co-registration?
i read the source code of
There is a normalizedCrossCorrelation function in this class(Line)

i read it for quit a long time and i am still confused. i have several questions.
the basic principle of normalizedCrossCorrelation goes like this:

  1. are the logic in the code aligned with this principal?
  2. whats the function of LinearAlgebraUtils.setdata()?
  3. why the DoubleMatrix ncc( for storing coherence value ) twice lager as magMaster(line 83)
    4.what does the role of registrationWindowAccRange,registrationWindowAccAzimuth, OversamplingFactor play?
    think for your spreading of knowledge. Thank you !

this is the website of this code.anyone interested in it can check.

the  above code is the core of  the Offset-tracking operator, which is used to return  the azimuth and range offset and coherence.

After some hard decoding, i guess i caught the framework of this code. it directly use the whole registration window patches of master and slave image to calculate offsets,without choosing sub-size chips in the registration windows and sliding them to match for best coherence.
After having the coherence matrix(twice height and width as the registration window), range and azimuth offset of pixel lever accuracy can be get by retrieving the row and column of the largest element in coherence matrix.
Then there is a Oversamping factor for achieving Sub-pixel accuracy of range and azimuth offset, by oversamping a certain size sub-matrix of coherence matrix (The sub-matrix’s central point is the largest element of coherence matrix, the certain size is decided by registrationWindowAccRange,registrationWindowAccAzimuth ).
however i only know how was it proceed, why the results correspond with the real offset is unclear for likes a math tricks for me.But for a application-er , i guess its enough. if somebody knows and wantS to share, you are very welcomed.
I noticed for SNPE 5.0, the helper of offset tracking operator said it used normalizedCrossCorrelation Function. in later version , it switched to CrossCorrelationFFT. IS THAT RIGHT?