Exemplo n.º 1
0
Foam::pointField Foam::SmootherCell::geometricTransform()
{
    // TODO if found a way to have the face label from cellShape,
    // store face centre in MeshSmoother and avoid use of pointFields dO
    // faceList fList = cell.faces();
    // fList[0].centre(pts);

    // Faces centres
    pointField fc(6);
    const label f[] = {0, 0, 1, 2, 0, 4};
    const label g[] = {1, 4, 5, 6, 3, 7};
    const label h[] = {2, 5, 6, 7, 7, 6};
    const label i[] = {3, 1, 2, 3, 4, 5};
    for (label j = 0; j < 6; ++j)
    {
        fc[j] = (initPt(f[j]) + initPt(g[j]) + initPt(h[j]) + initPt(i[j]))/4.0;
    }

    // Transfomred points
    pointField H(8);
    const label a[] = {0, 0, 0, 0, 5, 5, 5, 5};
    const label b[] = {1, 2, 3, 4, 4, 1, 2, 3};
    const label d[] = {4, 1, 2, 3, 1, 2, 3, 4};
    for (label j = 0; j < 8; ++j)
    {
        const point c = (fc[a[j]] + fc[b[j]] + fc[d[j]])/3.0;
        const point n = (fc[b[j]] - fc[a[j]]) ^ (fc[d[j]] - fc[a[j]]);
        H[j] = c + _transParam/std::sqrt(mag(n))*n;
    }

    // Length scale
    scalar length = 0.0, lengthN = 0.0;
    const label k[] = {0, 1, 2, 3, 0, 1, 2, 3, 4, 5, 6, 7};
    const label l[] = {1, 2, 3, 0, 4, 5, 6, 7, 5, 6, 7, 4};
    for (label j = 0; j < 12; ++j)
    {
        length += mag(initPt(k[j]) - initPt(l[j]));
        lengthN += mag(H[k[j]] - H[l[j]]);
    }
    length /= lengthN;

    const point c = (H[0] + H[1] + H[2] + H[3] + H[4] + H[5] + H[6] + H[7])/8.0;
    const pointField C(8, c);

    return (C + length*(H - C));
}
Exemplo n.º 2
0
//The main function of the sweep algorithm.
void findIntersection(float pt[][2])
{
	int i,j;

	//"ordHead" doesn't save any data
	//ordHead->next is the first point in ordered list
	POrder *ordHead;
	POrder *ordTemp;
	ordHead = (POrder *)malloc(LEN_P);
	ordHead->next=NULL;

	//Initialize the original points and ordered list.
	initPt(ordHead,pt);

	//Draw the original points and lines.
	glPointSize(3.0);
	glBegin(GL_POINTS);
	glColor3f(0.0,0.0,0.0);
	for(i=0;i<NUM_PT;i+=2){
		glVertex2f(pt[i][0],pt[i][1]);
		glVertex2f(pt[i+1][0],pt[i+1][1]);
	}
	glEnd();
	glColor3f(0.5,0.5,0.5);
	glBegin(GL_LINES);
	for(i=0;i<NUM_PT;i++)
		glVertex2f(pt[i][0],pt[i][1]);
	glEnd();

	//Scan the ordered list and check intersection,
	//"top" is always the root node of the scan tree
	tree *top;
	top=(struct tree *)malloc(LEN_S);
	top->id=ordHead->next;
	top->left=NULL;
	top->right=NULL;
	top->father=NULL;

	_inteCount=0;
	_maxPtOrd=NUM_PT;
	tree *left_s;
	tree *right_s;
	tree *left_l;
	tree *right_l;

	tree *scan_temp;

	ordTemp = ordHead->next->next;
	i=1;
	float x_scan;
	float y_scan;

	while(i<_maxPtOrd)
	{
		if(ordTemp==NULL)
			break;
		tree *scan;
		scan=(struct tree *)malloc(LEN_S);
		scan->id=ordTemp;

		x_scan=scan->id->x;
		y_scan=scan->id->y;

		if(scan->id->type==ORD_UPPER)
		{
			//For an upper point:

			//Add it into scan tree.
			if(top==NULL)
			{
				top=scan;
				scan->id=ordTemp;
				scan->father=NULL;
				scan->left=NULL;
				scan->right=NULL;
			}else
				addIntoScan(top,scan,scan->id->y);

			//Get left and right neighbors in the scan tree.
			left_s=get_left(scan);
			while(left_s!=NULL && left_s->id->type!=ORD_UPPER)
				left_s=get_left(left_s);
			right_s=get_right(scan);
			while(right_s!=NULL && right_s->id->type!=ORD_UPPER)
				right_s=get_right(right_s);

			//Check intersection points.
			if(left_s!=NULL)
				checkInte(ordHead->next,left_s->id,scan->id,top,x_scan,y_scan);
			if(right_s!=NULL)
				checkInte(ordHead->next,scan->id,right_s->id,top,x_scan,y_scan);

		}else if(scan->id->type==ORD_LOWER){
			//For a lower point:

			//Find its upper point in scan tree.
			scan_temp=searchInScan(top,scan->id->l,NO_LINE,SCAN_L);

			//Get left and right neighbors of the upper point in scan tree.
			left_s=get_left(scan_temp);
			while(left_s!=NULL && (left_s->id->type!=ORD_UPPER || left_s==scan))
				left_s=get_left(left_s);
			right_s=get_right(scan_temp);
			while(right_s!=NULL && (right_s->id->type!=ORD_UPPER || right_s==scan))
				right_s=get_right(right_s);

			//Check intersection between left and right neighbors of the deleted line.
			if(left_s!=NULL && right_s!=NULL)
				checkInte(ordHead->next,left_s->id,right_s->id,top,x_scan,y_scan);

			//Delete the upper point.
			top=dltFromScan(top,scan_temp);

			//Find inte-points of the line, and mark them.
			//If both of two inte-lines have been deleted,
			//their inte-points have to be deleted in the scan tree.
			for(j=0;j<_inteCount;j++)
			{
				if(found[j][0]==scan->id->l || found[j][1]==scan->id->l)
				{
					if(found[j][2]==FND_2)
						found[j][2]=FND_1;
					else if(found[j][2]==FND_1){
						scan_temp=searchInScan(top,found[j][0],found[j][1],SCAN_L_L2);
						if(scan_temp!=NULL)
							top=dltFromScan(top,scan_temp);
						found[j][2]=FND_D;
					}
				}
			}
		}else if(scan->id->type==ORD_INTE){
			//For an intersection point:

			//Find its node in the scan tree
			//Because the current "scan" node is not in the scan tree,
			//only its "id" pointer is evaluated.
			scan=searchInScan(top,scan->id->l,scan->id->l2,SCAN_L_L2);

			//Check for inte-points between its left line and its right neighbor,
			//and between its right line and its left neighbor.

			left_l=searchInScan(top,scan->id->l,NO_LINE,SCAN_L);
			right_l=searchInScan(top,NO_LINE,scan->id->l2,SCAN_L2);

			left_s=get_left(left_l);
			while(left_s!=NULL && (left_s->id->type!=ORD_UPPER || left_s==left_l || left_s==right_l))
				left_s=get_left(left_s);
			right_s=get_right(right_l);
			while(right_s!=NULL && (right_s->id->type!=ORD_UPPER || right_s==left_l || right_s==right_l))
				right_s=get_right(right_s);

			switchScan(left_l,right_l);

			if(left_s!=NULL)
				checkInte(ordHead->next,left_s->id,left_l->id,top,x_scan,y_scan);
			if(right_s!=NULL)
				checkInte(ordHead->next,right_l->id,right_s->id,top,x_scan,y_scan);

			//Delete the inte-point node in the scan tree.
			top=dltFromScan(top,scan);
		}
		//Get next point in the ordered list
		ordTemp=ordTemp->next;
		i++;
	}

	//Draw all the intersection points.
	glPointSize(4.0);
	glBegin(GL_POINTS);
	glColor3f(0.0,0.0,1.0);
	for(i=0;i<_inteCount;i++)
		glVertex2f(inte[i][0],inte[i][1]);
	glEnd();
}