Exemplo n.º 1
0
        private void DebugMesh(PointSpriteMesh mesh)
        {
            System.Console.WriteLine("---------Positions-----------------");
            UnmanagedArray <Vertex> array = mesh.PositionArray;

            for (int i = 0; i < array.Length; i++)
            {
                Vertex v = array[i];
                System.Console.WriteLine(string.Format("({0},{1},{2})", v.X, v.Y, v.Z));
            }
            System.Console.WriteLine("---------Colors-----------------");
            UnmanagedArray <ColorF> colors = mesh.ColorArray;

            for (int i = 0; i < colors.Length; i++)
            {
                ColorF c = colors[i];
                System.Console.WriteLine(string.Format("({0},{1},{2},{3})", c.R, c.G, c.B, c.A));
            }
            System.Console.WriteLine("---------visibles-----------------");
            UnmanagedArray <float> visibles = mesh.VisibleArray;

            for (int i = 0; i < visibles.Length; i++)
            {
                float c = visibles[i];
                System.Console.WriteLine(string.Format("({0})", c));
            }

            System.Console.WriteLine("---------TriangleTrip-----------------");
            UnmanagedArray <float> triangles = mesh.RadiusArray;

            for (int i = 0; i < triangles.Length; i++)
            {
                float t = triangles[i];
                System.Console.WriteLine(string.Format("({0})", t));
            }
        }
Exemplo n.º 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());
            }
        }