Ejemplo n.º 1
0
        public override MeshBase CreateMesh(GridderSource source)
        {
            HexahedronGridderSource src = (HexahedronGridderSource)source;

            PositionBuffer            positions             = new HexahedronPositionBuffer();
            HalfHexahedronIndexBuffer halfHexahedronIndices = new HalfHexahedronIndexBuffer();
            int dimSize = src.DimenSize;
            int I, J, K;

            unsafe
            {
                positions.AllocMem(dimSize);

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

                //网格个数*每个六面体的面数*描述每个六面体的三角形个数
                int halfHexahedronIndexCount = dimSize * 2;
                //int memorySizeInBytes = halfHexahedronIndexCount * sizeof(HalfHexahedronIndex);
                //halfHexahedronIndices.AllocMem(memorySizeInBytes);
                halfHexahedronIndices.AllocMem(halfHexahedronIndexCount);

                HalfHexahedronIndex *array = (HalfHexahedronIndex *)halfHexahedronIndices.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;
                }

                HexahedronMeshGeometry3D mesh = new HexahedronMeshGeometry3D(positions, halfHexahedronIndices);
                mesh.Max = source.TransformedActiveBounds.Min;
                mesh.Min = source.TransformedActiveBounds.Max;
                return(mesh);
            }
        }
        private void CreateCatesianGridVisual3D(object sender, EventArgs e)
        {
            try
            {
                int   nx   = System.Convert.ToInt32(tbNX.Text);
                int   ny   = System.Convert.ToInt32(tbNY.Text);
                int   nz   = System.Convert.ToInt32(tbNZ.Text);
                float step = System.Convert.ToSingle(tbColorIndicatorStep.Text);
                //float radius = System.Convert.ToSingle(this.tbRadius.Text);
                float   propMin   = System.Convert.ToSingle(this.tbxPropertyMinValue.Text, CultureInfo.InvariantCulture);
                float   propMax   = System.Convert.ToSingle(this.tbxPropertyMaxValue.Text, CultureInfo.InvariantCulture);
                int     dimenSize = nx * ny * nz;
                float   dx        = System.Convert.ToSingle(this.tbDX.Text);
                float   dy        = System.Convert.ToSingle(this.gbDY.Text);
                float   dz        = System.Convert.ToSingle(this.tbDZ.Text);
                float[] dxArray   = initArray(dimenSize, dx);
                float[] dyArray   = initArray(dimenSize, dy);
                float[] dzArray   = initArray(dimenSize, dz);
                // use CatesianGridderSource to fill HexahedronGridderElement's content.

                DateTime t0 = DateTime.Now;
                CatesianGridderSource source = new CatesianGridderSource()
                {
                    NX = nx, NY = ny, NZ = nz, DX = dxArray, DY = dyArray, DZ = dzArray,
                };
                source.IBlocks = GridBlockHelper.CreateBlockCoords(nx);
                source.JBlocks = GridBlockHelper.CreateBlockCoords(ny);
                source.KBlocks = GridBlockHelper.CreateBlockCoords(nz);
                source.Init();
                DateTime t1 = DateTime.Now;

                InitSlice(lbxNI, source.IBlocks);
                InitSlice(lbxNJ, source.JBlocks);
                InitSlice(lbxNZ, source.KBlocks);
                InitPropertiesAndSelectDefault(dimenSize, propMin, propMax);

                DateTime t2 = DateTime.Now;

                ///模拟获得网格属性
                ///获得当前选中的属性


                float minValue = this.CurrentProperty.MinValue;
                float maxValue = this.CurrentProperty.MaxValue;
                step = (maxValue * 1.0f - minValue * 1.0f) / 10;
                int[]   gridIndexes = this.CurrentProperty.GridIndexes;
                float[] gridValues  = this.CurrentProperty.Values;
                //设置色标的范围
                this.sim3D.SetColorIndicator(minValue, maxValue, step);


                // use HexahedronGridderElement
                DateTime t3 = DateTime.Now;
                HexahedronMeshGeometry3D geometry = (HexahedronMeshGeometry3D)source.CreateMesh();
                DateTime       t4 = DateTime.Now;
                TexCoordBuffer textureCoodinates = source.CreateTextureCoordinates(gridIndexes, gridValues, minValue, maxValue);
                DateTime       t5 = DateTime.Now;

                Bitmap         texture = this.sim3D.uiColorIndicator.CreateTextureImage();
                HexahedronGrid gridder = new HexahedronGrid(this.sim3D.OpenGL, this.sim3D.Scene.CurrentCamera);
                gridder.Init(geometry);
                gridder.RenderGrid          = true;
                gridder.RenderGridWireframe = this.IsShowWireframe;
                gridder.SetTexture(texture);
                gridder.SetTextureCoods(textureCoodinates);
                texture.Dispose();
                //textureCoodinates.Dump();
                DateTime t6 = DateTime.Now;



                //gridderElement.SetBoundingBox(mesh.Min, mesh.Max);
                this.sim3D.Tag = source;



                // update ModelContainer's BoundingBox.
                BoundingBox boundingBox = this.sim3D.ModelContainer.BoundingBox;
                boundingBox.SetBounds(geometry.Min, geometry.Max);

                // update ViewType to UserView.
                this.sim3D.ViewType = ViewTypes.UserView;
                this.sim3D.AddModelElement(gridder);


                StringBuilder msgBuilder = new StringBuilder();
                msgBuilder.AppendLine(String.Format("Init Grid DataSource  in {0} secs", (t1 - t0).TotalSeconds));
                msgBuilder.AppendLine(String.Format("init ControlValues in {0} secs", (t2 - t1).TotalSeconds));
                msgBuilder.AppendLine(String.Format("prepare other params  in {0} secs", (t3 - t2).TotalSeconds));
                msgBuilder.AppendLine(String.Format("CreateMesh in {0} secs", (t4 - t3).TotalSeconds));
                msgBuilder.AppendLine(String.Format("CreateTextures in {0} secs", (t5 - t4).TotalSeconds));
                msgBuilder.AppendLine(String.Format("Init SimLabGrid  in {0} secs", (t6 - t5).TotalSeconds));
                msgBuilder.AppendLine(String.Format("Total, Create 3D Grid  in {0} secs", (t6 - t0).TotalSeconds));
                String msg = msgBuilder.ToString();
                MessageBox.Show(msg, "Summary", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            catch (Exception error)
            {
                MessageBox.Show(error.ToString());
            }
        }
Ejemplo n.º 3
0
        public override MeshBase CreateMesh(GridderSource source)
        {
            HexahedronGridderSource src = (HexahedronGridderSource)source;

            PositionBuffer positions = new HexahedronPositionBuffer();
            HalfHexahedronIndexBuffer halfHexahedronIndices = new HalfHexahedronIndexBuffer();
            int dimSize = src.DimenSize;
            int I, J, K;
            unsafe
            {
                positions.AllocMem(dimSize);

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

                //网格个数*每个六面体的面数*描述每个六面体的三角形个数
                int halfHexahedronIndexCount = dimSize * 2;
                //int memorySizeInBytes = halfHexahedronIndexCount * sizeof(HalfHexahedronIndex);
                //halfHexahedronIndices.AllocMem(memorySizeInBytes);
                halfHexahedronIndices.AllocMem(halfHexahedronIndexCount);

                HalfHexahedronIndex* array = (HalfHexahedronIndex*)halfHexahedronIndices.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;
                }

                HexahedronMeshGeometry3D mesh = new HexahedronMeshGeometry3D(positions, halfHexahedronIndices);
                mesh.Max = source.TransformedActiveBounds.Min;
                mesh.Min = source.TransformedActiveBounds.Max;
                return mesh;
            }
        }