コード例 #1
0
ファイル: RGPDrawGridCont.C プロジェクト: amiara/RGIS
DBInt RGPDrawGridContinuous (DBInt mode, DBInt *entryNum, DBObjData *grdData)

	{
	DBInt r, g, b;
	DBInt ret, shadeNum, colorNum, scaleMode = 0;
	DBPosition pos;
	char charBuffer [RGPBufferSIZE], errorMsg [RGPBufferSIZE];
	const char *colorMaps [] = { "default", "grey", "blue", "red", "blue-red", "elevation", "custom", NULL };
	char colorMap;
	const char *scaleModes [] = { "linear", "logarithmic", "square-root", NULL };
	RGPColorMapEntry *customColors;
	DBFloat value;
	float *array, translation [6], min, max, unit = 1.0;
	DBRegion extent = grdData->Extent ();
	DBObjRecord *layerRec;
	DBGridIF *gridIF = new DBGridIF (grdData);

	do {
		RGPPrintMessage (mode,entryNum,"Grid Layer:");
		if (fgets (charBuffer,sizeof (charBuffer) - 2,stdin) == (char *) NULL) { ret = DBFault; goto Stop; }
		if ((strlen (charBuffer) > 0) && (charBuffer [strlen (charBuffer) - 1] == '\n'))
			charBuffer [strlen (charBuffer) - 1] = '\0';
		if ((layerRec = gridIF->Layer (charBuffer)) != NULL) break;
		sprintf (errorMsg,"Invalid grid layer [%s]",charBuffer);
		if (RGPPrintError (mode,*entryNum,errorMsg)) { ret = DBFault; goto Stop;}
 		} while (true);

	do	{
		RGPPrintMessage (mode,entryNum,"Colormap [default|grey|blue|red-blue|elevation|custom]:");
		if (fgets (charBuffer,sizeof (charBuffer) - 2,stdin) == (char *) NULL) { ret = DBFault; goto Stop; }
		if ((strlen (charBuffer) > 0) && (charBuffer [strlen (charBuffer) - 1] == '\n'))
			charBuffer [strlen (charBuffer) - 1] = '\0';
		if ((colorMap = CMoptLookup (colorMaps,charBuffer,true)) != DBFault) break;
		sprintf (errorMsg,"Invalid colormap [%s]",charBuffer);
		if (RGPPrintError (mode,*entryNum,errorMsg)) { ret = DBFault; goto Stop; }
		} while (true);
	switch (colorMap)
		{
		default:
		case 0:
			switch (grdData->Flags () & DBDataFlagDispModeFlags)
				{
				case DBDataFlagDispModeContStandard:
				case DBDataFlagDispModeContGreyScale:
					shadeNum = RGPSetColorMap (_RGPGreyColors,		RGPColorNum (_RGPGreyColors));		break;
				case DBDataFlagDispModeContBlueScale:
					shadeNum = RGPSetColorMap	(_RGPBlueColors,		RGPColorNum (_RGPBlueColors));		break;
				case DBDataFlagDispModeContBlueRed:
					shadeNum = RGPSetColorMap (_RGPBlueRedColors,	RGPColorNum (_RGPBlueRedColors));	break;
				case DBDataFlagDispModeContElevation:
					shadeNum = RGPSetColorMap (_RGPElevationColors,	RGPColorNum (_RGPElevationColors));	break;
				}
			break;
		case 1:	shadeNum = RGPSetColorMap (_RGPGreyColors,		RGPColorNum (_RGPGreyColors));		break;
		case 2:	shadeNum = RGPSetColorMap (_RGPBlueColors,		RGPColorNum (_RGPBlueColors));		break;
		case 3:	shadeNum = RGPSetColorMap (_RGPRedColors,			RGPColorNum (_RGPRedColors));			break;
		case 4:	shadeNum = RGPSetColorMap (_RGPBlueRedColors,	RGPColorNum (_RGPBlueRedColors));	break;
		case 5:	shadeNum = RGPSetColorMap (_RGPElevationColors,	RGPColorNum (_RGPElevationColors));	break;
		case 6:
			colorNum = 0;
			if ((customColors = (RGPColorMapEntry *) calloc (1,sizeof (RGPColorMapEntry))) == (RGPColorMapEntry *) NULL)
				{ CMmsgPrint (CMmsgSysError, "Memory Allocation Error in: %s %d",__FILE__,__LINE__); delete gridIF; return (DBFault); }
			do	{
				RGPPrintMessage (mode,entryNum,"Background Shade [red,green,blue]:");
				if (fgets (charBuffer,sizeof (charBuffer) - 2,stdin) == (char *) NULL) { ret = DBFault; goto Stop; }
				if (sscanf (charBuffer,"%d,%d,%d",&r,&g,&b) == 3)
					{
					customColors [colorNum].Red = r;
					customColors [colorNum].Green = g;
					customColors [colorNum].Blue = b;
					colorNum++;
					break;
					}
				else	if (RGPPrintError (mode,*entryNum,"Background Color Entry Error")) { ret = DBFault; goto Stop; }
				} while (true);
			do	{
				RGPPrintMessage (mode,entryNum,"Color Shade [red,green,blue]:");
				if (fgets (charBuffer,sizeof (charBuffer) - 2,stdin) == (char *) NULL) { ret = DBFault; goto Stop; }
				if (sscanf (charBuffer,"%d,%d,%d",&r,&g,&b) == 3)
					{
					if ((customColors = (RGPColorMapEntry *) realloc (customColors,(colorNum + 1) * sizeof (RGPColorMapEntry))) == (RGPColorMapEntry *) NULL)
						{ CMmsgPrint (CMmsgSysError, "Memory Allocation Error in: %s %d",__FILE__,__LINE__); delete gridIF; return (DBFault); }
					customColors [colorNum].Red = r;
					customColors [colorNum].Green = g;
					customColors [colorNum].Blue = b;
					colorNum++;
					}
				else
					{
					if (colorNum < 3)
						{ if (RGPPrintError (mode,*entryNum,"Color Shade Entry Error")) { ret = DBFault; goto Stop; }}
					else	break;
					}
				} while (true);
			shadeNum = RGPSetColorMap (customColors,colorNum);
			free (customColors);
			break;
		}
	if (shadeNum == DBFault)	{ RGPPrintError (mode,*entryNum,"Colormap Initialization Error") ; ret = DBFault; goto Stop; }
	do	{
		RGPPrintMessage (mode,entryNum,"Scale mode [linear|logarithmic]:");
		if (fgets (charBuffer,sizeof (charBuffer) - 2,stdin) == (char *) NULL) { ret = DBFault; goto Stop; }
		if ((strlen (charBuffer) > 0) && (charBuffer [strlen (charBuffer) - 1] == '\n'))
			charBuffer [strlen (charBuffer) - 1] = '\0';
		if ((scaleMode = CMoptLookup (scaleModes,charBuffer,true)) != DBFault) break;
		sprintf (errorMsg,"Invalid scale mode [%s]",charBuffer);
		if (RGPPrintError (mode,*entryNum,errorMsg)) { ret = DBFault; goto Stop; }
		} while (true);
	do	{
		RGPPrintMessage (mode,entryNum,"Value range [minimum,maximum]:");
		if (fgets (charBuffer,sizeof (charBuffer) - 2,stdin) == (char *) NULL) { ret = DBFault; goto Stop; }
		if (sscanf (charBuffer,"%f,%f",&min,&max) == 2)	break;
		else	if (RGPPrintError (mode,*entryNum,"Value range input error")) { ret = DBFault; goto Stop; }
		} while (true);
	if ((array = (float *) calloc (gridIF->RowNum () * gridIF->ColNum (),sizeof (float))) == (float *) NULL)
		{ CMmsgPrint (CMmsgSysError, "Memory allocation error in: %s %d",__FILE__,__LINE__); ret = DBFault; goto Stop; }
	for (pos.Row = 0;pos.Row < gridIF->RowNum ();++pos.Row)
		for (pos.Col = 0;pos.Col < gridIF->ColNum ();++pos.Col)
			if (gridIF->Value (layerRec,pos,&value))
					{
					value = value > min ? value : min;
					value = value < max ? value : max;
					switch (scaleMode)
						{
						default:
						case 0:	array [pos.Row * gridIF->ColNum () + pos.Col] = value; break;
						case 1:	array [pos.Row * gridIF->ColNum () + pos.Col] = log10 (value); break;
						case 2:	array [pos.Row * gridIF->ColNum () + pos.Col] = sqrt (value); break;
						}
					}
			else 	array [pos.Row * gridIF->ColNum () + pos.Col] = min - (max - min) / (float) shadeNum;

	translation [0] = extent.LowerLeft.X - gridIF->CellWidth () / 2.0;
	translation [1] = gridIF->CellWidth ();
	translation [2] = 0.0;
	translation [3] = extent.LowerLeft.Y - gridIF->CellHeight () / 2.0;
	translation [4] = 0.0;
	translation [5] = gridIF->CellHeight ();
	RGPPrintMessage (mode,entryNum,"Unit:");
	if ((fgets (charBuffer,sizeof (charBuffer) - 2,stdin) == (char *) NULL) || (sscanf (charBuffer,"%f",&unit) != 1))
		{ RGPPrintError (mode,*entryNum,"Unit input error"), ret = DBFault; goto Stop; }

	RGPPrintMessage (mode,entryNum,"Unit label:");
	if (fgets (charBuffer,sizeof (charBuffer) - 2,stdin) == (char *) NULL)
		{ RGPPrintError (mode,*entryNum,"Unit label input error"); ret = DBFault; goto Stop; }
	if ((strlen (charBuffer) > 0) && (charBuffer [strlen (charBuffer) - 1] == '\n'))
			charBuffer [strlen (charBuffer) - 1] = '\0';

/*	cpgsitf (scaleMode); */
	switch (scaleMode)
		{
		default:
		case 0:
			min = min - (max - min) / (float) shadeNum;
			max = max + (max - min) / (float) shadeNum;
			cpgwedg ("BI",0.0,5.0,min * unit,max * unit,charBuffer);
			cpgimag (array,pos.Col,pos.Row,1,pos.Col,1,pos.Row,min,max,translation);
			break;
		case 1:
			cpgwedg ("BI",0.0,5.0,log10 (min * unit),log10 (max * unit),charBuffer);
			cpgimag (array,pos.Col,pos.Row,1,pos.Col,1,pos.Row,log10 (min),log10 (max),translation);
			break;
		case 2:
			cpgwedg ("BI",0.0,5.0,sqrt (min * unit),sqrt (max * unit),charBuffer);
			cpgimag (array,pos.Col,pos.Row,1,pos.Col,1,pos.Row,sqrt (min),sqrt (max),translation);
			break;
		}

Stop:
	delete gridIF;
	return (ret);
	}
コード例 #2
0
ファイル: RGPMain.C プロジェクト: rjs80/RGIS
int main (int argc,char **argv)

	{
	int argPos, argNum = argc;
	char charBuffer [RGPBufferSIZE], panelTitle [RGPBufferSIZE], *outFile = (char *) "rgisplot";
	int panelRow, panelCol, panelRowNum,panelColNum, defaultLW;
	DBInt dataNum, entryNum = 0;
	DBInt ret, mode = 0, device = 0, format = 0, layout = 0;
	float x0, y0, x1, y1, pWidth = -1.0, pHeight = -1.0;
	DBObjData *dbData;

	for (argPos = 1;argPos < argNum; )
		{
		if (CMargTest (argv [argPos],"-m","--mode"))
			{
			const char *modes [] = { "interactive", "batch", (char *) NULL };

			if ((argNum = CMargShiftLeft (argPos,argv,argNum)) <= argPos)
				{ CMmsgPrint (CMmsgUsrError,"Missing mode!");    return (CMfailed); }
			if ((mode = CMoptLookup (modes,argv [argPos],true)) == DBFault)
				{ CMmsgPrint (CMmsgUsrError,"Invalid mode %s",argv [argPos]); goto Usage; }
			if ((argNum = CMargShiftLeft (argPos,argv,argNum)) <= argPos) break;
			continue;
			}
		if (CMargTest (argv [argPos],"-d","--device"))
			{
			const char *devices [] = { "screen", "file", (char *) NULL };

			if ((argNum = CMargShiftLeft (argPos,argv,argNum)) <= argPos)
				{ CMmsgPrint (CMmsgUsrError,"Missing device!");  return (CMfailed); }
			if ((device = CMoptLookup (devices,argv [argPos],true)) == DBFault)
				{ CMmsgPrint (CMmsgUsrError,"Invalid device %s",argv [argPos]); goto Usage; }
			if ((argNum = CMargShiftLeft (argPos,argv,argNum)) <= argPos) break;
			continue;
			}
		if (CMargTest (argv [argPos],"-p","--psize"))
			{
			if ((argNum = CMargShiftLeft (argPos,argv,argNum)) <= argPos)
				{ CMmsgPrint (CMmsgUsrError,"Missing psize!");   return (CMfailed); }
			if ((argv [argPos] == (char *) NULL) || (sscanf (argv [argPos],"%f,%f",&pWidth,&pHeight) != 2))
				{ CMmsgPrint (CMmsgUsrError,"Invalid page size %s",argv [argPos]); goto Usage; }
			if ((argNum = CMargShiftLeft (argPos,argv,argNum)) <= argPos) break;
			continue;
			}
		if (CMargTest (argv [argPos],"-f","--format"))
			{
			const char *formats [] = { "eps", "gif", "ppm", (char *) NULL };

			if ((argNum = CMargShiftLeft (argPos,argv,argNum)) <= argPos)
				{ CMmsgPrint (CMmsgUsrError,"Missing format!");  return (CMfailed); }
			if ((format = CMoptLookup (formats,argv [argPos],true)) == DBFault)
				{ CMmsgPrint (CMmsgUsrError,"Invalid format %s",argv [argPos]); goto Usage; }
			if ((argNum = CMargShiftLeft (argPos,argv,argNum)) <= argPos) break;
			continue;
			}
		if (CMargTest (argv [argPos],"-l","--layout"))
			{
			const char *layouts [] = { "portrait","landscape", (char *) NULL };

			if ((argNum = CMargShiftLeft (argPos,argv,argNum)) <= argPos)
				{ CMmsgPrint (CMmsgUsrError,"Missing layout!");  return (CMfailed); }
			if ((layout = CMoptLookup (layouts,argv [argPos],true)) == DBFault)
				{ CMmsgPrint (CMmsgUsrError,"Invalid layout %s",argv [argPos]); goto Usage; }
			if ((argNum = CMargShiftLeft (argPos,argv,argNum)) <= argPos) break;
			continue;
			}
		if (CMargTest (argv [argPos],"-o","--output"))
			{
			if ((argNum = CMargShiftLeft (argPos,argv,argNum)) <= argPos)
				{ CMmsgPrint (CMmsgUsrError,"Missing output!");  return (CMfailed); }
			if (argv [argPos] == (char *) NULL)
				{ CMmsgPrint (CMmsgUsrError,"Invalid output file"); goto Usage; }
			outFile = argv [argPos];
			if ((argNum = CMargShiftLeft (argPos,argv,argNum)) <= argPos) break;
			continue;
			}
		if (CMargTest (argv [argPos],"-h","--help"))
			{
			Usage:
			CMmsgPrint (CMmsgUsrError,"Usage: rgisPlot [-m <>] [-d <>] [-f <>] [-l <>] [-o <>] -h");
			CMmsgPrint (CMmsgUsrError,"                 -m, --mode <interactive | batch>");
			CMmsgPrint (CMmsgUsrError,"                 -d, --device <screen | file>");
			CMmsgPrint (CMmsgUsrError,"                 -p, --psize width,height");
			CMmsgPrint (CMmsgUsrError,"                 -f, --format <eps | gif>");
			CMmsgPrint (CMmsgUsrError,"                 -l, --layout <landscape | portrait>");
			CMmsgPrint (CMmsgUsrError,"                 -o, --output <filename>");
			argNum = CMargShiftLeft (argPos,argv,argNum);
			return (DBSuccess);
			}
		if ((argv [argPos][0] == '-') && (strlen (argv [argPos]) > 1))
			{ CMmsgPrint (CMmsgUsrError,"Unknown option: %s!",argv [argPos]); return (CMfailed); }
		argPos++;

		}

	switch (device)
		{
		case 0: cpgopen ("/XWINDOW");	break;
		case 1:
			{
			char *formatStrings [] = { (char *) "CPS", (char *) "GIF", (char *) "PPM" };
			sprintf (charBuffer,layout == 0 ? "%s/V%s" : "%s/%s", outFile, formatStrings [format]);
			cpgopen (charBuffer);
			} break;
		default: return (CMfailed);
		}
	cpgscrn (0,"WHITE",&ret);
	if ((pWidth > 0.0) && (pHeight > 0.0)) cpgpap (pWidth, pHeight / pWidth);

	do	{
		RGPPrintMessage (mode,&entryNum,"Panel Layout [horizontal,vertical]:");
		while (fgets (charBuffer,sizeof (charBuffer) - 1,stdin) == (char *) NULL);
		if (sscanf (charBuffer,"%d,%d",&panelColNum,&panelRowNum) == 2) break;
		else
			if (RGPPrintError (mode,entryNum,"Panel layout input error")) goto Stop;
		} while (true);

	RGPInitPenColors ();
	cpgsubp (panelColNum,panelRowNum);
	cpgqlw (&defaultLW);

	ret = DBSuccess;
	for (panelRow = 0;panelRow < panelRowNum;++panelRow)
		for (panelCol = 0;panelCol < panelColNum; ++panelCol)

			{
			cpgpanl (panelCol + 1,panelRow + 1);
			cpgsch (1.8);
			cpgvstd ();
			do	{
				sprintf (charBuffer,"Panel Title [%d,%d]:",panelRow,panelCol);
				RGPPrintMessage (mode,&entryNum,charBuffer);
				if (fgets (panelTitle,sizeof (panelTitle) - 1,stdin) != (char *) NULL)
					{
					if (panelTitle [strlen (panelTitle) - 1] == '\n')
						panelTitle [strlen (panelTitle) - 1] = '\0';
					if (strlen (panelTitle) > 0) break;
					}
				RGPPrintError (mode,entryNum,"Panel Title input error"); goto Stop;
				} while (true);

			dataNum = 0;
			do {
				RGPPrintMessage (mode,&entryNum,"Mapextent [X0,Y0,X1,Y1]:");
				if (fgets (charBuffer,sizeof (charBuffer) - 1,stdin) == (char *) NULL) continue;
				if (sscanf (charBuffer,"%f,%f,%f,%f",&x0,&y0,&x1,&y1) == 4)	break;
				else	if (RGPPrintError (mode,entryNum,"Mapextent input error")) goto Stop;
				} while (true);
			cpgwnad (x0,x1,y0,y1);

			do	{
				sprintf (charBuffer,"RiverGIS data file [%d]:",++dataNum);
				RGPPrintMessage (mode,&entryNum, charBuffer);
				if ((fgets (charBuffer,sizeof (charBuffer) - 1,stdin) != (char *) NULL) &&
					 (strlen (charBuffer) > 0) && charBuffer [0] != '\n')
					{
					if (charBuffer [strlen (charBuffer) - 1] == '\n') charBuffer [strlen (charBuffer) - 1] = '\0';
					dbData = new DBObjData ();
					if (dbData->Read (charBuffer) != DBSuccess) { dataNum--; continue; }
					switch (dbData->Type ())
						{
						case DBTypeVectorPoint:
							if ((ret = RGPDrawVecPoint (mode, &entryNum, dbData)) == DBFault) goto Stop;
							break;
						case DBTypeVectorLine:
							if ((ret = RGPDrawVecLine (mode, &entryNum, dbData)) == DBFault) goto Stop;
							break;
						case DBTypeVectorPolygon:
							break;
						case DBTypeGridContinuous:
								if ((ret = RGPDrawGridContinuous (mode,&entryNum,dbData)) == DBFault)	goto Stop;
							break;
						case DBTypeGridDiscrete:
							break;
						case DBTypeNetwork:
							if ((ret = RGPDrawNetwork (mode, &entryNum, dbData)) == DBFault) goto Stop;
							break;
						default: CMmsgPrint (CMmsgUsrError,"Invalid data type"); dataNum--; break;
						}
					delete dbData;
					}
				else	break;
				} while (true);
			cpgbox ("BCMTS",0.0,0,"BCNMTS",0.0,0);
			cpgslw (2);
			cpgsch (2.5);
			cpgmtxt ("T",1.5,0.5,0.5,panelTitle);
			cpgslw (defaultLW);
			}
Stop:
	cpgend ();
	return (ret);
	}