private void Create3DObject(object sender, EventArgs e) { try { MessageBox.Show("Please make sure you put 'geometry.txt' under the same directory with this exe."); MessageBox.Show("Use 'J' to increase lines, 'K' to decrease lines."); String dataRoot = @"."; String modelGrid = "geometry.txt"; var startTime = DateTime.Now; string gridPathFileName = Path.Combine(dataRoot, modelGrid); DynamicUnstructureGeometryLoader loader = new DynamicUnstructureGeometryLoader(); DateTime start = DateTime.Now; // TODO: 如何取得实际业务中的11716?是否应在LoadSource中指定? DynamicUnstructuredGridderSource source = loader.LoadSource(gridPathFileName, 11716, 1, 1); DateTime stop = DateTime.Now; double seconds = (stop.Ticks - start.Ticks) / 1000.0d; this.element = new DynamicUnStructuredGridderElement(source, this.scientificVisual3DControl.Scene.CurrentCamera) { Name = "UnStructuredGridderElement}" }; element.Initialize(this.scientificVisual3DControl.OpenGL); ///模拟获得网格属性 int minValue = 100; int maxValue = 10000; float step = (maxValue * 1.0f - minValue * 1.0f) / 10; //设置色标的范围 this.scientificVisual3DControl.SetColorIndicator(minValue, maxValue, step); this.scientificVisual3DControl.AddModelElement(element); // update ModelContainer's BoundingBox. BoundingBox boundingBox = this.scientificVisual3DControl.ModelContainer.BoundingBox; if (this.scientificVisual3DControl.ModelContainer.Children.Count > 1) { boundingBox.Extend(source.Min); boundingBox.Extend(source.Max); } else { boundingBox.SetBounds(source.Min, source.Max); } //boundingBox.Expand(); // update ViewType to UserView. this.scientificVisual3DControl.ViewType = ViewTypes.UserView; var endTime = DateTime.Now; var interval = endTime.Subtract(startTime); } catch (Exception error) { MessageBox.Show(error.ToString()); } }
private void CreateCatesianGridVisual3D(object sender, EventArgs e) { try { string fileName = @"geometry.txt"; DynamicUnstructureGeometryLoader loader = new DynamicUnstructureGeometryLoader(); // use CatesianGridderSource to fill HexahedronGridderElement's content. DynamicUnstructuredGridderSource source = loader.LoadSource(fileName); source.Init(); int nx = source.NX; int ny = source.NY; int nz = source.NZ; int dimenSize = nx * ny * nz; 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); 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); InitPropertiesAndSelectDefault(dimenSize, propMin, propMax); ///模拟获得网格属性 ///获得当前选中的属性 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 t0 = DateTime.Now; DynamicUnstructureGeometry geometry = source.CreateMesh() as DynamicUnstructureGeometry; TexCoordBuffer matrixTextureCoordinates = source.CreateTextureCoordinates(gridIndexes, gridValues, minValue, maxValue); TexCoordBuffer fractureTextureCoordindates = source.CreateFractureTextureCoordinates(gridIndexes, gridValues, minValue, maxValue); Bitmap texture = ColorPaletteHelper.GenBitmap(this.sim3D.uiColorIndicator.Data.ColorPalette); //geometry.Positions.Dump(); //geometry.TriangleIndices.Dump(); //MeshGeometry mesh = HexahedronGridderHelper.CreateMesh(source); DynamicUnstructureGrid gridder = new DynamicUnstructureGrid(this.sim3D.OpenGL, this.sim3D.Scene.CurrentCamera); gridder.Init(geometry); gridder.RenderGrid = true; gridder.RenderGridWireframe = this.IsShowWireframe; gridder.SetTexture(texture); gridder.SetMatrixTextureCoords(matrixTextureCoordinates); gridder.SetFractionTextureCoords(fractureTextureCoordindates); this.element = gridder; //textureCoodinates.Dump(); 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); this.sim3D.Tag = source; //gridderElement.Name = string.Format("element {0}", elementCounter++); //this.scientificVisual3DControl.AddModelElement(gridderElement); DateTime t3 = DateTime.Now; // 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); //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()); } }