Esempio n. 1
0
        protected virtual void InitializeVertexQuadrics()
        {
            int NT = mesh.MaxTriangleID;

            QuadricError[] triQuadrics = new QuadricError[NT];
            double[]       triAreas    = new double[NT];
            gParallel.ForEach(mesh.TriangleIndices(), (tid) => {
                Vector3d c, n;
                mesh.GetTriInfo(tid, out n, out triAreas[tid], out c);
                triQuadrics[tid] = new QuadricError(n, c);
            });


            int NV = mesh.MaxVertexID;

            vertQuadrics = new QuadricError[NV];
            gParallel.ForEach(mesh.VertexIndices(), (vid) => {
                vertQuadrics[vid] = QuadricError.Zero;
                foreach (int tid in mesh.VtxTrianglesItr(vid))
                {
                    vertQuadrics[vid].Add(triAreas[tid], ref triQuadrics[tid]);
                }
                //Util.gDevAssert(MathUtil.EpsilonEqual(0, vertQuadrics[i].Evaluate(mesh.GetVertex(i)), MathUtil.Epsilon * 10));
            });
        }
Esempio n. 2
0
        public static Vector3d QuickCompute(DMesh3 mesh, int vid, NormalsTypes type = NormalsTypes.Vertex_OneRingFaceAverage_AreaWeighted)
        {
            Vector3d sum = Vector3d.Zero;
            Vector3d n, c; double a;

            foreach (int tid in mesh.VtxTrianglesItr(vid))
            {
                mesh.GetTriInfo(tid, out n, out a, out c);
                sum += a * n;
            }
            return(sum.Normalized);
        }
Esempio n. 3
0
        public MeshTriInfoCache(DMesh3 mesh)
        {
            int NT = mesh.TriangleCount;

            Centroids = new DVector <Vector3d>(); Centroids.resize(NT);
            Normals   = new DVector <Vector3d>(); Normals.resize(NT);
            Areas     = new DVector <double>(); Areas.resize(NT);
            gParallel.ForEach(mesh.TriangleIndices(), (tid) => {
                Vector3d c, n; double a;
                mesh.GetTriInfo(tid, out n, out a, out c);
                Centroids[tid] = c;
                Normals[tid]   = n;
                Areas[tid]     = a;
            });
        }
Esempio n. 4
0
 /// <summary>
 /// Count all input mesh face normals
 /// </summary>
 public void CountFaceNormals(DMesh3 mesh, bool bWeightByArea = true)
 {
     foreach (int tid in mesh.TriangleIndices())
     {
         if (bWeightByArea)
         {
             Vector3d n, c; double area;
             mesh.GetTriInfo(tid, out n, out area, out c);
             Count(n, area, true);
         }
         else
         {
             Count(mesh.GetTriNormal(tid), 1.0, true);
         }
     }
 }
Esempio n. 5
0
        /// <summary>
        /// Computes <see cref="BaseFaceCentroids"/> and <see cref="BaseFaceNormals"/>.
        /// Allocates other sets.
        /// </summary>
        void initialize()
        {
            BaseFaceCentroids = new Vector3d[Target.MaxTriangleID];
            BaseFaceNormals   = new Vector3d[Target.MaxTriangleID];
            foreach (int tid in Target.TriangleIndices())
            {
                Target.GetTriInfo(tid, out BaseFaceNormals[tid], out _, out BaseFaceCentroids[tid]);
            }

            // allocate internals
            SegVertices           = new List <SegmentVtx>();
            EdgeVertices          = new Dictionary <int, List <SegmentVtx> >();
            FaceVertices          = new Dictionary <int, List <SegmentVtx> >();
            SubFaces              = new Dictionary <int, HashSet <int> >();
            ParentFaces           = new Dictionary <int, int>();
            SegmentInsertVertices = new HashSet <int>();
            VIDToSegVtxMap        = new Dictionary <int, SegmentVtx>();
        }
Esempio n. 6
0
        protected virtual void InitializeVertexQuadrics()
        {
            int NT = mesh.MaxTriangleID;

            QuadricError[] triQuadrics = new QuadricError[NT];
            double[]       triAreas    = new double[NT];
            gParallel.BlockStartEnd(0, mesh.MaxTriangleID - 1, (start_tid, end_tid) => {
                Vector3d c, n;
                for (int tid = start_tid; tid <= end_tid; tid++)
                {
                    if (mesh.IsTriangle(tid))
                    {
                        mesh.GetTriInfo(tid, out n, out triAreas[tid], out c);
                        triQuadrics[tid] = new QuadricError(ref n, ref c);
                    }
                }
            });


            int NV = mesh.MaxVertexID;

            vertQuadrics = new QuadricError[NV];
            gParallel.BlockStartEnd(0, mesh.MaxVertexID - 1, (start_vid, end_vid) => {
                for (int vid = start_vid; vid <= end_vid; vid++)
                {
                    vertQuadrics[vid] = QuadricError.Zero;
                    if (mesh.IsVertex(vid))
                    {
                        foreach (int tid in mesh.VtxTrianglesItr(vid))
                        {
                            vertQuadrics[vid].Add(triAreas[tid], ref triQuadrics[tid]);
                        }
                        //Util.gDevAssert(MathUtil.EpsilonEqual(0, vertQuadrics[i].Evaluate(mesh.GetVertex(i)), MathUtil.Epsilon * 10));
                    }
                }
            });
        }