减面算法

using System;
using System.Collections.Generic;
using System.Linq;
using GenesisWinForm;
using GenesisWinForm.G3DObject.G3DCore;
//using System.Threading.Tasks;
using GenesisWinForm.MathG3D;
using OpenTK;

public static class CollapseVertexFunction
{
    /// <summary>
    /// 计算边的坍塌cost
    /// </summary>
    public static double ComputeEdgeCollapseCost(Vertex u, Vertex v)
    {

        // if we collapse edge uv by moving u to v then how

        // much different will the model change, i.e. the “error”.

        double edgelength = (v.position - u.position).Length;

        double curvature = 0;

        // find the “sides” triangles that are on the edge uv

        List<TriangleP> sides = new List<TriangleP>();

        for (int i = 0; i < u.Face.Count; i++)
        {

            if (u.Face[i].HasVertex(v.id))
            {

                sides.Add(u.Face[i]);

            }

        }

        // use the triangle facing most away from the sides

        // to determine our curvature term

        for (int i = 0; i < u.Face.Count; i++)
        {

            double mincurv = 1;

            for (int j = 0; j < sides.Count; j++)
            {

                // use dot product of face normals.

                double dotprod = Vector3d.Dot(u.Face[i].normal, sides[j].normal);

                mincurv = Math.Min(mincurv, (1 - dotprod) / 2.0f);

            }

            curvature = Math.Max(curvature, mincurv);

        }
        Debug.Log("curvature" + curvature);
        return edgelength * curvature;

    }

    /// <summary>
    /// 通过顶点计算坍塌cost
    /// </summary>
    public static void ComputeEdgeCostAtVertex(Vertex v)
    {

        if (v.neighbor.Count == 0)
        {

            v.collapse = null;

            v.cost = -0.01f;

            return;

        }

        v.cost = 1000000;

        v.collapse = null;

        // search all neighboring edges for “least cost” edge

        for (int i = 0; i < v.neighbor.Count; i++)
        {

            double c;

            c = ComputeEdgeCollapseCost(v, v.neighbor[i]);

            if (c < v.cost)
            {

                v.collapse = v.neighbor[i];

                v.cost = c;

            }

        }

    }

    #region
    /// <summary>
    /// 通过三个顶点查找一个三角形
    /// </summary>
    //public static int FindTriangleByVertexs(Vertex v1, Vertex v2, Vertex v3)
    //{
    //    TriangleP t = new TriangleP(0);
    //    for (int i = 0; i < v1.Face.Count; i++)
    //    {
    //        for (int j = 0; j < v2.Face.Count; j++)
    //        {
    //            for (int k = 0; k < v3.Face.Count; k++)
    //            {
    //                if (v1.Face[i] == v2.Face[j] && v2.Face[j] == v3.Face[k])
    //                {

    //                    return v1.Face[i].id;
    //                }
    //            }

    //        }

    //    }

    //    return t.id;
    //}


    //public static bool DeleteFace(G3DCore3DObjectOptimize _mesh, TriangleP _triangleP)
    //{

    //    _mesh.DeleteTriangleP(_triangleP.id);

    //    return true;

    //}

    //public static bool DeleteVertexs(G3DCore3DObjectOptimize _mesh, Vertex _v1)
    //{
    //    #region
    //    //Vertex v1 = _v1;
    //    //Vertex v2 = _v1.collapse;

    //    //List<Vertex> v3v4 = FindVertexsHavingSameSide(v1, v2);
    //    //Vertex v3 = v3v4[0];
    //    //Vertex v4 = v3v4[1];
    //    //Vertex v5;//v1v3共边的另一个点,需要更新v1v3v5面的neighbor
    //    //Vertex v6;//v1v4共边的另一个点,需要更新v1v4v6面的neighbor
    //    //Vertex v7;//v2v3共边的另一个点,需要更新v2v3v7面的neighbor
    //    //Vertex v8;//v2v4共边的另一个点,需要更新v2v4v7面的neighbor

    //    //List<Vertex> V2V5 = FindVertexsHavingSameSide(v1, v3);
    //    //List<Vertex> V2V6 = FindVertexsHavingSameSide(v1, v4);
    //    //List<Vertex> V7V1 = FindVertexsHavingSameSide(v2, v3);
    //    //List<Vertex> V8V1 = FindVertexsHavingSameSide(v2, v4);
    //    v5
    //    //if (V2V5[0] == v2)
    //    //{
    //    //    v5 = V2V5[1];
    //    //}
    //    //else
    //    //{
    //    //    v5 = V2V5[0];
    //    //}
    //    v6
    //    //if (V2V6[0] == v2)
    //    //{
    //    //    v6 = V2V6[1];
    //    //}
    //    //else
    //    //{
    //    //
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值