Ejemplo n.º 1
0
        public void CubicClassify(EntityCollection part)
        {
            this.Boundary = part.Boundary;
            this.Dimentions = (Boundary[1] - Boundary[0]).ToArray();
            double longEdgeLength = (new double[] { Norm(new PointD(this.Dimentions[0], this.Dimentions[1], 0)), this.Dimentions[2] }).Max();
            double unit = longEdgeLength / this.n;
            this.CubeDimentions = new double[] { unit, unit, unit };
            this.CubeArrayDimentions = new int[]{ 
                (int)System.Math.Ceiling(Dimentions[0] / CubeDimentions[0]), 
                n, 
                (int)System.Math.Ceiling(Dimentions[2] / CubeDimentions[2]) };
            this.CubeArrayLastIndex = new int[]{ 
                CubeArrayDimentions[0] - 1, 
                CubeArrayDimentions[1] - 1, 
                CubeArrayDimentions[2] - 1 };

            CubeSpaces = new CubicSpace[CubeArrayDimentions[0], CubeArrayDimentions[1], CubeArrayDimentions[2]];
            for (int i = 0; i < CubeArrayDimentions[0]; i++)
            {
                for (int j = 0; j < CubeArrayDimentions[1]; j++)
                {
                    for (int k = 0; k < CubeArrayDimentions[2]; k++)
                    {
                        CubeSpaces[i, j, k] = new CubicSpace();
                    }
                }
            }

            //foreach (Entity entity in part.Entities.Values)
            //{
            //    PointD[] boundary = entity.Boundary;
            //    int[] startCubeIndex = GetCubicSpaceIndex(boundary[0]);
            //    int[] endCubeIndex = GetCubicSpaceIndex(boundary[1]);

            //    for (int i = startCubeIndex[0]; i <= endCubeIndex[0]; i++)
            //    {
            //        for (int j = startCubeIndex[1]; j <= endCubeIndex[1]; j++)
            //        {
            //            for (int k = startCubeIndex[2]; k <= endCubeIndex[2]; k++)
            //            {
            //                CubeSpaces[i, j, k].Add(entity);
            //            }
            //        }
            //    }
            //}
        }
Ejemplo n.º 2
0
        public void CubicClassify(EntityCollection part)
        {
            this.Boundary = part.Boundary;
            this.Dimentions =  (Boundary[1] - Boundary[0]).ToArray();
            double longEdgeLength = this.Dimentions.Max();
            double unit = longEdgeLength / this.n;
            this.CubeDimentions = new double[] { unit, unit, unit };
            this.CubeArrayDimentions = new int[]{ 
                (int)System.Math.Ceiling(Dimentions[0] / CubeDimentions[0]), 
                (int)System.Math.Ceiling(Dimentions[1] / CubeDimentions[1]), 
                (int)System.Math.Ceiling(Dimentions[2] / CubeDimentions[2]) };
            this.CubeArrayLastIndex = new int[]{ 
                CubeArrayDimentions[0] - 1, 
                CubeArrayDimentions[1] - 1, 
                CubeArrayDimentions[2] - 1 };
            
            //計算節點
            this.Nodes = new PointD[CubeArrayDimentions[0] + 1, CubeArrayDimentions[1] + 1, CubeArrayDimentions[2] + 1];
            for (int i = 0; i < CubeArrayDimentions[0] + 1; i++)
            {
                for (int j = 0; j < CubeArrayDimentions[1] + 1; j++)
                {
                    for (int k = 0; k < CubeArrayDimentions[2] + 1; k++)
                    {
                        this.Nodes[i, j, k] = new PointD()
                        {
                            X = Boundary[0].X + CubeDimentions[0] *i,
                            Y = Boundary[0].Y + CubeDimentions[1] * j,
                            Z = Boundary[0].Z + CubeDimentions[2] * k
                        };
                    }
                }
            }
            //建立方塊
            this.CubeSpaces = new CubicSpace[CubeArrayDimentions[0], CubeArrayDimentions[1], CubeArrayDimentions[2]];
            for (int i = 0; i < CubeArrayDimentions[0]; i++)
            {
                for (int j = 0; j < CubeArrayDimentions[1]; j++)
                {
                    for (int k = 0; k < CubeArrayDimentions[2]; k++)
                    {
                        CubeSpaces[i, j, k] = new CubicSpace() { Boundary = new PointD[] { this.Nodes[i, j, k], this.Nodes[i+1, j+1, k+1] } };
                    }
                }
            }

            foreach (Entity entity in part.Entities.Values)
            {
                PointD[] boundary = entity.Boundary;
                int[] startCubeIndex = GetCubicSpaceIndex(boundary[0]);
                int[] endCubeIndex = GetCubicSpaceIndex(boundary[1]);

                for (int i = startCubeIndex[0]; i <= endCubeIndex[0]; i++)
                {
                    for (int j = startCubeIndex[1]; j <= endCubeIndex[1]; j++)
                    {
                        for (int k = startCubeIndex[2]; k <= endCubeIndex[2]; k++)
                        {
                            CubeSpaces[i, j, k].Add(entity);
                        }
                    }
                }
            }
        }