Ejemplo n.º 1
0
/*==================================================================================
 psline - subroutine to output a line (absolute).
 ==================================================================================*/
void psline_ (double *x1, double *y1, double *x2, double *y2, double *rline, double *width) {
	DEBUGPRINT(("In psline from (%f, %f) to (%f, %f), with rline=%f and width=%f.\n", *x1, *y1, *x2, *y2, *rline, *width));
	completeRelativeOperation();
	cairo_move_to(dmh_cr, deviceX(*x1), deviceY(*y1));
	cairo_line_to(dmh_cr, deviceX(*x2), deviceY(*y2));
	setLineProperties(*rline, *width);
	cairo_set_source_rgb (dmh_cr, 0, 0, 0);	/* black */
	cairo_stroke(dmh_cr);
}
Ejemplo n.º 2
0
/*==================================================================================
 pselip - generates an ellipse
	if dx or dy = 0, then they are set to minimum values in device space
 ==================================================================================*/
void pselip_ (double *xor, double *yor, double *dx, double *dy, double *rline, double *width, int *ifill) {
	double devX = deviceX(*xor);
	double devY = deviceY(*yor);
	double devW = deviceW(*dx);
	double devH = deviceH(*dy);
	
	DEBUGPRINT(("In pselip.  Origin: (%f, %f), Size: (%f, %f), DevOrigin: (%f, %f), DevSize: (%f, %f).\n", 
				*xor, *yor, *dx, *dy, devX, devY, devW, devH));
	completeRelativeOperation();
	cairo_new_path(dmh_cr);
	cairo_save (dmh_cr);
	
	if (devW == 0 || devH == 0) {
		devW = MINCIRCLESIZE;
		devH = MINCIRCLESIZE;
	}

	cairo_translate (dmh_cr, devX + devW/ 2., devY + devH / 2.);
	cairo_scale (dmh_cr, devW / 2., devH / 2.);
	cairo_arc (dmh_cr, 0., 0., 1., 0., 2 * M_PI);
	cairo_restore (dmh_cr);
	
	setLineProperties((int) *rline, *width);
	cairo_set_source_rgb (dmh_cr, 0, 0, 0);	/* black */
	cairo_stroke_preserve(dmh_cr);
	setFillType (*ifill);
	cairo_fill(dmh_cr);
}
Ejemplo n.º 3
0
/*==================================================================================
 psrecr - subroutine to output a rectangle, with real fill
 ==================================================================================*/
void psrecr_ (double *x1, double *x2, double *y1, double *y2, double *rline, double *width, double *rfill) {
	DEBUGPRINT(("In psrecr. minPt(1)=(%f, %f); maxPt(2)=(%f, %f), rline=%f, width=%f, fill=%f\n", *x1, *y1, *x2, *y2, *rline, *width, *rfill));
	DEBUGPRINT(("In psrecr. Device Coords: minPt=(%f, %f); Size=(%f, %f)\n", deviceX(*x1), 
				deviceY(*y2),
				deviceW(*x2 - *x1), 
				deviceH(*y2 - *y1)));
	completeRelativeOperation();
	cairo_rectangle(dmh_cr, deviceX(*x1), 
					deviceY(*y2),	/* this is y2, not y1, to deal with Cairo's flipped coordinate system */
					deviceW(*x2 - *x1),
					deviceH(*y2 - *y1));
	setLineProperties((int) *rline, *width);
	cairo_set_source_rgb (dmh_cr, 0, 0, 0);
	cairo_stroke_preserve(dmh_cr);
	cairo_set_source_rgb (dmh_cr, *rfill, *rfill, *rfill);
	cairo_fill(dmh_cr);
}
Ejemplo n.º 4
0
/*==================================================================================
 pspygn - subroutine to generate closed polygons, abs. coordinates
 ==================================================================================*/
void pspygn_ (double *x, double *y, int *npts, double *rline, double *width, int *ifill) {

	int i;
	
	DEBUGPRINT(("In pspygn.  Received %i points.  First=(%f, %f); Dev=(%f,%f). rline=%f, width=%f, fill=%i\n", *npts, x[0], y[0], deviceX(x[0]), deviceY(y[0]), *rline, *width, *ifill));
	completeRelativeOperation();
	cairo_move_to(dmh_cr, deviceX(x[0]), deviceY(y[0]));
	for (i = 1; i <= *npts-1; i++) {
		cairo_line_to(dmh_cr, deviceX(x[i]), deviceY(y[i]));
	}
	cairo_close_path(dmh_cr);
	
	setLineProperties((int) *rline, *width);
	cairo_set_source_rgb (dmh_cr, 0, 0, 0);	/* black */
	cairo_stroke_preserve(dmh_cr);
	setFillType (*ifill);
	cairo_fill(dmh_cr);
}
Ejemplo n.º 5
0
void BvhTetrahedronSystem::formTetrahedronAabbs()
{
	void * cvs = deviceX();
	void * vsrc = deviceV();
    void * idx = deviceTretradhedronIndices();
    void * dst = leafAabbs();
    tetrasys::formTetrahedronAabbs((Aabb *)dst, (float3 *)cvs, (float3 *)vsrc, 1.f/60.f, (uint4 *)idx, numTetrahedrons());
    CudaBase::CheckCudaError("tetrahedron system form aabb");
}
Ejemplo n.º 6
0
void BvhTriangleSystem::integrate(float dt)
{
    masssystem::integrateAllAnchored((float3 *)deviceX(),
                                     (float3 *)deviceV(),
                                     (float3 *)deviceVa(),
                                     dt,
                                     numPoints());
    CudaBase::CheckCudaError("triangle system integrate");
}
Ejemplo n.º 7
0
/*==================================================================================
 pspyln - subroutine to generate open polylines
 ==================================================================================*/
void pspyln_ (double *x, double *y, int *npts, double *rline, double *width, int *ifill) {
	int i;
	
	DEBUGPRINT(("In pspyln. Received %i points, with rline=%f, width=%f, fill=%i\n", *npts, *rline, *width, *ifill));
	completeRelativeOperation();

	if (dmh_inRotatedTransform) {
		cairo_set_matrix(dmh_cr, &dmh_unrotatedMatrix);	/* remove rotation */
		dmh_inRotatedTransform = 0;
		DEBUGPRINT(("Removing rotation.\n"));
	}

	cairo_move_to(dmh_cr, deviceX(x[0]), deviceY(y[0]));
	for (i = 1; i <= *npts-1; i++) {
		DEBUGPRINT(("In pspyln, lineto: (%f, %f).\n", deviceX(x[i]), deviceY(y[i])));
		cairo_line_to(dmh_cr, deviceX(x[i]), deviceY(y[i]));
	}
	
	setLineProperties((int) *rline, *width);
	cairo_set_source_rgb (dmh_cr, 0, 0, 0);	/* black */
	cairo_stroke_preserve(dmh_cr);
	setFillType (*ifill);
	cairo_fill(dmh_cr);
}
Ejemplo n.º 8
0
void BvhTetrahedronSystem::formTetrahedronAabbsImpulsed()
{
    void * pos = deviceX();
    void * vel = deviceV();
    void * deltaVel = deviceImpulse();
    void * idx = deviceTretradhedronIndices();
    void * dst = leafAabbs();
    tetrasys::formTetrahedronAabbsImpulsed((Aabb *)dst, 
                                   (float3 *)pos, 
                                   (float3 *)vel, 
                                   (float3 *)deltaVel,
                                   1.f/60.f, 
                                   (uint4 *)idx, 
                                   numTetrahedrons());
    CudaBase::CheckCudaError("tetrahedron system form aabb");
}
Ejemplo n.º 9
0
/*==================================================================================
 psmove - subroutine to move the current point
 ==================================================================================*/
void psmove_ (double *x1, double *y1) {
	DEBUGPRINT(("In psmove to (%f, %f)\n", deviceX(*x1), deviceY(*y1)));
	completeRelativeOperation();
	cairo_move_to(dmh_cr, deviceX(*x1), deviceY(*y1));
}
Ejemplo n.º 10
0
/*==================================================================================
 pspltrgn - subroutine to set which small plot region to use
 	This routine is called by pschem in psvdraw_new in order to plot multiple
 	ternary chemographies on a single page.  Each page can hold MAXPLOTSPERPAGE.  If
 	another is requested, then a new document will be created with a name similar to 
 	that of the first, and the process will begin again.
 	
 	This overrides any settings made in psssc2, and assumes that x and y (real-unit) 
 	bounds are 0.0-1.0.  Note that if this routine is called, then plot_aspect_ratio will be ignored.  
 	
 	Note that plotnum is a zero-based index
 ==================================================================================*/
void pspltrgn_ (int *plotnum) {
	char *outFileName = malloc((strlen(dmh_fileNameRoot)+50) * sizeof(char));
			
	int plotPosition = *plotnum % MAXPLOTSPERPAGE;
	int pageNum = *plotnum / MAXPLOTSPERPAGE;
	int boxEdge, rowNum, colNum;
	
	DEBUGPRINT(("In pspltrgn. Plotnum = %i, plotPosition = %i, pageNum = %i\n", *plotnum, plotPosition, pageNum));
	
	if (plotPosition == 0 && pageNum > 0) {
		/* we need to start a new page, so let's close the current one, and start a new one
			with a related name */
		DEBUGPRINT(("In pspltrgn. Closing current page and starting a new one with\n page number=%i and file type=%i\n", pageNum, dmh_outputFileType));
		closeSurface();	// close existing surface
		switch(dmh_outputFileType) {
			case PDFTYPE:
				sprintf(outFileName, "%s_%i.%s", dmh_fileNameRoot, pageNum, "pdf");
				dmh_surf = cairo_pdf_surface_create (outFileName, dmh_pageWidth, dmh_pageHeight);
				break;
			case PSTYPE:
				sprintf(outFileName, "%s_%i.%s", dmh_fileNameRoot, pageNum, "ps");
				dmh_surf = cairo_ps_surface_create (outFileName, dmh_pageWidth, dmh_pageHeight);
				cairo_ps_surface_set_eps (dmh_surf, 1);
				break;
			case SVGTYPE:
				sprintf(outFileName, "%s_%i.%s", dmh_fileNameRoot, pageNum, "svg");
				dmh_surf = cairo_svg_surface_create (outFileName, dmh_pageWidth, dmh_pageHeight);
				break;
		}
		
		dmh_cr = cairo_create (dmh_surf);
		cairo_identity_matrix(dmh_cr);
		cairo_set_line_join(dmh_cr, CAIRO_LINE_JOIN_ROUND);
		
		dmh_min_tracked_x = DBL_MAX;
	}
	
	/* Set the location on the page for the small plot */
	dmh_aspectRatio = 1.0;	/* Ignores plot_aspect_ratio.  */
	boxEdge = (dmh_pageWidth - LEFTMARGIN - RIGHTMARGIN - MULTIPLOTGUTTER) / 2;
	rowNum = plotPosition / 2;
	colNum = plotPosition % 2;
	dmh_xoffset = LEFTMARGIN + ((boxEdge + MULTIPLOTGUTTER) * colNum);
	dmh_yoffset = (dmh_pageHeight * 0.5) + (boxEdge * 1.5) + MULTIPLOTGUTTER - (boxEdge * (rowNum+1)) - (MULTIPLOTGUTTER * rowNum); 
	dmh_xscale = boxEdge;
	dmh_yscale = boxEdge;
	DEBUGPRINT(("End pspltrgn.  boxEdge=%i; r,c=(%i,%i); scale=(%f, %f); offset=(%f, %f); DevPtRange=(%f,%f)-(%f,%f).\n", boxEdge, rowNum, colNum, dmh_xscale, dmh_yscale, dmh_xoffset, dmh_yoffset,deviceX(0), deviceY(0), deviceX(1), deviceY(1)));
}
Ejemplo n.º 11
0
/*==================================================================================
 psbspl - subroutine to generate open bsplines
	We receive only the vertices from perplex, so we must figure out good control
	points to use for the spline.
 ==================================================================================*/
void psbspl_ (double *x, double *y, int *npts, double *rline, double *width, int *ifill) {
	int i, N;
	double ctrl1_x, ctrl1_y, ctrl2_x, ctrl2_y;
	
	N = *npts;
	
	DEBUGPRINT(("In psbspl. With %i points, rline=%f, wdith=%f, fill=%i.\n", N, *rline, *width, *ifill));
	completeRelativeOperation();

	if (dmh_inRotatedTransform) {
		cairo_set_matrix(dmh_cr, &dmh_unrotatedMatrix);	/* remove rotation */
		dmh_inRotatedTransform = 0;
		DEBUGPRINT(("Removing rotation.\n"));
	}

	if (N >= 4) {
		cairo_move_to(dmh_cr, deviceX(x[0]), deviceY(y[0]));
		getControlPoints(deviceX(x[0]), deviceY(y[0]), deviceX(x[0]), deviceY(y[0]), 
						 deviceX(x[1]), deviceY(y[1]), deviceX(x[2]), deviceY(y[2]), 
						 &ctrl1_x, &ctrl1_y, &ctrl2_x, &ctrl2_y);
		cairo_curve_to(dmh_cr, ctrl1_x, ctrl1_y, ctrl2_x, ctrl2_y, deviceX(x[1]), deviceY(y[1]));
//		cairo_line_to(dmh_cr, deviceX(x[1]), deviceY(y[1]));
		for (i=1; i <= N-3; i++) {
			getControlPoints(deviceX(x[i-1]), deviceY(y[i-1]), deviceX(x[i]), deviceY(y[i]), 
							 deviceX(x[i+1]), deviceY(y[i+1]), deviceX(x[i+2]), deviceY(y[i+2]), 
							 &ctrl1_x, &ctrl1_y, &ctrl2_x, &ctrl2_y);
			cairo_curve_to(dmh_cr, ctrl1_x, ctrl1_y, ctrl2_x, ctrl2_y, deviceX(x[i+1]), deviceY(y[i+1]));
		}
		
		/* We've now drawn all the way to N-2.  We need to draw through N-1.
			We can get one more control point by working backwards from the end: */
		getControlPoints(deviceX(x[N-3]), deviceY(y[N-3]), deviceX(x[N-2]), deviceY(y[N-2]), 
						 deviceX(x[N-1]), deviceY(y[N-1]), deviceX(x[N-1]), deviceY(y[N-1]), 
						 &ctrl1_x, &ctrl1_y, &ctrl2_x, &ctrl2_y);
		cairo_curve_to(dmh_cr, ctrl1_x, ctrl1_y, ctrl2_x, ctrl2_y, deviceX(x[N-1]), deviceY(y[N-1]));
//		cairo_line_to(dmh_cr, deviceX(x[N-1]), deviceY(y[N-1]));
	} else if (N == 3) {
		/* for three points, we'll pretend for the purposes of control point calculation that
		 it's a closed loop */
		cairo_move_to(dmh_cr, deviceX(x[0]), deviceY(y[0]));
		getControlPoints(deviceX(x[2]), deviceY(y[2]), deviceX(x[0]), deviceY(y[0]), 
						 deviceX(x[1]), deviceY(y[1]), deviceX(x[2]), deviceY(y[2]), 
						 &ctrl1_x, &ctrl1_y, &ctrl2_x, &ctrl2_y);
		cairo_curve_to(dmh_cr, ctrl1_x, ctrl1_y, ctrl2_x, ctrl2_y, deviceX(x[1]), deviceY(y[1]));
		getControlPoints(deviceX(x[0]), deviceY(y[0]), deviceX(x[1]), deviceY(y[1]), 
						 deviceX(x[2]), deviceY(y[2]), deviceX(x[0]), deviceY(y[0]), 
						 &ctrl1_x, &ctrl1_y, &ctrl2_x, &ctrl2_y);
		cairo_curve_to(dmh_cr, ctrl1_x, ctrl1_y, ctrl2_x, ctrl2_y, deviceX(x[2]), deviceY(y[2]));
	} else if (N == 2) {
		/* for two points, it's a line segment.  Duh. */
		cairo_move_to(dmh_cr, deviceX(x[0]), deviceY(y[0]));
		cairo_line_to(dmh_cr, deviceX(x[1]), deviceY(y[1]));
	}
	setLineProperties((int) *rline, *width);
	cairo_set_source_rgb (dmh_cr, 0, 0, 0);	/* black */
	cairo_stroke_preserve(dmh_cr);
	setFillType (*ifill);
	cairo_fill(dmh_cr);
}
Ejemplo n.º 12
0
/*==================================================================================
	pstext - subroutine to output text strings.

		x, y - coordinates of the label's reference point, in real coordinates (but see valign and halign, below)
		text - character string to be output
		jchar - length of meaningful character string, 0 if unknown.
		textlen - automatic argument supplied by fortran, gives allocated length of string
		valign: integer alignment code for vertical (from possibly rotated character standpoint) alignment.
			0 = top-aligned
			1 = middle-aligned
			2 = bottom-aligned
			10-12 = y should be considered a number of lines from top margin of page, then alignment=valign-10
			100-902 = valign is given by the final digit.  The y-coordinate should be calculated
				based upon the given y, but then add a number of lines to move down the page from there
				given by this code/100 (e.g., 1-9 lines)
			1000-9002 = valign is given by the final digit.  The y-coordinate should be calculated
			based upon the given y, but then add a number of lines to move up the page from there
			given by this code/1000 (e.g., 1-9 lines)
			(e.g., 202 would mean that the text should be bottom-aligned to the reference point, and 
				the y coordinate is two lines below the supplied y coordinate
		halign: integer alignment code for horizontal (from possibly rotated character standpoint) alignment.
			0 = left-aligned
			1 = center-aligned
			2 = right-aligned
			10-12 = x should be considered a number of lines from left margin of page, then alignment=halign-10
			100-9002 = halign is given by the final digit.  The x coordinate should be calculated based upon
			    the given x, but add a number of points given by this code / 100 (e.g., 1-90).
			REFERENCE_TO_TRACKED_MIN_X - REFERENCE_TO_TRACKED_MIN_X+2 = halign is given by the final digit. The
				x coordinate to be used is the tracked minimum x.
 
==================================================================================*/
void pstext_ (double *x, double *y, char *text, int *jchar, int *valign, int *halign, int textlen) {
	cairo_text_extents_t te;
	cairo_font_extents_t fe;
	cairo_matrix_t curMatrix;
	
	double userX, userY;
	double tempX, tempY;
	int valignCode, halignCode;
	int linesToMove = 0;
	double pointsToMove = 0;
	double xOffset = 0;
	double yOffset = 0;
	char *temptext=malloc(255 * sizeof(char));
	char *mytext;
	
	strncpy(temptext, text, 254);	/* copy only as many characters as will fit in value */

	if (*jchar == 0) {
		temptext[textlen]='\0';
	} else {
		temptext[*jchar]='\0';
	}
	
	mytext = trim(temptext);
	compressSpaces(mytext);
	completeRelativeOperation();

	DEBUGPRINT(("In pstext.  Pt=(%f, %f), DevPoint=(%f, %f), Text=%s, jchar=%i, textlen=%i, valign=%i, halign=%i.\n", *x, *y, deviceX(*x), deviceY(*y), mytext, *jchar, textlen, *valign, *halign));
	cairo_text_extents(dmh_cr,mytext,&te);
	cairo_font_extents (dmh_cr, &fe);
	cairo_set_source_rgb (dmh_cr, 0, 0, 0);	/* black */

	userX = deviceX(*x);	/* change coordinates from real to device */
	userY = deviceY(*y);

	if (dmh_debug) {
		tempX = userX;
		tempY = userY;
		cairo_device_to_user(dmh_cr, &tempX, &tempY);	/* need this to deal with possibly rotated transform */
		cairo_rectangle(dmh_cr, tempX-4, tempY-4, 8, 8);
		cairo_set_source_rgb (dmh_cr, 1, 0.5, 0);
		cairo_fill(dmh_cr);
		cairo_set_source_rgb (dmh_cr, 0, 0, 0);
		cairo_move_to(dmh_cr, tempX, tempY);
	}
	
	DEBUGPRINT(("In pstext.  UserPt=(%f, %f) tempPt=(%f, %f).\n", userX, userY, tempX, tempY));
	if (*valign > 9 && *valign < 100) {
		/* y should be considered a number of lines from top of page.  Note that cairo thinks the origin is at top-left */
		userY = TOPMARGIN + ((int)*y * fe.height);
	} else if (*valign > 99 && *valign < 1000) {
		linesToMove = *valign / 100;
	} else if (*valign > 990 && *valign < 10000) {
		linesToMove = -(*valign / 1000);
	}
	DEBUGPRINT(("In pstext.  LinesToMove=%i.\n", linesToMove));
	if (*halign > 9 && *halign < 100) {
		/* x should be considered a number of lines from top of page.  Note that cairo thinks the origin is at top-left */
		userX = LEFTMARGIN + ((int)*x * fe.height);
	} else if (*halign > 99 && *halign < 10000) {
		pointsToMove = (*halign)/100;
	} else if (*halign >= REFERENCE_TO_TRACKED_MIN_X && *halign <= REFERENCE_TO_TRACKED_MIN_X+2) {
		userX = dmh_min_tracked_x;
		dmh_min_tracked_x = DBL_MAX;	/* Now turn off tracking */
		dmh_track_min_x = 0;
	}

	DEBUGPRINT(("In pstext.  UserPt=(%f, %f).\n", userX, userY));
	cairo_device_to_user(dmh_cr, &userX, &userY);	/* need this to deal with possibly rotated transform */
	cairo_move_to(dmh_cr, userX, userY);
	if (linesToMove != 0) {
		cairo_rel_move_to(dmh_cr, 0, linesToMove * fe.height);
	}
	
	if (pointsToMove != 0) {
		cairo_rel_move_to(dmh_cr, pointsToMove, 0);
	}
	
	if (dmh_debug) {
		cairo_get_current_point(dmh_cr, &tempX, &tempY);
		cairo_rectangle(dmh_cr, tempX-2, tempY-2, 4, 4);
		cairo_set_source_rgb (dmh_cr, 0, 0.5, 1);
		cairo_fill(dmh_cr);
		cairo_set_source_rgb (dmh_cr, 0, 0, 0);
		cairo_move_to(dmh_cr, tempX, tempY);
	}

	valignCode = *valign % 10;
	halignCode = *halign % 10;
	switch (valignCode) {
		case 0:	/* Top-aligned */
			yOffset = te.height + EXTRASPACEPTS;
			break;
		case 1:	/* Middle-aligned */
			yOffset = te.height * 0.5;
			break;
		case 2:	/* Bottom-aligned */
			yOffset = -EXTRASPACEPTS;
			break;
	}

	switch (halignCode) {
		case 0:	/* Left-aligned */
			xOffset = EXTRASPACEPTS;
			break;
		case 1:	/* Center-aligned */
			xOffset = -te.width * 0.5;
			break;
		case 2:	/* Right-aligned */
			xOffset = -te.width - EXTRASPACEPTS;
			break;
	}
	DEBUGPRINT(("In pstext.  Offset=(%f, %f).\n", xOffset, yOffset));
	cairo_rel_move_to(dmh_cr, xOffset, yOffset);

	if (dmh_debug) {
		cairo_get_current_point(dmh_cr, &tempX, &tempY);
		cairo_rectangle(dmh_cr, tempX-2, tempY-2, 4, 4);
		cairo_set_source_rgb (dmh_cr, 1, 0, 0.5);
		cairo_fill(dmh_cr);
		cairo_set_source_rgb (dmh_cr, 0, 0, 0);
		cairo_move_to(dmh_cr, tempX, tempY);
	}

	cairo_get_matrix(dmh_cr, &curMatrix);
	DEBUGPRINT(("Current matrix: %f, %f, %f, %f, %f, %f.\n", curMatrix.xx, curMatrix.yx, curMatrix.xy, curMatrix.yy, curMatrix.x0, curMatrix.y0));

	if (dmh_track_min_x) {
		cairo_get_current_point(dmh_cr, &tempX, &tempY);
		if (tempX < dmh_min_tracked_x) {
			dmh_min_tracked_x = tempX;
		}
	}
	cairo_show_text (dmh_cr, mytext);

	DEBUGPRINT(("Status:%s\n",cairo_status_to_string(cairo_status(dmh_cr))));

	free(temptext);
}