/// <summary> /// Search for closest point on model-mesh and corresponding normal vector /// when given an arbitrary point. A fe-model needs to exist before this /// function gives correct results. /// </summary> /// <param name="test_point">point for which closest point on the mesh /// of a model is desired</param> /// <param name="pointOnModel">point on model mesh which is closest to /// given point</param> /// <param name="normalOnModel"> normal vector at model point closest to /// given point</param> /// /// <returns>true if a closest model mesh-point exists</returns> public bool ClosestPoint( Point3 test_point, out Point3 pointOnModel, out Vector3 normalOnModel) { var res = false; #if !UnitTest var min_dist = double.MaxValue; double dist; #endif pointOnModel = new Point3(); normalOnModel = new Vector3(); var tp = test_point.Convert(); foreach (var mesh in meshes_) { #if UnitTest throw new NotImplementedException(); #else var mpoint = mesh.ClosestMeshPoint( tp, double.MaxValue); dist = mpoint.Point.DistanceTo(tp); if (dist < min_dist) { res = true; pointOnModel = mpoint.Point.Convert(); // calculate face normal var face = mesh.Faces[mpoint.FaceIndex]; normalOnModel = FaceNormal(mesh, face); min_dist = dist; } #endif } return(res); }
public int AddVertex(Point3 vertex) { var res = mesh.Vertices.Count; mesh.Vertices.Add(vertex.Convert()); return(res); }
/// <summary> /// /// Gets the point on the mesh that is closest to a given test point. Similar to the /// ClosestPoint function except this returns a MeshPoint class which includes /// extra information beyond just the location of the closest point. /// </summary> /// <param name="testPoint"></param> /// <param name="maximumDistance"></param> /// <returns></returns> public Point3 ClosestMeshPoint(Point3 testPoint, double maximumDistance) { #if UnitTest throw new NotImplementedException(); #else return((mesh.ClosestMeshPoint(testPoint.Convert(), maximumDistance)).Point.Convert()); #endif }
/// <summary> /// Determine whether there exists a closest point to any mesh whose distance /// to the test_point is smaller or equal than limit_dist. /// /// </summary> /// <param name="testPoint">Test point.</param> /// <param name="limit_dist"></param> /// <returns>True if such a point exists, false otherwise.</returns> public bool HasClosestPoint( Point3 testPoint, double limit_dist) { #if !UnitTest var min_dist = double.MaxValue; double dist; #endif var tp = testPoint.Convert(); foreach (var mesh in meshes_) { #if UnitTest throw new NotImplementedException(); #else var mpoint = mesh.ClosestMeshPoint( tp, double.MaxValue); dist = mpoint.Point.DistanceTo(tp); if (dist <= limit_dist && dist < min_dist) { return(true); } #endif } return(false); }
private void LoadObj() { ImportObj(path); IntPtr sizePtr = GetSizes(); Size sizes = (Size)Marshal.PtrToStructure(new IntPtr(sizePtr.ToInt32()), typeof(Size)); IntPtr vertPtr = GetVertices(); Point3[] vertsT = GetElements <Point3>(vertPtr, sizes.vSize); Vector3[] verts = Point3.Convert(vertsT); IntPtr normPtr = GetNormals(); Point3[] normsT = GetElements <Point3>(normPtr, sizes.nSize); Vector3[] norms = Point3.Convert(normsT); IntPtr uvPtr = GetUVs(); Point2[] uvsT = GetElements <Point2>(uvPtr, sizes.uSize); Vector2[] uvs = Point2.Convert(uvsT); IntPtr triPtr = GetTris(); int[] tris = GetElements <int>(triPtr, sizes.tSize); Mesh mesh = new Mesh(); mesh.vertices = verts; mesh.uv = uvs; mesh.normals = norms; mesh.triangles = tris; mesh.RecalculateBounds(); meshFilter.mesh = mesh; }
public bool IsNear(Point3 p) { Point3d p3d = p.Convert(); foreach (Point3d to_point in to_points_) { if (to_point.DistanceTo(p3d) < limit_dist_) { return(true); } } foreach (Curve to_curve in to_curves_) { #if UnitTest throw new NotImplementedException(); #else double t; if (to_curve.ClosestPoint(p3d, out t, limit_dist_)) { return(true); } #endif } foreach (var to_line in to_lines_) { if (to_line.DistanceTo(p3d, true) <= limit_dist_) { return(true); } } foreach (Plane to_plane in to_planes_) { if (Math.Abs(to_plane.DistanceTo(p3d)) <= limit_dist_) { return(true); } } foreach (Brep to_brep in to_breps_) { #if UnitTest throw new NotImplementedException(); #else Point3d closest_point; ComponentIndex ci; double s, t; Vector3d normal; if (to_brep.ClosestPoint(p3d, out closest_point, out ci, out s, out t, limit_dist_, out normal)) { return(true); } #endif } foreach (Mesh to_mesh in to_meshes_) { #if UnitTest throw new NotImplementedException(); #else if (to_mesh.ClosestPoint(p3d).DistanceTo(p3d) <= limit_dist_) { return(true); } #endif } return(false); }