Exemplo n.º 1
0
        internal double CheckLocalCompactness(int vertId, double[] vNew)
        {
            var n1   = model.Neighbors(vertId);
            var cMin = 1.0;

            foreach (var faceId in n1)
            {
                if (!model.FaceIsValid(faceId))
                {
                    continue;
                }

                var         face   = model.Face(faceId);
                MxVector3[] fAfter = new MxVector3[3];
                for (var i = 0; i < 3; i++)
                {
                    fAfter[i] = (face[i] == vertId)
                                    ? new MxVector3(vNew)
                                    : new MxVector3(model.Vertex(face[i]));
                }

                var c = MxGeom3d.TriangleCompactness(fAfter[0], fAfter[1], fAfter[2]);
                if (c < cMin)
                {
                    cMin = c;
                }
            }

            return(cMin);
        }
Exemplo n.º 2
0
        internal double CheckLocalInversion(int vertId, double[] vNew)
        {
            var nMin = 1.0;
            var n1   = model.Neighbors(vertId);

            foreach (var faceId in n1)
            {
                if (!model.FaceIsValid(faceId))
                {
                    continue;
                }

                var face = model.Face(faceId);
                var nml  = new double[3];
                model.ComputeFaceNormal(faceId, ref nml);
                var nBefore = new MxVector3(nml);

                var fAfter = new MxVector3[3];
                for (var i = 0; i < 3; i++)
                {
                    fAfter[i] = (face[i] == vertId)
                                    ? new MxVector3(vNew)
                                    : new MxVector3(model.Vertex(face[i]));
                }

                var newNml = MxGeom3d.TriangleNormal(fAfter[0], fAfter[1], fAfter[2]);
                var delta  = nBefore * newNml;
                if (delta < nMin)
                {
                    nMin = delta;
                }
            }

            return(nMin);
        }
Exemplo n.º 3
0
        protected void CollectQuadrics()
        {
            foreach (var quad in quadrics)
            {
                quad.Clear();
            }

            for (var i = 0; i < model.FaceCount; i++)
            {
                var face  = model.Face(i);
                var vert0 = new MxVector3(model.Vertex(face[0]));
                var vert1 = new MxVector3(model.Vertex(face[1]));
                var vert2 = new MxVector3(model.Vertex(face[2]));

                var plane = (WeightingPolicy == MxWeighting.RawNormals)
                                ? MxGeom3d.TriangleRawPlane(vert0, vert1, vert2)
                                : MxGeom3d.TrianglePlane(vert0, vert1, vert2);

                var quad = new MxQuadric3(plane[0], plane[1], plane[2], plane[3], model.ComputeFaceArea(i));

                switch (WeightingPolicy)
                {
                case MxWeighting.Angle:
                {
                    for (int j = 0; j < 3; j++)
                    {
                        var quadJ = new MxQuadric3(quad);
                        quadJ             *= model.ComputeCornerAngle(i, j);
                        quadrics[face[j]] += quadJ;
                    }
                    break;
                }

                case MxWeighting.Area:
                {
                    quad *= quad.Area;
                    quadrics[face[0]] += quad;
                    quadrics[face[1]] += quad;
                    quadrics[face[2]] += quad;
                    break;
                }

                case MxWeighting.AreaAverage:
                {
                    quad *= quad.Area;
                    quadrics[face[0]] += quad;
                    quadrics[face[1]] += quad;
                    quadrics[face[2]] += quad;
                    break;
                }

                default:
                {
                    quadrics[face[0]] += quad;
                    quadrics[face[1]] += quad;
                    quadrics[face[2]] += quad;
                    break;
                }
                }
            }
        }