예제 #1
0
        public void TestCatesianModel()
        {
            CatesianGridderSource catesianSource = new CatesianGridderSource();

            catesianSource.NX = 6;
            catesianSource.NY = 22;
            catesianSource.NZ = 85;
            catesianSource.DX = 500;
            catesianSource.DY = 500;
            catesianSource.DZ = 20;

            HexahedronGridder hexaGridder = HexahedronGridderBuilder.BuildGridder(catesianSource);
            int arrayIndex = 0;
            int i, j, k;

            foreach (Hexahedron cell in hexaGridder.Cells)
            {
                arrayIndex++;
                catesianSource.InvertIJK(cell.gridIndex, out i, out j, out k);
                System.Console.WriteLine("[{0},{1},{2}]", i, j, k);
                System.Console.WriteLine(FormatVertex(cell.flt));
                System.Console.WriteLine(FormatVertex(cell.frt));
                System.Console.WriteLine(FormatVertex(cell.flb));
                System.Console.WriteLine(FormatVertex(cell.frt));
                System.Console.WriteLine(FormatVertex(cell.blt));
                System.Console.WriteLine(FormatVertex(cell.brt));
                System.Console.WriteLine(FormatVertex(cell.blb));
                System.Console.WriteLine(FormatVertex(cell.brb));
            }
        }
예제 #2
0
 /// <summary>
 /// base model for gridview.
 /// </summary>
 /// <param name="dataSource"></param>
 /// <param name="gridProps"></param>
 /// <param name="minColorCode"></param>
 /// <param name="maxColorCode"></param>
 /// <param name="defaultBlockPropertyIndex"></param>
 public GridViewModel(CatesianGridderSource dataSource, List <GridBlockProperty> gridProps,
                      float minColorCode, float maxColorCode, int defaultBlockPropertyIndex = 0)
 {
     this.DataSource                = dataSource;
     this.GridBlockProperties       = gridProps;
     this.MinColorCode              = minColorCode;
     this.MaxColorCode              = maxColorCode;
     this.defaultBlockPropertyIndex = defaultBlockPropertyIndex;
 }
        public static CatesianGrid DumpCatesianGrid(this SimulationInputData inputData,
                                                    float minColorCode, float maxColorCode)
        {
            GridDimens dimens = inputData.RootDataFile.GetDIMENS();

            if (dimens == null)
            {
                throw new ArgumentException("Missing DIMENS or SPECGRID");
            }
            float[] dx = inputData.RootDataFile.GetDX();
            if (dx == null)
            {
                throw new ArgumentException("Missing DX or related description");
            }
            float[] dy = inputData.RootDataFile.GetDY();
            if (dy == null)
            {
                throw new ArgumentException("Missing DY or related description");
            }
            float[] dz = inputData.RootDataFile.GetDZ();
            if (dy == null)
            {
                throw new ArgumentException("Missing DZ or related description");
            }

            var dataSource = new CatesianGridderSource();

            dataSource.NX           = dimens.NI;
            dataSource.NY           = dimens.NJ;
            dataSource.NZ           = dimens.NK;
            dataSource.DX           = dx;
            dataSource.DY           = dy;
            dataSource.DZ           = dz;
            dataSource.TOPS         = inputData.RootDataFile.GetTOPS();
            dataSource.ActiveBlocks = inputData.RootDataFile.GetACTNUM();
            dataSource.IBlocks      = SimLab.ArrayHelper.CreateAllSlices(dimens.NI);
            dataSource.JBlocks      = SimLab.ArrayHelper.CreateAllSlices(dimens.NJ);
            dataSource.KBlocks      = SimLab.ArrayHelper.CreateAllSlices(dimens.NK);
            dataSource.Init();
            List <GridBlockProperty> gridProps = inputData.RootDataFile.GetGridProperties();
            var grid = new CatesianGrid(dataSource, gridProps, minColorCode, maxColorCode);

            return(grid);
        }
예제 #4
0
 public CatesianGrid(CatesianGridderSource dataSource, List <GridBlockProperty> gridProps,
                     float minColorCode, float maxColorCode, int defaultBlockPropertyIndex = 0)
     : base(dataSource, gridProps, minColorCode, maxColorCode, defaultBlockPropertyIndex)
 {
 }
예제 #5
0
        private void Create3DObject(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);
                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.
                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);


                //DemoPointSpriteGridderSource source = new DemoPointSpriteGridderSource() { NX = nx, NY = ny, NZ = nz, };

                ///模拟获得网格属性
                int minValue = 100;
                int maxValue = 10000;
                step = (maxValue * 1.0f - minValue * 1.0f) / 10;
                int[]   gridIndexes;
                float[] gridValues;
                //设置色标的范围
                this.scientificVisual3DControl.SetColorIndicator(minValue, maxValue, step);
                //获得每个网格上的属性值
                HexahedronGridderHelper.RandomValue(source.DimenSize, minValue, maxValue, out gridIndexes, out gridValues);
                ColorF[] colors = new ColorF[source.DimenSize];
                for (int i = 0; i < colors.Length; i++)
                {
                    colors[i] = (ColorF)this.scientificVisual3DControl.MapToColor(gridValues[i]);
                }

                // use HexahedronGridderElement
                DateTime     t0   = DateTime.Now;
                MeshGeometry mesh = HexahedronGridderHelper.CreateMesh(source);
                DateTime     t1   = DateTime.Now;
                TimeSpan     ts1  = t1 - t0;

                mesh.VertexColors = HexahedronGridderHelper.FromColors(source, gridIndexes, colors, mesh.Visibles);
                //this.DebugMesh(mesh);

                HexahedronGridderElement gridderElement = new HexahedronGridderElement(source, this.scientificVisual3DControl.Scene.CurrentCamera);
                gridderElement.renderWireframe = false;
                //method1
                //gridderElement.Initialize(this.scientificVisual3DControl.OpenGL);

                //method2
                gridderElement.Initialize(this.scientificVisual3DControl.OpenGL, mesh);
                DateTime t2 = DateTime.Now;

                //gridderElement.SetBoundingBox(mesh.Min, mesh.Max);

                //// use PointSpriteGridderElement
                //PointSpriteMesh mesh = PointSpriteGridderElementHelper.CreateMesh(source);
                //mesh.ColorArray = PointSpriteGridderElementHelper.FromColors(source, gridIndexes, colors, mesh.VisibleArray);

                //PointSpriteGridderElement gridderElement = new PointSpriteGridderElement(source, this.scientificVisual3DControl.Scene.CurrentCamera);
                //gridderElement.Initialize(this.scientificVisual3DControl.OpenGL, mesh);
                ////DebugMesh(mesh);

                //


                gridderElement.Name = string.Format("element {0}", elementCounter++);
                this.scientificVisual3DControl.AddModelElement(gridderElement);
                DateTime t3 = DateTime.Now;
                // update ModelContainer's BoundingBox.
                BoundingBox boundingBox = this.scientificVisual3DControl.ModelContainer.BoundingBox;
                if (this.scientificVisual3DControl.ModelContainer.Children.Count > 1)
                {
                    boundingBox.Extend(mesh.Min);
                    boundingBox.Extend(mesh.Max);
                }
                else
                {
                    boundingBox.SetBounds(mesh.Min, mesh.Max);
                }
                //boundingBox.Expand();

                // update ViewType to UserView.
                this.scientificVisual3DControl.ViewType = ViewTypes.UserView;
                mesh.Dispose();

                StringBuilder msgBuilder = new StringBuilder();
                msgBuilder.AppendLine(String.Format("create mesh in {0} secs", (t1 - t0).TotalSeconds));
                msgBuilder.AppendLine(String.Format("init SceneElement in {0} secs", (t2 - t1).TotalSeconds));
                msgBuilder.AppendLine(String.Format("total load in {0} secs", (t2 - t0).TotalSeconds));
                String msg = msgBuilder.ToString();
                MessageBox.Show(msg, "Summary", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            catch (Exception error)
            {
                MessageBox.Show(error.ToString());
            }
        }
        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());
            }
        }