int main(int argc,char* argv[])
	{
	/* Load the two point sets: */
	PointTree* trees[2];
	for(int i=0;i<2;++i)
		trees[i]=loadPointSet(argv[1+i]);
	
	/* Get the epsilon value: */
	Scalar epsilon=Scalar(atof(argv[3]));
	
	/* Compare the point sets: */
	int numMatches=0;
	for(int tree=0;tree<2;++tree)
		{
		PointTree& tree1=*trees[tree];
		PointTree& tree2=*trees[1-tree];
		for(int i=0;i<tree1.getNumNodes();++i)
			{
			/* Find a match for the point in tree1 in tree2: */
			MatchingPointFinder mpf(tree1.getNode(i),epsilon);
			tree2.traverseTreeDirected(mpf);
			if(mpf.isFound())
				++numMatches;
			}
		}
	
	/* Print the result: */
	std::cout<<"Similarity percentage between the two point sets: "<<double(numMatches)*100.0/double(trees[0]->getNumNodes()+trees[1]->getNumNodes())<<"%"<<std::endl;
	
	for(int i=0;i<2;++i)
		delete trees[i];
	
	return 0;
	}
Exemplo n.º 2
0
Arquivo: mp.c Projeto: rforge/mperm
/* The actually multiset permutation is done here recursively.*/
void mpf(FILE *fp, int cSize, char *leading, int vSize, int *nVec, char * cVec){
	int i, j;
	int *newNVec;
	char *newLeading;
	if(vSize==1){
		for(i=0; i<cSize; i++) putc(leading[i], fp);
		for(i=0; i<nVec[0]; i++) putc(cVec[0], fp);
		fputs("\n", fp);
		return;
	}
	for(i=0; i<vSize; i++){
		newLeading = (char *) calloc(cSize+1, sizeof(char));
		for(j=0; j<cSize; j++) newLeading[j] = leading[j];
		newLeading[cSize] = cVec[i];
		if(nVec[i]==1){
			//one group will be empty, do it forward
			//copy the non-empty
			newNVec = (int *) calloc(vSize-1, sizeof(int));
			for(j=0; j<i; j++) newNVec[j] = nVec[j];
			for(j=i+1; j<vSize; j++) newNVec[j-1] = nVec[j];
			char *newCVec;
			newCVec = (char *) calloc(vSize-1, sizeof(char));
			for(j=0; j<i; j++) newCVec[j] = cVec[j];
			for(j=i+1; j<vSize; j++) newCVec[j-1] = cVec[j];
			mpf(fp, cSize+1, newLeading, vSize-1, newNVec, newCVec);
			//free
			free(newCVec);
		}else{
			newNVec = (int *) calloc(vSize, sizeof(int));
			for(j=0; j<i; j++) newNVec[j] = nVec[j];
			newNVec[i] = nVec[i]-1;
			for(j=i+1; j<vSize; j++) newNVec[j] = nVec[j];
			mpf(fp, cSize+1, newLeading, vSize, newNVec, cVec);
		}
		free(newNVec);
		free(newLeading);
	}
}
Exemplo n.º 3
0
 static ::PyObject *convert(const piranha::real &r)
 {
     bp::object str(boost::lexical_cast<std::string>(r));
     try {
         bp::object mpmath = bp::import("mpmath");
         bp::object mpf = mpmath.attr("mpf");
         return bp::incref(mpf(str).ptr());
     } catch (...) {
         ::PyErr_SetString(
             PyExc_RuntimeError,
             "could not convert real number to mpf object - please check the installation of mpmath");
         bp::throw_error_already_set();
         // A fake return value that will never be returned, to make a GCC warning go away.
         return nullptr;
     }
 }
Exemplo n.º 4
0
	/* Methods: */
	void operator()(LidarProcessOctree::Node& node,unsigned int nodeLevel)
		{
		/* Check if this node is a leaf: */
		if(node.isLeaf())
			{
			/* Look for each node's point in the subtract set: */
			for(unsigned int i=0;i<node.getNumPoints();++i)
				{
				MatchingPointFinder mpf(node[i],epsilon);
				subtractPoints.traverseTreeDirected(mpf);
				if(!mpf.isFound())
					{
					/* Point has no match in subtract set; add it to point accumulator: */
					pa.addPoint(PointAccumulator::Point(node[i].getComponents()),PointAccumulator::Color(node[i].value.getRgba()));
					}
				}
			}
		}
Exemplo n.º 5
0
Arquivo: mp.c Projeto: rforge/mperm
/* main entrance, read in group size vector, create file handle, call subroutine.*/
SEXP MPfile(SEXP Rvec){
	int i, m, n;
	double nPerm, mSize;
	int *vec;
	char *vsymbol;
	Rvec = coerceVector(Rvec, INTSXP);
	vec = INTEGER(Rvec);
	m = length(Rvec);
	//check size
	if(m > 10){
		printf("# of group > 10, plz take a smaller bite.\n");
		return R_NilValue;
	}

	for(i = 0; i < m; i++){
		if(vec[i]==0){
			printf("Can't have group size of 0.");
			return R_NilValue;
		}
	}
	
	printf("The group sizes are: ");
	for (i = 0; i < m-1; i++) printf("%d, ", vec[i]);
	printf("%d \n", vec[m-1]);

	//get sum
	n = 0;
	for (i = 0; i < m; i++) n += vec[i];
	//calculate # of permutation
	nPerm = factorial(n);
	for (i = 0; i < m; i++) nPerm /= factorial(vec[i]);
	printf("Total # of permutation is %g.\n", nPerm);
	
	mSize = nPerm*m/1024/1024;
	printf("The estimated output file size is %g Mega byte.\n", mSize);
	if(mSize > 500){
		printf("File size too large.\n");
		return R_NilValue;
	}
	
	//create symbol array
	char * vSymbol;
	vSymbol = (char *) calloc(m, sizeof(char));
	for (i = 0; i < m; i++) vSymbol[i] = 48+i;
	//open file
	FILE *fp;
	fp = fopen("output.txt", "w");
	char *temp;
	if (fp == NULL){
		printf("Error opening file.\n");
	}
	else{
		mpf(fp, 0, temp, m, vec, vSymbol);
	}

	//close file
	fclose(fp);
	printf("Permutation of the group has been created in file output.txt.\n");
	return R_NilValue;
	
}
Exemplo n.º 6
0
mpf CosineCalculator::calculatePrecision(int exponent) {
  mpf epsilon(0, exponent);
  mpf_pow_ui(epsilon.get_mpf_t(), mpf(exponent >= 0 ? 0.1 : 10).get_mpf_t(), std::abs(exponent));
  return epsilon;
}