www.pudn.com > ManualCameraCalibrationSourceCode_v1.0.rar > KMathematica.cpp


// KMathematica.cpp: implementation of the KMathematica class. 
// 
////////////////////////////////////////////////////////////////////// 
 
#include "stdafx.h" 
#include "ZhangImplementation_1.h" 
#include "KMathematica.h" 
 
#ifdef _DEBUG 
#undef THIS_FILE 
static char THIS_FILE[]=__FILE__; 
#define new DEBUG_NEW 
#endif 
 
////////////////////////////////////////////////////////////////////// 
// Construction/Destruction 
////////////////////////////////////////////////////////////////////// 
 
KMathematica::KMathematica() 
{ 
 
} 
 
KMathematica::~KMathematica() 
{ 
 
} 
 
// returns a list of all possible permutations of a given array 
int ** KMathematica::PermutationMatrix(int *arr, int n) 
{ 
	int ** out  = NULL; 
	int ** temp = NULL; 
 
	int i,j,k,tS,missed,prime; 
	 
	int size = Permutation(n,n); 
 
	// allocate memory for output 
	out = new int*[size];  
	for( i=0; i0; i-- ) 
	{ 
		ret *= i; 
	} 
 
	return ret; 
} 
 
int * KMathematica::Sort(int *arr, int n) 
{ 
	return 0; 
} 
 
int KMathematica::Place(int number, int *arr, int n) 
{ 
	return -1; 
} 
 
long KMathematica::Permutation(int n, int m) 
{ 
	return Combination(n,m)*Factorial(m); 
} 
 
long KMathematica::Combination(int n, int m) 
{ 
	long ret=1; 
 
	if( m > n/2 ) 
		m = n-m; 
	 
	for(int i=m; i>0; i-- ) 
	{ 
		ret *= n; 
		n--; 
	} 
 
	for( i=m; i>0; i-- ) 
	{ 
		ret /= i; 
	} 
 
	return ret; 
} 
 
double KMathematica::FindOrientation(CvPoint2D32f *points, int n) 
{ 
	float a = 0; 
	float b = 0; 
	float c = 0; 
 
	int pointNumber = n; 
 
	CvPoint2D32f center; 
	center = FindCenterofMass( points, n ); 
 
	for( int i=0; iPI ) theta -= 2*PI; 
   return theta; 
} 
 
// returns a list of all possible (n,m) combinations of a given array 
int ** KMathematica::CombinationMatrix(int *arr, int n, int m) 
{ 
	int i,j,k,tS,missed,prime; 
	int ** out = NULL; 
	int ** temp = NULL; 
 
	if( n < m ) return NULL; 
 
	int size = Combination(n,m); 
 
	// allocate memory for output 
	out = new int*[size];  
	for( i=0; i 0 ) 
		{ 
			temp = CombinationMatrix(tarr, k ,m-1); // compute n-1 by m-1 combination 
			 
			if( temp == NULL ) 
			{ 
				continue; 
			} 
 
			for( j=0; j