Example #1
0
void outxlsInt(Mat listK1, string filename)
{
	ofstream outEdge(filename);
	for (int i = 0; i < listK1.rows; i++)
	{
		for (int j = 0; j < listK1.cols; j++)
		{
			outEdge << listK1.at<int>(i, j) << "\t";
		}
		outEdge << "\n";
	}
	outEdge.close();
}
Example #2
0
vector<LPEdge> sampleLRTBig(vector<ModEdge> lGraph, bool silent)
{
	vector<LPEdge> tree;
	while (lGraph.size() != 0)
	{
		ModEdge e = lGraph.back();
		double denom = cofactorLog(wLaplacianNew(lGraph));
		vector<ModEdge> cGraph = contractEdgeNew(lGraph, e);
		double num = cofactorLog(wLaplacianNew(cGraph));
		double prob = e.weight * exp(num - denom);
		if (should(prob) || lGraph.size() == 1)
		{
			lGraph = cGraph;
			LPEdge outEdge(e.orig0, e.orig1, e.weight);
			tree.push_back(outEdge);
		}
		else
		{
			lGraph.pop_back();
		}
	}
	return tree;
}
Polygon* Polygon::reorientTo(Polygon* reference, int index, int refIndex,Pair &ctrans,float &crotation)
{

    Polygon* output = new Polygon(this);

    //determine translation
    Pair shift(reference->vertex[refIndex].x - vertex[index].x, reference->vertex[refIndex].y - vertex[index].y);
    ctrans = shift;
    //translate
    for(int i = 0; i < nVertices; i++)
    {
        output->vertex[i].x = output->vertex[i].x + shift.x;
        output->vertex[i].y = output->vertex[i].y + shift.y;
    }


    //determine rotation
    int isReflex;
    int magRefSqr;
    int magOutSqr;
    float dotProd;
    float rotation;
    if(output->order == reference->order)
    {
        Pair refEdge(reference->vertex[(refIndex+1) % reference->nVertices].x - reference->vertex[refIndex].x, reference->vertex[(refIndex+1) % reference->nVertices].y - reference->vertex[refIndex].y);
        Pair outEdge(output->vertex[(index-1+output->nVertices)%output->nVertices].x - output->vertex[index].x, output->vertex[(index-1+output->nVertices)%output->nVertices].y - output->vertex[index].y);
        isReflex = outEdge.x * refEdge.y - outEdge.y * refEdge.x;
        magRefSqr = (refEdge.x * refEdge.x) + (refEdge.y * refEdge.y);
        magOutSqr = (outEdge.x * outEdge.x) + (outEdge.y * outEdge.y);
        dotProd = (refEdge.x * outEdge.x) + (refEdge.y * outEdge.y);
        rotation = acos(dotProd/(sqrt((float)magRefSqr) * sqrt((float)magOutSqr)));
        if(isReflex > 0)
        {
            rotation = 2*PI - rotation;
        }
    }
    else
    {
        Pair refEdge(reference->vertex[(refIndex+1) % reference->nVertices].x - reference->vertex[refIndex].x, reference->vertex[(refIndex+1) % reference->nVertices].y - reference->vertex[refIndex].y);
        Pair outEdge(output->vertex[(index+1) % output->nVertices].x - output->vertex[index].x, output->vertex[(index+1) % output->nVertices].y - output->vertex[index].y);
        isReflex = outEdge.x * refEdge.y - outEdge.y * refEdge.x;
        magRefSqr = (refEdge.x * refEdge.x) + (refEdge.y * refEdge.y);
        magOutSqr = (outEdge.x * outEdge.x) + (outEdge.y * outEdge.y);
        dotProd = (refEdge.x * outEdge.x) + (refEdge.y * outEdge.y);
        rotation = acos(dotProd/(sqrt((float)magRefSqr) * sqrt((float)magOutSqr)));
        if(isReflex > 0)
        {
            rotation = 2*PI - rotation;
        }
    }
    crotation = rotation;
    //rotate
    Pair rot(0,0);
    for(int i = 0; i < nVertices; i++)
    {
        shift.x = output->vertex[i].x - reference->vertex[refIndex].x;
        shift.y = output->vertex[i].y - reference->vertex[refIndex].y;
        rot.x = shift.x * cos(rotation) + shift.y * sin(rotation);
        rot.y = -shift.x * sin(rotation) + shift.y * cos(rotation);
        output->vertex[i].x = rot.x + reference->vertex[refIndex].x;
        output->vertex[i].y = rot.y + reference->vertex[refIndex].y;
    }
    /*
    else
    {
    	//find the mean of the reference polygon
    	Pair refMean(reference->vertex[refIndex].x, reference->vertex[refIndex].y);
    	int count = 1;
    	for(int id = (refIndex+1) % reference->nVertices; id <= refStopIndex; id = (id+1) % reference->nVertices)
    	{
    		refMean.x += reference->vertex[id].x;
    		refMean.y += reference->vertex[id].y;
    		count++;
    	}
    	refMean.x /= count;
    	refMean.y /= count;

    	//find the mean of this polygon
    	Pair thisMean(vertex[index].x, vertex[index].y);
    	count = 1;
    	if(order != reference->order)
    	{
    		for(int id = (index+1) % nVertices; id <= stopIndex; id = (id+1) % nVertices)
    		{
    			thisMean.x += vertex[id].x;
    			thisMean.y += vertex[id].y;
    			count++;
    		}
    		thisMean.x /= count;
    		thisMean.y /= count;
    	}
    	else
    	{
    		for(int id = (index - 1 + nVertices) % nVertices; id >= stopIndex; id = (id - 1 + nVertices) % nVertices)
    		{
    			thisMean.x += vertex[id].x;
    			thisMean.y += vertex[id].y;
    			count++;
    		}
    		thisMean.x /= count;
    		thisMean.y /= count;
    	}

    	//determine translation
    	Pair shift(refMean.x - thisMean.x, refMean.y - thisMean.y);
    	//translate
    	for(int i = 0; i < nVertices; i++)
    	{
    		output->vertex[i].x = output->vertex[i].x + shift.x;
    		output->vertex[i].y = output->vertex[i].y + shift.y;
    	}
    }
    */
    return output;
}