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); }
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()); } }