コード例 #1
0
        /// <summary>
        /// Elementary descriptor for calculating the largest distance between any two contour points.
        /// </summary>
        /// <param name="mesh">The mesh of which the descriptor value is calculated.</param>
        /// <returns>The elementary descriptor with the calculated value.</returns>
        public static ElemDescriptor Diameter(IMesh mesh)
        {
            if (mesh == null)
            {
                throw new ArgumentNullException(nameof(mesh));
            }

            float biggestDiameter = 0;

            Parallel.For(0, mesh.VertexCount - 1, i => {
                Parallel.For(i + 1, mesh.VertexCount, j => {
                    float distance = Vector3.Distance(mesh.GetVertex((uint)i), mesh.GetVertex((uint)j));
                    float tempDiameter;

                    do
                    {
                        tempDiameter = biggestDiameter;
                        if (distance <= biggestDiameter)
                        {
                            break;
                        }
                    }while (Interlocked.CompareExchange(ref biggestDiameter, distance, tempDiameter) != tempDiameter);
                });
            });

            IBoundingBox bb = mesh.GetBoundingBox();

            biggestDiameter /= NumberUtil.Max(bb.MaxX, bb.MaxY, bb.MaxZ);
            return(new ElemDescriptor("Diameter", biggestDiameter));
        }
コード例 #2
0
        private static Shapes.SimpleMesh ScaleShape(Shapes.IMesh mesh)
        {
            IBoundingBox bb = mesh.GetBoundingBox();


            float min = NumberUtil.Min(bb.MinX, bb.MinY, bb.MinZ);
            float max = NumberUtil.Max(bb.MaxX, bb.MaxY, bb.MaxZ);
            float dif = (MAX_VALUE - MIN_VALUE) / (max - min);

            Vector3 minVector    = new Vector3(min, min, min);
            Vector3 minExpVector = new Vector3(MIN_VALUE, MIN_VALUE, MIN_VALUE);

            Vector3[] points = new Vector3[mesh.VertexCount];
            for (int i = points.Length - 1; i >= 0; i--)
            {
                points[i] = (mesh.GetVertex((uint)i) - minVector) * dif + minExpVector;
            }


            Shapes.SimpleMesh modifiedMesh = Shapes.SimpleMesh.CreateFrom(mesh);
            modifiedMesh.Vertices = points;
            return(modifiedMesh);
        }