public static void Example() { PZDirection d1 = new PZDirection(1, 1); // 45d PZDirection d2 = new PZDirection(-1, 1); // 135d PZDirection d3 = new PZDirection(-1, -1); // 225d PZDirection d4 = new PZDirection(1, -1); // -45d or 315d System.Console.WriteLine("d1: " + d1.GetAngle()); System.Console.WriteLine("d2: " + d2.GetAngle()); System.Console.WriteLine("d3: " + d3.GetAngle()); System.Console.WriteLine("d4: " + d4.GetAngle()); }
/// <summary> /// extend from a given point, direction and distance /// </summary> /// <param name="p"></param> /// <param name="d"></param> /// <param name="dist"></param> /// <returns></returns> public void ExtendFrom(PZPoint p, PZDirection d, double dist) { x = p.x + dist * d.x; y = p.y + dist * d.y; z = p.z + dist * d.z; }
public PZDirection(PZDirection d) { x = d.x; y = d.y; z = d.z; }
public double GetAngle() { PZDirection h = new PZDirection(1, 0); double a = this.GetAngle(h); return a; }
public void MemCopyFrom(PZDirection d) { x = d.x; y = d.y; z = d.z; }
/// <summary> /// get angle to direction d in radius /// </summary> /// <param name="d"></param> /// <returns></returns> public double GetAngle(PZDirection d) { double cos = (x * d.x + y * d.y) / System.Math.Sqrt(x * x + y * y) / System.Math.Sqrt(d.x * d.x + d.y * d.y); if (cos > 1.0) cos = 1.0; if (cos < -1.0) cos = 1.0; double angle = System.Math.Acos(cos); return angle; }
/// <summary> /// calculate Cs, the average line segment direction /// </summary> /// <param name="directionList"></param> /// <returns></returns> private PZDirection CalculateCs(List<PZDirection> directionList) { double x = 0.0; double y = 0.0; int length = directionList.Count; for (int i = 0; i < length; i++) { x += directionList[i].x; y += directionList[i].y; } PZDirection thetas = new PZDirection(x / (double)length, y / (double)length); return thetas; }
/// <summary> /// assign data term /// </summary> private void AssignDataTerm(Bitmap srcImage, PZMath_matrix gvfU, PZMath_matrix gvfV, PZMath_matrix gvfMagnitude, List<PZPoint> pointList, List<PZDirection> directionList, ref List<int> intensityList, ref List<double> gvfUList, ref List<double> gvfVList, ref List<double> gvfMagnitudeList) { // clear lists intensityList.Clear(); gvfUList.Clear(); gvfVList.Clear(); gvfMagnitudeList.Clear(); int length = pointList.Count; double offset = 1.0; // for each point for (int i = 0; i < length; i++) { PZPoint point = pointList[i]; double x = point.x; double y = point.y; // assign intensity int intensity = Convert.ToInt32(srcImage.GetPixel((int)x, (int)y).R); intensityList.Add(intensity); // find normal direction PZDirection lineDirection = new PZDirection(directionList[i]); lineDirection.Rotate(90); // offset 1 or 2 pixels y += lineDirection.y * offset; x += lineDirection.x * offset; // asigne GVF info gvfUList.Add(gvfU[(int)y, (int)x]); gvfVList.Add(gvfV[(int)y, (int)x]); gvfMagnitudeList.Add(gvfMagnitude[(int)y, (int)x]); } }
/// <summary> /// initialize prior model /// </summary> public void InitializePriorModel() { // check line segment validity //string errorMessage; //if (!CheckLineSegmentConnectivity(out errorMessage)) // throw new ApplicationException("LineSegment::InitializePirorModel(), " + errorMessage); // clear connections //_startPointConnectionList.Clear(); //_startPointConnectionTypeList.Clear(); //_endPointConnectionList.Clear(); //_endPointConnectionTypeList.Clear(); // calculate direction list CalculateDirection(_pointList, ref _directionList); // calculate Cs _Cs = CalculateCs(_directionList); // assure Ls _Ls = _pointList.Count; }
public void CalculateCs() { _Cs = CalculateCs(_directionList); }