/// <summary> /// Builds the UV values for thw mesh represented by the vertices /// </summary> /// <param name="vertices"></param> /// <returns></returns> protected Vector2[] BuildUVs(Vector3[] vertices) { List <Vector2> ret = new List <Vector2>(); List <Vector3d> vertices3d = vertices.ToList <Vector3>().ConvertAll(item => (Vector3d)item); // // create a UV mapping plane // to make image planes work - we assume that the origin of UV plane is the last vertex // OrthogonalPlaneFit3 orth = new OrthogonalPlaneFit3(vertices3d); Frame3f frame = new Frame3f(vertices[vertices.Length - 1], -1 * orth.Normal); // // check the orientation of the plane in UV space. // for image planes - we assume that the x direction from the first point to the second point should always be positive // if not - reverse the frame // if (Math.Sign( frame.ToPlaneUV((Vector3f)vertices3d[0], 2).x - frame.ToPlaneUV((Vector3f)vertices3d[1], 2).x ) > -1) { frame = new Frame3f(vertices[vertices.Length - 1], orth.Normal); } // // map all of the points to UV space // foreach (Vector3d v in vertices3d) { ret.Add(frame.ToPlaneUV((Vector3f)v, 2)); } // // normalize UVs to [0..1, 0..1] // float maxX = float.NegativeInfinity; float maxY = float.NegativeInfinity; float minX = float.PositiveInfinity; float minY = float.PositiveInfinity; for (int i = 0; i < ret.Count; i++) { Vector2 v = ret[i]; maxX = maxX > v.x ? maxX : v.x; minX = minX < v.x ? minX : v.x; maxY = maxY > v.y ? maxY : v.y; minY = minY < v.y ? minY : v.y; } scaleX = maxX - minX; scaleY = maxY - minY; for (int i = 0; i < ret.Count; i++) { ret[i] = new Vector2((ret[i].x - minX) / scaleX, (ret[i].y - minY) / scaleY); } return(ret.ToArray()); }
/// <summary> /// this method sets the ground point attribute of the given internal data list to the right value /// </summary> /// <param name="listOfDataLists">List of internal data</param> public static void SetGroundLabels(List <InternalDataFormat> listOfDataLists) { int segmentCount = 3; float initialSeedDistanceThreshold = 0.3f; float seedDistanceThreshold = 0.2f; float covarIterations = 1; InternalDataFormat seed = new InternalDataFormat(0, Vector3.zero, 0, 2); List <InternalDataFormat> seedPoints = new List <InternalDataFormat>(); //List<List<InternalDataFormat>> cloudSegments = GetSimpleCloudSegments(listOfDataLists); //List<List<InternalDataFormat>> cloudSegments = GetCloudSegmentsSegmentedByYAxis(listOfDataLists, segmentCount); List <List <InternalDataFormat> > cloudSegments = GetCloudSegmentsSegmentedByYAndXAxis(listOfDataLists, segmentCount); for (int i = 0; i < cloudSegments.Count; i++) { List <InternalDataFormat> segmentData = cloudSegments.ElementAt(i); seedPoints = GetInitialSeedPoints(segmentData, initialSeedDistanceThreshold); for (int j = 0; j < covarIterations; j++) { List <Vector3d> points = new List <Vector3d>(); for (int m = 0; m < seedPoints.Count; m++) { var pos = seedPoints[m]._position; points.Add(new Vector3d(pos.x, pos.y, pos.z)); } OrthogonalPlaneFit3 estimatedGroundPlane = new OrthogonalPlaneFit3(points); Vector3 planeOriginPoint = new Vector3((float)estimatedGroundPlane.Origin.x, (float)estimatedGroundPlane.Origin.y, (float)estimatedGroundPlane.Origin.z); Vector3 planeNormal = new Vector3((float)estimatedGroundPlane.Normal.x, (float)estimatedGroundPlane.Normal.y, (float)estimatedGroundPlane.Normal.z); Plane estimatedGroundPlaneUnity = new Plane(planeNormal, planeOriginPoint); if (j == covarIterations - 1) { Util.DrawPlane(planeOriginPoint, planeNormal, planeNormal.magnitude * 2, i); } for (int k = 0; k < segmentData.Count; k++) { seed = cloudSegments.ElementAt(i).ElementAt(k); float distancePointToPlane = estimatedGroundPlaneUnity.GetDistanceToPoint(seed._position); if (distancePointToPlane <= seedDistanceThreshold) { seed._groundPointLabel = 1; seedPoints.Add(seed); } else { seed._groundPointLabel = 0; } } } } }
public static OrthogonalPlaneFit3 FitPlane(double[] x, double[] y, double[] z) { List <Vector3d> pos = new List <Vector3d>(); for (int i = 0; i < x.Length; i++) { pos.Add(new Vector3d(x[i], y[i], z[i])); } var fit = new OrthogonalPlaneFit3(pos); return(fit); }
public static GeneralPolygon2d ToPolygon(this List <Dataline> list, ref Frame3f frame) { List <VertexLookup> VertexTable = list[0].VertexTable; Vector3d[] vertices = new Vector3d[VertexTable.Count]; for (int j = 0; j < VertexTable.Count; j++) { vertices[j] = VertexTable.Find(item => item.Vertex == j).Com.transform.position; } OrthogonalPlaneFit3 orth = new OrthogonalPlaneFit3(vertices); frame = new Frame3f(orth.Origin, orth.Normal); GeneralPolygon2d poly = new GeneralPolygon2d(new Polygon2d()); for (int i = 0; i < list.Count; i++) { VertexTable = list[i].VertexTable; vertices = new Vector3d[VertexTable.Count]; for (int j = 0; j < VertexTable.Count; j++) { vertices[j] = VertexTable.Find(item => item.Vertex == j).Com.transform.position; } List <Vector2d> vertices2d = new List <Vector2d>(); foreach (Vector3d v in vertices) { Vector2f vertex = frame.ToPlaneUV((Vector3f)v, 3); if (i != 0 && !poly.Outer.Contains(vertex)) { break; } vertices2d.Add(vertex); } Polygon2d p2d = new Polygon2d(vertices2d); if (i == 0) { p2d = new Polygon2d(vertices2d); p2d.Reverse(); poly.Outer = p2d; } else { try { poly.AddHole(p2d, true, true); } catch { p2d.Reverse(); poly.AddHole(p2d, true, true); } } } return(poly); }
public static PlaneParams FitPlane(List <PosXYZ> pos) { var plane = new OrthogonalPlaneFit3(pos.Select(p => new Vector3d(p.X, p.Y, p.Z))); var ret = new PlaneParams() { Normal = plane.Normal, Origin = plane.Origin }; if (ret.Normal.z < 0) { ret.Normal = -ret.Normal; } return(ret); }
public static GeneralPolygon2d ToPolygon(this List <DCurve3> list, ref Frame3f frame) { OrthogonalPlaneFit3 orth = new OrthogonalPlaneFit3(list[0].Vertices); frame = new Frame3f(orth.Origin, orth.Normal); GeneralPolygon2d poly = new GeneralPolygon2d(new Polygon2d()); for (int i = 0; i < list.Count; i++) { List <Vector3d> vertices = list[i].Vertices.ToList(); List <Vector2d> vertices2d = new List <Vector2d>(); foreach (Vector3d v in vertices) { Vector2f vertex = frame.ToPlaneUV((Vector3f)v, 3); if (i != 0 && !poly.Outer.Contains(vertex)) { break; } vertices2d.Add(vertex); } Polygon2d p2d = new Polygon2d(vertices2d); if (i == 0) { p2d = new Polygon2d(vertices2d); p2d.Reverse(); poly.Outer = p2d; } else { try { poly.AddHole(p2d, true, true); } catch { p2d.Reverse(); poly.AddHole(p2d, true, true); } } } return(poly); }
public static void CalculateUVs(this DMesh3 dMesh) { dMesh.EnableVertexUVs(Vector2f.Zero); OrthogonalPlaneFit3 orth = new OrthogonalPlaneFit3(dMesh.Vertices()); Frame3f frame = new Frame3f(orth.Origin, orth.Normal); AxisAlignedBox3d bounds = dMesh.CachedBounds; AxisAlignedBox2d boundsInFrame = new AxisAlignedBox2d(); for (int i = 0; i < 8; i++) { boundsInFrame.Contain(frame.ToPlaneUV((Vector3f)bounds.Corner(i), 3)); } Vector2f min = (Vector2f)boundsInFrame.Min; float width = (float)boundsInFrame.Width; float height = (float)boundsInFrame.Height; for (int i = 0; i < dMesh.VertexCount; i++) { Vector2f UV = frame.ToPlaneUV((Vector3f)dMesh.GetVertex(i), 3); UV.x = (UV.x - min.x) / width; UV.y = (UV.y - min.y) / height; dMesh.SetVertexUV(i, UV); } }
public static double CalcZ(OrthogonalPlaneFit3 plane, double x, double y) { return(-(((x - plane.Origin.x) * plane.Normal.x) + ((y - plane.Origin.y) * plane.Normal.y)) / plane.Normal.z + plane.Origin.z); }
public static double Point2Plane(OrthogonalPlaneFit3 plane, double[] pos) { var v1 = new Vector3d(pos[0], pos[1], pos[2]); return((v1 - plane.Origin).Dot(plane.Normal)); }
public ProfileOfSurfaceCalc(OrthogonalPlaneFit3 datumPlane) { GDTType = GDTType.ProfileOfSurface; Datum = datumPlane; }
public ParallelismCalc(OrthogonalPlaneFit3 datum) { Datum = datum; GDTType = GDTType.Parallelism; }