Пример #1
0
        /// <summary>
        /// Find distance from point to mesh
        /// Returns interpolated vertex-normal frame if available, otherwise tri-normal frame.
        /// </summary>
        public static double NearestPointDistance(DMesh3 mesh, ISpatial spatial, Vector3d queryPoint, double maxDist = double.MaxValue)
        {
            int tid = spatial.FindNearestTriangle(queryPoint, maxDist);

            if (tid == DMesh3.InvalidID)
            {
                return(double.MaxValue);
            }
            return(Math.Sqrt(TriangleDistance(mesh, tid, queryPoint).DistanceSquared));
        }
Пример #2
0
            public Vector3d FindNearestAndOffset(Vector3d pos)
            {
                int tNearestID                 = Spatial.FindNearestTriangle(pos);
                DistPoint3Triangle3 q          = MeshQueries.TriangleDistance(Mesh, tNearestID, pos);
                Vector3d            vHitNormal =
                    (UseFaceNormal == false && Mesh.HasVertexNormals) ?
                    Mesh.GetTriBaryNormal(tNearestID, q.TriangleBaryCoords.x, q.TriangleBaryCoords.y, q.TriangleBaryCoords.z)
                        : Mesh.GetTriNormal(tNearestID);

                return(q.TriangleClosest + Distance * vHitNormal);
            }
Пример #3
0
        /// <summary>
        /// Find point-normal(Z) frame at closest point to queryPoint on mesh.
        /// Returns interpolated vertex-normal frame if available, otherwise tri-normal frame.
        /// </summary>
        public static Frame3f NearestPointFrame(DMesh3 mesh, ISpatial spatial, Vector3d queryPoint, bool bForceFaceNormal = false)
        {
            int      tid    = spatial.FindNearestTriangle(queryPoint);
            Vector3d surfPt = TriangleDistance(mesh, tid, queryPoint).TriangleClosest;

            if (mesh.HasVertexNormals && bForceFaceNormal == false)
            {
                return(SurfaceFrame(mesh, tid, surfPt));
            }
            else
            {
                return(new Frame3f(surfPt, mesh.GetTriNormal(tid)));
            }
        }
Пример #4
0
        public MeshFacesFromLoop(DMesh3 Mesh, DCurve3 SpaceCurve, ISpatial Spatial, int tSeed)
        {
            this.Mesh = Mesh;

            int N = SpaceCurve.VertexCount;

            InitialLoopT = new int[N];
            for (int i = 0; i < N; ++i)
            {
                InitialLoopT[i] = Spatial.FindNearestTriangle(SpaceCurve[i]);
            }

            find_path();
            find_interior_from_seed(tSeed);
        }
Пример #5
0
        public MeshFacesFromLoop(NGonsCore.geometry3Sharp.mesh.DMesh3 Mesh, DCurve3 SpaceCurve, ISpatial Spatial)
        {
            this.Mesh = Mesh;

            int N = SpaceCurve.VertexCount;

            InitialLoopT = new int[N];
            for (int i = 0; i < N; ++i)
            {
                InitialLoopT[i] = Spatial.FindNearestTriangle(SpaceCurve[i]);
            }

            find_path();
            find_interior_from_tris();
        }
Пример #6
0
        public void Precompute_NearestTriangleNormals()
        {
            int N = DisplaceMesh.MaxTriangleID;

            TriVtxNormalDisplacements = new TriVtxNormalsDisplace[N];

            update_vertex_frames();

            //foreach ( int vid in DisplaceMesh.VertexIndices() ) {
            gParallel.ForEach <int>(DisplaceMesh.VertexIndices(), (vid) => {
                Vector3f pos = (Vector3f)DisplaceMesh.GetVertex(vid);
                int tid      = BaseSpatial.FindNearestTriangle(pos);
                Index3i tri  = BaseMesh.GetTriangle(tid);

                Vector3f dv0 = VtxFrames[tri.a].ToFrameP(pos);
                Vector3f dv1 = VtxFrames[tri.b].ToFrameP(pos);
                Vector3f dv2 = VtxFrames[tri.c].ToFrameP(pos);

                TriVtxNormalDisplacements[vid] = new TriVtxNormalsDisplace()
                {
                    tID = tid, dv0 = dv0, dv1 = dv1, dv2 = dv2
                };
            });
        }
Пример #7
0
        /// <summary>
        /// Find distance from point to mesh
        /// Returns interpolated vertex-normal frame if available, otherwise tri-normal frame.
        /// </summary>
        public static double NearestPointDistance(DMesh3 mesh, ISpatial spatial, Vector3d queryPoint, double maxDist = double.MaxValue)
        {
            int tid = spatial.FindNearestTriangle(queryPoint, maxDist);

            if (tid == DMesh3.InvalidID)
            {
                return(double.MaxValue);
            }
            Triangle3d tri = new Triangle3d();

            mesh.GetTriVertices(tid, ref tri.V0, ref tri.V1, ref tri.V2);
            Vector3d closest, bary;
            double   dist_sqr = DistPoint3Triangle3.DistanceSqr(ref queryPoint, ref tri, out closest, out bary);

            return(Math.Sqrt(dist_sqr));
        }