Пример #1
0
        private unsafe HexahedronPositionBuffer GeneratePositionBuffer(ref Vertex max, ref Vertex min)
        {
            HexahedronGridderSource  src            = this;
            HexahedronPositionBuffer positionBuffer = new HexahedronPositionBuffer();
            int dimSize = src.DimenSize;
            int I, J, K;

            positionBuffer.AllocMem(dimSize);

            HexahedronPosition *cell = (HexahedronPosition *)positionBuffer.Data;

            for (int gridIndex = 0; gridIndex < dimSize; gridIndex++)
            {
                src.InvertIJK(gridIndex, out I, out J, out K);
                cell[gridIndex].FLT = src.PointFLT(I, J, K);
                cell[gridIndex].FRT = src.PointFRT(I, J, K);
                cell[gridIndex].BRT = src.PointBRT(I, J, K);
                cell[gridIndex].BLT = src.PointBLT(I, J, K);
                cell[gridIndex].FLB = src.PointFLB(I, J, K);
                cell[gridIndex].FRB = src.PointFRB(I, J, K);
                cell[gridIndex].BRB = src.PointBRB(I, J, K);
                cell[gridIndex].BLB = src.PointBLB(I, J, K);

                if (!isSet && src.IsActiveBlock(gridIndex))
                {
                    min   = cell[gridIndex].FLT;
                    max   = min;
                    isSet = true;
                }

                if (isSet && src.IsActiveBlock(gridIndex))
                {
                    min = SimLab.SimGrid.helper.VertexHelper.MinVertex(min, cell[gridIndex].FLT);
                    max = SimLab.SimGrid.helper.VertexHelper.MaxVertex(max, cell[gridIndex].FLT);

                    min = SimLab.SimGrid.helper.VertexHelper.MinVertex(min, cell[gridIndex].FRT);
                    max = SimLab.SimGrid.helper.VertexHelper.MaxVertex(max, cell[gridIndex].FRT);

                    min = SimLab.SimGrid.helper.VertexHelper.MinVertex(min, cell[gridIndex].BRT);
                    max = SimLab.SimGrid.helper.VertexHelper.MaxVertex(max, cell[gridIndex].BRT);

                    min = SimLab.SimGrid.helper.VertexHelper.MinVertex(min, cell[gridIndex].BLT);
                    max = SimLab.SimGrid.helper.VertexHelper.MaxVertex(max, cell[gridIndex].BLT);

                    min = SimLab.SimGrid.helper.VertexHelper.MinVertex(min, cell[gridIndex].FLB);
                    max = SimLab.SimGrid.helper.VertexHelper.MaxVertex(max, cell[gridIndex].FLB);

                    min = SimLab.SimGrid.helper.VertexHelper.MinVertex(min, cell[gridIndex].FRB);
                    max = SimLab.SimGrid.helper.VertexHelper.MaxVertex(max, cell[gridIndex].FRB);

                    min = SimLab.SimGrid.helper.VertexHelper.MinVertex(min, cell[gridIndex].BRB);
                    max = SimLab.SimGrid.helper.VertexHelper.MaxVertex(max, cell[gridIndex].BRB);

                    min = SimLab.SimGrid.helper.VertexHelper.MinVertex(min, cell[gridIndex].BLB);
                    max = SimLab.SimGrid.helper.VertexHelper.MaxVertex(max, cell[gridIndex].BLB);
                }
            }

            return(positionBuffer);
        }
Пример #2
0
        private HexahedronTexCoordBuffer GenerateTexCoordBuffer(int[] gridIndexes, float[] values, float minValue, float maxValue)
        {
            HexahedronGridderSource src = this;

            int[] resultsVisibles = src.ExpandVisibles(gridIndexes);
            int[] bindVisibles    = src.BindCellActive(src.BindVisibles, resultsVisibles);

            int dimenSize = src.DimenSize;

            float[] textures = src.GetInvisibleTextureCoords();
            float   distance = Math.Abs(maxValue - minValue);

            for (int i = 0; i < gridIndexes.Length; i++)
            {
                int   gridIndex = gridIndexes[i];
                float value     = values[i];
                if (value < minValue)
                {
                    value = minValue;
                }
                if (value > maxValue)
                {
                    value = maxValue;
                }

                if (bindVisibles[gridIndex] > 0)
                {
                    if (!(distance <= 0.0f))
                    {
                        textures[gridIndex] = (value - minValue) / distance;
                    }
                    else
                    {
                        //最小值最大值相等时,显示最小值的颜色
                        textures[gridIndex] = 0.0f;
                    }
                }
            }

            HexahedronTexCoordBuffer coordBuffer = new HexahedronTexCoordBuffer();

            unsafe
            {
                int gridCellCount = src.DimenSize;
                coordBuffer.AllocMem(gridCellCount);
                HexahedronTexCoord *coords = (HexahedronTexCoord *)coordBuffer.Data;
                for (int gridIndex = 0; gridIndex < dimenSize; gridIndex++)
                {
                    coords[gridIndex].SetCoord(textures[gridIndex]);
                }
            }

            return(coordBuffer);
        }
Пример #3
0
        private unsafe HalfHexahedronIndexBuffer GenerateIndexBuffer()
        {
            HexahedronGridderSource   src         = this;
            HalfHexahedronIndexBuffer indexBuffer = new HalfHexahedronIndexBuffer();
            int dimSize = src.DimenSize;

            //网格个数*2:每个六面体需要2个半六面体索引来描述。
            //半六面体描述的是GL_QUAD_STRIP格式的3个四边形。
            int indexLength = dimSize * 2;

            indexBuffer.AllocMem(indexLength);

            HalfHexahedronIndex *array = (HalfHexahedronIndex *)indexBuffer.Data;

            for (int gridIndex = 0; gridIndex < dimSize; gridIndex++)
            {
                array[gridIndex * 2].dot0         = (uint)(8 * gridIndex + 6);
                array[gridIndex * 2].dot1         = (uint)(8 * gridIndex + 2);
                array[gridIndex * 2].dot2         = (uint)(8 * gridIndex + 7);
                array[gridIndex * 2].dot3         = (uint)(8 * gridIndex + 3);
                array[gridIndex * 2].dot4         = (uint)(8 * gridIndex + 4);
                array[gridIndex * 2].dot5         = (uint)(8 * gridIndex + 0);
                array[gridIndex * 2].dot6         = (uint)(8 * gridIndex + 5);
                array[gridIndex * 2].dot7         = (uint)(8 * gridIndex + 1);
                array[gridIndex * 2].restartIndex = uint.MaxValue;

                array[gridIndex * 2 + 1].dot0         = (uint)(8 * gridIndex + 3);
                array[gridIndex * 2 + 1].dot1         = (uint)(8 * gridIndex + 0);
                array[gridIndex * 2 + 1].dot2         = (uint)(8 * gridIndex + 2);
                array[gridIndex * 2 + 1].dot3         = (uint)(8 * gridIndex + 1);
                array[gridIndex * 2 + 1].dot4         = (uint)(8 * gridIndex + 6);
                array[gridIndex * 2 + 1].dot5         = (uint)(8 * gridIndex + 5);
                array[gridIndex * 2 + 1].dot6         = (uint)(8 * gridIndex + 7);
                array[gridIndex * 2 + 1].dot7         = (uint)(8 * gridIndex + 4);
                array[gridIndex * 2 + 1].restartIndex = uint.MaxValue;
            }

            return(indexBuffer);
        }