⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pm_genproc.cpp

📁 mpi 结合vc编程用模拟退火法算一个最小路径的值
💻 CPP
📖 第 1 页 / 共 2 页
字号:
{
	Q_Checksize(q);
	q->r[q->tail] = *r;
	if (++q->tail == q->size) q->tail = 0;
}

/* Q_Dequeue - remove a rectangle from the queue */
void Q_Dequeue(rect_queue *q, rect *r)
{
	double rand_no;
	*r = q->r[q->head];
	if (++q->head == q->size) q->head = 0;
	if (q->randomize && ((q->head == q->randomPt) ||
		(q->head == q->randomPt + 1))) 
	{
		int i, j, numItems;
		rect temp;
		numItems = (q->tail<q->head)
			? q->size-q->head + q->tail
			: q->tail - q->head;
		for (i = q->head; i != q->tail; i++) 
		{
			rand_no = drand48();
			j = (int)(rand_no * numItems) + q->head;
			if (j >= q->size) j -= q->size;
			temp = q->r[j];
			q->r[j] = q->r[i];
			q->r[i] = temp;
			if (i == q->size-1) 
			{
				i = -1;
			}
		}
		q->randomPt = q->tail;
	}
}




int RectBorderLen(rect *r)
{
	return (r->r-r->l) ?
		(r->b-r->t) ?
		(2 * (r->r-r->l + r->b-r->t))
		:
	(r->r - r->l + 1)
		:
	   (r->b-r->t) ?
		   (r->b - r->t + 1)
		   :
	   1;
}


void PrintHelp(char *progName)
{
	printf("Options recognized by %s:\n", progName);
	printf("(defaults are in parentheses ())\n");
	printf("   -i <filename>              (none) input file\n");
	printf("   -xpos <xpos>               (%d) window horizontal coordinate\n",
		DEF_xpos);
	printf("   -ypos <xpos>               (%d) window vertical coordinate\n",
		DEF_ypos);
	printf("   -width <width>             (%d) width of computed area in points\n", DEF_width);
	printf("   -height <height>           (%d) height of computed area in points\n", DEF_height);
	printf("   -boundary <boundary>       (%.1lf) boundary value for M-set computation\n", DEF_boundary);
	printf("   -maxiter <max. iter>       (%d) maximum # of iterations for M-set\n", DEF_maxiter);
	printf("                              compuptation algorithm\n");
	printf("   -rmin <real min.>          (%.2lf) minimum real coordinate of computed area\n", DEF_rmin);
	printf("   -rmax <real max.>          (%.2lf) maximum real coordinate of computed area\n", DEF_rmax);
	printf("   -imin <imag. min.>         (%.2lf) minimum imaginary coordinate of computed\n", DEF_imin);
	printf("                              area\n");
	printf("   -imax <imag. max.>         (%.2lf) maximum imaginary coordinate of computed\n", DEF_imax);
	printf("                              area\n");
	printf("\n");
	printf("      alternate form: (if specified, overrides <r | i><min | max>)\n");
	printf("   -rcenter <real center>     (%.2lf) center real coordinate of computed area\n", (DEF_rmin + DEF_rmax)/2);
	printf("   -icenter <imag. center>    (%.2lf) center imaginary coordinate of computed\n", (DEF_imin + DEF_imax)/2);
	printf("                              area\n");
	printf("   -radius <area radius>      (%.2lf) radius of the computed area\n", (DEF_rmax - DEF_rmin));
	printf("\n");
	printf("   -breakout <breakout size>  (%d) maximum length or width rectangle to\n", DEF_breakout);
	printf("                              subdivide\n");
	printf("   -colors <# of colors>      (%d) number of colors to request\n", DEF_numColors);
	printf("   -colreduce <reduce factor> (%d) factor by which to scale down iteration\n", DEF_colReduceFactor);
	printf("                              values to reduce color changes\n");
	printf("   <+, ->zoom                  (%s) turn on (off) drag&zoom\n",
		DEF_zoom ? "on" : "off");
	printf("   <+, ->randomize             (%sset) (on, off) compute regions in as random of\n",
		DEF_randomize ? "" : "not ");
	printf("                              order as possible\n");
	printf("   -bw                        (%sset) draw in black and white instead of\n", DEF_bw ? "" : "not ");
	printf("                              color\n");
	exit(0);
}


MPE_Color Iter2Color(Flags *flags, int iter)
{
	if (flags->winspecs->bw) 
	{
		return ((iter == flags->maxiter) ? MPE_BLACK :
		((iter / flags->colReduceFactor) % 2) ? MPE_WHITE : MPE_BLACK);
	} 
	else 
	{
		if (iter == flags->maxiter) 
		{
			return MPE_BLACK;
		} 
		else 
		{
			return flags->winspecs->colorArray[(iter / flags->colReduceFactor) %
				flags->winspecs->numColors];
		}
	}
}


void ChunkIter2Color(Flags *flags, int *iterData, int *colorData, int size)
{
	int i;
	
	for (i = 0; i<size; i++) 
	{
		*colorData = Iter2Color(flags, *iterData);
		colorData++;
		iterData++;
	}
}




int ComputeChunk(Flags *flags, rect *r, MPE_Point *pointData, int *iterData, int maxnpoints, int *npoints)
{
	int i, x, y;
	CalcField(flags->fractal, iterData, r->l, r->r, r->t, r->b);
    /* compute the field */
	
	*npoints = (r->r - r->l + 1) * (r->b - r->t + 1);
	x = r->l;  y = r->t;
	for (i = 0; i<*npoints; i++) 
	{
		pointData[i].x = x++;
		pointData[i].y = y;
		pointData[i].c = Iter2Color(flags, iterData[i]);
		if (x > r->r) 
		{
			x = r->l;
			y++;
		}
	}
	return 0;
}


/*
int DrawChunk(MPE_XGraph graph, MPE_Color *colorData, rect r)
{
	int a, b;
	
	for (b = r.t; b <= r.b; b++) 
	{
		for (a = r.l; a <= r.r; a++) 
		{
			MPE_Draw_point(graph, a, b, *colorData);
			colorData++;
		}
	}
	MPE_Update(graph);
	return 0;
}
//*/

#define LOOP(start, toContinue, incrBefore, fn, check, lbl, incrAfter) \
	start; \
while (toContinue) \
{ \
incrBefore; \
pointPtr->x = x; \
pointPtr->y = y; \
pointPtr->c = Iter2Color(flags, fn(re, im)); \
check \
lbl \
incrAfter; \
}

/*
fprintf(stderr, "computed (%d %d) to be %d\n", x, y, pointPtr->c); \
*/

/* really, all these stupid loop macros will make it easier! */

#define LOOP_TOP(fn, check, lbl) \
	LOOP((y = r.t, x = r.l + 1), x <= r.r, NUM_ASSIGN(re, NUM_ADD(re, rstep)), \
fn, check, lbl, (pointPtr++, x++));

#define LOOP_RIGHT(fn, check, lbl) \
	LOOP((x = r.r, y = r.t + 1), y <= r.b, NUM_ASSIGN(im, NUM_ADD(im, istep)), \
fn, check, lbl, (pointPtr++, y++));

#define LOOP_BOTTOM(fn, check, lbl) \
	LOOP((y = r.b, x = r.r-1), x >= r.l, NUM_ASSIGN(re, NUM_SUB(re, rstep)), \
fn, check, lbl, (pointPtr++, x--));

#define LOOP_LEFT(fn, check, lbl) \
	LOOP((x = r.l, y = r.b-1), y>r.t,  NUM_ASSIGN(im, NUM_SUB(im, istep)), \
fn, check, lbl, (pointPtr++, y--));

#define LOOP_TOP_CHECK(fn, lbl) \
LOOP_TOP(fn, if (pointPtr->c != firstColor) goto lbl; ,; );

#define LOOP_RIGHT_CHECK(fn, lbl) \
LOOP_RIGHT(fn, if (pointPtr->c != firstColor) goto lbl; ,; );

#define LOOP_BOTTOM_CHECK(fn, lbl) \
LOOP_BOTTOM(fn, if (pointPtr->c != firstColor) goto lbl; ,; );

#define LOOP_LEFT_CHECK(fn, lbl) \
LOOP_LEFT(fn, if (pointPtr->c != firstColor) goto lbl; ,; );

#define LOOP_TOP_NOCHECK(fn, lbl) \
LOOP_TOP(fn,; , lbl:);

#define LOOP_RIGHT_NOCHECK(fn, lbl) \
LOOP_RIGHT(fn,; , lbl:);

#define LOOP_BOTTOM_NOCHECK(fn, lbl) \
LOOP_BOTTOM(fn,; , lbl:);

#define LOOP_LEFT_NOCHECK(fn, lbl) \
LOOP_LEFT(fn,; , lbl:);

#define LOOP_FN(fn, lbl1, lbl2, lbl3, lbl4) \
if (r.b-r.t>1 && r.r-r.l>1) \
{ \
/* if there's a chance to subdivide, */ \
LOOP_TOP_CHECK(fn, lbl1); \
LOOP_RIGHT_CHECK(fn, lbl2); \
LOOP_BOTTOM_CHECK(fn, lbl3); \
LOOP_LEFT_CHECK(fn, lbl4); \
*isContinuous = 1; \
return 1;   /* if we made it to this point, it's continuous */ \
LOOP_TOP_NOCHECK(fn, lbl1); \
LOOP_RIGHT_NOCHECK(fn, lbl2); \
LOOP_BOTTOM_NOCHECK(fn, lbl3); \
LOOP_LEFT_NOCHECK(fn, lbl4); \
*isContinuous = 0; \
return 0;   /* it ain't continuous */ \
} \
else \
{ /* if there's no chance to subdivide, don't insert the checks */ \
LOOP_TOP(fn,; ,; ); \
LOOP_RIGHT(fn,; ,; ); \
if (r.r-r.l && r.b-r.t) \
{ \
/* only do the opposite sides if >1 row and >1 column */ \
LOOP_BOTTOM(fn,; ,; ); \
LOOP_LEFT(fn,; ,; ); \
} \
*isContinuous = 0; \
return 0;  /* it may or may not be continuous, doesn't matter */ \
}



int ComputeBorder(Winspecs *winspecs, Flags *flags, rect *rectPtr, MPE_Point *pointData, int maxnpoints,
				  int *npoints, int *isContinuous)
{
	register NUM re, im, rstep, istep;
	register int x, y;
	register MPE_Point *pointPtr;
	register MPE_Color firstColor;
	rect r;
	
	r = *rectPtr;
	/* xsplit, ysplit - where to split the rectangle */
	
    /* set the complex points */
	NUM_ASSIGN(re, COORD2CMPLX(flags->rmin, flags->rmax, 0,
		winspecs->width-1,  r.l));
	NUM_ASSIGN(im, COORD2CMPLX(flags->imax, flags->imin, 0,
		winspecs->height-1, r.t));
	NUM_ASSIGN(rstep,  NUM_DIV(NUM_SUB(flags->rmax, flags->rmin),
		INT2NUM(winspecs->width-1)));
	NUM_ASSIGN(istep,  NUM_DIV(NUM_SUB(flags->imin, flags->imax),
		INT2NUM(winspecs->height-1)));
	
	pointPtr = pointData + 1;
	pointData->x = r.l;
	pointData->y = r.t;
	pointData->c = firstColor = Iter2Color(flags,
		(flags->fractal == MBROT) ? MbrotCalcIter(re, im) :
	(flags->fractal == JULIA) ? JuliaCalcIter(re, im) :
	MbrotCalcIter(re, im));
	
	*npoints = r.length;
    /* calculate first point */
	
	
	switch (flags->fractal) 
	{
	case MBROT:
		LOOP_FN(MbrotCalcIter, m1, m2, m3, m4);
	case JULIA:
		LOOP_FN(JuliaCalcIter, j1, j2, j3, j4);
	case NEWTON:
		LOOP_FN(MbrotCalcIter, n1, n2, n3, n4);
	}
	return 0;
}

/*
void DrawBorder(MPE_XGraph graph, MPE_Color *colorData, rect r)
{
	int x, y;
	
	for (y = r.t, x = r.l; x <= r.r; x++) 
	{
		MPE_Draw_point(graph, x, y, *colorData);
		colorData++;
	}
	for (x = r.r, y = r.t + 1; y <= r.b; y++) 
	{
		MPE_Draw_point(graph, x, y, *colorData);
		colorData++;
	}
	if (r.r-r.l && r.b-r.t) 
	{
		for (y = r.b, x = r.r-1; x >= r.l; x--) 
		{
			MPE_Draw_point(graph, x, y, *colorData);
			colorData++;
		}
		for (x = r.l, y = r.b-1; y>r.t; y--) 
		{
			MPE_Draw_point(graph, x, y, *colorData);
			colorData++;
		}
	}
	MPE_Update(graph);
}
*/

void DrawBlock(MPE_XGraph graph, MPE_Point *pointData, rect *r)
{
	//printf("block color: %d\n", pointData->c);
	MPE_Fill_rectangle(graph, r->l, r->t, r->r - r->l + 1, r->b - r->t + 1,
		      pointData->c);
	
	MPE_Update(graph);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -