コード例 #1
0
ファイル: HtmCover.cs プロジェクト: davelondon/dontstayin
		/// <summary>
		/// 		// EXP May 24, 2005 GYF
		/// Use the legacy text interface to build a region. This version uses
		/// a two-pass method to tighten the fit a bit.
		/// </summary>
		/// <param name="textSpec">Legacy style descritption of region</param>
		/// <param name="directory">Trace information is deposited here.
		///                    Use <em>null</em> if no trace is required</param>
		/// <returns>A table of HtmIDs or null</returns>
		public static Int64[,] RegionTighter(String textSpec, string directory) {
			Int64[,] returnResult;
			Region reg = new Region(directory);
			Parser par;
			ArrayList lohis = new ArrayList();
			par = new Parser();
			par.input = textSpec;
			par.buildto(reg);
			if (par.parse() == false) {
				return null;
			}
			reg.smartintersect(false,
				HtmState.Instance.minlevel,
				HtmState.Instance.maxlevel, lohis);

			// EXP EXP EXP EXP //  
			// I moved the below stuff to be done inside each convex...
			// and then merge..
			// reg.smartintersect() is like reg.intersect, but
			// does this stuff below for each convex
			//
			//if (lohis.Count > 1) { //repeat with the heuristic rule
			//    int fudle;
			//    int hlevel;
			//    int magic = HtmState.Instance.magicnumber;
			//    // make magic 31 for tight fit
			//    // make magic 30 for relaxed fit (unlike jeans)
			//    // 
			//    Int64 blorp = HtmState.Instance.tcount;
			//    for (fudle = 0; blorp > 0; fudle++) {
			//        blorp >>= 2;
			//    }
			//    hlevel = (magic - fudle) / 2;
			//    HtmState.Instance.minlevel = hlevel; // Do you reset this anytime?
			//    HtmState.Instance.maxlevel = hlevel + 4; // reasonable cutoff? <EXP> 
			//    lohis.Clear();
			//    reg.intersect(false,
			//        HtmState.Instance.minlevel,
			//        HtmState.Instance.maxlevel, lohis);
			//}
			//
			int rows = lohis.Count / 2;
			int cols = 2;
			int k = 0;
			returnResult = new Int64[rows, cols];
			for (int i = 0; i < rows; i++) {
				returnResult[i, 0] = (Int64)lohis[k++];
				returnResult[i, 1] = (Int64)lohis[k++];
			}
			return returnResult;
		}
コード例 #2
0
ファイル: HtmCover.cs プロジェクト: davelondon/dontstayin
		/// <summary>
		/// Get the error message that describes why xphtm.Region may have returned
		/// a null table
		/// </summary>
		/// <param name="textSpec">Legacy style descritption of region</param>
		/// <returns>String containing error message</returns>
		public static String Error(String textSpec) {
			Region reg = new Region(null); // no Trace output!
			Parser par;
			ArrayList lohis = new ArrayList();
			par = new Parser();
			par.input = textSpec;

			par.buildto(reg); //We give the location of the target object. There parser will assemble the region here
			if (par.parse() == false) { // Start the parser. if it returns true, all is well, else error
				return par.errmsg();
			}
			//reg.intersect(false,
			//    HtmState.Instance.minlevel,
			//    HtmState.Instance.maxlevel, lohis); // lohis remains unchanged when called from polygon
			return "ok";
		}
コード例 #3
0
ファイル: HtmCover.cs プロジェクト: davelondon/dontstayin
		/// <summary>
		/// Use the legacy text interface to build a region.
		/// </summary>
		/// <param name="textSpec">Legacy style descritption of region</param>
		/// <param name="directory">Trace information is deposited here.
		///                    Use <i>null</i> if no trace is require</param>
		/// <returns>A table of HtmIDs or null</returns>
		public static Int64[,] Region(String textSpec, string directory){
			Int64[,] returnResult;
			Region reg = new Region(directory);
			Parser par;
			Parser.Geometry g;
			ArrayList lohis = new ArrayList();
			
			par = new Parser();
			par.input = textSpec;
			g = par.peekGeometry(); // Peeking into the spec decides what kind of object we build
			switch(g){
				case Parser.Geometry.Region:
				case Parser.Geometry.Convex:
				case Parser.Geometry.Rect:
				case Parser.Geometry.Circle:
				case Parser.Geometry.Poly:
					par.buildto(reg); //We give the location of the target object. There parser will assemble the region here
					if (par.parse() == false){ // Start the parser. if it returns true, all is well, else error
						return null;
					}
					reg.intersect(false,
						HtmState.Instance.minlevel,
						HtmState.Instance.maxlevel, lohis); // lohis remains unchanged when called from polygon
					break;
				case Parser.Geometry.Chull:
					par.buildto(reg);
					if (par.parse() == false){
						return null;
					}
					reg.intersect(false,
						HtmState.Instance.minlevel,
						HtmState.Instance.maxlevel, lohis);
					break;
				case Parser.Geometry.Null:
					return null;
			}
			int rows = lohis.Count/2;
			int cols = 2;
			int k = 0;
			returnResult = new Int64[rows,cols];
			for(int i=0; i<rows; i++){
				returnResult[i,0] = (Int64) lohis[k++];
				returnResult[i,1] = (Int64) lohis[k++];
			}
			return returnResult;
		}
コード例 #4
0
ファイル: HtmCover.cs プロジェクト: davelondon/dontstayin
		public static string NormalForm(String textSpec, out String errmsg) {
			Region reg = new Region();
			Parser par = new Parser();
			par.input = textSpec;
			par.buildto(reg);
			if (par.parse() == false) {
				errmsg = par.errmsg();
				return null;
			} else {
				errmsg = "ok";
			}
			reg.normalize();
			return reg.ToString();
		}
コード例 #5
0
ファイル: HtmCover.cs プロジェクト: davelondon/dontstayin
		/// <summary>
		/// Normalize the region specification.
		/// The text interface allow a region to be specified in terms of
		/// rectangles, circles, polygons, convex hulls of points, etc.
		/// A so called <i>normal form</i> is a string that contains only
		/// a union of convexes.
		/// </summary>
		/// <param name="textSpec">Legacy style descritption of region</param>
		/// <returns>A specification consisting of a union of Convexes</returns>
		public static string NormalForm ( String textSpec ) {
			Region reg = new Region();
			Parser par = new Parser();
			par.input = textSpec;
			par.buildto(reg);
			if (par.parse() == false) {
				return null;
			}
			reg.normalize();
			return reg.ToString();
		}
コード例 #6
0
ファイル: HtmCover.cs プロジェクト: davelondon/dontstayin
		public static Double[,] CoverToHalfspaces ( String textSpec ) {
			Region reg = new Region ( );
			Parser par = new Parser ( );
			double cid, hid;
			int rowcount, row;
			par.input = textSpec;
			par.buildto ( reg );
			if ( par. parse ( ) == false ) {
				return null;
			}
			reg.normalize ( );
			

			rowcount = 0;
			for (int i = 0; i < reg.Count; i++) {
				rowcount += reg.getNth(i).Count;
			}
			row = 0;
			Double[,] result = new Double[rowcount, 6];
			cid = 0.0;
			for (int i = 0; i < reg.Count; i++) {
				Convex con = reg.getNth (i);
				hid = 0.0;
				for (int j=0; j< con.Count; j++ ) {
					Halfspace h = con.hsAt (j);
					result[row, 0] = cid;
					result[row, 1] = hid;
					result[row, 2] = h.sv.x;
					result[row, 3] = h.sv.y;
					result[row, 4] = h.sv.z;
					result[row, 5] = h.d;
					hid += 1.0;
					row++;
				}
				cid += 1.0;
			}
			return result;
		}