Ejemplo n.º 1
0
        /// <summary>
        /// compute normals for a all vectors of pointSource
        /// </summary>
        /// <param name="pointsSource"></param>
        /// <returns></returns>
        public List <Vector3> Normals(PointCloudVertices pointsSource, bool centerOfMassMethod, bool flipNormalWithOriginVector)
        {
            Vector3        normalPrevious = new Vector3();
            List <Vector3> normals        = new List <Vector3>();

            for (int i = 0; i < pointsSource.Count; i++)
            {
                Vertex          v       = pointsSource[i];
                List <Vector3d> sublist = new List <Vector3d>();
                for (int j = 0; j < v.KDTreeSearch.Count; j++)
                {
                    Vertex vNearest = pointsSource[v.KDTreeSearch[j].Key];
                    sublist.Add(pointsSource[v.KDTreeSearch[j].Key].Vector);
                }
                if (centerOfMassMethod)
                {
                    Vector3d centroid = sublist.CalculateCentroid();
                    sublist.SubtractVector(centroid);
                }
                else
                {
                    sublist.SubtractVector(v.Vector);
                }
                SVD_ForListVectorsMassCentered(sublist, true);

                Vector3 normal = V.ExtractRow(2).ToVector();
                if (flipNormalWithOriginVector)
                {
                    AdjustOrientationWithVector(ref normal, v.Vector.ToVector());
                }

                //if (i > 0)
                //    AdjustOrientation(ref normal, normalPrevious);
                normalPrevious = normal;


                normal.Normalize();
                normals.Add(normal);
                v.IndexNormals.Add(normals.Count - 1);

                // to show ALL vectors (including the 2 vectors on the plane:
                //AddAllPlaneVectors(v, normals);
            }

            return(normals);
        }