Ejemplo n.º 1
0
        public HE_MeshPoint(Point3d point, HE_Face face)
        {
            List <HE_Vertex> adj = face.adjacentVertices();

            double[] bary = Convert.Point3dToBarycentric(point, adj[0], adj[1], adj[2]);
            U = bary[0];
            V = bary[1];
            W = bary[2];
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Compute the level on a specified face.
        /// </summary>
        /// <param name="valueKey">Key of the value to be computed per vertex.</param>
        /// <param name="level">Level value to be computed.</param>
        /// <param name="face">Face to computee the level in.</param>
        /// <param name="line">Resulting level line on the face</param>
        /// <returns>True if successful, false if not.</returns>
        public static bool GetFaceLevel(string valueKey, double level, HE_Face face, out Line line)
        {
            List <HE_Vertex> adj          = face.adjacentVertices();
            List <double>    vertexValues = new List <double> {
                adj[0].UserValues[valueKey], adj[1].UserValues[valueKey], adj[2].UserValues[valueKey]
            };

            List <int> above = new List <int>();
            List <int> below = new List <int>();

            for (int i = 0; i < vertexValues.Count; i++)
            {
                if (vertexValues[i] < level)
                {
                    below.Add(i);
                }
                else
                {
                    above.Add(i);
                }
            }

            if (above.Count == 3 || below.Count == 3)
            {
                // Triangle is above or below level
                line = new Line(new Point3d(), new Point3d());
                return(false);
            }
            else
            {
                // Triangle intersects level
                List <Point3d> intersectionPoints = new List <Point3d>();

                foreach (int i in above)
                {
                    foreach (int j in below)
                    {
                        double   diff             = vertexValues[i] - vertexValues[j];
                        double   desiredDiff      = level - vertexValues[j];
                        double   unitizedDistance = desiredDiff / diff;
                        Vector3d edgeV            = adj[i] - adj[j];
                        Point3d  levelPoint       = (Point3d)adj[j] + (edgeV * unitizedDistance);
                        intersectionPoints.Add(levelPoint);
                    }
                }
                line = new Line(intersectionPoints[0], intersectionPoints[1]);
                return(true);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Compute the gradient on a given mesh face given some per-vertex values
        /// </summary>
        /// <param name="valueKey">Key of the values in the vertex.UserData dictionary</param>
        /// <param name="face">Face to compute thee gradient.</param>
        /// <returns>A vector representing the gradient on that mesh face</returns>
        public static Vector3d ComputeFaceGradient(string valueKey, HE_Face face)
        {
            List <HE_Vertex> adjacentVertices = face.adjacentVertices();
            Point3d          i = adjacentVertices[0];
            Point3d          j = adjacentVertices[1];
            Point3d          k = adjacentVertices[2];

            double gi = adjacentVertices[0].UserValues[valueKey];
            double gj = adjacentVertices[1].UserValues[valueKey];
            double gk = adjacentVertices[2].UserValues[valueKey];

            Vector3d faceNormal      = face.Normal / (2 * face.Area);
            Vector3d rotatedGradient = (gi * (k - j) + gj * (i - k) + gk * (j - i)) / (2 * face.Area);
            Vector3d gradient        = rotatedGradient.Cross(faceNormal);

            return(gradient);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Compute the intersection between a mesh face perimeter and a ray tangent to the face.
        /// </summary>
        /// <param name="ray">The tangent ray.</param>
        /// <param name="Face">The mesh face.</param>
        /// <param name="result">The resulting intersection point.</param>
        /// <param name="halfEdge">The half-edge on where the intersection lies.</param>
        /// <returns></returns>
        public static ISRayFacePerimeter RayFacePerimeter(Ray ray, HE_Face Face, out Point3d result, out HE_HalfEdge halfEdge)
        {
            Vector3d faceNormal = HE_MeshGeometry.FaceNormal(Face);
            Vector3d biNormal   = Vector3d.CrossProduct(ray.Direction, faceNormal);

            Plane perpPlane = new Plane(ray.Origin, ray.Direction, faceNormal, biNormal);

            List <HE_Vertex> vertices = Face.adjacentVertices();

            Point3d temp = new Point3d();

            Line line = new Line(vertices[0], vertices[1]);

            if (LinePlane(line, perpPlane, out temp) != ISLinePlane.Point)
            {
                result = null; halfEdge = null; return(ISRayFacePerimeter.Point);
            }                                                                                                                                   // No intersection found
            if (temp != ray.Origin && temp != null)
            {
                result = temp; halfEdge = null; return(ISRayFacePerimeter.Point);
            }                                                                                                            // Intersection found

            line = new Line(vertices[1], vertices[2]);
            if (LinePlane(line, perpPlane, out temp) != ISLinePlane.Point)
            {
                result = null; halfEdge = null; return(ISRayFacePerimeter.NoIntersection);
            }                                                                                                                                            // No intersection found
            if (temp != ray.Origin && temp != null)
            {
                result = temp; halfEdge = null; return(ISRayFacePerimeter.Point);
            }                                                                                                            // Intersection found

            line = new Line(vertices[2], vertices[0]);
            if (LinePlane(line, perpPlane, out temp) != ISLinePlane.Point)
            {
                result = null; halfEdge = null; return(ISRayFacePerimeter.NoIntersection);
            }
            if (temp != ray.Origin && temp != null)
            {
                result = temp; halfEdge = null; return(ISRayFacePerimeter.Point);
            }
            else
            {
                result = null; halfEdge = null; return(ISRayFacePerimeter.Error);
            }
        }