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