コード例 #1
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());
            }
        }
コード例 #2
0
        private void scientificVisual3DControl_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == 'r')
            {
                // 随机显示某些hexahedron
                foreach (var item in this.scientificVisual3DControl.ModelContainer.Children)
                {
                    {
                        HexahedronGridderElement element = item as HexahedronGridderElement;
                        if (element != null)
                        {
                            YieldingGeometryModel.Builder.HexahedronGridderElementHelper.RandomVisibility(element, this.scientificVisual3DControl.OpenGL, 0.2);
                        }
                    }
                    {
                        PointSpriteGridderElement element = item as PointSpriteGridderElement;
                        if (element != null)
                        {
                            YieldingGeometryModel.Builder.PointSpriteGridderElementHelper.RandomVisibility(element, this.scientificVisual3DControl.OpenGL, 0.2);
                        }
                    }
                }

                this.scientificVisual3DControl.Invalidate();
            }


            if (e.KeyChar == 'c')
            {
                OpenGL gl = this.scientificVisual3DControl.OpenGL;

                List <HexahedronGridderElement> elements = this.scientificVisual3DControl.ModelContainer.Traverse <HexahedronGridderElement>().ToList <HexahedronGridderElement>();
                if (elements.Count > 0)
                {
                    HexahedronGridderElement gridder  = elements[0];
                    HexahedronGridderSource  source   = gridder.Source;
                    UnmanagedArray <float>   visibles = HexahedronGridderHelper.GridVisibleFromActive(source);

                    //随机生成不完整网格的属性。
                    int propCount = source.DimenSize / 2;
                    if (propCount <= 0)
                    {
                        return;
                    }

                    int     minValue = 5000;
                    int     maxValue = 10000;
                    int[]   gridIndexes;
                    float[] gridValues;
                    HexahedronGridderHelper.RandomValue(propCount, minValue, maxValue, out gridIndexes, out gridValues);
                    float step = (maxValue - minValue) / 10.0f;
                    this.scientificVisual3DControl.SetColorIndicator(minValue, maxValue, step);

                    ColorF[] colors = new ColorF[propCount];
                    for (int i = 0; i < colors.Length; i++)
                    {
                        colors[i] = (ColorF)this.scientificVisual3DControl.MapToColor(gridValues[i]);
                    }

                    UnmanagedArray <ColorF> colorArray = HexahedronGridderHelper.FromColors(source, gridIndexes, colors, visibles);
                    gridder.UpdateColorBuffer(gl, colorArray, visibles);
                    colorArray.Dispose();
                    visibles.Dispose();
                    this.scientificVisual3DControl.Invalidate();
                }
            }
        }
コード例 #3
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);

                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.
                //DemoPointSpriteGridderSource source = new DemoPointSpriteGridderSource() { NX = nx, NY = ny, NZ = nz, };
                //var source = new dfmPointSpriteGridderSource() { NX = nx, NY = ny, NZ = nz, };
                var source = new dfmPointSpriteGridderSource(this.maxRadius)
                {
                    NX = 386527, NY = 1, NZ = 1,
                };

                ///模拟获得网格属性
                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 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);

                //
                gridderElement.Name = string.Format("element {0}", elementCounter++);

                this.scientificVisual3DControl.AddModelElement(gridderElement);

                // 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();
            }
            catch (Exception error)
            {
                MessageBox.Show(error.ToString());
            }
        }