KSquare Utilities
ContourFollower.cpp File Reference
#include "FirstIncludes.h"
#include <stdlib.h>
#include <memory>
#include <math.h>
#include <complex>
#include <fstream>
#include <iostream>
#include <string>
#include <vector>
#include "MemoryDebug.h"
#include "kku_fftw.h"
#include "ContourFollower.h"
#include "Raster.h"
#include "KKStr.h"

Go to the source code of this file.

Functions

float CalcMagnitude (KK_DFT1D_Float::DftComplexType *dest, kkint32 index)
 
ComplexDouble ** GetFourierOneDimMask (kkint32 size)
 
ComplexDouble ** GetRevFourierOneDimMask (kkint32 size)
 

Variables

const MovDir movements [8]
 

Function Documentation

float CalcMagnitude ( KK_DFT1D_Float::DftComplexType dest,
kkint32  index 
)

Definition at line 204 of file ContourFollower.cpp.

207  {
208  double rp = (float)dest[index].real ();
209  double ip = (float)dest[index].imag ();
210  return (float)sqrt (rp * rp + ip * ip);
211  } /* CalcMagnitude */
ComplexDouble** GetFourierOneDimMask ( kkint32  size)

Definition at line 842 of file ContourFollower.cpp.

843 {
844  static
845  kkint32 curMaskSize = 0;
846 
847  static
848  ComplexDouble** fourierMask = NULL;
849 
850  if (size == curMaskSize)
851  return fourierMask;
852 
853  ComplexDouble N(size, 0);
854  ComplexDouble M(size, 0);
855 
856  kkint32 x;
857 
858  if (fourierMask)
859  {
860  for (x = 0; x < curMaskSize; x++)
861  {
862  delete fourierMask[x];
863  fourierMask[x] = NULL;
864  }
865 
866  delete[] fourierMask;
867  fourierMask = NULL;
868  }
869 
870  fourierMask = new ComplexDouble*[size];
871  for (x = 0; x < size; x++)
872  {
873  fourierMask[x] = new ComplexDouble[size];
874  }
875  curMaskSize = size;
876 
877 
878  ComplexDouble j;
879  ComplexDouble MinusOne (-1, 0);
880  j = sqrt (MinusOne);
881 
882  ComplexDouble Pi (3.14159265359, 0);
883  ComplexDouble One (1.0, 0);
884  ComplexDouble Two (2.0, 0);
885 
886  for (kkint32 m = 0; m < size; m++)
887  {
888  complex<double> mc (m, 0);
889 
890  for (kkint32 k = 0; k < size; k++)
891  {
892  complex<double> kc (k, 0);
893 
894  // double xxx = 2 * 3.14159265359 * (double)k * (double)m / (double)size;
895 
896  // fourierMask[m][k] = exp (MinusOne * j * Two * Pi * kc * mc / M);
897  fourierMask[m][k] = exp (MinusOne * j * Two * Pi * kc * mc / M);
898 
899  double exponetPart = 2.0 * 3.14159265359 * (double)k * (double)m / (double)size;
900  double realPart = cos (exponetPart);
901  double imgPart = -sin (exponetPart);
902 
903  if (realPart != fourierMask[m][k].real ())
904  {
905  continue;
906  }
907 
908  if (imgPart != fourierMask[m][k].imag ())
909  {
910  continue;
911  }
912  }
913  }
914 
915  return fourierMask;
916 } /* GetFourierOneDimMask */
__int32 kkint32
Definition: KKBaseTypes.h:88
std::complex< double > ComplexDouble
ComplexDouble** GetRevFourierOneDimMask ( kkint32  size)

Definition at line 921 of file ContourFollower.cpp.

922 {
923  static
924  kkint32 curRevMaskSize = 0;
925 
926  static
927  ComplexDouble** revFourierMask = NULL;
928 
929 
930  if (size == curRevMaskSize)
931  return revFourierMask;
932 
933  ComplexDouble N(size, 0);
934  ComplexDouble M(size, 0);
935 
936  kkint32 x;
937 
938 
939  if (revFourierMask)
940  {
941  for (x = 0; x < curRevMaskSize; x++)
942  {
943  delete revFourierMask[x];
944  revFourierMask[x] = NULL;
945  }
946 
947  delete[] revFourierMask;
948  revFourierMask = NULL;
949  }
950 
951 
952  revFourierMask = new ComplexDouble*[size];
953  for (x = 0; x < size; x++)
954  {
955  revFourierMask[x] = new ComplexDouble[size];
956  }
957  curRevMaskSize = size;
958 
959  ComplexDouble j;
960  ComplexDouble MinusOne (-1, 0);
961  ComplexDouble PositiveOne (1, 0);
962  j = sqrt (MinusOne);
963 
964  ComplexDouble Pi (3.1415926, 0);
965  ComplexDouble One (1.0, 0);
966  ComplexDouble Two (2.0, 0);
967 
968  for (kkint32 m = 0; m < size; m++)
969  {
970  complex<double> mc (m, 0);
971 
972  for (kkint32 k = 0; k < size; k++)
973  {
974  complex<double> kc (k, 0);
975 
976  // double xxx = 2 * 3.14159265359 * (double)k * (double)m / (double)size;
977 
978  // fourierMask[m][k] = exp (MinusOne * j * Two * Pi * kc * mc / M);
979  revFourierMask[m][k] = exp (PositiveOne * j * Two * Pi * kc * mc / M);
980 
981 
982  double exponetPart = 2.0 * 3.14159265359 * (double)k * (double)m / (double)size;
983  double realPart = cos (exponetPart);
984  double imgPart = sin (exponetPart);
985 
986  if (realPart != revFourierMask[m][k].real ())
987  {
988  continue;
989  }
990 
991  if (imgPart != revFourierMask[m][k].imag ())
992  {
993  continue;
994  }
995  }
996  }
997 
998  return revFourierMask;
999 } /* GetRevFourierOneDimMask */
__int32 kkint32
Definition: KKBaseTypes.h:88
std::complex< double > ComplexDouble

Variable Documentation

const MovDir movements[8]
Initial value:
= {{-1, 0},
{-1, 1},
{ 0, 1},
{ 1, 1},
{ 1, 0},
{ 1, -1},
{ 0, -1},
{-1, -1}
}

Definition at line 34 of file ContourFollower.cpp.