コード例 #1
0
        private void CreateGridVisual3D(object sender, EventArgs e)
        {
            try
            {
                int   nx   = 236365;
                int   ny   = 1;
                int   nz   = 1;
                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);

                // use CatesianGridderSource to fill HexahedronGridderElement's content.
                string             fileName = @"TET5_cvxyz.txt";
                PointSetLoader     loader   = new PointSetLoader();
                PointGridderSource source   = loader.LoadFromFile(fileName, nx, ny, nz);
                source.Init();

                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;
                PointMeshGeometry3D geometry          = source.CreateMesh() as PointMeshGeometry3D;
                TexCoordBuffer      textureCoodinates = source.CreateTextureCoordinates(gridIndexes, gridValues, minValue, maxValue);
                Bitmap    texture = ColorPaletteHelper.GenBitmap(this.sim3D.uiColorIndicator.Data.ColorPalette);
                PointGrid gridder = new PointGrid(this.sim3D.OpenGL, this.sim3D.Scene.CurrentCamera);
                gridder.Init(geometry);
                gridder.RenderGrid          = true;
                gridder.RenderGridWireframe = this.IsShowWireframe;
                gridder.SetTexture(texture);
                gridder.SetTextureCoods(textureCoodinates);



                DateTime t1  = DateTime.Now;
                TimeSpan ts1 = t1 - t0;


                DateTime t2 = DateTime.Now;

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

                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());
            }
        }
コード例 #2
0
        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());
            }
        }